generate_IEC_std.py
author lbessard
Tue, 10 Jul 2007 14:29:31 +0200
changeset 31 d833bf7567b1
parent 26 36d378bd852e
child 36 e7d67b27877f
permissions -rw-r--r--
Bug on variable location fixed
25
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
     1
# Get definitions
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
     2
from plcopen.structures import *
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
     3
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
     4
#import pprint
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
     5
#pp = pprint.PrettyPrinter(indent=4)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
     6
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
     7
def ANY_to_compiler_test_type_GEN(typename, paramname):
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
     8
    """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
     9
    Convert ANY_XXX IEC type declaration into IEC2CC's generated type test.
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    10
    This tests are defined in search_expression_type.cc 
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    11
    """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    12
    return {"ANY" : "",
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    13
    "ANY_BIT" : "if(search_expression_type->is_binary_type(%(paramname)s_type_symbol))",
26
36d378bd852e Stage4 changes according to new STD lib implementation
etisserant
parents: 25
diff changeset
    14
    "ANY_NBIT" : "if(search_expression_type->is_nbinary_type(%(paramname)s_type_symbol))",
25
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    15
    "ANY_NUM" : "if(search_expression_type->is_num_type(%(paramname)s_type_symbol))",
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    16
    "ANY_REAL" : "if(search_expression_type->is_real_type(%(paramname)s_type_symbol))",
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    17
    "ANY_INT" : "if(search_expression_type->is_integer_type(%(paramname)s_type_symbol))"
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    18
    }.get(typename,
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    19
        "if (typeid(*last_type_symbol) == typeid(%(typename)s_type_name_c))")%{
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    20
                "paramname" : paramname, "typename": typename.lower()}
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    21
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    22
def recurse_and_indent(fdecls, indent, do_type_search_only = False, do_il = False):
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    23
    """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    24
    This function generate visit(function_invocation) code for 
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    25
        - ST code generator
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    26
        - IL code generator
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    27
        - search_expression_type class for ST
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    28
        - search_expression_type class for IL
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    29
        
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    30
    Input data is a 
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    31
    "{fname : {IN[0]paramname : {IN[0]paramtype : {IN[1]paraname : {IN[1]paramtype : {... : {IN[N]paraname : {IN[N]paramtype : (fdecl,)}}}}}}"
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    32
    nested dictionary structure.
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    33
    """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    34
    if type(fdecls) != type(tuple()):
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    35
        res = ""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    36
        for Paramname, ParamTypes in fdecls.iteritems():
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    37
            if do_il:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    38
                res += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    39
{"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    40
                if not do_type_search_only:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    41
                    res += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    42
    /* Get the value from a foo(<param_name> = <param_value>) style call */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    43
    symbol_c *%(input_name)s_param_value = &this->default_variable_name;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    44
"""%{"input_name":Paramname}
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    45
                res += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    46
    symbol_c *%(input_name)s_type_symbol = param_data_type;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    47
    last_type_symbol = param_data_type;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    48
"""%{"input_name":Paramname}
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    49
            else:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    50
                res += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    51
{
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    52
    identifier_c param_name("%(input_name)s");
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    53
    /* Get the value from a foo(<param_name> = <param_value>) style call */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    54
    symbol_c *%(input_name)s_param_value = function_call_param_iterator.search(&param_name);
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    55
    
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    56
    /* Get the value from a foo(<param_value>) style call */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    57
    if (%(input_name)s_param_value == NULL)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    58
      %(input_name)s_param_value = function_call_param_iterator.next();
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    59
    symbol_c *%(input_name)s_type_symbol = search_expression_type->get_type(%(input_name)s_param_value);
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    60
    last_type_symbol = last_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 ;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    61
"""%{"input_name":Paramname}
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    62
            
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    63
            for ParamType,NextParamDecl in ParamTypes.iteritems():
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    64
            
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    65
                res += """    
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    66
    %(type_test)s
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    67
    {
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    68
%(if_good_type_code)s
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    69
    }
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    70
"""%{
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    71
    "type_test":ANY_to_compiler_test_type_GEN(ParamType,Paramname), 
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    72
    "if_good_type_code":recurse_and_indent(NextParamDecl,indent,do_type_search_only).replace('\n','\n    ')}
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    73
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    74
            res += """    
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    75
    ERROR;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    76
}
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    77
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    78
        
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    79
        return res.replace('\n','\n'+indent)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    80
    else:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    81
        res = "\n"
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    82
        fdecl=fdecls[0]
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    83
        
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    84
        result_type_rule = fdecl["return_type_rule"]
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    85
        res += {
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    86
            "copy_input" : "symbol_c * return_type_symbol = last_type_symbol;\n",
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    87
            "defined" : "symbol_c * return_type_symbol = &search_constant_type_c::%s_type_name;\n"%fdecl["outputs"][0][1].lower(),
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    88
            }.get(result_type_rule, "symbol_c * return_type_symbol = %s;\n"%result_type_rule)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    89
        
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    90
        if not do_type_search_only:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    91
            code_gen = eval(fdecl["python_eval_c_code_format"])
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    92
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    93
            code_gen_dic_decl = {}
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    94
            for paramname,paramtype,unused in fdecl["inputs"]:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    95
                code_gen_dic_decl[paramname+"_value"] = '");\n%s_param_value->accept(*this);\ns4o.print("'%(paramname)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    96
                code_gen_dic_decl[paramname+"_type"] = '");\n%s_type_symbol->accept(*this);\ns4o.print("'%(paramname)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    97
            code_gen_dic_decl["return_type"] = '");\nreturn_type_symbol->accept(*this);\ns4o.print("'
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    98
            code_gen_dic_decl["param_count"] = '");\ns4o.print_integer(nb_param);\ns4o.print("'
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
    99
            code_gen_dic_decl["start_bool_filter"] = '");\nif (search_expression_type->is_bool_type(last_type_symbol))\n  s4o.print("('
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   100
            code_gen_dic_decl["end_bool_filter"] = '");\nif (search_expression_type->is_bool_type(last_type_symbol)) {\n  s4o.print("&1");\n  s4o.print(")");\n}\ns4o.print("'
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   101
            
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   102
            if type(code_gen) == type(tuple()):
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   103
                res += 's4o.print("%s");\n'%(code_gen[0]%code_gen_dic_decl)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   104
                static_param_accept_list = []
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   105
                for paramname,paramtype,unused in fdecl["inputs"]:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   106
                    static_param_accept_list.append("%s_param_value->accept(*this);\n"%(paramname))
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   107
                res += ('s4o.print("%s");\n'%(code_gen[1])).join(static_param_accept_list)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   108
                code = 's4o.print("%s");\nparam_value->accept(*this);\n'%(code_gen[1])
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   109
                end_code = 's4o.print("%s");\nreturn NULL;\n'%(code_gen[2]%code_gen_dic_decl)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   110
            else:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   111
                code = ''
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   112
                end_code = ('s4o.print("' + code_gen%code_gen_dic_decl + '");\nreturn NULL;\n').replace('s4o.print("");\n','')
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   113
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   114
            if fdecl["extensible"]:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   115
                res += ("""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   116
int base_num = %d;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   117
symbol_c *param_value = NULL;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   118
do{
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   119
    char my_name[10];
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   120
    sprintf(my_name, "IN%%d", base_num++);
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   121
    identifier_c param_name(my_name);
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   122
    
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   123
    /* Get the value from a foo(<param_name> = <param_value>) style call */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   124
    param_value = function_call_param_iterator.search(&param_name);
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   125
    
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   126
    /* Get the value from a foo(<param_value>) style call */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   127
    if (param_value == NULL)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   128
      param_value = function_call_param_iterator.next();
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   129
    if (param_value != NULL){
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   130
        symbol_c *current_type_symbol = search_expression_type->get_type(param_value);
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   131
        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 ;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   132
    
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   133
        /*Function specific CODE */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   134
        %s
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   135
    }
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   136
    
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   137
}while(param_value != NULL);
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   138
%s
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   139
"""%(fdecl["baseinputnumber"]+2, code.replace('\n','\n        '), end_code))
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   140
            else:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   141
                #res += code + end_code
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   142
                res += end_code
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   143
        else:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   144
            res += "return return_type_symbol;\n"
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   145
        
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   146
                
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   147
        return res.replace('\n','\n'+indent)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   148
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   149
###################################################################
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   150
###                                                             ###
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   151
###                           MAIN                              ###
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   152
###                                                             ###
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   153
###################################################################
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   154
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   155
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   156
Reorganize std_decl from structure.py
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   157
into a nested dictionnary structure (i.e. a tree):
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   158
"{fname : {IN[0]paramname : {IN[0]paramtype : {IN[1]paraname : {IN[1]paramtype : {... : {IN[N]paraname : {IN[N]paramtype : (fdecl,)}}}}}}"
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   159
Keep ptrack of original declaration order in a 
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   160
separated list called official_order
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   161
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   162
std_fdecls = {}
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   163
official_order = []
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   164
for section in std_decl:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   165
    for fdecl in section["list"]:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   166
        if len(official_order)==0 or official_order[-1] != fdecl["name"]:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   167
            official_order.append(fdecl["name"])
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   168
        # store all func by name in a dict
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   169
        std_fdecls_fdecl_name = std_fdecls.get(fdecl["name"], {})
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   170
        current = std_fdecls_fdecl_name
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   171
        for i in fdecl["inputs"]:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   172
            current[i[0]] = current.get(i[0], {})
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   173
            current = current[i[0]]
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   174
            last = current
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   175
            current[i[1]] = current.get(i[1], {})
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   176
            current = current[i[1]]
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   177
        last[i[1]]=(fdecl,)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   178
        std_fdecls[fdecl["name"]] = std_fdecls_fdecl_name
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   179
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   180
###################################################################
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   181
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   182
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   183
Generate the long enumeration of std function types
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   184
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   185
function_type_decl =  """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   186
/****
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   187
 * IEC 61131-3 standard function lib
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   188
 * generated code, do not edit by hand
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   189
 */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   190
typedef enum {
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   191
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   192
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   193
    function_type_decl += "    function_"+fname.lower()+",\n"
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   194
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   195
function_type_decl += """    function_none
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   196
} function_type_t;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   197
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   198
###################################################################
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   199
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   200
Generate the funct that return enumerated according function name
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   201
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   202
get_function_type_decl = """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   203
/****
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   204
 * IEC 61131-3 standard function lib
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   205
 * generated code, do not edit by hand
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   206
 */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   207
function_type_t get_function_type(identifier_c *function_name) {
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   208
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   209
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   210
    get_function_type_decl += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   211
if (!strcasecmp(function_name->value, "%s"))
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   212
    return function_%s;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   213
"""%(fname,fname.lower())
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   214
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   215
get_function_type_decl += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   216
    else return function_none;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   217
}
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   218
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   219
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   220
###################################################################
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   221
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   222
Generate the part of generate_cc_st_c::visit(function_invocation)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   223
that is responsible to generate C code for std lib calls.
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   224
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   225
st_code_gen = """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   226
/****
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   227
 * IEC 61131-3 standard function lib
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   228
 * generated code, do not edit by hand
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   229
 */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   230
switch(current_function_type){
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   231
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   232
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   233
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   234
    st_code_gen += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   235
/****
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   236
 *%s
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   237
 */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   238
    case function_%s :
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   239
    {
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   240
        symbol_c *last_type_symbol = NULL;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   241
"""    %(fname, fname.lower())
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   242
    indent =  "    "
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   243
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   244
    st_code_gen += recurse_and_indent(fdecls, indent).replace('\n','\n    ')
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   245
    
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   246
    st_code_gen += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   247
    }/*function_%s*/
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   248
    break;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   249
