Broken - some pass abstraction work

This commit is contained in:
greg 2018-07-06 03:17:37 -07:00
parent 3597ad4eef
commit 5e48eb2dee
4 changed files with 21 additions and 15 deletions

View File

@ -65,8 +65,8 @@ pub fn derive_programming_language_interface(input: TokenStream) -> TokenStream
let mut chain = pass_chain![self, options; #(#passes),* ];
chain(input)
}
fn get_passes(&self) -> Vec<String> {
vec![ #(#pass_names.to_string()),* ]
fn get_passes(&self) -> Vec<PassDescriptor> {
vec![ #(PassDescriptor { name: #pass_names.to_string(), debug_options: vec![] }),* ]
}
}
};

View File

@ -87,7 +87,7 @@ fn parsing(_handle: &mut Schala, input: Vec<tokenizing::Token>, comp: Option<&mu
Some(ref s) if s == "compact" => comp.add_artifact(TraceArtifact::new("ast", format!("{:?}", ast))),
Some(ref s) if s == "expanded" => comp.add_artifact(TraceArtifact::new("ast", format!("{:#?}", ast))),
Some(ref s) if s == "trace" => comp.add_artifact(TraceArtifact::new_parse_trace(trace)),
Some(ref x) => println!("Bad parsing option: {}", x),
Some(ref x) => println!("Bad parsing debug option: {}", x),
};
});
ast.map_err(|err| err.msg)

View File

@ -10,6 +10,12 @@ pub struct EvalOptions {
pub debug_passes: HashMap<String, PassDebugDescriptor>,
}
#[derive(Debug, Hash, PartialEq)]
pub struct PassDescriptor {
pub name: String,
pub debug_options: Vec<String>
}
#[derive(Debug, Serialize, Deserialize)]
pub struct PassDebugDescriptor {
pub opts: Vec<String>,
@ -127,7 +133,7 @@ pub trait ProgrammingLanguageInterface {
fn get_language_name(&self) -> String;
fn get_source_file_suffix(&self) -> String;
fn get_passes(&self) -> Vec<String> {
fn get_passes(&self) -> Vec<PassDescriptor> {
vec![]
}
fn handle_custom_interpreter_directives(&mut self, _commands: &Vec<&str>) -> Option<String> {

View File

@ -112,7 +112,7 @@ fn run_noninteractive(filename: &str, languages: Vec<Box<ProgrammingLanguageInte
source_file.read_to_string(&mut buffer).unwrap();
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(|desc| desc.name == pass) {
options.debug_passes.insert(pass, PassDebugDescriptor { opts: vec![] });
}
}
@ -335,8 +335,8 @@ impl Repl {
CommandTree::term("help", Some("Print this help message")),
CommandTree::NonTerminal(format!("debug"), vec![
CommandTree::term("passes", None),
CommandTree::NonTerminal(format!("show"), passes.iter().map(|p| CommandTree::term(p, None)).collect(), None),
CommandTree::NonTerminal(format!("hide"), passes.iter().map(|p| CommandTree::term(p, None)).collect(), None),
CommandTree::NonTerminal(format!("show"), passes.iter().map(|p| CommandTree::term(&p.name, None)).collect(), None),
CommandTree::NonTerminal(format!("hide"), passes.iter().map(|p| CommandTree::term(&p.name, None)).collect(), None),
], Some(format!("show or hide pass info for a given pass, or display the names of all passes"))),
CommandTree::NonTerminal(format!("lang"), vec![
CommandTree::term("next", None),
@ -436,12 +436,12 @@ impl Repl {
match commands.get(1) {
Some(&"passes") => Some(
passes.into_iter()
.map(|p| {
if self.options.debug_passes.contains_key(&p) {
.map(|desc| {
if self.options.debug_passes.contains_key(&desc.name) {
let color = "green";
format!("*{}", p.color(color))
format!("*{}", desc.name.color(color))
} else {
p
desc.name
}
})
.intersperse(format!(" -> "))
@ -453,16 +453,16 @@ impl Repl {
None => return Some(format!("Must specify a stage to debug")),
};
let pass_opt = commands.get(3);
if let Some(stage) = passes.iter().find(|stage_name| **stage_name == debug_pass) {
if let Some(desc) = passes.iter().find(|desc| desc.name == debug_pass) {
let mut opts = vec![];
if let Some(opt) = pass_opt {
opts.push(opt.to_string());
}
let msg = format!("{} debug for stage {}", if show { "Enabling" } else { "Disabling" }, debug_pass);
let msg = format!("{} debug for pass {}", if show { "Enabling" } else { "Disabling" }, debug_pass);
if show {
self.options.debug_passes.insert(stage.clone(), PassDebugDescriptor { opts });
self.options.debug_passes.insert(desc.name.clone(), PassDebugDescriptor { opts });
} else {
self.options.debug_passes.remove(stage);
self.options.debug_passes.remove(&desc.name);
}
Some(msg)
} else {