11#include "llvm/ADT/SmallString.h"
18 signals.push_back({name.str(), width});
19 for (
auto &step : recorded)
20 step.resize(signals.size());
21 return signals.size() - 1;
25 if (step >= recorded.size())
26 recorded.resize(step + 1,
Step(signals.size()));
30 assert(signal < signals.size() &&
"signal index out of range");
32 recorded[step][signal] = handle;
35std::optional<circt::bmc::BMCTrace::Handle>
37 if (step >= recorded.size() || signal >= signals.size())
39 return recorded[step][signal];
44 os <<
"counterexample for " << topName <<
":\n";
45 for (
size_t step = 0, e = recorded.size(); step != e; ++step) {
46 os <<
"cycle " << step <<
":\n";
47 for (
size_t signal = 0, numSignals = signals.size(); signal != numSignals;
49 auto handle = recorded[step][signal];
52 auto value = evaluate(*handle, signals[signal].width);
53 if (!value || value->getBitWidth() != signals[signal].width)
55 llvm::SmallString<40> str;
56 value->toString(str, 16,
false,
58 os <<
" " << signals[signal].name <<
" = 0x" << str <<
"\n";
assert(baseType &&"element must be base type")
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...
void ensureStep(size_t step)
BMCTrace(llvm::StringRef topName="bmc")
Create an empty trace for the given top-level design/module name.
const void * Handle
Opaque per-signal value reference recorded for a specific cycle.
size_t addSignal(llvm::StringRef name, unsigned width)
Register a signal to be tracked and return its stable index.
std::vector< std::optional< Handle > > Step
Per-cycle storage for all tracked signals.
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.
void record(size_t step, size_t signal, Handle handle)
Record the value handle for a tracked signal at the given cycle.
std::optional< Handle > lookup(size_t step, size_t signal) const
Return the recorded handle for a signal at a given cycle, if present.