ghc-lib-parser-9.12.2.20250421: The GHC API, decoupled from GHC versions

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
Safe Haskell | Ignore
Language | GHC2021

GHC.StgToJS.Object

Contents

- JS object
- HS object
- Orphan instances

Description

Synopsis

- data ObjectKind
  - = ObjJs
  - | ObjHs
  - | ObjCc
- getObjectKind :: FilePath -> IO (Maybe ObjectKind)
- getObjectKindBS :: ByteString -> Maybe ObjectKind
- data JSOptions = JSOptions {
  - enableCPP :: !Bool
  - emccExtraOptions :: ![String]
  - emccExportedFunctions :: ![String]
  - emccExportedRuntimeMethods :: ![String]
  }
- defaultJSOptions :: JSOptions
- getOptionsFromJsFile :: FilePath -> IO JSOptions
- writeJSObject :: JSOptions -> ByteString -> FilePath -> IO ()
- readJSObject :: FilePath -> IO (JSOptions, ByteString)
- parseJSObject :: ReadBinHandle -> IO (JSOptions, ByteString)
- parseJSObjectBS :: ByteString -> IO (JSOptions, ByteString)
- putObject :: WriteBinHandle -> ModuleName -> BlockInfo -> [ObjBlock] -> IO ()
- getObjectHeader :: ReadBinHandle -> IO (Either String ModuleName)
- getObjectBody :: ReadBinHandle -> ModuleName -> IO Object
- getObject :: ReadBinHandle -> IO (Maybe Object)
- readObject :: FilePath -> IO (Maybe Object)
- getObjectBlocks :: Object -> BlockIds -> IO [ObjBlock]
- readObjectBlocks :: FilePath -> BlockIds -> IO [ObjBlock]
- readObjectBlockInfo :: FilePath -> IO (Maybe BlockInfo)
- isGlobalBlock :: BlockId -> Bool
- data Object = Object {
  - objModuleName :: !ModuleName
  - objHandle :: !ReadBinHandle
  - objPayloadOffset :: !(Bin ObjBlock)
  - objBlockInfo :: !BlockInfo
  - objIndex :: !Index
  }
- data IndexEntry = IndexEntry {
  - idxSymbols :: ![FastString]
  - idxOffset :: !(Bin ObjBlock)
  }
- data LocatedBlockInfo = LocatedBlockInfo {
  - lbi_loc :: !BlockLocation
  - lbi_info :: !BlockInfo
  }
- data BlockInfo = BlockInfo {
  - bi_module :: !Module
  - bi_must_link :: !BlockIds
  - bi_exports :: !(Map ExportedFun BlockId)
  - bi_block_deps :: !(Array BlockId BlockDeps)
  }
- data BlockDeps = BlockDeps {
  - blockBlockDeps :: [BlockId]
  - blockFunDeps :: [ExportedFun]
  }
- data BlockLocation
  - = ObjectFile FilePath
  - | ArchiveFile FilePath
  - | InMemory String Object
- type BlockId = Int
- type BlockIds = IntSet
- data BlockRef = BlockRef {
  - block_ref_mod :: !Module
  - block_ref_idx :: !BlockId
  }
- data ExportedFun = ExportedFun {
  - funModule :: !Module
  - funSymbol :: !LexicalFastString
  }

# Documentation

data ObjectKind Source #

Different kinds of object (.o) supported by the JS backend

Constructors

ObjJs | JavaScript source embedded in a .o
ObjHs | JS backend object for Haskell code
ObjCc | Wasm module object as produced by emcc

#### Instances

Instances details

Show ObjectKind Source # |
Instance details Defined in GHC.StgToJS.Object Methods showsPrec :: Int -> ObjectKind -> ShowS Source # show :: ObjectKind -> String Source # showList :: [ObjectKind] -> ShowS Source #
Eq ObjectKind Source # |
Instance details Defined in GHC.StgToJS.Object Methods (==) :: ObjectKind -> ObjectKind -> Bool Source # (/=) :: ObjectKind -> ObjectKind -> Bool Source #
Ord ObjectKind Source # |

Instance details

Defined in GHC.StgToJS.Object

Methods

compare :: ObjectKind -> ObjectKind -> Ordering Source #

(<) :: ObjectKind -> ObjectKind -> Bool Source #

(<=) :: ObjectKind -> ObjectKind -> Bool Source #

(>) :: ObjectKind -> ObjectKind -> Bool Source #

