10#include <framework/logging/Logger.h>
51 for (
int i = 0; i < size; i++) {
52 if (count[i] >= 0 && count[i] < 9) {
55 B2WARNING(
"invalid signal detected: " <<
static_cast<int>(count[i]));
66 int ini = padding ? signal.size() % 4 : 0;
67 std::string res(ini,
'0');
68 for (
auto const& bit : signal) {
69 if (bit >= 0 && bit < 9) {
72 B2WARNING(
"invalid signal detected: " <<
static_cast<int>(bit));
83 std::ios oldState(
nullptr);
84 oldState.copyfmt(std::cout);
85 if (std::any_of(signal.begin(), signal.end(), [](
char i)
86 {return i != zero_val && i != one_val;})) {
87 B2WARNING(
"Some bit in the signal vector is neither 0 nor 1. \n" <<
88 "Displaying binary values instead.");
92 std::cout << std::setfill(
'0');
93 for (
unsigned i = 0; i < signal.size(); i += 4) {
94 std::bitset<4> set(binString.substr(i, 4));
95 std::cout << std::setw(1) << std::hex << set.to_ulong();
99 std::cout.copyfmt(oldState);
106 if (std::any_of(signal.begin(), signal.end(), [](
char i)
107 {return i != zero_val;})) {
119 template<
size_t nbits,
size_t min,
size_t max>
120 std::bitset < max - min + 1 >
subset(std::bitset<nbits> set)
122 const size_t outWidth = max - min + 1;
123 std::string str = set.to_string();
124 return std::bitset<outWidth>(str.substr(nbits - max - 1, outWidth));
128#include <ext/stdio_filebuf.h>
130using __gnu_cxx::stdio_filebuf;
134inline stdio_filebuf<char>* fileBufFromFD(
int fd, std::_Ios_Openmode mode)
136 return (
new stdio_filebuf<char> (fd, mode));
139istream* createInStreamFromFD(
int fd)
141 stdio_filebuf<char>* fileBuf = fileBufFromFD(fd, std::ios::in);
142 return (
new istream(fileBuf));
145ostream* createOutStreamFromFD(
int fd)
147 stdio_filebuf<char>* fileBuf = fileBufFromFD(fd, std::ios::out);
148 return (
new ostream(fileBuf));
151std::string getcurrentdir()
154 getcwd(buf,
sizeof(buf) - 1);
155 buf[
sizeof(buf) - 1] = 0;
Helper class for software (C++) / firmware (VHDL) co-simulation.
std::bitset< max - min+1 > subset(std::bitset< nbits > set)
extract a subset of bitstring, like substring.
const char one_val
'1' in XSI VHDL simulation
void display_hex(const std::array< char, N > &signal)
Display signal in hex.
const char * std_logic_literal[]
In case you are not familiar with VHDL simulation, there are 9 possible values defined for the standa...
void display_nonzero_hex(const std::array< char, N > &signal)
Display nonzero value of signal in hex.
std::string slv_to_bin_string(std::array< char, N > signal, bool padding=false)
Transform into string.
std::string display_value(const char *count, int size)
Display value of the signal.
const char zero_val
'0' in XSI VHDL simulation