aboutsummaryrefslogtreecommitdiffstats
path: root/libevmasm
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-09-19 04:25:52 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-09-26 03:39:35 +0800
commit21beba76e2d4d30949da6eddd2473c34c426d047 (patch)
treef1ffdb35d5cda42ac6209806af2f39a30ca6251e /libevmasm
parent608f36d77b0dc6d908d89fe3a1b8e1626df8391c (diff)
downloaddexon-solidity-21beba76e2d4d30949da6eddd2473c34c426d047.tar.gz
dexon-solidity-21beba76e2d4d30949da6eddd2473c34c426d047.tar.zst
dexon-solidity-21beba76e2d4d30949da6eddd2473c34c426d047.zip
Add helpers for the LOG instruction
Diffstat (limited to 'libevmasm')
-rw-r--r--libevmasm/GasMeter.cpp3
-rw-r--r--libevmasm/Instruction.h12
2 files changed, 13 insertions, 2 deletions
diff --git a/libevmasm/GasMeter.cpp b/libevmasm/GasMeter.cpp
index 3554f809..b525c301 100644
--- a/libevmasm/GasMeter.cpp
+++ b/libevmasm/GasMeter.cpp
@@ -125,8 +125,7 @@ GasMeter::GasConsumption GasMeter::estimateMax(AssemblyItem const& _item, bool _
case Instruction::LOG3:
case Instruction::LOG4:
{
- unsigned n = unsigned(_item.instruction()) - unsigned(Instruction::LOG0);
- gas = GasCosts::logGas + GasCosts::logTopicGas * n;
+ gas = GasCosts::logGas + GasCosts::logTopicGas * getLogNumber(_item.instruction());
gas += memoryGas(0, -1);
if (u256 const* value = classes.knownConstant(m_state->relativeStackElement(-1)))
gas += GasCosts::logDataGas * (*value);
diff --git a/libevmasm/Instruction.h b/libevmasm/Instruction.h
index e2e2b63e..50c1f47d 100644
--- a/libevmasm/Instruction.h
+++ b/libevmasm/Instruction.h
@@ -218,6 +218,12 @@ inline bool isSwapInstruction(Instruction _inst)
return Instruction::SWAP1 <= _inst && _inst <= Instruction::SWAP16;
}
+/// @returns true if the instruction is a LOG
+inline bool isLogInstruction(Instruction _inst)
+{
+ return Instruction::LOG0 <= _inst && _inst <= Instruction::LOG4;
+}
+
/// @returns the number of PUSH Instruction _inst
inline unsigned getPushNumber(Instruction _inst)
{
@@ -236,6 +242,12 @@ inline unsigned getSwapNumber(Instruction _inst)
return (byte)_inst - unsigned(Instruction::SWAP1) + 1;
}
+/// @returns the number of LOG Instruction _inst
+inline unsigned getLogNumber(Instruction _inst)
+{
+ return (byte)_inst - unsigned(Instruction::LOG0);
+}
+
/// @returns the PUSH<_number> instruction
inline Instruction pushInstruction(unsigned _number)
{