Skip to content

Commit

Permalink
Merge pull request #3868 from Apotell/rtts
Browse files Browse the repository at this point in the history
Introducing ref_typespec, parallel to ref_obj for referencing typespecs
  • Loading branch information
alaindargelas authored Sep 20, 2023
2 parents afe293a + 1c12b4f commit 7cb11f2
Show file tree
Hide file tree
Showing 694 changed files with 893,815 additions and 451,347 deletions.
5 changes: 4 additions & 1 deletion src/Design/ModuleInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ void ModuleInstance::overrideParentChild(ModuleInstance* parent,
p->VpiLineNo(param.second.second);
p->VpiLocalParam(true);
UHDM::int_typespec* ts = s.MakeInt_typespec();
p->Typespec(ts);
UHDM::ref_typespec* rt = s.MakeRef_typespec();
rt->VpiParent(p);
p->Typespec(rt);
rt->Actual_typespec(ts);
UHDM::param_assign* pass = s.MakeParam_assign();
pass->Lhs(p);
UHDM::constant* c = s.MakeConstant();
Expand Down
16 changes: 12 additions & 4 deletions src/Design/Struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <Surelog/Design/Struct.h>

// UHDM
#include <uhdm/ref_typespec.h>
#include <uhdm/struct_typespec.h>
#include <uhdm/typespec_member.h>

Expand All @@ -44,10 +45,17 @@ bool Struct::isNet() const {
const UHDM::struct_typespec* tps = (const UHDM::struct_typespec*)m_typespec;
if (tps->Members()) {
for (UHDM::typespec_member* member : *tps->Members()) {
const UHDM::typespec* tm = member->Typespec();
if (!tm) return false;
UHDM::UHDM_OBJECT_TYPE type = tm->UhdmType();
if (type != UHDM::uhdmlogic_typespec) return false;
if (const UHDM::ref_typespec* rt = member->Typespec()) {
if (const UHDM::typespec* ag = rt->Actual_typespec()) {
if (ag->UhdmType() != UHDM::uhdmlogic_typespec) {
return false;
}
} else {
return false;
}
} else {
return false;
}
}
}
return true;
Expand Down
286 changes: 193 additions & 93 deletions src/DesignCompile/CompileExpression.cpp

Large diffs are not rendered by default.

577 changes: 392 additions & 185 deletions src/DesignCompile/CompileHelper.cpp

Large diffs are not rendered by default.

112 changes: 88 additions & 24 deletions src/DesignCompile/CompileStmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,12 @@ VectorOfany* CompileHelper::compileStmt(DesignComponent* component,
tps->VpiName(fC->SymName(loopVarId));
fC->populateCoreMembers(loopVarId, loopVarId, tps);
tps->VpiParent(ref);
ref->Typespec(tps);
if (ref->Typespec() == nullptr) {
ref_typespec* tpsRef = s.MakeRef_typespec();
tpsRef->VpiParent(ref);
ref->Typespec(tpsRef);
}
ref->Typespec()->Actual_typespec(tps);
component->needLateTypedefBinding(ref);
loop_vars->push_back(ref);
ref->VpiParent(for_each);
Expand Down Expand Up @@ -592,7 +597,14 @@ VectorOfany* CompileHelper::compileStmt(DesignComponent* component,
param_assigns->push_back(param_assign);
param->VpiParent(param_assign);
param->VpiName(fC->SymName(name));
param->Typespec(ts);
if (ts != nullptr) {
if (param->Typespec() == nullptr) {
ref_typespec* tsRef = s.MakeRef_typespec();
tsRef->VpiParent(param);
param->Typespec(tsRef);
}
param->Typespec()->Actual_typespec(ts);
}
param_assign->Lhs(param);
param_assign->Rhs((expr*)compileExpression(
component, fC, value, compileDesign,
Expand Down Expand Up @@ -1138,18 +1150,42 @@ VectorOfany* CompileHelper::compileDataDeclaration(
array_var* arr = s.MakeArray_var();
fC->populateCoreMembers(Var, Var, arr);
array_typespec* tps = s.MakeArray_typespec();
tps->Elem_typespec((typespec*)var->Typespec());
if (ref_typespec* var_ts = var->Typespec()) {
if (typespec* ts = var_ts->Actual_typespec()) {
if (tps->Elem_typespec() == nullptr) {
ref_typespec* varRef = s.MakeRef_typespec();
varRef->VpiParent(tps);
tps->Elem_typespec(varRef);
}
tps->Elem_typespec()->Actual_typespec(ts);
}
}
fC->populateCoreMembers(Var, fC->Sibling(Var), tps);
tps->VpiEndLineNo(unpackedDimensions->back()->VpiEndLineNo());
tps->VpiEndColumnNo(unpackedDimensions->back()->VpiEndColumnNo());
tps->Ranges(unpackedDimensions);
for (auto r : *unpackedDimensions) r->VpiParent(tps);
arr->Typespec(tps);
if (arr->Typespec() == nullptr) {
ref_typespec* tpsRef = s.MakeRef_typespec();
tpsRef->VpiParent(arr);
arr->Typespec(tpsRef);
}
arr->Typespec()->Actual_typespec(tps);
for (range* r : *unpackedDimensions) {
const expr* rrange = r->Right_expr();
if (rrange->VpiValue() == "STRING:associative") {
arr->VpiArrayType(vpiAssocArray);
tps->Index_typespec((typespec*)rrange->Typespec());
if (const ref_typespec* rrange_ts = rrange->Typespec()) {
if (const typespec* ts = rrange_ts->Actual_typespec()) {
if (tps->Index_typespec() == nullptr) {
ref_typespec* indexRef = s.MakeRef_typespec();
indexRef->VpiParent(tps);
tps->Index_typespec(indexRef);
}
tps->Index_typespec()->Actual_typespec(
const_cast<typespec*>(ts));
}
}
} else if (rrange->VpiValue() == "STRING:unsized") {
arr->VpiArrayType(vpiDynamicArray);
} else if (rrange->VpiValue() == "STRING:$") {
Expand Down Expand Up @@ -1554,7 +1590,14 @@ n<> u<142> t<Tf_item_declaration> p<386> c<141> s<384> l<28>
decl->VpiName(name);
ioMap.emplace(name, decl);
fC->populateCoreMembers(nameId, nameId, decl);
decl->Typespec(ts);
if (ts != nullptr) {
if (decl->Typespec() == nullptr) {
ref_typespec* tsRef = s.MakeRef_typespec();
tsRef->VpiParent(decl);
decl->Typespec(tsRef);
}
decl->Typespec()->Actual_typespec(ts);
}
decl->Ranges(ranges);
if (fC->Type(Variable_dimension) ==
VObjectType::paVariable_dimension) {
Expand Down Expand Up @@ -1594,12 +1637,22 @@ n<> u<142> t<Tf_item_declaration> p<386> c<141> s<384> l<28>
var->VpiAutomatic(!is_static);
var->VpiName(name);
vars->push_back(var);
if (ts) {
var->Typespec(ts);
if (ts != nullptr) {
if (var->Typespec() == nullptr) {
ref_typespec* tsRef = s.MakeRef_typespec();
tsRef->VpiParent(var);
var->Typespec(tsRef);
}
var->Typespec()->Actual_typespec(ts);
}
}
} else {
(*itr).second->Typespec(ts);
} else if (ts != nullptr) {
if (itr->second->Typespec() == nullptr) {
ref_typespec* tsRef = s.MakeRef_typespec();
tsRef->VpiParent(itr->second);
itr->second->Typespec(tsRef);
}
itr->second->Typespec()->Actual_typespec(ts);
}
Variable_decl_assignment = fC->Sibling(Variable_decl_assignment);
}
Expand Down Expand Up @@ -1700,7 +1753,16 @@ std::vector<io_decl*>* CompileHelper::compileTfPortList(
}
}
decl->VpiParent(parent);
decl->Typespec(ts);

if (ts != nullptr) {
if (decl->Typespec() == nullptr) {
ref_typespec* tsRef = s.MakeRef_typespec();
tsRef->VpiParent(decl);
decl->Typespec(tsRef);
}
decl->Typespec()->Actual_typespec(ts);
}

const std::string_view name = fC->SymName(tf_param_name);
decl->VpiName(name);

Expand Down Expand Up @@ -2076,25 +2138,24 @@ bool CompileHelper::compileClassConstructorDeclaration(
var->VpiParent(func);
func->Return(var);
UHDM::class_typespec* tps = s.MakeClass_typespec();
var->Typespec(tps);
ref_typespec* tpsRef = s.MakeRef_typespec();
tpsRef->VpiParent(var);
tpsRef->Actual_typespec(tps);
var->Typespec(tpsRef);
NodeId tf_Port_ItemId = fC->Child(Tf_port_list);
NodeId data_type_or_implicitId = fC->Child(tf_Port_ItemId);
NodeId varId = fC->Sibling(data_type_or_implicitId);
if (varId) fC->populateCoreMembers(varId, varId, var);
ClassDefinition* cdef = valuedcomponenti_cast<ClassDefinition*>(component);
if (cdef) {
if (ClassDefinition* cdef =
valuedcomponenti_cast<ClassDefinition*>(component)) {
tps->Class_defn(cdef->getUhdmDefinition());
const std::string_view name = cdef->getUhdmDefinition()->VpiName();
tps->VpiName(name);
} else {
Package* p = valuedcomponenti_cast<Package*>(component);
if (p) {
ClassDefinition* cdef = p->getClassDefinition(className);
if (cdef) {
const std::string_view name = cdef->getUhdmDefinition()->VpiName();
tps->Class_defn(cdef->getUhdmDefinition());
tps->VpiName(name);
}
} else if (Package* p = valuedcomponenti_cast<Package*>(component)) {
if (ClassDefinition* cdef = p->getClassDefinition(className)) {
const std::string_view name = cdef->getUhdmDefinition()->VpiName();
tps->Class_defn(cdef->getUhdmDefinition());
tps->VpiName(name);
}
}

Expand Down Expand Up @@ -2258,7 +2319,10 @@ bool CompileHelper::compileFunction(DesignComponent* component,
var->VpiParent(func);
func->Return(var);
UHDM::class_typespec* tps = s.MakeClass_typespec();
var->Typespec(tps);
ref_typespec* tpsRef = s.MakeRef_typespec();
tpsRef->VpiParent(var);
tpsRef->Actual_typespec(tps);
var->Typespec(tpsRef);
ClassDefinition* cdef = valuedcomponenti_cast<ClassDefinition*>(component);
tps->Class_defn(cdef->getUhdmDefinition());
tps->VpiName(cdef->getUhdmDefinition()->VpiFullName());
Expand Down
Loading

0 comments on commit 7cb11f2

Please sign in to comment.