Ch5 Basic OOP.ppt_第1頁(yè)
Ch5 Basic OOP.ppt_第2頁(yè)
Ch5 Basic OOP.ppt_第3頁(yè)
Ch5 Basic OOP.ppt_第4頁(yè)
Ch5 Basic OOP.ppt_第5頁(yè)
已閱讀5頁(yè),還剩18頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、Ch5,Basic OOP,OOB Terminology,Class a basic building block containing routines and variables. The analogue in Verilog is a module. Object an instance of a class. In Verilog, you need to instantiate a module to use it. Handle a pointer to an object. In Verilog, you use the name of an instance when yo

2、u refer to signals and methods from outside the module. An OOP handle is like the address of the object, but is stored in a pointer that can only refer to one type. Property a variable that holds data. In Verilog, this is a signal such as a register or wire. Method the procedural code that manipulat

3、es variables, contained in tasks and functions. Verilog modules have tasks and functions plus initial and always blocks. Prototype the header of a routine that shows the name, type, and argument list. The body of the routine contains the executable code.,Defining A Simple Class,class Transaction; lo

4、gic 31:0 addr; logic kind; logic 63:0 data; function new(logic 31:0 addr); this.addr = addr; this.kind = x; this.data = x; endfunction function void display(); $display(“addr=%h, kind=%b, data=%h”, addr, kind, data); endfunction endclass,You can define a class in a program, module, package, or outsi

5、de of any of these.,Defining Methods Outside,class Transaction; logic 31:0 addr; logic kind; logic 63:0 data; extern function new(); extern function void display(); endclass,function Transaction:new(logic 31:0 addr); this.addr = addr; this.kind = x; this.data = x; endfunction: new function void Tran

6、saction:display(); $display(“addr=%h, kind=%b, data=%h”, addr, kind, data); endfunction: display,Method prototype must match the one in the body.,Using One Class Inside Another,/normal order class Statistics; . endclass class Transaction; Statistics stats; . endclass,/use a undefined class typedef c

7、lass Statistics; class Transaction; Statistics stats; . endclass class Statistics; . endclass,Using A Simple Class,Transaction tr_gen; Transaction tr_drv; initial begin tr_gen = new(32b7788); tr_drv = new(32b8877); tr_gen.kind = 1b1; tr_drv.data = b0; tr_gen.display(); tr_drv.display(); end,Classes

8、can be used in programs and modules.,Handle and ObjectConstructor and Deallocation,Transaction tr_gen, tr_drv; tr_gen = new; tr_drv = tr_gen; tr_gen = new; tr_gen = null;,Stack,tr_gen,tr_drv,Static Varibles,class Transaction; static int count = 0; int id; function new(); id = count+; / Set ID, bump

9、count endfunction endclass Transaction t1, t2; initial begin t1 = new(); / 1st instance, id=0, count=1 t2 = new(); / 2nd instance, id=1, count=2 $display(Second id=%d, count=%d, t2.id, t2.count); end,Stack,heap,count,Passing Objects to Methods,class Transaction; logic 31:0 addr; function new(logic 3

10、1:0 addr); this.addr = addr; endfunction function void display(); $display(addr); endfunction endclass,program testgen; task transmit(Transaction t); t.addr = t.addr 2; endtask Transaction t; initial begin t = new(32h0033); $display(before transmit); t.display(); transmit(t); $display(after transmit

11、); t.display(); end endprogram,There is a mistake in book “SystemVerilog for Verification, 2nd Edition” on page 147.,Modifying a Handle in a Task,class Transaction; logic 31:0 addr; function new(logic 31:0 addr); this.addr = addr; endfunction function void display(); $display(addr); endfunction endc

12、lass,program testgen; task transmit(Transaction t); t = new(32h3300); t.addr = t.addr 2; endtask Transaction t; initial begin t = new(32h0033); $display(before transmit); t.display(); transmit(t); $display(after transmit); t.display(); end endprogram,Modifying a Handle in a Task,class Transaction; l

13、ogic 31:0 addr; function new(logic 31:0 addr); this.addr = addr; endfunction function void display(); $display(addr); endfunction endclass,program testgen; task transmit(ref Transaction t); t = new(32h3300); t.addr = t.addr 2; endtask Transaction t; initial begin t = new(32h0033); $display(before tr

14、ansmit); t.display(); transmit(t); $display(after transmit); t.display(); end endprogram,Modifying Objects in Flight,/ buggy generator task generator_bad(int n); Transaction t; t = new(); repeat (n) begin t.addr = $random(); transmit(t); end endtask,/ good generator task generator_bad(int n); Transa

15、ction t; repeat (n) begin t = new(); t.addr = $random(); transmit(t); end endtask,Arrays of Handles,class Transaction; logic 31:0 addr; function new(logic 31:0 addr = x); this.addr = addr; endfunction function void display(); $display(addr = %h, addr); endfunction endclass,program testgen; Transacti

16、on t; initial begin t = new5; foreach(ti) begin ti = new(i); ti.display(); end end endprogram,Copying Objects,class Transaction; logic 31:0 addr; function new(logic 31:0 addr); this.addr = addr; endfunction function void display(); $display(addr); endfunction endclass,program testgen; Transaction t1

17、, t2; initial begin t1 = new(32h0033); t2 = new(32h0044); t2 = t1; t1.display(); t2.display(); end endprogram,What happened?,Copying Objects,The 1st situation.,Stack,t1,t2,t2 = t1;,Copying Objects,The 2st situation.,Stack,t1,t2,Copying a simple class with new, t2 = new t1;,Copying Objects,The 3st si

18、tuation,Stack,t1,t2,using ref before arguments in task/function,Copying Objects,Copying a complex class with new,class Statistics; int id; function new(); id = 0; endfunction endclass class Transaction; logic 31:0 addr; Statistics stat; function new(logic 31:0 addr); this.addr = addr; this.stat = ne

19、w; endfunction endclass,program testgen; Transaction t1, t2; initial begin t1 = new(32h0003); t2 = new(32h0004); t2 = new t1; t2.stat.id = -1; $display(t1.stat.id); $display(t2.stat.addr); end endprogram,Copying Objects,Copying a complex class with new,Stack,t1,t2,stat,stat,addr,addr,Write Your Own Simple Copy,class Transaction; logic 31:0 addr; function new(logic 31:0 addr = x); this.addr = addr; endfunction function Transaction copy(); Transaction dst = new; dst.addr = this.addr; return d

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論