> Notice: This project is not being actively worked on. If you're interested to pick it up, let me know. See [#12](https://github.com/ts-llvm/ts-llvm/issues/12). # ts-llvm [![Build Status](https://travis-ci.org/ts-llvm/ts-llvm.svg?branch=master)](https://travis-ci.org/ts-llvm/ts-llvm) ts-llvm is a compiler for [TypeScript](https://www.typescriptlang.org/) that generates [LLVM](https://llvm.org/) code, which can then be optimized using all existing LLVM optimizations, and converted further into e.g. native code, WebAssembly, or JavaScript (using [emscripten](https://github.com/kripken/emscripten)). It uses the TypeScript [Compiler API](https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API) to parse and typecheck the input TypeScript code. The resulting TypeScript AST is transformed into LLVM IR using the [llvm-node](https://github.com/MichaReiser/llvm-node) bindings. ts-llvm also provides a runtime library written in C++ that implements native replacements for built-in TypeScript APIs such as `console.log`. ts-llvm is still in very early stages of development. For example, it cannot yet compile most TypeScript programs and it doesn't yet do any garbage collection. If you're willing to contribute, any help will be greatly appreciated. For questions you can create a GitHub issue or ask on the [ts-llvm Slack](https://join.slack.com/t/ts-llvm/shared_invite/enQtMzU4MjQwMjI4MzUzLTk3M2VjYWU4MjA3MzIxMGIxMTJkMDg0ODdlZWNlNzg1ZDBkMjRiMjJmMzc2ZDYwZTYxMTg3NzVlMmJlY2JiNDg). Check out the [language features roadmap](https://github.com/ts-llvm/ts-llvm/issues/6) and the [standard library roadmap](https://github.com/ts-llvm/ts-llvm/issues/7) to see what has been implemented so far, and what still needs to be implemented for the v1.0 release. ## Goals - Compile a strictly-typed subset of TypeScript to LLVM IR. - Use the TypeScript compiler API to parse and type-check the input code. - Implement the JavaScript standard library (such as the array and string types) in C++/C/Rust to allow TypeScript code compiled using ts-llvm to use it. - Experiment with ideas such as Node Addons written in TS compiled to native code using ts-llvm, with autogenerated JS/TS bindings. - Don't add new features to TypeScript, such as integer types or manual memory management. ## Related projects - [StaticScript](https://github.com/ovr/StaticScript), another TypeScript to LLVM compiler. - [AssemblyScript](https://github.com/AssemblyScript/assemblyscript), a TypeScript to WebAssembly compiler. - [Speedy.js](https://github.com/MichaReiser/speedy.js), a JavaScript subset to WebAssembly compiler. Uses the TypeScript compiler API. ## Building from source 1. You need to have LLVM installed on your system. 2. Run `npm install` to install other dependencies. If llvm-config is not on your PATH, you may need to tell llvm-node where to find LLVM on your system, e.g. by running `npm config set cmake_LLVM_DIR $(path-to-llvm/bin/llvm-config --cmakedir)` before `npm install`. 3. If you want ts-llvm to generate native code, you need to have [`llc`](https://llvm.org/docs/CommandGuide/llc.html) and `g++` (any C++ compiler) on your PATH. `llc` will not be required once llvm-node gains support for the LLVM legacy PassManager and addPassesToEmitFile APIs. `g++` will not be required once ts-llvm learns to detect the system C++ compiler on its own. Once everything above is set up, you can use the following commands: - `npm run build` will build the ts-llvm compiler in the `build` directory. - `npm start` will run the ts-llvm compiler. You can pass arguments to the compiler after two consecutive hyphens: e.g. `npm start -- --help` will print the compiler's usage information. - `npm test` will run the test suite. ts-llvm uses [snapshot testing](https://sqa.stackexchange.com/questions/29696/what-is-snapshot-testing) to test the output LLVM IR code. Use `npm run updateSnapshots` to update the snapshot files. ## License ts-llvm is licensed under the MIT license.