Exemple #1
0
def _proc(val):
    if isinstance(val, list):
        # Lists of instructions we leave alone:
        return InstructionList(val)
    elif isinstance(val, jvm.Method) and not val.is_static():
        # For virtual methods, we first push an instance of the relevant
        # class, then the arguments, and then invoke the method.  Note
        # that we only allow virtual methods of certain pre-designated
        # classes to be in the table.
        if val.class_name == jvm.jPyPy.name:
            return InstructionList((PushPyPy, PushAllArgs, val, StoreResult))
        else:
            raise Exception("Unknown class for non-static method")
    # For anything else (static methods, strings, etc) we first push
    # all arguments, then invoke the emit() routine, and finally
    # store the result.
    return InstructionList((PushAllArgs, val, StoreResult))
Exemple #2
0
def render_sub_op(sub_op, db, generator):
    op = sub_op.op
    instr_list = db.genoo.opcodes.get(op.opname, None)
    assert instr_list is not None, 'Unknown opcode: %s ' % op
    assert isinstance(instr_list, InstructionList)
    assert instr_list[
        -1] is StoreResult, "Cannot inline an operation that doesn't store the result"

    # record that we know about the type of result and args
    db.cts.lltype_to_cts(op.result.concretetype)
    for v in op.args:
        db.cts.lltype_to_cts(v.concretetype)

    instr_list = InstructionList(
        instr_list[:-1])  # leave the value on the stack if this is a sub-op
    instr_list.render(generator, op)
Exemple #3
0
 def __init__(self, instr, mapping):
     if isinstance(instr, str):
         self.instr = InstructionList([PushAllArgs, instr, StoreResult])
     else:
         self.instr = InstructionList(instr)
     self.mapping = mapping
Exemple #4
0
    'ullong_gt':
    'cgt.un',
    'ullong_ge':
    _not('clt.un'),
    'ullong_lshift': [PushAllArgs, 'conv.u4', 'shl'],
    'ullong_rshift': [PushAllArgs, 'conv.i4', 'shr'],
    'ullong_and':
    'and',
    'ullong_or':
    'or',
    'oois':
    'ceq',
    'ooisnot':
    _not('ceq'),
}

opcodes = misc_ops.copy()
opcodes.update(unary_ops)
opcodes.update(binary_ops)

for key, value in opcodes.iteritems():
    if type(value) is str:
        value = InstructionList([PushAllArgs, value, StoreResult])
    elif value is not None:
        if value is not Ignore and StoreResult not in value and not isinstance(
                value[0], MapException):
            value.append(StoreResult)
        value = InstructionList(value)

    opcodes[key] = value