mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
update globals test and todos.
This commit is contained in:
@ -10,13 +10,13 @@ logger: Logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
def emit_global(module: ir.Module, node, name):
|
def emit_global(module: ir.Module, node, name):
|
||||||
logger.info(f"global identifier {name} processing")
|
logger.info(f"global identifier {name} processing")
|
||||||
# TODO: below part is LLM generated check logic.
|
|
||||||
# deduce LLVM type from the annotated return
|
# deduce LLVM type from the annotated return
|
||||||
if not isinstance(node.returns, ast.Name):
|
if not isinstance(node.returns, ast.Name):
|
||||||
raise ValueError(f"Unsupported return annotation {ast.dump(node.returns)}")
|
raise ValueError(f"Unsupported return annotation {ast.dump(node.returns)}")
|
||||||
ty = ctypes_to_ir(node.returns.id)
|
ty = ctypes_to_ir(node.returns.id)
|
||||||
|
|
||||||
# extract the return expression
|
# extract the return expression
|
||||||
|
# TODO: turn this return extractor into a generic function I can use everywhere.
|
||||||
ret_stmt = node.body[0]
|
ret_stmt = node.body[0]
|
||||||
if not isinstance(ret_stmt, ast.Return) or ret_stmt.value is None:
|
if not isinstance(ret_stmt, ast.Return) or ret_stmt.value is None:
|
||||||
raise ValueError(f"Global '{name}' has no valid return")
|
raise ValueError(f"Global '{name}' has no valid return")
|
||||||
@ -29,7 +29,7 @@ def emit_global(module: ir.Module, node, name):
|
|||||||
|
|
||||||
# variable reference like "return SOME_CONST"
|
# variable reference like "return SOME_CONST"
|
||||||
elif isinstance(init_val, ast.Name):
|
elif isinstance(init_val, ast.Name):
|
||||||
# you may need symbol resolution here, stub as 0 for now
|
# need symbol resolution here, stub as 0 for now
|
||||||
raise ValueError(f"Name reference {init_val.id} not yet supported")
|
raise ValueError(f"Name reference {init_val.id} not yet supported")
|
||||||
|
|
||||||
# constructor call like "return c_int64(0)" or dataclass(...)
|
# constructor call like "return c_int64(0)" or dataclass(...)
|
||||||
|
|||||||
@ -6,17 +6,17 @@ from ctypes import c_void_p, c_int64, c_int32
|
|||||||
@bpf
|
@bpf
|
||||||
@bpfglobal
|
@bpfglobal
|
||||||
def somevalue() -> c_int32:
|
def somevalue() -> c_int32:
|
||||||
return c_int32(0)
|
return c_int32(42)
|
||||||
|
|
||||||
@bpf
|
@bpf
|
||||||
@bpfglobal
|
@bpfglobal
|
||||||
def somevalue2() -> c_int64:
|
def somevalue2() -> c_int64:
|
||||||
return c_int64(0)
|
return c_int64(69)
|
||||||
|
|
||||||
@bpf
|
@bpf
|
||||||
@bpfglobal
|
@bpfglobal
|
||||||
def somevalue1() -> c_int32:
|
def somevalue1() -> c_int32:
|
||||||
return c_int32(0)
|
return c_int32(42)
|
||||||
|
|
||||||
|
|
||||||
# --- Passing examples ---
|
# --- Passing examples ---
|
||||||
@ -31,7 +31,7 @@ def g1() -> c_int64:
|
|||||||
@bpf
|
@bpf
|
||||||
@bpfglobal
|
@bpfglobal
|
||||||
def g2() -> c_int64:
|
def g2() -> c_int64:
|
||||||
return c_int64(0)
|
return c_int64(69)
|
||||||
|
|
||||||
|
|
||||||
# --- Failing examples ---
|
# --- Failing examples ---
|
||||||
|
|||||||
Reference in New Issue
Block a user