equal
deleted
inserted
replaced
124 |
124 |
125 |
125 |
126 |
126 |
127 |
127 |
128 |
128 |
129 class generate_c_il_c: public generate_c_typedecl_c, il_default_variable_visitor_c { |
129 class generate_c_il_c: public generate_c_base_c, il_default_variable_visitor_c { |
130 |
130 |
131 public: |
131 public: |
132 typedef enum { |
132 typedef enum { |
133 expression_vg, |
133 expression_vg, |
134 assignment_vg, |
134 assignment_vg, |
195 |
195 |
196 variablegeneration_t wanted_variablegeneration; |
196 variablegeneration_t wanted_variablegeneration; |
197 |
197 |
198 public: |
198 public: |
199 generate_c_il_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
199 generate_c_il_c(stage4out_c *s4o_ptr, symbol_c *name, symbol_c *scope, const char *variable_prefix = NULL) |
200 : generate_c_typedecl_c(s4o_ptr), |
200 : generate_c_base_c(s4o_ptr), |
201 implicit_variable_current (IL_DEFVAR, NULL), |
201 implicit_variable_current (IL_DEFVAR, NULL), |
202 implicit_variable_result (IL_DEFVAR, NULL), |
202 implicit_variable_result (IL_DEFVAR, NULL), |
203 implicit_variable_result_back(IL_DEFVAR_BACK, NULL) |
203 implicit_variable_result_back(IL_DEFVAR_BACK, NULL) |
204 { |
204 { |
205 search_fb_instance_decl = new search_fb_instance_decl_c (scope); |
205 search_fb_instance_decl = new search_fb_instance_decl_c (scope); |
365 |
365 |
366 void *print_getter(symbol_c *symbol) { |
366 void *print_getter(symbol_c *symbol) { |
367 unsigned int vartype = search_var_instance_decl->get_vartype(symbol); |
367 unsigned int vartype = search_var_instance_decl->get_vartype(symbol); |
368 if (wanted_variablegeneration == fparam_output_vg) { |
368 if (wanted_variablegeneration == fparam_output_vg) { |
369 if (vartype == search_var_instance_decl_c::external_vt) { |
369 if (vartype == search_var_instance_decl_c::external_vt) { |
370 if (search_var_instance_decl->type_is_fb(symbol)) |
370 if (!get_datatype_info_c::is_type_valid (symbol->datatype)) ERROR; |
|
371 if ( get_datatype_info_c::is_function_block(symbol->datatype)) |
371 s4o.print(GET_EXTERNAL_FB_BY_REF); |
372 s4o.print(GET_EXTERNAL_FB_BY_REF); |
372 else |
373 else |
373 s4o.print(GET_EXTERNAL_BY_REF); |
374 s4o.print(GET_EXTERNAL_BY_REF); |
374 } |
375 } |
375 else if (vartype == search_var_instance_decl_c::located_vt) |
376 else if (vartype == search_var_instance_decl_c::located_vt) |
377 else |
378 else |
378 s4o.print(GET_VAR_BY_REF); |
379 s4o.print(GET_VAR_BY_REF); |
379 } |
380 } |
380 else { |
381 else { |
381 if (vartype == search_var_instance_decl_c::external_vt) { |
382 if (vartype == search_var_instance_decl_c::external_vt) { |
382 if (search_var_instance_decl->type_is_fb(symbol)) |
383 if (!get_datatype_info_c::is_type_valid (symbol->datatype)) ERROR; |
|
384 if ( get_datatype_info_c::is_function_block(symbol->datatype)) |
383 s4o.print(GET_EXTERNAL_FB); |
385 s4o.print(GET_EXTERNAL_FB); |
384 else |
386 else |
385 s4o.print(GET_EXTERNAL); |
387 s4o.print(GET_EXTERNAL); |
386 } |
388 } |
387 else if (vartype == search_var_instance_decl_c::located_vt) |
389 else if (vartype == search_var_instance_decl_c::located_vt) |
392 s4o.print("("); |
394 s4o.print("("); |
393 |
395 |
394 variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration; |
396 variablegeneration_t old_wanted_variablegeneration = wanted_variablegeneration; |
395 wanted_variablegeneration = complextype_base_vg; |
397 wanted_variablegeneration = complextype_base_vg; |
396 symbol->accept(*this); |
398 symbol->accept(*this); |
397 if (search_var_instance_decl->type_is_complex(symbol)) |
399 s4o.print(","); |
398 s4o.print(","); |
|
399 wanted_variablegeneration = complextype_suffix_vg; |
400 wanted_variablegeneration = complextype_suffix_vg; |
400 symbol->accept(*this); |
401 symbol->accept(*this); |
401 s4o.print(")"); |
402 s4o.print(")"); |
402 wanted_variablegeneration = old_wanted_variablegeneration; |
403 wanted_variablegeneration = old_wanted_variablegeneration; |
403 return NULL; |
404 return NULL; |
408 symbol_c* value, |
409 symbol_c* value, |
409 symbol_c* fb_symbol = NULL, |
410 symbol_c* fb_symbol = NULL, |
410 symbol_c* fb_value = NULL, |
411 symbol_c* fb_value = NULL, |
411 bool negative = false) { |
412 bool negative = false) { |
412 |
413 |
413 bool type_is_complex = search_var_instance_decl->type_is_complex(symbol); |
414 bool type_is_complex = false; |
414 if (fb_symbol == NULL) { |
415 if (fb_symbol == NULL) { |
415 unsigned int vartype = search_var_instance_decl->get_vartype(symbol); |
416 unsigned int vartype = search_var_instance_decl->get_vartype(symbol); |
|
417 type_is_complex = analyse_variable_c::contains_complex_type(symbol); |
416 if (vartype == search_var_instance_decl_c::external_vt) { |
418 if (vartype == search_var_instance_decl_c::external_vt) { |
417 if (search_var_instance_decl->type_is_fb(symbol)) |
419 if (!get_datatype_info_c::is_type_valid (symbol->datatype)) ERROR; |
|
420 if ( get_datatype_info_c::is_function_block(symbol->datatype)) |
418 s4o.print(SET_EXTERNAL_FB); |
421 s4o.print(SET_EXTERNAL_FB); |
419 else |
422 else |
420 s4o.print(SET_EXTERNAL); |
423 s4o.print(SET_EXTERNAL); |
421 } |
424 } |
422 else if (vartype == search_var_instance_decl_c::located_vt) |
425 else if (vartype == search_var_instance_decl_c::located_vt) |
444 wanted_variablegeneration = assignment_vg; |
447 wanted_variablegeneration = assignment_vg; |
445 |
448 |
446 symbol->accept(*this); |
449 symbol->accept(*this); |
447 s4o.print(","); |
450 s4o.print(","); |
448 if (negative) { |
451 if (negative) { |
449 if (get_datatype_info_c::is_BOOL_compatible(this->current_operand->datatype)) |
452 if (get_datatype_info_c::is_BOOL_compatible(this->current_operand->datatype)) |
450 s4o.print("!"); |
453 s4o.print("!"); |
451 else |
454 else |
452 s4o.print("~"); |
455 s4o.print("~"); |
453 } |
456 } |
454 wanted_variablegeneration = expression_vg; |
457 wanted_variablegeneration = expression_vg; |
570 /*************************************/ |
573 /*************************************/ |
571 |
574 |
572 // SYM_REF2(structured_variable_c, record_variable, field_selector) |
575 // SYM_REF2(structured_variable_c, record_variable, field_selector) |
573 void *visit(structured_variable_c *symbol) { |
576 void *visit(structured_variable_c *symbol) { |
574 TRACE("structured_variable_c"); |
577 TRACE("structured_variable_c"); |
575 bool type_is_complex = search_var_instance_decl->type_is_complex(symbol->record_variable); |
578 bool type_is_complex = analyse_variable_c::is_complex_type(symbol->record_variable); |
576 switch (wanted_variablegeneration) { |
579 switch (wanted_variablegeneration) { |
577 case complextype_base_vg: |
580 case complextype_base_vg: |
578 case complextype_base_assignment_vg: |
581 case complextype_base_assignment_vg: |
579 symbol->record_variable->accept(*this); |
582 symbol->record_variable->accept(*this); |
580 if (!type_is_complex) { |
583 if (!type_is_complex) { |
836 * have reached the end, and should simply jump out of the for loop. |
839 * have reached the end, and should simply jump out of the for loop. |
837 */ |
840 */ |
838 if ((param_value == NULL) && (fp_iterator.is_extensible_param())) { |
841 if ((param_value == NULL) && (fp_iterator.is_extensible_param())) { |
839 break; |
842 break; |
840 } |
843 } |
|
844 |
|
845 /* We do not yet support embedded IL lists, so we abort the compiler if we find one */ |
|
846 /* Note that in IL function calls the syntax does not allow embeded IL lists, so this check is not necessary here! */ |
|
847 /* |
|
848 {simple_instr_list_c *instruction_list = dynamic_cast<simple_instr_list_c *>(param_value); |
|
849 if (NULL != instruction_list) STAGE4_ERROR(param_value, param_value, "The compiler does not yet support formal invocations in IL that contain embedded IL lists. Aborting!"); |
|
850 } |
|
851 */ |
841 |
852 |
842 if ((param_value == NULL) && (param_direction == function_param_iterator_c::direction_in)) { |
853 if ((param_value == NULL) && (param_direction == function_param_iterator_c::direction_in)) { |
843 /* No value given for parameter, so we must use the default... */ |
854 /* No value given for parameter, so we must use the default... */ |
844 /* First check whether default value specified in function declaration...*/ |
855 /* First check whether default value specified in function declaration...*/ |
845 param_value = fp_iterator.default_value(); |
856 param_value = fp_iterator.default_value(); |
1058 * were implicitly defined! |
1069 * were implicitly defined! |
1059 */ |
1070 */ |
1060 if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) |
1071 if ((param_value == NULL) && !fp_iterator.is_en_eno_param_implicit()) |
1061 param_value = function_call_param_iterator.next_nf(); |
1072 param_value = function_call_param_iterator.next_nf(); |
1062 |
1073 |
|
1074 /* We do not yet support embedded IL lists, so we abort the compiler if we find one */ |
|
1075 {simple_instr_list_c *instruction_list = dynamic_cast<simple_instr_list_c *>(param_value); |
|
1076 if (NULL != instruction_list) STAGE4_ERROR(param_value, param_value, "The compiler does not yet support formal invocations in IL that contain embedded IL lists. Aborting!"); |
|
1077 } |
|
1078 |
1063 symbol_c *param_type = fp_iterator.param_type(); |
1079 symbol_c *param_type = fp_iterator.param_type(); |
1064 if (param_type == NULL) ERROR; |
1080 if (param_type == NULL) ERROR; |
1065 |
1081 |
1066 /* now output the value assignment */ |
1082 /* now output the value assignment */ |
1067 if (param_value != NULL) |
1083 if (param_value != NULL) |
1224 * of the function declaration is an extensible parameter, we |
1240 * of the function declaration is an extensible parameter, we |
1225 * have reached the end, and should simply jump out of the for loop. |
1241 * have reached the end, and should simply jump out of the for loop. |
1226 */ |
1242 */ |
1227 if ((param_value == NULL) && (fp_iterator.is_extensible_param())) { |
1243 if ((param_value == NULL) && (fp_iterator.is_extensible_param())) { |
1228 break; |
1244 break; |
|
1245 } |
|
1246 |
|
1247 /* We do not yet support embedded IL lists, so we abort the compiler if we find one */ |
|
1248 {simple_instr_list_c *instruction_list = dynamic_cast<simple_instr_list_c *>(param_value); |
|
1249 if (NULL != instruction_list) STAGE4_ERROR(param_value, param_value, "The compiler does not yet support formal invocations in IL that contain embedded IL lists. Aborting!"); |
1229 } |
1250 } |
1230 |
1251 |
1231 if ((param_value == NULL) && (param_direction == function_param_iterator_c::direction_in)) { |
1252 if ((param_value == NULL) && (param_direction == function_param_iterator_c::direction_in)) { |
1232 /* No value given for parameter, so we must use the default... */ |
1253 /* No value given for parameter, so we must use the default... */ |
1233 /* First check whether default value specified in function declaration...*/ |
1254 /* First check whether default value specified in function declaration...*/ |
1528 return NULL; |
1549 return NULL; |
1529 } |
1550 } |
1530 |
1551 |
1531 |
1552 |
1532 void *visit(S_operator_c *symbol) { |
1553 void *visit(S_operator_c *symbol) { |
|
1554 /* This operator must implement one of two possible semantics: |
|
1555 * - FB call |
|
1556 * - Set all the bits of an ANY_BIT type variable to 1 |
|
1557 */ |
|
1558 |
|
1559 /* Check whether we must implement the FB call semantics... */ |
|
1560 if (NULL != symbol->called_fb_declaration) |
|
1561 return XXX_CAL_operator( "S", this->current_operand); |
|
1562 |
|
1563 /* Implement the bit setting semantics... */ |
1533 if (wanted_variablegeneration != expression_vg) { |
1564 if (wanted_variablegeneration != expression_vg) { |
1534 s4o.print("LD"); |
1565 s4o.print("LD"); |
1535 return NULL; |
1566 return NULL; |
1536 } |
1567 } |
1537 |
1568 |
1550 return NULL; |
1581 return NULL; |
1551 } |
1582 } |
1552 |
1583 |
1553 |
1584 |
1554 void *visit(R_operator_c *symbol) { |
1585 void *visit(R_operator_c *symbol) { |
|
1586 /* This operator must implement one of two possible semantics: |
|
1587 * - FB call |
|
1588 * - Set all the bits of an ANY_BIT type variable to 0 |
|
1589 */ |
|
1590 |
|
1591 /* Check whether we must implement the FB call semantics... */ |
|
1592 if (NULL != symbol->called_fb_declaration) |
|
1593 return XXX_CAL_operator( "R", this->current_operand); |
|
1594 |
|
1595 /* Implement the bit setting semantics... */ |
1555 if (wanted_variablegeneration != expression_vg) { |
1596 if (wanted_variablegeneration != expression_vg) { |
1556 s4o.print("LD"); |
1597 s4o.print("LD"); |
1557 return NULL; |
1598 return NULL; |
1558 } |
1599 } |
1559 |
1600 |