Jump to content

How to trace std::list<int> with sc_trace? [solved]


SiGa

Recommended Posts

Hello Forum,

I want to have std::list<int> as type for a sc_port and sc_signal. 

In the e-book "SystemC : From The Ground Up" and "IEEE Std 1666™-2011" I found the necessary information.

So I created a wrapper class that implements the necessary overloaded operators, and the sc_trace function that are needed for this purpose.

// List that is traceable by sc_trace																				  
class TraceList {
private:
	std::list<int> lst;
public:
	// Methods for accessing list
	std::list<int>& read() {
		return lst;
	}
	void write(std::list<int> var) {
		lst = var;
	}

	// CTOR
	TraceList() {
	}
	// CTOR for init values
	TraceList(std::list<int> var) {
		lst = var;
	}

	// Required by sc_signal<> and sc_fifo<>
	TraceList& operator= (const TraceList& var) {
		lst = var.lst;
		return *this;
	}
	// Required by sc_signal<>
	bool operator== (const TraceList& var) const {
		return lst == var.lst;
	}
	// Required functions by SystemC
	friend ostream& operator<< (ostream& os, const TraceList& var) {
		os << "{";
		auto it = var.lst.begin();
		while (it != var.lst.end()) {
			os << *it;
			it = std::next(it);
		}
		os << "}";
		return os;
	}
	void sc_trace(sc_trace_file* tf, const TraceList& var, const std::string& nm) {
		int pos = 0;
		auto it = var.lst.begin();
		while (it != var.lst.end()) {
			// use namespace, compiler otherwise chooses wrong function
			sc_core::sc_trace(tf, *it, nm + std::to_string(pos++));
			it = std::next(it);
		}
	}
};

 

I get these kind of errors:

Severity    Code    Description    Project    File    Line    Suppression State
Error    C2665    'sc_core::sc_trace': none of the 60 overloads could convert all the argument types    MILBUS_CoSimulator    c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\communication\sc_signal_ports.h    307    
Error    C2665    'sc_core::sc_trace': none of the 60 overloads could convert all the argument types    MILBUS_CoSimulator    c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\communication\sc_signal_ports.h    1144    
Error    C2665    'sc_core::sc_trace': none of the 60 overloads could convert all the argument types    MILBUS_CoSimulator   c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h    279     

Reading the output of the compiler gives me the hint that this errors are caused by a non matching overload of sc_trace.

1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\communication\sc_signal_ports.h(307): error C2665: 'sc_core::sc_trace': none of the 60 overloads could convert all the argument types
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(324): note: could be 'void sc_core::sc_trace(sc_core::sc_trace_file *,const void *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(249): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxnum_fast *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(249): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxnum_fast &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(248): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxnum *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(248): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxnum &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(247): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxval_fast *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(247): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxval_fast &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(246): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxval *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(246): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxval &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(244): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_lv_base *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(244): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_lv_base &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(243): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_bv_base *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(243): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_bv_base &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(241): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_unsigned *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(241): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_unsigned &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(240): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_signed *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(240): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_signed &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(239): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_uint_base *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(239): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_uint_base &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(238): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_int_base *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(238): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_int_base &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(236): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_logic *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(236): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_logic &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(235): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_bit *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(235): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_bit &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(232): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::uint64 *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(232): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::uint64 &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(231): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::int64 *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(231): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::int64 &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(230): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const long *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(230): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const long &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(229): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const int *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(229): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const int &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(228): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const short *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(228): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const short &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(227): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const char *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(227): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const char &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(226): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned long *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(226): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned long &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(225): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned int *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(225): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned int &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(224): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned short *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(224): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned short &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(223): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned char *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(223): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned char &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(221): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const double *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(221): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const double &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(220): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const float *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(220): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const float &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(219): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const bool *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(219): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const bool &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(217): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_core::sc_time *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(217): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_core::sc_time &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(216): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_core::sc_event *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(216): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_core::sc_event &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\communication\sc_signal_ports.h(307): note: while trying to match the argument list '(sc_core::sc_trace_file *, const T, std::string)'
1>        with
1>        [
1>            T=TraceList
1>        ]

 

Why is the overloading of sc_trace not working?

What am I doing wrong?

Is my approach a bad choice and should I solve it in a different way? If yes, which one?

 

 

Link to comment
Share on other sites

Your sc_trace function is a member function of the TraceList class and cannot be called like the sc_trace functions coming with the SystemC reference implementation. Those are free functions in the sc_core namespace.

