-
Notifications
You must be signed in to change notification settings - Fork 1
/
dump.go
64 lines (52 loc) · 1.1 KB
/
dump.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package mruby
import (
"fmt"
"unsafe"
)
var (
binaryHeaderSize = uint32(unsafe.Sizeof(binaryHeader{}))
sectionHeaderSize = uint32(unsafe.Sizeof(sectionHeader{}))
)
type binaryVersion struct {
Major [2]byte
Minor [2]byte
}
func (v binaryVersion) String() string {
return fmt.Sprintf("%s.%s", v.Major, v.Minor)
}
type binaryCompiler struct {
Name [4]byte
Version [4]byte
}
func (c binaryCompiler) String() string {
return fmt.Sprintf("%s#%s", c.Name, c.Version)
}
type binaryHeader struct {
Identifier [4]byte
Version binaryVersion
Size uint32
Compiler binaryCompiler
}
func (h binaryHeader) String() string {
return fmt.Sprintf(
`#<RITE id="%s" version="%s" size="%d" compiler="%s">`,
h.Identifier,
h.Version,
h.Size,
h.Compiler,
)
}
type sectionType = string
const (
sectionTypeIRep sectionType = "IREP"
sectionTypeDebug sectionType = "DBG\x00"
sectionTypeLv sectionType = "LVAR"
sectionTypeEof sectionType = "EOF\x00"
)
type sectionHeader struct {
Identity [4]byte
Size uint32
}
func (h sectionHeader) String() string {
return string(h.Identity[:])
}