how do i tell zig to output an IR file when building my program

46 views Asked by At

How do i tell zig (either at the command-line or in my build.zig file to create/generate/save an IR file corresponding to my program?

Right now, I'm able to "disassemble" the .elf file -- but would like something a little higher-level.

1

There are 1 answers

0
Crispy Strawberry On

You can do the following inside your build script-

const exe = b.addExecutable(.{
    ...
});

const ir_file = b.addInstallFile(exe.getEmittedLlvmIr(), "my_exe.ll");
b.getInstallStep().dependOn(&ir_file.step);

After running zig build, the generated LLVM IR in zig-out/my_exe.ll

If you want to get the assembly file, just replace exe.getEmittedLlvmIr() with exe.getEmittedAsm()!