Skip to main content

melior/ir/operation/
printing_flags.rs

1use mlir_sys::{
2    mlirOpPrintingFlagsCreate, mlirOpPrintingFlagsDestroy,
3    mlirOpPrintingFlagsElideLargeElementsAttrs, mlirOpPrintingFlagsEnableDebugInfo,
4    mlirOpPrintingFlagsPrintGenericOpForm, mlirOpPrintingFlagsUseLocalScope, MlirOpPrintingFlags,
5};
6
7/// Operation printing flags.
8#[derive(Debug)]
9pub struct OperationPrintingFlags(MlirOpPrintingFlags);
10
11impl OperationPrintingFlags {
12    /// Creates operation printing flags.
13    pub fn new() -> Self {
14        Self(unsafe { mlirOpPrintingFlagsCreate() })
15    }
16
17    /// Elides large elements attributes.
18    pub fn elide_large_elements_attributes(self, limit: usize) -> Self {
19        unsafe { mlirOpPrintingFlagsElideLargeElementsAttrs(self.0, limit as isize) }
20
21        self
22    }
23
24    /// Enables debug info.
25    pub fn enable_debug_info(self, enabled: bool, pretty_form: bool) -> Self {
26        unsafe { mlirOpPrintingFlagsEnableDebugInfo(self.0, enabled, pretty_form) }
27
28        self
29    }
30
31    /// Prints operations in a generic form.
32    pub fn print_generic_operation_form(self) -> Self {
33        unsafe { mlirOpPrintingFlagsPrintGenericOpForm(self.0) }
34
35        self
36    }
37
38    /// Uses local scope.
39    pub fn use_local_scope(self) -> Self {
40        unsafe { mlirOpPrintingFlagsUseLocalScope(self.0) }
41
42        self
43    }
44
45    /// Converts a printing flags into a raw object.
46    pub const fn to_raw(&self) -> MlirOpPrintingFlags {
47        self.0
48    }
49}
50
51impl Drop for OperationPrintingFlags {
52    fn drop(&mut self) {
53        unsafe { mlirOpPrintingFlagsDestroy(self.0) }
54    }
55}
56
57impl Default for OperationPrintingFlags {
58    fn default() -> Self {
59        Self::new()
60    }
61}