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