mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-03 18:47:47 +00:00
wasm: include wasi-libc
This allows CGo code to call some libc functions. Additionally, by putting memset/memmove/memcpy in an archive they're not included anymore when not necessary, reducing code size for small programs.
This commit is contained in:
committed by
Ron Evans
parent
c61657d22d
commit
e2aa3789c3
@@ -2,10 +2,6 @@
|
||||
|
||||
package runtime
|
||||
|
||||
import (
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type timeUnit float64 // time in milliseconds, just like Date.now() in JavaScript
|
||||
|
||||
const tickMicros = 1000000
|
||||
@@ -68,25 +64,3 @@ func ticks() timeUnit
|
||||
func abort() {
|
||||
trap()
|
||||
}
|
||||
|
||||
//go:export memset
|
||||
func memset(ptr unsafe.Pointer, c byte, size uintptr) unsafe.Pointer {
|
||||
for i := uintptr(0); i < size; i++ {
|
||||
*(*byte)(unsafe.Pointer(uintptr(ptr) + i)) = c
|
||||
}
|
||||
return ptr
|
||||
}
|
||||
|
||||
// Implement memmove for LLVM and compiler-rt.
|
||||
//go:export memmove
|
||||
func libc_memmove(dst, src unsafe.Pointer, size uintptr) unsafe.Pointer {
|
||||
memmove(dst, src, size)
|
||||
return dst
|
||||
}
|
||||
|
||||
// Implement memcpy for LLVM and compiler-rt.
|
||||
//go:export memcpy
|
||||
func libc_memcpy(dst, src unsafe.Pointer, size uintptr) unsafe.Pointer {
|
||||
memcpy(dst, src, size)
|
||||
return dst
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user