(>=) :: ObjectKind -> ObjectKind -> Bool Source #

max :: ObjectKind -> ObjectKind -> ObjectKind Source #

min :: ObjectKind -> ObjectKind -> ObjectKind Source #

getObjectKind :: FilePath -> IO (Maybe ObjectKind) Source #

Get the kind of a file object, if any

getObjectKindBS :: ByteString -> Maybe ObjectKind Source #

Get the kind of an object stored in a bytestring, if any

# JS object

data JSOptions Source #

Options obtained from pragmas in JS files

Constructors

JSOptions |

Fields

- enableCPP :: !Bool

  Enable CPP on the JS file

- emccExtraOptions :: ![String]

  Pass additional options to emcc at link time

- emccExportedFunctions :: ![String]

  Arguments for `-sEXPORTED_FUNCTIONS`

- emccExportedRuntimeMethods :: ![String]

  Arguments for `-sEXPORTED_RUNTIME_METHODS`

#### Instances

Instances details

Semigroup JSOptions Source # |
Instance details Defined in GHC.StgToJS.Object Methods (<>) :: JSOptions -> JSOptions -> JSOptions Source # sconcat :: NonEmpty JSOptions -> JSOptions Source # stimes :: Integral b => b -> JSOptions -> JSOptions Source #
Binary JSOptions Source # |
Instance details Defined in GHC.StgToJS.Object Methods put_ :: WriteBinHandle -> JSOptions -> IO () Source # put :: WriteBinHandle -> JSOptions -> IO (Bin JSOptions) Source # get :: ReadBinHandle -> IO JSOptions Source #
Eq JSOptions Source # |
Instance details Defined in GHC.StgToJS.Object Methods (==) :: JSOptions -> JSOptions -> Bool Source # (/=) :: JSOptions -> JSOptions -> Bool Source #
Ord JSOptions Source # |

Instance details

Defined in GHC.StgToJS.Object

Methods

compare :: JSOptions -> JSOptions -> Ordering Source #

(<) :: JSOptions -> JSOptions -> Bool Source #

(<=) :: JSOptions -> JSOptions -> Bool Source #

(>) :: JSOptions -> JSOptions -> Bool Source #

(>=) :: JSOptions -> JSOptions -> Bool Source #

max :: JSOptions -> JSOptions -> JSOptions Source #

min :: JSOptions -> JSOptions -> JSOptions Source #

defaultJSOptions :: JSOptions Source #

getOptionsFromJsFile Source #

Arguments

:: FilePath | Input file
-> IO JSOptions | Parsed options.

Parse option pragma in JS file

writeJSObject :: JSOptions -> ByteString -> FilePath -> IO () Source #

Write a JS object (embed some handwritten JS code)

readJSObject :: FilePath -> IO (JSOptions, ByteString) Source #

Read a JS object from file

parseJSObject :: ReadBinHandle -> IO (JSOptions, ByteString) Source #

Read a JS object from BinHandle

parseJSObjectBS :: ByteString -> IO (JSOptions, ByteString) Source #

Read a JS object from ByteString

# HS object

putObject Source #

Arguments

:: WriteBinHandle |
-> ModuleName | module
-> BlockInfo | block infos
-> [ObjBlock] | 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 :: ReadBinHandle -> IO (Either String ModuleName) Source #

Parse object header

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

Parse object body. Must be called after a successful getObjectHeader

getObject :: ReadBinHandle -> 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).

getObjectBlocks :: Object -> BlockIds -> IO [ObjBlock] Source #

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

readObjectBlocks :: FilePath -> BlockIds -> IO [ObjBlock] Source #

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

readObjectBlockInfo :: FilePath -> IO (Maybe BlockInfo) Source #

Reads only the part necessary to get the block info

isGlobalBlock :: BlockId -> Bool Source #

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

data Object Source #

A HS object file

Constructors

Object |

Fields

- objModuleName :: !ModuleName

  name of the module

- objHandle :: !ReadBinHandle

  BinHandle that can be used to read the ObjBlocks

- objPayloadOffset :: !(Bin ObjBlock)

  Offset of the payload (units)

- objBlockInfo :: !BlockInfo

  Information about blocks

- objIndex :: !Index

  Block index: symbols per block and block offset in the object file

data IndexEntry Source #

Constructors

IndexEntry |

Fields

- idxSymbols :: ![FastString]

  Symbols exported by a block

