Zilliqa / scilla-compiler

Compile Scilla to LLVM-IR
GNU General Public License v3.0
8 stars 4 forks source link
llvm llvm-ir scilla scilla-compiler scilla-vm

Scilla Compiler

Build Status License

Introduction

A compiler to translate Scilla to LLVM-IR. Scilla transitions in the generated LLVM-IR can be compiled to a shared library and executed using ScillaRTL. The project is under active development and is not intended for production use yet.

Building

Prerequisites:

LLVM

The Scilla compiler requires LLVM-13 to be installed on your system. Refer to https://apt.llvm.org/ on how to install LLVM-13.

Building LLVM from Source (Optional)

Instructions to build LLVM from source If you are building LLVM from source, it must be built with OCaml support. First, you need to install the requirements in your OCaml switch: ``` opam install ctypes ocamlfind ``` To install the OCaml bindings to your local opam directory, the following CMake configuration flags must be provided to LLVM: - `-DLLVM_OCAML_INSTALL_PATH="/your/opam/switch/lib"`: change the value based on your [OCaml switch](https://github.com/Zilliqa/scilla/blob/master/INSTALL.md#installing-opam-packages). The built OCaml bindings will be installed to this path. - `-DLLVM_ENABLE_RTTI=ON`: This is required by ScillaRTL. - `-G "Ninja"` to build LLVM using `ninja` instead of `make`. This is not necessary, but is usually faster. Check if your LLVM bindings are built successfully: - `ninja check-llvm-bindings-ocaml`. Install the bindings to your opam switch: - `ninja bindings/ocaml/install` For convenience and CI purposes [scripts/build_install_llvm.sh](./scripts/build_install_llvm.sh) has been provided which downloads and builds LLVM in `${HOME}` and installs it to the current opam switch. You can modify and use it as necessary.

Install Scilla_base and other dependencies

The compiler depends on Scilla base, which can be installed by following the instructions here After installing Scilla_base, run the following.

Build and test the Compiler

To build and obtain the executables in the project's bin directory:

If you are using LLVM from a non-system path (because you built it yourself, for example) then the environment variable LIBRARY_PATH must be set to the directory that contains built LLVM libraries.

Installing the compiler to your opam switch

This will install the compiler binaries to your current opam switch. This step is not usually necessary to try out and use the compiler.

This will uninstall Scilla compiler installed with the previous command.

Compiling Scilla to LLVM-IR

LLVM-IR generated from this compiler can be compiled and linked into a shared library (clang -shared) and executed using ScillaRTL. (If you didn't install the compiler to your opam switch, you can run the binaries directly from the bin directory).

Compile a full Scilla contract:

Compile a pure Scilla expression:

Testsuite

The testsuite includes both Scilla expressions and full contracts for which LLVM-IR is generated and compared against pre-generated text.