authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-20 03:44:36+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-23 09:27:17+02:00
loga1441943e41014cfbce3105c4cdd9d3e0d137e4f
treeca5fa875ded89f59f797a515f312b519123e3389
parentee72f06f47055ecf3fa650eae9ef49446745f509
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.Target: add stackGrowth() function


1 files changed, 18 insertions(+), 0 deletions(-)

lib/std/Target.zig+18
...@@ -2930,6 +2930,24 @@ pub fn stackAlignment(target: *const Target) u16 {...@@ -2930,6 +2930,24 @@ pub fn stackAlignment(target: *const Target) u16 {
2930 return @divExact(target.ptrBitWidth(), 8);2930 return @divExact(target.ptrBitWidth(), 8);
2931}2931}
29322932
2933pub const StackGrowth = enum {
2934 down,
2935 up,
2936};
2937
2938pub fn stackGrowth(target: *const Target) StackGrowth {
2939 // Strictly speaking, most architectures don't inherently define the stack growth direction; you
2940 // could quite easily argue that it is in fact a property of the ABI. However, that's just not
2941 // really how it plays out in the real world. And besides, we have no mechanism for indicating
2942 // a different stack growth ABI, nor a compelling use case for creating such a mechanism.
2943 return switch (target.cpu.arch) {
2944 .hppa,
2945 .hppa64,
2946 => .up,
2947 else => .down,
2948 };
2949}
2950
2933/// Default signedness of `char` for the native C compiler for this target2951/// Default signedness of `char` for the native C compiler for this target
2934/// Note that char signedness is implementation-defined and many compilers provide2952/// Note that char signedness is implementation-defined and many compilers provide
2935/// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char2953/// an option to override the default signedness e.g. GCC's -funsigned-char / -fsigned-char