Merge pull request #10097 from ethereum/develop

Merge develop into breaking.
This commit is contained in:
chriseth
2020-10-23 10:30:24 +02:00
committed by GitHub
61 changed files with 498 additions and 599 deletions
+18 -4
View File
@@ -434,6 +434,21 @@ string YulUtilFunctions::updateByteSliceFunctionDynamic(size_t _numBytes)
});
}
string YulUtilFunctions::maskBytesFunctionDynamic()
{
string functionName = "mask_bytes_dynamic";
return m_functionCollector.createFunction(functionName, [&]() {
return Whiskers(R"(
function <functionName>(data, bytes) -> result {
let mask := not(<shr>(mul(8, bytes), not(0)))
result := and(data, mask)
})")
("functionName", functionName)
("shr", shiftRightFunctionDynamic())
.render();
});
}
string YulUtilFunctions::roundUpFunction()
{
string functionName = "round_up_to_mul_of_32";
@@ -1237,12 +1252,11 @@ string YulUtilFunctions::shortByteArrayEncodeUsedAreaSetLengthFunction()
function <functionName>(data, len) -> used {
// we want to save only elements that are part of the array after resizing
// others should be set to zero
let mask := <shl>(mul(8, sub(32, len)), <ones>)
used := or(and(data, mask), mul(2, len))
data := <maskBytes>(data, len)
used := or(data, mul(2, len))
})")
("functionName", functionName)
("shl", shiftLeftFunctionDynamic())
("ones", formatNumber((bigint(1) << 256) - 1))
("maskBytes", maskBytesFunctionDynamic())
.render();
});
}
+5
View File
@@ -101,6 +101,11 @@ public:
/// signature: (value, shiftBytes, toInsert) -> result
std::string updateByteSliceFunctionDynamic(size_t _numBytes);
/// Function that sets all but the first ``bytes`` bytes of ``value`` to zero.
/// @note ``bytes`` has to be small enough not to overflow ``8 * bytes``.
/// signature: (value, bytes) -> result
std::string maskBytesFunctionDynamic();
/// @returns the name of a function that rounds its input to the next multiple
/// of 32 or the input if it is a multiple of 32.
/// signature: (value) -> result
+2 -2
View File
@@ -50,7 +50,7 @@ using namespace solidity::frontend;
pair<string, string> IRGenerator::run(
ContractDefinition const& _contract,
map<ContractDefinition const*, string const> const& _otherYulSources
map<ContractDefinition const*, string_view const> const& _otherYulSources
)
{
string const ir = yul::reindent(generate(_contract, _otherYulSources));
@@ -78,7 +78,7 @@ pair<string, string> IRGenerator::run(
string IRGenerator::generate(
ContractDefinition const& _contract,
map<ContractDefinition const*, string const> const& _otherYulSources
map<ContractDefinition const*, string_view const> const& _otherYulSources
)
{
auto subObjectSources = [&_otherYulSources](std::set<ContractDefinition const*, ASTNode::CompareByID> const& subObjects) -> string
+2 -2
View File
@@ -53,13 +53,13 @@ public:
/// (or just pretty-printed, depending on the optimizer settings).
std::pair<std::string, std::string> run(
ContractDefinition const& _contract,
std::map<ContractDefinition const*, std::string const> const& _otherYulSources
std::map<ContractDefinition const*, std::string_view const> const& _otherYulSources
);
private:
std::string generate(
ContractDefinition const& _contract,
std::map<ContractDefinition const*, std::string const> const& _otherYulSources
std::map<ContractDefinition const*, std::string_view const> const& _otherYulSources
);
std::string generate(Block const& _block);