basicblock: calculate offset in instructionstream
authorBernhard Urban <lewurm@gmail.com>
Mon, 2 Apr 2012 19:40:00 +0000 (21:40 +0200)
committerBernhard Urban <lewurm@gmail.com>
Mon, 2 Apr 2012 19:40:00 +0000 (21:40 +0200)
Mate/BasicBlocks.hs

index 1db07104cd34d63566f5cefcb2ab0214c13bcdb2..68d8cb9a8f44c0c83528b83ade08728cba24a129 100644 (file)
@@ -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])