Пример #1
0
def xcompound_to_ast_expr(xc: X.XprCompound,
                          astree: AbstractSyntaxTree) -> AST.ASTExpr:
    """Convert a compound expression to an AST Expr node."""

    op = xc.operator
    operands = xc.operands

    if len(operands) == 1:
        op1 = xxpr_to_ast_expr(operands[0], astree)
        return astree.mk_unary_op(op, op1)

    elif len(operands) == 2:
        if xc.is_stack_address:
            stackoffset = xc.stack_address_offset()
            rhslval = astree.mk_stack_variable_lval(stackoffset)
            return astree.mk_address_of(rhslval)
        else:
            op1 = xxpr_to_ast_expr(operands[0], astree)
            op2 = xxpr_to_ast_expr(operands[1], astree)
            if op1.ctype is not None and op in ["plus", "minus"]:
                return xtyped_expr_to_ast_expr(op, op1, op2, astree)
            else:
                return astree.mk_binary_op(op, op1, op2)

    else:
        raise UF.CHBError("AST conversion of compound expression " + str(xc) +
                          " not yet supported")
    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, [], [])