How khronosgroup/glslang works
Main Components
a. Front Ends
• GLSL/ESSL Parser (MachineIndependent/Preprocessor, Scan.cpp, glslang.y)
• HLSL Parser (glslang/HLSL)
b. Intermediate Representation (AST)
• SymbolTable & AST (MachineIndependent/*.cpp, Intermediate.cpp)
c. Back End
• SPIR-V Generator (SPIRV/*)
d. Reflection API
• Reflection queries on AST (MachineIndependent/reflection.cpp/h)
e. Library Interfaces
• C++ Class API (ShaderLang.h, TShader/TProgram)
• C Functional API (Sh* functions in ShaderLang.h)
• C Interface (glslang_c_interface.h)
f. Standalone Wrapper
• CLI tool (StandAlone/StandAlone.cpp)
g. External Projects & Tools
• SPIRV-Tools scripts (External/)
• Python scripts (update_glslang_sources.py, gen_extension_headers.py)
h. Build System & CI/CD
• CMakeLists.txt, BUILD.gn, GN support, GK layouts (.github/workflows)
i. Testing Harnesses
• GoogleTest (gtests/)
• “runtests” script (Test/runtests, Test/baseResults)
Relationships & Data Flows
• Shader source → Preprocessor → Scanner → Parser → AST
• AST → Back End → SPIR-V binary
• AST → Reflection API → Reflection data
• CLI wrapper or Library API → Front Ends & Back End → Outputs (errors, AST, SPIR-V)
• Build system invokes CMake/GN, drives compilation of all components
• CI/CD pipelines trigger builds, tests, deployment
Architectural Patterns
• Compiler pipeline (Lexical → Syntax → Semantic → IR → CodeGen)
• Layered modular libraries (MachineIndependent, SPIRV, OSDependent, GenericCodeGen)
• Plugin-like External modules for SPIRV-Tools integration
• Singleton initialization/finalization in APIs (InitializeProcess/FinalizeProcess)
Technologies & Frameworks
• C++17, bison (glslang.y), Python 3 for scripts
• CMake & Ninja, GN & depot_tools
• GoogleTest for unit & integration tests
• SPIR-V specification libraries (SPIRV-Headers)