Libra

Libra

  • 文档
  • 社区
  • 博客
  • libra-china.org
  • GitHub

›READMEs

学习 Libra

  • 欢迎
  • Libra协议: 核心概念
  • 交易生命周期
  • Technical Papers

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

体验 Libra Core

  • 第一笔交易!
  • Move语言初体验

社区

  • 开源:Libra区块链的基础
  • 贡献代码
  • Coding Guidelines
  • Reporting Vulnerabilities

Libra 代码库

  • Libra Core 概要
  • READMEs

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

参考

  • 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 verifer at the end of compilation.

Command-line options

USAGE:
    compiler [FLAGS] [OPTIONS] 

FLAGS:
    -h, --help         Prints help information
        --no-stdlib    Do not automatically compile stdlib dependencies
        --no-verify    Do not automatically run the bytecode verifier
    -s, --script       Treat input file as a script (default is to treat file as a module)
    -V, --version      Prints version information

OPTIONS:
    -o, --output     Serialize and write the compiled output to this file

ARGS:
        Path to the Move IR source to compile

Example Usage

To compile a *.mvir file:

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 a *.mvir module file:

compiler a.mvir

To compile and verify a *.mvir transaction script file:

compiler -s *.mvir

Folder Structure

 *
 |- parser/
    |- 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.
 |- compiler.rs       # Main compiler logic - converts an AST generated by `syntax.rs` to a `CompiledModule` or `CompiledScript`.
 |- 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
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