mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 14:48:47 +00:00
wasm: fix target wasm64p32 runtime procs
LLVM generates calls with `i32` regardless of target, so if a call to any of these procs was generated this failed to compile. I opted to fix by changing from `int` to `i32` on wasm64p32 and adding `#any_int` so existing code keeps working.
This commit is contained in:
+15
-9
@@ -26,12 +26,18 @@ when ODIN_NO_CRT && ODIN_OS == .Windows {
|
|||||||
return dst
|
return dst
|
||||||
}
|
}
|
||||||
} else when ODIN_NO_CRT || (ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32) {
|
} else when ODIN_NO_CRT || (ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32) {
|
||||||
|
// NOTE: on wasm, calls to these procs are generated (by LLVM) with type `i32` instead of `int`.
|
||||||
|
//
|
||||||
|
// NOTE: `#any_int` is also needed, because calls that we generate (and package code)
|
||||||
|
// will be using `int` and need to be converted.
|
||||||
|
int_t :: i32 when ODIN_ARCH == .wasm64p32 else int
|
||||||
|
|
||||||
@(link_name="memset", linkage="strong", require)
|
@(link_name="memset", linkage="strong", require)
|
||||||
memset :: proc "c" (ptr: rawptr, val: i32, len: int) -> rawptr {
|
memset :: proc "c" (ptr: rawptr, val: i32, #any_int len: int_t) -> rawptr {
|
||||||
if ptr != nil && len != 0 {
|
if ptr != nil && len != 0 {
|
||||||
b := byte(val)
|
b := byte(val)
|
||||||
p := ([^]byte)(ptr)
|
p := ([^]byte)(ptr)
|
||||||
for i := 0; i < len; i += 1 {
|
for i := int_t(0); i < len; i += 1 {
|
||||||
p[i] = b
|
p[i] = b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -39,10 +45,10 @@ when ODIN_NO_CRT && ODIN_OS == .Windows {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@(link_name="bzero", linkage="strong", require)
|
@(link_name="bzero", linkage="strong", require)
|
||||||
bzero :: proc "c" (ptr: rawptr, len: int) -> rawptr {
|
bzero :: proc "c" (ptr: rawptr, #any_int len: int_t) -> rawptr {
|
||||||
if ptr != nil && len != 0 {
|
if ptr != nil && len != 0 {
|
||||||
p := ([^]byte)(ptr)
|
p := ([^]byte)(ptr)
|
||||||
for i := 0; i < len; i += 1 {
|
for i := int_t(0); i < len; i += 1 {
|
||||||
p[i] = 0
|
p[i] = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -50,7 +56,7 @@ when ODIN_NO_CRT && ODIN_OS == .Windows {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@(link_name="memmove", linkage="strong", require)
|
@(link_name="memmove", linkage="strong", require)
|
||||||
memmove :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
|
memmove :: proc "c" (dst, src: rawptr, #any_int len: int_t) -> rawptr {
|
||||||
d, s := ([^]byte)(dst), ([^]byte)(src)
|
d, s := ([^]byte)(dst), ([^]byte)(src)
|
||||||
if d == s || len == 0 {
|
if d == s || len == 0 {
|
||||||
return dst
|
return dst
|
||||||
@@ -63,7 +69,7 @@ when ODIN_NO_CRT && ODIN_OS == .Windows {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if s > d && uintptr(s)-uintptr(d) < uintptr(len) {
|
if s > d && uintptr(s)-uintptr(d) < uintptr(len) {
|
||||||
for i := 0; i < len; i += 1 {
|
for i := int_t(0); i < len; i += 1 {
|
||||||
d[i] = s[i]
|
d[i] = s[i]
|
||||||
}
|
}
|
||||||
return dst
|
return dst
|
||||||
@@ -71,10 +77,10 @@ when ODIN_NO_CRT && ODIN_OS == .Windows {
|
|||||||
return memcpy(dst, src, len)
|
return memcpy(dst, src, len)
|
||||||
}
|
}
|
||||||
@(link_name="memcpy", linkage="strong", require)
|
@(link_name="memcpy", linkage="strong", require)
|
||||||
memcpy :: proc "c" (dst, src: rawptr, len: int) -> rawptr {
|
memcpy :: proc "c" (dst, src: rawptr, #any_int len: int_t) -> rawptr {
|
||||||
d, s := ([^]byte)(dst), ([^]byte)(src)
|
d, s := ([^]byte)(dst), ([^]byte)(src)
|
||||||
if d != s {
|
if d != s {
|
||||||
for i := 0; i < len; i += 1 {
|
for i := int_t(0); i < len; i += 1 {
|
||||||
d[i] = s[i]
|
d[i] = s[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,4 +98,4 @@ when ODIN_NO_CRT && ODIN_OS == .Windows {
|
|||||||
}
|
}
|
||||||
return ptr
|
return ptr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user