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[AST.ASTInstruction]: rhs = XU.xxpr_to_ast_expr(xdata.xprs[1], astree) lhs = XU.xvariable_to_ast_lval(xdata.vars[0], astree) assign = astree.mk_assign(lhs, rhs) astree.add_instruction_span(assign.id, iaddr, bytestring) return [assign]
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]
def assembly_ast(self, astree: AbstractSyntaxTree, iaddr: str, bytestring: str, xdata: InstrXData) -> List[AST.ASTInstruction]: (rhs, preinstrs, postinstrs) = self.operands[1].ast_rvalue(astree) (lhs, _, _) = self.operands[0].ast_lvalue(astree) assign = astree.mk_assign(lhs, rhs) astree.add_instruction_span(assign.id, iaddr, bytestring) return preinstrs + [assign] + postinstrs
def ast(self, astree: AbstractSyntaxTree, iaddr: str, bytestring: str, xdata: InstrXData) -> List[AST.ASTInstruction]: (rhs, _, _) = self.operands[0].ast_rvalue(astree) lhs = xdata.vars[0] lval = XU.xvariable_to_ast_lval(lhs, astree) assign = astree.mk_assign(lval, rhs) astree.add_instruction_span(assign.id, iaddr, bytestring) return [assign]
def assembly_ast(self, astree: AbstractSyntaxTree, iaddr: str, bytestring: str, xdata: InstrXData) -> List[AST.ASTInstruction]: (rhs1, preinstrs1, postinstrs1) = self.operands[1].ast_rvalue(astree) (rhs2, preinstrs2, postinstrs2) = self.operands[2].ast_rvalue(astree) (lhs, _, _) = self.operands[0].ast_lvalue(astree) binop = astree.mk_binary_op("band", rhs1, rhs2) assign = astree.mk_assign(lhs, binop) astree.add_instruction_span(assign.id, iaddr, bytestring) return preinstrs1 + preinstrs2 + [assign] + postinstrs1 + postinstrs2
def assembly_ast(self, astree: AbstractSyntaxTree, iaddr: str, bytestring: str, xdata: InstrXData) -> List[ASTInstruction]: (lhs, _, _) = self.operands[0].ast_lvalue(astree) (op1, _, _) = self.operands[1].ast_rvalue(astree) (op2, _, _) = self.operands[2].ast_rvalue(astree) binop = astree.mk_binary_op("minus", op1, op2) result = astree.mk_assign(lhs, binop) astree.add_instruction_span(result.id, iaddr, bytestring) return [result]
def assembly_ast(self, astree: AbstractSyntaxTree, iaddr: str, bytestring: str, xdata: InstrXData) -> List[AST.ASTInstruction]: if len(xdata.vars) == 1 and len(xdata.xprs) == 1: lhs = astree.mk_variable_lval(str(xdata.vars[0])) rhs = XU.xxpr_to_ast_expr(xdata.xprs[0], astree) assign = astree.mk_assign(lhs, rhs) astree.add_instruction_span(assign.id, iaddr, bytestring) return [assign] else: return []
def assembly_ast(self, astree: AbstractSyntaxTree, iaddr: str, bytestring: str, xdata: InstrXData) -> List[AST.ASTInstruction]: (lhs1, preinstrs1, postinstrs1) = self.operands[4].ast_lvalue(astree) (lhs2, preinstrs2, postinstrs2) = self.operands[5].ast_lvalue(astree) (rhs1, _, _) = self.operands[0].ast_rvalue(astree) (rhs2, _, _) = self.operands[1].ast_rvalue(astree) assign1 = astree.mk_assign(lhs1, rhs1) assign2 = astree.mk_assign(lhs2, rhs2) astree.add_instruction_span(assign1.id, iaddr, bytestring) return (preinstrs1 + preinstrs2 + [assign1, assign2] + postinstrs1 + postinstrs2)
def assembly_ast( self, astree: AbstractSyntaxTree, iaddr: str, bytestring: str, xdata: InstrXData) -> List[AST.ASTInstruction]: if xdata.instruction_is_subsumed(): return [] else: (lhs, _, _) = self.operands[0].ast_lvalue(astree) (rhs, _, _) = self.operands[1].ast_rvalue(astree) assign = astree.mk_assign(lhs, rhs) astree.add_instruction_span(assign.id, iaddr, bytestring) return [assign]
def ast(self, astree: AbstractSyntaxTree, iaddr: str, bytestring: str, xdata: InstrXData) -> List[AST.ASTInstruction]: (rhs1, _, _) = self.operands[0].ast_rvalue(astree) (rhs2, _, _) = self.operands[1].ast_rvalue(astree) lhs1 = str(xdata.vars[0]) lhs2 = str(xdata.vars[1]) if lhs1.endswith("[0]"): lhs1 = "*" + lhs1[:-3] lval1 = astree.mk_variable_lval(lhs1) lval2 = astree.mk_variable_lval(lhs2) assign1 = astree.mk_assign(lval1, rhs1) assign2 = astree.mk_assign(lval2, rhs2) astree.add_instruction_span(assign1.id, iaddr, bytestring) astree.add_instruction_span(assign2.id, iaddr, bytestring) return [assign1, assign2]
def ast( self, astree: AbstractSyntaxTree, iaddr: str, bytestring: str, xdata: InstrXData) -> List[AST.ASTInstruction]: if xdata.instruction_is_subsumed(): return [] else: lhs = XU.xvariable_to_ast_lval(xdata.vars[0], astree) rhs = XU.xxpr_to_ast_expr(xdata.xprs[0], astree) # (lhs, _, _) = self.operands[0].ast_lvalue(astree) # (rhs, _, _) = self.operands[1].ast_rvalue(astree) assign = astree.mk_assign(lhs, rhs) astree.add_instruction_span(assign.id, iaddr, bytestring) return [assign]
def ast_lvalue( self, astree: AbstractSyntaxTree ) -> Tuple[AST.ASTLval, List[AST.ASTInstruction], List[AST.ASTInstruction]]: offset = self.memory_offset.ast_rvalue(astree) if not self.is_add: offset = astree.mk_unary_op("minus", offset) xreg = astree.mk_register_variable_expr(self.register) xindex = astree.mk_binary_op("plus", xreg, offset) if self.is_write_back: reglv = astree.mk_variable_lval(self.register) assign = astree.mk_assign(reglv, xindex) if self.is_index: memexp = astree.mk_memref_lval(xindex) return (memexp, [], [assign]) else: memexp = astree.mk_memref_lval(xreg) return (memexp, [], [assign]) else: memexp = astree.mk_memref_lval(xindex) return (memexp, [], [])