10817629e2faf25e37e2642aba7d6d6a4b0af0e2
[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         op_index = 0,
10         pinned   = "no",
11 ),
12
13 binop = dict(
14         abstract = True,
15         ins      = [ "left", "right" ],
16         op_index = 0,
17         pinned   = "no",
18 ),
19
20 #
21 # Real node types
22 #
23 Abs = dict(
24         is_a     = "unop",
25         flags    = "none",
26 ),
27
28 Add = dict(
29         is_a     = "binop",
30         flags    = "commutative",
31 ),
32
33 Alloc = dict(
34         ins   = [ "mem", "size" ],
35         outs  = [ "M", "X_regular", "X_except", "res" ],
36         flags = "fragile, uses_memory",
37         attrs = [
38                 dict(
39                         name = "type",
40                         type = "ir_type*"
41                 ),
42                 dict(
43                         name = "where",
44                         type = "ir_where_alloc"
45                 )
46         ],
47         pinned      = "yes",
48         attr_struct = "alloc_attr",
49         d_post = '''
50         #if PRECISE_EXC_CONTEXT
51         firm_alloc_frag_arr(res, op_Alloc, &res->attr.alloc.exc.frag_arr);
52         #endif
53         '''
54 ),
55
56 Anchor = dict(
57         mode        = "mode_ANY",
58         arity       = "variable",
59         flags       = "dump_noblock",
60         pinned      = "yes",
61         knownBlock  = True,
62         singleton   = True,
63 ),
64
65 And = dict(
66         is_a     = "binop",
67         flags    = "commutative",
68 ),
69
70 ASM = dict(
71         mode          = "mode_T",
72         arity         = "variable",
73         flags         = "keep, uses_memory",
74         attr_struct   = "asm_attr",
75         pinned        = "memory",
76         pinned_init   = "op_pin_state_pinned",
77         attrs = [
78                 dict(
79                         name = "input_constraints",
80                         type = "ir_asm_constraint*",
81                 ),
82                 dict(
83                         name = "n_output_constraints",
84                         type = "int",
85                 ),
86                 dict(
87                         name = "output_constraints",
88                         type = "ir_asm_constraint*",
89                 ),
90                 dict(
91                         name = "n_clobbers",
92                         type = "int",
93                 ),
94                 dict(
95                         name = "clobbers",
96                         type = "ident**",
97                 ),
98                 dict(
99                         name = "text",
100                         type = "ident*",
101                 ),
102         ],
103         java_noconstr = True,
104 ),
105
106 Bad = dict(
107         mode       = "mode_Bad",
108         flags      = "cfopcode, fragile, start_block, dump_noblock",
109         pinned     = "yes",
110         knownBlock = True,
111         singleton  = True,
112 ),
113
114 Block = dict(
115         mode        = "mode_BB",
116         knownBlock  = True,
117         block       = "NULL",
118         pinned      = "yes",
119         optimize    = False,
120         arity       = "variable",
121         flags       = "labeled",
122         attr_struct = "block_attr",
123         java_noconstr = True,
124
125         init = '''
126         /* macroblock header */
127         res->in[0] = res;
128
129         res->attr.block.is_dead     = 0;
130         res->attr.block.is_mb_head  = 1;
131         res->attr.block.irg         = irg;
132         res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
133         res->attr.block.in_cg       = NULL;
134         res->attr.block.cg_backedge = NULL;
135         res->attr.block.extblk      = NULL;
136         res->attr.block.mb_depth    = 0;
137         res->attr.block.entity      = NULL;
138
139         set_Block_matured(res, 1);
140         set_Block_block_visited(res, 0);
141         ''',
142
143         d_pre = '''
144         int i;
145         int has_unknown = 0;
146         ''',
147
148         d_post = '''
149         /* Create and initialize array for Phi-node construction. */
150         if (get_irg_phase_state(current_ir_graph) == phase_building) {
151                 res->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,
152                                                       current_ir_graph->n_loc);
153                 memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
154         }
155
156         for (i = arity - 1; i >= 0; i--)
157                 if (is_Unknown(in[i])) {
158                         has_unknown = 1;
159                         break;
160                 }
161
162         if (!has_unknown) res = optimize_node(res);
163
164         current_ir_graph->current_block = res;
165
166         IRN_VRFY_IRG(res, current_ir_graph);
167         ''',
168
169         java_add   = '''
170         public void addPred(Node node) {
171                 binding_cons.add_immBlock_pred(ptr, node.ptr);
172         }
173
174         public void mature() {
175                 binding_cons.mature_immBlock(ptr);
176         }
177
178         @Override
179         public Block getBlock() {
180                 return null;
181         }
182
183         public boolean blockVisited() {
184                 return 0 != binding.Block_block_visited(ptr);
185         }
186
187         public void markBlockVisited() {
188                 binding.mark_Block_block_visited(ptr);
189         }
190
191         public boolean isBad() {
192                 return binding.is_Bad(ptr) != 0;
193         }
194         ''',
195 ),
196
197 Borrow = dict(
198         is_a     = "binop",
199         flags    = "none",
200 ),
201
202 Bound = dict(
203         ins    = [ "mem", "index", "lower", "upper" ],
204         outs   = [ "M", "X_regular", "X_except", "res" ],
205         flags  = "fragile, highlevel",
206         pinned = "exception",
207         pinned_init = "op_pin_state_pinned",
208         attr_struct = "bound_attr",
209         d_post = '''
210         #if PRECISE_EXC_CONTEXT
211         firm_alloc_frag_arr(res, op_Bound, &res->attr.bound.exc.frag_arr);
212         #endif
213         '''
214 ),
215
216 Break = dict(
217         mode   = "mode_X",
218         flags  = "cfopcode",
219         pinned = "yes",
220 ),
221
222 Builtin = dict(
223         ins      = [ "mem" ],
224         arity    = "variable",
225         outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
226         flags    = "uses_memory",
227         attrs    = [
228                 dict(
229                         type = "ir_builtin_kind",
230                         name = "kind"
231                 ),
232                 dict(
233                         type = "ir_type*",
234                         name = "type"
235                 )
236         ],
237         pinned      = "memory",
238         pinned_init = "op_pin_state_pinned",
239         attr_struct = "builtin_attr",
240         init   = '''
241         assert((get_unknown_type() == type) || is_Method_type(type));
242         '''
243
244         # TODO: No firm_alloc_frag_arr??
245 ),
246
247 Call = dict(
248         ins      = [ "mem", "ptr" ],
249         arity    = "variable",
250         outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
251         flags    = "fragile, uses_memory",
252         attrs    = [
253                 dict(
254                         type = "ir_type*",
255                         name = "type"
256                 )
257         ],
258         attr_struct = "call_attr",
259         pinned      = "memory",
260         pinned_init = "op_pin_state_pinned",
261         init = '''
262         assert((get_unknown_type() == type) || is_Method_type(type));
263         ''',
264         d_post = '''
265         #if PRECISE_EXC_CONTEXT
266         firm_alloc_frag_arr(res, op_Call, &res->attr.call.exc.frag_arr);
267         #endif
268         '''
269 ),
270
271 CallBegin = dict(
272         ins   = [ "ptr" ],
273         outs  = [ "" ], # TODO
274         flags         = "cfopcode, ip_cfopcode",
275         pinned        = "yes",
276         # TODO: attribute with call...
277         attr_struct   = "callbegin_attr",
278         attrs         = [
279                 dict(
280                         type = "ir_node*",
281                         name = "call"
282                 )
283         ],
284         java_noconstr = True,
285 ),
286
287 Carry = dict(
288         is_a     = "binop",
289         flags    = "commutative",
290 ),
291
292 Cast = dict(
293         ins      = [ "op" ],
294         mode     = "get_irn_mode(irn_op)",
295         flags    = "highlevel",
296         pinned   = "no",
297         attrs    = [
298                 dict(
299                         type = "ir_type*",
300                         name = "type"
301                 )
302         ],
303         attr_struct = "cast_attr",
304         init     = "assert(is_atomic_type(type));"
305 ),
306
307 Cmp = dict(
308         is_a     = "binop",
309         outs     = [ "False", "Eq", "Lt", "Le", "Gt", "Ge", "Lg", "Leg", "Uo", "Ue", "Ul", "Ule", "Ug", "Uge", "Ne", "True" ],
310         flags    = "none",
311 ),
312
313 Cond = dict(
314         ins      = [ "selector" ],
315         outs     = [ "false", "true" ],
316         flags    = "cfopcode, forking",
317         pinned   = "yes",
318         attrs    = [
319                 dict(
320                         name = "kind",
321                         type = "cond_kind",
322                         init = "dense"
323                 ),
324                 dict(
325                         name = "default_proj",
326                         type = "long",
327                         init = "0"
328                 ),
329                 dict(
330                         name = "jmp_pred",
331                         type = "cond_jmp_predicate",
332                         init = "COND_JMP_PRED_NONE"
333                 )
334         ],
335         attr_struct = "cond_attr"
336 ),
337
338 Confirm = dict(
339         ins      = [ "value", "bound" ],
340         mode     = "get_irn_mode(irn_value)",
341         flags    = "highlevel",
342         pinned   = "yes",
343         attrs    = [
344                 dict(
345                         name = "cmp",
346                         type = "pn_Cmp"
347                 ),
348         ],
349         attr_struct = "confirm_attr",
350 ),
351
352 Const = dict(
353         mode       = "",
354         flags      = "constlike, start_block",
355         knownBlock = True,
356         pinned     = "no",
357         attrs_name = "con",
358         attrs      = [
359                 dict(
360                         type = "tarval*",
361                         name = "tarval",
362                 )
363         ],
364         attr_struct = "const_attr",
365 ),
366
367 Conv = dict(
368         is_a     = "unop",
369         flags    = "none",
370         attrs = [
371                 dict(
372                         name = "strict",
373                         type = "int",
374                         init = "0",
375                         special = dict(
376                                 prefix = "strict",
377                                 init = "1"
378                         )
379                 )
380         ],
381         attr_struct = "conv_attr",
382 ),
383
384 CopyB = dict(
385         ins   = [ "mem", "dst", "src" ],
386         outs  = [ "M", "X_regular", "X_except" ],
387         flags = "fragile, highlevel, uses_memory",
388         attrs = [
389                 dict(
390                         name = "type",
391                         type = "ir_type*"
392                 )
393         ],
394         attr_struct = "copyb_attr",
395         pinned      = "memory",
396         pinned_init = "op_pin_state_pinned",
397         d_post = '''
398         #if PRECISE_EXC_CONTEXT
399         firm_alloc_frag_arr(res, op_CopyB, &res->attr.copyb.exc.frag_arr);
400         #endif
401         '''
402 ),
403
404 Div = dict(
405         ins   = [ "mem", "left", "right" ],
406         outs  = [ "M", "X_regular", "X_except", "res" ],
407         flags = "fragile, uses_memory",
408         attrs_name = "divmod",
409         attrs = [
410                 dict(
411                         type = "ir_mode*",
412                         name = "resmode"
413                 ),
414                 dict(
415                         name = "no_remainder",
416                         type = "int",
417                         init = "0",
418                         special = dict(
419                                 suffix = "RL",
420                                 init = "1"
421                         )
422                 )
423         ],
424         attr_struct = "divmod_attr",
425         pinned      = "exception",
426         op_index    = 1,
427         arity_override = "oparity_binary",
428         d_post = '''
429         #if PRECISE_EXC_CONTEXT
430         firm_alloc_frag_arr(res, op_Div, &res->attr.except.frag_arr);
431         #endif
432         '''
433 ),
434
435 DivMod = dict(
436         ins   = [ "mem", "left", "right" ],
437         outs  = [ "M", "X_regular", "X_except", "res_div", "res_mod" ],
438         flags = "fragile, uses_memory",
439         attrs_name = "divmod",
440         attrs = [
441                 dict(
442                         type = "ir_mode*",
443                         name = "resmode"
444                 ),
445         ],
446         attr_struct = "divmod_attr",
447         pinned      = "exception",
448         op_index    = 1,
449         arity_override = "oparity_binary",
450         d_post = '''
451         #if PRECISE_EXC_CONTEXT
452         firm_alloc_frag_arr(res, op_DivMod, &res->attr.except.frag_arr);
453         #endif
454         '''
455 ),
456
457 Dummy = dict(
458         ins   = [],
459         flags = "cfopcode, fragile, start_block, constlike, dump_noblock",
460         knownBlock = True,
461         pinned     = "yes",
462         block      = "get_irg_start_block(irg)",
463 ),
464
465 End = dict(
466         mode       = "mode_X",
467         pinned     = "yes",
468         arity      = "dynamic",
469         flags      = "cfopcode",
470         singleton  = True,
471 ),
472
473 EndExcept = dict(
474         mode      = "mode_X",
475         pinned    = "yes",
476         arity     = "dynamic",
477         flags     = "cfopcode, ip_cfopcode",
478         singleton = True
479 ),
480
481 EndReg = dict(
482         mode      = "mode_X",
483         pinned    = "yes",
484         arity     = "dynamic",
485         flags     = "cfopcode, ip_cfopcode",
486         singleton = True
487 ),
488
489 Eor = dict(
490         is_a     = "binop",
491         flags    = "commutative",
492 ),
493
494 Filter = dict(
495         ins   = [ "pred" ],
496         flags = "none",
497         attrs = [
498                 dict(
499                         name = "proj",
500                         type = "long"
501                 )
502         ],
503         pinned      = "yes",
504         attr_struct = "filter_attr",
505         java_noconstr = True
506
507         # TODO: Broken asserts in original:
508         # assert(get_Proj_pred(res));
509         # assert(get_nodes_block(get_Proj_pred(res)));
510 ),
511
512 Free = dict(
513         ins    = [ "mem", "ptr", "size" ],
514         mode   = "mode_M",
515         flags  = "uses_memory",
516         pinned = "yes",
517         attrs  = [
518                 dict(
519                         name = "type",
520                         type = "ir_type*"
521                 ),
522                 dict(
523                         name = "where",
524                         type = "ir_where_alloc"
525                 )
526         ],
527         attr_struct = "free_attr",
528 ),
529
530 Id = dict(
531         ins    = [ "pred" ],
532         pinned = "no",
533         flags  = "none",
534 ),
535
536 IJmp = dict(
537         mode     = "mode_X",
538         pinned   = "yes",
539         ins      = [ "target" ],
540         flags    = "cfopcode, forking, keep",
541 ),
542
543 InstOf = dict(
544         ins   = [ "store", "obj" ],
545         outs  = [ "M", "X_regular", "X_except", "res", "M_except" ],
546         flags = "highlevel",
547         attrs = [
548                 dict(
549                         name = "type",
550                         type = "ir_type*"
551                 )
552         ],
553         attr_struct = "io_attr",
554         pinned      = "memory",
555         pinned_init = "op_pin_state_floats",
556 ),
557
558 Jmp = dict(
559         mode     = "mode_X",
560         pinned   = "yes",
561         ins      = [],
562         flags    = "cfopcode",
563 ),
564
565 Load = dict(
566         ins      = [ "mem", "ptr" ],
567         outs     = [ "M", "X_regular", "X_except", "res" ],
568         flags    = "fragile, uses_memory",
569         pinned   = "exception",
570         pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned",
571         attrs    = [
572                 dict(
573                         type = "ir_mode*",
574                         name = "mode",
575                         java_name = "load_mode"
576                 ),
577         ],
578         attr_struct = "load_attr",
579         constructor_args = [
580                 dict(
581                         type = "ir_cons_flags",
582                         name = "flags",
583                 ),
584         ],
585         d_post = '''
586 #if PRECISE_EXC_CONTEXT
587         firm_alloc_frag_arr(res, op_Load, &res->attr.load.exc.frag_arr);
588 #endif
589         '''
590 ),
591
592 Minus = dict(
593         is_a     = "unop",
594         flags    = "none",
595 ),
596
597 Mod = dict(
598         ins   = [ "mem", "left", "right" ],
599         outs  = [ "M", "X_regular", "X_except", "res" ],
600         flags = "fragile, uses_memory",
601         attrs_name = "divmod",
602         attrs = [
603                 dict(
604                         type = "ir_mode*",
605                         name = "resmode"
606                 ),
607         ],
608         attr_struct = "divmod_attr",
609         pinned      = "exception",
610         op_index    = 1,
611         arity_override = "oparity_binary",
612         d_post = '''
613         #if PRECISE_EXC_CONTEXT
614         firm_alloc_frag_arr(res, op_Mod, &res->attr.except.frag_arr);
615         #endif
616         '''
617 ),
618
619 Mul = dict(
620         is_a     = "binop",
621         flags    = "commutative",
622 ),
623
624 Mulh = dict(
625         is_a     = "binop",
626         flags    = "commutative",
627 ),
628
629 Mux = dict(
630         ins    = [ "sel", "false", "true" ],
631         flags  = "none",
632         pinned = "no",
633 ),
634
635 NoMem = dict(
636         mode       = "mode_M",
637         flags      = "dump_noblock, dump_noinput",
638         pinned     = "yes",
639         knownBlock = True,
640         singleton  = True,
641 ),
642
643 Not = dict(
644         is_a     = "unop",
645         flags    = "none",
646 ),
647
648 Or = dict(
649         is_a     = "binop",
650         flags    = "commutative",
651 ),
652
653 Phi = dict(
654         pinned      = "yes",
655         arity       = "variable",
656         flags       = "none",
657         attr_struct = "phi_attr",
658         custom_is   = True,
659         java_noconstr = True,
660 ),
661
662 Pin = dict(
663         ins      = [ "op" ],
664         mode     = "get_irn_mode(irn_op)",
665         flags    = "highlevel",
666         pinned   = "yes",
667 ),
668
669 Proj = dict(
670         ins      = [ "pred" ],
671         flags    = "none",
672         pinned   = "no",
673         attrs    = [
674                 dict(
675                         type = "long",
676                         name = "proj",
677                         initname = ""
678                 )
679         ],
680         attr_struct = "long",
681         custom_is   = True,
682 ),
683
684 Quot = dict(
685         ins   = [ "mem", "left", "right" ],
686         outs  = [ "M", "X_regular", "X_except", "res" ],
687         flags = "fragile, uses_memory",
688         attrs_name = "divmod",
689         attrs = [
690                 dict(
691                         type = "ir_mode*",
692                         name = "resmode"
693                 ),
694         ],
695         attr_struct = "divmod_attr",
696         pinned      = "exception",
697         op_index    = 1,
698         arity_override = "oparity_binary",
699         d_post = '''
700         #if PRECISE_EXC_CONTEXT
701         firm_alloc_frag_arr(res, op_Quot, &res->attr.except.frag_arr);
702         #endif
703         '''
704 ),
705
706 Raise = dict(
707         ins    = [ "mem", "exo_ptr" ],
708         outs   = [ "M", "X" ],
709         flags  = "highlevel, cfopcode",
710         pinned = "yes",
711 ),
712
713 Return = dict(
714         ins      = [ "mem" ],
715         arity    = "variable",
716         mode     = "mode_X",
717         flags    = "cfopcode",
718         pinned   = "yes",
719 ),
720
721 Rotl = dict(
722         is_a     = "binop",
723         flags    = "none",
724 ),
725
726 Sel = dict(
727         ins    = [ "mem", "ptr" ],
728         arity  = "variable",
729         flags  = "none",
730         mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data",
731         pinned = "no",
732         attrs  = [
733                 dict(
734                         type = "ir_entity*",
735                         name = "entity"
736                 )
737         ],
738         attr_struct = "sel_attr",
739 ),
740
741 Shl = dict(
742         is_a     = "binop",
743         flags    = "none",
744 ),
745
746 Shr = dict(
747         is_a     = "binop",
748         flags    = "none",
749 ),
750
751 Shrs = dict(
752         is_a     = "binop",
753         flags    = "none",
754 ),
755
756 Start = dict(
757         mode       = "mode_T",
758         pinned     = "yes",
759         flags      = "cfopcode",
760         singleton  = True,
761 ),
762
763 Store = dict(
764         ins      = [ "mem", "ptr", "value" ],
765         outs     = [ "M", "X_regular", "X_except" ],
766         flags    = "fragile, uses_memory",
767         pinned   = "exception",
768         attr_struct = "store_attr",
769         pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned",
770         constructor_args = [
771                 dict(
772                         type = "ir_cons_flags",
773                         name = "flags",
774                 ),
775         ],
776         d_post = '''
777 #if PRECISE_EXC_CONTEXT
778         firm_alloc_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr);
779 #endif
780         '''
781 ),
782
783 Sub = dict(
784         is_a     = "binop",
785         flags    = "none",
786 ),
787
788 SymConst = dict(
789         mode       = "mode_P",
790         flags      = "constlike, start_block",
791         knownBlock = True,
792         pinned     = "no",
793         attrs      = [
794                 dict(
795                         type = "ir_entity*",
796                         name = "entity"
797                 )
798         ],
799         attr_struct = "symconst_attr",
800         java_noconstr = True,
801 ),
802
803 Sync = dict(
804         mode     = "mode_M",
805         flags    = "none",
806         pinned   = "no",
807         optimize = False,
808         arity    = "dynamic"
809 ),
810
811 Tuple = dict(
812         arity  = "variable",
813         mode   = "mode_T",
814         pinned = "no",
815         flags  = "labeled",
816         java_noconstr = True
817 ),
818
819 Unknown = dict(
820         knownBlock = True,
821         pinned     = "yes",
822         block      = "get_irg_start_block(irg)",
823         flags      = "cfopcode, fragile, start_block, constlike, dump_noblock",
824 ),
825 )