Skip to content

Commit dbf9c7b

Browse files
committed
compiler: add support for arc_interrupt calling convention
Only for use with the C backend at the moment.
1 parent 49eea79 commit dbf9c7b

File tree

8 files changed

+43
-0
lines changed

8 files changed

+43
-0
lines changed

lib/std/Target.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1754,6 +1754,7 @@ pub const Cpu = struct {
17541754
=> &.{ .wasm64, .wasm32 },
17551755

17561756
.arc_sysv,
1757+
.arc_interrupt,
17571758
=> &.{.arc},
17581759

17591760
.avr_gnu,

lib/std/builtin.zig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ pub const CallingConvention = union(enum(u8)) {
277277

278278
/// The standard `arc` calling convention.
279279
arc_sysv: CommonOptions,
280+
arc_interrupt: ArcInterruptOptions,
280281

281282
// Calling conventions for the `avr` architecture.
282283
avr_gnu,
@@ -368,6 +369,22 @@ pub const CallingConvention = union(enum(u8)) {
368369
register_params: u2 = 0,
369370
};
370371

372+
/// Options for the `arc_interrupt` calling convention.
373+
pub const ArcInterruptOptions = struct {
374+
/// The boundary the stack is aligned to when the function is called.
375+
/// `null` means the default for this calling convention.
376+
incoming_stack_alignment: ?u64 = null,
377+
/// The kind of interrupt being received.
378+
type: InterruptType,
379+
380+
pub const InterruptType = enum(u2) {
381+
ilink1,
382+
ilink2,
383+
ilink,
384+
firq,
385+
};
386+
};
387+
371388
/// Options for the `arm_interrupt` calling convention.
372389
pub const ArmInterruptOptions = struct {
373390
/// The boundary the stack is aligned to when the function is called.

src/InternPool.zig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12950,6 +12950,11 @@ const PackedCallingConvention = packed struct(u18) {
1295012950
.incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
1295112951
.extra = pl.register_params,
1295212952
},
12953+
std.builtin.CallingConvention.ArcInterruptOptions => .{
12954+
.tag = tag,
12955+
.incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
12956+
.extra = @intFromEnum(pl.type),
12957+
},
1295312958
std.builtin.CallingConvention.ArmInterruptOptions => .{
1295412959
.tag = tag,
1295512960
.incoming_stack_alignment = .fromByteUnits(pl.incoming_stack_alignment orelse 0),
@@ -12984,6 +12989,10 @@ const PackedCallingConvention = packed struct(u18) {
1298412989
.incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
1298512990
.register_params = @intCast(cc.extra),
1298612991
},
12992+
std.builtin.CallingConvention.ArcInterruptOptions => .{
12993+
.incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
12994+
.type = @enumFromInt(cc.extra),
12995+
},
1298712996
std.builtin.CallingConvention.ArmInterruptOptions => .{
1298812997
.incoming_stack_alignment = cc.incoming_stack_alignment.toByteUnits(),
1298912998
.type = @enumFromInt(cc.extra),

src/Sema.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9122,6 +9122,7 @@ fn callConvIsCallable(cc: std.builtin.CallingConvention.Tag) bool {
91229122
return switch (cc) {
91239123
.naked,
91249124

9125+
.arc_interrupt,
91259126
.arm_interrupt,
91269127
.avr_interrupt,
91279128
.avr_signal,
@@ -9284,6 +9285,7 @@ fn funcCommon(
92849285
else => return sema.fail(block, param_src, "'{s}' calling convention supports up to 2 parameters, found {d}", .{ @tagName(cc), i + 1 }),
92859286
}
92869287
},
9288+
.arc_interrupt,
92879289
.arm_interrupt,
92889290
.mips64_interrupt,
92899291
.mips_interrupt,
@@ -9515,6 +9517,7 @@ fn finishFunc(
95159517
.mips_interrupt,
95169518
.riscv64_interrupt,
95179519
.riscv32_interrupt,
9520+
.arc_interrupt,
95189521
.avr_interrupt,
95199522
.csky_interrupt,
95209523
.m68k_interrupt,
@@ -30038,6 +30041,9 @@ fn callconvCoerceAllowed(
3003830041
std.builtin.CallingConvention.X86RegparmOptions => {
3003930042
if (src_data.register_params != dest_data.register_params) return false;
3004030043
},
30044+
std.builtin.CallingConvention.ArcInterruptOptions => {
30045+
if (src_data.type != dest_data.type) return false;
30046+
},
3004130047
std.builtin.CallingConvention.ArmInterruptOptions => {
3004230048
if (src_data.type != dest_data.type) return false;
3004330049
},

src/Zcu.zig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4475,6 +4475,9 @@ pub fn callconvSupported(zcu: *Zcu, cc: std.builtin.CallingConvention) union(enu
44754475
.arm_aapcs_vfp,
44764476
=> |opts| opts.incoming_stack_alignment == null,
44774477

4478+
.arc_interrupt,
4479+
=> |opts| opts.incoming_stack_alignment == null,
4480+
44784481
.arm_interrupt,
44794482
=> |opts| opts.incoming_stack_alignment == null,
44804483

src/codegen/c.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8077,6 +8077,10 @@ fn toCallingConvention(cc: std.builtin.CallingConvention, zcu: *Zcu) ?[]const u8
80778077
.arm_aapcs => "pcs(\"aapcs\")",
80788078
.arm_aapcs_vfp => "pcs(\"aapcs-vfp\")",
80798079

8080+
.arc_interrupt => |opts| switch (opts.type) {
8081+
inline else => |t| "interrupt(\"" ++ @tagName(t) ++ "\")",
8082+
},
8083+
80808084
.arm_interrupt => |opts| switch (opts.type) {
80818085
.generic => "interrupt",
80828086
.irq => "interrupt(\"IRQ\")",

src/codegen/llvm.zig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11816,6 +11816,7 @@ pub fn toLlvmCallConv(cc: std.builtin.CallingConvention, target: *const std.Targ
1181611816
const incoming_stack_alignment: ?u64, const register_params: u2 = switch (cc) {
1181711817
inline else => |pl| switch (@TypeOf(pl)) {
1181811818
void => .{ null, 0 },
11819+
std.builtin.CallingConvention.ArcInterruptOptions,
1181911820
std.builtin.CallingConvention.ArmInterruptOptions,
1182011821
std.builtin.CallingConvention.RiscvInterruptOptions,
1182111822
std.builtin.CallingConvention.MipsInterruptOptions,
@@ -11919,6 +11920,7 @@ fn toLlvmCallConvTag(cc_tag: std.builtin.CallingConvention.Tag, target: *const s
1191911920
.powerpc_aix_altivec,
1192011921
.wasm_mvp,
1192111922
.arc_sysv,
11923+
.arc_interrupt,
1192211924
.avr_gnu,
1192311925
.bpf_std,
1192411926
.csky_sysv,

src/link/Dwarf.zig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3917,6 +3917,7 @@ fn updateLazyType(
39173917
.mips_interrupt,
39183918
.riscv64_interrupt,
39193919
.riscv32_interrupt,
3920+
.arc_interrupt,
39203921
.avr_builtin,
39213922
.avr_signal,
39223923
.avr_interrupt,

0 commit comments

Comments
 (0)