mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #10137 from ethereum/fixedBytesOps
[Sol->Yul] Bit operations for fixed bytes types.
This commit is contained in:
commit
ace810b078
@ -2557,47 +2557,49 @@ string IRGeneratorForStatements::binaryOperation(
|
||||
!TokenTraits::isShiftOp(_operator),
|
||||
"Have to use specific shift operation function for shifts."
|
||||
);
|
||||
if (IntegerType const* type = dynamic_cast<IntegerType const*>(&_type))
|
||||
string fun;
|
||||
if (TokenTraits::isBitOp(_operator))
|
||||
{
|
||||
string fun;
|
||||
// TODO: Implement all operations for signed and unsigned types.
|
||||
solAssert(
|
||||
_type.category() == Type::Category::Integer ||
|
||||
_type.category() == Type::Category::FixedBytes,
|
||||
"");
|
||||
switch (_operator)
|
||||
{
|
||||
case Token::Add:
|
||||
fun = m_utils.overflowCheckedIntAddFunction(*type);
|
||||
break;
|
||||
case Token::Sub:
|
||||
fun = m_utils.overflowCheckedIntSubFunction(*type);
|
||||
break;
|
||||
case Token::Mul:
|
||||
fun = m_utils.overflowCheckedIntMulFunction(*type);
|
||||
break;
|
||||
case Token::Div:
|
||||
fun = m_utils.overflowCheckedIntDivFunction(*type);
|
||||
break;
|
||||
case Token::Mod:
|
||||
fun = m_utils.checkedIntModFunction(*type);
|
||||
break;
|
||||
case Token::BitOr:
|
||||
fun = "or";
|
||||
break;
|
||||
case Token::BitXor:
|
||||
fun = "xor";
|
||||
break;
|
||||
case Token::BitAnd:
|
||||
fun = "and";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case Token::BitOr: fun = "or"; break;
|
||||
case Token::BitXor: fun = "xor"; break;
|
||||
case Token::BitAnd: fun = "and"; break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
else if (TokenTraits::isArithmeticOp(_operator))
|
||||
{
|
||||
IntegerType const* type = dynamic_cast<IntegerType const*>(&_type);
|
||||
solAssert(type, "");
|
||||
switch (_operator)
|
||||
{
|
||||
case Token::Add:
|
||||
fun = m_utils.overflowCheckedIntAddFunction(*type);
|
||||
break;
|
||||
case Token::Sub:
|
||||
fun = m_utils.overflowCheckedIntSubFunction(*type);
|
||||
break;
|
||||
case Token::Mul:
|
||||
fun = m_utils.overflowCheckedIntMulFunction(*type);
|
||||
break;
|
||||
case Token::Div:
|
||||
fun = m_utils.overflowCheckedIntDivFunction(*type);
|
||||
break;
|
||||
case Token::Mod:
|
||||
fun = m_utils.checkedIntModFunction(*type);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
solUnimplementedAssert(!fun.empty(), "");
|
||||
return fun + "(" + _left + ", " + _right + ")\n";
|
||||
}
|
||||
else
|
||||
solUnimplementedAssert(false, "");
|
||||
|
||||
return {};
|
||||
solUnimplementedAssert(!fun.empty(), "Type: " + _type.toString());
|
||||
return fun + "(" + _left + ", " + _right + ")\n";
|
||||
}
|
||||
|
||||
std::string IRGeneratorForStatements::shiftOperation(
|
||||
|
@ -29,6 +29,8 @@ contract Homer is ERC165, Simpson {
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// supportsInterface(bytes4): left(0x01ffc9a0) -> false
|
||||
// supportsInterface(bytes4): left(0x01ffc9a7) -> true
|
||||
|
@ -40,6 +40,8 @@ contract Lisa is ERC165MappingImplementation, Simpson {
|
||||
}
|
||||
}
|
||||
|
||||
// ====
|
||||
// compileViaYul: also
|
||||
// ----
|
||||
// supportsInterface(bytes4): left(0x01ffc9a0) -> false
|
||||
// supportsInterface(bytes4): left(0x01ffc9a7) -> true
|
||||
|
Loading…
Reference in New Issue
Block a user