def ast_rvalue(
     self, astree: AbstractSyntaxTree
 ) -> Tuple[AST.ASTExpr, List[AST.ASTInstruction],
            List[AST.ASTInstruction]]:
     (lval, preinstrs, postinstrs) = self.ast_lvalue(astree)
     rval = astree.mk_lval_expr(lval)
     return (rval, preinstrs, postinstrs)
Beispiel #2
0
 def ast(self, astree: AbstractSyntaxTree, iaddr: str, bytestring: str,
         xdata: InstrXData) -> List[AST.ASTInstruction]:
     rhslval = XU.xvariable_to_ast_lval(xdata.vars[1], astree)
     rhs = astree.mk_lval_expr(rhslval)
     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]
Beispiel #3
0
def basevar_variable_to_ast_lval(basevar: "X.XVariable",
                                 offset: "VMemoryOffset",
                                 astree: AbstractSyntaxTree) -> AST.ASTLval:

    if offset.is_constant_value_offset:
        offsetvalue = offset.offsetvalue()
        baselval = xvariable_to_ast_lval(basevar, astree)
        basetype = baselval.ctype
        if basetype is not None:
            if basetype.is_array:
                elttype = cast("BCTypArray", basetype).tgttyp
                eltsize = elttype.byte_size()
                index = offsetvalue // eltsize
                indexoffset = astree.mk_scalar_index_offset(index)
                return astree.mk_lval(baselval.lhost, indexoffset)
            elif basetype.is_pointer:
                tgttype = cast("BCTypPtr", basetype).tgttyp
                basexpr = astree.mk_lval_expr(baselval)
                if tgttype.is_scalar:
                    tgtsize = tgttype.byte_size()
                    index = offsetvalue // tgtsize
                    indexoffset = astree.mk_scalar_index_offset(index)
                    return astree.mk_lval(baselval.lhost, indexoffset)
                elif tgttype.is_struct:
                    compinfo = cast("BCTypComp", tgttype).compinfo
                    fieldoffset = field_at_offset(compinfo, offsetvalue,
                                                  astree)
                    return astree.mk_memref_lval(basexpr, fieldoffset)
                elif tgttype.is_void:
                    index = offsetvalue
                    indexoffset = astree.mk_scalar_index_offset(index)
                    return astree.mk_lval(baselval.lhost, indexoffset)
                elif offsetvalue == 0:
                    return astree.mk_memref_lval(basexpr)
            else:
                print(" -> Basevar with basetype")
        else:
            index = offsetvalue
            indexoffset = astree.mk_scalar_index_offset(index)
            return astree.mk_lval(baselval.lhost, indexoffset)

    print("Basevar_variable: " + str(basevar) + "; offset: " + str(offset))
    return astree.mk_variable_lval(str(basevar) + str(offset))
Beispiel #4
0
def xprvariable_to_ast_expr(xv: X.XprVariable,
                            astree: AbstractSyntaxTree) -> AST.ASTExpr:
    """Convert a variable to an AST Expr node."""

    lval = xvariable_to_ast_lval(xv.variable, astree)
    return astree.mk_lval_expr(lval)