PandA-2024.02
vcd_parser.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
37 #ifndef VCD_PARSER_HPP
38 #define VCD_PARSER_HPP
39 
40 // include from STL
41 #include <list>
42 #include <stack>
43 #include <string>
44 #include <utility>
45 
46 #include "custom_map.hpp"
47 #include "custom_set.hpp"
48 
49 // include from parser/vcd/
50 #include "sig_variation.hpp"
51 
52 // include from utility/
53 #include "refcount.hpp"
54 
55 // forward declarations
57 
59 {
60  public:
62  std::string type;
64  bool is_vec;
66  size_t msb;
68  size_t lsb;
69  /*
70  * if the signal is a vector, this puts in relationship every bit in the
71  * vector with the vcd_id related to that bit. the size of this map can
72  * be: 0 if the signal is not a vector, 1 if the signal is a bit vector
73  * but in the vcd the variations are already grouped together, or (msb -
74  * lsb + 1) if the signal is a vector and in the vcd a different id is
75  * used for every bit
76  */
78 
79  vcd_sig_info(const std::string& _type, const bool _is_vec, const size_t _msb, const size_t _lsb)
80  : type(_type), is_vec(_is_vec), msb(_msb), lsb(_lsb)
81  {
82  }
83 };
84 
86 {
87  public:
92  explicit vcd_parser(const ParameterConstRef& params);
93 
102 
110 
118  vcd_trace_t parse_vcd(const std::string& vcd_file_to_parse, const vcd_parser::vcd_filter_t& selected_signals);
119 
120  private:
124  const int debug_level;
125 
126  // ---- METADATA ON THE PARSED FILE ----
127 
131  std::string vcd_filename;
132 
136  FILE* vcd_fp;
137 
141  unsigned long sig_n;
142 
149 
150  // ---- LOCAL MEMBERS TO HOLD INTERMEDIATE RESULTS DURING PARSE ----
151 
156 
160  std::map<std::pair<std::string, std::string>, vcd_sig_info> scope_and_name_to_sig_info;
161 
165  std::map<std::string, CustomUnorderedSet<std::pair<std::string, std::string>>> vcd_id_to_scope_and_name;
166 
167  /* Parses the simulation part in the vcd_file */
168  int vcd_parse_sim();
169 
170  /* Parses the definition part in the vcd_file */
171  int vcd_parse_def();
172 
173  /* Parses and ignore useless token */
174  int vcd_parse_skip_to_end();
175 
176  /* Parses $var token */
177  int vcd_parse_def_var(const std::string& scope);
178 
179  void vcd_push_def_scope(std::stack<std::string>& scope);
180 
181  void vcd_pop_def_scope(std::stack<std::string>& scope);
182 
183  /* Parses vector in simulation part */
184  int vcd_parse_sim_vector(char* value, unsigned long timestamp);
185 
186  /* Parses real in sumlation part (actually unused)*/
187  int vcd_parse_sim_real(char* value, unsigned long timestamp);
188 
199  bool check_filter_list(const std::string& scope_str, const std::string& name);
200 
212  void vcd_add_signal(const std::string& scope, const std::string& name, const std::string& vcd_id,
213  const std::string& type, const bool isvect, const unsigned int msb, const unsigned int lsb);
214 
218  bool check_signals() const;
219 
220  /* initializes the variations before parsing */
221  void init_variations();
222 
223  /* add the parsed variation to the proper signal */
224  void add_variation(const std::string& id, const std::string& value, unsigned long long ts);
225 };
226 #endif
vcd_trace_t parse_result
holds the parsed vcd trace during the parsing
Definition: vcd_parser.hpp:155
std::string vcd_filename
name of the vcd file to parse
Definition: vcd_parser.hpp:131
std::map< std::pair< std::string, std::string >, vcd_sig_info > scope_and_name_to_sig_info
maps every pair (scope, signal name) to the corresponding sig_info
Definition: vcd_parser.hpp:160
redefinition of map to manage ordered/unordered structures
size_t msb
position of the msb of this signal in the vector. valid only if is_vec == true
Definition: vcd_parser.hpp:66
CONSTREF_FORWARD_DECL(Parameter)
UnorderedMapStd< std::string, UnorderedSetStdStable< std::string > > vcd_filter_t
this is the type used to select which signals have to be filtered during parsing. ...
Definition: vcd_parser.hpp:101
absl::flat_hash_map< T, U, Hash, Eq, Alloc > CustomUnorderedMap
Definition: custom_map.hpp:148
unsigned long sig_n
total number of signals in the vcd file
Definition: vcd_parser.hpp:141
FILE * vcd_fp
file pointer to the vcd file to parse
Definition: vcd_parser.hpp:136
bool is_vec
true if the vcd_signal is part of a vector
Definition: vcd_parser.hpp:64
redefinition of set to manage ordered/unordered structures
vcd_filter_t filtered_signals
set of signals to select from the vcd file.
Definition: vcd_parser.hpp:148
UnorderedMapStd< std::string, CustomUnorderedMapStable< std::string, std::list< sig_variation > >> vcd_trace_t
this type is the result of a parse.
Definition: vcd_parser.hpp:109
size_t lsb
position of the lsb of this signal in the vector. valid only if is_vec == true
Definition: vcd_parser.hpp:68
vcd_sig_info(const std::string &_type, const bool _is_vec, const size_t _msb, const size_t _lsb)
Definition: vcd_parser.hpp:79
Template definition of refcount.
const int debug_level
Debug Level.
Definition: vcd_parser.hpp:124
std::unordered_map< T, U, Hash, Eq, Alloc > UnorderedMapStd
Autoheader include.
Definition: custom_map.hpp:56
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
CustomUnorderedMap< std::string, size_t > vcd_id_to_bit
Definition: vcd_parser.hpp:77
std::string type
the type of the signal in vcd file
Definition: vcd_parser.hpp:62
std::map< std::string, CustomUnorderedSet< std::pair< std::string, std::string > > > vcd_id_to_scope_and_name
maps every signal id in the vcd to the set of the corresponding pairs (scope, hdl signal name) ...
Definition: vcd_parser.hpp:165

Generated on Mon Feb 12 2024 13:02:55 for PandA-2024.02 by doxygen 1.8.13