| 134 | } |
| 135 | |
| 136 | void Assembly::importAssemblyItemsFromJSON(Json const& _code, std::vector<std::string> const& _sourceList) |
| 137 | { |
| 138 | // Assembly constructor creates first code section with proper type and empty `items` |
| 139 | solAssert(m_codeSections.size() == 1); |
| 140 | solAssert(m_codeSections[0].items.empty()); |
| 141 | // TODO: Add support for EOF and more than one code sections. |
| 142 | solUnimplementedAssert(!m_eofVersion.has_value(), "Assembly import for EOF is not yet implemented."); |
| 143 | solRequire(_code.is_array(), AssemblyImportException, "Supplied JSON is not an array."); |
| 144 | for (auto jsonItemIter = std::begin(_code); jsonItemIter != std::end(_code); ++jsonItemIter) |
| 145 | { |
| 146 | AssemblyItem const& newItem = m_codeSections[0].items.emplace_back(createAssemblyItemFromJSON(*jsonItemIter, _sourceList)); |
| 147 | if (newItem == Instruction::JUMPDEST) |
| 148 | solThrow(AssemblyImportException, "JUMPDEST instruction without a tag"); |
| 149 | else if (newItem.type() == AssemblyItemType::Tag) |
| 150 | { |
| 151 | ++jsonItemIter; |
| 152 | if (jsonItemIter != std::end(_code) && createAssemblyItemFromJSON(*jsonItemIter, _sourceList) != Instruction::JUMPDEST) |
| 153 | solThrow(AssemblyImportException, "JUMPDEST expected after tag."); |
| 154 | } |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | AssemblyItem Assembly::createAssemblyItemFromJSON(Json const& _json, std::vector<std::string> const& _sourceList) |
| 159 | { |