Skip to content

Instantly share code, notes, and snippets.

@andrewrk
Last active January 1, 2020 22:27
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
how to create a small zig file for viewing IR
// 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