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