[project @ 2001-03-19 16:20:44 by simonpj]
[ghc-hetmet.git] / ghc / compiler / ghci / ByteCodeLink.lhs
1 %
2 % (c) The University of Glasgow 2000
3 %
4 \section[ByteCodeLink]{Bytecode assembler and linker}
5
6 \begin{code}
7 module ByteCodeLink ( UnlinkedBCO, UnlinkedBCOExpr, assembleBCO,
8                       ClosureEnv, HValue, filterNameMap,
9                       linkIModules, linkIExpr,
10                       iNTERP_STACK_CHECK_THRESH
11                    ) where
12
13 #include "HsVersions.h"
14
15 import Outputable
16 import Name             ( Name, getName, nameModule, toRdrName, isGlobalName )
17 import RdrName          ( rdrNameOcc, rdrNameModule )
18 import OccName          ( occNameString )
19 import FiniteMap        ( FiniteMap, addListToFM, filterFM,
20                           addToFM, lookupFM, emptyFM )
21 import CoreSyn
22 import Literal          ( Literal(..) )
23 import PrimOp           ( PrimOp, primOpOcc )
24 import PrimRep          ( PrimRep(..) )
25 import Constants        ( wORD_SIZE )
26 import Module           ( ModuleName, moduleName, moduleNameFS )
27 import Linker           ( lookupSymbol )
28 import FastString       ( FastString(..) )
29 import ByteCodeInstr    ( BCInstr(..), ProtoBCO(..) )
30 import ByteCodeItbls    ( ItblEnv, ItblPtr )
31
32
33 import Monad            ( foldM )
34 import ST               ( runST )
35 import MArray           ( castSTUArray, 
36                           newFloatArray, writeFloatArray,
37                           newDoubleArray, writeDoubleArray,
38                           newIntArray, writeIntArray,
39                           newAddrArray, writeAddrArray )
40 import Foreign          ( Word16, Ptr(..) )
41 import Addr             ( Word, Addr, nullAddr )
42 import FiniteMap
43
44 import PrelBase         ( Int(..) )
45 import PrelGHC          ( BCO#, newBCO#, unsafeCoerce#, 
46                           ByteArray#, Array#, addrToHValue#, mkApUpd0# )
47 import IOExts           ( fixIO )
48 import ArrayBase        
49 import PrelArr          ( Array(..) )
50 import PrelIOBase       ( IO(..) )
51
52 \end{code}
53
54 %************************************************************************
55 %*                                                                      *
56 \subsection{Top-level stuff}
57 %*                                                                      *
58 %************************************************************************
59
60 \begin{code}
61 -- Linking stuff
62 linkIModules :: ItblEnv    -- incoming global itbl env; returned updated
63              -> ClosureEnv -- incoming global closure env; returned updated
64              -> [([UnlinkedBCO], ItblEnv)]
65              -> IO ([HValue], ItblEnv, ClosureEnv)
66 linkIModules gie gce mods 
67    = do let (bcoss, ies) = unzip mods
68             bcos = concat bcoss
69             final_gie = foldr plusFM gie ies
70         (final_gce, linked_bcos) <- linkSomeBCOs True final_gie gce bcos
71         return (linked_bcos, final_gie, final_gce)
72
73
74 linkIExpr :: ItblEnv -> ClosureEnv -> UnlinkedBCOExpr
75           -> IO HValue    -- IO BCO# really
76 linkIExpr ie ce (root_ul_bco, aux_ul_bcos)
77    = do (aux_ce, _) <- linkSomeBCOs False ie ce aux_ul_bcos
78         (_, [root_bco]) <- linkSomeBCOs False ie aux_ce [root_ul_bco]
79         return root_bco
80
81 -- Link a bunch of BCOs and return them + updated closure env.
82 linkSomeBCOs :: Bool    -- False <=> add _all_ BCOs to returned closure env
83                         -- True  <=> add only toplevel BCOs to closure env
84              -> ItblEnv 
85              -> ClosureEnv 
86              -> [UnlinkedBCO]
87              -> IO (ClosureEnv, [HValue])
88 linkSomeBCOs toplevs_only ie ce_in ul_bcos
89    = do let nms = map nameOfUnlinkedBCO ul_bcos
90         hvals <- fixIO 
91                     ( \ hvs -> let ce_out = addListToFM ce_in (zipLazily nms hvs)
92                                in  mapM (linkBCO ie ce_out) ul_bcos )
93
94         let ce_all_additions = zip nms hvals
95             ce_top_additions = filter (isGlobalName.fst) ce_all_additions
96             ce_additions     = if toplevs_only then ce_top_additions 
97                                                else ce_all_additions
98             ce_out = -- make sure we're not inserting duplicate names into the 
99                      -- closure environment, which leads to trouble.
100                      ASSERT (all (not . (`elemFM` ce_in)) (map fst ce_additions))
101                      addListToFM ce_in ce_additions
102         return (ce_out, hvals)
103      where
104         -- A lazier zip, in which no demand is propagated to the second
105         -- list unless some demand is propagated to the snd of one of the
106         -- result list elems.
107         zipLazily []     ys = []
108         zipLazily (x:xs) ys = (x, head ys) : zipLazily xs (tail ys)
109
110
111 data UnlinkedBCO
112    = UnlinkedBCO Name
113                  (SizedSeq Word16)               -- insns
114                  (SizedSeq Word)                 -- literals
115                  (SizedSeq (Either Name PrimOp)) -- ptrs
116                  (SizedSeq Name)                 -- itbl refs
117
118 nameOfUnlinkedBCO (UnlinkedBCO nm _ _ _ _) = nm
119
120 -- When translating expressions, we need to distinguish the root
121 -- BCO for the expression
122 type UnlinkedBCOExpr = (UnlinkedBCO, [UnlinkedBCO])
123
124 instance Outputable UnlinkedBCO where
125    ppr (UnlinkedBCO nm insns lits ptrs itbls)
126       = sep [text "BCO", ppr nm, text "with", 
127              int (sizeSS insns), text "insns",
128              int (sizeSS lits), text "lits",
129              int (sizeSS ptrs), text "ptrs",
130              int (sizeSS itbls), text "itbls"]
131
132
133 -- these need a proper home
134 type ClosureEnv = FiniteMap Name HValue
135 data HValue     = HValue  -- dummy type, actually a pointer to some Real Code.
136
137 -- remove all entries for a given set of modules from the environment;
138 -- note that this removes all local names too (ie. temporary bindings from
139 -- the command line).
140 filterNameMap :: [ModuleName] -> FiniteMap Name a -> FiniteMap Name a
141 filterNameMap mods env 
142    = filterFM (\n _ -> isGlobalName n && 
143                         moduleName (nameModule n) `elem` mods) env
144 \end{code}
145
146 %************************************************************************
147 %*                                                                      *
148 \subsection{The bytecode assembler}
149 %*                                                                      *
150 %************************************************************************
151
152 The object format for bytecodes is: 16 bits for the opcode, and 16 for
153 each field -- so the code can be considered a sequence of 16-bit ints.
154 Each field denotes either a stack offset or number of items on the
155 stack (eg SLIDE), and index into the pointer table (eg PUSH_G), an
156 index into the literal table (eg PUSH_I/D/L), or a bytecode address in
157 this BCO.
158
159 \begin{code}
160 -- Top level assembler fn.
161 assembleBCO :: ProtoBCO Name -> IO UnlinkedBCO
162
163 assembleBCO (ProtoBCO nm instrs origin)
164    = let
165          -- pass 1: collect up the offsets of the local labels.
166          -- Remember that the first insn starts at offset 1 since offset 0
167          -- (eventually) will hold the total # of insns.
168          label_env = mkLabelEnv emptyFM 1 instrs
169
170          mkLabelEnv env i_offset [] = env
171          mkLabelEnv env i_offset (i:is)
172             = let new_env 
173                      = case i of LABEL n -> addToFM env n i_offset ; _ -> env
174               in  mkLabelEnv new_env (i_offset + instrSize16s i) is
175
176          findLabel lab
177             = case lookupFM label_env lab of
178                  Just bco_offset -> bco_offset
179                  Nothing -> pprPanic "assembleBCO.findLabel" (int lab)
180      in
181      do  -- pass 2: generate the instruction, ptr and nonptr bits
182          insns <- return emptySS :: IO (SizedSeq Word16)
183          lits  <- return emptySS :: IO (SizedSeq Word)
184          ptrs  <- return emptySS :: IO (SizedSeq (Either Name PrimOp))
185          itbls <- return emptySS :: IO (SizedSeq Name)
186          let init_asm_state = (insns,lits,ptrs,itbls)
187          (final_insns, final_lits, final_ptrs, final_itbls) 
188             <- mkBits findLabel init_asm_state instrs         
189
190          return (UnlinkedBCO nm final_insns final_lits final_ptrs final_itbls)
191
192 -- instrs nonptrs ptrs itbls
193 type AsmState = (SizedSeq Word16, SizedSeq Word, 
194                  SizedSeq (Either Name PrimOp), SizedSeq Name)
195
196 data SizedSeq a = SizedSeq !Int [a]
197 emptySS = SizedSeq 0 []
198 addToSS (SizedSeq n r_xs) x = return (SizedSeq (n+1) (x:r_xs))
199 addListToSS (SizedSeq n r_xs) xs 
200    = return (SizedSeq (n + length xs) (reverse xs ++ r_xs))
201 sizeSS (SizedSeq n r_xs) = n
202 listFromSS (SizedSeq n r_xs) = return (reverse r_xs)
203
204
205 -- This is where all the action is (pass 2 of the assembler)
206 mkBits :: (Int -> Int)                  -- label finder
207        -> AsmState
208        -> [BCInstr]                     -- instructions (in)
209        -> IO AsmState
210
211 mkBits findLabel st proto_insns
212   = foldM doInstr st proto_insns
213     where
214        doInstr :: AsmState -> BCInstr -> IO AsmState
215        doInstr st i
216           = case i of
217                ARGCHECK  n        -> instr2 st i_ARGCHECK n
218                STKCHECK  n        -> instr2 st i_STKCHECK n
219                PUSH_L    o1       -> instr2 st i_PUSH_L o1
220                PUSH_LL   o1 o2    -> instr3 st i_PUSH_LL o1 o2
221                PUSH_LLL  o1 o2 o3 -> instr4 st i_PUSH_LLL o1 o2 o3
222                PUSH_G    nm       -> do (p, st2) <- ptr st nm
223                                         instr2 st2 i_PUSH_G p
224                PUSH_AS   nm pk    -> do (p, st2)  <- ptr st (Left nm)
225                                         (np, st3) <- ctoi_itbl st2 pk
226                                         instr3 st3 i_PUSH_AS p np
227                PUSH_UBX  lit nws  -> do (np, st2) <- literal st lit
228                                         instr3 st2 i_PUSH_UBX np nws
229                PUSH_TAG  tag      -> instr2 st i_PUSH_TAG tag
230                SLIDE     n by     -> instr3 st i_SLIDE n by
231                ALLOC     n        -> instr2 st i_ALLOC n
232                MKAP      off sz   -> instr3 st i_MKAP off sz
233                UNPACK    n        -> instr2 st i_UNPACK n
234                UPK_TAG   n m k    -> instr4 st i_UPK_TAG n m k
235                PACK      dcon sz  -> do (itbl_no,st2) <- itbl st dcon
236                                         instr3 st2 i_PACK itbl_no sz
237                LABEL     lab      -> return st
238                TESTLT_I  i l      -> do (np, st2) <- int st i
239                                         instr3 st2 i_TESTLT_I np (findLabel l)
240                TESTEQ_I  i l      -> do (np, st2) <- int st i
241                                         instr3 st2 i_TESTEQ_I np (findLabel l)
242                TESTLT_F  f l      -> do (np, st2) <- float st f
243                                         instr3 st2 i_TESTLT_F np (findLabel l)
244                TESTEQ_F  f l      -> do (np, st2) <- float st f
245                                         instr3 st2 i_TESTEQ_F np (findLabel l)
246                TESTLT_D  d l      -> do (np, st2) <- double st d
247                                         instr3 st2 i_TESTLT_D np (findLabel l)
248                TESTEQ_D  d l      -> do (np, st2) <- double st d
249                                         instr3 st2 i_TESTEQ_D np (findLabel l)
250                TESTLT_P  i l      -> instr3 st i_TESTLT_P i (findLabel l)
251                TESTEQ_P  i l      -> instr3 st i_TESTEQ_P i (findLabel l)
252                CASEFAIL           -> instr1 st i_CASEFAIL
253                ENTER              -> instr1 st i_ENTER
254                RETURN rep         -> do (itbl_no,st2) <- itoc_itbl st rep
255                                         instr2 st2 i_RETURN itbl_no
256
257        i2s :: Int -> Word16
258        i2s = fromIntegral
259
260        instr1 (st_i0,st_l0,st_p0,st_I0) i1
261           = do st_i1 <- addToSS st_i0 (i2s i1)
262                return (st_i1,st_l0,st_p0,st_I0)
263
264        instr2 (st_i0,st_l0,st_p0,st_I0) i1 i2
265           = do st_i1 <- addToSS st_i0 (i2s i1)
266                st_i2 <- addToSS st_i1 (i2s i2)
267                return (st_i2,st_l0,st_p0,st_I0)
268
269        instr3 (st_i0,st_l0,st_p0,st_I0) i1 i2 i3
270           = do st_i1 <- addToSS st_i0 (i2s i1)
271                st_i2 <- addToSS st_i1 (i2s i2)
272                st_i3 <- addToSS st_i2 (i2s i3)
273                return (st_i3,st_l0,st_p0,st_I0)
274
275        instr4 (st_i0,st_l0,st_p0,st_I0) i1 i2 i3 i4
276           = do st_i1 <- addToSS st_i0 (i2s i1)
277                st_i2 <- addToSS st_i1 (i2s i2)
278                st_i3 <- addToSS st_i2 (i2s i3)
279                st_i4 <- addToSS st_i3 (i2s i4)
280                return (st_i4,st_l0,st_p0,st_I0)
281
282        float (st_i0,st_l0,st_p0,st_I0) f
283           = do let ws = mkLitF f
284                st_l1 <- addListToSS st_l0 ws
285                return (sizeSS st_l0, (st_i0,st_l1,st_p0,st_I0))
286
287        double (st_i0,st_l0,st_p0,st_I0) d
288           = do let ws = mkLitD d
289                st_l1 <- addListToSS st_l0 ws
290                return (sizeSS st_l0, (st_i0,st_l1,st_p0,st_I0))
291
292        int (st_i0,st_l0,st_p0,st_I0) i
293           = do let ws = mkLitI i
294                st_l1 <- addListToSS st_l0 ws
295                return (sizeSS st_l0, (st_i0,st_l1,st_p0,st_I0))
296
297        addr (st_i0,st_l0,st_p0,st_I0) a
298           = do let ws = mkLitA a
299                st_l1 <- addListToSS st_l0 ws
300                return (sizeSS st_l0, (st_i0,st_l1,st_p0,st_I0))
301
302        ptr (st_i0,st_l0,st_p0,st_I0) p
303           = do st_p1 <- addToSS st_p0 p
304                return (sizeSS st_p0, (st_i0,st_l0,st_p1,st_I0))
305
306        itbl (st_i0,st_l0,st_p0,st_I0) dcon
307           = do st_I1 <- addToSS st_I0 (getName dcon)
308                return (sizeSS st_I0, (st_i0,st_l0,st_p0,st_I1))
309
310        literal st (MachWord w)   = int st (fromIntegral w)
311        literal st (MachInt j)    = int st (fromIntegral j)
312        literal st (MachFloat r)  = float st (fromRational r)
313        literal st (MachDouble r) = double st (fromRational r)
314        literal st (MachChar c)   = int st c
315
316        ctoi_itbl st pk
317           = addr st ret_itbl_addr
318             where
319                ret_itbl_addr = case pk of
320                                   PtrRep    -> stg_ctoi_ret_R1p_info
321                                   WordRep   -> stg_ctoi_ret_R1n_info
322                                   IntRep    -> stg_ctoi_ret_R1n_info
323                                   AddrRep   -> stg_ctoi_ret_R1n_info
324                                   CharRep   -> stg_ctoi_ret_R1n_info
325                                   FloatRep  -> stg_ctoi_ret_F1_info
326                                   DoubleRep -> stg_ctoi_ret_D1_info
327                                   VoidRep   -> stg_ctoi_ret_V_info
328                                   _ -> pprPanic "mkBits.ctoi_itbl" (ppr pk)
329
330        itoc_itbl st pk
331           = addr st ret_itbl_addr
332             where
333                ret_itbl_addr = case pk of
334                                   CharRep   -> stg_gc_unbx_r1_info
335                                   IntRep    -> stg_gc_unbx_r1_info
336                                   FloatRep  -> stg_gc_f1_info
337                                   DoubleRep -> stg_gc_d1_info
338                                   VoidRep   -> nullAddr  
339                                   -- Interpreter.c spots this special case
340                      
341 foreign label "stg_ctoi_ret_R1p_info" stg_ctoi_ret_R1p_info :: Addr
342 foreign label "stg_ctoi_ret_R1n_info" stg_ctoi_ret_R1n_info :: Addr
343 foreign label "stg_ctoi_ret_F1_info"  stg_ctoi_ret_F1_info :: Addr
344 foreign label "stg_ctoi_ret_D1_info"  stg_ctoi_ret_D1_info :: Addr
345 foreign label "stg_ctoi_ret_V_info"   stg_ctoi_ret_V_info :: Addr
346
347 foreign label "stg_gc_unbx_r1_info" stg_gc_unbx_r1_info :: Addr
348 foreign label "stg_gc_f1_info"      stg_gc_f1_info :: Addr
349 foreign label "stg_gc_d1_info"      stg_gc_d1_info :: Addr
350
351 -- The size in 16-bit entities of an instruction.
352 instrSize16s :: BCInstr -> Int
353 instrSize16s instr
354    = case instr of
355         STKCHECK _     -> 2
356         ARGCHECK _     -> 2
357         PUSH_L   _     -> 2
358         PUSH_LL  _ _   -> 3
359         PUSH_LLL _ _ _ -> 4
360         PUSH_G   _     -> 2
361         PUSH_AS  _ _   -> 3
362         PUSH_UBX _ _   -> 3
363         PUSH_TAG _     -> 2
364         SLIDE    _ _   -> 3
365         ALLOC    _     -> 2
366         MKAP     _ _   -> 3
367         UNPACK   _     -> 2
368         UPK_TAG  _ _ _ -> 4
369         PACK     _ _   -> 3
370         LABEL    _     -> 0     -- !!
371         TESTLT_I _ _   -> 3
372         TESTEQ_I _ _   -> 3
373         TESTLT_F _ _   -> 3
374         TESTEQ_F _ _   -> 3
375         TESTLT_D _ _   -> 3
376         TESTEQ_D _ _   -> 3
377         TESTLT_P _ _   -> 3
378         TESTEQ_P _ _   -> 3
379         CASEFAIL       -> 1
380         ENTER          -> 1
381         RETURN   _     -> 2
382
383
384 -- Make lists of host-sized words for literals, so that when the
385 -- words are placed in memory at increasing addresses, the
386 -- bit pattern is correct for the host's word size and endianness.
387 mkLitI :: Int    -> [Word]
388 mkLitF :: Float  -> [Word]
389 mkLitD :: Double -> [Word]
390 mkLitA :: Addr   -> [Word]
391
392 mkLitF f
393    = runST (do
394         arr <- newFloatArray ((0::Int),0)
395         writeFloatArray arr 0 f
396         f_arr <- castSTUArray arr
397         w0 <- readWordArray f_arr 0
398         return [w0]
399      )
400
401 mkLitD d
402    | wORD_SIZE == 4
403    = runST (do
404         arr <- newDoubleArray ((0::Int),1)
405         writeDoubleArray arr 0 d
406         d_arr <- castSTUArray arr
407         w0 <- readWordArray d_arr 0
408         w1 <- readWordArray d_arr 1
409         return [w0,w1]
410      )
411    | wORD_SIZE == 8
412    = runST (do
413         arr <- newDoubleArray ((0::Int),0)
414         writeDoubleArray arr 0 d
415         d_arr <- castSTUArray arr
416         w0 <- readWordArray d_arr 0
417         return [w0]
418      )
419
420 mkLitI i
421    = runST (do
422         arr <- newIntArray ((0::Int),0)
423         writeIntArray arr 0 i
424         i_arr <- castSTUArray arr
425         w0 <- readWordArray i_arr 0
426         return [w0]
427      )
428
429 mkLitA a
430    = runST (do
431         arr <- newAddrArray ((0::Int),0)
432         writeAddrArray arr 0 a
433         a_arr <- castSTUArray arr
434         w0 <- readWordArray a_arr 0
435         return [w0]
436      )
437
438 \end{code}
439
440 %************************************************************************
441 %*                                                                      *
442 \subsection{Linking interpretables into something we can run}
443 %*                                                                      *
444 %************************************************************************
445
446 \begin{code}
447
448 {- 
449 data BCO# = BCO# ByteArray#             -- instrs   :: array Word16#
450                  ByteArray#             -- literals :: array Word32#
451                  PtrArray#              -- ptrs     :: Array HValue
452                  ByteArray#             -- itbls    :: Array Addr#
453 -}
454
455 linkBCO ie ce (UnlinkedBCO nm insnsSS literalsSS ptrsSS itblsSS)
456    = do insns    <- listFromSS insnsSS
457         literals <- listFromSS literalsSS
458         ptrs     <- listFromSS ptrsSS
459         itbls    <- listFromSS itblsSS
460
461         linked_ptrs  <- mapM (lookupCE ce) ptrs
462         linked_itbls <- mapM (lookupIE ie) itbls
463
464         let n_insns    = sizeSS insnsSS
465             n_literals = sizeSS literalsSS
466             n_ptrs     = sizeSS ptrsSS
467             n_itbls    = sizeSS itblsSS
468
469         let ptrs_arr = array (0, n_ptrs-1) (indexify linked_ptrs)
470                        :: Array Int HValue
471             ptrs_parr = case ptrs_arr of Array lo hi parr -> parr
472
473             itbls_arr = array (0, n_itbls-1) (indexify linked_itbls)
474                         :: UArray Int ItblPtr
475             itbls_barr = case itbls_arr of UArray lo hi barr -> barr
476
477             insns_arr | n_insns > 65535
478                       = panic "linkBCO: >= 64k insns in BCO"
479                       | otherwise 
480                       = array (0, n_insns) 
481                               (indexify (fromIntegral n_insns:insns))
482                         :: UArray Int Word16
483             insns_barr = case insns_arr of UArray lo hi barr -> barr
484
485             literals_arr = array (0, n_literals-1) (indexify literals)
486                            :: UArray Int Word
487             literals_barr = case literals_arr of UArray lo hi barr -> barr
488
489             indexify :: [a] -> [(Int, a)]
490             indexify xs = zip [0..] xs
491
492         BCO bco# <- newBCO insns_barr literals_barr ptrs_parr itbls_barr
493
494         -- WAS: return (unsafeCoerce# bco#)
495         case mkApUpd0# (unsafeCoerce# bco#) of
496            (# final_bco #) -> return final_bco
497
498
499 data BCO = BCO BCO#
500
501 newBCO :: ByteArray# -> ByteArray# -> Array# a -> ByteArray# -> IO BCO
502 newBCO a b c d
503    = IO (\s -> case newBCO# a b c d s of (# s1, bco #) -> (# s1, BCO bco #))
504
505
506 lookupCE :: ClosureEnv -> Either Name PrimOp -> IO HValue
507 lookupCE ce (Right primop)
508    = do m <- lookupSymbol (primopToCLabel primop "closure")
509         case m of
510            Just (Ptr addr) -> case addrToHValue# addr of
511                                  (# hval #) -> return hval
512            Nothing -> pprPanic "ByteCodeGen.lookupCE(primop)" (ppr primop)
513 lookupCE ce (Left nm)
514    = case lookupFM ce nm of
515         Just aa -> return aa
516         Nothing 
517            -> do m <- lookupSymbol (nameToCLabel nm "closure")
518                  case m of
519                     Just (Ptr addr) -> case addrToHValue# addr of
520                                           (# hval #) -> return hval
521                     Nothing        -> pprPanic "ByteCodeGen.lookupCE" (ppr nm)
522
523 lookupIE :: ItblEnv -> Name -> IO (Ptr a)
524 lookupIE ie con_nm 
525    = case lookupFM ie con_nm of
526         Just (Ptr a) -> return (Ptr a)
527         Nothing
528            -> do -- try looking up in the object files.
529                  m <- lookupSymbol (nameToCLabel con_nm "con_info")
530                  case m of
531                     Just addr -> return addr
532                     Nothing 
533                        -> do -- perhaps a nullary constructor?
534                              n <- lookupSymbol (nameToCLabel con_nm "static_info")
535                              case n of
536                                 Just addr -> return addr
537                                 Nothing -> pprPanic "ByteCodeGen.lookupIE" (ppr con_nm)
538
539 -- HACKS!!!  ToDo: cleaner
540 nameToCLabel :: Name -> String{-suffix-} -> String
541 nameToCLabel n suffix
542    = _UNPK_(moduleNameFS (rdrNameModule rn)) 
543      ++ '_':occNameString(rdrNameOcc rn) ++ '_':suffix
544      where rn = toRdrName n
545
546 primopToCLabel :: PrimOp -> String{-suffix-} -> String
547 primopToCLabel primop suffix
548    = let str = "PrelPrimopWrappers_" ++ occNameString (primOpOcc primop) ++ '_':suffix
549      in --trace ("primopToCLabel: " ++ str)
550         str
551
552 \end{code}
553
554 %************************************************************************
555 %*                                                                      *
556 \subsection{Connect to actual values for bytecode opcodes}
557 %*                                                                      *
558 %************************************************************************
559
560 \begin{code}
561
562 #include "Bytecodes.h"
563
564 i_ARGCHECK = (bci_ARGCHECK :: Int)
565 i_PUSH_L   = (bci_PUSH_L :: Int)
566 i_PUSH_LL  = (bci_PUSH_LL :: Int)
567 i_PUSH_LLL = (bci_PUSH_LLL :: Int)
568 i_PUSH_G   = (bci_PUSH_G :: Int)
569 i_PUSH_AS  = (bci_PUSH_AS :: Int)
570 i_PUSH_UBX = (bci_PUSH_UBX :: Int)
571 i_PUSH_TAG = (bci_PUSH_TAG :: Int)
572 i_SLIDE    = (bci_SLIDE :: Int)
573 i_ALLOC    = (bci_ALLOC :: Int)
574 i_MKAP     = (bci_MKAP :: Int)
575 i_UNPACK   = (bci_UNPACK :: Int)
576 i_UPK_TAG  = (bci_UPK_TAG :: Int)
577 i_PACK     = (bci_PACK :: Int)
578 i_TESTLT_I = (bci_TESTLT_I :: Int)
579 i_TESTEQ_I = (bci_TESTEQ_I :: Int)
580 i_TESTLT_F = (bci_TESTLT_F :: Int)
581 i_TESTEQ_F = (bci_TESTEQ_F :: Int)
582 i_TESTLT_D = (bci_TESTLT_D :: Int)
583 i_TESTEQ_D = (bci_TESTEQ_D :: Int)
584 i_TESTLT_P = (bci_TESTLT_P :: Int)
585 i_TESTEQ_P = (bci_TESTEQ_P :: Int)
586 i_CASEFAIL = (bci_CASEFAIL :: Int)
587 i_ENTER    = (bci_ENTER :: Int)
588 i_RETURN   = (bci_RETURN :: Int)
589 i_STKCHECK = (bci_STKCHECK :: Int)
590
591 iNTERP_STACK_CHECK_THRESH = (INTERP_STACK_CHECK_THRESH :: Int)
592
593 \end{code}