wrench-0.0.6.3
Safe HaskellNone
LanguageHaskell2010

Wrench.Isa.Wasm32.Instruction

Description

The instruction set itself: the Wasm32Isa type, the assembly syntax that produces it, the field guards every immediate has to pass, and the size each instruction occupies.

Synopsis

Documentation

data Wasm32Isa w l Source #

One instruction. Each entry starts with its syntax and stack effect.

Constructors

I32Const l
i32.const <value: i32> ( -- value: i32 )

Push an immediate: a number or a label, which is how a function address is produced (see Functions and locals).

I32Add
i32.add ( a: i32, b: i32 -- sum: i32 )
I32Sub
i32.sub ( a: i32, b: i32 -- difference: i32 )

a - b.

I32Mul
i32.mul ( a: i32, b: i32 -- product: i32 )

Keeps the low 32 bits of the product.

I32DivS
i32.div_s ( a: i32, b: i32 -- quotient: i32 )

Signed division truncating toward zero: -7 / 2 is -3. Stops with an error on a zero divisor and on minBound / -1.

I32RemS
i32.rem_s ( a: i32, b: i32 -- remainder: i32 )

Signed remainder with the sign of a: -7 % 2 is -1. Stops with an error only on a zero divisor; minBound % -1 is 0.

I32And
i32.and ( a: i32, b: i32 -- bits: i32 )
I32Or
i32.or ( a: i32, b: i32 -- bits: i32 )
I32Xor
i32.xor ( a: i32, b: i32 -- bits: i32 )
I32Shl
i32.shl ( value: i32, amount: i32 -- shifted: i32 )

Shift left. The amount is taken modulo 32, as for every shift.

I32ShrS
i32.shr_s ( value: i32, amount: i32 -- shifted: i32 )

Arithmetic (sign-extending) shift right.

I32ShrU
i32.shr_u ( value: i32, amount: i32 -- shifted: i32 )

Logical (zero-filling) shift right.

I32Eqz
i32.eqz ( value: i32 -- flag: i32 )

Push 1 if the value is 0, else 0.

I32Eq
i32.eq ( a: i32, b: i32 -- flag: i32 )

Push 1 if a = b, else 0, like every comparison.

I32LtS
i32.lt_s ( a: i32, b: i32 -- flag: i32 )

Signed a < b.

I32LeS
i32.le_s ( a: i32, b: i32 -- flag: i32 )

Signed a <= b.

I32GtS
i32.gt_s ( a: i32, b: i32 -- flag: i32 )

Signed a > b.

I32GeS
i32.ge_s ( a: i32, b: i32 -- flag: i32 )

Signed a >= b.

I32LtU
i32.lt_u ( a: i32, b: i32 -- flag: i32 )

Unsigned a < b, so -1 compares greater than 1.

I32LeU
i32.le_u ( a: i32, b: i32 -- flag: i32 )

Unsigned a <= b.

I32GtU
i32.gt_u ( a: i32, b: i32 -- flag: i32 )

Unsigned a > b.

I32GeU
i32.ge_u ( a: i32, b: i32 -- flag: i32 )

Unsigned a >= b.

I32Load l
i32.load <offset: u8> ( address: i32 -- value: i32 )

Push the word at address + offset. Every load and store takes an optional offset, 0 to 255, so a struct field or a small array element needs no i32.add:

i32.const point
i32.load 4            ; point.y
I32Load8U l
i32.load8_u <offset: u8> ( address: i32 -- value: i32 )

Like I32Load, but reads one byte and zero-extends it.

I32Load8S l
i32.load8_s <offset: u8> ( address: i32 -- value: i32 )

Like I32Load8U, but sign-extends.

I32Store l
i32.store <offset: u8> ( address: i32, value: i32 -- )

Write the word at address + offset. The address goes under the value, so push it first.

I32Store8 l
i32.store8 <offset: u8> ( address: i32, value: i32 -- )

Like I32Store, but writes only the low byte.

Block
block ( -- )

Open a scope; a branch to it continues after its end.

Loop
loop ( -- )

Open a scope; a branch to it continues at the start of its body. Without a branch the body runs once.

