Commit 5f579b1b by Olli Etuaho

Improve handling of internal function calls

Many parts of the shader translator that deal with function calls have been written without internal function calls in mind. Fix some of these so that they can handle internal function calls. -Fix TLValueTrackingTraverser handling a shader where there are an internal and non-internal function of the same name. -Maintain internalness when shallow copying function calls in SeparateExpressionReturningArrays and ArrayReturnValueToOutParameter AST transformations. -Output function internalness in intermOut. BUG=angleproject:1116 TEST=angle_unittests Change-Id: Ic65e2803062b807651f1b3952409face6aceb780 Reviewed-on: https://chromium-review.googlesource.com/303353Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent e623bd46
......@@ -41,7 +41,7 @@ TIntermAggregate *CreateReplacementCall(TIntermAggregate *originalCall, TIntermT
TIntermAggregate *replacementCall = new TIntermAggregate(EOpFunctionCall);
replacementCall->setType(TType(EbtVoid));
replacementCall->setUserDefined();
replacementCall->setName(originalCall->getName());
replacementCall->setNameObj(originalCall->getNameObj());
replacementCall->setFunctionId(originalCall->getFunctionId());
replacementCall->setLine(originalCall->getLine());
TIntermSequence *replacementParameters = replacementCall->getSequence();
......@@ -117,7 +117,7 @@ bool ArrayReturnValueToOutParameterTraverser::visitAggregate(Visit visit, TInter
CopyAggregateChildren(node, replacement);
replacement->getSequence()->push_back(CreateReturnValueOutSymbol(node->getType()));
replacement->setUserDefined();
replacement->setName(node->getName());
replacement->setNameObj(node->getNameObj());
replacement->setFunctionId(node->getFunctionId());
replacement->setLine(node->getLine());
replacement->setType(TType(EbtVoid));
......
......@@ -894,7 +894,7 @@ class TLValueTrackingTraverser : public TIntermTraverser
bool operatorRequiresLValue() const { return mOperatorRequiresLValue; }
// Add a function encountered during traversal to the function map.
void addToFunctionMap(const TString &name, TIntermSequence *paramSequence);
void addToFunctionMap(const TName &name, TIntermSequence *paramSequence);
// Return the parameters sequence from the function definition or prototype.
TIntermSequence *getFunctionParameters(const TIntermAggregate *callNode);
......@@ -906,13 +906,20 @@ class TLValueTrackingTraverser : public TIntermTraverser
bool mOperatorRequiresLValue;
bool mInFunctionCallOutParameter;
struct TStringComparator
struct TNameComparator
{
bool operator()(const TString &a, const TString &b) const { return a.compare(b) < 0; }
bool operator()(const TName &a, const TName &b) const
{
int compareResult = a.getString().compare(b.getString());
if (compareResult != 0)
return compareResult < 0;
// Internal functions may have same names as non-internal functions.
return !a.isInternal() && b.isInternal();
}
};
// Map from mangled function names to their parameter sequences
TMap<TString, TIntermSequence *, TStringComparator> mFunctionMap;
TMap<TName, TIntermSequence *, TNameComparator> mFunctionMap;
const TSymbolTable &mSymbolTable;
const int mShaderVersion;
......
......@@ -160,7 +160,7 @@ void TIntermTraverser::nextTemporaryIndex()
++(*mTemporaryIndex);
}
void TLValueTrackingTraverser::addToFunctionMap(const TString &name, TIntermSequence *paramSequence)
void TLValueTrackingTraverser::addToFunctionMap(const TName &name, TIntermSequence *paramSequence)
{
mFunctionMap[name] = paramSequence;
}
......@@ -168,13 +168,13 @@ void TLValueTrackingTraverser::addToFunctionMap(const TString &name, TIntermSequ
bool TLValueTrackingTraverser::isInFunctionMap(const TIntermAggregate *callNode) const
{
ASSERT(callNode->getOp() == EOpFunctionCall);
return (mFunctionMap.find(callNode->getName()) != mFunctionMap.end());
return (mFunctionMap.find(callNode->getNameObj()) != mFunctionMap.end());
}
TIntermSequence *TLValueTrackingTraverser::getFunctionParameters(const TIntermAggregate *callNode)
{
ASSERT(isInFunctionMap(callNode));
return mFunctionMap[callNode->getName()];
return mFunctionMap[callNode->getNameObj()];
}
void TLValueTrackingTraverser::setInFunctionCallOutParameter(bool inOutParameter)
......@@ -426,11 +426,11 @@ void TLValueTrackingTraverser::traverseAggregate(TIntermAggregate *node)
TIntermAggregate *params = sequence->front()->getAsAggregate();
ASSERT(params != nullptr);
ASSERT(params->getOp() == EOpParameters);
addToFunctionMap(node->getName(), params->getSequence());
addToFunctionMap(node->getNameObj(), params->getSequence());
break;
}
case EOpPrototype:
addToFunctionMap(node->getName(), sequence);
addToFunctionMap(node->getNameObj(), sequence);
break;
default:
break;
......
......@@ -64,7 +64,7 @@ TIntermAggregate *CopyAggregateNode(TIntermAggregate *node)
{
copyNode->setUserDefined();
}
copyNode->setName(node->getName());
copyNode->setNameObj(node->getNameObj());
return copyNode;
}
......
......@@ -10,6 +10,12 @@
namespace
{
void OutputFunction(TInfoSinkBase &out, const char *str, TIntermAggregate *node)
{
const char *internal = node->getNameObj().isInternal() ? " (internal function)" : "";
out << str << internal << ": " << node->getNameObj().getString();
}
//
// Two purposes:
// 1. Show an example of how to iterate tree. Functions can
......@@ -395,10 +401,10 @@ bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
{
case EOpSequence: out << "Sequence\n"; return true;
case EOpComma: out << "Comma\n"; return true;
case EOpFunction: out << "Function Definition: " << node->getName(); break;
case EOpFunctionCall: out << "Function Call: " << node->getName(); break;
case EOpFunction: OutputFunction(out, "Function Definition", node); break;
case EOpFunctionCall: OutputFunction(out, "Function Call", node); break;
case EOpParameters: out << "Function Parameters: "; break;
case EOpPrototype: out << "Function Prototype: " << node->getName(); break;
case EOpPrototype: OutputFunction(out, "Function Prototype", node); break;
case EOpConstructFloat: out << "Construct float"; break;
case EOpConstructVec2: out << "Construct vec2"; break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment