# How do i generate IR when building an executable

**URL:** <https://ziggit.dev/t/how-do-i-generate-ir-when-building-an-executable/3624>\
**Category:** Help\
**Tags:** build-system\
**Created:** [March 20, 2024, 5:26pm UTC](https://ziggit.dev/t/how-do-i-generate-ir-when-building-an-executable/3624 "2024-03-20T17:26:44Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [March 21, 2024, 4:37pm UTC](https://ziggit.dev/t/how-do-i-generate-ir-when-building-an-executable/3624/8 "2024-03-21T16:37:41Z")

</div>

The answer is in my first linked topic:

> [@Emit "monomorphized" zig code](https://ziggit.dev/t/emit-monomorphized-zig-code/2657/2):
>
> The pipeline of Zig code looks something like this: Source code [AST (Abstract Syntax Tree)](https://github.com/ziglang/zig/blob/master/lib/std/zig/Ast.zig)[ZIR (Zig Intermediate Representation)](https://github.com/ziglang/zig/blob/master/src/Zir.zig)[AIR (Analyzed Intermediate Representation)](https://github.com/ziglang/zig/blob/master/src/Air.zig) Backend-specific logic (LLVM backend, x86-64 self-hosted backend, etc.) Comptime evaluation happens in the transition from ZIR to AIR, using a process called [Sema](https://github.com/ziglang/zig/blob/master/src/Sema.zig). So, it sounds like AIR is what you’re looking for. It is possible to look at a textual representation of ZIR and AIR using the following two commands, but the…

> [@Emit "monomorphized" zig code](https://ziggit.dev/t/emit-monomorphized-zig-code/2657/2):
>
> > [@Emit "monomorphized" zig code](https://ziggit.dev/t/emit-monomorphized-zig-code/2657/1):
> >
> > I’m guessing there is a step for interpreting the compile-time parts of a Zig program and emitting the “monomorphized” version of it
> 
> Comptime evaluation happens in the transition from ZIR to AIR, using a process called [Sema](https://github.com/ziglang/zig/blob/master/src/Sema.zig). So, it sounds like AIR is what you’re looking for.

For the full explanation take a look at the linked answer.

There is no step that generates something that looks like Zig source code again, because it would be an unnecessary step / going backwards, it may even be difficult to generate such a thing without creating something that is a bit of a lie (In the sense that abstractions lie), it might be possible to generate the “monomorphized” version, but still that would probably result in an explosion of code size and ultimately the AIR is always more faithful towards what is going on, because it’s the representation that is actually used.

Personally I think `@compileLog` together with assertions is already sufficient to gain the necessary insight into what is happening at comptime. So basically I would say use programming to ensure that the things you wanted to happen, do happen. Via checking types and using `@compileError` if they are wrong.

---

_[View the full topic](https://ziggit.dev/t/how-do-i-generate-ir-when-building-an-executable/3624)._
