ProjectController.py
changeset 985 cd8dadcef426
parent 978 3290eff761f1
child 992 72ee7f3e3cf3
equal deleted inserted replaced
984:2d03056993f6 985:cd8dadcef426
   775                 "VAR":"        return %(type)s_ENUM;\n"}[v["vartype"]]%v
   775                 "VAR":"        return %(type)s_ENUM;\n"}[v["vartype"]]%v
   776                 for v in self._VariablesList if v["vartype"] != "FB" and v["type"] in DebugTypesSize ])}
   776                 for v in self._VariablesList if v["vartype"] != "FB" and v["type"] in DebugTypesSize ])}
   777         
   777         
   778         return debug_code
   778         return debug_code
   779         
   779         
   780     def Generate_plc_common_main(self):
   780     def Generate_plc_main(self):
   781         """
   781         """
   782         Use confnodes layout given in LocationCFilesAndCFLAGS to
   782         Use confnodes layout given in LocationCFilesAndCFLAGS to
   783         generate glue code that dispatch calls to all confnodes
   783         generate glue code that dispatch calls to all confnodes
   784         """
   784         """
   785         # filter location that are related to code that will be called
   785         # filter location that are related to code that will be called
   787         locstrs = map(lambda x:"_".join(map(str,x)),
   787         locstrs = map(lambda x:"_".join(map(str,x)),
   788            [loc for loc,Cfiles,DoCalls in self.LocationCFilesAndCFLAGS if loc and DoCalls])
   788            [loc for loc,Cfiles,DoCalls in self.LocationCFilesAndCFLAGS if loc and DoCalls])
   789 
   789 
   790         # Generate main, based on template
   790         # Generate main, based on template
   791         if not self.BeremizRoot.getDisable_Extensions():
   791         if not self.BeremizRoot.getDisable_Extensions():
   792             plc_main_code = targets.GetCode("plc_common_main") % {
   792             plc_main_code = targets.GetCode("plc_main_head") % {
   793                 "calls_prototypes":"\n".join([(
   793                 "calls_prototypes":"\n".join([(
   794                       "int __init_%(s)s(int argc,char **argv);\n"+
   794                       "int __init_%(s)s(int argc,char **argv);\n"+
   795                       "void __cleanup_%(s)s(void);\n"+
   795                       "void __cleanup_%(s)s(void);\n"+
   796                       "void __retrieve_%(s)s(void);\n"+
   796                       "void __retrieve_%(s)s(void);\n"+
   797                       "void __publish_%(s)s(void);")%{'s':locstr} for locstr in locstrs]),
   797                       "void __publish_%(s)s(void);")%{'s':locstr} for locstr in locstrs]),
   807                 "cleanup_calls":"\n    ".join([
   807                 "cleanup_calls":"\n    ".join([
   808                       "if(init_level >= %d) "%i+
   808                       "if(init_level >= %d) "%i+
   809                       "__cleanup_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)])
   809                       "__cleanup_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)])
   810                 }
   810                 }
   811         else:
   811         else:
   812             plc_main_code = targets.GetCode("plc_common_main") % {
   812             plc_main_code = targets.GetCode("plc_main_head") % {
   813                 "calls_prototypes":"\n",
   813                 "calls_prototypes":"\n",
   814                 "retrieve_calls":"\n",
   814                 "retrieve_calls":"\n",
   815                 "publish_calls":"\n",
   815                 "publish_calls":"\n",
   816                 "init_calls":"\n",
   816                 "init_calls":"\n",
   817                 "cleanup_calls":"\n"
   817                 "cleanup_calls":"\n"
   818                 }
   818                 }
   819         plc_main_code += targets.GetTargetCode(self.GetTarget().getcontent()["name"])
   819         plc_main_code += targets.GetTargetCode(self.GetTarget().getcontent()["name"])
       
   820         plc_main_code += targets.GetCode("plc_main_tail")
   820         return plc_main_code
   821         return plc_main_code
   821 
   822 
   822         
   823         
   823     def _Build(self):
   824     def _Build(self):
   824         """
   825         """
   895         # files are stacked at the beginning, as files of confnode tree root
   896         # files are stacked at the beginning, as files of confnode tree root
   896         for generator, filename, name in [
   897         for generator, filename, name in [
   897            # debugger code
   898            # debugger code
   898            (self.Generate_plc_debugger, "plc_debugger.c", "Debugger"),
   899            (self.Generate_plc_debugger, "plc_debugger.c", "Debugger"),
   899            # init/cleanup/retrieve/publish, run and align code
   900            # init/cleanup/retrieve/publish, run and align code
   900            (self.Generate_plc_common_main,"plc_common_main.c","Common runtime")]:
   901            (self.Generate_plc_main,"plc_main.c","Common runtime")]:
   901             try:
   902             try:
   902                 # Do generate
   903                 # Do generate
   903                 code = generator()
   904                 code = generator()
   904                 if code is None:
   905                 if code is None:
   905                      raise
   906                      raise