]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/llvm/XRay/FDRRecordConsumer.h
Vendor import of llvm trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / include / llvm / XRay / FDRRecordConsumer.h
1 //===- FDRRecordConsumer.h - XRay Flight Data Recorder Mode Records -------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_INCLUDE_LLVM_XRAY_FDRRECORDCONSUMER_H_
10 #define LLVM_INCLUDE_LLVM_XRAY_FDRRECORDCONSUMER_H_
11
12 #include "llvm/Support/Error.h"
13 #include "llvm/XRay/FDRRecords.h"
14 #include <algorithm>
15 #include <memory>
16 #include <vector>
17
18 namespace llvm {
19 namespace xray {
20
21 class RecordConsumer {
22 public:
23   virtual Error consume(std::unique_ptr<Record> R) = 0;
24   virtual ~RecordConsumer() = default;
25 };
26
27 // This consumer will collect all the records into a vector of records, in
28 // arrival order.
29 class LogBuilderConsumer : public RecordConsumer {
30   std::vector<std::unique_ptr<Record>> &Records;
31
32 public:
33   explicit LogBuilderConsumer(std::vector<std::unique_ptr<Record>> &R)
34       : RecordConsumer(), Records(R) {}
35
36   Error consume(std::unique_ptr<Record> R) override;
37 };
38
39 // A PipelineConsumer applies a set of visitors to every consumed Record, in the
40 // order by which the visitors are added to the pipeline in the order of
41 // appearance.
42 class PipelineConsumer : public RecordConsumer {
43   std::vector<RecordVisitor *> Visitors;
44
45 public:
46   PipelineConsumer(std::initializer_list<RecordVisitor *> V)
47       : RecordConsumer(), Visitors(V) {}
48
49   Error consume(std::unique_ptr<Record> R) override;
50 };
51
52 } // namespace xray
53 } // namespace llvm
54
55 #endif // LLVM_INCLUDE_LLVM_XRAY_FDRRECORDCONSUMER_H_