ghc-7.6.3: The GHC API

Safe Haskell | None

CgMonad

Synopsis

- type Code = FCode ()
- data FCode a
- initC :: IO CgState
- runC :: DynFlags -> Module -> CgState -> FCode a -> (a, CgState)
- thenC :: Code -> FCode a -> FCode a
- thenFC :: FCode a -> (a -> FCode c) -> FCode c
- listCs :: [Code] -> Code
- listFCs :: [FCode a] -> FCode [a]
- mapCs :: (a -> Code) -> [a] -> Code
- mapFCs :: (a -> FCode b) -> [a] -> FCode [b]
- returnFC :: a -> FCode a
- fixC :: (a -> FCode a) -> FCode a
- fixC_ :: (a -> FCode a) -> FCode ()
- checkedAbsC :: CmmStmt -> Code
- stmtC :: CmmStmt -> Code
- stmtsC :: [CmmStmt] -> Code
- labelC :: BlockId -> Code
- emitStmts :: CmmStmts -> Code
- nopC :: Code
- whenC :: Bool -> Code -> Code
- newLabelC :: FCode BlockId
- newUnique :: FCode Unique
- newUniqSupply :: FCode UniqSupply
- type CgStmts = OrdList CgStmt
- emitCgStmts :: CgStmts -> Code
- forkCgStmts :: CgStmts -> FCode BlockId
- cgStmtsToBlocks :: CgStmts -> FCode [CmmBasicBlock]
- getCgStmts' :: FCode a -> FCode (a, CgStmts)
- getCgStmts :: FCode a -> FCode CgStmts
- noCgStmts :: CgStmts
- oneCgStmt :: CmmStmt -> CgStmts
- consCgStmt :: CmmStmt -> CgStmts -> CgStmts
- getCmm :: Code -> FCode CmmGroup
- emitDecl :: CmmDecl -> Code
- emitProc :: CmmInfoTable -> CLabel -> [CmmFormal] -> [CmmBasicBlock] -> Code
- emitSimpleProc :: CLabel -> Code -> Code
- forkLabelledCode :: Code -> FCode BlockId
- forkClosureBody :: Code -> Code
- forkStatics :: FCode a -> FCode a
- forkAlts :: [FCode a] -> FCode [a]
- forkEval :: EndOfBlockInfo -> Code -> FCode Sequel -> FCode EndOfBlockInfo
- forkEvalHelp :: EndOfBlockInfo -> Code -> FCode a -> FCode (VirtualSpOffset, a)
- forkProc :: Code -> FCode CgStmts
- codeOnly :: Code -> Code
- type SemiTaggingStuff = Maybe ([(ConTagZ, CmmLit)], CmmLit)
- type ConTagZ = Int
- data EndOfBlockInfo = EndOfBlockInfo VirtualSpOffset Sequel
- setEndOfBlockInfo :: EndOfBlockInfo -> Code -> Code
- getEndOfBlockInfo :: FCode EndOfBlockInfo
- setSRT :: SRT -> FCode a -> FCode a
- getSRT :: FCode SRT
- setSRTLabel :: CLabel -> FCode a -> FCode a
- getSRTLabel :: FCode CLabel
- setTickyCtrLabel :: CLabel -> Code -> Code
- getTickyCtrLabel :: FCode CLabel
- data StackUsage = StackUsage {
  - virtSp :: VirtualSpOffset
  - frameSp :: VirtualSpOffset
  - freeStk :: [VirtualSpOffset]
  - realSp :: VirtualSpOffset
  - hwSp :: VirtualSpOffset
  }
- data HeapUsage = HeapUsage {
  - virtHp :: VirtualHpOffset
  - realHp :: VirtualHpOffset
  }
- type VirtualSpOffset = WordOff
- type VirtualHpOffset = WordOff
- initStkUsage :: StackUsage
- initHpUsage :: HeapUsage
- getHpUsage :: FCode HeapUsage
- setHpUsage :: HeapUsage -> Code
- heapHWM :: HeapUsage -> VirtualHpOffset
- getModuleName :: FCode Module
- data Sequel
  - = OnStack
  - | CaseAlts CLabel SemiTaggingStuff Id
