Prevent instructions to be generated as names.

This commit is contained in:
chriseth
2019-04-24 14:35:21 +02:00
parent eac0048176
commit 0af8d758a5
6 changed files with 56 additions and 25 deletions
+14 -1
View File
@@ -23,6 +23,10 @@
#include <libyul/optimiser/NameCollector.h>
#include <libyul/AsmData.h>
#include <libyul/Dialect.h>
#include <libyul/backends/evm/EVMDialect.h>
#include <libyul/AsmParser.h>
#include <libevmasm/Instruction.h>
using namespace std;
using namespace dev;
@@ -42,7 +46,7 @@ NameDispenser::NameDispenser(Dialect const& _dialect, set<YulString> _usedNames)
YulString NameDispenser::newName(YulString _nameHint)
{
YulString name = _nameHint;
while (name.empty() || m_usedNames.count(name) || m_dialect.builtin(name))
while (illegalName(name))
{
m_counter++;
name = YulString(_nameHint.str() + "_" + to_string(m_counter));
@@ -50,3 +54,12 @@ YulString NameDispenser::newName(YulString _nameHint)
m_usedNames.emplace(name);
return name;
}
bool NameDispenser::illegalName(YulString _name)
{
if (_name.empty() || m_usedNames.count(_name) || m_dialect.builtin(_name))
return true;
if (dynamic_cast<EVMDialect const*>(&m_dialect))
return Parser::instructions().count(_name.str());
return false;
}