From 562341501dfeab7e6ec85b54ec5f3f4aa1c02078 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Mon, 2 Apr 2012 21:40:00 +0200 Subject: [PATCH] basicblock: calculate offset in instructionstream --- Mate/BasicBlocks.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/Mate/BasicBlocks.hs b/Mate/BasicBlocks.hs index 1db0710..68d8cb9 100644 --- a/Mate/BasicBlocks.hs +++ b/Mate/BasicBlocks.hs @@ -60,4 +60,15 @@ testCFG _ = error "no method to build cfg" buildCFG :: [Instruction] -> [String] -buildCFG xs = map show xs +buildCFG xs = map (\(x,y) -> show x ++ ", " ++ show y) xs' + where + xs' = calculateInstructionOffset xs + +type Offset = Int +calculateInstructionOffset :: [Instruction] -> [(Offset, Instruction)] +calculateInstructionOffset = cio' 0 + where + cio' :: Offset -> [Instruction] -> [(Offset, Instruction)] + cio' _ [] = [] + cio' off (x:xs) = (off,x):(cio' newoffset xs) + where newoffset = off + (fromIntegral $ B.length $ encodeInstructions [x]) -- 2.25.1