Skip to content

Commit cd6b176

Browse files
authored
Disassembler (#166, DFI-455)
* Move disassembler. * Refactoring. * Added disassemble documentation.
1 parent c05cab2 commit cd6b176

68 files changed

Lines changed: 4711 additions & 928 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 78 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

compiler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ rand = "0.7.3"
2929
log = "0.4.8"
3030
termcolor = "1.1.0"
3131
reqwest = { version = "0.10.4", features = ["blocking", "json"] }
32+
itertools = "0.9.0"
3233

3334
[dev-dependencies]
3435
ds = { path = "../data-source", package = "dvm-data-source" }

compiler/src/cmd/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::manifest::MoveToml;
44
use crate::mv::builder::Builder;
55
use crate::mv::dependence::loader::make_rest_loader;
66

7+
/// Execute build command.
78
pub fn execute(project_dir: &Path, manifest: MoveToml) -> Result<()> {
89
let loader = make_rest_loader(&project_dir, &manifest)?;
910
let builder = Builder::new(project_dir, manifest, &loader, true, true);

compiler/src/cmd/check.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::manifest::MoveToml;
44
use crate::mv::builder::Builder;
55
use crate::mv::dependence::loader::make_rest_loader;
66

7+
/// Execute check command.
78
pub fn execute(project_dir: &Path, manifest: MoveToml) -> Result<()> {
89
let loader = make_rest_loader(project_dir, &manifest)?;
910
let builder = Builder::new(project_dir, manifest, &loader, true, true);

compiler/src/cmd/init.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::path::Path;
44
use crate::manifest::{MANIFEST, MoveToml, store_manifest, Layout};
55
use std::fs;
66

7+
/// Execute init command.
78
pub fn execute(
89
project_dir: &Path,
910
source_dir: String,

compiler/src/cmd/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
/// Project builder.
12
pub mod build;
3+
/// Project checker.
24
pub mod check;
5+
/// Project initializer.
36
pub mod init;
7+
/// Project creator.
48
pub mod new;
9+
/// Project dependencies loader.
510
pub mod update;

compiler/src/cmd/new.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::path::Path;
44
use std::fs;
55
use crate::cmd::init;
66

7+
/// Execute create project command.
78
pub fn execute(
89
root: &Path,
910
source_dir: String,

compiler/src/cmd/update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::path::Path;
33
use crate::manifest::MoveToml;
44
use std::fs;
55

6+
/// Execute update dependencies command.
67
pub fn execute(project_dir: &Path, manifest: MoveToml) -> Result<(), Error> {
78
let cache_path = manifest
89
.layout

compiler/src/embedded/ds_loader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::mv::dependence::loader::BytecodeSource;
1+
use crate::mv::dependence::loader::BytecodeLoader;
22
use anyhow::Result;
33
use libra::prelude::*;
44

@@ -16,7 +16,7 @@ where
1616
}
1717
}
1818

19-
impl<S> BytecodeSource for StateViewLoader<S>
19+
impl<S> BytecodeLoader for StateViewLoader<S>
2020
where
2121
S: StateView + Clone,
2222
{

compiler/src/embedded/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::manifest::{MoveToml, Layout};
1313
use std::fs::OpenOptions;
1414
use std::io::Write;
1515

16+
/// Embedded move compiler.
1617
#[derive(Clone)]
1718
pub struct Compiler<S: StateView + Clone> {
1819
loader: Option<Loader<StateViewLoader<S>>>,
@@ -22,12 +23,14 @@ impl<S> Compiler<S>
2223
where
2324
S: StateView + Clone,
2425
{
26+
/// Create move compiler.
2527
pub fn new(view: S) -> Compiler<S> {
2628
Compiler {
2729
loader: Some(Loader::new(None, StateViewLoader::new(view))),
2830
}
2931
}
3032

33+
/// Compile multiple sources.
3134
pub fn compile_source_map(
3235
&self,
3336
source_map: HashMap<String, String>,
@@ -69,6 +72,7 @@ where
6972
builder.verify(text_source, units)
7073
}
7174

75+
/// Compiler source codes.
7276
pub fn compile(&self, code: &str, address: Option<AccountAddress>) -> Result<Vec<u8>> {
7377
let mut source_map = HashMap::new();
7478
source_map.insert("source".to_string(), code.to_string());
@@ -81,11 +85,14 @@ where
8185
}
8286
}
8387

88+
/// Temp directory.
89+
/// Random temporary directory which will be removed when 'TempDir' drop.
8490
pub struct TempDir {
8591
path: PathBuf,
8692
}
8793

8894
impl TempDir {
95+
/// Create a new temporary directory.
8996
pub fn new() -> Result<TempDir> {
9097
let dir = env::temp_dir();
9198
let mut rng = rand::thread_rng();
@@ -98,6 +105,7 @@ impl TempDir {
98105
Ok(TempDir { path })
99106
}
100107

108+
/// Returns the directory path.
101109
pub fn path(&self) -> &Path {
102110
&self.path
103111
}
@@ -116,11 +124,13 @@ impl Drop for TempDir {
116124
}
117125
}
118126

127+
/// Compiler string with move source code.
119128
pub fn compile(code: &str, address: Option<AccountAddress>) -> Result<Vec<u8>> {
120129
let compiler = Compiler::new(ZeroStateView);
121130
compiler.compile(code, address)
122131
}
123132

133+
/// State view mock.
124134
#[derive(Clone)]
125135
struct ZeroStateView;
126136

0 commit comments

Comments
 (0)