If
if ( condition: i32 -- )

Run the following body if the condition is non-zero, otherwise continue after the matching else or end. Opens no scope.

Else
else ( -- )

Reached at the end of a taken if body: continue after the matching end.

End
end ( -- )

Close the block or loop it belongs to; for an if, do nothing.

Br l
br <depth: u8> ( -- )

Branch to the scope depth levels out, 0 being the innermost open block or loop, and close every scope inside it. A target block is closed too, since execution leaves it; a target loop stays open.

BrIf l
br_if <depth: u8> ( condition: i32 -- )

Br if the condition is non-zero, otherwise continue.

Unreachable
unreachable ( -- )

Stop with an error.

Call
call <paramCount: u8>, <resultCount: u8> ( ...params: i32, target: i32 -- ...results: i32 )

Call the function at target: the paramCount values under it become its first locals, and resultCount values come back. Neither count is checked against the callee.

Fields

Return
return ( ...results: i32 -- )

Leave the current function, closing every scope it still has open and passing the call's resultCount values from the top of the stack back to the caller.

LocalGet l
local.get <index: u8> ( -- value: i32 )
LocalSet l
local.set <index: u8> ( value: i32 -- )
LocalTee l
local.tee <index: u8> ( value: i32 -- value: i32 )

Like local.set, but keeps the value on the stack.

LocalsReserve l
locals.reserve <count: u8> ( -- )

Add count locals after the ones the frame has. Use it first thing in a function, before pushing anything: the new locals are the next words down the stack. They are not cleared.

Drop
drop ( value: i32 -- )

Discard the top value, e.g. a result the caller does not need.

Select
select ( a: i32, b: i32, condition: i32 -- chosen: i32 )

Push a if the condition is non-zero, b otherwise.

SpInit
sp.init ( address: i32 -- )

Move stackRoot, where both stacks start, to address. Both stacks restart empty there, so use it before anything is pushed: the frame's locals and any open scope are lost. Nothing checks the address.

Halt
halt ( -- )

Stop the machine.

Instances

Instances details
Functor (Wasm32Isa w) Source # 
Instance details

Defined in Wrench.Isa.Wasm32.Instruction

Methods

fmap :: (a -> b) -> Wasm32Isa w a -> Wasm32Isa w b #

(<$) :: a -> Wasm32Isa w b -> Wasm32Isa w a #

IsWord w => DerefMnemonic (Wasm32Isa w) w Source # 
Instance details

Defined in Wrench.Isa.Wasm32.Instruction

Methods

derefMnemonic :: (Text -> Maybe w) -> w -> Wasm32Isa w (Ref w) -> Wasm32Isa w w Source #

IsWord w => Machine (Wasm32St w) (Wasm32Isa w w) w Source # 
Instance details

Defined in Wrench.Isa.Wasm32.Execute

Show l => Show (Wasm32Isa w l) Source # 
Instance details

Defined in Wrench.Isa.Wasm32.Instruction

Methods

showsPrec :: Int -> Wasm32Isa w l -> ShowS #

show :: Wasm32Isa w l -> String #

showList :: [Wasm32Isa w l] -> ShowS #

Eq l => Eq (Wasm32Isa w l) Source # 
Instance details

Defined in Wrench.Isa.Wasm32.Instruction

Methods

(==) :: Wasm32Isa w l -> Wasm32Isa w l -> Bool #

(/=) :: Wasm32Isa w l -> Wasm32Isa w l -> Bool #

ByteSize (Wasm32Isa w l) Source # 
Instance details

Defined in Wrench.Isa.Wasm32.Instruction

Methods

byteSize :: Wasm32Isa w l -> Int Source #

CommentStart (Wasm32Isa w l) Source # 
Instance details

Defined in Wrench.Isa.Wasm32.Instruction

IsWord w => MnemonicParser (Wasm32Isa w (Ref w)) Source # 
Instance details

Defined in Wrench.Isa.Wasm32.Instruction

Methods

mnemonic :: Parser (Wasm32Isa w (Ref w)) Source #

wasm32Mnemonics :: [Text] Source #

Every mnemonic the MnemonicParser instance accepts.