From a1441943e41014cfbce3105c4cdd9d3e0d137e4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 20 Oct 2025 03:44:36 +0200 Subject: [PATCH] std.Target: add stackGrowth() function --- lib/std/Target.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/std/Target.zig b/lib/std/Target.zig index d5caf8665968afbf819b688d5355e714fd158c72..20d37b893943aa313d4addea7065fec1ba01cf3f 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -2930,6 +2930,24 @@ pub fn stackAlignment(target: *const Target) u16 { return @divExact(target.ptrBitWidth(), 8); } +pub const StackGrowth = enum { + down, + up, +}; + +pub fn stackGrowth(target: *const Target) StackGrowth { + // Strictly speaking, most architectures don't inherently define the stack growth direction; you + // could quite easily argue that it is in fact a property of the ABI. However, that's just not + // really how it plays out in the real world. And besides, we have no mechanism for indicating + // a different stack growth ABI, nor a compelling use case for creating such a mechanism. + return switch (target.cpu.arch) { + .hppa, + .hppa64, + => .up, + else => .down, + }; +} + /// Default signedness of `char` for the native C compiler for this target /// Note that char signedness is implementation-defined and many compilers provide /// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char -- 2.54.0