gen_irio.c.inl 3.19 KB
Newer Older
Matthias Braun's avatar
Matthias Braun committed
1
{{warning}}
2
{%- for node in nodes|has('serializer') %}
Matthias Braun's avatar
Matthias Braun committed
3
4
static ir_node *read_{{node.name}}(read_env_t *env)
{
5
	{%- if not node.block %}
Matthias Braun's avatar
Matthias Braun committed
6
7
8
	ir_node *block = read_node_ref(env);
	{%- endif %}
	{%- for input in node.ins %}
9
	ir_node *irn_{{input.name}} = read_node_ref(env);
Matthias Braun's avatar
Matthias Braun committed
10
11
12
13
14
	{%- endfor %}
	{%- if not hasattr(node, "mode") %}
	ir_mode *mode = read_mode_ref(env);
	{%- endif %}
	{%- for attr in node.attrs %}
15
	{{attr.type}} {{attr.name}} = read_{{attr.type|simplify_type}}(env);
Matthias Braun's avatar
Matthias Braun committed
16
	{%- endfor %}
17
	{%- if is_dynamic_pinned(node) %}
Matthias Braun's avatar
Matthias Braun committed
18
19
20
21
22
23
	op_pin_state pin_state = read_pin_state(env);
	{%- endif %}
	{%- if "fragile" in node.flags %}
	bool throws = read_throws(env);
	{%- endif %}
	{%- if node.arity == "dynamic" or node.arity == "variable" %}
24
25
	int arity = read_preds(env);
	ir_node **in = (ir_node**)obstack_finish(&env->preds_obst);
Matthias Braun's avatar
Matthias Braun committed
26
	{%- endif %}
27
28
	{%- if node.attrs|has('to_flags') %}
	ir_cons_flags flags = cons_none
Matthias Braun's avatar
Matthias Braun committed
29
		{%- for attr in node.attrs %}
30
			{%- if attr.to_flags %}
31
		| ({{attr.to_flags|stringformat(attr.name)}})
Matthias Braun's avatar
Matthias Braun committed
32
33
			{%- endif %}
		{%- endfor %}
34
35
		{%- if is_dynamic_pinned(node) %}
		| (pin_state == op_pin_state_floats ? cons_floats : cons_none)
Matthias Braun's avatar
Matthias Braun committed
36
37
		{%- endif %}
		{%- if "fragile" in node.flags %}
38
39
40
		| (throws ? cons_throws_exception : cons_none)
		{%- endif -%}
		;
Matthias Braun's avatar
Matthias Braun committed
41
	{%- endif %}
42
	ir_node *res = new_r_{{node.name}}(
Matthias Braun's avatar
Matthias Braun committed
43
		{%- filter arguments %}
44
45
46
			{{node|block}}
			{{node.arguments|args}}
		{%- endfilter %});
Matthias Braun's avatar
Matthias Braun committed
47
48

	{%- if node.arity == "dynamic" or node.arity == "variable" %}
49
	obstack_free(&env->preds_obst, in);
Matthias Braun's avatar
Matthias Braun committed
50
	{%- endif %}
51
	{%- for attr in node.attrs|has('init') %}
Matthias Braun's avatar
Matthias Braun committed
52
53
54
	set_{{node.name}}_{{attr.name}}(res, {{attr.name}});
	{%- endfor %}
	{%- if not node.constructorFlags %}
55
		{%- if is_dynamic_pinned(node) and hasattr(node, "pinned_init") %}
Matthias Braun's avatar
Matthias Braun committed
56
57
58
59
60
61
62
63
64
65
	set_irn_pinned(res, pin_state);
		{%- endif %}
		{%- if "fragile" in node.flags and hasattr(node, "throws_init") %}
	ir_set_throws_exception(res, throws);
		{%- endif %}
	{%- endif %}
	return res;
}
{% endfor %}

66
{%- for node in nodes|has('serializer') %}
Matthias Braun's avatar
Matthias Braun committed
67
68
69
70
static void write_{{node.name}}(write_env_t *env, const ir_node *node)
{
	write_symbol(env, "{{node.name}}");
	write_node_nr(env, node);
71
	{%- if not node.block %}
Matthias Braun's avatar
Matthias Braun committed
72
73
74
	write_node_ref(env, get_nodes_block(node));
	{%- endif %}
	{%- for input in node.ins %}
75
	write_node_ref(env, get_{{node.name}}_{{input.name}}(node));
Matthias Braun's avatar
Matthias Braun committed
76
77
78
79
80
	{%- endfor %}
	{%- if not hasattr(node, "mode") %}
	write_mode_ref(env, get_irn_mode(node));
	{%- endif %}
	{%- for attr in node.attrs %}
81
	write_{{attr.type|simplify_type}}(env, get_{{node.name}}_{{attr.name}}(node));
Matthias Braun's avatar
Matthias Braun committed
82
	{%- endfor %}
83
	{%- if is_dynamic_pinned(node) %}
Matthias Braun's avatar
Matthias Braun committed
84
85
86
87
88
89
90
91
92
93
94
95
96
	write_pin_state(env, get_irn_pinned(node));
	{%- endif %}
	{%- if "fragile" in node.flags %}
	write_throws(env, ir_throws_exception(node));
	{%- endif %}
	{%- if node.arity == "dynamic" or node.arity == "variable" %}
	write_pred_refs(env, node, {% if node.ins %}n_{{node.name}}_max+1{% else %}0{%endif%});
	{%- endif %}
}
{% endfor %}

static void register_generated_node_readers(void)
{
97
	{%- for node in nodes|has('serializer') %}
98
	register_node_reader("{{node.name}}", read_{{node.name}});
Matthias Braun's avatar
Matthias Braun committed
99
100
101
102
103
	{%- endfor %}
}

static void register_generated_node_writers(void)
{
104
	{%- for node in nodes|has('serializer') %}
Matthias Braun's avatar
Matthias Braun committed
105
106
107
	register_node_writer(op_{{node.name}}, write_{{node.name}});
	{%- endfor %}
}