Skip to content

Commit 9a015f4

Browse files
author
Takeshi Yoneda
authored
add wasm-abi field in TargetSpec && set generic for WASI by default (#1421)
Signed-off-by: mathetake <[email protected]>
1 parent 9ad2315 commit 9a015f4

File tree

7 files changed

+17
-9
lines changed

7 files changed

+17
-9
lines changed

builder/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil
7979
// keep functions interoperable, pass int64 types as pointers to
8080
// stack-allocated values.
8181
// Use -wasm-abi=generic to disable this behaviour.
82-
if config.Options.WasmAbi == "js" && strings.HasPrefix(config.Triple(), "wasm") {
82+
if config.WasmAbi() == "js" {
8383
err := transform.ExternalInt64AsPtr(mod)
8484
if err != nil {
8585
return err

compileopts/config.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,15 @@ func (c *Config) RelocationModel() string {
329329
return "static"
330330
}
331331

332+
// WasmAbi returns the WASM ABI which is specified in the target JSON file, and
333+
// the value is overridden by `-wasm-abi` flag if it is provided
334+
func (c *Config) WasmAbi() string {
335+
if c.Options.WasmAbi != "" {
336+
return c.Options.WasmAbi
337+
}
338+
return c.Target.WasmAbi
339+
}
340+
332341
type TestConfig struct {
333342
CompileTestBinary bool
334343
// TODO: Filter the test functions to run, include verbose flag, etc

compileopts/target.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ type TargetSpec struct {
5555
JLinkDevice string `json:"jlink-device"`
5656
CodeModel string `json:"code-model"`
5757
RelocationModel string `json:"relocation-model"`
58+
WasmAbi string `json:"wasm-abi"`
5859
}
5960

6061
// overrideProperties overrides all properties that are set in child into itself using reflection.

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,7 +828,7 @@ func main() {
828828
programmer := flag.String("programmer", "", "which hardware programmer to use")
829829
cFlags := flag.String("cflags", "", "additional cflags for compiler")
830830
ldFlags := flag.String("ldflags", "", "additional ldflags for linker")
831-
wasmAbi := flag.String("wasm-abi", "js", "WebAssembly ABI conventions: js (no i64 params) or generic")
831+
wasmAbi := flag.String("wasm-abi", "", "WebAssembly ABI conventions: js (no i64 params) or generic")
832832
heapSize := flag.String("heap-size", "1M", "default heap size in bytes (only supported by WebAssembly)")
833833

834834
var flagJSON, flagDeps *bool

main_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,7 @@ func runTest(path, target string, t *testing.T) {
165165
VerifyIR: true,
166166
Debug: true,
167167
PrintSizes: "",
168-
WasmAbi: "js",
169-
}
170-
171-
if target == "wasi" {
172-
config.WasmAbi = "generic"
168+
WasmAbi: "",
173169
}
174170

175171
binary := filepath.Join(tmpdir, "test")

targets/wasi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
"--no-demangle",
1919
"{root}/lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a"
2020
],
21-
"emulator": ["wasmtime"]
21+
"emulator": ["wasmtime"],
22+
"wasm-abi": "generic"
2223
}

targets/wasm.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@
1717
"--no-demangle",
1818
"{root}/lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a"
1919
],
20-
"emulator": ["node", "targets/wasm_exec.js"]
20+
"emulator": ["node", "targets/wasm_exec.js"],
21+
"wasm-abi": "js"
2122
}

0 commit comments

Comments
 (0)