diff options
Diffstat (limited to 'libevmasm')
-rw-r--r-- | libevmasm/AssemblyItem.cpp | 16 | ||||
-rw-r--r-- | libevmasm/Instruction.h | 14 |
2 files changed, 19 insertions, 11 deletions
diff --git a/libevmasm/AssemblyItem.cpp b/libevmasm/AssemblyItem.cpp index 5af618ff..a3a4d6b6 100644 --- a/libevmasm/AssemblyItem.cpp +++ b/libevmasm/AssemblyItem.cpp @@ -26,27 +26,35 @@ using namespace std; using namespace dev; using namespace dev::eth; +static_assert(sizeof(size_t) <= 8, "size_t must be at most 64-bits wide"); + AssemblyItem AssemblyItem::toSubAssemblyTag(size_t _subId) const { assertThrow(data() < (u256(1) << 64), Exception, "Tag already has subassembly set."); - assertThrow(m_type == PushTag || m_type == Tag, Exception, ""); + size_t tag = size_t(u256(data()) & 0xffffffffffffffffULL); AssemblyItem r = *this; r.m_type = PushTag; - r.setPushTagSubIdAndTag(_subId, size_t(data())); + r.setPushTagSubIdAndTag(_subId, tag); return r; } pair<size_t, size_t> AssemblyItem::splitForeignPushTag() const { assertThrow(m_type == PushTag || m_type == Tag, Exception, ""); - return make_pair(size_t((data()) / (u256(1) << 64)) - 1, size_t(data())); + u256 combined = u256(data()); + size_t subId = size_t((combined >> 64) - 1); + size_t tag = size_t(combined & 0xffffffffffffffffULL); + return make_pair(subId, tag); } void AssemblyItem::setPushTagSubIdAndTag(size_t _subId, size_t _tag) { assertThrow(m_type == PushTag || m_type == Tag, Exception, ""); - setData(_tag + (u256(_subId + 1) << 64)); + u256 data = _tag; + if (_subId != size_t(-1)) + data |= (u256(_subId) + 1) << 64; + setData(data); } unsigned AssemblyItem::bytesRequired(unsigned _addressLength) const diff --git a/libevmasm/Instruction.h b/libevmasm/Instruction.h index be788ddb..dc116f88 100644 --- a/libevmasm/Instruction.h +++ b/libevmasm/Instruction.h @@ -39,7 +39,7 @@ enum class Instruction: uint8_t { STOP = 0x00, ///< halts execution ADD, ///< addition operation - MUL, ///< mulitplication operation + MUL, ///< multiplication operation SUB, ///< subtraction operation DIV, ///< integer division operation SDIV, ///< signed integer division operation @@ -50,11 +50,11 @@ enum class Instruction: uint8_t EXP, ///< exponential operation SIGNEXTEND, ///< extend length of signed integer - LT = 0x10, ///< less-than comparision - GT, ///< greater-than comparision - SLT, ///< signed less-than comparision - SGT, ///< signed greater-than comparision - EQ, ///< equality comparision + LT = 0x10, ///< less-than comparison + GT, ///< greater-than comparison + SLT, ///< signed less-than comparison + SGT, ///< signed greater-than comparison + EQ, ///< equality comparison ISZERO, ///< simple not operator AND, ///< bitwise AND operation OR, ///< bitwise OR operation @@ -293,7 +293,7 @@ struct InstructionInfo /// Information on all the instructions. InstructionInfo instructionInfo(Instruction _inst); -/// check whether instructions exists +/// check whether instructions exists. bool isValidInstruction(Instruction _inst); /// Convert from string mnemonic to Instruction type. |