UVM的Messages机制有些时候很繁琐,很多时候希望能够在UVM messages的基础上做一些个人化的订制,这里给出来一个找到的例子作为参考。

my_macros.sv:
   `define my_info(MSG, VERBOSITY) \
      begin \
         if(uvm_report_enabled(VERBOSITY,UVM_INFO,get_full_name())) \
            uvm_report_info(get_full_name(), $sformatf MSG, 0, `uvm_file, `uvm_line); \
      end
  `define my_err(MSG) \
      begin \
         if(uvm_report_enabled(UVM_NONE,UVM_ERROR,get_full_name())) \
            uvm_report_error(get_full_name(), $sformatf MSG, UVM_NONE, `uvm_file, `uvm_line); \
      end
   `define my_warn(MSG) \
      begin \
         if(uvm_report_enabled(UVM_NONE,UVM_WARNING,get_full_name())) \
            uvm_report_warning(get_full_name(), $sformatf MSG, UVM_NONE, `uvm_file, `uvm_line); \
      end
   `define my_fatal(MSG) \
      begin \
         if(uvm_report_enabled(UVM_NONE,UVM_FATAL,get_full_name())) \
            uvm_report_fatal(get_full_name(), $sformatf MSG, UVM_NONE, `uvm_file, `uvm_line); \
      end
my_init.sv:
  initial begin
      my_report_server_c report_server = new("my_report_server");
      if($value$plusargs("fname_width=%d", fwidth)) begin
         report_server.file_name_width = fwidth;
      end
      if($value$plusargs("hier_width=%d", hwidth)) begin
         report_server.hier_width = hwidth;
      end
      uvm_pkg::uvm_report_server::set_server(report_server);
      // all "%t" shall print out in ns format with 8 digit field width
      $timeformat(-9,0,"ns",8);
   end
