{-# OPTIONS_GHC -fno-warn-name-shadowing #-}{-# LANGUAGE CPP, MagicHash, UnboxedTuples #-}----------------------------------------------------------------------------------- (c) The University of Glasgow 2007---- | Break Arrays---- An array of bytes, indexed by a breakpoint number (breakpointId in Tickish)-- There is one of these arrays per module.---- Each byte is-- 1 if the corresponding breakpoint is enabled-- 0 otherwise---------------------------------------------------------------------------------moduleGHCi.BreakArray(BreakArray #ifdef GHCI (BA )-- constructor is exported only for ByteCodeGen,newBreakArray ,getBreak ,setBreakOn ,setBreakOff ,showBreakArray #endif )where#ifdef GHCI importPrelude-- See note [Why do we import Prelude here?]importControl.MonadimportData.WordimportGHC.WordimportGHC.ExtsimportGHC.IO(IO(..))importSystem.IO.Unsafe(unsafeDupablePerformIO)dataBreakArray =BA (MutableByteArray#RealWorld)breakOff,breakOn::Word8breakOn =1breakOff =0showBreakArray::BreakArray ->IO()showBreakArray array =doforM_[0..(size array -1)]$\i ->doval <-readBreakArray array i putStr$' ':showval putStr"\n"setBreakOn::BreakArray ->Int->IOBoolsetBreakOn array index |safeIndex array index =dowriteBreakArray array index breakOn returnTrue|otherwise=returnFalsesetBreakOff::BreakArray ->Int->IOBoolsetBreakOff array index |safeIndex array index =dowriteBreakArray array index breakOff returnTrue|otherwise=returnFalsegetBreak::BreakArray ->Int->IO(MaybeWord8)getBreak array index |safeIndex array index =doval <-readBreakArray array index return$Justval |otherwise=returnNothingsafeIndex::BreakArray ->Int->BoolsafeIndex array index =index <size array &&index >=0size::BreakArray ->Intsize (BA array )=size where-- We want to keep this operation pure. The mutable byte array-- is never resized so this is safe.size =unsafeDupablePerformIO$sizeofMutableByteArray array sizeofMutableByteArray::MutableByteArray#RealWorld->IOIntsizeofMutableByteArray arr =IO$\s ->casegetSizeofMutableByteArray#arr s of(#s' ,n# #)->(#s' ,I#n# #)allocBA::Int->IOBreakArray allocBA (I#sz )=IO$\s1 ->casenewByteArray#sz s1 of{(#s2 ,array #)->(#s2 ,BA array #)}-- create a new break array and initialise elements to zeronewBreakArray::Int->IOBreakArray newBreakArray entries @(I#sz )=doBA array <-allocBA entries casebreakOff ofW8#off ->doletloop n |isTrue#(n ==#sz )=return()|otherwise=dowriteBA# array n off ;loop (n +#1#)loop 0#return$BA array writeBA#::MutableByteArray#RealWorld->Int#->Word#->IO()writeBA# array i word =IO$\s ->casewriteWord8Array#array i word s of{s ->(#s ,()#)}writeBreakArray::BreakArray ->Int->Word8->IO()writeBreakArray (BA array )(I#i )(W8#word )=writeBA# array i word readBA#::MutableByteArray#RealWorld->Int#->IOWord8readBA# array i =IO$\s ->casereadWord8Array#array i s of{(#s ,c #)->(#s ,W8#c #)}readBreakArray::BreakArray ->Int->IOWord8readBreakArray (BA array )(I#i )=readBA# array i #else dataBreakArray#endif