Skip to content

Commit

Permalink
Fixed unused variable optimizer under 6809.
Browse files Browse the repository at this point in the history
  • Loading branch information
spotlessmind1975 committed Oct 26, 2024
1 parent 0c051e8 commit 077d58d
Showing 1 changed file with 79 additions and 1 deletion.
80 changes: 79 additions & 1 deletion ugbc/src/targets/d32/_optimizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2021,8 +2021,86 @@ static void optim_remove_unused_temporary( Environment * _environment ) {
++_environment->removedAssemblyLines;
}
} else if (
( ( po_buf_match( buf[0], " LDA #*", v1 ) || po_buf_match( buf[0], " CLRA") ) && po_buf_match( buf[1], " STA *", v2 ) && po_buf_match( buf[2], " STA *", v3 ) ) ||
( ( po_buf_match( buf[0], " LDB #*", v1 ) || po_buf_match( buf[0], " CLRB") ) && po_buf_match( buf[1], " STB *", v2 ) && po_buf_match( buf[2], " STB *", v3 ) ) ||
( po_buf_match( buf[0], " LDD #*", v1 ) && po_buf_match( buf[1], " STD *", v2 ) && po_buf_match( buf[1], " STD *", v3 ) )
) {

char * realVarName = strdup( v2->str );
char * c = strstr( realVarName, "+" );
if ( c ) {
*c = 0;
}
c = strstr( realVarName, "<(" );
if ( c ) {
strcpy( c, c+2 );
}
c = strstr( realVarName, ")" );
if ( c ) {
*c = 0;
}

// printf(" RULE #2 for [%s]\n", realVarName );

UnusedSymbol * tmp = currentlyUnusedSymbols;
while( tmp ) {
// printf(" - compare %s = %s\n", realVarName, tmp->realName );
if ( strcmp( realVarName, tmp->realName ) == 0 ) {
// printf(" > found!\n" );
break;
}
tmp = tmp->next;
}
// printf( "\n" );
if ( tmp ) {
// printf(" APPLIED #2\n");
// optim( buf[0], RULE "unused temporary", NULL );
optim( buf[1], RULE "unused temporary", NULL );
++_environment->removedAssemblyLines;
++_environment->removedAssemblyLines;
}
} else if (
po_buf_match( buf[0], " DEC*", v1 ) &&
po_buf_match( buf[1], "_*", v4 ) &&
po_buf_match( buf[2], " ST* *", v3, v2 ) &&
(po_buf_cmp( v1, v3 ) == 0)
) {

char * realVarName = strdup( v2->str );
char * c = strstr( realVarName, "+" );
if ( c ) {
*c = 0;
}
c = strstr( realVarName, "<(" );
if ( c ) {
strcpy( c, c+2 );
}
c = strstr( realVarName, ")" );
if ( c ) {
*c = 0;
}

// printf(" RULE #2 for [%s]\n", realVarName );

UnusedSymbol * tmp = currentlyUnusedSymbolsQ;
while( tmp ) {
// printf(" - compare %s = %s\n", realVarName, tmp->realName );
if ( strcmp( realVarName, tmp->realName ) == 0 ) {
// printf(" > found!\n" );
break;
}
tmp = tmp->next;
}
// printf( "\n" );
if ( tmp ) {
// printf(" APPLIED #2\n");
// optim( buf[0], RULE "unused temporary", NULL );
optim( buf[2], RULE "unused temporary", "\tTST%s", v1->str );
++_environment->removedAssemblyLines;
}
} else if (
( ( po_buf_match( buf[0], " LDA #*", v1 ) || po_buf_match( buf[0], " CLRA") ) && po_buf_match( buf[1], " STA *", v2 ) ) ||
( ( po_buf_match( buf[0], " LDB #*", v1 ) || po_buf_match( buf[0], " CLRB") ) && po_buf_match( buf[1], " STB *", v2 ) ) ||
( ( po_buf_match( buf[0], " LDB #*", v1 ) || po_buf_match( buf[0], " CLRB") ) && po_buf_match( buf[1], " STB *", v2 ) ) ||
( po_buf_match( buf[0], " LDD #*", v1 ) && po_buf_match( buf[1], " STD *", v2 ) )
) {

Expand Down

0 comments on commit 077d58d

Please sign in to comment.