How crossgl/crosstl works
Project type and purpose
• CrossTL (crosstl) is an open-source universal programming language translator and compiler toolkit. It defines the CrossGL IR language (.cgl) and translates between CrossGL and various target languages/platforms (CUDA, HIP, Metal, DirectX/HLSL, OpenGL/GLSL, Vulkan/SPIRV, Rust, Mojo, Slang).
• The README describes a multi-stage translation pipeline: lexical analysis → syntax analysis → semantic analysis → IR generation (CrossGL AST) → optimization → backend code generation → post-processing/formatting.
File structure
• Top-level:
• setup.py, requirements.txt, setup.cfg → packaging and installation
• crosstl/ → main Python package
• examples/ and examples/output/ → sample .cgl inputs and generated target code
• tests/ → unit tests for translator and each backend
• crosstl/ contains:
• _crosstl.py → core translation orchestration
• formatter.py → code formatting and post-processing
• translator/lexer.py, parser.py, ast.py → lexical and syntax analysis, AST definitions
• translator/codegen/*.py → IR-to-backend codegen modules for each target
• backend/* → backend-specific parser, lexer, AST and CrossGL-to-CrossGL translators (used for reverse/import translation)
• Deployment script (deploy.sh) and CI workflows (GitHub Actions) indicate automated testing and release pipelines.
README for additional insights
• Architecture section lists seven pipeline stages.
• It emphasizes bidirectional translation (import/export).
• It highlights extensibility: adding new backends by implementing lexer/parser/AST/codegen modules.
Elements
• Labels: “CLI/API”, “Lexer”, “Parser”, “Semantic Analyzer/IR Generator”, “Optimizer”, “Codegen Dispatcher”, “Formatter”, “File Output”
• Right-to-left for import pipeline back into IR
• Front-end modules in blue
• Middle-end in green
• Back-end codegen in orange
• Import backends in purple
• Testing/Examples in gray
• Rectangles for components