-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
81 lines (62 loc) · 1.4 KB
/
main.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"fmt"
"os"
"github.com/loopholelabs/wasm-toolkit/pkg/wasm/debug"
"github.com/loopholelabs/wasm-toolkit/pkg/wasm/wasmfile"
)
func main() {
args := os.Args[1:]
wasmfilename := args[0] // For now...
fmt.Printf("Loading up wasm file %s\n", wasmfilename)
wfile, err := wasmfile.New(wasmfilename)
if err != nil {
panic(err)
}
wfile.Debug = &debug.WasmDebug{}
fmt.Printf("Parsing custom name section...\n")
wfile.Debug.ParseNameSectionData(wfile.GetCustomSectionData("name"))
fmt.Printf("Parsing custom dwarf debug sections...\n")
err = wfile.Debug.ParseDwarf(wfile)
if err != nil {
panic(err)
}
fmt.Printf("Parsing dwarf line numbers...\n")
err = wfile.Debug.ParseDwarfLineNumbers()
if err != nil {
panic(err)
}
fmt.Printf("Parsing dwarf local variables...\n")
err = wfile.Debug.ParseDwarfVariables(wfile)
if err != nil {
panic(err)
}
outputWasm := "output.wasm"
outputWat := "output.wat"
fmt.Printf("Writing wasm out to %s...\n", outputWasm)
f, err := os.Create(outputWasm)
if err != nil {
panic(err)
}
err = wfile.EncodeBinary(f)
if err != nil {
panic(err)
}
err = f.Close()
if err != nil {
panic(err)
}
fmt.Printf("Writing wat out to %s...\n", outputWat)
watf, err := os.Create(outputWat)
if err != nil {
panic(err)
}
err = wfile.EncodeWat(watf)
if err != nil {
panic(err)
}
err = watf.Close()
if err != nil {
panic(err)
}
}