1 // 2 // Copyright 2017 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 // IntermNode_util.h: High-level utilities for creating AST nodes and node hierarchies. Mostly meant 7 // to be used in AST transforms. 8 9 #ifndef COMPILER_TRANSLATOR_INTERMNODEUTIL_H_ 10 #define COMPILER_TRANSLATOR_INTERMNODEUTIL_H_ 11 12 #include "compiler/translator/IntermNode.h" 13 #include "compiler/translator/tree_util/FindFunction.h" 14 15 namespace sh 16 { 17 18 class TSymbolTable; 19 class TVariable; 20 21 TIntermFunctionPrototype *CreateInternalFunctionPrototypeNode(const TFunction &func); 22 TIntermFunctionDefinition *CreateInternalFunctionDefinitionNode(const TFunction &func, 23 TIntermBlock *functionBody); 24 25 TIntermTyped *CreateZeroNode(const TType &type); 26 TIntermConstantUnion *CreateFloatNode(float value); 27 TIntermConstantUnion *CreateIndexNode(int index); 28 TIntermConstantUnion *CreateBoolNode(bool value); 29 30 TVariable *CreateTempVariable(TSymbolTable *symbolTable, const TType *type); 31 TVariable *CreateTempVariable(TSymbolTable *symbolTable, const TType *type, TQualifier qualifier); 32 33 TIntermSymbol *CreateTempSymbolNode(const TVariable *tempVariable); 34 TIntermDeclaration *CreateTempDeclarationNode(const TVariable *tempVariable); 35 TIntermDeclaration *CreateTempInitDeclarationNode(const TVariable *tempVariable, 36 TIntermTyped *initializer); 37 TIntermBinary *CreateTempAssignmentNode(const TVariable *tempVariable, TIntermTyped *rightNode); 38 39 TVariable *DeclareTempVariable(TSymbolTable *symbolTable, 40 const TType *type, 41 TQualifier qualifier, 42 TIntermDeclaration **declarationOut); 43 TVariable *DeclareTempVariable(TSymbolTable *symbolTable, 44 TIntermTyped *initializer, 45 TQualifier qualifier, 46 TIntermDeclaration **declarationOut); 47 const TVariable *DeclareInterfaceBlock(TIntermBlock *root, 48 TSymbolTable *symbolTable, 49 TFieldList *fieldList, 50 TQualifier qualifier, 51 const TMemoryQualifier &memoryQualifier, 52 uint32_t arraySize, 53 const ImmutableString &blockTypeName, 54 const ImmutableString &blockVariableName); 55 56 // If the input node is nullptr, return nullptr. 57 // If the input node is a block node, return it. 58 // If the input node is not a block node, put it inside a block node and return that. 59 TIntermBlock *EnsureBlock(TIntermNode *node); 60 61 // Should be called from inside Compiler::compileTreeImpl() where the global level is in scope. 62 TIntermSymbol *ReferenceGlobalVariable(const ImmutableString &name, 63 const TSymbolTable &symbolTable); 64 65 // Note: this can't access desktop GLSL built-ins. Those can only be accessed directly through 66 // BuiltIn_autogen.h. 67 TIntermSymbol *ReferenceBuiltInVariable(const ImmutableString &name, 68 const TSymbolTable &symbolTable, 69 int shaderVersion); 70 71 TIntermTyped *CreateBuiltInFunctionCallNode(const char *name, 72 TIntermSequence *arguments, 73 const TSymbolTable &symbolTable, 74 int shaderVersion); 75 76 } // namespace sh 77 78 #endif // COMPILER_TRANSLATOR_INTERMNODEUTIL_H_ 79