MLIR  20.0.0git
RuntimeVerifiableOpInterface.cpp
Go to the documentation of this file.
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 //===----------------------------------------------------------------------===//
8 
10 
11 namespace mlir {
12 class Location;
13 class OpBuilder;
14 
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;
34 }
35 } // namespace mlir
36 
37 /// Include the definitions of the interface.
38 #include "mlir/Interfaces/RuntimeVerifiableOpInterface.cpp.inc"
Include the generated interface declarations.