use cretonne_codegen::isa::TargetIsa;
use cretonne_codegen::settings::{Configurable, Flags, SetError};
use error::{Location, ParseResult};
use testcommand::TestOption;
pub enum IsaSpec {
None(Flags),
Some(Vec<Box<TargetIsa>>),
}
impl IsaSpec {
pub fn unique_isa(&self) -> Option<&TargetIsa> {
if let IsaSpec::Some(ref isa_vec) = *self {
if isa_vec.len() == 1 {
return Some(&*isa_vec[0]);
}
}
None
}
}
pub fn parse_options<'a, I>(iter: I, config: &mut Configurable, loc: Location) -> ParseResult<()>
where
I: Iterator<Item = &'a str>,
{
for opt in iter.map(TestOption::new) {
match opt {
TestOption::Flag(name) => match config.enable(name) {
Ok(_) => {}
Err(SetError::BadName) => return err!(loc, "unknown flag '{}'", opt),
Err(_) => return err!(loc, "not a boolean flag: '{}'", opt),
},
TestOption::Value(name, value) => match config.set(name, value) {
Ok(_) => {}
Err(SetError::BadName) => return err!(loc, "unknown setting '{}'", opt),
Err(SetError::BadType) => return err!(loc, "invalid setting type: '{}'", opt),
Err(SetError::BadValue) => return err!(loc, "invalid setting value: '{}'", opt),
},
}
}
Ok(())
}