"""    %(fname.lower())
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   250
st_code_gen +=  """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   251
    case function_none :
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   252
    ERROR;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   253
}
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   254
return NULL;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   255
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   256
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   257
###################################################################
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   258
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   259
Generate the part of generate_cc_il_c::visit(il_function_call)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   260
that is responsible to generate C code for std lib calls.
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   261
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   262
il_code_gen = """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   263
/****
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   264
 * IEC 61131-3 standard function lib
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   265
 * generated code, do not edit by hand
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   266
 */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   267
switch(current_function_type){
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   268
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   269
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   270
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   271
    il_code_gen += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   272
/****
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   273
 *%s
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   274
 */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   275
    case function_%s :
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   276
    {
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   277
        symbol_c *last_type_symbol = NULL;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   278
"""    %(fname, fname.lower())
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   279
    indent =  "    "
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   280
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   281
    il_code_gen += recurse_and_indent(fdecls, indent, do_il=True).replace('\n','\n    ')
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   282
    
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   283
    il_code_gen += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   284
    }/*function_%s*/
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   285
    break;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   286
"""    %(fname.lower())
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   287
il_code_gen +=  """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   288
    case function_none :
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   289
    ERROR;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   290
}
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   291
return NULL;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   292
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   293
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   294
###################################################################
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   295
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   296
Generate the part of search_expression_type_c::visit(function_invocation)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   297
that is responsible of returning type symbol for function invocation.
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   298
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   299
search_type_code =  """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   300
/****
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   301
 * IEC 61131-3 standard function lib
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   302
 * generated code, do not edit by hand
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   303
 */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   304
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   305
void *compute_standard_function_st(function_invocation_c *symbol) {
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   306
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   307
  function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   308
  function_call_param_iterator_c function_call_param_iterator(symbol);
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   309
  search_expression_type_c* search_expression_type = this;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   310
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   311
  switch(current_function_type){
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   312
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   313
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   314
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   315
    search_type_code += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   316
/****
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   317
 *%s
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   318
 */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   319
    case function_%s :
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   320
    {
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   321
        symbol_c *last_type_symbol = NULL;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   322
"""    %(fname, fname.lower())
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   323
    indent =  "    "
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   324
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   325
    search_type_code += recurse_and_indent(fdecls, indent, True).replace('\n','\n    ')
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   326
    
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   327
    search_type_code += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   328
    }/*function_%s*/
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   329
    break;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   330
