(originally published on May 9, 2018)
Most of the updates for this release compared to RC1 are incremental, relating to improved performance, some optimisations on code elimination and code size, as well as some extended support for C++ constructs.
In addition, individual classes and functions can be tagged using Cheerp custom attributes (
[[cheerp::asmjs]]), to determine how they will be compiled. As an example, see this code snippet which can be compiled to WebAssembly:
Any method tagged with
As an example, consider this C++ code:
Here, the user wants to interact with the DOM to show a message to the user, while compiling some heavy computation code in WebAssembly for performance reasons. If compiled with the
-cheerp-mode wasmflag, Cheerp will try to compile the entire code to WebAssembly, which cannot directly access the DOM. As a result, you will get this error at compile time:
interop.cpp:7:19: error: Cheerp: Method 'getElementById' of object client::document of non-wasm type 'client::Document' cannot be called in the wasm section
interop.cpp:7:46: error: Cheerp: Method 'set_textContent' of object client::document.getElementById("testDiv") of non-wasm type 'client::HTMLElement *' cannot be called in the wasm section
2 errors generated.
Fixing this is very easy, the user only needs to add the
[[cheerp::genericjs]] tag to the writeMessageToDom function. Changing the signature of the function to something like this:
[[cheerp::genericjs]] void writeMessageToDom(const char* str)
will allow the code to compile correctly.
Other updates in Cheerp 2.0-RC2
Other updates comping with Cheerp 2.0-RC2 are:
- Introduced Identical Code Folding to remove duplicated code in WebAssembly and asm.js
- New size optimisations for the WebAssembly target
Cheerp 2.0-RC2 is available to download for Linux, Windows and macOS at https://leaningtech.com/cheerp/download/. To get started with Cheerp, please visit the main GitHub project page. You will find instructions on how to download, install and use Cheerp, as well as step-by-step tutorials.
Want to know more?
For more information on how Cheerp, check out our website at https://leaningtech.com/cheerp/. Follow us on twitter (@leaningtech), visit our website, and our main Documentation page for more information.