Infrastructure for adding more debug options
This commit is contained in:
parent
d075f613f9
commit
1761d11d36
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashMap;
|
||||||
use colored::*;
|
use colored::*;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
@ -7,8 +7,14 @@ pub struct LLVMCodeString(pub String);
|
|||||||
#[derive(Debug, Default, Serialize, Deserialize)]
|
#[derive(Debug, Default, Serialize, Deserialize)]
|
||||||
pub struct EvalOptions {
|
pub struct EvalOptions {
|
||||||
pub execution_method: ExecutionMethod,
|
pub execution_method: ExecutionMethod,
|
||||||
pub debug_passes: HashSet<String>,
|
pub debug_passes: HashMap<String, PassDebugDescriptor>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
|
pub struct PassDebugDescriptor {
|
||||||
|
pub opts: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub enum ExecutionMethod {
|
pub enum ExecutionMethod {
|
||||||
Compile,
|
Compile,
|
||||||
@ -151,13 +157,15 @@ macro_rules! pass_chain {
|
|||||||
macro_rules! pass_chain_helper {
|
macro_rules! pass_chain_helper {
|
||||||
(($state:expr, $comp:expr, $options:expr); $input:expr, $pass:path $(, $rest:path)*) => {
|
(($state:expr, $comp:expr, $options:expr); $input:expr, $pass:path $(, $rest:path)*) => {
|
||||||
{
|
{
|
||||||
|
use schala_repl::PassDebugDescriptor;
|
||||||
let pass_name = stringify!($pass);
|
let pass_name = stringify!($pass);
|
||||||
let output = {
|
let output = {
|
||||||
let ref debug_set = $options.debug_passes;
|
let ref debug_map = $options.debug_passes;
|
||||||
let debug_handle: Option<&mut UnfinishedComputation> = if debug_set.contains(pass_name) {
|
//let (debug_handle: Option<&mut UnfinishedComputation>, debug_opts) = if debug_set.contains_key(pass_name) {
|
||||||
Some(&mut $comp)
|
//let (debug_handle: Option<&mut UnfinishedComputation>, debug_opts: Vec<String>) = match debug_map.get(pass_name) {
|
||||||
} else {
|
let (debug_handle, debug_opts) = match debug_map.get(pass_name) {
|
||||||
None
|
Some(PassDebugDescriptor { opts }) => (Some(&mut $comp), Some(opts.clone())),
|
||||||
|
_ => (None, None)
|
||||||
};
|
};
|
||||||
$pass($state, $input, debug_handle)
|
$pass($state, $input, debug_handle)
|
||||||
};
|
};
|
||||||
|
@ -33,7 +33,9 @@ const VERSION_STRING: &'static str = "0.1.0";
|
|||||||
|
|
||||||
include!(concat!(env!("OUT_DIR"), "/static.rs"));
|
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<Fn() -> Box<ProgrammingLanguageInterface> + Send + Sync>;
|
pub type PLIGenerator = Box<Fn() -> Box<ProgrammingLanguageInterface> + Send + Sync>;
|
||||||
|
|
||||||
pub fn repl_main(generators: Vec<PLIGenerator>) {
|
pub fn repl_main(generators: Vec<PLIGenerator>) {
|
||||||
@ -111,7 +113,7 @@ fn run_noninteractive(filename: &str, languages: Vec<Box<ProgrammingLanguageInte
|
|||||||
|
|
||||||
for pass in debug_passes.into_iter() {
|
for pass in debug_passes.into_iter() {
|
||||||
if let Some(_) = language.get_passes().iter().find(|stage_name| **stage_name == pass) {
|
if let Some(_) = language.get_passes().iter().find(|stage_name| **stage_name == pass) {
|
||||||
options.debug_passes.insert(pass);
|
options.debug_passes.insert(pass, PassDebugDescriptor { opts: vec![] });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -436,7 +438,7 @@ impl Repl {
|
|||||||
Some(&"passes") => Some(
|
Some(&"passes") => Some(
|
||||||
passes.into_iter()
|
passes.into_iter()
|
||||||
.map(|p| {
|
.map(|p| {
|
||||||
if self.options.debug_passes.contains(&p) {
|
if self.options.debug_passes.contains_key(&p) {
|
||||||
let color = "green";
|
let color = "green";
|
||||||
format!("*{}", p.color(color))
|
format!("*{}", p.color(color))
|
||||||
} else {
|
} else {
|
||||||
@ -454,7 +456,7 @@ impl Repl {
|
|||||||
if let Some(stage) = passes.iter().find(|stage_name| **stage_name == debug_pass) {
|
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);
|
let msg = format!("{} debug for stage {}", if show { "Enabling" } else { "Disabling" }, debug_pass);
|
||||||
if show {
|
if show {
|
||||||
self.options.debug_passes.insert(stage.clone());
|
self.options.debug_passes.insert(stage.clone(), PassDebugDescriptor { opts: vec![] });
|
||||||
} else {
|
} else {
|
||||||
self.options.debug_passes.remove(stage);
|
self.options.debug_passes.remove(stage);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user