示例#1
0
class Store(Node):
	"""Stores a value into memory (heap or stack)."""
	ins   = [
	   ("mem",   "memory dependency"),
	   ("ptr",   "address to store to"),
	   ("value", "value to store"),
	]
	outs  = [
		("M",         "memory result"),
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
	]
	flags    = [ "fragile", "uses_memory" ]
	pinned   = "exception"
	attr_struct = "store_attr"
	pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
	throws_init = "(flags & cons_throws_exception) != 0"
	attrs = [
                Attribute("type", type="ir_type*",
                          comment="The type of the object which is stored at ptr (need not match with value's type)"),
		Attribute("volatility", type="ir_volatility",
		          init="flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
		          to_flags="%s == volatility_is_volatile ? cons_volatile : cons_none",
		          comment="volatile stores are a visible side-effect and may not be optimized"),
		Attribute("unaligned", type="ir_align",
		          init="flags & cons_unaligned ? align_non_aligned : align_is_aligned",
		          to_flags="%s == align_non_aligned ? cons_unaligned : cons_none",
		          comment="pointers to unaligned stores don't need to respect the load-mode/type alignments"),
	]
	constructor_args = [
		Attribute("flags", type="ir_cons_flags",
		          comment="specifies alignment, volatility and pin state"),
	]
示例#2
0
class Div(Node):
	"""returns the quotient of its 2 operands"""
	ins   = [
		("mem",   "memory dependency"),
		("left",  "first operand"),
		("right", "second operand"),
	]
	outs  = [
		("M",         "memory result"),
		("res",       "result of computation"),
		("X_regular", "control flow when no exception occurs"),
		("X_except",  "control flow when exception occured"),
	]
	flags = [ "fragile", "uses_memory", "const_memory" ]
	attrs = [
		Attribute("resmode", type="ir_mode*",
		          init="get_irn_mode(irn_left)",
		          comment="mode of the result value"),
		Attribute("no_remainder", type="int", init="0"),
	]
	attr_struct = "div_attr"
	pinned      = "exception"
	throws_init = "false"
	op_index    = 1
	arity_override = "oparity_binary"
示例#3
0
class CopyB(Node):
    """Copies a block of memory with statically known size/type."""
    ins = [
        ("mem", "memory dependency"),
        ("dst", "destination address"),
        ("src", "source address"),
    ]
    mode = "mode_M"
    flags = ["uses_memory"]
    attrs = [
        Attribute("type", type="ir_type*", comment="type of copied data"),
        Attribute(
            "volatility",
            type="ir_volatility",
            init=
            "flags & cons_volatile ? volatility_is_volatile : volatility_non_volatile",
            to_flags="%s == volatility_is_volatile ? cons_volatile : cons_none",
            comment=
            "volatile CopyB nodes have a visible side-effect and may not be optimized"
        ),
    ]
    attr_struct = "copyb_attr"
    constructor_args = [
        Attribute("flags",
                  type="ir_cons_flags",
                  comment="specifies volatility"),
    ]
示例#4
0
class Switch(Node):
    """Change control flow. The destination is choosen based on an integer input value which is looked up in a table.

	Backends can implement this efficiently using a jump table."""
    ins = [
        ("selector", "input selector"),
    ]
    outs = [
        ("default", "control flow if no other case matches"),
    ]
    mode = "mode_T"
    flags = ["cfopcode", "forking"]
    pinned = "yes"
    attrs = [
        Attribute("n_outs",
                  type="unsigned",
                  comment="number of outputs (including pn_Switch_default)"),
        Attribute(
            "table",
            type="ir_switch_table*",
            comment="table describing mapping from input values to Proj numbers"
        ),
    ]
    attr_struct = "switch_attr"
    attrs_name = "switcha"
