module EVM.Opcode.Positional
( Position
, PositionalOpcode
, translate
, jumpSize
) where
import EVM.Opcode (Opcode, Opcode'(..), jump, jumpi, jumpdest, concrete, opcodeSize)
type Position = Word
type PositionalOpcode = Opcode' Position
translate :: [PositionalOpcode] -> [Opcode]
translate :: [PositionalOpcode] -> [Opcode]
translate = (PositionalOpcode -> [Opcode]) -> [PositionalOpcode] -> [Opcode]
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap PositionalOpcode -> [Opcode]
inline
where
inline :: PositionalOpcode -> [Opcode]
inline :: PositionalOpcode -> [Opcode]
inline (JUMP Position
addr) = [ Word256 -> Opcode
forall j. Word256 -> Opcode' j
PUSH (Position -> Word256
forall a b. (Integral a, Num b) => a -> b
fromIntegral Position
addr), Opcode
jump ]
inline (JUMPI Position
addr) = [ Word256 -> Opcode
forall j. Word256 -> Opcode' j
PUSH (Position -> Word256
forall a b. (Integral a, Num b) => a -> b
fromIntegral Position
addr), Opcode
jumpi ]
inline (JUMPDEST Position
_) = [ Opcode
jumpdest ]
inline PositionalOpcode
opcode = [ PositionalOpcode -> Opcode
forall a. Opcode' a -> Opcode
concrete PositionalOpcode
opcode ]
jumpSize :: Num i => Position -> i
jumpSize :: Position -> i
jumpSize Position
pos = Opcode -> i
forall i. Num i => Opcode -> i
opcodeSize (Word256 -> Opcode
forall j. Word256 -> Opcode' j
PUSH (Position -> Word256
forall a b. (Integral a, Num b) => a -> b
fromIntegral Position
pos)) i -> i -> i
forall a. Num a => a -> a -> a
+ Opcode -> i
forall i. Num i => Opcode -> i
opcodeSize Opcode
jump