明确的赋值模式类型

huangapple go评论45阅读模式
英文:

Explicit assignment pattern type

问题

I'd like to be able to provide an explicit struct type in an assignment pattern (1800-2012 sec. 10.9) so that the left-hand side of the assignment does not need to be of that struct type. Is there a way to accomplish this?

例如,我想要做类似以下的事情:

logic a, b;
logic [1:0] c;

assign c = struct_t'{s1:a, s2:b};```

另一种方法是:

```typedef struct packed { logic s1; logic s2 } struct_t;
logic a, b;
struct_t tmp;
logic [1:0] c;

always_comb begin
    tmp = '{s1:a, s2:b};
    c   = tmp;
end

但是这显然有一个缺点,需要一个临时变量。

在标准中,我没有看到类似这样的内容。此外,我尝试在 QuestaSim 中使用它,但它不起作用,尽管它也没有抱怨表达式 struct_t'{s1:a, s2:b}; 的语法错误。根据赋值模式的语法表,这似乎是无效的语法。对吗?

有没有办法实现我想要的效果?我还尝试了将赋值模式进行类型转换,如 struct_t'('{s1:a, s2:b}),但也没有成功。

英文:

I'd like to be able to provide an explicit struct type in an assignment pattern (1800-2012 sec. 10.9) so that the left-hand side of the assignment does not need to be of that struct type. Is there a way to accomplish this?

For example, I'd like to do something like the following:

typedef struct packed { logic s1; logic s2 } struct_t;
logic a, b;
logic [1:0] c;

assign c = struct_t'{s1:a, s2:b};

An alternative would be to do:

typedef struct packed { logic s1; logic s2 } struct_t;
logic a, b;
struct_t tmp;
logic [1:0] c;

always_comb begin
    tmp = '{s1:a, s2:b};
    c   = tmp;
end

But that has the obvious disadvantage of requiring a temporary variable.

I didn't see any mention of something like this in the standard. Additionally, I tried it with QuestaSim and it didn't work, though it also didn't complain about a syntax error with the expression struct_t'{s1:a, s2:b};. Based on the syntax table for assignment patterns, this appears to be invalid syntax. Is that right?

Is there some way to achieve what I want? I also tried to cast the assignment pattern, like struct_t'('{s1:a, s2:b}), but that didn't work either.

答案1

得分: 0

以下是您要翻译的内容:

"Since these are all packed types, they should all be assignment compatible.

I get a syntax error in your typedef - missing a semicolon after s2

** Error: (vlog-13069) myfile.sv(3): near "}": syntax error, unexpected '}', expecting ';' or ','.

Once I fix that, it works for me. If you don't agree please show a complete example with the actual errors."

英文:

Since these are all packed types, they should all be assignment compatible.

I get a syntax error in your typedef - missing a semicolon after s2

** Error: (vlog-13069) myfile.sv(3): near "}": syntax error, unexpected '}', expecting ';' or ','.

Once I fix that, it works for me. If you don't agree please show a complete example with the actual errors.

huangapple
  • 本文由 发表于 2023年4月20日 06:09:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76059159.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定