Merge pull request #10137 from ethereum/fixedBytesOps

[Sol->Yul] Bit operations for fixed bytes types.
This commit is contained in:
chriseth 2020-10-29 18:04:07 +01:00 committed by GitHub
commit ace810b078
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 35 deletions

View File

@ -2557,47 +2557,49 @@ string IRGeneratorForStatements::binaryOperation(
!TokenTraits::isShiftOp(_operator), !TokenTraits::isShiftOp(_operator),
"Have to use specific shift operation function for shifts." "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; solAssert(
// TODO: Implement all operations for signed and unsigned types. _type.category() == Type::Category::Integer ||
_type.category() == Type::Category::FixedBytes,
"");
switch (_operator) switch (_operator)
{ {
case Token::Add: case Token::BitOr: fun = "or"; break;
fun = m_utils.overflowCheckedIntAddFunction(*type); case Token::BitXor: fun = "xor"; break;
break; case Token::BitAnd: fun = "and"; break;
case Token::Sub: default: break;
fun = m_utils.overflowCheckedIntSubFunction(*type); }
break; }
case Token::Mul: else if (TokenTraits::isArithmeticOp(_operator))
fun = m_utils.overflowCheckedIntMulFunction(*type); {
break; IntegerType const* type = dynamic_cast<IntegerType const*>(&_type);
case Token::Div: solAssert(type, "");
fun = m_utils.overflowCheckedIntDivFunction(*type); switch (_operator)
break; {
case Token::Mod: case Token::Add:
fun = m_utils.checkedIntModFunction(*type); fun = m_utils.overflowCheckedIntAddFunction(*type);
break; break;
case Token::BitOr: case Token::Sub:
fun = "or"; fun = m_utils.overflowCheckedIntSubFunction(*type);
break; break;
case Token::BitXor: case Token::Mul:
fun = "xor"; fun = m_utils.overflowCheckedIntMulFunction(*type);
break; break;
case Token::BitAnd: case Token::Div:
fun = "and"; fun = m_utils.overflowCheckedIntDivFunction(*type);
break; break;
default: case Token::Mod:
break; 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( std::string IRGeneratorForStatements::shiftOperation(

View File

@ -29,6 +29,8 @@ contract Homer is ERC165, Simpson {
} }
} }
// ====
// compileViaYul: also
// ---- // ----
// supportsInterface(bytes4): left(0x01ffc9a0) -> false // supportsInterface(bytes4): left(0x01ffc9a0) -> false
// supportsInterface(bytes4): left(0x01ffc9a7) -> true // supportsInterface(bytes4): left(0x01ffc9a7) -> true

View File

@ -40,6 +40,8 @@ contract Lisa is ERC165MappingImplementation, Simpson {
} }
} }
// ====
// compileViaYul: also
// ---- // ----
// supportsInterface(bytes4): left(0x01ffc9a0) -> false // supportsInterface(bytes4): left(0x01ffc9a0) -> false
// supportsInterface(bytes4): left(0x01ffc9a7) -> true // supportsInterface(bytes4): left(0x01ffc9a7) -> true