a49aa3f750d59b641402d14d838408bc036d3010
[libfirm] / scripts / ir_spec.py
1 nodes = dict(
2 Start = dict(
3         mode       = "mode_T",
4         op_flags   = "cfopcode",
5         state      = "pinned",
6         noconstr   = True,
7         optimize   = False
8 ),
9
10 End = dict(
11         mode       = "mode_X",
12         op_flags   = "cfopcode",
13         state      = "pinned",
14         arity      = "dynamic",
15         noconstr   = True,
16         optimize   = False
17 ),
18
19 Id = dict(
20         ins = [ "pred" ]
21 ),
22
23 Phi = dict(
24         noconstr = True,
25         state    = "pinned",
26         arity    = "variable",
27 ),
28
29 Jmp = dict(
30         mode     = "mode_X",
31         op_flags = "cfopcode",
32         state    = "pinned",
33         ins      = [],
34 ),
35
36 IJmp = dict(
37         mode     = "mode_X",
38         op_flags = "cfopcode",
39         state    = "pinned",
40         ins      = [ "target" ],
41 ),
42
43 Const = dict(
44         mode       = "",
45         knownBlock = True,
46         attrs_name = "con",
47         attrs      = [
48                 dict(
49                         type = "tarval*",
50                         name = "tarval",
51                 )
52         ],
53 ),
54
55 Block = dict(
56         mode       = "mode_BB",
57         knownBlock = True,
58         block      = "NULL",
59         noconstr   = True,
60         optimize   = False,
61         arity      = "variable",
62
63         init = '''
64         /* macroblock header */
65         res->in[0] = res;
66
67         res->attr.block.is_dead     = 0;
68         res->attr.block.is_mb_head  = 1;
69         res->attr.block.has_label   = 0;
70         res->attr.block.irg         = irg;
71         res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
72         res->attr.block.in_cg       = NULL;
73         res->attr.block.cg_backedge = NULL;
74         res->attr.block.extblk      = NULL;
75         res->attr.block.mb_depth    = 0;
76         res->attr.block.label       = 0;
77
78         set_Block_matured(res, 1);
79         set_Block_block_visited(res, 0);
80         ''',
81
82         d_pre = '''
83         int i;
84         int has_unknown = 0;
85         ''',
86
87         d_post = '''
88         /* Create and initialize array for Phi-node construction. */
89         if (get_irg_phase_state(current_ir_graph) == phase_building) {
90                 res->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,
91                                                       current_ir_graph->n_loc);
92                 memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
93         }
94
95         for (i = arity - 1; i >= 0; i--)
96                 if (is_Unknown(in[i])) {
97                         has_unknown = 1;
98                         break;
99                 }
100
101         if (!has_unknown) res = optimize_node(res);
102
103         current_ir_graph->current_block = res;
104
105         IRN_VRFY_IRG(res, current_ir_graph);
106         ''',
107
108         java_add   = '''
109         public void addPred(Node node) {
110                 binding_cons.add_immBlock_pred(ptr, node.ptr);
111         }
112
113         public void mature() {
114                 binding_cons.mature_immBlock(ptr);
115         }
116
117         @Override
118         public Block getBlock() {
119                 return null;
120         }
121
122         public boolean blockVisited() {
123                 return 0 != binding.Block_block_visited(ptr);
124         }
125
126         public void markBlockVisited() {
127                 binding.mark_Block_block_visited(ptr);
128         }''',
129 ),
130
131 SymConst = dict(
132         mode       = "mode_P",
133         knownBlock = True,
134         noconstr   = True,
135         attrs      = [
136                 dict(
137                         type = "ir_entity*",
138                         name = "entity"
139                 )
140         ],
141 ),
142
143 # SymConst
144
145 Call = dict(
146         ins      = [ "mem", "ptr" ],
147         arity    = "variable",
148         outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
149         attrs    = [
150                 dict(
151                         type = "ir_type*",
152                         name = "type"
153                 )
154         ]
155 ),
156
157 Builtin = dict(
158         ins      = [ "mem" ],
159         arity    = "variable",
160         outs     = [ "M_regular", "X_regular", "X_except", "T_result", "M_except", "P_value_res_base" ],
161         attrs    = [
162                 dict(
163                         type = "ir_builtin_kind",
164                         name = "kind"
165                 ),
166                 dict(
167                         type = "ir_type*",
168                         name = "type"
169                 )
170         ]
171 ),
172
173 binop = dict(
174         abstract = True,
175         ins      = [ "left", "right" ]
176 ),
177
178 Add = dict(
179         is_a     = "binop"
180 ),
181
182 Carry = dict(
183         is_a     = "binop"
184 ),
185
186 Sub = dict(
187         is_a     = "binop"
188 ),
189
190 Borrow = dict(
191         is_a     = "binop"
192 ),
193
194 Mul = dict(
195         is_a     = "binop"
196 ),
197
198 Mulh = dict(
199         is_a     = "binop"
200 ),
201
202 Abs = dict(
203         is_a     = "unop"
204 ),
205
206 And = dict(
207         is_a     = "binop"
208 ),
209
210 Or = dict(
211         is_a     = "binop"
212 ),
213
214 Eor = dict(
215         is_a     = "binop"
216 ),
217
218 Not = dict(
219         is_a     = "unop"
220 ),
221
222 Shl = dict(
223         is_a     = "binop"
224 ),
225
226 Shr = dict(
227         is_a     = "binop"
228 ),
229
230 Shrs = dict(
231         is_a     = "binop"
232 ),
233
234 Rotl = dict(
235         is_a     = "binop"
236 ),
237
238 Quot = dict(
239         ins   = [ "mem", "dividend", "divisor" ],
240         outs  = [ "M", "X_regular", "X_except", "res" ],
241         attrs = [
242                 dict(
243                         type = "ir_mode*",
244                         name = "resmode"
245                 ),
246                 dict(
247                         name = "state",
248                         type = "op_pin_state"
249                 )
250         ]
251 ),
252
253 Div = dict(
254         ins   = [ "mem", "dividend", "divisor" ],
255         outs  = [ "M", "X_regular", "X_except", "res" ],
256         attrs = [
257                 dict(
258                         type = "ir_mode*",
259                         name = "resmode"
260                 ),
261                 dict(
262                         name = "state",
263                         type = "op_pin_state"
264                 ),
265                 dict(
266                         name = "no_remainder",
267                         type = "int",
268                         init = "0",
269                         special = dict(
270                                 suffix = "RL",
271                                 init = "1"
272                         )
273                 )
274         ]
275 ),
276
277 DivMod = dict(
278         ins   = [ "mem", "dividend", "divisor" ],
279         outs  = [ "M", "X_regular", "X_except", "res_div", "res_mod" ],
280         attrs = [
281                 dict(
282                         type = "ir_mode*",
283                         name = "resmode"
284                 ),
285                 dict(
286                         name = "state",
287                         type = "op_pin_state"
288                 )
289         ]
290 ),
291
292 Mod = dict(
293         ins   = [ "mem", "dividend", "divisor" ],
294         outs  = [ "M", "X_regular", "X_except", "res" ],
295         attrs = [
296                 dict(
297                         type = "ir_mode*",
298                         name = "resmode"
299                 ),
300                 dict(
301                         name = "state",
302                         type = "op_pin_state"
303                 )
304         ]
305 ),
306
307 Load = dict(
308         ins      = [ "mem", "ptr" ],
309         outs     = [ "M", "X_regular", "X_except", "res" ],
310         attrs    = [
311                 dict(
312                         type = "ir_mode*",
313                         name = "mode",
314                         java_name = "load_mode"
315                 ),
316         ],
317         constructor_args = [
318                 dict(
319                         type = "ir_cons_flags",
320                         name = "flags",
321                 ),
322         ],
323         d_post = '''
324 #if PRECISE_EXC_CONTEXT
325         firm_alloc_frag_arr(res, op_Load, &res->attr.load.exc.frag_arr);
326 #endif
327         '''
328 ),
329
330 Store = dict(
331         ins      = [ "mem", "ptr", "value" ],
332         outs     = [ "M", "X_regular", "X_except" ],
333         constructor_args = [
334                 dict(
335                         type = "ir_cons_flags",
336                         name = "flags",
337                 ),
338         ],
339         d_post = '''
340 #if PRECISE_EXC_CONTEXT
341         firm_alloc_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr);
342 #endif
343         '''
344 ),
345
346 Anchor = dict(
347         mode       = "mode_ANY",
348         ins        = [ "end_block", "start_block", "end", "start",
349                        "end_reg", "end_except", "initial_exec",
350                                    "frame", "tls", "initial_mem", "args",
351                                    "bad", "no_mem" ],
352         knownBlock = True,
353         noconstr   = True
354 ),
355
356 NoMem = dict(
357         mode       = "mode_M",
358         knownBlock = True,
359 ),
360
361 Bad = dict(
362         mode       = "mode_Bad",
363         knownBlock = True,
364 ),
365
366 Pin = dict(
367         ins      = [ "op" ],
368         mode     = "get_irn_mode(irn_op)"
369 ),
370
371 Proj = dict(
372         ins      = [ "pred" ],
373         attrs    = [
374                 dict(
375                         type = "long",
376                         name = "proj",
377                         initname = ""
378                 )
379         ]
380 ),
381
382 Sel = dict(
383         ins    = [ "mem", "ptr" ],
384         arity  = "variable",
385         mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data",
386         attrs    = [
387                 dict(
388                         type = "ir_entity*",
389                         name = "entity"
390                 )
391         ]
392 ),
393
394 Sync = dict(
395         mode     = "mode_M",
396         optimize = False,
397         arity    = "dynamic"
398 ),
399
400 Tuple = dict(
401         arity    = "variable",
402         mode     = "mode_T",
403 ),
404
405 Unknown = dict(
406         knownBlock = True,
407         block      = "get_irg_start_block(irg)",
408         nodbginfo  = True
409 ),
410
411 Confirm = dict(
412         ins      = [ "value", "bound" ],
413         mode     = "get_irn_mode(irn_value)",
414         attrs    = [
415                 dict(
416                         name = "cmp",
417                         type = "pn_Cmp"
418                 ),
419         ],
420 ),
421
422 Return = dict(
423         ins      = [ "mem" ],
424         arity    = "variable",
425         mode     = "mode_X"
426 ),
427
428 unop = dict(
429         abstract = True,
430         ins      = [ "op" ]
431 ),
432
433 Minus = dict(
434         is_a     = "unop"
435 ),
436
437 Mux = dict(
438         ins      = [ "sel", "false", "true" ]
439 ),
440
441 Cond = dict(
442         ins      = [ "selector" ],
443         outs     = [ "false", "true" ],
444         attrs    = [
445                 dict(
446                         name = "kind",
447                         type = "cond_kind",
448                         init = "dense"
449                 ),
450                 dict(
451                         name = "default_proj",
452                         type = "long",
453                         init = "0"
454                 ),
455                 dict(
456                         name = "jmp_pred",
457                         type = "cond_jmp_predicate",
458                         init = "COND_JMP_PRED_NONE"
459                 )
460         ]
461 ),
462
463 Cmp = dict(
464         is_a     = "binop",
465         outs     = [ "False", "Eq", "Lt", "Le", "Gt", "Ge", "Lg", "Leg", "Uo", "Ue", "Ul", "Ule", "Ug", "Uge", "Ne", "True" ],
466 ),
467
468 Conv = dict(
469         is_a     = "unop",
470         attrs = [
471                 dict(
472                         name = "strict",
473                         type = "int",
474                         init = "0",
475                         special = dict(
476                                 prefix = "strict",
477                                 init = "1"
478                         )
479                 )
480         ]
481 ),
482
483 Alloc = dict(
484         ins   = [ "mem", "size" ],
485         outs  = [ "M", "X_regular", "X_except", "res" ],
486         attrs = [
487                 dict(
488                         name = "type",
489                         type = "ir_type*"
490                 ),
491                 dict(
492                         name = "where",
493                         type = "ir_where_alloc"
494                 )
495         ]
496 ),
497
498 Free = dict(
499         ins   = [ "mem", "ptr", "size" ],
500         mode  = "mode_M",
501         attrs = [
502                 dict(
503                         name = "type",
504                         type = "ir_type*"
505                 ),
506                 dict(
507                         name = "where",
508                         type = "ir_where_alloc"
509                 )
510         ]
511 ),
512
513 CopyB = dict(
514         ins   = [ "mem", "dst", "src" ],
515         outs  = [ "M", "X_regular", "X_except" ],
516         attrs = [
517                 dict(
518                         name = "type",
519                         type = "ir_type*"
520                 )
521         ]
522 ),
523 )