Commit 813fb58d authored by Jeff Smits's avatar Jeff Smits

Fixed bug: strategy can be not found if in library. Added debug flag

parent e3d1dff3
...@@ -39,13 +39,15 @@ struct Opt { ...@@ -39,13 +39,15 @@ struct Opt {
program: String, program: String,
#[structopt(help = "Output file (CTree), stdout if not present", default_value = "-")] #[structopt(help = "Output file (CTree), stdout if not present", default_value = "-")]
output: String, output: String,
#[structopt(help = "Debug: don't optimize, just rearrange", default_value = "false")]
debug: bool,
} }
fn main() { fn main() {
use std::error::Error; use std::error::Error;
let opt = Opt::from_args(); let opt = Opt::from_args();
match exec(&opt.program, &opt.output) { match exec(&opt.program, &opt.output, opt.debug) {
Err(e) => { Err(e) => {
eprintln!("{} ({})", e, e.description()); eprintln!("{} ({})", e, e.description());
process::exit(1) process::exit(1)
...@@ -54,7 +56,7 @@ fn main() { ...@@ -54,7 +56,7 @@ fn main() {
} }
} }
fn exec(program: &str, output: &str) -> Result<()> { fn exec(program: &str, output: &str, debug: bool) -> Result<()> {
use aterm::print::ATermWrite; use aterm::print::ATermWrite;
use std::io::Write; use std::io::Write;
// Error out if the output file already exists // Error out if the output file already exists
...@@ -73,7 +75,11 @@ fn exec(program: &str, output: &str) -> Result<()> { ...@@ -73,7 +75,11 @@ fn exec(program: &str, output: &str) -> Result<()> {
let program: ctree::Module = (&program).try_into()?; let program: ctree::Module = (&program).try_into()?;
let program: preprocess_ext::Module = program.try_into()?; let program: preprocess_ext::Module = program.try_into()?;
let program = program.optimize(&mut ()); let program = if !debug {
program.optimize(&mut ())
} else {
program
};
if output == "-" { if output == "-" {
println!("{}", program.to_ascii_string()?); println!("{}", program.to_ascii_string()?);
...@@ -208,13 +214,18 @@ impl<'s> Scopes<'s> { ...@@ -208,13 +214,18 @@ impl<'s> Scopes<'s> {
} }
fn apply_strategy<'a>(&'a mut self, strat_name: &str) { fn apply_strategy<'a>(&'a mut self, strat_name: &str) {
let (vars, no_of_scopes) = self.0 let (vars, no_of_scopes) = {
.iter() let opt = self.0
.rev() .iter()
.flat_map(|scope| scope.strategy.get(strat_name)) .rev()
.cloned() .flat_map(|scope| scope.strategy.get(strat_name))
.next() .cloned()
.expect("Strategy name was not found in any scope!"); .next();
if opt.is_none() {
return;
}
opt.unwrap()
};
if vars == Err(DynamicCall) { if vars == Err(DynamicCall) {
conservative_maybe_bind(self); conservative_maybe_bind(self);
return; return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment