Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/Remarks/RemarkParser.h
Line
Count
Source (jump to first uncovered line)
1
//===-- llvm/Remarks/Remark.h - The remark type -----------------*- C++/-*-===//
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
//
9
// This file provides an interface for parsing remarks in LLVM.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_REMARKS_REMARK_PARSER_H
14
#define LLVM_REMARKS_REMARK_PARSER_H
15
16
#include "llvm/ADT/SmallVector.h"
17
#include "llvm/ADT/StringRef.h"
18
#include "llvm/Remarks/Remark.h"
19
#include "llvm/Remarks/RemarkFormat.h"
20
#include "llvm/Support/Error.h"
21
#include <memory>
22
23
namespace llvm {
24
namespace remarks {
25
26
class EndOfFileError : public ErrorInfo<EndOfFileError> {
27
public:
28
  static char ID;
29
30
26
  EndOfFileError() {}
31
32
0
  void log(raw_ostream &OS) const override { OS << "End of file reached."; }
33
0
  std::error_code convertToErrorCode() const override {
34
0
    return inconvertibleErrorCode();
35
0
  }
36
};
37
38
/// Parser used to parse a raw buffer to remarks::Remark objects.
39
struct Parser {
40
  /// The format of the parser.
41
  Format ParserFormat;
42
43
51
  Parser(Format ParserFormat) : ParserFormat(ParserFormat) {}
44
45
  /// If no error occurs, this returns a valid Remark object.
46
  /// If an error of type EndOfFileError occurs, it is safe to recover from it
47
  /// by stopping the parsing.
48
  /// If any other error occurs, it should be propagated to the user.
49
  /// The pointer should never be null.
50
  virtual Expected<std::unique_ptr<Remark>> next() = 0;
51
52
51
  virtual ~Parser() = default;
53
};
54
55
/// In-memory representation of the string table parsed from a buffer (e.g. the
56
/// remarks section).
57
struct ParsedStringTable {
58
  /// The buffer mapped from the section contents.
59
  StringRef Buffer;
60
  /// This object has high changes to be std::move'd around, so don't use a
61
  /// SmallVector for once.
62
  std::vector<size_t> Offsets;
63
64
  ParsedStringTable(StringRef Buffer);
65
  /// Disable copy.
66
  ParsedStringTable(const ParsedStringTable &) = delete;
67
  ParsedStringTable &operator=(const ParsedStringTable &) = delete;
68
  /// Should be movable.
69
8
  ParsedStringTable(ParsedStringTable &&) = default;
70
  ParsedStringTable &operator=(ParsedStringTable &&) = default;
71
72
0
  size_t size() const { return Offsets.size(); }
73
  Expected<StringRef> operator[](size_t Index) const;
74
};
75
76
Expected<std::unique_ptr<Parser>> createRemarkParser(Format ParserFormat,
77
                                                     StringRef Buf);
78
79
Expected<std::unique_ptr<Parser>> createRemarkParser(Format ParserFormat,
80
                                                     StringRef Buf,
81
                                                     ParsedStringTable StrTab);
82
83
} // end namespace remarks
84
} // end namespace llvm
85
86
#endif /* LLVM_REMARKS_REMARK_PARSER_H */