-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cleanup print number of program blocks in the script change path to string refactor refactor more refactor based on review remove debug rebase next rename binary to mvt
- Loading branch information
Showing
5 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ members = [ | |
"miden", | ||
"processor", | ||
"stdlib", | ||
"tools", | ||
"verifier" | ||
] | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use assembly::Assembler; | ||
use vm_core::ProgramInputs; | ||
|
||
#[derive(Debug, PartialEq)] | ||
pub struct ProgramInfo { | ||
total_vm_cycles: usize, | ||
} | ||
|
||
impl ProgramInfo { | ||
///Creates a new ProgramInfo object | ||
pub fn new(total_vm_cycles: usize) -> ProgramInfo { | ||
Self { total_vm_cycles } | ||
} | ||
|
||
///Get total vm cycles to execute a program | ||
pub fn total_vm_cycles(&self) -> usize { | ||
self.total_vm_cycles | ||
} | ||
} | ||
|
||
/// Returns program analysis for a given script string. Returns ProgramInfo with following fields: | ||
/// - total_vm_cycles (vm cycles it takes to execute the entire script) | ||
pub fn analyze(program: String) -> ProgramInfo { | ||
let assembler = Assembler::new(); | ||
let script = assembler.compile_script(&program).unwrap(); | ||
let inputs = ProgramInputs::none(); | ||
let count = processor::execute_iter(&script, &inputs).count() - 1; | ||
ProgramInfo::new(count) | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
|
||
#[test] | ||
fn analyze_test() { | ||
let source = "proc.foo.1 pop.local.0 end begin popw.mem.1 push.17 exec.foo end"; | ||
let program_info: super::ProgramInfo = super::analyze(source.to_string()); | ||
let expected_program_info = super::ProgramInfo::new(24); | ||
assert_eq!(program_info, expected_program_info); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[package] | ||
name = "miden-vm-tools" | ||
version = "0.1.0" | ||
description = "Tools for working with Miden VM" | ||
authors = ["miden contributors"] | ||
readme = "README.md" | ||
license = "MIT" | ||
repository = "https://github.com/maticnetwork/miden" | ||
edition = "2021" | ||
rust-version = "1.60" | ||
|
||
[dependencies] | ||
miden = { path = "../miden", version = "0.2", default-features = false } | ||
structopt = { version = "0.3", default-features = false } | ||
|
||
[[bin]] | ||
name = "mvt" | ||
path = "src/main.rs" | ||
bench = false | ||
doctest = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use miden::tools::{analyze, ProgramInfo}; | ||
use structopt::StructOpt; | ||
|
||
#[derive(StructOpt)] | ||
struct Args { | ||
/// Script Source File Path | ||
path: String, | ||
} | ||
|
||
fn main() { | ||
let args = Args::from_args(); | ||
//reads input masm file | ||
let program = std::fs::read_to_string(&args.path).expect("Could not read source file"); | ||
let program_info: ProgramInfo = analyze(program); | ||
let total_vm_cycles = program_info.total_vm_cycles(); | ||
println!("Total Number of VM Cycles: {total_vm_cycles}"); | ||
} |