我可以在生成语句中使用变量吗?
我想知道是否可以在生成语句中使用变量。
signal bitmap_nodes : std_logic_vector(0 to NB_NODES-1) := (others => '0');
CIRCULAR: if (CLOCKWISE = 0) generate
variable index : integer := 0;
begin
GENERATE_NODE : for i in NB_NODES-1 to 0 generate
begin
node_inst: node
port map (
rx_bitmap => bitmap_nodes(index)
);
-- Increment index
index := index + 1;
end generate GENERATE_NODE;
end generate CIRCULAR;
这里,该变量仅用于向量切片。它将执行以下操作(假设 NB_NODES 等于 4):
NODE0 -> bitmap_nodes(3)
NODE1 -> bitmap_nodes(2)
NODE2 -> bitmap_nodes(1)
NODE3 -> bitmap_nodes(0)
I am wondering if it is possible to use a variable inside a generate statement.
signal bitmap_nodes : std_logic_vector(0 to NB_NODES-1) := (others => '0');
CIRCULAR: if (CLOCKWISE = 0) generate
variable index : integer := 0;
begin
GENERATE_NODE : for i in NB_NODES-1 to 0 generate
begin
node_inst: node
port map (
rx_bitmap => bitmap_nodes(index)
);
-- Increment index
index := index + 1;
end generate GENERATE_NODE;
end generate CIRCULAR;
Here, the variable is only used for the vector slicing. What it will do is assign the following (assume NB_NODES equals 4):
NODE0 -> bitmap_nodes(3)
NODE1 -> bitmap_nodes(2)
NODE2 -> bitmap_nodes(1)
NODE3 -> bitmap_nodes(0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎与:
不是吗?
编辑:
我仍然不清楚为什么你想这样做,但是你可以(VHDL87后)放置一个
共享变量
在这个区域中(您可以将其视为architecture
和begin
之间的部分)。请记住,如果您不想遇到各种竞争条件问题,则共享变量必须是受保护的类型。但是,您不能像现在这样增加变量,因为生成语句必须填充并发语句(而变量赋值则不然)。
再说一次,我真的很想看到一个例子,其中这个功能是必要的(或者它更像是一个学术问题?)
That seems to be the same as:
isn't it?
EDIT:
I'm still not clear why you'd like to do this, but you can (post-VHDL87) put a
shared variable
in this area (you can treat it much like the part betweenarchitecture
andbegin
). Remember that shared variables have to be of aprotected
type if you're not going to have all sorts of problems with race conditions.However, you can't increment a variable like you are doing as the generate statement has to be populated with concurrent statements (and variable assignments aren't).
Again, I'd be really interested to see an example where this functionality is necessary (or is it more of an academic question?)