README.md
Go to the documentation of this file.
1 
2 # VCD Tools
3 This is a multipurpose utility for handling VCD files.
4 It started as a fork of the excellent Verilog VCD Parser, therefore keeping its original README file below.
5 
6 ## Features
7 * Display full path of signals contained within th VCD file.
8 * Display the list of scopes within the VCD file.
9 * Display VCD file header
10 * Display number of toggles for each signal
11 * Restrict VCD file to a range of timestamps
12 
13 ## TODO
14 * Export VCD file (useful for producing a cut-down VCD file)
15 * Filter some signals/scopes (useful for the VCD export)
16 
17 Please see below for the original Verilog VCD Parser README.md file:
18 
19 ---
20 # Verilog VCD Parser
21 
22 [![Documentation](https://codedocs.xyz/ben-marshall/verilog-vcd-parser.svg)](https://codedocs.xyz/ben-marshall/verilog-vcd-parser/)
23 
24 This project implements a no-frills *Value Change Dump* (VCD) file parser, as
25 described in the IEEE System Verilog 1800-2012 standard. It can be used to
26 write custom tools which need to read signal traces dumped out by Verilog (or
27 VHDL) simulators.
28 
29 ---
30 
31 ## Getting Started
32 
33 After cloning the repository to your local machine, run the following in a
34 shell:
35 
36 ```sh
37 $> cd ./verilog-vcd-parser
38 $> make all
39 ```
40 
41 This will build both the demonstration executable in `build/vcd-parser` and
42 the API documentation in `build/docs`.
43 
44 ## Code Example
45 
46 This code will load up a VCD file and print the hierarchy of the scopes
47 and signals declared in it.
48 
49 ```cpp
50 VCDFileParser parser;
51 
52 VCDFile * trace = parser.parse_file("path-to-my-file.vcd");
53 
54 if(trace == nullptr) {
55  // Something went wrong.
56 } else {
57 
58  for(VCDScope * scope : *trace -> get_scopes()) {
59 
60  std::cout << "Scope: " << scope -> name << std::endl;
61 
62  for(VCDSignal * signal : scope -> signals) {
63 
64  std::cout << "\t" << signal -> hash << "\t"
65  << signal -> reference;
66 
67  if(signal -> size > 1) {
68  std::cout << " [" << signal -> size << ":0]";
69  }
70 
71  std::cout << std::endl;
72 
73  }
74  }
75 
76 }
77 ```
78 
79 We can also query the value of a signal at a particular time. Because a VCD
80 file can have multiple signals in multiple scopes which represent the same
81 physical signal, we use the signal hash to access it's value at a particular
82 time:
83 
84 ```cpp
85 // Get the first signal we fancy.
86 VCDSignal * mysignal = trace -> get_scope("$root") -> signals[0];
87 
88 // Print the value of this signal at every time step.
89 
90 for (VCDTime time : *trace -> get_timestamps()) {
91 
92  VCDValue * val = trace -> get_signal_value_at( mysignal -> hash, time);
93 
94  std::cout << "t = " << time
95  << ", " << mysignal -> reference
96  << " = ";
97 
98  // Assumes val is not nullptr!
99  switch(val -> get_type()) {
100  case (VCD_SCALAR):
101  std::cout << VCDValue::VCDBit2Char(val -> get_value_bit());
102  break;
103  case (VCD_VECTOR):
104  VCDBitVector * vecval = val -> get_value_vector()
105  for(auto it = vecval -> begin();
106  it != vecval -> end();
107  ++it) {
108  std::cout << VCDValue::VCDBit2Char(*it);
109  }
110  break;
111  case (VCD_REAL):
112  std::cout << val -> get_value_real();
113  default:
114  break;
115  }
116 
117  std::cout << endl;
118 
119 }
120 
121 ```
122 
123 The example above is deliberately verbose to show how common variables and
124 signal attributes can be accessed.
125 
126 
127 ## Integration
128 
129 It is assumed that given a set of source files, it will be easy for people to
130 integrate this as a submodule of their own projects. However, Flex and Bison
131 *must* be run before all compilable source files are present. If integrating
132 this into a larger project, you will want to ensure the following commands are
133 run before compiling any of the VCD parser sources.
134 
135 ```sh
136 $> make parser-srcs
137 ```
138 
139 This will run flex and bison on the `.ypp` and `.l` files in `src/` and put
140 the generated parser and lexer code in `build/`. The complete file list for
141 inclusion in a larger project is:
142 
143 ```
144 src/VCDFile.cpp
145 src/VCDFileParser.cpp
146 src/VCDValue.cpp
147 build/VCDParser.cpp
148 build/VCDScanner.cpp
149 ```
150 
151 With header files located in both `src/` and `build/`.
152 
153 ## Integration using static link library
154 
155 `build/libverilog-vcd-parser.a` and the required .hpp files are copied into `build/`.
156 
157 To use these from another application add -I and the .a file to your gcc command line:
158 
159 ```sh
160 $ gcc -Ibuild/ build/libverilog-vcd-parser.a myapp.cpp
161 ```
162 
163 
164 ## Tools
165 
166 - The parser and lexical analyser are written using Bison and Flex
167  respectively.
168 - The data structures and other functions are written using C++ 2011.
169 - The build system is GNU Make.
170 - The codebase is documented using Doxygen.