compiler: work around i64 limitation in JavaScript

JavaScript does not support i64 directly, so make sure we pass a pointer
instead which can be read from JavaScript.

This is a temporary workaround which should be removed once JavaScript
supports some form of i64 (probably in the form of BigInt).
This commit is contained in:
Ayke van Laethem
2018-11-03 11:57:21 +01:00
parent d7844ce124
commit 2e22d53e5d
3 changed files with 116 additions and 0 deletions
+9
View File
@@ -64,6 +64,15 @@ func Compile(pkgName, outpath string, spec *TargetSpec, config *BuildConfig, act
return err
}
// Browsers cannot handle external functions that have type i64 because it
// cannot be represented exactly in JavaScript (JS only has doubles). To
// keep functions interoperable, pass int64 types as pointers to
// stack-allocated values.
if strings.HasPrefix(spec.Triple, "wasm") {
c.ExternalInt64AsPtr()
c.Verify()
}
// Optimization levels here are roughly the same as Clang, but probably not
// exactly.
switch config.opt {