CIRCT 23.0.0git
Loading...
Searching...
No Matches
BMCTrace.h
Go to the documentation of this file.
1//===- BMCTrace.h - Runtime trace storage for circt-bmc ---------*- 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 defines the runtime trace store used by circt-bmc.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef CIRCT_TOOLS_CIRCT_BMC_BMCTRACE_H
14#define CIRCT_TOOLS_CIRCT_BMC_BMCTRACE_H
15
16#include "llvm/ADT/APInt.h"
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/FunctionExtras.h"
19#include "llvm/ADT/StringRef.h"
20#include "llvm/Support/raw_ostream.h"
21
22#include <optional>
23#include <string>
24#include <vector>
25
26namespace circt::bmc {
27
28class BMCTrace {
29public:
30 /// Opaque per-signal value reference recorded for a specific cycle.
31 using Handle = const void *;
32 /// Callback used to materialize a recorded handle into a concrete value when
33 /// formatting a trace. The provided width is the declared width of the
34 /// signal, which may be zero for i0 values.
35 using Evaluator =
36 llvm::function_ref<std::optional<llvm::APInt>(Handle, unsigned width)>;
37
38 /// Metadata for a tracked signal in the trace.
39 struct Signal {
40 std::string name;
41 unsigned width;
42 };
43
44 /// Create an empty trace for the given top-level design/module name.
45 explicit BMCTrace(llvm::StringRef topName = "bmc");
46
47 /// Register a signal to be tracked and return its stable index. Signals may
48 /// have zero width to represent i0 values.
49 size_t addSignal(llvm::StringRef name, unsigned width);
50 /// Record the value handle for a tracked signal at the given cycle.
51 void record(size_t step, size_t signal, Handle handle);
52
53 llvm::StringRef getTopName() const { return topName; }
54 llvm::ArrayRef<Signal> getSignals() const { return signals; }
55 size_t getNumSteps() const { return recorded.size(); }
56 /// Return the recorded handle for a signal at a given cycle, if present.
57 std::optional<Handle> lookup(size_t step, size_t signal) const;
58
59 /// Render the trace as cycle-by-cycle text using the provided evaluator to
60 /// materialize values from recorded handles.
61 bool printTextTrace(llvm::raw_ostream &os, Evaluator evaluate) const;
62
63private:
64 /// Per-cycle storage for all tracked signals.
65 using Step = std::vector<std::optional<Handle>>;
66
67 void ensureStep(size_t step);
68
69 std::string topName;
70 std::vector<Signal> signals;
71 std::vector<Step> recorded;
72};
73
74} // namespace circt::bmc
75
76#endif // CIRCT_TOOLS_CIRCT_BMC_BMCTRACE_H
llvm::StringRef getTopName() const
Definition BMCTrace.h:53
bool printTextTrace(llvm::raw_ostream &os, Evaluator evaluate) const
Render the trace as cycle-by-cycle text using the provided evaluator to materialize values from recor...
Definition BMCTrace.cpp:42
size_t getNumSteps() const
Definition BMCTrace.h:55
void ensureStep(size_t step)
Definition BMCTrace.cpp:24
std::vector< Step > recorded
Definition BMCTrace.h:71
const void * Handle
Opaque per-signal value reference recorded for a specific cycle.
Definition BMCTrace.h:31
llvm::ArrayRef< Signal > getSignals() const
Definition BMCTrace.h:54
size_t addSignal(llvm::StringRef name, unsigned width)
Register a signal to be tracked and return its stable index.
Definition BMCTrace.cpp:17
std::vector< std::optional< Handle > > Step
Per-cycle storage for all tracked signals.
Definition BMCTrace.h:65
llvm::function_ref< std::optional< llvm::APInt >(Handle, unsigned width)> Evaluator
Callback used to materialize a recorded handle into a concrete value when formatting a trace.
Definition BMCTrace.h:36
std::string topName
Definition BMCTrace.h:69
std::vector< Signal > signals
Definition BMCTrace.h:70
void record(size_t step, size_t signal, Handle handle)
Record the value handle for a tracked signal at the given cycle.
Definition BMCTrace.cpp:29
std::optional< Handle > lookup(size_t step, size_t signal) const
Return the recorded handle for a signal at a given cycle, if present.
Definition BMCTrace.cpp:36
Metadata for a tracked signal in the trace.
Definition BMCTrace.h:39