错误 (10327) 无法确定运算符“”=”的定义

Error (10327) can't determine definition of operator ""=""

对于此 VHDL 设计说明:

library ieee;
     use ieee.std_logic_1164.all;
     use ieee.std_logic_arith.all;

entity four_bit_counter is
    port (
        count_out : out unsigned (3 downto 0);
        clk : in std_logic;
        enable:in std_logic;
        reset: in std_logic) ;
    end four_bit_counter;
    
architecture arc of four_bit_counter is
    signal count : unsigned (3 downto 0);
    begin
        process (clk, reset, enable)
            begin
                if (reset = '1') then
                count <= "0000";
            elsif (clk' event and clk = '1') then
                if (enable = '1') then
                    if (count="1010") then
                    count<="0000";
                    else
                        count <= count +1;
                end if;
            end ;
        end if;
    end process;
            count_out <= count;
            end arc;

我有错误

Error (10327): VHDL error at four_bit_counter.vhd(22): can't determine definition of operator ""="" -- found 2 possible definitions

我不知道如何解决这个问题。

两个可能的定义都来自包std_logic_arith

function "="(L: UNSIGNED; R: UNSIGNED) return BOOLEAN;
function "="(L: SIGNED; R: UNSIGNED) return BOOLEAN;

由于提供第二个定义的包以及如何确定字符串文字的右操作数的类型,导致相等运算符的重载决策产生歧义。

参见 IEEE Std 1076-2008 9.3.2 文字:

String and bit string literals are representations of one-dimensional arrays of characters. The type of a string or bit string literal shall be determinable solely from the context in which the literal appears, excluding the literal itself but using the fact that the type of the literal shall be a one-dimensional array of a character type. The lexical structure of string and bit string literals is defined in Clause 15.

这里上下文是相等运算符,其中12.5重载解析的上下文指定错误:

Overloading is defined for names, subprograms, and enumeration literals.

For overloaded entities, overload resolution determines the actual meaning that an occurrence of an identifier or a character literal has whenever the visibility rules have determined that more than one meaning is acceptable at the place of this occurrence; overload resolution likewise determines the actual meaning of an occurrence of an operator or basic operation (see 5.1).

At such a place, all visible declarations are considered. The occurrence is only legal if there is exactly one interpretation of each constituent of the innermost complete context. ...

运算符的重载由函数声明提供( 4.5.2 运算符重载)。对于二元运算符,左操作数与第一个函数参数关联,右操作数与第二个参数关联。 return 值是一个布尔值(同样来自上下文,它是一个 if 语句的条件,它是一个布尔表达式)。

无法根据上下文确定右操作数的类型。

有几种可能的解决方案

  1. 改用 IEEE 的 numeric_std 包,其中实现运算符的函数不具有有符号和无符号操作数。包 numeric_std 已纳入标准的 -2008 修订版,导致包 std_logic_arith 最终弃用。

  2. 使用限定表达式(9.3.5)具体说明操作数的类型。

        if count = unsigned'("1010") then

(为清楚起见,删除了条件周围多余的括号)

  1. 依赖不存在歧义的抽象文字 (15.5)。这可以是十进制文字 (15.5.2) 或基于文字 (15.5.3) 的形式。

  2. 使用选定名称对重载运算符声明的函数调用,注意命名关联不能用于运算符重载。

  3. 用值表达式提供的值定义一个对象(这里是常量)。该类型是对象声明中固有的。