clif-util: try both global and target-dependent settings when parsing --set flags;

This commit is contained in:
Benjamin Bouvier
2020-04-27 18:35:43 +02:00
parent 6ef106fee9
commit 6bee767129
4 changed files with 83 additions and 14 deletions

View File

@@ -6,7 +6,7 @@
//! If a test case file contains `isa` commands, the tests will only be run against the specified
//! ISAs. If the file contains no `isa` commands, the tests will be run against all supported ISAs.
use crate::error::{Location, ParseResult};
use crate::error::{Location, ParseError};
use crate::testcommand::TestOption;
use cranelift_codegen::isa::TargetIsa;
use cranelift_codegen::settings::{Configurable, Flags, SetError};
@@ -34,12 +34,49 @@ impl IsaSpec {
}
}
/// An error type returned by `parse_options`.
pub enum ParseOptionError {
/// A generic ParseError.
Generic(ParseError),
/// An unknown flag was used, with the given name at the given location.
UnknownFlag {
/// Location where the flag was given.
loc: Location,
/// Name of the unknown flag.
name: String,
},
}
impl From<ParseOptionError> for ParseError {
fn from(err: ParseOptionError) -> Self {
match err {
ParseOptionError::Generic(err) => err,
ParseOptionError::UnknownFlag { loc, name } => Self {
location: loc,
message: format!("unknown setting '{}'", name),
is_warning: false,
},
}
}
}
macro_rules! option_err {
( $loc:expr, $fmt:expr, $( $arg:expr ),+ ) => {
Err($crate::ParseOptionError::Generic($crate::ParseError {
location: $loc.clone(),
message: format!( $fmt, $( $arg ),+ ),
is_warning: false,
}))
};
}
/// Parse an iterator of command line options and apply them to `config`.
pub fn parse_options<'a, I>(
iter: I,
config: &mut dyn Configurable,
loc: Location,
) -> ParseResult<()>
) -> Result<(), ParseOptionError>
where
I: Iterator<Item = &'a str>,
{
@@ -47,15 +84,21 @@ where
match opt {
TestOption::Flag(name) => match config.enable(name) {
Ok(_) => {}
Err(SetError::BadName(name)) => return err!(loc, "unknown flag '{}'", name),
Err(_) => return err!(loc, "not a boolean flag: '{}'", opt),
Err(SetError::BadName(name)) => {
return Err(ParseOptionError::UnknownFlag { loc, name })
}
Err(_) => return option_err!(loc, "not a boolean flag: '{}'", opt),
},
TestOption::Value(name, value) => match config.set(name, value) {
Ok(_) => {}
Err(SetError::BadName(name)) => return err!(loc, "unknown setting '{}'", name),
Err(SetError::BadType) => return err!(loc, "invalid setting type: '{}'", opt),
Err(SetError::BadName(name)) => {
return Err(ParseOptionError::UnknownFlag { loc, name })
}
Err(SetError::BadType) => {
return option_err!(loc, "invalid setting type: '{}'", opt)
}
Err(SetError::BadValue(expected)) => {
return err!(
return option_err!(
loc,
"invalid setting value for '{}', expected {}",
opt,

View File

@@ -27,7 +27,7 @@
)]
pub use crate::error::{Location, ParseError, ParseResult};
pub use crate::isaspec::{parse_options, IsaSpec};
pub use crate::isaspec::{parse_options, IsaSpec, ParseOptionError};
pub use crate::parser::{parse_functions, parse_run_command, parse_test, ParseOptions};
pub use crate::run_command::{Comparison, DataValue, Invocation, RunCommand};
pub use crate::sourcemap::SourceMap;

View File

@@ -1178,7 +1178,8 @@ impl<'a> Parser<'a> {
self.consume_line().trim().split_whitespace(),
&mut flag_builder,
self.loc,
)?;
)
.map_err(|err| ParseError::from(err))?;
}
"target" => {
let loc = self.loc;