- idxOffset :: !(Bin ObjBlock)

  Offset of the block in the object file

#### Instances

Instances details

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

data LocatedBlockInfo Source #

Constructors

LocatedBlockInfo |

Fields

- lbi_loc :: !BlockLocation

  Where to find the blocks

- lbi_info :: !BlockInfo

  Block information

data BlockInfo Source #

Information about blocks (linkable units)

Constructors

BlockInfo |

Fields

- bi_module :: !Module

  Module they were generated from

- bi_must_link :: !BlockIds

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

- bi_exports :: !(Map ExportedFun BlockId)

  exported Haskell functions -> block

- bi_block_deps :: !(Array BlockId BlockDeps)

  dependencies of each block

#### Instances

Instances details

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

data BlockDeps Source #

Constructors

BlockDeps |

Fields

- blockBlockDeps :: [BlockId]

  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_ :: WriteBinHandle -> BlockDeps -> IO () Source # put :: WriteBinHandle -> BlockDeps -> IO (Bin BlockDeps) Source # get :: ReadBinHandle -> IO BlockDeps Source #

data BlockLocation Source #

Where are the blocks

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 BlockLocation Source # |
Instance details Defined in GHC.StgToJS.Object Methods ppr :: BlockLocation -> SDoc Source #

type BlockId = Int Source #

type BlockIds = IntSet Source #

data BlockRef Source #

A `BlockRef` is a pair of a module and the index of the block in the object file

Constructors

BlockRef |

Fields

- block_ref_mod :: !Module

  Module

- block_ref_idx :: !BlockId

  Block index in the object file

#### Instances

Instances details

Eq BlockRef Source # |
Instance details Defined in GHC.StgToJS.Object Methods (==) :: BlockRef -> BlockRef -> Bool Source # (/=) :: BlockRef -> BlockRef -> Bool Source #
Ord BlockRef Source # |
Instance details Defined in GHC.StgToJS.Object Methods compare :: BlockRef -> BlockRef -> Ordering Source # (<) :: BlockRef -> BlockRef -> Bool Source # (<=) :: BlockRef -> BlockRef -> Bool Source # (>) :: BlockRef -> BlockRef -> Bool Source # (>=) :: BlockRef -> BlockRef -> Bool Source # max :: BlockRef -> BlockRef -> BlockRef Source # min :: BlockRef -> BlockRef -> BlockRef 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_ :: WriteBinHandle -> ExportedFun -> IO () Source # put :: WriteBinHandle -> ExportedFun -> IO (Bin ExportedFun) Source # get :: ReadBinHandle -> 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 Source # (/=) :: ExportedFun -> ExportedFun -> Bool Source #
Ord ExportedFun Source # |

Instance details

Defined in GHC.StgToJS.Object

Methods

compare :: ExportedFun -> ExportedFun -> Ordering Source #

(<) :: ExportedFun -> ExportedFun -> Bool Source #

(<=) :: ExportedFun -> ExportedFun -> Bool Source #

(>) :: ExportedFun -> ExportedFun -> Bool Source #

(>=) :: ExportedFun -> ExportedFun -> Bool Source #

max :: ExportedFun -> ExportedFun -> ExportedFun Source #

min :: ExportedFun -> ExportedFun -> ExportedFun Source #

# Orphan instances

