LLVM and Emscripten: Small Steps towards Platform-Agnostic Programming

posted in: Uncategorized | 0

Programming languages are human-readable languages that produce instructions for a computer to understand. Choosing a programming language, however, is currently tied to a hardware platform (e.g., Android, iOS, Windows, Mac).

Here are some examples of choosing a language that matches its respective hardware platform. For writing an iOS or Mac OS X app, developers write source code in C, Objective-C, and Swift. For Android app development, a developer writes in the Java language. For Windows Phone development, a developer writes in the C# language. For web development, a developer writes in JavaScript (or with CoffeeScript syntactic sugar).

This current approach to writing software takes significant effort because of re-writing the same logic to launch on different hardware platforms. These hardware platforms might have slightly different SDKs and hardware features, but the overall goal is very similar. The added human engineering effort seems misplaced when computers are good at translating programming languages.

Several projects are decoupling the hardware platform and programming language. Here are a few technologies. PhoneGap (Cordova) is a technology that wraps a web browser inside an app, which allows developers to write once in JavaScript. Xamarin SDK writes in C# and cross-compiles to various mobile hardware platforms. And Unity SDK allows games written in C# to run on various mobile hardware platforms. Yet, all of these solutions still tie a specific language to an SDK.

In the foreseeable future, we should decouple the hardware platform and programming language by improving its compiler. Compilers translate programming language code into machine-readable code. Compilers should be able to take many programming languages as input and produce output in any other language. In moving towards this goal, the LLVM compiler can compile C/C++ to JavaScript using the Emscripten plugin. This enables legacy software to run, even after the original hardware is obsolete. Here’s an example of Mac OS emulated in a web browser.

These tools being produced by the open-source community are enabling technologies for platform-agnostic programming. For example, instead of training skilled JavaScript developers for web development, developers will be able to write in the language of their own choice and run in a web browser (e.g., with Python). Developers should not be tied to a programming language in order to target a hardware platform.