SystemVerilog学习——系统函数$test$plusargs与$value$plusargs总结

系统函数$test $plusargs与 $value $plusargs总结

systemVerilog可以采用define与parameter等方式定义变量,但是需要在编译前完成变量的定义,编译之后不能修改,如果在仿真时需要修改变量,则只能重新定义变量、重新编译。由此引出$test $plusargs 和 $value $plusargs的功能:可以在仿真时从命令框读取参数,从而实现在不重新编译的情况下完成变量的重新赋值。

  1. $test $ plusargs
    在仿真时,$test $plusargs 会在命令框内搜索制定字符,如果存在相应字符,则返回“1”,如果不存在相应字符,则返回“0”。示例如下:
module tb
initial begin
	if($test$plusargs("test0"))
		$display("test0 is here");
	else
		$display("test0 is not here");
end
endmodule

当命令框中输入:sim +test0时,$ test $ plusargs会判断是否存在“test0”,显然存在,返回“1”,打印“test0 is here”。
当命令框中输入:sim +test1时,$ test $ plusargs搜索不到“test0”,故返回“0”,将打印“test0 is not here”。

虽然$test $plusargs解决了重新编译的问题,但是不推荐大量使用该语句,因为这会使编译变得更加复杂。

  1. $ value $ plusargs
    在仿真时,$ value $ plusargs可以将外部参数传递到内部信号,完成对内部信号的赋值。示例如下:
module tb
initial begin
	string t;
	if($value$plusagrs("my_string=%s",t))
		$display("now %s is here",t);
end
endmodule

当命令框内输入:sim +my_string=test1时,$ value $ plusargs搜识别到“my_string”,并将test1赋值给字符串t,那么将打印“now test1 is here”。
如果传递参数没有被识别,或者没有传递参数,那么仿真器会利用系统函数$error()来报告错误。

  • 3
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
请逐行注释下面的代码:class riscv_instr_base_test extends uvm_test; riscv_instr_gen_config cfg; string test_opts; string asm_file_name = "riscv_asm_test"; riscv_asm_program_gen asm_gen; string instr_seq; int start_idx; uvm_coreservice_t coreservice; uvm_factory factory; uvm_component_utils(riscv_instr_base_test) function new(string name="", uvm_component parent=null); super.new(name, parent); void'($value$plusargs("asm_file_name=%0s", asm_file_name)); void'($value$plusargs("start_idx=%0d", start_idx)); endfunction virtual function void build_phase(uvm_phase phase); super.build_phase(phase); coreservice = uvm_coreservice_t::get(); factory = coreservice.get_factory(); uvm_info(gfn, "Create configuration instance", UVM_LOW) cfg = riscv_instr_gen_config::type_id::create("cfg"); uvm_info(gfn, "Create configuration instance...done", UVM_LOW) uvm_config_db#(riscv_instr_gen_config)::set(null, "*", "instr_cfg", cfg); if(cfg.asm_test_suffix != "") asm_file_name = {asm_file_name, ".", cfg.asm_test_suffix}; // Override the default riscv instruction sequence if($value$plusargs("instr_seq=%0s", instr_seq)) begin factory.set_type_override_by_name("riscv_instr_sequence", instr_seq); end if (riscv_instr_pkg::support_debug_mode) begin factory.set_inst_override_by_name("riscv_asm_program_gen", "riscv_debug_rom_gen", {gfn, ".asm_gen.debug_rom"}); end endfunction function void report_phase(uvm_phase phase); uvm_report_server rs; int error_count; rs = uvm_report_server::get_server(); error_count = rs.get_severity_count(UVM_WARNING) + rs.get_severity_count(UVM_ERROR) + rs.get_severity_count(UVM_FATAL); if (error_count == 0) begin uvm_info("", "TEST PASSED", UVM_NONE); end else begin uvm_info("", "TEST FAILED", UVM_NONE); end uvm_info("", "TEST GENERATION DONE", UVM_NONE); super.report_phase(phase); endfunction virtual function void apply_directed_instr(); endfunction task run_phase(uvm_phase phase); int fd; for(int i = 0; i < cfg.num_of_tests; i++) begin string test_name; randomize_cfg(); riscv_instr::create_instr_list(cfg); riscv_csr_instr::create_csr_filter(cfg); asm_gen = riscv_asm_program_gen::type_id::create("asm_gen", , gfn); asm_gen.cfg = cfg; asm_gen.get_directed_instr_stream(); test_name = $sformatf("%0s_%0d.S", asm_file_name, i+start_idx); apply_directed_instr(); uvm_info(gfn, "All directed instruction is applied", UVM_LOW) asm_gen.gen_program(); asm_gen.gen_test_file(test_name); end endtask virtual function void randomize_cfg(); DV_CHECK_RANDOMIZE_FATAL(cfg); uvm_info(`gfn, $sformatf("riscv_instr_gen_config is randomized:\n%0s", cfg.sprint()), UVM_LOW) endfunction endclass
05-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值