CIRCT  19.0.0git
Trace.h
Go to the documentation of this file.
1 //===- Trace.h - Simulation trace definition --------------------*- 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 Trace class, used to handle the signal trace generation
10 // for the llhd-sim tool.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef CIRCT_DIALECT_LLHD_SIMULATOR_TRACE_H
15 #define CIRCT_DIALECT_LLHD_SIMULATOR_TRACE_H
16 
17 #include "State.h"
18 
19 #include <map>
20 #include <vector>
21 
22 namespace llvm {
23 class raw_ostream;
24 } // namespace llvm
25 
26 namespace circt {
27 namespace llhd {
28 namespace sim {
29 
31 
32 class Trace {
33  llvm::raw_ostream &out;
34  std::unique_ptr<State> const &state;
37  // Each entry defines if the respective signal is active for tracing.
38  std::vector<bool> isTraced;
39  // Buffer of changes ready to be flushed.
40  std::vector<std::pair<std::string, std::string>> changes;
41  // Buffer of changes for the merged formats.
42  std::map<std::pair<unsigned, int>, std::string> mergedChanges;
43  // Buffer of last dumped change for each signal.
44  std::map<std::pair<std::string, int>, std::string> lastValue;
45 
46  /// Push one change to the changes vector.
47  void pushChange(unsigned inst, unsigned sigIndex, int elem);
48  /// Push one change for each element of a signal if it is of a structured
49  /// type, or the full signal otherwise.
50  void pushAllChanges(unsigned inst, unsigned sigIndex);
51 
52  /// Add a merged change to the change buffer.
53  void addChangeMerged(unsigned);
54 
55  /// Sorts the changes buffer lexicographically wrt. the hierarchical paths.
56  void sortChanges();
57 
58  /// Flush the changes buffer to the output stream with full format.
59  void flushFull();
60  // Flush the changes buffer to the output stream with merged format.
61  void flushMerged();
62 
63 public:
64  Trace(std::unique_ptr<State> const &state, llvm::raw_ostream &out,
65  TraceMode mode);
66 
67  /// Add a value change to the trace changes buffer.
68  void addChange(unsigned);
69 
70  /// Flush the changes buffer to the output stream. The flush can be forced for
71  /// merged changes, flushing even if the next real-time step has not been
72  /// reached.
73  void flush(bool force = false);
74 };
75 } // namespace sim
76 } // namespace llhd
77 } // namespace circt
78 
79 #endif // CIRCT_DIALECT_LLHD_SIMULATOR_TRACE_H
The simulator's internal representation of time.
Definition: State.h:30
std::vector< bool > isTraced
Definition: Trace.h:38
void flush(bool force=false)
Flush the changes buffer to the output stream.
Definition: Trace.cpp:121
void addChangeMerged(unsigned)
Add a merged change to the change buffer.
Definition: Trace.cpp:94
std::map< std::pair< std::string, int >, std::string > lastValue
Definition: Trace.h:44
void pushChange(unsigned inst, unsigned sigIndex, int elem)
Push one change to the changes vector.
Definition: Trace.cpp:36
TraceMode mode
Definition: Trace.h:35
void addChange(unsigned)
Add a value change to the trace changes buffer.
Definition: Trace.cpp:75
void flushFull()
Flush the changes buffer to the output stream with full format.
Definition: Trace.cpp:130
std::vector< std::pair< std::string, std::string > > changes
Definition: Trace.h:40
std::unique_ptr< State > const & state
Definition: Trace.h:34
void pushAllChanges(unsigned inst, unsigned sigIndex)
Push one change for each element of a signal if it is of a structured type, or the full signal otherw...
Definition: Trace.cpp:62
Trace(std::unique_ptr< State > const &state, llvm::raw_ostream &out, TraceMode mode)
Definition: Trace.cpp:20
void sortChanges()
Sorts the changes buffer lexicographically wrt. the hierarchical paths.
Definition: Trace.cpp:113
llvm::raw_ostream & out
Definition: Trace.h:33
std::map< std::pair< unsigned, int >, std::string > mergedChanges
Definition: Trace.h:42
This file defines an intermediate representation for circuits acting as an abstraction for constraint...
Definition: DebugAnalysis.h:21