Skip to content

Commit ab61014

Browse files
update globals test and todos.
1 parent 7720fe9 commit ab61014

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pythonbpf/globals_pass.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
def emit_global(module: ir.Module, node, name):
1212
logger.info(f"global identifier {name} processing")
13-
# TODO: below part is LLM generated check logic.
1413
# deduce LLVM type from the annotated return
1514
if not isinstance(node.returns, ast.Name):
1615
raise ValueError(f"Unsupported return annotation {ast.dump(node.returns)}")
1716
ty = ctypes_to_ir(node.returns.id)
1817

1918
# extract the return expression
19+
# TODO: turn this return extractor into a generic function I can use everywhere.
2020
ret_stmt = node.body[0]
2121
if not isinstance(ret_stmt, ast.Return) or ret_stmt.value is None:
2222
raise ValueError(f"Global '{name}' has no valid return")
@@ -29,7 +29,7 @@ def emit_global(module: ir.Module, node, name):
2929

3030
# variable reference like "return SOME_CONST"
3131
elif isinstance(init_val, ast.Name):
32-
# you may need symbol resolution here, stub as 0 for now
32+
# need symbol resolution here, stub as 0 for now
3333
raise ValueError(f"Name reference {init_val.id} not yet supported")
3434

3535
# constructor call like "return c_int64(0)" or dataclass(...)

tests/failing_tests/globals.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
@bpf
77
@bpfglobal
88
def somevalue() -> c_int32:
9-
return c_int32(0)
9+
return c_int32(42)
1010

1111
@bpf
1212
@bpfglobal
1313
def somevalue2() -> c_int64:
14-
return c_int64(0)
14+
return c_int64(69)
1515

1616
@bpf
1717
@bpfglobal
1818
def somevalue1() -> c_int32:
19-
return c_int32(0)
19+
return c_int32(42)
2020

2121

2222
# --- Passing examples ---
@@ -31,7 +31,7 @@ def g1() -> c_int64:
3131
@bpf
3232
@bpfglobal
3333
def g2() -> c_int64:
34-
return c_int64(0)
34+
return c_int64(69)
3535

3636

3737
# --- Failing examples ---

0 commit comments

Comments
 (0)