/// A custom handler for MLIR diagnostics, which prints them through Moore's own
/// diagnostic engine.
A custom handler for MLIR diagnostics, which prints them through Moore's own
diagnostic engine.
A custom handler for MLIR diagnostics which prints them through Moore ' s own diagnostic engine .
unsafe extern "C" fn moore_mlir_diagnostic_handler(
    diag: MlirDiagnostic,
    sess: *mut std::ffi::c_void,
) -> MlirLogicalResult {
    let sess: &Session = (sess as *const Session).as_ref().unwrap();
    // Map the severity from MLIR to Moore.
    #[allow(non_upper_case_globals)]
    let severity = match mlirDiagnosticGetSeverity(diag) {
        MlirDiagnosticSeverity_MlirDiagnosticError => Severity::Error,
        MlirDiagnosticSeverity_MlirDiagnosticWarning => Severity::Warning,
        MlirDiagnosticSeverity_MlirDiagnosticNote | MlirDiagnosticSeverity_MlirDiagnosticRemark => {
            Severity::Note
        }
        _ => panic!("unsupported MLIR diagnostic severity"),
    };
    // Create the main diagnostic message and attach location information if
    // possible.
    let mut d = DiagBuilder2::new(severity, mlir_diagnostic_to_string(diag));
    let main_loc = mlirDiagnosticGetLocation(diag);
    if let Some(main_span) = mlir_location_to_span(main_loc) {
        d = d.span(main_span);
    }
    // Add additional notes.
    let mut notes_todo = vec![diag];
    while let Some(note) = notes_todo.pop() {
        if note.ptr != diag.ptr {
            let msg = mlir_diagnostic_to_string(note);
            let loc = mlirDiagnosticGetLocation(note);
            d = d.add_note(msg);
            if !loc.ptr.is_null() && main_loc.ptr != loc.ptr {
                if let Some(span) = mlir_location_to_span(loc) {
                    d = d.span(span);
                }
            }
        }
        let num_notes = mlirDiagnosticGetNumNotes(note);
        for i in (0..num_notes).rev() {
            notes_todo.push(mlirDiagnosticGetNote(note, i));
        }
    }
    sess.emit(d);
    MlirLogicalResult { value: 1 }
}
unsafe extern " " fn moore_mlir_diagnostic_handler ( diag : MlirDiagnostic , sess : * mut std :: ffi :: c_void , ) -> MlirLogicalResult { let sess : & Session = ( sess as * const Session ) . as_ref ( ) . unwrap ( ) ; // Map the severity from MLIR to Moore. # [ allow ( non_upper_case_globals ) ] let severity = match mlirDiagnosticGetSeverity ( diag ) { MlirDiagnosticSeverity_MlirDiagnosticError => Severity :: Error , MlirDiagnosticSeverity_MlirDiagnosticWarning => Severity :: Warning , MlirDiagnosticSeverity_MlirDiagnosticNote | MlirDiagnosticSeverity_MlirDiagnosticRemark => { Severity :: Note } _ => panic ! ( " " ) , } ; // Create the main diagnostic message and attach location information if // possible. let mut d = DiagBuilder2 :: new ( severity , mlir_diagnostic_to_string ( diag ) ) ; let main_loc = mlirDiagnosticGetLocation ( diag ) ; if let Some ( main_span ) = mlir_location_to_span ( main_loc ) { d = d . span ( main_span ) ; } // Add additional notes. let mut notes_todo = vec ! [ diag ] ; while let Some ( note ) = notes_todo . pop ( ) { if note . ptr != diag . ptr { let msg = mlir_diagnostic_to_string ( note ) ; let loc = mlirDiagnosticGetLocation ( note ) ; d = d . add_note ( msg ) ; if ! loc . ptr . is_null ( ) && main_loc . ptr != loc . ptr { if let Some ( span ) = mlir_location_to_span ( loc ) { d = d . span ( span ) ; } } } let num_notes = mlirDiagnosticGetNumNotes ( note ) ; for i in ( 0 .. num_notes ) . rev ( ) { notes_todo . push ( mlirDiagnosticGetNote ( note , i ) ) ; } } sess . emit ( d ) ; MlirLogicalResult { value : 1 } }
A custom handler for MLIR diagnostics, which prints them through Moore's own
diagnostic engine.
A custom handler for MLIR diagnostics which prints them through Moore ' s own diagnostic engine .
diag
MlirDiagnostic
sess
*mut std::ffi::c_void