VHDL Record to SV structure

VHDL code:
type t_x is record
row: integer range 0 to 1023;
size: integer range 0 to 1023;
end record;

type x_array is array(7 downto 0) of t_x;

please provide
equivalent System Verilog code

In reply to Mallikarjun79:
You have two options:

  1. Use a struct definition. I like to include those in a package.
  2. Use a class definition, and instantiate that class with a new().
    The class offers much more flexibility, as you can extended it,
    and constraint randomize all objects of the class if they are
    pre-qualified with the rand
    Below is an example of those two techniques:

class R; 
	/* VHDL code:
       type t_x is record
       row: integer range 0 to 1023;
       size: integer range 0 to 1023;
       end record;
       type x_array is array(7 downto 0) of t_x; */
	bit[0:9] row, size; 	
	rand bit[0:9] rw, sz; 	
	endclass

package my_pkg;
	typedef struct {
		bit[0:9] row, size; 
	} t_x;
endpackage : my_pkg

module m; 
	import my_pkg::*; 
	t_x mrz; // from the package
	R r;
	bit clk, a;  
	bit[0:9] w, q;
	initial forever #10 clk=!clk;   
	initial begin  
		r=new(); 
		w=1023; q=70;
		r.row=w;
		r.size=q; 
		mrz.size=1023; 
		mrz.row=15;
 	  
		if (!randomize(r)  with 
		   { r.rw > 5; w <70; 
		     r.sz > 1; r.sz < 14;}) $error("randomization error"); 
	end 
endmodule  

Ben Cohen
http://www.systemverilog.us/ ben@systemverilog.us

  • SystemVerilog Assertions Handbook 4th Edition, 2016 ISBN 978-1518681448
  • A Pragmatic Approach to VMM Adoption 2006 ISBN 0-9705394-9-5
  • Using PSL/SUGAR for Formal and Dynamic Verification 2nd Edition, 2004, ISBN 0-9705394-6-0
  • Real Chip Design and Verification Using Verilog and VHDL, 2002 isbn 0-9705394-2-8
  • Component Design by Example ", 2001 ISBN 0-9705394-0-1
  • VHDL Coding Styles and Methodologies, 2nd Edition, 1999 ISBN 0-7923-8474-1
  • VHDL Answers to Frequently Asked Questions, 2nd Edition ISBN 0-7923-8115

In reply to ben@SystemVerilog.us:

Both VHDL code and SV code will be in package.

VHDL code.

type t_x is record
row: integer range 0 to 1023;
size: integer range 0 to 1023;
end record;

type x_array is array(7 downto 0) of t_x;

SV code.
typedef struct {
int row, size;
} t_x;
My question is
How to declare the array of type t_x variable?
typedef t_x_array[0:7] t_x;
When tried this it is saying that t_x_array is unknown type.

please provide equivalent SV code for this (type x_array is array(7 downto 0) of t_x;)

In reply to Mallikarjun79:
The syntax is

typedef t_x x_array[7:0];

Note that some tools will allow you to share types in packages between VHDL and SystemVerilog so you only need to declare them in one package. Check your user manual.

Hi All,

In VHDL Record is there for combining two or more signals/ports and we can call the records in a single name of representation.

So in Verilog is there any equivalent keyword for the same.

Thanks in Advance PHP Training in Chennai | Web Designing Training in Chennai

In reply to acemaria90:
In SystemVerilog, you can use the SystemVerilog interface to combine signals/ports. The interface is actually far more powerful than the VHDL record, as you can include functions, tasks, assertions, and computations with signal assignments and clocked procedures. The original Verilog does not support this capability; SystemVerilog is inclusive of Verilog.
Ben Cohen
http://www.systemverilog.us/

  • SystemVerilog Assertions Handbook 4th Edition, 2016 ISBN 978-1518681448

In reply to acemaria90:

The direct equivalent of a VHDL record is a SystemVerilog struct. An interface is certainly much more powerful as Ben states that gives you almost class-like functionality, but a struct may be more appropriate in many cases.

In reply to dave_59:

hello
I am trying to assign a signal from in-depth VHDL DUT hierarchy ot type

type mif_fifo_status_t is record
a : unsigned( 4 downto 0);
b : unsigned( 3 downto 0);
c : unsigned( 4 downto 0);
end record;

to a SV variable in the test bench of ttpue

typedef struct packed {

 logic unsigned [4:0] a;
 logic unsigned [3:0] b;
 logic unsigned [4:0] v;

} mif_fifo_status_t;

same type name, same field type and size
this.status = $root.tb.i_dut.carrier_a_block.i_a_h_hm2.i_hm_core.i_fifo_monitor.i_fifo1_i.mif_fifo_statu;
types are compiled in VHDL and verilog from two different files
I get

Time: 0 fs Iteration: 0 Region: /simutils_hm2_sv_unit File: …/tb/simutils_hm2.sv Line: 189

** Error: (vsim-13216) Illegal assignment to type ‘struct fifo_pkg::mif_fifo_status_t’ from type 'struct ': Struct/union types must match.

whatt’s wrong here?

thanks

In reply to stanzani:

SystemVerilog requires that structures have to be derived from the same type definition to be assignment compatible. It is not good enough to give two types the same name and same layout.

Please consult your tools User Manual as sharing types for mixed language simulations is a tool specific feature.

In reply to dave_59:

VHDL Record paramter to SV structure.

Hi Dave,

I have a VHDL model, which contains VHDL record as parameter, i am trying to integrate the model into SV environment. I converted VHDL record parameter in to struct in my sv code as shown below. I am getting below error

Error :
xmelab: *E,CFIGTC (model_tb.sv): VHDL generic model.config model.vhd) type is not compatible with Verilog.
.config (tb_config)
|
xrun: *E,ELBERR: Error during elaboration (status 1), exiting.

code :
TYPE rtl_config is
RECORD
path : string ;
x : STD_LOGIC ;
y : STD_LOGIC_VECTOR(1 DOWNTO 0);
z : INTEGER_ARRAY(1 DOWNTO 0);
END RECORD ;

model (cfg : rtl_config)
PORT ( A : IN STD_LOGIC ;
B : OUT STD_LOGIC )
end model ;

module model_tb ;
bit a,b;

typedef struct { is
string path ;
bit x ;
bit [1:0] y ;
bit z [1:0];
} tb_config_tb_t
tb_config_tb_t tb_config ;

model #(.cfg(tb_config))
model_inst(.a(a),
.b(b));

endmodule : model_tb

Regards,
Jayaprakash