[project @ 2003-12-10 10:12:13 by wolfgang]
[ghc-hetmet.git] / ghc / compiler / nativeGen / PprMach.lhs
index 3a38756..945fab4 100644 (file)
@@ -19,7 +19,6 @@ import MachMisc
 
 import CLabel          ( pprCLabel, externallyVisibleCLabel, labelDynamic )
 import Stix            ( CodeSegment(..) )
-import Unique          ( pprUnique )
 import Panic           ( panic )
 import Pretty
 import FastString
@@ -27,9 +26,10 @@ import qualified Outputable
 
 #if __GLASGOW_HASKELL__ >= 504
 import Data.Array.ST
-import Data.Word       ( Word8 )
+import Data.Word       ( Word8, Word16 )
 #else
 import MutableArray
+import Word             ( Word16 )
 #endif
 
 import MONAD_ST
@@ -574,8 +574,8 @@ pprInstr (DATA s xs)
 #if powerpc_TARGET_ARCH
        ppr_item B  x = [ptext SLIT("\t.byte\t") <> pprImm x]
        ppr_item Bu  x = [ptext SLIT("\t.byte\t") <> pprImm x]
-       ppr_item H  x = [ptext SLIT("\t.byte\t") <> pprImm x]
-       ppr_item Hu  x = [ptext SLIT("\t.byte\t") <> pprImm x]
+       ppr_item H  x = [ptext SLIT("\t.short\t") <> pprImm x]
+       ppr_item Hu  x = [ptext SLIT("\t.short\t") <> pprImm x]
        ppr_item W  x = [ptext SLIT("\t.long\t") <> pprImm x]
        ppr_item F  (ImmFloat r)
            = let bs = floatToBytes (fromRational r)
@@ -971,7 +971,7 @@ pprSizeRegRegReg name size reg1 reg2 reg3
        pprReg reg3
     ]
 
-#endif {-alpha_TARGET_ARCH-}
+#endif /* alpha_TARGET_ARCH */
 \end{code}
 
 %************************************************************************
@@ -1544,7 +1544,7 @@ pprCondInstr :: LitString -> Cond -> Doc -> Doc
 pprCondInstr name cond arg
   = hcat [ char '\t', ptext name, pprCond cond, space, arg]
 
-#endif {-i386_TARGET_ARCH-}
+#endif /* i386_TARGET_ARCH */
 \end{code}
 
 %************************************************************************
@@ -1831,7 +1831,7 @@ pp_rbracket_comma = text "],"
 pp_comma_lbracket = text ",["
 pp_comma_a       = text ",a"
 
-#endif {-sparc_TARGET_ARCH-}
+#endif /* sparc_TARGET_ARCH */
 \end{code}
 
 %************************************************************************
@@ -1950,7 +1950,7 @@ pprInstr (MTCTR reg) = hcat [
        char '\t',
        pprReg reg
     ]
-pprInstr (BCTR) = hcat [
+pprInstr (BCTR _) = hcat [
        char '\t',
        ptext SLIT("bctr")
     ]
@@ -1965,7 +1965,7 @@ pprInstr (BCTRL _) = hcat [
        ptext SLIT("bctrl")
     ]
 pprInstr (ADD reg1 reg2 ri) = pprLogic SLIT("add") reg1 reg2 ri
-pprInstr (SUBF reg1 reg2 ri) = pprLogic SLIT("subf") reg1 reg2 ri
+pprInstr (SUBF reg1 reg2 reg3) = pprLogic SLIT("subf") reg1 reg2 (RIReg reg3)
 pprInstr (MULLW reg1 reg2 ri@(RIReg _)) = pprLogic SLIT("mullw") reg1 reg2 ri
 pprInstr (MULLW reg1 reg2 ri@(RIImm _)) = pprLogic SLIT("mull") reg1 reg2 ri
 pprInstr (DIVW reg1 reg2 reg3) = pprLogic SLIT("divw") reg1 reg2 (RIReg reg3)
@@ -1983,10 +1983,10 @@ pprInstr (AND reg1 reg2 (RIImm imm)) = hcat [
        ptext SLIT(", "),
        pprImm imm
     ]
-pprInstr (AND reg1 reg2 ri) = pprLogic SLIT("and") reg1 reg2 ri
+pprInstr (AND reg1 reg2 ri) = pprLogic SLIT("and") reg1 reg2 (toUI16 ri)
 
-pprInstr (OR reg1 reg2 ri) = pprLogic SLIT("or") reg1 reg2 ri
-pprInstr (XOR reg1 reg2 ri) = pprLogic SLIT("xor") reg1 reg2 ri
+pprInstr (OR reg1 reg2 ri) = pprLogic SLIT("or") reg1 reg2 (toUI16 ri)
+pprInstr (XOR reg1 reg2 ri) = pprLogic SLIT("xor") reg1 reg2 (toUI16 ri)
 
 pprInstr (XORIS reg1 reg2 imm) = hcat [
        char '\t',
@@ -2068,6 +2068,16 @@ pprRI (RIImm r) = pprImm r
 pprFSize DF = empty
 pprFSize F = char 's'
 
+-- hack to ensure that negative vals come out in non-negative form
+-- (assuming that fromIntegral{Int->Word16} will do a 'c-style'
+-- conversion, and not throw a fit/exception.)
+toUI16 :: RI -> RI
+toUI16 (RIImm (ImmInt x)) 
+  | x < 0 = RIImm (ImmInt (fromIntegral ((fromIntegral x) :: Word16)))
+toUI16 (RIImm (ImmInteger x)) 
+  | x < 0 = RIImm (ImmInt (fromIntegral ((fromIntegral x) :: Word16)))
+toUI16 x = x
+
 {-
   The Mach-O object file format used in Darwin/Mac OS X needs a so-called
   "symbol stub" for every function that might be imported from a dynamic
@@ -2096,7 +2106,7 @@ pprDyldSymbolStub fn =
 #endif
 
 
-#endif {-powerpc_TARGET_ARCH-}
+#endif /* powerpc_TARGET_ARCH */
 \end{code}
 
 \begin{code}