• 通过uvm_printer的print_generic进行扩展打印


    uvmfield automation机制实现的其中一项功能就是sprint功能,该函数通过调用do_print函数实现。在某些情况的,uvm的打印功能不是我们所期望的,比如多维数组的field automation机制就不支持,struct之类的结构体打印结果为大数。因此我们需要对uvmsprint功能进行扩展,使其打印的log内容符合我们的预期。

    1. do_print函数的定义

    virtual function void do_print( uvm_printer printer );
    	super.do_print( printer );
    	//print customed variables or structs
    	...
    endfunction: do_print
    
    • 1
    • 2
    • 3
    • 4
    • 5

    2. print_generic

    uvm源码中对uvm_sequen_item的打印是通过调用如下函数实现的,因此我们可以通过调用该函数实现打印功能扩展。

    virtual function void print_generic (
       	string 	name,	  	
       	string 	type_name,	  	
       	int 	size,	  	
       	string 	value,	  	
       	byte 	scope_separator	 = 	"."
    )
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    功能描述:Prints a field having the given name, type_name, size, and value.

    3. application example

    假如我们在扩展的uvm_transaction中定义了如下的结构体变量:

    typedef struct {
           bit [7:0] x;
           bit [7:0] y;
           bit [7:0] z;
    } point_s
    
    point_s p;
    
    `uvm_field_int(p, UVM_ALL_ON)
    ...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10

    如果要对uvm_transaction的派生类的实例调用sprint函数进行打印,p打印的结果为整数,而我们期望的结果是打印出p的x,y,z的值。

    通过对do_print函数的扩展可以实现上述功能,如下:

    virtual function void do_print( uvm_printer printer );
    	super.do_print( printer );
    	//print customed variables or structs
    	printer.print_generic(
       		"p",  	
       		"struct"
       		$size(p),	  	
       		$sformatf("x='h%0h,y='h%0h,z='h%0h",p.x,p.y,p.z)
    	);
    endfunction: do_print
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
  • 相关阅读:
    深度学习P1——实现mnist手写数字识别
    MySQL数据库备份的三种方式
    订水商城实战教程09-跑马灯
    图像特征提取算法之LBP算法(2)
    golang工程——opentelemetry简介、架构、概念、追踪原理
    【微信小程序篇】- 组件
    Linux学习---uboot入门
    Windows PHP 将 WORD转PDF,执行完成后 释放进程
    Mysql进阶学习(七)联合查询与DML语言
    阿里云物联网平台之极速体验
  • 原文地址:https://blog.csdn.net/hungtaowu/article/details/127869701