|
1 | 1 | import ast |
2 | 2 | from llvmlite import ir |
| 3 | +from .license_pass import license_processing |
3 | 4 |
|
4 | | -def parser(source_code, filename): |
| 5 | +def processor(source_code, filename, module): |
5 | 6 | tree = ast.parse(source_code, filename) |
6 | | - |
7 | | - for node in tree.body: |
8 | | - if isinstance(node, ast.FunctionDef): |
9 | | - print("Function:", node.name) |
10 | | - for dec in node.decorator_list: |
11 | | - print(" Decorator AST:", ast.dump(dec)) |
| 7 | + license_processing(tree, module) |
12 | 8 |
|
13 | 9 | def compile_to_ir(filename: str, output: str): |
14 | 10 | with open(filename) as f: |
15 | | - parser(f.read(), filename) |
| 11 | + source = f.read() |
| 12 | + |
16 | 13 | module = ir.Module(name=filename) |
17 | 14 | module.data_layout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128" |
18 | 15 | module.triple = "bpf" |
19 | 16 |
|
20 | | - func_ty = ir.FunctionType(ir.IntType(64), [], False) |
21 | | - func = ir.Function(module, func_ty, name="trace_execve") |
22 | | - |
23 | | - block = func.append_basic_block(name="entry") |
24 | | - builder = ir.IRBuilder(block) |
25 | | - builder.ret(ir.IntType(64)(0)) |
| 17 | + processor(source, filename, module) |
26 | 18 |
|
27 | 19 | with open(output, "w") as f: |
28 | 20 | f.write(str(module)) |
|
0 commit comments