Online compilers – all integrated into Compiler Explorer – what a great idea

Online compilers - all integrated into Compiler Explorer - what a great idea

A compiler is a program that translates source code written in a high-level programming language (such as C, C++, Java, and so on) into a low-level language, usually machine code or an intermediate language, that can be executed directly from a computer processor. In another article we saw all the differences between compiled and interpreted languages. A online compiler It’s especially useful for those who want to quickly try out small snippets of code, experiment, or learn a new programming language without having to set up a full development environment.

The projects open source they offer the possibility to examine the program source code and verify, for example, that binary files published on online stores or developer websites are actually produced from publicly shared programming code.

In all those cases where the source code is not available, the in-depth study of the functioning of an application becomes more complicated and requires an activity reverse engineering. In this regard, there are several ways to decompile an executable file tool which help recreate the high-level code or a representation as close to it as possible.

Compiler Explorer, an intelligent online compiler that supports 70 programming languages

One of the projects that literally leaves even those who have been dealing with it for years speechless software developmentand Compiler Explorer.

As soon as the application’s home page is opened, on the left there is a box containing the programming code while on the right theoutput compiled, usually in Assembly language.

Online compiler: how Compiler Explorer works

Compiler Explorer supports around 70 different languages, over 2,000 compilers and a wide range of architectures for executing compiled code, including x86, ARM, RISC-V, MIPS, AVR, Tensa, 68k, PowerPC, SPARC and even the historic 6502 architecture .

A tool like Compiler Explorer becomes essential for anyone interested in the world of compilers and, in general,computer architecture and other electronic devices. Since it is a project open source (it is hosted in this GitHub repository), given its very nature, it is even possible to host Compiler Explorer independently to carry out experiments locally, without relying on any remote server.

For what purposes can Compiler Explorer be used?

The author of Compiler Explorer, Matt Godbolt, has already explained in May 2024 what can be done with his powerful tool. We invite you to refer to the content of this YouTube video.

In our article, we limit ourselves to highlighting a few purpose really interesting about this splendid online compiler. First, you can check the codice Assembly generated for the different architectures. For example, what are the differences between the code intended for the x86-64 platform and that “packaged” by a certain compiler for AMD64 and RISC-V?

Indeed, if we are talking about NVIDIA CUDA architecture, Compiler Explorer can return the codice PTX (Parallel Thread Execution). It is a virtual Assembly language used within the programming ecosystem CUDA and created from source code written in high-level programming languages ​​such as C or C++. PTX is used as an intermediate step before generating the target device-specific binary code and is designed to be independent of the specific architecture of the target GPU.

Compiler Explorer operation

Every single Assembly instruction can be studied by leaving the mouse pointer there for a few moments. A simple right click, selecting the item View Assembly documentationallows you to access a series of additional resources.

By default, using the drop-down menu in the left panel, you can choose the programming language and then type or paste the code in the area below.

Choose programming language

On the right, you can instead specify multiple compilers, so as to understand how the same code is rendered in Assembly, sometimes in a significantly different way, depending on the chosen compiler.

Interpreted languages: Compiler Explorer generates the corresponding bytecode

To demonstrate how Compiler Explorer can adapt to any need, the application is not just an online compiler. In fact, it deals with managing the interpreted languagessuch as Python and Ruby, and then show the bytecode product.

Il bytecode it is an intermediate representation of the program that can be executed by an interpreter or by a virtual machine. It consists of a set of platform-independent instructions that can be interpreted or translated into machine language.

In the case of Javafor example, the bytecode is executed on the Java Virtual Machine (JVM), while the C# bytecode on the Common Language Runtime (CLR). The approach allows programs to run on different platforms without having to be recompiled for each of them.

Compiler Explorer also accepts input options to pass to the online compiler, such as optimization flags, debug flags or flags specific to the compiler itself.

With one click on the menu More, Settings, it is possible to adjust parameters such as the behavior of the platform (default language, coloring of elements, keyboard shortcuts, editor functionality, automatic compilation of the source with each modification,…). For cancel customizations and restore the initial configuration of Compiler Explorer, just click More then on the voice Reset code and UI layout.

Opening image credit: – Manfort Surroundings

Leave a Reply

Your email address will not be published. Required fields are marked *