--
-- Pretty-printing of Cmm as (a superset of) C--
--
--- (c) The University of Glasgow 2004
+-- (c) The University of Glasgow 2004-2006
--
-----------------------------------------------------------------------------
#include "HsVersions.h"
import Cmm
-import CmmUtils ( isTrivialCmmExpr )
-import MachOp ( MachOp(..), pprMachOp, MachRep(..), wordRep )
-import CLabel ( pprCLabel, mkForeignLabel, entryLblToInfoLbl )
+import CmmUtils
+import MachOp
+import CLabel
-import ForeignCall ( CCallConv(..) )
-import Unique ( getUnique )
+import ForeignCall
+import Unique
import Outputable
-import FastString ( mkFastString )
+import FastString
-import Data.List ( intersperse, groupBy )
-import IO ( Handle )
-import Maybe ( isJust )
-import Data.Char ( chr )
+import Data.List
+import System.IO
+import Data.Maybe
+import Data.Char
pprCmms :: [Cmm] -> SDoc
pprCmms cmms = pprCode CStyle (vcat (intersperse separator $ map ppr cmms))
infixMachOp1 _ = Nothing
-- %left '-' '+'
+pprExpr7 (CmmMachOp (MO_Add rep1) [x, CmmLit (CmmInt i rep2)]) | i < 0
+ = pprExpr7 (CmmMachOp (MO_Sub rep1) [x, CmmLit (CmmInt (negate i) rep2)])
pprExpr7 (CmmMachOp op [x,y]) | Just doc <- infixMachOp7 op
= pprExpr7 x <+> doc <+> pprExpr8 y
pprExpr7 e = pprExpr8 e
|| isJust (infixMachOp7 mop)
|| isJust (infixMachOp8 mop) = parens (pprExpr (CmmMachOp mop args))
- | otherwise = char '%' <> pprMachOp mop <> parens (commafy (map pprExpr args))
+ | otherwise = char '%' <> ppr_op <> parens (commafy (map pprExpr args))
+ where ppr_op = text (map (\c -> if c == ' ' then '_' else c)
+ (show mop))
+ -- replace spaces in (show mop) with underscores,
--
-- Unsigned ops on the word size of the machine get nice symbols.