# HG changeset patch # User lbessard # Date 1186066616 -7200 # Node ID c96d1a4c23f80dd2dddefe34c06cf5b523058119 # Parent 3d24cc85bb3ce2b06b3ec0679a28319b9379ac1b Changing file headers Modifying SFC generation diff -r 3d24cc85bb3c -r c96d1a4c23f8 lib/iec_std_lib_generated.h --- a/lib/iec_std_lib_generated.h Wed Aug 01 13:50:14 2007 +0200 +++ b/lib/iec_std_lib_generated.h Thu Aug 02 16:56:56 2007 +0200 @@ -1,4 +1,28 @@ +/* + * (c) 2003 Mario de Sousa + * + * Offered to the public under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * This code is made available on the understanding that it will not be + * used in safety-critical situations without a full and competent review. + */ +/* + * An IEC 61131-3 IL and ST compiler. + * + * Based on the + * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) + * + */ + + /**** * IEC 61131-3 standard function lib * generated code, do not edit by hand diff -r 3d24cc85bb3c -r c96d1a4c23f8 stage1_2/standard_function_names.c --- a/stage1_2/standard_function_names.c Wed Aug 01 13:50:14 2007 +0200 +++ b/stage1_2/standard_function_names.c Thu Aug 02 16:56:56 2007 +0200 @@ -1,4 +1,28 @@ +/* + * (c) 2003 Mario de Sousa + * + * Offered to the public under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * This code is made available on the understanding that it will not be + * used in safety-critical situations without a full and competent review. + */ +/* + * An IEC 61131-3 IL and ST compiler. + * + * Based on the + * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) + * + */ + + /**** * IEC 61131-3 standard function lib * generated code, do not edit by hand diff -r 3d24cc85bb3c -r c96d1a4c23f8 stage4/generate_cc/function_type_decl.h --- a/stage4/generate_cc/function_type_decl.h Wed Aug 01 13:50:14 2007 +0200 +++ b/stage4/generate_cc/function_type_decl.h Thu Aug 02 16:56:56 2007 +0200 @@ -1,4 +1,28 @@ +/* + * (c) 2003 Mario de Sousa + * + * Offered to the public under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * This code is made available on the understanding that it will not be + * used in safety-critical situations without a full and competent review. + */ +/* + * An IEC 61131-3 IL and ST compiler. + * + * Based on the + * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) + * + */ + + /**** * IEC 61131-3 standard function lib * generated code, do not edit by hand diff -r 3d24cc85bb3c -r c96d1a4c23f8 stage4/generate_cc/generate_cc.cc --- a/stage4/generate_cc/generate_cc.cc Wed Aug 01 13:50:14 2007 +0200 +++ b/stage4/generate_cc/generate_cc.cc Thu Aug 02 16:56:56 2007 +0200 @@ -189,8 +189,8 @@ #include "search_expression_type.cc" #include "generate_cc_base.cc" +#include "generate_cc_typedecl.cc" #include "generate_cc_sfcdecl.cc" -#include "generate_cc_typedecl.cc" #include "generate_cc_vardecl.cc" #include "generate_cc_configbody.cc" #include "generate_location_list.cc" @@ -751,6 +751,7 @@ //SYM_REF4(program_declaration_c, program_type_name, var_declarations, function_block_body, unused) void *visit(program_declaration_c *symbol) { generate_cc_vardecl_c *vardecl; + generate_cc_sfcdecl_c *sfcdecl; TRACE("program_declaration_c"); /* start off by adding this declaration to the global @@ -787,10 +788,10 @@ vardecl->print(symbol->var_declarations); delete vardecl; /* (A.4) Generate private internal variables for SFC */ - generate_cc_sfctables_c generate_cc_sfctables(&s4o); - symbol->function_block_body->accept(generate_cc_sfctables); - s4o.print("\n"); - + sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::sfcdecl_sg); + sfcdecl->print(symbol->function_block_body); + delete sfcdecl; + /* (A.5) Program data structure type name. */ s4o.indent_left(); s4o.print("} "); @@ -823,15 +824,27 @@ generate_cc_vardecl_c::external_vt); vardecl->print(symbol->var_declarations, NULL, FB_FUNCTION_PARAM"->"); delete vardecl; + s4o.print("\n"); + /* (B.3) Generate private internal variables for SFC */ + sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::sfcinit_sg); + sfcdecl->print(symbol->function_block_body,FB_FUNCTION_PARAM"->"); + delete sfcdecl; + s4o.indent_left(); - s4o.print("\n" + s4o.indent_spaces + "}\n\n"); + s4o.print(s4o.indent_spaces + "}\n\n"); /* (C) Function with PROGRAM body */ - /* (C.1) Step and Action definitions */ - generate_cc_sfcdecl_c generate_cc_sfcdecl(&s4o); - symbol->function_block_body->accept(generate_cc_sfcdecl); - - /* (C.2) Function declaration */ + /* (C.1) Step definitions */ + sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::stepdef_sg); + sfcdecl->print(symbol->function_block_body); + delete sfcdecl; + + /* (C.2) Action definitions */ + sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::actiondef_sg); + sfcdecl->print(symbol->function_block_body); + delete sfcdecl; + + /* (C.3) Function declaration */ s4o.print("// Code part\n"); /* function interface */ s4o.print("void "); @@ -845,7 +858,7 @@ s4o.print(") {\n"); s4o.indent_right(); - /* (C.3) Initialize TEMP variables */ + /* (C.4) Initialize TEMP variables */ /* function body */ s4o.print(s4o.indent_spaces + "// Initialise TEMP variables\n"); vardecl = new generate_cc_vardecl_c(&s4o, @@ -855,7 +868,7 @@ delete vardecl; s4o.print("\n"); - /* (C.4) Function code */ + /* (C.5) Function code */ generate_cc_SFC_IL_ST_c generate_cc_code(&s4o, symbol, FB_FUNCTION_PARAM"->"); symbol->function_block_body->accept(generate_cc_code); s4o.indent_left(); @@ -864,10 +877,16 @@ s4o.print(FB_FUNCTION_SUFFIX); s4o.print(s4o.indent_spaces + "() \n\n"); - /* (C.5) Step and Action undefinitions */ - generate_cc_sfcundecl_c generate_cc_sfcundecl(&s4o); - symbol->function_block_body->accept(generate_cc_sfcundecl); - + /* (C.6) Step undefinitions */ + sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::stepundef_sg); + sfcdecl->print(symbol->function_block_body); + delete sfcdecl; + + /* (C.7) Action undefinitions */ + sfcdecl = new generate_cc_sfcdecl_c(&s4o, generate_cc_sfcdecl_c::actionundef_sg); + sfcdecl->print(symbol->function_block_body); + delete sfcdecl; + s4o.indent_left(); s4o.print("\n\n\n\n"); diff -r 3d24cc85bb3c -r c96d1a4c23f8 stage4/generate_cc/generate_cc_sfcdecl.cc --- a/stage4/generate_cc/generate_cc_sfcdecl.cc Wed Aug 01 13:50:14 2007 +0200 +++ b/stage4/generate_cc/generate_cc_sfcdecl.cc Thu Aug 02 16:56:56 2007 +0200 @@ -39,518 +39,223 @@ /***********************************************************************/ /***********************************************************************/ -class generate_cc_sfc_steptable_c: public generate_cc_base_c { +class generate_cc_sfcdecl_c: protected generate_cc_typedecl_c { + + public: + typedef enum { + sfcdecl_sg, + sfcinit_sg, + stepdef_sg, + stepundef_sg, + actiondef_sg, + actionundef_sg + } sfcgeneration_t; private: char step_number; + char action_number; + char transition_number; + + sfcgeneration_t wanted_sfcgeneration; public: - generate_cc_sfc_steptable_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} - ~generate_cc_sfc_steptable_c(void) {} - - void reset_step_number(void) {step_number = 0;} - void print_step_number(void) { - char str[10]; - sprintf(str, "%d", step_number); - s4o.print(str); - } + generate_cc_sfcdecl_c(stage4out_c *s4o_ptr, sfcgeneration_t sfcgeneration) + : generate_cc_typedecl_c(s4o_ptr) { + wanted_sfcgeneration = sfcgeneration; + } + ~generate_cc_sfcdecl_c(void) {} + + void print(symbol_c *symbol, const char *variable_prefix = NULL) { + this->set_variable_prefix(variable_prefix); + + symbol->accept(*this); + } + /*********************************************/ /* B.1.6 Sequential function chart elements */ /*********************************************/ + void *visit(sequential_function_chart_c *symbol) { + step_number = 0; + action_number = 0; + transition_number = 0; + switch (wanted_sfcgeneration) { + case sfcdecl_sg: + for(int i = 0; i < symbol->n; i++) + symbol->elements[i]->accept(*this); + + /* steps table declaration */ + s4o.print(s4o.indent_spaces + "STEP step_list["); + s4o.print_integer(step_number); + s4o.print("];\n"); + s4o.print(s4o.indent_spaces + "UINT nb_steps = "); + s4o.print_integer(step_number); + s4o.print(";\n"); + + /* actions table declaration */ + s4o.print(s4o.indent_spaces + "ACTION action_list["); + s4o.print_integer(action_number); + s4o.print("];\n"); + s4o.print(s4o.indent_spaces + "UINT nb_actions = "); + s4o.print_integer(action_number); + s4o.print(";\n"); + + /* transitions table declaration */ + s4o.print(s4o.indent_spaces + "USINT transition_list["); + s4o.print_integer(transition_number); + s4o.print("];\n"); + break; + case sfcinit_sg: + /* steps table initialisation */ + s4o.print(s4o.indent_spaces + "STEP temp_step = {0, 0, 0};\n"); + s4o.print(s4o.indent_spaces + "for(UINT i = 0; i < "); + print_variable_prefix(); + s4o.print("nb_steps; i++) {\n"); + s4o.indent_right(); + s4o.print(s4o.indent_spaces); + print_variable_prefix(); + s4o.print("step_list[i] = temp_step;\n"); + s4o.indent_left(); + s4o.print(s4o.indent_spaces + "}\n"); + for(int i = 0; i < symbol->n; i++) + symbol->elements[i]->accept(*this); + + /* actions table initialisation */ + s4o.print(s4o.indent_spaces + "ACTION temp_action = {0, 0, 0, 0, 0, 0};\n"); + s4o.print(s4o.indent_spaces + "for(UINT i = 0; i < "); + print_variable_prefix(); + s4o.print("nb_actions; i++) {\n"); + s4o.indent_right(); + s4o.print(s4o.indent_spaces); + print_variable_prefix(); + s4o.print("action_list[i] = temp_action;\n"); + s4o.indent_left(); + s4o.print(s4o.indent_spaces + "}\n"); + break; + case stepdef_sg: + s4o.print("// Steps definitions\n"); + for(int i = 0; i < symbol->n; i++) + symbol->elements[i]->accept(*this); + s4o.print("\n"); + break; + case actiondef_sg: + s4o.print("// Actions definitions\n"); + for(int i = 0; i < symbol->n; i++) + symbol->elements[i]->accept(*this); + s4o.print("\n"); + break; + case stepundef_sg: + s4o.print("// Steps undefinitions\n"); + for(int i = 0; i < symbol->n; i++) + symbol->elements[i]->accept(*this); + s4o.print("\n"); + break; + case actionundef_sg: + s4o.print("// Actions undefinitions\n"); + for(int i = 0; i < symbol->n; i++) + symbol->elements[i]->accept(*this); + s4o.print("\n"); + break; + } + return NULL; + } + void *visit(initial_step_c *symbol) { - if (step_number > 0) { - s4o.print(",\n"); - } - s4o.print(s4o.indent_spaces + "{1, 0, 0}"); - step_number++; + switch (wanted_sfcgeneration) { + case sfcdecl_sg: + step_number++; + break; + case sfcinit_sg: + s4o.print(s4o.indent_spaces); + print_variable_prefix(); + s4o.print("action_list["); + s4o.print_integer(step_number); + s4o.print("].state = 1;\n"); + step_number++; + break; + case stepdef_sg: + s4o.print("#define "); + s4o.print(SFC_STEP_ACTION_PREFIX); + symbol->step_name->accept(*this); + s4o.print(" "); + s4o.print_integer(step_number); + s4o.print("\n"); + step_number++; + break; + case stepundef_sg: + s4o.print("#undef "); + s4o.print(SFC_STEP_ACTION_PREFIX); + symbol->step_name->accept(*this); + s4o.print("\n"); + break; + default: + break; + } return NULL; } void *visit(step_c *symbol) { - if (step_number > 0) { - s4o.print(",\n"); - } - s4o.print(s4o.indent_spaces + "{0, 0, 0}"); - step_number++; - return NULL; - } - - void *visit(transition_c *symbol) {return NULL;} - - void *visit(action_c *symbol) {return NULL;} - -}; /* generate_cc_sfc_steptable_c */ - - - - -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - -class generate_cc_sfc_actiontable_c: public generate_cc_base_c { - - private: - char action_number; - - public: - generate_cc_sfc_actiontable_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} - ~generate_cc_sfc_actiontable_c(void) {} - - void reset_action_number(void) {action_number = 0;} - void print_action_number(void) { - char str[10]; - sprintf(str, "%d", action_number); - s4o.print(str); - } -/*********************************************/ -/* B.1.6 Sequential function chart elements */ -/*********************************************/ - - void *visit(initial_step_c *symbol) {return NULL;} - - void *visit(step_c *symbol) {return NULL;} - - void *visit(transition_c *symbol) {return NULL;} + switch (wanted_sfcgeneration) { + case sfcdecl_sg: + step_number++; + break; + case stepdef_sg: + s4o.print("#define "); + s4o.print(SFC_STEP_ACTION_PREFIX); + symbol->step_name->accept(*this); + s4o.print(" "); + s4o.print_integer(step_number); + s4o.print("\n"); + step_number++; + break; + case stepundef_sg: + s4o.print("#undef "); + s4o.print(SFC_STEP_ACTION_PREFIX); + symbol->step_name->accept(*this); + s4o.print("\n"); + break; + default: + break; + } + return NULL; + } + + void *visit(transition_c *symbol) { + switch (wanted_sfcgeneration) { + case sfcdecl_sg: + transition_number++; + break; + default: + break; + } + return NULL; + } void *visit(action_c *symbol) { - if (action_number > 0) { - s4o.print(",\n"); - } - s4o.print(s4o.indent_spaces + "{0, 0, 0, 0, 0, 0}"); - action_number++; - return NULL; - } - -}; /* generate_cc_sfc_actiontable_c */ - - - - -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - -class generate_cc_sfc_transitiontable_c: public generate_cc_base_c { - - private: - char transition_number; - - public: - generate_cc_sfc_transitiontable_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} - ~generate_cc_sfc_transitiontable_c(void) {} - - void reset_transition_number(void) {transition_number = 0;} - void print_transition_number(void) { - char str[10]; - sprintf(str, "%d", transition_number); - s4o.print(str); - } -/*********************************************/ -/* B.1.6 Sequential function chart elements */ -/*********************************************/ - - void *visit(initial_step_c *symbol) {return NULL;} - - void *visit(step_c *symbol) {return NULL;} - - void *visit(transition_c *symbol) { - transition_number++; - return NULL; - } - - void *visit(action_c *symbol) {return NULL;} - -}; /* generate_cc_sfc_steptable_c */ - - - - -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - -class generate_cc_sfctables_c: public iterator_visitor_c { - - protected: - stage4out_c &s4o; - - private: - generate_cc_sfc_steptable_c *generate_cc_sfc_steptable; - generate_cc_sfc_actiontable_c *generate_cc_sfc_actiontable; - generate_cc_sfc_transitiontable_c *generate_cc_sfc_transitiontable; - - public: - generate_cc_sfctables_c(stage4out_c *s4o_ptr) : s4o(*s4o_ptr) { - generate_cc_sfc_steptable = new generate_cc_sfc_steptable_c(s4o_ptr); - generate_cc_sfc_actiontable = new generate_cc_sfc_actiontable_c(s4o_ptr); - generate_cc_sfc_transitiontable = new generate_cc_sfc_transitiontable_c(s4o_ptr); - } - - virtual ~generate_cc_sfctables_c(void) { - delete generate_cc_sfc_steptable; - delete generate_cc_sfc_actiontable; - delete generate_cc_sfc_transitiontable; - } - - public: - - /* generate steps and actions tables */ - void *visit(sequential_function_chart_c *symbol) { - /* generate steps table */ - generate_cc_sfc_steptable->reset_step_number(); - s4o.print(s4o.indent_spaces + "STEP step_list[] = {\n"); - s4o.indent_right(); - symbol->accept(*generate_cc_sfc_steptable); - s4o.indent_left(); - s4o.print("\n" + s4o.indent_spaces + "};\n" + s4o.indent_spaces + "nb_steps = "); - generate_cc_sfc_steptable->print_step_number(); - s4o.print(";\n"); - - /* generate actions table */ - generate_cc_sfc_actiontable->reset_action_number(); - s4o.print(s4o.indent_spaces + "ACTION action_list[] = {\n"); - s4o.indent_right(); - symbol->accept(*generate_cc_sfc_actiontable); - s4o.indent_left(); - s4o.print("\n" + s4o.indent_spaces + "};\n" + s4o.indent_spaces + "nb_actions = "); - generate_cc_sfc_actiontable->print_action_number(); - s4o.print(";\n"); - - /* generate transitions table */ - generate_cc_sfc_transitiontable->reset_transition_number(); - symbol->accept(*generate_cc_sfc_transitiontable); - s4o.print(s4o.indent_spaces + "char transition_list["); - generate_cc_sfc_transitiontable->print_transition_number(); - s4o.print("];\n"); - - return NULL; - } - -/***********************************/ -/* B 2.1 Instructions and Operands */ -/***********************************/ -/*| instruction_list il_instruction */ - void *visit(instruction_list_c *symbol) {return NULL;} - -/***************************************/ -/* B.3 - Language ST (Structured Text) */ -/***************************************/ -/********************/ -/* B 3.2 Statements */ -/********************/ - void *visit(statement_list_c *symbol) {return NULL;} - -/* Remainder implemented in generate_cc_sfcdecl_c... */ -}; - - - - -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - -class generate_cc_sfc_stepdecl_c: public generate_cc_base_c { - - private: - char step_number; - - public: - generate_cc_sfc_stepdecl_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} - ~generate_cc_sfc_stepdecl_c(void) {} - - void reset_step_number(void) {step_number = 0;} - void print_step_number(void) { - char str[10]; - sprintf(str, "%d", step_number); - s4o.print(str); - } - -/*********************************************/ -/* B.1.6 Sequential function chart elements */ -/*********************************************/ - - void *visit(initial_step_c *symbol) { - s4o.print("#define "); - s4o.print(SFC_STEP_ACTION_PREFIX); - symbol->step_name->accept(*this); - s4o.print(" "); - print_step_number(); - s4o.print("\n"); - step_number++; - return NULL; - } - - void *visit(step_c *symbol) { - s4o.print("#define "); - s4o.print(SFC_STEP_ACTION_PREFIX); - symbol->step_name->accept(*this); - s4o.print(" "); - print_step_number(); - s4o.print("\n"); - step_number++; - return NULL; - } - - void *visit(transition_c *symbol) {return NULL;} - - void *visit(action_c *symbol) {return NULL;} - -}; /* generate_cc_sfc_stepdecl_c */ - - - - -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - -class generate_cc_sfc_actiondecl_c: public generate_cc_base_c { - - private: - char action_number; - - public: - generate_cc_sfc_actiondecl_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} - ~generate_cc_sfc_actiondecl_c(void) {} - - void reset_action_number(void) {action_number = 0;} - void print_action_number(void) { - char str[10]; - sprintf(str, "%d", action_number); - s4o.print(str); - } - -/*********************************************/ -/* B.1.6 Sequential function chart elements */ -/*********************************************/ - - void *visit(initial_step_c *symbol) {return NULL;} - - void *visit(step_c *symbol) {return NULL;} - - void *visit(transition_c *symbol) {return NULL;} - - void *visit(action_c *symbol) { - s4o.print("#define "); - s4o.print(SFC_STEP_ACTION_PREFIX); - symbol->action_name->accept(*this); - s4o.print(" "); - print_action_number(); - s4o.print("\n"); - action_number++; - return NULL; - } - -}; /* generate_cc_sfc_actiondecl_c */ - - - - -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - -class generate_cc_sfcdecl_c: public iterator_visitor_c { - - protected: - stage4out_c &s4o; - - private: - generate_cc_sfc_stepdecl_c *generate_cc_sfc_stepdecl; - generate_cc_sfc_actiondecl_c *generate_cc_sfc_actiondecl; - - public: - generate_cc_sfcdecl_c(stage4out_c *s4o_ptr) : s4o(*s4o_ptr) { - generate_cc_sfc_stepdecl = new generate_cc_sfc_stepdecl_c(s4o_ptr); - generate_cc_sfc_actiondecl = new generate_cc_sfc_actiondecl_c(s4o_ptr); - } - - virtual ~generate_cc_sfcdecl_c(void) { - delete generate_cc_sfc_stepdecl; - delete generate_cc_sfc_actiondecl; - } - - public: - - /* generate steps and actions tables */ - void *visit(sequential_function_chart_c *symbol) { - /* generate steps definitions */ - generate_cc_sfc_stepdecl->reset_step_number(); - s4o.print("// Steps definitions\n"); - symbol->accept(*generate_cc_sfc_stepdecl); - s4o.print("\n"); - - /* generate actions definitions */ - generate_cc_sfc_actiondecl->reset_action_number(); - s4o.print("// Actions definitions\n"); - symbol->accept(*generate_cc_sfc_actiondecl); - s4o.print("\n"); - - return NULL; - } - -/***********************************/ -/* B 2.1 Instructions and Operands */ -/***********************************/ -/*| instruction_list il_instruction */ - void *visit(instruction_list_c *symbol) {return NULL;} - -/***************************************/ -/* B.3 - Language ST (Structured Text) */ -/***************************************/ -/********************/ -/* B 3.2 Statements */ -/********************/ - void *visit(statement_list_c *symbol) {return NULL;} - -/* Remainder implemented in generate_cc_sfcdecl_c... */ -}; - - - - -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - -class generate_cc_sfc_stepundecl_c: public generate_cc_base_c { - - public: - generate_cc_sfc_stepundecl_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} - ~generate_cc_sfc_stepundecl_c(void) {} - -/*********************************************/ -/* B.1.6 Sequential function chart elements */ -/*********************************************/ - - void *visit(initial_step_c *symbol) { - s4o.print("#undef "); - s4o.print(SFC_STEP_ACTION_PREFIX); - symbol->step_name->accept(*this); - s4o.print("\n"); - return NULL; - } - - void *visit(step_c *symbol) { - s4o.print("#undef "); - s4o.print(SFC_STEP_ACTION_PREFIX); - symbol->step_name->accept(*this); - s4o.print("\n"); - return NULL; - } - - void *visit(transition_c *symbol) {return NULL;} - - void *visit(action_c *symbol) {return NULL;} - -}; /* generate_cc_sfc_stepdecl_c */ - - - - -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - -class generate_cc_sfc_actionundecl_c: public generate_cc_base_c { - - public: - generate_cc_sfc_actionundecl_c(stage4out_c *s4o_ptr): generate_cc_base_c(s4o_ptr) {} - ~generate_cc_sfc_actionundecl_c(void) {} - -/*********************************************/ -/* B.1.6 Sequential function chart elements */ -/*********************************************/ - - void *visit(initial_step_c *symbol) {return NULL;} - - void *visit(step_c *symbol) {return NULL;} - - void *visit(transition_c *symbol) {return NULL;} - - void *visit(action_c *symbol) { - s4o.print("#undef "); - s4o.print(SFC_STEP_ACTION_PREFIX); - symbol->action_name->accept(*this); - s4o.print("\n"); - return NULL; - } - -}; /* generate_cc_sfc_stepdecl_c */ - - - - -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ -/***********************************************************************/ - -class generate_cc_sfcundecl_c: public iterator_visitor_c { - - protected: - stage4out_c &s4o; - - private: - generate_cc_sfc_stepundecl_c *generate_cc_sfc_stepundecl; - generate_cc_sfc_actionundecl_c *generate_cc_sfc_actionundecl; - - public: - generate_cc_sfcundecl_c(stage4out_c *s4o_ptr) : s4o(*s4o_ptr) { - generate_cc_sfc_stepundecl = new generate_cc_sfc_stepundecl_c(s4o_ptr); - generate_cc_sfc_actionundecl = new generate_cc_sfc_actionundecl_c(s4o_ptr); - } - - virtual ~generate_cc_sfcundecl_c(void) { - delete generate_cc_sfc_stepundecl; - delete generate_cc_sfc_actionundecl; - } - - public: - -/*********************************************/ -/* B.1.6 Sequential function chart elements */ -/*********************************************/ - - /* generate steps and actions tables */ - void *visit(sequential_function_chart_c *symbol) { - /* generate steps undefinitions */ - s4o.print("// Steps undefinitions\n"); - symbol->accept(*generate_cc_sfc_stepundecl); - s4o.print("\n"); - - /* generate actions table */ - s4o.print("// Actions undefinitions\n"); - symbol->accept(*generate_cc_sfc_actionundecl); - s4o.print("\n"); - - return NULL; - } - -/***********************************/ -/* B 2.1 Instructions and Operands */ -/***********************************/ -/*| instruction_list il_instruction */ - void *visit(instruction_list_c *symbol) {return NULL;} - -/***************************************/ -/* B.3 - Language ST (Structured Text) */ -/***************************************/ -/********************/ -/* B 3.2 Statements */ -/********************/ - void *visit(statement_list_c *symbol) {return NULL;} - -/* Remainder implemented in generate_cc_sfcdecl_c... */ -}; + switch (wanted_sfcgeneration) { + case actiondef_sg: + s4o.print("#define "); + s4o.print(SFC_STEP_ACTION_PREFIX); + symbol->action_name->accept(*this); + s4o.print(" "); + s4o.print_integer(action_number); + s4o.print("\n"); + action_number++; + break; + case actionundef_sg: + s4o.print("#undef "); + s4o.print(SFC_STEP_ACTION_PREFIX); + symbol->action_name->accept(*this); + s4o.print("\n"); + break; + case sfcdecl_sg: + action_number++; + break; + default: + break; + } + return NULL; + } + +}; /* generate_cc_sfcdecl_c */ + diff -r 3d24cc85bb3c -r c96d1a4c23f8 stage4/generate_cc/get_function_type_decl.c --- a/stage4/generate_cc/get_function_type_decl.c Wed Aug 01 13:50:14 2007 +0200 +++ b/stage4/generate_cc/get_function_type_decl.c Thu Aug 02 16:56:56 2007 +0200 @@ -1,4 +1,28 @@ - +/* + * (c) 2003 Mario de Sousa + * + * Offered to the public under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * This code is made available on the understanding that it will not be + * used in safety-critical situations without a full and competent review. + */ + +/* + * An IEC 61131-3 IL and ST compiler. + * + * Based on the + * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) + * + */ + + /**** * IEC 61131-3 standard function lib * generated code, do not edit by hand diff -r 3d24cc85bb3c -r c96d1a4c23f8 stage4/generate_cc/il_code_gen.c --- a/stage4/generate_cc/il_code_gen.c Wed Aug 01 13:50:14 2007 +0200 +++ b/stage4/generate_cc/il_code_gen.c Thu Aug 02 16:56:56 2007 +0200 @@ -1,4 +1,28 @@ - +/* + * (c) 2003 Mario de Sousa + * + * Offered to the public under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * This code is made available on the understanding that it will not be + * used in safety-critical situations without a full and competent review. + */ + +/* + * An IEC 61131-3 IL and ST compiler. + * + * Based on the + * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) + * + */ + + /**** * IEC 61131-3 standard function lib * generated code, do not edit by hand diff -r 3d24cc85bb3c -r c96d1a4c23f8 stage4/generate_cc/search_type_code.c --- a/stage4/generate_cc/search_type_code.c Wed Aug 01 13:50:14 2007 +0200 +++ b/stage4/generate_cc/search_type_code.c Thu Aug 02 16:56:56 2007 +0200 @@ -1,4 +1,28 @@ - +/* + * (c) 2003 Mario de Sousa + * + * Offered to the public under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * This code is made available on the understanding that it will not be + * used in safety-critical situations without a full and competent review. + */ + +/* + * An IEC 61131-3 IL and ST compiler. + * + * Based on the + * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) + * + */ + + /**** * IEC 61131-3 standard function lib * generated code, do not edit by hand diff -r 3d24cc85bb3c -r c96d1a4c23f8 stage4/generate_cc/st_code_gen.c --- a/stage4/generate_cc/st_code_gen.c Wed Aug 01 13:50:14 2007 +0200 +++ b/stage4/generate_cc/st_code_gen.c Thu Aug 02 16:56:56 2007 +0200 @@ -1,4 +1,28 @@ - +/* + * (c) 2003 Mario de Sousa + * + * Offered to the public under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General + * Public License for more details. + * + * This code is made available on the understanding that it will not be + * used in safety-critical situations without a full and competent review. + */ + +/* + * An IEC 61131-3 IL and ST compiler. + * + * Based on the + * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10) + * + */ + + /**** * IEC 61131-3 standard function lib * generated code, do not edit by hand