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