mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Allow int** pointers to store binops of type int** op int
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import ast
|
||||
import logging
|
||||
from llvmlite import ir
|
||||
from pythonbpf.expr import eval_expr, get_base_type_and_depth
|
||||
from pythonbpf.expr import eval_expr
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -37,10 +37,8 @@ def handle_variable_assignment(
|
||||
return False
|
||||
|
||||
val, val_type = val_result
|
||||
logger.info(f"Evaluated value for {var_name}: {val} of type {val_type}, {var_type}")
|
||||
if val_type != var_type:
|
||||
logger.info(f"val = {val}")
|
||||
logger.info(f"var = {var_ptr}")
|
||||
logger.info(f"truthy {var_type}")
|
||||
if isinstance(val_type, ir.IntType) and isinstance(var_type, ir.IntType):
|
||||
# Allow implicit int widening
|
||||
if val_type.width < var_type.width:
|
||||
@ -50,23 +48,17 @@ def handle_variable_assignment(
|
||||
val = builder.trunc(val, var_type)
|
||||
logger.info(f"Implicitly truncated int for variable {var_name}")
|
||||
elif isinstance(val_type, ir.IntType) and isinstance(var_type, ir.PointerType):
|
||||
ptr_target, ptr_depth = get_base_type_and_depth(var_type)
|
||||
if ptr_target.width > val_type.width:
|
||||
val = builder.sext(val, ptr_target)
|
||||
elif ptr_target.width < val_type.width:
|
||||
val = builder.trunc(val, ptr_target)
|
||||
|
||||
if ptr_depth > 1:
|
||||
# NOTE: This is assignment to a PTR_TO_MAP_VALUE_OR_NULL
|
||||
var_ptr_tmp = local_sym_tab[f"{var_name}_tmp"].var
|
||||
builder.store(val, var_ptr_tmp)
|
||||
val = var_ptr_tmp
|
||||
# NOTE: This is assignment to a PTR_TO_MAP_VALUE_OR_NULL
|
||||
logger.info(
|
||||
f"Creating temporary variable for pointer assignment to {var_name}"
|
||||
)
|
||||
var_ptr_tmp = local_sym_tab[f"{var_name}_tmp"].var
|
||||
builder.store(val, var_ptr_tmp)
|
||||
val = var_ptr_tmp
|
||||
else:
|
||||
logger.error(
|
||||
f"Type mismatch for variable {var_name}: {val_type} vs {var_type}"
|
||||
)
|
||||
logger.error(f"var_type: {isinstance(var_type, ir.PointerType)}")
|
||||
logger.error(f"val_type: {isinstance(val_type, ir.IntType)}")
|
||||
return False
|
||||
|
||||
builder.store(val, var_ptr)
|
||||
|
||||
Reference in New Issue
Block a user