Added double curly braces for pragma (kept single curly braces for compatibility). Added macro def and undef surrounding pragma to simplify user code. Moved useless comment from generated code back to code generator.
authorEdouard Tisserant
Fri, 19 Oct 2012 12:10:32 +0200
changeset 634 736b36a83548
parent 633 73b56dc69e61
child 636 dd57e63bdc3d
Added double curly braces for pragma (kept single curly braces for compatibility). Added macro def and undef surrounding pragma to simplify user code. Moved useless comment from generated code back to code generator.
stage1_2/iec_flex.ll
stage4/generate_c/generate_c.cc
stage4/generate_c/generate_c_base.cc
--- a/stage1_2/iec_flex.ll	Thu Sep 13 16:35:10 2012 +0200
+++ b/stage1_2/iec_flex.ll	Fri Oct 19 12:10:32 2012 +0200
@@ -513,7 +513,7 @@
 
 /* Any other pragma... */
 
-pragma "{"[^}]*"}"
+pragma "{"[^}]*"}"|"{{"([^}]|"}"[^}])*"}}"
 
 /* NOTE: this seemingly unnecessary complex definition is required
  *       to be able to eat up comments such as:
@@ -849,8 +849,9 @@
 	/* Any other pragma we find, we just pass it up to the syntax parser...   */
 	/* Note that the <body_state> state is exclusive, so we have to include it here too. */
 {pragma}	{/* return the pragmma without the enclosing '{' and '}' */
-		 yytext[strlen(yytext)-1] = '\0';
-		 yylval.ID=strdup(yytext+1);
+         uint cut = yytext[1]=='{'?2:1;
+		 yytext[strlen(yytext)-cut] = '\0';
+		 yylval.ID=strdup(yytext+cut);
 		 return pragma_token;
 		}
 <body_state>{pragma} {/* return the pragmma without the enclosing '{' and '}' */
--- a/stage4/generate_c/generate_c.cc	Thu Sep 13 16:35:10 2012 +0200
+++ b/stage4/generate_c/generate_c.cc	Fri Oct 19 12:10:32 2012 +0200
@@ -962,8 +962,7 @@
        * To work around this we introduce the useless goto.
        */
       s4o.print("\n");
-      s4o.print(s4o.indent_spaces);
-      s4o.print("/* to humour the compiler, we insert a goto */\n");
+      /* to humour the compiler, we insert a goto */
       s4o.print(s4o.indent_spaces);
       s4o.print("goto ");
       s4o.print(END_LABEL);
--- a/stage4/generate_c/generate_c_base.cc	Thu Sep 13 16:35:10 2012 +0200
+++ b/stage4/generate_c/generate_c_base.cc	Fri Oct 19 12:10:32 2012 +0200
@@ -260,7 +260,19 @@
     void *visit(disable_code_generation_pragma_c * symbol)  {s4o.disable_output(); return NULL;} 
 
     /* Do not use print_token() as it will change everything into uppercase */
-    void *visit(pragma_c *symbol) {return s4o.print(symbol->value);}
+    void *visit(pragma_c *symbol) {
+        s4o.print(s4o.indent_spaces);
+        s4o.print("#define GetFbVar(var,...) __GET_VAR(data__->var,__VA_ARGS__)\n");
+        s4o.print(s4o.indent_spaces);
+        s4o.print("#define SetFbVar(var,val,...) __SET_VAR(data__->,var,val,__VA_ARGS__)\n");
+        s4o.print(symbol->value);
+        s4o.print("\n");
+        s4o.print(s4o.indent_spaces);
+        s4o.print("#undef GetFbVar\n");
+        s4o.print(s4o.indent_spaces);
+        s4o.print("#undef SetFbVar\n");
+        return NULL;
+    }
 
 
 /***************************/