beifg: Simplify the implementation of be_ifg_foreach_node().
[libfirm] / scripts / ir_spec.py
index 017a3c0..6492420 100755 (executable)
@@ -1,3 +1,6 @@
+# This file is part of libFirm.
+# Copyright (C) 2012 Karlsruhe Institute of Technology.
+#
 # Firm node specifications
 # The comments are in (standard python) restructured text format and are used
 # to generate documentation.
@@ -122,6 +125,7 @@ class ASM:
        """
        mode             = "mode_T"
        arity            = "variable"
+       input_name       = "input"
        flags            = [ "keep", "uses_memory" ]
        pinned           = "memory"
        pinned_init      = "op_pin_state_pinned"
@@ -215,6 +219,7 @@ class Block:
        block            = "NULL"
        pinned           = "yes"
        arity            = "variable"
+       input_name       = "cfgpred"
        flags            = []
        attr_struct      = "block_attr"
        attrs            = [
@@ -229,56 +234,29 @@ class Block:
 
        init = '''
        res->attr.block.irg.irg     = irg;
-       res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
+       res->attr.block.backedge    = new_backedge_arr(get_irg_obstack(irg), arity);
        set_Block_matured(res, 1);
 
        /* Create and initialize array for Phi-node construction. */
        if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_CONSTRUCTION)) {
-               res->attr.block.graph_arr = NEW_ARR_D(ir_node *, irg->obst, irg->n_loc);
-               memset(res->attr.block.graph_arr, 0, irg->n_loc * sizeof(ir_node*));
+               res->attr.block.graph_arr = NEW_ARR_DZ(ir_node*, get_irg_obstack(irg), irg->n_loc);
        }
        '''
 
-@op
-class Borrow(Binop):
-       """Returns the borrow bit from and implied subtractions of its 2 operands"""
-       flags = []
-
-@op
-class Bound:
-       """Performs a bounds-check: if lower <= index < upper then return index,
-       otherwise throw an exception."""
-       ins    = [
-               ("mem",    "memory dependency"),
-               ("index",  "value to test"),
-               ("lower",  "lower bound (inclusive)"),
-               ("upper",  "upper bound (exclusive)"),
-       ]
-       outs  = [
-               ("M",         "memory result"),
-               ("res",       "the checked index"),
-               ("X_regular", "control flow when no exception occurs"),
-               ("X_except",  "control flow when exception occured"),
-       ]
-       flags  = [ "fragile", "highlevel" ]
-       pinned = "exception"
-       pinned_init = "op_pin_state_pinned"
-       throws_init = "false"
-       attr_struct = "bound_attr"
-
 @op
 class Builtin:
        """performs a backend-specific builtin."""
-       ins      = [
+       ins         = [
                ("mem", "memory dependency"),
        ]
-       arity    = "variable"
-       outs     = [
+       arity       = "variable"
+       input_name  = "param"
+       outs        = [
                ("M", "memory result"),
                # results follow here
        ]
-       flags    = [ "uses_memory" ]
-       attrs    = [
+       flags       = [ "uses_memory" ]
+       attrs       = [
                dict(
                        type    = "ir_builtin_kind",
                        name    = "kind",
@@ -293,7 +271,7 @@ class Builtin:
        pinned      = "memory"
        pinned_init = "op_pin_state_pinned"
        attr_struct = "builtin_attr"
-       init   = '''
+       init        = '''
        assert((get_unknown_type() == type) || is_Method_type(type));
        '''
 
@@ -303,19 +281,20 @@ class Call:
        operands are passed to the called code. Called code usually performs a
        return operation. The operands of this return operation are the result
        of the Call node."""
