@@ -222,33 +222,11 @@ string Assembly::assemblyString(
222
222
return tmp.str ();
223
223
}
224
224
225
- Json::Value Assembly::createJsonValue (string _name, int _source, int _begin, int _end, string _value, string _jumpType)
226
- {
227
- Json::Value value{Json::objectValue};
228
- value[" name" ] = _name;
229
- value[" source" ] = _source;
230
- value[" begin" ] = _begin;
231
- value[" end" ] = _end;
232
- if (!_value.empty ())
233
- value[" value" ] = _value;
234
- if (!_jumpType.empty ())
235
- value[" jumpType" ] = _jumpType;
236
- return value;
237
- }
238
-
239
- string Assembly::toStringInHex (u256 _value)
240
- {
241
- std::stringstream hexStr;
242
- hexStr << std::uppercase << hex << _value;
243
- return hexStr.str ();
244
- }
245
-
246
- Json::Value Assembly::assemblyJSON (map<string, unsigned > const & _sourceIndices) const
225
+ Json::Value Assembly::assemblyJSON (map<string, unsigned > const & _sourceIndices, bool _includeSourceList) const
247
226
{
248
227
Json::Value root;
249
228
root[" .code" ] = Json::arrayValue;
250
-
251
- Json::Value& collection = root[" .code" ];
229
+ Json::Value& code = root[" .code" ];
252
230
for (AssemblyItem const & i: m_items)
253
231
{
254
232
int sourceIndex = -1 ;
@@ -259,104 +237,68 @@ Json::Value Assembly::assemblyJSON(map<string, unsigned> const& _sourceIndices)
259
237
sourceIndex = static_cast <int >(iter->second );
260
238
}
261
239
262
- switch (i.type ())
240
+ auto [name, data] = i.nameAndData ();
241
+ Json::Value item;
242
+ item[" name" ] = name;
243
+ item[" begin" ] = i.location ().start ;
244
+ item[" end" ] = i.location ().end ;
245
+ if (i.m_modifierDepth != 0 )
246
+ item[" modifierDepth" ] = static_cast <int >(i.m_modifierDepth );
247
+ std::string jumpType = i.getJumpTypeAsString ();
248
+ if (!jumpType.empty ())
263
249
{
264
- case Operation:
265
- collection.append (
266
- createJsonValue (
267
- instructionInfo (i.instruction ()).name ,
268
- sourceIndex,
269
- i.location ().start ,
270
- i.location ().end ,
271
- i.getJumpTypeAsString ())
272
- );
273
- break ;
274
- case Push:
275
- collection.append (
276
- createJsonValue (" PUSH" , sourceIndex, i.location ().start , i.location ().end , toStringInHex (i.data ()), i.getJumpTypeAsString ()));
277
- break ;
278
- case PushTag:
279
- if (i.data () == 0 )
280
- collection.append (
281
- createJsonValue (" PUSH [ErrorTag]" , sourceIndex, i.location ().start , i.location ().end , " " ));
282
- else
283
- collection.append (
284
- createJsonValue (" PUSH [tag]" , sourceIndex, i.location ().start , i.location ().end , toString (i.data ())));
285
- break ;
286
- case PushSub:
287
- collection.append (
288
- createJsonValue (" PUSH [$]" , sourceIndex, i.location ().start , i.location ().end , toString (h256 (i.data ()))));
289
- break ;
290
- case PushSubSize:
291
- collection.append (
292
- createJsonValue (" PUSH #[$]" , sourceIndex, i.location ().start , i.location ().end , toString (h256 (i.data ()))));
293
- break ;
294
- case PushProgramSize:
295
- collection.append (
296
- createJsonValue (" PUSHSIZE" , sourceIndex, i.location ().start , i.location ().end ));
297
- break ;
298
- case PushLibraryAddress:
299
- collection.append (
300
- createJsonValue (" PUSHLIB" , sourceIndex, i.location ().start , i.location ().end , m_libraries.at (h256 (i.data ())))
301
- );
302
- break ;
303
- case PushDeployTimeAddress:
304
- collection.append (
305
- createJsonValue (" PUSHDEPLOYADDRESS" , sourceIndex, i.location ().start , i.location ().end )
306
- );
307
- break ;
308
- case PushImmutable:
309
- collection.append (createJsonValue (
310
- " PUSHIMMUTABLE" ,
311
- sourceIndex,
312
- i.location ().start ,
313
- i.location ().end ,
314
- m_immutables.at (h256 (i.data ()))
315
- ));
316
- break ;
317
- case AssignImmutable:
318
- collection.append (createJsonValue (
319
- " ASSIGNIMMUTABLE" ,
320
- sourceIndex,
321
- i.location ().start ,
322
- i.location ().end ,
323
- m_immutables.at (h256 (i.data ()))
324
- ));
325
- break ;
326
- case Tag:
327
- collection.append (
328
- createJsonValue (" tag" , sourceIndex, i.location ().start , i.location ().end , toString (i.data ())));
329
- collection.append (
330
- createJsonValue (" JUMPDEST" , sourceIndex, i.location ().start , i.location ().end ));
331
- break ;
332
- case PushData:
333
- collection.append (createJsonValue (" PUSH data" , sourceIndex, i.location ().start , i.location ().end , toStringInHex (i.data ())));
334
- break ;
335
- case VerbatimBytecode:
336
- collection.append (createJsonValue (" VERBATIM" , sourceIndex, i.location ().start , i.location ().end , util::toHex (i.verbatimData ())));
337
- break ;
338
- default :
339
- assertThrow (false , InvalidOpcode, " " );
250
+ if (name == " JUMP" )
251
+ item[" value" ] = jumpType;
252
+ if (name == " PUSH" )
253
+ item[" jumpType" ] = jumpType;
254
+ }
255
+ if (name == " PUSHLIB" )
256
+ data = m_libraries.at (h256 (data));
257
+ else if (name == " PUSHIMMUTABLE" || name == " ASSIGNIMMUTABLE" )
258
+ data = m_immutables.at (h256 (data));
259
+ if (!data.empty ())
260
+ item[" value" ] = data;
261
+ item[" source" ] = sourceIndex;
262
+ code.append (item);
263
+
264
+ if (name == " tag" )
265
+ {
266
+ Json::Value jumpdest;
267
+ jumpdest[" name" ] = " JUMPDEST" ;
268
+ jumpdest[" begin" ] = i.location ().start ;
269
+ jumpdest[" end" ] = i.location ().end ;
270
+ jumpdest[" source" ] = sourceIndex;
271
+ code.append (jumpdest);
340
272
}
341
273
}
274
+ if (_includeSourceList)
275
+ {
276
+ root[" sourceList" ] = Json::arrayValue;
277
+ Json::Value& jsonSourceList = root[" sourceList" ];
278
+ vector<string> sourceNames (_sourceIndices.size ());
279
+ for (auto const & [name, index]: _sourceIndices)
280
+ sourceNames[index] = name;
281
+ for (auto const & item: sourceNames)
282
+ jsonSourceList.append (item);
283
+ }
342
284
343
285
if (!m_data.empty () || !m_subs.empty ())
344
286
{
345
287
root[" .data" ] = Json::objectValue;
346
288
Json::Value& data = root[" .data" ];
347
289
for (auto const & i: m_data)
348
290
if (u256 (i.first ) >= m_subs.size ())
349
- data[toStringInHex (( u256)i.first )] = util::toHex (i.second );
291
+ data[util::toHex ( toBigEndian (( u256)i.first ), util::HexPrefix::DontAdd, util::HexCase::Upper )] = util::toHex (i.second );
350
292
351
293
for (size_t i = 0 ; i < m_subs.size (); ++i)
352
294
{
353
295
std::stringstream hexStr;
354
296
hexStr << hex << i;
355
- data[hexStr.str ()] = m_subs[i]->assemblyJSON (_sourceIndices);
297
+ data[hexStr.str ()] = m_subs[i]->assemblyJSON (_sourceIndices, /* _includeSourceList = */ false );
356
298
}
357
299
}
358
300
359
- if (m_auxiliaryData.size () > 0 )
301
+ if (! m_auxiliaryData.empty () )
360
302
root[" .auxdata" ] = util::toHex (m_auxiliaryData);
361
303
362
304
return root;
0 commit comments