CgExtCode

ghc-7.0.4: The GHC API

CgExtCode

Description

Our extended FCode monad.

Synopsis

- newtype ExtFCode a = EC {
  - unEC :: Env -> Decls -> FCode (Decls, a)
  }
- type ExtCode = ExtFCode ()
- data Named
  - = Var CmmExpr
  - | Fun PackageId
  - | Label BlockId
- type Env = UniqFM Named
- loopDecls :: ExtFCode a -> ExtFCode a
- getEnv :: ExtFCode Env
- newLocal :: CmmType -> FastString -> ExtFCode LocalReg
- newLabel :: FastString -> ExtFCode BlockId
- newFunctionName :: FastString -> PackageId -> ExtCode
- newImport :: (FastString, CLabel) -> ExtFCode ()
- lookupLabel :: FastString -> ExtFCode BlockId
- lookupName :: FastString -> ExtFCode CmmExpr
- code :: FCode a -> ExtFCode a
- code2 :: (FCode (Decls, b) -> FCode ((Decls, b), c)) -> ExtFCode b -> ExtFCode c
- nopEC :: ExtFCode ()
- stmtEC :: CmmStmt -> ExtFCode ()
- stmtsEC :: [CmmStmt] -> ExtFCode ()
- getCgStmtsEC :: ExtFCode a -> ExtFCode CgStmts
- getCgStmtsEC' :: ExtFCode a -> ExtFCode (a, CgStmts)
- forkLabelledCodeEC :: ExtFCode a -> ExtFCode BlockId

# Documentation

newtype ExtFCode a

Does a computation in the FCode monad, with a current environment and a list of local declarations. Returns the resulting list of declarations.

Constructors

EC |
Fields unEC :: Env -> Decls -> FCode (Decls, a)

Instances

Monad ExtFCode |

type ExtCode = ExtFCode ()

data Named

The environment contains variable definitions or blockids.

Constructors

Var CmmExpr | Holds CmmLit(CmmLabel ..) which gives the label type, eg, RtsLabel, ForeignLabel, CmmLabel etc.
Fun PackageId | A function name from this package
Label BlockId | A blockid of some code or data.

type Env = UniqFM Named

An environment of named things.

loopDecls :: ExtFCode a -> ExtFCode a

Takes the variable decarations and imports from the monad and makes an environment, which is looped back into the computation. In this way, we can have embedded declarations that scope over the whole procedure, and imports that scope over the entire module. Discards the local declaration contained within decl'

getEnv :: ExtFCode Env

Get the current environment from the monad.

newLocal

Arguments

:: CmmType | data type
-> FastString | name of variable
-> ExtFCode LocalReg | register holding the value

Create a fresh local variable of a given type.

newLabel :: FastString -> ExtFCode BlockId

Allocate a fresh label.

newFunctionName

Arguments

:: FastString | name of the function
-> PackageId | package of the current module
-> ExtCode |

Add add a local function to the environment.

newImport :: (FastString, CLabel) -> ExtFCode ()

Add an imported foreign label to the list of local declarations. If this is done at the start of the module the declaration will scope over the whole module.

lookupLabel :: FastString -> ExtFCode BlockId

Lookup the BlockId bound to the label with this name. If one hasn't been bound yet, create a fresh one based on the Unique of the name.

lookupName :: FastString -> ExtFCode CmmExpr

Lookup the location of a named variable. Unknown names are treated as if they had been 'import'ed from the runtime system. This saves us a lot of bother in the RTS sources, at the expense of deferring some errors to link time.

code :: FCode a -> ExtFCode a

Lift an FCode computation into the ExtFCode monad

code2 :: (FCode (Decls, b) -> FCode ((Decls, b), c)) -> ExtFCode b -> ExtFCode c

nopEC :: ExtFCode ()

Do nothing in the ExtFCode monad.

stmtEC :: CmmStmt -> ExtFCode ()

Accumulate a CmmStmt into the monad state.

stmtsEC :: [CmmStmt] -> ExtFCode ()

Accumulate some CmmStmts into the monad state.

getCgStmtsEC :: ExtFCode a -> ExtFCode CgStmts

Get the generated statements out of the monad state.

getCgStmtsEC' :: ExtFCode a -> ExtFCode (a, CgStmts)

Get the generated statements, and the return value out of the monad state.

forkLabelledCodeEC :: ExtFCode a -> ExtFCode BlockId

Emit a chunk of code outside the instruction stream, and return its block id.