根据1800-2012 规格 http://standards.ieee.org/getieee/1800/download/1800-2012.pdf,
Queue::delete( [input int index] )
删除 SystemVerilog 中队列的一个元素,此外,队列可以执行与解包数组相同的操作,使其可以访问:
Array::find_first_index( )
它返回符合特定条件的第一个元素的索引。 IE。
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 是否可能返回一个大小为 1 且索引位于位置 0 的数组?
编辑:我愚蠢地没有提供一个独立的示例:我正在做的事情的剥离示例如下所示:
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 之前,会进行检查以确保相关任务存在。