- newoffset :: Instruction -> Int -> Offset
- newoffset x off = (off + fromIntegral (B.length $ encodeInstructions [x]), Nothing)
-
- addW16Signed :: Int -> Word16 -> Int
- addW16Signed i w16 = i + fromIntegral s16
- where s16 = fromIntegral w16 :: Int16
-
- cio' :: Offset -> [Instruction] -> [OffIns]
- cio' _ [] = []
- -- TODO(bernhard): add more instruction with offset (IF_ACMP, JSR, ...)
- cio' (off,_) (x:xs) = case x of
- IF _ w16 -> twotargets w16
- IF_ICMP _ w16 -> twotargets w16
- IF_ACMP _ w16 -> twotargets w16
- GOTO w16 -> onetarget w16
- IRETURN -> notarget
- ARETURN -> notarget
- RETURN -> notarget
- _ -> ((off, Nothing), x):next
- where
- notarget = ((off, Just Return), x):next
- onetarget w16 = ((off, Just $ OneTarget (off `addW16Signed` w16)), x):next
- twotargets w16 = ((off, Just $ TwoTarget (off + 3) (off `addW16Signed` w16)), x):next
- next = cio' (newoffset x off) xs
+ newoffset :: Instruction -> Int -> Offset
+ newoffset x off = (off + fromIntegral (B.length $ encodeInstructions [x]), Nothing)
+
+ addW16Signed :: Int -> Word16 -> Int
+ addW16Signed i w16 = i + fromIntegral s16
+ where s16 = fromIntegral w16 :: Int16
+
+ cio' :: Offset -> [Instruction] -> [OffIns]
+ cio' _ [] = []
+ -- TODO(bernhard): add more instruction with offset (IF_ACMP, JSR, ...)
+ cio' (off,_) (x:xs) = case x of
+ IF _ w16 -> twotargets w16
+ IF_ICMP _ w16 -> twotargets w16
+ IF_ACMP _ w16 -> twotargets w16
+ IFNONNULL w16 -> twotargets w16
+ IFNULL w16 -> twotargets w16
+ GOTO w16 -> onetarget w16
+ IRETURN -> notarget
+ ARETURN -> notarget
+ RETURN -> notarget
+ _ -> ((off, Nothing), x):next
+ where
+ notarget = ((off, Just Return), x):next
+ onetarget w16 = ((off, Just $ OneTarget (off `addW16Signed` w16)), x):next
+ twotargets w16 = ((off, Just $ TwoTarget (off + 3) (off `addW16Signed` w16)), x):next
+ next = cio' (newoffset x off) xs