# HG changeset patch # User Laurent Bessard # Date 1347318324 -7200 # Node ID fe0d516fe291bca012092ed2fa2a404d67ade046 # Parent e7caa7d32ef5bdfcf30b0298d4fe525e1a201d83 Fix bug in SFC generated code. Action state was declared in the list of variables to debug, but wasn't stored using structure with flags. This error had side effects that makes Beremiz debug crash. diff -r e7caa7d32ef5 -r fe0d516fe291 lib/iec_types_all.h --- a/lib/iec_types_all.h Tue Sep 04 18:02:06 2012 +0200 +++ b/lib/iec_types_all.h Tue Sep 11 01:05:24 2012 +0200 @@ -131,7 +131,7 @@ typedef struct { BOOL stored; // action storing state. 0 : not stored, 1: stored - BOOL state; // current action state. 0 : inative, 1: active + __IEC_BOOL_t state; // current action state. 0 : inative, 1: active BOOL set; // set have been requested (reset each time the body is evaluated) BOOL reset; // reset have been requested (reset each time the body is evaluated) TIME set_remaining_time; // time before set will be requested diff -r e7caa7d32ef5 -r fe0d516fe291 stage4/generate_c/generate_c_sfc.cc --- a/stage4/generate_c/generate_c_sfc.cc Tue Sep 04 18:02:06 2012 +0200 +++ b/stage4/generate_c/generate_c_sfc.cc Tue Sep 11 01:05:24 2012 +0200 @@ -398,11 +398,13 @@ switch (wanted_sfcgeneration) { case actionbody_sg: s4o.print(s4o.indent_spaces + "if("); + s4o.print(GET_VAR); + s4o.print("("); print_variable_prefix(); s4o.print("__action_list["); s4o.print(SFC_STEP_ACTION_PREFIX); symbol->action_name->accept(*this); - s4o.print("].state) {\n"); + s4o.print("].state)) {\n"); s4o.indent_right(); // generate action code @@ -497,8 +499,10 @@ s4o.print(")) {\n"); s4o.indent_right(); s4o.print(s4o.indent_spaces); - print_action_argument(symbol->action_name, "state"); - s4o.print(" = 1;\n"); + s4o.print(SET_VAR); + s4o.print("("); + print_action_argument(symbol->action_name, "state", true); + s4o.print(",1);\n"); s4o.indent_left(); s4o.print(s4o.indent_spaces + "}"); } @@ -545,8 +549,10 @@ if (strcmp(qualifier, "N") == 0 || strcmp(qualifier, "P") == 0 || strcmp(qualifier, "D") == 0 || strcmp(qualifier, "L") == 0 || strcmp(qualifier, "P0") == 0 || strcmp(qualifier, "P1") == 0) { - print_action_argument(current_action, "state"); - s4o.print(" = 1;\n"); + s4o.print(SET_VAR); + s4o.print("("); + print_action_argument(current_action, "state", true); + s4o.print(",1);\n"); } if (strcmp(qualifier, "S") == 0 || strcmp(qualifier, "SL") == 0) { print_action_argument(current_action, "set"); @@ -719,8 +725,10 @@ 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(SET_VAR); + s4o.print("("); + 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"); @@ -839,10 +847,16 @@ 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(SET_VAR); + s4o.print("("); + print_variable_prefix(); + s4o.print(",__action_list[i].state,"); + s4o.print(GET_VAR); + s4o.print("("); + print_variable_prefix(); + 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"); @@ -867,11 +881,13 @@ s4o.print(","); pt->symbol->accept(*this); s4o.print(","); + s4o.print(GET_VAR); + s4o.print("("); print_variable_prefix(); s4o.print("__action_list["); s4o.print(SFC_STEP_ACTION_PREFIX); pt->symbol->accept(*this); - s4o.print("].state);\n"); + s4o.print("].state));\n"); } } } diff -r e7caa7d32ef5 -r fe0d516fe291 stage4/generate_c/generate_c_sfcdecl.cc --- a/stage4/generate_c/generate_c_sfcdecl.cc Tue Sep 04 18:02:06 2012 +0200 +++ b/stage4/generate_c/generate_c_sfcdecl.cc Tue Sep 11 01:05:24 2012 +0200 @@ -156,7 +156,7 @@ wanted_sfcdeclaration = sfcinit_sd; /* actions table initialisation */ - s4o.print(s4o.indent_spaces + "static const ACTION temp_action = {0, 0, 0, 0, {0, 0}, {0, 0}};\n"); + s4o.print(s4o.indent_spaces + "static const ACTION temp_action = {0, {0, 0}, 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");