how to create a small zig file for viewing IR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// trick #1 export a void function and put your logic here | |
// using std lib functions creates a lot of IR | |
export fn entry() void { | |
var x: i32 = 1; | |
x += 1; | |
} | |
// trick #2, override the default panic handler to something trivial | |
const std = @import("std"); | |
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace) noreturn { | |
@breakpoint(); unreachable; | |
} | |
// build this with: | |
// zig build-obj example.zig --verbose-ir | |
// or | |
// zig build-obj example.zig --verbose-llvm-ir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment