Skip to content

Commit

Permalink
fixup! fixup! Introduce sub-assembly offset output artifact
Browse files Browse the repository at this point in the history
  • Loading branch information
nikola-matic committed Jan 13, 2025
1 parent dd91d46 commit d086ad9
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 173 deletions.
57 changes: 24 additions & 33 deletions libsolidity/interface/StandardCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -392,39 +392,6 @@ Json formatSubAssemblyOffsets(std::vector<evmasm::LinkerObject::SubAssembly> con
return subs;
}

Json collectEVMObject(
langutil::EVMVersion _evmVersion,
evmasm::LinkerObject const& _object,
std::string const* _sourceMap,
Json _generatedSources,
bool _runtimeObject,
std::function<bool(std::string)> const& _artifactRequested
)
{
Json output;
if (_artifactRequested("object"))
output["object"] = _object.toHex();
if (_artifactRequested("opcodes"))
output["opcodes"] = evmasm::disassemble(_object.bytecode, _evmVersion);
if (_artifactRequested("sourceMap"))
output["sourceMap"] = _sourceMap ? *_sourceMap : "";
if (_artifactRequested("functionDebugData"))
output["functionDebugData"] = StandardCompiler::formatFunctionDebugData(_object.functionDebugData);
if (_artifactRequested("linkReferences"))
output["linkReferences"] = formatLinkReferences(_object.linkReferences);
if (_runtimeObject && _artifactRequested("immutableReferences"))
output["immutableReferences"] = formatImmutableReferences(_object.immutableReferences);
if (_artifactRequested("generatedSources"))
output["generatedSources"] = std::move(_generatedSources);
if (_artifactRequested("subAssemblyOffsets"))
{
Json ret = Json::object();
ret["subs"] = formatSubAssemblyOffsets(_object.subAssemblyData);
output["subAssemblyOffsets"] = std::move(ret);
}
return output;
}

std::optional<Json> checkKeys(Json const& _input, std::set<std::string> const& _keys, std::string const& _name)
{
if (!_input.empty() && !_input.is_object())
Expand Down Expand Up @@ -1286,6 +1253,12 @@ Json StandardCompiler::importEVMAssembly(StandardCompiler::InputsAndSettings _in
creationJSON["functionDebugData"] = formatFunctionDebugData(stack.object(sourceName).functionDebugData);
if (evmCreationArtifactRequested("linkReferences"))
creationJSON["linkReferences"] = formatLinkReferences(stack.object(sourceName).linkReferences);
if (evmCreationArtifactRequested("subAssemblyOffsets"))
{
Json ret = Json::object();
ret["subs"] = formatSubAssemblyOffsets(stack.runtimeObject(sourceName).subAssemblyData);
creationJSON["subAssemblyOffsets"] = std::move(ret);
}
evmData["bytecode"] = creationJSON;
}

Expand Down Expand Up @@ -1314,6 +1287,12 @@ Json StandardCompiler::importEVMAssembly(StandardCompiler::InputsAndSettings _in
deployedJSON["linkReferences"] = formatLinkReferences(stack.runtimeObject(sourceName).linkReferences);
if (evmDeployedArtifactRequested("immutableReferences"))
deployedJSON["immutableReferences"] = formatImmutableReferences(stack.runtimeObject(sourceName).immutableReferences);
if (evmDeployedArtifactRequested("subAssemblyOffsets"))
{
Json ret = Json::object();
ret["subs"] = formatSubAssemblyOffsets(stack.runtimeObject(sourceName).subAssemblyData);
deployedJSON["subAssemblyOffsets"] = std::move(ret);
}
evmData["deployedBytecode"] = deployedJSON;
}

Expand Down Expand Up @@ -1554,6 +1533,12 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu
creationJSON["linkReferences"] = formatLinkReferences(compilerStack.object(contractName).linkReferences);
if (evmCreationArtifactRequested("generatedSources"))
creationJSON["generatedSources"] = compilerStack.generatedSources(contractName, /* _runtime */ false);
if (evmCreationArtifactRequested("subAssemblyOffsets"))
{
Json ret = Json::object();
ret["subs"] = formatSubAssemblyOffsets(compilerStack.object(contractName).subAssemblyData);
creationJSON["subAssemblyOffsets"] = std::move(ret);
}
evmData["bytecode"] = creationJSON;
}

