• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 *CreateUIntNode(unsigned int value);
29 TIntermConstantUnion *CreateBoolNode(bool value);
30 
31 TVariable *CreateTempVariable(TSymbolTable *symbolTable, const TType *type);
32 TVariable *CreateTempVariable(TSymbolTable *symbolTable, const TType *type, TQualifier qualifier);
33 
34 TIntermSymbol *CreateTempSymbolNode(const TVariable *tempVariable);
35 TIntermDeclaration *CreateTempDeclarationNode(const TVariable *tempVariable);
36 TIntermDeclaration *CreateTempInitDeclarationNode(const TVariable *tempVariable,
37                                                   TIntermTyped *initializer);
38 TIntermBinary *CreateTempAssignmentNode(const TVariable *tempVariable, TIntermTyped *rightNode);
39 
40 TVariable *DeclareTempVariable(TSymbolTable *symbolTable,
41                                const TType *type,
42                                TQualifier qualifier,
43                                TIntermDeclaration **declarationOut);
44 TVariable *DeclareTempVariable(TSymbolTable *symbolTable,
45                                TIntermTyped *initializer,
46                                TQualifier qualifier,
47                                TIntermDeclaration **declarationOut);
48 const TVariable *DeclareInterfaceBlock(TIntermBlock *root,
49                                        TSymbolTable *symbolTable,
50                                        TFieldList *fieldList,
51                                        TQualifier qualifier,
52                                        const TMemoryQualifier &memoryQualifier,
53                                        uint32_t arraySize,
54                                        const ImmutableString &blockTypeName,
55                                        const ImmutableString &blockVariableName);
56 
57 // If the input node is nullptr, return nullptr.
58 // If the input node is a block node, return it.
59 // If the input node is not a block node, put it inside a block node and return that.
60 TIntermBlock *EnsureBlock(TIntermNode *node);
61 
62 // Should be called from inside Compiler::compileTreeImpl() where the global level is in scope.
63 TIntermSymbol *ReferenceGlobalVariable(const ImmutableString &name,
64                                        const TSymbolTable &symbolTable);
65 
66 // Note: this can't access desktop GLSL built-ins. Those can only be accessed directly through
67 // BuiltIn.h.
68 TIntermSymbol *ReferenceBuiltInVariable(const ImmutableString &name,
69                                         const TSymbolTable &symbolTable,
70                                         int shaderVersion);
71 
72 TIntermTyped *CreateBuiltInFunctionCallNode(const char *name,
73                                             TIntermSequence *arguments,
74                                             const TSymbolTable &symbolTable,
75                                             int shaderVersion);
76 
GetSwizzleIndex(TVector<int> * indexOut)77 inline void GetSwizzleIndex(TVector<int> *indexOut) {}
78 
79 template <typename T, typename... ArgsT>
GetSwizzleIndex(TVector<int> * indexOut,T arg,ArgsT...args)80 void GetSwizzleIndex(TVector<int> *indexOut, T arg, ArgsT... args)
81 {
82     indexOut->push_back(arg);
83     GetSwizzleIndex(indexOut, args...);
84 }
85 
86 template <typename... ArgsT>
CreateSwizzle(TIntermTyped * reference,ArgsT...args)87 TIntermSwizzle *CreateSwizzle(TIntermTyped *reference, ArgsT... args)
88 {
89     TVector<int> swizzleIndex;
90     GetSwizzleIndex(&swizzleIndex, args...);
91     return new TIntermSwizzle(reference, swizzleIndex);
92 }
93 
94 }  // namespace sh
95 
96 #endif  // COMPILER_TRANSLATOR_INTERMNODEUTIL_H_
97