mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-01 10:52:18 +00:00
add memcpy impl to builtins
This commit is contained in:
parent
93cc2e579f
commit
ca9938bf7c
2 changed files with 42 additions and 0 deletions
41
crates/compiler/builtins/bitcode/src/libc.zig
Normal file
41
crates/compiler/builtins/bitcode/src/libc.zig
Normal file
|
@ -0,0 +1,41 @@
|
|||
const std = @import("std");
|
||||
const builtin = @import("builtin");
|
||||
const arch = builtin.cpu.arch;
|
||||
|
||||
comptime {
|
||||
@export(memcpy, .{ .name = "roc_memcpy", .linkage = .Weak });
|
||||
@export(memcpy, .{ .name = "memcpy", .linkage = .Weak });
|
||||
}
|
||||
|
||||
const Memcpy = fn (noalias [*]u8, noalias [*]const u8, len: usize) callconv(.C) [*]u8;
|
||||
|
||||
pub var memcpy_target: Memcpy = switch (arch) {
|
||||
.x86_64 => memcpy,
|
||||
else => unreachable,
|
||||
};
|
||||
|
||||
pub fn memcpy(noalias dest: [*]u8, noalias src: [*]const u8, len: usize) callconv(.C) [*]u8 {
|
||||
switch (arch) {
|
||||
.x86_64 => {
|
||||
@memcpy(dest, src, len);
|
||||
return memcpy_target(dest, src, len);
|
||||
},
|
||||
.i386 => {
|
||||
@memcpy(dest, src, len);
|
||||
return dest;
|
||||
},
|
||||
.aarch64 => {
|
||||
@memcpy(dest, src, len);
|
||||
return dest;
|
||||
},
|
||||
.arm => {
|
||||
@memcpy(dest, src, len);
|
||||
return dest;
|
||||
},
|
||||
.wasm32 => {
|
||||
@memcpy(dest, src, len);
|
||||
return dest;
|
||||
},
|
||||
else => @compileError("Unsupported architecture for memcpy"),
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@ const panic_utils = @import("panic.zig");
|
|||
|
||||
comptime {
|
||||
_ = @import("compiler_rt.zig");
|
||||
_ = @import("libc.zig");
|
||||
}
|
||||
|
||||
const ROC_BUILTINS = "roc_builtins";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue