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 ...@@ -264,6 +264,7 @@ bool TIntermOperator::isAssignment() const
case EOpMatrixTimesScalarAssign: case EOpMatrixTimesScalarAssign:
case EOpMatrixTimesMatrixAssign: case EOpMatrixTimesMatrixAssign:
case EOpDivAssign: case EOpDivAssign:
case EOpModAssign:
return true; return true;
default: default:
return false; return false;
...@@ -556,9 +557,11 @@ bool TIntermBinary::promote(TInfoSink &infoSink) ...@@ -556,9 +557,11 @@ bool TIntermBinary::promote(TInfoSink &infoSink)
case EOpAdd: case EOpAdd:
case EOpSub: case EOpSub:
case EOpDiv: case EOpDiv:
case EOpMod:
case EOpAddAssign: case EOpAddAssign:
case EOpSubAssign: case EOpSubAssign:
case EOpDivAssign: case EOpDivAssign:
case EOpModAssign:
if ((mLeft->isMatrix() && mRight->isVector()) || if ((mLeft->isMatrix() && mRight->isVector()) ||
(mLeft->isVector() && mRight->isMatrix())) (mLeft->isVector() && mRight->isMatrix()))
{ {
...@@ -729,6 +732,7 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -729,6 +732,7 @@ TIntermTyped *TIntermConstantUnion::fold(
break; break;
case EOpDiv: case EOpDiv:
case EOpMod:
{ {
tempConstArray = new ConstantUnion[objectSize]; tempConstArray = new ConstantUnion[objectSize];
for (size_t i = 0; i < objectSize; i++) for (size_t i = 0; i < objectSize; i++)
......
...@@ -188,7 +188,8 @@ enum TOperator ...@@ -188,7 +188,8 @@ enum TOperator
EOpVectorTimesScalarAssign, EOpVectorTimesScalarAssign,
EOpMatrixTimesScalarAssign, EOpMatrixTimesScalarAssign,
EOpMatrixTimesMatrixAssign, EOpMatrixTimesMatrixAssign,
EOpDivAssign EOpDivAssign,
EOpModAssign
}; };
class TIntermTraverser; class TIntermTraverser;
......
...@@ -76,7 +76,16 @@ TIntermTyped *TIntermediate::addBinaryMath( ...@@ -76,7 +76,16 @@ TIntermTyped *TIntermediate::addBinaryMath(
case EOpDiv: case EOpDiv:
case EOpMul: case EOpMul:
if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool) if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool)
{
return NULL; return NULL;
}
break;
case EOpMod:
if (left->getBasicType() == EbtStruct || left->getBasicType() == EbtBool || left->getBasicType() == EbtFloat)
{
return NULL;
}
break;
default: default:
break; break;
} }
......
...@@ -223,6 +223,9 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node) ...@@ -223,6 +223,9 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node)
case EOpDivAssign: case EOpDivAssign:
writeTriplet(visit, "(", " /= ", ")"); writeTriplet(visit, "(", " /= ", ")");
break; break;
case EOpModAssign:
writeTriplet(visit, "(", " %= ", ")");
break;
// Notice the fall-through. // Notice the fall-through.
case EOpMulAssign: case EOpMulAssign:
case EOpVectorTimesMatrixAssign: case EOpVectorTimesMatrixAssign:
...@@ -341,7 +344,7 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node) ...@@ -341,7 +344,7 @@ bool TOutputGLSLBase::visitBinary(Visit visit, TIntermBinary *node)
writeTriplet(visit, "(", " / ", ")"); writeTriplet(visit, "(", " / ", ")");
break; break;
case EOpMod: case EOpMod:
UNIMPLEMENTED(); writeTriplet(visit, "(", " % ", ")");
break; break;
case EOpEqual: case EOpEqual:
writeTriplet(visit, "(", " == ", ")"); writeTriplet(visit, "(", " == ", ")");
......
...@@ -1564,6 +1564,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) ...@@ -1564,6 +1564,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
} }
break; break;
case EOpDivAssign: outputTriplet(visit, "(", " /= ", ")"); break; case EOpDivAssign: outputTriplet(visit, "(", " /= ", ")"); break;
case EOpModAssign: outputTriplet(visit, "(", " %= ", ")"); break;
case EOpIndexDirect: case EOpIndexDirect:
{ {
const TType& leftType = node->getLeft()->getType(); const TType& leftType = node->getLeft()->getType();
...@@ -1651,6 +1652,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) ...@@ -1651,6 +1652,7 @@ bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
case EOpSub: outputTriplet(visit, "(", " - ", ")"); break; case EOpSub: outputTriplet(visit, "(", " - ", ")"); break;
case EOpMul: outputTriplet(visit, "(", " * ", ")"); break; case EOpMul: outputTriplet(visit, "(", " * ", ")"); break;
case EOpDiv: outputTriplet(visit, "(", " / ", ")"); break; case EOpDiv: outputTriplet(visit, "(", " / ", ")"); break;
case EOpMod: outputTriplet(visit, "(", " % ", ")"); break;
case EOpEqual: case EOpEqual:
case EOpNotEqual: case EOpNotEqual:
if (node->getLeft()->isScalar()) if (node->getLeft()->isScalar())
......
...@@ -56,6 +56,7 @@ const char *GetOperatorString(TOperator op) ...@@ -56,6 +56,7 @@ const char *GetOperatorString(TOperator op)
case EOpAddAssign: return "+="; case EOpAddAssign: return "+=";
case EOpSubAssign: return "-="; case EOpSubAssign: return "-=";
case EOpDivAssign: return "/="; case EOpDivAssign: return "/=";
case EOpModAssign: return "%=";
// Fall-through. // Fall-through.
case EOpMulAssign: case EOpMulAssign:
...@@ -75,7 +76,7 @@ const char *GetOperatorString(TOperator op) ...@@ -75,7 +76,7 @@ const char *GetOperatorString(TOperator op)
case EOpSub: return "-"; case EOpSub: return "-";
case EOpMul: return "*"; case EOpMul: return "*";
case EOpDiv: return "/"; case EOpDiv: return "/";
case EOpMod: UNIMPLEMENTED(); break; case EOpMod: return "%";
case EOpEqual: return "=="; case EOpEqual: return "==";
case EOpNotEqual: return "!="; case EOpNotEqual: return "!=";
case EOpLessThan: return "<"; case EOpLessThan: return "<";
......
...@@ -555,6 +555,14 @@ multiplicative_expression ...@@ -555,6 +555,14 @@ multiplicative_expression
$$ = $1; $$ = $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 additive_expression
...@@ -739,6 +747,7 @@ assignment_operator ...@@ -739,6 +747,7 @@ assignment_operator
: EQUAL { $$.op = EOpAssign; } : EQUAL { $$.op = EOpAssign; }
| MUL_ASSIGN { $$.op = EOpMulAssign; } | MUL_ASSIGN { $$.op = EOpMulAssign; }
| DIV_ASSIGN { $$.op = EOpDivAssign; } | DIV_ASSIGN { $$.op = EOpDivAssign; }
| MOD_ASSIGN { $$.op = EOpModAssign; }
| ADD_ASSIGN { $$.op = EOpAddAssign; } | ADD_ASSIGN { $$.op = EOpAddAssign; }
| SUB_ASSIGN { $$.op = EOpSubAssign; } | 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) ...@@ -131,6 +131,9 @@ bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary *node)
case EOpDivAssign: case EOpDivAssign:
out << "divide second child into first child"; out << "divide second child into first child";
break; break;
case EOpModAssign:
out << "modulo second child into first child";
break;
case EOpIndexDirect: case EOpIndexDirect:
out << "direct index"; out << "direct index";
break; break;
...@@ -159,6 +162,9 @@ bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary *node) ...@@ -159,6 +162,9 @@ bool TOutputTraverser::visitBinary(Visit visit, TIntermBinary *node)
case EOpDiv: case EOpDiv:
out << "divide"; out << "divide";
break; break;
case EOpMod:
out << "modulo";
break;
case EOpEqual: case EOpEqual:
out << "Compare Equal"; out << "Compare Equal";
break; 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