diff -r 5dd92bd6e6e5 -r b03f586547c9 LPCBeremiz.py --- a/LPCBeremiz.py Thu Jun 03 17:26:47 2010 +0200 +++ b/LPCBeremiz.py Fri Jun 04 09:02:22 2010 +0200 @@ -97,6 +97,15 @@ children.append(child) return children +def _GetVariables(module): + variables = [] + for child in module["children"]: + if child["type"] in [LOCATION_GROUP, LOCATION_MODULE]: + variables.extend(_GetVariables(child)) + else: + variables.append(child) + return variables + def _GetLastModuleGroup(module): group = module for child in module["children"]: @@ -136,14 +145,13 @@ #include "iec_std_lib.h" #endif -%(declare_code)s - /* LPCBus plugin user variables definition */ %(var_decl)s /* LPCBus plugin functions */ int __init_%(location_str)s(int argc,char **argv) { +%(declare_code)s return 0; } @@ -153,12 +161,12 @@ void __retrieve_%(location_str)s(void) { - %(retrieve_code)s +%(retrieve_code)s } void __publish_%(location_str)s(void) { - %(publish_code)s +%(publish_code)s } """ @@ -285,6 +293,10 @@ "publish_code": "", } + for variable in _GetVariables(self): + if variable["declare"] != "": + code_str["declare_code"] += " %s\n" % variable["declare"] + # Adding variables vars = [] self.ResetUsedLocations() @@ -310,7 +322,6 @@ self.AddUsedLocation(location["LOC"]) vars.append({"location": location["NAME"], "Type": variable["IEC_type"], - "Declare": variable["declare"], "Retrieve": variable["retrieve"], "Publish": variable["publish"], }) @@ -322,12 +333,10 @@ prefix = "IEC_" code_str["var_decl"] += "%s%s beremiz%s;\n"%(prefix, var["Type"], var["location"]) code_str["var_decl"] += "%s%s *%s = &beremiz%s;\n"%(prefix, var["Type"], var["location"], var["location"]) - if var["Declare"] != "": - code_str["declare_code"] += var["Declare"] + "\n" if var["Retrieve"] != "": - code_str["retrieve_code"] += var["Retrieve"] % ("*" + var["location"]) + "\n" + code_str["retrieve_code"] += " " + var["Retrieve"] % ("*" + var["location"]) + "\n" if var["Publish"] != "": - code_str["publish_code"] += var["Publish"] % ("*" + var["location"]) + "\n" + code_str["publish_code"] += " " + var["Publish"] % ("*" + var["location"]) + "\n" Gen_Module_path = os.path.join(buildpath, "Module_%s.c"%location_str) module = open(Gen_Module_path,'w')