toolkit

package
v0.0.0-...-c56c372 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2021 License: Unlicense Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	J2W_LANGUAGE_TYPES = map[string]byte{
		"i32":        0x7f,
		"i64":        0x7e,
		"f32":        0x7d,
		"f64":        0x7c,
		"anyFunc":    0x70,
		"func":       0x60,
		"block_type": 0x40,
	}

	J2W_EXTERNAL_KIND = map[string]byte{
		"function": 0,
		"table":    1,
		"memory":   2,
		"global":   3,
	}

	J2W_SECTION_IDS = map[string]byte{
		"custom":   0,
		"type":     1,
		"import":   2,
		"function": 3,
		"table":    4,
		"memory":   5,
		"global":   6,
		"export":   7,
		"start":    8,
		"element":  9,
		"code":     10,
		"data":     11,
	}

	J2W_OPCODES = map[string]byte{}/* 172 elements not displayed */

)
View Source
var (
	// https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#language-types
	// All types are distinguished by a negative varint7 values that is the first
	// byte of their encoding (representing a type constructor)
	W2J_LANGUAGE_TYPES = map[byte]string{
		0x7f: "i32",
		0x7e: "i64",
		0x7d: "f32",
		0x7c: "f64",
		0x70: "anyFunc",
		0x60: "func",
		0x40: "block_type",
	}

	// https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#external_kind
	// A single-byte unsigned integer indicating the kind of definition being imported or defined:
	W2J_EXTERNAL_KIND = map[byte]string{
		0x00: "function",
		0x01: "table",
		0x02: "memory",
		0x03: "global",
	}

	W2J_OPCODES = map[byte]string{}/* 172 elements not displayed */

	W2J_SECTION_IDS = map[byte]string{
		0:  "custom",
		1:  "type",
		2:  "import",
		3:  "function",
		4:  "table",
		5:  "memory",
		6:  "global",
		7:  "export",
		8:  "start",
		9:  "element",
		10: "code",
		11: "data",
	}
)
View Source
var OP_IMMEDIATES = map[string]string{
	"block":          "block_type",
	"loop":           "block_type",
	"if":             "block_type",
	"br":             "varuint32",
	"br_if":          "varuint32",
	"br_table":       "br_table",
	"call":           "varuint32",
	"call_indirect":  "call_indirect",
	"get_local":      "varuint32",
	"set_local":      "varuint32",
	"tee_local":      "varuint32",
	"get_global":     "varuint32",
	"set_global":     "varuint32",
	"load":           "memory_immediate",
	"load8_s":        "memory_immediate",
	"load8_u":        "memory_immediate",
	"load16_s":       "memory_immediate",
	"load16_u":       "memory_immediate",
	"load32_s":       "memory_immediate",
	"load32_u":       "memory_immediate",
	"store":          "memory_immediate",
	"store8":         "memory_immediate",
	"store16":        "memory_immediate",
	"store32":        "memory_immediate",
	"current_memory": "varuint1",
	"grow_memory":    "varuint1",
	"i32":            "varint32",
	"i64":            "varint64",
	"f32":            "uint32",
	"f64":            "uint64",
}

Functions

func DecodeSLEB128

func DecodeSLEB128(stream *Stream) (s int64)

DecodeSLEB128 decodes bytes from stream with signed LEB128 encoding.

func DecodeULEB128

func DecodeULEB128(stream *Stream) (u uint64)

DecodeULEB128 decodes bytes from stream with unsigned LEB128 encoding.

func EncodeSLEB128

func EncodeSLEB128(v int64, stream *Stream) (out []byte)

EncodeSLEB128 appends v to b using signed LEB128 encoding.

func EncodeULEB128

func EncodeULEB128(v uint64, stream *Stream) (out []byte)

EncodeULEB128 appends v to b using unsigned LEB128 encoding.

func Interface2Bytes

func Interface2Bytes(arr interface{}) (out []byte)

func Json2Wasm

func Json2Wasm(j []JSON) []byte

Json2Wasm converts a JSON array to wasm binary.

func Lcfirst

func Lcfirst(str string) string

Camel-Case to underline

func Ucfirst

func Ucfirst(str string) string

underline to Camel-Case

Types

type CodeBody

type CodeBody struct {
	Locals []LocalEntry `json:"locals"`
	Code   []OP         `json:"code"`
}

type CodeSec

type CodeSec struct {
	Name    string     `json:"name,omitempty"`
	Entries []CodeBody `json:"entries"`
}

type CustomSec

type CustomSec struct {
	Name        string `json:"name,omitempty"`
	SectionName string `json:"section_name,omitempty"`
	Payload     string `json:"payload,omitempty"`
}

Section data structures.

type DataSec

type DataSec struct {
	Name    string        `json:"name,omitempty"`
	Entries []DataSegment `json:"entries"`
}

type DataSegment

type DataSegment struct {
	Index  uint32 `json:"index,omitempty"`
	Offset OP     `json:"offset,omitempty"`
	Data   []byte `json:"data"`
}

type ElementEntry

