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))
instance Outputable CmmReg where
ppr e = pprReg e
+instance Outputable LocalReg where
+ ppr e = pprLocalReg e
+
instance Outputable GlobalReg where
ppr e = pprGlobalReg e
pprTop :: CmmTop -> SDoc
pprTop (CmmProc info lbl params blocks )
- = vcat [ pprCLabel lbl <> parens (commafy $ map pprLocalReg params) <+> lbrace
+ = vcat [ pprCLabel lbl <> parens (commafy $ map ppr params) <+> lbrace
, nest 8 $ pprInfo info lbl
, nest 4 $ vcat (map ppr blocks)
, rbrace ]
CmmBranch ident -> genBranch ident
CmmCondBranch expr ident -> genCondBranch expr ident
CmmJump expr params -> genJump expr params
+ CmmReturn params -> genReturn params
CmmSwitch arg ids -> genSwitch arg ids
-- --------------------------------------------------------------------------
--
-- jump foo(a, b, c);
--
-genJump :: CmmExpr -> [LocalReg] -> SDoc
-genJump expr actuals =
+genJump :: CmmExpr -> [(CmmExpr, MachHint)] -> SDoc
+genJump expr args =
hcat [ ptext SLIT("jump")
, space
else case expr of
CmmLoad (CmmReg _) _ -> pprExpr expr
_ -> parens (pprExpr expr)
- , pprActuals actuals
+ , space
+ , parens ( commafy $ map ppr args )
, semi ]
- where
- pprActuals [] = empty
- pprActuals as = parens ( commafy $ map pprLocalReg as )
+-- --------------------------------------------------------------------------
+-- Return from a function. [1], Section 6.8.2 of version 1.128
+--
+-- return (a, b, c);
+--
+genReturn :: [(CmmExpr, MachHint)] -> SDoc
+genReturn args =
+
+ hcat [ ptext SLIT("return")
+ , space
+ , parens ( commafy $ map ppr args )
+ , semi ]
-- --------------------------------------------------------------------------
-- Tabled jump to local label
|| 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.
CmmUninitialised i -> nest 4 $ text "I8" <> brackets (int i)
CmmAlign i -> nest 4 $ text "align" <+> int i
CmmDataLabel clbl -> pprCLabel clbl <> colon
- CmmString s' -> nest 4 $ text "I8[]" <+>
- doubleQuotes (text (map (chr.fromIntegral) s'))
+ CmmString s' -> nest 4 $ text "I8[]" <+> text (show s')
-- --------------------------------------------------------------------------
-- Registers, whether local (temps) or global