Open jrmuizel opened 5 years ago
Hm, I need to have more information / find more material about that symbole table they’re using. Do you have any link?
Sure.
The symbol table is defined here: https://github.com/KhronosGroup/glslang/blob/f04f1f93a70f4608ffa9903b20bfb95f20a063f5/glslang/MachineIndependent/SymbolTable.h#L567
Here's an example of what happens:
During parsing declareVariable
is called:
https://github.com/KhronosGroup/glslang/blob/f04f1f93a70f4608ffa9903b20bfb95f20a063f5/glslang/MachineIndependent/glslang.y#L1056
declareVariable
calls into declareNonArray
https://github.com/KhronosGroup/glslang/blob/f04f1f93a70f4608ffa9903b20bfb95f20a063f5/glslang/MachineIndependent/ParseHelper.cpp#L6395
declareNonArray
adds the typed symbol to the symbol table https://github.com/KhronosGroup/glslang/blob/f04f1f93a70f4608ffa9903b20bfb95f20a063f5/glslang/MachineIndependent/ParseHelper.cpp#L6551
Symbols are looked up during scanning https://github.com/KhronosGroup/glslang/blob/974a586688c169c5724faf34ed5ed6c8e7563711/glslang/MachineIndependent/Scan.cpp#L1643 and used like this https://github.com/KhronosGroup/glslang/blob/f04f1f93a70f4608ffa9903b20bfb95f20a063f5/glslang/MachineIndependent/glslang.y#L303
Alternatively, the mesa glsl compiler parses to a low level AST and then lifts to a HIR: https://github.com/mesa3d/mesa/blob/4bf7e7b17092487b6b6c4aff5e920dbe1fd4470e/src/compiler/glsl/README
I'm experimenting with HIR approach here: https://github.com/jrmuizel/glsl-to-spriv
@jrmuizel great! I haven’t had enough spare time lately to look into that, but feel free to go for it! I’ll have a look at the code you wrote, I’m interested in the approach. :)
This is needed to do semantic analysis and translation to spirv.
Do you have any thoughts on how you'd like to represent it?
glslang builds the symbol table during parsing and refers to it in the resulting parse tree. That has the advantage of not needing to represent both an unresolved syntax tree and a syntax tree with resolved symbols.