Moreover your sc_trace implementation is non-static so it cannot be used without a TraceList object. You need to move the function out of the class scope.

Basically this is a valid approach to setup complex types. But under performance considerations I would suggest to use a different container. Best choices are std::vector or std::dqueue. And if you are using C++ 11 I would replace the while loop with a range based loop, something like:

for(auto& val: var.lst) {
  // use namespace, compiler otherwise chooses wrong function
  sc_core::sc_trace(tf, val, nm + std::to_string(pos++));
}

 

Link to comment
Share on other sites

Out of curiosity, Eyck, is this actually correct/safe to do with a std::list (or std::vector or similar)? My understanding is that

void sc_trace(sc_trace_file* tf, const TraceList& var, const std::string& nm);

would be called once when you're calling the sc_trace for the signal/port/... carrying the TraceList, and the kernel would then keep the references to the list's elements.

Now, assuming that TraceList's internal std::list would actually hold a non-constant amount of objects during the simulation, I guess you would run into the problem that the references to its members that you passed to sc_trace would be left dangling once the std::list's elements are reallocated for whatever reason (not as likely with a std::list than with a std::vector, but still a problem). Additionally, as far as I understood this, VCD's cannot deal with a varying amount of elements to be traced.

So, by my understanding, the proposed method would only be safe to use if the list is known to hold a constant amount of values throughout the simulation (including during startup). I'm not sure whether SystemC's tracing mechanism can deal with a is non-constant amount of elements to be traced at all.

 

Link to comment
Share on other sites

2 hours ago, rainer said:

So, by my understanding, the proposed method would only be safe to use if the list is known to hold a constant amount of values throughout the simulation (including during startup). I'm not sure whether SystemC's tracing mechanism can deal with a is non-constant amount of elements to be traced at all.

This is correct, you cannot trace dynamic data structure. This is not even a SystemC limitation, but limitation of VCD waveform dump in general. VCD does not allow to add/remove signals to waveform dynamically.

So usually you have two options

1) If maximum capacity is known in advance and is small, you can create your own "list" that utilizes statically sized array as a storage:

template<typename T>
struct my_list_item 
{
  bool has_value = false;
  T value;
}

template<typename T, size_t MAX_SIZE>
class my_list 
{
  std::array<my_list_item, MAX_SIZE> storage;
  // ...
}

2) If maximum size is large or unknown, but it is sufficient for you to trace only head and tail of the list, you can have a copy of tail and head that is updated on every push and pop:

class my_list 
{
std::list<T> storage;
my_list_item head_copy;
my_list_item tail_copy;
//... custom push pop
}

 

Link to comment
Share on other sites

@Eyck Thank you for the hint. Now that I know it, I also saw that it was done that way in the book, and I didn't spot the closing curly bracket.

My overloaded sc_trace function is only matched correctly, when I don't use a ref for the TraceList argument.

void sc_trace(sc_trace_file* tf, TraceList& var, const std::string& nm); // doesn't work
void sc_trace(sc_trace_file* tf, TraceList var, const std::string& nm); // works

Compiler output for not working case:

1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\communication\sc_signal_ports.h(307): error C2665: 'sc_trace': none of the 61 overloads could convert all the argument types
1>c:\users\xx\xx\xx\milbus_cosimulator\helper.h(96): note: could be 'void sc_trace(sc_core::sc_trace_file *,TraceList &,const std::string &)' [found using argument-dependent lookup]
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(324): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const void *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(249): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxnum_fast *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(249): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxnum_fast &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(248): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxnum *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(248): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxnum &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(247): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxval_fast *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(247): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxval_fast &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(246): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxval *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(246): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxval &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(244): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_lv_base *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(244): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_lv_base &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(243): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_bv_base *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(243): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_bv_base &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(241): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_unsigned *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(241): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_unsigned &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(240): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_signed *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(240): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_signed &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(239): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_uint_base *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(239): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_uint_base &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(238): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_int_base *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(238): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_int_base &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(236): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_logic *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(236): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_logic &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(235): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_bit *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(235): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_bit &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(232): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::uint64 *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(232): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::uint64 &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(231): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::int64 *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(231): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::int64 &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(230): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const long *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(230): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const long &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(229): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const int *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(229): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const int &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(228): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const short *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(228): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const short &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(227): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const char *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(227): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const char &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(226): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned long *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(226): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned long &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(225): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned int *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(225): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned int &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(224): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned short *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(224): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned short &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(223): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned char *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(223): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned char &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(221): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const double *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(221): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const double &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(220): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const float *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(220): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const float &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(219): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const bool *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(219): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const bool &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(217): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_core::sc_time *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(217): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_core::sc_time &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(216): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_core::sc_event *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(216): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_core::sc_event &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\communication\sc_signal_ports.h(307): note: while trying to match the argument list '(sc_core::sc_trace_file *, const T, std::string)'
1>        with
1>        [
1>            T=sim_type
1>        ]
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\communication\sc_signal_ports.h(302): note: while compiling class template member function 'void sc_core::sc_in<T>::end_of_elaboration(void)'
1>        with
1>        [
1>            T=sim_type
1>        ]
1>c:\users\xx\xx\xx\milbus_cosimulator\milbus_if.h(14): note: see reference to class template instantiation 'sc_core::sc_in<T>' being compiled
1>        with
1>        [
1>            T=sim_type
1>        ]
1>c:\users\xx\xx\xx\milbus_cosimulator\milbus_if_with_model.h(14): note: see reference to class template instantiation 'milbus_if_inputs<sim_type>' being compiled
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\communication\sc_signal_ports.h(1144): error C2665: 'sc_trace': none of the 61 overloads could convert all the argument types

