-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_section.go
More file actions
executable file
·49 lines (40 loc) · 1.04 KB
/
function_section.go
File metadata and controls
executable file
·49 lines (40 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package wax
import (
"bytes"
)
/*
Function section
The function section has the id 3.
It decodes into a vector of type indices that represent the 𝗍𝗒𝗉𝖾 fields of the functions in the 𝖿𝗎𝗇𝖼𝗌 component of a module.
The locals and body fields of the respective functions are encoded separately in the code section.
funcsec ::= x*:section_3(vec(typeidx)) => x*
*/
type FunctionSection struct {
SectionBase
Types []TypeIdx
}
func ParseFunctionSection(ber *BinaryEncodingReader, id SectionID) (*FunctionSection, error) {
sb, err := ParseSectionBase(ber, id)
if err != nil {
return nil, err
}
cr := NewBinaryEncodingReader(bytes.NewReader(sb.Content))
// Read Count
count64, _, err := cr.ReadVaruint()
if err != nil {
return nil, err
}
count := uint32(count64)
types := make([]TypeIdx, 0, count)
for i := uint32(0); i < count; i++ {
t, _, err := cr.ReadVaruint()
if err != nil {
return nil, err
}
types = append(types, TypeIdx(t))
}
return &FunctionSection{
SectionBase: *sb,
Types: types,
}, nil
}