bluespec.com Forum Index bluespec.com
Bluespec Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Unable to declare a Vector of CRegs

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ...
View previous topic :: View next topic  
Author Message
Neel



Joined: 13 Jun 2009
Posts: 5

PostPosted: Wed Jul 01, 2015 6:28 am    Post subject: Unable to declare a Vector of CRegs Reply with quote

Hi,

I wish to create a Vector of CRegs. Each CReg has 2 ports. Based from what I read in the reference guide, I tried the following:

Vector#(size,Reg#(Bit#(32))) status[2] <-replicateM(mkCReg(2,0));

But the following error pops up :

Type error at the use of the following function:
replicateM

The expected return type of the function:
e__#(Array#(Vector::Vector#(size, Reg#(All_types::LdStatus))))

The return type according to the use:
a__#(Vector::Vector#(c__, b__))

I next tried to create an Array of CReg in the following manner which worked :

Reg#(Bit#(32)) status[vsize][2] ;
for(Integer i=0;i<vsize;i=i+1)
status[i] <- mkCReg(2,0);

I would still prefer using a Vector of CRegs over an array of CReg since it allows using multiple functions/transformations easily. Is there a workaround for using Vector of CRegs?

regards,
Neel
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 500

PostPosted: Wed Jul 01, 2015 7:13 am    Post subject: Re: Unable to declare a Vector of CRegs Reply with quote

When you write this:
Code:
Vector#(size,Reg#(Bit#(32))) status[2]

you are declaring an array of Vectors. What you want is a Vector of arrays, which can be written like this:
Code:
Vector#(size,Array#(Reg#(Bit#(32)))) status

This uses the explicit type "Array". When you use bracket syntax, that is implicitly defining an "Array" type. But you can explicitly write "Array" in places where the bracket shorthand is not available.
Back to top
View user's profile Send private message
Neel



Joined: 13 Jun 2009
Posts: 5

PostPosted: Wed Jul 01, 2015 10:25 am    Post subject: Reply with quote

Thanks quark for the quick reply. Did the following and works like a charm :

Vector#(size,Array#(Reg#(Bit#(32)))) status <-replicateM(mkCReg(2,0));

regards,
Neel
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Designing with BSV's Rules, Interfaces, ... All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum
bluespec.com topic RSS feed 


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP