- Moved the implementation for ShCompile to the compiler class so that internal details about compiler can be encapsulated. Now we do not need to expose built-in symbol table.
- Fixed a few const violations.
- Added CollectAttribsUniforms class.
BUG=26
Review URL: http://codereview.appspot.com/2263041
git-svn-id: https://angleproject.googlecode.com/svn/trunk@437 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/ShaderLang.cpp b/src/compiler/ShaderLang.cpp
index b83e736..5383f7b 100644
--- a/src/compiler/ShaderLang.cpp
+++ b/src/compiler/ShaderLang.cpp
@@ -17,77 +17,6 @@
#include "compiler/ShHandle.h"
#include "compiler/SymbolTable.h"
-static bool InitializeSymbolTable(
- const TBuiltInStrings& builtInStrings,
- EShLanguage language, EShSpec spec, const TBuiltInResource& resources,
- TInfoSink& infoSink, TSymbolTable& symbolTable)
-{
- TIntermediate intermediate(infoSink);
- TExtensionBehavior extBehavior;
- TParseContext parseContext(symbolTable, extBehavior, intermediate, language, spec, infoSink);
-
- GlobalParseContext = &parseContext;
-
- setInitialState();
-
- assert(symbolTable.isEmpty());
- //
- // Parse the built-ins. This should only happen once per
- // language symbol table.
- //
- // Push the symbol table to give it an initial scope. This
- // push should not have a corresponding pop, so that built-ins
- // are preserved, and the test for an empty table fails.
- //
- symbolTable.push();
-
- //Initialize the Preprocessor
- if (InitPreprocessor())
- {
- infoSink.info.message(EPrefixInternalError, "Unable to intialize the Preprocessor");
- return false;
- }
-
- for (TBuiltInStrings::const_iterator i = builtInStrings.begin(); i != builtInStrings.end(); ++i)
- {
- const char* builtInShaders[1];
- int builtInLengths[1];
-
- builtInShaders[0] = (*i).c_str();
- builtInLengths[0] = (int) (*i).size();
-
- if (builtInLengths[0] && PaParseStrings(const_cast<char**>(builtInShaders), builtInLengths, 1, parseContext) != 0)
- {
- infoSink.info.message(EPrefixInternalError, "Unable to parse built-ins");
- return false;
- }
- }
-
- IdentifyBuiltIns(language, spec, resources, symbolTable);
-
- FinalizePreprocessor();
-
- return true;
-}
-
-static bool GenerateBuiltInSymbolTable(
- EShLanguage language, EShSpec spec, const TBuiltInResource& resources,
- TInfoSink& infoSink, TSymbolTable& symbolTable)
-{
- TBuiltIns builtIns;
-
- builtIns.initialize(language, spec, resources);
- return InitializeSymbolTable(builtIns.getBuiltInStrings(), language, spec, resources, infoSink, symbolTable);
-}
-
-static void DefineExtensionMacros(const TExtensionBehavior& extBehavior)
-{
- for (TExtensionBehavior::const_iterator iter = extBehavior.begin();
- iter != extBehavior.end(); ++iter) {
- PredefineIntMacro(iter->first.c_str(), 1);
- }
-}
-
//
// This is the platform independent interface between an OGL driver
// and the shading language compiler.
@@ -149,11 +78,10 @@
return 0;
// Generate built-in symbol table.
- if (!GenerateBuiltInSymbolTable(language, spec, *resources, compiler->getInfoSink(), compiler->getSymbolTable())) {
+ if (!compiler->Init(*resources)) {
ShDestruct(base);
return 0;
}
- InitExtensionBehavior(*resources, compiler->getExtensionBehavior());
return reinterpret_cast<void*>(base);
}
@@ -192,79 +120,11 @@
TCompiler* compiler = base->getAsCompiler();
if (compiler == 0)
return 0;
-
+
GlobalPoolAllocator.push();
- TInfoSink& infoSink = compiler->getInfoSink();
- infoSink.info.erase();
- infoSink.debug.erase();
- infoSink.obj.erase();
- if (numStrings == 0)
- return 1;
+ bool success = compiler->compile(shaderStrings, numStrings, compileOptions);
- TIntermediate intermediate(infoSink);
- TSymbolTable& symbolTable = compiler->getSymbolTable();
- const TExtensionBehavior& extBehavior = compiler->getExtensionBehavior();
-
- TParseContext parseContext(symbolTable, extBehavior, intermediate,
- compiler->getLanguage(), compiler->getSpec(), infoSink);
- GlobalParseContext = &parseContext;
-
- setInitialState();
-
- InitPreprocessor();
- DefineExtensionMacros(extBehavior);
- //
- // Parse the application's shaders. All the following symbol table
- // work will be throw-away, so push a new allocation scope that can
- // be thrown away, then push a scope for the current shader's globals.
- //
- bool success = true;
-
- symbolTable.push();
- if (!symbolTable.atGlobalLevel())
- parseContext.infoSink.info.message(EPrefixInternalError, "Wrong symbol table level");
-
- if (PaParseStrings(const_cast<char**>(shaderStrings), 0, numStrings, parseContext))
- success = false;
-
- if (success && parseContext.treeRoot) {
- success = intermediate.postProcess(parseContext.treeRoot, parseContext.language);
- if (success) {
- if (compileOptions & EShOptIntermediateTree)
- intermediate.outputTree(parseContext.treeRoot);
-
- //
- // Call the machine dependent compiler
- //
- if (compileOptions & EShOptObjectCode)
- success = compiler->compile(parseContext.treeRoot);
-
- // TODO(alokp): Extract attributes and uniforms.
- //if (compileOptions & EShOptAttribsUniforms)
- }
- } else if (!success) {
- parseContext.infoSink.info.prefix(EPrefixError);
- parseContext.infoSink.info << parseContext.numErrors << " compilation errors. No code generated.\n\n";
- success = false;
- if (compileOptions & EShOptIntermediateTree)
- intermediate.outputTree(parseContext.treeRoot);
- } else if (!parseContext.treeRoot) {
- parseContext.error(1, "Unexpected end of file.", "", "");
- parseContext.infoSink.info << parseContext.numErrors << " compilation errors. No code generated.\n\n";
- success = false;
- }
-
- intermediate.remove(parseContext.treeRoot);
-
- //
- // Ensure symbol table is returned to the built-in level,
- // throwing away all but the built-ins.
- //
- while (!symbolTable.atBuiltInLevel())
- symbolTable.pop();
-
- FinalizePreprocessor();
//
// Throw away all the temporary memory used by the compilation process.
//