# Seeing the MLIR/LLVM or ASM code generated by Mojo

**URL:** <https://forum.modular.com/t/seeing-the-mlir-llvm-or-asm-code-generated-by-mojo/250>\
**Category:** Mojo\
**Tags:** discussion\
**Created:** [December 11, 2024, 8:24pm UTC](https://forum.modular.com/t/seeing-the-mlir-llvm-or-asm-code-generated-by-mojo/250 "2024-12-11T20:24:45Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![sora](https://avatars.discourse-cdn.com/v4/letter/s/ad7895/32.png) [@sora](https://forum.modular.com/u/sora)\
**Post date:** [December 12, 2024, 3:56pm UTC](https://forum.modular.com/t/seeing-the-mlir-llvm-or-asm-code-generated-by-mojo/250/5 "2024-12-12T15:56:09Z")

</div>

You can use the `compile` module as follows:

```mojo
import compile

fn f(x: Int) -> Int:
  return x + 1

fn main():
  print(compile.compile_info[f, emission_kind="asm"]())
  print(compile.compile_info[f, emission_kind="llvm"]())

```

However, writing code like this manually quickly becomes tedious. To make it easier, here is my [little utility script](https://gist.github.com/soraros/44d56698cb20a6c5db3160f13ca81675) to dump the IR to a file. Below is an example demonstrating how to use this lib:

```mojo
import math
from sys.intrinsics import assume

from ir_utils import dump_ir

fn main():
  dump_ir[f, "out1"]()
  dump_ir[g, "out2"]()

@export # use `export` so get cleaner names
fn f(x: Int) -> Int:
  assume(0 <= x < 100)
  return max(1, x * 2)

@export
fn g(x: Int) -> Int:
  assume(0 <= x < 100)
  return x * 2 + int(x == 0)

```

---

_[View the full topic](https://forum.modular.com/t/seeing-the-mlir-llvm-or-asm-code-generated-by-mojo/250)._
