[Sol->Yul] Refactor shift functions to be consistent

This commit is contained in:
Mathias Baumann 2019-06-06 17:59:30 +02:00
parent 89c435a167
commit 6a0976ed5e

View File

@ -224,34 +224,24 @@ string YulUtilFunctions::shiftLeftFunction(size_t _numBits)
solAssert(_numBits < 256, ""); solAssert(_numBits < 256, "");
string functionName = "shift_left_" + to_string(_numBits); string functionName = "shift_left_" + to_string(_numBits);
if (m_evmVersion.hasBitwiseShifting()) return m_functionCollector->createFunction(functionName, [&]() {
{ return
return m_functionCollector->createFunction(functionName, [&]() { Whiskers(R"(
return function <functionName>(value) -> newValue {
Whiskers(R"( newValue :=
function <functionName>(value) -> newValue { <?hasShifts>
newValue := shl(<numBits>, value) shl(<numBits>, value)
} <!hasShifts>
)") mul(value, <multiplier>)
("functionName", functionName) </hasShifts>
("numBits", to_string(_numBits)) }
.render(); )")
}); ("functionName", functionName)
} ("numBits", to_string(_numBits))
else ("hasShifts", m_evmVersion.hasBitwiseShifting())
{ ("multiplier", toCompactHexWithPrefix(u256(1) << _numBits))
return m_functionCollector->createFunction(functionName, [&]() { .render();
return });
Whiskers(R"(
function <functionName>(value) -> newValue {
newValue := mul(value, <multiplier>)
}
)")
("functionName", functionName)
("multiplier", toCompactHexWithPrefix(u256(1) << _numBits))
.render();
});
}
} }
string YulUtilFunctions::dynamicShiftLeftFunction() string YulUtilFunctions::dynamicShiftLeftFunction()
@ -282,7 +272,7 @@ string YulUtilFunctions::shiftRightFunction(size_t _numBits)
// Note that if this is extended with signed shifts, // Note that if this is extended with signed shifts,
// the opcodes SAR and SDIV behave differently with regards to rounding! // the opcodes SAR and SDIV behave differently with regards to rounding!
string functionName = "shift_right_" + to_string(_numBits) + "_unsigned_" + m_evmVersion.name(); string functionName = "shift_right_" + to_string(_numBits) + "_unsigned";
return m_functionCollector->createFunction(functionName, [&]() { return m_functionCollector->createFunction(functionName, [&]() {
return return
Whiskers(R"( Whiskers(R"(