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.