70 likes | 87 Views
GLSlang compiler. GLSlang Front-End. GL Shading Language compiler front end developed by 3DLabs. Redistribution and use in source and binary forms, with or without modification, are permitted. Ready to build on Linux and Windows Windows → Requires Visual Studio .NET
E N D
GLSlang Front-End • GL Shading Language compiler front end developed by 3DLabs. • Redistribution and use in source and binary forms, with or without modification, are permitted. • Ready to build on Linux and Windows • Windows → Requires Visual Studio .NET • Linux → Compilation problems with libc versión in fargas • By now compiled in Visual Studio .NET
GLSlang compiler source code • It´s completely machine independent code • Code is parsed by flex/bison, with the aid of a symbol table and an intermediate representation • The intermediate representation (IR) is very high-level, and represented as an in memory tree • No lose information from the original program • In the IR constants are propogated and folded... • ... and some dead code is eliminated.
GLSlang compiler source code • The back-end compiler has to traverse the IR-tree and create an internal object code representation. • It has to derive from TCompiler: class TGenericCompiler : public TCompiler { public: TGenericCompiler(EShLanguage l, int dOptions) : TCompiler(l, infoSink), debugOptions(dOptions) { } virtual bool compile(TIntermNode* root); TInfoSink infoSink; int debugOptions; };
GLSlang compiler source code • intermediate.hhas the definition of the IR tree. • Nodes in the IR tree are defined as a hierarchy of classes derived from TIntermNode. • Example: class TIntermLoop : public TIntermNode; represents a loop in the tree. class TIntermOperator : public TIntermTyped; represents an operator in the tree.
GLSlang generic compiler output • A little back end is implemented • Only to print a brief description of the IR tree. • Example (the glslang code): varying vec3 color; void main() { color = vec3(1.0, 1.0, 1.0); gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; }
GLSlang generic compiler output • The output: #### BEGIN COMPILER 0 INFO LOG #### 0:? Sequence 0:37 Function Definition: main( (void) 0:37 Function Parameters: 0:39 Sequence 0:39 move second child to first child (3-component vector of float) 0:39 'color' (varying 3-component vector of float) 0:39 Construct vec3 (const 3-component vector of float) 0:39 1.000000 (const float) 0:39 1.000000 (const float) 0:39 1.000000 (const float) 0:41 move second child to first child (4-component vector of float) 0:41 'gl_Position' (Position 4-component vector of float) 0:41 matrix-times-vector (4-component vector of float) 0:41 'gl_ModelViewProjectionMatrix' (uniform 4X4 matrix of float) 0:41 'gl_Vertex' (attribute 4-component vector of float) #### END COMPILER 0 INFO LOG #### #### BEGIN LINKER INFO LOG #### #### END LINKER INFO LOG ####