mirror of
https://github.com/verilator/verilator.git
synced 2025-01-01 04:07:34 +00:00
examples: Use unique_ptr
This commit is contained in:
parent
5b280c1911
commit
7eeb930c72
@ -5,6 +5,9 @@
|
|||||||
// SPDX-License-Identifier: CC0-1.0
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
//======================================================================
|
//======================================================================
|
||||||
|
|
||||||
|
// For std::unique_ptr
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
// Include common routines
|
// Include common routines
|
||||||
#include <verilated.h>
|
#include <verilated.h>
|
||||||
|
|
||||||
@ -43,7 +46,8 @@ int main(int argc, char** argv, char** env) {
|
|||||||
Verilated::mkdir("logs");
|
Verilated::mkdir("logs");
|
||||||
|
|
||||||
// Construct the Verilated model, from Vtop.h generated from Verilating "top.v"
|
// Construct the Verilated model, from Vtop.h generated from Verilating "top.v"
|
||||||
Vtop* top = new Vtop; // Or use a const unique_ptr, or the VL_UNIQUE_PTR wrapper
|
// Using unique_ptr is similar to "Vtop* top = new Vtop" then deleting at end
|
||||||
|
const std::unique_ptr<Vtop> top{new Vtop};
|
||||||
|
|
||||||
// Set some inputs
|
// Set some inputs
|
||||||
top->reset_l = !0;
|
top->reset_l = !0;
|
||||||
@ -97,10 +101,6 @@ int main(int argc, char** argv, char** env) {
|
|||||||
VerilatedCov::write("logs/coverage.dat");
|
VerilatedCov::write("logs/coverage.dat");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Destroy model
|
|
||||||
delete top;
|
|
||||||
top = nullptr;
|
|
||||||
|
|
||||||
// Fin
|
// Fin
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,9 @@
|
|||||||
// SPDX-License-Identifier: CC0-1.0
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
//======================================================================
|
//======================================================================
|
||||||
|
|
||||||
|
// For std::unique_ptr
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
// SystemC global header
|
// SystemC global header
|
||||||
#include <systemc.h>
|
#include <systemc.h>
|
||||||
|
|
||||||
@ -45,8 +48,8 @@ int sc_main(int argc, char* argv[]) {
|
|||||||
ios::sync_with_stdio();
|
ios::sync_with_stdio();
|
||||||
|
|
||||||
// Define clocks
|
// Define clocks
|
||||||
sc_clock clk("clk", 10, SC_NS, 0.5, 3, SC_NS, true);
|
sc_clock clk{"clk", 10, SC_NS, 0.5, 3, SC_NS, true};
|
||||||
sc_clock fastclk("fastclk", 2, SC_NS, 0.5, 2, SC_NS, true);
|
sc_clock fastclk{"fastclk", 2, SC_NS, 0.5, 2, SC_NS, true};
|
||||||
|
|
||||||
// Define interconnect
|
// Define interconnect
|
||||||
sc_signal<bool> reset_l;
|
sc_signal<bool> reset_l;
|
||||||
@ -58,7 +61,9 @@ int sc_main(int argc, char* argv[]) {
|
|||||||
sc_signal<sc_bv<70> > out_wide;
|
sc_signal<sc_bv<70> > out_wide;
|
||||||
|
|
||||||
// Construct the Verilated model, from inside Vtop.h
|
// Construct the Verilated model, from inside Vtop.h
|
||||||
Vtop* top = new Vtop("top");
|
// Using unique_ptr is similar to "Vtop* top = new Vtop" then deleting at end
|
||||||
|
const std::unique_ptr<Vtop> top{new Vtop{"top"}};
|
||||||
|
|
||||||
// Attach signals to the model
|
// Attach signals to the model
|
||||||
top->clk(clk);
|
top->clk(clk);
|
||||||
top->fastclk(fastclk);
|
top->fastclk(fastclk);
|
||||||
@ -129,10 +134,6 @@ int sc_main(int argc, char* argv[]) {
|
|||||||
VerilatedCov::write("logs/coverage.dat");
|
VerilatedCov::write("logs/coverage.dat");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Destroy model
|
|
||||||
delete top;
|
|
||||||
top = nullptr;
|
|
||||||
|
|
||||||
// Fin
|
// Fin
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user