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

Method parse_run_command

cranelift/reader/src/parser.rs:2504–2543  ·  view source on GitHub ↗

Parse a CLIF run command. run-command ::= "run" [":" invocation comparison expected] \ "print" [":" invocation]

(&mut self, sig: &Signature)

Source from the content-addressed store, hash-verified

2502 /// run-command ::= "run" [":" invocation comparison expected]
2503 /// \ "print" [":" invocation]
2504 fn parse_run_command(&mut self, sig: &Signature) -> ParseResult<RunCommand> {
2505 // skip semicolon
2506 match self.token() {
2507 Some(Token::Identifier("run")) => {
2508 self.consume();
2509 if self.optional(Token::Colon) {
2510 let invocation = self.parse_run_invocation(sig)?;
2511 let comparison = self.parse_run_comparison()?;
2512 let expected = self.parse_run_returns(sig)?;
2513 Ok(RunCommand::Run(invocation, comparison, expected))
2514 } else if sig.params.is_empty()
2515 && sig.returns.len() == 1
2516 && sig.returns[0].value_type.is_int()
2517 {
2518 // To match the existing run behavior that does not require an explicit
2519 // invocation, we create an invocation from a function like `() -> i*` and
2520 // require the result to be non-zero.
2521 let invocation = Invocation::new("default", vec![]);
2522 let expected = vec![DataValue::I8(0)];
2523 let comparison = Comparison::NotEquals;
2524 Ok(RunCommand::Run(invocation, comparison, expected))
2525 } else {
2526 Err(self.error("unable to parse the run command"))
2527 }
2528 }
2529 Some(Token::Identifier("print")) => {
2530 self.consume();
2531 if self.optional(Token::Colon) {
2532 Ok(RunCommand::Print(self.parse_run_invocation(sig)?))
2533 } else if sig.params.is_empty() {
2534 // To allow printing of functions like `() -> *`, we create a no-arg invocation.
2535 let invocation = Invocation::new("default", vec![]);
2536 Ok(RunCommand::Print(invocation))
2537 } else {
2538 Err(self.error("unable to parse the print command"))
2539 }
2540 }
2541 _ => Err(self.error("expected a 'run:' or 'print:' command")),
2542 }
2543 }
2544
2545 /// Parse the invocation of a CLIF function.
2546 ///

Callers 2

parse_run_commandFunction · 0.80
parseFunction · 0.80

Calls 12

OkFunction · 0.85
tokenMethod · 0.80
optionalMethod · 0.80
parse_run_invocationMethod · 0.80
parse_run_comparisonMethod · 0.80
parse_run_returnsMethod · 0.80
newFunction · 0.50
consumeMethod · 0.45
is_emptyMethod · 0.45
lenMethod · 0.45
is_intMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected