Peek Into The Compiler’s Code — Lots Of Compilers

Peek Into The Compiler’s Code — Lots Of Compilers

We don’t know what normal people argue about, but we know we spend a lot of time arguing about the best microcontroller, which editor is the best, and what language or compiler does the best job. The problem with all those compilers is getting them loaded and digging into the generated code. If you too spend your time thinking about those things, you ought to have a look at [Matt Godbolt’s] Compiler Explorer. We know that hosting an IDE-like web page and compiling code is old hat — although [Matt’s] site has been around quite some time. But [Matt’s] doing it differently. The code you build on the left hand pane shows up as assembly language on the right hand side.


There are plenty of options, too. For example, here’s a bit of C code from the site’s example:


int square(int num) { return num * num;
}

Here’s the corresponding assembly from gcc 9.2 for x86-64:


square: push rbp mov rbp, rsp mov DWORD PTR [rbp-4], edi mov eax, DWORD PTR [rbp-4] imul eax, eax pop rbp ret

However, ARM64 gcc 8.2 outputs:


square: sub sp, sp, #16 str w0, [sp, 12] ldr w1, [sp, 12] ldr w0, [sp, 12] mul w0, w1, w0 add sp, sp, 16 ret

There are options for many compilers including AVR. 6502, and MIPS. Even more interesting is there is support for many other languages ranging from FORTRAN to Rust and Go. It is a nice touch that the source code lines get colors that match the region of the disassembly that corresponds to that line.


As a side note, you can click the Output button at the bottom and actually run your test program, if you like. If you are ..

Support the originator by clicking the read the rest link below.