ghc-9.8.3: The GHC API
Safe HaskellNone
LanguageHaskell2010

GHC.CmmToAsm.Wasm.Types

Synopsis

Documentation

data WasmType Source #

WebAssembly type of a WebAssembly value that WebAssembly code could either expect on the evaluation stack or leave on the evaluation stack.

Constructors

I32 
I64 
F32 
F64 

Instances

Instances details
TestEquality WasmTypeTag Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

Methods

testEquality :: forall (a :: WasmType) (b :: WasmType). WasmTypeTag a -> WasmTypeTag b -> Maybe (a :~: b) Source #

data WasmTypeTag (a :: WasmType) where Source #

Singleton type useful for programming with WasmType at the type level.

Instances

Instances details
TestEquality WasmTypeTag Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

Methods

testEquality :: forall (a :: WasmType) (b :: WasmType). WasmTypeTag a -> WasmTypeTag b -> Maybe (a :~: b) Source #

Show (WasmTypeTag t) Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

data SomeWasmType where Source #

Constructors

SomeWasmType :: forall (t :: WasmType). WasmTypeTag t -> SomeWasmType 

Instances

Instances details
Eq SomeWasmType Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

data TypeList (a :: [WasmType]) where Source #

List of WebAssembly types used to describe the sequence of WebAssembly values that a block of code may expect on the stack or leave on the stack.

Constructors

