Skip to content

Commit 4cf284a

Browse files
committed
provide type as weel in eval_expr
1 parent 1517f6e commit 4cf284a

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

pythonbpf/expr_pass.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ def eval_expr(func, module, builder, expr, local_sym_tab, map_sym_tab, structs_s
88
if expr.id in local_sym_tab:
99
var = local_sym_tab[expr.id][0]
1010
val = builder.load(var)
11-
return val
11+
return val, local_sym_tab[expr.id][1] # return value and type
1212
else:
1313
print(f"Undefined variable {expr.id}")
1414
return None
1515
elif isinstance(expr, ast.Constant):
1616
if isinstance(expr.value, int):
17-
return ir.Constant(ir.IntType(64), expr.value)
17+
return ir.Constant(ir.IntType(64), expr.value), ir.IntType(64)
1818
elif isinstance(expr.value, bool):
19-
return ir.Constant(ir.IntType(1), int(expr.value))
19+
return ir.Constant(ir.IntType(1), int(expr.value)), ir.IntType(1)
2020
else:
2121
print("Unsupported constant type")
2222
return None
@@ -44,8 +44,9 @@ def eval_expr(func, module, builder, expr, local_sym_tab, map_sym_tab, structs_s
4444
if arg is None:
4545
print("Failed to evaluate deref argument")
4646
return None
47+
# Since we are handling only name case, directly take type from sym tab
4748
val = builder.load(arg)
48-
return val
49+
return val, local_sym_tab[expr.args[0].id][1]
4950

5051
# check for helpers
5152
if expr.func.id in helper_func_list:

0 commit comments

Comments
 (0)