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 

Problem with typedefs/imports

 
Post new topic   Reply to topic    bluespec.com Forum Index -> Tools: BSC (Bluespec Compiler)
View previous topic :: View next topic  
Author Message
vmurali



Joined: 30 Jul 2008
Posts: 11

PostPosted: Wed Jun 29, 2011 2:01 pm    Post subject: Problem with typedefs/imports Reply with quote

If I typedef an interface in a new package, and import only the package containing the typedef, I am not able to access the methods of the interface. Is this a bug or is it intentional? The compiler version that I am using is 2011.04.C (build 23804, 2011-04-18 ).

I am listing a small test case to exploit this (three files: Test1.bsv, Test2.bsv, Test3.bsv)

Test1.bsv:
Code:

interface Test1;
  method Action req();
endinterface


Test2.bsv:
Code:

import Test1::*;

typedef Test1 Test2;

module mkTest2(Test2);
  method req = noAction;
endmodule


Test3.bsv:
Code:

import Test2::*;

module mkTest3();
  Test2 t <- mkTest2;

  rule r;
    t.req;
  endrule
endmodule


The error is


    Error: "Test3.bsv", line 7, column 7: (T0005)
    Unbound field `req'. Perhaps the name was mis-spelled or the type has not
    been imported.


If I change Test3.bsv to this, it compiles:

Code:

import Test1::*;
import Test2::*;

module mkTest3();
  Test2 t <- mkTest2;

  rule r;
    t.req;
  endrule
endmodule
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 496

PostPosted: Wed Jun 29, 2011 3:12 pm    Post subject: Re: Problem with typedefs/imports Reply with quote

I'll have to think about this some more, but I think it's the expected behavior. When you use typedef like this:
Code:
typedef T1 T2;

you're just creating an alias. You're not creating a whole new type.

And exporting the alias doesn't automatically export the types that it uses -- and that might be the "bug" to consider.

So ... when you define the packages Test1 and Test2, because you never wrote an "export" statement, BSC assumes that you want to export everything in the file ... that was defined in the file. So in Test2, BSC exports the type alias "Test2" and the module "mkTest2". BSC does not export the type "Test1".

A solution to your problem might be to define the package Test2 like this:
Code:
import Test1::*;

export Test1(..);
export Test2;
export mkTest2;


With this change, the package Test3 should only have to import Test2, and not also Test1.
Back to top
View user's profile Send private message
vmurali



Joined: 30 Jul 2008
Posts: 11

PostPosted: Wed Jun 29, 2011 4:35 pm    Post subject: Reply with quote

Alright thanks for the explanation.

For future reference, the syntax for 'export' is documented in the reference guide (Section: Packages and the outermost structure of a BSV design).

On a slightly related note, there seems to be an error in the reference guide

    To export all identi ers de fined in a package and all identi fiers
    from imported packages, export the package itself.


This didn't work. I had to explicitly export all the packages. In the above code, for example, according to the reference guide, if I wrote Test2.bsv this way, it should have worked
Code:

import Test1::*;

export Test2::*;

typedef Test1 Test2;

module mkTest2(Test2);
  method req = noAction;
endmodule


The example mentioned in the same section also seems to confirm that the above code should work.

However, to make it compile I had to explicitly add to Test2.bsv
Code:

export Test1::*;
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    bluespec.com Forum Index -> Tools: BSC (Bluespec Compiler) 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