import SplitUniq
import Unique -- the UniqueSupply monadery used herein
-import AbsPrel ( unpackCStringId, stringTy,
+import AbsPrel ( unpackCStringId, unpackCString2Id, stringTy,
integerTy, rationalTy, ratioDataCon,
PrimOp(..), -- For Int2IntegerOp etc
integerZeroId, integerPlusOneId, integerMinusOneId
\begin{code}
bOGUS_LVs :: PlainStgLiveVars
-bOGUS_LVs = panic "bOGUS_LVs"
+bOGUS_LVs = panic "bOGUS_LVs" -- emptyUniqSet (used when pprTracing)
bOGUS_FVs :: [Id]
-bOGUS_FVs = panic "bOGUS_FVs"
+bOGUS_FVs = panic "bOGUS_FVs" -- [] (ditto)
\end{code}
\begin{code}
do_top_bind env bind@(CoNonRec var rhs)
= coreBindToStg env bind `thenSUs` \ (stg_binds, new_env, float_binds) ->
-
+{- TESTING:
+ let
+ ppr_blah xs = ppInterleave ppComma (map pp_x xs)
+ pp_x (u,x) = ppBesides [pprUnique u, ppStr ": ", ppr PprDebug x]
+ in
+ pprTrace "do_top_bind:" (ppAbove (ppr PprDebug stg_binds) (ppr_blah (ufmToList new_env))) $
+-}
case stg_binds of
[StgNonRec var (StgRhsClosure cc bi fvs u [] rhs_body)] ->
-- Mega-special case; there's still a binding there
-- but instead be unpacked each time. But on some programs that costs a lot
-- [eg hpg], so now we update them.
- val = StgApp (StgVarAtom unpackCStringId)
- [StgLitAtom (MachStr s)]
+ val = if (any is_NUL (_UNPK_ s)) then -- must cater for NULs in literal string
+ StgApp (StgVarAtom unpackCString2Id)
+ [StgLitAtom (MachStr s),
+ StgLitAtom (mkMachInt (toInteger (_LENGTH_ s)))]
+ bOGUS_LVs
+ else
+ StgApp (StgVarAtom unpackCStringId)
+ [StgLitAtom (MachStr s)]
bOGUS_LVs
in
returnSUs (StgVarAtom var, unitBag (StgNonRec var rhs))
+ where
+ is_NUL c = c == '\0'
litToStgAtom (NoRepInteger i)
-- extremely convenient to look out for a few very common
returnSUs (StgBindDefault binder True{-used? no it is lying-} stg_rhs,
rhs_binds)
where
-
-
+ --
-- We convert case x of {...; x' -> ...x'...}
-- to
-- case x of {...; _ -> ...x... }
-- default binder to the scrutinee.
--
new_env = case discrim of
- CoVar v -> addOneToIdEnv env binder (StgVarAtom v)
+ CoVar v -> addOneToIdEnv env binder (stgLookup env v)
other -> env
\end{code}
\end{code}
\begin{code}
+#ifdef DEBUG
coreExprToStg env other = panic "coreExprToStg: it really failed here"
+#endif
\end{code}
%************************************************************************