shangzheng的个人空间 https://blog.eetop.cn/188374 [收藏] [复制] [分享] [RSS]

空间首页 动态 记录 日志 相册 主题 分享 留言板 个人资料

日志

summary of <systemveriog_for_verification> (day10)

已有 803 次阅读| 2008-1-30 10:49

Chapter8 Advanced OOP and Guidelines
1Always declare routines inside a class as virtual so that they
can be redefined in an extended class. This applies to all tasks
and functions, except the new function, which is called when
the object is constructed, so there is no way to extend it.
Systemverilog always calls the new function based on the
handle’s type.
2 If your base class constructor has any arguments, the extend constructor must have a constructor and must call the base’s constructor on its first line.
3 OOP rules say that if you have a handle of the base type (Transaction), it can also point to an object of an extended type (BadTr). This is because the handle tr can only reference the variables src, dst, crc, and data, and the routine calc_crc.
So you can send BadTr objects into the driver without changing it.
When the driver calls tr.calc_crc, SystemVerilog looks at the type of
object stored in tr, because the task was declared as virtual. If the object is of
type Transaction, SystemVerilog calls Transaction::calc_crc. If it is
of type BadTr, SystemVerilog calls BadTr::calc_crc.//it's true that i don't need to rewrite my code. but if i want to access the unique variable in the extended class, how shall i do??Maybe you shouldn't access that variable, because it should be hidden.
4

class Generator;
mailbox gen2drv;
Transaction blueprint;
function new(mailbox gen2drv);
this.gen2drv = gen2drv;
endfunction
function build;
blueprint = new;
endfunction
task run;
Transaction tr;
forever begin
assert(blueprint.randomize);
tr = blueprint.copy; // * see below// this is the key point, you copy the father object to the son objects
gen2drv.put(tr); // Send to driver
end
endtask
endclass

// Testbench environment class
class Environment;
Generator gen;
Driver drv;
mailbox gen2drv;
function new;
gen = new(gen2drv);
drv = new(gen2drv);
endfunction
function build;
gen.build;
drv.build;
endfunction
task run;
fork
gen.run;
drv.run;
join_none
endtask
task wrapup;
gen.wrapup;
drv.wrapup;
endtask
endclass

program automatic test;
Environment env;
initial begin
env = new; // Construct the environment
env.build; // Build testbench objects
env.run; // Run the test
env.wrap_up; // Clean up afterwards
end
endprogram

program automatic test;
Environment env;
initial begin
env = new;
env.build; // Construct a blueprint
begin
BadTr bad; // Create a bad transaction
bad = new; // Replace blueprint with
env.drv.tr = bad; // the "bad" one
end
env.run; // Run the test
env.wrap_up; // Clean up afterwards
end
endprogram

Note how all the references to BadTr are in this one
file, so you don’t have to change the Environment or Generator classes


点赞

评论 (0 个评论)

facelist

您需要登录后才可以评论 登录 | 注册

  • 关注TA
  • 加好友
  • 联系TA
  • 0

    周排名
  • 0

    月排名
  • 0

    总排名
  • 0

    关注
  • 1

    粉丝
  • 0

    好友
  • 0

    获赞
  • 2

    评论
  • 139

    访问数
关闭

站长推荐 上一条 /1 下一条

小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-11-16 22:22 , Processed in 0.022633 second(s), 6 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
返回顶部