Skip to content

Commit

Permalink
feat: add logging to the assembler
Browse files Browse the repository at this point in the history
  • Loading branch information
Fumuran committed Nov 6, 2023
1 parent 01ee16a commit e0ce650
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
3 changes: 2 additions & 1 deletion assembly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ doctest = false

[features]
default = ["std"]
std = ["vm-core/std"]
std = ["vm-core/std", "log/std"]

[dependencies]
log = { version = "0.4", default-features = false, optional = true }
num_enum = "0.7"
vm-core = { package = "miden-core", path = "../core", version = "0.8", default-features = false }
6 changes: 6 additions & 0 deletions assembly/src/assembler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ impl Assembler {
}
}

// log the completion of the module
log::debug!(
"\n - Module \"{}\" has been compiled",
path.unwrap_or(&LibraryPath::anon_path())
);

Ok(proc_roots)
}

Expand Down
7 changes: 7 additions & 0 deletions miden/examples/merkle_store/merkle_store.masm
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use.std::math::u64

begin
# push the root of the Partial Merkle Tree on the stack
push.0x82bb4d9a8e93582f1387611949703eecd8e4c74b904880f9c9c85f1fc1d7576d
Expand Down Expand Up @@ -33,6 +35,11 @@ begin
push.22.0.0.0
assert_eqw



dropw

push.1.2
exec.u64::checked_add

end
3 changes: 2 additions & 1 deletion miden/src/cli/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde_derive::{Deserialize, Serialize};
use std::{
collections::HashMap,
fs,
io::Write,
io::{stdout, Write},
path::{Path, PathBuf},
time::Instant,
};
Expand Down Expand Up @@ -406,6 +406,7 @@ impl ProgramFile {
L: Library,
{
print!("Compiling program... ");
stdout().flush().expect("Couldn't flush stdout");
let now = Instant::now();

// compile program
Expand Down
8 changes: 1 addition & 7 deletions miden/src/cli/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::data::{Debug, InputFile, Libraries, OutputFile, ProgramFile, ProofFil
use clap::Parser;
use miden::ProvingOptions;
use processor::{DefaultHost, ExecutionOptions, ExecutionOptionsError};
use std::{io::Write, path::PathBuf, time::Instant};
use std::{path::PathBuf, time::Instant};

// TODO check if clap is supporting automatic generation of list values of hash function
#[derive(Debug, Clone, Parser)]
Expand Down Expand Up @@ -65,12 +65,6 @@ impl ProveCmd {
println!("Prove program");
println!("============================================================");

// configure logging
env_logger::Builder::new()
.format(|buf, record| writeln!(buf, "{}", record.args()))
.filter_level(log::LevelFilter::Debug)
.init();

// load libraries from files
let libraries = Libraries::new(&self.library_paths)?;

Expand Down
11 changes: 11 additions & 0 deletions miden/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::Parser;
use core::fmt;
use miden::{AssemblyError, ExecutionError};
use std::io::Write;

mod cli;
mod examples;
Expand Down Expand Up @@ -53,6 +54,16 @@ pub fn main() {
// read command-line args
let cli = Cli::parse();

// configure logging
// if logging level is not specified, set level to "warn"
if std::env::var("MIDEN_LOG").is_err() {
std::env::set_var("MIDEN_LOG", "warn");
}
// use "MIDEN_LOG" environment variable to change the logging level
env_logger::Builder::from_env("MIDEN_LOG")
.format(|buf, record| writeln!(buf, "{}", record.args()))
.init();

// execute cli action
if let Err(error) = cli.execute() {
println!("{}", error);
Expand Down

0 comments on commit e0ce650

Please sign in to comment.