HAL  v4.5.0-83-g30c8f0afc
The Hardware Analyzer - a comprehensive reverse engineering and manipulation framework for gate-level netlists.
saleae_parser.cpp
Go to the documentation of this file.
1 #ifdef STANDALONE_PARSER
2 #include "saleae_parser.h"
3 #include "saleae_file.h"
4 #else
7 #include "hal_core/netlist/net.h"
8 #endif
9 #include <fstream>
10 #include <sstream>
11 #include <stdio.h>
12 #include <cctype>
13 #include <iostream>
14 
15 namespace hal
16 {
17  uint64_t SaleaeParser::sTimeScaleFactor = 1000000000;
18 
19  SaleaeParser::SaleaeParser(const std::string& filename)
20  : mSaleaeDirectory(filename)
21  {;}
22 
23  std::string SaleaeParser::strim(std::string s)
24  {
25  if (s.empty()) return s;
26  int p0 = 0;
27  int p1 = s.length()-1;
28  while (p0 <= p1 && isspace(s.at(p0))) p0++;
29  while (p0 <= p1 && isspace(s.at(p1))) p1--;
30  if (s.at(p0) == '"' && s.at(p1) == '"' && p1-p0 >= 2)
31  {
32  ++p0;
33  --p1;
34  }
35  return s.substr(p0,p1-p0+1);
36  }
37 
39  {
40  auto it = mNextValueMap.begin();
41  if (it == mNextValueMap.end()) return false;
42  uint64_t currT = it->first;
43  DataFileHandle wff = it->second;
44  mNextValueMap.erase(it);
45 // std::cerr << "SaleaeParser::callback o=" << std::hex << (uintptr_t)wff.obj << " t=" << std::dec << currT << " v=" << wff.value << " size=" << mNextValueMap.size() << std::endl;
46  wff.callback(wff.obj,currT,wff.value);
47  if (wff.file->good())
48  {
49  SaleaeDataTuple sdt = wff.file->get_next_value();
50  if (!sdt.readError())
51  {
52  wff.value = sdt.mValue;
53  uint64_t nextT = sdt.mTime;
54  mNextValueMap.insert(std::pair<uint64_t,DataFileHandle>(nextT,wff));
55  }
56  else
57  delete wff.file;
58  }
59  else
60  delete wff.file;
61  return true;
62  }
63 
64  uint64_t SaleaeParser::get_max_time() const
65  {
66  return mSaleaeDirectory.get_max_time();
67  }
68 
69  bool SaleaeParser::register_callback(const Net *net, std::function<void(void*,uint64_t, int)> callback, void *obj)
70  {
71  return register_callback(net->get_name(), net->get_id(), callback, obj);
72  }
73 
74  bool SaleaeParser::register_callback(const std::string& name, uint32_t id, std::function<void(void*,uint64_t, int)> callback, void *obj)
75  {
76 // std::cerr << "SaleaeParser::register_callback <" << net->get_name() << "> " << std::hex << (uintptr_t) obj << std::endl;
77  std::string path = mSaleaeDirectory.get_datafile_path(name,id);
78  if (path.empty()) return false;
79  SaleaeInputFile* datafile = new SaleaeInputFile(path);
80  if (!datafile->good())
81  {
82  std::cerr << "Error loading SALEAE datafile <" << datafile->get_last_error()
83  << "> path: <" << path << "> net: <" << name << "> id: " << id << std::endl;
84  delete datafile;
85  return false;
86  }
87  mNextValueMap.insert(std::pair<uint64_t,DataFileHandle>(0,{callback, datafile, datafile->get_next_value().mValue, obj}));
88  return true;
89  }
90 }
Definition: net.h:58
int mValue
Data value.
Definition: saleae_file.h:171
uint64_t mTime
Transition time.
Definition: saleae_file.h:168
bool readError() const
Indicates that there was an error and no data was returned.
Definition: saleae_file.h:174
std::string get_datafile_path(int index) const
Get full path to waveform data file.
uint64_t get_max_time() const
Getter for maximum time.
SaleaeDataTuple get_next_value()
Getter for next (time,value) tuple in sequential read.
std::string get_last_error() const
Get verbose error message based on internal status, empty string if no error.
bool next_event()
Call to parser to deliver next event via registered callbacks (see above).
bool register_callback(const std::string &name, uint32_t id, std::function< void(void *, uint64_t, int)> callback, void *obj)
Registers callback which gets executed upon next_event()
uint64_t get_max_time() const
Get last simulated time from SALEAE directory.
static uint64_t sTimeScaleFactor
conversion factor to be applied when converting double values from original SALEAE file to integer va...
SaleaeParser(const std::string &filename)
Definition: defines.h:45
Net * net
std::string name