Skip to content

Commit d24d59c

Browse files
fix structure for IR generation separation.
1 parent f190a33 commit d24d59c

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

pythonbpf/vmlinux_parser/dependency_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from typing import Optional, Dict, List, Iterator
2-
from dependency_node import DependencyNode
2+
from .dependency_node import DependencyNode
33

44

55
class DependencyHandler:

pythonbpf/vmlinux_parser/import_detector.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import ast
22
import logging
3-
from typing import List, Tuple
3+
from typing import List, Tuple, Dict
44
import importlib
55
import inspect
6+
7+
from .dependency_handler import DependencyHandler
8+
from .ir_generation import IRGenerator
69
from .vmlinux_class_handler import process_vmlinux_class
710

811
logger = logging.getLogger(__name__)
@@ -75,6 +78,11 @@ def detect_import_statement(tree: ast.AST) -> List[Tuple[str, ast.ImportFrom]]:
7578
def vmlinux_proc(tree: ast.AST, module):
7679
import_statements = detect_import_statement(tree)
7780

81+
# initialise dependency handler
82+
handler = DependencyHandler()
83+
# initialise assignment dictionary of name to type
84+
assignments: Dict[str, type] = {}
85+
7886
if not import_statements:
7987
logger.info("No vmlinux imports found")
8088
return
@@ -100,19 +108,21 @@ def vmlinux_proc(tree: ast.AST, module):
100108
found = False
101109
for mod_node in mod_ast.body:
102110
if isinstance(mod_node, ast.ClassDef) and mod_node.name == imported_name:
103-
process_vmlinux_class(mod_node, module)
111+
process_vmlinux_class(mod_node, module, handler)
104112
found = True
105113
break
106114
if isinstance(mod_node, ast.Assign):
107115
for target in mod_node.targets:
108116
if isinstance(target, ast.Name) and target.id == imported_name:
109-
process_vmlinux_assign(mod_node, module)
117+
process_vmlinux_assign(mod_node, module, assignments)
110118
found = True
111119
break
112120
if found:
113121
break
114122
if not found:
115123
logger.info(f"{imported_name} not found as ClassDef or Assign in vmlinux")
116124

117-
def process_vmlinux_assign(node, module):
125+
IRGenerator(module, handler)
126+
127+
def process_vmlinux_assign(node, module, assignments: Dict[str, type]):
118128
raise NotImplementedError("Assignment handling has not been implemented yet")
Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
# here, we will iterate through the dependencies and generate IR once dependencies are resolved fully
1+
# here, we will iterate through the dependencies and generate IR once dependencies are resolved fully
2+
from .dependency_handler import DependencyHandler
3+
4+
5+
class IRGenerator:
6+
def __init__(self, module, handler):
7+
self.module = module
8+
self.handler: DependencyHandler = handler

pythonbpf/vmlinux_parser/vmlinux_class_handler.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import logging
33
from functools import lru_cache
44
import importlib
5+
from .dependency_handler import DependencyHandler
6+
from .dependency_node import DependencyNode
57

68
logger = logging.getLogger(__name__)
79

@@ -10,6 +12,12 @@ def get_module_symbols(module_name: str):
1012
module = importlib.import_module(module_name)
1113
return [name for name in dir(module)]
1214

13-
def process_vmlinux_class(node, module, num=0):
15+
def process_vmlinux_class(node, module, handler: DependencyHandler, parent=""):
1416
symbols_in_module = get_module_symbols("vmlinux")
17+
current_symbol_name = node.name
18+
if current_symbol_name not in symbols_in_module:
19+
raise ImportError(f"{current_symbol_name} not present in module vmlinux")
20+
logger.info(f"Resolving vmlinux class {current_symbol_name}")
21+
# Now we find fields present in current class
22+
pass
1523

0 commit comments

Comments
 (0)