type ElementEntry struct {
	Index    uint32   `json:"index,omitempty"`
	Offset   OP       `json:"offset,omitempty"`
	Elements []uint64 `json:"elements"`
}

type ElementSec

type ElementSec struct {
	Name    string         `json:"name,omitempty"`
	Entries []ElementEntry `json:"entries"`
}

type ExportEntry

type ExportEntry struct {
	FieldStr string `json:"field_str,omitempty"`
	Kind     string `json:"kind,omitempty"`
	Index    uint32 `json:"index,omitempty"`
}

type ExportSec

type ExportSec struct {
	Name    string        `json:"name,omitempty"`
	Entries []ExportEntry `json:"entries"`
}

type FuncSec

type FuncSec struct {
	Name    string   `json:"name,omitempty"`
	Entries []uint64 `json:"entries"`
}

type Global

type Global struct {
	ContentType string `json:"content_type,omitempty"`
	Mutability  byte   `json:"mutability,omitempty"`
}

type GlobalEntry

type GlobalEntry struct {
	Type Global `json:"type,omitempty"`
	Init OP     `json:"init,omitempty"`
}

type GlobalSec

type GlobalSec struct {
	Name    string        `json:"name,omitempty"`
	Entries []GlobalEntry `json:"entries"`
}

type ImportEntry

type ImportEntry struct {
	ModuleStr string      `json:"module_str,omitempty"`
	FieldStr  string      `json:"field_str,omitempty"`
	Kind      string      `json:"kind,omitempty"`
	Type      interface{} `json:"type,omitempty"`
}

type ImportSec

type ImportSec struct {
	Name    string        `json:"name,omitempty"`
	Entries []ImportEntry `json:"entries"`
}

type JSON

type JSON = map[string]interface{}

func ParsePreramble

func ParsePreramble(stream *Stream) JSON

func ReadFromFile

func ReadFromFile(path string) JSON

func Text2Json

func Text2Json(text string) (res []JSON)

func Wasm2Json

func Wasm2Json(buf []byte) []JSON

Wasm2Json convert the wasm binary to a JSON array output.

type LocalEntry

type LocalEntry struct {
	Count uint32 `json:"count,omitempty"`
	Type  string `json:"type,omitempty"`
}

type MemLimits

type MemLimits struct {
	Flags   uint64      `json:"flags,omitempty"`
	Intial  uint64      `json:"intial,omitempty"`
	Maximum interface{} `json:"maximum,omitempty"` // to distinguish the field is nil or uint64(0)
}

type MemSec

type MemSec struct {
	Name    string      `json:"name,omitempty"`
	Entries []MemLimits `json:"entries"`
}

type OP

type OP struct {
	Name       string      `json:"name,omitempty"`
	ReturnType string      `json:"return_type,omitempty"`
	Type       string      `json:"type,omitempty"`
	Immediates interface{} `json:"immediates,omitempty"`
}

func ParseOp

func ParseOp(stream *Stream) OP

type SectionHeader

type SectionHeader struct {
	Id   byte   `json:"id,omitempty"`
	Name string `json:"name,omitempty"`
	Size uint64 `json:"size,omitempty"`
}

func ParseSectionHeader

func ParseSectionHeader(stream *Stream) SectionHeader

type StartSec

type StartSec struct {
	Name  string `json:"name,omitempty"`
	Index uint32 `json:"index,omitempty"`
}

type Stream

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

func GenerateOP

func GenerateOP(op OP, stream *Stream) *Stream

func GeneratePreramble

func GeneratePreramble(j JSON, stream *Stream) *Stream

func GenerateSection

func GenerateSection(j JSON, stream *Stream) *Stream

func NewStream

func NewStream(buf []byte) *Stream

func (*Stream) Bytes

func (s *Stream) Bytes() []byte

func (*Stream) Len

func (s *Stream) Len() int

Len returns the number of bytes of the unread portion of the buffer;

func (*Stream) Read

func (s *Stream) Read(n int) []byte

Read returns a slice containing the next n bytes from the buffer.

func (*Stream) ReadByte

func (s *Stream) ReadByte() byte

ReadBytes reads and returns the next byte from the buffer.

func (*Stream) String

func (s *Stream) String() string

func (*Stream) Write

func (s *Stream) Write(buf []byte) (n int, err error)

func (*Stream) WriteByte

func (s *Stream) WriteByte(c byte) error

type Table

type Table struct {
	ElementType string    `json:"element_type,omitempty"`
	Limits      MemLimits `json:"limits,omitempty"`
}

type TableSec

type TableSec struct {
	Name    string  `json:"name,omitempty"`
	Entries []Table `json:"entries"`
}

type TypeEntry

type TypeEntry struct {
	Form       string   `json:"form,omitempty"`
	Params     []string `json:"params"`
	ReturnType string   `json:"return_type,omitempty"`
}

type TypeSec

type TypeSec struct {
	Name    string      `json:"name,omitempty"`
	Entries []TypeEntry `json:"entries"`
}

Jump to

Keyboard shortcuts

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