From 2416a77f61a2bc9d8427db1779223d26dfd61c92 Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Wed, 26 Jan 2022 11:05:42 +0700 Subject: [PATCH] feat: more verbose-y log --- blspc/src/compiler/lib.rs | 4 ++-- blspc/src/main.rs | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/blspc/src/compiler/lib.rs b/blspc/src/compiler/lib.rs index 3fac83b..2c02f4f 100644 --- a/blspc/src/compiler/lib.rs +++ b/blspc/src/compiler/lib.rs @@ -33,7 +33,7 @@ impl Display for Register { #[derive(Clone, Debug)] pub enum Instr { // Load a literal value onto the stack. - Load { address: Register, label: usize }, + // Load { address: Register, label: usize }, // Store a literal value into a register. Store { address: Register, value: Type, label: usize }, // Call intrinsic function. @@ -53,7 +53,7 @@ pub enum Instr { impl Display for Instr { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { match self { - Instr::Load { address, label } => write!(f, "{}: LOAD {}", label, address), + // Instr::Load { address, label } => write!(f, "{}: LOAD {}", label, address), Instr::Store { address, value , label} => write!(f, "{}: STORE {} {}", label, address, value), Instr::Call { address, args, label } => write!(f, "{}: CALL {} {}", label, address, args), Instr::IAdd { lhs, rhs, to, label } => write!(f, "{}: IADD {} {} {}", label, lhs, rhs, to), diff --git a/blspc/src/main.rs b/blspc/src/main.rs index fdec7ca..aa521c0 100644 --- a/blspc/src/main.rs +++ b/blspc/src/main.rs @@ -1,4 +1,4 @@ -use std::{fs::{read_to_string, File}, path::Path, io::Write}; +use std::{fs::{read_to_string, File}, path::Path, io::Write, time::Instant}; use structopt::StructOpt; @@ -15,6 +15,7 @@ mod compiler; use compiler::compile::Compiler; fn main() { + let start = Instant::now(); let args = Args::from_args(); let src = cover_paren(read_to_string(&args.file).unwrap()); @@ -29,14 +30,45 @@ fn main() { let mut file = File::create(format!("{}.bbb", file_name)).unwrap(); let mut compiler = Compiler::new(); + let before = Instant::now(); for instr in compiler.compile(result.unwrap(), 0).unwrap() { write!(file, "{}\n", instr).unwrap(); } + let spent = before.elapsed(); + let total = start.elapsed(); + + println!("Compiled in {}.{}s, Total of {}.{}s", spent.as_secs(), spent.subsec_millis(), total.as_secs(), total.subsec_millis()); + }, + 1 => { + println!("Parsed AST: {:#?}", result); + + let mut file = File::create(format!("{}.bbb", file_name)).unwrap(); + + let mut compiler = Compiler::new(); + let before = Instant::now(); + for instr in compiler.compile(result.unwrap(), 0).unwrap() { + write!(file, "{}\n", instr).unwrap(); + } + let spent = before.elapsed(); + let total = start.elapsed(); + + println!("Compiled in {}.{}s, Total of {}.{}s", spent.as_secs(), spent.subsec_millis(), total.as_secs(), total.subsec_millis()); }, - 1 => println!("{:?}", result), 2 | _ => { println!("Tokens: {:?}", tokens); - println!("Parsed: {:#?}", result); + println!("Parsed AST: {:#?}", result); + + let mut file = File::create(format!("{}.bbb", file_name)).unwrap(); + + let mut compiler = Compiler::new(); + let before = Instant::now(); + for instr in compiler.compile(result.unwrap(), 0).unwrap() { + write!(file, "{}\n", instr).unwrap(); + } + let spent = before.elapsed(); + let total = start.elapsed(); + + println!("Compiled in {}.{}s, Total of {}.{}s", spent.as_secs(), spent.subsec_millis(), total.as_secs(), total.subsec_millis()); } } }