NCG: Move RegLiveness -> RegAlloc.Liveness
[ghc-hetmet.git] / compiler / nativeGen / AsmCodeGen.lhs
index ee39dcd..ce411ed 100644 (file)
@@ -19,24 +19,25 @@ module AsmCodeGen ( nativeCodeGen ) where
 #include "HsVersions.h"
 #include "nativeGen/NCG.h"
 
-import MachInstrs
-import MachRegs
+import Instrs
+import Regs
 import MachCodeGen
 import PprMach
 import RegAllocInfo
 import NCGMonad
 import PositionIndependentCode
-import RegLiveness
-import RegCoalesce
-import qualified RegAllocLinear        as Linear
-import qualified RegAllocColor as Color
-import qualified RegAllocStats as Color
-import qualified GraphColor    as Color
+import RegAlloc.Liveness
+
+import qualified RegAlloc.Linear.Main  as Linear
+
+import qualified GraphColor                    as Color
+import qualified RegAlloc.Graph.Main           as Color
+import qualified RegAlloc.Graph.Stats          as Color
+import qualified RegAlloc.Graph.Coalesce       as Color
 
 import Cmm
 import CmmOpt          ( cmmMiniInline, cmmMachOpFold )
 import PprCmm
-import MachOp
 import CLabel
 import State
 
@@ -54,6 +55,7 @@ import Module
 
 import Digraph
 import qualified Pretty
+import BufWrite
 import Outputable
 import FastString
 import UniqSet
@@ -128,8 +130,12 @@ nativeCodeGen dflags h us cmms
  = do
        let split_cmms  = concat $ map add_split cmms
 
-       (imports, prof)
-               <- cmmNativeGens dflags h us split_cmms [] [] 0
+        -- BufHandle is a performance hack.  We could hide it inside
+        -- Pretty if it weren't for the fact that we do lots of little
+        -- printDocs here (in order to do codegen in constant space).
+        bufh <- newBufHandle h
+       (imports, prof) <- cmmNativeGens dflags bufh us split_cmms [] [] 0
+        bFlush bufh
 
        let (native, colorStats, linearStats)
                = unzip3 prof
@@ -187,7 +193,7 @@ cmmNativeGens dflags h us (cmm : cmms) impAcc profAcc count
        (us', native, imports, colorStats, linearStats)
                <- cmmNativeGen dflags us cmm count
 
-       Pretty.printDoc Pretty.LeftMode h
+       Pretty.bufLeftRender h
                $ {-# SCC "pprNativeCode" #-} Pretty.vcat $ map pprNatCmmTop native
 
        let lsPprNative =
@@ -716,9 +722,9 @@ cmmStmtConFold stmt
                                e' <- cmmExprConFold CallReference e
                                return $ CmmCallee e' conv
                              other -> return other
-                 args' <- mapM (\(CmmKinded arg hint) -> do
+                 args' <- mapM (\(CmmHinted arg hint) -> do
                                   arg' <- cmmExprConFold DataReference arg
-                                  return (CmmKinded arg' hint)) args
+                                  return (CmmHinted arg' hint)) args
                 return $ CmmCall target' regs args' srt returns
 
         CmmCondBranch test dest
@@ -759,9 +765,9 @@ cmmExprConFold referenceKind expr
            -> do
                 dflags <- getDynFlagsCmmOpt
                 dynRef <- cmmMakeDynamicReference dflags addImportCmmOpt referenceKind lbl
-                 return $ cmmMachOpFold (MO_Add wordRep) [
+                 return $ cmmMachOpFold (MO_Add wordWidth) [
                      dynRef,
-                     (CmmLit $ CmmInt (fromIntegral off) wordRep)
+                     (CmmLit $ CmmInt (fromIntegral off) wordWidth)
                    ]
 
 #if powerpc_TARGET_ARCH
@@ -795,7 +801,7 @@ cmmExprConFold referenceKind expr
                     -> case mid of 
                           BaseReg -> cmmExprConFold DataReference baseRegAddr
                           other   -> cmmExprConFold DataReference
-                                        (CmmLoad baseRegAddr (globalRegRep mid))
+                                        (CmmLoad baseRegAddr (globalRegType mid))
           -- eliminate zero offsets
        CmmRegOff reg 0
           -> cmmExprConFold referenceKind (CmmReg reg)
@@ -807,10 +813,10 @@ cmmExprConFold referenceKind expr
            -> case get_GlobalReg_reg_or_addr mid of
                 Left  realreg -> return expr
                 Right baseRegAddr
-                   -> cmmExprConFold DataReference (CmmMachOp (MO_Add wordRep) [
+                   -> cmmExprConFold DataReference (CmmMachOp (MO_Add wordWidth) [
                                         CmmReg (CmmGlobal mid),
                                         CmmLit (CmmInt (fromIntegral offset)
-                                                       wordRep)])
+                                                       wordWidth)])
         other
            -> return other