gen_irio.c.inl 3.24 KB
Newer Older
Matthias Braun's avatar
Matthias Braun committed
1
2
3
4
5
6
7
8
{{warning}}
{%- for node in nodes|notset('customSerializer') %}
static ir_node *read_{{node.name}}(read_env_t *env)
{
	{%- if not node.knownBlock %}
	ir_node *block = read_node_ref(env);
	{%- endif %}
	{%- for input in node.ins %}
9
	ir_node *irn_{{input[0]}} = 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
30
		{%- for attr in node.attrs %}
			{%- if "to_flags" in attr %}
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
	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 %}

{%- for node in nodes|notset('customSerializer') %}
static void write_{{node.name}}(write_env_t *env, const ir_node *node)
{
	write_symbol(env, "{{node.name}}");
	write_node_nr(env, node);
	{%- if not node.knownBlock %}
	write_node_ref(env, get_nodes_block(node));
	{%- endif %}
	{%- for input in node.ins %}
	write_node_ref(env, get_{{node.name}}_{{input[0]}}(node));
	{%- 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
97
	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)
{
	{%- for node in nodes|notset('customSerializer') %}
98
	register_node_reader("{{node.name}}", read_{{node.name}});
Matthias Braun's avatar
Matthias Braun committed
99
100
101
102
103
104
105
106
107
	{%- endfor %}
}

static void register_generated_node_writers(void)
{
	{%- for node in nodes|notset('customSerializer') %}
	register_node_writer(op_{{node.name}}, write_{{node.name}});
	{%- endfor %}
}