add base for ir gen

This commit is contained in:
2025-10-15 02:00:23 +05:30
parent d3f0e3b2ef
commit 11e8e72188
3 changed files with 43 additions and 3 deletions

View File

@ -147,3 +147,23 @@ class DependencyHandler:
int: The number of nodes
"""
return len(self._nodes)
def __getitem__(self, name: str) -> DependencyNode:
"""
Get a node by name using dictionary-style access.
Args:
name: The name of the node to retrieve
Returns:
DependencyNode: The node with the given name
Raises:
KeyError: If no node with the given name exists
Example:
node = handler["some-dep_node_name"]
"""
if name not in self._nodes:
raise KeyError(f"No node with name '{name}' found")
return self._nodes[name]

View File

@ -8,10 +8,28 @@ class IRGenerator:
def __init__(self, module, handler: DependencyHandler):
self.module = module
self.handler: DependencyHandler = handler
self.generated: list[str] = []
if not handler.is_ready:
raise ImportError(
"Semantic analysis of vmlinux imports failed. Cannot generate IR"
)
for struct in handler:
print(struct)
self.struct_processor(struct)
print()
def struct_processor(self, struct):
if struct.name not in self.generated:
print(f"IR generating for {struct.name}")
print(f"Struct is {struct}")
for dependency in struct.depends_on:
if dependency not in self.generated:
dep_node_from_dependency = self.handler[dependency]
self.struct_processor(dep_node_from_dependency)
self.generated.append(dependency)
# write actual processor logic here after assuming all dependencies are resolved
# this part cannot yet resolve circular dependencies. Gets stuck on an infinite loop during that.
self.generated.append(struct.name)
def struct_name_generator(self, ):
pass

View File

@ -1,9 +1,11 @@
from pythonbpf import bpf, map, section, bpfglobal, compile_to_ir
from pythonbpf.maps import HashMap
from pythonbpf.helper import XDP_PASS
# from vmlinux import struct_request
from vmlinux import struct_trace_event_raw_sys_enter
from vmlinux import struct_xdp_md
from vmlinux import struct_trace_event_raw_sys_enter # noqa: F401
from vmlinux import struct_ring_buffer_per_cpu # noqa: F401
# from vmlinux import struct_trace_event_raw_sys_enter # noqa: F401
# from vmlinux import struct_ring_buffer_per_cpu # noqa: F401
from ctypes import c_int64