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

Function parse_sets_and_triple

cranelift/reader/src/lib.rs:49–106  ·  view source on GitHub ↗

Parse "set" and "triple" commands.

(flag_set: &[String], flag_triple: &str)

Source from the content-addressed store, hash-verified

47
48/// Parse "set" and "triple" commands.
49pub fn parse_sets_and_triple(flag_set: &[String], flag_triple: &str) -> Result<OwnedFlagsOrIsa> {
50 let mut flag_builder = settings::builder();
51
52 // Collect unknown system-wide settings, so we can try to parse them as target specific
53 // settings, if a target is defined.
54 let mut unknown_settings = Vec::new();
55 for flag in flag_set {
56 match parse_option(flag, &mut flag_builder, Location { line_number: 0 }) {
57 Err(ParseOptionError::UnknownFlag { name, .. }) => {
58 unknown_settings.push(name);
59 }
60 Err(ParseOptionError::UnknownValue { name, value, .. }) => {
61 unknown_settings.push(format!("{name}={value}"));
62 }
63 Err(ParseOptionError::Generic(err)) => return Err(err.into()),
64 Ok(()) => {}
65 }
66 }
67
68 let mut words = flag_triple.trim().split_whitespace();
69 // Look for `target foo`.
70 if let Some(triple_name) = words.next() {
71 let triple = match Triple::from_str(triple_name) {
72 Ok(triple) => triple,
73 Err(parse_error) => return Err(Error::from(parse_error)),
74 };
75
76 let mut isa_builder = isa::lookup(triple).map_err(|err| match err {
77 isa::LookupError::SupportDisabled => {
78 anyhow::anyhow!("support for triple '{triple_name}' is disabled")
79 }
80 isa::LookupError::Unsupported => {
81 anyhow::anyhow!("support for triple '{triple_name}' is not implemented yet")
82 }
83 })?;
84
85 // Try to parse system-wide unknown settings as target-specific settings.
86 parse_options(
87 unknown_settings.iter().map(|x| x.as_str()),
88 &mut isa_builder,
89 Location { line_number: 0 },
90 )
91 .map_err(ParseError::from)?;
92
93 // Apply the ISA-specific settings to `isa_builder`.
94 parse_options(words, &mut isa_builder, Location { line_number: 0 })
95 .map_err(ParseError::from)?;
96
97 Ok(OwnedFlagsOrIsa::Isa(
98 isa_builder.finish(settings::Flags::new(flag_builder))?,
99 ))
100 } else {
101 if !unknown_settings.is_empty() {
102 anyhow::bail!("unknown settings: '{}'", unknown_settings.join("', '"));
103 }
104 Ok(OwnedFlagsOrIsa::Flags(settings::Flags::new(flag_builder)))
105 }
106}

Callers 3

runFunction · 0.85
runFunction · 0.85
runFunction · 0.85

Calls 15

fromFunction · 0.85
parse_optionsFunction · 0.85
OkFunction · 0.85
IsaEnum · 0.85
parse_optionFunction · 0.70
builderFunction · 0.50
newFunction · 0.50
lookupFunction · 0.50
FlagsClass · 0.50
pushMethod · 0.45
nextMethod · 0.45
mapMethod · 0.45

Tested by

no test coverage detected