MLIR  19.0.0git
FileLineColLocBreakpointManager.cpp
Go to the documentation of this file.
1 //===- FileLineColLocBreakpointManager.cpp - MLIR Optimizer Driver --------===//
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 #include "mlir/IR/Diagnostics.h"
11 #include "llvm/Support/raw_ostream.h"
12 
13 using namespace mlir;
14 using namespace mlir::tracing;
15 
18  function_ref<void(Twine)> diag) {
19  // Watch at debug locations arguments are expected to be in the form:
20  // `fileName:line:col`, `fileName:line`, or `fileName`.
21 
22  if (str.empty()) {
23  if (diag)
24  diag("error: initializing FileLineColLocBreakpoint with empty file name");
25  return failure();
26  }
27 
28  // This logic is complex because on Windows `:` is a comment valid path
29  // character: `C:\...`.
30  auto [fileLine, colStr] = str.rsplit(':');
31  auto [file, lineStr] = fileLine.rsplit(':');
32  // Extract the line and column value
33  int64_t line = -1, col = -1;
34  if (lineStr.empty()) {
35  // No candidate for line number, try to use the column string as line
36  // instead.
37  file = fileLine;
38  if (!colStr.empty() && colStr.getAsInteger(0, line))
39  file = str;
40  } else {
41  if (lineStr.getAsInteger(0, line)) {
42  // Failed to parse a line number, try to use the column string as line
43  // instead. If this failed as well, the entire string is the file name.
44  file = fileLine;
45  if (colStr.getAsInteger(0, line))
46  file = str;
47  } else {
48  // We successfully parsed a line number, try to parse the column number.
49  // This shouldn't fail, or the entire string is the file name.
50  if (colStr.getAsInteger(0, col)) {
51  file = str;
52  line = -1;
53  }
54  }
55  }
56  return std::tuple<StringRef, int64_t, int64_t>{file, line, col};
57 }
static std::string diag(const llvm::Value &value)
This class provides support for representing a failure result, or a valid value of type T.
Definition: LogicalResult.h:78
static FailureOr< std::tuple< StringRef, int64_t, int64_t > > parseFromString(StringRef str, llvm::function_ref< void(Twine)> diag=[](Twine) {})
Parse a string representation in the form of "<file>:<line>:<col>".
Include the generated interface declarations.
LogicalResult failure(bool isFailure=true)
Utility function to generate a LogicalResult.
Definition: LogicalResult.h:62