Binary Ident Source # |
Instance details Methods put_ :: WriteBinHandle -> Ident -> IO () Source # put :: WriteBinHandle -> Ident -> IO (Bin Ident) Source # get :: ReadBinHandle -> IO Ident Source #
Binary AOp Source # |
Instance details Methods put_ :: WriteBinHandle -> AOp -> IO () Source # put :: WriteBinHandle -> AOp -> IO (Bin AOp) Source # get :: ReadBinHandle -> IO AOp Source #
Binary JExpr Source # |
Instance details Methods put_ :: WriteBinHandle -> JExpr -> IO () Source # put :: WriteBinHandle -> JExpr -> IO (Bin JExpr) Source # get :: ReadBinHandle -> IO JExpr Source #
Binary JStat Source # |
Instance details Methods put_ :: WriteBinHandle -> JStat -> IO () Source # put :: WriteBinHandle -> JStat -> IO (Bin JStat) Source # get :: ReadBinHandle -> IO JStat Source #
Binary JVal Source # |
Instance details Methods put_ :: WriteBinHandle -> JVal -> IO () Source # put :: WriteBinHandle -> JVal -> IO (Bin JVal) Source # get :: ReadBinHandle -> IO JVal Source #
Binary Op Source # |
Instance details Methods put_ :: WriteBinHandle -> Op -> IO () Source # put :: WriteBinHandle -> Op -> IO (Bin Op) Source # get :: ReadBinHandle -> IO Op Source #
Binary UOp Source # |
Instance details Methods put_ :: WriteBinHandle -> UOp -> IO () Source # put :: WriteBinHandle -> UOp -> IO (Bin UOp) Source # get :: ReadBinHandle -> IO UOp Source #
Binary CILayout Source # |
Instance details Methods put_ :: WriteBinHandle -> CILayout -> IO () Source # put :: WriteBinHandle -> CILayout -> IO (Bin CILayout) Source # get :: ReadBinHandle -> IO CILayout Source #
Binary CIRegs Source # |
Instance details Methods put_ :: WriteBinHandle -> CIRegs -> IO () Source # put :: WriteBinHandle -> CIRegs -> IO (Bin CIRegs) Source # get :: ReadBinHandle -> IO CIRegs Source #
Binary CIStatic Source # |
Instance details Methods put_ :: WriteBinHandle -> CIStatic -> IO () Source # put :: WriteBinHandle -> CIStatic -> IO (Bin CIStatic) Source # get :: ReadBinHandle -> IO CIStatic Source #
Binary CIType Source # |
Instance details Methods put_ :: WriteBinHandle -> CIType -> IO () Source # put :: WriteBinHandle -> CIType -> IO (Bin CIType) Source # get :: ReadBinHandle -> IO CIType Source #
Binary ClosureInfo Source # |
Instance details Methods put_ :: WriteBinHandle -> ClosureInfo -> IO () Source # put :: WriteBinHandle -> ClosureInfo -> IO (Bin ClosureInfo) Source # get :: ReadBinHandle -> IO ClosureInfo Source #
Binary ExpFun Source # |
Instance details Methods put_ :: WriteBinHandle -> ExpFun -> IO () Source # put :: WriteBinHandle -> ExpFun -> IO (Bin ExpFun) Source # get :: ReadBinHandle -> IO ExpFun Source #
Binary ForeignJSRef Source # |
Instance details Methods put_ :: WriteBinHandle -> ForeignJSRef -> IO () Source # put :: WriteBinHandle -> ForeignJSRef -> IO (Bin ForeignJSRef) Source # get :: ReadBinHandle -> IO ForeignJSRef Source #
Binary JSFFIType Source # |
Instance details Methods put_ :: WriteBinHandle -> JSFFIType -> IO () Source # put :: WriteBinHandle -> JSFFIType -> IO (Bin JSFFIType) Source # get :: ReadBinHandle -> IO JSFFIType Source #
Binary JSRep Source # |
Instance details Methods put_ :: WriteBinHandle -> JSRep -> IO () Source # put :: WriteBinHandle -> JSRep -> IO (Bin JSRep) Source # get :: ReadBinHandle -> IO JSRep Source #
Binary StaticArg Source # |
Instance details Methods put_ :: WriteBinHandle -> StaticArg -> IO () Source # put :: WriteBinHandle -> StaticArg -> IO (Bin StaticArg) Source # get :: ReadBinHandle -> IO StaticArg Source #
Binary StaticInfo Source # |
Instance details Methods put_ :: WriteBinHandle -> StaticInfo -> IO () Source # put :: WriteBinHandle -> StaticInfo -> IO (Bin StaticInfo) Source # get :: ReadBinHandle -> IO StaticInfo Source #
Binary StaticLit Source # |
Instance details Methods put_ :: WriteBinHandle -> StaticLit -> IO () Source # put :: WriteBinHandle -> StaticLit -> IO (Bin StaticLit) Source # get :: ReadBinHandle -> IO StaticLit Source #
Binary StaticUnboxed Source # |
Instance details Methods put_ :: WriteBinHandle -> StaticUnboxed -> IO () Source # put :: WriteBinHandle -> StaticUnboxed -> IO (Bin StaticUnboxed) Source # get :: ReadBinHandle -> IO StaticUnboxed Source #
Binary StaticVal Source # |
Instance details Methods put_ :: WriteBinHandle -> StaticVal -> IO () Source # put :: WriteBinHandle -> StaticVal -> IO (Bin StaticVal) Source # get :: ReadBinHandle -> IO StaticVal Source #