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

Method try_use_var

cranelift/frontend/src/frontend.rs:451–476  ·  view source on GitHub ↗

Returns the Cranelift IR necessary to use a previously defined user variable, returning an error if this is not possible.

(&mut self, var: Variable)

Source from the content-addressed store, hash-verified

449 /// Returns the Cranelift IR necessary to use a previously defined user
450 /// variable, returning an error if this is not possible.
451 pub fn try_use_var(&mut self, var: Variable) -> Result<Value, UseVariableError> {
452 // Assert that we're about to add instructions to this block using the definition of the
453 // given variable. ssa.use_var is the only part of this crate which can add block parameters
454 // behind the caller's back. If we disallow calling append_block_param as soon as use_var is
455 // called, then we enforce a strict separation between user parameters and SSA parameters.
456 self.ensure_inserted_block();
457
458 let (val, side_effects) = {
459 let ty = *self
460 .func_ctx
461 .variables
462 .get(var)
463 .ok_or(UseVariableError::UsedBeforeDeclared(var))?;
464 debug_assert_ne!(
465 ty,
466 types::INVALID,
467 "variable {var:?} is used but its type has not been declared"
468 );
469 self.func_ctx
470 .ssa
471 .use_var(self.func, var, ty, self.position.unwrap())
472 };
473 self.handle_ssa_side_effects(side_effects);
474
475 Ok(val)
476 }
477
478 /// Returns the Cranelift IR value corresponding to the utilization at the current program
479 /// position of a previously defined user variable.

Callers 1

use_varMethod · 0.80

Calls 6

OkFunction · 0.85
ensure_inserted_blockMethod · 0.80
getMethod · 0.45
use_varMethod · 0.45
unwrapMethod · 0.45

Tested by

no test coverage detected