Simplify AST transformations that need to find main
Share code for finding the main function from the AST between
InitializeVariables, DeferGlobalInitializers,
EmulateGLFragColorBroadcast and UseInterfaceBlockFields. This makes
InitializeVariables simpler in particular, as it doesn't need an AST
traverser anymore.
BUG=angleproject:2033
TEST=angle_unittests, WebGL conformance tests
Change-Id: I14c994bbde58a904f6684d2f0b72bd8004f70902
Reviewed-on: https://chromium-review.googlesource.com/501166
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/DeferGlobalInitializers.cpp b/src/compiler/translator/DeferGlobalInitializers.cpp
index cf7ebb5..c1585a5 100644
--- a/src/compiler/translator/DeferGlobalInitializers.cpp
+++ b/src/compiler/translator/DeferGlobalInitializers.cpp
@@ -12,6 +12,7 @@
#include "compiler/translator/DeferGlobalInitializers.h"
+#include "compiler/translator/FindMain.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/SymbolTable.h"
@@ -116,19 +117,14 @@
root->getSequence()->push_back(functionDefinition);
// Insert call into main function
- for (TIntermNode *node : *root->getSequence())
- {
- TIntermFunctionDefinition *nodeFunction = node->getAsFunctionDefinition();
- if (nodeFunction != nullptr && nodeFunction->getFunctionSymbolInfo()->isMain())
- {
- TIntermAggregate *functionCallNode = CreateInternalFunctionCallNode(
- TType(EbtVoid), functionName, initFunctionId, nullptr);
+ TIntermFunctionDefinition *main = FindMain(root);
+ ASSERT(main != nullptr);
+ TIntermAggregate *functionCallNode =
+ CreateInternalFunctionCallNode(TType(EbtVoid), functionName, initFunctionId, nullptr);
- TIntermBlock *mainBody = nodeFunction->getBody();
- ASSERT(mainBody != nullptr);
- mainBody->getSequence()->insert(mainBody->getSequence()->begin(), functionCallNode);
- }
- }
+ TIntermBlock *mainBody = main->getBody();
+ ASSERT(mainBody != nullptr);
+ mainBody->getSequence()->insert(mainBody->getSequence()->begin(), functionCallNode);
}
} // namespace