Last active
January 1, 2020 22:27
-
-
Save andrewrk/5684434a2a8d4cbb08bb0d855c4f2ada to your computer and use it in GitHub Desktop.
how to create a small zig file for viewing IR
This file contains hidden or 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