make runtime compatible with wasm

This commit is contained in:
Li Jie
2025-04-08 16:50:47 +08:00
parent 7c81d9293b
commit be4737461a
183 changed files with 14122 additions and 647 deletions

View File

@@ -0,0 +1,10 @@
#include <unistd.h>
int llgo_maxprocs()
{
#ifdef _SC_NPROCESSORS_ONLN
return (int)sysconf(_SC_NPROCESSORS_ONLN);
#else
return 1;
#endif
}

View File

@@ -0,0 +1,5 @@
package runtime
// const (
// heapAddrBits = (_64bit*(1-goarch.IsWasm)*(1-goos.IsIos*goarch.IsArm64))*48 + (1-_64bit+goarch.IsWasm)*(32-(goarch.IsMips+goarch.IsMipsle)) + 40*goos.IsIos*goarch.IsArm64
// )

View File

@@ -16,27 +16,21 @@
package runtime
/*
#include <unistd.h>
int llgo_maxprocs() {
#ifdef _SC_NPROCESSORS_ONLN
return (int)sysconf(_SC_NPROCESSORS_ONLN);
#else
return 1;
#endif
}
*/
import "C"
import (
"unsafe"
c "github.com/goplus/llgo/runtime/internal/clite"
"github.com/goplus/llgo/runtime/internal/runtime"
)
// llgo:skipall
type _runtime struct{}
const (
LLGoPackage = "link"
LLGoFiles = "_wrap/runtime.c"
)
// GOROOT returns the root of the Go tree. It uses the
// GOROOT environment variable, if set at process start,
// or else the root used during the Go build.
@@ -58,6 +52,11 @@ func Goexit() {
func KeepAlive(x any) {
}
//go:linkname c_write C.write
func c_write(fd c.Int, p unsafe.Pointer, n c.SizeT) int32
func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
return int32(C.write(C.int(fd), p, C.size_t(n)))
return int32(c_write(c.Int(fd), p, c.SizeT(n)))
}
const heapArenaBytes = 1024 * 1024

View File

@@ -4,9 +4,7 @@
package runtime
import (
"runtime"
)
import "runtime"
// Layout of in-memory per-function information prepared by linker
// See https://golang.org/s/go12symtab.