Beispiel #1
0
    def assembly_ast(self, astree: AbstractSyntaxTree, iaddr: str,
                     bytestring: str,
                     xdata: InstrXData) -> List[AST.ASTInstruction]:
        regsop = self.operands[1]
        if not regsop.is_register_list:
            raise UF.CHBError("Argument to push is not a register list")

        (splval, _, _) = self.operands[0].ast_lvalue(astree)
        (sprval, _, _) = self.operands[0].ast_rvalue(astree)

        instrs: List[AST.ASTInstruction] = []
        registers = regsop.registers
        sp_decr = 4 * len(registers)
        sp_offset = sp_decr
        for r in registers:
            sp_offset_c = astree.mk_integer_constant(sp_offset)
            addr = astree.mk_binary_op("minus", sprval, sp_offset_c)
            lhs = astree.mk_memref_lval(addr)
            rhs = astree.mk_register_variable_expr(r)
            instrs.append(astree.mk_assign(lhs, rhs))
            sp_offset -= 4
        sp_decr_c = astree.mk_integer_constant(sp_decr)
        sp_rhs = astree.mk_binary_op("minus", sprval, sp_decr_c)
        instrs.append(astree.mk_assign(splval, sp_rhs))
        astree.add_instruction_span(instrs[0].id, iaddr, bytestring)
        return instrs
    def ast(self,
            astree: AbstractSyntaxTree,
            iaddr: str,
            bytestring: str,
            xdata: InstrXData) -> List[ASTInstruction]:
        lhs = xdata.vars[0]
        rhs1 = str(xdata.xprs[0])
        rhs2 = xdata.xprs[1]
        rhs3 = xdata.xprs[3]

        if lhs == "SP" and rhs1 == "SP" and rhs2.is_constant:
            return []

        lhsast = XU.xvariable_to_ast_lval(lhs, astree)
        if rhs1 == "SP" and rhs3.is_stack_address:
            rhs3 = cast("XprCompound", rhs3)
            stackoffset = rhs3.stack_address_offset()
            rhslval = astree.mk_stack_variable_lval(stackoffset)
            rhsast: ASTExpr = astree.mk_address_of(rhslval)

        elif rhs1 == "PC" or str(rhs2) == "PC":
            if rhs3.is_int_constant:
                rhsval = cast("XprConstant", rhs3).intvalue
                rhsast = astree.mk_integer_constant(rhsval)
            else:
                rhsast = XU.xxpr_to_ast_expr(rhs3, astree)

        else:
            rhsast = XU.xxpr_to_ast_expr(rhs3, astree)

        result = astree.mk_assign(lhsast, rhsast)
        astree.add_instruction_span(result.id, iaddr, bytestring)
        return [result]
Beispiel #3
0
def xconstant_to_ast_expr(xc: X.XprConstant,
                          astree: AbstractSyntaxTree) -> AST.ASTExpr:
    """Convert a constant value to an AST Expr node."""

    if xc.is_int_constant:
        return astree.mk_integer_constant(xc.intvalue)

    else:
        raise UF.CHBError("AST conversion of xconstant " + str(xc) +
                          " not yet supported")
 def ast_rvalue(self, astree: AbstractSyntaxTree) -> AST.ASTExpr:
     return astree.mk_integer_constant(self.immediate)
 def ast_rvalue(
     self, astree: AbstractSyntaxTree
 ) -> Tuple[AST.ASTExpr, List[AST.ASTInstruction],
            List[AST.ASTInstruction]]:
     return (astree.mk_integer_constant(self.value), [], [])