Simplify code by removing callbacks

This commit is contained in:
gephaistos 2024-09-19 16:55:56 +03:00
parent f4f65a8436
commit c1b8c097df
4 changed files with 24 additions and 39 deletions

View File

@ -0,0 +1,18 @@
#include "verilated.h"
#include "vpi_user.h"
#include VM_PREFIX_INCLUDE
void iterate(vpiHandle root_handle);
int main(int argc, char** argv) {
const std::unique_ptr<VerilatedContext> contextp{new VerilatedContext};
contextp->commandArgs(argc, argv);
const std::unique_ptr<VM_PREFIX> top{new VM_PREFIX{contextp.get(), ""}};
iterate(nullptr);
return 0;
}

View File

@ -14,49 +14,18 @@
#include <string_view>
#include "vpi_user.h"
#include "TestVpi.h"
void iterate(TestVpiHandle root_handle) {
TestVpiHandle module_iter = vpi_iterate(vpiModule, root_handle);
for (TestVpiHandle handle = vpi_scan(module_iter); handle != nullptr;
void iterate(vpiHandle root_handle) {
vpiHandle module_iter = vpi_iterate(vpiModule, root_handle);
for (vpiHandle handle = vpi_scan(module_iter); handle != nullptr;
handle = vpi_scan(module_iter)) {
iterate(handle);
}
TestVpiHandle reg_iter = vpi_iterate(vpiReg, root_handle);
for (TestVpiHandle handle = vpi_scan(reg_iter); handle != nullptr;
vpiHandle reg_iter = vpi_iterate(vpiReg, root_handle);
for (vpiHandle handle = vpi_scan(reg_iter); handle != nullptr;
handle = vpi_scan(reg_iter)) {
const std::string_view name = vpi_get_str(vpiFullName, handle);
std::cout << name << std::endl;
}
}
PLI_INT32 start_of_sim(t_cb_data* data) {
iterate(nullptr);
return 0;
}
//cver, xcelium entry
void vpi_compat_bootstrap(void) {
// We're able to call vpi_main() here on Verilator/Xcelium,
// but Icarus complains (rightfully so)
s_cb_data cb_data;
s_vpi_time vpi_time;
vpi_time.high = 0;
vpi_time.low = 0;
vpi_time.type = vpiSimTime;
cb_data.reason = cbStartOfSimulation;
cb_data.cb_rtn = &start_of_sim;
cb_data.obj = NULL;
cb_data.time = &vpi_time;
cb_data.value = NULL;
cb_data.index = 0;
cb_data.user_data = NULL;
TestVpiHandle callback_h = vpi_register_cb(&cb_data);
}
// Verilator (via t_vpi_main.cpp), and standard LRM entry
void (*vlog_startup_routines[])() = {vpi_compat_bootstrap, 0};

View File

@ -1,3 +1 @@
[0] Model running...
t.sub.clk
*-* All Finished *-*

View File

@ -16,7 +16,7 @@ test.compile(make_top_shell=False,
make_pli=True,
verilator_flags2=[
"--exe --vpi", test.pli_filename,
test.t_dir + "/TestVpiMain.cpp"
test.t_dir + "/TestVpiHierarchyMain.cpp"
],
make_flags=['CPPFLAGS_ADD=-DVL_NO_LEGACY'])