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