@@ -222,13 +222,16 @@ 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 (
226
+ string _name, int _sourceIndex, size_t _modifierDepth, int _begin, int _end, string _value, string _jumpType)
226
227
{
227
228
Json::Value value{Json::objectValue};
228
229
value[" name" ] = _name;
229
- value[" source" ] = _source ;
230
+ value[" source" ] = _sourceIndex ;
230
231
value[" begin" ] = _begin;
231
232
value[" end" ] = _end;
233
+ if (_modifierDepth != 0 )
234
+ value[" modifierDepth" ] = static_cast <int >(_modifierDepth);
232
235
if (!_value.empty ())
233
236
value[" value" ] = _value;
234
237
if (!_jumpType.empty ())
@@ -248,7 +251,8 @@ AssemblyItem Assembly::loadItemFromJSON(Json::Value const& _json)
248
251
std::string name = _json[" name" ].isString () ? _json[" name" ].asString () : " " ;
249
252
int begin = _json[" begin" ].isInt () ? _json[" begin" ].asInt () : -1 ;
250
253
int end = _json[" end" ].isInt () ? _json[" end" ].asInt () : -1 ;
251
- int srcIndex = _json[" source" ].isInt () ? _json[" source" ].asInt () : -1 ;
254
+ int srcIndex = _json[" source" ].isInt () ? _json[" source" ].asInt () : -1 ;
255
+ size_t modifierDepth = _json[" modifierDepth" ].isInt () ? static_cast <size_t >(_json[" modifierDepth" ].asInt ()) : 0 ;
252
256
std::string value = _json[" value" ].isString () ? _json[" value" ].asString () : " " ;
253
257
std::string jumpType = _json[" jumpType" ].isString () ? _json[" jumpType" ].asString () : " " ;
254
258
solAssert (!name.empty (), " " );
@@ -274,15 +278,18 @@ AssemblyItem Assembly::loadItemFromJSON(Json::Value const& _json)
274
278
SourceLocation location;
275
279
location.start = begin;
276
280
location.end = end;
277
- if (srcIndex > -1 && srcIndex < (int )sources ().size ())
281
+ if (srcIndex > -1 && srcIndex < (int ) sources ().size ())
278
282
location.sourceName = sources ()[static_cast <size_t >(srcIndex)];
279
283
284
+ AssemblyItem result (0 );
285
+
280
286
if (c_instructions.find (name) != c_instructions.end ())
281
287
{
282
288
AssemblyItem item{c_instructions.at (name), location};
289
+ item.m_modifierDepth = modifierDepth;
283
290
if (!value.empty ())
284
291
item.setJumpType (value);
285
- return item;
292
+ result = item;
286
293
}
287
294
else
288
295
{
@@ -294,69 +301,71 @@ AssemblyItem Assembly::loadItemFromJSON(Json::Value const& _json)
294
301
AssemblyItem item{AssemblyItemType::Push, data, location};
295
302
if (!jumpType.empty ())
296
303
item.setJumpType (jumpType);
297
- return item;
304
+ result = item;
298
305
}
299
306
else if (name == " PUSH [ErrorTag]" )
300
- return {AssemblyItemType::PushTag, data, location};
307
+ result = {AssemblyItemType::PushTag, data, location};
301
308
else if (name == " PUSH [tag]" )
302
309
{
303
310
if (!value.empty ())
304
311
data = u256 (value);
305
312
updateUsedTags (data);
306
- return {AssemblyItemType::PushTag, data, location};
313
+ result = {AssemblyItemType::PushTag, data, location};
307
314
}
308
315
else if (name == " PUSH [$]" )
309
316
{
310
317
if (!value.empty ())
311
318
data = u256 (" 0x" + value);
312
- return {AssemblyItemType::PushSub, data, location};
319
+ result = {AssemblyItemType::PushSub, data, location};
313
320
}
314
321
else if (name == " PUSH #[$]" )
315
322
{
316
323
if (!value.empty ())
317
324
data = u256 (" 0x" + value);
318
- return {AssemblyItemType::PushSubSize, data, location};
325
+ result = {AssemblyItemType::PushSubSize, data, location};
319
326
}
320
327
else if (name == " PUSHSIZE" )
321
- return {AssemblyItemType::PushProgramSize, data, location};
328
+ result = {AssemblyItemType::PushProgramSize, data, location};
322
329
else if (name == " PUSHLIB" )
323
330
{
324
331
h256 hash = updateLibraries (value);
325
- return {AssemblyItemType::PushLibraryAddress, hash, location};
332
+ result = {AssemblyItemType::PushLibraryAddress, hash, location};
326
333
}
327
334
else if (name == " PUSHDEPLOYADDRESS" )
328
- return {AssemblyItemType::PushDeployTimeAddress, data, location};
335
+ result = {AssemblyItemType::PushDeployTimeAddress, data, location};
329
336
else if (name == " PUSHIMMUTABLE" )
330
337
{
331
338
h256 hash = updateImmutables (value);
332
- return {AssemblyItemType::PushImmutable, hash, location};
339
+ result = {AssemblyItemType::PushImmutable, hash, location};
333
340
}
334
341
else if (name == " ASSIGNIMMUTABLE" )
335
342
{
336
343
h256 hash = updateImmutables (value);
337
- return {AssemblyItemType::AssignImmutable, hash, location};
344
+ result = {AssemblyItemType::AssignImmutable, hash, location};
338
345
}
339
346
else if (name == " tag" )
340
347
{
341
348
if (!value.empty ())
342
349
data = u256 (value);
343
- return {AssemblyItemType::Tag, data, location};
350
+ result = {AssemblyItemType::Tag, data, location};
344
351
}
345
352
else if (name == " PUSH data" )
346
353
{
347
354
if (!value.empty ())
348
355
data = u256 (" 0x" + value);
349
- return {AssemblyItemType::PushData, data, location};
356
+ result = {AssemblyItemType::PushData, data, location};
350
357
}
351
358
else if (name == " VERBATIM" )
352
359
{
353
360
AssemblyItem item (fromHex (value), 0 , 0 );
354
361
item.setLocation (location);
355
- return item;
362
+ result = item;
356
363
}
357
364
else
358
365
assertThrow (false , InvalidOpcode, " " );
359
366
}
367
+ result.m_modifierDepth = modifierDepth;
368
+ return result;
360
369
}
361
370
362
371
vector<Json::Value> Assembly::assemblyItemAsJSON (AssemblyItem const & _item, int _sourceIndex) const
@@ -369,6 +378,7 @@ vector<Json::Value> Assembly::assemblyItemAsJSON(AssemblyItem const& _item, int
369
378
result.emplace_back (createJsonValue (
370
379
instructionInfo (_item.instruction ()).name ,
371
380
_sourceIndex,
381
+ _item.m_modifierDepth ,
372
382
_item.location ().start ,
373
383
_item.location ().end ,
374
384
_item.getJumpTypeAsString ()));
@@ -377,42 +387,70 @@ vector<Json::Value> Assembly::assemblyItemAsJSON(AssemblyItem const& _item, int
377
387
result.emplace_back (createJsonValue (
378
388
" PUSH" ,
379
389
_sourceIndex,
390
+ _item.m_modifierDepth ,
380
391
_item.location ().start ,
381
392
_item.location ().end ,
382
393
toStringInHex (_item.data ()),
383
394
_item.getJumpTypeAsString ()));
384
395
break ;
385
396
case PushTag:
386
397
if (_item.data () == 0 )
387
- result.emplace_back (
388
- createJsonValue (" PUSH [ErrorTag]" , _sourceIndex, _item.location ().start , _item.location ().end , " " ));
398
+ result.emplace_back (createJsonValue (
399
+ " PUSH [ErrorTag]" ,
400
+ _sourceIndex,
401
+ _item.m_modifierDepth ,
402
+ _item.location ().start ,
403
+ _item.location ().end ,
404
+ " " ));
389
405
else
390
406
result.emplace_back (createJsonValue (
391
- " PUSH [tag]" , _sourceIndex, _item.location ().start , _item.location ().end , toString (_item.data ())));
407
+ " PUSH [tag]" ,
408
+ _sourceIndex,
409
+ _item.m_modifierDepth ,
410
+ _item.location ().start ,
411
+ _item.location ().end ,
412
+ toString (_item.data ())));
392
413
break ;
393
414
case PushSub:
394
415
result.emplace_back (createJsonValue (
395
- " PUSH [$]" , _sourceIndex, _item.location ().start , _item.location ().end , toString (h256 (_item.data ()))));
416
+ " PUSH [$]" ,
417
+ _sourceIndex,
418
+ _item.m_modifierDepth ,
419
+ _item.location ().start ,
420
+ _item.location ().end ,
421
+ toString (h256 (_item.data ()))));
396
422
break ;
397
423
case PushSubSize:
398
424
result.emplace_back (createJsonValue (
399
- " PUSH #[$]" , _sourceIndex, _item.location ().start , _item.location ().end , toString (h256 (_item.data ()))));
425
+ " PUSH #[$]" ,
426
+ _sourceIndex,
427
+ _item.m_modifierDepth ,
428
+ _item.location ().start ,
429
+ _item.location ().end ,
430
+ toString (h256 (_item.data ()))));
400
431
break ;
401
432
case PushProgramSize:
402
- result.emplace_back (createJsonValue (" PUSHSIZE" , _sourceIndex, _item.location ().start , _item.location ().end ));
433
+ result.emplace_back (createJsonValue (
434
+ " PUSHSIZE" , _sourceIndex, _item.m_modifierDepth , _item.location ().start , _item.location ().end ));
403
435
break ;
404
436
case PushLibraryAddress:
405
437
result.emplace_back (createJsonValue (
406
- " PUSHLIB" , _sourceIndex, _item.location ().start , _item.location ().end , m_libraries.at (h256 (_item.data ()))));
438
+ " PUSHLIB" ,
439
+ _sourceIndex,
440
+ _item.m_modifierDepth ,
441
+ _item.location ().start ,
442
+ _item.location ().end ,
443
+ m_libraries.at (h256 (_item.data ()))));
407
444
break ;
408
445
case PushDeployTimeAddress:
409
- result.emplace_back (
410
- createJsonValue ( " PUSHDEPLOYADDRESS" , _sourceIndex, _item.location ().start , _item.location ().end ));
446
+ result.emplace_back (createJsonValue (
447
+ " PUSHDEPLOYADDRESS" , _sourceIndex, _item. m_modifierDepth , _item.location ().start , _item.location ().end ));
411
448
break ;
412
449
case PushImmutable:
413
450
result.emplace_back (createJsonValue (
414
451
" PUSHIMMUTABLE" ,
415
452
_sourceIndex,
453
+ _item.m_modifierDepth ,
416
454
_item.location ().start ,
417
455
_item.location ().end ,
418
456
m_immutables.at (h256 (_item.data ()))));
@@ -421,22 +459,39 @@ vector<Json::Value> Assembly::assemblyItemAsJSON(AssemblyItem const& _item, int
421
459
result.emplace_back (createJsonValue (
422
460
" ASSIGNIMMUTABLE" ,
423
461
_sourceIndex,
462
+ _item.m_modifierDepth ,
424
463
_item.location ().start ,
425
464
_item.location ().end ,
426
465
m_immutables.at (h256 (_item.data ()))));
427
466
break ;
428
467
case Tag:
429
- result.emplace_back (
430
- createJsonValue (" tag" , _sourceIndex, _item.location ().start , _item.location ().end , toString (_item.data ())));
431
- result.emplace_back (createJsonValue (" JUMPDEST" , _sourceIndex, _item.location ().start , _item.location ().end ));
468
+ result.emplace_back (createJsonValue (
469
+ " tag" ,
470
+ _sourceIndex,
471
+ _item.m_modifierDepth ,
472
+ _item.location ().start ,
473
+ _item.location ().end ,
474
+ toString (_item.data ())));
475
+ result.emplace_back (createJsonValue (
476
+ " JUMPDEST" , _sourceIndex, _item.m_modifierDepth , _item.location ().start , _item.location ().end ));
432
477
break ;
433
478
case PushData:
434
479
result.emplace_back (createJsonValue (
435
- " PUSH data" , _sourceIndex, _item.location ().start , _item.location ().end , toStringInHex (_item.data ())));
480
+ " PUSH data" ,
481
+ _sourceIndex,
482
+ _item.m_modifierDepth ,
483
+ _item.location ().start ,
484
+ _item.location ().end ,
485
+ toStringInHex (_item.data ())));
436
486
break ;
437
487
case VerbatimBytecode:
438
488
result.emplace_back (createJsonValue (
439
- " VERBATIM" , _sourceIndex, _item.location ().start , _item.location ().end , util::toHex (_item.verbatimData ())));
489
+ " VERBATIM" ,
490
+ _sourceIndex,
491
+ _item.m_modifierDepth ,
492
+ _item.location ().start ,
493
+ _item.location ().end ,
494
+ util::toHex (_item.verbatimData ())));
440
495
break ;
441
496
default :
442
497
assertThrow (false , InvalidOpcode, " " );
0 commit comments