Bug on SFC debugging fixed
authorlaurent
Tue, 08 Dec 2009 16:26:06 +0100
changeset 229 ca7bc1324540
parent 228 43831b683764
child 230 816846a8d66b
Bug on SFC debugging fixed
Adding support for forcing transition state
stage4/generate_c/generate_c_sfc.cc
stage4/generate_c/generate_c_sfcdecl.cc
stage4/generate_c/generate_var_list.cc
--- a/stage4/generate_c/generate_c_sfc.cc	Mon Dec 07 15:36:29 2009 +0100
+++ b/stage4/generate_c/generate_c_sfc.cc	Tue Dec 08 16:26:06 2009 +0100
@@ -661,7 +661,7 @@
       s4o.print(s4o.indent_spaces +"BOOL transition;\n");
       s4o.print(s4o.indent_spaces +"TIME elapsed_time, current_time;\n\n");
       
-      /* generate elapsed_time initialisations */
+      /* generate elapsed_time initializations */
       s4o.print(s4o.indent_spaces + "// Calculate elapsed_time\n");
       s4o.print(s4o.indent_spaces +"current_time = __CURRENT_TIME;\n");
       s4o.print(s4o.indent_spaces +"elapsed_time = __time_sub(__BOOL_LITERAL(TRUE), NULL, current_time, ");
@@ -671,8 +671,26 @@
       print_variable_prefix();
       s4o.print("__lasttick_time = current_time;\n");
       
-      /* generate step initialisations */
-      s4o.print(s4o.indent_spaces + "// Steps initialisation\n");
+      /* generate transition initializations */
+      s4o.print(s4o.indent_spaces + "// Transitions initialization\n");
+      s4o.print(s4o.indent_spaces + "if (__DEBUG) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces + "for (i = 0; i < ");
+      print_variable_prefix();
+      s4o.print("__nb_transitions; i++) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__transition_list[i] = ");
+      print_variable_prefix();
+      s4o.print("__debug_transition_list[i];\n");
+      s4o.indent_left();
+      s4o.print(s4o.indent_spaces + "}\n");
+      s4o.indent_left();
+      s4o.print(s4o.indent_spaces + "}\n");
+
+      /* generate step initializations */
+      s4o.print(s4o.indent_spaces + "// Steps initialization\n");
       s4o.print(s4o.indent_spaces + "for (i = 0; i < ");
       print_variable_prefix();
       s4o.print("__nb_steps; i++) {\n");
@@ -700,8 +718,8 @@
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n");
 
-      /* generate action initilizations */
-      s4o.print(s4o.indent_spaces + "// Actions initialisation\n");
+      /* generate action initializations */
+      s4o.print(s4o.indent_spaces + "// Actions initialization\n");
       s4o.print(s4o.indent_spaces + "for (i = 0; i < ");
       print_variable_prefix();
       s4o.print("__nb_actions; i++) {\n");
--- a/stage4/generate_c/generate_c_sfcdecl.cc	Mon Dec 07 15:36:29 2009 +0100
+++ b/stage4/generate_c/generate_c_sfcdecl.cc	Tue Dec 08 16:26:06 2009 +0100
@@ -50,7 +50,8 @@
         stepundef_sd,
         actiondef_sd,
         actionundef_sd,
-        actioncount_sd
+        actioncount_sd,
+        transitioncount_sd
        } sfcdeclaration_t;
   
   private:
@@ -107,6 +108,7 @@
           s4o.print(s4o.indent_spaces + "__IEC_BOOL_t __debug_transition_list[");
           s4o.print_integer(transition_number);
           s4o.print("];\n");
+          s4o.print(s4o.indent_spaces + "UINT __nb_transitions;\n");
           
           /* last_ticktime declaration */
           s4o.print(s4o.indent_spaces + "TIME __lasttick_time;\n");
@@ -165,6 +167,18 @@
           s4o.indent_left();
           s4o.print(s4o.indent_spaces + "}\n");
           
+          /* transitions table count */
+          wanted_sfcdeclaration = transitioncount_sd;
+          for(int i = 0; i < symbol->n; i++)
+            symbol->elements[i]->accept(*this);
+          s4o.print(s4o.indent_spaces);
+          print_variable_prefix();
+          s4o.print("__nb_transitions = ");
+          s4o.print_integer(transition_number);
+          s4o.print(";\n");
+          transition_number = 0;
+          wanted_sfcdeclaration = sfcinit_sd;
+
           /* last_ticktime initialisation */
           s4o.print(s4o.indent_spaces);
           print_variable_prefix();
@@ -268,6 +282,7 @@
     void *visit(transition_c *symbol) {
       switch (wanted_sfcdeclaration) {
         case sfcdecl_sd:
+        case transitioncount_sd:
           transition_number++;
           break;
         default:
--- a/stage4/generate_c/generate_var_list.cc	Mon Dec 07 15:36:29 2009 +0100
+++ b/stage4/generate_c/generate_var_list.cc	Tue Dec 08 16:26:06 2009 +0100
@@ -561,7 +561,7 @@
       print_symbol_list();
       s4o.print("__step_list[");
       print_step_number();
-      s4o.print("].state;STEP;\n");
+      s4o.print("].state;BOOL;\n");
       step_number++;
       return NULL;
     }
@@ -577,7 +577,7 @@
       print_symbol_list();
       s4o.print("__step_list[");
       print_step_number();
-      s4o.print("].state;STEP;\n");
+      s4o.print("].state;BOOL;\n");
       step_number++;
       return NULL;
     }
@@ -601,7 +601,7 @@
       print_symbol_list();
       s4o.print("__debug_transition_list[");
       print_transition_number();
-      s4o.print("];TRANSITION;\n");
+      s4o.print("];BOOL;\n");
       transition_number++;
       return NULL;
     }
@@ -640,7 +640,7 @@
       print_symbol_list();
       s4o.print("__action_list[");
       print_action_number();
-      s4o.print("].state;ACTION;\n");
+      s4o.print("].state;BOOL;\n");
       action_number++;
       return NULL;
     }