MCPcopy Create free account
hub / github.com/argotorg/solidity / assemblyJSON

Method assemblyJSON

libevmasm/Assembly.cpp:499–586  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

497}
498
499Json Assembly::assemblyJSON(std::map<std::string, unsigned> const& _sourceIndices, bool _includeSourceList) const
500{
501 Json root;
502 root[".code"] = Json::array();
503 Json& code = root[".code"];
504 // TODO: support EOF
505 solUnimplementedAssert(!m_eofVersion.has_value(), "Assembly output for EOF is not yet implemented.");
506 solAssert(m_codeSections.size() == 1);
507 for (AssemblyItem const& item: m_codeSections.front().items)
508 {
509 int sourceIndex = -1;
510 if (item.location().sourceName)
511 {
512 auto iter = _sourceIndices.find(*item.location().sourceName);
513 if (iter != _sourceIndices.end())
514 sourceIndex = static_cast<int>(iter->second);
515 }
516
517 auto [name, data] = item.nameAndData(m_evmVersion);
518 Json jsonItem;
519 jsonItem["name"] = name;
520 jsonItem["begin"] = item.location().start;
521 jsonItem["end"] = item.location().end;
522 if (item.m_modifierDepth != 0)
523 jsonItem["modifierDepth"] = static_cast<int>(item.m_modifierDepth);
524 std::string jumpType = item.getJumpTypeAsString();
525 if (!jumpType.empty())
526 jsonItem["jumpType"] = jumpType;
527 if (name == "PUSHLIB")
528 data = m_libraries.at(h256(data));
529 else if (name == "PUSHIMMUTABLE" || name == "ASSIGNIMMUTABLE")
530 data = m_immutables.at(h256(data));
531 if (!data.empty())
532 jsonItem["value"] = data;
533 jsonItem["source"] = sourceIndex;
534 code.emplace_back(std::move(jsonItem));
535
536 if (item.type() == AssemblyItemType::Tag)
537 {
538 Json jumpdest;
539 jumpdest["name"] = "JUMPDEST";
540 jumpdest["begin"] = item.location().start;
541 jumpdest["end"] = item.location().end;
542 jumpdest["source"] = sourceIndex;
543 if (item.m_modifierDepth != 0)
544 jumpdest["modifierDepth"] = static_cast<int>(item.m_modifierDepth);
545 code.emplace_back(std::move(jumpdest));
546 }
547 }
548 if (_includeSourceList)
549 {
550 root["sourceList"] = Json::array();
551 Json& jsonSourceList = root["sourceList"];
552 unsigned maxSourceIndex = 0;
553 for (auto const& [sourceName, sourceIndex]: _sourceIndices)
554 {
555 maxSourceIndex = std::max(sourceIndex, maxSourceIndex);
556 jsonSourceList[sourceIndex] = sourceName;

Callers 4

Assembler.cppFile · 0.45
handleEVMAssemblyMethod · 0.45
handleCombinedJSONMethod · 0.45
assembleYulMethod · 0.45

Calls 12

toHexFunction · 0.85
toBigEndianFunction · 0.85
nameAndDataMethod · 0.80
getJumpTypeAsStringMethod · 0.80
atMethod · 0.80
strMethod · 0.80
sizeMethod · 0.45
locationMethod · 0.45
findMethod · 0.45
endMethod · 0.45
emptyMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected