]> git.lizzy.rs Git - rust.git/blob - src/pretty_clif.rs
Implement int casts
[rust.git] / src / pretty_clif.rs
1 use std::collections::HashMap;
2 use std::fmt;
3
4 use cranelift::codegen::{
5     ir::{Function, Inst},
6     write::{FuncWriter, PlainWriter},
7 };
8 use cranelift::prelude::*;
9
10 pub struct CommentWriter(pub HashMap<Inst, String>);
11
12 impl FuncWriter for CommentWriter {
13     fn write_instruction(
14         &mut self,
15         w: &mut dyn fmt::Write,
16         func: &Function,
17         isa: Option<&dyn isa::TargetIsa>,
18         inst: Inst,
19         indent: usize,
20     ) -> fmt::Result {
21         if let Some(comment) = self.0.get(&inst) {
22             writeln!(w, "; {}", comment.replace('\n', "\n; "))?;
23         }
24         PlainWriter.write_instruction(w, func, isa, inst, indent)
25     }
26
27     fn write_preamble(
28         &mut self,
29         w: &mut dyn fmt::Write,
30         func: &Function,
31         reg_info: Option<&isa::RegInfo>,
32     ) -> Result<bool, fmt::Error> {
33         PlainWriter.write_preamble(w, func, reg_info)
34     }
35 }