Instruction.cpp
1 #include "Instruction.h" 2 3 #include "preprocessor/llvm_includes_start.h" 4 #include <llvm/ADT/APInt.h> 5 #include "preprocessor/llvm_includes_end.h" 6 7 namespace dev 8 { 9 namespace evmjit 10 { 11 12 llvm::APInt readPushData(code_iterator& _curr, code_iterator _end) 13 { 14 auto pushInst = *_curr; 15 assert(Instruction(pushInst) >= Instruction::PUSH1 && Instruction(pushInst) <= Instruction::PUSH32); 16 auto numBytes = pushInst - static_cast<size_t>(Instruction::PUSH1) + 1; 17 llvm::APInt value(256, 0); 18 ++_curr; // Point the data 19 for (decltype(numBytes) i = 0; i < numBytes; ++i) 20 { 21 byte b = (_curr != _end) ? *_curr++ : 0; 22 value <<= 8; 23 value |= b; 24 } 25 --_curr; // Point the last real byte read 26 return value; 27 } 28 29 void skipPushData(code_iterator& _curr, code_iterator _end) 30 { 31 auto pushInst = *_curr; 32 assert(Instruction(pushInst) >= Instruction::PUSH1 && Instruction(pushInst) <= Instruction::PUSH32); 33 auto numBytes = pushInst - static_cast<size_t>(Instruction::PUSH1) + 1; 34 --_end; 35 for (decltype(numBytes) i = 0; i < numBytes && _curr < _end; ++i, ++_curr) {} 36 } 37 38 } 39 }