KMLM List
View email archives for the history of this mailing list.
|
|
|
|
systemc-forum - Re: [Systemc-forum] Name Argument in sc_module
|
Message Thread:
Previous |
Next
|
- To: Slater Rob-R53680 <R.Slater@xxxxxxxxxxxx>
- From: Martin Janssen <Martin.Janssen@xxxxxxxxxxxx>
- Date: Thu, 04 Apr 2002 13:51:53 +0200
- Cc: systemc-forum <systemc-forum@xxxxxxxxxxxxxxxxxxx>
- Send Email to systemc-forum@osci.kavi.com:
- Send new message
- Reply to this message
|
Hi Rob,
(giving it another try to the forum)
One comment to your question inlined below.
Slater Rob-R53680 wrote:
[Martin's response didn't make it to the list. I've included
it below, along with my response to his response. -- R.S.]
Excellent!
But why not remove the sc_module() constructor which takes
no arguments? That way, I'd be forced to supply a name at
compile time.
Because a lot of existing code would break. Consider the following
code:
SC_MODULE(foobar) {
sc_in_clk clk;
void proc() { ... }
SC_CTOR(foobar) {
SC_THREAD(proc);
sensitive << clk.pos();
}
};
This code relies on a default constructor for sc_module, because foobar
is derived from sc_module, but the constructor does not initialize the
base class explicitly (the SC_CTOR macro doesn't do that, and although
it could, we cannot change it because that would again break existing
code).
Martin
-oo-
Rob
-----Original Message-----
From: Martin Janssen [mailto:Martin.Janssen@xxxxxxxxxxxx]
Sent: Thursday, April 04, 2002 12:50 PM
To: Rob Slater
Cc: SystemC Forum
Subject: Re: [Systemc-forum] Name Argument in sc_module
Hi Rob,
In the next release of SystemC (2.0.1, available around mid
April), you
do not get a core dump anymore, but an error message. E.g.
SystemC 2.0.1 --- Apr 4 2002 10:19:13
Copyright (c) 1996-2002 by all Contributors
ALL RIGHTS RESERVED
Error: (E533) module name stack is empty: did you forget to add a
sc_module_name parameter to your module constructor?
In file:
/home/pumba0/mjanssen/sc_rel201/sc_rel201/systemc_020402/src/s
ystemc/kernel/sc_object_manager.cpp:183
The use of a sc_module_name constructor parameter is
mandatory. Otherwise
an error message will be produced and the simulation is terminated.
You can access the name of any sc_object (including sc_module) with
the name() or basename() method, e.g.
Dog::printError()
{
cerr << sc_time_stamp() << ": " << name() << " has an error\n";
} // printError()
The name() method returns the full hierarchical instance name, whereas
the basename() methods returns the basename of name().
From an sc_module_name argument you can get the character
string by casting
it to const char*, e.g.
Dog::Dog( sc_module_name name_ )
: sc_module( name_ )
{
cout << (const char*) name_ << endl;
}
Martin
-oo-
Slater Rob-R53680 wrote:
Hi,
SystemC requires the use of a string name as an argument when
declaring a sc_module:
class Dog : public sc_module // Or SC_MODULE(Dog)
{
// ...
}; // class Dog
Dog barak("barak");
Failure to include a string name passes compilation, but
dumps core, e.g.:
Dog rover(); // Passes compilation; dumps core
First of all, "rover" above should either not pass compilation
or not dump core, i.e. if the compiler accepts it, it should work
at run time. I'm in favor of making the string argument mandatory
and having the compiler check this.
Two, if we are going to make string arguments mandatory, I'd
like to be able to access name so I can use this information
for debugging, reports, etc.
I propose something like this:
#include <cstring>
class sc_module : public sc_object
{
private:
const char *_moduleName;
public:
sc_module(const char* name) : _moduleName((const
char*)strdup(name))
{
// ...
}
// Other versions of sc_module's constructor
implemented as well...
const char* sc_get_module_name() const
{
return _moduleName;
}
~sc_module()
{
free((char*)_moduleName);
// ...
}
// ...
}; // class sc_module
I could then access the module name in my class:
Dog::printError()
{
cerr << sc_time_stamp() << ": " << sc_get_module_name()
<< " has an error\n";
} // printError()
And use it as follows:
Dog barak("barak");
//...
barak.printError();
// Prints --> 100: barak has an error
Rob Slater
Motorola Semiconductor Israel, Ltd. (MSIL)
_______________________________________________
Systemc-forum mailing list
Systemc-forum@xxxxxxxxxxxxxxxxxxx
https://server2.systemc.org/mailman/listinfo/systemc-forum
_______________________________________________
Systemc-forum mailing list
Systemc-forum@xxxxxxxxxxxxxxxxxxx
https://server2.systemc.org/mailman/listinfo/systemc-forum
|
|