Adding support for transition debugging
authorlbessard
Mon, 08 Sep 2008 10:33:37 +0200
changeset 141 d2dc99c319b6
parent 140 8c0366d41e84
child 142 120772c527f3
Adding support for transition debugging
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	Sun Sep 07 10:08:11 2008 +0200
+++ b/stage4/generate_c/generate_c_sfc.cc	Mon Sep 08 10:33:37 2008 +0200
@@ -53,6 +53,7 @@
     typedef enum {
       transitionlist_sg,
       transitiontest_sg,
+      transitiontestdebug_sg,
       stepset_sg,
       stepreset_sg,
       actionassociation_sg,
@@ -112,7 +113,7 @@
 
     void print_step_argument(symbol_c *step_name, const char* argument) {
       print_variable_prefix();
-      s4o.print("step_list[");
+      s4o.print("__step_list[");
       s4o.print(SFC_STEP_ACTION_PREFIX);
       step_name->accept(*this);
       s4o.print("].");
@@ -121,7 +122,7 @@
 
     void print_action_argument(symbol_c *action_name, const char* argument) {
       print_variable_prefix();
-      s4o.print("action_list[");
+      s4o.print("__action_list[");
       s4o.print(SFC_STEP_ACTION_PREFIX);
       action_name->accept(*this);
       s4o.print("].");
@@ -262,7 +263,7 @@
           if (symbol->integer != NULL) {
             s4o.print(s4o.indent_spaces + "if (");
             print_variable_prefix();
-            s4o.print("transition_list[");
+            s4o.print("__transition_list[");
             print_transition_number();
             s4o.print("]) {\n");
             s4o.indent_right();
@@ -273,11 +274,20 @@
             s4o.print(s4o.indent_spaces + "}\n");
           }
           s4o.indent_left();
-          s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "else {\n");
+          s4o.print(s4o.indent_spaces + "}\n");
+          s4o.print(s4o.indent_spaces + "else {\n");
           s4o.indent_right();
+          // Calculate transition value for debug
+          s4o.print(s4o.indent_spaces + "if (__DEBUG) {\n");
+          s4o.indent_right();
+          wanted_sfcgeneration = transitiontestdebug_sg;
+          symbol->transition_condition->accept(*this);
+          wanted_sfcgeneration = transitiontest_sg;
+          s4o.indent_left();
+          s4o.print(s4o.indent_spaces + "}\n");
           s4o.print(s4o.indent_spaces);
           print_variable_prefix();
-          s4o.print("transition_list[");
+          s4o.print("__transition_list[");
           print_transition_number();
           s4o.print("] = 0;\n");
           s4o.indent_left();
@@ -286,7 +296,7 @@
         case stepset_sg:
           s4o.print(s4o.indent_spaces + "if (");
           print_variable_prefix();
-          s4o.print("transition_list[");
+          s4o.print("__transition_list[");
           print_transition_number();
           s4o.print("]) {\n");
           s4o.indent_right();
@@ -299,7 +309,7 @@
           if (symbol->integer == NULL) {
             s4o.print(s4o.indent_spaces + "if (");
             print_variable_prefix();
-            s4o.print("transition_list[");
+            s4o.print("__transition_list[");
             print_transition_number();
             s4o.print("]) {\n");
             s4o.indent_right();
@@ -318,12 +328,17 @@
     void *visit(transition_condition_c *symbol) {
       switch (wanted_sfcgeneration) {
         case transitiontest_sg:
+        case transitiontestdebug_sg:
           // Transition condition is in IL
           if (symbol->transition_condition_il != NULL) {
             generate_c_il->declare_backup_variable();
             s4o.print(s4o.indent_spaces);
             symbol->transition_condition_il->accept(*generate_c_il);
             print_variable_prefix();
+            if (wanted_sfcgeneration == transitiontestdebug_sg)
+              s4o.print("__debug_");
+            else
+              s4o.print("__");
             s4o.print("transition_list[");
             print_transition_number();
             s4o.print("] = ");
@@ -334,12 +349,31 @@
           if (symbol->transition_condition_st != NULL) {
             s4o.print(s4o.indent_spaces);
             print_variable_prefix();
+            if (wanted_sfcgeneration == transitiontestdebug_sg)
+              s4o.print("__debug_");
+            else
+              s4o.print("__");
             s4o.print("transition_list[");
             print_transition_number();
             s4o.print("] = ");
             symbol->transition_condition_st->accept(*generate_c_st);
             s4o.print(";\n");
           }
+          if (wanted_sfcgeneration == transitiontest_sg) {
+            s4o.print(s4o.indent_spaces + "if (__DEBUG) {\n");
+            s4o.indent_right();
+            s4o.print(s4o.indent_spaces);
+            print_variable_prefix();
+            s4o.print("__debug_transition_list[");
+            print_transition_number();
+            s4o.print("] = ");
+            print_variable_prefix();
+            s4o.print("__transition_list[");
+            print_transition_number();
+            s4o.print("];\n");
+            s4o.indent_left();
+            s4o.print(s4o.indent_spaces + "}\n");
+          }
           break;
         default:
           break;
@@ -352,7 +386,7 @@
         case actionbody_sg:
           s4o.print(s4o.indent_spaces + "if(");
           print_variable_prefix();
-          s4o.print("action_list[");
+          s4o.print("__action_list[");
           s4o.print(SFC_STEP_ACTION_PREFIX);
           symbol->action_name->accept(*this);
           s4o.print("].state) {\n");
@@ -591,31 +625,31 @@
       s4o.print(s4o.indent_spaces +"current_time = __CURRENT_TIME;\n");
       s4o.print(s4o.indent_spaces +"elapsed_time = __time_sub(current_time, ");
       print_variable_prefix();
-      s4o.print("lasttick_time);\n");
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("lasttick_time = current_time;\n");
+      s4o.print("__lasttick_time);\n");
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__lasttick_time = current_time;\n");
       
       /* generate step initialisations */
       s4o.print(s4o.indent_spaces + "// Steps initialisation\n");
       s4o.print(s4o.indent_spaces + "for (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].prev_state = ");
-      print_variable_prefix();
-      s4o.print("step_list[i].state;\n");
+      s4o.print("__nb_steps; i++) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__step_list[i].prev_state = ");
+      print_variable_prefix();
+      s4o.print("__step_list[i].state;\n");
       s4o.print(s4o.indent_spaces + "if (");
       print_variable_prefix();
-      s4o.print("step_list[i].state) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("step_list[i].elapsed_time = __time_add(");
-      print_variable_prefix();
-      s4o.print("step_list[i].elapsed_time, elapsed_time);\n");
+      s4o.print("__step_list[i].state) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__step_list[i].elapsed_time = __time_add(");
+      print_variable_prefix();
+      s4o.print("__step_list[i].elapsed_time, elapsed_time);\n");
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n");
       s4o.indent_left();
@@ -625,38 +659,38 @@
       s4o.print(s4o.indent_spaces + "// Actions initialisation\n");
       s4o.print(s4o.indent_spaces + "for (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].state = 0;\n");
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].set = 0;\n");
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].reset = 0;\n");
+      s4o.print("__nb_actions; i++) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].state = 0;\n");
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].set = 0;\n");
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].reset = 0;\n");
       s4o.print(s4o.indent_spaces + "if (");
       s4o.print("__gt_TIME(2, ");
       print_variable_prefix();
-      s4o.print("action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].set_remaining_time = __time_sub(");
-      print_variable_prefix();
-      s4o.print("action_list[i].set_remaining_time, elapsed_time);\n");
+      s4o.print("__action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].set_remaining_time = __time_sub(");
+      print_variable_prefix();
+      s4o.print("__action_list[i].set_remaining_time, elapsed_time);\n");
       s4o.print(s4o.indent_spaces + "if (");
       s4o.print("__le_TIME(2, ");
       print_variable_prefix();
-      s4o.print("action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].set_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n");
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].set = 1;\n");
+      s4o.print("__action_list[i].set_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].set_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n");
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].set = 1;\n");
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n");
       s4o.indent_left();
@@ -664,24 +698,24 @@
       s4o.print(s4o.indent_spaces + "if (");
       s4o.print("__gt_TIME(2, ");
       print_variable_prefix();
-      s4o.print("action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].reset_remaining_time = __time_sub(");
-      print_variable_prefix();
-      s4o.print("action_list[i].reset_remaining_time, elapsed_time);\n");
+      s4o.print("__action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].reset_remaining_time = __time_sub(");
+      print_variable_prefix();
+      s4o.print("__action_list[i].reset_remaining_time, elapsed_time);\n");
       s4o.print(s4o.indent_spaces + "if (");
       s4o.print("__le_TIME(2, ");
       print_variable_prefix();
-      s4o.print("action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n");
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].reset = 1;\n");
+      s4o.print("__action_list[i].reset_remaining_time, __time_to_timespec(1, 0, 0, 0, 0, 0))) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n");
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].reset = 1;\n");
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n");
       s4o.indent_left();