With sim_type being:

typedef TraceList sim_type;

Why is it like that?

Link to comment
Share on other sites

On 11/14/2019 at 1:54 PM, SiGa said:

@Eyck Thank you for the hint. Now that I know it, I also saw that it was done that way in the book, and I didn't spot the closing curly bracket.

My overloaded sc_trace function is only matched correctly, when I don't use a ref for the TraceList argument.


void sc_trace(sc_trace_file* tf, TraceList& var, const std::string& nm); // doesn't work
void sc_trace(sc_trace_file* tf, TraceList var, const std::string& nm); // works

Compiler output for not working case:


1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\communication\sc_signal_ports.h(307): error C2665: 'sc_trace': none of the 61 overloads could convert all the argument types
1>c:\users\xx\xx\xx\milbus_cosimulator\helper.h(96): note: could be 'void sc_trace(sc_core::sc_trace_file *,TraceList &,const std::string &)' [found using argument-dependent lookup]
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(324): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const void *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(249): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxnum_fast *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(249): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxnum_fast &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(248): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxnum *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(248): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxnum &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(247): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxval_fast *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(247): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxval_fast &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(246): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxval *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(246): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_fxval &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(244): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_lv_base *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(244): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_lv_base &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(243): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_bv_base *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(243): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_bv_base &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(241): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_unsigned *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(241): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_unsigned &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(240): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_signed *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(240): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_signed &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(239): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_uint_base *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(239): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_uint_base &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(238): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_int_base *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(238): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_int_base &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(236): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_logic *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(236): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_logic &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(235): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_bit *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(235): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::sc_bit &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(232): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::uint64 *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(232): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::uint64 &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(231): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::int64 *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(231): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_dt::int64 &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(230): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const long *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(230): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const long &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(229): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const int *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(229): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const int &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(228): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const short *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(228): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const short &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(227): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const char *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(227): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const char &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(226): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned long *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(226): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned long &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(225): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned int *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(225): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned int &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(224): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned short *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(224): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned short &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(223): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned char *,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(223): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const unsigned char &,const std::string &,int)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(221): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const double *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(221): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const double &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(220): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const float *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(220): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const float &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(219): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const bool *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(219): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const bool &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(217): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_core::sc_time *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(217): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_core::sc_time &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(216): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_core::sc_event *,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\tracing\sc_trace.h(216): note: or       'void sc_core::sc_trace(sc_core::sc_trace_file *,const sc_core::sc_event &,const std::string &)'
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\communication\sc_signal_ports.h(307): note: while trying to match the argument list '(sc_core::sc_trace_file *, const T, std::string)'
1>        with
1>        [
1>            T=sim_type
1>        ]
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\communication\sc_signal_ports.h(302): note: while compiling class template member function 'void sc_core::sc_in<T>::end_of_elaboration(void)'
1>        with
1>        [
1>            T=sim_type
1>        ]
1>c:\users\xx\xx\xx\milbus_cosimulator\milbus_if.h(14): note: see reference to class template instantiation 'sc_core::sc_in<T>' being compiled
1>        with
1>        [
1>            T=sim_type
1>        ]
1>c:\users\xx\xx\xx\milbus_cosimulator\milbus_if_with_model.h(14): note: see reference to class template instantiation 'milbus_if_inputs<sim_type>' being compiled
1>c:\users\xx\xx\xx\systemc-2.3.3\src\sysc\communication\sc_signal_ports.h(1144): error C2665: 'sc_trace': none of the 61 overloads could convert all the argument types

