)
where
-#include "HsVersions.h"
-
import CmmExpr
import Cmm ( GenCmm(..), GenCmmTop(..), CmmStatic, CmmInfo
- , CmmCallTarget(..), CmmActuals, CmmFormals
+ , CmmCallTarget(..), CmmActuals, CmmFormals, CmmHinted(..)
, CmmStmt(CmmSwitch) -- imported in order to call ppr
)
import PprCmm()
import FastString
import ForeignCall
import MachOp
-import qualified ZipDataflow as DF
+import qualified ZipDataflow0 as DF
import ZipCfg
import MkZipCfg
+import Util
import Maybes
import Outputable
CmmFormals -- zero or more results
CmmActuals -- zero or more arguments
+ | MidAddToContext -- push a frame on the stack;
+ -- I will return to this frame
+ CmmExpr -- The frame's return address; it must be
+ -- preceded by an info table that describes the
+ -- live variables.
+ [CmmExpr] -- The frame's live variables, to go on the
+ -- stack with the first one at the young end
+
| CopyIn -- Move incoming parameters or results from conventional
-- locations to registers. Note [CopyIn invariant]
Convention
instance UserOfLocalRegs Middle where
foldRegsUsed f z m = middle m
where middle (MidComment {}) = z
- middle (MidAssign _lhs expr) = foldRegsUsed f z expr
- middle (MidStore addr rval) = foldRegsUsed f (foldRegsUsed f z addr) rval
- middle (MidUnsafeCall tgt _ress args) = foldRegsUsed f (foldRegsUsed f z tgt) args
+ middle (MidAssign _lhs expr) = fold f z expr
+ middle (MidStore addr rval) = fold f (fold f z addr) rval
+ middle (MidUnsafeCall tgt _ress args) = fold f (fold f z tgt) args
+ middle (MidAddToContext ra args) = fold f (fold f z ra) args
middle (CopyIn _ _formals _) = z
- middle (CopyOut _ actuals) = foldRegsUsed f z actuals
--- fold = foldRegsUsed
+ middle (CopyOut _ actuals) = fold f z actuals
+ fold f z m = foldRegsUsed f z m -- avoid monomorphism restriction
instance UserOfLocalRegs Last where
foldRegsUsed f z m = last m
last (LastCondBranch e _ _) = foldRegsUsed f z e
last (LastSwitch e _tbl) = foldRegsUsed f z e
-instance UserOfLocalRegs (ZLast Last) where
- foldRegsUsed f z (LastOther l) = foldRegsUsed f z l
- foldRegsUsed _f z LastExit = z
-
----------------------------------------------------------------------
----- Instance declarations for prettyprinting (avoids recursive imports)
instance DF.DebugNodes Middle Last
-instance Outputable CmmGraph where
- ppr = pprLgraph
-
debugPpr :: Bool
debugPpr = debugIsOn
pprMiddle stmt = (case stmt of
CopyIn conv args _ ->
- if null args then ptext SLIT("empty CopyIn")
+ if null args then ptext (sLit "empty CopyIn")
else commafy (map pprHinted args) <+> equals <+>
- ptext SLIT("foreign") <+> doubleQuotes(ppr conv) <+> ptext SLIT("...")
+ ptext (sLit "foreign") <+> doubleQuotes(ppr conv) <+> ptext (sLit "...")
CopyOut conv args ->
- ptext SLIT("next, pass") <+> doubleQuotes(ppr conv) <+>
+ ptext (sLit "next, pass") <+> doubleQuotes(ppr conv) <+>
parens (commafy (map pprHinted args))
-- // text
hcat [ if null results
then empty
else parens (commafy $ map ppr results) <>
- ptext SLIT(" = "),
- ptext SLIT("call"), space,
+ ptext (sLit " = "),
+ ptext (sLit "call"), space,
doubleQuotes(ppr cconv), space,
- target fn, parens ( commafy $ map ppr args ),
+ ppr_target fn, parens ( commafy $ map ppr args ),
semi ]
- where
- target t@(CmmLit _) = ppr t
- target fn' = parens (ppr fn')
MidUnsafeCall (CmmPrim op) results args ->
pprMiddle (MidUnsafeCall (CmmCallee (CmmLit lbl) CCallConv) results args)
where
lbl = CmmLabel (mkForeignLabel (mkFastString (show op)) Nothing False)
+
+ MidAddToContext ra args ->
+ hcat [ ptext (sLit "return via ")
+ , ppr_target ra, parens (commafy $ map ppr args), semi ]
+
) <>
if debugPpr then empty
else text " //" <+>
MidComment {} -> text "MidComment"
MidAssign {} -> text "MidAssign"
MidStore {} -> text "MidStore"
- MidUnsafeCall {} -> text "MidUnsafeCall"
+ MidUnsafeCall {} -> text "MidUnsafeCall"
+ MidAddToContext {} -> text "MidAddToContext"
+
+
+ppr_target :: CmmExpr -> SDoc
+ppr_target t@(CmmLit _) = ppr t
+ppr_target fn' = parens (ppr fn')
-pprHinted :: Outputable a => (a, MachHint) -> SDoc
-pprHinted (a, NoHint) = ppr a
-pprHinted (a, PtrHint) = doubleQuotes (text "address") <+> ppr a
-pprHinted (a, SignedHint) = doubleQuotes (text "signed") <+> ppr a
-pprHinted (a, FloatHint) = doubleQuotes (text "float") <+> ppr a
+pprHinted :: Outputable a => CmmHinted a -> SDoc
+pprHinted (CmmHinted a NoHint) = ppr a
+pprHinted (CmmHinted a PtrHint) = doubleQuotes (text "address") <+> ppr a
+pprHinted (CmmHinted a SignedHint) = doubleQuotes (text "signed") <+> ppr a
+pprHinted (CmmHinted a FloatHint) = doubleQuotes (text "float") <+> ppr a
pprLast :: Last -> SDoc
pprLast stmt = (case stmt of
- LastBranch ident -> ptext SLIT("goto") <+> ppr ident <> semi
+ LastBranch ident -> ptext (sLit "goto") <+> ppr ident <> semi
LastCondBranch expr t f -> genFullCondBranch expr t f
- LastJump expr -> hcat [ ptext SLIT("jump"), space, pprFun expr
- , ptext SLIT("(...)"), semi]
- LastReturn -> hcat [ ptext SLIT("return"), space
- , ptext SLIT("(...)"), semi]
+ LastJump expr -> hcat [ ptext (sLit "jump"), space, pprFun expr
+ , ptext (sLit "(...)"), semi]
+ LastReturn -> hcat [ ptext (sLit "return"), space
+ , ptext (sLit "(...)"), semi]
LastSwitch arg ids -> ppr $ CmmSwitch arg ids
LastCall tgt k -> genBareCall tgt k
) <>
genBareCall :: CmmExpr -> Maybe BlockId -> SDoc
genBareCall fn k =
- hcat [ ptext SLIT("call"), space
- , pprFun fn, ptext SLIT("(...)"), space
- , case k of Nothing -> ptext SLIT("never returns")
- Just k -> ptext SLIT("returns to") <+> ppr k
+ hcat [ ptext (sLit "call"), space
+ , pprFun fn, ptext (sLit "(...)"), space
+ , case k of Nothing -> ptext (sLit "never returns")
+ Just k -> ptext (sLit "returns to") <+> ppr k
, semi ]
where
genFullCondBranch :: Outputable id => CmmExpr -> id -> id -> SDoc
genFullCondBranch expr t f =
- hsep [ ptext SLIT("if")
+ hsep [ ptext (sLit "if")
, parens(ppr expr)
- , ptext SLIT("goto")
+ , ptext (sLit "goto")
, ppr t <> semi
- , ptext SLIT("else goto")
+ , ptext (sLit "else goto")
, ppr f <> semi
]