Description
Implement the translation of astx.StructDefStmt to LLVM IR identified struct types. This is the foundation for struct support in IRx.
Background
astx already provides StructDefStmt for defining structs
- IRx needs to translate this to LLVM's
IdentifiedStructType
- Inspired by LLVM's CodeGenTypes.cpp
Tasks
Example Input (Python)
struct_def = astx.StructDefStmt(
name="Point",
attributes=[
astx.VariableDeclaration(name="x", type_=astx.Int32()),
astx.VariableDeclaration(name="y", type_=astx.Int32()),
],
)
Expected LLVM IR Output
%"Point" = type {i32, i32}
Files to Modify
src/irx/builders/llvmliteir.py
Acceptance Criteria
Description
Implement the translation of
astx.StructDefStmtto LLVM IR identified struct types. This is the foundation for struct support in IRx.Background
astxalready providesStructDefStmtfor defining structsIdentifiedStructTypeTasks
struct_types: dict[str, ir.IdentifiedStructType]inLLVMLiteIRVisitorto track struct name → LLVM type mappingstruct_defs: dict[str, astx.StructDefStmt]to store struct definitions for field lookupvisit(node: astx.StructDefStmt)visitor method:IdentifiedStructTypeusingmodule.context.get_identified_type(name)get_data_type()struct_type.set_body(*field_types)Example Input (Python)
Expected LLVM IR Output
Files to Modify
src/irx/builders/llvmliteir.pyAcceptance Criteria
StructDefStmttranslates to LLVMIdentifiedStructTypetest_struct_definitionpasses