-       ins      = [
+       ins         = [
                ("mem",   "memory dependency"),
                ("ptr",   "pointer to called code"),
        ]
-       arity    = "variable"
-       outs     = [
+       arity       = "variable"
+       input_name  = "param"
+       outs        = [
                ("M",                "memory result"),
                ("T_result",         "tuple containing all results"),
                ("X_regular",        "control flow when no exception occurs"),
                ("X_except",         "control flow when exception occured"),
        ]
-       flags    = [ "fragile", "uses_memory" ]
-       attrs    = [
+       flags       = [ "fragile", "uses_memory" ]
+       attrs       = [
                dict(
                        type    = "ir_type*",
                        name    = "type",
@@ -330,27 +309,6 @@ class Call:
        assert((get_unknown_type() == type) || is_Method_type(type));
        '''
 
-@op
-class Carry(Binop):
-       """Computes the value of the carry-bit that would result when adding the 2
-       operands"""
-       flags = [ "commutative" ]
-
-@op
-class Cast(Unop):
-       """perform a high-level type cast"""
-       mode     = "get_irn_mode(irn_op)"
-       flags    = [ "highlevel" ]
-       attrs    = [
-               dict(
-                       type    = "ir_type*",
-                       name    = "type",
-                       comment = "target type of the case",
-               )
-       ]
-       attr_struct = "cast_attr"
-       init     = "assert(is_atomic_type(type));"
-
 @op
 class Cmp(Binop):
        """Compares its two operands and checks whether a specified
@@ -543,6 +501,7 @@ class End:
        mode             = "mode_X"
        pinned           = "yes"
        arity            = "dynamic"
+       input_name       = "keepalive"
        flags            = [ "cfopcode" ]
        knownBlock       = True
        block            = "get_irg_end_block(irg)"
@@ -773,15 +732,11 @@ class Phi:
        all phi nodes produce their nth input as result."""
        pinned        = "yes"
        arity         = "variable"
+       input_name    = "pred"
        flags         = []
        attr_struct   = "phi_attr"
        init          = '''
-       res->attr.phi.u.backedge = new_backedge_arr(irg->obst, arity);'''
-       init_after_opt = '''
-       /* Memory Phis in endless loops must be kept alive.
-          As we can't distinguish these easily we keep all of them alive. */
-       if (is_Phi(res) && mode == mode_M)
-               add_End_keepalive(get_irg_end(irg), res);'''
+       res->attr.phi.u.backedge = new_backedge_arr(get_irg_obstack(irg), arity);'''
        customSerializer = True
 
 @op
@@ -837,13 +792,14 @@ class Raise:
 class Return:
        """Returns from the current function. Takes memory and return values as
        operands."""
-       ins      = [
+       ins        = [
                ("mem", "memory dependency"),
        ]
-       arity    = "variable"
-       mode     = "mode_X"
-       flags    = [ "cfopcode" ]
-       pinned   = "yes"
+       arity      = "variable"
+       input_name = "res"
+       mode       = "mode_X"
+       flags      = [ "cfopcode" ]
+       pinned     = "yes"
 
 class Rotl(Binop):
        """Returns its first operand bits rotated left by the amount in the 2nd
@@ -857,15 +813,16 @@ class Sel:
 
        Optimisations assume that a Sel node can only produce a NULL pointer if the
        ptr input was NULL."""
-       ins    = [
+       ins         = [
                ("mem", "memory dependency"),
                ("ptr", "pointer to object to select from"),
        ]
-       arity  = "variable"
-       flags  = []
-       mode   = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
-       pinned = "no"
-       attrs  = [
+       arity       = "variable"
+       input_name  = "index"
+       flags       = []
+       mode        = "is_Method_type(get_entity_type(entity)) ? mode_P_code : mode_P_data"
+       pinned      = "no"
+       attrs       = [
                dict(
                        type    = "ir_entity*",
                        name    = "entity",
@@ -1007,10 +964,11 @@ class Sync:
        be identical.  This operation allows to specify all operations that
        eventually need several partial memory blocks as input with a single
        entrance by unifying the memories with a preceding Sync operation."""
-       mode     = "mode_M"
-       flags    = []
-       pinned   = "no"
-       arity    = "dynamic"
+       mode       = "mode_M"
+       flags      = []
+       pinned     = "no"
+       arity      = "dynamic"
+       input_name = "pred"
 
 @op
 class Tuple:
@@ -1022,10 +980,11 @@ class Tuple:
        the implementation with pointers in only one direction.) The Tuple node is
        smaller than any other node, so that a node can be changed into a Tuple by
        just changing its opcode and giving it a new in array."""
-       arity  = "variable"
-       mode   = "mode_T"
-       pinned = "no"
-       flags  = []
+       arity      = "variable"
+       input_name = "pred"
+       mode       = "mode_T"
+       pinned     = "no"
+       flags      = []
 
 @op
 class Unknown: