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 = 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) = [ forall j. Word256 -> Opcode' j
PUSH (forall a b. (Integral a, Num b) => a -> b
fromIntegral Position
addr), Opcode
jump ]
inline (JUMPI Position
addr) = [ forall j. Word256 -> Opcode' j
PUSH (forall a b. (Integral a, Num b) => a -> b
fromIntegral Position
addr), Opcode
jumpi ]
inline (JUMPDEST Position
_) = [ Opcode
jumpdest ]
inline PositionalOpcode
opcode = [ forall a. Opcode' a -> Opcode
concrete PositionalOpcode
opcode ]
jumpSize :: Num i => Position -> i
jumpSize :: forall i. Num i => Position -> i
jumpSize Position
pos = forall i. Num i => Opcode -> i
opcodeSize (forall j. Word256 -> Opcode' j
PUSH (forall a b. (Integral a, Num b) => a -> b
fromIntegral Position
pos)) forall a. Num a => a -> a -> a
+ forall i. Num i => Opcode -> i
opcodeSize Opcode
jump