Bit operations for fixed bytes types.

This commit is contained in:
chriseth 2020-10-28 18:01:41 +01:00
parent cfc1eb0029
commit 0c12b2e53a
3 changed files with 24 additions and 18 deletions

View File

@ -2557,10 +2557,25 @@ 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::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:
@ -2578,26 +2593,13 @@ string IRGeneratorForStatements::binaryOperation(
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;
}
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(

View File

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