@@ -721,33 +755,33 @@
       s4o.print(s4o.indent_spaces + "// Actions state evaluation\n");
       s4o.print(s4o.indent_spaces + "for (i = 0; i < ");
       print_variable_prefix();
-      s4o.print("nb_actions; i++) {\n");
+      s4o.print("__nb_actions; i++) {\n");
       s4o.indent_right();
       s4o.print(s4o.indent_spaces + "if (");
       print_variable_prefix();
-      s4o.print("action_list[i].set) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].stored = 1;\n");
+      s4o.print("__action_list[i].set) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].stored = 1;\n");
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces + "if (");
       print_variable_prefix();
-      s4o.print("action_list[i].reset) {\n");
-      s4o.indent_right();
-      s4o.print(s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].set_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n" + s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n" + s4o.indent_spaces);
-      print_variable_prefix();
-      s4o.print("action_list[i].stored = 0;\n");
+      s4o.print("__action_list[i].reset) {\n");
+      s4o.indent_right();
+      s4o.print(s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].set_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n" + s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].reset_remaining_time = __time_to_timespec(1, 0, 0, 0, 0, 0);\n" + s4o.indent_spaces);
+      print_variable_prefix();
+      s4o.print("__action_list[i].stored = 0;\n");
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n" + s4o.indent_spaces);
       print_variable_prefix();
