1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
//*************************************************************************
//
// Copyright 2010-2011 by Wilson Snyder. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// Lesser General Public License Version 3 or the Perl Artistic License
// Version 2.0.
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
//
//*************************************************************************
#include "svdpi.h"
#include "vpi_user.h"
#include <cstdio>
// These require the above. Comment prevents clang-format moving them
#include "TestCheck.h"
#include "TestSimulator.h"
#include "TestVpi.h"
#include <map>
#include <vector>
int errors = 0;
// vpiType -> list of vpiTypes to iterate over
std::map<int32_t, std::vector<int32_t>> iterate_over = [] {
// static decltype(iterate_over) iterate_over = [] {
/* for reused lists */
// vpiInstance is the base class for module, program, interface, etc.
std::vector<int32_t> instance_options = {
vpiNet,
vpiNetArray,
vpiReg,
vpiRegArray,
};
std::vector<int32_t> module_options = {
// vpiModule, // Aldec SEGV on mixed language
// vpiModuleArray, // Aldec SEGV on mixed language
// vpiIODecl, // Don't care about these
vpiMemory, vpiIntegerVar, vpiRealVar,
// vpiRealNet, Vpi extension
vpiStructVar, vpiStructNet, vpiNamedEvent, vpiNamedEventArray, vpiParameter,
// vpiVariables, // parent of vpiReg, vpiRegArray, vpiIntegerVar, etc vars
// vpiSpecParam, // Don't care
// vpiParamAssign, // Aldec SEGV on mixed language
// vpiDefParam, // Don't care
vpiPrimitive, vpiPrimitiveArray,
// vpiContAssign, // Don't care
// vpiProcess, // Don't care
vpiModPath, vpiTchk, vpiAttribute, vpiPort, vpiInternalScope,
// vpiInterface, // Aldec SEGV on mixed language
// vpiInterfaceArray, // Aldec SEGV on mixed language
};
// append base class vpiInstance members
module_options.insert(module_options.begin(), instance_options.begin(),
instance_options.end());
std::vector<int32_t> struct_options = {
vpiNet, vpiReg, vpiRegArray, vpiMemory,
vpiParameter, vpiPrimitive, vpiPrimitiveArray, vpiAttribute,
vpiMember,
};
return decltype(iterate_over){
{vpiModule, module_options},
{vpiInterface, instance_options},
{vpiGenScope, module_options},
{vpiStructVar, struct_options},
{vpiStructNet, struct_options},
{vpiNet,
{
// vpiContAssign, // Driver and load handled separately
// vpiPrimTerm,
// vpiPathTerm,
// vpiTchkTerm,
// vpiDriver,
// vpiLocalDriver,
// vpiLoad,
// vpiLocalLoad,
vpiNetBit,
}},
{vpiNetArray,
{
vpiNet,
}},
{vpiRegArray,
{
vpiReg,
}},
{vpiMemory,
{
vpiMemoryWord,
}},
{vpiPort,
{
vpiPortBit,
}},
{vpiGate,
{
vpiPrimTerm,
vpiTableEntry,
vpiUdpDefn,
}},
{vpiPackage,
{
vpiParameter,
}},
};
}();
void modDump(TestVpiHandle& it, int n) {
if (n > 8) {
printf("going too deep\n");
return;
}
while (const TestVpiHandle& hndl = vpi_scan(it)) {
for (int i = 0; i < n; i++) printf(" ");
const int type = vpi_get(vpiType, hndl);
const char* name = vpi_get_str(vpiName, hndl);
const char* fullname = vpi_get_str(vpiFullName, hndl);
printf("%s (%s) %s ", name, strFromVpiObjType(type), fullname);
if (type == vpiParameter || type == vpiConstType) {
printf(" vpiConstType=%s", strFromVpiConstType(vpi_get(vpiConstType, hndl)));
}
if (type == vpiModule) printf(" vpiDefName=%s", vpi_get_str(vpiDefName, hndl));
printf("\n");
if (iterate_over.find(type) == iterate_over.end()) continue;
for (int type : iterate_over.at(type)) {
TestVpiHandle subIt = vpi_iterate(type, hndl);
if (subIt) {
for (int i = 0; i < n + 1; i++) printf(" ");
printf("%s:\n", strFromVpiObjType(type));
modDump(subIt, n + 1);
}
}
}
it.freed();
}
PLI_INT32 start_of_sim(t_cb_data* data) {
TestVpiHandle it = vpi_iterate(vpiModule, NULL);
TEST_CHECK_NZ(it);
modDump(it, 0);
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};
|