-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wasm-unknown: add math builtins that LLVM needs
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package builder | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/tinygo-org/tinygo/goenv" | ||
) | ||
|
||
var WasmBuiltins = Library{ | ||
name: "wasmbuiltins", | ||
makeHeaders: func(target, includeDir string) error { | ||
os.Mkdir(includeDir+"/bits", 0o777) | ||
f, err := os.Create(includeDir + "/bits/alltypes.h") | ||
if err != nil { | ||
return err | ||
} | ||
if _, err := f.Write([]byte(wasmAllTypes)); err != nil { | ||
return err | ||
} | ||
return f.Close() | ||
}, | ||
cflags: func(target, headerPath string) []string { | ||
libcDir := filepath.Join(goenv.Get("TINYGOROOT"), "lib/wasi-libc") | ||
return []string{ | ||
"-Werror", | ||
"-Wall", | ||
"-std=gnu11", | ||
"-nostdlibinc", | ||
"-isystem", libcDir + "/libc-top-half/musl/arch/wasm32", | ||
"-isystem", libcDir + "/libc-top-half/musl/arch/generic", | ||
"-isystem", libcDir + "/libc-top-half/musl/src/internal", | ||
"-isystem", libcDir + "/libc-top-half/musl/src/include", | ||
"-isystem", libcDir + "/libc-top-half/musl/include", | ||
"-I" + headerPath, | ||
} | ||
}, | ||
sourceDir: func() string { return filepath.Join(goenv.Get("TINYGOROOT"), "lib/wasi-libc") }, | ||
librarySources: func(target string) ([]string, error) { | ||
return []string{ | ||
"libc-top-half/musl/src/math/__math_divzero.c", | ||
"libc-top-half/musl/src/math/__math_invalid.c", | ||
"libc-top-half/musl/src/math/__math_oflow.c", | ||
"libc-top-half/musl/src/math/__math_uflow.c", | ||
"libc-top-half/musl/src/math/__math_xflow.c", | ||
"libc-top-half/musl/src/math/exp.c", | ||
"libc-top-half/musl/src/math/exp_data.c", | ||
"libc-top-half/musl/src/math/exp2.c", | ||
"libc-top-half/musl/src/math/log.c", | ||
"libc-top-half/musl/src/math/log_data.c", | ||
}, nil | ||
}, | ||
} | ||
|
||
const wasmAllTypes = ` | ||
typedef __INT8_TYPE__ int8_t; | ||
typedef __INT16_TYPE__ int16_t; | ||
typedef __INT32_TYPE__ int32_t; | ||
typedef __INT64_TYPE__ int64_t; | ||
typedef __UINT8_TYPE__ uint8_t; | ||
typedef __UINT16_TYPE__ uint16_t; | ||
typedef __UINT32_TYPE__ uint32_t; | ||
typedef __UINT64_TYPE__ uint64_t; | ||
typedef double double_t; | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters