MLIR  22.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 
11 using namespace mlir;
12 using namespace mlir::tracing;
13 
14 FailureOr<std::tuple<StringRef, int64_t, int64_t>>
16  function_ref<void(Twine)> diag) {
17  // Watch at debug locations arguments are expected to be in the form:
18  // `fileName:line:col`, `fileName:line`, or `fileName`.
19 
20  if (str.empty()) {
21  if (diag)
22  diag("error: initializing FileLineColLocBreakpoint with empty file name");
23  return failure();
24  }
25 
26  // This logic is complex because on Windows `:` is a comment valid path
27  // character: `C:\...`.
28  auto [fileLine, colStr] = str.rsplit(':');
29  auto [file, lineStr] = fileLine.rsplit(':');
30  // Extract the line and column value
31  int64_t line = -1, col = -1;
32  if (lineStr.empty()) {
33  // No candidate for line number, try to use the column string as line
34  // instead.
35  file = fileLine;
36  if (!colStr.empty() && colStr.getAsInteger(0, line))
37  file = str;
38  } else {
39  if (lineStr.getAsInteger(0, line)) {
40  // Failed to parse a line number, try to use the column string as line
41  // instead. If this failed as well, the entire string is the file name.
42  file = fileLine;
43  if (colStr.getAsInteger(0, line))
44  file = str;
45  } else {
46  // We successfully parsed a line number, try to parse the column number.
47  // This shouldn't fail, or the entire string is the file name.
48  if (colStr.getAsInteger(0, col)) {
49  file = str;
50  line = -1;
51  }
52  }
53  }
54  return std::tuple<StringRef, int64_t, int64_t>{file, line, col};
55 }
static std::string diag(const llvm::Value &value)
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.