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
14namespace sh
15{
16
17class TSymbolTable;
18class TVariable;
19
20TIntermFunctionPrototype *CreateInternalFunctionPrototypeNode(const TFunction &func);
21TIntermFunctionDefinition *CreateInternalFunctionDefinitionNode(const TFunction &func,
22 TIntermBlock *functionBody);
23
24TIntermTyped *CreateZeroNode(const TType &type);
25TIntermConstantUnion *CreateIndexNode(int index);
26TIntermConstantUnion *CreateBoolNode(bool value);
27
28TVariable *CreateTempVariable(TSymbolTable *symbolTable, const TType *type);
29TVariable *CreateTempVariable(TSymbolTable *symbolTable, const TType *type, TQualifier qualifier);
30
31TIntermSymbol *CreateTempSymbolNode(const TVariable *tempVariable);
32TIntermDeclaration *CreateTempDeclarationNode(const TVariable *tempVariable);
33TIntermDeclaration *CreateTempInitDeclarationNode(const TVariable *tempVariable,
34 TIntermTyped *initializer);
35TIntermBinary *CreateTempAssignmentNode(const TVariable *tempVariable, TIntermTyped *rightNode);
36
37TVariable *DeclareTempVariable(TSymbolTable *symbolTable,
38 const TType *type,
39 TQualifier qualifier,
40 TIntermDeclaration **declarationOut);
41TVariable *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.
49TIntermBlock *EnsureBlock(TIntermNode *node);
50
51// Should be called from inside Compiler::compileTreeImpl() where the global level is in scope.
52TIntermSymbol *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.
57TIntermSymbol *ReferenceBuiltInVariable(const ImmutableString &name,
58 const TSymbolTable &symbolTable,
59 int shaderVersion);
60
61TIntermTyped *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_