]> git.gag.com Git - fw/sdcc/commitdiff
* src/SDCCast.h,
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 20 Dec 2003 07:08:30 +0000 (07:08 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 20 Dec 2003 07:08:30 +0000 (07:08 +0000)
* 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

ChangeLog
src/SDCC.y
src/SDCCast.c
src/SDCCast.h
src/SDCCglobl.h
src/SDCCicode.c
src/SDCCicode.h
src/SDCCopt.c

index 9fdc955703c042413eadf9a9967ce7bd6c1a0610..76d7b8cbcba77539a95f2884a2a05055916b4ba5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2003-12-20 Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+       * 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 <epetrich@ivorytower.norman.ok.us>
 
        * support/Util/SDCCerr.c,
index 5d1473bfd60ab44075c5c8addd28e2edce5a1286..7f5f7e215ca2ec80f8b437eeb18a65e6c85d2fc2 100644 (file)
@@ -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;
index 3209c0c9eaf80b0633ab362ff092279a8380c81d..7a8bfc61e050f3f3d72585f92238abae3eb1659c 100644 (file)
@@ -84,6 +84,7 @@ newAst_ (unsigned type)
   ex->level = NestLevel;
   ex->block = currBlockno;
   ex->initMode = inInitMode;
+  ex->seqPoint = seqPointNo;
   return ex;
 }
 
index 6747881dd1d131396cd92f93562b390249c79f7a..649960e7f0177e762dc4082370bc70cb3cac3086 100644 (file)
@@ -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
       {
index b09081bda301a041037caaea6204782f4bc9dcc6..494b79c189a6c4a71080a5fc30cfd7190bd27e6e 100644 (file)
@@ -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;             /* */
index 9637d52dd11313e42b2129658c337727efd3e67e..b723c54116810e4fcfc3e4d25a8e3103bf5b2de6 100644 (file)
@@ -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);
index 81b6fb5ab72b9a72245c523ba4be6cd77a6791d8..8d6c543b5a64b34e2c4d1c370b079742e13a6b22 100644 (file)
@@ -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 */
index 1ac5b7f94cf7c928e6236603990bd14e13a30cef..a4c7de2261b6a42e56537c9821350e8ce2ef8f14 100644 (file)
@@ -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++;