Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documents structured control instructions #61

Merged
merged 2 commits into from
Nov 29, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions wasm/optcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,25 @@ package wasm
type OptCode = byte

const (
// control instruction
OptCodeUnreachable OptCode = 0x00
OptCodeNop OptCode = 0x01
OptCodeBlock OptCode = 0x02
OptCodeLoop OptCode = 0x03
OptCodeIf OptCode = 0x04
OptCodeElse OptCode = 0x05
// control instructions. See https://www.w3.org/TR/wasm-core-1/#control-instructions

// OptCodeUnreachable causes an unconditional trap.
OptCodeUnreachable OptCode = 0x00
// OptCodeNop does nothing
OptCodeNop OptCode = 0x01
// OptCodeBlock brackets a sequence of instructions. A branch instruction on an if label breaks out to after its
// OptCodeEnd.
OptCodeBlock OptCode = 0x02
// OptCodeLoop brackets a sequence of instructions. A branch instruction on a loop label will jump back to the
// beginning of its block.
OptCodeLoop OptCode = 0x03
// OptCodeIf brackets a sequence of instructions. When the top of the stack evaluates to 1, the block is executed.
// Zero jumps to the optional OptCodeElse. A branch instruction on an if label breaks out to after its OptCodeEnd.
OptCodeIf OptCode = 0x04
// OptCodeElse brackets a sequence of instructions enclosed by an OptCodeIf. A branch instruction on a then label
// breaks out to after the OptCodeEnd on the enclosing OptCodeIf.
OptCodeElse OptCode = 0x05
// OptCodeEnd terminates a control instruction OptCodeBlock, OptCodeLoop or OptCodeIf.
OptCodeEnd OptCode = 0x0b
OptCodeBr OptCode = 0x0c
OptCodeBrIf OptCode = 0x0d
Expand All @@ -18,18 +30,21 @@ const (
OptCodeCall OptCode = 0x10
OptCodeCallIndirect OptCode = 0x11

// parametric instruction
// parametric instructions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra newline ensures this comment isn't mistaken for a godoc on OptCodeDrop

OptCodeDrop OptCode = 0x1a
OptCodeSelect OptCode = 0x1b

// variable instruction
// variable instructions

OptCodeLocalGet OptCode = 0x20
OptCodeLocalSet OptCode = 0x21
OptCodeLocalTee OptCode = 0x22
OptCodeGlobalGet OptCode = 0x23
OptCodeGlobalSet OptCode = 0x24

// memory instruction
// memory instructions

OptCodeI32Load OptCode = 0x28
OptCodeI64Load OptCode = 0x29
OptCodeF32Load OptCode = 0x2a
Expand All @@ -56,13 +71,15 @@ const (
OptCodeMemorySize OptCode = 0x3f
OptCodeMemoryGrow OptCode = 0x40

// const instructions.
// const instructions

OptCodeI32Const OptCode = 0x41
OptCodeI64Const OptCode = 0x42
OptCodeF32Const OptCode = 0x43
OptCodeF64Const OptCode = 0x44

// numeric instructions.
// numeric instructions

OptCodeI32eqz OptCode = 0x45
OptCodeI32eq OptCode = 0x46
OptCodeI32ne OptCode = 0x47
Expand Down