b3165e535748cb2a22aa135e574da6491126e9dc
[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 Break = dict(
153         mode = "mode_X"
154 ),
155
156 Builtin = dict(
157         ins      = [ "mem" ],
158         arity    = "variable",
159         outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
160         attrs    = [
161                 dict(
162                         name = "state",
163                         type = "op_pin_state",
164                         initname = ".exc.pin_state",
165                         init = "op_pin_state_pinned"
166                 ),
167                 dict(
168                         type = "ir_builtin_kind",
169                         name = "kind"
170                 ),
171                 dict(
172                         type = "ir_type*",
173                         name = "type"
174                 )
175         ],
176         init = '''
177         assert((get_unknown_type() == type) || is_Method_type(type));
178         '''
179
180         # TODO: No firm_alloc_frag_arr??
181 ),
182
183 Call = dict(
184         ins      = [ "mem", "ptr" ],
185         arity    = "variable",
186         outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
187         attrs    = [
188                 dict(
189                         name = "state",
190                         type = "op_pin_state",
191                         initname = ".exc.pin_state",
192                         init = "op_pin_state_pinned"
193                 ),
194                 dict(
195                         type = "ir_type*",
196                         name = "type"
197                 )
198         ],
199         init = '''
200         assert((get_unknown_type() == type) || is_Method_type(type));
201         ''',
202         d_post = '''
203         #if PRECISE_EXC_CONTEXT
204         firm_alloc_frag_arr(res, op_Call, &res->attr.call.exc.frag_arr);
205         #endif
206         '''
207 ),
208
209 Carry = dict(
210         is_a     = "binop"
211 ),
212
213 Cast = dict(
214         ins      = [ "op" ],
215         mode     = "get_irn_mode(irn_op)",
216         attrs    = [
217                 dict(
218                         type = "ir_type*",
219                         name = "type"
220                 )
221         ],
222         init     = "assert(is_atomic_type(type));"
223 ),
224
225 Cmp = dict(
226         is_a     = "binop",
227         outs     = [ "False", "Eq", "Lt", "Le", "Gt", "Ge", "Lg", "Leg", "Uo", "Ue", "Ul", "Ule", "Ug", "Uge", "Ne", "True" ],
228 ),
229
230 Cond = dict(
231         ins      = [ "selector" ],
232         outs     = [ "false", "true" ],
233         attrs    = [
234                 dict(
235                         name = "kind",
236                         type = "cond_kind",
237                         init = "dense"
238                 ),
239                 dict(
240                         name = "default_proj",
241                         type = "long",
242                         init = "0"
243                 ),
244                 dict(
245                         name = "jmp_pred",
246                         type = "cond_jmp_predicate",
247                         init = "COND_JMP_PRED_NONE"
248                 )
249         ]
250 ),
251
252 Confirm = dict(
253         ins      = [ "value", "bound" ],
254         mode     = "get_irn_mode(irn_value)",
255         attrs    = [
256                 dict(
257                         name = "cmp",
258                         type = "pn_Cmp"
259                 ),
260         ],
261 ),
262
263 Const = dict(
264         mode       = "",
265         knownBlock = True,
266         attrs_name = "con",
267         attrs      = [
268                 dict(
269                         type = "tarval*",
270                         name = "tarval",
271                 )
272         ],
273 ),
274
275 Conv = dict(
276         is_a     = "unop",
277         attrs = [
278                 dict(
279                         name = "strict",
280                         type = "int",
281                         init = "0",
282                         special = dict(
283                                 prefix = "strict",
284                                 init = "1"
285                         )
286                 )
287         ]
288 ),
289
290 CopyB = dict(
291         ins   = [ "mem", "dst", "src" ],
292         outs  = [ "M", "X_regular", "X_except" ],
293         attrs = [
294                 dict(
295                         name = "state",
296                         type = "op_pin_state",
297                         initname = ".exc.pin_state",
298                         init = "op_pin_state_pinned"
299                 ),
300                 dict(
301                         name = "type",
302                         type = "ir_type*"
303                 )
304         ]
305 ),
306
307 Div = dict(
308         ins   = [ "mem", "dividend", "divisor" ],
309         outs  = [ "M", "X_regular", "X_except", "res" ],
310         attrs_name = "divmod",
311         attrs = [
312                 dict(
313                         type = "ir_mode*",
314                         name = "resmode"
315                 ),
316                 dict(
317                         name = "state",
318                         type = "op_pin_state",
319                         initname = ".exc.pin_state"
320                 ),
321                 dict(
322                         name = "no_remainder",
323                         type = "int",
324                         init = "0",
325                         special = dict(
326                                 suffix = "RL",
327                                 init = "1"
328                         )
329                 )
330         ],
331         d_post = '''
332         #if PRECISE_EXC_CONTEXT
333         firm_alloc_frag_arr(res, op_Div, &res->attr.except.frag_arr);
334         #endif
335         '''
336 ),
337
338 DivMod = dict(
339         ins   = [ "mem", "dividend", "divisor" ],
340         outs  = [ "M", "X_regular", "X_except", "res_div", "res_mod" ],
341         attrs_name = "divmod",
342         attrs = [
343                 dict(
344                         type = "ir_mode*",
345                         name = "resmode"
346                 ),
347                 dict(
348                         name = "state",
349                         type = "op_pin_state",
350                         initname = ".exc.pin_state"
351                 )
352         ],
353         d_post = '''
354         #if PRECISE_EXC_CONTEXT
355         firm_alloc_frag_arr(res, op_DivMod, &res->attr.except.frag_arr);
356         #endif
357         '''
358 ),
359
360 End = dict(
361         mode       = "mode_X",
362         op_flags   = "cfopcode",
363         state      = "pinned",
364         arity      = "dynamic",
365         noconstr   = True,
366         optimize   = False
367 ),
368
369 Eor = dict(
370         is_a     = "binop"
371 ),
372
373 Filter = dict(
374         ins   = [ "pred" ],
375         attrs = [
376                 dict(
377                         name = "proj",
378                         type = "long"
379                 )
380         ]
381
382         # TODO: Broken asserts in original:
383         # assert(get_Proj_pred(res));
384         # assert(get_nodes_block(get_Proj_pred(res)));
385 ),
386
387 Free = dict(
388         ins   = [ "mem", "ptr", "size" ],
389         mode  = "mode_M",
390         attrs = [
391                 dict(
392                         name = "type",
393                         type = "ir_type*"
394                 ),
395                 dict(
396                         name = "where",
397                         type = "ir_where_alloc"
398                 )
399         ]
400 ),
401
402 Id = dict(
403         ins = [ "pred" ]
404 ),
405
406 IJmp = dict(
407         mode     = "mode_X",
408         op_flags = "cfopcode",
409         state    = "pinned",
410         ins      = [ "target" ],
411 ),
412
413 Jmp = dict(
414         mode     = "mode_X",
415         op_flags = "cfopcode",
416         state    = "pinned",
417         ins      = [],
418 ),
419
420 Load = dict(
421         ins      = [ "mem", "ptr" ],
422         outs     = [ "M", "X_regular", "X_except", "res" ],
423         attrs    = [
424                 dict(
425                         type = "ir_mode*",
426                         name = "mode",
427                         java_name = "load_mode"
428                 ),
429         ],
430         constructor_args = [
431                 dict(
432                         type = "ir_cons_flags",
433                         name = "flags",
434                 ),
435         ],
436         d_post = '''
437 #if PRECISE_EXC_CONTEXT
438         firm_alloc_frag_arr(res, op_Load, &res->attr.load.exc.frag_arr);
439 #endif
440         '''
441 ),
442
443 Minus = dict(
444         is_a     = "unop"
445 ),
446
447 Mod = dict(
448         ins   = [ "mem", "dividend", "divisor" ],
449         outs  = [ "M", "X_regular", "X_except", "res" ],
450         attrs_name = "divmod",
451         attrs = [
452                 dict(
453                         type = "ir_mode*",
454                         name = "resmode"
455                 ),
456                 dict(
457                         name = "state",
458                         type = "op_pin_state",
459                         initname = ".exc.pin_state"
460                 )
461         ],
462         d_post = '''
463         #if PRECISE_EXC_CONTEXT
464         firm_alloc_frag_arr(res, op_Mod, &res->attr.except.frag_arr);
465         #endif
466         '''
467 ),
468
469 Mul = dict(
470         is_a     = "binop"
471 ),
472
473 Mulh = dict(
474         is_a     = "binop"
475 ),
476
477 Mux = dict(
478         ins      = [ "sel", "false", "true" ]
479 ),
480
481 NoMem = dict(
482         mode       = "mode_M",
483         knownBlock = True,
484 ),
485
486 Not = dict(
487         is_a     = "unop"
488 ),
489
490 Or = dict(
491         is_a     = "binop"
492 ),
493
494 Phi = dict(
495         noconstr = True,
496         state    = "pinned",
497         arity    = "variable",
498 ),
499
500 Pin = dict(
501         ins      = [ "op" ],
502         mode     = "get_irn_mode(irn_op)"
503 ),
504
505 Proj = dict(
506         ins      = [ "pred" ],
507         attrs    = [
508                 dict(
509                         type = "long",
510                         name = "proj",
511                         initname = ""
512                 )
513         ]
514 ),
515
516 Quot = dict(
517         ins   = [ "mem", "dividend", "divisor" ],
518         outs  = [ "M", "X_regular", "X_except", "res" ],
519         attrs_name = "divmod",
520         attrs = [
521                 dict(
522                         type = "ir_mode*",
523                         name = "resmode"
524                 ),
525                 dict(
526                         name = "state",
527                         type = "op_pin_state",
528                         initname = ".exc.pin_state"
529                 )
530         ],
531         d_post = '''
532         #if PRECISE_EXC_CONTEXT
533         firm_alloc_frag_arr(res, op_Quot, &res->attr.except.frag_arr);
534         #endif
535         '''
536 ),
537
538 Return = dict(
539         ins      = [ "mem" ],
540         arity    = "variable",
541         mode     = "mode_X"
542 ),
543
544 Rotl = dict(
545         is_a     = "binop"
546 ),
547
548 Sel = dict(
549         ins    = [ "mem", "ptr" ],
550         arity  = "variable",
551         mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data",
552         attrs    = [
553                 dict(
554                         type = "ir_entity*",
555                         name = "entity"
556                 )
557         ]
558 ),
559
560 Shl = dict(
561         is_a     = "binop"
562 ),
563
564 Shr = dict(
565         is_a     = "binop"
566 ),
567
568 Shrs = dict(
569         is_a     = "binop"
570 ),
571
572 Start = dict(
573         mode       = "mode_T",
574         op_flags   = "cfopcode",
575         state      = "pinned",
576         noconstr   = True,
577         optimize   = False
578 ),
579
580 Store = dict(
581         ins      = [ "mem", "ptr", "value" ],
582         outs     = [ "M", "X_regular", "X_except" ],
583         constructor_args = [
584                 dict(
585                         type = "ir_cons_flags",
586                         name = "flags",
587                 ),
588         ],
589         d_post = '''
590 #if PRECISE_EXC_CONTEXT
591         firm_alloc_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr);
592 #endif
593         '''
594 ),
595
596 Sub = dict(
597         is_a     = "binop"
598 ),
599
600 SymConst = dict(
601         mode       = "mode_P",
602         knownBlock = True,
603         noconstr   = True,
604         attrs      = [
605                 dict(
606                         type = "ir_entity*",
607                         name = "entity"
608                 )
609         ],
610 ),
611
612 Sync = dict(
613         mode     = "mode_M",
614         optimize = False,
615         arity    = "dynamic"
616 ),
617
618 Tuple = dict(
619         arity    = "variable",
620         mode     = "mode_T",
621 ),
622
623 Unknown = dict(
624         knownBlock = True,
625         block      = "get_irg_start_block(irg)",
626         nodbginfo  = True
627 ),
628 )