UVM Tutorial for Candy Lovers – 33. Defining do_print

2023-10-19 12:40

本文主要是介绍UVM Tutorial for Candy Lovers – 33. Defining do_print,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

When we implemented the “do” hooks before, we defined the convert2string function, but we did not define our own do_print function. This was because the convert2string is very flexible and light weight as it does not require a so-called print policy that provides a print format. But if you define your own do_print, you can enjoy pre-defined print formats immediately. You can also create your own formats. This article shows how.

Defining do_print

Defining do_print itself is not very difficult. But before doing so, let’s look at the convert2string function we defined before. As you see, the convert2string function defines what variables to print and how.

class jelly_bean_transaction extends uvm_sequence_item;virtual function string convert2string();string s = super.convert2string();s = { s, $psprintf( "\nname      : %s", get_name()    ) };s = { s, $psprintf( "\nflavor    : %s", flavor.name() ) };s = { s, $psprintf( "\ncolor     : %s", color.name()  ) };s = { s, $psprintf( "\nsugar_free: %b", sugar_free    ) };s = { s, $psprintf( "\nsour      : %b", sour          ) };s = { s, $psprintf( "\ntaste     : %s", taste.name()  ) };return s;endfunction: convert2string// ...
endclass: jelly_bean_transaction

Unlike convert2string, usually do_print does not define a print format by itself. Instead, it delegates the formatting to a print policy object (printer). Below is our definition of do_print. The uvm_printer class provides an interface for printing uvm_objects in various formats (line 1). In the do_print function, we merely list the variables we want to print using the functions of uvm_printer class (lines 3 to 8).

Strictly speaking, you can define the do_print without using the uvm_printer, but if you do so, you are not able to use the printer formats defined in the subclasses of uvm_printer.

   virtual function void do_print( uvm_printer printer );super.do_print( printer );printer.print_string( "name",   get_name() );printer.print_string( "flavor", flavor.name() );printer.print_string( "color",  color.name() );printer.print_field_int( "sugar_free", sugar_free, .size( 1 ) );printer.print_field_int( "sour",       sour,       .size( 1 ) );printer.print_string( "taste",  taste.name() );endfunction: do_print

Using do_print

The print and sprint functions of uvm_object call the do_print. Let’s call the sprint in our jelly bean scoreboard. For convenience, UVM pre-defines three print policies (uvm_default_table_printeruvm_default_tree_printer, and uvm_default_line_printer; lines 5 to 7). If you do not specify a print policy, uvm_default_printer, which is set to uvm_default_table_printer by default, is used (line 4). For comparison, we call convert2string on line 3, too.

class jelly_bean_sb_subscriber extends uvm_subscriber#( jelly_bean_transaction );function void write( jelly_bean_transaction t );`uvm_info( get_name(), { "using convert2string",              t.convert2string() }, UVM_LOW )`uvm_info( get_name(), { "using uvm_default_printer\n",       t.sprint() }, UVM_LOW ) // use uvm_default_printer`uvm_info( get_name(), { "using uvm_default_table_printer\n", t.sprint( uvm_default_table_printer ) }, UVM_LOW )`uvm_info( get_name(), { "using uvm_default_tree_printer\n",  t.sprint( uvm_default_tree_printer  ) }, UVM_LOW )`uvm_info( get_name(), { "using uvm_default_line_printer\n",  t.sprint( uvm_default_line_printer  ) }, UVM_LOW )endfunction: write// ...
endclass: jelly_bean_sb_subscriber

Let’s see the each output. After running a simulation, you should see something like these:

Output of convert2string

This is our old friend. We see the output as specified in the function.

UVM_INFO env.svh(134) @ 185: uvm_test_top.jb_env.jb_sb [jb_sb] using convert2string
name      : jb_tx
flavor    : BUBBLE_GUM
color     : RED
sugar_free: 1
sour      : 1
taste     : YUMMY

Output of sprint using uvm_default_printer

This is the output if we do not specify the print policy. As we mentioned before, the uvm_default_printer is used, which is set to uvm_default_table_printer by default.

UVM_INFO env.svh(136) @ 185: uvm_test_top.jb_env.jb_sb [jb_sb] using uvm_default_printer
-----------------------------------------------------------------
Name          Type                               Size  Value     
-----------------------------------------------------------------
jb_tx         sugar_free_jelly_bean_transaction  -     @861      name        string                             5     jb_tx     flavor      string                             10    BUBBLE_GUMcolor       string                             3     RED       sugar_free  integral                           1     'h1       sour        integral                           1     'h1       taste       string                             5     YUMMY     
-----------------------------------------------------------------

