stage3/constant_folding.cc
changeset 690 6156ee2b4e32
parent 667 bd1360f29f15
child 735 0304ff59fd7f
equal deleted inserted replaced
689:45c35d829db9 690:6156ee2b4e32
   980 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */
   980 /* | il_expr_operator '(' [il_operand] eol_list [simple_instr_list] ')' */
   981 // SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_list);
   981 // SYM_REF3(il_expression_c, il_expr_operator, il_operand, simple_instr_list);
   982 void *constant_folding_c::visit(il_expression_c *symbol) {
   982 void *constant_folding_c::visit(il_expression_c *symbol) {
   983   symbol_c *prev_il_instruction_backup = prev_il_instruction;
   983   symbol_c *prev_il_instruction_backup = prev_il_instruction;
   984   
   984   
   985   if (NULL != symbol->il_operand)
   985   /* Stage2 will insert an artificial (and equivalent) LD <il_operand> to the simple_instr_list if necessary. We can therefore ignore the 'il_operand' entry! */
   986     symbol->il_operand->accept(*this);
   986   // if (NULL != symbol->il_operand)
       
   987   //   symbol->il_operand->accept(*this);
   987 
   988 
   988   if(symbol->simple_instr_list != NULL)
   989   if(symbol->simple_instr_list != NULL)
   989     symbol->simple_instr_list->accept(*this);
   990     symbol->simple_instr_list->accept(*this);
   990 
   991 
   991   /* Now do the operation,  */
   992   /* Now do the operation,  */
   994   symbol->il_expr_operator->accept(*this);
   995   symbol->il_expr_operator->accept(*this);
   995   il_operand = NULL;
   996   il_operand = NULL;
   996   
   997   
   997   /* This object has (inherits) the same cvalues as the il_instruction */
   998   /* This object has (inherits) the same cvalues as the il_instruction */
   998   symbol->const_value = symbol->il_expr_operator->const_value;
   999   symbol->const_value = symbol->il_expr_operator->const_value;
       
  1000   
       
  1001   /* Since stage2 will insert an artificial (and equivalent) LD <il_operand> to the simple_instr_list when an 'il_operand' exists, we know
       
  1002    * that if (symbol->il_operand != NULL), then the first IL instruction in the simple_instr_list will be the equivalent and artificial
       
  1003    * 'LD <il_operand>' IL instruction.
       
  1004    * Just to be cosistent, we will copy the constant info back into the il_operand, even though this should not be necessary!
       
  1005    */
       
  1006   if ((NULL != symbol->il_operand) && ((NULL == symbol->simple_instr_list) || (0 == ((list_c *)symbol->simple_instr_list)->n))) ERROR; // stage2 is not behaving as we expect it to!
       
  1007   if  (NULL != symbol->il_operand)
       
  1008     symbol->il_operand->const_value = ((list_c *)symbol->simple_instr_list)->elements[0]->const_value;
       
  1009 
   999   return NULL;
  1010   return NULL;
  1000 }
  1011 }
  1001 
  1012 
  1002 
  1013 
  1003 
  1014