1 // 2 // Copyright 2020 The ANGLE Project Authors. All rights reserved. 3 // Use of this source code is governed by a BSD-style license that can be 4 // found in the LICENSE file. 5 // 6 // RunAtTheBeginningOfShader.cpp: Add code to be run at the beginning of the shader. 7 // void main() { body } 8 // => 9 // void main() 10 // { 11 // codeToRun 12 // body 13 // } 14 // 15 16 #include "compiler/translator/tree_util/RunAtTheBeginningOfShader.h" 17 18 #include "compiler/translator/Compiler.h" 19 #include "compiler/translator/IntermNode.h" 20 #include "compiler/translator/StaticType.h" 21 #include "compiler/translator/SymbolTable.h" 22 #include "compiler/translator/tree_util/FindMain.h" 23 #include "compiler/translator/tree_util/IntermNode_util.h" 24 #include "compiler/translator/tree_util/IntermTraverse.h" 25 26 namespace sh 27 { 28 RunAtTheBeginningOfShader(TCompiler * compiler,TIntermBlock * root,TIntermNode * codeToRun)29bool RunAtTheBeginningOfShader(TCompiler *compiler, TIntermBlock *root, TIntermNode *codeToRun) 30 { 31 TIntermFunctionDefinition *main = FindMain(root); 32 main->getBody()->insertStatement(0, codeToRun); 33 return compiler->validateAST(root); 34 } 35 36 } // namespace sh 37