@@ -25,32 +25,27 @@ using namespace solidity::evmasm::ethdebug;
25
25
namespace
26
26
{
27
27
28
- Json programInstructions (Assembly const * _assembly, LinkerObject const & _linkerObject, unsigned _sourceId)
28
+ Json programInstructions (Assembly const & _assembly, LinkerObject const & _linkerObject, unsigned _sourceId)
29
29
{
30
- // e.g. interfaces don't have a valid assembly object.
31
- if (_assembly)
32
- {
33
- solUnimplementedAssert (_assembly->eofVersion () == std::nullopt, " ethdebug does not yet support EOF." );
34
- solUnimplementedAssert (_assembly->codeSections ().size () == 1 , " ethdebug does not yet support multiple code-sections." );
35
- for (auto const & instruction: _assembly->codeSections ()[0 ].items )
36
- solUnimplementedAssert (instruction.type () != VerbatimBytecode, " Verbatim bytecode is currently not supported by ethdebug." );
37
- }
30
+ solUnimplementedAssert (_assembly.eofVersion () == std::nullopt, " ethdebug does not yet support EOF." );
31
+ solUnimplementedAssert (_assembly.codeSections ().size () == 1 , " ethdebug does not yet support multiple code-sections." );
32
+ for (auto const & instruction: _assembly.codeSections ()[0 ].items )
33
+ solUnimplementedAssert (instruction.type () != VerbatimBytecode, " Verbatim bytecode is currently not supported by ethdebug." );
38
34
39
35
solAssert (_linkerObject.codeSectionLocations .size () == 1 );
40
36
solAssert (_linkerObject.codeSectionLocations [0 ].end <= _linkerObject.bytecode .size ());
41
37
Json instructions = Json::array ();
42
38
for (size_t i = 0 ; i < _linkerObject.codeSectionLocations [0 ].instructionLocations .size (); ++i)
43
39
{
44
- solAssert (_assembly);
45
40
LinkerObject::InstructionLocation currentInstruction = _linkerObject.codeSectionLocations [0 ].instructionLocations [i];
46
41
size_t start = currentInstruction.start ;
47
42
size_t end = currentInstruction.end ;
48
43
size_t assemblyItemIndex = currentInstruction.assemblyItemIndex ;
49
44
solAssert (end <= _linkerObject.bytecode .size ());
50
45
solAssert (start < end);
51
- solAssert (assemblyItemIndex < _assembly-> codeSections ().at (0 ).items .size ());
46
+ solAssert (assemblyItemIndex < _assembly. codeSections ().at (0 ).items .size ());
52
47
Json operation = Json::object ();
53
- operation[" mnemonic" ] = instructionInfo (static_cast <Instruction>(_linkerObject.bytecode [start]), _assembly-> evmVersion ()).name ;
48
+ operation[" mnemonic" ] = instructionInfo (static_cast <Instruction>(_linkerObject.bytecode [start]), _assembly. evmVersion ()).name ;
54
49
static size_t constexpr instructionSize = 1 ;
55
50
if (start + instructionSize < end)
56
51
{
@@ -61,7 +56,7 @@ Json programInstructions(Assembly const* _assembly, LinkerObject const& _linkerO
61
56
solAssert (!argumentData.empty ());
62
57
operation[" arguments" ] = Json::array ({util::toHex (argumentData, util::HexPrefix::Add)});
63
58
}
64
- langutil::SourceLocation const & location = _assembly-> codeSections ().at (0 ).items .at (assemblyItemIndex).location ();
59
+ langutil::SourceLocation const & location = _assembly. codeSections ().at (0 ).items .at (assemblyItemIndex).location ();
65
60
Json instruction = Json::object ();
66
61
instruction[" offset" ] = start;
67
62
instruction[" operation" ] = operation;
@@ -90,8 +85,11 @@ Json ethdebug::program(std::string_view _name, unsigned _sourceId, Assembly cons
90
85
result[" contract" ][" definition" ] = Json::object ();
91
86
result[" contract" ][" definition" ][" source" ] = Json::object ();
92
87
result[" contract" ][" definition" ][" source" ][" id" ] = _sourceId;
93
- result[" environment" ] = (!_assembly || _assembly->isCreation ()) ? " create" : " call" ;
94
- result[" instructions" ] = programInstructions (_assembly, _linkerObject, _sourceId);
88
+ if (_assembly)
89
+ {
90
+ result[" environment" ] = _assembly->isCreation () ? " create" : " call" ;
91
+ result[" instructions" ] = programInstructions (*_assembly, _linkerObject, _sourceId);
92
+ }
95
93
return result;
96
94
}
97
95
0 commit comments