365855e7fce927de977929d87c184fe919c03a0e
[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 = "state",
33                         type = "op_pin_state",
34                         initname = ".exc.pin_state",
35                         init = "op_pin_state_pinned"
36                 ),
37                 dict(
38                         name = "type",
39                         type = "ir_type*"
40                 ),
41                 dict(
42                         name = "where",
43                         type = "ir_where_alloc"
44                 )
45         ],
46         d_post = '''
47         #if PRECISE_EXC_CONTEXT
48         firm_alloc_frag_arr(res, op_Alloc, &res->attr.alloc.exc.frag_arr);
49         #endif
50         '''
51 ),
52
53 Anchor = dict(
54         mode       = "mode_ANY",
55         ins        = [ "end_block", "start_block", "end", "start",
56                        "end_reg", "end_except", "initial_exec",
57                                    "frame", "tls", "initial_mem", "args",
58                                    "bad", "no_mem" ],
59         knownBlock = True,
60         noconstr   = True
61 ),
62
63 And = dict(
64         is_a     = "binop"
65 ),
66
67 Bad = dict(
68         mode       = "mode_Bad",
69         knownBlock = True,
70 ),
71
72 Block = dict(
73         mode       = "mode_BB",
74         knownBlock = True,
75         block      = "NULL",
76         noconstr   = True,
77         optimize   = False,
78         arity      = "variable",
79
80         init = '''
81         /* macroblock header */
82         res->in[0] = res;
83
84         res->attr.block.is_dead     = 0;
85         res->attr.block.is_mb_head  = 1;
86         res->attr.block.has_label   = 0;
87         res->attr.block.irg         = irg;
88         res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
89         res->attr.block.in_cg       = NULL;
90         res->attr.block.cg_backedge = NULL;
91         res->attr.block.extblk      = NULL;
92         res->attr.block.mb_depth    = 0;
93         res->attr.block.label       = 0;
94
95         set_Block_matured(res, 1);
96         set_Block_block_visited(res, 0);
97         ''',
98
99         d_pre = '''
100         int i;
101         int has_unknown = 0;
102         ''',
103
104         d_post = '''
105         /* Create and initialize array for Phi-node construction. */
106         if (get_irg_phase_state(current_ir_graph) == phase_building) {
107                 res->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,
108                                                       current_ir_graph->n_loc);
109                 memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
110         }
111
112         for (i = arity - 1; i >= 0; i--)
113                 if (is_Unknown(in[i])) {
114                         has_unknown = 1;
115                         break;
116                 }
117
118         if (!has_unknown) res = optimize_node(res);
119
120         current_ir_graph->current_block = res;
121
122         IRN_VRFY_IRG(res, current_ir_graph);
123         ''',
124
125         java_add   = '''
126         public void addPred(Node node) {
127                 binding_cons.add_immBlock_pred(ptr, node.ptr);
128         }
129
130         public void mature() {
131                 binding_cons.mature_immBlock(ptr);
132         }
133
134         @Override
135         public Block getBlock() {
136                 return null;
137         }
138
139         public boolean blockVisited() {
140                 return 0 != binding.Block_block_visited(ptr);
141         }
142
143         public void markBlockVisited() {
144                 binding.mark_Block_block_visited(ptr);
145         }''',
146 ),
147
148 Borrow = dict(
149         is_a     = "binop"
150 ),
151
152 Bound = dict(
153         ins   = [ "mem", "index", "lower", "upper" ],
154         outs  = [ "M", "X_regular", "X_except", "res" ],
155         attrs = [
156                 dict(
157                         name = "state",
158                         type = "op_pin_state",
159                         initname = ".exc.pin_state",
160                         init = "op_pin_state_pinned"
161                 )
162         ],
163         d_post = '''
164         #if PRECISE_EXC_CONTEXT
165         firm_alloc_frag_arr(res, op_Bound, &res->attr.bound.exc.frag_arr);
166         #endif
167         '''
168 ),
169
170
171 Break = dict(
172         mode = "mode_X"
173 ),
174
175 Builtin = dict(
176         ins      = [ "mem" ],
177         arity    = "variable",
178         outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
179         attrs    = [
180                 dict(
181                         name = "state",
182                         type = "op_pin_state",
183                         initname = ".exc.pin_state",
184                         init = "op_pin_state_pinned"
185                 ),
186                 dict(
187                         type = "ir_builtin_kind",
188                         name = "kind"
189                 ),
190                 dict(
191                         type = "ir_type*",
192                         name = "type"
193                 )
194         ],
195         init = '''
196         assert((get_unknown_type() == type) || is_Method_type(type));
197         '''
198
199         # TODO: No firm_alloc_frag_arr??
200 ),
201
202 Call = dict(
203         ins      = [ "mem", "ptr" ],
204         arity    = "variable",
205         outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
206         attrs    = [
207                 dict(
208                         name = "state",
209                         type = "op_pin_state",
210                         initname = ".exc.pin_state",
211                         init = "op_pin_state_pinned"
212                 ),
213                 dict(
214                         type = "ir_type*",
215                         name = "type"
216                 )
217         ],
218         init = '''
219         assert((get_unknown_type() == type) || is_Method_type(type));
220         ''',
221         d_post = '''
222         #if PRECISE_EXC_CONTEXT
223         firm_alloc_frag_arr(res, op_Call, &res->attr.call.exc.frag_arr);
224         #endif
225         '''
226 ),
227
228 Carry = dict(
229         is_a     = "binop"
230 ),
231
232 Cast = dict(
233         ins      = [ "op" ],
234         mode     = "get_irn_mode(irn_op)",
235         attrs    = [
236                 dict(
237                         type = "ir_type*",
238                         name = "type"
239                 )
240         ],
241         init     = "assert(is_atomic_type(type));"
242 ),
243
244 Cmp = dict(
245         is_a     = "binop",
246         outs     = [ "False", "Eq", "Lt", "Le", "Gt", "Ge", "Lg", "Leg", "Uo", "Ue", "Ul", "Ule", "Ug", "Uge", "Ne", "True" ],
247 ),
248
249 Cond = dict(
250         ins      = [ "selector" ],
251         outs     = [ "false", "true" ],
252         attrs    = [
253                 dict(
254                         name = "kind",
255                         type = "cond_kind",
256                         init = "dense"
257                 ),
258                 dict(
259                         name = "default_proj",
260                         type = "long",
261                         init = "0"
262                 ),
263                 dict(
264                         name = "jmp_pred",
265                         type = "cond_jmp_predicate",
266                         init = "COND_JMP_PRED_NONE"
267                 )
268         ]
269 ),
270
271 Confirm = dict(
272         ins      = [ "value", "bound" ],
273         mode     = "get_irn_mode(irn_value)",
274         attrs    = [
275                 dict(
276                         name = "cmp",
277                         type = "pn_Cmp"
278                 ),
279         ],
280 ),
281
282 Const = dict(
283         mode       = "",
284         knownBlock = True,
285         attrs_name = "con",
286         attrs      = [
287                 dict(
288                         type = "tarval*",
289                         name = "tarval",
290                 )
291         ],
292 ),
293
294 Conv = dict(
295         is_a     = "unop",
296         attrs = [
297                 dict(
298                         name = "strict",
299                         type = "int",
300                         init = "0",
301                         special = dict(
302                                 prefix = "strict",
303                                 init = "1"
304                         )
305                 )
306         ]
307 ),
308
309 CopyB = dict(
310         ins   = [ "mem", "dst", "src" ],
311         outs  = [ "M", "X_regular", "X_except" ],
312         attrs = [
313                 dict(
314                         name = "state",
315                         type = "op_pin_state",
316                         initname = ".exc.pin_state",
317                         init = "op_pin_state_pinned"
318                 ),
319                 dict(
320                         name = "type",
321                         type = "ir_type*"
322                 )
323         ],
324         d_post = '''
325         #if PRECISE_EXC_CONTEXT
326         firm_alloc_frag_arr(res, op_CopyB, &res->attr.copyb.exc.frag_arr);
327         #endif
328         '''
329 ),
330
331 Div = dict(
332         ins   = [ "mem", "dividend", "divisor" ],
333         outs  = [ "M", "X_regular", "X_except", "res" ],
334         attrs_name = "divmod",
335         attrs = [
336                 dict(
337                         type = "ir_mode*",
338                         name = "resmode"
339                 ),
340                 dict(
341                         name = "state",
342                         type = "op_pin_state",
343                         initname = ".exc.pin_state"
344                 ),
345                 dict(
346                         name = "no_remainder",
347                         type = "int",
348                         init = "0",
349                         special = dict(
350                                 suffix = "RL",
351                                 init = "1"
352                         )
353                 )
354         ],
355         d_post = '''
356         #if PRECISE_EXC_CONTEXT
357         firm_alloc_frag_arr(res, op_Div, &res->attr.except.frag_arr);
358         #endif
359         '''
360 ),
361
362 DivMod = dict(
363         ins   = [ "mem", "dividend", "divisor" ],
364         outs  = [ "M", "X_regular", "X_except", "res_div", "res_mod" ],
365         attrs_name = "divmod",
366         attrs = [
367                 dict(
368                         type = "ir_mode*",
369                         name = "resmode"
370                 ),
371                 dict(
372                         name = "state",
373                         type = "op_pin_state",
374                         initname = ".exc.pin_state"
375                 )
376         ],
377         d_post = '''
378         #if PRECISE_EXC_CONTEXT
379         firm_alloc_frag_arr(res, op_DivMod, &res->attr.except.frag_arr);
380         #endif
381         '''
382 ),
383
384 End = dict(
385         mode       = "mode_X",
386         op_flags   = "cfopcode",
387         state      = "pinned",
388         arity      = "dynamic",
389         noconstr   = True,
390         optimize   = False
391 ),
392
393 Eor = dict(
394         is_a     = "binop"
395 ),
396
397 Filter = dict(
398         ins   = [ "pred" ],
399         attrs = [
400                 dict(
401                         name = "proj",
402                         type = "long"
403                 )
404         ]
405
406         # TODO: Broken asserts in original:
407         # assert(get_Proj_pred(res));
408         # assert(get_nodes_block(get_Proj_pred(res)));
409 ),
410
411 Free = dict(
412         ins   = [ "mem", "ptr", "size" ],
413         mode  = "mode_M",
414         attrs = [
415                 dict(
416                         name = "type",
417                         type = "ir_type*"
418                 ),
419                 dict(
420                         name = "where",
421                         type = "ir_where_alloc"
422                 )
423         ]
424 ),
425
426 Id = dict(
427         ins = [ "pred" ]
428 ),
429
430 IJmp = dict(
431         mode     = "mode_X",
432         op_flags = "cfopcode",
433         state    = "pinned",
434         ins      = [ "target" ],
435 ),
436
437 InstOf = dict(
438         ins   = [ "store", "objptr" ],
439         outs  = [ "M", "X_regular", "X_except", "res", "M_except" ],
440         attrs = [
441                 dict(
442                         name = "state",
443                         type = "op_pin_state",
444                         initname = ".exc.pin_state",
445                         init = "op_pin_state_floats"
446                 ),
447                 dict(
448                         name = "type",
449                         type = "ir_type*"
450                 )
451         ]
452
453         # TODO: No firm_alloc_frag_arr???
454 ),
455
456 Jmp = dict(
457         mode     = "mode_X",
458         op_flags = "cfopcode",
459         state    = "pinned",
460         ins      = [],
461 ),
462
463 Load = dict(
464         ins      = [ "mem", "ptr" ],
465         outs     = [ "M", "X_regular", "X_except", "res" ],
466         attrs    = [
467                 dict(
468                         type = "ir_mode*",
469                         name = "mode",
470                         java_name = "load_mode"
471                 ),
472         ],
473         constructor_args = [
474                 dict(
475                         type = "ir_cons_flags",
476                         name = "flags",
477                 ),
478         ],
479         d_post = '''
480 #if PRECISE_EXC_CONTEXT
481         firm_alloc_frag_arr(res, op_Load, &res->attr.load.exc.frag_arr);
482 #endif
483         '''
484 ),
485
486 Minus = dict(
487         is_a     = "unop"
488 ),
489
490 Mod = dict(
491         ins   = [ "mem", "dividend", "divisor" ],
492         outs  = [ "M", "X_regular", "X_except", "res" ],
493         attrs_name = "divmod",
494         attrs = [
495                 dict(
496                         type = "ir_mode*",
497                         name = "resmode"
498                 ),
499                 dict(
500                         name = "state",
501                         type = "op_pin_state",
502                         initname = ".exc.pin_state"
503                 )
504         ],
505         d_post = '''
506         #if PRECISE_EXC_CONTEXT
507         firm_alloc_frag_arr(res, op_Mod, &res->attr.except.frag_arr);
508         #endif
509         '''
510 ),
511
512 Mul = dict(
513         is_a     = "binop"
514 ),
515
516 Mulh = dict(
517         is_a     = "binop"
518 ),
519
520 Mux = dict(
521         ins      = [ "sel", "false", "true" ]
522 ),
523
524 NoMem = dict(
525         mode       = "mode_M",
526         knownBlock = True,
527 ),
528
529 Not = dict(
530         is_a     = "unop"
531 ),
532
533 Or = dict(
534         is_a     = "binop"
535 ),
536
537 Phi = dict(
538         noconstr = True,
539         state    = "pinned",
540         arity    = "variable",
541 ),
542
543 Pin = dict(
544         ins      = [ "op" ],
545         mode     = "get_irn_mode(irn_op)"
546 ),
547
548 Proj = dict(
549         ins      = [ "pred" ],
550         attrs    = [
551                 dict(
552                         type = "long",
553                         name = "proj",
554                         initname = ""
555                 )
556         ]
557 ),
558
559 Quot = dict(
560         ins   = [ "mem", "dividend", "divisor" ],
561         outs  = [ "M", "X_regular", "X_except", "res" ],
562         attrs_name = "divmod",
563         attrs = [
564                 dict(
565                         type = "ir_mode*",
566                         name = "resmode"
567                 ),
568                 dict(
569                         name = "state",
570                         type = "op_pin_state",
571                         initname = ".exc.pin_state"
572                 )
573         ],
574         d_post = '''
575         #if PRECISE_EXC_CONTEXT
576         firm_alloc_frag_arr(res, op_Quot, &res->attr.except.frag_arr);
577         #endif
578         '''
579 ),
580
581 Raise = dict(
582         ins   = [ "mem", "exo_ptr" ],
583         outs  = [ "M", "X" ]
584 ),
585
586 Return = dict(
587         ins      = [ "mem" ],
588         arity    = "variable",
589         mode     = "mode_X"
590 ),
591
592 Rotl = dict(
593         is_a     = "binop"
594 ),
595
596 Sel = dict(
597         ins    = [ "mem", "ptr" ],
598         arity  = "variable",
599         mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data",
600         attrs    = [
601                 dict(
602                         type = "ir_entity*",
603                         name = "entity"
604                 )
605         ]
606 ),
607
608 Shl = dict(
609         is_a     = "binop"
610 ),
611
612 Shr = dict(
613         is_a     = "binop"
614 ),
615
616 Shrs = dict(
617         is_a     = "binop"
618 ),
619
620 Start = dict(
621         mode       = "mode_T",
622         op_flags   = "cfopcode",
623         state      = "pinned",
624         noconstr   = True,
625         optimize   = False
626 ),
627
628 Store = dict(
629         ins      = [ "mem", "ptr", "value" ],
630         outs     = [ "M", "X_regular", "X_except" ],
631         constructor_args = [
632                 dict(
633                         type = "ir_cons_flags",
634                         name = "flags",
635                 ),
636         ],
637         d_post = '''
638 #if PRECISE_EXC_CONTEXT
639         firm_alloc_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr);
640 #endif
641         '''
642 ),
643
644 Sub = dict(
645         is_a     = "binop"
646 ),
647
648 SymConst = dict(
649         mode       = "mode_P",
650         knownBlock = True,
651         noconstr   = True,
652         attrs      = [
653                 dict(
654                         type = "ir_entity*",
655                         name = "entity"
656                 )
657         ],
658 ),
659
660 Sync = dict(
661         mode     = "mode_M",
662         optimize = False,
663         arity    = "dynamic"
664 ),
665
666 Tuple = dict(
667         arity    = "variable",
668         mode     = "mode_T",
669 ),
670
671 Unknown = dict(
672         knownBlock = True,
673         block      = "get_irg_start_block(irg)",
674         nodbginfo  = True
675 ),
676 )