Skip to content

Commit d667e76

Browse files
committed
Model class hierarchy change for select nodes
bit_select, and other select classes use the vpiParent pointer (as refobj) to provide parent and actual_group access. bit_select.vpiParent.vpiParent is the "true" parent of the bit_select and bit_select.vpiParent.actual_group is access to the actual. However, vpiParent edges in the graph are weak references and ignored for all traversals (including VpiListener, UhdmListener, and vpi_visitor). Tail of parent edges are missing in the UHDM output since the nodes are ignored. The traversal mode also generate unexpected results during runtime because of the ignored edges. Changing the hierarchy so that ref_obj works as a base (intermediate class in the class hierarchy, yet instantiable) and other select classes (including bit_select, indexed_part_select, part_select, and var_select) are subclasses of ref_obj. This gives access to ref_obj.actual_group and ref.vpiParent can be used for the usual parenting purposes. * Updated class file generation logic to support generating class files for intermediate nodes in the class hierarchy. * Updated vpi_visitor, ExprEval, and clone_tree logic to compensate for the model hierarchy change.
1 parent 9288dc8 commit d667e76

File tree

6 files changed

+84
-126
lines changed

6 files changed

+84
-126
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
55
# Version changes whenever some new features accumulated, or the
66
# grammar or the cache format changes to make sure caches
77
# are invalidated.
8-
project(SURELOG VERSION 1.59)
8+
project(SURELOG VERSION 1.60)
99

1010
# Detect build type, fallback to release and throw a warning if use didn't
1111
# specify any

include/Surelog/DesignCompile/CompileHelper.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ class CompileHelper final {
154154
ValuedComponentI* instance);
155155

156156
UHDM::any* compileTfCall(DesignComponent* component, const FileContent* fC,
157-
NodeId Tf_call_stmt, CompileDesign* compileDesign);
157+
NodeId Tf_call_stmt, CompileDesign* compileDesign,
158+
UHDM::any* pexpr);
158159

