OpenSource For You

This article gives an introducti­on to Emscripten, an LLVM to the JS compiler.

-

Imagine that you have a very large project written in CLCHH, and you now want it in JavaScript, so as to port it to the Web. You might ask, “Why in JavaScript?” Well, you can run applicatio­ns written in high-level languages, but you need to install many plugins for that and it doesn’t always work as expected. JavaScript is currently supported in almost all Web browsers. With the coming of Node.js and mongoDB, and an array of other JavaScript-based front-ends and back-ends, it makes sense to port your favourite app. Rewriting the code in Java Script is too tedious, so Emscripten is the tool that you are looking for.

Emscripten is an open source LLVM (low-level virtual machine) to the JavaScript compiler, using which you can compile C and CHH code into JavaScript! This avoids the need to rewrite code. $ mkdir /path/to/clang-build $ cd /path/to/clang-build $ svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm $ cd llvm/tools $ svn co http://llvm.org/svn/llvm-project/cfe/trunk clang $ cd ../.. $ mkdir build $ cd build $ ../OOvP/cRnfiJure –enaEOe-RStLPL]ed –dLVaEOe-aVVertLRnV $ make && sudo make install

Node.js (0.5.5 or above): To run the back-end JavaScript, it needs to be interprete­d and executed, which is what Node.js does. We can clone Node.js from the git client:

$ git clone https://github.com/joyent/node.git

After cloning, you need to build it, as follows: $ cd node $ ./cRnfiJure $ make $ sudo make install

Now that you are ready with the prerequisi­tes, set up Emscripten. Check if Clang and Node work perfectly—go to the Emscripten directory, and run the following command: $ clang tests/hello_world.cpp $ ./a.out

 ??  ??

Newspapers in English

Newspapers from India