my_report_server.sv:
class my_report_server_c extends uvm_report_server;
   `uvm_object_utils(my_report_server_c)
   string filename_cache[string];
   string hier_cache[string];
   int unsigned file_name_width = 28;
   int unsigned hier_width = 60;
   uvm_severity_type sev_type;
   string prefix, time_str, code_str, fill_char, file_str, hier_str;
   int last_slash, flen, hier_len;
   function new(string name="my_report_server");
      super.new();
   endfunction : new
   virtual function string compose_message(uvm_severity severity, string name, string id, string message,
                                           string filename, int line);
      // format filename & line-number
      last_slash = filename.len() - 1;
      if(file_name_width > 0) begin
         if(filename_cache.exists(filename))
            file_str = filename_cache[filename];
         else begin
            while(filename[last_slash] != "/" && last_slash != 0)
               last_slash--;
            file_str = (filename[last_slash] == "/")?
                       filename.substr(last_slash+1, filename.len()-1) :
                       filename;
            flen = file_str.len();
            file_str = (flen > file_name_width)?
                       file_str.substr((flen - file_name_width), flen-1) :
                       {{(file_name_width-flen){" "}}, file_str};
            filename_cache[filename] = file_str;
         end
         $swrite(file_str, "(%s:%6d) ", file_str, line);
      end else
         file_str = "";
      // format hier
      hier_len = id.len();
      if(hier_width > 0) begin
         if(hier_cache.exists(id))
            hier_str = hier_cache[id];
         else begin
            if(hier_len > 13 && id.substr(0,12) == "uvm_test_top.") begin
               id = id.substr(13, hier_len-1);
               hier_len -= 13;
            end
            if(hier_len < hier_width)
               hier_str = {id, {(hier_width - hier_len){" "}}};
            else if(hier_len > hier_width)
               hier_str = id.substr(hier_len - hier_width, hier_len - 1);
            else
               hier_str = id;
            hier_str = {"[", hier_str, "]"};
            hier_cache[id] = hier_str;
         end
      end else
         hier_str = "";
      // format time
      $swrite(time_str, " {%t}", $time);
      // determine fill character
      sev_type = uvm_severity_type'(severity);
      case(sev_type)
         UVM_INFO: begin code_str = "%I"; fill_char = " "; end
         UVM_ERROR: begin code_str = "%E"; fill_char = "_"; end
         UVM_WARNING: begin code_str = "%W"; fill_char = "."; end
         UVM_FATAL: begin code_str = "%F"; fill_char = "*"; end
         default: begin code_str = "%?"; fill_char = "?"; end
      endcase
      // create line's prefix (everything up to time)
      $swrite(prefix, "%s-%s%s%s", code_str, file_str, hier_str, time_str);
      if(fill_char != " ") begin
         for(int x = 0; x < prefix.len(); x++)
            if(prefix[x] == " ")
               prefix.putc(x, fill_char);
      end
      // append message
      return {prefix, " ", message};
   endfunction : compose_message
endclass : my_report_server_c

定制UVM Messages(参考)的更多相关文章

  1. 定制个性化码表技术 ibus

    在不同用户的工作环境中,都会根据各自使用的字符集的不同,而需要定制优化各自的输入法码表,例如,在GB18030中的大量汉字,或许因为输入法码表的老旧,而难于利用自己熟悉的“五笔”方法快速录入,同样,需 ...

  2. 【OpenStack】OpenStack系列14之Dashboard定制开发

    django概述 参考资料:http://blog.javachen.com/2014/01/11/how-to-create-a-django-site.html http://djangobook ...

  3. scss组件定制的一些学习

    应组织上的要求,简化前端开发,提高工作效率,开始着手研究scss框架及组件化. 把一些长的像的弄在一起,就有了组件化. 但组件只用一部分需要的,就有了定制. 下面是参考一个button组件写出的一些简 ...

  4. 浏览器扩展系列————在WPF中定制WebBrowser快捷菜单

    原文:浏览器扩展系列----在WPF中定制WebBrowser快捷菜单 关于如何定制菜单可以参考codeproject上的这篇文章:http://www.codeproject.com/KB/book ...

  5. [技术] 如何正确食用cnblogs的CSS定制

    用过cnblogs的估计都知道cnblogs提供了相对比较开放的个性化选项,其中最为突出的估计就是页面CSS定制了.但是没学过Web前端的人可能并不会用这个东西... 所以我打算在此分享一些定制CSS ...

  6. django学习记录

    1.参考资料问题: 现在django发布了1.11版本,离线文档下载引擎地址 文档下载地址 在线文档:https://docs.djangoproject.com/en/1.10/intro/tuto ...

  7. gson笔记 解析json数据

    gson中负责json数据解析的类是JsonReader. Json格式有两种结构,一种是对象(键值对的组合,无序),另外一种是数组(值的有序集合). 因此针对这两种格式,JsonReader提供了不 ...

  8. PostgreSQL全文检索zhparser使用

    本文引用自: http://blog.chinaunix.net/uid-20726500-id-4820580.html 防止文章丢失才进行复制 PostgreSQL支持全文检索,其内置的缺省的分词 ...

  9. linux PPTP VPN客户端安装

    转载于http://www.2cto.com/os/201209/157462.html 下载pptp-1.7.2.tar.gz http://pptpclient.sourceforge.net/ ...

随机推荐

  1. noip模拟赛 洗澡

    分析:首先肯定是要用线性筛把素数全部给筛出来的,然后可以维护一个前缀和数组记录1~i个素数的和,对于每一个询问可以从n到1+k枚举它的右端点,然后利用前缀和统计一个长度为K的区间和,看看是不是满足条件 ...

  2. 用信号量及其PV操作处理实际问题

    43.现有3个生产者P1.P2.P3,他们都要生产橘子汁,每个生产者都已分别购得两种不同的原料,待购齐第三种原料后就可配制成橘子汁装瓶出售.有一供应商能源源不断的供应糖.水.橘子精,但每次只拿出一种原 ...

  3. 1.7-BGP④

    注意:默认路由ip route 0.0.0.0 0.0.0.0 12.1.1.1是不可以作为BGP邻居TCP始发连接的(但回包可以) 要配静态路由:ip route 13.1.1.3 255.255. ...

  4. linux高级技巧:集群之keepalived

    1.keepalived简单介绍         Keepalived是一个基于VRRP协议来实现的WEB服务高可用方案.能够利用其来避免单点故障.使用多台节点安装keepalived. 其它的节点用 ...

  5. ORACLE database console无法登陆

    登陆EM时给我报这个错 Code d'erreur : ssl_error_weak_server_cert_key 仅仅须要关闭EM的SSL就好了 [oracle@ace-PROD1 ~]$ emc ...

  6. 使用JavaScript开发IE浏览器本地插件实例

    使用JavaScript开发IE浏览器本地插件实例 投稿:junjie 字体:[增加 减小] 类型:转载 时间:2015-02-18我要评论 这篇文章主要介绍了使用JavaScript开发IE浏览器本 ...

  7. bzoj 4590: [Shoi2015]自动刷题机

    好恶心.. 二分上界到100000LL*1000000000LL  %_% #include<cstdio> #include<iostream> #include<cs ...

  8. codeforces 939E Maximize! 双指针(two pointers)

    E. Maximize! time limit per test 3 seconds memory limit per test 256 megabytes input standard input ...

  9. LuoguP4462 [CQOI2018]异或序列

    https://zybuluo.com/ysner/note/1124952 题面 给你一个大小为\(n\)的序列,然后给你一个数字\(k\),再给出\(m\)组询问,询问给出一个区间,问这个区间里面 ...

  10. Flink编程练习

    目录 1.wordcount 2.双流警报EventTime 3.持续计数stateful + timer + SideOutputs 4.一定时间范围内的极值windowfunction + che ...