arrays - 这些类型不应该密切相关吗?

标签 arrays casting type-conversion vhdl ghdl

我正在尝试分析以下文件,该文件应该与 VHDL-2008 兼容。

entity closely_related is
end;

architecture example of closely_related is
    type integer_vector is array (natural range <>) of integer;
    type real_vector is array (natural range <>) of real;
begin
    process
        variable int_vect: integer_vector(1 to 3);
        variable real_vect: real_vector(1 to 3);
    begin
        real_vect := ( 1.0, 2.0, 3.0 );
        int_vect := integer_vector( real_vect );

        wait;
    end process;
end;

这应该是一个关于密切相关类型的实验。根据LRM,有两种密切相关类型的情况:

— 抽象数字类型 — 任何抽象数字类型都与任何其他抽象数字密切相关 类型。 — 数组类型 - 两个数组类型密切相关当且仅当类型具有相同的 维度和元素类型密切相关

我知道实数和整数密切相关;它们之间的类型转换(又名类型转换)工作正常。那么为什么它不适用于上述数组类型呢?

GHDL 给出以下错误:

conversion not allowed between not closely related types

Modelsim Altera 10.1e(带 -2008 开关)也好不到哪儿去:

Illegal type conversion from std.STANDARD.REAL_VECTOR to std.STANDARD.INTEGER_VECTOR 
(array element type difference).

为了彻底起见,我尝试一次对一个元素执行相同的操作:

int_vect(1) := integer( real_vect(1) );
int_vect(2) := integer( real_vect(2) );
int_vect(3) := integer( real_vect(3) );

而且效果非常好。有什么想法吗?

最佳答案

这些类型不应该密切相关吗?

不适用于 ghdl,默认情况下严格遵守 -1993。

这来自 IEEE Std 1076-1993, 7.3.5 类型转换:

A type conversion provides for explicit conversion between closely related types.
...

b. Array Types -- Two array types are closely related if and only if

-- The types have the same dimensionality;

-- For each index position, the index types are either the same or are closely related; and

-- The element types are the same.
...

没有其他类型密切相关。

所以问题是元素类型不一样。

-2008年,9.3.6类型转换:

— Abstract numeric types—Any abstract numeric type is closely related to any other abstract numeric type.

— Array types — Two array types are closely related if and only if the types have the same dimensionality and the element types are closely related

这告诉我们,任何抽象数字类型(整数、实数)都是密切相关的,并且当数组类型的元素类型密切相关时,它们现在也密切相关。

因此,您指定的 Modelsim 版本似乎不符合更改,或者某些内容停止了对其 -2008 标志的调用。

我的 Mac 上没有为 ghdl 加载 -2008 版本的库。我也不会打赌它会与 --std=08 标志一起使用。

我从 Sourceforge 上的 ghdl-updates 检查了最新的 ghdl 源代码,实现与密切相关的元素密切相关的数组类型的更改尚未合并。请参阅 sem_names.adb 第 1024 - 1047 行。

当我们发现由于像这样的标准修订而没有实现的事情时,通常是因为没有测试用例在应该失败或通过的时候失败或通过,并且因为没有办法看到标准版本之间的变化。

您需要一个 diff PDF 和一种将各个条款和子条款之间的要求关联起来的方法,以及确定标准中的语句是否可测试,如果可以,则通过什么代码进行测试。可以肯定地说,版权正在阻碍实现。

冲击因素 -2008 标准的(页数)也会影响发生合规问题的可能性。

有什么想法吗?

 int_vect := integer_vector'(integer(real_vect(1)),integer(real_vect(2)), integer(real_vect(3)));

关于arrays - 这些类型不应该密切相关吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25906931/

相关文章:

c# - TryParse 创建内联参数?

arrays - 将 reversed() 赋给 swift 数组有什么麻烦?

c++ - 如何使用基本循环创建二维数组矩阵

char ** 然后取消对 char * 的引用

java - 在 Java 中创建泛型数组

c# - 将一个对象转换到另一个对象

c++ - 从 'DWORD' 到 'const char *' 的无效转换

c++ - 将 std::variant 转换为另一个具有父类(super class)型集的 std::variant

Javascript:输入栏不起作用或没有给出任何结果

Javascript:如何检查数组中的空对象?