MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / parse_target_specs

Method parse_target_specs

cranelift/reader/src/parser.rs:1086–1176  ·  view source on GitHub ↗

Parse a list of target specs. Accept a mix of `target` and `set` command lines. The `set` commands are cumulative.

(&mut self, options: &ParseOptions)

Source from the content-addressed store, hash-verified

1084 /// Accept a mix of `target` and `set` command lines. The `set` commands are cumulative.
1085 ///
1086 fn parse_target_specs(&mut self, options: &ParseOptions) -> ParseResult<isaspec::IsaSpec> {
1087 // Were there any `target` commands?
1088 let mut seen_target = false;
1089 // Location of last `set` command since the last `target`.
1090 let mut last_set_loc = None;
1091
1092 let mut targets = Vec::new();
1093 let mut flag_builder = settings::builder();
1094
1095 let bool_to_str = |val: bool| {
1096 if val { "true" } else { "false" }
1097 };
1098
1099 // default to enabling cfg info
1100 flag_builder
1101 .set(
1102 "machine_code_cfg_info",
1103 bool_to_str(options.machine_code_cfg_info),
1104 )
1105 .expect("machine_code_cfg_info option should be present");
1106
1107 flag_builder
1108 .set("unwind_info", bool_to_str(options.unwind_info))
1109 .expect("unwind_info option should be present");
1110
1111 while let Some(Token::Identifier(command)) = self.token() {
1112 match command {
1113 "set" => {
1114 last_set_loc = Some(self.loc);
1115 isaspec::parse_options(
1116 self.consume_line().trim().split_whitespace(),
1117 &mut flag_builder,
1118 self.loc,
1119 )
1120 .map_err(|err| ParseError::from(err))?;
1121 }
1122 "target" => {
1123 let loc = self.loc;
1124 // Grab the whole line so the lexer won't go looking for tokens on the
1125 // following lines.
1126 let mut words = self.consume_line().trim().split_whitespace().peekable();
1127 // Look for `target foo`.
1128 let target_name = match words.next() {
1129 Some(w) => w,
1130 None => return err!(loc, "expected target triple"),
1131 };
1132 let triple = match Triple::from_str(target_name) {
1133 Ok(triple) => triple,
1134 Err(err) => return err!(loc, err),
1135 };
1136 let mut isa_builder = match isa::lookup(triple) {
1137 Err(isa::LookupError::SupportDisabled) => {
1138 continue;
1139 }
1140 Err(isa::LookupError::Unsupported) => {
1141 return warn!(loc, "unsupported target '{}'", target_name);
1142 }
1143 Ok(b) => b,

Callers 1

parse_testFunction · 0.80

Calls 14

parse_optionsFunction · 0.85
fromFunction · 0.85
OkFunction · 0.85
tokenMethod · 0.80
consume_lineMethod · 0.80
newFunction · 0.50
builderFunction · 0.50
lookupFunction · 0.50
expectMethod · 0.45
setMethod · 0.45
nextMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected