--- a/stage4/generate_c/generate_c.cc Sat May 07 21:17:49 2016 +0100
+++ b/stage4/generate_c/generate_c.cc Sun May 08 20:01:15 2016 +0100
@@ -893,19 +893,28 @@
}
s4o.print(";\n\n");
- s4o.print(s4o.indent_spaces + "// Control execution\n");
- s4o.print(s4o.indent_spaces + "if (!EN) {\n");
- s4o.indent_right();
- s4o.print(s4o.indent_spaces + "if (__ENO != NULL) {\n");
- s4o.indent_right();
- s4o.print(s4o.indent_spaces + "*__ENO = __BOOL_LITERAL(FALSE);\n");
- s4o.indent_left();
- s4o.print(s4o.indent_spaces + "}\n");
- s4o.print(s4o.indent_spaces + "return ");
- symbol->derived_function_name->accept(print_base);
- s4o.print(";\n");
- s4o.indent_left();
- s4o.print(s4o.indent_spaces + "}\n");
+
+ // Only generate the code that controls the execution of the function's body if the
+ // function contains a declaration of both the EN and ENO variables
+ search_var_instance_decl_c search_var(symbol);
+ identifier_c en_var("EN");
+ identifier_c eno_var("ENO");
+ if ( (search_var.get_vartype(& en_var) == search_var_instance_decl_c::input_vt)
+ && (search_var.get_vartype(&eno_var) == search_var_instance_decl_c::output_vt)) {
+ s4o.print(s4o.indent_spaces + "// Control execution\n");
+ s4o.print(s4o.indent_spaces + "if (!EN) {\n");
+ s4o.indent_right();
+ s4o.print(s4o.indent_spaces + "if (__ENO != NULL) {\n");
+ s4o.indent_right();
+ s4o.print(s4o.indent_spaces + "*__ENO = __BOOL_LITERAL(FALSE);\n");
+ s4o.indent_left();
+ s4o.print(s4o.indent_spaces + "}\n");
+ s4o.print(s4o.indent_spaces + "return ");
+ symbol->derived_function_name->accept(print_base);
+ s4o.print(";\n");
+ s4o.indent_left();
+ s4o.print(s4o.indent_spaces + "}\n");
+ }
/* (C) Function body */
generate_c_SFC_IL_ST_c generate_c_code(&s4o, symbol->derived_function_name, symbol);
@@ -1071,31 +1080,40 @@
} else {
s4o.print(" {\n");
s4o.indent_right();
-
- s4o.print(s4o.indent_spaces + "// Control execution\n");
- s4o.print(s4o.indent_spaces + "if (!");
- s4o.print(GET_VAR);
- s4o.print("(");
- s4o.print(FB_FUNCTION_PARAM);
- s4o.print("->EN)) {\n");
- s4o.indent_right();
- s4o.print(s4o.indent_spaces);
- s4o.print(SET_VAR);
- s4o.print("(");
- s4o.print(FB_FUNCTION_PARAM);
- s4o.print("->,ENO,,__BOOL_LITERAL(FALSE));\n");
- s4o.print(s4o.indent_spaces + "return;\n");
- s4o.indent_left();
- s4o.print(s4o.indent_spaces + "}\n");
- s4o.print(s4o.indent_spaces + "else {\n");
- s4o.indent_right();
- s4o.print(s4o.indent_spaces);
- s4o.print(SET_VAR);
- s4o.print("(");
- s4o.print(FB_FUNCTION_PARAM);
- s4o.print("->,ENO,,__BOOL_LITERAL(TRUE));\n");
- s4o.indent_left();
- s4o.print(s4o.indent_spaces + "}\n");
+
+ // Only generate the code that controls the execution of the function's body if the
+ // function contains a declaration of both the EN and ENO variables
+ search_var_instance_decl_c search_var(symbol);
+ identifier_c en_var("EN");
+ identifier_c eno_var("ENO");
+ if ( (search_var.get_vartype(& en_var) == search_var_instance_decl_c::input_vt)
+ && (search_var.get_vartype(&eno_var) == search_var_instance_decl_c::output_vt)) {
+
+ s4o.print(s4o.indent_spaces + "// Control execution\n");
+ s4o.print(s4o.indent_spaces + "if (!");
+ s4o.print(GET_VAR);
+ s4o.print("(");
+ s4o.print(FB_FUNCTION_PARAM);
+ s4o.print("->EN)) {\n");
+ s4o.indent_right();
+ s4o.print(s4o.indent_spaces);
+ s4o.print(SET_VAR);
+ s4o.print("(");
+ s4o.print(FB_FUNCTION_PARAM);
+ s4o.print("->,ENO,,__BOOL_LITERAL(FALSE));\n");
+ s4o.print(s4o.indent_spaces + "return;\n");
+ s4o.indent_left();
+ s4o.print(s4o.indent_spaces + "}\n");
+ s4o.print(s4o.indent_spaces + "else {\n");
+ s4o.indent_right();
+ s4o.print(s4o.indent_spaces);
+ s4o.print(SET_VAR);
+ s4o.print("(");
+ s4o.print(FB_FUNCTION_PARAM);
+ s4o.print("->,ENO,,__BOOL_LITERAL(TRUE));\n");
+ s4o.indent_left();
+ s4o.print(s4o.indent_spaces + "}\n");
+ }
/* (C.4) Initialize TEMP variables */
/* function body */
@@ -1380,6 +1398,15 @@
s4o.print("/* FILE GENERATED BY iec2c */\n");
s4o.print("/* Editing this file is not recommended... */\n");
s4o.print("/*******************************************/\n\n");
+
+ if (runtime_options.disable_implicit_en_eno) {
+ // If we are not generating the EN and ENO parameters for functions and FB,
+ // then make sure we use the standard library version compiled without these parameters too!
+ s4o.print("#ifndef DISABLE_EN_ENO_PARAMETERS\n");
+ s4o.print("#define DISABLE_EN_ENO_PARAMETERS\n");
+ s4o.print("#endif\n");
+ }
+
s4o.print("#include \"iec_std_lib.h\"\n\n");
s4o.print("#include \"accessor.h\"\n\n");
s4o.print("#include \"POUS.h\"\n\n");
@@ -1685,6 +1712,15 @@
s4o.print("/* FILE GENERATED BY iec2c */\n");
s4o.print("/* Editing this file is not recommended... */\n");
s4o.print("/*******************************************/\n\n");
+
+ if (runtime_options.disable_implicit_en_eno) {
+ // If we are not generating the EN and ENO parameters for functions and FB,
+ // then make sure we use the standard library version compiled without these parameters too!
+ s4o.print("#ifndef DISABLE_EN_ENO_PARAMETERS\n");
+ s4o.print("#define DISABLE_EN_ENO_PARAMETERS\n");
+ s4o.print("#endif\n");
+ }
+
s4o.print("#include \"iec_std_lib.h\"\n\n");
/* (A) resource declaration... */
@@ -2118,7 +2154,17 @@
/* B 0 - Programming Model */
/***************************/
void *visit(library_c *symbol) {
- pous_incl_s4o.print("#ifndef __POUS_H\n#define __POUS_H\n\n#include \"accessor.h\"\n#include \"iec_std_lib.h\"\n\n");
+ pous_incl_s4o.print("#ifndef __POUS_H\n#define __POUS_H\n\n");
+
+ if (runtime_options.disable_implicit_en_eno) {
+ // If we are not generating the EN and ENO parameters for functions and FB,
+ // then make sure we use the standard library version compiled without these parameters too!
+ pous_incl_s4o.print("#ifndef DISABLE_EN_ENO_PARAMETERS\n");
+ pous_incl_s4o.print("#define DISABLE_EN_ENO_PARAMETERS\n");
+ pous_incl_s4o.print("#endif\n");
+ }
+
+ pous_incl_s4o.print("#include \"accessor.h\"\n#include \"iec_std_lib.h\"\n\n");
for(int i = 0; i < symbol->n; i++) {
symbol->elements[i]->accept(*this);