• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright © 2024 Collabora, Ltd.
2 // SPDX-License-Identifier: MIT
3 
4 use std::io;
5 
6 use crate::bindings;
7 use crate::bindings::nir_instr;
8 use crate::memstream::MemStream;
9 
10 /// A memstream that holds the printed NIR instructions.
11 pub struct NirInstrPrinter {
12     stream: MemStream,
13 }
14 
15 impl NirInstrPrinter {
new() -> io::Result<Self>16     pub fn new() -> io::Result<Self> {
17         Ok(Self {
18             stream: MemStream::new()?,
19         })
20     }
21 
22     /// Prints the given NIR instruction.
instr_to_string(&mut self, instr: &nir_instr) -> io::Result<String>23     pub fn instr_to_string(&mut self, instr: &nir_instr) -> io::Result<String> {
24         unsafe { bindings::nir_print_instr(instr, self.stream.c_file()) };
25         self.stream.take_utf8_string_lossy()
26     }
27 }
28