Implement signed addition for sol->yul code generation.

This commit is contained in:
Daniel Kirchner
2019-06-20 11:42:50 +02:00
committed by chriseth
parent 5b92640ab5
commit 88988af561
5 changed files with 75 additions and 24 deletions
@@ -1126,18 +1126,27 @@ string IRGeneratorForStatements::binaryOperation(
if (IntegerType const* type = dynamic_cast<IntegerType const*>(&_type))
{
string fun;
// TODO: Only division is implemented for signed integers for now.
if (!type->isSigned())
// TODO: Implement all operations for signed and unsigned types.
switch (_operator)
{
if (_operator == Token::Add)
fun = m_utils.overflowCheckedUIntAddFunction(type->numBits());
else if (_operator == Token::Sub)
fun = m_utils.overflowCheckedUIntSubFunction();
else if (_operator == Token::Mul)
fun = m_utils.overflowCheckedUIntMulFunction(type->numBits());
case Token::Add:
fun = m_utils.overflowCheckedIntAddFunction(*type);
break;
case Token::Sub:
if (!type->isSigned())
fun = m_utils.overflowCheckedUIntSubFunction();
break;
case Token::Mul:
if (!type->isSigned())
fun = m_utils.overflowCheckedUIntMulFunction(type->numBits());
break;
case Token::Div:
fun = m_utils.overflowCheckedIntDivFunction(*type);
break;
default:
break;
}
if (_operator == Token::Div)
fun = m_utils.overflowCheckedIntDivFunction(*type);
solUnimplementedAssert(!fun.empty(), "");
return fun + "(" + _left + ", " + _right + ")\n";
}