+parseBasicBlock :: Int -> [OffIns] -> BasicBlock
+parseBasicBlock i insns = BasicBlock insonly endblock
+ where
+ startlist = dropWhile (\((x,_),_) -> x < i) insns
+ (Just ((_,(Just endblock)),_), is) = takeWhilePlusOne validins startlist
+ insonly = snd $ unzip is
+
+ -- also take last (non-matched) element and return it
+ takeWhilePlusOne :: (a -> Bool) -> [a] -> (Maybe a,[a])
+ takeWhilePlusOne _ [] = (Nothing,[])
+ takeWhilePlusOne p (x:xs)
+ | p x = let (lastins, list) = takeWhilePlusOne p xs in (lastins, (x:list))
+ | otherwise = (Just x,[x])
+
+ validins :: ((Int, Maybe BBEnd), Instruction) -> Bool
+ validins ((_,x),_) = case x of Just _ -> False; Nothing -> True
+
+
+calculateInstructionOffset :: [Instruction] -> [OffIns]