diff -r f2323f79252e -r 31553c22f318 stage4/generate_c/generate_c_il.cc --- a/stage4/generate_c/generate_c_il.cc Thu Nov 08 18:55:57 2012 +0100 +++ b/stage4/generate_c/generate_c_il.cc Thu Nov 15 22:28:53 2012 +0100 @@ -441,20 +441,28 @@ void *print_getter(symbol_c *symbol) { unsigned int vartype = search_var_instance_decl->get_vartype(symbol); if (wanted_variablegeneration == fparam_output_vg) { - if (vartype == search_var_instance_decl_c::external_vt) - s4o.print(GET_EXTERNAL_BY_REF); + if (vartype == search_var_instance_decl_c::external_vt) { + if (search_var_instance_decl->type_is_fb(symbol)) + s4o.print(GET_EXTERNAL_FB_BY_REF); + else + s4o.print(GET_EXTERNAL_BY_REF); + } else if (vartype == search_var_instance_decl_c::located_vt) s4o.print(GET_LOCATED_BY_REF); else s4o.print(GET_VAR_BY_REF); } else { - if (vartype == search_var_instance_decl_c::external_vt) - s4o.print(GET_EXTERNAL); - else if (vartype == search_var_instance_decl_c::located_vt) - s4o.print(GET_LOCATED); - else - s4o.print(GET_VAR); + if (vartype == search_var_instance_decl_c::external_vt) { + if (search_var_instance_decl->type_is_fb(symbol)) + s4o.print(GET_EXTERNAL_FB); + else + s4o.print(GET_EXTERNAL); + } + else if (vartype == search_var_instance_decl_c::located_vt) + s4o.print(GET_LOCATED); + else + s4o.print(GET_VAR); } s4o.print("("); @@ -471,25 +479,33 @@ } void *print_setter(symbol_c* symbol, - symbol_c* type, - symbol_c* value, - symbol_c* fb_symbol = NULL, - symbol_c* fb_value = NULL, - bool negative = false) { - - bool type_is_complex = false; + symbol_c* type, + symbol_c* value, + symbol_c* fb_symbol = NULL, + symbol_c* fb_value = NULL, + bool negative = false) { + + bool type_is_complex = search_var_instance_decl->type_is_complex(symbol); if (fb_symbol == NULL) { unsigned int vartype = search_var_instance_decl->get_vartype(symbol); - type_is_complex = search_var_instance_decl->type_is_complex(symbol); - if (vartype == search_var_instance_decl_c::external_vt) - s4o.print(SET_EXTERNAL); + if (vartype == search_var_instance_decl_c::external_vt) { + if (search_var_instance_decl->type_is_fb(symbol)) + s4o.print(SET_EXTERNAL_FB); + else + s4o.print(SET_EXTERNAL); + } else if (vartype == search_var_instance_decl_c::located_vt) s4o.print(SET_LOCATED); else s4o.print(SET_VAR); } - else - s4o.print(SET_VAR); + else { + unsigned int vartype = search_var_instance_decl->get_vartype(fb_symbol); + if (vartype == search_var_instance_decl_c::external_vt) + s4o.print(SET_EXTERNAL_FB); + else + s4o.print(SET_VAR); + } s4o.print("("); if (fb_symbol != NULL) { @@ -505,10 +521,10 @@ symbol->accept(*this); s4o.print(","); if (negative) { - if (search_expression_type->is_bool_type(this->current_operand_type)) - s4o.print("!"); - else - s4o.print("~"); + if (search_expression_type->is_bool_type(this->current_operand_type)) + s4o.print("!"); + else + s4o.print("~"); } wanted_variablegeneration = expression_vg; print_check_function(type, value, fb_value); @@ -588,10 +604,10 @@ generate_c_base_c::visit(symbol); break; case complextype_suffix_vg: - break; + break; default: if (this->is_variable_prefix_null()) { - vartype = search_var_instance_decl->get_vartype(symbol); + vartype = search_var_instance_decl->get_vartype(symbol); if (wanted_variablegeneration == fparam_output_vg) { s4o.print("&("); generate_c_base_c::visit(symbol); @@ -618,14 +634,14 @@ if (strlen(symbol->value) == 0) ERROR; if (this->is_variable_prefix_null()) { if (wanted_variablegeneration != fparam_output_vg) - s4o.print("*("); + s4o.print("*("); } else { switch (wanted_variablegeneration) { case expression_vg: - s4o.print(GET_LOCATED); - s4o.print("("); - break; + s4o.print(GET_LOCATED); + s4o.print("("); + break; case fparam_output_vg: s4o.print(GET_LOCATED_BY_REF); s4o.print("("); @@ -637,7 +653,7 @@ this->print_variable_prefix(); s4o.printlocation(symbol->value + 1); if ((this->is_variable_prefix_null() && wanted_variablegeneration != fparam_output_vg) || - wanted_variablegeneration != assignment_vg) + wanted_variablegeneration != assignment_vg) s4o.print(")"); return NULL; } @@ -660,25 +676,25 @@ } break; case complextype_suffix_vg: - symbol->record_variable->accept(*this); - if (type_is_complex) { - s4o.print("."); - symbol->field_selector->accept(*this); - } - break; - case assignment_vg: - symbol->record_variable->accept(*this); - s4o.print("."); - symbol->field_selector->accept(*this); - break; + symbol->record_variable->accept(*this); + if (type_is_complex) { + s4o.print("."); + symbol->field_selector->accept(*this); + } + break; + case assignment_vg: + symbol->record_variable->accept(*this); + s4o.print("."); + symbol->field_selector->accept(*this); + break; default: if (this->is_variable_prefix_null()) { - symbol->record_variable->accept(*this); - s4o.print("."); - symbol->field_selector->accept(*this); + symbol->record_variable->accept(*this); + s4o.print("."); + symbol->field_selector->accept(*this); } else - print_getter(symbol); + print_getter(symbol); break; } return NULL; @@ -716,7 +732,7 @@ current_array_type = NULL; } else - print_getter(symbol); + print_getter(symbol); break; } return NULL; @@ -727,9 +743,9 @@ array_dimension_iterator_c* array_dimension_iterator = new array_dimension_iterator_c(current_array_type); for (int i = 0; i < symbol->n; i++) { symbol_c* dimension = array_dimension_iterator->next(); - if (dimension == NULL) ERROR; - - s4o.print("[("); + if (dimension == NULL) ERROR; + + s4o.print("[("); symbol->elements[i]->accept(*this); s4o.print(") - ("); dimension->accept(*this); @@ -968,7 +984,7 @@ s4o.print(")"); } if (function_type_suffix != NULL) { - function_type_suffix = search_expression_type->default_literal_type(function_type_suffix); + function_type_suffix = search_expression_type->default_literal_type(function_type_suffix); } if (has_output_params) { fcall_number++; @@ -993,7 +1009,7 @@ print_function_parameter_data_types_c overloaded_func_suf(&s4o); f_decl->accept(overloaded_func_suf); } - } + } if (function_type_suffix != NULL) function_type_suffix->accept(*this); } @@ -1169,13 +1185,13 @@ if (param_value != NULL) if ((param_direction == function_param_iterator_c::direction_in) || (param_direction == function_param_iterator_c::direction_inout)) { - if (this->is_variable_prefix_null()) { - symbol->fb_name->accept(*this); + if (this->is_variable_prefix_null()) { + symbol->fb_name->accept(*this); s4o.print("."); param_name->accept(*this); s4o.print(" = "); print_check_function(param_type, param_value); - } + } else { print_setter(param_name, param_type, param_value, symbol->fb_name); } @@ -1186,7 +1202,9 @@ /* now call the function... */ function_block_type_name->accept(*this); s4o.print(FB_FUNCTION_SUFFIX); - s4o.print("(&"); + s4o.print("("); + if (search_var_instance_decl->get_vartype(symbol->fb_name) != search_var_instance_decl_c::external_vt) + s4o.print("&"); print_variable_prefix(); symbol->fb_name->accept(*this); s4o.print(")"); @@ -1217,12 +1235,12 @@ s4o.print(";\n" + s4o.indent_spaces); if (this->is_variable_prefix_null()) { param_value->accept(*this); - s4o.print(" = "); - print_check_function(param_type, param_name, symbol->fb_name); - } - else { - print_setter(param_value, param_type, param_name, NULL, symbol->fb_name); - } + s4o.print(" = "); + print_check_function(param_type, param_name, symbol->fb_name); + } + else { + print_setter(param_value, param_type, param_name, NULL, symbol->fb_name); + } } } /* for(...) */ @@ -1376,7 +1394,7 @@ s4o.print(")"); } if (function_type_suffix != NULL) { - function_type_suffix = search_expression_type->default_literal_type(function_type_suffix); + function_type_suffix = search_expression_type->default_literal_type(function_type_suffix); } if (has_output_params) { fcall_number++; @@ -1574,7 +1592,7 @@ } // SYM_REF1(il_simple_instruction_c, il_simple_instruction, symbol_c *prev_il_instruction;) -void *visit(il_simple_instruction_c *symbol) { +void *visit(il_simple_instruction_c *symbol) { return symbol->il_simple_instruction->accept(*this); } @@ -1597,7 +1615,7 @@ /* B 2.2 Operators */ /*******************/ -void *visit(LD_operator_c *symbol) { +void *visit(LD_operator_c *symbol) { if (wanted_variablegeneration != expression_vg) { s4o.print("LD"); return NULL; @@ -1609,7 +1627,7 @@ return NULL; } -void *visit(LDN_operator_c *symbol) { +void *visit(LDN_operator_c *symbol) { /* the data type resulting from this operation... */ this->default_variable_name.current_type = this->current_operand_type; XXX_operator(&(this->default_variable_name), @@ -1618,10 +1636,10 @@ return NULL; } -void *visit(ST_operator_c *symbol) { +void *visit(ST_operator_c *symbol) { symbol_c *operand_type = search_varfb_instance_type->get_type_id(this->current_operand); if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type) || - search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) + search_expression_type->is_literal_real_type(this->default_variable_name.current_type)) this->default_variable_name.current_type = this->current_operand_type; if (this->is_variable_prefix_null()) { this->current_operand->accept(*this); @@ -1629,16 +1647,16 @@ print_check_function(operand_type, (symbol_c*)&(this->default_variable_name)); } else { - print_setter(this->current_operand, operand_type, (symbol_c*)&(this->default_variable_name)); + print_setter(this->current_operand, operand_type, (symbol_c*)&(this->default_variable_name)); } /* the data type resulting from this operation is unchanged. */ return NULL; } -void *visit(STN_operator_c *symbol) { +void *visit(STN_operator_c *symbol) { symbol_c *operand_type = search_varfb_instance_type->get_type_id(this->current_operand); if (search_expression_type->is_literal_integer_type(this->default_variable_name.current_type)) - this->default_variable_name.current_type = this->current_operand_type; + this->default_variable_name.current_type = this->current_operand_type; if (this->is_variable_prefix_null()) { this->current_operand->accept(*this); @@ -1646,17 +1664,17 @@ if (search_expression_type->is_bool_type(this->current_operand_type)) s4o.print("!"); else - s4o.print("~"); + s4o.print("~"); this->default_variable_name.accept(*this); } else { - print_setter(this->current_operand, operand_type, (symbol_c*)&(this->default_variable_name), NULL, NULL, true); + print_setter(this->current_operand, operand_type, (symbol_c*)&(this->default_variable_name), NULL, NULL, true); } /* the data type resulting from this operation is unchanged. */ return NULL; } -void *visit(NOT_operator_c *symbol) { +void *visit(NOT_operator_c *symbol) { /* NOTE: the standard allows syntax in which the NOT operator is followed by an optional * NOT [] * However, it does not define the semantic of the NOT operation when the is specified. @@ -1671,7 +1689,7 @@ return NULL; } -void *visit(S_operator_c *symbol) { +void *visit(S_operator_c *symbol) { if (wanted_variablegeneration != expression_vg) { s4o.print("LD"); return NULL; @@ -1694,7 +1712,7 @@ return NULL; } -void *visit(R_operator_c *symbol) { +void *visit(R_operator_c *symbol) { if (wanted_variablegeneration != expression_vg) { s4o.print("LD"); return NULL; @@ -1726,11 +1744,11 @@ void *visit(IN_operator_c *symbol) {return XXX_CAL_operator("IN", this->current_operand);} void *visit(PT_operator_c *symbol) {return XXX_CAL_operator("PT", this->current_operand);} -void *visit(AND_operator_c *symbol) { +void *visit(AND_operator_c *symbol) { if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { - BYTE_operator_result_type(); - XXX_operator(&(this->default_variable_name), " &= ", this->current_operand); + BYTE_operator_result_type(); + XXX_operator(&(this->default_variable_name), " &= ", this->current_operand); /* the data type resulting from this operation... */ this->default_variable_name.current_type = this->current_operand_type; } @@ -1738,11 +1756,11 @@ return NULL; } -void *visit(OR_operator_c *symbol) { +void *visit(OR_operator_c *symbol) { if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { - BYTE_operator_result_type(); - XXX_operator(&(this->default_variable_name), " |= ", this->current_operand); + BYTE_operator_result_type(); + XXX_operator(&(this->default_variable_name), " |= ", this->current_operand); /* the data type resulting from this operation... */ this->default_variable_name.current_type = this->current_operand_type; } @@ -1750,11 +1768,11 @@ return NULL; } -void *visit(XOR_operator_c *symbol) { +void *visit(XOR_operator_c *symbol) { if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { - BYTE_operator_result_type(); - // '^' is a bit by bit exclusive OR !! Also seems to work with boolean types! + BYTE_operator_result_type(); + // '^' is a bit by bit exclusive OR !! Also seems to work with boolean types! XXX_operator(&(this->default_variable_name), " ^= ", this->current_operand); /* the data type resulting from this operation... */ this->default_variable_name.current_type = this->current_operand_type; @@ -1763,11 +1781,11 @@ return NULL; } -void *visit(ANDN_operator_c *symbol) { +void *visit(ANDN_operator_c *symbol) { if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { - BYTE_operator_result_type(); - XXX_operator(&(this->default_variable_name), + BYTE_operator_result_type(); + XXX_operator(&(this->default_variable_name), search_expression_type->is_bool_type(this->current_operand_type)?" &= !":" &= ~", this->current_operand); /* the data type resulting from this operation... */ @@ -1777,11 +1795,11 @@ return NULL; } -void *visit(ORN_operator_c *symbol) { +void *visit(ORN_operator_c *symbol) { if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { - BYTE_operator_result_type(); - XXX_operator(&(this->default_variable_name), + BYTE_operator_result_type(); + XXX_operator(&(this->default_variable_name), search_expression_type->is_bool_type(this->current_operand_type)?" |= !":" |= ~", this->current_operand); /* the data type resulting from this operation... */ @@ -1791,11 +1809,11 @@ return NULL; } -void *visit(XORN_operator_c *symbol) { +void *visit(XORN_operator_c *symbol) { if (search_expression_type->is_binary_type(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { - BYTE_operator_result_type(); - XXX_operator(&(this->default_variable_name), + BYTE_operator_result_type(); + XXX_operator(&(this->default_variable_name), // bit by bit exclusive OR !! Also seems to work with boolean types! search_expression_type->is_bool_type(this->current_operand_type)?" ^= !":" ^= ~", this->current_operand); @@ -1806,7 +1824,7 @@ return NULL; } -void *visit(ADD_operator_c *symbol) { +void *visit(ADD_operator_c *symbol) { if (search_expression_type->is_time_type(this->default_variable_name.current_type) && search_expression_type->is_time_type(this->current_operand_type)) { XXX_function("__time_add", &(this->default_variable_name), this->current_operand); @@ -1815,8 +1833,8 @@ } else if (search_expression_type->is_num_type(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { - NUM_operator_result_type(); - XXX_operator(&(this->default_variable_name), " += ", this->current_operand); + NUM_operator_result_type(); + XXX_operator(&(this->default_variable_name), " += ", this->current_operand); /* the data type resulting from this operation... */ this->default_variable_name.current_type = this->current_operand_type; } @@ -1824,7 +1842,7 @@ return NULL; } -void *visit(SUB_operator_c *symbol) { +void *visit(SUB_operator_c *symbol) { if (search_expression_type->is_time_type(this->default_variable_name.current_type) && search_expression_type->is_time_type(this->current_operand_type)) { XXX_function("__time_sub", &(this->default_variable_name), this->current_operand); @@ -1833,8 +1851,8 @@ } else if (search_expression_type->is_num_type(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { - NUM_operator_result_type(); - XXX_operator(&(this->default_variable_name), " -= ", this->current_operand); + NUM_operator_result_type(); + XXX_operator(&(this->default_variable_name), " -= ", this->current_operand); /* the data type resulting from this operation... */ this->default_variable_name.current_type = this->current_operand_type; } @@ -1842,7 +1860,7 @@ return NULL; } -void *visit(MUL_operator_c *symbol) { +void *visit(MUL_operator_c *symbol) { if (search_expression_type->is_time_type(this->default_variable_name.current_type) && search_expression_type->is_integer_type(this->current_operand_type)) { XXX_function("__time_mul", &(this->default_variable_name), this->current_operand); @@ -1850,7 +1868,7 @@ } else if (search_expression_type->is_num_type(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { - NUM_operator_result_type(); + NUM_operator_result_type(); XXX_operator(&(this->default_variable_name), " *= ", this->current_operand); /* the data type resulting from this operation... */ this->default_variable_name.current_type = this->current_operand_type; @@ -1859,7 +1877,7 @@ return NULL; } -void *visit(DIV_operator_c *symbol) { +void *visit(DIV_operator_c *symbol) { if (search_expression_type->is_time_type(this->default_variable_name.current_type) && search_expression_type->is_integer_type(this->current_operand_type)) { XXX_function("__time_div", &(this->default_variable_name), this->current_operand); @@ -1867,8 +1885,8 @@ } else if (search_expression_type->is_num_type(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { - NUM_operator_result_type(); - XXX_operator(&(this->default_variable_name), " /= ", this->current_operand); + NUM_operator_result_type(); + XXX_operator(&(this->default_variable_name), " /= ", this->current_operand); /* the data type resulting from this operation... */ this->default_variable_name.current_type = this->current_operand_type; return NULL; @@ -1877,11 +1895,11 @@ return NULL; } -void *visit(MOD_operator_c *symbol) { +void *visit(MOD_operator_c *symbol) { if (search_expression_type->is_num_type(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { - NUM_operator_result_type(); - XXX_operator(&(this->default_variable_name), " %= ", this->current_operand); + NUM_operator_result_type(); + XXX_operator(&(this->default_variable_name), " %= ", this->current_operand); /* the data type resulting from this operation... */ this->default_variable_name.current_type = this->current_operand_type; } @@ -1889,7 +1907,7 @@ return NULL; } -void *visit(GT_operator_c *symbol) { +void *visit(GT_operator_c *symbol) { if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { CMP_operator(this->current_operand, "GT_"); @@ -1899,7 +1917,7 @@ return NULL; } -void *visit(GE_operator_c *symbol) { +void *visit(GE_operator_c *symbol) { if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { CMP_operator(this->current_operand, "GE_"); @@ -1909,7 +1927,7 @@ return NULL; } -void *visit(EQ_operator_c *symbol) { +void *visit(EQ_operator_c *symbol) { if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { CMP_operator(this->current_operand, "EQ_"); } else { @@ -1918,7 +1936,7 @@ return NULL; } -void *visit(LT_operator_c *symbol) { +void *visit(LT_operator_c *symbol) { if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { CMP_operator(this->current_operand, "LT_"); @@ -1928,7 +1946,7 @@ return NULL; } -void *visit(LE_operator_c *symbol) { +void *visit(LE_operator_c *symbol) { if (!search_base_type.type_is_enumerated(this->default_variable_name.current_type) && search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { CMP_operator(this->current_operand, "LE_"); @@ -1938,7 +1956,7 @@ return NULL; } -void *visit(NE_operator_c *symbol) { +void *visit(NE_operator_c *symbol) { if (search_expression_type->is_same_type(this->default_variable_name.current_type, this->current_operand_type)) { CMP_operator(this->current_operand, "NE_"); } else { @@ -1992,7 +2010,7 @@ } //SYM_REF0(JMP_operator_c) -void *visit(JMP_operator_c *symbol) { +void *visit(JMP_operator_c *symbol) { if (NULL == this->jump_label) ERROR; s4o.print("goto "); @@ -2002,7 +2020,7 @@ } // SYM_REF0(JMPC_operator_c) -void *visit(JMPC_operator_c *symbol) { +void *visit(JMPC_operator_c *symbol) { if (NULL == this->jump_label) ERROR; C_modifier(); @@ -2013,7 +2031,7 @@ } // SYM_REF0(JMPCN_operator_c) -void *visit(JMPCN_operator_c *symbol) { +void *visit(JMPCN_operator_c *symbol) { if (NULL == this->jump_label) ERROR; CN_modifier();