open
close
Libra

Libra

White Paper
  • Vision
  • Association
  • Developers
  • Learn
  • Media
  • White Paper

Developers

/Libra Docs
  • Overview
  • Libra Docs
  • Governance
  • Community
  • GitHub
open
close

›READMEs

Learn About Libra

  • Welcome
  • Libra Protocol: Key Concepts
  • Life of a Transaction
  • Technical Papers

    • The Libra Blockchain
    • Move: A Language With Programmable Resources
    • State Machine Replication in the Libra Blockchain

Try Libra Core

  • My First Transaction
  • Getting Started With Move
  • Run a Local Network
  • Run Move Programs Locally

Community

  • Libra Open Source
  • Contribution Guide
  • Coding Guidelines
  • Reporting Vulnerabilities

Libra Codebase

  • Libra Core Overview
  • READMEs

    • Admission Control
    • Bytecode Verifier
    • Consensus
    • Crypto
    • Mempool
    • Move IR Compiler
    • Move Language
    • Network
    • Storage
    • Virtual Machine

Reference

  • Libra CLI
  • Glossary
Edit

Move IR Compiler

Summary

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

Overview

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

USAGE:
    compiler [FLAGS] [OPTIONS] 

FLAGS:
    -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 script)
        --no-stdlib            Do not automatically compile stdlib dependencies
        --no-verify            Do not automatically run the bytecode verifier
    -V, --version              Prints version information

OPTIONS:
    -a, --address 
Account address used for publishing --deps Path to the list of modules that we want to link with -o, --output Serialize and write the compiled output to this file ARGS: 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.
│           ├── lexer.rs        # Lexer for the Move IR language.
|           └── syntax.rs       # Parser for the Move IR language.
└── src
    ├── main.rs                 # Compiler driver - parses command line options and calls the parser, compiler, and bytecode verifier.
    └── util.rs                 # Misc compiler utilities.
← MempoolMove Language →
  • Summary
  • Overview
  • Command-line options
    • Example Usage
  • Folder Structure
Libra
Learn About Libra
Welcome to LibraLibra ProtocolLibra BlockchainLife of a Transaction

Try Libra Core
My First TransactionGetting Started With Move
Policies
Privacy PolicyTerms of UseCookies PolicyCode of Conduct

Community
Developer ForumNewsletter
Social
libra
Follow @libradev
© Libra Association

To help us provide relevant content, analyze our traffic, and provide a variety of features, we use cookies. By clicking on or navigating the site, you agree to allow us to collect information on and off the Libra Website through cookies. To learn more, view our Cookie Policy:

Cookies Policy