【问题标题】:SystemVerilog name aliasSystemVerilog 名称别名
【发布时间】:2015-07-17 11:51:07
【问题描述】:

SystemVerilog 是否为模块实例和枚举启用别名?例如,我该如何编码:

enum logic {foo, bar} myEnum
enum logic {baz, qux} myEnum

bazqux分别是foobar的别名。

【问题讨论】:

    标签: system-verilog


    【解决方案1】:

    let 构造可以对任何表达式执行此操作

    enum logic {foo, bar} myEnum
    let baz = foo;
    let qux = bar;
    

    您不能为实例名称设置别名。

    【讨论】:

      【解决方案2】:

      它们不能别名,但可以转换/转换。请参阅IEEE Std 1800-2012 § 6.19.4 数值表达式中的枚举类型。 LRM 示例:

      typedef enum {Red, Green, Blue} Colors;
      typedef enum {Mo,Tu,We,Th,Fr,Sa,Su} Week;
      Colors C;
      Week W;
      int I;
      C = Colors'(C+1);            // C is converted to an integer, then added to
                                   // one, then converted back to a Colors type
      C = C + 1; C++; C+=2; C = I; // Illegal because they would all be
                                   // assignments of expressions without a cast
      C = Colors'(Su);             // Legal; puts an out of range value into C
      I = C + W;                   // Legal; C and W are automatically cast to int
      

      【讨论】:

        猜你喜欢
        • 2013-03-27
        • 1970-01-01
        • 2012-08-26
        • 1970-01-01
        • 2015-04-14
        • 2020-07-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多