Prepared for diff.
[libfirm] / scripts / gen_ir_io.py
index 22c9b09..f8c5c06 100755 (executable)
@@ -53,26 +53,25 @@ def get_io_type(type, attrname, node):
                exportcmd = "write_mode(env, %(val)s);"
        elif type == "ir_entity*":
                importcmd = "ir_entity *%s = read_entity(env);" % attrname
-               exportcmd = """write_entity_ref(env, %(val)s);"""
+               exportcmd = "write_entity_ref(env, %(val)s);"
        elif type == "ir_type*":
                importcmd = "ir_type *%s = read_type(env);" % attrname
-               exportcmd = """write_type_ref(env, %(val)s);"""
+               exportcmd = "write_type_ref(env, %(val)s);"
        elif type == "long" and node.name == "Proj":
                importcmd = "long %s = read_long(env);" % attrname
-               exportcmd = """write_long(env, %(val)s);"""
-       elif type == "pn_Cmp" or type == "ir_where_alloc":
+               exportcmd = "write_long(env, %(val)s);"
+       elif type == "ir_relation" or type == "ir_where_alloc":
                importcmd = "%s %s = (%s) read_long(env);" % (type, attrname, type)
-               exportcmd = """write_long(env, (long) %(val)s);"""
-       elif type == "ir_cons_flags" and node.name == "Store":
+               exportcmd = "write_long(env, (long) %(val)s);"
+       elif type == "ir_align":
+               importcmd = "ir_align %s = read_align(env);" % attrname
+               exportcmd = "write_align(env, %(val)s);"
+       elif type == "ir_volatility":
+               importcmd = "ir_volatility %s = read_volatility(env);" % attrname
+               exportcmd = "write_volatility(env, %(val)s);"
+       elif type == "ir_cons_flags":
                importcmd = "ir_cons_flags %s = get_cons_flags(env);" % attrname
-               exportcmd = """write_pin_state(env, irn);
-                       write_volatility(env, irn);
-                       write_align(env, irn);"""
-       elif type == "ir_cons_flags" and node.name == "Load":
-               importcmd = "ir_cons_flags %s = get_cons_flags(env);" % attrname
-               exportcmd = """write_pin_state(env, irn);
-                       write_volatility(env, irn);
-                       write_align(env, irn);"""
+               exportcmd = "" # can't really export cons_flags
        elif type == "op_pin_state":
                importcmd = "op_pin_state %s = read_pin_state(env);" % attrname
                exportcmd = "write_pin_state(env, irn);"
@@ -87,13 +86,13 @@ def get_io_type(type, attrname, node):
                exportcmd = "write_cond_jmp_predicate(env, irn);"
        elif type == "int":
                importcmd = "int %s = read_int(env);" % attrname
-               exportcmd = """write_int(env, %(val)s);"""
+               exportcmd = "write_int(env, %(val)s);"
        elif type == "unsigned":
                importcmd = "unsigned %s = read_unsigned(env);" % attrname
-               exportcmd = """write_unsigned(env, %(val)s);"""
+               exportcmd = "write_unsigned(env, %(val)s);"
        elif type == "long":
                importcmd = "long %s = read_long(env);" % attrname
-               exportcmd = """write_long(env, %(val)s);"""
+               exportcmd = "write_long(env, %(val)s);"
        else:
                warning("cannot generate import/export for node %s: unsupported attribute type: %s" % (node.name, type))
                importcmd = """// BAD: %s %s
@@ -123,7 +122,6 @@ def preprocess_node(node):
        # construct node arguments
        arguments = [ ]
        initargs = [ ]
-       specialconstrs = [ ]
        i = 1
        for input in node.ins:
                arguments.append("preds[%i]" % i)
@@ -136,36 +134,9 @@ def preprocess_node(node):
        if not hasattr(node, "mode"):
                arguments.append("mode")
 
-       attrs_with_special = 0
        for attr in node.attrs:
                prepare_attr(node, attr)
-               if "special" in attr:
-                       if not "init" in attr:
-                               warning("Node type %s has an attribute with a \"special\" entry but without \"init\"" % node.name)
-                               sys.exit(1)
-
-                       if attrs_with_special != 0:
-                               warning("Node type %s has more than one attribute with a \"special\" entry" % node.name)
-                               sys.exit(1)
-
-                       attrs_with_special += 1
-
-                       if "prefix" in attr["special"]:
-                               specialname = attr["special"]["prefix"] + node.name
-                       elif "suffix" in attr["special"]:
-                               specialname = node.name + attr["special"]["suffix"]
-                       else:
-                               error("Unknown special constructor type for node type %s" % node.name)
-                               sys.exit(1)
-
-                       specialconstrs.append(
-                               dict(
-                                       constrname = specialname,
-                                       attrname = attr["name"],
-                                       value = attr["special"]["init"]
-                               )
-                       )
-               elif "init" in attr:
+               if "init" in attr:
                        if attr["type"] == "op_pin_state":
                                initfunc = "set_irn_pinned"
                        else:
@@ -180,7 +151,6 @@ def preprocess_node(node):
 
        node.arguments = arguments
        node.initargs = initargs
-       node.special_constructors = specialconstrs
 
 export_attrs_template = env.from_string('''
        case iro_{{node.name}}:
@@ -199,15 +169,6 @@ import_attrs_template = env.from_string('''
                {% for attr in node.constructor_args %}
                {{attr.importcmd}}
                {% endfor -%}
-               {% for special in node.special_constructors %}
-               if ({{special.attrname}} == {{special.value}})
-                       newnode = new_r_{{special.constrname}}(
-{%- filter arguments %}
-{{node|block}}
-{{node.arguments|args}}
-{% endfilter %});
-               else
-               {% endfor -%}
                newnode = new_r_{{node.name}}(
 {%- filter arguments %}
 {{node|block}}