stage4/generate_cc/generate_cc.cc
changeset 18 e6af5eb5f546
parent 17 38754701ac41
child 23 d5b55ac4efe6
equal deleted inserted replaced
17:38754701ac41 18:e6af5eb5f546
   145  */
   145  */
   146 
   146 
   147 #define FB_FUNCTION_SUFFIX "_body__"
   147 #define FB_FUNCTION_SUFFIX "_body__"
   148 
   148 
   149 /* The FB body function is passed as the only parameter a pointer to the FB data
   149 /* The FB body function is passed as the only parameter a pointer to the FB data
   150  * structure instance. The name of this parameter is given by the following cosntant.
   150  * structure instance. The name of this parameter is given by the following constant.
   151  * In order not to clash with any variable in the IL and ST source codem the
   151  * In order not to clash with any variable in the IL and ST source codem the
   152  * following constant should contain a double underscore, which is not allowed
   152  * following constant should contain a double underscore, which is not allowed
   153  * in IL and ST.
   153  * in IL and ST.
   154  *
   154  *
   155  * e.g.: the body of FUNTION_BLOCK TEST
   155  * e.g.: the body of FUNTION_BLOCK TEST
   156  * is mapped onto the C function
   156  * is mapped onto the C function
   157  *  TEST_body__(TEST *data__)
   157  *  TEST_body__(TEST *data__)
   158  */
   158  */
   159 
   159 
   160 #define FB_FUNCTION_PARAM "data__"
   160 #define FB_FUNCTION_PARAM "data__"
       
   161 
       
   162 
       
   163 #define SFC_STEP_ACTION_PREFIX "__SFC_"
   161 
   164 
   162 
   165 
   163 /***********************************************************************/
   166 /***********************************************************************/
   164 /***********************************************************************/
   167 /***********************************************************************/
   165 /***********************************************************************/
   168 /***********************************************************************/
   519   s4o.print("\n");
   522   s4o.print("\n");
   520   /* (A.3) Private internal variables */
   523   /* (A.3) Private internal variables */
   521   s4o.print(s4o.indent_spaces + "// FB private variables - TEMP, private and located variables\n");
   524   s4o.print(s4o.indent_spaces + "// FB private variables - TEMP, private and located variables\n");
   522   vardecl = new generate_cc_vardecl_c(&s4o,
   525   vardecl = new generate_cc_vardecl_c(&s4o,
   523   				      generate_cc_vardecl_c::local_vf,
   526   				      generate_cc_vardecl_c::local_vf,
   524 				      generate_cc_vardecl_c::temp_vt |
   527 				        generate_cc_vardecl_c::temp_vt |
   525   				      generate_cc_vardecl_c::private_vt |
   528   				      generate_cc_vardecl_c::private_vt |
   526   				      generate_cc_vardecl_c::located_vt);
   529   				      generate_cc_vardecl_c::located_vt);
   527   vardecl->print(symbol->var_declarations);
   530   vardecl->print(symbol->var_declarations);
   528   delete vardecl;
   531   delete vardecl;
   529   s4o.print("\n");
   532   s4o.print("\n");
   625                 generate_cc_vardecl_c::private_vt |
   628                 generate_cc_vardecl_c::private_vt |
   626                 generate_cc_vardecl_c::located_vt |
   629                 generate_cc_vardecl_c::located_vt |
   627                 generate_cc_vardecl_c::external_vt);
   630                 generate_cc_vardecl_c::external_vt);
   628   vardecl->print(symbol->var_declarations);
   631   vardecl->print(symbol->var_declarations);
   629   delete vardecl;
   632   delete vardecl;
       
   633   /* (A.4) Generate private internal variables for SFC */
       
   634   generate_cc_sfctables_c generate_cc_sfctables(&s4o);
       
   635   symbol->function_block_body->accept(generate_cc_sfctables);
   630   s4o.print("\n");
   636   s4o.print("\n");
   631 
       
   632   /* (A.4) Generate private internal variables for SFC*/
       
   633   generate_cc_sfcdecl_c generate_cc_sfcdecl(&s4o);
       
   634   symbol->function_block_body->accept(generate_cc_sfcdecl);
       
   635 
   637 
   636   /* (A.5) Program data structure type name. */
   638   /* (A.5) Program data structure type name. */
   637   s4o.indent_left();
   639   s4o.indent_left();
   638   s4o.print("} ");
   640   s4o.print("} ");
   639   symbol->program_type_name->accept(*this);
   641   symbol->program_type_name->accept(*this);
   640   s4o.print(";\n\n");
   642   s4o.print(";\n\n");
   641 
   643 
   642   /* (B) Function with PROGRAM body */
   644   /* (B) Function with PROGRAM body */
   643   /* (B.1) Function declaration */
   645   /* (B.1) Step and Action definitions */
       
   646   generate_cc_sfcdecl_c generate_cc_sfcdecl(&s4o);
       
   647   symbol->function_block_body->accept(generate_cc_sfcdecl);
       
   648 
       
   649   /* (B.2) Function declaration */
   644   s4o.print("// Code part\n");
   650   s4o.print("// Code part\n");
   645   /* function interface */
   651   /* function interface */
   646   s4o.print("void ");
   652   s4o.print("void ");
   647   symbol->program_type_name->accept(*this);
   653   symbol->program_type_name->accept(*this);
   648   s4o.print(FB_FUNCTION_SUFFIX);
   654   s4o.print(FB_FUNCTION_SUFFIX);
   652   s4o.print(" *");
   658   s4o.print(" *");
   653   s4o.print(FB_FUNCTION_PARAM);
   659   s4o.print(FB_FUNCTION_PARAM);
   654   s4o.print(") {\n");
   660   s4o.print(") {\n");
   655   s4o.indent_right();
   661   s4o.indent_right();
   656 
   662 
   657   /* (B.2) Initialize TEMP variables */
   663   /* (B.3) Initialize TEMP variables */
   658   /* function body */
   664   /* function body */
   659   s4o.print(s4o.indent_spaces + "// Initialise TEMP variables\n");
   665   s4o.print(s4o.indent_spaces + "// Initialise TEMP variables\n");
   660   vardecl = new generate_cc_vardecl_c(&s4o,
   666   vardecl = new generate_cc_vardecl_c(&s4o,
   661   				      generate_cc_vardecl_c::init_vf,
   667   				      generate_cc_vardecl_c::init_vf,
   662 				      generate_cc_vardecl_c::temp_vt);
   668 				      generate_cc_vardecl_c::temp_vt);
   663   vardecl->print(symbol->var_declarations, NULL,  FB_FUNCTION_PARAM"->");
   669   vardecl->print(symbol->var_declarations, NULL,  FB_FUNCTION_PARAM"->");
   664   delete vardecl;
   670   delete vardecl;
   665   s4o.print("\n");
   671   s4o.print("\n");
   666 
   672 
   667   /* (B.3) Function code */
   673   /* (B.4) Function code */
   668   generate_cc_SFC_IL_ST_c generate_cc_code(&s4o, symbol, FB_FUNCTION_PARAM"->");
   674   generate_cc_SFC_IL_ST_c generate_cc_code(&s4o, symbol, FB_FUNCTION_PARAM"->");
   669   symbol->function_block_body->accept(generate_cc_code);
   675   symbol->function_block_body->accept(generate_cc_code);
   670   s4o.indent_left();
   676   s4o.indent_left();
   671   s4o.print(s4o.indent_spaces + "} // ");
   677   s4o.print(s4o.indent_spaces + "} // ");
   672   symbol->program_type_name->accept(*this);
   678   symbol->program_type_name->accept(*this);
   673   s4o.print(FB_FUNCTION_SUFFIX);
   679   s4o.print(FB_FUNCTION_SUFFIX);
   674   s4o.print(s4o.indent_spaces + "() \n\n");
   680   s4o.print(s4o.indent_spaces + "() \n\n");
       
   681 
       
   682   /* (B.5) Step and Action undefinitions */
       
   683   generate_cc_sfcundecl_c generate_cc_sfcundecl(&s4o);
       
   684   symbol->function_block_body->accept(generate_cc_sfcundecl);
   675 
   685 
   676   s4o.indent_left();
   686   s4o.indent_left();
   677   s4o.print("\n\n\n\n");
   687   s4o.print("\n\n\n\n");
   678 
   688 
   679   return NULL;
   689   return NULL;