Function cranelift_reader::parse_options
source · pub fn parse_options<'a, I>(
iter: I,
config: &mut dyn Configurable,
loc: Location
) -> Result<(), ParseOptionError>where
I: Iterator<Item = &'a str>,
Expand description
Parse an iterator of command line options and apply them to config
.
Examples found in repository?
src/parser.rs (lines 1161-1165)
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225
fn parse_target_specs(&mut self, options: &ParseOptions) -> ParseResult<isaspec::IsaSpec> {
// Were there any `target` commands?
let mut seen_target = false;
// Location of last `set` command since the last `target`.
let mut last_set_loc = None;
let mut targets = Vec::new();
let mut flag_builder = settings::builder();
let unwind_info = if options.unwind_info { "true" } else { "false" };
flag_builder
.set("unwind_info", unwind_info)
.expect("unwind_info option should be present");
while let Some(Token::Identifier(command)) = self.token() {
match command {
"set" => {
last_set_loc = Some(self.loc);
isaspec::parse_options(
self.consume_line().trim().split_whitespace(),
&mut flag_builder,
self.loc,
)
.map_err(|err| ParseError::from(err))?;
}
"target" => {
let loc = self.loc;
// Grab the whole line so the lexer won't go looking for tokens on the
// following lines.
let mut words = self.consume_line().trim().split_whitespace().peekable();
// Look for `target foo`.
let target_name = match words.next() {
Some(w) => w,
None => return err!(loc, "expected target triple"),
};
let triple = match Triple::from_str(target_name) {
Ok(triple) => triple,
Err(err) => return err!(loc, err),
};
let mut isa_builder = match isa::lookup(triple) {
Err(isa::LookupError::SupportDisabled) => {
continue;
}
Err(isa::LookupError::Unsupported) => {
return warn!(loc, "unsupported target '{}'", target_name);
}
Ok(b) => b,
};
last_set_loc = None;
seen_target = true;
// Apply the target-specific settings to `isa_builder`.
isaspec::parse_options(words, &mut isa_builder, self.loc)?;
// Construct a trait object with the aggregate settings.
targets.push(
isa_builder
.finish(settings::Flags::new(flag_builder.clone()))
.map_err(|e| ParseError {
location: loc,
message: format!(
"invalid ISA flags for '{}': {:?}",
target_name, e
),
is_warning: false,
})?,
);
}
_ => break,
}
}
if !seen_target {
// No `target` commands, but we allow for `set` commands.
Ok(isaspec::IsaSpec::None(settings::Flags::new(flag_builder)))
} else if let Some(loc) = last_set_loc {
err!(
loc,
"dangling 'set' command after ISA specification has no effect."
)
} else {
Ok(isaspec::IsaSpec::Some(targets))
}
}