Output of sprint using uvm_default_table_printer

This output is exactly same as the above.

UVM_INFO env.svh(138) @ 185: uvm_test_top.jb_env.jb_sb [jb_sb] using uvm_default_table_printer
-----------------------------------------------------------------
Name          Type                               Size  Value     
-----------------------------------------------------------------
jb_tx         sugar_free_jelly_bean_transaction  -     @861      name        string                             5     jb_tx     flavor      string                             10    BUBBLE_GUMcolor       string                             3     RED       sugar_free  integral                           1     'h1       sour        integral                           1     'h1       taste       string                             5     YUMMY     
-----------------------------------------------------------------

Output of sprint using uvm_default_tree_printer

The uvm_default_tree_printer outputs the object in a tree form.

UVM_INFO env.svh(140) @ 185: uvm_test_top.jb_env.jb_sb [jb_sb] using uvm_default_tree_printer
jb_tx: (sugar_free_jelly_bean_transaction@861) {name: jb_tx flavor: BUBBLE_GUM color: RED sugar_free: 'h1 sour: 'h1 taste: YUMMY 
}

Output of sprint using uvm_default_line_printer

The uvm_default_line_printer outputs the same information as the uvm_default_tree_printer does, but in one line.

UVM_INFO env.svh(142) @ 185: uvm_test_top.jb_env.jb_sb [jb_sb] using uvm_default_line_printer
jb_tx: (sugar_free_jelly_bean_transaction@861) { name: jb_tx  flavor: BUBBLE_GUM  color: RED  sugar_free: 'h1  sour: 'h1  taste: YUMMY  }

Defining our own print policy

If the pre-defined formats do not satisfy your needs, you can create your own print policy. As an example, we are going to create a policy that prints an uvm_object in JSON format. Our goal is to print a jelly_bean_transaction like this:

{"jb_tx": {"name": "jb_tx","flavor": "BUBBLE_GUM","color": "RED","sugar_free": "'h1","sour": "'h1","taste": "YUMMY"}
}

For those of you who are not familiar with JSON, please see this link.

To create your own print policy, you need to extend the uvm_printer class and define the emit function. The information to print is stored in an array (m_rows) of uvm_printer_row_info structure (line 16) which holds the name of variable, size, value, etc. Line 31 prints a name-value pair such as "flavor":"BUBBLE_GUM". I’m not going to explain the implementation line-by-line because most of the other lines deal with detail formatting. One note I have to mention, though, is that the printer settings are defined in knobs (an object of uvm_printer_knobs class). We use one of the settings (indent; the number of spaces to use for level indentation) on line 18.

class json_printer extends uvm_printer;function new();super.new();endfunction: newvirtual function string emit();string s;string comma = "";string space = { 100 { " " } };string indent;int    next_level;s = "{\n"; // begin JSONforeach ( m_rows[i] ) beginuvm_printer_row_info row = m_rows[i];indent = space.substr( 1, ( row.level + 1 ) * knobs.indent );s = { s, comma, indent };if ( i == m_rows.size() - 1 ) begin // last rownext_level = 0;end else begin // not last rownext_level = m_rows[ i + 1 ].level;if ( row.level < next_level ) begin // next level is deeprs = { s, "\"", row.name, "\": {\n" }; // begin nested JSON objectcomma = "";continue;endends = { s, "\"", row.name, "\": \"", row.val, "\"" }; // name-value paircomma = ",\n";if ( next_level < row.level ) begin // next level is shallowerfor ( int l = row.level; l > next_level; l-- ) beginindent = space.substr( 1, l * knobs.indent );s = { s, "\n", indent, "}" }; // end nested JSON objectendendend // foreach ( m_rows[i] )emit = { s, "\n}" }; // end JSONm_rows.delete();endfunction: emit
endclass: json_printer

To use the new print policy, we create it (line 6) and pass it when we call sprint (line 10).

class jelly_bean_sb_subscriber extends uvm_subscriber#( jelly_bean_transaction );json_printer json_p;virtual function void build_phase( uvm_phase phase );super.build_phase( phase );json_p = new;endfunction: build_phasefunction void write( jelly_bean_transaction t );`uvm_info( get_name(), { "using json_printer\n", t.sprint( json_p ) }, UVM_LOW )endfunction: write// ...
endclass: jelly_bean_sb_subscriber

You should see something like this when you run:

UVM_INFO env.svh(144) @ 185: uvm_test_top.jb_env.jb_sb [jb_sb] using json_printer
{"jb_tx": {"name": "jb_tx","flavor": "BUBBLE_GUM","color": "RED","sugar_free": "'h1","sour": "'h1","taste": "YUMMY"}
}

For your reference, these are the classes and struct we used in this article.

 

这篇关于UVM Tutorial for Candy Lovers – 33. Defining do_print的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/239864

相关文章

UVM:callback机制的意义和用法

1. 作用         Callback机制在UVM验证平台,最大用处就是为了提高验证平台的可重用性。在不创建复杂的OOP层次结构前提下,针对组件中的某些行为,在其之前后之后,内置一些函数,增加或者修改UVM组件的操作,增加新的功能,从而实现一个环境多个用例。此外还可以通过Callback机制构建异常的测试用例。 2. 使用步骤         (1)在UVM组件中内嵌callback函

ImportError: cannot import name ‘print_log‘ from ‘logging‘

mmcv升级到2.+后删除了很多 解决 查FAQ文档,找到 添加到mmcv.utils下即可

【python pandas】 Dataframe的数据print输出 显示为...省略号

pandas.set_option() 可以设置pandas相关的参数,从而改变默认参数。 打印pandas数据事,默认是输出100行,多的话会输出….省略号。 那么可以添加: pandas.set_option('display.max_rows',None) 这样就可以显示全部数据 同样,某一列比如url太长 显示省略号 也可以设置。 pd.set_option('display.

[UVM]6.component driver monitor sequencer agent scoreboard env test

1.知识点回顾 (1)component需要有parent,因为参加构成组件,所以需要(继承); (2)object与component之间间隔report_object。 2.组件家族 (1)构建寄存器模型 :uvm_reg_predictor;激励器:driver/random_stimulus/sequencer_base/sequencer;监测器:monitor;

LeetCode - 33. Search in Rotated Sorted Array

33. Search in Rotated Sorted Array  Problem's Link  ---------------------------------------------------------------------------- Mean:  给你一个数组,这个数组是由两个有序的数组拼接成的(无重复元素),在这个数组中查找元素k的下标. anal

「图」邻接矩阵|边集数组|邻接表 / LeetCode 35|33|81(C++)

概述 我们开始入门图论:图的存储。 图是一种高级数据结构:链表是一个节点由一条边指向下一个节点,二叉树是一个节点由两条边指向下两个节点,而图是由任意多个节点由任意多条边指向任意多个节点。 图由节点和边构成,边往往存在边权。边权在不同的问题中往往有不同含义,如在最短路径中表示边的长度,在AOE网中表示任务所需时间。 对于这种复杂的结构,如何存储在计算机的程序语言中呢? 我们先来介绍三种存储

iReport利用Print Repeated Values做分组报表以及对重复值做distinct运算

iReport自带的分组功能有可能是比较符合西方的分组标准,对于中国人来说希望显示方便、节省纸张,对于iReport实现起来就稍微复杂一点了。 本文所用demo地址:http://download.csdn.net/detail/u013284604/6812623 iReport版本 5.1.0,demo所用数据源:json数据源 一、iReport利用Print Repeated Val

A Tutorial on Near-Field XL-MIMO Communications Towards 6G【论文阅读笔记】

此系列是本人阅读论文过程中的简单笔记,比较随意且具有严重的偏向性(偏向自己研究方向和感兴趣的),随缘分享,共同进步~ 论文主要内容: 建立XL-MIMO模型,考虑NUSW信道和非平稳性; 基于近场信道模型,分析性能(SNR scaling laws,波束聚焦、速率、DoF) XL-MIMO设计问题:信道估计、波束码本、波束训练、DAM XL-MIMO信道特性变化: UPW ➡ NU

【软件技巧】第33课,软件逆向安全工程师之如何快速的跑到某行代码EIP设置,每天5分钟学习逆向吧!

鼠标右键在此设置EIP EIP(Extended Instruction Pointer)是x86架构中一个重要的寄存器,它用于存储当前正在执行的指令的地址。EIP是程序计数器(Program Counter)的扩展版本,因为它是32位寄存器,所以它能够存储一个32位的地址。 在x86架构中,EIP寄存器的作用如下: 指令地址:EIP寄存器存储当前正在执行的指令的内存地址。当CPU执行一个指令

CF C. Candy Store

原题链接:Problem - C - Codeforces 题意:多测,先给出n代表n种糖果,每种糖果分别给出数量和单价,可以将糖果平均分成若干袋,每一袋的的价格是一袋糖果数量×单价,对于每一种糖果都求出一袋的价格,对于每种糖果都需要用标签贴出一袋的价格,但是如果相邻的糖果价格相同,那么就可以用一个标签来代表价格,问最少使用几个标签。 思路:如果一段糖果价格是一样的,那么设置价格为cost。因