【问题标题】:Why this Modelsim error? "Ambiguous types in signal assignment statement."为什么会出现这个 Modelsim 错误? “信号赋值语句中的模棱两可的类型。”
【发布时间】:2014-05-06 20:02:05
【问题描述】:

我正在尝试使用 ModelSim Microsemi 10.2c 编译以下示例:

architecture example of assignment_to_an_aggregate is
    type vowel_type is (a, e, i, o, u);
    type consonant_type is (b, c, d, f, g);

    signal my_vowel: vowel_type;
    signal my_consonant: consonant_type;
begin

    (my_vowel, my_consonant) <= (a, b);

end;

它给出了以下错误:

** Error: assignment_to_aggregates.vhdl(40): (vcom-1349) Ambiguous types in signal assignment statement.

   Possible target types are:
        std.STANDARD.TIME_VECTOR
        std.STANDARD.REAL_VECTOR
        std.STANDARD.INTEGER_VECTOR
        std.STANDARD.BIT_VECTOR
        std.STANDARD.BOOLEAN_VECTOR
        std.STANDARD.STRING

** Error: assignment_to_aggregates.vhdl(57): VHDL Compiler exiting

任何人都可以解释这不起作用吗?为什么编译器会认为 TIME_VECTOR、STRING 等是这个赋值目标的合理类型?注意:即使目标聚合只有相同类型的信号,我也会遇到相同的错误。

谢谢!

【问题讨论】:

    标签: variable-assignment vhdl aggregate


    【解决方案1】:

    虽然我无法评论 Modelsim 类型消息的特殊性,但问题是无法从上下文中辨别出右侧聚合的类型。

    试试:

    entity assignment_to_an_aggregate is
    end entity;
    architecture example of assignment_to_an_aggregate is
        type vowel_type is (a, e, i, o, u);
        type consonant_type is (b, c, d, f, g);
    
        type vowel_consonant is 
            record 
                vowel: vowel_type;
                consonant: consonant_type; 
            end record;
    
        signal my_vowel: vowel_type;
        signal my_consonant: consonant_type;
    begin
    
        (my_vowel, my_consonant) <= vowel_consonant'(a,b);
    
    end;
    

    您会注意到左侧聚合取决于右侧表达式的类型。

    (并且类型声明不承担模拟或综合开销负担,并且没有任何地方将命名对象声明为记录类型)。

    好的,如果我理解正确,那么出现在赋值右侧的所有内容都需要有明确定义的类型吗?或者换句话说,每个聚合都必须有一个定义的类型? – VHDL Addict 5 分钟前

    没有。在这种情况下,信号分配的目标是聚合:

    IEEE Std 1076-1993, 8.4 Signal assignment statement (-2008, 10.5/10.5.2.1):

    如果信号赋值语句的目标是 聚合,那么聚合的类型必须可以从 上下文,不包括聚合本身,但包括事实 聚合的类型必须是复合类型。

    除了右边还有什么上下文?您不能使左侧的聚合成为合格的表达式。信号赋值的目标必须有名字,表达式没有名字。

    您收到的 Modelsim 错误消息没有指定它抱怨的赋值语句的哪一侧,而其他一些工具可能更具有启发性:

    assignment_to_aggregate.vhdl:23:19:波形类型未知,使用类型限定符

    您是否注意到错误消息是为不需要它们的人准备的?

    【讨论】:

    • 好的,如果我理解正确,那么出现在赋值右侧的所有内容都需要有明确定义的类型?或者换句话说,每个聚合都必须有一个定义的类型?
    • 我仍然无法解决这个问题。我将使用您的代码作为起点发布另一个问题。谢谢!
    猜你喜欢
    • 2010-10-05
    • 1970-01-01
    • 1970-01-01
    • 2011-08-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多