codegen: make use of Functor instance
[mate.git] / Mate / X86CodeGen.hs
index 7d17a9d7314d0f18929f124fdca250909381f9c7..af3e98d282a31e37c35e40898c70bfa487eac400 100644 (file)
@@ -63,7 +63,7 @@ emitFromBB cls method = do
   hmap = rawMapBB method
 
   getLabel :: BlockID -> [(BlockID, Label)] -> Label
-  getLabel _ [] = error "label not found!"
+  getLabel bid [] = error $ "label " ++ show bid ++ " not found"
   getLabel i ((x,l):xs) = if i==x then l else getLabel i xs
 
   efBB :: (BlockID, BasicBlock) -> TrapMap -> BBStarts -> [(BlockID, Label)] -> CodeGen e s (TrapMap, BBStarts)
@@ -99,10 +99,9 @@ emitFromBB cls method = do
 
     getCurrentOffset :: CodeGen e s Word32
     getCurrentOffset = do
-      ep <- getEntryPoint
-      let w32_ep = (fromIntegral $ ptrToIntPtr ep) :: Word32
-      offset <- getCodeOffset
-      return $ w32_ep + fromIntegral offset
+      ep <- (fromIntegral . ptrToIntPtr) <$> getEntryPoint
+      offset <- fromIntegral <$> getCodeOffset
+      return $ ep + offset
 
     emitInvoke :: Word16 -> Bool -> CodeGen e s (Maybe (Word32, TrapCause))
     emitInvoke cpidx hasThis = do