@@ -16,9 +16,6 @@ def emit_globals(module: ir.Module, names: list[str]):
1616 g = module .get_global (name )
1717 else :
1818 g = ir .GlobalValue (module , ptr_ty , name )
19- print ("global emitted:" , name )
20- print (isinstance (g , ir .GlobalVariable ))
21- print (isinstance (g , ir .Function ))
2219 elems .append (g .bitcast (ptr_ty ))
2320
2421 gv = ir .GlobalVariable (module , used_array_ty , "llvm.compiler.used" )
@@ -31,16 +28,19 @@ def globals_processing(tree, module: ir.Module):
3128 collected = ["LICENSE" ]
3229
3330 for node in tree .body :
34- if isinstance (node , ast .FunctionDef ) and len (node .decorator_list ) == 2 :
35- dec = node .decorator_list [1 ]
36- if (
37- isinstance (dec , ast .Call )
38- and isinstance (dec .func , ast .Name )
39- and dec .func .id == "section"
40- and len (dec .args ) == 1
41- and isinstance (dec .args [0 ], ast .Constant )
42- and isinstance (dec .args [0 ].value , str )
43- ):
44- collected .append (node .name )
31+ if isinstance (node , ast .FunctionDef ):
32+ for dec in node .decorator_list :
33+ if (
34+ isinstance (dec , ast .Call )
35+ and isinstance (dec .func , ast .Name )
36+ and dec .func .id == "section"
37+ and len (dec .args ) == 1
38+ and isinstance (dec .args [0 ], ast .Constant )
39+ and isinstance (dec .args [0 ].value , str )
40+ ):
41+ collected .append (node .name )
42+
43+ elif isinstance (dec , ast .Name ) and dec .id == "bpfglobal" :
44+ collected .append (node .name )
4545
4646 emit_globals (module , collected )
0 commit comments