6 UVM Object

news2025/3/20 7:28:44

uvm_object类是所有uvm层次类的基类,如uvm_report_object、uvm_component、uvm_transaction、uvm_sequence_item、uvm_sequence等。它在定义一组方法(如create, copy, print, clone, compare, record等)方面起着重要作用。

6.1 UVM Utility Macros and field macros

我们在UVM factory章节已经看到了“create”方法是如何工作的,“create”方法为对象分配内存空间并返回相同类型的句柄。

`uvm_object_utils或`uvm_abject_utils_begin`uvm_object_utils_end宏用于在uvm工厂中注册uvm_object和其他派生类型,如uvm_transaction、uvm_sequece_items。

UVM字段宏(field macros)提供了 create, copy, print, clone, compare, record等方法的实现。工厂中有不同的`uvm_field_*宏可用于各种数据类型变量的注册。`uvm_field_*宏至少接受两个参数作为arg(与`uvm_field_*宏兼容的变量的实例名)和flag(用作添加相应数据方法的控制机制)。

new()方法很重要,可以用相应的类名作为扩充来定义。

注:在编译期间,这些UVM自动化宏扩展了相应宏可用的完整代码。

Syntax without field macros:

`uvm_object_utils(<class Type>)

Syntax with field macros:

`uvm_object_utils_begin(<class_type>)
  `uvm_field_*(<arg>, <flag>)
`uvm_object_utils_end

以下字段宏通常用于标量/动态类属性的数据方法[data methods](copy, compare, pack, unpack, print, clone, 等)。可以从UVM参考文件中研究完整列表。 

6.1.1 `uvm_field_* macros

`uvm_field_*宏实现标量属性的数据方法。

6.1.2 `uvm_field_sarray_* macros

`uvm_field_sarray*宏实现一维静态数组属性的数据方法。

6.1.3 `uvm_field_array_* macros

uvm_field_array*宏实现一维动态数组属性的数据方法。

6.1.4 `uvm_field_* macro flag

也可以指定打印的进制。默认是16进制HEX。

6.2 Code with `uvm_object_utils

typedef enum{RED, GREEN, BLUE} color_type;
class my_object extends uvm_object;
  int        o_var;
  string     o_name;
  color_type colors;
  byte       data[4];
  bit [7:0]  addr;
  
  `uvm_object_utils(my_object)
  
  function new(string name = "my_object");
    super.new(name);
  endfunction
endclass

6.3 Code with `uvm_object_utils_begin and `uvm_object_utils_end

typedef enum{RED, GREEN, BLUE} color_type;
class my_object extends uvm_object;
  rand int        value;
       string     names;
  rand color_type colors;
  rand byte       data[4];
  rand bit [7:0]  addr;
  
  `uvm_object_utils_begin(my_object)
    `uvm_field_int(value, UVM_ALL_ON)
    `uvm_field_string(names, UVM_ALL_ON)
    `uvm_field_enum(color_type, colors, UVM_ALL_ON)
    `uvm_field_sarray_int(data, UVM_ALL_ON)
    `uvm_field_int(addr, UVM_ALL_ON)
  `uvm_object_utils_end
  
  function new(string name = "my_object");
    super.new(name);
  endfunction
endclass

6.4 UVM中的打印方法

打印方法用于以格式良好的方式深度打印UVM对象类的属性。需要根据类属性的数据类型使用适当的`uvm_field_*宏。

注意:sprint()方法与print()方法相同,不同的是sprint()方法以字符串格式打印对象。

6.4.1 打印方法示例

typedef enum{RED, GREEN, BLUE} color_type;

class temp_class extends uvm_object;
  rand bit [7:0] tmp_addr;
  rand bit [7:0] tmp_data;
  
  function new(string name = "temp_class");
    super.new(name);
  endfunction
  
  `uvm_object_utils_begin(temp_class)
    `uvm_field_int(tmp_addr, UVM_ALL_ON)
    `uvm_field_int(tmp_data, UVM_ALL_ON)
  `uvm_object_utils_end
endclass

class my_object extends uvm_object;
  rand int        value;
       string     names;
  rand color_type colors;
  rand byte       data[4];
  rand bit [7:0]  addr;
  rand temp_class tmp;
  
  `uvm_object_utils_begin(my_object)
    `uvm_field_int(value, UVM_ALL_ON)
    `uvm_field_string(names, UVM_ALL_ON)
    `uvm_field_enum(color_type, colors, UVM_ALL_ON)
    `uvm_field_sarray_int(data, UVM_ALL_ON)
    `uvm_field_int(addr, UVM_ALL_ON)
    `uvm_field_object(tmp, UVM_ALL_ON)
  `uvm_object_utils_end
  
  function new(string name = "my_object");
    super.new(name);
    tmp = new();
    this.names = "UVM";
  endfunction
