mesa/src/compiler/rust/nir_instr_printer.rs
Christian Gmeiner 5fa4c1a191 compiler/rust: Copy NirInstrPrinter from NAK
Switch NAK to it.

Signed-off-by: Christian Gmeiner <cgmeiner@igalia.com>
Reviewed-by: M Henning <drawoc@darkrefraction.com>
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31706>
2024-10-18 12:43:52 +00:00

27 lines
671 B
Rust

// Copyright © 2024 Collabora, Ltd.
// SPDX-License-Identifier: MIT
use std::io;
use crate::bindings;
use crate::bindings::nir_instr;
use crate::memstream::MemStream;
/// A memstream that holds the printed NIR instructions.
pub struct NirInstrPrinter {
stream: MemStream,
}
impl NirInstrPrinter {
pub fn new() -> io::Result<Self> {
Ok(Self {
stream: MemStream::new()?,
})
}
/// Prints the given NIR instruction.
pub fn instr_to_string(&mut self, instr: &nir_instr) -> io::Result<String> {
unsafe { bindings::nir_print_instr(instr, self.stream.c_file()) };
self.stream.take_utf8_string_lossy()
}
}