aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/c.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-07-11 22:03:00 -0700
committerAndrew Kelley <andrew@ziglang.org>2025-07-16 10:23:02 -0700
commitfcafc63f3d5ce250e404871571aa3b26aeae6611 (patch)
tree49e3354bb24dd1d8663127598e4f2f63942f2655 /src/codegen/c.zig
parent6002514b72cb2a571abc6ac4ac7fbec44d6302b1 (diff)
downloadzig-fcafc63f3d5ce250e404871571aa3b26aeae6611.tar.gz
zig-fcafc63f3d5ce250e404871571aa3b26aeae6611.zip
inline assembly: use types
until now these were stringly typed. it's kinda obvious when you think about it.
Diffstat (limited to 'src/codegen/c.zig')
-rw-r--r--src/codegen/c.zig43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/codegen/c.zig b/src/codegen/c.zig
index 61bd5259ae..955a83bc33 100644
--- a/src/codegen/c.zig
+++ b/src/codegen/c.zig
@@ -5545,11 +5545,11 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
const zcu = pt.zcu;
const ty_pl = f.air.instructions.items(.data)[@intFromEnum(inst)].ty_pl;
const extra = f.air.extraData(Air.Asm, ty_pl.payload);
- const is_volatile = @as(u1, @truncate(extra.data.flags >> 31)) != 0;
- const clobbers_len: u31 = @truncate(extra.data.flags);
+ const is_volatile = extra.data.flags.is_volatile;
+ const outputs_len = extra.data.flags.outputs_len;
const gpa = f.object.dg.gpa;
var extra_i: usize = extra.end;
- const outputs: []const Air.Inst.Ref = @ptrCast(f.air.extra.items[extra_i..][0..extra.data.outputs_len]);
+ const outputs: []const Air.Inst.Ref = @ptrCast(f.air.extra.items[extra_i..][0..outputs_len]);
extra_i += outputs.len;
const inputs: []const Air.Inst.Ref = @ptrCast(f.air.extra.items[extra_i..][0..extra.data.inputs_len]);
extra_i += inputs.len;
@@ -5645,12 +5645,6 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
try f.object.newline();
}
}
- for (0..clobbers_len) |_| {
- const clobber = mem.sliceTo(mem.sliceAsBytes(f.air.extra.items[extra_i..]), 0);
- // This equation accounts for the fact that even if we have exactly 4 bytes
- // for the string, we still use the next u32 for the null terminator.
- extra_i += clobber.len / 4 + 1;
- }
{
const asm_source = mem.sliceAsBytes(f.air.extra.items[extra_i..])[0..extra.data.source_len];
@@ -5757,17 +5751,28 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
try w.writeByte(')');
}
try w.writeByte(':');
- for (0..clobbers_len) |clobber_i| {
- const clobber = mem.sliceTo(mem.sliceAsBytes(f.air.extra.items[extra_i..]), 0);
- // This equation accounts for the fact that even if we have exactly 4 bytes
- // for the string, we still use the next u32 for the null terminator.
- extra_i += clobber.len / 4 + 1;
-
- if (clobber.len == 0) continue;
-
- if (clobber_i > 0) try w.writeByte(',');
- try w.print(" {f}", .{fmtStringLiteral(clobber, null)});
+ const ip = &zcu.intern_pool;
+ const aggregate = ip.indexToKey(extra.data.clobbers).aggregate;
+ const struct_type: Type = .fromInterned(aggregate.ty);
+ switch (aggregate.storage) {
+ .elems => |elems| for (elems, 0..) |elem, i| switch (elem) {
+ .bool_true => {
+ const name = struct_type.structFieldName(i, zcu).toSlice(ip).?;
+ assert(name.len != 0);
+ try w.print(" {f}", .{fmtStringLiteral(name, null)});
+ (try w.writableArray(1))[0] = ',';
+ },
+ .bool_false => continue,
+ else => unreachable,
+ },
+ .repeated_elem => |elem| switch (elem) {
+ .bool_true => @panic("TODO"),
+ .bool_false => {},
+ else => unreachable,
+ },
+ .bytes => @panic("TODO"),
}
+ w.undo(1); // erase the last comma
try w.writeAll(");");
try f.object.newline();