557 """ |
557 """ |
558 Return a Builder (compile C code into machine code) |
558 Return a Builder (compile C code into machine code) |
559 """ |
559 """ |
560 # Get target, module and class name |
560 # Get target, module and class name |
561 targetname = self.GetTarget().getcontent()["name"] |
561 targetname = self.GetTarget().getcontent()["name"] |
562 modulename = "targets." + targetname |
562 targetclass = targets.GetBuilder(targetname) |
563 classname = targetname + "_target" |
|
564 |
|
565 # Get module reference |
|
566 try : |
|
567 targetmodule = getattr(__import__(modulename), targetname) |
|
568 |
|
569 except Exception, msg: |
|
570 self.logger.write_error(_("Can't find module for target %s!\n")%targetname) |
|
571 self.logger.write_error(str(msg)) |
|
572 return None |
|
573 |
|
574 # Get target class |
|
575 targetclass = getattr(targetmodule, classname) |
|
576 |
563 |
577 # if target already |
564 # if target already |
578 if self._builder is None or not isinstance(self._builder,targetclass): |
565 if self._builder is None or not isinstance(self._builder,targetclass): |
579 # Get classname instance |
566 # Get classname instance |
580 self._builder = targetclass(self) |
567 self._builder = targetclass(self) |
693 Generate trace/debug code out of PLC variable list |
680 Generate trace/debug code out of PLC variable list |
694 """ |
681 """ |
695 self.GetIECProgramsAndVariables() |
682 self.GetIECProgramsAndVariables() |
696 |
683 |
697 # prepare debug code |
684 # prepare debug code |
698 debug_code = targets.code("plc_debug") % { |
685 debug_code = targets.GetCode("plc_debug") % { |
699 "buffer_size": reduce(lambda x, y: x + y, [DebugTypesSize.get(v["type"], 0) for v in self._VariablesList], 0), |
686 "buffer_size": reduce(lambda x, y: x + y, [DebugTypesSize.get(v["type"], 0) for v in self._VariablesList], 0), |
700 "programs_declarations": |
687 "programs_declarations": |
701 "\n".join(["extern %(type)s %(C_path)s;"%p for p in self._ProgramList]), |
688 "\n".join(["extern %(type)s %(C_path)s;"%p for p in self._ProgramList]), |
702 "extern_variables_declarations":"\n".join([ |
689 "extern_variables_declarations":"\n".join([ |
703 {"EXT":"extern __IEC_%(type)s_p %(C_path)s;", |
690 {"EXT":"extern __IEC_%(type)s_p %(C_path)s;", |
735 locstrs = map(lambda x:"_".join(map(str,x)), |
722 locstrs = map(lambda x:"_".join(map(str,x)), |
736 [loc for loc,Cfiles,DoCalls in self.LocationCFilesAndCFLAGS if loc and DoCalls]) |
723 [loc for loc,Cfiles,DoCalls in self.LocationCFilesAndCFLAGS if loc and DoCalls]) |
737 |
724 |
738 # Generate main, based on template |
725 # Generate main, based on template |
739 if not self.BeremizRoot.getDisable_Extensions(): |
726 if not self.BeremizRoot.getDisable_Extensions(): |
740 plc_main_code = targets.code("plc_common_main") % { |
727 plc_main_code = targets.GetCode("plc_common_main") % { |
741 "calls_prototypes":"\n".join([( |
728 "calls_prototypes":"\n".join([( |
742 "int __init_%(s)s(int argc,char **argv);\n"+ |
729 "int __init_%(s)s(int argc,char **argv);\n"+ |
743 "void __cleanup_%(s)s(void);\n"+ |
730 "void __cleanup_%(s)s(void);\n"+ |
744 "void __retrieve_%(s)s(void);\n"+ |
731 "void __retrieve_%(s)s(void);\n"+ |
745 "void __publish_%(s)s(void);")%{'s':locstr} for locstr in locstrs]), |
732 "void __publish_%(s)s(void);")%{'s':locstr} for locstr in locstrs]), |
755 "cleanup_calls":"\n ".join([ |
742 "cleanup_calls":"\n ".join([ |
756 "if(init_level >= %d) "%i+ |
743 "if(init_level >= %d) "%i+ |
757 "__cleanup_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]) |
744 "__cleanup_%s();"%locstrs[i-1] for i in xrange(len(locstrs), 0, -1)]) |
758 } |
745 } |
759 else: |
746 else: |
760 plc_main_code = targets.code("plc_common_main") % { |
747 plc_main_code = targets.GetCode("plc_common_main") % { |
761 "calls_prototypes":"\n", |
748 "calls_prototypes":"\n", |
762 "retrieve_calls":"\n", |
749 "retrieve_calls":"\n", |
763 "publish_calls":"\n", |
750 "publish_calls":"\n", |
764 "init_calls":"\n", |
751 "init_calls":"\n", |
765 "cleanup_calls":"\n" |
752 "cleanup_calls":"\n" |
766 } |
753 } |
767 plc_main_code += targets.targetcode(self.GetTarget().getcontent()["name"]) |
754 plc_main_code += targets.GetTargetCode(self.GetTarget().getcontent()["name"]) |
768 return plc_main_code |
755 return plc_main_code |
769 |
756 |
770 |
757 |
771 def _Build(self): |
758 def _Build(self): |
772 """ |
759 """ |