summaryrefslogtreecommitdiff
path: root/compiler/ghci/ByteCodeGen.lhs
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2012-09-15 08:09:56 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2012-09-15 08:09:56 +0100
commitcf02909e1fc10597c3291817ab905d426307405b (patch)
treedea7dbee8ca23d57168ccedb1c5e2e92a2ef9b91 /compiler/ghci/ByteCodeGen.lhs
parent7d83fdea229b940ae198ddc5c179ac449defd2ef (diff)
parentc3f4c6fa3228102eaada6efde8049724461a3bb0 (diff)
downloadhaskell-cf02909e1fc10597c3291817ab905d426307405b.tar.gz
Merge remote branch 'origin/master'
Diffstat (limited to 'compiler/ghci/ByteCodeGen.lhs')
-rw-r--r--compiler/ghci/ByteCodeGen.lhs33
1 files changed, 18 insertions, 15 deletions
diff --git a/compiler/ghci/ByteCodeGen.lhs b/compiler/ghci/ByteCodeGen.lhs
index b277a1ed30..59dfbc896e 100644
--- a/compiler/ghci/ByteCodeGen.lhs
+++ b/compiler/ghci/ByteCodeGen.lhs
@@ -49,7 +49,6 @@ import SMRep
import ClosureInfo
import Bitmap
import OrdList
-import Constants
import Data.List
import Foreign
@@ -152,7 +151,8 @@ ppBCEnv p
-- Create a BCO and do a spot of peephole optimisation on the insns
-- at the same time.
mkProtoBCO
- :: name
+ :: DynFlags
+ -> name
-> BCInstrList
-> Either [AnnAlt Id VarSet] (AnnExpr Id VarSet)
-> Int
@@ -161,10 +161,10 @@ mkProtoBCO
-> Bool -- True <=> is a return point, rather than a function
-> [BcPtr]
-> ProtoBCO name
-mkProtoBCO nm instrs_ordlist origin arity bitmap_size bitmap is_ret mallocd_blocks
+mkProtoBCO dflags nm instrs_ordlist origin arity bitmap_size bitmap is_ret mallocd_blocks
= ProtoBCO {
protoBCOName = nm,
- protoBCOInstrs = maybe_with_stack_check,
+ protoBCOInstrs = maybe_with_stack_check dflags,
protoBCOBitmap = bitmap,
protoBCOBitmapSize = bitmap_size,
protoBCOArity = arity,
@@ -179,8 +179,8 @@ mkProtoBCO nm instrs_ordlist origin arity bitmap_size bitmap is_ret mallocd_bloc
-- BCO anyway, so we only need to add an explicit one in the
-- (hopefully rare) cases when the (overestimated) stack use
-- exceeds iNTERP_STACK_CHECK_THRESH.
- maybe_with_stack_check
- | is_ret && stack_usage < fromIntegral aP_STACK_SPLIM = peep_d
+ maybe_with_stack_check dflags
+ | is_ret && stack_usage < fromIntegral (aP_STACK_SPLIM dflags) = peep_d
-- don't do stack checks at return points,
-- everything is aggregated up to the top BCO
-- (which must be a function).
@@ -223,6 +223,7 @@ schemeTopBind :: (Id, AnnExpr Id VarSet) -> BcM (ProtoBCO Name)
schemeTopBind (id, rhs)
| Just data_con <- isDataConWorkId_maybe id,
isNullaryRepDataCon data_con = do
+ dflags <- getDynFlags
-- Special case for the worker of a nullary data con.
-- It'll look like this: Nil = /\a -> Nil a
-- If we feed it into schemeR, we'll get
@@ -231,7 +232,7 @@ schemeTopBind (id, rhs)
-- by just re-using the single top-level definition. So
-- for the worker itself, we must allocate it directly.
-- ioToBc (putStrLn $ "top level BCO")
- emitBc (mkProtoBCO (getName id) (toOL [PACK data_con 0, ENTER])
+ emitBc (mkProtoBCO dflags (getName id) (toOL [PACK data_con 0, ENTER])
(Right rhs) 0 0 [{-no bitmap-}] False{-not alts-})
| otherwise
@@ -281,7 +282,9 @@ collect (_, e) = go [] e
schemeR_wrk :: [Id] -> Id -> AnnExpr Id VarSet -> ([Var], AnnExpr' Var VarSet) -> BcM (ProtoBCO Name)
schemeR_wrk fvs nm original_body (args, body)
- = let
+ = do
+ dflags <- getDynFlags
+ let
all_args = reverse args ++ fvs
arity = length all_args
-- all_args are the args in reverse order. We're compiling a function
@@ -295,11 +298,10 @@ schemeR_wrk fvs nm original_body (args, body)
-- make the arg bitmap
bits = argBits (reverse (map idCgRep all_args))
bitmap_size = genericLength bits
- bitmap = mkBitmap bits
- in do
+ bitmap = mkBitmap dflags bits
body_code <- schemeER_wrk szw_args p_init body
- emitBc (mkProtoBCO (getName nm) body_code (Right original_body)
+ emitBc (mkProtoBCO dflags (getName nm) body_code (Right original_body)
arity bitmap_size bitmap False{-not alts-})
-- introduce break instructions for ticked expressions
@@ -772,7 +774,9 @@ doCase d s p (_,scrut) bndr alts is_unboxed_tuple
| UbxTupleRep _ <- repType (idType bndr)
= unboxedTupleException
| otherwise
- = let
+ = do
+ dflags <- getDynFlags
+ let
-- Top of stack is the return itbl, as usual.
-- underneath it is the pointer to the alt_code BCO.
-- When an alt is entered, it assumes the returned value is
@@ -875,7 +879,7 @@ doCase d s p (_,scrut) bndr alts is_unboxed_tuple
bitmap_size = trunc16 $ d-s
bitmap_size' :: Int
bitmap_size' = fromIntegral bitmap_size
- bitmap = intsToReverseBitmap bitmap_size'{-size-}
+ bitmap = intsToReverseBitmap dflags bitmap_size'{-size-}
(sort (filter (< bitmap_size') rel_slots))
where
binds = Map.toList p
@@ -886,13 +890,12 @@ doCase d s p (_,scrut) bndr alts is_unboxed_tuple
| otherwise = []
where rel_offset = trunc16 $ d - fromIntegral offset - 1
- in do
alt_stuff <- mapM codeAlt alts
alt_final <- mkMultiBranch maybe_ncons alt_stuff
let
alt_bco_name = getName bndr
- alt_bco = mkProtoBCO alt_bco_name alt_final (Left alts)
+ alt_bco = mkProtoBCO dflags alt_bco_name alt_final (Left alts)
0{-no arity-} bitmap_size bitmap True{-is alts-}
-- trace ("case: bndr = " ++ showSDocDebug (ppr bndr) ++ "\ndepth = " ++ show d ++ "\nenv = \n" ++ showSDocDebug (ppBCEnv p) ++
-- "\n bitmap = " ++ show bitmap) $ do