aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-10-02 18:51:44 +0800
committerGitHub <noreply@github.com>2017-10-02 18:51:44 +0800
commitc61610302aa2bfa029715b534719d25fe3949059 (patch)
treea4eeccab1f5ff547528dff4cf675006336c435b2
parentba7c5d2305d3486ddd699637a881ee229627082f (diff)
parent8a32d7c3d73a303198ab069459718cd2de1be67c (diff)
downloaddexon-solidity-c61610302aa2bfa029715b534719d25fe3949059.tar
dexon-solidity-c61610302aa2bfa029715b534719d25fe3949059.tar.gz
dexon-solidity-c61610302aa2bfa029715b534719d25fe3949059.tar.bz2
dexon-solidity-c61610302aa2bfa029715b534719d25fe3949059.tar.lz
dexon-solidity-c61610302aa2bfa029715b534719d25fe3949059.tar.xz
dexon-solidity-c61610302aa2bfa029715b534719d25fe3949059.tar.zst
dexon-solidity-c61610302aa2bfa029715b534719d25fe3949059.zip
Merge pull request #3004 from ethereum/instr-helpers
Add helpers for isPush/isDup/isSwap
-rw-r--r--libevmasm/Instruction.h18
-rw-r--r--libsolidity/inlineasm/AsmParser.cpp6
2 files changed, 21 insertions, 3 deletions
diff --git a/libevmasm/Instruction.h b/libevmasm/Instruction.h
index afbef71d..d9c53900 100644
--- a/libevmasm/Instruction.h
+++ b/libevmasm/Instruction.h
@@ -197,6 +197,24 @@ enum class Instruction: uint8_t
SELFDESTRUCT = 0xff ///< halt execution and register account for later deletion
};
+/// @returns true if the instruction is a PUSH
+inline bool isPushInstruction(Instruction _inst)
+{
+ return Instruction::PUSH1 <= _inst && _inst <= Instruction::PUSH32;
+}
+
+/// @returns true if the instruction is a DUP
+inline bool isDupInstruction(Instruction _inst)
+{
+ return Instruction::DUP1 <= _inst && _inst <= Instruction::DUP16;
+}
+
+/// @returns true if the instruction is a SWAP
+inline bool isSwapInstruction(Instruction _inst)
+{
+ return Instruction::SWAP1 <= _inst && _inst <= Instruction::SWAP16;
+}
+
/// @returns the number of PUSH Instruction _inst
inline unsigned getPushNumber(Instruction _inst)
{
diff --git a/libsolidity/inlineasm/AsmParser.cpp b/libsolidity/inlineasm/AsmParser.cpp
index 3087ad86..1f4df75b 100644
--- a/libsolidity/inlineasm/AsmParser.cpp
+++ b/libsolidity/inlineasm/AsmParser.cpp
@@ -256,7 +256,7 @@ std::map<string, dev::solidity::Instruction> const& Parser::instructions()
{
if (
instruction.second == solidity::Instruction::JUMPDEST ||
- (solidity::Instruction::PUSH1 <= instruction.second && instruction.second <= solidity::Instruction::PUSH32)
+ solidity::isPushInstruction(instruction.second)
)
continue;
string name = instruction.first;
@@ -443,9 +443,9 @@ assembly::Statement Parser::parseCall(assembly::Statement&& _instruction)
ret.location = ret.instruction.location;
solidity::Instruction instr = ret.instruction.instruction;
InstructionInfo instrInfo = instructionInfo(instr);
- if (solidity::Instruction::DUP1 <= instr && instr <= solidity::Instruction::DUP16)
+ if (solidity::isDupInstruction(instr))
fatalParserError("DUPi instructions not allowed for functional notation");
- if (solidity::Instruction::SWAP1 <= instr && instr <= solidity::Instruction::SWAP16)
+ if (solidity::isSwapInstruction(instr))
fatalParserError("SWAPi instructions not allowed for functional notation");
expectToken(Token::LParen);
unsigned args = unsigned(instrInfo.args);