"""    %(fname.lower())
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   331
search_type_code += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   332
    case function_none :
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   333
    ERROR;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   334
  }
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   335
  return NULL;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   336
}
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   337
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   338
void *compute_standard_function_il(il_function_call_c *symbol, symbol_c *param_data_type) {
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   339
  
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   340
  function_type_t current_function_type = get_function_type((identifier_c *)symbol->function_name);
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   341
  function_call_param_iterator_c function_call_param_iterator(symbol);  
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   342
  search_expression_type_c* search_expression_type = this;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   343
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   344
  switch(current_function_type){
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   345
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   346
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   347
for fname, fdecls in [ (fname,std_fdecls[fname]) for fname in official_order ]:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   348
    search_type_code += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   349
/****
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   350
 *%s
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   351
 */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   352
    case function_%s :
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   353
    {
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   354
        symbol_c *last_type_symbol = NULL;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   355
"""    %(fname, fname.lower())
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   356
    indent =  "    "
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   357
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   358
    search_type_code += recurse_and_indent(fdecls, indent, True, True).replace('\n','\n    ')
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   359
    
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   360
    search_type_code += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   361
    }/*function_%s*/
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   362
    break;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   363
"""    %(fname.lower())
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   364
search_type_code += """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   365
    case function_none :
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   366
    ERROR;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   367
  }
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   368
  return NULL;
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   369
}
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   370
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   371
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   372
###################################################################
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   373
###################################################################
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   374
###################################################################
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   375
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   376
Generate the C implementation of the IEC standard function library.
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   377
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   378
iec_std_lib_generated =  """
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   379
/****
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   380
 * IEC 61131-3 standard function lib
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   381
 * generated code, do not edit by hand
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   382
 */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   383
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   384
/* Macro that expand to subtypes */
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   385
"""
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   386
for typename, parenttypename in TypeHierarchy_list:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   387
    if (typename.startswith("ANY")):
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   388
        iec_std_lib_generated += "#define " + typename + "(DO)"
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   389
        for typename2, parenttypename2 in TypeHierarchy_list:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   390
            if(parenttypename2 == typename):
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   391
                if(typename2.startswith("ANY")):
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   392
                    iec_std_lib_generated +=  " " + typename2 + "(DO)"
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   393
                else:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   394
                    iec_std_lib_generated +=  " DO(" + typename2 + ")"
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   395
        iec_std_lib_generated +=  "\n"
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   396
    else:
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   397
        break
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   398
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   399
if len(sys.argv) != 2 :
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   400
    print "Usage: " + sys.argv[0] + "path_name\n -> create files in path_name"
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   401
    sys.exit(0)
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   402
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   403
# Now, print that out, or write to files from sys.argv
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   404
for name, ext in [
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   405
        ('function_type_decl','h'),
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   406
        ('get_function_type_decl','c'),
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   407
        ('st_code_gen','c'),
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   408
        ('il_code_gen','c'),
26
36d378bd852e Stage4 changes according to new STD lib implementation
etisserant
parents: 25
diff changeset
   409
        ('search_type_code','c')#,
36d378bd852e Stage4 changes according to new STD lib implementation
etisserant
parents: 25
diff changeset
   410
        #('iec_std_lib_generated','h')
36d378bd852e Stage4 changes according to new STD lib implementation
etisserant
parents: 25
diff changeset
   411
        ]:
25
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   412
    fd = open(os.path.join(sys.argv[1],name+'.'+ext),'w')
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   413
    fd.write(eval(name))
8dc68e669d99 Early implementation of STD library.
etisserant
parents:
diff changeset
   414
    fd.close()