ghc-9.6.3: The GHC API

Copyright | (c) The University of Glasgow 2001
License | BSD-style (see the file LICENSE)
Maintainer | Sylvain Henry <sylvain.henry@iohk.io> Jeffrey Young <jeffrey.young@iohk.io> Luite Stegeman <luite.stegeman@iohk.io> Josh Meredith <josh.meredith@iohk.io>

Stability

experimental Serialization/deserialization of binary .o files for the JavaScript backend The .o files contain dependency information and generated code. All strings are mapped to a central string table, which helps reduce file size and gives us efficient hash consing on read Binary intermediate JavaScript object files: serialized [Text] -> ([ClosureInfo], JStat) blocks file layout: - magic "GHCJSOBJ" - compiler version tag - module name - offsets of string table - dependencies - offset of the index - unit infos - index - string table

Safe Haskell | Safe-Inferred
Language | Haskell2010

GHC.StgToJS.Object

Contents

- Orphan instances

Description

Synopsis

- putObject :: BinHandle -> ModuleName -> Deps -> [ObjUnit] -> IO ()
- getObjectHeader :: BinHandle -> IO (Either String ModuleName)
- getObjectBody :: BinHandle -> ModuleName -> IO Object
- getObject :: BinHandle -> IO (Maybe Object)
- readObject :: FilePath -> IO (Maybe Object)
- getObjectUnits :: Object -> (Word -> IndexEntry -> Bool) -> IO [ObjUnit]
- readObjectUnits :: FilePath -> (Word -> IndexEntry -> Bool) -> IO [ObjUnit]
- readObjectDeps :: FilePath -> IO (Maybe Deps)
- isGlobalUnit :: Int -> Bool
- isJsObjectFile :: FilePath -> IO Bool
- data Object = Object {
  - objModuleName :: !ModuleName
  - objHandle :: !BinHandle
  - objPayloadOffset :: !(Bin ObjUnit)
  - objDeps :: !Deps
  - objIndex :: !Index
  }
- data IndexEntry = IndexEntry {
  - idxSymbols :: ![FastString]
  - idxOffset :: !(Bin ObjUnit)
  }
- data Deps = Deps {
  - depsModule :: !Module
  - depsRequired :: !BlockIds
  - depsHaskellExported :: !(Map ExportedFun BlockId)
  - depsBlocks :: !(Array BlockId BlockDeps)
  }
- data BlockDeps = BlockDeps {
  - blockBlockDeps :: [Int]
  - blockFunDeps :: [ExportedFun]
  }
- data DepsLocation
  - = ObjectFile FilePath
  - | ArchiveFile FilePath
  - | InMemory String Object
- data ExportedFun = ExportedFun {
  - funModule :: !Module
  - funSymbol :: !LexicalFastString
  }

# Documentation

putObject Source #

Arguments

:: BinHandle |
-> ModuleName | module
-> Deps | dependencies
-> [ObjUnit] | linkable units and their symbols
-> IO () |

Given a handle to a Binary payload, add the module, `mod_name`, its dependencies, `deps`, and its linkable units to the payload.

getObjectHeader :: BinHandle -> IO (Either String ModuleName) Source #

Parse object header

getObjectBody :: BinHandle -> ModuleName -> IO Object Source #

Parse object body. Must be called after a sucessful getObjectHeader

getObject :: BinHandle -> IO (Maybe Object) Source #

Parse object

readObject :: FilePath -> IO (Maybe Object) Source #

Read object from file

The object is still in memory after this (see objHandle).

getObjectUnits :: Object -> (Word -> IndexEntry -> Bool) -> IO [ObjUnit] Source #

Get units in the object file, using the given filtering function

readObjectUnits :: FilePath -> (Word -> IndexEntry -> Bool) -> IO [ObjUnit] Source #

Read units in the object file, using the given filtering function

readObjectDeps :: FilePath -> IO (Maybe Deps) Source #

Reads only the part necessary to get the dependencies

isGlobalUnit :: Int -> Bool Source #

we use the convention that the first unit (0) is a module-global unit that's always included when something from the module is loaded. everything in a module implicitly depends on the global block. the global unit itself can't have dependencies

isJsObjectFile :: FilePath -> IO Bool Source #

Test if the object file is a JS object

data Object Source #

An object file

Constructors

Object |

Fields

- objModuleName :: !ModuleName

  name of the module

- objHandle :: !BinHandle

  BinHandle that can be used to read the ObjUnits

- objPayloadOffset :: !(Bin ObjUnit)

  Offset of the payload (units)

- objDeps :: !Deps

  Dependencies

- objIndex :: !Index

  The Index, serialed unit indices and their linkable units

data IndexEntry Source #

Constructors

IndexEntry |

Fields

- idxSymbols :: ![FastString]

  Symbols exported by a unit

- idxOffset :: !(Bin ObjUnit)

  Offset of the unit in the object file

#### Instances

Instances details

Binary IndexEntry Source # |
Instance details Defined in GHC.StgToJS.Object Methods put_ :: BinHandle -> IndexEntry -> IO () Source # put :: BinHandle -> IndexEntry -> IO (Bin IndexEntry) Source # get :: BinHandle -> IO IndexEntry Source #

data Deps Source #

dependencies for a single module

Constructors

Deps |

Fields

- depsModule :: !Module

  module

- depsRequired :: !BlockIds

  blocks that always need to be linked when this object is loaded (e.g. everything that contains initializer code or foreign exports)

- depsHaskellExported :: !(Map ExportedFun BlockId)

  exported Haskell functions -> block

- depsBlocks :: !(Array BlockId BlockDeps)

  info about each block

#### Instances

Instances details

Binary Deps Source # |
Instance details Defined in GHC.StgToJS.Object Methods put_ :: BinHandle -> Deps -> IO () Source # put :: BinHandle -> Deps -> IO (Bin Deps) Source # get :: BinHandle -> IO Deps Source #
Outputable Deps Source # |
Instance details Defined in GHC.StgToJS.Object Methods ppr :: Deps -> SDoc Source #

data BlockDeps Source #

Constructors

BlockDeps |

Fields

- blockBlockDeps :: [Int]

  dependencies on blocks in this object

- blockFunDeps :: [ExportedFun]

  dependencies on exported symbols in other objects , blockForeignExported :: [ExpFun] , blockForeignImported :: [ForeignRef]

#### Instances

Instances details

Binary BlockDeps Source # |
Instance details Defined in GHC.StgToJS.Object Methods put_ :: BinHandle -> BlockDeps -> IO () Source # put :: BinHandle -> BlockDeps -> IO (Bin BlockDeps) Source # get :: BinHandle -> IO BlockDeps Source #

data DepsLocation Source #

Where are the dependencies

Constructors

ObjectFile FilePath | In an object file at path
ArchiveFile FilePath | In a Ar file at path
InMemory String Object | In memory

#### Instances

Instances details

Outputable DepsLocation Source # |
Instance details Defined in GHC.StgToJS.Object Methods ppr :: DepsLocation -> SDoc Source #

data ExportedFun Source #

Exported Functions

Constructors

ExportedFun |

Fields

- funModule :: !Module

  The module containing the function

- funSymbol :: !LexicalFastString

  The function

#### Instances

Instances details

Binary ExportedFun Source # |
Instance details Defined in GHC.StgToJS.Object Methods put_ :: BinHandle -> ExportedFun -> IO () Source # put :: BinHandle -> ExportedFun -> IO (Bin ExportedFun) Source # get :: BinHandle -> IO ExportedFun Source #
Outputable ExportedFun Source # |
Instance details Defined in GHC.StgToJS.Object Methods ppr :: ExportedFun -> SDoc Source #
Eq ExportedFun Source # |
Instance details Defined in GHC.StgToJS.Object Methods (==) :: ExportedFun -> ExportedFun -> Bool # (/=) :: ExportedFun -> ExportedFun -> Bool #
Ord ExportedFun Source # |
Instance details Defined in GHC.StgToJS.Object Methods compare :: ExportedFun -> ExportedFun -> Ordering # (<) :: ExportedFun -> ExportedFun -> Bool # (<=) :: ExportedFun -> ExportedFun -> Bool # (>) :: ExportedFun -> ExportedFun -> Bool # (>=) :: ExportedFun -> ExportedFun -> Bool # max :: ExportedFun -> ExportedFun -> ExportedFun # min :: ExportedFun -> ExportedFun -> ExportedFun #

# Orphan instances