endclass

class my_test extends uvm_test;
  `uvm_component_utils(my_test)
  my_object obj;
  bit packed_data_bits[];
  byte unsigned packed_data_bytes[];
  int unsigned packed_data_ints[];
  
  my_object unpack_obj;
  
  function new(string name = "my_test", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    obj = my_object::type_id::create("obj", this);
    assert(obj.randomize());
    obj.print();
    // or
    //`uvm_info(get_full_name(), $sformatf("obj = \n%s", obj.sprint()), UVM_LOW);
  endfunction
endclass

module tb_top;
  initial begin
    run_test("my_test");
  end
endmodule

Output:

UVM_INFO @ 0: reporter [RNTST] Running test my_test...
--------------------------------------------
Name          Type          Size  Value     
--------------------------------------------
obj           my_object     -     @349      
  value       integral      32    'h1f135537
  names       string        3     UVM       
  colors      color_type    32    GREEN     
  data        sa(integral)  4     -         
    [0]       integral      8     'h9f      
    [1]       integral      8     'h33      
    [2]       integral      8     'h12      
    [3]       integral      8     'h9c      
  addr        integral      8     'h2f      
  tmp         temp_class    -     @350      
    tmp_addr  integral      8     'h39      
    tmp_data  integral      8     'hbd      
--------------------------------------------

6.4.2 print method with `uvm_object_utils

如果print方法与`uvm_object_utils一起使用,则不会打印类属性。

