Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>For top level declarations, it's not too hard. Local definitions can be harder to recognize as their names get mangled and they are likely to get inlined.</p> <p>Let's see what happens when we compile this simple module.</p> <pre class="lang-hs prettyprint-override"><code>module Example where add :: Int -&gt; Int -&gt; Int add x y = x + y </code></pre> <pre class="lang-asm prettyprint-override"><code><strong>.data .align 8 .globl Example_add_closure .type Example_add_closure, @object Example_add_closure: .quad Example_add_info .text .align 8 .quad 8589934604 .quad 0 .quad 15 .globl Example_add_info .type Example_add_info, @object Example_add_info: .LckX: jmp base_GHCziBase_plusInt_info</strong> .data .align 8 _module_registered: .quad 0 .text .align 8 .globl __stginit_Example_ .type __stginit_Example_, @object __stginit_Example_: .Lcl7: cmpq $0,_module_registered jne .Lcl8 .Lcl9: movq $1,_module_registered addq $-8,%rbp movq $__stginit_base_Prelude_,(%rbp) .Lcl8: addq $8,%rbp jmp *-8(%rbp) .text .align 8 .globl __stginit_Example .type __stginit_Example, @object __stginit_Example: .Lcld: jmp __stginit_Example_ .section .note.GNU-stack,"",@progbits .ident "GHC 7.0.2" </code></pre> <p>You can see that our function <code>Example.add</code> resulted in the generation of <code>Example_add_closure</code> and <code>Example_add_info</code>. The <code>_closure</code> part, as the name suggests, has to do with closures. The <code>_info</code> part contains the actual instructions of the function. In this case, this is simply a jump to the built-in function <code>GHC.Base.plusInt</code>. </p> <p>Note that assembly generated from Haskell code looks quite different from what you might get from other languages. The calling conventions are different, and things can get reordered a lot.</p> <p>In most cases you don't want to jump straight to assembly. It is usually much easier to understand <em>core</em>, a simplified version of Haskell. (Simpler to compile, not necessarily to read). To get at the core, compile with the <code>-ddump-simpl</code> option.</p> <pre class="lang-none prettyprint-override"><code>Example.add :: GHC.Types.Int -&gt; GHC.Types.Int -&gt; GHC.Types.Int [GblId, Arity=2] Example.add = \ (x_abt :: GHC.Types.Int) (y_abu :: GHC.Types.Int) -&gt; GHC.Num.+ @ GHC.Types.Int GHC.Num.$fNumInt x_abt y_abu </code></pre> <p>For some good resources on how to read core, see <a href="https://stackoverflow.com/questions/6121146/reading-ghc-core/6121495#6121495">this question</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload