Laurent@814: #!/usr/bin/env python Laurent@814: # -*- coding: utf-8 -*- Laurent@814: Laurent@814: #This file is part of PLCOpenEditor, a library implementing an IEC 61131-3 editor Laurent@814: #based on the plcopen standard. Laurent@814: # Laurent@814: #Copyright (C) 2007-2011: Edouard TISSERANT and Laurent BESSARD Laurent@814: # Laurent@814: #See COPYING file for copyrights details. Laurent@814: # Laurent@814: #This library is free software; you can redistribute it and/or Laurent@814: #modify it under the terms of the GNU General Public Laurent@814: #License as published by the Free Software Foundation; either Laurent@814: #version 2.1 of the License, or (at your option) any later version. Laurent@814: # Laurent@814: #This library is distributed in the hope that it will be useful, Laurent@814: #but WITHOUT ANY WARRANTY; without even the implied warranty of Laurent@814: #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Laurent@814: #General Public License for more details. Laurent@814: # Laurent@814: #You should have received a copy of the GNU General Public Laurent@814: #License along with this library; if not, write to the Free Software Laurent@814: #Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Laurent@814: Laurent@814: """ Laurent@814: THIS CODE GENARATES C++ CODE FOR IEC2C COMPILER Laurent@814: """ Laurent@814: Laurent@814: file_list = [ Laurent@814: ('absyntax_utils', 'function_type_decl','h' ), Laurent@814: ('absyntax_utils', 'get_function_type_decl','c' ), Laurent@814: ('absyntax_utils', 'search_type_code','c' ), Laurent@814: ('stage4/generate_c', 'st_code_gen','c' ), Laurent@814: ('stage4/generate_c', 'il_code_gen','c' ), Laurent@814: ('stage1_2', 'standard_function_names','c' ), Laurent@814: ('lib', 'iec_std_lib_generated','h' ) Laurent@814: ] Laurent@814: Laurent@814: # Get definitions Laurent@814: from plcopen.structures import * Laurent@814: Laurent@814: if len(sys.argv) != 2 : Laurent@814: print "Usage: " + sys.argv[0] + " path_name\n -> create files in path_name" Laurent@814: sys.exit(0) Laurent@814: Laurent@814: #import pprint Laurent@814: #pp = pprint.PrettyPrinter(indent=4) Laurent@814: Laurent@814: matiec_header = """/* Laurent@814: * Copyright (C) 2007-2011: Edouard TISSERANT and Laurent BESSARD Laurent@814: * Laurent@814: * See COPYING and COPYING.LESSER files for copyright details. Laurent@814: * Laurent@814: * This program is free software: you can redistribute it and/or modify Laurent@814: * it under the terms of the GNU General Public License as published by Laurent@814: * the Free Software Foundation, either version 3 of the License, or Laurent@814: * (at your option) any later version. Laurent@814: * Laurent@814: * This program is distributed in the hope that it will be useful, Laurent@814: * but WITHOUT ANY WARRANTY; without even the implied warranty of Laurent@814: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Laurent@814: * GNU General Public License for more details. Laurent@814: * Laurent@814: * You should have received a copy of the GNU General Public License Laurent@814: * along with this program. If not, see . Laurent@814: * Laurent@814: */ Laurent@814: Laurent@814: /**** Laurent@814: * IEC 61131-3 standard function library Laurent@814: * generated code, do not edit by hand Laurent@814: */ Laurent@814: Laurent@814: """ Laurent@814: Laurent@814: matiec_lesser_header = """/* Laurent@814: * Copyright (C) 2007-2011: Edouard TISSERANT and Laurent BESSARD Laurent@814: * Laurent@814: * See COPYING and COPYING.LESSER files for copyright details. Laurent@814: * Laurent@814: * This library is free software; you can redistribute it and/or Laurent@814: * modify it under the terms of the GNU Lesser General Public Laurent@814: * License as published by the Free Software Foundation; either Laurent@814: * version 3 of the License, or (at your option) any later version. Laurent@814: * Laurent@814: * This library is distributed in the hope that it will be useful, Laurent@814: * but WITHOUT ANY WARRANTY; without even the implied warranty of Laurent@814: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Laurent@814: * Lesser General Public License for more details. Laurent@814: * Laurent@814: * You should have received a copy of the GNU Lesser General Public License Laurent@814: * along with this library. If not, see . Laurent@814: * Laurent@814: */ Laurent@814: Laurent@814: /**** Laurent@814: * IEC 61131-3 standard function library Laurent@814: * generated code, do not edit by hand Laurent@814: */ Laurent@814: Laurent@814: """ Laurent@814: Laurent@814: def ANY_to_compiler_test_type_GEN(typename, paramname): Laurent@814: """ Laurent@814: Convert ANY_XXX IEC type declaration into IEC2C's generated type test. Laurent@814: This tests are defined in search_expression_type.cc Laurent@814: """ Laurent@814: return {"ANY" : "", Laurent@814: "ANY_BIT" : "if(%(paramname)s_type_symbol == NULL || search_expression_type->is_binary_type(%(paramname)s_type_symbol))", Laurent@814: "ANY_NBIT" : "if(%(paramname)s_type_symbol == NULL || search_expression_type->is_nbinary_type(%(paramname)s_type_symbol))", Laurent@814: "ANY_NUM" : "if(%(paramname)s_type_symbol == NULL || search_expression_type->is_num_type(%(paramname)s_type_symbol))", Laurent@814: "ANY_REAL" : "if(%(paramname)s_type_symbol == NULL || search_expression_type->is_real_type(%(paramname)s_type_symbol))", Laurent@814: "ANY_INT" : "if(%(paramname)s_type_symbol == NULL || search_expression_type->is_integer_type(%(paramname)s_type_symbol))" Laurent@814: }.get(typename, Laurent@814: #"if (typeid(*last_type_symbol) == typeid(%(typename)s_type_name_c))")%{ Laurent@814: "if(%(paramname)s_type_symbol == NULL || search_expression_type->is_same_type(&search_constant_type_c::%(typename)s_type_name, last_type_symbol))")%{ Laurent@814: "paramname" : paramname, "typename": typename.lower()} Laurent@814: Laurent@814: def recurse_and_indent(fdecls, indent, do_type_search_only = False, do_il = False): Laurent@814: """ Laurent@814: This function generate visit(function_invocation) code for Laurent@814: - ST code generator Laurent@814: - IL code generator Laurent@814: - search_expression_type class for ST Laurent@814: - search_expression_type class for IL Laurent@814: Laurent@814: Input data is a Laurent@814: "{fname : {IN[0]paramname : {IN[0]paramtype : {IN[1]paraname : {IN[1]paramtype : {... : {IN[N]paraname : {IN[N]paramtype : (fdecl,)}}}}}}" Laurent@814: nested dictionary structure. Laurent@814: """ Laurent@814: if type(fdecls) != type(tuple()): Laurent@814: res = "" Laurent@814: for Paramname, ParamTypes in fdecls.iteritems(): Laurent@814: if do_il: Laurent@814: res += """ Laurent@814: {""" Laurent@814: if not do_type_search_only: Laurent@814: res += """ Laurent@814: symbol_c *%(input_name)s_param_name = (symbol_c *)(new identifier_c("%(input_name)s")); Laurent@814: /* Get the value from a foo( = ) style call */ Laurent@814: symbol_c *%(input_name)s_param_value = &this->default_variable_name; Laurent@814: """%{"input_name":Paramname} Laurent@814: res += """ Laurent@814: symbol_c *%(input_name)s_type_symbol = param_data_type; Laurent@814: last_type_symbol = %(input_name)s_type_symbol; Laurent@814: """%{"input_name":Paramname} Laurent@814: else: Laurent@814: res += """ Laurent@814: { Laurent@814: symbol_c *%(input_name)s_param_name = (symbol_c *)(new identifier_c("%(input_name)s")); Laurent@814: /* Get the value from a foo( = ) style call */ Laurent@814: symbol_c *%(input_name)s_param_value = function_call_param_iterator.search_f(%(input_name)s_param_name); Laurent@814: symbol_c *%(input_name)s_type_symbol = NULL; Laurent@814: Laurent@814: /* Get the value from a foo() style call */ Laurent@814: if (%(input_name)s_param_value == NULL) Laurent@814: %(input_name)s_param_value = function_call_param_iterator.next_nf(); Laurent@814: if (%(input_name)s_param_value != NULL) { Laurent@814: %(input_name)s_type_symbol = search_expression_type->get_type(%(input_name)s_param_value); Laurent@814: last_type_symbol = last_type_symbol && %(input_name)s_type_symbol && search_expression_type->is_same_type(%(input_name)s_type_symbol, last_type_symbol) ? search_expression_type->common_type(%(input_name)s_type_symbol, last_type_symbol) : %(input_name)s_type_symbol ; Laurent@814: } Laurent@814: """%{"input_name":Paramname} Laurent@814: Laurent@814: for ParamType,NextParamDecl in ParamTypes.iteritems(): Laurent@814: Laurent@814: res += """ Laurent@814: %(type_test)s Laurent@814: { Laurent@814: %(if_good_type_code)s Laurent@814: } Laurent@814: """%{ Laurent@814: "type_test":ANY_to_compiler_test_type_GEN(ParamType,Paramname), Laurent@814: "if_good_type_code":recurse_and_indent(NextParamDecl,indent,do_type_search_only).replace('\n','\n ')} Laurent@814: Laurent@814: res += """ Laurent@814: Laurent@814: ERROR; Laurent@814: } Laurent@814: """ Laurent@814: Laurent@814: return res.replace('\n','\n'+indent) Laurent@814: else: Laurent@814: res = "\n" Laurent@814: fdecl=fdecls[0] Laurent@814: Laurent@814: if not do_type_search_only: Laurent@814: code_gen = eval(fdecl["python_eval_c_code_format"]) Laurent@814: Laurent@814: if code_gen[1] is not None: Laurent@814: res += "function_name = (symbol_c*)(new pragma_c(\"%s\"));\n"%code_gen[1] Laurent@814: if fdecl["extensible"]: Laurent@814: res += """ Laurent@814: if (nb_param < %(min_nb_param)d) Laurent@814: nb_param = %(min_nb_param)d; Laurent@814: char* nb_param_str = new char[10]; Laurent@814: sprintf(nb_param_str, "%%d", nb_param); Laurent@814: symbol_c * nb_param_name = (symbol_c *)(new identifier_c("nb_param")); Laurent@814: ADD_PARAM_LIST(nb_param_name, (symbol_c*)(new integer_c((const char *)nb_param_str)), (symbol_c*)(new int_type_name_c()), function_param_iterator_c::direction_in) Laurent@814: """%{"min_nb_param" : len(fdecl["inputs"])} Laurent@814: for paramname,paramtype,unused in fdecl["inputs"]: Laurent@814: res += """ Laurent@814: if (%(input_name)s_type_symbol == NULL) Laurent@814: %(input_name)s_type_symbol = last_type_symbol; Laurent@814: ADD_PARAM_LIST(%(input_name)s_param_name, %(input_name)s_param_value, %(input_name)s_type_symbol, function_param_iterator_c::direction_in) Laurent@814: """%{"input_name" : paramname} Laurent@814: if fdecl["extensible"]: Laurent@814: res += """ Laurent@814: int base_num = %d; Laurent@814: symbol_c *param_value = NULL; Laurent@814: symbol_c *param_name = NULL; Laurent@814: do{ Laurent@814: char my_name[10]; Laurent@814: sprintf(my_name, "IN%%d", base_num++); Laurent@814: param_name = (symbol_c*)(new identifier_c(my_name)); Laurent@814: Laurent@814: /* Get the value from a foo( = ) style call */ Laurent@814: param_value = function_call_param_iterator.search_f(param_name); Laurent@814: Laurent@814: /* Get the value from a foo() style call */ Laurent@814: if (param_value == NULL) Laurent@814: param_value = function_call_param_iterator.next_nf(); Laurent@814: if (param_value != NULL){ Laurent@814: symbol_c *current_type_symbol = search_expression_type->get_type(param_value); Laurent@814: last_type_symbol = last_type_symbol && search_expression_type->is_same_type(current_type_symbol, last_type_symbol) ? search_expression_type->common_type(current_type_symbol, last_type_symbol) : current_type_symbol ; Laurent@814: Laurent@814: /*Function specific CODE */ Laurent@814: ADD_PARAM_LIST(param_name, param_value, current_type_symbol, function_param_iterator_c::direction_in) Laurent@814: } Laurent@814: Laurent@814: }while(param_value != NULL); Laurent@814: """%(fdecl["baseinputnumber"] + 2) Laurent@814: Laurent@814: result_type_rule = fdecl["return_type_rule"] Laurent@814: res += { Laurent@814: "copy_input" : "symbol_c * return_type_symbol = last_type_symbol;\n", Laurent@814: "defined" : "symbol_c * return_type_symbol = &search_constant_type_c::%s_type_name;\n"%fdecl["outputs"][0][1].lower(), Laurent@814: }.get(result_type_rule, "symbol_c * return_type_symbol = %s;\n"%result_type_rule) Laurent@814: Laurent@814: if not do_type_search_only: Laurent@814: if code_gen[0] is not None: Laurent@814: res += "function_type_prefix = %s;\n"%{"return_type" : "return_type_symbol"}.get(code_gen[0], "(symbol_c*)(new pragma_c(\"%s\"))"%code_gen[0]) Laurent@814: if code_gen[2] is not None: Laurent@814: res += "function_type_suffix = %s_symbol;\n"%{"common_type" : "last_type"}.get(code_gen[2], code_gen[2]) Laurent@814: Laurent@814: any_common = reduce(lambda x, y: {"ANY": lambda x: x, Laurent@814: "ANY_BIT": lambda x: {"ANY": y, "ANY_NUM": y}.get(y, x), Laurent@814: "ANY_NUM": lambda x: {"ANY": y}.get(y, x), Laurent@814: "ANY_REAL": lambda x: {"ANY": y, "ANY_NUM": y}.get(y, x)}.get(x, y), Laurent@814: [paramtype for paramname,paramtype,unused in fdecl["inputs"]], "BOOL") Laurent@814: Laurent@814: first = True Laurent@814: for list, test_type, default_type in [(["ANY", "ANY_NUM"], "integer", "lint"), Laurent@814: (["ANY_BIT"], "integer", "lword"), Laurent@814: (["ANY", "ANY_REAL"], "real", "lreal")]: Laurent@814: Laurent@814: if any_common in list: Laurent@814: if not first: Laurent@814: res += "else " Laurent@814: first = False Laurent@814: res += """if (search_expression_type->is_literal_%s_type(function_type_suffix)) Laurent@814: function_type_suffix = &search_constant_type_c::%s_type_name; Laurent@814: """%(test_type, default_type) Laurent@814: Laurent@814: res += "break;\n" Laurent@814: else: Laurent@814: res += "return return_type_symbol;\n" Laurent@814: Laurent@814: return res.replace('\n','\n'+indent) Laurent@814: Laurent@814: def get_default_input_type(fdecls): Laurent@814: if type(fdecls) != type(tuple()) and len(fdecls) == 1: Laurent@814: ParamTypes = fdecls.values()[0] Laurent@814: if len(ParamTypes) == 1: Laurent@814: ParamType_name, ParamType_value = ParamTypes.items()[0] Laurent@814: if not ParamType_name.startswith("ANY") and type(ParamType_value) == type(tuple()): Laurent@814: return "&search_constant_type_c::%s_type_name" % ParamType_name.lower() Laurent@814: return "NULL" Laurent@814: Laurent@814: ################################################################### Laurent@814: ### ### Laurent@814: ### MAIN ### Laurent@814: ### ### Laurent@814: ################################################################### Laurent@814: Laurent@814: """ Laurent@814: Reorganize std_decl from structure.py Laurent@814: into a nested dictionnary structure (i.e. a tree): Laurent@814: "{fname : {IN[0]paramname : {IN[0]paramtype : {IN[1]paraname : {IN[1]paramtype : {... : {IN[N]paraname : {IN[N]paramtype : (fdecl,)}}}}}}" Laurent@814: Keep ptrack of original declaration order in a Laurent@814: separated list called official_order Laurent@814: """ Laurent@814: std_fdecls = {} Laurent@814: official_order = [] Laurent@814: for section in std_decl: Laurent@814: for fdecl in section["list"]: Laurent@814: if len(official_order)==0 or fdecl["name"] not in official_order: Laurent@814: official_order.append(fdecl["name"]) Laurent@814: # store all func by name in a dict Laurent@814: std_fdecls_fdecl_name = std_fdecls.get(fdecl["name"], {}) Laurent@814: current = std_fdecls_fdecl_name Laurent@814: for i in fdecl["inputs"]: Laurent@814: current[i[0]] = current.get(i[0], {}) Laurent@814: current = current[i[0]] Laurent@814: last = current Laurent@814: current[i[1]] = current.get(i[1], {}) Laurent@814: current = current[i[1]] Laurent@814: last[i[1]]=(fdecl,) Laurent@814: std_fdecls[fdecl["name"]] = std_fdecls_fdecl_name Laurent@814: Laurent@814: ################################################################### Laurent@814: Laurent@814: """ Laurent@814: Generate the long enumeration of std function types Laurent@814: """ Laurent@814: function_type_decl = matiec_header + """ Laurent@814: typedef enum { Laurent@814: """ Laurent@814: for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: Laurent@814: function_type_decl += " function_"+fname.lower()+",\n" Laurent@814: Laurent@814: function_type_decl += """ function_none Laurent@814: } function_type_t; Laurent@814: """ Laurent@814: ################################################################### Laurent@814: """ Laurent@814: Generate the funct that return enumerated according function name Laurent@814: """ Laurent@814: get_function_type_decl = matiec_header + """ Laurent@814: function_type_t get_function_type(identifier_c *function_name) { Laurent@814: """ Laurent@814: for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: Laurent@814: get_function_type_decl += """ Laurent@814: if (!strcasecmp(function_name->value, "%s")) Laurent@814: return function_%s; Laurent@814: """%(fname,fname.lower()) Laurent@814: Laurent@814: get_function_type_decl += """ Laurent@814: else return function_none; Laurent@814: } Laurent@814: Laurent@814: """ Laurent@814: ################################################################### Laurent@814: """ Laurent@814: Generate the part of generate_c_st_c::visit(function_invocation) Laurent@814: that is responsible to generate C code for std lib calls. Laurent@814: """ Laurent@814: st_code_gen = matiec_header + """ Laurent@814: switch(current_function_type){ Laurent@814: """ Laurent@814: Laurent@814: for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: Laurent@814: st_code_gen += """ Laurent@814: /**** Laurent@814: *%s Laurent@814: */ Laurent@814: case function_%s : Laurent@814: { Laurent@814: symbol_c *last_type_symbol = %s; Laurent@814: """ %(fname, fname.lower(), get_default_input_type(fdecls)) Laurent@814: indent = " " Laurent@814: Laurent@814: st_code_gen += recurse_and_indent(fdecls, indent).replace('\n','\n ') Laurent@814: Laurent@814: st_code_gen += """ Laurent@814: }/*function_%s*/ Laurent@814: break; Laurent@814: """ %(fname.lower()) Laurent@814: st_code_gen += """ Laurent@814: case function_none : Laurent@814: ERROR; Laurent@814: } Laurent@814: """ Laurent@814: Laurent@814: ################################################################### Laurent@814: """ Laurent@814: Generate the part of generate_c_il_c::visit(il_function_call) Laurent@814: that is responsible to generate C code for std lib calls. Laurent@814: """ Laurent@814: il_code_gen = matiec_header + """ Laurent@814: switch(current_function_type){ Laurent@814: """ Laurent@814: Laurent@814: for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: Laurent@814: il_code_gen += """ Laurent@814: /**** Laurent@814: *%s Laurent@814: */ Laurent@814: case function_%s : Laurent@814: { Laurent@814: symbol_c *last_type_symbol = %s; Laurent@814: """ %(fname, fname.lower(), get_default_input_type(fdecls)) Laurent@814: indent = " " Laurent@814: Laurent@814: il_code_gen += recurse_and_indent(fdecls, indent, do_il=True).replace('\n','\n ') Laurent@814: Laurent@814: il_code_gen += """ Laurent@814: }/*function_%s*/ Laurent@814: break; Laurent@814: """ %(fname.lower()) Laurent@814: il_code_gen += """ Laurent@814: case function_none : Laurent@814: ERROR; Laurent@814: } Laurent@814: """ Laurent@814: Laurent@814: ################################################################### Laurent@814: """ Laurent@814: Generate the part of search_expression_type_c::visit(function_invocation) Laurent@814: that is responsible of returning type symbol for function invocation. Laurent@814: """ Laurent@814: search_type_code = matiec_header + """ Laurent@814: Laurent@814: void *search_expression_type_c::compute_standard_function_default(function_invocation_c *st_symbol = NULL, il_formal_funct_call_c *il_symbol = NULL) { Laurent@814: function_type_t current_function_type; Laurent@814: function_call_param_iterator_c *tmp_function_call_param_iterator; Laurent@814: if (st_symbol != NULL && il_symbol == NULL) { Laurent@814: current_function_type = get_function_type((identifier_c *)st_symbol->function_name); Laurent@814: tmp_function_call_param_iterator = new function_call_param_iterator_c(st_symbol); Laurent@814: } Laurent@814: else if (st_symbol == NULL && il_symbol != NULL) { Laurent@814: current_function_type = get_function_type((identifier_c *)il_symbol->function_name); Laurent@814: tmp_function_call_param_iterator = new function_call_param_iterator_c(il_symbol); Laurent@814: } Laurent@814: else Laurent@814: ERROR; Laurent@814: function_call_param_iterator_c function_call_param_iterator(*tmp_function_call_param_iterator); Laurent@814: search_expression_type_c* search_expression_type = this; Laurent@814: Laurent@814: switch(current_function_type){ Laurent@814: """ Laurent@814: Laurent@814: for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: Laurent@814: search_type_code += """ Laurent@814: /**** Laurent@814: *%s Laurent@814: */ Laurent@814: case function_%s : Laurent@814: { Laurent@814: symbol_c *last_type_symbol = %s; Laurent@814: """ %(fname, fname.lower(), get_default_input_type(fdecls)) Laurent@814: indent = " " Laurent@814: Laurent@814: search_type_code += recurse_and_indent(fdecls, indent, True).replace('\n','\n ') Laurent@814: Laurent@814: search_type_code += """ Laurent@814: }/*function_%s*/ Laurent@814: break; Laurent@814: """ %(fname.lower()) Laurent@814: search_type_code += """ Laurent@814: case function_none : Laurent@814: ERROR; Laurent@814: } Laurent@814: return NULL; Laurent@814: } Laurent@814: Laurent@814: void *search_expression_type_c::compute_standard_function_il(il_function_call_c *symbol, symbol_c *param_data_type) { Laurent@814: Laurent@814: function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name); Laurent@814: function_call_param_iterator_c function_call_param_iterator(symbol); Laurent@814: search_expression_type_c* search_expression_type = this; Laurent@814: Laurent@814: switch(current_function_type){ Laurent@814: """ Laurent@814: Laurent@814: for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: Laurent@814: search_type_code += """ Laurent@814: /**** Laurent@814: *%s Laurent@814: */ Laurent@814: case function_%s : Laurent@814: { Laurent@814: symbol_c *last_type_symbol = %s; Laurent@814: """ %(fname, fname.lower(), get_default_input_type(fdecls)) Laurent@814: indent = " " Laurent@814: Laurent@814: search_type_code += recurse_and_indent(fdecls, indent, True, True).replace('\n','\n ') Laurent@814: Laurent@814: search_type_code += """ Laurent@814: }/*function_%s*/ Laurent@814: break; Laurent@814: """ %(fname.lower()) Laurent@814: search_type_code += """ Laurent@814: case function_none : Laurent@814: ERROR; Laurent@814: } Laurent@814: return NULL; Laurent@814: } Laurent@814: """ Laurent@814: Laurent@814: ################################################################### Laurent@814: ################################################################### Laurent@814: ################################################################### Laurent@814: """ Laurent@814: Generate the standard_function_names[] for inclusion in bizon generated code Laurent@814: """ Laurent@814: standard_function_names = matiec_header + """ Laurent@814: const char *standard_function_names[] = { Laurent@814: """ Laurent@814: for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]: Laurent@814: standard_function_names += "\""+fname+"\",\n" Laurent@814: standard_function_names += """ Laurent@814: /* end of array marker! Do not remove! */ Laurent@814: NULL Laurent@814: }; Laurent@814: Laurent@814: """ Laurent@814: Laurent@814: ################################################################### Laurent@814: ################################################################### Laurent@814: ################################################################### Laurent@814: """ Laurent@814: Generate the C implementation of the IEC standard function library. Laurent@814: """ Laurent@814: iec_std_lib_generated = matiec_lesser_header + """ Laurent@814: Laurent@814: /* Macro that expand to subtypes */ Laurent@814: """ Laurent@814: for typename, parenttypename in TypeHierarchy_list: Laurent@814: if (typename.startswith("ANY")): Laurent@814: iec_std_lib_generated += "#define " + typename + "(DO)" Laurent@814: for typename2, parenttypename2 in TypeHierarchy_list: Laurent@814: if(parenttypename2 == typename): Laurent@814: if(typename2.startswith("ANY")): Laurent@814: iec_std_lib_generated += " " + typename2 + "(DO)" Laurent@814: else: Laurent@814: iec_std_lib_generated += " DO(" + typename2 + ")" Laurent@814: iec_std_lib_generated += "\n" Laurent@814: else: Laurent@814: break Laurent@814: Laurent@814: # Now, print that out, or write to files from sys.argv Laurent@814: for path, name, ext in file_list : Laurent@814: fd = open(os.path.join(sys.argv[1], path, name+'.'+ext),'w') Laurent@814: fd.write(eval(name)) Laurent@814: fd.close() Laurent@814: Laurent@814: #print "/* Code to eventually paste in iec_std_lib.h if type hierarchy changed */" Laurent@814: #print "/* you also have to change iec_std_lib.h according to new types */\n\n" Laurent@814: #print iec_std_lib_generated