Coder Social home page Coder Social logo

woxjro / lltz Goto Github PK

View Code? Open in Web Editor NEW
13.0 4.0 1.0 507 KB

LLTZ: Compiler from MLIR to Michelson

License: MIT License

Rust 74.42% C 0.38% C++ 21.24% CMake 2.62% Shell 0.47% MLIR 0.87%
blockchain llvm tezos michelson tezos-blockchain mlir compiler smartcontracts web3 language programming-language rust vm stackmachine

lltz's Introduction

LLTZ: Compiler from MLIR to Michelson

github build status license
lltz-logo

[WIP] LLTZ is a compiler from MLIR to Michelson, VM of blockchain Tezos.

Table of contents

Features

  • Reusable and readable intermediate representation Michelson Dialect
  • Compilation method with easy analysis and practical gas consumption
  • World's first compiler from MLIR to a blockchain VM
lltz_overview

Motivation

A Domain-Specific Language (DSL) is generally necessary to write smart contracts. These DSLs have contributed to the advancement of blockchain technology. However, these impose a high learning cost on developers, becoming a barrier to entry into blockchain ecosystems such as Tezos.

To address this issue and enable smart contract development using general-purpose programming languages, I've developed LLTZ as a first step. This compiler compiles MLIR, an intermediate representation defined by the LLVM compiler infrastructure, into Michelson. Unlike LLVM IR, JVM and WebAssembly, MLIR provides a higher level of abstraction with control structures and types and allows the definition of custom intermediate representations for specific domains through a feature called Dialect.

If smart contracts can be written in a general-purpose programming language, a single program can run both off-chain and on-chain.

Prerequisites

  • Working C and C++ toolchains(compiler, linker)
  • cmake
  • make or ninja
  • tezos-client: Only required for running tests.

Supported OS

This software has been tested and verified to work correctly on the following operating systems:

  • Ubuntu 22.04.2 LTS

Clone LLTZ

git clone --recursive https://github.com/woxjro/lltz
cd lltz

Build & Usage

Build LLVM and MLIR:

$ cd llvm-project
$ mkdir build && cd build
$ cmake -G Ninja ../llvm \
    -DCMAKE_BUILD_TYPE=Release \
    -DLLVM_ENABLE_PROJECTS=mlir \
    -DLLVM_BUILD_EXAMPLES=ON \
    -DLLVM_TARGETS_TO_BUILD=X86 \
    -DCMAKE_BUILD_WITH_INSTALL_RPATH=ON \
    -DCMAKE_EXPORT_COMPILE_COMMANDS=YES \
    -DLLVM_CCACHE_BUILD=ON \
    -DLLVM_CCACHE_DIR=$CCACHE_DIR \
    -DCMAKE_C_COMPILER=clang-15 \
    -DCMAKE_CXX_COMPILER=clang++-15
$ cmake --build . --parallel 7 --target check-mlir

Build michelson-mlir-opt and michelson-mlir-lsp-server:

$ pwd
<path/to/lltz>
$ cd mlir && mkdir build && cd build
$ cmake -G Ninja .. \
    -DMLIR_DIR=$PWD/../../llvm-project/build/lib/cmake/mlir \
    -DCMAKE_EXPORT_COMPILE_COMMANDS=YES
$ cmake --build .

There are sample and test code under the examples directory.

You can compile them by the following command.

$ cargo run --bin cli -- --input ./examples/mlir/boomerang.mlir

To show details, run the following command.

$ cargo run --bin cli -- --help

Contributing

This project is currently in the Proof of Concept (PoC) stage. Contributions are kindly requested to be postponed until further notice.

lltz's People

Contributors

woxjro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

gmh5225

lltz's Issues

TODO

概観

$$ \texttt{LLVM IR} \rightarrow \texttt{LLTZ IR} \rightarrow \texttt{Michelson} $$

方針

とりあえず,front-end(FE)とback-end(BE)はjsonでつなぐ.
FEをC++で書いて,CFGの情報などjsonで出力して,BEに渡す.

TODO

  • front-end
    • CFG の復元
    • Metadata を用いたMichelson プリミティブの復元
  • back-end
    • (重要)即値とレジスタを区別するように変更する.
    • 未対応の命令の実装(優先度低)
      • phi 関数のサポートについて考える.
  • michelson-ast の実装
  • TransferTokens の型引数サポート
  • 最適化
    • mem2reg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.