mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Add pointer handling to helper_utils, finish pointer assignment
This commit is contained in:
@ -1,4 +1,10 @@
|
||||
from .expr_pass import eval_expr, handle_expr
|
||||
from .type_normalization import convert_to_bool, get_base_type_and_depth
|
||||
from .type_normalization import convert_to_bool, get_base_type_and_depth, deref_to_depth
|
||||
|
||||
__all__ = ["eval_expr", "handle_expr", "convert_to_bool", "get_base_type_and_depth"]
|
||||
__all__ = [
|
||||
"eval_expr",
|
||||
"handle_expr",
|
||||
"convert_to_bool",
|
||||
"get_base_type_and_depth",
|
||||
"deref_to_depth",
|
||||
]
|
||||
|
||||
@ -26,7 +26,7 @@ def _handle_constant_expr(expr: ast.Constant):
|
||||
if isinstance(expr.value, int) or isinstance(expr.value, bool):
|
||||
return ir.Constant(ir.IntType(64), int(expr.value)), ir.IntType(64)
|
||||
else:
|
||||
logger.error("Unsupported constant type")
|
||||
logger.error(f"Unsupported constant type {ast.dump(expr)}")
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@ -26,7 +26,7 @@ def get_base_type_and_depth(ir_type):
|
||||
return cur_type, depth
|
||||
|
||||
|
||||
def _deref_to_depth(func, builder, val, target_depth):
|
||||
def deref_to_depth(func, builder, val, target_depth):
|
||||
"""Dereference a pointer to a certain depth."""
|
||||
|
||||
cur_val = val
|
||||
@ -92,9 +92,9 @@ def _normalize_types(func, builder, lhs, rhs):
|
||||
rhs_base, rhs_depth = get_base_type_and_depth(rhs.type)
|
||||
if lhs_base == rhs_base:
|
||||
if lhs_depth < rhs_depth:
|
||||
rhs = _deref_to_depth(func, builder, rhs, rhs_depth - lhs_depth)
|
||||
rhs = deref_to_depth(func, builder, rhs, rhs_depth - lhs_depth)
|
||||
elif rhs_depth < lhs_depth:
|
||||
lhs = _deref_to_depth(func, builder, lhs, lhs_depth - rhs_depth)
|
||||
lhs = deref_to_depth(func, builder, lhs, lhs_depth - rhs_depth)
|
||||
return _normalize_types(func, builder, lhs, rhs)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user