Libra 中文文档|深入浅出区块链

Libra 中文文档|深入浅出区块链

  • 首页
  • 文档
  • Blog
  • Libra官网
  • GitHub

›模块

学习 Libra

  • 来到 Libra 世界
  • Libra 协议核心概念
  • 交易的生命周期
  • 技术论文

    • Libra 区块链
    • Move: 可编程资源语言
    • Libra区块链中的状态机复制

理解 Libra 要点

  • Libra上的第一笔交易
  • 了解 Move 语言

Libra 协议实现

  • Libra Core 概要
  • 模块

    • 准入控制(AC)
    • 字节码验证程序
    • 共识协议
    • 加密组件
    • 执行组件
    • 内存池 Mempool
    • Move IR 编译器
    • Move 编程语言
    • 网络 Network
    • 存储模块 Storage
    • 虚拟机

参考引用

  • Libra CLI 命令指南
  • 词汇表

社区

  • Libra 开放源码
  • 贡献指南
  • 编码指南
  • 报告漏洞
Edit

Move IR 编译器

摘要

Move IR编译器将Move IR编译为其字节码表示形式。

概要

Move IR编译器把Move语言编写模块和脚本编译为对应以字节码表示形式,有两种数据类型用于表示这些输出: CompiledModule 和 CompiledScript. 这些数据类型在 file_format.rs 中有定义.

除了把Move IR转换为Move字节码之外,编译器也可以作为字节码验证器当作一个测试工具。 因此,它的字节码程序输出会尽可能与输入IR接近; 在编译过程中,不会执行优化和高级语义检查。事实上,即使是 Move IR 语义上无效的代码也会对应的字节码程序, 然后由 bytecode verifier 验证编译后的字节码的语义. 编译器命令行在编译结束时自动调用字节码验证器。

命令行选项

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

用法示例

编译 *.mvir 文件:

cargo build -—bin compiler

  • 这将构建 编译器+验证器 二进制文件。
  • 二进制文件可以在 libra/target/debug/compiler 找到.
  • 此外,二进制文件也可以直接使用 cargo run -p compiler 运行.

编译并验证 *.mvir 模块文件:

compiler a.mvir

编译并验证 *.mvir 交易脚本文件:

compiler -s *.mvir

文件夹结构

 *
 |- 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 编程语言 →
  • 摘要
  • 概要
  • 命令行选项
    • 用法示例
  • 文件夹结构
Libra 中文文档|深入浅出区块链
Learn About Libra
Welcome to LibraLibra ProtocolLibra BlockchainLife of a Transaction

Try Libra Core
My First TransactionGetting Started With Move
Libra开发者社区
备注 "Libra" 加群
Libra 中文文档 | 深入浅出区块链社区翻译,未经许可请勿转载 |