mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
Initialize PythonBPF project and toolchain
This commit is contained in:
19
pythonbpf/codegen.py
Normal file
19
pythonbpf/codegen.py
Normal file
@ -0,0 +1,19 @@
|
||||
import ast
|
||||
from llvmlite import ir
|
||||
|
||||
def compile_to_ir(filename: str, output: str):
|
||||
with open(filename) as f:
|
||||
ast.parse(f.read(), filename)
|
||||
|
||||
module = ir.Module(name="pythonbpf")
|
||||
func_ty = ir.FunctionType(ir.IntType(64), [], False)
|
||||
func = ir.Function(module, func_ty, name="trace_execve")
|
||||
|
||||
block = func.append_basic_block(name="entry")
|
||||
builder = ir.IRBuilder(block)
|
||||
builder.ret(ir.IntType(64)(0))
|
||||
|
||||
with open(output, "w") as f:
|
||||
f.write(str(module))
|
||||
|
||||
return output
|
||||
Reference in New Issue
Block a user