Support vpiBitVar (#7107).

Fixes #7107.
This commit is contained in:
Wilson Snyder 2026-02-20 05:39:38 -05:00
parent ace9a34c10
commit 2d86f1373e
8 changed files with 29 additions and 3 deletions

View File

@ -157,7 +157,8 @@ enum VerilatedVarFlags {
VLVF_DPI_CLAY = (1 << 10), // DPI compatible C standard layout
VLVF_CONTINUOUSLY = (1 << 11), // Is continously assigned
VLVF_FORCEABLE = (1 << 12), // Forceable
VLVF_SIGNED = (1 << 13) // Signed integer
VLVF_SIGNED = (1 << 13), // Signed integer
VLVF_BITVAR = (1 << 14) // Four state bit (vs two state logic)
};
// IEEE 1800-2023 Table 20-6

View File

@ -161,6 +161,7 @@ public:
// DPI compatible C standard layout
bool isDpiCLayout() const { return ((m_vlflags & VLVF_DPI_CLAY) != 0); }
bool isSigned() const { return ((m_vlflags & VLVF_SIGNED) != 0); }
bool isBitVar() const { return ((m_vlflags & VLVF_BITVAR) != 0); }
int udims() const VL_MT_SAFE { return m_unpacked.size(); }
int pdims() const VL_MT_SAFE { return m_packed.size(); }
int dims() const VL_MT_SAFE { return pdims() + udims(); }

View File

@ -421,11 +421,12 @@ public:
return ret;
}
uint32_t type() const override {
uint32_t type = vpiReg;
uint32_t type;
// TODO have V3EmitCSyms.cpp put vpiType directly into constant table
switch (varp()->vltype()) {
case VLVT_REAL: type = vpiRealVar; break;
case VLVT_STRING: type = vpiStringVar; break;
default: break;
default: type = varp()->isBitVar() ? vpiBitVar : vpiReg; break;
}
if (isIndexedDimUnpacked())
return vpiRegArray;

View File

@ -828,6 +828,8 @@ std::vector<std::string> EmitCSyms::getSymCtorStmts() {
stmt += ", ";
stmt += varp->vlEnumDir(); // VLVD_IN etc
if (varp->dtypep()->skipRefp()->isSigned()) stmt += "|VLVF_SIGNED";
if (varp->dtypep()->skipRefp()->basicp()->keyword() == VBasicDTypeKwd::BIT)
stmt += "|VLVF_BITVAR";
stmt += ", ";
stmt += std::to_string(udim);
stmt += ", ";

View File

@ -419,6 +419,21 @@ int _mon_check_var() {
CHECK_RESULT(d, vpiUndefined);
}
// other unsigned types
constexpr struct {
const char* name;
PLI_INT32 exp_type;
} uint_vars[] = {
// uvm_hdl_polling.v requires single bits return vpiBitVar
{"bit1", vpiBitVar},
};
for (const auto& s : uint_vars) {
TestVpiHandle vh101 = VPI_HANDLE(s.name);
CHECK_RESULT_NZ(vh101);
d = vpi_get(vpiType, vh101);
CHECK_RESULT(d, s.exp_type);
}
// other integer types
tmpValue.format = vpiIntVal;
constexpr struct {

View File

@ -54,6 +54,7 @@ extern "C" int mon_check();
integer status;
bit bit1 /*verilator public_flat_rw */;
integer integer1 /*verilator public_flat_rw */;
byte byte1 /*verilator public_flat_rw */;
shortint short1 /*verilator public_flat_rw */;
@ -82,6 +83,7 @@ extern "C" int mon_check();
text = "Verilog Test module";
too_big = "some text";
bit1 = 1;
integer1 = 123;
byte1 = 123;
short1 = 123;

View File

@ -73,6 +73,7 @@ extern "C" int mon_check();
integer status;
/*verilator public_flat_rw_on*/
bit bit1;
integer integer1;
byte byte1;
shortint short1;
@ -99,6 +100,7 @@ extern "C" int mon_check();
text = "Verilog Test module";
too_big = "some text";
bit1 = 1;
integer1 = 123;
byte1 = 123;
short1 = 123;

View File

@ -54,6 +54,7 @@ extern "C" int mon_check();
integer status;
bit bit1;
integer integer1;
byte byte1;
shortint short1;
@ -79,6 +80,7 @@ extern "C" int mon_check();
text = "Verilog Test module";
too_big = "some text";
bit1 = 1;
integer1 = 123;
byte1 = 123;
short1 = 123;