- getState :: FCode CgState
- setState :: CgState -> FCode ()
- getInfoDown :: FCode CgInfoDownwards
- getDynFlags :: HasDynFlags m => m DynFlags
- getThisPackage :: FCode PackageId
- getStkUsage :: FCode StackUsage
- setStkUsage :: StackUsage -> Code
- getBinds :: FCode CgBindings
- setBinds :: CgBindings -> FCode ()
- getStaticBinds :: FCode CgBindings
- data CgInfoDownwards = MkCgInfoDown {
  - cgd_dflags :: DynFlags
  - cgd_mod :: Module
  - cgd_statics :: CgBindings
  - cgd_srt_lbl :: CLabel
  - cgd_srt :: SRT
  - cgd_ticky :: CLabel
  - cgd_eob :: EndOfBlockInfo
  }
- data CgState = MkCgState {
  - cgs_stmts :: OrdList CgStmt
  - cgs_tops :: OrdList CmmDecl
  - cgs_binds :: CgBindings
  - cgs_stk_usg :: StackUsage
  - cgs_hp_usg :: HeapUsage
  - cgs_uniqs :: UniqSupply
  }

# Documentation

type Code = FCode ()

data FCode a

Instances

Monad FCode |
HasDynFlags FCode |

initC :: IO CgState

runC :: DynFlags -> Module -> CgState -> FCode a -> (a, CgState)

thenC :: Code -> FCode a -> FCode a

thenFC :: FCode a -> (a -> FCode c) -> FCode c

listCs :: [Code] -> Code

listFCs :: [FCode a] -> FCode [a]

mapCs :: (a -> Code) -> [a] -> Code

mapFCs :: (a -> FCode b) -> [a] -> FCode [b]

returnFC :: a -> FCode a

fixC :: (a -> FCode a) -> FCode a

Knot-tying combinator for `FCode`

fixC_ :: (a -> FCode a) -> FCode ()

Knot-tying combinator that throws result away

checkedAbsC :: CmmStmt -> Code

stmtC :: CmmStmt -> Code

stmtsC :: [CmmStmt] -> Code

labelC :: BlockId -> Code

emitStmts :: CmmStmts -> Code

nopC :: Code

whenC :: Bool -> Code -> Code

newLabelC :: FCode BlockId

newUnique :: FCode Unique

newUniqSupply :: FCode UniqSupply

type CgStmts = OrdList CgStmt

emitCgStmts :: CgStmts -> Code

forkCgStmts :: CgStmts -> FCode BlockId

cgStmtsToBlocks :: CgStmts -> FCode [CmmBasicBlock]

getCgStmts' :: FCode a -> FCode (a, CgStmts)

getCgStmts :: FCode a -> FCode CgStmts

noCgStmts :: CgStmts

oneCgStmt :: CmmStmt -> CgStmts

consCgStmt :: CmmStmt -> CgStmts -> CgStmts

getCmm :: Code -> FCode CmmGroup

emitDecl :: CmmDecl -> Code

emitProc :: CmmInfoTable -> CLabel -> [CmmFormal] -> [CmmBasicBlock] -> Code

emitSimpleProc :: CLabel -> Code -> Code

forkLabelledCode :: Code -> FCode BlockId

forkClosureBody :: Code -> Code

Takes code and compiles it in a completely fresh environment, except that compilation info and statics are passed in unchanged. The current environment is passed on completely unaltered, except that the Cmm code from the fork is incorporated.

forkStatics :: FCode a -> FCode a

`forkStatics` $fc$ compiles $fc$ in an environment whose statics come from the current bindings, but which is otherwise freshly initialised. The Cmm returned is attached to the current state, but the bindings and usage information is otherwise unchanged.

forkAlts :: [FCode a] -> FCode [a]

`forkAlts` $bs~d$ takes fcodes $bs$ for the branches of a `case`, and an an fcode for the default case $d$, and compiles each in the current environment. The current environment is passed on unmodified, except that: * the worst stack high-water mark is incorporated * the virtual Hp is moved on to the worst virtual Hp for the branches

forkEval :: EndOfBlockInfo -> Code -> FCode Sequel -> FCode EndOfBlockInfo

`forkEval` takes two blocks of code.

- The first meddles with the environment to set it up as expected by the alternatives of a `case` which does an eval (or gc-possible primop). * The second block is the code for the alternatives. (plus info for semi-tagging purposes)

