| 497 | } |
| 498 | |
| 499 | Json 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; |
no test coverage detected