Expand Down Expand Up @@ -1584,6 +1569,12 @@ Json StandardCompiler::compileSolidity(StandardCompiler::InputsAndSettings _inpu
deployedJSON["immutableReferences"] = formatImmutableReferences(compilerStack.runtimeObject(contractName).immutableReferences);
if (evmDeployedArtifactRequested("generatedSources"))
deployedJSON["generatedSources"] = compilerStack.generatedSources(contractName, /* _runtime */ true);
if (evmDeployedArtifactRequested("subAssemblyOffsets"))
{
Json ret = Json::object();
ret["subs"] = formatSubAssemblyOffsets(compilerStack.object(contractName).subAssemblyData);
deployedJSON["subAssemblyOffsets"] = std::move(ret);
}
evmData["deployedBytecode"] = deployedJSON;
}

Expand Down
8 changes: 1 addition & 7 deletions test/cmdlineTests/standard_import_asm_json/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,7 @@
"opcodes":"<OPCODES REMOVED>",
"sourceMap":"<SOURCEMAP REMOVED>",
"subAssemblyOffsets": {
"subs": [
{
"isCreation": true,
"length": 1,
"start": 0
}
]
"subs": []
}
},
"deployedBytecode": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,9 @@
"subAssemblyOffsets": {
"subs": [
{
"isCreation": true,
"length": 5,
"start": 0,
"subs": [
{
"isCreation": false,
"length": 87,
"start": 18446744073709551534
}
]
"isCreation": false,
"length": 87,
"start": 0
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,9 @@
"subAssemblyOffsets": {
"subs": [
{
"isCreation": true,
"length": 1,
"start": 0,
"subs": [
{
"isCreation": false,
"length": 75,
"start": 18446744073709551542
}
]
"isCreation": false,
"length": 75,
"start": 0
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
"subs": [
{
"isCreation": true,
"length": 131,
"length": 130,
"start": 0,
"subs": [
{
"isCreation": false,
"length": 105,
"length": 104,
"start": 26
}
]
Expand Down
14 changes: 7 additions & 7 deletions test/cmdlineTests/standard_subassembly_offsets/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
"subs": [
{
"isCreation": true,
"length": 1789,
"length": 1787,
"start": 0,
"subs": [
{
"isCreation": false,
"length": 781,
"start": 1008
"length": 780,
"start": 1007
},
{
"isCreation": true,
"length": 131,
"start": 1658,
"length": 130,
"start": 1657,
"subs": [
{
"isCreation": false,
"length": 105,
"start": 1684
"length": 104,
"start": 1683
}
]
}
Expand Down
11 changes: 1 addition & 10 deletions test/cmdlineTests/standard_yul/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,7 @@
"linkReferences": {},
"object": "<BYTECODE REMOVED>",
"opcodes":"<OPCODES REMOVED>",
"sourceMap":"<SOURCEMAP REMOVED>",
"subAssemblyOffsets": {
"subs": [
{
"isCreation": true,
"length": 7,
"start": 0
}
]
}
"sourceMap":"<SOURCEMAP REMOVED>"
}
},
"ir": "object \"object\" {
Expand Down
29 changes: 2 additions & 27 deletions test/cmdlineTests/standard_yul_immutable_references/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,7 @@
"linkReferences": {},
"object": "<BYTECODE REMOVED>",
"opcodes":"<OPCODES REMOVED>",
"sourceMap":"<SOURCEMAP REMOVED>",
"subAssemblyOffsets": {
"subs": [
{
"isCreation": true,
"length": 56,
"start": 0,
"subs": [
{
"isCreation": true,
"length": 39,
"start": 17
}
]
}
]
}
"sourceMap":"<SOURCEMAP REMOVED>"
},
"deployedBytecode": {
"functionDebugData": {},
Expand All @@ -39,16 +23,7 @@
"linkReferences": {},
"object": "<BYTECODE REMOVED>",
"opcodes":"<OPCODES REMOVED>",
"sourceMap":"<SOURCEMAP REMOVED>",
"subAssemblyOffsets": {
"subs": [
{
"isCreation": true,
"length": 39,
"start": 0
}
]
}
"sourceMap":"<SOURCEMAP REMOVED>"
}
}
}
Expand Down
11 changes: 1 addition & 10 deletions test/cmdlineTests/standard_yul_object/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@ data_4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45 616263
"linkReferences": {},
"object": "<BYTECODE REMOVED>",
"opcodes":"<OPCODES REMOVED>",
"sourceMap":"<SOURCEMAP REMOVED>",
"subAssemblyOffsets": {
"subs": [
{
"isCreation": true,
"length": 11,
"start": 0
}
]
}
"sourceMap":"<SOURCEMAP REMOVED>"
}
},
"ir": "object \"NamedObject\" {
Expand Down
29 changes: 2 additions & 27 deletions test/cmdlineTests/standard_yul_object_name/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,15 @@ sub_0: assembly {
"linkReferences": {},
"object": "<BYTECODE REMOVED>",
"opcodes":"<OPCODES REMOVED>",
"sourceMap":"<SOURCEMAP REMOVED>",
"subAssemblyOffsets": {
"subs": [
{
"isCreation": true,
"length": 11,
"start": 0,
"subs": [
{
"isCreation": true,
"length": 3,
"start": 8
}
]
}
]
}
"sourceMap":"<SOURCEMAP REMOVED>"
},
"deployedBytecode": {
"functionDebugData": {},
"immutableReferences": {},
"linkReferences": {},
"object": "<BYTECODE REMOVED>",
"opcodes":"<OPCODES REMOVED>",
"sourceMap":"<SOURCEMAP REMOVED>",
"subAssemblyOffsets": {
"subs": [
{
"isCreation": true,
"length": 3,
"start": 0
}
]
}
"sourceMap":"<SOURCEMAP REMOVED>"
}
},
"ir": "object \"NamedObject\" {
Expand Down
11 changes: 1 addition & 10 deletions test/cmdlineTests/standard_yul_optimiserSteps/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@
"linkReferences": {},
"object": "<BYTECODE REMOVED>",
"opcodes":"<OPCODES REMOVED>",
"sourceMap":"<SOURCEMAP REMOVED>",
"subAssemblyOffsets": {
"subs": [
{
"isCreation": true,
"length": 5,
"start": 0
}
]
}
"sourceMap":"<SOURCEMAP REMOVED>"
}
},
"ir": "object \"object\" {
Expand Down
11 changes: 1 addition & 10 deletions test/cmdlineTests/standard_yul_optimized/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,7 @@
"linkReferences": {},
"object": "<BYTECODE REMOVED>",
"opcodes":"<OPCODES REMOVED>",
"sourceMap":"<SOURCEMAP REMOVED>",
"subAssemblyOffsets": {
"subs": [
{
"isCreation": true,
"length": 5,
"start": 0
}
]
}
"sourceMap":"<SOURCEMAP REMOVED>"
}
},
"ir": "object \"object\" {
Expand Down
11 changes: 1 addition & 10 deletions test/cmdlineTests/standard_yul_output_warning/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,7 @@
"linkReferences": {},
"object": "<BYTECODE REMOVED>",
"opcodes":"<OPCODES REMOVED>",
"sourceMap":"<SOURCEMAP REMOVED>",
"subAssemblyOffsets": {
"subs": [
{
"isCreation": true,
"length": 8,
"start": 0
}
]
}
"sourceMap":"<SOURCEMAP REMOVED>"
}
},
"irOptimized": "object \"object\" {
Expand Down

0 comments on commit d086ad9

Please sign in to comment.