TypeListNil :: TypeList ('[] :: [WasmType]) 
TypeListCons :: forall (t :: WasmType) (ts :: [WasmType]). WasmTypeTag t -> TypeList ts -> TypeList (t ': ts) 

data WasmFunctionType (pre :: [WasmType]) (post :: [WasmType]) Source #

The type of a WebAssembly function, loop, block, or conditional. This type says what values the code expects to pop off the stack and what values it promises to push. The WebAssembly standard requires that this type appear explicitly in the code.

Constructors

WasmFunctionType 

Fields

newtype SymName Source #

For simplicity, we record other metadata in WasmCodeGenState by need, instead of carrying them along with SymName.

Constructors

SymName FastString 

Instances

Instances details
IsString SymName Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

Show SymName Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

Uniquable SymName Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

Eq SymName Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

Methods

(==) :: SymName -> SymName -> Bool #

(/=) :: SymName -> SymName -> Bool #

Ord SymName Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

data SymVisibility Source #

Constructors

SymUndefined

Not defined in the current compilation unit.

[ undefined binding=global vis=default ]
SymStatic

Defined, not visible to other compilation units.

[ binding=local vis=default ]
SymDefault

Defined, visible to other compilation units.

Adds .hidden & .globl directives in the output assembly.

[ binding=global vis=hidden ]

data SymKind Source #

Represents whether a symbol is a data symbol or a function symbol. Unlike linkers for other targets, wasm-ld does panic at link-time if it finds symbol kind inconsistency between the definition site and other use sites.

Currently we solely rely on isCFunctionLabel to determine a symbol's kind, but it does take extra effort to make it work. The main source of inconsistency arises from hand-written Cmm sources, where it's possible to refer to external entities like xxx_info and xxx_closure without explicit import CLOSURE declarations. The Cmm parser will implicitly assume those are foreign function labels, and then this will break the WebAssembly backend. #22368 provides more context on this issue.

tl;dr for any GHC contributor that accidentally triggers wasm-ld errors when hacking Cmm: whatever data symbols are used in new code, just add the corresponding import CLOSURE declarations at the top of that Cmm file.

Constructors

SymData 
SymFunc 

Instances

Instances details
Eq SymKind Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

Methods

(==) :: SymKind -> SymKind -> Bool #

(/=) :: SymKind -> SymKind -> Bool #

data DataSectionKind Source #

WebAssembly doesn't really have proper read-only memory regions yet. Neverthless we add the .rodata logic here, wasm-ld will aggregate all .rodata sections into a single one, which adds possibility for runtime checks later, either via a customized runtime, or via code instrumentation. See https://github.com/llvm/llvm-project/blob/b296aed8ae239c20ebdd7969e978f8d2a3b9c178/lld/wasm/Writer.cpp#L856

Constructors

SectionData 
SectionROData 

data DataSectionContent Source #

Neither Cmm or Wasm type system takes integer signedness into account, therefore we always round up a CmmLit to the right width and handle it as an untyped integer.

data FuncBody (w :: WasmType) Source #

Constructors

FuncBody 

Fields

data Signage Source #

Constructors

Signed 
Unsigned 

data WasmInstr (a :: WasmType) (b :: [WasmType]) (c :: [WasmType]) where Source #

The w type variable in the Wasm IR stands for "platform word type", so TagI32 on wasm32, and TagI64 on wasm64. This way, we can make the codegen logic work on both wasm32/wasm64 in a type-safe manner.

Constructors

WasmComment :: forall (a :: WasmType) (b :: [WasmType]). String -> WasmInstr a b b 
WasmNop :: forall (a :: WasmType) (b :: [WasmType]). WasmInstr a b b 
WasmDrop :: forall (a :: WasmType) (t :: WasmType) (c :: [WasmType]). WasmInstr a (t ': c) c 
WasmUnreachable :: forall (a :: WasmType) (b :: [WasmType]) (c :: [WasmType]). WasmInstr a b c 
WasmConst :: forall (t :: WasmType) (a :: WasmType) (b :: [WasmType]). WasmTypeTag t -> Integer -> WasmInstr a b (t ': b) 
WasmSymConst :: forall (a :: WasmType) (b :: [WasmType]). SymName -> WasmInstr a b (a ': b) 
WasmLoad :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t -> Maybe Int -> Signage -> Int -> AlignmentSpec -> WasmInstr a (a ': pre) (t ': pre) 
WasmStore :: forall (t :: WasmType) (a :: WasmType) (c :: [WasmType]). WasmTypeTag t -> Maybe Int -> Int -> AlignmentSpec -> WasmInstr a (t ': (a ': c)) c 
WasmGlobalGet :: forall (t :: WasmType) (a :: WasmType) (b :: [WasmType]). WasmTypeTag t -> SymName -> WasmInstr a b (t ': b) 
WasmGlobalSet :: forall (t :: WasmType) (a :: WasmType) (c :: [WasmType]). WasmTypeTag t -> SymName -> WasmInstr a (t ': c) c 
WasmLocalGet :: forall (t :: WasmType) (a :: WasmType) (b :: [WasmType]). WasmTypeTag t -> Int -> WasmInstr a b (t ': b) 
WasmLocalSet :: forall (t :: WasmType) (a :: WasmType) (c :: [WasmType]). WasmTypeTag t -> Int -> WasmInstr a (t ': c) c 
WasmLocalTee :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t -> Int -> WasmInstr a (t ': pre) (t ': pre) 
WasmCCall :: forall (a :: WasmType) (b :: [WasmType]) (c :: [WasmType]). SymName -> WasmInstr a b c 
WasmCCallIndirect :: forall (arg_tys :: [WasmType]) (ret_tys :: [WasmType]) (a :: WasmType) (pre :: [WasmType]) (c :: [WasmType]). TypeList arg_tys -> TypeList ret_tys -> WasmInstr a (a ': pre) c 
WasmConcat :: forall (a :: WasmType) (b :: [WasmType]) (mid :: [WasmType]) (c :: [WasmType]). WasmInstr a b mid -> WasmInstr a mid c -> WasmInstr a b c 
WasmReinterpret :: forall (t0 :: WasmType) (t1 :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t0 -> WasmTypeTag t1 -> WasmInstr a (t0 ': pre) (t1 ': pre) 
WasmTruncSat :: forall (t0 :: WasmType) (t1 :: WasmType) (a :: WasmType) (pre :: [WasmType]). Signage -> WasmTypeTag t0 -> WasmTypeTag t1 -> WasmInstr a (t0 ': pre) (t1 ': pre) 
WasmConvert :: forall (t0 :: WasmType) (t1 :: WasmType) (a :: WasmType) (pre :: [WasmType]). Signage -> WasmTypeTag t0 -> WasmTypeTag t1 -> WasmInstr a (t0 ': pre) (t1 ': pre) 
WasmAdd :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (t ': pre) 
WasmSub :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (t ': pre) 
WasmMul :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (t ': pre) 
WasmDiv :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). Signage -> WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (t ': pre) 
WasmRem :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). Signage -> WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (t ': pre) 
WasmAnd :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (t ': pre) 
WasmOr :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (t ': pre) 
WasmXor :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (t ': pre) 
WasmEq :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (a ': pre) 
WasmNe :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (a ': pre) 
WasmLt :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). Signage -> WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (a ': pre) 
WasmGt :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). Signage -> WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (a ': pre) 
WasmLe :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). Signage -> WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (a ': pre) 
WasmGe :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). Signage -> WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (a ': pre) 
WasmShl :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (t ': pre) 
WasmShr :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). Signage -> WasmTypeTag t -> WasmInstr a (t ': (t ': pre)) (t ': pre) 
WasmI32Extend8S :: forall (a :: WasmType) (pre :: [WasmType]). WasmInstr a ('I32 ': pre) ('I32 ': pre) 
WasmI32Extend16S :: forall (a :: WasmType) (pre :: [WasmType]). WasmInstr a ('I32 ': pre) ('I32 ': pre) 
WasmI64Extend8S :: forall (a :: WasmType) (pre :: [WasmType]). WasmInstr a ('I64 ': pre) ('I64 ': pre) 
WasmI64Extend16S :: forall (a :: WasmType) (pre :: [WasmType]). WasmInstr a ('I64 ': pre) ('I64 ': pre) 
WasmI64Extend32S :: forall (a :: WasmType) (pre :: [WasmType]). WasmInstr a ('I64 ': pre) ('I64 ': pre) 
WasmI64ExtendI32 :: forall (a :: WasmType) (pre :: [WasmType]). Signage -> WasmInstr a ('I32 ': pre) ('I64 ': pre) 
WasmI32WrapI64 :: forall (a :: WasmType) (pre :: [WasmType]). WasmInstr a ('I64 ': pre) ('I32 ': pre) 
WasmF32DemoteF64 :: forall (a :: WasmType) (pre :: [WasmType]). WasmInstr a ('F64 ': pre) ('F32 ': pre) 
WasmF64PromoteF32 :: forall (a :: WasmType) (pre :: [WasmType]). WasmInstr a ('F32 ': pre) ('F64 ': pre) 
WasmAbs :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t -> WasmInstr a (t ': pre) (t ': pre) 
WasmNeg :: forall (t :: WasmType) (a :: WasmType) (pre :: [WasmType]). WasmTypeTag t -> WasmInstr a (t ': pre) (t ': pre) 
WasmCond :: forall (a :: WasmType) (c :: [WasmType]). WasmInstr a c c -> WasmInstr a (a ': c) c 

newtype WasmExpr (w :: WasmType) (t :: WasmType) Source #

Constructors

WasmExpr (forall (pre :: [WasmType]). WasmInstr w pre (t ': pre)) 

data SomeWasmExpr (w :: WasmType) where Source #

Constructors

SomeWasmExpr :: forall (t :: WasmType) (w :: WasmType). WasmTypeTag t -> WasmExpr w t -> SomeWasmExpr w 

newtype WasmStatements (w :: WasmType) Source #

Constructors

WasmStatements (forall (pre :: [WasmType]). WasmInstr w pre pre) 

data WasmControl a b (c :: [WasmType]) (d :: [WasmType]) where Source #

Representation of WebAssembly control flow. Normally written as WasmControl s e pre post Type parameter s is the type of (unspecified) statements. It might be instantiated with an open Cmm block or with a sequence of Wasm instructions. Parameter e is the type of expressions. Parameter pre represents the values that are expected on the WebAssembly stack when the code runs, and post represents the state of the stack on completion.

Constructors

WasmPush :: forall (t :: WasmType) b a (c :: [WasmType]). WasmTypeTag t -> b -> WasmControl a b c (t ': c) 
WasmBlock :: forall (c :: [WasmType]) (d :: [WasmType]) a b. WasmFunctionType c d -> WasmControl a b c d -> WasmControl a b c d 
WasmLoop :: forall (c :: [WasmType]) (d :: [WasmType]) a b. WasmFunctionType c d -> WasmControl a b c d -> WasmControl a b c d 
WasmIfTop :: forall (pre :: [WasmType]) (d :: [WasmType]) a b. WasmFunctionType pre d -> WasmControl a b pre d -> WasmControl a b pre d -> WasmControl a b ('I32 ': pre) d 
WasmBr :: forall a b (c :: [WasmType]) (d :: [WasmType]). Int -> WasmControl a b c d 
WasmFallthrough :: forall a b (c :: [WasmType]) (d :: [WasmType]). WasmControl a b c d 
WasmBrTable :: forall b a (c :: [WasmType]) (d :: [WasmType]). b -> BrTableInterval -> [Int] -> Int -> WasmControl a b c d 
WasmTailCall :: forall b a (c :: [WasmType]) (d :: [WasmType]). b -> WasmControl a b c d 
WasmActions :: forall a b (c :: [WasmType]). a -> WasmControl a b c c 
WasmSeq :: forall a b (c :: [WasmType]) (mid :: [WasmType]) (d :: [WasmType]). WasmControl a b c mid -> WasmControl a b mid d -> WasmControl a b c d 

wasmControlCast :: forall s e (pre :: [WasmType]) (post :: [WasmType]) (pre' :: [WasmType]) (post' :: [WasmType]). WasmControl s e pre post -> WasmControl s e pre' post' Source #

data WasmCodeGenState (w :: WasmType) Source #

Constructors

WasmCodeGenState 

Fields

newtype WasmCodeGenM (w :: WasmType) a Source #

Constructors

WasmCodeGenM (State (WasmCodeGenState w) a) 

Instances

Instances details
Applicative (WasmCodeGenM w) Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

Methods

pure :: a -> WasmCodeGenM w a Source #

(<*>) :: WasmCodeGenM w (a -> b) -> WasmCodeGenM w a -> WasmCodeGenM w b Source #

liftA2 :: (a -> b -> c) -> WasmCodeGenM w a -> WasmCodeGenM w b -> WasmCodeGenM w c Source #

(*>) :: WasmCodeGenM w a -> WasmCodeGenM w b -> WasmCodeGenM w b Source #

(<*) :: WasmCodeGenM w a -> WasmCodeGenM w b -> WasmCodeGenM w a Source #

Functor (WasmCodeGenM w) Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

Methods

fmap :: (a -> b) -> WasmCodeGenM w a -> WasmCodeGenM w b Source #

(<$) :: a -> WasmCodeGenM w b -> WasmCodeGenM w a Source #

Monad (WasmCodeGenM w) Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

Methods

(>>=) :: WasmCodeGenM w a -> (a -> WasmCodeGenM w b) -> WasmCodeGenM w b Source #

(>>) :: WasmCodeGenM w a -> WasmCodeGenM w b -> WasmCodeGenM w b Source #

return :: a -> WasmCodeGenM w a Source #

MonadUnique (WasmCodeGenM w) Source # 
Instance details

Defined in GHC.CmmToAsm.Wasm.Types

wasmGetsM :: forall (w :: WasmType) a. (WasmCodeGenState w -> a) -> WasmCodeGenM w a Source #

wasmStateM :: forall (w :: WasmType) a. (WasmCodeGenState w -> (# a, WasmCodeGenState w #)) -> WasmCodeGenM w a Source #