示例#5
0
class ASM(Node):
    """executes assembler fragments of the target machine.

    The node contains a template for an assembler snippet. The compiler will
    replace occurences of %0 to %9 with input/output registers,
    %% with a single % char. Some backends allow additional specifiers (for
    example %w3, %l3, %h3 on x86 to get a 16bit, 8hit low, 8bit high part
    of a register).
    After the replacements the text is emitted into the final assembly.

    The clobber list contains names of registers which have an undefined value
    after the assembler instruction is executed; it may also contain 'memory'
    or 'cc' if global state/memory changes or the condition code registers
    (some backends implicitely set cc, memory clobbers on all ASM statements).

    Example (an i386 instruction)::

        ASM(text="btsl %1, %0",
            constraints = ["=m", "r"],
            clobbers = ["cc"])

    As there are no output, the %0 references the first input which is just an
    address which the asm operation writes to. %1 references to an input which
    is passed as a register. The condition code register has an unknown value
    after the instruction.

    (This format is inspired by the gcc extended asm syntax)
    """
    mode = "mode_T"
    arity = "variable"
    input_name = "input"
    flags = ["keep", "uses_memory"]
    pinned = "exception"
    pinned_init = "op_pin_state_pinned"
    attr_struct = "asm_attr"
    attrs_name = "assem"
    ins = [
        ("mem", "memory dependency"),
    ]
    attrs = [
        Attribute("n_constraints",
                  type="size_t",
                  noprop=True,
                  comment="number of constraints"),
        Attribute("constraints",
                  type="ir_asm_constraint*",
                  comment="constraints"),
        Attribute("n_clobbers",
                  type="size_t",
                  noprop=True,
                  comment="number of clobbered registers/memory"),
        Attribute("clobbers",
                  type="ident**",
                  comment="list of clobbered registers/memory"),
        Attribute("text", type="ident*", comment="assembler text"),
    ]
    # constructor is written manually at the moment, because of the clobbers+
    # constraints arrays needing special handling (2 arguments for 1 attribute)
    constructor = False
示例#6
0
def preprocess_node(node):
    parent = node.__base__
    if parent == object:
        parent = Node
    node.parent = parent
    node.classname = CamelCase(node.name)

    # construct node arguments
    if not is_abstract(node):
        arguments = []
        for input in node.ins:
            arguments.append(
                Attribute(name=input.name, type="Node", comment=input.comment))
        if node.arity == "variable" or node.arity == "dynamic":
            arguments.append(Attribute("ins", type="Node[]"))
        if node.mode is None:
            arguments.append(Attribute("mode", type="firm.Mode"))
        for attr in node.attrs:
            prepare_attr(attr)
            if attr.init is not None:
                continue

            arguments.append(
                JavaArgument(name=attr.java_name,
                             type=attr.java_type,
                             to_wrapper=attr.to_wrapper,
                             comment=attr.comment))
        if is_dynamic_pinned(node):
            if node.pinned_init is None:
                (java_type, wrap_type, to_wrapper,
                 from_wrapper) = get_java_type("op_pin_state")
                arguments.append(
                    JavaArgument(name="pin_state",
                                 type=java_type,
                                 to_wrapper=to_wrapper))
        for arg in node.constructor_args:
            old_type = arg.type
            (java_type, wrap_type, to_wrapper,
             from_wrapper) = get_java_type(old_type)

            arguments.append(
                JavaArgument(name=arg.name,
                             type=java_type,
                             to_wrapper=to_wrapper,
                             comment=arg.comment))

        for arg in arguments:
            arg.name = filterkeywords(arg.name)

        node.arguments = arguments
