stage4/generate_c/generate_c.cc
changeset 392 9b88b8b6bccd
parent 381 2fd934b91ffd
child 396 155560bfe837
equal deleted inserted replaced
391:4798bd4739d0 392:9b88b8b6bccd
   122 #define GET_LOCATED_BY_REF "__GET_LOCATED_BY_REF"
   122 #define GET_LOCATED_BY_REF "__GET_LOCATED_BY_REF"
   123 
   123 
   124 /* Variable setter symbol for accessor macros */
   124 /* Variable setter symbol for accessor macros */
   125 #define SET_VAR "__SET_VAR"
   125 #define SET_VAR "__SET_VAR"
   126 #define SET_EXTERNAL "__SET_EXTERNAL"
   126 #define SET_EXTERNAL "__SET_EXTERNAL"
   127 #define SET_COMPLEX_EXTERNAL "__SET_COMPLEX_EXTERNAL"
       
   128 #define SET_LOCATED "__SET_LOCATED"
   127 #define SET_LOCATED "__SET_LOCATED"
   129 
   128 
   130 
   129 
   131 /* Generate a name for a temporary variable.
   130 /* Generate a name for a temporary variable.
   132  * Each new name generated is appended a different number,
   131  * Each new name generated is appended a different number,
  1332   s4o.indent_right();
  1331   s4o.indent_right();
  1333   s4o.print(s4o.indent_spaces);
  1332   s4o.print(s4o.indent_spaces);
  1334   s4o.print(SET_VAR);
  1333   s4o.print(SET_VAR);
  1335   s4o.print("(");
  1334   s4o.print("(");
  1336   s4o.print(FB_FUNCTION_PARAM);
  1335   s4o.print(FB_FUNCTION_PARAM);
  1337   s4o.print("->ENO,__BOOL_LITERAL(FALSE));\n");
  1336   s4o.print("->,ENO,__BOOL_LITERAL(FALSE));\n");
  1338   s4o.print(s4o.indent_spaces + "return;\n");
  1337   s4o.print(s4o.indent_spaces + "return;\n");
  1339   s4o.indent_left();
  1338   s4o.indent_left();
  1340   s4o.print(s4o.indent_spaces + "}\n");
  1339   s4o.print(s4o.indent_spaces + "}\n");
  1341   s4o.print(s4o.indent_spaces + "else {\n");
  1340   s4o.print(s4o.indent_spaces + "else {\n");
  1342   s4o.indent_right();
  1341   s4o.indent_right();
  1343   s4o.print(s4o.indent_spaces);
  1342   s4o.print(s4o.indent_spaces);
  1344   s4o.print(SET_VAR);
  1343   s4o.print(SET_VAR);
  1345   s4o.print("(");
  1344   s4o.print("(");
  1346   s4o.print(FB_FUNCTION_PARAM);
  1345   s4o.print(FB_FUNCTION_PARAM);
  1347   s4o.print("->ENO,__BOOL_LITERAL(TRUE));\n");
  1346   s4o.print("->,ENO,__BOOL_LITERAL(TRUE));\n");
  1348   s4o.indent_left();
  1347   s4o.indent_left();
  1349   s4o.print(s4o.indent_spaces + "}\n");
  1348   s4o.print(s4o.indent_spaces + "}\n");
  1350 
  1349 
  1351   /* (C.4) Initialize TEMP variables */
  1350   /* (C.4) Initialize TEMP variables */
  1352   /* function body */
  1351   /* function body */
  1619   s4o.print("\n");
  1618   s4o.print("\n");
  1620   
  1619   
  1621   /* (A.2) Global variables */
  1620   /* (A.2) Global variables */
  1622   vardecl = new generate_c_vardecl_c(&s4o,
  1621   vardecl = new generate_c_vardecl_c(&s4o,
  1623                                      generate_c_vardecl_c::local_vf,
  1622                                      generate_c_vardecl_c::local_vf,
  1624                                      generate_c_vardecl_c::global_vt);
  1623                                      generate_c_vardecl_c::global_vt,
       
  1624                                      symbol->configuration_name);
  1625   vardecl->print(symbol);
  1625   vardecl->print(symbol);
  1626   delete vardecl;
  1626   delete vardecl;
  1627   s4o.print("\n");
  1627   s4o.print("\n");
  1628 
  1628 
  1629   /* (B) Initialisation Function */
  1629   /* (B) Initialisation Function */
  1892       s4o.print("\n\n");
  1892       s4o.print("\n\n");
  1893       
  1893       
  1894       s4o.print("extern unsigned long long common_ticktime__;\n\n");
  1894       s4o.print("extern unsigned long long common_ticktime__;\n\n");
  1895 
  1895 
  1896       s4o.print("#include \"accessor.h\"\n\n");
  1896       s4o.print("#include \"accessor.h\"\n\n");
       
  1897       s4o.print("#include \"POUS.h\"\n\n");
  1897 
  1898 
  1898       /* (A.2) Global variables... */
  1899       /* (A.2) Global variables... */
  1899       if (current_global_vars != NULL) {
  1900       if (current_global_vars != NULL) {
  1900         vardecl = new generate_c_vardecl_c(&s4o,
  1901         vardecl = new generate_c_vardecl_c(&s4o,
  1901                                            generate_c_vardecl_c::local_vf,
  1902                                            generate_c_vardecl_c::local_vf,
  1905         delete vardecl;
  1906         delete vardecl;
  1906         s4o.print("\n");
  1907         s4o.print("\n");
  1907       }
  1908       }
  1908       
  1909       
  1909       /* (A.3) POUs inclusion */
  1910       /* (A.3) POUs inclusion */
  1910       s4o.print("#include \"POUS.h\"\n\n");
       
  1911       s4o.print("#include \"POUS.c\"\n\n");
  1911       s4o.print("#include \"POUS.c\"\n\n");
  1912       
  1912       
  1913       wanted_declaretype = declare_dt;
  1913       wanted_declaretype = declare_dt;
  1914       
  1914       
  1915       /* (A.4) Resource programs declaration... */
  1915       /* (A.4) Resource programs declaration... */
  2096           break;
  2096           break;
  2097         case run_dt:
  2097         case run_dt:
  2098           if (symbol->single_data_source != NULL) {
  2098           if (symbol->single_data_source != NULL) {
  2099             symbol_c *config_var_decl = NULL;
  2099             symbol_c *config_var_decl = NULL;
  2100             symbol_c *res_var_decl = NULL;
  2100             symbol_c *res_var_decl = NULL;
  2101             unsigned int vartype;
  2101             s4o.print(s4o.indent_spaces + "{");
  2102             symbol_c *current_var_reference = ((global_var_reference_c *)(symbol->single_data_source))->global_var_name;
  2102             symbol_c *current_var_reference = ((global_var_reference_c *)(symbol->single_data_source))->global_var_name;
  2103             res_var_decl = search_resource_instance->get_decl(current_var_reference);
  2103             res_var_decl = search_resource_instance->get_decl(current_var_reference);
  2104             if (res_var_decl == NULL) {
  2104             if (res_var_decl == NULL) {
  2105               config_var_decl = search_config_instance->get_decl(current_var_reference);
  2105               config_var_decl = search_config_instance->get_decl(current_var_reference);
  2106               if (config_var_decl == NULL)
  2106               if (config_var_decl == NULL)
  2107                 ERROR;
  2107                 ERROR;
  2108               vartype = search_config_instance->get_vartype();
       
  2109               s4o.print(s4o.indent_spaces + "{extern ");
       
  2110               config_var_decl->accept(*this);
  2108               config_var_decl->accept(*this);
  2111               s4o.print(" *");
       
  2112               symbol->single_data_source->accept(*this);
       
  2113               s4o.print("; ");
       
  2114             }
  2109             }
  2115             else {
  2110             else {
  2116               vartype = search_resource_instance->get_vartype();
  2111               res_var_decl->accept(*this);
  2117               s4o.print(s4o.indent_spaces);
       
  2118             }
  2112             }
       
  2113             s4o.print("* ");
       
  2114             symbol->single_data_source->accept(*this);
       
  2115             s4o.print(" = __GET_GLOBAL_");
       
  2116             symbol->single_data_source->accept(*this);
       
  2117             s4o.print("();");
  2119             s4o.print(SET_VAR);
  2118             s4o.print(SET_VAR);
  2120             s4o.print("(");
  2119             s4o.print("(");
  2121             current_task_name->accept(*this);
  2120             current_task_name->accept(*this);
  2122             s4o.print("_R_TRIG.CLK, *__GET_GLOBAL_");
  2121             s4o.print("_R_TRIG.,CLK, *");
  2123             symbol->single_data_source->accept(*this);
  2122             symbol->single_data_source->accept(*this);
  2124             s4o.print("());");
  2123             s4o.print(");}\n");
  2125             if (config_var_decl != NULL)
       
  2126               s4o.print("}");
       
  2127             s4o.print("\n");
       
  2128             s4o.print(s4o.indent_spaces + "R_TRIG");
  2124             s4o.print(s4o.indent_spaces + "R_TRIG");
  2129             s4o.print(FB_FUNCTION_SUFFIX);
  2125             s4o.print(FB_FUNCTION_SUFFIX);
  2130             s4o.print("(&");
  2126             s4o.print("(&");
  2131             current_task_name->accept(*this);
  2127             current_task_name->accept(*this);
  2132             s4o.print("_R_TRIG);\n");
  2128             s4o.print("_R_TRIG);\n");