| 1 | // |
| 2 | // Copyright (c) 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 | |
| 14 | namespace sh |
| 15 | { |
| 16 | |
| 17 | class TSymbolTable; |
| 18 | class TVariable; |
| 19 | |
| 20 | TIntermFunctionPrototype *CreateInternalFunctionPrototypeNode(const TFunction &func); |
| 21 | TIntermFunctionDefinition *CreateInternalFunctionDefinitionNode(const TFunction &func, |
| 22 | TIntermBlock *functionBody); |
| 23 | |
| 24 | TIntermTyped *CreateZeroNode(const TType &type); |
| 25 | TIntermConstantUnion *CreateIndexNode(int index); |
| 26 | TIntermConstantUnion *CreateBoolNode(bool value); |
| 27 | |
| 28 | TVariable *CreateTempVariable(TSymbolTable *symbolTable, const TType *type); |
| 29 | TVariable *CreateTempVariable(TSymbolTable *symbolTable, const TType *type, TQualifier qualifier); |
| 30 | |
| 31 | TIntermSymbol *CreateTempSymbolNode(const TVariable *tempVariable); |
| 32 | TIntermDeclaration *CreateTempDeclarationNode(const TVariable *tempVariable); |
| 33 | TIntermDeclaration *CreateTempInitDeclarationNode(const TVariable *tempVariable, |
| 34 | TIntermTyped *initializer); |
| 35 | TIntermBinary *CreateTempAssignmentNode(const TVariable *tempVariable, TIntermTyped *rightNode); |
| 36 | |
| 37 | TVariable *DeclareTempVariable(TSymbolTable *symbolTable, |
| 38 | const TType *type, |
| 39 | TQualifier qualifier, |
| 40 | TIntermDeclaration **declarationOut); |
| 41 | TVariable *DeclareTempVariable(TSymbolTable *symbolTable, |
| 42 | TIntermTyped *initializer, |
| 43 | TQualifier qualifier, |
| 44 | TIntermDeclaration **declarationOut); |
| 45 | |
| 46 | // If the input node is nullptr, return nullptr. |
| 47 | // If the input node is a block node, return it. |
| 48 | // If the input node is not a block node, put it inside a block node and return that. |
| 49 | TIntermBlock *EnsureBlock(TIntermNode *node); |
| 50 | |
| 51 | // Should be called from inside Compiler::compileTreeImpl() where the global level is in scope. |
| 52 | TIntermSymbol *ReferenceGlobalVariable(const ImmutableString &name, |
| 53 | const TSymbolTable &symbolTable); |
| 54 | |
| 55 | // Note: this can't access desktop GLSL built-ins. Those can only be accessed directly through |
| 56 | // BuiltIn_autogen.h. |
| 57 | TIntermSymbol *ReferenceBuiltInVariable(const ImmutableString &name, |
| 58 | const TSymbolTable &symbolTable, |
| 59 | int shaderVersion); |
| 60 | |
| 61 | TIntermTyped *CreateBuiltInFunctionCallNode(const char *name, |
| 62 | TIntermSequence *arguments, |
| 63 | const TSymbolTable &symbolTable, |
| 64 | int shaderVersion); |
| 65 | |
| 66 | } // namespace sh |
| 67 | |
| 68 | #endif // COMPILER_TRANSLATOR_INTERMNODEUTIL_H_ |