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 {
program: String,
#[structopt(help = "Output file (CTree), stdout if not present", default_value = "-")]
output: String,
#[structopt(help = "Debug: don't optimize, just rearrange", default_value = "false")]
debug: bool,
}
fn main() {
use std::error::Error;
let opt = Opt::from_args();
match exec(&opt.program, &opt.output) {
match exec(&opt.program, &opt.output, opt.debug) {
Err(e) => {
eprintln!("{} ({})", e, e.description());
process::exit(1)
......@@ -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 std::io::Write;
// Error out if the output file already exists
......@@ -73,7 +75,11 @@ fn exec(program: &str, output: &str) -> Result<()> {
let program: ctree::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 == "-" {
println!("{}", program.to_ascii_string()?);
......@@ -208,13 +214,18 @@ impl<'s> Scopes<'s> {
}
fn apply_strategy<'a>(&'a mut self, strat_name: &str) {
let (vars, no_of_scopes) = self.0
let (vars, no_of_scopes) = {
let opt = self.0
.iter()
.rev()
.flat_map(|scope| scope.strategy.get(strat_name))
.cloned()
.next()
.expect("Strategy name was not found in any scope!");
.next();
if opt.is_none() {
return;
}
opt.unwrap()
};
if vars == Err(DynamicCall) {
conservative_maybe_bind(self);
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