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 

Compilation Error

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



Joined: 18 Feb 2014
Posts: 3

PostPosted: Fri Mar 21, 2014 2:38 am    Post subject: Compilation Error Reply with quote

I am trying to run the code to add two results obtained by 2 multiplication task

z1 and z2 are the results and I want to add them using the code shown below.

DO_CYCLE2 doesnt pass the results to do_cycle3 rather it returns a garbage result.
Both the rules work correctly independently


Reg#(Tout) z1 <- mkReg(?);
Reg#(Tout) z2 <- mkReg(?);
Reg#(Tout) z3 <- mkReg(?);


rule do_cycle2;
let z1 = dut1.result();
$display (" z1 = %d", z1);
let z2 = dut2.result();
$display (" z2 = %d", z2);

endrule

(* descending_urgency = "do_cycle1,do_cycle2,do_cycle3" *)

rule do_cycle3();
let z3 = dut1.sum(z1,z2);
$display("z3=%d",z3);
$finish(0);

endrule
Back to top
View user's profile Send private message
quark
Site Admin


Joined: 02 Nov 2007
Posts: 499

PostPosted: Sun Mar 23, 2014 4:35 pm    Post subject: Re: Compilation Error Reply with quote

Rule "do_cycle2" does not refer to the registers. The "let" keyword declares a new variable, so the statement "let z1" in the rule is declaring a local variable (that shadows the register by the same name). (This variable also have no state. It is not a register, it is just a name for referring to an expression.)

If you want to assign a value to a register, remove the "let" keyword and use the "<=" assignment operator.
Code:
rule do_cycle2;
   z1 <= dut1.result();
   z2 <= dut2.result();
endrule

Local variables can be used to name the results, so that you can also display them:
Code:
rule do_cycle2;
   let res1 = dut1.result();
   $display("res1=%d", res1);
   z1 <= res1;

   let res2 = dut2.result();
   $display("res2=%d", res1);
   z2 <= res2;
endrule

(If you tried to display the register values, you would be displaying the old value, not the new value being assigned.)

Note that if you don't need to register the results, you can omit the registers and just use the values directly, in the same rule:
Code:
rule do_cycle2and3;
   let res1 = dut1.result();
   let res2 = dut2.result();
   let sum = dut1.sum(res1,res2);
   $display("sum=%d",sum);
   $finish(0);
endrule
Back to top
View user's profile Send private message
rahul09



Joined: 18 Feb 2014
Posts: 3

PostPosted: Mon Mar 24, 2014 6:14 am    Post subject: Reply with quote

Thanks for the swift response, it worked Smile
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