gpt4 book ai didi

vhdl - 枚举中的字 rune 字别名的正确语法是什么?

转载 作者:行者123 更新时间:2023-12-02 09:36:02 27 4
gpt4 key购买 nike

出于教育目的,我试图为作为字符文字的枚举值声明别名。在下面的示例中,我试图为枚举类型bit_one(在std.standard中声明)为值“1”创建别名bit

我很困惑为什么下面的第一种形式被两个编译器(GHDL 0.29.1和Quartus II 13.01)拒绝,而第二种形式又被ModelSim和ActiveHDL所接受。因此,问题:如下面的注释行中那样声明此别名是否非法?

entity character_literal_alias is
end;

architecture rtl of character_literal_alias is
--alias bit_one is '1'[return bit]; -- Doesn't work in GHDL or Quartus
alias bit_one is std.standard.'1'[return bit]; -- Works with ModelSim, ActiveHDL, GHDL, and Quartus

alias append is append_mode[return file_open_kind]; -- Works with the whole bunch
begin
end;

我正在其他工具中使用GHDL中的VHDL-2002开关和VHDL-2008中的开关。

如果我稍作推测,在VHDL-2008 LRM中,所有示例均以以下形式编写:
-- implicit aliases ...
-- alias '0' is STD.STANDARD.'0' [return STD.STANDARD.BIT];
-- alias '1' is STD.STANDARD.'1' [return STD.STANDARD.BIT];

但是这些是隐式声明,即使示例使用选定的名称,也不意味着每个别名都应以这种方式声明,IMO。那么也许某些供应商会误解该标准?

最佳答案

这实际上与哪个VHDL工具符合哪个标准修订版有关

两组VHDL分析仪之一不符合该标准,但哪个标准修订版?

ghdl说:

charlitalias.vhdl:5:22: identifier expected here
ghdl: compilation error

虽然不是特别有启发性的错误消息,但ghdl默认情况下大致符合IEEE Std 1076-1993。 ghdl默认为 --std=93c,它与-1993兼容,有关后来的标准更改的宽松规则。在-2008修订之前,没有标准更改会影响此问题,因此 --std=02应该没有任何影响。

除非另有说明,否则以下摘录均摘自-1993标准。还要注意,在标准正文中找到的EBNF是规范性的指定语法,而文本提供了语义规范。

4.3.3别名声明

An alias declaration declares an alternate name for an existing named entity.


alias_declaration ::=  
alias alias_designator [ : subtype_indication ] is name [ signature ] ;

哪里:
name ::=                                                    [§ 6.1]  
simple_name
| operator_symbol
| selected_name
| indexed_name
| slice_name
| attribute_name
name的EBNF已在-2008标准8.1中更新:
name ::= 
simple_name
| operator_symbol
| character_literal
| selected_name
| indexed_name
| slice_name
| attribute_name
| external_name

在-2008中,它包含一个字符文字,它是一个词汇元素。

这使示例:
alias bit_one is '1'[return bit];  

在-2008年合法。字符文字可以被视为 alias_declaration中的名称。

通用工作的示例使用带有字符字面量的后缀指定所选名称(扩展名称):
alias bit_one is std.standard.'1'[return bit];

6.3选择的名称,第9段中找到了选择的名称适用于字符文字的原因:

An expanded name denotes a named entity declared in a package if the prefix denotes the package and the suffix is the simple name, character literal, or operator symbol of a named entity whose declaration occurs immediately within that package.



进一步地,将后缀视为函数的名称:

3.1.1枚举类型,第4段:

The identifiers and character literals listed by an enumeration type definition must be distinct within the enumeration type definition. Each enumeration literal is the declaration of the corresponding enumeration literal; for the purpose of determining the parameter and result type profile of an enumeration literal, this declaration is equivalent to the declaration of a parameterless function whose designator is the same as the enumeration literal and whose result type is the same as the enumeration type.



-2008标准5.2.2.1中有一些澄清:

...,this declaration is equivalent to the declaration of a parameterless function whose designator is the same as the enumeration literal and whose result type is the same as the enumeration type; the declaration is, nonetheless, a declaration of a literal, not of a function.



之所以感兴趣,是因为函数是命名的,运算符是函数,并且双引号中的运算符允许作为函数名。但是,没有任何东西允许字符文字作为函数名称。

根据别名是指对象(信号,常量,变量,文件,命名对象)还是其他命名实体,对别名进行分类。

非对象别名(-1993 4.3.3.2,-2008 6.6.3)需要字符文字的签名。签名提供了类似于函数的返回类型,从而可以为字符文字实现重载解析,而该文字本身就是模棱两可的。知道类型对于消除枚举文字的位置值是必不可少的。以BIT类型和std_ulogic类型为例。两者都具有'1'枚举文字,但是位置值(自然)对于BIT('0','1')是1,对于std_ulogic('U','X','0','1', 'Z','W','L','H','-')。评估表达式需要位置值。

返回ghdl / -1993:

因此,选定的名称起作用。字符文字本身不适合 name的-1993扩展,但适用于-2008。

如果Modelsim和ActiveHDL严格符合-1993,则它们将是错误的。回想起来很明显,它们符合-2008标准,这解释了公认语法的差异。

如果已通过传递标志来确保-1993遵从性,那么如果他们接受别名声明,则Modelsim和ActiveHDL似乎会将枚举文字声明视为函数名称。

在-2008之前,您不能将字符文字视为名称。您总是可以将命名枚举文字视为名称。您可以想象这种差异是为什么在-2008中将 character_literal添加到 name的原因。现在,所有枚举文字都被“命名”。

因此,我们想到了一个问题:

But those are implicit declarations, and even if the examples use selected names, it doesn't mean that every alias should be declared this way, IMO. So maybe some vendors misinterpreted the standard?



隐式别名声明是非对象别名一节中在语法和语义上正确的表示形式。它们恰好同时符合-1993和-2008标准。在ghdl中失败并在Modelsim中通过的示例不是。

要在版本的各个版本之间保持可移植性 ,请使用选定的名称。您可能会发现采用新的VHDL修订版的时间明显滞后。

这是一个至关重要的质量问题,首先由Aldec在驱动ActiveHDL上使用Jerry Kaczynski解决,然后是Modelsim。我知道,正在积极开发的两个开源实现也正在朝-2008合规性发展。

关于vhdl - 枚举中的字 rune 字别名的正确语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26171659/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com