#!/usr/bin/env python
import sys
+import re
from jinja2 import Environment, Template
from jinja2.filters import do_dictsort
from spec_util import is_dynamic_pinned, verify_node, isAbstract
sys.stderr.write("Warning: " + msg + "\n");
def format_args(arglist):
- s = ", ".join(arglist)
- if len(s) == 0:
- return ""
- return ", " + s
+ return "\n".join(arglist)
def format_ifnset(string, node, key):
if hasattr(node, key):
def format_block(node):
if hasattr(node, "knownBlock"):
- return ""
+ if hasattr(node, "knownGraph"):
+ return ""
+ return "current_ir_graph"
else:
- return ", get_node(env, preds[0])"
+ return "get_node(env, preds[0])"
+
+def format_arguments(string):
+ args = re.split('\s*\n\s*', string)
+ if args[0] == '':
+ args = args[1:]
+ if len(args) > 0 and args[-1] == '':
+ args = args[:-1]
+ return ", ".join(args)
env = Environment()
-env.filters['args'] = format_args
-env.filters['ifnset'] = format_ifnset
-env.filters['block'] = format_block
+env.filters['args'] = format_args
+env.filters['ifnset'] = format_ifnset
+env.filters['block'] = format_block
+env.filters['arguments'] = format_arguments
def get_io_type(type, attrname, node):
if type == "tarval*":
elif type == "int":
importcmd = "int %s = (int) read_long(env);" % attrname
exportcmd = """fprintf(env->file, "%%d ", %(val)s);"""
+ elif type == "unsigned":
+ importcmd = "unsigned %s = (unsigned) read_long(env);" % attrname
+ exportcmd = """fprintf(env->file, "%%u ", %(val)s);"""
elif type == "long":
importcmd = "long %s = read_long(env);" % attrname
exportcmd = """fprintf(env->file, "%%ld ", %(val)s);"""
{% endfor %}break;''')
import_attrs_template = env.from_string('''
- case iro_{{node.name}}:
- {
+ case iro_{{node.name}}: {
{{"ir_mode *mode = read_mode(env);"|ifnset(node,"mode")}}
- {% for attr in node.attrs %}{{attr.importcmd}}
- {% endfor %}
- {% 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}}(current_ir_graph{{node|block}}{{node.arguments|args}});
- else{% endfor %}
- newnode = new_r_{{node.name}}(current_ir_graph{{node|block}}{{node.arguments|args}});
- {% for (initarg, initfunc) in node.initargs %}{{initfunc}}(newnode, {{initarg}});
- {% endfor %}
+ {% for attr in node.attrs %}
+ {{attr.importcmd}}
+ {% endfor -%}
+ {% 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}}
+{{node.arguments|args}}
+{% endfilter %});
+ {% for (initarg, initfunc) in node.initargs %}
+ {{initfunc}}(newnode, {{initarg}});
+ {% endfor -%}
break;
}
''')
for node in real_nodes:
if node.name in niynodes:
continue
- file.write("\tINSERT(\"" + node.name + "\", tt_iro, iro_" + node.name + ");\n");
+ file.write("\tINSERT(tt_iro, \"%s\", iro_%s);\n" % (node.name, node.name));
file.close()
main(sys.argv)