X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=scripts%2Fgen_ir.py;h=7ab17318f3e884591df6a598c41b04012113846a;hb=41f96b4dc5a6b5e4a2cc1b5b480b7cece31d1d66;hp=53c9031a18aa5218a4bb3b36406cc0d6c98e6fce;hpb=6278615bbce6038743bdb928ddde498f6b2b9277;p=libfirm diff --git a/scripts/gen_ir.py b/scripts/gen_ir.py index 53c9031a1..7ab17318f 100755 --- a/scripts/gen_ir.py +++ b/scripts/gen_ir.py @@ -3,86 +3,101 @@ import sys import re from jinja2 import Environment, Template from jinja2.filters import do_dictsort -from spec_util import is_dynamic_pinned, verify_node +from spec_util import is_dynamic_pinned, verify_node, isAbstract, setdefault from ir_spec import nodes -def format_argdecls(node, first = False, voidwhenempty = False): - if not node.has_key("args") or len(node["args"]) == 0: - if voidwhenempty: - return "void" - else: - return "" +def format_parameterlist(parameterlist): + return "\n".join(parameterlist) + +def format_nodearguments(node): + arguments = map(lambda arg: arg["name"], node.arguments) + return format_parameterlist(arguments) +def format_nodeparameters(node): + parameters = map(lambda arg: arg["type"] + " " + arg["name"], node.arguments) + return format_parameterlist(parameters) + +def format_nodeparametershelp(node): res = "" - if not first: - comma = ", " - else: - comma = "" - for arg in node["args"]: - res = res + (comma + arg["type"] + " " + arg["name"]) - comma = ", " + for param in node.arguments: + res += " * @param %-9s %s\n" % (param["name"], param["comment"]) return res -def format_args(node, first = False): - if not node.has_key("args"): - return "" +def format_a_an(text): + if text[0] in "aAeEuUoOiI": + return "an " + text + return "a " + text - res = "" - if not first: - comma = ", " +def format_blockparameter(node): + if hasattr(node, "knownBlock"): + if hasattr(node, "knownGraph"): + return "" + return "ir_graph *irg" else: - comma = "" - for arg in node["args"]: - res = res + (comma + arg["name"]) - comma = ", " - return res + return "ir_node *block" -def format_blockdecl(node): - if node.get("knownBlock"): - return "" +def format_blockparameterhelp(node): + if hasattr(node, "knownBlock"): + if hasattr(node, "knownGraph"): + return "" + return " * @param irg The IR graph the node belongs to.\n" else: - return ", ir_node *block" + return " * @param block The IR block the node belongs to.\n" -def format_block(node): - if node.get("knownBlock"): +def format_blockargument(node): + if hasattr(node, "knownBlock"): + if hasattr(node, "knownGraph"): + return "" + return "irg" + else: + return "block" + +def format_irgassign(node): + if hasattr(node, "knownGraph"): + return "ir_graph *irg = %s;\n" % node.graph + + if hasattr(node, "knownBlock"): return "" else: - return ", block" + return "ir_graph *irg = get_Block_irg(block);\n" def format_curblock(node): - if node.get("knownBlock"): - return "" + if hasattr(node, "knownBlock"): + if hasattr(node, "knownGraph"): + return "" + return "current_ir_graph" else: - return ", current_ir_graph->current_block" + return "current_ir_graph->current_block" def format_insdecl(node): - arity = node["arity"] - if arity == "variable" and len(node["ins"]) == 0 or arity == "dynamic" or arity == 0: + arity = node.arity + if arity == "variable" and len(node.ins) == 0 or arity == "dynamic" or arity == 0: return "" if arity == "variable": - insarity = len(node["ins"]) - res = "int r_arity = arity + " + `insarity` + ";\n\tir_node **r_in;\n\t" \ - + "NEW_ARR_A(ir_node *, r_in, r_arity);\n\t" + insarity = len(node.ins) + res = "int r_arity = arity + " + `insarity` + ";" + res += "\n\tir_node **r_in;" + res += "\n\tNEW_ARR_A(ir_node *, r_in, r_arity);" i = 0 - for input in node["ins"]: - res += "r_in[" + `i` + "] = irn_" + input + ";\n\t" + for input in node.ins: + res += "\n\tr_in[" + `i` + "] = irn_" + input[0] + ";" i += 1 - res += "memcpy(&r_in[" + `insarity` + "], in, sizeof(ir_node *) * arity);\n\t" + res += "\n\tmemcpy(&r_in[" + `insarity` + "], in, sizeof(ir_node *) * arity);\n\t" else: - res = "ir_node *in[" + `arity` + "];\n\t" + res = "ir_node *in[" + `arity` + "];" i = 0 - for input in node["ins"]: - res += "in[" + `i` + "] = irn_" + input + ";\n\t" + for input in node.ins: + res += "\n\tin[" + `i` + "] = irn_" + input[0] + ";" i += 1 return res def format_arity_and_ins(node): - arity = node["arity"] + arity = node.arity if arity == "dynamic": return "-1, NULL" elif arity == "variable": - if len(node["ins"]) == 0: + if len(node.ins) == 0: return "arity, in" else: return "r_arity, r_in" @@ -92,9 +107,9 @@ def format_arity_and_ins(node): return `arity` + ", in" def format_arity(node): - if "arity_override" in node: - return node["arity_override"] - arity = node['arity'] + if hasattr(node, "arity_override"): + return node.arity_override + arity = node.arity if arity == "dynamic": return "oparity_dynamic" if arity == "variable": @@ -110,7 +125,7 @@ def format_arity(node): return "oparity_any" def format_pinned(node): - pinned = node["pinned"] + pinned = node.pinned if pinned == "yes": return "op_pin_state_pinned" if pinned == "no": @@ -123,269 +138,323 @@ def format_pinned(node): return "" def format_flags(node): - flags = node['flags'] - flags = re.split("\s*,\s*", flags) - flags = map(lambda x : "irop_flag_" + x, flags) + flags = map(lambda x : "irop_flag_" + x, node.flags) + if flags == []: + flags = [ "irop_flag_none" ] return " | ".join(flags) def format_attr_size(node): - if "attr_struct" not in node: + if not hasattr(node, "attr_struct"): return "0" - return "sizeof(%s)" % node['attr_struct'] + return "sizeof(%s)" % node.attr_struct def format_opindex(node): - if "op_index" in node: - return node["op_index"] + if hasattr(node, "op_index"): + return node.op_index return "-1" +keywords = frozenset([ "true", "false" ]) +def format_escape_keywords(word): + if word in keywords: + return word + "_" + return word + def filter_isnot(list, flag): - result = [] - for nodename, node in list: - if flag in node: - continue - result.append((nodename, node)) - return result + return filter(lambda x: not hasattr(x, flag), list) + +def filter_hasnot(list, flag): + return filter(lambda x: flag not in x, list) + +def format_arguments(string, voidwhenempty = False): + args = re.split('\s*\n\s*', string) + if args[0] == '': + args = args[1:] + if len(args) > 0 and args[-1] == '': + args = args[:-1] + if len(args) == 0 and voidwhenempty: + return "void" + return ", ".join(args) + +def format_parameters(string): + return format_arguments(string, voidwhenempty = True) env = Environment() -env.filters['argdecls'] = format_argdecls -env.filters['args'] = format_args -env.filters['blockdecl'] = format_blockdecl -env.filters['block'] = format_block -env.filters['curblock'] = format_curblock -env.filters['insdecl'] = format_insdecl -env.filters['arity_and_ins'] = format_arity_and_ins -env.filters['arity'] = format_arity -env.filters['pinned'] = format_pinned -env.filters['flags'] = format_flags -env.filters['attr_size'] = format_attr_size -env.filters['isnot'] = filter_isnot -env.filters['opindex'] = format_opindex - -def add_attr(list, type, name, init = None, initname = None): - if initname == None: - initname = "." + name - if init != None: - list.append(dict(type = type, name = name, init = init, initname = initname)) - else: - list.append(dict(type = type, name = name, initname = initname)) +env.filters['a_an'] = format_a_an +env.filters['parameterlist'] = format_parameterlist +env.filters['nodearguments'] = format_nodearguments +env.filters['nodeparameters'] = format_nodeparameters +env.filters['nodeparametershelp'] = format_nodeparametershelp +env.filters['blockparameter'] = format_blockparameter +env.filters['blockparameterhelp'] = format_blockparameterhelp +env.filters['blockargument'] = format_blockargument +env.filters['irgassign'] = format_irgassign +env.filters['curblock'] = format_curblock +env.filters['insdecl'] = format_insdecl +env.filters['arity_and_ins'] = format_arity_and_ins +env.filters['arity'] = format_arity +env.filters['pinned'] = format_pinned +env.filters['flags'] = format_flags +env.filters['attr_size'] = format_attr_size +env.filters['opindex'] = format_opindex +env.filters['isnot'] = filter_isnot +env.filters['hasnot'] = filter_hasnot +env.filters['arguments'] = format_arguments +env.filters['parameters'] = format_parameters +env.filters['escape_keywords'] = format_escape_keywords def prepare_attr(attr): if "init" in attr: - return dict(type = attr["type"], name = attr["name"], init = attr["init"]) + return dict( + type = attr["type"], + name = attr["name"], + init = attr["init"], + comment = attr["comment"]) else: - return dict(type = attr["type"], name = attr["name"]) - -def preprocess_node(nodename, node): - # set default attributes - if "is_a" in node: - parent = nodes[node["is_a"]] - node["ins"] = parent["ins"] - if "op_index" in parent: - node["op_index"] = parent["op_index"] - if "pinned" in parent: - node["pinned"] = parent["pinned"] - if "outs" in parent: - node["outs"] = parent["outs"] - - if "outs" in node: - node["mode"] = "mode_T" - node["db"] = "db" - node["dbdecl"] = "dbg_info *db, " - node["dbdeclnocomma"] = "dbg_info *db" - - if "flags" not in node and "abstract" not in node: - print "WARNING: no flags specified for %s (you should say at least 'none')\n" % nodename - - node.setdefault("ins", []) - node.setdefault("arity", len(node["ins"])) - node.setdefault("attrs", []) - node.setdefault("constrname", nodename); - node.setdefault("constructor_args", []) - node.setdefault("attrs_name", nodename.lower()) - node.setdefault("block", "block") - node.setdefault("flags", "none") - - verify_node(nodename, node) + return dict( + type = attr["type"], + name = attr["name"], + comment = attr["comment"]) + +def preprocess_node(node): + verify_node(node) + + setdefault(node, "attrs_name", node.name.lower()) + setdefault(node, "block", "block") # construct node arguments arguments = [ ] initattrs = [ ] - specialconstrs = [ ] - for input in node["ins"]: - arguments.append(dict(type = "ir_node *", name = "irn_" + input)) - - if node["arity"] == "variable" or node["arity"] == "dynamic": - arguments.append(dict(type = "int", name = "arity")) - arguments.append(dict(type = "ir_node **", name = "in")) - - if "mode" not in node: - arguments.append(dict(type = "ir_mode *", name = "mode")) - node["mode"] = "mode" - - attrs_with_special = 0 - for attr in node["attrs"]: - attr.setdefault("initname", "." + attr["name"]) - - if "special" in attr: - if not "init" in attr: - print "Node type %s has an attribute with a \"special\" entry but without \"init\"" % nodename - sys.exit(1) - - if attrs_with_special != 0: - print "Node type %s has more than one attribute with a \"special\" entry" % nodename - sys.exit(1) - - attrs_with_special += 1 - - if "prefix" in attr["special"]: - specialname = attr["special"]["prefix"] + nodename - elif "suffix" in attr["special"]: - specialname = nodename + attr["special"]["suffix"] - else: - print "Unknown special constructor type for node type %s" % nodename - sys.exit(1) - - specialconstrs.append( - dict( - constrname = specialname, - attr = attr - ) - ) - elif not "init" in attr: - arguments.append(prepare_attr(attr)) + for input in node.ins: + arguments.append(dict( + type = "ir_node *", + name = "irn_" + input[0], + comment = input[1])) + + if node.arity == "variable" or node.arity == "dynamic": + arguments.append(dict( + type = "int", + name = "arity", + comment = "size of additional inputs array")) + arguments.append(dict( + type = "ir_node *const *", + name = "in", + comment = "additional inputs")) + + if not hasattr(node, "mode"): + arguments.append(dict( + type = "ir_mode *", + name = "mode", + comment = "mode of the operations result")) + node.mode = "mode" + + for attr in node.attrs: + attr["fqname"] = "." + attr["name"] + if "init" in attr: + continue + arguments.append(attr) # dynamic pin state means more constructor arguments if is_dynamic_pinned(node): - if "pinned_init" in node: + if hasattr(node, "pinned_init"): initattrs.append(dict( - initname = ".exc.pin_state", - init = node["pinned_init"] + fqname = ".exc.pin_state", + init = node.pinned_init )) else: - node["constructor_args"].append( + node.constructor_args.append( dict( - name = "pin_state", - type = "op_pin_state" + name = "pin_state", + type = "op_pin_state", + comment = "pinned state", ) ) initattrs.append(dict( - initname = ".exc.pin_state", - init = "pin_state" + fqname = ".exc.pin_state", + init = "pin_state" )) - for arg in node["constructor_args"]: + for arg in node.constructor_args: arguments.append(prepare_attr(arg)) - if arg["type"] == "ir_cons_flags": - name = arg["name"] - initattrs.append(dict(initname = ".exc.pin_state", - init = name + " & cons_floats ? op_pin_state_floats : op_pin_state_pinned")) - initattrs.append(dict(initname = ".volatility", - init = name + " & cons_volatile ? volatility_is_volatile : volatility_non_volatile")) - initattrs.append(dict(initname = ".aligned", - init = name + " & cons_unaligned ? align_non_aligned : align_is_aligned")) - - node["args"] = arguments - node["initattrs"] = initattrs - node["special_constructors"] = specialconstrs -############################# + node.arguments = arguments + node.initattrs = initattrs -constructor_template = env.from_string(''' +############################# -ir_node *new_rd_{{node["constrname"]}}({{node["dbdecl"]}}ir_graph *irg{{node|blockdecl}}{{node|argdecls}}) +gen_ircons_c_inl_template = env.from_string( +'''/* Warning: automatically generated code */ + +{%- for node in nodes %} +{%- if not node.noconstructor %} +ir_node *new_rd_{{node.name}}( + {%- filter parameters %} + dbg_info *dbgi + {{node|blockparameter}} + {{node|nodeparameters}} + {% endfilter %}) { ir_node *res; - ir_graph *rem = current_ir_graph; + {%- if node.arity == "dynamic" %} + int i; + {%- endif %} + {{node|irgassign}} {{node|insdecl}} - current_ir_graph = irg; - res = new_ir_node({{node["db"]}}, irg, {{node["block"]}}, op_{{nodename}}, {{node["mode"]}}, {{node|arity_and_ins}}); - {% for attr in node["attrs"] -%} - res->attr.{{node["attrs_name"]}}{{attr["initname"]}} = + + res = new_ir_node( + {%- filter arguments %} + dbgi + irg + {{node.block}} + op_{{node.name}} + {{node.mode}} + {{node|arity_and_ins}} + {% endfilter %}); + {%- if node.arity == "dynamic" %} + for (i = 0; i < arity; ++i) { + add_irn_n(res, in[i]); + } + {%- endif %} + {%- for attr in node.attrs %} + res->attr.{{node.attrs_name}}{{attr["fqname"]}} = {%- if "init" in attr %} {{ attr["init"] -}}; {%- else %} {{ attr["name"] -}}; - {% endif %} - {% endfor %} - {%- for attr in node["initattrs"] -%} - res->attr.{{node["attrs_name"]}}{{attr["initname"]}} = {{ attr["init"] -}}; + {%- endif %} + {%- endfor %} + {%- for attr in node.initattrs %} + res->attr.{{node.attrs_name}}{{attr["fqname"]}} = {{ attr["init"] -}}; {%- endfor %} - {{- node["init"] }} - {% if node["optimize"] != False -%} - res = optimize_node(res); - {% endif -%} - IRN_VRFY_IRG(res, irg); - current_ir_graph = rem; + {{- node.init }} + res = optimize_node(res); + irn_verify_irg(res, irg); + {{- node.init_after_opt }} return res; } -ir_node *new_r_{{node["constrname"]}}(ir_graph *irg{{node|blockdecl}}{{node|argdecls}}) +ir_node *new_r_{{node.name}}( + {%- filter parameters %} + {{node|blockparameter}} + {{node|nodeparameters}} + {% endfilter %}) { - {% if node["nodbginfo"] -%} - return new_rd_{{node["constrname"]}}(irg{{node|block}}{{node|args}}); - {%- else -%} - return new_rd_{{node["constrname"]}}(NULL, irg{{node|block}}{{node|args}}); - {%- endif %} + return new_rd_{{node.name}}( + {%- filter arguments %} + NULL + {{node|blockargument}} + {{node|nodearguments}} + {% endfilter %}); } -ir_node *new_d_{{node["constrname"]}}({{node["dbdeclnocomma"]}}{{node|argdecls(node["nodbginfo"])}}) +ir_node *new_d_{{node.name}}( + {%- filter parameters %} + dbg_info *dbgi + {{node|nodeparameters}} + {% endfilter %}) { ir_node *res; - {{ node["d_pre"] }} - {% if node["nodbginfo"] -%} - res = new_rd_{{node["constrname"]}}(current_ir_graph{{node|curblock}}{{node|args}}); - {%- else -%} - res = new_rd_{{node["constrname"]}}(db, current_ir_graph{{node|curblock}}{{node|args}}); - {%- endif %} - {{ node["d_post"] }} + assert(get_irg_phase_state(current_ir_graph) == phase_building); + res = new_rd_{{node.name}}( + {%- filter parameters %} + dbgi + {{node|curblock}} + {{node|nodearguments}} + {% endfilter %}); return res; } -ir_node *new_{{node["constrname"]}}({{node|argdecls(True, True)}}) +ir_node *new_{{node.name}}( + {%- filter parameters %} + {{node|nodeparameters}} + {% endfilter %}) { - {% if node["nodbginfo"] -%} - return new_d_{{node["constrname"]}}({{node|args(True)}}); - {%- else -%} - return new_d_{{node["constrname"]}}(NULL{{node|args}}); - {%- endif %} + return new_d_{{node.name}}( + {%- filter arguments %} + NULL + {{node|nodearguments}} + {% endfilter %}); } +{% endif %} +{%- endfor %} ''') -irnode_h_template = env.from_string(''' -/* Warning: automatically generated code */ +irnode_h_template = env.from_string( +'''/* Warning: automatically generated code */ -{% for nodename, node in nodes|isnot('custom_is') %} -static inline int _is_{{nodename}}(const ir_node *node) +{%- for node in nodes|isnot('custom_is') %} +static inline int _is_{{node.name}}(const ir_node *node) { assert(node != NULL); - return _get_irn_op(node) == op_{{nodename}}; + return _get_irn_op(node) == op_{{node.name}}; } -{% endfor %} +{%- endfor -%} -{% for nodename, node in nodes %} -#define is_{{nodename}}(node) _is_{{nodename}}(node) +{% for node in nodes %} +#define is_{{node.name}}(node) _is_{{node.name}}(node) {%- endfor %} ''') -irnode_template = env.from_string(''' -/* Warning: automatically generated code */ -{% for nodename, node in nodes %} -int (is_{{nodename}})(const ir_node *node) +irnode_template = env.from_string( +'''/* Warning: automatically generated code */ +{% for node in nodes %} +int (is_{{node.name}})(const ir_node *node) { - return _is_{{nodename}}(node); + return _is_{{node.name}}(node); } {% endfor %} + +{%- for node in nodes %} +{%- for attr in node.attrs|hasnot("noprop") %} +{{attr.type}} (get_{{node.name}}_{{attr.name}})(const ir_node *node) +{ + assert(is_{{node.name}}(node)); + return node->attr.{{node.attrs_name}}.{{attr.name}}; +} + +void (set_{{node.name}}_{{attr.name}})(ir_node *node, {{attr.type}} {{attr.name}}) +{ + assert(is_{{node.name}}(node)); + node->attr.{{node.attrs_name}}.{{attr.name}} = {{attr.name}}; +} +{% endfor -%} +{% endfor -%} + +{%- for node in nodes %} +{%- for in in node.ins %} +ir_node *(get_{{node.name}}_{{in[0]}})(const ir_node *node) +{ + assert(is_{{node.name}}(node)); + return get_irn_n(node, {{node.ins.index(in)}}); +} + +void (set_{{node.name}}_{{in[0]}})(ir_node *node, ir_node *{{in[0]|escape_keywords}}) +{ + assert(is_{{node.name}}(node)); + set_irn_n(node, {{node.ins.index(in)}}, {{in[0]|escape_keywords}}); +} +{% endfor %} +{% endfor %} ''') -irop_template = env.from_string(''' -/* Warning: automatically generated code */ -{% for nodename, node in nodes %} -ir_op *op_{{nodename}}; ir_op *get_op_{{nodename}}(void) { return op_{{nodename}}; } +irop_template = env.from_string( +'''/* Warning: automatically generated code */ +{% for node in nodes %} +ir_op *op_{{node.name}}; ir_op *get_op_{{node.name}}(void) { return op_{{node.name}}; } {%- endfor %} void init_op(void) { - {% for nodename, node in nodes %} - op_{{nodename}} = new_ir_op(iro_{{nodename}}, "{{nodename}}", {{node|pinned}}, {{node|flags}}, {{node|arity}}, {{node|opindex}}, {{node|attr_size}}, NULL); + {% for node in nodes %} + op_{{node.name}} = new_ir_op( + {%- filter arguments %} + iro_{{node.name}} + "{{node.name}}" + {{node|pinned}} + {{node|flags}} + {{node|arity}} + {{node|opindex}} + {{node|attr_size}} + NULL + {% endfilter %}); {%- endfor %} be_init_op(); @@ -393,51 +462,189 @@ void init_op(void) void finish_op(void) { - {% for nodename, node in nodes %} - free_ir_op(op_{{nodename}}); op_{{nodename}} = NULL; + {% for node in nodes %} + free_ir_op(op_{{node.name}}); op_{{node.name}} = NULL; {%- endfor %} } + +''') + +nodeops_h_template = env.from_string( +'''/* Warning: automatically generated code */ +#ifndef FIRM_IR_NODEOPS_H +#define FIRM_IR_NODEOPS_H + +#include "firm_types.h" + +/** + * @addtogroup ir_node + * @{ + */ + +{% for node in nodes -%} +{% if node.outs %} +/** + * Projection numbers for result of {{node.name}} node (use for Proj nodes) + */ +typedef enum { + {% for out in node.outs -%} + pn_{{node.name}}_{{out[0]}} + {%- if out.__len__() > 2 %} = {{out[2]}}{% endif %}, /**< {{out[1]}} */ + {% endfor -%} + pn_{{node.name}}_max +} pn_{{node.name}}; +{% endif %} +{%- endfor %} + +{% for node in nodes %} +{%- if not node.noconstructor %} +/** + * Construct {{node.name|a_an}} node. + * + * @param dbgi A pointer to debug information. +{{ node|blockparameterhelp -}} +{{ node|nodeparametershelp -}} + */ +FIRM_API ir_node *new_rd_{{node.name}}( + {%- filter parameters %} + dbg_info *dbgi + {{node|blockparameter}} + {{node|nodeparameters}} + {% endfilter %}); + +/** + * Construct {{node.name|a_an}} node. + * +{{ node|blockparameterhelp -}} +{{ node|nodeparametershelp -}} + */ +FIRM_API ir_node *new_r_{{node.name}}( + {%- filter parameters %} + {{node|blockparameter}} + {{node|nodeparameters}} + {% endfilter %}); + +/** + * Construct {{node.name|a_an}} node. + * + * @param dbgi A pointer to debug information. +{{ node|nodeparametershelp -}} + */ +FIRM_API ir_node *new_d_{{node.name}}( + {%- filter parameters %} + dbg_info *dbgi + {{node|nodeparameters}} + {% endfilter %}); + +/** + * Construct {{node.name|a_an}} node. + * +{{ node|nodeparametershelp -}} + */ +FIRM_API ir_node *new_{{node.name}}( + {%- filter parameters %} + {{node|nodeparameters}} + {% endfilter %}); +{%- endif %} +{% endfor %} + +{% for node in nodes %} +/** Return true of the node is a {{node.name}} node. */ +FIRM_API int is_{{node.name}}(const ir_node *node); +{%- endfor %} + +{% for node in nodes %} +{% for in in node.ins -%} +FIRM_API ir_node *get_{{node.name}}_{{in[0]}}(const ir_node *node); +void set_{{node.name}}_{{in[0]}}(ir_node *node, ir_node *{{in[0]|escape_keywords}}); +{% endfor -%} +{% for attr in node.attrs|hasnot("noprop") -%} +FIRM_API {{attr.type}} get_{{node.name}}_{{attr.name}}(const ir_node *node); +FIRM_API void set_{{node.name}}_{{attr.name}}(ir_node *node, {{attr.type}} {{attr.name}}); +{% endfor -%} +{% endfor -%} + +/** @} */ + +#endif + +''') + +opcodes_h_template = env.from_string( +'''/* Warning: automatically generated code */ +#ifndef FIRM_IR_OPCODES_H +#define FIRM_IR_OPCODES_H + +/** The opcodes of the libFirm predefined operations. */ +typedef enum ir_opcode { +{%- for node in nodes %} + iro_{{node.name}}, +{%- endfor %} + iro_First = iro_{{nodes[0].name}}, + iro_Last = iro_{{nodes[-1].name}}, + + beo_First, + /* backend specific nodes */ + beo_Spill = beo_First, + beo_Reload, + beo_Perm, + beo_MemPerm, + beo_Copy, + beo_Keep, + beo_CopyKeep, + beo_Call, + beo_Return, + beo_AddSP, + beo_SubSP, + beo_IncSP, + beo_Start, + beo_FrameAddr, + /* last backend node number */ + beo_Last = beo_FrameAddr, + iro_MaxOpcode +} ir_opcode; + +{% for node in nodes %} +FIRM_API ir_op *op_{{node.name}}; +{%- endfor %} + +{% for node in nodes %} +FIRM_API ir_op *get_op_{{node.name}}(void); +{%- endfor %} + +#endif + ''') ############################# -def main(argv): - """the main function""" +def prepare_nodes(): + real_nodes = [] + for node in nodes: + if isAbstract(node): + continue + real_nodes.append(node) + for node in real_nodes: + preprocess_node(node) + + return real_nodes + +def main(argv): if len(argv) < 3: print "usage: %s specname(ignored) destdirectory" % argv[0] sys.exit(1) gendir = argv[2] + # hardcoded path to libfirm/include/libfirm + gendir2 = argv[2] + "/../../include/libfirm" - # List of TODOs - niymap = ["ASM", "CallBegin", "Const", "Const_type", "Const_long", - "defaultProj", "Dummy", "Phi", "simpleSel", "SymConst", "SymConst_type", - "Sync"] + real_nodes = prepare_nodes() file = open(gendir + "/gen_ir_cons.c.inl", "w") - for nodename, node in do_dictsort(nodes): - preprocess_node(nodename, node) - if nodename in niymap: - continue - if "abstract" not in node and "singleton" not in node: - file.write(constructor_template.render(vars())) - - if "special_constructors" in node: - for special in node["special_constructors"]: - node["constrname"] = special["constrname"] - special["attr"]["init"] = special["attr"]["special"]["init"] - file.write(constructor_template.render(vars())) - file.write("\n") + file.write(gen_ircons_c_inl_template.render(nodes = real_nodes)) file.close() - real_nodes = dict() - for nodename, node in nodes.iteritems(): - if "abstract" in node: - continue - real_nodes[nodename] = node - real_nodes = do_dictsort(real_nodes) - file = open(gendir + "/gen_irnode.h", "w") file.write(irnode_h_template.render(nodes = real_nodes)) file.close() @@ -450,5 +657,12 @@ def main(argv): file.write(irop_template.render(nodes = real_nodes)) file.close() -if __name__ == "__main__": - main(sys.argv) + file = open(gendir2 + "/opcodes.h", "w") + file.write(opcodes_h_template.render(nodes = real_nodes)) + file.close() + + file = open(gendir2 + "/nodeops.h", "w") + file.write(nodeops_h_template.render(nodes = real_nodes)) + file.close() + +main(sys.argv)