Now, LOCATED variables do declare extern C variables the same way EXTERNAL variables do.
--- a/stage4/generate_cc/generate_cc.cc Fri May 11 16:29:22 2007 +0200
+++ b/stage4/generate_cc/generate_cc.cc Mon May 14 09:48:25 2007 +0200
@@ -564,6 +564,7 @@
generate_cc_vardecl_c::output_vt |
generate_cc_vardecl_c::inoutput_vt |
generate_cc_vardecl_c::private_vt |
+ generate_cc_vardecl_c::located_vt |
generate_cc_vardecl_c::external_vt);
vardecl->print(symbol->var_declarations, NULL, FB_FUNCTION_PARAM"->");
delete vardecl;
@@ -703,6 +704,7 @@
generate_cc_vardecl_c::output_vt |
generate_cc_vardecl_c::inoutput_vt |
generate_cc_vardecl_c::private_vt |
+ generate_cc_vardecl_c::located_vt |
generate_cc_vardecl_c::external_vt);
vardecl->print(symbol->var_declarations, NULL, FB_FUNCTION_PARAM"->");
delete vardecl;
--- a/stage4/generate_cc/generate_cc_base.cc Fri May 11 16:29:22 2007 +0200
+++ b/stage4/generate_cc/generate_cc_base.cc Mon May 14 09:48:25 2007 +0200
@@ -537,7 +537,7 @@
void *visit(direct_variable_c *symbol) {
TRACE("direct_variable_c");
/* Do not use print_token() as it will change everything into uppercase */
- return s4o.print(symbol->value);
+ return s4o.printlocation(symbol->value);
}
--- a/stage4/generate_cc/generate_cc_st.cc Fri May 11 16:29:22 2007 +0200
+++ b/stage4/generate_cc/generate_cc_st.cc Mon May 14 09:48:25 2007 +0200
@@ -131,7 +131,7 @@
/*********************/
void *visit(symbolic_variable_c *symbol) {
unsigned int vartype = search_varfb_instance_type->get_vartype(symbol);
- if (vartype == search_var_instance_decl_c::external_vt) {
+ if (vartype == search_var_instance_decl_c::external_vt || vartype == search_var_instance_decl_c::located_vt) {
s4o.print("*(");
generate_cc_base_c::visit(symbol);
s4o.print(")");
--- a/stage4/generate_cc/generate_cc_typedecl.cc Fri May 11 16:29:22 2007 +0200
+++ b/stage4/generate_cc/generate_cc_typedecl.cc Mon May 14 09:48:25 2007 +0200
@@ -370,7 +370,7 @@
TRACE("direct_variable_c");
/* Do not use print_token() as it will change everything into uppercase */
if (strlen(symbol->value) == 0) ERROR;
- return s4o.print(symbol->value + 1);
+ return s4o.printlocation(symbol->value + 1);
}
--- a/stage4/generate_cc/generate_cc_vardecl.cc Fri May 11 16:29:22 2007 +0200
+++ b/stage4/generate_cc/generate_cc_vardecl.cc Mon May 14 09:48:25 2007 +0200
@@ -722,20 +722,9 @@
/* now to produce the c equivalent... */
switch(wanted_varformat) {
case local_vf:
- /* NOTE: located variables must be declared static, as the connection to the
- * MatPLC point must be initialised at program startup, and not whenever
- * a new function block is instantiated!
- * Since they always refer to the same MatPLC point, it is OK to let several
- * function block instances share the same located variable!
- * If the IEC compiler maps IEC tasks to Linux threads, with tasks/threads
- * running simultaneously, then we must make sure the MatPLC IO library
- * is thread safe!
- */
- s4o.print(s4o.indent_spaces + "static __plc_pt_c<");
+ s4o.print(s4o.indent_spaces);
this->current_var_type_symbol->accept(*this);
- s4o.print(", 8*sizeof(");
- this->current_var_type_symbol->accept(*this);
- s4o.print(")> ");
+ s4o.print(" *");
if (symbol->variable_name != NULL)
symbol->variable_name->accept(*this);
else
@@ -743,6 +732,21 @@
s4o.print(";\n");
break;
+ case constructorinit_vf:
+ s4o.print(nv->get());
+ s4o.print("{extern ");
+ symbol->location->accept(*this);
+ s4o.print(";");
+ print_variable_prefix();
+ if (symbol->variable_name != NULL)
+ symbol->variable_name->accept(*this);
+ else
+ symbol->location->accept(*this);
+ s4o.print(" = &");
+ symbol->location->accept(*this);
+ s4o.print(";}");
+ break;
+
case globalinit_vf:
s4o.print(s4o.indent_spaces + "__plc_pt_c<");
this->current_var_type_symbol->accept(*this);
@@ -858,7 +862,7 @@
s4o.print(";");
print_variable_prefix();
symbol->global_var_name->accept(*this);
- s4o.print(" = &");
+ s4o.print(" = ");
symbol->global_var_name->accept(*this);
s4o.print(";}");
break;
@@ -1441,8 +1445,10 @@
function_param_iterator_c::param_direction_t param_direction = fp_iterator.param_direction();
+#if 0
/* Get the value from a foo(<param_name> = <param_value>) style call */
symbol_c *param_value = function_call_param_iterator.search(param_name);
+#endif
switch (param_direction) {
case function_param_iterator_c::direction_in:
--- a/stage4/generate_cc/search_var_instance_decl.cc Fri May 11 16:29:22 2007 +0200
+++ b/stage4/generate_cc/search_var_instance_decl.cc Mon May 14 09:48:25 2007 +0200
@@ -151,7 +151,7 @@
if (res == NULL) {
current_vartype = none_vt;
}
- return NULL;
+ return res;
}
/* VAR RETAIN var_init_decl_list END_VAR */
@@ -161,7 +161,7 @@
if (res == NULL) {
current_vartype = none_vt;
}
- return NULL;
+ return res;
}
/* VAR [CONSTANT|RETAIN|NON_RETAIN] located_var_decl_list END_VAR */
@@ -173,7 +173,7 @@
if (res == NULL) {
current_vartype = none_vt;
}
- return NULL;
+ return res;
}
/*| VAR_EXTERNAL [CONSTANT] external_declaration_list END_VAR */
@@ -185,7 +185,7 @@
if (res == NULL) {
current_vartype = none_vt;
}
- return NULL;
+ return res;
}
/* var1_list is one of the following...
--- a/stage4/stage4.cc Fri May 11 16:29:22 2007 +0200
+++ b/stage4/stage4.cc Mon May 14 09:48:25 2007 +0200
@@ -79,6 +79,15 @@
return NULL;
}
+void *stage4out_c::printlocation(const char *str) {
+ std::cout << "__";
+ for (int i = 0; str[i] != '\0'; i++)
+ if(str[i] == '.')
+ std::cout << '_';
+ else
+ std::cout << (unsigned char)toupper(str[i]);
+ return NULL;
+}
void *stage4out_c::print(std::string str) {
std::cout << str;
@@ -100,7 +109,9 @@
#endif
return NULL;
}
-
+void *stage4out_c::printlocation(std::string str) {
+ printlocation(str.c_str());
+}
/***********************************************************************/
--- a/stage4/stage4.hh Fri May 11 16:29:22 2007 +0200
+++ b/stage4/stage4.hh Mon May 14 09:48:25 2007 +0200
@@ -49,6 +49,10 @@
void *printupper(const char *str);
void *printupper(std::string str);
+
+ void *printlocation(const char *str);
+ void *printlocation(std::string str);
+
};