gen_docu: fix missing attributes, show generation time at the end
[libfirm] / scripts / ir_spec.py
1 from spec_util import abstract, setnodedefaults
2
3 class Op(object):
4         """Base class for firm nodes"""
5 abstract(Op)
6
7 class Unop(Op):
8         """Unary nodes have exactly 1 input"""
9         name     = "unop"
10         ins      = [
11                 ("op",  "operand"),
12         ]
13         op_index = 0
14         pinned   = "no"
15 abstract(Unop)
16
17 class Binop(Op):
18         """Binary nodes have exactly 2 inputs"""
19         name     = "binop"
20         ins      = [
21                 ( "left",   "first operand" ),
22                 ( "right", "second operand" ),
23         ]
24         op_index = 0
25         pinned   = "no"
26 abstract(Binop)
27
28 class Add(Binop):
29         """returns the sum of its operands"""
30         flags = [ "commutative" ]
31
32 class Alloc(Op):
33         """allocates a block of memory.
34         It can be specified whether the variable should be allocated to the stack
35         or to the heap."""
36         ins   = [
37                 ("mem",   "memory dependency" ),
38                 ("count", "number of objects to allocate" ),
39         ]
40         outs  = [
41                 ("M",         "memory result"),
42                 ("res",       "pointer to newly allocated memory"),
43                 ("X_regular", "control flow when no exception occurs"),
44                 ("X_except",  "control flow when exception occured"),
45         ]
46         attrs = [
47                 dict(
48                         name    = "type",
49                         type    = "ir_type*",
50                         comment = "type of the allocated variable",
51                 ),
52                 dict(
53                         name    = "where",
54                         type    = "ir_where_alloc",
55                         comment = "whether to allocate the variable on the stack or heap",
56                 )
57         ]
58         flags       = [ "fragile", "uses_memory" ]
59         pinned      = "exception"
60         throws_init = "false"
61         pinned_init = "op_pin_state_pinned"
62         attr_struct = "alloc_attr"
63
64 class Anchor(Op):
65         """utiliy node used to "hold" nodes in a graph that might possibly not be
66         reachable by other means or which should be reachable immediately without
67         searching through the graph.
68         Each firm-graph contains exactly one anchor node whose address is always
69         known. All other well-known graph-nodes like Start, End, NoMem, Bad, ...
70         are found by looking at the respective Anchor operand."""
71         mode             = "mode_ANY"
72         arity            = "variable"
73         flags            = [ "dump_noblock" ]
74         pinned           = "yes"
75         attr_struct      = "irg_attr"
76         knownBlock       = True
77         singleton        = True
78         noconstructor    = True
79         customSerializer = True
80
81 class And(Binop):
82         """returns the result of a bitwise and operation of its operands"""
83         flags    = [ "commutative" ]
84
85 class ASM(Op):
86         """executes assembler fragments of the target machine"""
87         mode             = "mode_T"
88         arity            = "variable"
89         flags            = [ "keep", "uses_memory" ]
90         pinned           = "memory"
91         pinned_init      = "op_pin_state_pinned"
92         attr_struct      = "asm_attr"
93         attrs_name       = "assem"
94         customSerializer = True
95         attrs = [
96                 dict(
97                         name    = "input_constraints",
98                         type    = "ir_asm_constraint*",
99                         comment = "input constraints",
100                 ),
101                 dict(
102                         name    = "n_output_constraints",
103                         type    = "int",
104                         noprop  = True,
105                         comment = "number of output constraints",
106                 ),
107                 dict(
108                         name    = "output_constraints",
109                         type    = "ir_asm_constraint*",
110                         comment = "output constraints",
111                 ),
112                 dict(
113                         name    = "n_clobbers",
114                         type    = "int",
115                         noprop  = True,
116                         comment = "number of clobbered registers/memory",
117                 ),
118                 dict(
119                         name    = "clobbers",
120                         type    = "ident**",
121                         comment = "list of clobbered registers/memory",
122                 ),
123                 dict(
124                         name    = "text",
125                         type    = "ident*",
126                         comment = "assembler text",
127                 ),
128         ]
129         # constructor is written manually at the moment, because of the clobbers+
130         # constraints arrays needing special handling (2 arguments for 1 attribute)
131         noconstructor = True
132
133 class Bad(Op):
134         """Bad nodes indicate invalid input, which is values which should never be
135         computed.
136
137         The typical use case for the Bad node is removing unreachable code.
138         Frontends should set the current_block to Bad when it is clear that
139         following code must be unreachable (ie. after a goto or return statement).
140         Optimisations also set block predecessors to Bad when it becomes clear,
141         that a control flow edge can never be executed.
142
143         The gigo optimisations ensures that nodes with Bad as their block, get
144         replaced by Bad themselfes. Nodes with at least 1 Bad input get exchanged
145         with Bad too. Exception to this rule are Block, Phi, Tuple and End node;
146         This is because removing inputs from a Block is hairy operation (requiring,
147         Phis to be shortened too for example). So instead of removing block inputs
148         they are set to Bad, and the actual removal is left to the control flow
149         optimisation phase. Block, Phi, Tuple with only Bad inputs however are
150         replaced by Bad right away."""
151         flags         = [ "start_block", "dump_noblock" ]
152         pinned        = "yes"
153         knownBlock    = True
154         block         = "get_irg_start_block(irg)"
155         attr_struct   = "bad_attr"
156         init = '''
157         res->attr.bad.irg.irg = irg;
158         '''
159
160 class Deleted(Op):
161         """Internal node which is temporary set to nodes which are already removed
162         from the graph."""
163         mode             = "mode_Bad"
164         flags            = [ ]
165         pinned           = "yes"
166         noconstructor    = True
167         customSerializer = True
168
169 class Block(Op):
170         """A basic block"""
171         mode             = "mode_BB"
172         knownBlock       = True
173         block            = "NULL"
174         pinned           = "yes"
175         arity            = "variable"
176         flags            = [ "labeled" ]
177         attr_struct      = "block_attr"
178         customSerializer = True
179
180         init = '''
181         res->attr.block.irg.irg     = irg;
182         res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
183         set_Block_matured(res, 1);
184
185         /* Create and initialize array for Phi-node construction. */
186         if (get_irg_phase_state(irg) == phase_building) {
187                 res->attr.block.graph_arr = NEW_ARR_D(ir_node *, irg->obst, irg->n_loc);
188                 memset(res->attr.block.graph_arr, 0, irg->n_loc * sizeof(ir_node*));
189         }
190         '''
191
192 class Borrow(Binop):
193         """Returns the borrow bit from and implied subtractions of its 2 operands"""
194         flags = []
195
196 class Bound(Op):
197         """Performs a bounds-check: if lower <= index < upper then return index,
198         otherwise throw an exception."""
199         ins    = [
200                 ("mem",    "memory dependency"),
201                 ("index",  "value to test"),
202                 ("lower",  "lower bound (inclusive)"),
203                 ("upper",  "upper bound (exclusive)"),
204         ]
205         outs  = [
206                 ("M",         "memory result"),
207                 ("res",       "the checked index"),
208                 ("X_regular", "control flow when no exception occurs"),
209                 ("X_except",  "control flow when exception occured"),
210         ]
211         flags  = [ "fragile", "highlevel" ]
212         pinned = "exception"
213         pinned_init = "op_pin_state_pinned"
214         throws_init = "false"
215         attr_struct = "bound_attr"
216
217 class Builtin(Op):
218         """performs a backend-specific builtin."""
219         ins      = [
220                 ("mem", "memory dependency"),
221         ]
222         arity    = "variable"
223         outs     = [
224                 ("M", "memory result"),
225                 # results follow here
226         ]
227         flags    = [ "uses_memory" ]
228         attrs    = [
229                 dict(
230                         type    = "ir_builtin_kind",
231                         name    = "kind",
232                         comment = "kind of builtin",
233                 ),
234                 dict(
235                         type    = "ir_type*",
236                         name    = "type",
237                         comment = "method type for the builtin call",
238                 )
239         ]
240         pinned      = "memory"
241         pinned_init = "op_pin_state_pinned"
242         attr_struct = "builtin_attr"
243         init   = '''
244         assert((get_unknown_type() == type) || is_Method_type(type));
245         '''
246
247 class Call(Op):
248         """Calls other code. Control flow is transfered to ptr, additional
249         operands are passed to the called code. Called code usually performs a
250         return operation. The operands of this return operation are the result
251         of the Call node."""
252         ins      = [
253                 ("mem",   "memory dependency"),
254                 ("ptr",   "pointer to called code"),
255         ]
256         arity    = "variable"
257         outs     = [
258                 ("M",                "memory result"),
259                 ("T_result",         "tuple containing all results"),
260                 ("X_regular",        "control flow when no exception occurs"),
261                 ("X_except",         "control flow when exception occured"),
262         ]
263         flags    = [ "fragile", "uses_memory" ]
264         attrs    = [
265                 dict(
266                         type    = "ir_type*",
267                         name    = "type",
268                         comment = "type of the call (usually type of the called procedure)",
269                 ),
270                 dict(
271                         type = "unsigned",
272                         name = "tail_call",
273                         # the tail call attribute can only be set by analysis
274                         init = "0",
275                 )
276         ]
277         attr_struct = "call_attr"
278         pinned      = "memory"
279         pinned_init = "op_pin_state_pinned"
280         throws_init = "false"
281         init = '''
282         assert((get_unknown_type() == type) || is_Method_type(type));
283         '''
284
285 class Carry(Binop):
286         """Computes the value of the carry-bit that would result when adding the 2
287         operands"""
288         flags = [ "commutative" ]
289
290 class Cast(Unop):
291         """perform a high-level type cast"""
292         mode     = "get_irn_mode(irn_op)"
293         flags    = [ "highlevel" ]
294         attrs    = [
295                 dict(
296                         type    = "ir_type*",
297                         name    = "type",
298                         comment = "target type of the case",
299                 )
300         ]
301         attr_struct = "cast_attr"
302         init     = "assert(is_atomic_type(type));"
303
304 class Cmp(Binop):
305         """Compares its two operands and checks whether a specified
306            relation (like less or equal) is fulfilled."""
307         flags = []
308         mode  = "mode_b"
309         attrs = [
310                 dict(
311                         type    = "ir_relation",
312                         name    = "relation",
313                         comment = "Comparison relation"
314                 )
315         ]
316         attr_struct = "cmp_attr"
317
318 class Cond(Op):
319         """Conditionally change control flow."""
320         ins      = [
321                 ("selector",  "condition parameter"),
322         ]
323         outs     = [
324                 ("false", "control flow if operand is \"false\""),
325                 ("true",  "control flow if operand is \"true\""),
326         ]
327         flags    = [ "cfopcode", "forking" ]
328         pinned   = "yes"
329         attrs    = [
330                 dict(
331                         name    = "jmp_pred",
332                         type    = "cond_jmp_predicate",
333                         init    = "COND_JMP_PRED_NONE",
334                         comment = "can indicate the most likely jump",
335                 ),
336         ]
337         attr_struct = "cond_attr"
338
339 class Switch(Op):
340         """Change control flow. The destination is choosen based on an integer input value which is looked up in a table.
341
342         Backends can implement this efficiently using a jump table."""
343         ins    = [
344                 ("selector", "input selector"),
345         ]
346         outs   = [
347                 ("default", "control flow if no other case matches"),
348         ]
349         flags  = [ "cfopcode", "forking" ]
350         pinned = "yes"
351         attrs  = [
352                 dict(
353                         name    = "n_outs",
354                         type    = "unsigned",
355                         comment = "number of outputs (including pn_Switch_default)",
356                 ),
357                 dict(
358                         name    = "table",
359                         type    = "ir_switch_table*",
360                         comment = "table describing mapping from input values to Proj numbers",
361                 ),
362         ]
363         attr_struct = "switch_attr"
364         attrs_name  = "switcha"
365
366 class Confirm(Op):
367         """Specifies constraints for a value. This allows explicit representation
368         of path-sensitive properties. (Example: This value is always >= 0 on 1
369         if-branch then all users within that branch are rerouted to a confirm-node
370         specifying this property).
371
372         A constraint is specified for the relation between value and bound.
373         value is always returned.
374         Note that this node does NOT check or assert the constraint, it merely
375         specifies it."""
376         ins      = [
377                 ("value",  "value to express a constraint for"),
378                 ("bound",  "value to compare against"),
379         ]
380         mode     = "get_irn_mode(irn_value)"
381         flags    = [ "highlevel" ]
382         pinned   = "yes"
383         attrs    = [
384                 dict(
385                         name    = "relation",
386                         type    = "ir_relation",
387                         comment = "relation of value to bound",
388                 ),
389         ]
390         attr_struct = "confirm_attr"
391
392 class Const(Op):
393         """Returns a constant value."""
394         flags      = [ "constlike", "start_block" ]
395         block      = "get_irg_start_block(irg)"
396         mode       = "get_tarval_mode(tarval)"
397         knownBlock = True
398         pinned     = "no"
399         attrs      = [
400                 dict(
401                         type    = "ir_tarval*",
402                         name    = "tarval",
403                         comment = "constant value (a tarval object)",
404                 )
405         ]
406         attr_struct = "const_attr"
407         attrs_name  = "con"
408
409 class Conv(Unop):
410         """Converts values between modes"""
411         flags = []
412         attrs = [
413                 dict(
414                         name    = "strict",
415                         type    = "int",
416                         init    = "0",
417                         comment = "force floating point to restrict precision even if backend computes in higher precision (deprecated)",
418                 )
419         ]
420         attr_struct = "conv_attr"
421
422 class CopyB(Op):
423         """Copies a block of memory"""
424         ins   = [
425                 ("mem",  "memory dependency"),
426                 ("dst",  "destination address"),
427                 ("src",  "source address"),
428         ]
429         outs  = [
430                 ("M",         "memory result"),
431                 ("X_regular", "control flow when no exception occurs"),
432                 ("X_except",  "control flow when exception occured"),
433         ]
434         flags = [ "fragile", "uses_memory" ]
435         attrs = [
436                 dict(
437                         name    = "type",
438                         type    = "ir_type*",
439                         comment = "type of copied data",
440                 )
441         ]
442         attr_struct = "copyb_attr"
443         pinned      = "memory"
444         pinned_init = "op_pin_state_pinned"
445         throws_init = "false"
446
447 class Div(Op):
448         """returns the quotient of its 2 operands"""
449         ins   = [
450                 ("mem",   "memory dependency"),
451                 ("left",  "first operand"),
452                 ("right", "second operand"),
453         ]
454         outs  = [
455                 ("M",         "memory result"),
456                 ("res",       "result of computation"),
457                 ("X_regular", "control flow when no exception occurs"),
458                 ("X_except",  "control flow when exception occured"),
459         ]
460         flags = [ "fragile", "uses_memory" ]
461         attrs = [
462                 dict(
463                         type    = "ir_mode*",
464                         name    = "resmode",
465                         comment = "mode of the result value",
466                 ),
467                 dict(
468                         name = "no_remainder",
469                         type = "int",
470                         init = "0",
471                 )
472         ]
473         attr_struct = "div_attr"
474         pinned      = "exception"
475         throws_init = "false"
476         op_index    = 1
477         arity_override = "oparity_binary"
478
479 class Dummy(Op):
480         """A placeholder value. This is used when constructing cyclic graphs where
481         you have cases where not all predecessors of a phi-node are known. Dummy
482         nodes are used for the unknown predecessors and replaced later."""
483         ins        = []
484         flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
485         knownBlock = True
486         pinned     = "yes"
487         block      = "get_irg_start_block(irg)"
488
489 class End(Op):
490         """Last node of a graph. It references nodes in endless loops (so called
491         keepalive edges)"""
492         mode             = "mode_X"
493         pinned           = "yes"
494         arity            = "dynamic"
495         flags            = [ "cfopcode" ]
496         knownBlock       = True
497         block            = "get_irg_end_block(irg)"
498         singleton        = True
499         customSerializer = True
500
501 class Eor(Binop):
502         """returns the result of a bitwise exclusive or operation of its operands"""
503         flags    = [ "commutative" ]
504
505 class Free(Op):
506         """Frees a block of memory previously allocated by an Alloc node"""
507         ins    = [
508                 ("mem",   "memory dependency" ),
509                 ("ptr",   "pointer to the object to free"),
510                 ("count", "number of objects to allocate" ),
511         ]
512         mode   = "mode_M"
513         flags  = [ "uses_memory" ]
514         pinned = "yes"
515         attrs  = [
516                 dict(
517                         name    = "type",
518                         type    = "ir_type*",
519                         comment = "type of the allocated variable",
520                 ),
521                 dict(
522                         name    = "where",
523                         type    = "ir_where_alloc",
524                         comment = "whether allocation was on the stack or heap",
525                 )
526         ]
527         attr_struct = "free_attr"
528
529 class Id(Op):
530         """Returns its operand unchanged."""
531         ins    = [
532            ("pred", "the value which is returned unchanged")
533         ]
534         pinned = "no"
535         flags  = []
536
537 class IJmp(Op):
538         """Jumps to the code in its argument. The code has to be in the same
539         function and the the destination must be one of the blocks reachable
540         by the tuple results"""
541         mode     = "mode_X"
542         pinned   = "yes"
543         ins      = [
544            ("target", "target address of the jump"),
545         ]
546         flags    = [ "cfopcode", "forking", "keep", "unknown_jump" ]
547
548 class InstOf(Op):
549         """Tests whether an object is an instance of a class-type"""
550         ins   = [
551            ("store", "memory dependency"),
552            ("obj",   "pointer to object being queried")
553         ]
554         outs  = [
555                 ("M",         "memory result"),
556                 ("res",       "checked object pointer"),
557                 ("X_regular", "control flow when no exception occurs"),
558                 ("X_except",  "control flow when exception occured"),
559         ]
560         flags = [ "highlevel" ]
561         attrs = [
562                 dict(
563                         name    = "type",
564                         type    = "ir_type*",
565                         comment = "type to check ptr for",
566                 )
567         ]
568         attr_struct = "io_attr"
569         pinned      = "memory"
570         pinned_init = "op_pin_state_floats"
571
572 class Jmp(Op):
573         """Jumps to the block connected through the out-value"""
574         mode     = "mode_X"
575         pinned   = "yes"
576         ins      = []
577         flags    = [ "cfopcode" ]
578
579 class Load(Op):
580         """Loads a value from memory (heap or stack)."""
581         ins   = [
582                 ("mem", "memory dependency"),
583                 ("ptr",  "address to load from"),
584         ]
585         outs  = [
586                 ("M",         "memory result"),
587                 ("res",       "result of load operation"),
588                 ("X_regular", "control flow when no exception occurs"),
589                 ("X_except",  "control flow when exception occured"),
590         ]
591         flags    = [ "fragile", "uses_memory" ]
592         pinned   = "exception"
593         attrs    = [
594                 dict(
595                         type      = "ir_mode*",
596                         name      = "mode",
597                         comment   = "mode of the value to be loaded",
598                 ),
599                 dict(
600                         type      = "ir_volatility",
601                         name      = "volatility",
602                         comment   = "volatile loads are a visible side-effect and may not be optimized",
603                         init      = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
604                 ),
605                 dict(
606                         type      = "ir_align",
607                         name      = "unaligned",
608                         comment   = "pointers to unaligned loads don't need to respect the load-mode/type alignments",
609                         init      = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
610                 ),
611         ]
612         attr_struct = "load_attr"
613         constructor_args = [
614                 dict(
615                         type    = "ir_cons_flags",
616                         name    = "flags",
617                         comment = "specifies alignment, volatility and pin state",
618                 ),
619         ]
620         pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
621         throws_init = "(flags & cons_throws_exception) != 0"
622
623 class Minus(Unop):
624         """returns the difference between its operands"""
625         flags = []
626
627 class Mod(Op):
628         """returns the remainder of its operands from an implied division.
629
630         Examples:
631
632         * mod(5,3)   produces 2
633         * mod(5,-3)  produces 2
634         * mod(-5,3)  produces -2
635         * mod(-5,-3) produces -2
636         """
637         ins   = [
638                 ("mem",   "memory dependency"),
639                 ("left",  "first operand"),
640                 ("right", "second operand"),
641         ]
642         outs  = [
643                 ("M",         "memory result"),
644                 ("res",       "result of computation"),
645                 ("X_regular", "control flow when no exception occurs"),
646                 ("X_except",  "control flow when exception occured"),
647         ]
648         flags = [ "fragile", "uses_memory" ]
649         attrs = [
650                 dict(
651                         type    = "ir_mode*",
652                         name    = "resmode",
653                         comment = "mode of the result",
654                 ),
655         ]
656         attr_struct = "mod_attr"
657         pinned      = "exception"
658         throws_init = "false"
659         op_index    = 1
660         arity_override = "oparity_binary"
661
662 class Mul(Binop):
663         """returns the product of its operands"""
664         flags = [ "commutative" ]
665
666 class Mulh(Binop):
667         """returns the upper word of the product of its operands (the part which
668         would not fit into the result mode of a normal Mul anymore)"""
669         flags = [ "commutative" ]
670
671 class Mux(Op):
672         """returns the false or true operand depending on the value of the sel
673         operand"""
674         ins    = [
675            ("sel",   "value making the output selection"),
676            ("false", "selected if sel input is false"),
677            ("true",  "selected if sel input is true"),
678         ]
679         flags  = []
680         pinned = "no"
681
682 class NoMem(Op):
683         """Placeholder node for cases where you don't need any memory input"""
684         mode          = "mode_M"
685         flags         = [ "dump_noblock", "dump_noinput" ]
686         pinned        = "yes"
687         knownBlock    = True
688         block         = "get_irg_start_block(irg)"
689         singleton     = True
690
691 class Not(Unop):
692         """returns the logical complement of a value. Works for integer values too.
693         If the input is false/zero then true/one is returned, otherwise false/zero
694         is returned."""
695         flags = []
696
697 class Or(Binop):
698         """returns the result of a bitwise or operation of its operands"""
699         flags = [ "commutative" ]
700
701 class Phi(Op):
702         """Choose a value based on control flow. A phi node has 1 input for each
703         predecessor of its block. If a block is entered from its nth predecessor
704         all phi nodes produce their nth input as result."""
705         pinned        = "yes"
706         arity         = "variable"
707         flags         = []
708         attr_struct   = "phi_attr"
709         init          = '''
710         res->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);'''
711         init_after_opt = '''
712         /* Memory Phis in endless loops must be kept alive.
713            As we can't distinguish these easily we keep all of them alive. */
714         if (is_Phi(res) && mode == mode_M)
715                 add_End_keepalive(get_irg_end(irg), res);'''
716
717 class Pin(Op):
718         """Pin the value of the node node in the current block. No users of the Pin
719         node can float above the Block of the Pin. The node cannot float behind
720         this block. Often used to Pin the NoMem node."""
721         ins      = [
722                 ("op", "value which is pinned"),
723         ]
724         mode     = "get_irn_mode(irn_op)"
725         flags    = [ "highlevel" ]
726         pinned   = "yes"
727
728 class Proj(Op):
729         """returns an entry of a tuple value"""
730         ins              = [
731                 ("pred", "the tuple value from which a part is extracted"),
732         ]
733         flags            = []
734         pinned           = "no"
735         knownBlock       = True
736         knownGraph       = True
737         block            = "get_nodes_block(irn_pred)"
738         graph            = "get_irn_irg(irn_pred)"
739         customSerializer = True
740         attrs      = [
741                 dict(
742                         type    = "long",
743                         name    = "proj",
744                         comment = "number of tuple component to be extracted",
745                 ),
746         ]
747         attr_struct = "proj_attr"
748
749 class Raise(Op):
750         """Raises an exception. Unconditional change of control flow. Writes an
751         explicit Except variable to memory to pass it to the exception handler.
752         Must be lowered to a Call to a runtime check function."""
753         ins    = [
754                 ("mem",     "memory dependency"),
755                 ("exo_ptr", "pointer to exception object to be thrown"),
756         ]
757         outs  = [
758                 ("M", "memory result"),
759                 ("X", "control flow to exception handler"),
760         ]
761         flags  = [ "highlevel", "cfopcode" ]
762         pinned = "yes"
763
764 class Return(Op):
765         """Returns from the current function. Takes memory and return values as
766         operands."""
767         ins      = [
768                 ("mem", "memory dependency"),
769         ]
770         arity    = "variable"
771         mode     = "mode_X"
772         flags    = [ "cfopcode" ]
773         pinned   = "yes"
774
775 class Rotl(Binop):
776         """Returns its first operand bits rotated left by the amount in the 2nd
777         operand"""
778         flags    = []
779
780 class Sel(Op):
781         """Computes the address of a entity of a compound type given the base
782         address of an instance of the compound type."""
783         ins    = [
784                 ("mem", "memory dependency"),
785                 ("ptr", "pointer to object to select from"),
786         ]
787         arity  = "variable"
788         flags  = []
789         mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
790         pinned = "no"
791         attrs  = [
792                 dict(
793                         type    = "ir_entity*",
794                         name    = "entity",
795                         comment = "entity which is selected",
796                 )
797         ]
798         attr_struct = "sel_attr"
799
800 class Shl(Binop):
801         """Returns its first operands bits shifted left by the amount of the 2nd
802         operand"""
803         flags = []
804
805 class Shr(Binop):
806         """Returns its first operands bits shifted right by the amount of the 2nd
807         operand. No special handling for the sign bit (zero extension)"""
808         flags = []
809
810 class Shrs(Binop):
811         """Returns its first operands bits shifted right by the amount of the 2nd
812         operand. The leftmost bit (usually the sign bit) stays the same
813         (sign extension)"""
814         flags = []
815
816 class Start(Op):
817         """The first node of a graph. Execution starts with this node."""
818         outs       = [
819                 ("X_initial_exec", "control flow"),
820                 ("M",              "initial memory"),
821                 ("P_frame_base",   "frame base pointer"),
822                 ("T_args",         "function arguments")
823         ]
824         mode             = "mode_T"
825         pinned           = "yes"
826         flags            = [ "cfopcode" ]
827         singleton        = True
828         knownBlock       = True
829         customSerializer = True
830         block            = "get_irg_start_block(irg)"
831
832 class Store(Op):
833         """Stores a value into memory (heap or stack)."""
834         ins   = [
835            ("mem",   "memory dependency"),
836            ("ptr",   "address to store to"),
837            ("value", "value to store"),
838         ]
839         outs  = [
840                 ("M",         "memory result"),
841                 ("X_regular", "control flow when no exception occurs"),
842                 ("X_except",  "control flow when exception occured"),
843         ]
844         flags    = [ "fragile", "uses_memory" ]
845         pinned   = "exception"
846         attr_struct = "store_attr"
847         pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
848         throws_init = "(flags & cons_throws_exception) != 0"
849         attrs = [
850                 dict(
851                         type      = "ir_volatility",
852                         name      = "volatility",
853                         comment   = "volatile stores are a visible side-effect and may not be optimized",
854                         init      = "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
855                 ),
856                 dict(
857                         type      = "ir_align",
858                         name      = "unaligned",
859                         comment   = "pointers to unaligned stores don't need to respect the load-mode/type alignments",
860                         init      = "flags & cons_unaligned ? align_non_aligned : align_is_aligned",
861                 ),
862         ]
863         constructor_args = [
864                 dict(
865                         type    = "ir_cons_flags",
866                         name    = "flags",
867                         comment = "specifies alignment, volatility and pin state",
868                 ),
869         ]
870
871 class Sub(Binop):
872         """returns the difference of its operands"""
873         flags = []
874
875 class SymConst(Op):
876         """A symbolic constant.
877
878          - *symconst_type_tag*  The symbolic constant represents a type tag.  The
879                                 type the tag stands for is given explicitly.
880          - *symconst_type_size* The symbolic constant represents the size of a type.
881                                 The type of which the constant represents the size
882                                 is given explicitly.
883          - *symconst_type_align* The symbolic constant represents the alignment of a
884                                 type.  The type of which the constant represents the
885                                 size is given explicitly.
886          - *symconst_addr_ent*  The symbolic constant represents the address of an
887                                 entity (variable or method).  The variable is given
888                                 explicitly by a firm entity.
889          - *symconst_ofs_ent*   The symbolic constant represents the offset of an
890                                 entity in its owner type.
891          - *symconst_enum_const* The symbolic constant is a enumeration constant of
892                                 an enumeration type."""
893         mode       = "mode_P"
894         flags      = [ "constlike", "start_block" ]
895         knownBlock = True
896         pinned     = "no"
897         attrs      = [
898                 dict(
899                         type    = "ir_entity*",
900                         name    = "entity",
901                         noprop  = True,
902                         comment = "entity whose address is returned",
903                 )
904         ]
905         attr_struct = "symconst_attr"
906         customSerializer = True
907         # constructor is written manually at the moment, because of the strange
908         # union argument
909         noconstructor = True
910
911 class Sync(Op):
912         """The Sync operation unifies several partial memory blocks. These blocks
913         have to be pairwise disjunct or the values in common locations have to
914         be identical.  This operation allows to specify all operations that
915         eventually need several partial memory blocks as input with a single
916         entrance by unifying the memories with a preceding Sync operation."""
917         mode     = "mode_M"
918         flags    = []
919         pinned   = "no"
920         arity    = "dynamic"
921
922 class Tuple(Op):
923         """Builds a Tuple from single values.
924
925         This is needed to implement optimizations that remove a node that produced
926         a tuple.  The node can be replaced by the Tuple operation so that the
927         following Proj nodes have not to be changed. (They are hard to find due to
928         the implementation with pointers in only one direction.) The Tuple node is
929         smaller than any other node, so that a node can be changed into a Tuple by
930         just changing its opcode and giving it a new in array."""
931         arity  = "variable"
932         mode   = "mode_T"
933         pinned = "no"
934         flags  = [ "labeled" ]
935
936 class Unknown(Op):
937         """Returns an unknown (at compile- and runtime) value. It is a valid
938         optimisation to replace an Unknown by any other constant value."""
939         knownBlock = True
940         pinned     = "yes"
941         block      = "get_irg_start_block(irg)"
942         flags      = [ "start_block", "constlike", "dump_noblock" ]
943
944 # Prepare node list
945
946 def getOpList(namespace):
947         nodes = []
948         for t in namespace.values():
949                 if type(t) != type:
950                         continue
951
952                 if issubclass(t, Op):
953                         setnodedefaults(t)
954                         nodes.append(t)
955         return nodes
956
957 nodes = getOpList(globals())
958 nodes = sorted(nodes, lambda x,y: cmp(x.name, y.name))