Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Compiler Explorer (godbolt.org)
135 points by kercker on May 11, 2016 | hide | past | favorite | 38 comments


It's not very discoverable but there are sister sites for Rust, Go and D:

https://rust.godbolt.org/ https://go.godbolt.org/ https://d.godbolt.org/


FWIW, the Rust Playground [1] also has support for viewing assembly, along with intermediate representations.

[1] https://play.rust-lang.org


Nice, I wasn't aware of those! BTW, the Go one looks broken on the example when using 6g (gccgo seems to work.)


Thanks; I'll take a look (feel free to file bugs on github https://github.com/mattgodbolt/gcc-explorer/issues too)


Hmm.. For D it's https://d.godbolt.org/ but for C (not limited to gcc) it's https://gcc.godbolt.org/ ?


Yeah...It started out as GCC only but then I added clang, and ICC and... naming is hard!


You can make an alias and redirect the gcc prefix to that one with c.


These are really nice! Have you considered creating a sister site for Nim?


So far I've limited myself to compilers etc that model very closely on GCC; i.e. very similar compile options etc. I'd happily accept patches though...


the rust compiler is out of date :(


Not by much, it lacks 1.8 and the beta compiler is 1.7b4 but that's about it.


are you planning one for swift?


IBM already provides one.

https://swiftlang.ng.bluemix.net/?cm_mmc=developerWorks-_-dW...

They are investing into it.

https://developer.ibm.com/swift/

I am expecting a Swift EE any day. :)


that seems to be running the code, i'm interested in something showing assembly. i realize that i can run the commands myself but the gcc explorer is very interactive which i like.


I created SILInspector to do some demos for a presentation:

https://github.com/alblue/SILInspector

You can switch between the various stages of the Swift compiler including assembly.

I did a talk for Swift London recently which was recoded: should be at https://m.youtube.com/channel/UC5ypB3f_gdQm2qJ4gmjYkJg at some point.


The video of SILInspector (and background on SIL) is at https://m.youtube.com/watch?v=NH-qIKOoKgA


This looks dank


Well they are taking survey input about it, you can provide that as feedback.


Not currently; I'd happily accept patches though! :)


I would like to point out that compiler explorer is very easy to extend with other toolchains and that Matt Godbolt is a very nice person.

I extended Godbolt's Gcc Explorer adding other toolchains (Motorola 68000 and MIPS, built with crosstools-ng) beside the standard AMD64 one, and released as a Docker image.

I did this because... I had to read and write M68k code for a class, and having GCC generate code for me (with -O0 and the colourisation feature) was the easiest way to get some code to read, besides the very basic examples)

In case you have to work with MIPS or M68K, you can find my "version" here: https://hub.docker.com/r/esantoro/acso-explorer/

IIRC, the bundled gcc is version 4.9.something


This is a fabulous tool for exploring micro-optimizations across a range of CPUs.

I've used it for investigating how some inner loops get pipelined across AVR, ARM+Thumb, ARM32, ARM64, PowerPC, x86-32, and x86-64 processors.


This site is so handy -- if it's useful to you too please Flattr the author so they can continue to host it. It's been a helpful tool to be able to link people to code+assembly when trying to convince people not to "optimize" code in code reviews :).


Excellent!

LLVM used to have an online compiler page but IIRC they took it down due to security concerns.

Of course I have a couple of suggestions ;) :

What this needs is synchronized scrolling ala http://stackoverflow.com/questions/21410675/getting-the-orig...

And would be nice if it can show intermediate steps (the AST, the IR) in parallel or show different optimisation levels beside each other too.


Please feel free to file some suggestions at https://github.com/mattgodbolt/gcc-explorer/issues :)


Some of the examples are broken because they use C++ language constructs but they're being compiled as C code, which leads to error messages like:

  13 : error: 'static_cast' undeclared (first use in this function)
     input = static_cast<int*>(__builtin_assume_aligned(input, 64));
             ^


Remove the -xc option. But agreed, it'd be nice if that kind of thing would be automatic, at least for the supplied examples.


The supplied examples by design don't override the settings you've chosen: this lets you play independently with the text and the settings. It seems the original link here on HN was to a canned example with settings for C, which I think caused the confusion.


Suggestion: Add a switch to show C/C++ code lines next to the created assembly. This is very helpful for learning.

In gdb you can get this with disassemble /m, or with objdump -S.

Helped me a lot in the past.


The "colourise" option does that, kind-of.


Suggestion: make the opcodes clickable, leading the user to the documentation of the opcode.


A slight problem with that is that the definitive documentation for the opcodes are gigantic PDF manuals that may be hard to obtain for some architectures (e.g. ARM-ARM).

There are some assembly opcode reference manuals on the internet but they're of varying quality and typically cover only one instruction set per site.


If this site steps up and offers to provide an easily searchable documentation interface, I imagine people will immediately help out keeping the docs up to date.


This is exactly why it is useful :)


Great tool! I sometimes do the same locally to check out language behaviour, but most of the time it's just one compiler. This tool lets me see compiler differences and the evolution between compiler versions. Nice.


I've used this to help friends fudge their CS homework in a CS class.

It's an assembly class that's impossible since you aren't taught, so they can write their labs in C and decompile it to make it easy.


Isn't compiler generated assembly really easy to tell apart from hand written assembly?


Good handwritten Asm is extremely different from compiler output. For a class that is likely to be "mimic what a compiler does" (which isn't the point of using Asm, but I digress...), probably not.


Well, there are two types of students who pass this class:

a) Those who know someone who took it. b) Those who have a chegg account.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: