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 

Define struct with a module element

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



Joined: 29 Oct 2011
Posts: 22

PostPosted: Mon Feb 20, 2017 2:26 pm    Post subject: Define struct with a module element Reply with quote

Code:
import RegFile::*;

typedef struct {
   String config_name;
   Integer num_elements;
   module#(RegFile#(Bit#(a), Bit#(d))) mkRF;
} SRAMConfig#(numeric type a, numeric type d);


I get the following error:

Internal Bluespec Compiler Error:
Please report this failure to your Bluespec technical contact.
If you do not know your contact, you may email support@bluespec.com.
The following internal error message should be included in your
correspondence along with any other relevant details:
Bluespec Compiler, version 2014.07.A (build 34078, 2014-07-30)
kcCType: TDefMonad
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 492

PostPosted: Mon Feb 20, 2017 5:47 pm    Post subject: Re: Define struct with a module element Reply with quote

This internal error occurs whenever you use the special type "module" outside of a "module..endmodule" block. (We will eventually make it a more helpful user error.)

Ordinary modules in BSV have the type "Module#(Ifc)". It's likely that you want to define the struct like this (with a capital M):
Code:
typedef struct {
   String config_name;
   Integer num_elements;
   Module#(RegFile#(Bit#(a), Bit#(d))) mkRF;
} SRAMConfig#(numeric type a, numeric type d);


An advanced feature of BSV, though, is support for new types of modules. You can extend the ordinary module to create your own types of modules with additional features. The way you specify the type of a module, is with a bracket syntax:
Code:
module [MyModuleType] mkMod (Ifc);
  ...
endmodule

An ordinary module could then be written like this:
Code:
module [Module] mkOrdinaryMod (Ifc);

When you write a module without specifying the type:
Code:
module mkSomeMod (Ifc);

you are giving a definition that can be used as any type module. It's as if you declared the module with a parameter variable for the type:
Code:
module [modType] mkSomeMod (Ifc);

And that's what the special type "module" is for. It stands in for the type of the module that's used in. So, if somewhere inside "mkSomeMod", you needed to explicitly give the type of the module, and you didn't explicitly declare the module with a variable like "modType", then "module" will stand in for that variable.

If you want "mkRF" in your struct to also be a generic module type, then you'll need to use a variable -- but not the reserved keyword "module". Use "m" for example:
Code:
typedef struct {
   String config_name;
   Integer num_elements;
   m#(RegFile#(Bit#(a), Bit#(d))) mkRF;
} SRAMConfig#(type m, numeric type a, numeric type d);

However, you may also need an "IsModule#(m,c)" proviso.

But, those are advanced concepts. If you're not using new module types, then just remember to write "Module" with a capital "M" for the type of modules.
Back to top
View user's profile Send private message
mehultikekar



Joined: 29 Oct 2011
Posts: 22

PostPosted: Tue Feb 21, 2017 3:11 pm    Post subject: Reply with quote

Thanks for the explanation. Out of curiosity, what is "c" in IsModule#(m, c)? I don't see it being used anywhere.
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 492

PostPosted: Tue Feb 21, 2017 4:55 pm    Post subject: Reply with quote

Yes, the variable "c" isn't mentioned.

When someone defines a new module type, they have to define an instance of the "IsModule" typeclass, which says how ordinary modules (of type "Module") can be used within this new module (of type "m"). Because you want to still be able to instantiate "mkReg" within in your new module.

The typeclass also defines how operators on ordinary modules can be applied to the new module. That's what the type variable "c" is needed for. It's a type that represents the extended data contained in the new module. An operator on "Module" is applied to the new "m" module by exporting the extended data, applying the operator on the core module that remains, and then putting the extended data back.

The variable "c" isn't mentioned because it is unique for each "m". In technical jargon, it is a dependent variable of the typeclass. Because it can be uniquely determined once you know "m".
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