[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / mlir / lib / Interfaces / RuntimeVerifiableOpInterface.cpp
blob8aa194befb420542cbc51cd04ca9cb03cad8a3dd
1 //===- RuntimeVerifiableOpInterface.cpp - Op Verification -----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "mlir/Interfaces/RuntimeVerifiableOpInterface.h"
11 namespace mlir {
12 class Location;
13 class OpBuilder;
15 /// Generate an error message string for the given op and the specified error.
16 std::string
17 RuntimeVerifiableOpInterface::generateErrorMessage(Operation *op,
18 const std::string &msg) {
19 std::string buffer;
20 llvm::raw_string_ostream stream(buffer);
21 OpPrintingFlags flags;
22 // We may generate a lot of error messages and so we need to ensure the
23 // printing is fast.
24 flags.elideLargeElementsAttrs();
25 flags.printGenericOpForm();
26 flags.skipRegions();
27 flags.useLocalScope();
28 stream << "ERROR: Runtime op verification failed\n";
29 op->print(stream, flags);
30 stream << "\n^ " << msg;
31 stream << "\nLocation: ";
32 op->getLoc().print(stream);
33 return buffer;
35 } // namespace mlir
37 /// Include the definitions of the interface.
38 #include "mlir/Interfaces/RuntimeVerifiableOpInterface.cpp.inc"