diff --git a/BIL/BilDisassemble.cpp b/BIL/BilDisassemble.cpp index 6425b865..25bbd005 100644 --- a/BIL/BilDisassemble.cpp +++ b/BIL/BilDisassemble.cpp @@ -33,3 +33,11 @@ //POSSIBILITY OF SUCH DAMAGE. #include "BilDisassemble.h" + +namespace glbil { + +void Disassemble(std::ostream& out, const std::vector&) +{ +} + +}; // end glbil namespace diff --git a/BIL/BilDisassemble.h b/BIL/BilDisassemble.h index 3400675e..eab6eb9a 100644 --- a/BIL/BilDisassemble.h +++ b/BIL/BilDisassemble.h @@ -32,5 +32,19 @@ //ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE //POSSIBILITY OF SUCH DAMAGE. +#pragma once +#ifndef BilDisassembler_H +#define BilDisassembler_H + #include "Bil.h" +#include +#include + +namespace glbil { + + void Disassemble(std::ostream& out, const std::vector&); + +}; // end glbil namespace + +#endif // BilDisassembler_H diff --git a/BIL/GlslangToBil.cpp b/BIL/GlslangToBil.cpp index bb48a6ef..043d9d37 100644 --- a/BIL/GlslangToBil.cpp +++ b/BIL/GlslangToBil.cpp @@ -43,7 +43,11 @@ namespace glslang { -void GlslangToBil(const glslang::TIntermediate& intermediate) +void GlslangToBil(const glslang::TIntermediate& intermediate, std::vector bil) +{ +} + +void OutputBil(const std::vector& bil, const char* baseName) { } diff --git a/BIL/GlslangToBil.h b/BIL/GlslangToBil.h index b030fe38..025bb08a 100644 --- a/BIL/GlslangToBil.h +++ b/BIL/GlslangToBil.h @@ -36,6 +36,8 @@ namespace glslang { -void GlslangToBil(const glslang::TIntermediate& intermediate); +void GlslangToBil(const glslang::TIntermediate& intermediate, std::vector bil); + +void OutputBil(const std::vector& bil, const char* baseName); }; diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index 06710f5d..7f349fcb 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -41,6 +41,7 @@ #include "./../glslang/Include/ShHandle.h" #include "./../glslang/Public/ShaderLang.h" #include "../BIL/GlslangToBil.h" +#include "../BIL/BilDisassemble.h" #include #include #include @@ -637,8 +638,22 @@ void CompileAndLinkShaders() printf("Bil is not generated for failed compile or link\n"); else { for (int stage = 0; stage < EShLangCount; ++stage) { - if (program.getIntermediate((EShLanguage)stage)) - glslang::GlslangToBil(*program.getIntermediate((EShLanguage)stage)); + if (program.getIntermediate((EShLanguage)stage)) { + std::vector bil; + glslang::GlslangToBil(*program.getIntermediate((EShLanguage)stage), bil); + const char* name; + switch (stage) { + case EShLangVertex: name = "vert"; break; + case EShLangTessControl: name = "tesc"; break; + case EShLangTessEvaluation: name = "tese"; break; + case EShLangGeometry: name = "geom"; break; + case EShLangFragment: name = "frag"; break; + case EShLangCompute: name = "comp"; break; + default: name = "unknown"; break; + } + glbil::Disassemble(std::cout, bil); + glslang::OutputBil(bil, name); + } } } } diff --git a/Todo.txt b/Todo.txt index 5f8b254b..2b49dbc6 100644 --- a/Todo.txt +++ b/Todo.txt @@ -85,7 +85,7 @@ Shader Functionality to Implement/Finish + frexp/ldexp + packUnorm4x8(),packSnorm4x8(), unpackUnorm4x8(), unpackSnorm4x8() + 2DMS samplers and images - - inheritance of memory qualifiers in block members + + inheritance of memory qualifiers in block members GLSL 1.2 + Handle multiple compilation units per stage + Allow initializers on uniform declarations diff --git a/glslang/MachineIndependent/preprocessor/PpContext.h b/glslang/MachineIndependent/preprocessor/PpContext.h index 4823b57f..c75febf7 100644 --- a/glslang/MachineIndependent/preprocessor/PpContext.h +++ b/glslang/MachineIndependent/preprocessor/PpContext.h @@ -373,8 +373,74 @@ protected: public: tStringInput(TPpContext* pp, TInputScanner& i) : tInput(pp), input(&i) { } virtual int scan(TPpToken*); - virtual int getch(); - virtual void ungetch(); + + // Scanner used to get source stream characters. + // - Escaped newlines are handled here, invisibly to the caller. + // - All forms of newline are handled, and turned into just a '\n'. + int tStringInput::getch() + { + int ch = input->get(); + + if (ch == '\\') { + // Move past escaped newlines, as many as sequentially exist + do { + if (input->peek() == '\r' || input->peek() == '\n') { + bool allowed = pp->parseContext.lineContinuationCheck(input->getSourceLoc(), pp->inComment); + if (! allowed && pp->inComment) + return '\\'; + + // escape one newline now + ch = input->get(); + int nextch = input->get(); + if (ch == '\r' && nextch == '\n') + ch = input->get(); + else + ch = nextch; + } else + return '\\'; + } while (ch == '\\'); + } + + // handle any non-escaped newline + if (ch == '\r' || ch == '\n') { + if (ch == '\r' && input->peek() == '\n') + ch = input->get(); + return '\n'; + } + + return ch; + } + + // Scanner used to backup the source stream characters. Newlines are + // handled here, invisibly to the caller, meaning have to undo exactly + // what getch() above does (e.g., don't leave things in the middle of a + // sequence of escaped newlines). + void tStringInput::ungetch() + { + input->unget(); + + do { + int ch = input->peek(); + if (ch == '\r' || ch == '\n') { + if (ch == '\n') { + // correct for two-character newline + input->unget(); + if (input->peek() != '\r') + input->get(); + } + // now in front of a complete newline, move past an escape character + input->unget(); + if (input->peek() == '\\') + input->unget(); + else { + input->get(); + break; + } + } else + break; + } while (true); + } + protected: TInputScanner* input; }; diff --git a/glslang/MachineIndependent/preprocessor/PpScanner.cpp b/glslang/MachineIndependent/preprocessor/PpScanner.cpp index 4fa7ad5a..afeff0fd 100644 --- a/glslang/MachineIndependent/preprocessor/PpScanner.cpp +++ b/glslang/MachineIndependent/preprocessor/PpScanner.cpp @@ -669,77 +669,6 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) } } -// -// Scanner used to get source stream characters. -// - Escaped newlines are handled here, invisibly to the caller. -// - All forms of newline are handled, and turned into just a '\n'. -// -int TPpContext::tStringInput::getch() -{ - int ch = input->get(); - - if (ch == '\\') { - // Move past escaped newlines, as many as sequentially exist - do { - if (input->peek() == '\r' || input->peek() == '\n') { - bool allowed = pp->parseContext.lineContinuationCheck(input->getSourceLoc(), pp->inComment); - if (! allowed && pp->inComment) - return '\\'; - - // escape one newline now - ch = input->get(); - int nextch = input->get(); - if (ch == '\r' && nextch == '\n') - ch = input->get(); - else - ch = nextch; - } else - return '\\'; - } while (ch == '\\'); - } - - // handle any non-escaped newline - if (ch == '\r' || ch == '\n') { - if (ch == '\r' && input->peek() == '\n') - ch = input->get(); - return '\n'; - } - - return ch; -} - -// -// Scanner used to backup the source stream characters. Newlines are -// handled here, invisibly to the caller, meaning have to undo exactly -// what getch() above does (e.g., don't leave things in the middle of a -// sequence of escaped newlines). -// -void TPpContext::tStringInput::ungetch() -{ - input->unget(); - - do { - int ch = input->peek(); - if (ch == '\r' || ch == '\n') { - if (ch == '\n') { - // correct for two-character newline - input->unget(); - if (input->peek() != '\r') - input->get(); - } - // now in front of a complete newline, move past an escape character - input->unget(); - if (input->peek() == '\\') - input->unget(); - else { - input->get(); - break; - } - } else - break; - } while (true); -} - // // The main functional entry-point into the preprocessor, which will // scan the source strings to figure out and return the next processing token.