Adding support for forcing global without perturbation from setting external
authorlaurent
Fri, 11 Dec 2009 12:53:54 +0100
changeset 231 b8527b0abe75
parent 230 816846a8d66b
child 232 29ab33687333
Adding support for forcing global without perturbation from setting external
lib/accessor.h
stage4/generate_c/generate_c.cc
stage4/generate_c/generate_c_il.cc
stage4/generate_c/generate_c_inlinefcall.cc
stage4/generate_c/generate_c_st.cc
--- a/lib/accessor.h	Wed Dec 09 16:45:27 2009 +0100
+++ b/lib/accessor.h	Fri Dec 11 12:53:54 2009 +0100
@@ -7,7 +7,11 @@
 	__IEC_##type##_t name;
 #define __DECLARE_GLOBAL(type, resource, name)\
 	__IEC_##type##_t resource##__##name;\
-	static __IEC_##type##_t *GLOBAL__##name = &resource##__##name;
+	static __IEC_##type##_t *GLOBAL__##name = &resource##__##name;\
+	void __SET_GLOBAL_##name(type value) {\
+		if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\
+			(*GLOBAL__##name).value = value;\
+	}
 #define __DECLARE_GLOBAL_LOCATION(type, location)\
 	extern type *location;
 #define __DECLARE_GLOBAL_LOCATED(type, resource, name)\
@@ -60,8 +64,11 @@
 // variable setting macros
 #define __SET_VAR(name, new_value, ...)\
 	if (!(name.flags & __IEC_FORCE_FLAG)) name.value __VA_ARGS__ = new_value
-#define __SET_EXTERNAL(name, new_value, ...)\
-	if (!(name.flags & __IEC_FORCE_FLAG)) *(name.value) __VA_ARGS__ = new_value
+#define __SET_EXTERNAL(global, name, new_value)\
+	if (!(name.flags & __IEC_FORCE_FLAG))\
+		__SET_GLOBAL_##global(new_value)
+#define __SET_COMPLEX_EXTERNAL(name, new_value, ...)\
+	*(name.value) __VA_ARGS__ = new_value
 #define __SET_LOCATED(name, new_value, ...)\
 	if (!(name.flags & __IEC_FORCE_FLAG)) *(name.value) __VA_ARGS__ = new_value
 
--- a/stage4/generate_c/generate_c.cc	Wed Dec 09 16:45:27 2009 +0100
+++ b/stage4/generate_c/generate_c.cc	Fri Dec 11 12:53:54 2009 +0100
@@ -151,6 +151,7 @@
 /* Variable setter symbol for accessor macros */
 #define SET_VAR "__SET_VAR"
 #define SET_EXTERNAL "__SET_EXTERNAL"
+#define SET_COMPLEX_EXTERNAL "__SET_COMPLEX_EXTERNAL"
 #define SET_LOCATED "__SET_LOCATED"
 
 
--- a/stage4/generate_c/generate_c_il.cc	Wed Dec 09 16:45:27 2009 +0100
+++ b/stage4/generate_c/generate_c_il.cc	Fri Dec 11 12:53:54 2009 +0100
@@ -461,13 +461,27 @@
     		symbol_c* fb_value = NULL,
     		bool negative = false) {
       unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
-      if (vartype == search_var_instance_decl_c::external_vt)
-        s4o.print(SET_EXTERNAL);
-      else if (vartype == search_var_instance_decl_c::located_vt)
-        s4o.print(SET_LOCATED);
-      else
-        s4o.print(SET_VAR);
-      s4o.print("(");
+      if (vartype == search_var_instance_decl_c::external_vt) {
+        symbolic_variable_c *variable = dynamic_cast<symbolic_variable_c *>(symbol);
+        /* TODO Find a solution for forcing global complex variables */
+        if (variable != NULL) {
+          s4o.print(SET_EXTERNAL);
+          s4o.print("(");
+          variable->var_name->accept(*this);
+          s4o.print(",");
+        }
+        else {
+          s4o.print(SET_COMPLEX_EXTERNAL);
+          s4o.print("(");
+        }
+      }
+      else {
+        if (vartype == search_var_instance_decl_c::located_vt)
+          s4o.print(SET_LOCATED);
+        else
+          s4o.print(SET_VAR);
+        s4o.print("(");
+      }
 
       if (fb_symbol != NULL) {
         print_variable_prefix();
--- a/stage4/generate_c/generate_c_inlinefcall.cc	Wed Dec 09 16:45:27 2009 +0100
+++ b/stage4/generate_c/generate_c_inlinefcall.cc	Fri Dec 11 12:53:54 2009 +0100
@@ -207,13 +207,27 @@
     		symbol_c* type,
     		symbol_c* value) {
       unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
-      if (vartype == search_var_instance_decl_c::external_vt)
-        s4o.print(SET_EXTERNAL);
-      else if (vartype == search_var_instance_decl_c::located_vt)
-        s4o.print(SET_LOCATED);
-      else
-        s4o.print(SET_VAR);
-      s4o.print("(");
+      if (vartype == search_var_instance_decl_c::external_vt) {
+        symbolic_variable_c *variable = dynamic_cast<symbolic_variable_c *>(symbol);
+        /* TODO Find a solution for forcing global complex variables */
+        if (variable != NULL) {
+          s4o.print(SET_EXTERNAL);
+          s4o.print("(");
+          variable->var_name->accept(*this);
+          s4o.print(",");
+        }
+        else {
+          s4o.print(SET_COMPLEX_EXTERNAL);
+          s4o.print("(");
+        }
+      }
+      else {
+        if (vartype == search_var_instance_decl_c::located_vt)
+          s4o.print(SET_LOCATED);
+        else
+          s4o.print(SET_VAR);
+        s4o.print("(");
+      }
 
       wanted_variablegeneration = complextype_base_vg;
       symbol->accept(*this);
--- a/stage4/generate_c/generate_c_st.cc	Wed Dec 09 16:45:27 2009 +0100
+++ b/stage4/generate_c/generate_c_st.cc	Fri Dec 11 12:53:54 2009 +0100
@@ -140,13 +140,27 @@
 		symbol_c* fb_symbol = NULL,
 		symbol_c* fb_value = NULL) {
   unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
-  if (vartype == search_var_instance_decl_c::external_vt)
-    s4o.print(SET_EXTERNAL);
-  else if (vartype == search_var_instance_decl_c::located_vt)
-    s4o.print(SET_LOCATED);
-  else
-    s4o.print(SET_VAR);
-  s4o.print("(");
+  if (vartype == search_var_instance_decl_c::external_vt) {
+    symbolic_variable_c *variable = dynamic_cast<symbolic_variable_c *>(symbol);
+    /* TODO Find a solution for forcing global complex variables */
+    if (variable != NULL) {
+      s4o.print(SET_EXTERNAL);
+      s4o.print("(");
+      variable->var_name->accept(*this);
+      s4o.print(",");
+    }
+    else {
+      s4o.print(SET_COMPLEX_EXTERNAL);
+      s4o.print("(");
+    }
+  }
+  else {
+    if (vartype == search_var_instance_decl_c::located_vt)
+      s4o.print(SET_LOCATED);
+    else
+      s4o.print(SET_VAR);
+    s4o.print("(");
+  }
 
   if (fb_symbol != NULL) {
     print_variable_prefix();