UVM基础之---Command-line Processor

提供一个厂商独立的通用接口命令行参数,支持分类:
  1. 基本参数和值:get_args,get_args_matches
  2. 工具信息:get_tool_name(),get_tool_version()
  3. 支持从命令行设置各种UVM变量如冗长和配置设置积分和字符串类型:  +uvm_set_config_int, +uvm_set_config_string

类:uvm_cmdline_processor:
这个类在模拟过程中提供一个命令参数接口,这个类应该是当成一个单例类使用,但这不是必须的。一个全局变量 uvm_cmdline_proc在初始化的时候创建,用于访问命令行提供的信息。也支持从命令行配置各种各样的UVM变量。

下面简单的分析下这个类的实现机制:首先这个类继承自uvm_report_object,是一个单态类。

  protected string m_argv[$]; 
  protected string m_plus_argv[$];
  protected string m_uvm_argv[$]; 
 
首先是基本的参数操作:
  get_args(output string args[$]) 命令行的所有用于控制仿真状态的参数做成一个队列并返回。
  get_plusargs(output string args[$]) :返回一个队列,包含所有用于启动仿真的附加参数。
  get_uvm_args(output string args[$]) : 使用一个队列返回所有uvm参数。
  get_arg_matches(string match, ref string args[$]) :这个函数加载所有匹配match string的参数到一个队列,并返回匹配的个数。如果表达式包含//扩展正则表达式,下面是一个例子:
 //| string myargs[$]
  //| initial begin
  //|    void'(uvm_cmdline_proc.get_arg_matches("+foo",myargs)); //matches +foo, +foobar
  //|                                                            //doesn't match +barfoo
  //|    void'(uvm_cmdline_proc.get_arg_matches("/foo/",myargs)); //matches +foo, +foobar,
  //|                                                             //foo.sv, barfoo, etc.
  //|    void'(uvm_cmdline_proc.get_arg_matches("/^foo.*.sv",myargs)); //matches foo.sv
  //|                                                                   //and foo123.sv,
  //|                                                                   //not barfoo.sv.

  function int get_arg_matches (string match, ref string args[$]);
   `ifndef UVM_CMDLINE_NO_DPI
    chandle exp_h = null;
    int len = match.len();   //检查match的长度
    args.delete();
    if((match.len() > 2) && (match[0] == "/") && (match[match.len()-1] == "/")) begin//如果长度大于2 且包含//
       match = match.substr(1,match.len()-2);//提取需要match的表达式
       exp_h = uvm_dpi_regcomp(match);//使用dpi匹配满足表达式,
       if(exp_h == nullbegin
         uvm_report_error("UVM_CMDLINE_PROC", {"Unable to compile the regular expression: ", match}, UVM_NONE);
         return 0;
       end
    end
    foreach (m_argv[i]) begin
      if(exp_h != nullbegin
        if(!uvm_dpi_regexec(exp_h, m_argv[i]))
           args.push_back(m_argv[i]);
      end
      else if((m_argv[i].len() >= len) && (m_argv[i].substr(0,len - 1) == match))
        args.push_back(m_argv[i]);
    end
    if(exp_h != null)
      uvm_dpi_regfree(exp_h);
    `endif
    return args.size();
  endfunction 


get_arg_value(string match,ref string value):从args里面找到第一个满足match的参数,并返回对应的值
get_arg_values(string match, ref srring values[$]) : 从args里面找到所有满足match的参数,并返回一个值得队列。返回参数是匹配的个数。
 
   function new(string name = ""); 用于收集命令行传来的参数,并保存到对应的队列里面
    string s;
    string sub;
    int doInit=1;
    super.new(name);
    do begin
      s = uvm_dpi_get_next_arg(doInit);
      doInit=0;
      if(s!=""begin
        m_argv.push_back(s);
        if(s[0] == "+"begin
          m_plus_argv.push_back(s);
        end 
        if(s.len() >= 4 && (s[0]=="-" || s[0]=="+")) begin
          sub = s.substr(1,3);
          sub = sub.toupper();
          if(sub == "UVM")
            m_uvm_argv.push_back(s);
        end 
      end
    end while(s!=""); 

命令行调试:
  1. +UVM_DUMP_CMDLINE_ARGS,允许用户dump所有的命令行参数发给report机制,在uvm_root里面实现
    2. +UVM_TESTNAME= 指定需要从工厂里面创建的test,如果指定很多,则使用第一个。在uvm_root实现,通过run_test调用
  3.+UVM_VERBOSITY= 指定message的冗余程度,在uvm_root实现,通过uvm_root:new()调用
    4. +uvm_set_verbosity 允许用户在特定的phase对特定的message的冗余度进行调整
    // ~+uvm_set_verbosity=<comp>,<id>,<verbosity>,<phase>~ and
    // ~+uvm_set_verbosity=<comp>,<id>,<verbosity>,time,<time>~ 

    +uvm_set_verbosity=uvm_test_top.env0.agent1.*,_ALL_,UVM_FULL,time,800

    5. +uvm_set_action:指定对应的message的动作
    +uvm_set_action=uvm_test_top.env0.*,_ALL_,UVM_ERROR,UVM_NO_ACTION
    6. +uvm_set_severity : 指定对应message的严重等级:
    7. +UVM_TIMEOUT= 
    8. +UVM_MAX_QUIT_COUNT 用于指定当出现几个ERROR就退出仿真
    9. +UVM_PHASE_TRACE
   10. +UVM_OBJECTION_TRACE
   11. +UVM_RESOURCE_DB_TRACE
   12. +UVM_CONFIG_DB_TRACE
   13. 工厂替换参数:  
   // Variable: +uvm_set_inst_override 
    // Variable: +uvm_set_type_override   
    // ~+uvm_set_inst_override=<req_type>,<override_type>,<full_inst_path>~ and
    // ~+uvm_set_type_override=<req_type>,<override_type>[,<replace>]~
 //| <sim command> +uvm_set_type_override=eth_packet,short_eth_packet
   14. 设置变量参数:
    // Variable: +uvm_set_config_int 
    // Variable: +uvm_set_config_string
    // ~+uvm_set_config_int=<comp>,<field>,<value>~ and
    // ~+uvm_set_config_string=<comp>,<field>,<value>~






原文地址:https://www.cnblogs.com/bob62/p/4101921.html