X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Fghci%2FByteCodeAsm.lhs;h=6f6e51d0f5ee0c5ca9fa9feb2184923e7e0e4c04;hp=f690aa69903d268e2f0ab2d4b5e89a851adef10e;hb=83d563cb9ede0ba792836e529b1e2929db926355;hpb=6d92f8127b85a52a472b692c6fa40320432dd5a5 diff --git a/compiler/ghci/ByteCodeAsm.lhs b/compiler/ghci/ByteCodeAsm.lhs index f690aa6..6f6e51d 100644 --- a/compiler/ghci/ByteCodeAsm.lhs +++ b/compiler/ghci/ByteCodeAsm.lhs @@ -23,7 +23,6 @@ import ByteCodeItbls import Name import NameSet -import FiniteMap import Literal import TyCon import PrimOp @@ -42,6 +41,8 @@ import Data.Array.ST ( castSTUArray ) import Foreign import Data.Char ( ord ) import Data.List +import Data.Map (Map) +import qualified Data.Map as Map import GHC.Base ( ByteArray#, MutableByteArray#, RealWorld ) @@ -121,19 +122,26 @@ assembleBCO :: ProtoBCO Name -> IO UnlinkedBCO assembleBCO (ProtoBCO nm instrs bitmap bsize arity _origin _malloced) = let -- pass 1: collect up the offsets of the local labels. - -- Remember that the first insn starts at offset 1 since offset 0 - -- (eventually) will hold the total # of insns. - label_env = mkLabelEnv emptyFM 1 instrs - + -- Remember that the first insn starts at offset + -- sizeOf Word / sizeOf Word16 + -- since offset 0 (eventually) will hold the total # of insns. + lableInitialOffset + | wORD_SIZE_IN_BITS == 64 = 4 + | wORD_SIZE_IN_BITS == 32 = 2 + | otherwise = error "wORD_SIZE_IN_BITS not 32 or 64?" + label_env = mkLabelEnv Map.empty lableInitialOffset instrs + + mkLabelEnv :: Map Word16 Word -> Word -> [BCInstr] + -> Map Word16 Word mkLabelEnv env _ [] = env mkLabelEnv env i_offset (i:is) = let new_env - = case i of LABEL n -> addToFM env n i_offset ; _ -> env + = case i of LABEL n -> Map.insert n i_offset env ; _ -> env in mkLabelEnv new_env (i_offset + instrSize16s i) is - findLabel :: Word16 -> Word16 + findLabel :: Word16 -> Word findLabel lab - = case lookupFM label_env lab of + = case Map.lookup lab label_env of Just bco_offset -> bco_offset Nothing -> pprPanic "assembleBCO.findLabel" (ppr lab) in @@ -148,9 +156,7 @@ assembleBCO (ProtoBCO nm instrs bitmap bsize arity _origin _malloced) let asm_insns = ssElts final_insns n_insns = sizeSS final_insns - insns_arr - | n_insns > 65535 = panic "linkBCO: >= 64k insns in BCO" - | otherwise = mkInstrArray (fromIntegral n_insns) asm_insns + insns_arr = mkInstrArray lableInitialOffset n_insns asm_insns !insns_barr = case insns_arr of UArray _lo _hi _n barr -> barr bitmap_arr = mkBitmapArray bsize bitmap @@ -172,9 +178,10 @@ mkBitmapArray :: Word16 -> [StgWord] -> UArray Int StgWord mkBitmapArray bsize bitmap = listArray (0, length bitmap) (fromIntegral bsize : bitmap) -mkInstrArray :: Word16 -> [Word16] -> UArray Word16 Word16 -mkInstrArray n_insns asm_insns - = listArray (0, n_insns) (n_insns : asm_insns) +mkInstrArray :: Word -> Word -> [Word16] -> UArray Word Word16 +mkInstrArray lableInitialOffset n_insns asm_insns + = let size = lableInitialOffset + n_insns + in listArray (0, size - 1) (largeArg size ++ asm_insns) -- instrs nonptrs ptrs type AsmState = (SizedSeq Word16, @@ -202,7 +209,7 @@ sizeSS16 :: SizedSeq a -> Word16 sizeSS16 (SizedSeq n _) = fromIntegral n -- Bring in all the bci_ bytecode constants. -#include "Bytecodes.h" +#include "rts/Bytecodes.h" largeArgInstr :: Word16 -> Word16 largeArgInstr bci = bci_FLAG_LARGE_ARGS .|. bci @@ -220,7 +227,7 @@ largeArg w | otherwise = error "wORD_SIZE_IN_BITS not 32 or 64?" -- This is where all the action is (pass 2 of the assembler) -mkBits :: (Word16 -> Word16) -- label finder +mkBits :: (Word16 -> Word) -- label finder -> AsmState -> [BCInstr] -- instructions (in) -> IO AsmState @@ -231,10 +238,7 @@ mkBits findLabel st proto_insns doInstr :: AsmState -> BCInstr -> IO AsmState doInstr st i = case i of - STKCHECK n - | n > 65535 -> - instrn st (largeArgInstr bci_STKCHECK : largeArg n) - | otherwise -> instr2 st bci_STKCHECK (fromIntegral n) + STKCHECK n -> instr1Large st bci_STKCHECK n PUSH_L o1 -> instr2 st bci_PUSH_L o1 PUSH_LL o1 o2 -> instr3 st bci_PUSH_LL o1 o2 PUSH_LLL o1 o2 o3 -> instr4 st bci_PUSH_LLL o1 o2 o3 @@ -282,27 +286,31 @@ mkBits findLabel st proto_insns instr3 st2 bci_PACK itbl_no sz LABEL _ -> return st TESTLT_I i l -> do (np, st2) <- int st i - instr3 st2 bci_TESTLT_I np (findLabel l) + instr2Large st2 bci_TESTLT_I np (findLabel l) TESTEQ_I i l -> do (np, st2) <- int st i - instr3 st2 bci_TESTEQ_I np (findLabel l) + instr2Large st2 bci_TESTEQ_I np (findLabel l) + TESTLT_W w l -> do (np, st2) <- word st w + instr2Large st2 bci_TESTLT_W np (findLabel l) + TESTEQ_W w l -> do (np, st2) <- word st w + instr2Large st2 bci_TESTEQ_W np (findLabel l) TESTLT_F f l -> do (np, st2) <- float st f - instr3 st2 bci_TESTLT_F np (findLabel l) + instr2Large st2 bci_TESTLT_F np (findLabel l) TESTEQ_F f l -> do (np, st2) <- float st f - instr3 st2 bci_TESTEQ_F np (findLabel l) + instr2Large st2 bci_TESTEQ_F np (findLabel l) TESTLT_D d l -> do (np, st2) <- double st d - instr3 st2 bci_TESTLT_D np (findLabel l) + instr2Large st2 bci_TESTLT_D np (findLabel l) TESTEQ_D d l -> do (np, st2) <- double st d - instr3 st2 bci_TESTEQ_D np (findLabel l) - TESTLT_P i l -> instr3 st bci_TESTLT_P i (findLabel l) - TESTEQ_P i l -> instr3 st bci_TESTEQ_P i (findLabel l) + instr2Large st2 bci_TESTEQ_D np (findLabel l) + TESTLT_P i l -> instr2Large st bci_TESTLT_P i (findLabel l) + TESTEQ_P i l -> instr2Large st bci_TESTEQ_P i (findLabel l) CASEFAIL -> instr1 st bci_CASEFAIL SWIZZLE stkoff n -> instr3 st bci_SWIZZLE stkoff n - JMP l -> instr2 st bci_JMP (findLabel l) + JMP l -> instr1Large st bci_JMP (findLabel l) ENTER -> instr1 st bci_ENTER RETURN -> instr1 st bci_RETURN RETURN_UBX rep -> instr1 st (return_ubx rep) - CCALL off m_addr -> do (np, st2) <- addr st m_addr - instr3 st2 bci_CCALL off np + CCALL off m_addr int -> do (np, st2) <- addr st m_addr + instr4 st2 bci_CCALL off np int BRK_FUN array index info -> do (p1, st2) <- ptr st (BCOPtrArray array) (p2, st3) <- ptr st2 (BCOPtrBreakInfo info) @@ -314,6 +322,14 @@ mkBits findLabel st proto_insns = do st_i' <- addToSS st_i i instrn (st_i', st_l, st_p) is + instr1Large st i1 large + | large > 65535 = instrn st (largeArgInstr i1 : largeArg large) + | otherwise = instr2 st i1 (fromIntegral large) + + instr2Large st i1 i2 large + | large > 65535 = instrn st (largeArgInstr i1 : i2 : largeArg large) + | otherwise = instr3 st i1 i2 (fromIntegral large) + instr1 (st_i0,st_l0,st_p0) i1 = do st_i1 <- addToSS st_i0 i1 return (st_i1,st_l0,st_p0) @@ -351,6 +367,11 @@ mkBits findLabel st proto_insns st_l1 <- addListToSS st_l0 (map BCONPtrWord ws) return (sizeSS16 st_l0, (st_i0,st_l1,st_p0)) + word (st_i0,st_l0,st_p0) w + = do let ws = [w] + st_l1 <- addListToSS st_l0 (map BCONPtrWord ws) + return (sizeSS16 st_l0, (st_i0,st_l1,st_p0)) + int64 (st_i0,st_l0,st_p0) i = do let ws = mkLitI64 i st_l1 <- addListToSS st_l0 (map BCONPtrWord ws) @@ -409,7 +430,7 @@ return_ubx PtrArg = bci_RETURN_P -- The size in 16-bit entities of an instruction. -instrSize16s :: BCInstr -> Word16 +instrSize16s :: BCInstr -> Word instrSize16s instr = case instr of STKCHECK{} -> 2 @@ -444,6 +465,8 @@ instrSize16s instr LABEL{} -> 0 -- !! TESTLT_I{} -> 3 TESTEQ_I{} -> 3 + TESTLT_W{} -> 3 + TESTEQ_W{} -> 3 TESTLT_F{} -> 3 TESTEQ_F{} -> 3 TESTLT_D{} -> 3 @@ -455,7 +478,7 @@ instrSize16s instr ENTER{} -> 1 RETURN{} -> 1 RETURN_UBX{} -> 1 - CCALL{} -> 3 + CCALL{} -> 4 SWIZZLE{} -> 3 BRK_FUN{} -> 4