示例#7
0
class Call(Node):
    """Calls other code. Control flow is transferred to ptr, additional
    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 = [
        ("mem", "memory dependency"),
        ("ptr", "pointer to called code"),
    ]
    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 occurred"),
    ]
    flags = ["fragile", "uses_memory"]
    attrs = [
        Attribute("type", type="ir_type*",
                  comment="type of the call (usually type of the called procedure)"),
    ]
    attr_struct = "call_attr"
    pinned = "exception"
    pinned_init = "op_pin_state_pinned"
    throws_init = "false"
    init = '''
示例#8
0
class Mod(Node):
    """returns the remainder of its operands from an implied division.

    Examples:

    * mod(5,3)   produces 2
    * mod(5,-3)  produces 2
    * mod(-5,3)  produces -2
    * mod(-5,-3) produces -2
    """
    ins = [
        ("mem", "memory dependency"),
        ("left", "first operand"),
        ("right", "second operand"),
    ]
    outs = [
        ("M", "memory result"),
        ("res", "result of computation"),
        ("X_regular", "control flow when no exception occurs"),
        ("X_except", "control flow when exception occurred"),
    ]
    flags = ["fragile", "uses_memory", "const_memory"]
    attrs = [
        Attribute("resmode", type="ir_mode*",
                  init="get_irn_mode(irn_left)",
                  comment="mode of the result"),
    ]
    attr_struct = "mod_attr"
    pinned = "exception"
    throws_init = "false"
    op_index = 1
    arity_override = "oparity_binary"
示例#9
0
class EntConst(Node):
    """Symbolic constant that represents an aspect of an entity"""
    name = "entconst"
    flags = ["constlike", "start_block"]
    attrs = [
        Attribute("entity", type="ir_entity*", comment="entity to operate on"),
    ]
    attr_struct = "entconst_attr"
    attrs_name = "entc"
示例#10
0
class TypeConst(Node):
    """A symbolic constant that represents an aspect of a type"""
    name = "typeconst"
    flags = ["constlike", "start_block"]
    attrs = [
        Attribute("type", type="ir_type*", comment="type to operate on"),
    ]
    attr_struct = "typeconst_attr"
    attrs_name = "typec"
示例#11
0
class Cmp(Binop):
    """Compares its two operands and checks whether a specified
       relation (like less or equal) is fulfilled."""
    flags = []
    mode = "mode_b"
    attrs = [
        Attribute("relation", type="ir_relation",
                  comment="Comparison relation"),
    ]
    attr_struct = "cmp_attr"
示例#12
0
class Const(Node):
    """Returns a constant value."""
    flags = ["constlike", "start_block"]
    mode = "get_tarval_mode(tarval)"
    attrs = [
        Attribute("tarval", type="ir_tarval*",
                  comment="constant value (a tarval object)"),
    ]
    attr_struct = "const_attr"
    attrs_name = "con"
示例#13
0
class Builtin(Node):
    """performs a backend-specific builtin."""
    ins = [
        ("mem", "memory dependency"),
    ]
    arity = "variable"
    input_name = "param"
    outs = [
        ("M", "memory result"),
        # results follow here
    ]
    mode = "mode_T"
    flags = ["uses_memory"]
    attrs = [
        Attribute("kind", type="ir_builtin_kind", comment="kind of builtin"),
        Attribute("type", type="ir_type*",
                  comment="method type for the builtin call"),
    ]
    pinned = "exception"
    pinned_init = "op_pin_state_pinned"
    attr_struct = "builtin_attr"
    init = '''
示例#14
0
class Proj(Node):
    """returns an entry of a tuple value"""
    ins = [
        ("pred", "the tuple value from which a part is extracted"),
    ]
    flags = []
    block = "get_nodes_block(irn_pred)"
    usesGraph = False
    attrs = [
        Attribute("num", type="unsigned",
                  comment="number of tuple component to be extracted"),
    ]
    attr_struct = "proj_attr"
示例#15
0
class Member(Node):
    """Computes the address of a compound type member given the base address
    of an instance of the compound type.

    A Member node must only produce a NULL pointer if the ptr input is NULL."""
    ins = [
        ("ptr", "pointer to object to select from"),
    ]
    flags = []
    mode = "mode_P"
    attrs = [
        Attribute("entity", type="ir_entity*",
                  comment="entity which is selected"),
    ]
    attr_struct = "member_attr"
示例#16
0
class Sel(Node):
    """Computes the address of an array element from the array base pointer and
    an index.

    A Sel node must only produce a NULL pointer if the ptr input is NULL."""
    ins = [
        ("ptr", "pointer to array to select from"),
        ("index", "index to select"),
    ]
    flags = []
    mode = "mode_P"
    attrs = [
        Attribute("type", type="ir_type*", comment="array type"),
    ]
    attr_struct = "sel_attr"
示例#17
0
class Block(Node):
    """A basic block"""
    mode = "mode_BB"
    block = "NULL"
    pinned = "yes"
    arity = "variable"
    input_name = "cfgpred"
    flags = []
    attr_struct = "block_attr"
    attrs = [
        Attribute("entity", type="ir_entity*", init="NULL",
                  comment="entity representing this block"),
    ]
    serializer = False

    init = '''
示例#18
0
class Phi(Node):
    """Choose a value based on control flow. A phi node has 1 input for each
    predecessor of its block. If a block is entered from its nth predecessor
    all phi nodes produce their nth input as result."""
    pinned = "yes"
    arity = "variable"
    input_name = "pred"
    flags = []
    attrs = [
        Attribute("loop", type="int", init="0",
                  comment="whether Phi represents the observable effect of a (possibly) nonterminating loop"),
    ]
    attr_struct = "phi_attr"
    init = '''
    res->attr.phi.u.backedge = new_backedge_arr(get_irg_obstack(irg), arity);'''
    serializer = False
示例#19
0
class Alloc(Node):
    """Allocates a block of memory on the stack."""
    ins = [
        ("mem", "memory dependency"),
        ("size", "size of the block in bytes"),
    ]
    outs = [
        ("M", "memory result"),
        ("res", "pointer to newly allocated memory"),
    ]
    attrs = [
        Attribute("alignment", type="unsigned",
                  comment="alignment of the memory block (must be a power of 2)"),
    ]
    flags = ["uses_memory", "const_memory"]
    pinned = "yes"
    attr_struct = "alloc_attr"
示例#20
0
class InstanceOf(Node):
    """Check if an object is an instance of a specified type (or a subtype).
	Passing a null pointer results in undefined behaviour."""
    ins = [
        ("mem", "memory dependency"),
        ("ptr", "pointer to object"),
    ]
    outs = [
        ("M", "memory result"),
        ("res", "result of instanceof check"),  # mode_b
    ]
    attrs = [
        Attribute("type", type="ir_type*", comment="classtype to check for"),
    ]
    flags = ["uses_memory"]
    pinned = "no"
    attr_struct = "op_InstanceOf_attr_t"
示例#21
0
class Cond(Node):
    """Conditionally change control flow."""
    ins = [
        ("selector", "condition parameter"),
    ]
    outs = [
        ("false", "control flow if operand is \"false\""),
        ("true", "control flow if operand is \"true\""),
    ]
    flags = ["cfopcode", "forking"]
    pinned = "yes"
    attrs = [
        Attribute("jmp_pred", type="cond_jmp_predicate",
                  init="COND_JMP_PRED_NONE",
                  comment="can indicate the most likely jump"),
    ]
    attr_struct = "cond_attr"
示例#22
0
class MethodSel(Node):
    """Performs a vtable lookup for a method (or rtti info)."""
    ins = [
        ("mem", "memory dependency"),
        ("ptr", "pointer to an object with a vtable"),
    ]
    outs = [
        ("M", "memory result"),
        ("res", "address of method"),
    ]
    attrs = [
        Attribute("entity",
                  type="ir_entity*",
                  comment="method entity which should be selected"),
    ]
    attr_struct = "op_MethodSel_attr_t"
    flags = ["uses_memory"]
    pinned = "no"
示例#23
0
class Confirm(Node):
    """Specifies constraints for a value. This allows explicit representation
    of path-sensitive properties. (Example: This value is always >= 0 on 1
    if-branch then all users within that branch are rerouted to a confirm-node
    specifying this property).

    A constraint is specified for the relation between value and bound.
    value is always returned.
    Note that this node does NOT check or assert the constraint, it merely
    specifies it."""
    ins = [
        ("value", "value to express a constraint for"),
        ("bound", "value to compare against"),
    ]
    mode = "get_irn_mode(irn_value)"
    flags = []
    pinned = "yes"
    attrs = [
        Attribute("relation", type="ir_relation",
                  comment="relation of value to bound"),
    ]
    attr_struct = "confirm_attr"
示例#24
0
class VptrIsSet(Node):
    """Mark that an objects vptr has been set. This node duplicates its pointer
	input and guarantees that all users of this node have an object of the
	specified type.

	In practice you would put such a node behind allocation calls in a java-like
	language or behind an external constructor call in a C++-like language.

	You could think of this as a special case of Confirm node, ensuring a
	certain object type."""
    ins = [
        ("mem", "memory dependency"),
        ("ptr", "pointer to an object"),
    ]
    outs = [
        ("M", "memory result"),
        ("res", "pointer to object"),
    ]
    attrs = [
        Attribute("type", type="ir_type*", comment="type of the object"),
    ]
    attr_struct = "op_VptrIsSet_attr_t"
    flags = ["uses_memory"]
    pinned = "no"
示例#25
0
class ASM(Node):
    """executes assembler fragments of the target machine.

    The node contains a template for an assembler snippet. The compiler will
    replace occurrences of %0, %1, ... with input/output operands, %% with a
    single % char. Some backends allow additional specifiers (for example %w3,
    %b3, %h3 on x86 to get a 16bit, 8hit low, 8bit high part of a register).
    After the replacements the text is emitted into the final assembly.

    The clobber list contains names of registers which have an undefined value
    after the assembler instruction is executed; it may also contain 'memory'
    or 'cc' if global state/memory changes or the condition code registers
    (some backends implicitly set cc on all ASM statements).

    Example (an i386 instruction):

        ASM(text="btsl %1, %0",
            constraints = ["+m", "r"],
            clobbers = ["cc"])

    %0 references a memory reference which the operation both reads and writes.
    For this the node has an address input operand.  %1 references an input
    which is passed as a register. The condition code register has an unknown
    value after the instruction.

    (This format is inspired by the gcc extended asm syntax)
    """
    mode = "mode_T"
    arity = "variable"
    input_name = "input"
    flags = ["fragile", "keep", "uses_memory"]
    only_regular = True
    pinned = "exception"
    pinned_init = "flags & cons_floats ? op_pin_state_floats : op_pin_state_pinned"
    throws_init = "(flags & cons_throws_exception) != 0"
    attr_struct = "asm_attr"
    attrs_name = "assem"
    ins = [
        ("mem", "memory dependency"),
    ]
    outs = [
        ("M", "memory result"),
        ("X_regular", "control flow when no jump occurs"),
        ("first_out", "first output"),
    ]
    attrs = [
        Attribute("constraints", type="ir_asm_constraint*", init="NULL",
                  comment="constraints"),
        Attribute("clobbers", type="ident**", init="NULL",
                  comment="list of clobbered registers/memory"),
        Attribute("text", type="ident*", comment="assembler text"),
    ]
    constructor_args = [
        Attribute("n_constraints", type="size_t",
                  comment="number of constraints"),
        Attribute("constraints", type="ir_asm_constraint*",
                  comment="constraints"),
        Attribute("n_clobbers", type="size_t",
                  comment="number of clobbered registers/memory"),
        Attribute("clobbers", type="ident**",
                  comment="list of clobbered registers/memory"),
        Attribute("flags", type="ir_cons_flags",
                  comment="specifies alignment, volatility and pin state"),
    ]
    init = '''
    struct obstack *const obst = get_irg_obstack(irg);
    attr->constraints = NEW_ARR_D(ir_asm_constraint, obst, n_constraints);
    attr->clobbers    = NEW_ARR_D(ident*,            obst, n_clobbers);

    MEMCPY(attr->constraints, constraints, n_constraints);
    MEMCPY(attr->clobbers,    clobbers,    n_clobbers);
    '''
    serializer = False