With sim_type being:


typedef TraceList sim_type;

Why is it like that?


 

When I add the 'const' keyqord to the reference parameter it works.

void sc_trace(sc_trace_file* tf, const TraceList& var, const std::string& nm); // works

Additionally I had to change my read method.

// Old
std::list<int>& read() {
	return lst;
}
// New
const std::list<int>& read() const {
	return lst;
}

 

 

I could not trace the values of a list, even when the size of the list remained constant. So I tried it with a vector and created TraceVector. The size of the vector will be 4. There are some size checks missing to ensure this, but that's not what I try to show with this.

class TraceVector {
private:
	std::vector<int> vec;
public:
	// Methods for accessing list
	const std::vector<int>& read() const {
		return vec;
	}
	void write(std::vector<int> var) {
		this->vec.assign(var.begin(), var.end());
	}

	// CTOR
	TraceVector() {
		vec.reserve(4);
	}
	// CTOR for init values
	TraceVector(std::vector<int> var) {
		vec = var;
	}

	// Required by sc_signal<> and sc_fifo<>
	TraceVector operator= (const TraceVector& var) {
		write(var.read());
		return *this;
	}
	// Required by sc_signal<>
	bool operator== ( const TraceVector& var) const {
		auto temp = var.read();
		// size check
		if (temp.size() != vec.size()) {
			return false;
		}
		// element wise comparison
		bool equal = std::equal(vec.begin(), vec.end(), temp.begin());
		return equal;
	}
};
// Required functions by SystemC
ostream& operator<< (ostream& os, TraceVector var);
void sc_trace(sc_trace_file* tf, const TraceVector& var, const std::string& nm);

Since I can not store multiple values in one datatype and trace it, I decided to create a trace for each element in the vector.

void sc_trace(sc_trace_file* tf, const TraceVector& var, const std::string& nm) {
	int pos = 0;
	sc_core::sc_trace(tf, 0, nm + "_test");
	for (auto val : var.read()) {
		// use namespace, compiler otherwise chooses wrong function
		sc_core::sc_trace(tf, val, nm + "_" + std::to_string(pos++));
	}
}

The result looks like this:

image.thumb.png.d00c3997d4fa634644380ed91e715858.png

The displayed values are not the values from the vector. 

Even the value of test_test is not 0, even though I set it to a constant 0.

Somebody knows why sc_trace is tracing the wrong values?

Link to comment
Share on other sites

I see at least 1 bug in code sample:

for (auto val : var.read())

here you create copies of vector elements on a stack of your function. And then pass references to them into SystemC kernel. So those will be dangling references one you return from your sc_trace overload.

Change to:

for (auto & val : var.read())

 

Link to comment
Share on other sites

Thank you for the explanation, I changed it.

To prove your statement I tried it with a static integer, and it is traced correctly. 

 

About the remaining bugs, regarding dangling references.

Only private member of my class is

private:
	std::vector<int> vec;

Access methods return ref to vec or store elements of passed argument inside the local ref, by copying. I added an exception for invalid vector size, to avoid reallocation of vector and thus dangling references.

const std::vector<int>& read() const {
	return vec;
}
void write(std::vector<int> var) {
	if (var.size() != 4) {
		throw std::invalid_argument("Argument is not size 4!");
	}
	this->vec.assign(var.begin(), var.end());
}

The assignment operator uses the write method.

TraceVector operator= (const TraceVector& var) {
	write(var.read());
	return *this;
}

 

I don't see the error where I leave dangling references that would cause the sc_trace mechanism to display wrong values.

In sc_main I declare my sc_signal like this

typedef TraceVector sim_type; // typedef for swapping signal type in one code line
#define SIM_TYPE_INIT std::vector<int>{9999,9999,9999,9999} // different type needs different inits

sc_main() {
...
	sc_signal< sim_type, SC_MANY_WRITERS> test{"test", SIM_TYPE_INIT };
...
	sc_trace_file *tf = sc_create_vcd_trace_file("traces");
	sc_trace(tf, test, "test");
  
	sc_start();
	sc_close_vcd_trace_file(tf);
}

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...