#solana #blockchain

bin+lib solana_libra_compiler

Libra compiler

4 releases

0.0.1-sol5 May 1, 2020
0.0.1-sol4 Oct 25, 2019
0.0.0 Aug 6, 2019
0.0.0-sol15 Jul 27, 2019

#2589 in Magic Beans

Download history 21/week @ 2023-06-13 41/week @ 2023-06-20 23/week @ 2023-06-27 19/week @ 2023-07-04 30/week @ 2023-07-11 24/week @ 2023-07-18 29/week @ 2023-07-25 13/week @ 2023-08-01 21/week @ 2023-08-08 28/week @ 2023-08-15 8/week @ 2023-08-22 11/week @ 2023-08-29 29/week @ 2023-09-05 20/week @ 2023-09-12 11/week @ 2023-09-19 19/week @ 2023-09-26

82 downloads per month
Used in 6 crates (3 directly)


24K SLoC

id: ir-to-bytecode title: Move IR Compiler custom_edit_url: https://github.com/libra/libra/edit/master/language/compiler/README.md

Move IR Compiler


The Move IR compiler compiles the Move IR down to its bytecode representation.


The Move IR compiler compiles modules and scripts written in Move down to their respective bytecode representations. The two data types used to represent these outputs are CompiledModule and CompiledScript. These data types are defined in file_format.rs.

Beyond translating Move IR to Move bytecode, the compiler's purpose is as a testing tool for the bytecode verifier. Because of this, its job is to output bytecode programs that correspond as closely as possible to the input IR; optimizations and advanced semantic checks are specifically not performed during the compilation process. In fact, the compiler goes out of its way to push these semantic checks into the bytecode, and compile semantically invalid code in the Move IR to equivalent---semantically invalid---bytecode programs. The semantics of the compiled bytecode is then verified by the bytecode verifier. The compiler command line automatically calls the bytecode verifier at the end of compilation.

Command-line options

    compiler [FLAGS] [OPTIONS] <source_path>

    -h, --help                 Prints help information
    -l, --list_dependencies    Instead of compiling the source, emit a dependency list of the compiled source
    -m, --module               Treat input file as a module (default is to treat file as a program)
        --no-stdlib            Do not automatically compile stdlib dependencies
        --no-verify            Do not automatically run the bytecode verifier
    -V, --version              Prints version information

    -a, --address <address>       Account address used for publishing
        --deps <deps_path>        Path to the list of modules that we want to link with
    -o, --output <output_path>    Serialize and write the compiled output to this file

    <source_path>    Path to the Move IR source to compile

Example Usage

cargo build --bin compiler

  • This will build the compiler + verifier binary.
  • The binary can be found at libra/target/debug/compiler.
  • Alternatively, the binary can be run directly with cargo run -p compiler.

To compile and verify foo.mvir, which contains a Move IR module:

compiler -m foo.mvir

To compile and verify bar.mvir, which contains a transaction script:

compiler bar.mvir

Folder Structure

compiler                        # Main compiler crate. This depends on stdlib.
├── ir_to_bytecode              # Core backend compiler logic, independent of stdlib.
│   ├── src
│   │   ├── compiler.rs         # Main compiler logic - converts an AST generated by `syntax.rs` to a `CompiledModule` or `CompiledScript`.
│   │   └── parser.rs           # Wrapper around Move IR syntax crate.
│   └── syntax                  # Crate containing Move IR syntax.
│       └── src
│           ├── ast.rs          # Contains all the data structures used to build the AST representing the parsed Move IR input.
│           ├── syntax.lalrpop  # Description of the Move IR language, used by lalrpop to generate a parser.
            └── syntax.rs       # Parser generated by lalrpop using the description in `syntax.lalrpop` - a clean checkout won't contain this file.
└── src
    ├── main.rs                 # Compiler driver - parses command line options and calls the parser, compiler, and bytecode verifier.
    └── util.rs                 # Misc compiler utilities.


~479K SLoC