Cheerp an open source compiler from C/C++ to WebAssembly and JavaScript


Cheerp: A C++ Compiler for the Web

It was recently announced Cheerp 3.0 release, a compiler that allows you to compile any C/C++ code into WebAssembly or JavaScript. The new branch is notable for moving the compiler and accompanying libraries to use permissive Apache 2.0 and LLVM licenses, rather than the previously applied limited license policy, which offers a GPLv2 license option for non-commercial projects and a license owner for commercial projects.

Cheerp can be used both to port existing C/C++ applications and libraries to run in the browser, or to create high-performance web applications and WebAssembly components from scratch.

It's been over a year since the previous release of Cheerp ( Cheerp 2.7 ), and this new version is packed with new features and optimizations that, once again, move the state of the art of using C++ as a programming language for Web applications. and games.

Most importantly, with this release we are making a significant change to Cheerp's licensing model. As of Cheerp 3.0, all core compiler components and libraries are now permissively licensed under the Apache 2.0/LLVM license. This marks a radical departure from our previous GPLv2/dual commercial license model, allowing Cheerp 3.0 to be used for any purpose, without restriction.

About Cheerp

The project allows you to combine C/C++ code and JavaScript in a web application with the ability to access from JavaScript code to functions originally developed in C/C++, and from C/C++ code to JavaScript objects, JavaScript libraries, Web APIs, and all DOM features, as well as allowing you to create mixed builds, part of the code which compiles to JavaScript and parts to WebAssembly. Supports build projects that use the standard libc and libc++ libraries.

Compared to the Emscripten compiler, Cheerp generates more optimized and compact WebAssembly intermediate code (On average, the resulting file sizes are 7% smaller.)

Conceptually, the differences boil down to the fact that script is used as the object format of WebAssembly and performs binding and optimization in the post-processing stage of WebAssembly (wasm-opt). Cheerp uses LLVM bytecode as an intermediate representation for libraries and object files, allowing for broader project-wide optimizations using LLVM-level metadata without the need for post-processing.

Related article:
Emscripten 3.0, a build toolchain for WebAssembly using LLVM

In addition, Cheerp uses the PreExecuter optimizer to preemptively execute code at compile time, for example, to convert constructors used to initialize global objects to constants. In addition, PartialExecuter is used during compilation, which, based on parsing the function's parameters, removes code that is guaranteed not to be used at execution.

Cheerp can also generate JavaScript code to work dynamically with memory. covered by the garbage collector. In particular, instead of emulating a traditional address space with typed arrays, Cheerp provides a direct mapping from C++ objects to JavaScript objects, which reduces memory consumption because the JavaScript garbage collector has the ability to remove unused objects. To improve performance, the generated WebAssembly intermediate code uses SIMD extensions to orchestrate the parallelization of data operations.

Cheerp can be used as a platform to build embedded web applications client/server in C++. In current practice, it is common to develop a separate browser-based front-end written in JavaScript and a separate back-end written in PHP, Python, Ruby, or JavaScript/Node.js.

Cheerp provides the means to build complete C++ web applications that support both backend and frontend in a single code base.

During the build process, the server-side is compiled to native code, and the interface is converted to a JavaScript representation. Debugging of all project components, including those converted to JavaScript, is carried out using C++ source texts using Source Map technology.

Finally, if you are interested in knowing more about it, you can check the details in the following link

The compiler code is based on the LLVM and Clang developments and includes additional optimizations to improve performance and reduce the size of the compiled output.

The content of the article adheres to our principles of editorial ethics. To report an error click here.

Be the first to comment

Leave a Comment

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



  1. Responsible for the data: AB Internet Networks 2008 SL
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.