4137a12b4e11603a9bfcc5786a36a5fb800ae837
[libfirm] / scripts / ir_spec.py
1 nodes = dict(
2
3 #
4 # Abstract node types
5 #
6 unop = dict(
7         abstract = True,
8         ins      = [ "op" ]
9 ),
10
11 binop = dict(
12         abstract = True,
13         ins      = [ "left", "right" ]
14 ),
15
16 #
17 # Real node types
18 #
19 Abs = dict(
20         is_a     = "unop"
21 ),
22
23 Add = dict(
24         is_a     = "binop"
25 ),
26
27 Alloc = dict(
28         ins   = [ "mem", "size" ],
29         outs  = [ "M", "X_regular", "X_except", "res" ],
30         attrs = [
31                 dict(
32                         name = "type",
33                         type = "ir_type*"
34                 ),
35                 dict(
36                         name = "where",
37                         type = "ir_where_alloc"
38                 )
39         ]
40 ),
41
42 Anchor = dict(
43         mode       = "mode_ANY",
44         ins        = [ "end_block", "start_block", "end", "start",
45                        "end_reg", "end_except", "initial_exec",
46                                    "frame", "tls", "initial_mem", "args",
47                                    "bad", "no_mem" ],
48         knownBlock = True,
49         noconstr   = True
50 ),
51
52 And = dict(
53         is_a     = "binop"
54 ),
55
56 Bad = dict(
57         mode       = "mode_Bad",
58         knownBlock = True,
59 ),
60
61 Block = dict(
62         mode       = "mode_BB",
63         knownBlock = True,
64         block      = "NULL",
65         noconstr   = True,
66         optimize   = False,
67         arity      = "variable",
68
69         init = '''
70         /* macroblock header */
71         res->in[0] = res;
72
73         res->attr.block.is_dead     = 0;
74         res->attr.block.is_mb_head  = 1;
75         res->attr.block.has_label   = 0;
76         res->attr.block.irg         = irg;
77         res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
78         res->attr.block.in_cg       = NULL;
79         res->attr.block.cg_backedge = NULL;
80         res->attr.block.extblk      = NULL;
81         res->attr.block.mb_depth    = 0;
82         res->attr.block.label       = 0;
83
84         set_Block_matured(res, 1);
85         set_Block_block_visited(res, 0);
86         ''',
87
88         d_pre = '''
89         int i;
90         int has_unknown = 0;
91         ''',
92
93         d_post = '''
94         /* Create and initialize array for Phi-node construction. */
95         if (get_irg_phase_state(current_ir_graph) == phase_building) {
96                 res->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,
97                                                       current_ir_graph->n_loc);
98                 memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
99         }
100
101         for (i = arity - 1; i >= 0; i--)
102                 if (is_Unknown(in[i])) {
103                         has_unknown = 1;
104                         break;
105                 }
106
107         if (!has_unknown) res = optimize_node(res);
108
109         current_ir_graph->current_block = res;
110
111         IRN_VRFY_IRG(res, current_ir_graph);
112         ''',
113
114         java_add   = '''
115         public void addPred(Node node) {
116                 binding_cons.add_immBlock_pred(ptr, node.ptr);
117         }
118
119         public void mature() {
120                 binding_cons.mature_immBlock(ptr);
121         }
122
123         @Override
124         public Block getBlock() {
125                 return null;
126         }
127
128         public boolean blockVisited() {
129                 return 0 != binding.Block_block_visited(ptr);
130         }
131
132         public void markBlockVisited() {
133                 binding.mark_Block_block_visited(ptr);
134         }''',
135 ),
136
137 Borrow = dict(
138         is_a     = "binop"
139 ),
140
141 Builtin = dict(
142         ins      = [ "mem" ],
143         arity    = "variable",
144         outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
145         attrs    = [
146                 dict(
147                         type = "ir_builtin_kind",
148                         name = "kind"
149                 ),
150                 dict(
151                         type = "ir_type*",
152                         name = "type"
153                 )
154         ]
155 ),
156
157 Call = dict(
158         ins      = [ "mem", "ptr" ],
159         arity    = "variable",
160         outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
161         attrs    = [
162                 dict(
163                         type = "ir_type*",
164                         name = "type"
165                 )
166         ]
167 ),
168
169 Carry = dict(
170         is_a     = "binop"
171 ),
172
173 Cast = dict(
174         ins      = [ "op" ],
175         mode     = "get_irn_mode(irn_op)",
176         attrs    = [
177                 dict(
178                         type = "ir_type*",
179                         name = "type"
180                 )
181         ],
182         init     = "assert(is_atomic_type(type));"
183 ),
184
185 Cmp = dict(
186         is_a     = "binop",
187         outs     = [ "False", "Eq", "Lt", "Le", "Gt", "Ge", "Lg", "Leg", "Uo", "Ue", "Ul", "Ule", "Ug", "Uge", "Ne", "True" ],
188 ),
189
190 Cond = dict(
191         ins      = [ "selector" ],
192         outs     = [ "false", "true" ],
193         attrs    = [
194                 dict(
195                         name = "kind",
196                         type = "cond_kind",
197                         init = "dense"
198                 ),
199                 dict(
200                         name = "default_proj",
201                         type = "long",
202                         init = "0"
203                 ),
204                 dict(
205                         name = "jmp_pred",
206                         type = "cond_jmp_predicate",
207                         init = "COND_JMP_PRED_NONE"
208                 )
209         ]
210 ),
211
212 Confirm = dict(
213         ins      = [ "value", "bound" ],
214         mode     = "get_irn_mode(irn_value)",
215         attrs    = [
216                 dict(
217                         name = "cmp",
218                         type = "pn_Cmp"
219                 ),
220         ],
221 ),
222
223 Const = dict(
224         mode       = "",
225         knownBlock = True,
226         attrs_name = "con",
227         attrs      = [
228                 dict(
229                         type = "tarval*",
230                         name = "tarval",
231                 )
232         ],
233 ),
234
235 Conv = dict(
236         is_a     = "unop",
237         attrs = [
238                 dict(
239                         name = "strict",
240                         type = "int",
241                         init = "0",
242                         special = dict(
243                                 prefix = "strict",
244                                 init = "1"
245                         )
246                 )
247         ]
248 ),
249
250 CopyB = dict(
251         ins   = [ "mem", "dst", "src" ],
252         outs  = [ "M", "X_regular", "X_except" ],
253         attrs = [
254                 dict(
255                         name = "type",
256                         type = "ir_type*"
257                 )
258         ]
259 ),
260
261 Div = dict(
262         ins   = [ "mem", "dividend", "divisor" ],
263         outs  = [ "M", "X_regular", "X_except", "res" ],
264         attrs = [
265                 dict(
266                         type = "ir_mode*",
267                         name = "resmode"
268                 ),
269                 dict(
270                         name = "state",
271                         type = "op_pin_state"
272                 ),
273                 dict(
274                         name = "no_remainder",
275                         type = "int",
276                         init = "0",
277                         special = dict(
278                                 suffix = "RL",
279                                 init = "1"
280                         )
281                 )
282         ]
283 ),
284
285 DivMod = dict(
286         ins   = [ "mem", "dividend", "divisor" ],
287         outs  = [ "M", "X_regular", "X_except", "res_div", "res_mod" ],
288         attrs = [
289                 dict(
290                         type = "ir_mode*",
291                         name = "resmode"
292                 ),
293                 dict(
294                         name = "state",
295                         type = "op_pin_state"
296                 )
297         ]
298 ),
299
300 End = dict(
301         mode       = "mode_X",
302         op_flags   = "cfopcode",
303         state      = "pinned",
304         arity      = "dynamic",
305         noconstr   = True,
306         optimize   = False
307 ),
308
309 Eor = dict(
310         is_a     = "binop"
311 ),
312
313 Free = dict(
314         ins   = [ "mem", "ptr", "size" ],
315         mode  = "mode_M",
316         attrs = [
317                 dict(
318                         name = "type",
319                         type = "ir_type*"
320                 ),
321                 dict(
322                         name = "where",
323                         type = "ir_where_alloc"
324                 )
325         ]
326 ),
327
328 Id = dict(
329         ins = [ "pred" ]
330 ),
331
332 IJmp = dict(
333         mode     = "mode_X",
334         op_flags = "cfopcode",
335         state    = "pinned",
336         ins      = [ "target" ],
337 ),
338
339 Jmp = dict(
340         mode     = "mode_X",
341         op_flags = "cfopcode",
342         state    = "pinned",
343         ins      = [],
344 ),
345
346 Load = dict(
347         ins      = [ "mem", "ptr" ],
348         outs     = [ "M", "X_regular", "X_except", "res" ],
349         attrs    = [
350                 dict(
351                         type = "ir_mode*",
352                         name = "mode",
353                         java_name = "load_mode"
354                 ),
355         ],
356         constructor_args = [
357                 dict(
358                         type = "ir_cons_flags",
359                         name = "flags",
360                 ),
361         ],
362         d_post = '''
363 #if PRECISE_EXC_CONTEXT
364         firm_alloc_frag_arr(res, op_Load, &res->attr.load.exc.frag_arr);
365 #endif
366         '''
367 ),
368
369 Minus = dict(
370         is_a     = "unop"
371 ),
372
373 Mod = dict(
374         ins   = [ "mem", "dividend", "divisor" ],
375         outs  = [ "M", "X_regular", "X_except", "res" ],
376         attrs = [
377                 dict(
378                         type = "ir_mode*",
379                         name = "resmode"
380                 ),
381                 dict(
382                         name = "state",
383                         type = "op_pin_state"
384                 )
385         ]
386 ),
387
388 Mul = dict(
389         is_a     = "binop"
390 ),
391
392 Mulh = dict(
393         is_a     = "binop"
394 ),
395
396 Mux = dict(
397         ins      = [ "sel", "false", "true" ]
398 ),
399
400 NoMem = dict(
401         mode       = "mode_M",
402         knownBlock = True,
403 ),
404
405 Not = dict(
406         is_a     = "unop"
407 ),
408
409 Or = dict(
410         is_a     = "binop"
411 ),
412
413 Phi = dict(
414         noconstr = True,
415         state    = "pinned",
416         arity    = "variable",
417 ),
418
419 Pin = dict(
420         ins      = [ "op" ],
421         mode     = "get_irn_mode(irn_op)"
422 ),
423
424 Proj = dict(
425         ins      = [ "pred" ],
426         attrs    = [
427                 dict(
428                         type = "long",
429                         name = "proj",
430                         initname = ""
431                 )
432         ]
433 ),
434
435 Quot = dict(
436         ins   = [ "mem", "dividend", "divisor" ],
437         outs  = [ "M", "X_regular", "X_except", "res" ],
438         attrs = [
439                 dict(
440                         type = "ir_mode*",
441                         name = "resmode"
442                 ),
443                 dict(
444                         name = "state",
445                         type = "op_pin_state"
446                 )
447         ]
448 ),
449
450 Return = dict(
451         ins      = [ "mem" ],
452         arity    = "variable",
453         mode     = "mode_X"
454 ),
455
456 Rotl = dict(
457         is_a     = "binop"
458 ),
459
460 Sel = dict(
461         ins    = [ "mem", "ptr" ],
462         arity  = "variable",
463         mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data",
464         attrs    = [
465                 dict(
466                         type = "ir_entity*",
467                         name = "entity"
468                 )
469         ]
470 ),
471
472 Shl = dict(
473         is_a     = "binop"
474 ),
475
476 Shr = dict(
477         is_a     = "binop"
478 ),
479
480 Shrs = dict(
481         is_a     = "binop"
482 ),
483
484 Start = dict(
485         mode       = "mode_T",
486         op_flags   = "cfopcode",
487         state      = "pinned",
488         noconstr   = True,
489         optimize   = False
490 ),
491
492 Store = dict(
493         ins      = [ "mem", "ptr", "value" ],
494         outs     = [ "M", "X_regular", "X_except" ],
495         constructor_args = [
496                 dict(
497                         type = "ir_cons_flags",
498                         name = "flags",
499                 ),
500         ],
501         d_post = '''
502 #if PRECISE_EXC_CONTEXT
503         firm_alloc_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr);
504 #endif
505         '''
506 ),
507
508 Sub = dict(
509         is_a     = "binop"
510 ),
511
512 SymConst = dict(
513         mode       = "mode_P",
514         knownBlock = True,
515         noconstr   = True,
516         attrs      = [
517                 dict(
518                         type = "ir_entity*",
519                         name = "entity"
520                 )
521         ],
522 ),
523
524 Sync = dict(
525         mode     = "mode_M",
526         optimize = False,
527         arity    = "dynamic"
528 ),
529
530 Tuple = dict(
531         arity    = "variable",
532         mode     = "mode_T",
533 ),
534
535 Unknown = dict(
536         knownBlock = True,
537         block      = "get_irg_start_block(irg)",
538         nodbginfo  = True
539 ),
540 )