redo pinned mode handling in spec generator
[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 = "type",
33                         type = "ir_type*"
34                 ),
35                 dict(
36                         name = "where",
37                         type = "ir_where_alloc"
38                 )
39         ],
40         pinned      = "exception",
41         pinned_init = "pinned",
42         d_post = '''
43         #if PRECISE_EXC_CONTEXT
44         firm_alloc_frag_arr(res, op_Alloc, &res->attr.alloc.exc.frag_arr);
45         #endif
46         '''
47 ),
48
49 Anchor = dict(
50         mode       = "mode_ANY",
51         arity      = "variable",
52         knownBlock = True,
53         noconstr   = True
54 ),
55
56 And = dict(
57         is_a     = "binop"
58 ),
59
60 Bad = dict(
61         mode       = "mode_Bad",
62         knownBlock = True,
63 ),
64
65 Block = dict(
66         mode       = "mode_BB",
67         knownBlock = True,
68         block      = "NULL",
69         noconstr   = True,
70         optimize   = False,
71         arity      = "variable",
72
73         init = '''
74         /* macroblock header */
75         res->in[0] = res;
76
77         res->attr.block.is_dead     = 0;
78         res->attr.block.is_mb_head  = 1;
79         res->attr.block.has_label   = 0;
80         res->attr.block.irg         = irg;
81         res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
82         res->attr.block.in_cg       = NULL;
83         res->attr.block.cg_backedge = NULL;
84         res->attr.block.extblk      = NULL;
85         res->attr.block.mb_depth    = 0;
86         res->attr.block.label       = 0;
87
88         set_Block_matured(res, 1);
89         set_Block_block_visited(res, 0);
90         ''',
91
92         d_pre = '''
93         int i;
94         int has_unknown = 0;
95         ''',
96
97         d_post = '''
98         /* Create and initialize array for Phi-node construction. */
99         if (get_irg_phase_state(current_ir_graph) == phase_building) {
100                 res->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,
101                                                       current_ir_graph->n_loc);
102                 memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
103         }
104
105         for (i = arity - 1; i >= 0; i--)
106                 if (is_Unknown(in[i])) {
107                         has_unknown = 1;
108                         break;
109                 }
110
111         if (!has_unknown) res = optimize_node(res);
112
113         current_ir_graph->current_block = res;
114
115         IRN_VRFY_IRG(res, current_ir_graph);
116         ''',
117
118         java_add   = '''
119         public void addPred(Node node) {
120                 binding_cons.add_immBlock_pred(ptr, node.ptr);
121         }
122
123         public void mature() {
124                 binding_cons.mature_immBlock(ptr);
125         }
126
127         @Override
128         public Block getBlock() {
129                 return null;
130         }
131
132         public boolean blockVisited() {
133                 return 0 != binding.Block_block_visited(ptr);
134         }
135
136         public void markBlockVisited() {
137                 binding.mark_Block_block_visited(ptr);
138         }''',
139 ),
140
141 Borrow = dict(
142         is_a     = "binop"
143 ),
144
145 Bound = dict(
146         ins    = [ "mem", "index", "lower", "upper" ],
147         outs   = [ "M", "X_regular", "X_except", "res" ],
148         pinned = "exception",
149         pinned_init = "pinned",
150         d_post = '''
151         #if PRECISE_EXC_CONTEXT
152         firm_alloc_frag_arr(res, op_Bound, &res->attr.bound.exc.frag_arr);
153         #endif
154         '''
155 ),
156
157
158 Break = dict(
159         mode = "mode_X"
160 ),
161
162 Builtin = dict(
163         ins      = [ "mem" ],
164         arity    = "variable",
165         outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
166         attrs    = [
167                 dict(
168                         type = "ir_builtin_kind",
169                         name = "kind"
170                 ),
171                 dict(
172                         type = "ir_type*",
173                         name = "type"
174                 )
175         ],
176         pinned      = "memory",
177         pinned_init = "pinned",
178         init   = '''
179         assert((get_unknown_type() == type) || is_Method_type(type));
180         '''
181
182         # TODO: No firm_alloc_frag_arr??
183 ),
184
185 Call = dict(
186         ins      = [ "mem", "ptr" ],
187         arity    = "variable",
188         outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
189         attrs    = [
190                 dict(
191                         type = "ir_type*",
192                         name = "type"
193                 )
194         ],
195         pinned      = "memory",
196         pinned_init = "pinned",
197         init = '''
198         assert((get_unknown_type() == type) || is_Method_type(type));
199         ''',
200         d_post = '''
201         #if PRECISE_EXC_CONTEXT
202         firm_alloc_frag_arr(res, op_Call, &res->attr.call.exc.frag_arr);
203         #endif
204         '''
205 ),
206
207 Carry = dict(
208         is_a     = "binop"
209 ),
210
211 Cast = dict(
212         ins      = [ "op" ],
213         mode     = "get_irn_mode(irn_op)",
214         attrs    = [
215                 dict(
216                         type = "ir_type*",
217                         name = "type"
218                 )
219         ],
220         init     = "assert(is_atomic_type(type));"
221 ),
222
223 Cmp = dict(
224         is_a     = "binop",
225         outs     = [ "False", "Eq", "Lt", "Le", "Gt", "Ge", "Lg", "Leg", "Uo", "Ue", "Ul", "Ule", "Ug", "Uge", "Ne", "True" ],
226 ),
227
228 Cond = dict(
229         ins      = [ "selector" ],
230         outs     = [ "false", "true" ],
231         attrs    = [
232                 dict(
233                         name = "kind",
234                         type = "cond_kind",
235                         init = "dense"
236                 ),
237                 dict(
238                         name = "default_proj",
239                         type = "long",
240                         init = "0"
241                 ),
242                 dict(
243                         name = "jmp_pred",
244                         type = "cond_jmp_predicate",
245                         init = "COND_JMP_PRED_NONE"
246                 )
247         ]
248 ),
249
250 Confirm = dict(
251         ins      = [ "value", "bound" ],
252         mode     = "get_irn_mode(irn_value)",
253         attrs    = [
254                 dict(
255                         name = "cmp",
256                         type = "pn_Cmp"
257                 ),
258         ],
259 ),
260
261 Const = dict(
262         mode       = "",
263         knownBlock = True,
264         attrs_name = "con",
265         attrs      = [
266                 dict(
267                         type = "tarval*",
268                         name = "tarval",
269                 )
270         ],
271 ),
272
273 Conv = dict(
274         is_a     = "unop",
275         attrs = [
276                 dict(
277                         name = "strict",
278                         type = "int",
279                         init = "0",
280                         special = dict(
281                                 prefix = "strict",
282                                 init = "1"
283                         )
284                 )
285         ]
286 ),
287
288 CopyB = dict(
289         ins   = [ "mem", "dst", "src" ],
290         outs  = [ "M", "X_regular", "X_except" ],
291         attrs = [
292                 dict(
293                         name = "type",
294                         type = "ir_type*"
295                 )
296         ],
297         pinned      = "memory",
298         pinned_init = "pinned",
299         d_post = '''
300         #if PRECISE_EXC_CONTEXT
301         firm_alloc_frag_arr(res, op_CopyB, &res->attr.copyb.exc.frag_arr);
302         #endif
303         '''
304 ),
305
306 Div = dict(
307         ins   = [ "mem", "dividend", "divisor" ],
308         outs  = [ "M", "X_regular", "X_except", "res" ],
309         attrs_name = "divmod",
310         attrs = [
311                 dict(
312                         type = "ir_mode*",
313                         name = "resmode"
314                 ),
315                 dict(
316                         name = "no_remainder",
317                         type = "int",
318                         init = "0",
319                         special = dict(
320                                 suffix = "RL",
321                                 init = "1"
322                         )
323                 )
324         ],
325         pinned = "exception",
326         d_post = '''
327         #if PRECISE_EXC_CONTEXT
328         firm_alloc_frag_arr(res, op_Div, &res->attr.except.frag_arr);
329         #endif
330         '''
331 ),
332
333 DivMod = dict(
334         ins   = [ "mem", "dividend", "divisor" ],
335         outs  = [ "M", "X_regular", "X_except", "res_div", "res_mod" ],
336         attrs_name = "divmod",
337         attrs = [
338                 dict(
339                         type = "ir_mode*",
340                         name = "resmode"
341                 ),
342         ],
343         pinned = "exception",
344         d_post = '''
345         #if PRECISE_EXC_CONTEXT
346         firm_alloc_frag_arr(res, op_DivMod, &res->attr.except.frag_arr);
347         #endif
348         '''
349 ),
350
351 End = dict(
352         mode       = "mode_X",
353         op_flags   = "cfopcode",
354         pinned     = "yes",
355         arity      = "dynamic",
356         noconstr   = True,
357         optimize   = False
358 ),
359
360 Eor = dict(
361         is_a     = "binop"
362 ),
363
364 Filter = dict(
365         ins   = [ "pred" ],
366         attrs = [
367                 dict(
368                         name = "proj",
369                         type = "long"
370                 )
371         ]
372
373         # TODO: Broken asserts in original:
374         # assert(get_Proj_pred(res));
375         # assert(get_nodes_block(get_Proj_pred(res)));
376 ),
377
378 Free = dict(
379         ins   = [ "mem", "ptr", "size" ],
380         mode  = "mode_M",
381         attrs = [
382                 dict(
383                         name = "type",
384                         type = "ir_type*"
385                 ),
386                 dict(
387                         name = "where",
388                         type = "ir_where_alloc"
389                 )
390         ]
391 ),
392
393 Id = dict(
394         ins = [ "pred" ]
395 ),
396
397 IJmp = dict(
398         mode     = "mode_X",
399         op_flags = "cfopcode",
400         pinned   = "yes",
401         ins      = [ "target" ],
402 ),
403
404 InstOf = dict(
405         ins   = [ "store", "objptr" ],
406         outs  = [ "M", "X_regular", "X_except", "res", "M_except" ],
407         attrs = [
408                 dict(
409                         name = "type",
410                         type = "ir_type*"
411                 )
412         ],
413         pinned      = "memory",
414         pinned_init = "floats",
415 ),
416
417 Jmp = dict(
418         mode     = "mode_X",
419         op_flags = "cfopcode",
420         pinned   = "yes",
421         ins      = [],
422 ),
423
424 Load = dict(
425         ins      = [ "mem", "ptr" ],
426         outs     = [ "M", "X_regular", "X_except", "res" ],
427         attrs    = [
428                 dict(
429                         type = "ir_mode*",
430                         name = "mode",
431                         java_name = "load_mode"
432                 ),
433         ],
434         constructor_args = [
435                 dict(
436                         type = "ir_cons_flags",
437                         name = "flags",
438                 ),
439         ],
440         d_post = '''
441 #if PRECISE_EXC_CONTEXT
442         firm_alloc_frag_arr(res, op_Load, &res->attr.load.exc.frag_arr);
443 #endif
444         '''
445 ),
446
447 Minus = dict(
448         is_a     = "unop"
449 ),
450
451 Mod = dict(
452         ins   = [ "mem", "dividend", "divisor" ],
453         outs  = [ "M", "X_regular", "X_except", "res" ],
454         attrs_name = "divmod",
455         attrs = [
456                 dict(
457                         type = "ir_mode*",
458                         name = "resmode"
459                 ),
460         ],
461         pinned = "exception",
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         pinned   = "yes",
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         ],
526         pinned = "exception",
527         d_post = '''
528         #if PRECISE_EXC_CONTEXT
529         firm_alloc_frag_arr(res, op_Quot, &res->attr.except.frag_arr);
530         #endif
531         '''
532 ),
533
534 Raise = dict(
535         ins   = [ "mem", "exo_ptr" ],
536         outs  = [ "M", "X" ]
537 ),
538
539 Return = dict(
540         ins      = [ "mem" ],
541         arity    = "variable",
542         mode     = "mode_X"
543 ),
544
545 Rotl = dict(
546         is_a     = "binop"
547 ),
548
549 Sel = dict(
550         ins    = [ "mem", "ptr" ],
551         arity  = "variable",
552         mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data",
553         attrs    = [
554                 dict(
555                         type = "ir_entity*",
556                         name = "entity"
557                 )
558         ]
559 ),
560
561 Shl = dict(
562         is_a     = "binop"
563 ),
564
565 Shr = dict(
566         is_a     = "binop"
567 ),
568
569 Shrs = dict(
570         is_a     = "binop"
571 ),
572
573 Start = dict(
574         mode       = "mode_T",
575         op_flags   = "cfopcode",
576         pinned     = "yes",
577         noconstr   = True,
578         optimize   = False
579 ),
580
581 Store = dict(
582         ins      = [ "mem", "ptr", "value" ],
583         outs     = [ "M", "X_regular", "X_except" ],
584         constructor_args = [
585                 dict(
586                         type = "ir_cons_flags",
587                         name = "flags",
588                 ),
589         ],
590         d_post = '''
591 #if PRECISE_EXC_CONTEXT
592         firm_alloc_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr);
593 #endif
594         '''
595 ),
596
597 Sub = dict(
598         is_a     = "binop"
599 ),
600
601 SymConst = dict(
602         mode       = "mode_P",
603         knownBlock = True,
604         noconstr   = True,
605         attrs      = [
606                 dict(
607                         type = "ir_entity*",
608                         name = "entity"
609                 )
610         ],
611 ),
612
613 Sync = dict(
614         mode     = "mode_M",
615         optimize = False,
616         arity    = "dynamic"
617 ),
618
619 Tuple = dict(
620         arity    = "variable",
621         mode     = "mode_T",
622 ),
623
624 Unknown = dict(
625         knownBlock = True,
626         block      = "get_irg_start_block(irg)",
627         nodbginfo  = True
628 ),
629 )