Properly filter requested artefacts inside the EVM objects.

This commit is contained in:
chriseth
2020-12-07 22:03:06 +01:00
committed by Leonardo Alt
parent b23d923023
commit 759db0e646
18 changed files with 71 additions and 33 deletions
+51 -14
View File
@@ -171,16 +171,21 @@ bool hashMatchesContent(string const& _hash, string const& _content)
bool isArtifactRequested(Json::Value const& _outputSelection, string const& _artifact, bool _wildcardMatchesExperimental)
{
static set<string> experimental{"ir", "irOptimized", "wast", "ewasm", "ewasm.wast"};
for (auto const& artifact: _outputSelection)
/// @TODO support sub-matching, e.g "evm" matches "evm.assembly"
if (artifact == _artifact)
for (auto const& selectedArtifactJson: _outputSelection)
{
string const& selectedArtifact = selectedArtifactJson.asString();
if (
_artifact == selectedArtifact ||
boost::algorithm::starts_with(_artifact, selectedArtifact + ".")
)
return true;
else if (artifact == "*")
else if (selectedArtifact == "*")
{
// "ir", "irOptimized", "wast" and "ewasm.wast" can only be matched by "*" if activated.
if (experimental.count(_artifact) == 0 || _wildcardMatchesExperimental)
return true;
}
}
return false;
}
@@ -370,17 +375,23 @@ Json::Value collectEVMObject(
evmasm::LinkerObject const& _object,
string const* _sourceMap,
Json::Value _generatedSources,
bool _runtimeObject
bool _runtimeObject,
function<bool(string)> const& _artifactRequested
)
{
Json::Value output = Json::objectValue;
output["object"] = _object.toHex();
output["opcodes"] = evmasm::disassemble(_object.bytecode);
output["sourceMap"] = _sourceMap ? *_sourceMap : "";
output["linkReferences"] = formatLinkReferences(_object.linkReferences);
if (_runtimeObject)
if (_artifactRequested("object"))
output["object"] = _object.toHex();
if (_artifactRequested("opcodes"))
output["opcodes"] = evmasm::disassemble(_object.bytecode);
if (_artifactRequested("sourceMap"))
output["sourceMap"] = _sourceMap ? *_sourceMap : "";
if (_artifactRequested("linkReferences"))
output["linkReferences"] = formatLinkReferences(_object.linkReferences);
if (_runtimeObject && _artifactRequested("immutableReferences"))
output["immutableReferences"] = formatImmutableReferences(_object.immutableReferences);
output["generatedSources"] = move(_generatedSources);
if (_artifactRequested("generatedSources"))
output["generatedSources"] = move(_generatedSources);
return output;
}
@@ -1147,7 +1158,14 @@ Json::Value StandardCompiler::compileSolidity(StandardCompiler::InputsAndSetting
compilerStack.object(contractName),
compilerStack.sourceMapping(contractName),
compilerStack.generatedSources(contractName),
false
false,
[&](string const& _element) { return isArtifactRequested(
_inputsAndSettings.outputSelection,
file,
name,
"evm.bytecode." + _element,
wildcardMatchesExperimental
); }
);
if (compilationSuccess && isArtifactRequested(
@@ -1161,7 +1179,14 @@ Json::Value StandardCompiler::compileSolidity(StandardCompiler::InputsAndSetting
compilerStack.runtimeObject(contractName),
compilerStack.runtimeSourceMapping(contractName),
compilerStack.generatedSources(contractName, true),
true
true,
[&](string const& _element) { return isArtifactRequested(
_inputsAndSettings.outputSelection,
file,
name,
"evm.deployedBytecode." + _element,
wildcardMatchesExperimental
); }
);
if (!evmData.empty())
@@ -1258,7 +1283,19 @@ Json::Value StandardCompiler::compileYul(InputsAndSettings _inputsAndSettings)
MachineAssemblyObject const& o = objectKind == "bytecode" ? object : runtimeObject;
if (o.bytecode)
output["contracts"][sourceName][contractName]["evm"][objectKind] =
collectEVMObject(*o.bytecode, o.sourceMappings.get(), Json::arrayValue, false);
collectEVMObject(
*o.bytecode,
o.sourceMappings.get(),
Json::arrayValue,
false,
[&](string const& _element) { return isArtifactRequested(
_inputsAndSettings.outputSelection,
sourceName,
contractName,
"evm." + objectKind + "." + _element,
wildcardMatchesExperimental
); }
);
}
if (isArtifactRequested(_inputsAndSettings.outputSelection, sourceName, contractName, "irOptimized", wildcardMatchesExperimental))