Commit be954a23 by Gregoire Payen de La Garanderie Committed by Jamie Madill

Implement support for the binary operator '%' in the translator.

BUG=angle:854 Change-Id: If116de132dc83d93255749b54c1919a75abcb65c Reviewed-on: https://chromium-review.googlesource.com/236330Tested-by: 's avatarGregoire Payen de La Garanderie <Gregory.Payen@imgtec.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent be12fa22
......@@ -264,6 +264,7 @@ bool TIntermOperator::isAssignment() const
case EOpMatrixTimesScalarAssign:
case EOpMatrixTimesMatrixAssign:
case EOpDivAssign:
case EOpModAssign:
return true;
default:
return false;
......@@ -556,9 +557,11 @@ bool TIntermBinary::promote(TInfoSink &infoSink)
case EOpAdd:
case EOpSub:
case EOpDiv:
case EOpMod:
case EOpAddAssign:
case EOpSubAssign:
case EOpDivAssign:
case EOpModAssign:
if ((mLeft->isMatrix() && mRight->isVector()) ||
(mLeft->isVector() && mRight->isMatrix()))
{
......@@ -729,6 +732,7 @@ TIntermTyped *TIntermConstantUnion::fold(
break;
case EOpDiv:
case EOpMod:
{
tempConstArray = new ConstantUnion[objectSize];
for (size_t i = 0; i < objectSize; i++)
......
......@@ -188,7 +188,8 @@ enum TOperator
EOpVectorTimesScalarAssign,
EOpMatrixTimesScalarAssign,
EOpMatrixTimesMatrixAssign,
EOpDivAssign
EOpDivAssign,
EOpModAssign
};
class TIntermTraverser;
......
......@@ -76,7 +76,16 @@ TIntermTyped *TIntermediate::addBinaryMath(
case EOpDiv:
case EOpMul:
if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool)
{
return NULL;
}
break;
case EOpMod:
if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool || left->getBasicType() == EbtFloat)
{
return NULL;
}
break;
default:
break;
}
......
......@@ -223,6 +223,9 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node)
case EOpDivAssign:
writeTriplet(visit, "(", " /= ", ")");
break;
case EOpModAssign:
writeTriplet(visit, "(", " %= ", ")");
break;
// Notice the fall-through.
case EOpMulAssign:
case EOpVectorTimesMatrixAssign:
......@@ -341,7 +344,7 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node)
writeTriplet(visit, "(", " / ", ")");
break;
case EOpMod:
UNIMPLEMENTED();
writeTriplet(visit, "(", " % ", ")");
break;
case EOpEqual:
writeTriplet(visit, "(", " == ", ")");
......
......@@ -1564,6 +1564,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
}
break;
case EOpDivAssign: outputTriplet(visit, "(", " /= ", ")"); break;
case EOpModAssign: outputTriplet(visit, "(", " %= ", ")"); break;
case EOpIndexDirect:
{
const TType& leftType = node->getLeft()->getType();
......@@ -1651,6 +1652,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
case EOpSub: outputTriplet(visit, "(", " - ", ")"); break;
case EOpMul: outputTriplet(visit, "(", " * ", ")"); break;
case EOpDiv: outputTriplet(visit, "(", " / ", ")"); break;
case EOpMod: outputTriplet(visit, "(", " % ", ")"); break;
case EOpEqual:
case EOpNotEqual:
if (node->getLeft()->isScalar())
......
......@@ -56,6 +56,7 @@ const char *GetOperatorString(TOperator op)
case EOpAddAssign: return "+=";
case EOpSubAssign: return "-=";
case EOpDivAssign: return "/=";
case EOpModAssign: return "%=";
// Fall-through.
case EOpMulAssign:
......@@ -75,7 +76,7 @@ const char *GetOperatorString(TOperator op)
case EOpSub: return "-";
case EOpMul: return "*";
case EOpDiv: return "/";
case EOpMod: UNIMPLEMENTED(); break;
case EOpMod: return "%";
case EOpEqual: return "==";
case EOpNotEqual: return "!=";
case EOpLessThan: return "<";
......
......@@ -555,6 +555,14 @@ multiplicative_expression
$$ = $1;
}
}
| multiplicative_expression PERCENT unary_expression {
$$ = context->intermediate.addBinaryMath(EOpMod, $1, $3, @2);
if ($$ == 0) {
context->binaryOpError(@2, "%", $1->getCompleteString(), $3->getCompleteString());
context->recover();
$$ = $1;
}
}
;
additive_expression
......@@ -739,6 +747,7 @@ assignment_operator
: EQUAL { $$.op = EOpAssign; }
| MUL_ASSIGN { $$.op = EOpMulAssign; }
| DIV_ASSIGN { $$.op = EOpDivAssign; }
| MOD_ASSIGN { $$.op = EOpModAssign; }
| ADD_ASSIGN { $$.op = EOpAddAssign; }
| SUB_ASSIGN { $$.op = EOpSubAssign; }
;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -131,6 +131,9 @@ bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary *node)
case EOpDivAssign:
out << "divide second child into first child";
break;
case EOpModAssign:
out << "modulo second child into first child";
break;
case EOpIndexDirect:
out << "direct index";
break;
......@@ -159,6 +162,9 @@ bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary *node)
case EOpDiv:
out << "divide";
break;
case EOpMod:
out << "modulo";
break;
case EOpEqual:
out << "Compare Equal";
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