mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #9323 from ethereum/evm-dialect
Drop instructions() from AsmParser
This commit is contained in:
commit
f2fa5b5fe2
@ -61,27 +61,6 @@ unique_ptr<Block> Parser::parse(std::shared_ptr<Scanner> const& _scanner, bool _
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
std::map<string, evmasm::Instruction> const& Parser::instructions()
|
||||
{
|
||||
// Allowed instructions, lowercase names.
|
||||
static map<string, evmasm::Instruction> s_instructions;
|
||||
if (s_instructions.empty())
|
||||
{
|
||||
for (auto const& instruction: evmasm::c_instructions)
|
||||
{
|
||||
if (
|
||||
instruction.second == evmasm::Instruction::JUMPDEST ||
|
||||
evmasm::isPushInstruction(instruction.second)
|
||||
)
|
||||
continue;
|
||||
string name = instruction.first;
|
||||
transform(name.begin(), name.end(), name.begin(), [](unsigned char _c) { return tolower(_c); });
|
||||
s_instructions[name] = instruction.second;
|
||||
}
|
||||
}
|
||||
return s_instructions;
|
||||
}
|
||||
|
||||
Block Parser::parseBlock()
|
||||
{
|
||||
RecursionGuard recursionGuard(*this);
|
||||
|
@ -30,8 +30,6 @@
|
||||
#include <liblangutil/Scanner.h>
|
||||
#include <liblangutil/ParserBase.h>
|
||||
|
||||
#include <libevmasm/Instruction.h>
|
||||
|
||||
#include <memory>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
@ -62,9 +60,6 @@ public:
|
||||
/// @returns an empty shared pointer on error.
|
||||
std::unique_ptr<Block> parse(std::shared_ptr<langutil::Scanner> const& _scanner, bool _reuseScanner);
|
||||
|
||||
/// @returns a map of all EVM instructions available to assembly.
|
||||
static std::map<std::string, evmasm::Instruction> const& instructions();
|
||||
|
||||
protected:
|
||||
using ElementaryOperation = std::variant<Literal, Identifier, FunctionCall>;
|
||||
|
||||
|
@ -115,18 +115,23 @@ pair<YulString, BuiltinFunctionForEVM> createFunction(
|
||||
map<YulString, BuiltinFunctionForEVM> createBuiltins(langutil::EVMVersion _evmVersion, bool _objectAccess)
|
||||
{
|
||||
map<YulString, BuiltinFunctionForEVM> builtins;
|
||||
// NOTE: Parser::instructions() will filter JUMPDEST and PUSHnn too
|
||||
for (auto const& instr: Parser::instructions())
|
||||
for (auto const& instr: evmasm::c_instructions)
|
||||
{
|
||||
string name = instr.first;
|
||||
transform(name.begin(), name.end(), name.begin(), [](unsigned char _c) { return tolower(_c); });
|
||||
auto const opcode = instr.second;
|
||||
|
||||
if (
|
||||
!evmasm::isDupInstruction(instr.second) &&
|
||||
!evmasm::isSwapInstruction(instr.second) &&
|
||||
!evmasm::isPushInstruction(instr.second) &&
|
||||
instr.second != evmasm::Instruction::JUMP &&
|
||||
instr.second != evmasm::Instruction::JUMPI &&
|
||||
instr.second != evmasm::Instruction::JUMPDEST &&
|
||||
_evmVersion.hasOpcode(instr.second)
|
||||
!evmasm::isDupInstruction(opcode) &&
|
||||
!evmasm::isSwapInstruction(opcode) &&
|
||||
!evmasm::isPushInstruction(opcode) &&
|
||||
opcode != evmasm::Instruction::JUMP &&
|
||||
opcode != evmasm::Instruction::JUMPI &&
|
||||
opcode != evmasm::Instruction::JUMPDEST &&
|
||||
_evmVersion.hasOpcode(opcode)
|
||||
)
|
||||
builtins.emplace(createEVMFunction(instr.first, instr.second));
|
||||
builtins.emplace(createEVMFunction(name, opcode));
|
||||
}
|
||||
|
||||
if (_objectAccess)
|
||||
{
|
||||
|
@ -22,8 +22,6 @@
|
||||
#include <libyul/AsmData.h>
|
||||
#include <libyul/optimiser/CallGraphGenerator.h>
|
||||
|
||||
#include <libevmasm/Instruction.h>
|
||||
|
||||
#include <stack>
|
||||
|
||||
using namespace std;
|
||||
|
@ -24,10 +24,8 @@
|
||||
#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>
|
||||
#include <libsolutil/CommonData.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace solidity;
|
||||
@ -61,7 +59,5 @@ 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;
|
||||
}
|
||||
|
@ -19,8 +19,7 @@
|
||||
#include <libyul/optimiser/VarNameCleaner.h>
|
||||
#include <libyul/AsmData.h>
|
||||
#include <libyul/Dialect.h>
|
||||
#include <libyul/AsmParser.h>
|
||||
#include <libyul/backends/evm/EVMDialect.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <climits>
|
||||
@ -113,8 +112,6 @@ bool VarNameCleaner::isUsedName(YulString const& _name) const
|
||||
{
|
||||
if (_name.empty() || m_dialect.builtin(_name) || m_usedNames.count(_name))
|
||||
return true;
|
||||
if (dynamic_cast<EVMDialect const*>(&m_dialect))
|
||||
return Parser::instructions().count(_name.str());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user