Hash :
daaff1cc
Author :
Date :
2017-07-05T18:03:26
Set correct symbol ids when referring to GLSL built-ins The symbol ids are fetched from the symbol table. A new utility function is added to make this more convenient. BUG=angleproject:1490 TEST=angle_unittests, angle_end2end_tests Change-Id: I780430e3386f6599503d8290c568ca9bc9cad147 Reviewed-on: https://chromium-review.googlesource.com/559535 Commit-Queue: Olli Etuaho <oetuaho@nvidia.com> Reviewed-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
//
// Copyright (c) 2017 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// IntermNode_util.cpp: High-level utilities for creating AST nodes and node hierarchies. Mostly
// meant to be used in AST transforms.
#include "compiler/translator/IntermNode_util.h"
#include "compiler/translator/SymbolTable.h"
namespace sh
{
namespace
{
TName GetInternalFunctionName(const char *name)
{
TString nameStr(name);
TName nameObj(nameStr);
nameObj.setInternal(true);
return nameObj;
}
} // anonymous namespace
TIntermFunctionPrototype *CreateInternalFunctionPrototypeNode(const TType &returnType,
const char *name,
const TSymbolUniqueId &functionId)
{
TIntermFunctionPrototype *functionNode = new TIntermFunctionPrototype(returnType, functionId);
functionNode->getFunctionSymbolInfo()->setNameObj(GetInternalFunctionName(name));
return functionNode;
}
TIntermFunctionDefinition *CreateInternalFunctionDefinitionNode(const TType &returnType,
const char *name,
TIntermBlock *functionBody,
const TSymbolUniqueId &functionId)
{
TIntermFunctionPrototype *prototypeNode =
CreateInternalFunctionPrototypeNode(returnType, name, functionId);
return new TIntermFunctionDefinition(prototypeNode, functionBody);
}
TIntermAggregate *CreateInternalFunctionCallNode(const TType &returnType,
const char *name,
const TSymbolUniqueId &functionId,
TIntermSequence *arguments)
{
TIntermAggregate *functionNode = TIntermAggregate::CreateFunctionCall(
returnType, functionId, GetInternalFunctionName(name), arguments);
return functionNode;
}
TIntermTyped *CreateZeroNode(const TType &type)
{
TType constType(type);
constType.setQualifier(EvqConst);
if (!type.isArray() && type.getBasicType() != EbtStruct)
{
size_t size = constType.getObjectSize();
TConstantUnion *u = new TConstantUnion[size];
for (size_t i = 0; i < size; ++i)
{
switch (type.getBasicType())
{
case EbtFloat:
u[i].setFConst(0.0f);
break;
case EbtInt:
u[i].setIConst(0);
break;
case EbtUInt:
u[i].setUConst(0u);
break;
case EbtBool:
u[i].setBConst(false);
break;
default:
// CreateZeroNode is called by ParseContext that keeps parsing even when an
// error occurs, so it is possible for CreateZeroNode to be called with
// non-basic types. This happens only on error condition but CreateZeroNode
// needs to return a value with the correct type to continue the typecheck.
// That's why we handle non-basic type by setting whatever value, we just need
// the type to be right.
u[i].setIConst(42);
break;
}
}
TIntermConstantUnion *node = new TIntermConstantUnion(u, constType);
return node;
}
if (type.getBasicType() == EbtVoid)
{
// Void array. This happens only on error condition, similarly to the case above. We don't
// have a constructor operator for void, so this needs special handling. We'll end up with a
// value without the array type, but that should not be a problem.
constType.clearArrayness();
return CreateZeroNode(constType);
}
TIntermSequence *arguments = new TIntermSequence();
if (type.isArray())
{
TType elementType(type);
elementType.clearArrayness();
size_t arraySize = type.getArraySize();
for (size_t i = 0; i < arraySize; ++i)
{
arguments->push_back(CreateZeroNode(elementType));
}
}
else
{
ASSERT(type.getBasicType() == EbtStruct);
TStructure *structure = type.getStruct();
for (const auto &field : structure->fields())
{
arguments->push_back(CreateZeroNode(*field->type()));
}
}
return TIntermAggregate::CreateConstructor(constType, arguments);
}
TIntermConstantUnion *CreateIndexNode(int index)
{
TConstantUnion *u = new TConstantUnion[1];
u[0].setIConst(index);
TType type(EbtInt, EbpUndefined, EvqConst, 1);
TIntermConstantUnion *node = new TIntermConstantUnion(u, type);
return node;
}
TIntermConstantUnion *CreateBoolNode(bool value)
{
TConstantUnion *u = new TConstantUnion[1];
u[0].setBConst(value);
TType type(EbtBool, EbpUndefined, EvqConst, 1);
TIntermConstantUnion *node = new TIntermConstantUnion(u, type);
return node;
}
TIntermBlock *EnsureBlock(TIntermNode *node)
{
if (node == nullptr)
return nullptr;
TIntermBlock *blockNode = node->getAsBlock();
if (blockNode != nullptr)
return blockNode;
blockNode = new TIntermBlock();
blockNode->setLine(node->getLine());
blockNode->appendStatement(node);
return blockNode;
}
TIntermSymbol *ReferenceGlobalVariable(const TString &name, const TSymbolTable &symbolTable)
{
TVariable *var = reinterpret_cast<TVariable *>(symbolTable.findGlobal(name));
ASSERT(var);
return new TIntermSymbol(var->getUniqueId(), name, var->getType());
}
TIntermSymbol *ReferenceBuiltInVariable(const TString &name,
const TSymbolTable &symbolTable,
int shaderVersion)
{
const TVariable *var =
reinterpret_cast<const TVariable *>(symbolTable.findBuiltIn(name, shaderVersion));
ASSERT(var);
return new TIntermSymbol(var->getUniqueId(), name, var->getType());
}
} // namespace sh