Ejemplo n.º 1
0
def xvariable_to_ast_lval(xv: X.XVariable,
                          astree: AbstractSyntaxTree) -> AST.ASTLval:
    """Convert a CHIF variable to an AST Lval node."""

    if xv.is_tmp:
        return astree.mk_temp_lval()

    elif xv.is_register_variable:
        xvden = cast("VRegisterVariable", xv.denotation)
        reg = xvden.register
        if reg.is_mips_register:
            mipsreg = cast("MIPSRegister", reg)
            name = "mips_" + mipsreg.name
        else:
            name = str(xv)
        return astree.mk_register_variable_lval(name)

    elif xv.is_memory_variable:
        xvmem = cast("VMemoryVariable", xv.denotation)
        return vmemory_variable_to_ast_lval(xvmem, astree)

    elif xv.is_auxiliary_variable:
        xvaux = cast("VAuxiliaryVariable", xv.denotation)
        return vauxiliary_variable_to_ast_lval(xvaux, astree)

    else:
        print("other: " + str(xv))
        return astree.mk_variable_lval(str(xv))
Ejemplo n.º 2
0
 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 = astree.mk_register_variable_lval(str(xdata.vars[0]))
     assign = astree.mk_assign(lhs, rhs)
     astree.add_instruction_span(assign.id, iaddr, bytestring)
     return [assign]
Ejemplo n.º 3
0
def vinitregister_value_to_ast_lval(vconstvar: "VInitialRegisterValue",
                                    astree: AbstractSyntaxTree) -> AST.ASTLval:

    if vconstvar.is_argument_value:
        argindex = vconstvar.argument_index()
        funarg = astree.function_argument(argindex)
        if funarg:
            return astree.mk_register_variable_lval(funarg.name,
                                                    vtype=funarg.typ,
                                                    parameter=argindex)
        else:
            return astree.mk_register_variable_lval(str(vconstvar.register))

    elif vconstvar.register.is_stack_pointer:
        return astree.mk_register_variable_lval("base_sp")
    else:
        print("Initial Register Value: " + str(vconstvar.register))
        return astree.mk_register_variable_lval(str(vconstvar.register))
Ejemplo n.º 4
0
 def assembly_ast(self, astree: AbstractSyntaxTree, iaddr: str,
                  bytestring: str,
                  xdata: InstrXData) -> List[ASTInstruction]:
     lhs = astree.mk_register_variable_lval("R0")
     tgt = self.operands[0]
     if tgt.is_absolute:
         tgtaddr = cast(ARMAbsoluteOp, tgt.opkind)
         if self.app.has_function_name(tgtaddr.address.get_hex()):
             faddr = tgtaddr.address.get_hex()
             fnsymbol = self.app.function_name(faddr)
             tgtxpr: ASTExpr = astree.mk_global_variable_expr(
                 fnsymbol, globaladdress=int(str(tgtaddr.address), 16))
         else:
             (tgtxpr, _, _) = self.operands[0].ast_rvalue(astree)
     else:
         (tgtxpr, _, _) = self.operands[0].ast_rvalue(astree)
     call = astree.mk_call(lhs, tgtxpr, [])
     astree.add_instruction_span(call.id, iaddr, bytestring)
     return [call]