Пример #1
0
def simple_unwrap_expr(expr: Expr, loc_db: LocationDB):
    ra = -1
    if expr.is_int():
        ra = int(expr)
    elif expr.is_loc():
        ra = loc_db.get_location_offset(expr.loc_key)
        if ra is None:
            ra = -1

    return ra
Пример #2
0
    def _skip_subtree(expr: Expr) -> bool:
        """
        Skips the subtree if an expression is a terminal expression.

        A terminal expression is a leaf in the abstract syntax tree,
        such as an ExprInt (register/variable), ExprMem (memory)
        or ExprLoc (location label) or ExprInt (integer).

        Args:
            expr: Expression to test.

        Returns:
            True if expr is terminal expression.
        """
        return expr.is_id() or expr.is_int() or expr.is_loc()  # type: ignore
Пример #3
0
    def add_to_set(e: Expr) -> Expr:
        """
        Helper function to add variables, memory 
        and labels to a set.

        Args:
            expr: Expression to add.

        Returns:
            Expression.
        """
        # memory
        if e.is_mem():
            results.add(e)
        # registers
        if e.is_id():
            results.add(e)
        # location IDs
        if e.is_loc():
            results.add(e)
        return e