Skip to content

Commit

Permalink
Added some missing intrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
yglukhov committed Nov 1, 2023
1 parent 85d54f5 commit 9b9a60f
Show file tree
Hide file tree
Showing 402 changed files with 28,261 additions and 1 deletion.
9 changes: 9 additions & 0 deletions wasmrt.nim
Original file line number Diff line number Diff line change
Expand Up @@ -679,12 +679,21 @@ proc mmap(a: pointer, len: csize_t, prot, flags, fildes: cint, off: int): pointe

wasmAlloc(len)

proc malloc(sz: csize_t): pointer {.exportc.} = alloc(sz)
proc free(p: pointer) {.exportc.} = dealloc(p)

# Suppress __wasm_call_ctors
# https://stackoverflow.com/questions/72568387/why-is-an-objects-constructor-being-called-in-every-exported-wasm-function
proc initialize() {.stackTrace: off, exportc: "_initialize", codegenDecl: wasmExportCodegenDecl.} =
proc ctors() {.importc: "__wasm_call_ctors".}
ctors()

when compileOption("stackTrace"):
{.push stackTrace: off.}
proc wasmStackTrace() {.exportwasm.} =
writeStackTrace()
{.pop.}

when not defined(gcDestructors):
GC_disable()

Expand Down
14 changes: 13 additions & 1 deletion wasmrt/libc.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import posix
import posix, strutils, os

import ../wasmrt

const
builtinsPath = currentSourcePath.rsplit({DirSep, AltSep}, 1)[0] &
"/llvm-builtins/builtins/"

template c(s: string) =
{.compile: builtinsPath & s.}

# TODO: Extend the following list as needed
c "multi3.c"
c "lshrti3.c"
c "ashrti3.c"

proc gettimeImpl(): cint {.importwasmf: "Date.now".}

proc clock_gettime(clkId: Clockid, tp: var Timespec): cint {.exportc.} =
Expand Down
4 changes: 4 additions & 0 deletions wasmrt/llvm-builtins/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
The builtins directory in this dir is a copy of
https://github.com/llvm/llvm-project/tree/main/compiler-rt/lib/builtins
of tag illvmorg-17.0.4

Loading

0 comments on commit 9b9a60f

Please sign in to comment.