Commit b4769581 by Alexis Hetu Committed by Alexis Hétu

Binary math cleanup

Moved functionality related to binary math into TParseContext. No WebGL tests were hurt in the making of this CL. Change-Id: I51b9aa8f98ceedc4e4a93b4b907d264086157c18 Reviewed-on: https://swiftshader-review.googlesource.com/3512Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 15ae36c4
...@@ -3055,6 +3055,91 @@ TIntermCase *TParseContext::addDefault(const TSourceLoc &loc) ...@@ -3055,6 +3055,91 @@ TIntermCase *TParseContext::addDefault(const TSourceLoc &loc)
return node; return node;
} }
TIntermTyped *TParseContext::addBinaryMathInternal(TOperator op, TIntermTyped *left, TIntermTyped *right,
const TSourceLoc &loc)
{
if(!binaryOpCommonCheck(op, left, right, loc))
return nullptr;
switch(op)
{
case EOpEqual:
case EOpNotEqual:
break;
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
ASSERT(!left->isArray() && !right->isArray());
if(left->isMatrix() || left->isVector() ||
left->getBasicType() == EbtStruct)
{
return nullptr;
}
break;
case EOpLogicalOr:
case EOpLogicalXor:
case EOpLogicalAnd:
ASSERT(!left->isArray() && !right->isArray());
if(left->getBasicType() != EbtBool ||
left->isMatrix() || left->isVector())
{
return nullptr;
}
break;
case EOpAdd:
case EOpSub:
case EOpDiv:
case EOpMul:
ASSERT(!left->isArray() && !right->isArray());
if(left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool)
{
return nullptr;
}
break;
case EOpIMod:
ASSERT(!left->isArray() && !right->isArray());
// Note that this is only for the % operator, not for mod()
if(left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool || left->getBasicType() == EbtFloat)
{
return nullptr;
}
break;
// Note that for bitwise ops, type checking is done in promote() to
// share code between ops and compound assignment
default:
break;
}
return intermediate.addBinaryMath(op, left, right, loc);
}
TIntermTyped *TParseContext::addBinaryMath(TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc)
{
TIntermTyped *node = addBinaryMathInternal(op, left, right, loc);
if(node == 0)
{
binaryOpError(loc, getOperatorString(op), left->getCompleteString(), right->getCompleteString());
recover();
return left;
}
return node;
}
TIntermTyped *TParseContext::addBinaryMathBooleanResult(TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc)
{
TIntermTyped *node = addBinaryMathInternal(op, left, right, loc);
if(node == 0)
{
binaryOpError(loc, getOperatorString(op), left->getCompleteString(), right->getCompleteString());
recover();
ConstantUnion *unionArray = new ConstantUnion[1];
unionArray->setBConst(false);
return intermediate.addConstantUnion(unionArray, TType(EbtBool, EbpUndefined, EvqConstExpr), loc);
}
return node;
}
TIntermBranch *TParseContext::addBranch(TOperator op, const TSourceLoc &loc) TIntermBranch *TParseContext::addBranch(TOperator op, const TSourceLoc &loc)
{ {
switch(op) switch(op)
......
...@@ -200,6 +200,8 @@ struct TParseContext { ...@@ -200,6 +200,8 @@ struct TParseContext {
TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc); TIntermTyped *addUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc); TIntermTyped *addUnaryMathLValue(TOperator op, TIntermTyped *child, const TSourceLoc &loc);
TIntermTyped *addBinaryMath(TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
TIntermTyped *addBinaryMathBooleanResult(TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc); TIntermBranch *addBranch(TOperator op, const TSourceLoc &loc);
TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc); TIntermBranch *addBranch(TOperator op, TIntermTyped *returnValue, const TSourceLoc &loc);
...@@ -207,6 +209,8 @@ struct TParseContext { ...@@ -207,6 +209,8 @@ struct TParseContext {
private: private:
bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable); bool declareVariable(const TSourceLoc &line, const TString &identifier, const TType &type, TVariable **variable);
TIntermTyped *addBinaryMathInternal(TOperator op, TIntermTyped *left, TIntermTyped *right, const TSourceLoc &loc);
// The funcReturnType parameter is expected to be non-null when the operation is a built-in function. // The funcReturnType parameter is expected to be non-null when the operation is a built-in function.
// It is expected to be null for other unary operators. // It is expected to be null for other unary operators.
TIntermTyped *createUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc, const TType *funcReturnType); TIntermTyped *createUnaryMath(TOperator op, TIntermTyped *child, const TSourceLoc &loc, const TType *funcReturnType);
......
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