blob: b43a435e93bba563129597422c0121fedd3a01a4 [file] [log] [blame]
Andrew Scull0372a572018-11-16 15:47:06 +00001//===- BlockVerifier.h - FDR Block Verifier -------------------------------===//
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//
10// An implementation of the RecordVisitor which verifies a sequence of records
11// associated with a block, following the FDR mode log format's specifications.
12//
13//===----------------------------------------------------------------------===//
14#ifndef LLVM_INCLUDE_LLVM_XRAY_BLOCKVERIFIER_H_
15#define LLVM_INCLUDE_LLVM_XRAY_BLOCKVERIFIER_H_
16
17#include "llvm/XRay/FDRRecords.h"
18#include <array>
19#include <bitset>
20
21namespace llvm {
22namespace xray {
23
24class BlockVerifier : public RecordVisitor {
25public:
26 // We force State elements to be size_t, to be used as indices for containers.
27 enum class State : std::size_t {
28 Unknown,
29 BufferExtents,
30 NewBuffer,
31 WallClockTime,
32 PIDEntry,
33 NewCPUId,
34 TSCWrap,
35 CustomEvent,
36 Function,
37 CallArg,
38 EndOfBuffer,
39 StateMax,
40 };
41
42private:
43 // We keep track of the current record seen by the verifier.
44 State CurrentRecord = State::Unknown;
45
46 // Transitions the current record to the new record, records an error on
47 // invalid transitions.
48 Error transition(State To);
49
50public:
51 Error visit(BufferExtents &) override;
52 Error visit(WallclockRecord &) override;
53 Error visit(NewCPUIDRecord &) override;
54 Error visit(TSCWrapRecord &) override;
55 Error visit(CustomEventRecord &) override;
56 Error visit(CallArgRecord &) override;
57 Error visit(PIDRecord &) override;
58 Error visit(NewBufferRecord &) override;
59 Error visit(EndBufferRecord &) override;
60 Error visit(FunctionRecord &) override;
61
62 Error verify();
63 void reset();
64};
65
66} // namespace xray
67} // namespace llvm
68
69#endif // LLVM_INCLUDE_LLVM_XRAY_BLOCKVERIFIER_H_