From 898ca824585e78306bb0137dbae1fbf859b762b6 Mon Sep 17 00:00:00 2001 From: dweiller <4678790+dweiller@users.noreply.github.com> Date: Thu, 23 Jan 2025 00:13:23 +1100 Subject: compiler: add @memmove builtin --- src/codegen/c.zig | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/codegen/c.zig') diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 2aee078b11..e7883b9def 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -3349,6 +3349,7 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail, .memset => try airMemset(f, inst, false), .memset_safe => try airMemset(f, inst, true), .memcpy => try airMemcpy(f, inst), + .memmove => try airMemmove(f, inst), .set_union_tag => try airSetUnionTag(f, inst), .get_union_tag => try airGetUnionTag(f, inst), .clz => try airUnBuiltinCall(f, inst, air_datas[@intFromEnum(inst)].ty_op.operand, "clz", .bits), @@ -6976,6 +6977,14 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue { } fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue { + return copyOp(f, inst, .memcpy); +} + +fn airMemmove(f: *Function, inst: Air.Inst.Index) !CValue { + return copyOp(f, inst, .memmove); +} + +fn copyOp(f: *Function, inst: Air.Inst.Index, op: enum { memcpy, memmove }) !CValue { const pt = f.object.dg.pt; const zcu = pt.zcu; const bin_op = f.air.instructions.items(.data)[@intFromEnum(inst)].bin_op; @@ -6990,7 +6999,11 @@ fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue { try writeArrayLen(f, writer, dest_ptr, dest_ty); try writer.writeAll(" != 0) "); } - try writer.writeAll("memcpy("); + const function_paren = switch (op) { + .memcpy => "memcpy(", + .memmove => "memmove(", + }; + try writer.writeAll(function_paren); try writeSliceOrPtr(f, writer, dest_ptr, dest_ty); try writer.writeAll(", "); try writeSliceOrPtr(f, writer, src_ptr, src_ty); -- cgit v1.2.3