159160
UHDM::VectorOfany* compileTfCallArguments(
160161
DesignComponent* component, const FileContent* fC, NodeId Arg_list_node,

src/DesignCompile/CompileExpression.cpp

Lines changed: 56 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,7 @@ UHDM::any *CompileHelper::compileSelectExpression(
11011101
VectorOfexpr *exprs = s.MakeExprVec();
11021102
var_select->Exprs(exprs);
11031103
var_select->VpiName(name);
1104+
var_select->VpiParent(pexpr);
11041105
result = var_select;
11051106
}
11061107
NodeId lastBitExp;
@@ -1132,27 +1133,26 @@ UHDM::any *CompileHelper::compileSelectExpression(
11321133

11331134
if (result) {
11341135
UHDM::var_select *var_select = (UHDM::var_select *)result;
1136+
var_select->VpiParent(pexpr);
11351137
VectorOfexpr *exprs = var_select->Exprs();
11361138
exprs->push_back(sel);
1137-
if (sel->VpiParent() == nullptr) sel->VpiParent(var_select);
1139+
sel->VpiParent(var_select);
11381140
} else if (fC->Child(Bit_select) && fC->Sibling(Bit_select)) {
11391141
UHDM::var_select *var_select = s.MakeVar_select();
11401142
VectorOfexpr *exprs = s.MakeExprVec();
11411143
var_select->Exprs(exprs);
11421144
var_select->VpiName(name);
1145+
var_select->VpiParent(pexpr);
1146+
sel->VpiParent(var_select);
11431147
exprs->push_back(sel);
11441148
result = var_select;
1145-
if (sel->VpiParent() == nullptr) sel->VpiParent(var_select);
11461149
} else {
11471150
bit_select *bit_select = s.MakeBit_select();
11481151
bit_select->VpiName(name);
11491152
bit_select->VpiIndex(sel);
1153+
bit_select->VpiParent(pexpr);
1154+
sel->VpiParent(bit_select);
11501155
result = bit_select;
1151-
if (sel->VpiParent() == nullptr) sel->VpiParent(bit_select);
1152-
ref_obj *ref = s.MakeRef_obj();
1153-
bit_select->VpiParent(ref);
1154-
ref->VpiName(name);
1155-
ref->VpiParent(pexpr);
11561156
}
11571157
lastBitExp = bitexp;
11581158
if (advanceBitSelect) Bit_select = bitexp;
@@ -1176,6 +1176,7 @@ UHDM::any *CompileHelper::compileSelectExpression(
11761176
VectorOfexpr *exprs = s.MakeExprVec();
11771177
var_select->Exprs(exprs);
11781178
var_select->VpiName(name);
1179+
var_select->VpiParent(pexpr);
11791180
exprs->push_back(sel);
11801181
sel->VpiParent(var_select);
11811182
} else {
@@ -1218,52 +1219,18 @@ UHDM::any *CompileHelper::compileSelectExpression(
12181219
compileExpression(component, fC, Bit_select, compileDesign,
12191220
reduce, pexpr, instance, muteErrors);
12201221
if (sel) {
1222+
hname.append(".")
1223+
.append(sel->VpiName())
1224+
.append(decompileHelper(sel));
12211225
if (sel->UhdmType() == uhdmhier_path) {
12221226
hier_path *p = (hier_path *)sel;
12231227
for (auto el : *p->Path_elems()) {
1228+
el->VpiParent(path);
12241229
elems->push_back(el);
1225-
std::string n(el->VpiName());
1226-
if (el->UhdmType() == uhdmbit_select) {
1227-
bit_select *bs = (bit_select *)el;
1228-
const expr *index = bs->VpiIndex();
1229-
std::string_view ind = index->VpiDecompile();
1230-
if (ind.empty()) ind = index->VpiName();
1231-
n.append("[").append(ind).append("]");
1232-
hname += "." + n;
1233-
ref_obj *r = nullptr;
1234-
if ((bs->VpiParent() != nullptr) &&
1235-
(bs->VpiParent()->UhdmType() == uhdmref_obj)) {
1236-
r = (ref_obj *)bs->VpiParent();
1237-
} else {
1238-
r = s.MakeRef_obj();
1239-
bs->VpiParent(r);
1240-
}
1241-
r->VpiName(hname);
1242-
r->VpiParent(path);
1243-
} else {
1244-
hname += "." + n;
1245-
el->VpiParent(path);
1246-
}
12471230
}
12481231
break;
12491232
} else {
1250-
hname.append(".")
1251-
.append(sel->VpiName())
1252-
.append(decompileHelper(sel));
1253-
if (sel->UhdmType() == uhdmbit_select) {
1254-
ref_obj *r = nullptr;
1255-
if ((sel->VpiParent() != nullptr) &&
1256-
(sel->VpiParent()->UhdmType() == uhdmref_obj)) {
1257-
r = (ref_obj *)sel->VpiParent();
1258-
} else {
1259-
r = s.MakeRef_obj();
1260-
sel->VpiParent(r);
1261-
}
1262-
r->VpiName(hname);
1263-
r->VpiParent(path);
1264-
} else {
1265-
sel->VpiParent(path);
1266-
}
1233+
sel->VpiParent(path);
12671234
elems->push_back(sel);
12681235
}
12691236
}
@@ -1972,7 +1939,7 @@ UHDM::any *CompileHelper::compileExpression(
19721939
operation->VpiParent(pexpr);
19731940
operation->Attributes(attributes);
19741941
if (opL) {
1975-
setParentNoOverride(opL, operation);
1942+
opL->VpiParent(operation);
19761943
operands->push_back(opL);
19771944
}
19781945
if (vopType == 0) {
@@ -2043,7 +2010,7 @@ UHDM::any *CompileHelper::compileExpression(
20432010
compileExpression(component, fC, rval, compileDesign, reduce,
20442011
operation, instance, muteErrors);
20452012
if (opR) {
2046-
setParentNoOverride(opR, operation);
2013+
opR->VpiParent(operation);
20472014
operands->push_back(opR);
20482015
}
20492016
if (opType == VObjectType::slQmark ||
@@ -3674,54 +3641,43 @@ UHDM::any *CompileHelper::compilePartSelectRange(
36743641
UHDM::any *result = nullptr;
36753642
NodeId Constant_expression = fC->Child(Constant_range);
36763643
if (fC->Type(Constant_range) == VObjectType::slConstant_range) {
3677-
UHDM::expr *lexp =
3678-
(expr *)compileExpression(component, fC, Constant_expression,
3679-
compileDesign, Reduce::No, pexpr, instance);
3644+
UHDM::part_select *part_select = s.MakePart_select();
3645+
UHDM::expr *lexp = (expr *)compileExpression(
3646+
component, fC, Constant_expression, compileDesign, Reduce::No,
3647+
part_select, instance);
36803648
UHDM::expr *rexp = (expr *)compileExpression(
36813649
component, fC, fC->Sibling(Constant_expression), compileDesign,
3682-
Reduce::No, pexpr, instance);
3683-
UHDM::part_select *part_select = s.MakePart_select();
3650+
Reduce::No, part_select, instance);
36843651
part_select->Left_range(lexp);
36853652
part_select->Right_range(rexp);
3686-
if (name == "CREATE_UNNAMED_PARENT") {
3687-
UHDM::ref_obj *ref = s.MakeRef_obj();
3688-
part_select->VpiParent(ref);
3689-
} else if (!name.empty()) {
3690-
UHDM::ref_obj *ref = s.MakeRef_obj();
3691-
ref->VpiName(name);
3692-
ref->VpiDefName(name);
3693-
ref->VpiParent(pexpr);
3694-
part_select->VpiParent(ref);
3653+
if (!name.empty() && (name != "CREATE_UNNAMED_PARENT")) {
3654+
part_select->VpiName(name);
3655+
part_select->VpiDefName(name);
36953656
}
3657+
part_select->VpiParent(pexpr);
36963658
part_select->VpiConstantSelect(true);
36973659
result = part_select;
36983660
} else {
36993661
// constant_indexed_range
3662+
UHDM::indexed_part_select *part_select = s.MakeIndexed_part_select();
37003663
UHDM::expr *lexp = (expr *)compileExpression(
3701-
component, fC, Constant_expression, compileDesign, reduce, pexpr,
3664+
component, fC, Constant_expression, compileDesign, reduce, part_select,
37023665
instance, muteErrors);
37033666
NodeId op = fC->Sibling(Constant_expression);
37043667
UHDM::expr *rexp =
37053668
(expr *)compileExpression(component, fC, fC->Sibling(op), compileDesign,
3706-
reduce, pexpr, instance, muteErrors);
3707-
3708-
UHDM::indexed_part_select *part_select = s.MakeIndexed_part_select();
3669+
reduce, part_select, instance, muteErrors);
37093670
part_select->Base_expr(lexp);
37103671
part_select->Width_expr(rexp);
37113672
if (fC->Type(op) == VObjectType::slIncPartSelectOp)
37123673
part_select->VpiIndexedPartSelectType(vpiPosIndexed);
37133674
else
37143675
part_select->VpiIndexedPartSelectType(vpiNegIndexed);
3715-
if (name == "CREATE_UNNAMED_PARENT") {
3716-
UHDM::ref_obj *ref = s.MakeRef_obj();
3717-
part_select->VpiParent(ref);
3718-
} else if (!name.empty()) {
3719-
UHDM::ref_obj *ref = s.MakeRef_obj();
3720-
ref->VpiName(name);
3721-
ref->VpiDefName(name);
3722-
ref->VpiParent(pexpr);
3723-
part_select->VpiParent(ref);
3676+
if (!name.empty() && (name != "CREATE_UNNAMED_PARENT")) {
3677+
part_select->VpiName(name);
3678+
part_select->VpiDefName(name);
37243679
}
3680+
part_select->VpiParent(pexpr);
37253681
part_select->VpiConstantSelect(true);
37263682
result = part_select;
37273683

@@ -4187,6 +4143,7 @@ UHDM::any *CompileHelper::compileBits(
41874143
} else if (sizeMode) {
41884144
UHDM::sys_func_call *sys = s.MakeSys_func_call();
41894145
sys->VpiName("$size");
4146+
sys->VpiParent(pexpr);
41904147
VectorOfany *arguments =
41914148
compileTfCallArguments(component, fC, List_of_arguments, compileDesign,
41924149
reduce, sys, instance, muteErrors);
@@ -4195,6 +4152,7 @@ UHDM::any *CompileHelper::compileBits(
41954152
} else {
41964153
UHDM::sys_func_call *sys = s.MakeSys_func_call();
41974154
sys->VpiName("$bits");
4155+
sys->VpiParent(pexpr);
41984156
VectorOfany *arguments =
41994157
compileTfCallArguments(component, fC, List_of_arguments, compileDesign,
42004158
reduce, sys, instance, muteErrors);
@@ -4433,6 +4391,7 @@ UHDM::any *CompileHelper::compileClog2(
44334391
} else {
44344392
UHDM::sys_func_call *sys = s.MakeSys_func_call();
44354393
sys->VpiName("$clog2");
4394+
sys->VpiParent(pexpr);
44364395
VectorOfany *arguments =
44374396
compileTfCallArguments(component, fC, List_of_arguments, compileDesign,
44384397
reduce, sys, instance, muteErrors);
@@ -4497,14 +4456,15 @@ UHDM::any *CompileHelper::compileComplexFuncCall(
44974456
} else if (fC->Type(nameId) == VObjectType::slConstant_expression) {
44984457
NodeId Constant_expresion = fC->Child(nameId);
44994458
if (Constant_expresion) {
4500-
name += "[";
4459+
bit_select *sel = s.MakeBit_select();
45014460
expr *select = (expr *)compileExpression(
4502-
component, fC, Constant_expresion, compileDesign, reduce, pexpr,
4461+
component, fC, Constant_expresion, compileDesign, reduce, sel,
45034462
instance, muteErrors);
4504-
name += select->VpiDecompile();
4505-
name += "]";
4506-
bit_select *sel = s.MakeBit_select();
4463+
std::string bsname = decompileHelper(select);
4464+
name.append("[").append(bsname).append("]");
4465+
sel->VpiName(bsname);
45074466
sel->VpiIndex(select);
4467+
sel->VpiParent(path);
45084468
elems->push_back(sel);
45094469
}
45104470
} else {
@@ -4513,6 +4473,7 @@ UHDM::any *CompileHelper::compileComplexFuncCall(
45134473
nameId = fC->Sibling(nameId);
45144474
}
45154475
path->VpiName(name);
4476+
path->VpiParent(pexpr);
45164477
result = path;
45174478
} else if (fC->Type(name) == VObjectType::slDollar_keyword) {
45184479
NodeId Dollar_keyword = name;
@@ -4539,6 +4500,7 @@ UHDM::any *CompileHelper::compileComplexFuncCall(
45394500
NodeId List_of_arguments = fC->Sibling(nameId);
45404501
UHDM::sys_func_call *sys = s.MakeSys_func_call();
45414502
sys->VpiName(StrCat("$", name));
4503+
sys->VpiParent(pexpr);
45424504
VectorOfany *arguments = compileTfCallArguments(
45434505
component, fC, List_of_arguments, compileDesign, reduce, sys,
45444506
instance, muteErrors);
@@ -4718,15 +4680,15 @@ UHDM::any *CompileHelper::compileComplexFuncCall(
47184680
ref->VpiName(StrCat(packagename, "::", functionname));
47194681
ref->VpiFullName(StrCat(packagename, "::", functionname));
47204682
ref->Actual_group(param);
4721-
ref->VpiParent(pexpr);
4683+
ref->VpiParent(path);
47224684
fC->populateCoreMembers(name, name, ref);
47234685
elems->push_back(ref);
47244686
while (List_of_arguments) {
47254687
if ((fC->Type(List_of_arguments) ==
47264688
VObjectType::slStringConst)) {
47274689
ref_obj *ref = s.MakeRef_obj();
47284690
ref->VpiName(fC->SymName(List_of_arguments));
4729-
ref->VpiParent(pexpr);
4691+
ref->VpiParent(path);
47304692
fC->populateCoreMembers(List_of_arguments, List_of_arguments,
47314693
ref);
47324694
elems->push_back(ref);
@@ -4787,11 +4749,6 @@ UHDM::any *CompileHelper::compileComplexFuncCall(
47874749
instance, muteErrors);
47884750
if (result && (result->UhdmType() == UHDM::uhdmpart_select)) {
47894751
fC->populateCoreMembers(name, dotedName, result);
4790-
if ((result->VpiParent() != nullptr) &&
4791-
(result->VpiParent()->UhdmType() == UHDM::uhdmref_obj)) {
4792-
ref_obj *const parent = (ref_obj *)result->VpiParent();
4793-
fC->populateCoreMembers(name, name, parent);
4794-
}
47954752
}
47964753
return result;
47974754
} else if ((!selectName) &&
@@ -4808,8 +4765,9 @@ UHDM::any *CompileHelper::compileComplexFuncCall(
48084765
instance);
48094766
if (index) {
48104767
bit_select *select = s.MakeBit_select();
4768+
index->VpiParent(select);
48114769
select->VpiIndex(index);
4812-
the_name += "[" + decompileHelper(index) + "]";
4770+
the_name.append("[").append(decompileHelper(index)).append("]");
48134771
select->VpiFullName(the_name);
48144772
select->VpiName(fC->SymName(name));
48154773
select->VpiParent(pexpr);
@@ -4922,10 +4880,8 @@ UHDM::any *CompileHelper::compileComplexFuncCall(
49224880
compileDesign, reduce, nullptr, instance, muteErrors);
49234881
// Fix start/end to include the name
49244882
select->VpiColumnNo(fC->Column(name));
4925-
ref_obj *parent = (ref_obj *)select->VpiParent();
4926-
if (parent) parent->VpiName(tmpName);
4927-
if (tmpName.empty()) {
4928-
select->VpiParent(nullptr);
4883+
if (ref_obj *ro = any_cast<ref_obj *>(select)) {
4884+
ro->VpiName(tmpName);
49294885
}
49304886
elems->push_back(select);
49314887
the_name += decompileHelper(select);
@@ -4938,8 +4894,9 @@ UHDM::any *CompileHelper::compileComplexFuncCall(
49384894
compileDesign, reduce, nullptr, instance, muteErrors);
49394895
// Fix start/end to include the name
49404896
select->VpiColumnNo(fC->Column(name));
4941-
ref_obj *parent = (ref_obj *)select->VpiParent();
4942-
if (parent) parent->VpiDefName(tmpName);
4897+
if (ref_obj *ro = any_cast<ref_obj *>(select)) {
4898+
ro->VpiDefName(tmpName);
4899+
}
49434900
elems->push_back(select);
49444901
the_name += decompileHelper(select);
49454902
} else if (Expression) {
@@ -4948,24 +4905,17 @@ UHDM::any *CompileHelper::compileComplexFuncCall(
49484905
instance, muteErrors);
49494906
if (index) {
49504907
bit_select *select = s.MakeBit_select();
4951-
elems->push_back(select);
4952-
ref_obj *ref = s.MakeRef_obj();
4953-
ref->VpiName(tmpName);
4954-
ref->VpiParent(path);
4955-
if (!tmpName.empty()) select->VpiParent(ref);
49564908
select->VpiIndex(index);
49574909
select->VpiName(tmpName);
4958-
select->VpiFullName(tmpName);
4910+
select->VpiParent(path);
49594911
fC->populateCoreMembers(name, name, select);
4960-
std::string indexName = "[" + decompileHelper(index) + "]";
4961-
the_name += indexName;
4962-
if (!tmpName.empty()) ref->VpiName(tmpName + indexName);
4912+
elems->push_back(select);
4913+
the_name.append("[").append(decompileHelper(index)).append("]");
49634914
}
49644915
} else {
49654916
ref_obj *ref = s.MakeRef_obj();
49664917
elems->push_back(ref);
49674918
ref->VpiName(tmpName);
4968-
ref->VpiFullName(tmpName);
49694919
ref->VpiParent(path);
49704920
fC->populateCoreMembers(name, name, ref);
49714921
}
@@ -5152,7 +5102,8 @@ UHDM::any *CompileHelper::compileComplexFuncCall(
51525102
result = ref;
51535103
}
51545104
} else if (fC->Type(dotedName) == VObjectType::slList_of_arguments) {
5155-
result = compileTfCall(component, fC, fC->Parent(name), compileDesign);
5105+
result =
5106+
compileTfCall(component, fC, fC->Parent(name), compileDesign, pexpr);
51565107
} else if (fC->Type(name) == VObjectType::slStringConst) {
51575108
const std::string_view n = fC->SymName(name);
51585109
ref_obj *ref = s.MakeRef_obj();

0 commit comments

Comments
 (0)