Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to access the expressions inside a Function using VPI

Status
Not open for further replies.

balavinayagam

Member level 3
Member level 3
Joined
Feb 24, 2010
Messages
59
Helped
9
Reputation
18
Reaction score
8
Trophy points
1,288
Location
banglore
Visit site
Activity points
1,630
Hi ,
I am trying to access an expression inside a function using VPI.
Let us say the handle to the vpiFuncCall is tt1. I tried to extract the expressions as given in the Object data model diagrams
htfv = vpi_handle(vpiFunction,tt1); // getting vpi_handle for the function from the vpiFuncCall
htfv2 = vpi_handle(vpiLeftRange,htfv); // Trying to access the expression by getting a handle to expr -- does not work
htfv2 = vpi_handle(vpiArgument,htfv); // Trying to access the expression by getting a handle to expr -- does not work
Let me give a verilog example . In the below case i want to access the 'case' expression inside the inv_o_bs function.
module comb (a,c,s,d);
input a,c,s;
output d;
reg d;
wire l,b;
assign b = a&s;
assign l = a^s;
always @*
begin
d = inv_o_bs(b,l);
end
function inv_o_bs;
input k,l;
begin
case (l)
1'b0: inv_o_bs = 1'b1;
1'b1: inv_o_bs = 1'b0;
endcase
end
endfunction
endmodule

It would be helpful if you could point out the method to do it or what is wrong in my approach
Thanks in advance
 

vpiLeft/RightRange is to get the declared integral range of the function's return value.

I'm going to assume you want to get the second argument of the function, input 'l', which happens to be the expression in the case statement. Trying to parse the function contents to find the case statement, and then parse the case statement to see what expression it uses is much harder, and takes more time than I have to help you.

Using vpiArgument is the correct first step, but since there is a one-to-many relationship between a function and its arguments, you need to iterate over the arguments to get to the second argument.

Code:
 arg_itor = vpi_iterate(vpiArgument,htfv);
 arg_h = vpi_scan(arg_itor); This returns a handle to the first argument k.
 arg_h = vpi_scan(arg_itor); This returns a handle to the second argument l.


vpi_free_object(arg_itor); // need to call this when you don't call vpi_scan enough times for it to return NULL.

Of course, your code would have all the proper checks for valid return values. :)
 
Hi Dave,
Thanks for the reply. The above method works and it returns me the arguments k & l. But these are the arguments that I pass on to the function. I want to access the variables inside the function.
I thought functions are in a way similar to accessing a module. So I used the following to access the variables inside the function
arg_itor2 = vpi_iterate(vpiIODecl,htfv);
htfv3 = vpi_scan(arg_itor2);
htfv_net = vpi_handle(vpiNet,htfv3);
htfv4 = vpi_scan(arg_itor2);
This does not return anything even though neither arg_itor2 nor htfv* is NULL (Not shown in the above code)
If you could give a hint of how to access inside the function it would be helpful. Thanks :)
The object data model diagram says I can access the IO decl from the function. But I am not able to do so
 

I don't know what you mean by "access the variables inside the function", k&l are the function arguments and the only local variables declared inside the function.

Perhaps you need to take a step back and explain the end result of what you are trying to accomplish without using VPI terminology.
 
Hi Dave ,
Thanks for the reply.
The goal of my code is to determine among the two inputs passed to the function which one is used and which is not
Let us suppose the function call uses variables k & l . the function uses variables y,z. Then vpiArugument gives me a handle to k & l but not the variables y & z. suppose y is used and z is not used . the function depends solely on y. That is what i try to find out
 

Hi , Ya finally I was able to access the internal varaibles by
arg_itor2 = vpi_iterate(vpiIODecl,htfv);
htfv3 = vpi_scan(arg_itor2);
htfv_net = vpi_handle(vpiExpr,htfv3);
:smile:
Next step is to determine which one is used
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top