mirror of
https://github.com/ziglang/zig.git
synced 2024-11-16 00:57:04 +00:00
C backend: implement ret_addr
This commit is contained in:
parent
4cb2f11693
commit
8b6ea9ffe7
@ -2214,7 +2214,9 @@ fn airBreakpoint(f: *Function) !CValue {
|
||||
}
|
||||
|
||||
fn airRetAddr(f: *Function) !CValue {
|
||||
return f.fail("TODO implement codegen for airRetAddr", .{});
|
||||
const local = try f.allocLocal(Type.usize, .Const);
|
||||
try f.object.writer().writeAll(" = zig_return_address();\n");
|
||||
return local;
|
||||
}
|
||||
|
||||
fn airFence(f: *Function, inst: Air.Inst.Index) !CValue {
|
||||
|
@ -60,6 +60,20 @@
|
||||
#define zig_breakpoint() raise(SIGTRAP)
|
||||
#endif
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define zig_return_address() _ReturnAddress()
|
||||
#elif defined(__GNUC__)
|
||||
#define zig_return_address() __builtin_extract_return_addr(__builtin_return_address(0))
|
||||
#else
|
||||
#define zig_return_address() 0
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define zig_frame_address() __builtin_frame_address(0)
|
||||
#else
|
||||
#define zig_frame_address() 0
|
||||
#endif
|
||||
|
||||
#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__)
|
||||
#include <stdatomic.h>
|
||||
#define zig_cmpxchg_strong(obj, expected, desired, succ, fail) atomic_compare_exchange_strong_explicit(obj, &(expected), desired, succ, fail)
|
||||
|
Loading…
Reference in New Issue
Block a user