mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Implement signed addition for sol->yul code generation.
This commit is contained in:
committed by
chriseth
parent
5b92640ab5
commit
88988af561
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user