Skip to content

Commit a2fdac2

Browse files
committed
fixup! [libevmasm] Add support to import evm assembly json.
1 parent 8e2cdc0 commit a2fdac2

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

libevmasm/Assembly.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ using namespace solidity::evmasm;
5252
using namespace solidity::langutil;
5353
using namespace solidity::util;
5454

55+
std::map<std::string, std::shared_ptr<std::string const>> Assembly::s_sharedSourceNames;
56+
5557
AssemblyItem const& Assembly::append(AssemblyItem _i)
5658
{
5759
assertThrow(m_deposit >= 0, AssemblyException, "Stack underflow.");
@@ -171,12 +173,7 @@ AssemblyItem Assembly::createAssemblyItemFromJSON(Json::Value const& _json, std:
171173

172174
solRequire(srcIndex >= -1 && srcIndex < static_cast<int>(_sourceList.size()), AssemblyImportException, "Source index out of bounds.");
173175
if (srcIndex != -1)
174-
{
175-
static std::map<std::string, std::shared_ptr<std::string const>> sharedSourceNames;
176-
if (sharedSourceNames.find(_sourceList[static_cast<size_t>(srcIndex)]) == sharedSourceNames.end())
177-
sharedSourceNames[_sourceList[static_cast<size_t>(srcIndex)]] = std::make_shared<std::string>(_sourceList[static_cast<size_t>(srcIndex)]);
178-
location.sourceName = sharedSourceNames[_sourceList[static_cast<size_t>(srcIndex)]];
179-
}
176+
location.sourceName = sharedSourceName(_sourceList[static_cast<size_t>(srcIndex)]);
180177

181178
AssemblyItem result(0);
182179

@@ -637,6 +634,14 @@ void Assembly::encodeAllPossibleSubPathsInAssemblyTree(std::vector<size_t> _path
637634
}
638635
}
639636

637+
std::shared_ptr<std::string const> Assembly::sharedSourceName(std::string const& _name) const
638+
{
639+
if (s_sharedSourceNames.find(_name) == s_sharedSourceNames.end())
640+
s_sharedSourceNames[_name] = std::make_shared<std::string>(_name);
641+
642+
return s_sharedSourceNames[_name];
643+
}
644+
640645
AssemblyItem Assembly::namedTag(std::string const& _name, size_t _params, size_t _returns, std::optional<uint64_t> _sourceID)
641646
{
642647
assertThrow(!_name.empty(), AssemblyException, "Empty named tag.");

libevmasm/Assembly.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ class Assembly
203203

204204
void encodeAllPossibleSubPathsInAssemblyTree(std::vector<size_t> _pathFromRoot = {}, std::vector<Assembly*> _assembliesOnPath = {});
205205

206+
std::shared_ptr<std::string const> sharedSourceName(std::string const& _name) const;
207+
206208
protected:
207209
/// 0 is reserved for exception
208210
unsigned m_usedTags = 1;
@@ -246,6 +248,9 @@ class Assembly
246248
std::string m_name;
247249
langutil::SourceLocation m_currentSourceLocation;
248250

251+
// FIXME: This being static means that the strings won't be freed when they're no longer needed
252+
static std::map<std::string, std::shared_ptr<std::string const>> s_sharedSourceNames;
253+
249254
public:
250255
size_t m_currentModifierDepth = 0;
251256
};

0 commit comments

Comments
 (0)