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