[UVM] PLUSARGS

本文介绍了Verilog和SystemVerilog中使用plusarg的功能,包括如何通过$test$plusargs和$value$plusargs来控制仿真行为,以及如何利用uvm_cmdline_processor处理多个相同的plusarg。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

function int get_arg_matches (string match,ref string args[$])
获取与字符串match的内容匹配的参数,结果存储在args字符串队列中;
 
functionint get_arg_value (string match, ref string value)
获取与字符串match匹配的参数值,如“+incdir+”后面的信息,仅获取第一个参数;
 
functionint get_arg_values (string match, ref string values[$])
获取与字符串match匹配的参数值,如“+incdir+”后面的信息,获取所有参数值
example:
initial begin
  string arg_values[$];
  string str_arg_value;
  int num;
  uvm_cmdline_processor clp;
  clp = uvm_cmdline_processor::get_inst();

  void'(clp.get_arg_values("+foo",arg_values));
  for(int ii=0;ii<arg_values.size;ii++)
    $display("arg_values[%0d],%s",ii,arg_values[ii]);
    clp.get_arg_value("seq_num =",str_arg_value);
    num = str_arg_value.atoi();   //string transfer to integer
end

run-time option \

seq_num=200 


uvm_cmdline_processor 可以接收多个相同的plusargs,而$test$plusargs$value$plusargs不能


 $test$plusargs$value$plusargs作为进行Verilog和SystemVerilog仿真运行时调用的系统函数,可以在仿真命令直接进行赋值.

$test$plusargs

当仿真运行时,$test$plusargs会在sim 命令行中搜索指定的字符,若找到相应字符,函数返回“1”,否则返回“0”;

module top ;
  reg[255:0] testname;

initial begin
  if($test$plusargs("TAISHAN"))
    $display("****************TAISHAN is selected******************");
end

endmodule

sim option: simv +TAISHAN

 

$value$plusargs

$value$plusargs用於(sim-options)中的参数值传递给指定的信号或者字符,若在sim options找到相应字符,函数返回“1”,否则返回“0”。

其语法格式如下:

Integer = $value$plusargs(“string”,signalname);

其中string = ”plusarg_format” + ”format_string”, ”plusarg_format” 指定了用户定义的要进行传递的值,”format_string”指定了要传递的值的格式(类似$display中定义的%s、%h、etc.),并且string中 ”plusarg_format” 和 ”format_string” 格式应该为”plusarg_format”(=/+)”format_string”。如果转换后的位宽和传递的值不一致,则按照如下规则转换:

plusarg位宽与sigalname的关系

Signalname值

<

plusarg左补零

>

plusarg截位

plusarg为负数

按照正数处理

不匹配

若为指定默认值,则reg类型为x

 

int stop_clk;
string test_name;
real freq;

if($value$plusargs("FINISH=%0d",stop_clk))begin

  repeat(stop_clk) @(posedge clk);
end

if($value$plusargs("TEST_NAME=%s",test_name))begin

  $display("run test %0s",test_name);
end

if($value$plusargs("FREQ=%0f",freq))begin

  $display("freq: %0f",freq);
end



若使用的运行命令如下:

    <sim-options>  +FINISH=10000 +TESTNAME=this_test +FREQ=5.6666

上例的运行结果为:

    stop_clk : 10000

    testname:this_test

    freq:5.6666

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值