根据1800-2012 specs的说法,
Queue::delete( [input int index] )
删除SystemVerilog中的队列元素,此外,队列可以执行与未打包数组相同的操作,使其可以访问:
Array::find_first_index( )
它返回匹配特定条件的第一个元素的索引。即
find_first_index( x ) with ( x == 3)
现在,我想从队列中删除一个保证存在的唯一项。1和1的组合得到:
queue.delete(queue.find_first_index( x ) with ( x == obj_to_del ));
编译器并不理解这一点,尽管声明传递的参数必须是整数或整数兼容的。我可以把这两个分开:
int index = queue.find_first_index( x ) with ( x == obj_to_del );
queue.delete( index );
或者通过类型转换find_first_index来强制使用整数:
queue.delete(int'(queue.find_first_index( x ) with ( x == obj_to_del ))) //Just finished compiling, does not work.
在我看来,前者看起来不是很优雅,而后者似乎有些勉强,这让我好奇是否有更合适的方法来实现这一点。find_first_index是否可能返回一个索引位置为0的大小为1的数组?
编辑:我愚蠢地没有提供一个自包含的示例:我正在做的事情的一个简化示例如下所示:
class parent_task;
endclass;
class child_taskA extends parent_task;
endclass;
class child_taskB extends parent_task;
endclass;
class task_collector;
child_taskA A_queue[$];
child_taskB B_queue[$];
function delete_from_queue(parent_task task_to_del);
case (task_to_del.type):
A: A_queue.delete(A_queue.find_first_index( x ) with ( x == task_to_del));
B: B_queue.delete(B_queue.find_first_index( x ) with ( x == task_to_del));
default: $display("This shouldn't happen.");
endfunction
endclass
错误消息逐字如下:
Error-[SV-IQDA] Invalid Queue delete argument
"this.A_queue.find_first_index( iterator ) with ((iterator == task))"
Queue method delete can take optional integer argument. So, argument passed
to it must be either integer or integer assignment compatible.
在调用delete_from_queue之前,会进行相应的检查以确保相关任务已经存在。
发布于 2015-05-28 14:54:00
queue.delete(int'(queue.find_first_index( x ) with ( x == obj_to_del )));
这对我很有效。如果你能像下面这样提供完整的自包含示例,那将会非常有帮助:
module top;
int queue[$] = {1,2,3,4,5};
let object_to_del = 3;
initial begin
queue.delete(int'(queue.find_first_index( x ) with ( x == object_to_del )));
$display("%p", queue);
end
endmodule
但是如果没有匹配呢?在删除之前,您是否不需要测试find_first_index()的结果?
发布于 2015-07-13 21:15:47
int类型转换对我来说不是很好,但是下面的代码可以工作
int index_to_del[$];
index_to_del = que.find_first_index(x) with ( x == task_to_del );
que.delete(index_to_del[0]);
https://stackoverflow.com/questions/30494550
复制相似问题