Beispiel #1
0
    def get(names):
        '''[str] -> (gpr|fpr, slot_ty)'''
        if 'void' in names:
            return yield_void()

        ti = ida.parse_decl(' '.join(names))
        (ty, base, slot) = chooser(ti)
        return (ty(base + i), slot)
Beispiel #2
0
    def get(names):
        '''[str] -> (gpr|fpr, slot_ty)'''
        if 'void' in names:
            return yield_void()

        ti = ida.parse_decl(' '.join(names))
        (ty, base, slot) = chooser(ti)
        return (ty(base + i), slot)
Beispiel #3
0
def type_to_reg_and_slot(node, chooser, i):
    '''c_ast -> fn -> int -> (reg_type, slot_type) | None'''

    def yield_void():
        # return an empty list for (void) arglists
        raise StopIteration

    def maybe_fail(node):
        if type(node) is c_ast.Struct:
            raise StructByValueError('structs by value not yet supported')
        return type_to_reg_and_slot(node.type, chooser, i)

    def get(names):
        '''[str] -> (gpr|fpr, slot_ty)'''
        if 'void' in names:
            return yield_void()

        ti = ida.parse_decl(' '.join(names))
        (ty, base, slot) = chooser(ti)
        return (ty(base + i), slot)

    sw = {
        c_ast.Decl: lambda x: type_to_reg_and_slot(x.type, chooser, i),
        c_ast.TypeDecl: lambda x: type_to_reg_and_slot(x.type, chooser, i),
        c_ast.Typename: lambda x: type_to_reg_and_slot(x.type, chooser, i),
        c_ast.IdentifierType: lambda x: get(x.names)
    }

    if i > 7:
        raise RegSpillError('spilling registers to stack not yet supported')

    # in order to use chooser we need a tinfo_t--make one suitable for an
    # an int (which is also suitable for a pointer on N32)
    dummy_ti = ida.parse_decl('int')

    (_, base, _) = chooser(dummy_ti)
    node_ty = type(node)

    if node_ty in [c_ast.ArrayDecl, c_ast.PtrDecl]:
        return (regs.gpr(base + i), ep_ct.slot_types.u64)
    elif node_ty is c_ast.Enum:
        return (regs.gpr(base + i), ep_ct.slot_types.i64)
    else:
        return utils.dictswitch(node_ty, sw, node, maybe_fail, node)
Beispiel #4
0
def type_to_reg_and_slot(node, chooser, i):
    '''c_ast -> fn -> int -> (reg_type, slot_type) | None'''
    def yield_void():
        # return an empty list for (void) arglists
        raise StopIteration

    def maybe_fail(node):
        if type(node) is c_ast.Struct:
            raise StructByValueError('structs by value not yet supported')
        return type_to_reg_and_slot(node.type, chooser, i)

    def get(names):
        '''[str] -> (gpr|fpr, slot_ty)'''
        if 'void' in names:
            return yield_void()

        ti = ida.parse_decl(' '.join(names))
        (ty, base, slot) = chooser(ti)
        return (ty(base + i), slot)

    sw = {
        c_ast.Decl : lambda x: type_to_reg_and_slot(x.type, chooser, i),
        c_ast.TypeDecl : lambda x: type_to_reg_and_slot(x.type, chooser, i),
        c_ast.Typename : lambda x: type_to_reg_and_slot(x.type, chooser, i),
        c_ast.IdentifierType : lambda x: get(x.names)
    }

    if i > 7:
        raise RegSpillError('spilling registers to stack not yet supported')

    # in order to use chooser we need a tinfo_t--make one suitable for an
    # an int (which is also suitable for a pointer on N32)
    dummy_ti = ida.parse_decl('int')

    (_, base, _) = chooser(dummy_ti)
    node_ty = type(node)

    if node_ty in [c_ast.ArrayDecl, c_ast.PtrDecl]:
        return (regs.gpr(base + i), ep_ct.slot_types.u64)
    elif node_ty is c_ast.Enum:
        return (regs.gpr(base + i), ep_ct.slot_types.i64)
    else:
        return utils.dictswitch(node_ty, sw, node, maybe_fail, node)