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