-      s4o.print("action_list[i].state |= ");
-      print_variable_prefix();
-      s4o.print("action_list[i].stored;\n");
+      s4o.print("__action_list[i].state |= ");
+      print_variable_prefix();
+      s4o.print("__action_list[i].stored;\n");
       s4o.indent_left();
       s4o.print(s4o.indent_spaces + "}\n\n");
       
--- a/stage4/generate_c/generate_c_sfcdecl.cc	Sun Sep 07 10:08:11 2008 +0200
+++ b/stage4/generate_c/generate_c_sfcdecl.cc	Mon Sep 08 10:33:37 2008 +0200
@@ -87,24 +87,29 @@
             symbol->elements[i]->accept(*this);
           
           /* steps table declaration */
-          s4o.print(s4o.indent_spaces + "STEP step_list[");
+          s4o.print(s4o.indent_spaces + "STEP __step_list[");
           s4o.print_integer(step_number);
           s4o.print("];\n");
-          s4o.print(s4o.indent_spaces + "UINT nb_steps;\n");
+          s4o.print(s4o.indent_spaces + "UINT __nb_steps;\n");
           
           /* actions table declaration */
-          s4o.print(s4o.indent_spaces + "ACTION action_list[");
+          s4o.print(s4o.indent_spaces + "ACTION __action_list[");
           s4o.print_integer(action_number);
           s4o.print("];\n");
-          s4o.print(s4o.indent_spaces + "UINT nb_actions;\n");
+          s4o.print(s4o.indent_spaces + "UINT __nb_actions;\n");
           
           /* transitions table declaration */
-          s4o.print(s4o.indent_spaces + "BOOL transition_list[");
+          s4o.print(s4o.indent_spaces + "BOOL __transition_list[");
           s4o.print_integer(transition_number);
           s4o.print("];\n");
           
+          /* transitions debug table declaration */
+          s4o.print(s4o.indent_spaces + "BOOL __debug_transition_list[");
+          s4o.print_integer(transition_number);
+          s4o.print("];\n");
+          
           /* last_ticktime declaration */
-          s4o.print(s4o.indent_spaces + "TIME lasttick_time;\n");
+          s4o.print(s4o.indent_spaces + "TIME __lasttick_time;\n");
           break;
         case sfcinit_sd:
           s4o.print(s4o.indent_spaces);
@@ -116,7 +121,7 @@
             symbol->elements[i]->accept(*this);
           s4o.print(s4o.indent_spaces);
           print_variable_prefix();
-          s4o.print("nb_steps = ");
+          s4o.print("__nb_steps = ");
           s4o.print_integer(step_number);
           s4o.print(";\n");
           step_number = 0;
@@ -126,11 +131,11 @@
           s4o.print(s4o.indent_spaces + "STEP temp_step = {0, 0, 0};\n");
           s4o.print(s4o.indent_spaces + "for(i = 0; i < ");
           print_variable_prefix();
-          s4o.print("nb_steps; i++) {\n");
+          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.print("__step_list[i] = temp_step;\n");
           s4o.indent_left();
           s4o.print(s4o.indent_spaces + "}\n");
           for(int i = 0; i < symbol->n; i++)
@@ -142,7 +147,7 @@
             symbol->elements[i]->accept(*this);
           s4o.print(s4o.indent_spaces);
           print_variable_prefix();
-          s4o.print("nb_actions = ");
+          s4o.print("__nb_actions = ");
           s4o.print_integer(action_number);
           s4o.print(";\n");
           action_number = 0;
@@ -152,17 +157,17 @@
           s4o.print(s4o.indent_spaces + "ACTION temp_action = {0, 0, 0, 0, 0, 0};\n");
           s4o.print(s4o.indent_spaces + "for(i = 0; i < ");
           print_variable_prefix();
-          s4o.print("nb_actions; i++) {\n");
+          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.print("__action_list[i] = temp_action;\n");
           s4o.indent_left();
           s4o.print(s4o.indent_spaces + "}\n");
           
           /* last_ticktime initialisation */
           print_variable_prefix();
-          s4o.print("lasttick_time = __CURRENT_TIME;\n");
+          s4o.print("__lasttick_time = __CURRENT_TIME;\n");
           break;
         case stepdef_sd:
           s4o.print("// Steps definitions\n");
@@ -203,7 +208,7 @@
         case sfcinit_sd:
           s4o.print(s4o.indent_spaces);
           print_variable_prefix();
-          s4o.print("step_list[");
+          s4o.print("__step_list[");
           s4o.print_integer(step_number);
           s4o.print("].state = 1;\n");
           step_number++;
--- a/stage4/generate_c/generate_var_list.cc	Sun Sep 07 10:08:11 2008 +0200
+++ b/stage4/generate_c/generate_var_list.cc	Mon Sep 08 10:33:37 2008 +0200
@@ -439,7 +439,7 @@
       symbol->step_name->accept(*this);
       s4o.print(".X;");
       print_symbol_list();
-      s4o.print("step_list[");
+      s4o.print("__step_list[");
       print_step_number();
       s4o.print("].state;STEP;\n");
       step_number++;
@@ -455,7 +455,7 @@
       symbol->step_name->accept(*this);
       s4o.print(".X;");
       print_symbol_list();
-      s4o.print("step_list[");
+      s4o.print("__step_list[");
       print_step_number();
       s4o.print("].state;STEP;\n");
       step_number++;
@@ -479,7 +479,7 @@
       symbol->to_steps->accept(*this);
       s4o.print(";");
       print_symbol_list();
-      s4o.print("transition_list[");
+      s4o.print("__debug_transition_list[");
       print_transition_number();
       s4o.print("];TRANSITION;\n");
       transition_number++;
@@ -518,7 +518,7 @@
       symbol->action_name->accept(*this);
       s4o.print(".Q;");
       print_symbol_list();
-      s4o.print("action_list[");
+      s4o.print("__action_list[");
       print_action_number();
       s4o.print("].state;ACTION;\n");
       action_number++;