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 access desktop GLSL built-ins that are hidden from the parser.
56 TIntermSymbol *ReferenceBuiltInVariable(const ImmutableString &name,
57                                         const TSymbolTable &symbolTable,
58                                         int shaderVersion);
59 
60 TIntermTyped *CreateBuiltInFunctionCallNode(const char *name,
61                                             TIntermSequence *arguments,
62                                             const TSymbolTable &symbolTable,
63                                             int shaderVersion);
64 
65 }  // namespace sh
66 
67 #endif  // COMPILER_TRANSLATOR_INTERMNODEUTIL_H_