What is the Definition of Emscripting

What is the Definition of Emscripting?

Technology Words

Emscripten is the name of a compiler that translates most of the LLVM language into JavaScript. This enables the code of various programming languages ​​to be executed in current browsers.

Emscripten’s job is to compile different languages ​​into each other . The main challenge here is to translate a machine-level source language (LLVM) into another type of language (high-level language). This means that Emscripten is faced with the opposite task that a compiler normally does.

Emscripten is an open source project. It is available under license from MIT and under license from University of Illinois / NCS Open Source (UIUC license). The main developer of the project is Alon Zakai, who is also known for his work for Mozilla. As a term, Emscripten is a neologism from the made-up word embiggen. This is originally from the series “The Simpsons”.

Challenges and special features

Translating a machine-level language into a high-level language involves a number of challenges that differ from other compilers.

JavaScript engines are typically designed for a natural flow of code. This is available in manual source code . However, it is missing in the machine-level LLVM infrastructure. Instead of the branches and loops in handwritten source code, the program sequence is determined by jumps and jump labels.

One of the tasks is therefore to restore the original high-level language. This is the only way to create high-performance JavaScript. Other compilers can adopt high-level language constructs directly. However, their disadvantage is that they can only support a single source language.

In addition, there is a further challenge in implementing the semantics of the source code exactly while still producing a high-performance JavaScript. Not all operations in the LLVM language can be implemented directly in JavaScript.

Connection to the LLVM compiler infrastructure

LLVM is an own name for the project and originally stood as an abbreviation for Low Level Virtual Machine. It no longer has much in common with the original version of a virtual machine. The LLVM project defines the LLVM assembly language.

The LLVM IR (LLVM intermediate representation) represents an abstraction of the machine language for current processors. The code of a certain programming language can be translated into the LLVM language through a front end. A backend can then translate the LLVM into the code of the target platform

In this context, Emscripten takes on the role of the backend. In this way, a large number of original source programming languages ​​can be translated into the language of the target platform (in this case JavaScript). Emscripten can still make use of the code optimization options that LLVM tools already contain ex works.

Execution of languages ​​and possibilities

Basically, two options are conceivable for executing a language using emscripts on the Internet. The LLVM intermediate code generated by an existing front end can either be translated directly into JavaScript. Or the entire runtime environment used to execute the language is ported to JavaScript.

The first-mentioned method is considered to be the more efficient variant. In this way, numerous popular and widely used languages ​​can be translated into JavaScript. However, if there is no front end for a certain language yet, the second method offers an alternative approach.

If the runtime environment of the language was written in a language that is supported by an LLVM frontend, a complete translation to JavaScript is possible. This means that it is possible to run it on the web. The code can be analyzed directly in the browser. It can also be executed in the runtime environment that runs within the JavaScript engine.

Emscripten and its inner functionality

Emscripten was developed as a compiler itself within JavaScript. This goes hand in hand with some usage advantages. Emscripten is able, for example, to simplify numerical expressions by directly evaluating them with eval (). The compiler also displays certain constant structures of the LLVM machine code internally as a JavaScript object.

Emscripten’s compilation work can be viewed in ideal-typical phases. First, the LLVM code is transferred into the internal representation of the code by means of emscripts. This is done via the so-called intertyper.

This internal representation is then examined by the analyzer. This generates information and data that can then be used for optimization. In the last phase, the internal data representation is converted to the desired JavaScript code by the jsifier.

Areas of application and tools

Emscripting can be used under Microsoft Windows as well as under Max OS X and Linux. Requirements for full use of the compiler are the components LLVM, Python and Node.js. There are other tools that make it easier for users to use. This should make it particularly easy to translate existing projects (for example in C and C ++) to JavaScript with Emscripts.

This includes emcc, a kind of replacement for the gcc compiler. This has largely identical calling conventions. In simple use cases, users can simply use emcc instead of the gcc compiler to create projects. Emcc takes care of the generation of the LLVM bit code, using the interfaces available in Emscripts.

The output can take place in JavaScript code or in a JavaScript embedded in an HTML document. Emscripten also offers tools for projects that are developed using ./configure or Makefile. The tools take over the calls of these tools and can configure them in the process.

What is the Definition of Emscripting