From 9a015f4f6441fd68eabe35b3dc9748a5467d5934 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Sun, 4 Oct 2020 02:52:01 +0900 Subject: [PATCH] add wasm-abi field in TargetSpec && set generic for WASI by default (#1421) Signed-off-by: mathetake --- builder/build.go | 2 +- compileopts/config.go | 9 +++++++++ compileopts/target.go | 1 + main.go | 2 +- main_test.go | 6 +----- targets/wasi.json | 3 ++- targets/wasm.json | 3 ++- 7 files changed, 17 insertions(+), 9 deletions(-) diff --git a/builder/build.go b/builder/build.go index 67c09df0..aa9205ab 100644 --- a/builder/build.go +++ b/builder/build.go @@ -79,7 +79,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil // keep functions interoperable, pass int64 types as pointers to // stack-allocated values. // Use -wasm-abi=generic to disable this behaviour. - if config.Options.WasmAbi == "js" && strings.HasPrefix(config.Triple(), "wasm") { + if config.WasmAbi() == "js" { err := transform.ExternalInt64AsPtr(mod) if err != nil { return err diff --git a/compileopts/config.go b/compileopts/config.go index ae143297..25b3ad1d 100644 --- a/compileopts/config.go +++ b/compileopts/config.go @@ -329,6 +329,15 @@ func (c *Config) RelocationModel() string { return "static" } +// WasmAbi returns the WASM ABI which is specified in the target JSON file, and +// the value is overridden by `-wasm-abi` flag if it is provided +func (c *Config) WasmAbi() string { + if c.Options.WasmAbi != "" { + return c.Options.WasmAbi + } + return c.Target.WasmAbi +} + type TestConfig struct { CompileTestBinary bool // TODO: Filter the test functions to run, include verbose flag, etc diff --git a/compileopts/target.go b/compileopts/target.go index 5fbf1640..8b3c68fc 100644 --- a/compileopts/target.go +++ b/compileopts/target.go @@ -55,6 +55,7 @@ type TargetSpec struct { JLinkDevice string `json:"jlink-device"` CodeModel string `json:"code-model"` RelocationModel string `json:"relocation-model"` + WasmAbi string `json:"wasm-abi"` } // overrideProperties overrides all properties that are set in child into itself using reflection. diff --git a/main.go b/main.go index 993463cb..30e8ee6b 100644 --- a/main.go +++ b/main.go @@ -828,7 +828,7 @@ func main() { programmer := flag.String("programmer", "", "which hardware programmer to use") cFlags := flag.String("cflags", "", "additional cflags for compiler") ldFlags := flag.String("ldflags", "", "additional ldflags for linker") - wasmAbi := flag.String("wasm-abi", "js", "WebAssembly ABI conventions: js (no i64 params) or generic") + wasmAbi := flag.String("wasm-abi", "", "WebAssembly ABI conventions: js (no i64 params) or generic") heapSize := flag.String("heap-size", "1M", "default heap size in bytes (only supported by WebAssembly)") var flagJSON, flagDeps *bool diff --git a/main_test.go b/main_test.go index 09c3919e..a7eca14f 100644 --- a/main_test.go +++ b/main_test.go @@ -165,11 +165,7 @@ func runTest(path, target string, t *testing.T) { VerifyIR: true, Debug: true, PrintSizes: "", - WasmAbi: "js", - } - - if target == "wasi" { - config.WasmAbi = "generic" + WasmAbi: "", } binary := filepath.Join(tmpdir, "test") diff --git a/targets/wasi.json b/targets/wasi.json index 97f7848f..521e467d 100644 --- a/targets/wasi.json +++ b/targets/wasi.json @@ -18,5 +18,6 @@ "--no-demangle", "{root}/lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a" ], - "emulator": ["wasmtime"] + "emulator": ["wasmtime"], + "wasm-abi": "generic" } diff --git a/targets/wasm.json b/targets/wasm.json index df4d5ee3..7767cd96 100644 --- a/targets/wasm.json +++ b/targets/wasm.json @@ -17,5 +17,6 @@ "--no-demangle", "{root}/lib/wasi-libc/sysroot/lib/wasm32-wasi/libc.a" ], - "emulator": ["node", "targets/wasm_exec.js"] + "emulator": ["node", "targets/wasm_exec.js"], + "wasm-abi": "js" }