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 

More than one return statements in one method

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



Joined: 21 Jul 2009
Posts: 10

PostPosted: Fri Aug 14, 2009 8:51 am    Post subject: More than one return statements in one method Reply with quote

I had written code:-
interface Ha_IFC;
method Action start(Bit#(1) a,Bit#(1) b);
method Bit#(1) result();
endinterface

(*synthesize*)
module mkHa(Ha_IFC);

Reg#(Bit#(1)) sum<- mkReg(0);
Reg#(Bit#(1)) cout<- mkReg(0);

method Action start(Bit#(1) a,Bit#(1) b);
sum<= a ^ b;
cout<=a & b;
endmethod

method Bit#(1) result();
return sum;
return cout;
endmethod

endmodule

I am getting following error:-
Error: "HA.bsv", line 19, column 3: (P0030)
`return' must be at end of block. Perhaps `endmethod' is missin

Can you pls tell me whts the exact error?
Back to top
View user's profile Send private message Send e-mail
hadar_agam



Joined: 10 May 2007
Posts: 38

PostPosted: Fri Aug 14, 2009 10:34 am    Post subject: More than one return statements in one method Reply with quote

Nilay05,

Methods can only have one return statement. So you have two options:

1. your interface should have two separate methods for the two values that you want to return:

Code:
interface Ha_IFC;
  method Action start(Bit#(1) a,Bit#(1) b);
  method Bit#(1) result_sum();
  method Bit#(1) result_cout();
endinterface


2. have your method return a result of type Tuple2, or a struct:

Code:
typedef struct {Bit#(1) sum; Bit#(1) cout; } ResultT deriving (Bits, Eq);

interface Ha_IFC;
  method Action start(Bit#(1) a,Bit#(1) b);
  method ResultT result();
endinterface
Back to top
View user's profile Send private message Visit poster's website
quark
Site Admin


Joined: 02 Nov 2007
Posts: 499

PostPosted: Fri Aug 14, 2009 1:05 pm    Post subject: Re: More than one return statements in one method Reply with quote

Or, in this case, you could even combine the start and result methods into one method, which is either an ActionValue method or even a purely combinational value method:

Code:
interface IFC;
 method ResultT start(Bit#(1) a,Bit#(1) b);
endinterface

module mkHa(IFC);
 method ResultT start(Bit#(1) a,Bit#(1) b);
   return (ResultT { sum: a ^ b; cout: a & b });
 endmethod
endmodule

This also guarantees that there is only one result for each input. With separate start and result methods, you can buffer the data, but a Bluespec design would typically use FIFO instead of Reg, which also guarantees that only one result is returned for each input.
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