mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
add bool assignment support
This commit is contained in:
@ -30,8 +30,12 @@ def hello_again(ctx: c_void_p) -> c_int64:
|
|||||||
# if delta < 1000000000:
|
# if delta < 1000000000:
|
||||||
# print("execve called within last second")
|
# print("execve called within last second")
|
||||||
# last().delete(key)
|
# last().delete(key)
|
||||||
if True:
|
x = False
|
||||||
|
x = True
|
||||||
|
if x:
|
||||||
print("we prevailed")
|
print("we prevailed")
|
||||||
|
if x:
|
||||||
|
print("we did not prevail")
|
||||||
ts = ktime()
|
ts = ktime()
|
||||||
# last().update(key, ts)
|
# last().update(key, ts)
|
||||||
return c_int64(0)
|
return c_int64(0)
|
||||||
|
|||||||
@ -37,7 +37,15 @@ def handle_assign(func, module, builder, stmt, map_sym_tab, local_sym_tab):
|
|||||||
var_name = target.id
|
var_name = target.id
|
||||||
rval = stmt.value
|
rval = stmt.value
|
||||||
if isinstance(rval, ast.Constant):
|
if isinstance(rval, ast.Constant):
|
||||||
if isinstance(rval.value, int):
|
if isinstance(rval.value, bool):
|
||||||
|
if rval.value:
|
||||||
|
builder.store(ir.Constant(ir.IntType(1), 1),
|
||||||
|
local_sym_tab[var_name])
|
||||||
|
else:
|
||||||
|
builder.store(ir.Constant(ir.IntType(1), 0),
|
||||||
|
local_sym_tab[var_name])
|
||||||
|
print(f"Assigned constant {rval.value} to {var_name}")
|
||||||
|
elif isinstance(rval.value, int):
|
||||||
# Assume c_int64 for now
|
# Assume c_int64 for now
|
||||||
# var = builder.alloca(ir.IntType(64), name=var_name)
|
# var = builder.alloca(ir.IntType(64), name=var_name)
|
||||||
# var.align = 8
|
# var.align = 8
|
||||||
@ -232,7 +240,13 @@ def process_func_body(module, builder, func_node, func, ret_type, map_sym_tab):
|
|||||||
print("Unsupported assignment call function type")
|
print("Unsupported assignment call function type")
|
||||||
continue
|
continue
|
||||||
elif isinstance(rval, ast.Constant):
|
elif isinstance(rval, ast.Constant):
|
||||||
if isinstance(rval.value, int):
|
if isinstance(rval.value, bool):
|
||||||
|
ir_type = ir.IntType(1)
|
||||||
|
var = builder.alloca(ir_type, name=var_name)
|
||||||
|
var.align = 1
|
||||||
|
print(
|
||||||
|
f"Pre-allocated variable {var_name} of type c_bool")
|
||||||
|
elif isinstance(rval.value, int):
|
||||||
# Assume c_int64 for now
|
# Assume c_int64 for now
|
||||||
ir_type = ir.IntType(64)
|
ir_type = ir.IntType(64)
|
||||||
var = builder.alloca(ir_type, name=var_name)
|
var = builder.alloca(ir_type, name=var_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user