Binary Ident Source # |
Instance details Methods put_ :: BinHandle -> Ident -> IO () Source # put :: BinHandle -> Ident -> IO (Bin Ident) Source # get :: BinHandle -> IO Ident Source #
Binary JExpr Source # |
Instance details Methods put_ :: BinHandle -> JExpr -> IO () Source # put :: BinHandle -> JExpr -> IO (Bin JExpr) Source # get :: BinHandle -> IO JExpr Source #
Binary JOp Source # |
Instance details Methods put_ :: BinHandle -> JOp -> IO () Source # put :: BinHandle -> JOp -> IO (Bin JOp) Source # get :: BinHandle -> IO JOp Source #
Binary JStat Source # |
Instance details Methods put_ :: BinHandle -> JStat -> IO () Source # put :: BinHandle -> JStat -> IO (Bin JStat) Source # get :: BinHandle -> IO JStat Source #
Binary JUOp Source # |
Instance details Methods put_ :: BinHandle -> JUOp -> IO () Source # put :: BinHandle -> JUOp -> IO (Bin JUOp) Source # get :: BinHandle -> IO JUOp Source #
Binary JVal Source # |
Instance details Methods put_ :: BinHandle -> JVal -> IO () Source # put :: BinHandle -> JVal -> IO (Bin JVal) Source # get :: BinHandle -> IO JVal Source #
Binary SaneDouble Source # |
Instance details Methods put_ :: BinHandle -> SaneDouble -> IO () Source # put :: BinHandle -> SaneDouble -> IO (Bin SaneDouble) Source # get :: BinHandle -> IO SaneDouble Source #
Binary CILayout Source # |
Instance details Methods put_ :: BinHandle -> CILayout -> IO () Source # put :: BinHandle -> CILayout -> IO (Bin CILayout) Source # get :: BinHandle -> IO CILayout Source #
Binary CIRegs Source # |
Instance details Methods put_ :: BinHandle -> CIRegs -> IO () Source # put :: BinHandle -> CIRegs -> IO (Bin CIRegs) Source # get :: BinHandle -> IO CIRegs Source #
Binary CIStatic Source # |
Instance details Methods put_ :: BinHandle -> CIStatic -> IO () Source # put :: BinHandle -> CIStatic -> IO (Bin CIStatic) Source # get :: BinHandle -> IO CIStatic Source #
Binary CIType Source # |
Instance details Methods put_ :: BinHandle -> CIType -> IO () Source # put :: BinHandle -> CIType -> IO (Bin CIType) Source # get :: BinHandle -> IO CIType Source #
Binary ClosureInfo Source # |
Instance details Methods put_ :: BinHandle -> ClosureInfo -> IO () Source # put :: BinHandle -> ClosureInfo -> IO (Bin ClosureInfo) Source # get :: BinHandle -> IO ClosureInfo Source #
Binary ExpFun Source # |
Instance details Methods put_ :: BinHandle -> ExpFun -> IO () Source # put :: BinHandle -> ExpFun -> IO (Bin ExpFun) Source # get :: BinHandle -> IO ExpFun Source #
Binary ForeignJSRef Source # |
Instance details Methods put_ :: BinHandle -> ForeignJSRef -> IO () Source # put :: BinHandle -> ForeignJSRef -> IO (Bin ForeignJSRef) Source # get :: BinHandle -> IO ForeignJSRef Source #
Binary JSFFIType Source # |
Instance details Methods put_ :: BinHandle -> JSFFIType -> IO () Source # put :: BinHandle -> JSFFIType -> IO (Bin JSFFIType) Source # get :: BinHandle -> IO JSFFIType Source #
Binary StaticArg Source # |
Instance details Methods put_ :: BinHandle -> StaticArg -> IO () Source # put :: BinHandle -> StaticArg -> IO (Bin StaticArg) Source # get :: BinHandle -> IO StaticArg Source #
Binary StaticInfo Source # |
Instance details Methods put_ :: BinHandle -> StaticInfo -> IO () Source # put :: BinHandle -> StaticInfo -> IO (Bin StaticInfo) Source # get :: BinHandle -> IO StaticInfo Source #
Binary StaticLit Source # |
Instance details Methods put_ :: BinHandle -> StaticLit -> IO () Source # put :: BinHandle -> StaticLit -> IO (Bin StaticLit) Source # get :: BinHandle -> IO StaticLit Source #
Binary StaticUnboxed Source # |
Instance details Methods put_ :: BinHandle -> StaticUnboxed -> IO () Source # put :: BinHandle -> StaticUnboxed -> IO (Bin StaticUnboxed) Source # get :: BinHandle -> IO StaticUnboxed Source #
Binary StaticVal Source # |
Instance details Methods put_ :: BinHandle -> StaticVal -> IO () Source # put :: BinHandle -> StaticVal -> IO (Bin StaticVal) Source # get :: BinHandle -> IO StaticVal Source #
Binary VarType Source # |
Instance details Methods put_ :: BinHandle -> VarType -> IO () Source # put :: BinHandle -> VarType -> IO (Bin VarType) Source # get :: BinHandle -> IO VarType Source #