RE: [sv-bc] RE: [sv-cc] DPI imported task can have dynamic array as formal argument??

From: Warmke, Doug <doug_warmke_at_.....>
Date: Thu Jan 17 2008 - 10:09:36 PST
Dhiraj,

 

Someone just corrected a mistake in my example.

See the very last paragraph in Sec 5.8 of Std.1800-2005.

The association of dynamic array actual out2 to the output

open array formal is not legal.

 

Regards,

Doug

 

From: owner-sv-bc@server.eda.org [mailto:owner-sv-bc@server.eda.org] On Behalf Of Warmke, Doug
Sent: Thursday, January 17, 2008 9:50 AM
To: Dhiraj Kumar Prasad; sv-bc@server.eda.org; sv-cc@server.eda.org
Subject: [sv-bc] RE: [sv-cc] DPI imported task can have dynamic array as formal argument??

 

Hi Dhiraj,

 

Based on my knowledge of the LRM, the following example

should clarify what is legal and illegal in terms of actual arguments

associated with open array formals.

 

Your precise example below is legal.  But it’s not very informative,

since there is no call of task1 in the example, and hence no actual arguments.

If you thought there was some association between the “in1” and “out1”

module ports and the task1 formal arguments, there is not.

 

Here is my example with more pertinent illustrations of

actual<->formal argument association.

 

module top;

    bit [3:0] in1;   // Bit vector (packed array of bit) 

    bit [3:0] out1;

    bit in2  [4];    // Fixed-size array of bit

    bit out2 [4];

    bit in3  [];     // Dynamic array of bit

    bit out3 [];

    bit in4  [int];  // Associative array of bit

    bit out4 [int];

    bit in5  [$];    // Queue of bit

    bit out5 [$];

 

    // Formal arguments are open arrays of bit.

    import "DPI-C" task task1(input bit in1[], output bit out1[]);

 

    always @(in1) begin

        // Initialize the various arrays

        out1 = in1;

        in2[0] = 1'b1;

        in2[1] = 1'b0;

        in3  = new[4];

        out3 = new[4];

        in4[42] = 99;

        in5[0] = 42;

        in5[1] = 42;

 

        task1(in1, out1);  // Illegal - assigning packed type to open array

        task1(in2, out2);  // Fine - assigning unpacked, fixed-size array to open array

        task1(in3, out3);  // Fine - assigning unpacked, dynamic array to open array

        task1(in4, out4);  // Illegal - associative array assigned to open array

        task1(in5, out5);  // Illegal - queue assigned to open array

    end

 

endmodule

 

Regards,

Doug

 

From: Dhiraj Kumar Prasad [mailto:dhiraj@cal.interrasystems.com] 
Sent: Thursday, January 17, 2008 1:52 AM
To: Warmke, Doug; sv-bc@eda.org; sv-cc@eda.org
Cc: Dhiraj Kumar Prasad
Subject: Re: [sv-cc] DPI imported task can have dynamic array as formal argument??

 

Hi Doug,

Is the following example legal??

module tmp(input bit [3:0] in1,output bit [3:0] out1);

import "DPI-C" task task1(input bit in1[],output bit out1[]);

always@(in1)
out1 = in1;
endmodule

Thanks,
Dhiraj



Warmke, Doug wrote: 

Dhiraj,

 

No, the text you highlighted in red applies to actual arguments, not formal arguments.

Any formal arguments of an import must have a representation in C.

Since bit and logic vectors have no natural C representation, Annex F goes

out of its way to define typedefs and supporting infrastructure that are

the C representation of bit and logic vectors.

 

The closest thing to a dynamic array in an import formal would be an open array.

That has the same [] syntax as dynamic array, but very different semantics.

Read in Annex F to learn all about open arrays.

 

Regards,

Doug

 

From: owner-sv-cc@server.eda.org [mailto:owner-sv-cc@server.eda.org] On Behalf Of Dhiraj Kumar Prasad
Sent: Wednesday, January 16, 2008 9:06 PM
To: sv-bc@server.eda.org; sv-cc@server.eda.org
Cc: Dhiraj Kumar Prasad
Subject: [sv-cc] DPI imported task can have dynamic array as formal argument??

 

Hi,

According to LRM P1800.2005, the different section says about the use of dynamic
array as formal argument of imported/exported task/function.


26.1.2

Formal arguments of an imported function can be specified as open arrays.

26.4.6

In exported DPI tasks or functions, it is erroneous to declare formal arguments of dynamic array types.

26.5.1.1

It is sometimes permissible to pass a dynamic array as an actual argument to an imported DPI task or function.


26.4.6.1

Formal arguments of imported functions can be specified as open arrays.

So is dynamic array permited in formal argument of imported task??.

Thanks,
Dhiraj


-- 
This message has been scanned for viruses and 
dangerous content by MailScanner <http://www.mailscanner.info/> , and is 
believed to be clean. 

 


-- 
This message has been scanned for viruses and 
dangerous content by MailScanner <http://www.mailscanner.info/> , and is 
believed to be clean. 


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Thu Jan 17 10:11:23 2008

This archive was generated by hypermail 2.1.8 : Thu Jan 17 2008 - 10:51:04 PST