1036 * 'LD <il_operand>' IL instruction. |
1036 * 'LD <il_operand>' IL instruction. |
1037 * Just to be cosistent, we will copy the constant info back into the il_operand, even though this should not be necessary! |
1037 * Just to be cosistent, we will copy the constant info back into the il_operand, even though this should not be necessary! |
1038 */ |
1038 */ |
1039 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! |
1039 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! |
1040 if (NULL != symbol->il_operand) |
1040 if (NULL != symbol->il_operand) |
1041 symbol->il_operand->const_value = ((list_c *)symbol->simple_instr_list)->elements[0]->const_value; |
1041 symbol->il_operand->const_value = ((list_c *)symbol->simple_instr_list)->get_element(0)->const_value; |
1042 |
1042 |
1043 return NULL; |
1043 return NULL; |
1044 } |
1044 } |
1045 |
1045 |
1046 |
1046 |
1087 void *constant_folding_c::visit(simple_instr_list_c *symbol) { |
1087 void *constant_folding_c::visit(simple_instr_list_c *symbol) { |
1088 if (symbol->n <= 0) |
1088 if (symbol->n <= 0) |
1089 return NULL; /* List is empty! Nothing to do. */ |
1089 return NULL; /* List is empty! Nothing to do. */ |
1090 |
1090 |
1091 for(int i = 0; i < symbol->n; i++) |
1091 for(int i = 0; i < symbol->n; i++) |
1092 symbol->elements[i]->accept(*this); |
1092 symbol->get_element(i)->accept(*this); |
1093 |
1093 |
1094 /* This object has (inherits) the same cvalues as the il_jump_operator */ |
1094 /* This object has (inherits) the same cvalues as the il_jump_operator */ |
1095 symbol->const_value = symbol->elements[symbol->n-1]->const_value; |
1095 symbol->const_value = symbol->get_element(symbol->n-1)->const_value; |
1096 return NULL; |
1096 return NULL; |
1097 } |
1097 } |
1098 |
1098 |
1099 |
1099 |
1100 |
1100 |
1365 void *constant_propagation_c::visit(library_c *symbol) { |
1365 void *constant_propagation_c::visit(library_c *symbol) { |
1366 int i; |
1366 int i; |
1367 |
1367 |
1368 for (i = 0; i < symbol->n; i++) { |
1368 for (i = 0; i < symbol->n; i++) { |
1369 // first analyse the configurations |
1369 // first analyse the configurations |
1370 if (NULL != dynamic_cast<configuration_declaration_c *>(symbol->elements[i])) |
1370 if (NULL != dynamic_cast<configuration_declaration_c *>(symbol->get_element(i))) |
1371 symbol->elements[i]->accept(*this); |
1371 symbol->get_element(i)->accept(*this); |
1372 } |
1372 } |
1373 |
1373 |
1374 for (i = 0; i < symbol->n; i++) { |
1374 for (i = 0; i < symbol->n; i++) { |
1375 /* NOTE: we will be re-visiting all the POUs that were already called indirectly through the |
1375 /* NOTE: we will be re-visiting all the POUs that were already called indirectly through the |
1376 * visit(program_configuration_c) of vist(fb_task_c) visitors during the previous for |
1376 * visit(program_configuration_c) of vist(fb_task_c) visitors during the previous for |
1377 * loop. However, this is OK as the only difference would be how the VAR_EXTERN are handled, |
1377 * loop. However, this is OK as the only difference would be how the VAR_EXTERN are handled, |
1378 * and that is taken care of in the visit(external_declaration_c) visitor! |
1378 * and that is taken care of in the visit(external_declaration_c) visitor! |
1379 */ |
1379 */ |
1380 if (NULL == dynamic_cast<configuration_declaration_c *>(symbol->elements[i])) |
1380 if (NULL == dynamic_cast<configuration_declaration_c *>(symbol->get_element(i))) |
1381 symbol->elements[i]->accept(*this); |
1381 symbol->get_element(i)->accept(*this); |
1382 } |
1382 } |
1383 |
1383 |
1384 return NULL; |
1384 return NULL; |
1385 } |
1385 } |
1386 |
1386 |
1463 init_value->accept(*this); // necessary when handling default initial values, that were not constant folded in the call type_decl->accept(*this) |
1463 init_value->accept(*this); // necessary when handling default initial values, that were not constant folded in the call type_decl->accept(*this) |
1464 |
1464 |
1465 list_c *list = dynamic_cast<list_c *>(var_list); |
1465 list_c *list = dynamic_cast<list_c *>(var_list); |
1466 if (NULL == list) ERROR; |
1466 if (NULL == list) ERROR; |
1467 for (int i = 0; i < list->n; i++) { |
1467 for (int i = 0; i < list->n; i++) { |
1468 token_c *var_name = dynamic_cast<token_c *>(list->elements[i]); |
1468 token_c *var_name = dynamic_cast<token_c *>(list->get_element(i)); |
1469 if (NULL == var_name) { |
1469 if (NULL == var_name) { |
1470 if (NULL != dynamic_cast<extensible_input_parameter_c *>(list->elements[i])) |
1470 if (NULL != dynamic_cast<extensible_input_parameter_c *>(list->get_element(i))) |
1471 continue; // this is an extensible standard function. Ignore this variable, and continue! |
1471 continue; // this is an extensible standard function. Ignore this variable, and continue! |
1472 // debug_c::print(list->elements[i]); |
1472 // debug_c::print(list->get_element(i)); |
1473 ERROR; |
1473 ERROR; |
1474 } |
1474 } |
1475 list->elements[i]->const_value = init_value->const_value; |
1475 list->get_element(i)->const_value = init_value->const_value; |
1476 if (fixed_init_value_) { |
1476 if (fixed_init_value_) { |
1477 (*values)[var_name->value] = init_value->const_value; |
1477 (*values)[var_name->value] = init_value->const_value; |
1478 if (is_global_var) |
1478 if (is_global_var) |
1479 // also store it in the var_global_values map!! |
1479 // also store it in the var_global_values map!! |
1480 // Notice that global variables are also placed in the values map!! |
1480 // Notice that global variables are also placed in the values map!! |