Aldec Verification Seminar Series May 12, 2007 Aldec Verification Seminar Series May 12, 2007 Object...

10
Aldec Verification Seminar Seri May 12, 20 Object Oriented Programming Demystified Mike Mintz Co-author Hardware Verification with C++, Hardware Verification with SystemVerilog [email protected]

description

mfm, OOP Lessons Learned, October Common Currency “There is nothing new under the sun.”

Transcript of Aldec Verification Seminar Series May 12, 2007 Aldec Verification Seminar Series May 12, 2007 Object...

Page 1: Aldec Verification Seminar Series May 12, 2007 Aldec Verification Seminar Series May 12, 2007 Object Oriented Programming Demystified Mike Mintz Co-author.

Aldec Verification Seminar SeriesMay 12, 2007

Object Oriented ProgrammingDemystified

Mike MintzCo-authorHardware Verification with C++,Hardware Verification with [email protected]

Page 2: Aldec Verification Seminar Series May 12, 2007 Aldec Verification Seminar Series May 12, 2007 Object Oriented Programming Demystified Mike Mintz Co-author.

mfm, www.trusster.com, OOP Lessons Learned, October 20062

Overview

• Common Currency• Data Abstraction• Virtual Functions• Base Classes• Q&A

Page 3: Aldec Verification Seminar Series May 12, 2007 Aldec Verification Seminar Series May 12, 2007 Object Oriented Programming Demystified Mike Mintz Co-author.

mfm, www.trusster.com, OOP Lessons Learned, October 20063

Common Currency

generator checker

monitordriver

DUT

“There is nothing new under the sun.”

Page 4: Aldec Verification Seminar Series May 12, 2007 Aldec Verification Seminar Series May 12, 2007 Object Oriented Programming Demystified Mike Mintz Co-author.

mfm, www.trusster.com, OOP Lessons Learned, October 20064

Data Abstraction

• Procedural code has separate data structures and functions

• OOP moves the functions into the data structure• Every possible function for that structure is now

in one place.• This works well for a driver.

Page 5: Aldec Verification Seminar Series May 12, 2007 Aldec Verification Seminar Series May 12, 2007 Object Oriented Programming Demystified Mike Mintz Co-author.

mfm, www.trusster.com, OOP Lessons Learned, October 20065

Data Abstraction –Code details

void send_packet (int type, int* data, int length);

struct usb_driver {

void init ();

void enumerate ();

void usb_send_packet (usb_driver * d, int type, int* data, int length);

struct usb_driver {wire d_plus, d_minus;}

void usb_init (usb_driver * d);

void usb_enumerate (usb_driver * d); };

Procedural: Data Abstraction:

wire d_plus, d_minus;

begin usb_driver driver;usb_init (&driver);usb_enumerate (&driver);usb_send (&driver, 0, {0,12}, 2);

end

begin usb_driver driver;driver. init ();driver.enumerate ();driver.send (0, {0,12}, 2);

end

Page 6: Aldec Verification Seminar Series May 12, 2007 Aldec Verification Seminar Series May 12, 2007 Object Oriented Programming Demystified Mike Mintz Co-author.

mfm, www.trusster.com, OOP Lessons Learned, October 20066

Virtual Functions• Is a run-time function call• Separates “when to do” from “what to do” • Great for separating concerns (and increasing

portability)• This works well for a monitor.

Page 7: Aldec Verification Seminar Series May 12, 2007 Aldec Verification Seminar Series May 12, 2007 Object Oriented Programming Demystified Mike Mintz Co-author.

mfm, www.trusster.com, OOP Lessons Learned, October 20067

Virtual Functions

virtual void packet_completed (int length, int* data) =0;

struct usb_monitor {

void start_monitor_thread ();

};

Monitor class: Derived for printing:virtual void packet_completed (int length, int* data) { for (int i(0); I < length; ++i) { printf (“Packet [%d] : 0x%x\n”, I, data[i]); }}

struct usb_monitor_printer : public usb_monitor {

};

wire d_plus, d_minus;

Derived for Checker:virtual void packet_completed (int length, int* data) { checker_->ckeck (length, data);}

struct usb_monitor_checker : public usb_monitor {

};

Derived for channel:

virtual void packet_completed (int length, int* data) { channel_->put (data_packet (length, data));}

struct usb_monitor_agent : public usb_monitor {

};

Page 8: Aldec Verification Seminar Series May 12, 2007 Aldec Verification Seminar Series May 12, 2007 Object Oriented Programming Demystified Mike Mintz Co-author.

mfm, www.trusster.com, OOP Lessons Learned, October 20068

Base Classes• A class with one or more virtual methods• Separates “what to do” from “who does it” • Sets up a framework or interface• This works well for a test irritator.

Page 9: Aldec Verification Seminar Series May 12, 2007 Aldec Verification Seminar Series May 12, 2007 Object Oriented Programming Demystified Mike Mintz Co-author.

mfm, www.trusster.com, OOP Lessons Learned, October 20069

Base ClassesCode Details

virtual void wait_for_completion () =0;

struct irritator {

virtual void start () =0;

};

Irritator class: Derived for usb:struct usb_irritator : public irritator {

};

virtual void out_of_reset () =0;

Derived for pcie:struct pcie_irritatpr : public irritator {

};

Derived for ethernet:struct ethernet_irritator : public irritator {

};

virtual void start () =0;

virtual void start ();

virtual void out_of_reset ();

virtual void start () ;

virtual void wait_for_completion ();

virtual void start ();

virtual void out_of_reset ();

virtual void start () ;

virtual void wait_for_completion ();

virtual void start ();

virtual void out_of_reset ();

virtual void start () ;

virtual void wait_for_completion ();

Page 10: Aldec Verification Seminar Series May 12, 2007 Aldec Verification Seminar Series May 12, 2007 Object Oriented Programming Demystified Mike Mintz Co-author.

mfm, www.trusster.com, OOP Lessons Learned, October 200610

Summary

• OOP is a little bit syntax and a large amount of attitude

• Learning OOP is gradual process, making mistakes is in integral part

• Its not really that different, just different packaging

• See www.trusster.com for forums, articles, etc.