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

Function write_instruction

cranelift/codegen/src/write.rs:335–387  ·  view source on GitHub ↗
(
    w: &mut dyn Write,
    func: &Function,
    aliases: &SecondaryMap<Value, Vec<Value>>,
    inst: Inst,
    mut indent: usize,
)

Source from the content-addressed store, hash-verified

333}
334
335fn write_instruction(
336 w: &mut dyn Write,
337 func: &Function,
338 aliases: &SecondaryMap<Value, Vec<Value>>,
339 inst: Inst,
340 mut indent: usize,
341) -> fmt::Result {
342 // Prefix containing source location, encoding, and value locations.
343 let mut s = String::with_capacity(16);
344
345 // Source location goes first.
346 let srcloc = func.srcloc(inst);
347 if !srcloc.is_default() {
348 write!(s, "{srcloc} ")?;
349 }
350
351 // Write out any debug tags.
352 write_debug_tags(w, &func, inst, &mut indent)?;
353
354 // Write out prefix and indent the instruction.
355 write!(w, "{s:indent$}")?;
356
357 // Write out the result values, if any.
358 let mut has_results = false;
359 for r in func.dfg.inst_results(inst) {
360 if !has_results {
361 has_results = true;
362 write!(w, "{r}")?;
363 } else {
364 write!(w, ", {r}")?;
365 }
366 }
367 if has_results {
368 write!(w, " = ")?;
369 }
370
371 // Then the opcode, possibly with a '.type' suffix.
372 let opcode = func.dfg.insts[inst].opcode();
373
374 match type_suffix(func, inst) {
375 Some(suf) => write!(w, "{opcode}.{suf}")?,
376 None => write!(w, "{opcode}")?,
377 }
378
379 write_operands(w, &func.dfg, inst)?;
380 writeln!(w)?;
381
382 // Value aliases come out on lines after the instruction defining the referent.
383 for r in func.dfg.inst_results(inst) {
384 write_value_aliases(w, aliases, *r, indent)?;
385 }
386 Ok(())
387}
388
389/// Write the operands of `inst` to `w` with a prepended space.
390pub fn write_operands(w: &mut dyn Write, dfg: &DataFlowGraph, inst: Inst) -> fmt::Result {

Callers 1

write_instructionMethod · 0.85

Calls 9

write_debug_tagsFunction · 0.85
type_suffixFunction · 0.85
write_operandsFunction · 0.85
write_value_aliasesFunction · 0.85
OkFunction · 0.85
srclocMethod · 0.45
is_defaultMethod · 0.45
inst_resultsMethod · 0.45
opcodeMethod · 0.45

Tested by

no test coverage detected