|
(1) 访问类型
VHDL中的访问类型(access type)相当子程序设计语言中的指针类型。
type Int is range 0 to 500; --
Int 是一个整数类型
type Int_Ptr is access Int; --
Int_Ptr是Int的访问类型
访问类型的值是指针,它指向(或链接到)动态分配的、无名的、其他类型的对象。访问类型可以保存在访问类型的对象中。保留字null用来表示访问值为空。
在声明一个访问类型的对象时,可以用保留字new来为其分配一个空间,并可指定一个初始值。例:
veriable V_Int_Ptr_1: Int_Ptr := new Int'(362);
--访问值为Int类型,
初始值为362.
veriable V_Int_Ptr_2: Int_Ptr := new Int;
--访问值为Int类型, 初始值为0
(Int'LEFT).
veriable V_Int_Ptr_3: Int_Ptr;
--访问值为空(null).
访问对象后面添加.all,将会访问该访问对象所指对象的值。在上面的例子中,表达式V_Int_Ptr_1.all的值为362。
如果访问对象是数组类型,则带下标的对象名引用该访问对象所指对象的元素。例如:
type Matrix is array (1 to 10, 1 to 10)of
Integer;
type Matrix_Ptr is access Matrix;
variable M: Matrix_Ptr := new Matrix'(others => (others
=>0));
variable Left_Corner_Cell: Integer := M(1,1);
-- M是访问类型变量,表达式M(1,1)将访问二维数组M的一个元素。
记录对象的访问类型与数组的情况相类似。例如:
type Rational is record
Numerator: Integer;
Denominator: Integer;
end record;
type Rational _Ptr is access Rational;
variable R: Rational _Ptr := new Rational¢(5, 7);
variable Num: Integer := R. Numerator;
-- R是访问类型变量,表达式R.
Numerator将访问记录R的Numerator域。
如果一个记录类型的某一个域是该记录类型的访问类型,要用嵌套定义的方法。例如:
type Element; -- 嵌套定义
type Element_ptr is access Element;
type Element is record
Value: Integer;
NextElement: ElementPtr; -- 注意Next是保留字
end record;
(2) 文件类型
文件类型和文件对象为VHDL设计与外部设计环境之间的通信提供了一个途径。
type Text is file of STRING;
file INPUT: Text is in "STD_INPUT";
INPUT为文件标识符,Text为文件类型,保留字in表示输入,引号中的字符串为实际文件名。
|