From: epetrich Date: Sat, 20 Dec 2003 07:08:30 +0000 (+0000) Subject: * src/SDCCast.h, X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=3d3fd6633add67fd559ddae48691eb4e92b81903;p=fw%2Fsdcc * src/SDCCast.h, * src/SDCCast.c (newAst_), * src/SDCCicode.h, * src/SDCCicode.c (ast2iCode, newiCode), * src/SDCCglobl.h, * src/SDCC.y (logical_and_expr, logical_or_expr, conditional_expr, expr, statement, expression_statement, selection_statement, iteration_statement, expr_opt, jump_statement): foundation for tracking sequence points * src/SDCCopt.c (killDeadCode): fixed bug #861580 (needs the sequence point code too) git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3064 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 9fdc9557..76d7b8cb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2003-12-20 Erik Petrich + + * src/SDCCast.h, + * src/SDCCast.c (newAst_), + * src/SDCCicode.h, + * src/SDCCicode.c (ast2iCode, newiCode), + * src/SDCCglobl.h, + * src/SDCC.y (logical_and_expr, logical_or_expr, conditional_expr, + expr, statement, expression_statement, selection_statement, + iteration_statement, expr_opt, jump_statement): foundation for tracking + sequence points + * src/SDCCopt.c (killDeadCode): fixed bug #861580 (needs the sequence + point code too) + 2003-12-19 Erik Petrich * support/Util/SDCCerr.c, diff --git a/src/SDCC.y b/src/SDCC.y index 5d1473bf..7f5f7e21 100644 --- a/src/SDCC.y +++ b/src/SDCC.y @@ -45,6 +45,7 @@ int reentrant = 0 ; int blockNo = 0 ; /* sequential block number */ int currBlockno=0 ; int inCritical= 0 ; +int seqPointNo= 1 ; /* sequence point number */ extern int yylex(); int yyparse(void); extern int noLineno ; @@ -373,21 +374,21 @@ inclusive_or_expr logical_and_expr : inclusive_or_expr - | logical_and_expr AND_OP inclusive_or_expr - { $$ = newNode(AND_OP,$1,$3);} + | logical_and_expr AND_OP { seqPointNo++;} inclusive_or_expr + { $$ = newNode(AND_OP,$1,$4);} ; logical_or_expr : logical_and_expr - | logical_or_expr OR_OP logical_and_expr - { $$ = newNode(OR_OP,$1,$3); } + | logical_or_expr OR_OP { seqPointNo++;} logical_and_expr + { $$ = newNode(OR_OP,$1,$4); } ; conditional_expr : logical_or_expr - | logical_or_expr '?' logical_or_expr ':' conditional_expr + | logical_or_expr '?' { seqPointNo++;} logical_or_expr ':' conditional_expr { - $$ = newNode(':',$3,$5) ; + $$ = newNode(':',$4,$6) ; $$ = newNode('?',$1,$$) ; } ; @@ -465,7 +466,7 @@ assignment_operator expr : assignment_expr - | expr ',' assignment_expr { $$ = newNode(',',$1,$3);} + | expr ',' { seqPointNo++;} assignment_expr { $$ = newNode(',',$1,$4);} ; constant_expr @@ -1297,8 +1298,11 @@ statement | jump_statement | critical_statement | INLINEASM ';' { - ast *ex = newNode(INLINEASM,NULL,NULL); + ast *ex; + seqPointNo++; + ex = newNode(INLINEASM,NULL,NULL); ex->values.inlineasm = strdup($1); + seqPointNo++; $$ = ex; } ; @@ -1401,7 +1405,7 @@ statement_list expression_statement : ';' { $$ = NULL;} - | expr ';' + | expr ';' { $$ = $1; seqPointNo++;} ; else_statement @@ -1411,11 +1415,17 @@ else_statement selection_statement - : IF '(' expr ')' statement else_statement { noLineno++ ; $$ = createIf ($3, $5, $6 ); noLineno--;} + : IF '(' expr ')' { seqPointNo++;} statement else_statement + { + noLineno++ ; + $$ = createIf ($3, $6, $7 ); + noLineno--; + } | SWITCH '(' expr ')' { ast *ex ; static int swLabel = 0 ; + seqPointNo++; /* create a node for expression */ ex = newNode(SWITCH,$3,NULL); STACK_PUSH(swStk,ex); /* save it in the stack */ @@ -1484,16 +1494,17 @@ for : FOR { /* create & push continue, break & body labels */ ; iteration_statement - : while '(' expr ')' statement + : while '(' expr ')' { seqPointNo++;} statement { noLineno++ ; $$ = createWhile ( $1, STACK_POP(continueStack), - STACK_POP(breakStack), $3, $5 ); + STACK_POP(breakStack), $3, $6 ); $$->lineno = $1->lineDef ; noLineno-- ; } | do statement WHILE '(' expr ')' ';' { + seqPointNo++; noLineno++ ; $$ = createDo ( $1 , STACK_POP(continueStack), STACK_POP(breakStack), $5, $2); @@ -1528,8 +1539,8 @@ iteration_statement ; expr_opt - : { $$ = NULL ; } - | expr + : { $$ = NULL ; seqPointNo++; } + | expr { $$ = $1 ; seqPointNo++; } ; jump_statement @@ -1562,6 +1573,7 @@ jump_statement } } | RETURN ';' { + seqPointNo++; if (inCritical) { werror(E_INVALID_CRITICAL); $$ = NULL; @@ -1570,6 +1582,7 @@ jump_statement } } | RETURN expr ';' { + seqPointNo++; if (inCritical) { werror(E_INVALID_CRITICAL); $$ = NULL; diff --git a/src/SDCCast.c b/src/SDCCast.c index 3209c0c9..7a8bfc61 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -84,6 +84,7 @@ newAst_ (unsigned type) ex->level = NestLevel; ex->block = currBlockno; ex->initMode = inInitMode; + ex->seqPoint = seqPointNo; return ex; } diff --git a/src/SDCCast.h b/src/SDCCast.h index 6747881d..649960e7 100644 --- a/src/SDCCast.h +++ b/src/SDCCast.h @@ -51,6 +51,7 @@ typedef struct ast unsigned initMode:1; int level; /* level for expr */ int block; /* block number */ + int seqPoint; /* sequence point */ /* union of values expression can have */ union { diff --git a/src/SDCCglobl.h b/src/SDCCglobl.h index b09081bd..494b79c1 100644 --- a/src/SDCCglobl.h +++ b/src/SDCCglobl.h @@ -265,6 +265,7 @@ extern char *dstPath; /* path for the output files; */ /* "" is equivalent with cwd */ extern char *moduleName; /* module name is source file without path and extension */ /* can be NULL while linking without compiling */ +extern int seqPointNo; /* current sequence point */ extern int currLineno; /* current line number */ extern int mylineno; /* line number of the current file SDCC.lex */ extern FILE *yyin; /* */ diff --git a/src/SDCCicode.c b/src/SDCCicode.c index 9637d52d..b723c541 100644 --- a/src/SDCCicode.c +++ b/src/SDCCicode.c @@ -38,6 +38,7 @@ char *filename; int lineno; int block; int scopeLevel; +int seqPoint; symbol *returnLabel; /* function return label */ symbol *entryLabel; /* function entry label */ @@ -572,6 +573,7 @@ newiCode (int op, operand * left, operand * right) ic = Safe_alloc ( sizeof (iCode)); + ic->seqPoint = seqPoint; ic->lineno = lineno; ic->filename = filename; ic->block = block; @@ -1426,7 +1428,7 @@ operandFromOperand (operand * op) nop->isLiteral = op->isLiteral; nop->usesDefs = op->usesDefs; nop->isParm = op->isParm; - + switch (nop->type) { case SYMBOL: @@ -3593,6 +3595,8 @@ ast2iCode (ast * tree,int lvl) block = tree->block; if (tree->level) scopeLevel = tree->level; + if (tree->seqPoint) + seqPoint = tree->seqPoint; if (tree->type == EX_VALUE) return operandFromValue (tree->opval.val); diff --git a/src/SDCCicode.h b/src/SDCCicode.h index 81b6fb5a..8d6c543b 100644 --- a/src/SDCCicode.h +++ b/src/SDCCicode.h @@ -130,6 +130,7 @@ typedef struct iCode unsigned int op; /* operation defined */ int key; /* running key for this iCode */ int seq; /* sequence number within routine */ + int seqPoint; /* sequence point */ short depth; /* loop depth of this iCode */ short level; /* scope level */ short block; /* sequential block number */ diff --git a/src/SDCCopt.c b/src/SDCCopt.c index 1ac5b7f9..a4c7de22 100644 --- a/src/SDCCopt.c +++ b/src/SDCCopt.c @@ -824,6 +824,18 @@ killDeadCode (eBBlock ** ebbs, int count) bool volRight = IS_SYMOP (IC_RIGHT (ic)) && isOperandVolatile (IC_RIGHT (ic), FALSE); + + if (ic->next && ic->seqPoint == ic->next->seqPoint + && (ic->next->op == '+' || ic->next->op == '-')) + { + if (isOperandEqual (IC_LEFT(ic), IC_LEFT(ic->next)) + || isOperandEqual (IC_LEFT(ic), IC_RIGHT(ic->next))) + volLeft = FALSE; + if (isOperandEqual (IC_RIGHT(ic), IC_LEFT(ic->next)) + || isOperandEqual (IC_RIGHT(ic), IC_RIGHT(ic->next))) + volRight = FALSE; + } + change = 1; gchange++;