1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use anyhow::Context;
use bytecode_source_map::source_map::SourceMap;
use ir_to_bytecode::{
compiler::{compile_module, compile_script},
parser::{parse_module, parse_script},
};
use move_binary_format::file_format::{CompiledModule, CompiledScript};
use move_symbol_pool::Symbol;
use std::{fs, path::Path};
pub fn do_compile_script(
source_path: &Path,
dependencies: &[CompiledModule],
) -> (CompiledScript, SourceMap) {
let source = fs::read_to_string(source_path)
.with_context(|| format!("Unable to read file: {:?}", source_path))
.unwrap();
let file = Symbol::from(source_path.as_os_str().to_str().unwrap());
let parsed_script = parse_script(file, &source).unwrap();
compile_script(parsed_script, dependencies).unwrap()
}
pub fn do_compile_module(
source_path: &Path,
dependencies: &[CompiledModule],
) -> (CompiledModule, SourceMap) {
let source = fs::read_to_string(source_path)
.with_context(|| format!("Unable to read file: {:?}", source_path))
.unwrap();
let file = Symbol::from(source_path.as_os_str().to_str().unwrap());
let parsed_module = parse_module(file, &source).unwrap();
compile_module(parsed_module, dependencies).unwrap()
}