Commit 6051e581 authored by Matthias Braun's avatar Matthias Braun
Browse files

rewrite irio import/export code generation for attributes

Avoid "preparation" of export/import commands which baked in values like
the node name which might be changed in subclasses.
- Remove the builtin conversion table in favor of a simple rule to
  convert a C type to a function name part.
parent bb6d50d1
......@@ -414,7 +414,7 @@ static void write_mode_ref(write_env_t *env, ir_mode *mode)
write_string(env, get_mode_name(mode));
}
static void write_tarval(write_env_t *env, ir_tarval *tv)
static void write_tarval_ref(write_env_t *env, ir_tarval *tv)
{
ir_mode *mode = get_tarval_mode(tv);
write_mode_ref(env, mode);
......@@ -430,15 +430,15 @@ static void write_align(write_env_t *env, ir_align align)
fputc(' ', env->file);
}
static void write_builtin_kind(write_env_t *env, const ir_node *node)
static void write_builtin_kind(write_env_t *env, ir_builtin_kind kind)
{
fputs(get_builtin_kind_name(get_Builtin_kind(node)), env->file);
fputs(get_builtin_kind_name(kind), env->file);
fputc(' ', env->file);
}
static void write_cond_jmp_predicate(write_env_t *env, const ir_node *node)
static void write_cond_jmp_predicate(write_env_t *env, cond_jmp_predicate pred)
{
fputs(get_cond_jmp_predicate_name(get_Cond_jmp_pred(node)), env->file);
fputs(get_cond_jmp_predicate_name(pred), env->file);
fputc(' ', env->file);
}
......@@ -491,7 +491,7 @@ static void write_initializer(write_env_t *env, ir_initializer_t *ini)
return;
case IR_INITIALIZER_TARVAL:
write_tarval(env, get_initializer_tarval_value(ini));
write_tarval_ref(env, get_initializer_tarval_value(ini));
return;
case IR_INITIALIZER_NULL:
......@@ -803,7 +803,8 @@ static void write_entity(write_env_t *env, ir_entity *ent)
fputc('\n', env->file);
}
static void write_switch_table(write_env_t *env, const ir_switch_table *table)
static void write_switch_table_ref(write_env_t *env,
const ir_switch_table *table)
{
size_t n_entries = ir_switch_table_get_n_entries(table);
size_t i;
......@@ -814,8 +815,8 @@ static void write_switch_table(write_env_t *env, const ir_switch_table *table)
ir_tarval *min = ir_switch_table_get_min(table, i);
ir_tarval *max = ir_switch_table_get_max(table, i);
write_long(env, pn);
write_tarval(env, min);
write_tarval(env, max);
write_tarval_ref(env, min);
write_tarval_ref(env, max);
}
}
......@@ -1606,7 +1607,7 @@ static ir_relation read_relation(read_env_t *env)
return (ir_relation)read_long(env);
}
static ir_tarval *read_tarval(read_env_t *env)
static ir_tarval *read_tarval_ref(read_env_t *env)
{
ir_mode *tvmode = read_mode_ref(env);
char *str = read_word(env);
......@@ -1616,7 +1617,7 @@ static ir_tarval *read_tarval(read_env_t *env)
return tv;
}
static ir_switch_table *read_switch_table(read_env_t *env)
static ir_switch_table *read_switch_table_ref(read_env_t *env)
{
size_t n_entries = read_size_t(env);
ir_switch_table *table = ir_new_switch_table(env->irg, n_entries);
......@@ -1624,8 +1625,8 @@ static ir_switch_table *read_switch_table(read_env_t *env)
for (i = 0; i < n_entries; ++i) {
long pn = read_long(env);
ir_tarval *min = read_tarval(env);
ir_tarval *max = read_tarval(env);
ir_tarval *min = read_tarval_ref(env);
ir_tarval *max = read_tarval_ref(env);
ir_switch_table_set(table, i, min, max, pn);
}
return table;
......@@ -1650,7 +1651,7 @@ static ir_initializer_t *read_initializer(read_env_t *env)
}
case IR_INITIALIZER_TARVAL:
return create_initializer_tarval(read_tarval(env));
return create_initializer_tarval(read_tarval_ref(env));
case IR_INITIALIZER_NULL:
return get_initializer_null();
......
......@@ -26,77 +26,23 @@ def format_block(node):
else:
return "block"
env = Environment(loader=FileSystemLoader([".", "/"]), keep_trailing_newline=True)
env.filters['args'] = format_args
env.filters['block'] = format_block
env.filters['arguments'] = format_arguments
env.filters['isnot'] = filter_isnot
env.filters['notset'] = filter_notset
env.filters['hasnot'] = filter_hasnot
def get_io_type(type, attrname, node):
if type == "ir_tarval*":
importcmd = "read_tarval(env)"
exportcmd = "write_tarval(env, %(val)s);"
elif type == "ir_mode*":
importcmd = "read_mode_ref(env)"
exportcmd = "write_mode_ref(env, %(val)s);"
elif type == "ir_entity*":
importcmd = "read_entity_ref(env)"
exportcmd = "write_entity_ref(env, %(val)s);"
elif type == "ir_type*":
importcmd = "read_type_ref(env)"
exportcmd = "write_type_ref(env, %(val)s);"
elif type == "long":
importcmd = "read_long(env)"
exportcmd = "write_long(env, %(val)s);"
elif type == "ir_relation":
importcmd = "read_relation(env)"
exportcmd = "write_relation(env, %(val)s);"
elif type == "ir_align":
importcmd = "read_align(env)"
exportcmd = "write_align(env, %(val)s);"
elif type == "ir_volatility":
importcmd = "read_volatility(env)"
exportcmd = "write_volatility(env, %(val)s);"
elif type == "ir_cons_flags":
importcmd = "cons_none"
exportcmd = "" # can't really export cons_flags
elif type == "op_pin_state":
importcmd = "read_pin_state(env)"
exportcmd = "write_pin_state(env, node);"
elif type == "ir_builtin_kind":
importcmd = "read_builtin_kind(env)"
exportcmd = "write_builtin_kind(env, node);"
elif type == "cond_kind":
importcmd = "read_cond_kind(env)"
exportcmd = "write_cond_kind(env, node);"
elif type == "cond_jmp_predicate":
importcmd = "read_cond_jmp_predicate(env)"
exportcmd = "write_cond_jmp_predicate(env, node);"
elif type == "int":
importcmd = "read_int(env)"
exportcmd = "write_int(env, %(val)s);"
elif type == "unsigned":
importcmd = "read_unsigned(env)"
exportcmd = "write_unsigned(env, %(val)s);"
elif type == "long":
importcmd = "read_long(env)"
exportcmd = "write_long(env, %(val)s);"
elif type == "ir_switch_table*":
importcmd = "read_switch_table(env)"
exportcmd = "write_switch_table(env, %(val)s);"
else:
warning("cannot generate import/export for node %s: unsupported attribute type: %s" % (node.name, type))
importcmd = "/* BAD: %s %s */ (%s)0" % (type, attrname, type)
exportcmd = "// BAD: %s" % type
return (importcmd, exportcmd)
def prepare_attr(node, attr):
(importcmd,exportcmd) = get_io_type(attr["type"], attr["name"], node)
attr["importcmd"] = importcmd
attr["exportcmd"] = exportcmd % {"val": "get_%s_%s(node)" % (node.name, attr["name"])}
def format_simplify_type(string):
"""Returns a simplified version of a C type for use in a function name.
Stars are replaced with _ref, spaces removed and the ir_ firm namespace
prefix stripped."""
res = string.replace("*", "_ref").replace(" ", "")
if res.startswith("ir_"):
res = res[3:]
return res
env = Environment(loader=FileSystemLoader([".", "/"]), keep_trailing_newline=True)
env.filters['args'] = format_args
env.filters['block'] = format_block
env.filters['arguments'] = format_arguments
env.filters['simplify_type'] = format_simplify_type
env.filters['isnot'] = filter_isnot
env.filters['notset'] = filter_notset
env.filters['hasnot'] = filter_hasnot
def preprocess_node(node):
if node.customSerializer:
......@@ -116,7 +62,6 @@ def preprocess_node(node):
arguments.append("mode")
for attr in node.attrs:
prepare_attr(node, attr)
if "to_flags" in attr:
node.constructorFlags = True
attr['to_flags'] = attr['to_flags'] % (attr["name"])
......
......@@ -12,7 +12,7 @@ static ir_node *read_{{node.name}}(read_env_t *env)
ir_mode *mode = read_mode_ref(env);
{%- endif %}
{%- for attr in node.attrs %}
{{attr.type}} {{attr.name}} = {{attr.importcmd}};
{{attr.type}} {{attr.name}} = read_{{attr.type|simplify_type}}(env);
{%- endfor %}
{%- if node.dynamic_pinned %}
op_pin_state pin_state = read_pin_state(env);
......@@ -83,7 +83,7 @@ static void write_{{node.name}}(write_env_t *env, const ir_node *node)
write_mode_ref(env, get_irn_mode(node));
{%- endif %}
{%- for attr in node.attrs %}
{{attr.exportcmd}}
write_{{attr.type|simplify_type}}(env, get_{{node.name}}_{{attr.name}}(node));
{%- endfor %}
{%- if node.dynamic_pinned %}
write_pin_state(env, get_irn_pinned(node));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment