From 1761d11d369568af2db9b035233467a234fcea9d Mon Sep 17 00:00:00 2001 From: greg Date: Tue, 3 Jul 2018 03:02:16 -0700 Subject: [PATCH] Infrastructure for adding more debug options --- schala-repl/src/language.rs | 22 +++++++++++++++------- schala-repl/src/lib.rs | 10 ++++++---- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/schala-repl/src/language.rs b/schala-repl/src/language.rs index 03a30b7..4d18131 100644 --- a/schala-repl/src/language.rs +++ b/schala-repl/src/language.rs @@ -1,4 +1,4 @@ -use std::collections::HashSet; +use std::collections::HashMap; use colored::*; use std::fmt::Write; @@ -7,8 +7,14 @@ pub struct LLVMCodeString(pub String); #[derive(Debug, Default, Serialize, Deserialize)] pub struct EvalOptions { pub execution_method: ExecutionMethod, - pub debug_passes: HashSet, + pub debug_passes: HashMap, } + +#[derive(Debug, Serialize, Deserialize)] +pub struct PassDebugDescriptor { + pub opts: Vec, +} + #[derive(Debug, Serialize, Deserialize)] pub enum ExecutionMethod { Compile, @@ -151,13 +157,15 @@ macro_rules! pass_chain { macro_rules! pass_chain_helper { (($state:expr, $comp:expr, $options:expr); $input:expr, $pass:path $(, $rest:path)*) => { { + use schala_repl::PassDebugDescriptor; let pass_name = stringify!($pass); let output = { - let ref debug_set = $options.debug_passes; - let debug_handle: Option<&mut UnfinishedComputation> = if debug_set.contains(pass_name) { - Some(&mut $comp) - } else { - None + let ref debug_map = $options.debug_passes; + //let (debug_handle: Option<&mut UnfinishedComputation>, debug_opts) = if debug_set.contains_key(pass_name) { + //let (debug_handle: Option<&mut UnfinishedComputation>, debug_opts: Vec) = match debug_map.get(pass_name) { + let (debug_handle, debug_opts) = match debug_map.get(pass_name) { + Some(PassDebugDescriptor { opts }) => (Some(&mut $comp), Some(opts.clone())), + _ => (None, None) }; $pass($state, $input, debug_handle) }; diff --git a/schala-repl/src/lib.rs b/schala-repl/src/lib.rs index cca2333..e0231f0 100644 --- a/schala-repl/src/lib.rs +++ b/schala-repl/src/lib.rs @@ -33,7 +33,9 @@ const VERSION_STRING: &'static str = "0.1.0"; include!(concat!(env!("OUT_DIR"), "/static.rs")); -pub use language::{LLVMCodeString, ProgrammingLanguageInterface, EvalOptions, ExecutionMethod, TraceArtifact, FinishedComputation, UnfinishedComputation}; +pub use language::{LLVMCodeString, ProgrammingLanguageInterface, EvalOptions, + ExecutionMethod, TraceArtifact, FinishedComputation, UnfinishedComputation, PassDebugDescriptor}; + pub type PLIGenerator = Box Box + Send + Sync>; pub fn repl_main(generators: Vec) { @@ -111,7 +113,7 @@ fn run_noninteractive(filename: &str, languages: Vec Some( passes.into_iter() .map(|p| { - if self.options.debug_passes.contains(&p) { + if self.options.debug_passes.contains_key(&p) { let color = "green"; format!("*{}", p.color(color)) } else { @@ -454,7 +456,7 @@ impl Repl { if let Some(stage) = passes.iter().find(|stage_name| **stage_name == debug_pass) { let msg = format!("{} debug for stage {}", if show { "Enabling" } else { "Disabling" }, debug_pass); if show { - self.options.debug_passes.insert(stage.clone()); + self.options.debug_passes.insert(stage.clone(), PassDebugDescriptor { opts: vec![] }); } else { self.options.debug_passes.remove(stage); }