mirror of
https://github.com/wader/fq.git
synced 2024-12-23 05:13:30 +03:00
wasm: make the godoc formatter happy
This commit is contained in:
parent
d5d9e738b6
commit
e5cf1731e3
@ -24,7 +24,9 @@ func decodeMemArg(d *decode.D, name string) {
|
||||
})
|
||||
}
|
||||
|
||||
// expr ::= (in:instr)* 0x0B => in* end
|
||||
// Decode expr.
|
||||
//
|
||||
// expr ::= (in:instr)* 0x0B => in* end
|
||||
func decodeExpr(d *decode.D, name string) {
|
||||
d.FieldArray(name, func(d *decode.D) {
|
||||
for {
|
||||
|
@ -20,19 +20,21 @@ var sectionIDToSym = scalar.UToSymStr{
|
||||
sectionIDDataCount: "data_count_section",
|
||||
}
|
||||
|
||||
// valtype ::= t:numtype => t
|
||||
// | t:vectype => t
|
||||
// | t:reftype => t
|
||||
// A map to convert valtypes to symbols.
|
||||
//
|
||||
// numtype ::= 0x7F => i32
|
||||
// | 0x7E => i64
|
||||
// | 0x7D => f32
|
||||
// | 0x7C => f64
|
||||
// valtype ::= t:numtype => t
|
||||
// | t:vectype => t
|
||||
// | t:reftype => t
|
||||
//
|
||||
// vectype ::= 0x7B => v128
|
||||
// numtype ::= 0x7F => i32
|
||||
// | 0x7E => i64
|
||||
// | 0x7D => f32
|
||||
// | 0x7C => f64
|
||||
//
|
||||
// reftype ::= 0x70 => funcref
|
||||
// | 0x6F => externref
|
||||
// vectype ::= 0x7B => v128
|
||||
//
|
||||
// reftype ::= 0x70 => funcref
|
||||
// | 0x6F => externref
|
||||
var valtypeToSymMapper = scalar.UToSymStr{
|
||||
0x7f: "i32",
|
||||
0x7e: "i64",
|
||||
@ -43,10 +45,12 @@ var valtypeToSymMapper = scalar.UToSymStr{
|
||||
0x6f: "externref",
|
||||
}
|
||||
|
||||
// importdesc ::= 0x00 x:typeidx => func x
|
||||
// | 0x01 tt:tabletype => table tt
|
||||
// | 0x02 mt:memtype => mem mt
|
||||
// | 0x03 gt:globaltype => global gt
|
||||
// A map to convert tags of importdesc to symbols.
|
||||
//
|
||||
// importdesc ::= 0x00 x:typeidx => func x
|
||||
// | 0x01 tt:tabletype => table tt
|
||||
// | 0x02 mt:memtype => mem mt
|
||||
// | 0x03 gt:globaltype => global gt
|
||||
var importdescTagToSym = scalar.UToSymStr{
|
||||
0x00: "func",
|
||||
0x01: "table",
|
||||
@ -54,10 +58,12 @@ var importdescTagToSym = scalar.UToSymStr{
|
||||
0x03: "global",
|
||||
}
|
||||
|
||||
// exportdesc ::= 0x00 x:funcidx => func x
|
||||
// | 0x01 x:tableidx => table x
|
||||
// | 0x02 x:memidx => mem x
|
||||
// | 0x03 x:globalidx => global x
|
||||
// A map to convert tags of exportdesc to symbols.
|
||||
//
|
||||
// exportdesc ::= 0x00 x:funcidx => func x
|
||||
// | 0x01 x:tableidx => table x
|
||||
// | 0x02 x:memidx => mem x
|
||||
// | 0x03 x:globalidx => global x
|
||||
var exportdescTagToSym = scalar.UToSymStr{
|
||||
0x00: "funcidx",
|
||||
0x01: "tableidx",
|
||||
@ -65,21 +71,27 @@ var exportdescTagToSym = scalar.UToSymStr{
|
||||
0x03: "globalidx",
|
||||
}
|
||||
|
||||
// reftype ::= 0x70 => funcref
|
||||
// | 0x6F => externref
|
||||
// A map to convert reftypes to symbols.
|
||||
//
|
||||
// reftype ::= 0x70 => funcref
|
||||
// | 0x6F => externref
|
||||
var reftypeTagToSym = scalar.UToSymStr{
|
||||
0x70: "funcref",
|
||||
0x6f: "externref",
|
||||
}
|
||||
|
||||
// mut ::= 0x00 => const
|
||||
// | 0x01 => var
|
||||
// A map to convert mut to symbols.
|
||||
//
|
||||
// mut ::= 0x00 => const
|
||||
// | 0x01 => var
|
||||
var mutToSym = scalar.UToSymStr{
|
||||
0x00: "const",
|
||||
0x01: "var",
|
||||
}
|
||||
|
||||
// elemkind ::= 0x00 => funcref
|
||||
// A map to convert elemkind to symbols.
|
||||
//
|
||||
// elemkind ::= 0x00 => funcref
|
||||
var elemkindTagToSym = scalar.UToSymStr{
|
||||
0x00: "funcref",
|
||||
}
|
||||
|
@ -79,28 +79,36 @@ func decodeName(d *decode.D, name string) {
|
||||
})
|
||||
}
|
||||
|
||||
// reftype ::= 0x70 => funcref
|
||||
// | 0x6F => externref
|
||||
// Decode reftype.
|
||||
//
|
||||
// reftype ::= 0x70 => funcref
|
||||
// | 0x6F => externref
|
||||
func decodeRefType(d *decode.D, name string) {
|
||||
d.FieldU8(name, reftypeTagToSym)
|
||||
}
|
||||
|
||||
// valtype ::= t:numtype => t
|
||||
// | t:vectype => t
|
||||
// | t:reftype => t
|
||||
// Decode valtype.
|
||||
//
|
||||
// valtype ::= t:numtype => t
|
||||
// | t:vectype => t
|
||||
// | t:reftype => t
|
||||
//nolint:unparam
|
||||
func decodeValType(d *decode.D, name string) {
|
||||
d.FieldU8(name, valtypeToSymMapper, scalar.ActualHex)
|
||||
}
|
||||
|
||||
// resulttype ::= t*:vec(valtype) => [t*]
|
||||
// Decode resulttype.
|
||||
//
|
||||
// resulttype ::= t*:vec(valtype) => [t*]
|
||||
func decodeResultType(d *decode.D, name string) {
|
||||
decodeVec(d, name, func(d *decode.D) {
|
||||
decodeValType(d, "t")
|
||||
})
|
||||
}
|
||||
|
||||
// functype ::= 0x60 rt1:resulttype rt2:resulttype => rt1 -> rt2
|
||||
// Decode functype.
|
||||
//
|
||||
// functype ::= 0x60 rt1:resulttype rt2:resulttype => rt1 -> rt2
|
||||
func decodeFuncType(d *decode.D, name string) {
|
||||
d.FieldStruct(name, func(d *decode.D) {
|
||||
d.FieldU8("tag", d.AssertU(0x60), scalar.ActualHex)
|
||||
@ -109,8 +117,10 @@ func decodeFuncType(d *decode.D, name string) {
|
||||
})
|
||||
}
|
||||
|
||||
// limits ::= 0x00 n:u32 => {min: n, max: ε}
|
||||
// | 0x01 n:u32 m:u32 => {min: n, max: m}
|
||||
// Decode limits.
|
||||
//
|
||||
// limits ::= 0x00 n:u32 => {min: n, max: ε}
|
||||
// | 0x01 n:u32 m:u32 => {min: n, max: m}
|
||||
func decodeLimits(d *decode.D, name string) {
|
||||
d.FieldStruct(name, func(d *decode.D) {
|
||||
tag := d.FieldU8("tag", scalar.ActualHex)
|
||||
@ -126,14 +136,18 @@ func decodeLimits(d *decode.D, name string) {
|
||||
})
|
||||
}
|
||||
|
||||
// memtype ::= lim:limits => lim
|
||||
// Decode memtype.
|
||||
//
|
||||
// memtype ::= lim:limits => lim
|
||||
func decodeMemType(d *decode.D, name string) {
|
||||
d.FieldStruct(name, func(d *decode.D) {
|
||||
decodeLimits(d, "lim")
|
||||
})
|
||||
}
|
||||
|
||||
// tabletype ::= et:reftype lim:limits => lim et
|
||||
// Decode tabletype.
|
||||
//
|
||||
// tabletype ::= et:reftype lim:limits => lim et
|
||||
func decodeTableType(d *decode.D, name string) {
|
||||
d.FieldStruct(name, func(d *decode.D) {
|
||||
decodeRefType(d, "et")
|
||||
@ -141,9 +155,11 @@ func decodeTableType(d *decode.D, name string) {
|
||||
})
|
||||
}
|
||||
|
||||
// globaltype ::= t:valtype m:mut => m t
|
||||
// mut ::= 0x00 => const
|
||||
// | 0x01 => var
|
||||
// Decode globaltype.
|
||||
//
|
||||
// globaltype ::= t:valtype m:mut => m t
|
||||
// mut ::= 0x00 => const
|
||||
// | 0x01 => var
|
||||
func decodeGlobalType(d *decode.D, name string) {
|
||||
d.FieldStruct(name, func(d *decode.D) {
|
||||
decodeValType(d, "t")
|
||||
@ -151,71 +167,95 @@ func decodeGlobalType(d *decode.D, name string) {
|
||||
})
|
||||
}
|
||||
|
||||
// typeidx ::= x:u32 => x
|
||||
// Decode typeidx.
|
||||
//
|
||||
// typeidx ::= x:u32 => x
|
||||
func decodeTypeIdx(d *decode.D, name string) {
|
||||
fieldU32(d, name)
|
||||
}
|
||||
|
||||
// funcidx ::= x:u32 => x
|
||||
// Decode funcidx.
|
||||
//
|
||||
// funcidx ::= x:u32 => x
|
||||
func decodeFuncIdx(d *decode.D, name string) {
|
||||
fieldU32(d, name)
|
||||
}
|
||||
|
||||
// tableidx ::= x:u32 => x
|
||||
// Decode tableidx.
|
||||
//
|
||||
// tableidx ::= x:u32 => x
|
||||
func decodeTableIdx(d *decode.D, name string) {
|
||||
fieldU32(d, name)
|
||||
}
|
||||
|
||||
// memidx ::= x:u32 => x
|
||||
// Decode memidx.
|
||||
//
|
||||
// memidx ::= x:u32 => x
|
||||
func decodeMemIdx(d *decode.D, name string) {
|
||||
fieldU32(d, name)
|
||||
}
|
||||
|
||||
// globalidx ::= x:u32 => x
|
||||
// Decode globalidx.
|
||||
//
|
||||
// globalidx ::= x:u32 => x
|
||||
func decodeGlobalIdx(d *decode.D, name string) {
|
||||
fieldU32(d, name)
|
||||
}
|
||||
|
||||
// elemidx ::= x:u32 => x
|
||||
// Decode elemidx.
|
||||
//
|
||||
// elemidx ::= x:u32 => x
|
||||
func decodeElemIdx(d *decode.D, name string) {
|
||||
fieldU32(d, name)
|
||||
}
|
||||
|
||||
// dataidx ::= x:u32 => x
|
||||
// Decode dataidx.
|
||||
//
|
||||
// dataidx ::= x:u32 => x
|
||||
func decodeDataIdx(d *decode.D, name string) {
|
||||
fieldU32(d, name)
|
||||
}
|
||||
|
||||
// localidx ::= x:u32 => x
|
||||
// Decode localidx.
|
||||
//
|
||||
// localidx ::= x:u32 => x
|
||||
func decodeLocalIdx(d *decode.D, name string) {
|
||||
fieldU32(d, name)
|
||||
}
|
||||
|
||||
// labelidx ::= l:u32 => l
|
||||
// Decode labelidx.
|
||||
//
|
||||
// labelidx ::= l:u32 => l
|
||||
func decodeLabelIdx(d *decode.D, name string) {
|
||||
fieldU32(d, name)
|
||||
}
|
||||
|
||||
// customsec ::= section_0(custom)
|
||||
// custom ::= name byte*
|
||||
// Decode custom section.
|
||||
//
|
||||
// customsec ::= section_0(custom)
|
||||
// custom ::= name byte*
|
||||
func decodeCustomSection(d *decode.D) {
|
||||
decodeName(d, "name")
|
||||
d.FieldRawLen("bytes", d.BitsLeft())
|
||||
}
|
||||
|
||||
// typesec ::= ft*:section_1(vec(functype)) => ft*
|
||||
// Decode type section.
|
||||
//
|
||||
// typesec ::= ft*:section_1(vec(functype)) => ft*
|
||||
func decodeTypeSection(d *decode.D) {
|
||||
decodeVec(d, "ft", func(d *decode.D) {
|
||||
decodeFuncType(d, "ft")
|
||||
})
|
||||
}
|
||||
|
||||
// importsec ::= im*:section_2(vec(import)) => im*
|
||||
// import ::= mod:name nm:name d:importdesc => {module mod, name nm, desc d}
|
||||
// importdesc ::= 0x00 x:typeidx => func x
|
||||
// | 0x01 tt:tabletype => table tt
|
||||
// | 0x02 mt:memtype => mem mt
|
||||
// | 0x03 gt:globaltype => global gt
|
||||
// Decode import section.
|
||||
//
|
||||
// importsec ::= im*:section_2(vec(import)) => im*
|
||||
// import ::= mod:name nm:name d:importdesc => {module mod, name nm, desc d}
|
||||
// importdesc ::= 0x00 x:typeidx => func x
|
||||
// | 0x01 tt:tabletype => table tt
|
||||
// | 0x02 mt:memtype => mem mt
|
||||
// | 0x03 gt:globaltype => global gt
|
||||
func decodeImportSection(d *decode.D) {
|
||||
decodeVec(d, "im", func(d *decode.D) {
|
||||
decodeImportSegment(d, "im")
|
||||
@ -248,31 +288,39 @@ func decodeImportDesc(d *decode.D, name string) {
|
||||
})
|
||||
}
|
||||
|
||||
// funcsec ::= x*:section_3(vec(typeidx)) => x*
|
||||
// Decode function section.
|
||||
//
|
||||
// funcsec ::= x*:section_3(vec(typeidx)) => x*
|
||||
func decodeFunctionSection(d *decode.D) {
|
||||
decodeVec(d, "x", func(d *decode.D) {
|
||||
decodeTypeIdx(d, "x")
|
||||
})
|
||||
}
|
||||
|
||||
// tablesec ::= tab*:section_4(vec(table)) => tab*
|
||||
// table ::= tt:tabletype => {type tt}
|
||||
// Decode table section.
|
||||
//
|
||||
// tablesec ::= tab*:section_4(vec(table)) => tab*
|
||||
// table ::= tt:tabletype => {type tt}
|
||||
func decodeTableSection(d *decode.D) {
|
||||
decodeVec(d, "tab", func(d *decode.D) {
|
||||
decodeTableType(d, "tab")
|
||||
})
|
||||
}
|
||||
|
||||
// memsec ::= mem*:section_5(vec(mem)) => mem*
|
||||
// mem ::= mt:memtype => {type mt}
|
||||
// Decode memory section.
|
||||
//
|
||||
// memsec ::= mem*:section_5(vec(mem)) => mem*
|
||||
// mem ::= mt:memtype => {type mt}
|
||||
func decodeMemorySection(d *decode.D) {
|
||||
decodeVec(d, "mem", func(d *decode.D) {
|
||||
decodeMemType(d, "mem")
|
||||
})
|
||||
}
|
||||
|
||||
// globalsec ::= glob*:section_6(vec(global)) => glob*
|
||||
// global ::= gt:globaltype e:expr => {type gt, init e}
|
||||
// Decode global section.
|
||||
//
|
||||
// globalsec ::= glob*:section_6(vec(global)) => glob*
|
||||
// global ::= gt:globaltype e:expr => {type gt, init e}
|
||||
func decodeGlobalSection(d *decode.D) {
|
||||
decodeVec(d, "glob", func(d *decode.D) {
|
||||
decodeGlobal(d, "glob")
|
||||
@ -286,12 +334,14 @@ func decodeGlobal(d *decode.D, name string) {
|
||||
})
|
||||
}
|
||||
|
||||
// exportsec ::= ex*:section_7(vec(export)) => ex*
|
||||
// export ::= nm:name d:exportdesc => {name nm, desc d}
|
||||
// exportdesc ::= 0x00 x:funcidx => func x
|
||||
// | 0x01 x:tableidx => table x
|
||||
// | 0x02 x:memidx => mem x
|
||||
// | 0x03 x:globalidx => global x
|
||||
// Decode export section.
|
||||
//
|
||||
// exportsec ::= ex*:section_7(vec(export)) => ex*
|
||||
// export ::= nm:name d:exportdesc => {name nm, desc d}
|
||||
// exportdesc ::= 0x00 x:funcidx => func x
|
||||
// | 0x01 x:tableidx => table x
|
||||
// | 0x02 x:memidx => mem x
|
||||
// | 0x03 x:globalidx => global x
|
||||
func decodeExportSection(d *decode.D) {
|
||||
decodeVec(d, "ex", func(d *decode.D) {
|
||||
decodeExport(d, "ex")
|
||||
@ -323,8 +373,10 @@ func decodeExportDesc(d *decode.D, name string) {
|
||||
})
|
||||
}
|
||||
|
||||
// startsec ::= st?:section_8(start) => st?
|
||||
// start ::= x:funcidx => {func x}
|
||||
// Decode start section.
|
||||
//
|
||||
// startsec ::= st?:section_8(start) => st?
|
||||
// start ::= x:funcidx => {func x}
|
||||
func decodeStartSection(d *decode.D) {
|
||||
decodeStart(d, "st")
|
||||
}
|
||||
@ -335,15 +387,17 @@ func decodeStart(d *decode.D, name string) {
|
||||
})
|
||||
}
|
||||
|
||||
// elemsec ::= seg*:section_9(vec(elem)) => seg*
|
||||
// elem ::= 0:u32 e:expr y*:vec(funcidx) => {type funcref, init ((ref.func y) end)*, mode active {table 0, offset e}}
|
||||
// | 1:u32 et:elemkind y*:vec(funcidx) => {type et, init ((ref.func y) end)*, mode passive}
|
||||
// | 2:u32 x:tableidx e:expr et:elemkind y*:vec(funcidx) => {type et, init ((ref.func y) end)*, mode active {table x, offset e}}
|
||||
// | 3:u32 et:elemkind y*:vec(funcidx) => {type et, init ((ref.func y) end)*, mode declarative}
|
||||
// | 4:u32 e:expr el*:vec(expr) => {type funcref, init el*, mode active {table 0, offset e}}
|
||||
// | 5:u32 et:reftype el*:vec(expr) => {type et, init el*, mode passive}
|
||||
// | 6:u32 x:tableidx e:expr et:reftype el*:vec(expr) => {type et, init el*, mode active {table x, offset e}}
|
||||
// | 7:u32 et:reftype el*:vec(expr) => {type et, init el*, mode declarative}
|
||||
// Decode element section.
|
||||
//
|
||||
// elemsec ::= seg*:section_9(vec(elem)) => seg*
|
||||
// elem ::= 0:u32 e:expr y*:vec(funcidx) => {type funcref, init ((ref.func y) end)*, mode active {table 0, offset e}}
|
||||
// | 1:u32 et:elemkind y*:vec(funcidx) => {type et, init ((ref.func y) end)*, mode passive}
|
||||
// | 2:u32 x:tableidx e:expr et:elemkind y*:vec(funcidx) => {type et, init ((ref.func y) end)*, mode active {table x, offset e}}
|
||||
// | 3:u32 et:elemkind y*:vec(funcidx) => {type et, init ((ref.func y) end)*, mode declarative}
|
||||
// | 4:u32 e:expr el*:vec(expr) => {type funcref, init el*, mode active {table 0, offset e}}
|
||||
// | 5:u32 et:reftype el*:vec(expr) => {type et, init el*, mode passive}
|
||||
// | 6:u32 x:tableidx e:expr et:reftype el*:vec(expr) => {type et, init el*, mode active {table x, offset e}}
|
||||
// | 7:u32 et:reftype el*:vec(expr) => {type et, init el*, mode declarative}
|
||||
func decodeElementSection(d *decode.D) {
|
||||
decodeVec(d, "seg", func(d *decode.D) {
|
||||
decodeElem(d, "seg")
|
||||
@ -398,10 +452,12 @@ func decodeElemKind(d *decode.D, name string) {
|
||||
d.FieldU8(name, d.AssertU(0x00), elemkindTagToSym)
|
||||
}
|
||||
|
||||
// codesec ::= code*:section_10(vec(code)) => code*
|
||||
// code ::= size:u32 code:func => code (if size = ||func||)
|
||||
// func ::= (t*)*:vec(locals) e:expr => concat((t*)*),e (if |concat((t*)*)| < 2^32)
|
||||
// locals ::= n:u32 t:valtype => t^n
|
||||
// Decode code section.
|
||||
//
|
||||
// codesec ::= code*:section_10(vec(code)) => code*
|
||||
// code ::= size:u32 code:func => code (if size = ||func||)
|
||||
// func ::= (t*)*:vec(locals) e:expr => concat((t*)*),e (if |concat((t*)*)| < 2^32)
|
||||
// locals ::= n:u32 t:valtype => t^n
|
||||
func decodeCodeSection(d *decode.D) {
|
||||
decodeVec(d, "code", func(d *decode.D) {
|
||||
decodeCode(d, "code")
|
||||
@ -433,10 +489,12 @@ func decodeLocals(d *decode.D, name string) {
|
||||
})
|
||||
}
|
||||
|
||||
// datasec ::= seg*:section_11(vec(data)) => seg*
|
||||
// data ::= 0:u32 e:expr b*:vec(byte) => {init b*, mode active {memory 0, offset e}}
|
||||
// | 1:u32 b*:vec(byte) => {init b*, mode passive}
|
||||
// | 2:u32 x:memidx e:expr b*:vec(byte) => {init b*, mode active {memory x, offset e}}
|
||||
// Decode data section.
|
||||
//
|
||||
// datasec ::= seg*:section_11(vec(data)) => seg*
|
||||
// data ::= 0:u32 e:expr b*:vec(byte) => {init b*, mode active {memory 0, offset e}}
|
||||
// | 1:u32 b*:vec(byte) => {init b*, mode passive}
|
||||
// | 2:u32 x:memidx e:expr b*:vec(byte) => {init b*, mode active {memory x, offset e}}
|
||||
func decodeDataSection(d *decode.D) {
|
||||
decodeVec(d, "seg", func(d *decode.D) {
|
||||
decodeDataSegment(d, "seg")
|
||||
@ -462,7 +520,9 @@ func decodeDataSegment(d *decode.D, name string) {
|
||||
})
|
||||
}
|
||||
|
||||
// datacountsec ::= n?:section_12(u32) => n?
|
||||
// Decode data count section.
|
||||
//
|
||||
// datacountsec ::= n?:section_12(u32) => n?
|
||||
func decodeDataCountSection(d *decode.D) {
|
||||
fieldU32(d, "n")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user