Re: What is the proper way to instantiate a class?
- From: Jonathan Bromley <jonathan.bromley@xxxxxxxxxxxxx>
- Date: Tue, 28 Aug 2007 16:30:34 +0100
On Tue, 28 Aug 2007 14:44:32 -0000, mrfirmware wrote:
On Aug 28, 10:16 am, Jonathan Bromley wrote:
On Tue, 28 Aug 2007 13:54:20 -0000,
mrfirmware <mrfirmw...@xxxxxxxxx> wrote:
Ah, elaboration is something like linking then.
Somewhat, but of course it does all the static construction of the
instantiated module hierarchy.
That's just a bit over my head.
Nope. It's the dynamic construction that you OOP guys do that
goes over *our* heads. You see, it's kinda tough to build
hardware on-the-fly, so wee need a language that can specify
the static structure of the program in some detail...
Oh for Pete's sake. So my top.sv file has to be the last file
specified? What a PITA but okay, now I know. Thank you for that bit of
knowledge as it will save me hours of futzing around. I never would
have guessed the order in which you specified independent source files
Independent? When the second one uses a data type (class)
that was defined by the first? I don't think so. If you really
want that independence, at any cost, we can talk about type
parameters. But that is in bandit country...
to a compiler would matter but then again I've been doing embedded
software for the last 20 years so what do I know about SV? :-)
No, it's just that you're stuck with C's palaeolithic
textual-include mechanism for grabbing existing bits of Stuff.
Most SV tools proceed by compiling design units (=packages,
modules, interfaces, programs) into one or more libraries.
Once a package is compiled into a library, you can import
it into other compilations at any future time. As you said,
As long as I compile top.sv last, I can compile my
packages independently and in any order? That's not so bad.
"In any order" as long as they don't import one another,
of course.
Thanks again for your help. Now on to my ref problem:
** Error: (vsim-8282) top.sv(85): Actual argument expression for ref
formal "(null)" is not an equivalent type.
This is caused by a dynamic array ref. I want my class to expand my
supplied dynamic array ref as needed and fill it with data parsed from
an arbitrary length data field found in a file. I got this to work
when I didn't have packages or classes, e.g. thing.sv contained only a
module.
I think this is just trouble with type syntax...
[top.sv]
module top
import thing_pkg::*;
initial begin : main // Yes, a C programmer I am
byte data[];
Thing thing = new;
thing.test(data);
end
That looks fine to me.
[thing.sv]
package thing_pkg;
class Thing;
task automatic test(ref data[]);
At the very least this should be (ref byte data[]).
I would be a lot more comfortable if you had created
a typedef:
package thing_pkg;
typedef byte dab[]; // dynamic array of bytes
class Thing;
task automatic test(ref dab data);
data = new[4];
data[0] = 0;
data[1] = 1;
data[2] = 2;
data[3] = 3;
endtask
endclass
endpackage
and then, in your module,
module top;
import thing_pkg::*; // get "typedef dab" and "class Thing"
initial begin : main
dab data; // same effect as "byte data[];"
Thing thing = new;
thing.test(data);
$display("data has %0d elements", data.size());
foreach (data[i])
$display("data[%0d] = %0d", i, data[i]);
end
endmodule
But it works for me, with or without the typedef.
By the way: tasks and functions in a class have automatic
lifetime by default, so your "automatic" keyword is harmless
but redundant. And while we're on that issue, please don't
ever fall into the trap of confusing
class Mumble;
static task ST()... // class-wide task
task static TS()... // method with static lifetime
Oh, and one last thing: Your task "test" does not block -
it never consumes simulated time - so it would be better
coded as a void function. Try to reserve tasks for
activity that blocks by waiting for time delays or events.
--
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services
Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK
jonathan.bromley@xxxxxxxxxxxxx
http://www.MYCOMPANY.com
The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
.
- Follow-Ups:
- Re: What is the proper way to instantiate a class?
- From: mrfirmware
- Re: What is the proper way to instantiate a class?
- References:
- SV: What is the proper way to instantiate a class?
- From: mrfirmware
- Re: SV: What is the proper way to instantiate a class?
- From: Jonathan Bromley
- Re: What is the proper way to instantiate a class?
- From: mrfirmware
- Re: What is the proper way to instantiate a class?
- From: Jonathan Bromley
- Re: What is the proper way to instantiate a class?
- From: mrfirmware
- SV: What is the proper way to instantiate a class?
- Prev by Date: Re: What is the proper way to instantiate a class?
- Next by Date: Re: What is the proper way to instantiate a class?
- Previous by thread: Re: What is the proper way to instantiate a class?
- Next by thread: Re: What is the proper way to instantiate a class?
- Index(es):
Relevant Pages
|
|