`forkEval` picks up the virtual stack pointer and returns a suitable `EndOfBlockInfo` for the caller to use, together with whatever value is returned by the second block.

It uses `initEnvForAlternatives` to initialise the environment, and `stateIncUsageAlt` to incorporate usage; the latter ignores the heap usage.

forkEvalHelp :: EndOfBlockInfo -> Code -> FCode a -> FCode (VirtualSpOffset, a)

forkProc :: Code -> FCode CgStmts

`forkProc` takes a code and compiles it in the current environment, returning the basic blocks thus constructed. The current environment is passed on completely unchanged. It is pretty similar to `getBlocks`, except that the latter does affect the environment.

codeOnly :: Code -> Code

type SemiTaggingStuff = Maybe ([(ConTagZ, CmmLit)], CmmLit)

type ConTagZ = Int

data EndOfBlockInfo

`EndOfBlockInfo` tells what to do at the end of this block of code or, if the expression is a `case`, what to do at the end of each alternative.

Constructors

EndOfBlockInfo VirtualSpOffset Sequel |

setEndOfBlockInfo :: EndOfBlockInfo -> Code -> Code

getEndOfBlockInfo :: FCode EndOfBlockInfo

setSRT :: SRT -> FCode a -> FCode a

getSRT :: FCode SRT

setSRTLabel :: CLabel -> FCode a -> FCode a

getSRTLabel :: FCode CLabel

setTickyCtrLabel :: CLabel -> Code -> Code

getTickyCtrLabel :: FCode CLabel

data StackUsage

Stack usage information during code generation.

INVARIANT: The environment contains no Stable references to stack slots below (lower offset) frameSp It can contain volatile references to this area though.

Constructors

StackUsage |

Fields

virtSp :: VirtualSpOffset
frameSp :: VirtualSpOffset
freeStk :: [VirtualSpOffset]
realSp :: VirtualSpOffset
hwSp :: VirtualSpOffset

data HeapUsage

Heap usage information during code generation.

virtHp keeps track of the next location to allocate an object at. realHp keeps track of what the Hp STG register actually points to. The reason these aren't always the same is that we want to be able to move the realHp in one go when allocating numerous objects to save having to bump it each time. virtHp we do bump each time but it doesn't create corresponding inefficient machine code.

Constructors

HeapUsage |

Fields

virtHp :: VirtualHpOffset
realHp :: VirtualHpOffset

type VirtualSpOffset = WordOff

type VirtualHpOffset = WordOff

initStkUsage :: StackUsage

Initial stack usage

initHpUsage :: HeapUsage

Initial heap usage

getHpUsage :: FCode HeapUsage

setHpUsage :: HeapUsage -> Code

heapHWM :: HeapUsage -> VirtualHpOffset

Return the heap usage high water mark

getModuleName :: FCode Module

data Sequel

`Sequel` is a representation of the next continuation to jump to after the current function.

Any addressing modes inside `Sequel` must be ``robust,'' in the sense that it must survive stack pointer adjustments at the end of the block.

Constructors

OnStack |
CaseAlts CLabel SemiTaggingStuff Id |

getState :: FCode CgState

setState :: CgState -> FCode ()

getInfoDown :: FCode CgInfoDownwards

getDynFlags :: HasDynFlags m => m DynFlags

getThisPackage :: FCode PackageId

getStkUsage :: FCode StackUsage

setStkUsage :: StackUsage -> Code

getBinds :: FCode CgBindings

setBinds :: CgBindings -> FCode ()

getStaticBinds :: FCode CgBindings

data CgInfoDownwards

State only passed *downwards* by the monad

Constructors

MkCgInfoDown |

Fields

cgd_dflags :: DynFlags
cgd_mod :: Module
cgd_statics :: CgBindings
cgd_srt_lbl :: CLabel
cgd_srt :: SRT
cgd_ticky :: CLabel
cgd_eob :: EndOfBlockInfo

data CgState

State passed around and modified during code generation

Constructors

MkCgState |

Fields

cgs_stmts :: OrdList CgStmt
cgs_tops :: OrdList CmmDecl
cgs_binds :: CgBindings
cgs_stk_usg :: StackUsage
cgs_hp_usg :: HeapUsage
cgs_uniqs :: UniqSupply