typedef enum{RED, GREEN, BLUE} color_type;
class my_object extends uvm_object;
  rand int        o_var;
       string     o_name;
  rand color_type colors;
  rand byte       data[4];
  rand bit [7:0]  addr;
  
  `uvm_object_utils(my_object)
  
  function new(string name = "my_object");
    super.new(name);
  endfunction
endclass

class my_test extends uvm_test;
  `uvm_component_utils(my_test)
  my_object obj;
  
  function new(string name = "my_test", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    obj = my_object::type_id::create("obj", this);
    assert(obj.randomize());
    obj.print();
  endfunction
   
  function void end_of_elaboration_phase(uvm_phase phase);
    super.end_of_elaboration_phase(phase);
    uvm_top.print_topology();
  endfunction
endclass

module tb_top;
  initial begin
    run_test("my_test");
  end
endmodule

Output:

UVM_INFO @ 0: reporter [RNTST] Running test my_test...
----------------------------
Name  Type       Size  Value
----------------------------
obj   my_object  -     @1872
----------------------------
UVM_INFO /xcelium20.09/tools//methodology/UVM/CDNS-1.2/sv/src/base/uvm_root.svh(605) @ 0: reporter [UVMTOP] UVM testbench topology:
----------------------------------
Name          Type     Size  Value
----------------------------------
uvm_test_top  my_test  -     @1805
----------------------------------

6.4.3 do_print() method

UVM自动化宏主要涉及许多影响仿真器性能的附加代码。因此,不建议使用。相反,do_print()回调方法是一个用户定义的钩子,由print()或sprint()方法调用。用户必须调用在do_print()实现的printer API来添加要打印的信息。

6.4.3.1 do_print() method example

typedef enum{RED, GREEN, BLUE} color_type;

class temp_class extends uvm_object;
  rand bit [7:0] tmp_addr;
  rand bit [7:0] tmp_data;
  
  function new(string name = "temp_class");
    super.new(name);
  endfunction
  
  `uvm_object_utils(temp_class)
    
  function void do_print(uvm_printer printer);
    super.do_print(printer);
    printer.print_field_int("tmp_addr", tmp_addr, $bits(tmp_addr), UVM_HEX);
    printer.print_field_int("tmp_data", tmp_data, $bits(tmp_data), UVM_HEX);
  endfunction
endclass

class my_object extends uvm_object;
  rand int        value;
       string     names = "UVM";
  rand color_type colors;
  rand byte       data[4];
  rand bit [7:0]  addr;
  rand temp_class tmp;
  
  `uvm_object_utils(my_object)
  
  function new(string name = "my_object");
    super.new(name);
    tmp = new();
  endfunction
  
  function void do_print(uvm_printer printer);
    super.do_print(printer);
    printer.print_field_int("value", value, $bits(value), UVM_HEX);
    printer.print_string("names", names);
    printer.print_string("colors", colors.name);
    foreach(data[i])
      printer.print_field_int($sformatf("data[%0d]", i), data[i], $bits(data[i]), UVM_HEX);
    printer.print_field_int("addr", addr, $bits(addr), UVM_HEX);
    printer.print_object("tmp", tmp);
  endfunction
endclass

class my_test extends uvm_test;
  `uvm_component_utils(my_test)
  my_object obj;
  
  function new(string name = "my_test", uvm_component parent = null);
    super.new(name, parent);
  endfunction
  
  function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    obj = my_object::type_id::create("obj", this);
    assert(obj.randomize());
    obj.print();
  endfunction
endclass

module tb_top;
  initial begin
    run_test("my_test");
  end
endmodule

Output:

UVM_INFO @ 0: reporter [RNTST] Running test my_test...
------------------------------------------
Name          Type        Size  Value     
------------------------------------------
obj           my_object   -     @1876     
  value       integral    32    'ha4a4f87e
  names       string      3     UVM       
  colors      string      3     RED       
  data[0]     integral    8     'hc6      
  data[1]     integral    8     'h4c      
  data[2]     integral    8     'hf       
  data[3]     integral    8     'h89      
  addr        integral    8     'h53      
  tmp         temp_class  -     @1878     
    tmp_addr  integral    8     'hea      
    tmp_data  integral    8     'hdf      
------------------------------------------

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1335812.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

我在 VSCode 插件里接入了 ChatGPT,解决了Bug无法定位的难题

作为一名软件开发者&#xff0c;我时常面临着代码中Bug的定位和解决问题。这个过程往往既费时又充满挑战。然而&#xff0c;最近我在我的VSCode插件中接入了ChatGPT&#xff0c;这个决定彻底改变了我处理Bug的方式。 Bug&#xff1a;开发者的噩梦 在开发过程中&#xff0c;遇…

《Spring Cloud学习笔记:Nacos配置管理 OpenFeign LoadBalancer Getway》

基于Feign的声明式远程调用&#xff08;代码更优雅&#xff09;&#xff0c;用它来去代替我们之前的RestTemplate方式的远程调用 1. Nacos配置管理 Nacos除了可以做注册中心&#xff0c;同样也可以做配置管理来使用。 利用Nacos实现统一配置管理以及配置的热更新&#xff1a;…

86% 的网络攻击是通过加密渠道进行

自 2022 年以来&#xff0c;HTTPS 威胁增长了 24%&#xff0c;凸显了针对加密通道的网络犯罪策略的复杂性。 制造业连续第二年成为最常受到攻击的行业&#xff0c;教育和政府组织的攻击同比增幅最高。此外&#xff0c;包括恶意 Web 内容和恶意软件负载在内的恶意软件继续主导其…

AcWing算法进阶课-1.17.1费用流

算法进阶课整理 CSDN个人主页&#xff1a;更好的阅读体验 原题链接 题目描述 给定一个包含 n n n 个点 m m m 条边的有向图&#xff0c;并给定每条边的容量和费用&#xff0c;边的容量非负。 图中可能存在重边和自环&#xff0c;保证费用不会存在负环。 求从 S S S 到 …

geyser互通服基岩版进不去

Java版需要在服务器安全组开通TCP端口&#xff08;如果有宝塔&#xff0c;也需要开通&#xff09; geyser下载好的安装运行也需要开通端口&#xff0c;但是它是UDP的&#xff08;但是我同时也开启了TCP&#xff0c;可能不需要&#xff1f; Java 版玩家隧道 Java 版玩家使用 T…

Cloudstack多个管理服务器节点

https://docs.cloudstack.apache.org/en/4.18.0.0/adminguide/reliability.html 参考翻译&#xff1a; 代理上支持多个管理服务器 在具有多个管理服务器的Cloudstack环境中&#xff0c;可以根据算法配置代理&#xff0c;将其连接到哪个管理服务器。这对于内部负载均衡器或高可…

渗透测试——1.3计算机网络基础

一、黑客术语 1、肉鸡&#xff1a;被黑客攻击电脑&#xff0c;可以受黑客控制不被发现 2、端口&#xff08;port&#xff09;&#xff1a;数据传输的通道 3、弱口令&#xff1a;强度不高&#xff0c;容易被猜到的口令、密码 4、客户端&#xff1a;请求申请电脑&#xff08;…

web前端项目-七彩夜空烟花【附源码】

web前端项目-七彩动态夜空烟花【附源码】 本项目仅使用了HTML&#xff0c;代码简单&#xff0c;实现效果绚丽&#xff0c;且本项目代码直接运行即可实现&#xff0c;无需图片素材&#xff0c;接下来让我们一起实现一场美丽的烟花秀叭 运行效果&#xff1a;鼠标点击和移动可控制…

Linux服务器流量监控、统计、限制、实时流量,按小时查询、按天数查询、按月数查询、按周数查询、查询TOP10等等各种纬度统计

Linux服务器流量监控、统计、限制、实时流量,按小时查询、按天数查询、按月数查询、按周数查询、查询TOP10等等各种纬度统计。 ServerStatus-V 是一个酷炫高逼格的云探针、云监控、服务器云监控、多服务器探针。使用方便,信息直观。ServerStatus-V 是 ServerStatus 中文版 项…

k8s 组件

k8s: kubernets:8个字母省略&#xff0c;就是k8s. 自动部署&#xff0c;自动扩展和管理容器化的应用程序的一个开源系统。 k8s是负责自动化运维管理多个容器化程序的集群&#xff0c;是一个功能强大的容器编排工具。 以分布式和集群化的方式进行容器管理。 1.20面试版本 …

如何使用 Matplotlib 绘制 3D 圣诞树

系列文章目录 前言 转自&#xff1a;How to draw a 3D Christmas Tree with Matplotlib | by Timur Bakibayev, Ph.D. | Analytics Vidhya | Mediumhttps://medium.com/analytics-vidhya/how-to-draw-a-3d-christmas-tree-with-matplotlib-aabb9bc27864 因为我们把圣诞树安装…

基于深度学习的性别识别算法matlab仿真

目录 1.算法运行效果图预览 2.算法运行软件版本 3.部分核心程序 4.算法理论概述 4.1 GoogLeNet网络结构 4.2. 基于GoogLeNet的性别识别算法 5.算法完整程序工程 1.算法运行效果图预览 2.算法运行软件版本 matlab2022a 3.部分核心程序 ..............................…

Jupyter Notebook的安装及在网页端和VScode中使用教程(详细图文教程)

目录 一、Jupyter Notebook1.1 组成组件1.2 优点1.3 常规用途 二、安装及使用2.1 网页端2.1.1 安装Jupyter Notebook2.1.2 检验是否安装成功2.1.3 启动Jupyter Notebook2.1.4 使用Jupyter Notebook 2.2 VScode中安装及使用2.2.1 安装Jupyter2.2.2 使用Jupyter 三、常用命令3.1 …

Vue核心语法、脚手架与组件化开发、VueRouterVuex、综合案例(待办事项工具)

学习源码可以看我的个人前端学习笔记 (github.com):qdxzw/frontlearningNotes 觉得有帮助的同学&#xff0c;可以点心心支持一下哈 一、Vue核心语法 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name…

约束-练习题

练习1 已经存在数据库test04_emp&#xff0c;两张表emp2和dept2 CREATE DATABASE test04_emp; use test04_emp; CREATE TABLE emp2( id INT, emp_name VARCHAR(15) ); CREATE TABLE dept2( id INT, dept_name VARCHAR(15) );题目: 向表emp2的id列中添加PRIMARY KEY约束向表d…

广州华锐互动VRAR:VR安全模拟驾驶让顾客身临其境感受真实试驾体验

随着科技的不断发展&#xff0c;汽车行业也在不断地进行创新。从电动汽车到自动驾驶&#xff0c;再到如今的虚拟现实技术&#xff0c;汽车行业的未来充满了无限的可能性。而在这些创新中&#xff0c;VR安全模拟驾驶无疑是最具吸引力的一项。通过戴上一副虚拟现实眼镜&#xff0…

计算机毕业设计 基于SpringBoot的高校宣讲会管理系统的设计与实现 Java实战项目 附源码+文档+视频讲解

博主介绍&#xff1a;✌从事软件开发10年之余&#xff0c;专注于Java技术领域、Python人工智能及数据挖掘、小程序项目开发和Android项目开发等。CSDN、掘金、华为云、InfoQ、阿里云等平台优质作者✌ &#x1f345;文末获取源码联系&#x1f345; &#x1f447;&#x1f3fb; 精…

JMeter逻辑控制器之IF控制器

Jmeter控制器之IF控制器 1.应用背景2.介绍3.使用4.添加控制器5.表达式说明6.函数助手调用7.举例 1.应用背景 存在一些使用场景&#xff0c;比如&#xff1a;一个测试场景中&#xff0c;包含多个请求&#xff0c;当上一个请求的结果不符合要求&#xff0c;就不需要执行下一个请求…

听GPT 讲Rust源代码--src/tools(27)

File: rust/src/tools/clippy/clippy_lints/src/methods/suspicious_to_owned.rs 文件rust/src/tools/clippy/clippy_lints/src/methods/suspicious_to_owned.rs的作用是实施Clippy lint规则&#xff0c;检测产生潜在性能问题的字符转换代码&#xff0c;并给出相关建议。 在Rus…

vscode中使用GitHub Copilot Chat

文章目录 一、什么是Github Copilot Chat二、安装使用三、如何使用1. 聊天功能2. 内联功能 一、什么是Github Copilot Chat GitHub Copilot Chat 由 OpenAI 的 GPT-4 大型多模态模型提供支持&#xff0c;能带来更准确的代码建议、解释和指导。GitHub Copilot Chat 的内联功能可…