codegen

package
v0.3.4-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SecType     byte = 1
	SecImports  byte = 2
	SecFunction byte = 3
	SecExport   byte = 7
	SecCode     byte = 10
)

IDs for different sections of WASM binaries

View Source
const (
	LocalTypeI32 byte = 0x7F
	LocalTypeF32 byte = 0x7D
)

IDs for different type IDs when creating locals

View Source
const (
	OpCodeBlock        byte = 0x02
	OpCodeLoop         byte = 0x03
	OpCodeEnd          byte = 0x0B
	OpCodeReturn       byte = 0x0F
	OpCodeCallFunction byte = 0x10
	OpCodeIf           byte = 0x04
	OpCodeElse         byte = 0x05
	OpCodeBrIf         byte = 0x0D
	OpCodeBr           byte = 0x0C

	OpCodeDrop byte = 0x1A

	OpCodeLocalGet byte = 0x20
	OpCodeLocalSet byte = 0x21
	OpCodeLocalTee byte = 0x22

	OpCodeI32Const                  byte = 0x41
	OpCodeI32Add                    byte = 0x6A
	OpCodeI32Sub                    byte = 0x6B
	OpCodeI32Mul                    byte = 0x6C
	OpCodeI32SignedDivision         byte = 0x6D
	OpCodeI32And                    byte = 0x71
	OpCodeI32EqualsZero             byte = 0x45
	OpCodeI32Eq                     byte = 0x46
	OpCodeI32NotEq                  byte = 0x47
	OpCodeI32LessThanSigned         byte = 0x48
	OpCodeI32GreaterThanSigned      byte = 0x4A
	OpCodeI32LessThanEqualSigned    byte = 0x4C
	OpCodeI32GreaterThanEqualSigned byte = 0x4E

	OpCodeF32Const            byte = 0x43
	OpCodeF32Neg              byte = 0x8C
	OpCodeF32Add              byte = 0x92
	OpCodeF32Sub              byte = 0x93
	OpCodeF32Mul              byte = 0x94
	OpCodeF32Division         byte = 0x95
	OpCodeF32Eq               byte = 0x5B
	OpCodeF32NotEq            byte = 0x5C
	OpCodeF32LessThan         byte = 0x5D
	OpCodeF32GreaterThan      byte = 0x5E
	OpCodeF32LessThanEqual    byte = 0x5F
	OpCodeF32GreaterThanEqual byte = 0x60
)

WASM instructions

Variables

This section is empty.

Functions

func EncodeF32

func EncodeF32(f float32) []byte

EncodeF32 converts a float32 to its 4-byte little-endian representation

func EncodeSLEB128

func EncodeSLEB128(n int32) []byte

Encodes signed integers to Little Endian Binary 128-bit format

func EncodeULEB128

func EncodeULEB128(n uint32) []byte

Encodes unsigned integers to Little Endian Binary 128-bit format

Types

type WASMModule

type WASMModule struct {
	// contains filtered or unexported fields
}

Represents an assembled WASM program

func NewModule

func NewModule(program *ast.Program) *WASMModule

func (*WASMModule) Generate

func (m *WASMModule) Generate() error

Generates the final WASM binary

func (*WASMModule) Save

func (m *WASMModule) Save(filename string) error

Saves the WASM binary to a file on disk

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL