a firm Makefile
[libfirm] / scripts / ir_spec.py
index 4dade90..0961109 100755 (executable)
@@ -20,15 +20,17 @@ class Binop(Op):
        pinned   = "no"
 abstract(Binop)
 
-class Abs(Unop):
-       flags = []
-
 class Add(Binop):
        flags = ["commutative"]
 
 class Alloc(Op):
-       ins   = [ "mem", "size" ]
-       outs  = [ "M", "X_regular", "X_except", "res" ]
+       ins   = [ "mem", "count" ]
+       outs  = [
+               ("M",         "memory result",                         "pn_Generic_M"),
+               ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
+               ("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
+               ("res",       "pointer to newly allocated memory",     "pn_Generic_other"),
+       ]
        flags = [ "fragile", "uses_memory" ]
        attrs = [
                dict(
@@ -42,17 +44,16 @@ class Alloc(Op):
        ]
        pinned      = "yes"
        attr_struct = "alloc_attr"
-       d_post = '''
-       firm_alloc_frag_arr(res, op_Alloc, &res->attr.alloc.exc.frag_arr);
-       '''
 
 class Anchor(Op):
        mode        = "mode_ANY"
        arity       = "variable"
        flags       = [ "dump_noblock" ]
        pinned      = "yes"
+       attr_struct = "irg_attr"
        knownBlock  = True
        singleton   = True
+       noconstructor = True
 
 class And(Binop):
        flags    = [ "commutative" ]
@@ -61,9 +62,10 @@ class ASM(Op):
        mode          = "mode_T"
        arity         = "variable"
        flags         = [ "keep", "uses_memory" ]
-       attr_struct   = "asm_attr"
        pinned        = "memory"
        pinned_init   = "op_pin_state_pinned"
+       attr_struct   = "asm_attr"
+       attrs_name    = "assem"
        attrs = [
                dict(
                        name = "input_constraints",
@@ -72,6 +74,7 @@ class ASM(Op):
                dict(
                        name = "n_output_constraints",
                        type = "int",
+                       noprop = True,
                ),
                dict(
                        name = "output_constraints",
@@ -80,6 +83,7 @@ class ASM(Op):
                dict(
                        name = "n_clobbers",
                        type = "int",
+                       noprop = True,
                ),
                dict(
                        name = "clobbers",
@@ -90,81 +94,53 @@ class ASM(Op):
                        type = "ident*",
                ),
        ]
-       java_noconstr = True
 
 class Bad(Op):
-       mode        = "mode_Bad"
-       flags       = [ "cfopcode", "fragile", "start_block", "dump_noblock" ]
-       pinned      = "yes"
-       knownBlock  = True
-       singleton   = True
-       attr_struct = "irg_attr"
+       mode          = "mode_T"
+       flags         = [ "cfopcode", "start_block", "dump_noblock" ]
+       pinned        = "yes"
+       knownBlock    = True
+       block         = "get_irg_start_block(irg)"
+       singleton     = True
+       attr_struct   = "bad_attr"
        init = '''
-       res->attr.irg.irg = irg;
+       res->attr.bad.irg.irg = irg;
        '''
 
+class Deleted(Op):
+       mode          = "mode_Bad"
+       flags         = [ ]
+       pinned        = "yes"
+       noconstructor = True
+
 class Block(Op):
        mode        = "mode_BB"
        knownBlock  = True
        block       = "NULL"
        pinned      = "yes"
-       optimize    = False
        arity       = "variable"
        flags       = [ "labeled" ]
        attr_struct = "block_attr"
-       java_noconstr = True
 
        init = '''
-       /* macroblock header */
-       res->in[0] = res;
-
-       res->attr.block.is_dead     = 0;
-       res->attr.block.is_mb_head  = 1;
        res->attr.block.irg.irg     = irg;
        res->attr.block.backedge    = new_backedge_arr(irg->obst, arity);
-       res->attr.block.in_cg       = NULL;
-       res->attr.block.cg_backedge = NULL;
-       res->attr.block.extblk      = NULL;
-       res->attr.block.mb_depth    = 0;
-       res->attr.block.entity      = NULL;
-
        set_Block_matured(res, 1);
-       set_Block_block_visited(res, 0);
-       '''
 
-       d_pre = '''
-       int i;
-       int has_unknown = 0;
-       '''
-
-       d_post = '''
        /* Create and initialize array for Phi-node construction. */
-       if (get_irg_phase_state(current_ir_graph) == phase_building) {
-               res->attr.block.graph_arr = NEW_ARR_D(ir_node *, current_ir_graph->obst,
-                                                     current_ir_graph->n_loc);
-               memset(res->attr.block.graph_arr, 0, sizeof(ir_node *)*current_ir_graph->n_loc);
+       if (get_irg_phase_state(irg) == phase_building) {
+               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*));
        }
-
-       for (i = arity - 1; i >= 0; i--)
-               if (is_Unknown(in[i])) {
-                       has_unknown = 1;
-                       break;
-               }
-
-       if (!has_unknown) res = optimize_node(res);
-
-       current_ir_graph->current_block = res;
-
-       IRN_VRFY_IRG(res, current_ir_graph);
        '''
 
        java_add   = '''
        public void addPred(Node node) {
-               binding_cons.add_immBlock_pred(ptr, node.ptr);
+               binding_ircons.add_immBlock_pred(ptr, node.ptr);
        }
 
        public void mature() {
-               binding_cons.mature_immBlock(ptr);
+               binding_ircons.mature_immBlock(ptr);
        }
 
        @Override
@@ -173,15 +149,15 @@ class Block(Op):
        }
 
        public boolean blockVisited() {
-               return 0 != binding.Block_block_visited(ptr);
+               return 0 != binding_irnode.Block_block_visited(ptr);
        }
 
        public void markBlockVisited() {
-               binding.mark_Block_block_visited(ptr);
+               binding_irnode.mark_Block_block_visited(ptr);
        }
 
        public boolean isBad() {
-               return binding.is_Bad(ptr) != 0;
+               return binding_irnode.is_Bad(ptr) != 0;
        }
        '''
 
@@ -190,24 +166,25 @@ class Borrow(Binop):
 
 class Bound(Op):
        ins    = [ "mem", "index", "lower", "upper" ]
-       outs   = [ "M", "X_regular", "X_except", "res" ]
+       outs  = [
+               ("M",         "memory result",                         "pn_Generic_M"),
+               ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
+               ("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
+               ("res",       "the checked index",                     "pn_Generic_other"),
+       ]
        flags  = [ "fragile", "highlevel" ]
        pinned = "exception"
        pinned_init = "op_pin_state_pinned"
        attr_struct = "bound_attr"
-       d_post = '''
-       firm_alloc_frag_arr(res, op_Bound, &res->attr.bound.exc.frag_arr);
-       '''
-
-class Break(Op):
-       mode   = "mode_X"
-       flags  = [ "cfopcode" ]
-       pinned = "yes"
+       attrs_name  = "bound"
 
 class Builtin(Op):
        ins      = [ "mem" ]
        arity    = "variable"
-       outs     = [ "M", "X_regular", "X_except", "T_result", "P_value_res_base" ]
+       outs     = [
+               ("M",        "memory result", "pn_Generic_M"),
+               ("1_result", "first result",  "pn_Generic_other"),
+       ]
        flags    = [ "uses_memory" ]
        attrs    = [
                dict(
@@ -229,7 +206,13 @@ class Builtin(Op):
 class Call(Op):
        ins      = [ "mem", "ptr" ]
        arity    = "variable"
-       outs     = [ "M", "X_regular", "X_except", "T_result", "P_value_res_base" ]
+       outs     = [
+               ("M",                "memory result",                         "pn_Generic_M"),
+               ("X_regular",        "control flow when no exception occurs", "pn_Generic_X_regular"),
+               ("X_except",         "control flow when exception occured",   "pn_Generic_X_except"),
+               ("T_result",         "tuple containing all results",          "pn_Generic_other"),
+               ("P_value_res_base", "pointer to memory register containing copied results passed by value"),
+       ]
        flags    = [ "fragile", "uses_memory" ]
        attrs    = [
                dict(
@@ -249,24 +232,6 @@ class Call(Op):
        init = '''
        assert((get_unknown_type() == type) || is_Method_type(type));
        '''
-       d_post = '''
-       firm_alloc_frag_arr(res, op_Call, &res->attr.call.exc.frag_arr);
-       '''
-
-class CallBegin(Op):
-       ins   = [ "ptr" ]
-       outs  = [ "" ] # TODO
-       flags         = [ "cfopcode", "ip_cfopcode" ]
-       pinned        = "yes"
-       # TODO: attribute with call...
-       attr_struct   = "callbegin_attr"
-       attrs         = [
-               dict(
-                       type = "ir_node*",
-                       name = "call"
-               )
-       ]
-       java_noconstr = True
 
 class Carry(Binop):
        flags = [ "commutative" ]
@@ -284,12 +249,32 @@ class Cast(Unop):
        init     = "assert(is_atomic_type(type));"
 
 class Cmp(Binop):
-       outs  = [ "False", "Eq", "Lt", "Le", "Gt", "Ge", "Lg", "Leg", "Uo", "Ue", "Ul", "Ule", "Ug", "Uge", "Ne", "True" ]
+       outs  = [
+               ("False", "always false",                            "0"),
+               ("Eq",    "equal",                                   "1"),
+               ("Lt",    "less",                                    "2"),
+               ("Le",    "less or equal",                           "pn_Cmp_Eq|pn_Cmp_Lt"),
+               ("Gt",    "greater",                                 "4"),
+               ("Ge",    "greater or equal",                        "pn_Cmp_Eq|pn_Cmp_Gt"),
+               ("Lg",    "less or greater ('not equal' for integer numbers)", "pn_Cmp_Lt|pn_Cmp_Gt"),
+               ("Leg",   "less, equal or greater ('not unordered')", "pn_Cmp_Lt|pn_Cmp_Eq|pn_Cmp_Gt"),
+               ("Uo",    "unordered",                               "8"),
+               ("Ue",    "unordered or equal",                      "pn_Cmp_Uo|pn_Cmp_Eq"),
+               ("Ul",    "unordered or less",                       "pn_Cmp_Uo|pn_Cmp_Lt"),
+               ("Ule",   "unordered, less or equal",                "pn_Cmp_Uo|pn_Cmp_Lt|pn_Cmp_Eq"),
+               ("Ug",    "unordered or greater",                    "pn_Cmp_Uo|pn_Cmp_Gt"),
+               ("Uge",   "onordered, greater or equal",             "pn_Cmp_Uo|pn_Cmp_Gt|pn_Cmp_Eq"),
+               ("Ne",    "unordered, less or greater ('not equal' for floatingpoint numbers)", "pn_Cmp_Uo|pn_Cmp_Lt|pn_Cmp_Gt"),
+               ("True",  "always true",                             "15"),
+       ]
        flags = []
 
 class Cond(Op):
        ins      = [ "selector" ]
-       outs     = [ "false", "true" ]
+       outs     = [
+               ("false", "control flow if operand is \"false\""),
+               ("true",  "control flow if operand is \"true\""),
+       ]
        flags    = [ "cfopcode", "forking" ]
        pinned   = "yes"
        attrs    = [
@@ -318,6 +303,7 @@ class Confirm(Op):
                ),
        ]
        attr_struct = "confirm_attr"
+       attrs_name  = "confirm"
 
 class Const(Op):
        mode       = ""
@@ -327,7 +313,7 @@ class Const(Op):
        attrs_name = "con"
        attrs      = [
                dict(
-                       type = "tarval*",
+                       type = "ir_tarval*",
                        name = "tarval",
                )
        ]
@@ -347,10 +333,15 @@ class Conv(Unop):
                )
        ]
        attr_struct = "conv_attr"
+       attrs_name  = "conv"
 
 class CopyB(Op):
        ins   = [ "mem", "dst", "src" ]
-       outs  = [ "M", "X_regular", "X_except" ]
+       outs  = [
+               ("M",         "memory result",                         "pn_Generic_M"),
+               ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
+               ("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
+       ]
        flags = [ "fragile", "highlevel", "uses_memory" ]
        attrs = [
                dict(
@@ -359,15 +350,18 @@ class CopyB(Op):
                )
        ]
        attr_struct = "copyb_attr"
+       attrs_name  = "copyb"
        pinned      = "memory"
        pinned_init = "op_pin_state_pinned"
-       d_post = '''
-       firm_alloc_frag_arr(res, op_CopyB, &res->attr.copyb.exc.frag_arr);
-       '''
 
 class Div(Op):
        ins   = [ "mem", "left", "right" ]
-       outs  = [ "M", "X_regular", "X_except", "res" ]
+       outs  = [
+               ("M",         "memory result",                         "pn_Generic_M"),
+               ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
+               ("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
+               ("res",       "result of computation",                 "pn_Generic_other"),
+       ]
        flags = [ "fragile", "uses_memory" ]
        attrs_name = "divmod"
        attrs = [
@@ -389,13 +383,16 @@ class Div(Op):
        pinned      = "exception"
        op_index    = 1
        arity_override = "oparity_binary"
-       d_post = '''
-       firm_alloc_frag_arr(res, op_Div, &res->attr.except.frag_arr);
-       '''
 
 class DivMod(Op):
        ins   = [ "mem", "left", "right" ]
-       outs  = [ "M", "X_regular", "X_except", "res_div", "res_mod" ]
+       outs  = [
+               ("M",         "memory result",                         "pn_Generic_M"),
+               ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
+               ("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
+               ("res_div",   "result of computation a/b",             "pn_Generic_other"),
+               ("res_mod",   "result of computation a%b"),
+       ]
        flags = [ "fragile", "uses_memory" ]
        attrs_name = "divmod"
        attrs = [
@@ -408,14 +405,10 @@ class DivMod(Op):
        pinned      = "exception"
        op_index    = 1
        arity_override = "oparity_binary"
-       d_post = '''
-       firm_alloc_frag_arr(res, op_DivMod, &res->attr.except.frag_arr);
-       '''
 
 class Dummy(Op):
        ins   = []
-       flags = [ "cfopcode", "fragile", "start_block", "constlike",
-                 "dump_noblock" ]
+       flags = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
        knownBlock = True
        pinned     = "yes"
        block      = "get_irg_start_block(irg)"
@@ -425,38 +418,13 @@ class End(Op):
        pinned     = "yes"
        arity      = "dynamic"
        flags      = [ "cfopcode" ]
+       knownBlock = True
+       block      = "get_irg_end_block(irg)"
        singleton  = True
 
-class EndExcept(Op):
-       mode      = "mode_X"
-       pinned    = "yes"
-       arity     = "dynamic"
-       flags     = [ "cfopcode", "ip_cfopcode" ]
-       singleton = True
-
-class EndReg(Op):
-       mode      = "mode_X"
-       pinned    = "yes"
-       arity     = "dynamic"
-       flags     = [ "cfopcode", "ip_cfopcode" ]
-       singleton = True
-
 class Eor(Binop):
        flags    = [ "commutative" ]
 
-class Filter(Op):
-       ins   = [ "pred" ]
-       flags = []
-       attrs = [
-               dict(
-                       name = "proj",
-                       type = "long"
-               )
-       ]
-       pinned      = "yes"
-       attr_struct = "filter_attr"
-       java_noconstr = True
-
 class Free(Op):
        ins    = [ "mem", "ptr", "size" ]
        mode   = "mode_M"
@@ -487,7 +455,12 @@ class IJmp(Op):
 
 class InstOf(Op):
        ins   = [ "store", "obj" ]
-       outs  = [ "M", "X_regular", "X_except", "res" ]
+       outs  = [
+               ("M",         "memory result",                         "pn_Generic_M"),
+               ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
+               ("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
+               ("res",       "checked object pointer",                "pn_Generic_other"),
+       ]
        flags = [ "highlevel" ]
        attrs = [
                dict(
@@ -507,7 +480,12 @@ class Jmp(Op):
 
 class Load(Op):
        ins      = [ "mem", "ptr" ]
-       outs     = [ "M", "X_regular", "X_except", "res" ]
+       outs  = [
+               ("M",         "memory result",                         "pn_Generic_M"),
+               ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
+               ("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
+               ("res",       "result of load operation",              "pn_Generic_other"),
+       ]
        flags    = [ "fragile", "uses_memory" ]
        pinned   = "exception"
        pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
@@ -525,16 +503,18 @@ class Load(Op):
                        name = "flags",
                ),
        ]
-       d_post = '''
-       firm_alloc_frag_arr(res, op_Load, &res->attr.load.exc.frag_arr);
-       '''
 
 class Minus(Unop):
        flags = []
 
 class Mod(Op):
        ins   = [ "mem", "left", "right" ]
-       outs  = [ "M", "X_regular", "X_except", "res" ]
+       outs  = [
+               ("M",         "memory result",                         "pn_Generic_M"),
+               ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
+               ("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
+               ("res",       "result of computation",                 "pn_Generic_other"),
+       ]
        flags = [ "fragile", "uses_memory" ]
        attrs_name = "divmod"
        attrs = [
@@ -547,9 +527,6 @@ class Mod(Op):
        pinned      = "exception"
        op_index    = 1
        arity_override = "oparity_binary"
-       d_post = '''
-       firm_alloc_frag_arr(res, op_Mod, &res->attr.except.frag_arr);
-       '''
 
 class Mul(Binop):
        flags = [ "commutative" ]
@@ -563,11 +540,12 @@ class Mux(Op):
        pinned = "no"
 
 class NoMem(Op):
-       mode       = "mode_M"
-       flags      = [ "dump_noblock", "dump_noinput" ]
-       pinned     = "yes"
-       knownBlock = True
-       singleton  = True
+       mode          = "mode_M"
+       flags         = [ "dump_noblock", "dump_noinput" ]
+       pinned        = "yes"
+       knownBlock    = True
+       block         = "get_irg_start_block(irg)"
+       singleton     = True
 
 class Not(Unop):
        flags = []
@@ -576,12 +554,10 @@ class Or(Binop):
        flags = [ "commutative" ]
 
 class Phi(Op):
-       pinned      = "yes"
-       arity       = "variable"
-       flags       = []
-       attr_struct = "phi_attr"
-       custom_is   = True
-       java_noconstr = True
+       pinned        = "yes"
+       arity         = "variable"
+       flags         = []
+       attr_struct   = "phi_attr"
        init = '''
        /* Memory Phis in endless loops must be kept alive.
           As we can't distinguish these easily we keep all of them alive. */
@@ -596,22 +572,31 @@ class Pin(Op):
        pinned   = "yes"
 
 class Proj(Op):
-       ins      = [ "pred" ]
-       flags    = []
-       pinned   = "no"
-       attrs    = [
+       ins        = [ "pred" ]
+       flags      = []
+       pinned     = "no"
+       knownBlock = True
+       knownGraph = True
+       block      = "get_nodes_block(irn_pred)"
+       graph      = "get_irn_irg(irn_pred)"
+       attrs      = [
                dict(
                        type = "long",
                        name = "proj",
-                       initname = ""
+                       initname = "",
+                       noprop = False,
                )
        ]
        attr_struct = "long"
-       custom_is   = True
 
 class Quot(Op):
        ins   = [ "mem", "left", "right" ]
-       outs  = [ "M", "X_regular", "X_except", "res" ]
+       outs  = [
+               ("M",         "memory result",                         "pn_Generic_M"),
+               ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
+               ("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
+               ("res",       "result of computation",                 "pn_Generic_other"),
+       ]
        flags = [ "fragile", "uses_memory" ]
        attrs_name = "divmod"
        attrs = [
@@ -624,13 +609,13 @@ class Quot(Op):
        pinned      = "exception"
        op_index    = 1
        arity_override = "oparity_binary"
-       d_post = '''
-       firm_alloc_frag_arr(res, op_Quot, &res->attr.except.frag_arr);
-       '''
 
 class Raise(Op):
        ins    = [ "mem", "exo_ptr" ]
-       outs   = [ "M", "X" ]
+       outs  = [
+               ("M", "memory result",                     "pn_Generic_M"),
+               ("X", "control flow to exception handler", "pn_Generic_X_regular"),
+       ]
        flags  = [ "highlevel", "cfopcode" ]
        pinned = "yes"
 
@@ -668,14 +653,27 @@ class Shrs(Binop):
        flags = []
 
 class Start(Op):
+       outs       = [
+               ("X_initial_exec", "control flow"),
+               ("M",              "initial memory"),
+               ("P_frame_base",   "frame base pointer"),
+               ("P_tls",          "pointer to thread local storage segment"),
+               ("T_args",         "function arguments")
+       ]
        mode       = "mode_T"
        pinned     = "yes"
        flags      = [ "cfopcode" ]
        singleton  = True
+       knownBlock = True
+       block      = "get_irg_start_block(irg)"
 
 class Store(Op):
        ins      = [ "mem", "ptr", "value" ]
-       outs     = [ "M", "X_regular", "X_except" ]
+       outs  = [
+               ("M",         "memory result",                         "pn_Generic_M"),
+               ("X_regular", "control flow when no exception occurs", "pn_Generic_X_regular"),
+               ("X_except",  "control flow when exception occured",   "pn_Generic_X_except"),
+       ]
        flags    = [ "fragile", "uses_memory" ]
        pinned   = "exception"
        attr_struct = "store_attr"
@@ -686,9 +684,6 @@ class Store(Op):
                        name = "flags",
                ),
        ]
-       d_post = '''
-       firm_alloc_frag_arr(res, op_Store, &res->attr.store.exc.frag_arr);
-       '''
 
 class Sub(Binop):
        flags = []
@@ -701,17 +696,16 @@ class SymConst(Op):
        attrs      = [
                dict(
                        type = "ir_entity*",
-                       name = "entity"
+                       name = "entity",
+                       noprop = True
                )
        ]
        attr_struct = "symconst_attr"
-       java_noconstr = True
 
 class Sync(Op):
        mode     = "mode_M"
        flags    = []
        pinned   = "no"
-       optimize = False
        arity    = "dynamic"
 
 class Tuple(Op):
@@ -719,14 +713,12 @@ class Tuple(Op):
        mode   = "mode_T"
        pinned = "no"
        flags  = [ "labeled" ]
-       java_noconstr = True
 
 class Unknown(Op):
        knownBlock = True
        pinned     = "yes"
        block      = "get_irg_start_block(irg)"
-       flags      = [ "cfopcode", "fragile", "start_block", "constlike",
-                      "dump_noblock" ]
+       flags      = [ "cfopcode", "start_block", "constlike", "dump_noblock" ]
 
 # Prepare node list