VPI memory access for packed arrays (#2922)

This commit is contained in:
Todd Strader
2021-05-07 07:17:54 -04:00
committed by GitHub
parent 44fd205e12
commit b2139f65d8
6 changed files with 128 additions and 91 deletions
+1
View File
@@ -935,6 +935,7 @@ public:
const VNumRange& nrange() const { return m.m_nrange; }
int hi() const { return (rangep() ? rangep()->hiConst() : m.m_nrange.hi()); }
int lo() const { return (rangep() ? rangep()->loConst() : m.m_nrange.lo()); }
int elements() const { return (rangep() ? rangep()->elementsConst() : m.m_nrange.elements()); }
int left() const { return littleEndian() ? lo() : hi(); } // How to show a declaration
int right() const { return littleEndian() ? hi() : lo(); }
bool littleEndian() const {
+11 -2
View File
@@ -762,6 +762,7 @@ void EmitCSyms::emitSymImp() {
AstScope* scopep = it->second.m_scopep;
AstVar* varp = it->second.m_varp;
//
int pwidth = 1;
int pdim = 0;
int udim = 0;
string bounds;
@@ -773,6 +774,7 @@ void EmitCSyms::emitSymImp() {
bounds += ",";
bounds += cvtToStr(basicp->lo());
pdim++;
pwidth *= basicp->elements();
}
for (AstNodeDType* dtypep = varp->dtypep(); dtypep;) {
dtypep
@@ -784,6 +786,7 @@ void EmitCSyms::emitSymImp() {
bounds += cvtToStr(adtypep->right());
if (VN_IS(dtypep, PackArrayDType)) {
pdim++;
pwidth *= adtypep->elementsConst();
} else {
udim++;
}
@@ -793,8 +796,14 @@ void EmitCSyms::emitSymImp() {
}
}
}
//
if (udim > 1 && (pdim && udim)) {
// TODO: actually expose packed arrays as vpiRegArray
if (pdim > 1 && udim == 0) {
bounds = ", ";
bounds += cvtToStr(pwidth - 1);
bounds += ",0";
pdim = 1;
}
if (pdim > 1 || udim > 1) {
puts("//UNSUP "); // VerilatedImp can't deal with >2d or packed arrays
}
puts(protect("__Vscope_" + it->second.m_scopeName) + ".varInsert(__Vfinal,");