Polymorphism
Problem Description
You are given a partial protocol checker hierarchy with three classes: Basedriver, Ahbdriver, and Apbdriver. Your task is to implement get_proto() in all three classes so that virtual dispatch works correctly through both derived and base handles.
The classes to implement:
Basedriver— declareget_proto()as a virtual function returning"BASE"Ahbdriver extends Basedriver— overrideget_proto()to return"AHB"Apbdriver extends Basedriver— overrideget_proto()to return"APB"
Inside the initial block, we are calling the function check_str().
When we call below line inisde initial begin, it shoud return me AHB handle and not base handle
check_str("TC3 Ahbdriver via Basedriver handle → AHB (virtual dispatch)",
base_h.get_proto(), "AHB");When we call below line inisde initial begin, it shoud return me APB handle and not base handle
check_str("TC4 Apbdriver via Basedriver handle → APB (virtual dispatch)",
base_h.get_proto(), "APB");SystemVerilog
Code Editor Access
Log in to write, run and submit your solution to this interview question. It's free.
