fix structure for IR generation separation.

This commit is contained in:
2025-10-11 18:11:46 +05:30
parent f190a33e21
commit d24d59c2ba
4 changed files with 32 additions and 7 deletions

View File

@ -1,5 +1,5 @@
from typing import Optional, Dict, List, Iterator
from dependency_node import DependencyNode
from .dependency_node import DependencyNode
class DependencyHandler:

View File

@ -1,8 +1,11 @@
import ast
import logging
from typing import List, Tuple
from typing import List, Tuple, Dict
import importlib
import inspect
from .dependency_handler import DependencyHandler
from .ir_generation import IRGenerator
from .vmlinux_class_handler import process_vmlinux_class
logger = logging.getLogger(__name__)
@ -75,6 +78,11 @@ def detect_import_statement(tree: ast.AST) -> List[Tuple[str, ast.ImportFrom]]:
def vmlinux_proc(tree: ast.AST, module):
import_statements = detect_import_statement(tree)
# initialise dependency handler
handler = DependencyHandler()
# initialise assignment dictionary of name to type
assignments: Dict[str, type] = {}
if not import_statements:
logger.info("No vmlinux imports found")
return
@ -100,13 +108,13 @@ def vmlinux_proc(tree: ast.AST, module):
found = False
for mod_node in mod_ast.body:
if isinstance(mod_node, ast.ClassDef) and mod_node.name == imported_name:
process_vmlinux_class(mod_node, module)
process_vmlinux_class(mod_node, module, handler)
found = True
break
if isinstance(mod_node, ast.Assign):
for target in mod_node.targets:
if isinstance(target, ast.Name) and target.id == imported_name:
process_vmlinux_assign(mod_node, module)
process_vmlinux_assign(mod_node, module, assignments)
found = True
break
if found:
@ -114,5 +122,7 @@ def vmlinux_proc(tree: ast.AST, module):
if not found:
logger.info(f"{imported_name} not found as ClassDef or Assign in vmlinux")
def process_vmlinux_assign(node, module):
IRGenerator(module, handler)
def process_vmlinux_assign(node, module, assignments: Dict[str, type]):
raise NotImplementedError("Assignment handling has not been implemented yet")

View File

@ -1 +1,8 @@
# here, we will iterate through the dependencies and generate IR once dependencies are resolved fully
# here, we will iterate through the dependencies and generate IR once dependencies are resolved fully
from .dependency_handler import DependencyHandler
class IRGenerator:
def __init__(self, module, handler):
self.module = module
self.handler: DependencyHandler = handler

View File

@ -2,6 +2,8 @@ import ast
import logging
from functools import lru_cache
import importlib
from .dependency_handler import DependencyHandler
from .dependency_node import DependencyNode
logger = logging.getLogger(__name__)
@ -10,6 +12,12 @@ def get_module_symbols(module_name: str):
module = importlib.import_module(module_name)
return [name for name in dir(module)]
def process_vmlinux_class(node, module, num=0):
def process_vmlinux_class(node, module, handler: DependencyHandler, parent=""):
symbols_in_module = get_module_symbols("vmlinux")
current_symbol_name = node.name
if current_symbol_name not in symbols_in_module:
raise ImportError(f"{current_symbol_name} not present in module vmlinux")
logger.info(f"Resolving vmlinux class {current_symbol_name}")
# Now we find fields present in current class
pass