Skip to content

Commit

Permalink
Introducing ref_typespec, parallel to ref_obj for referencing typespecs
Browse files Browse the repository at this point in the history
scope::Typespecs are cloned from non-elaborated tree to the elaborated tree.
However, at the moment, this collection doesn't have all the typespecs in the
non-elaborated tree.

This solves a few different problems -

* Avoids too many duplicates in the elaborated tree.
* For functions like $size and $bits, the parameter binding doesn't work
  because the parameter is a type and not an object. ref_typespec solves
  that binding problem.
* ref_typespec will hold the type location information in parameter
  declaration.

Known Issues -

* Need to collect all typespecs in the scope subtree to populate
  scope::Typespecs
* Though the typespecs are cloned, elaborated tree is still using the ones
  from the non-elaborated tree. The tree is still complete but typespecs are
  crossing the boundary between elaborated and non-elaborated. Need to fix
  this during binding.
  • Loading branch information
hs-apotell committed Sep 20, 2023
1 parent 795d043 commit 6bc980b
Show file tree
Hide file tree
Showing 36 changed files with 1,155 additions and 835 deletions.
4 changes: 2 additions & 2 deletions model/array_typespec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@
- class_ref: index_typespec
name: index typespec
vpi: vpiIndexTypespec
type: typespec
type: ref_typespec
card: 1
- class_ref: elem_typespec
name: elem typespec
vpi: vpiElemTypespec
type: typespec
type: ref_typespec
card: 1
- obj_ref: resolution_func
name: resolution func
Expand Down
4 changes: 2 additions & 2 deletions model/bit_typespec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
- obj_ref: bit_typespec
name: bit typespec
vpi: vpiElemTypespec
type: bit_typespec
type: ref_typespec
card: 1
- obj_ref: ranges
name: ranges
Expand All @@ -44,7 +44,7 @@
- class_ref: typespec
name: typespec
vpi: vpiIndexTypespec
type: typespec
type: ref_typespec
card: 1
- property: sign
name: sign
Expand Down
5 changes: 1 addition & 4 deletions model/class_obj.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
- obj_ref: class_typespec
name: class typespec
vpi: vpiClassTypespec
type: class_typespec
type: ref_typespec
card: 1
- obj_ref: threads
name: threads
Expand All @@ -47,6 +47,3 @@
type: constraint
card: any




14 changes: 7 additions & 7 deletions model/class_typespec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
vpi: vpiAutomatic
type: bool
card: 1
- obj_ref: class_typespec
name: class typespec
- obj_ref: extends
name: extends
vpi: vpiExtends
type: class_typespec
card: 1
type: ref_typespec
card: 1
- class_ref: variables
name: variables
vpi: vpiVariables
Expand All @@ -55,7 +55,7 @@
- obj_ref: param_assigns
vpi: vpiParamAssign
type: param_assign
card: any
card: any
- obj_ref: virtual_interface_vars
name: virtual interface vars
vpi: vpiVirtualInterfaceVar
Expand All @@ -70,12 +70,12 @@
name: named event arrays
vpi: vpiNamedEventArray
type: named_event_array
card: any
card: any
- class_ref: scopes
name: scopes
vpi: vpiInternalScope
type: scope
card: any
card: any
- obj_ref: class_defn
name: class defn
vpi: vpiClassDefn
Expand Down
2 changes: 1 addition & 1 deletion model/enum_typespec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- class_ref: base_typespec
name: base typespec
vpi: vpiBaseTypespec
type: typespec
type: ref_typespec
card: 1
- obj_ref: enum_consts
name: enum consts
Expand Down
2 changes: 1 addition & 1 deletion model/expr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
- class_ref: typespec
name: typespec
vpi: vpiTypespec
type: typespec
type: ref_typespec
card: 1
2 changes: 1 addition & 1 deletion model/extends.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- obj_ref: class_typespec
name: class typespec
vpi: vpiClassTypespec
type: class_typespec
type: ref_typespec
card: 1
- class_ref: arguments
name: arguments
Expand Down
2 changes: 1 addition & 1 deletion model/instance_array.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
- class_ref: elem_typespec
name: elem typespec
vpi: vpiElemTypespec
type: typespec
type: ref_typespec
card: 1
- obj_ref: ports
vpi: vpiPort
Expand Down
2 changes: 1 addition & 1 deletion model/io_decl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@
- class_ref: typespec
name: typespec
vpi: vpiTypedef
type: typespec
type: ref_typespec
card: 1
12 changes: 6 additions & 6 deletions model/logic_typespec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
vpi: vpiVector
type: bool
card: 1
- obj_ref: logic_typespec
name: logic typespec
- obj_ref: elem_typespec
name: elem typespec
vpi: vpiElemTypespec
type: logic_typespec
type: ref_typespec
card: 1
- obj_ref: ranges
name: ranges
Expand All @@ -41,10 +41,10 @@
vpi: vpiRightRange
type: expr
card: 1
- class_ref: typespec
name: typespec
- class_ref: index_typespec
name: index typespec
vpi: vpiIndexTypespec
type: typespec
type: ref_typespec
card: 1
- property: sign
name: sign
Expand Down
2 changes: 1 addition & 1 deletion model/named_event.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
- obj_ref: event_typespec
name: event typespec
vpi: vpiTypespec
type: event_typespec
type: ref_typespec
card: 1
- obj_ref: threads
name: threads
Expand Down
8 changes: 4 additions & 4 deletions model/packed_array_typespec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
vpi: vpiRightRange
type: expr
card: 1
- group_ref: elem_typespec
- class_ref: elem_typespec
name: elem typespec
vpi: vpiElemTypespec
type: enum_struct_union_packed_array_typespec_group
type: ref_typespec
card: 1
- class_ref: typespec
name: typespec
vpi: vpiIndexTypespec
type: typespec
type: ref_typespec
card: 1
- obj_ref: resolution_func
name: resolution func
vpi: vpiFunction
type: function
card: 1
card: 1
2 changes: 1 addition & 1 deletion model/ports.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
- class_ref: typespec
name: typespec
vpi: vpiTypedef
type: typespec
type: ref_typespec
card: 1
- class_ref: instance
name: instance
Expand Down
2 changes: 1 addition & 1 deletion model/prop_formal_decl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
- class_ref: typespec
name: typespec
vpi: vpiTypespec
type: typespec
type: ref_typespec
card: 1
8 changes: 4 additions & 4 deletions model/ref_obj.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

# Universal Hardware Data Model (UHDM) "ref_obj" formal description

- obj_def: ref_obj
- extends: simple_expr
- property: name
Expand All @@ -30,12 +30,12 @@
name: definition name
vpi: vpiDefName
type: string
card: 1
card: 1
- property: generic
name: generic
vpi: vpiGeneric
type: bool
card: 1
card: 1
- group_ref: actual_group
name: actual group
vpi: vpiActual
Expand All @@ -46,4 +46,4 @@
name: is struct member
vpi: vpiStructMember
type: bool
card: 1
card: 1
8 changes: 4 additions & 4 deletions model/ref_typespec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# Universal Hardware Data Model (UHDM) "ref_obj" formal description
# Universal Hardware Data Model (UHDM) "ref_typespec" formal description

- obj_def: ref_typespec
- extends: simple_expr
- property: name
Expand All @@ -30,9 +30,9 @@
name: definition name
vpi: vpiDefName
type: string
card: 1
card: 1
- class_ref: actual_typespec
name: actual typespec
vpi: vpiActual
type: typespec
card: 1
card: 1
2 changes: 1 addition & 1 deletion model/seq_formal_decl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@
- class_ref: typespec
name: typespec
vpi: vpiTypespec
type: typespec
type: ref_typespec
card: 1

2 changes: 1 addition & 1 deletion model/tagged_pattern.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@
- class_ref: typespec
name: typespec
vpi: vpiTypespec
type: typespec
type: ref_typespec
card: 1
4 changes: 2 additions & 2 deletions model/type_parameter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
- class_ref: typespec
name: typespec
vpi: vpiTypespec
type: typespec
type: ref_typespec
card: 1
- class_ref: expr
name: expr
vpi: vpiExpr
type: typespec
type: ref_typespec
card: 1
# Not standard, name of the package it is imported from
- property: imported
Expand Down
2 changes: 1 addition & 1 deletion model/typespec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
- class_ref: typedef_alias
name: typedef alias
vpi: vpiTypedefAlias
type: typespec
type: ref_typespec
card: 1
- class_ref: instance
name: instance
Expand Down
2 changes: 1 addition & 1 deletion model/typespec_member.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
- class_ref: typespec
name: typespec
vpi: vpiTypespec
type: typespec
type: ref_typespec
card: 1
- class_ref: default_value
name: default value
Expand Down
10 changes: 8 additions & 2 deletions python/swig_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ std::vector<vpiHandle> buildTestTypedef(UHDM::Serializer* s){
members->push_back(member1);

bit_typespec* btps = s->MakeBit_typespec();
member1->Typespec(btps);

ref_typespec* btps_rt = s->MakeRef_typespec();
btps_rt->Actual_typespec(btps);
member1->Typespec(btps_rt);

VectorOfrange* ranges = s->MakeRangeVec();
btps->VpiParent(member1);
Expand Down Expand Up @@ -76,7 +79,10 @@ std::vector<vpiHandle> buildTestTypedef(UHDM::Serializer* s){
members->push_back(member2);

btps = s->MakeBit_typespec();
member2->Typespec(btps);

btps_rt = s->MakeRef_typespec();
btps_rt->Actual_typespec(btps);
member2->Typespec(btps_rt);

ranges = s->MakeRangeVec();
btps->VpiParent(member2);
Expand Down
27 changes: 12 additions & 15 deletions scripts/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@ def _get_DeepClone_implementation(model, models):
content.append(f' if (!clone->{method}()) clone->{method}(elaboratorContext->m_elaborator.bindAny(VpiName()));')
content.append(f' if (!clone->{method}()) clone->{method}((any*) {method}());')

elif (classname in ['ref_typespec']) and (method == 'Actual_typespec'):
includes.add('ElaboratorListener')
includes.add('typespec')
content.append( ' if (elaboratorContext->m_elaborator.uniquifyTypespec()) {')
content.append(f' if (auto obj = {method}()) clone->{method}(obj->DeepClone(clone, context));')
content.append( ' } else {')
content.append(f' if (auto obj = {method}()) clone->{method}((typespec*) obj);')
content.append( ' }')

elif (classname == 'udp') and (method == 'Udp_defn'):
includes.add('ElaboratorListener')
content.append(f' if (!clone->{method}()) clone->{method}((udp_defn*) elaboratorContext->m_elaborator.bindAny(VpiDefName()));')
Expand Down Expand Up @@ -235,31 +244,18 @@ def _get_DeepClone_implementation(model, models):
includes.add('module_inst')
content.append(f' if (auto obj = {method}()) clone->{method}((interface_inst*) obj);')

elif method == 'Typespec':
includes.add('typespec')
content.append( ' if (elaboratorContext->m_elaborator.uniquifyTypespec()) {')
content.append(f' if (auto obj = {method}()) clone->{method}(obj->DeepClone(clone, context));')
content.append( ' } else {')
content.append(f' if (auto obj = {method}()) clone->{method}((typespec*) obj);')
content.append( ' }')

else:
content.append(f' if (auto obj = {method}()) clone->{method}(obj->DeepClone(clone, context));')

elif (classname == 'module_inst') and (method == 'Ref_modules'):
pass # No cloning

elif method == 'Typespecs':
# Don't deep clone
content.append(f' if (auto vec = {method}()) {{')
content.append(f' auto clone_vec = context->m_serializer->Make{Cast}Vec();')
content.append(f' clone->{method}(clone_vec);')
content.append( ' for (auto obj : *vec) {')
content.append( ' if (elaboratorContext->m_elaborator.uniquifyTypespec()) {')
content.append( ' clone_vec->push_back(obj->DeepClone(clone, context));')
content.append( ' } else {')
content.append( ' clone_vec->push_back(obj);')
content.append( ' }')
content.append( ' }')
content.append( ' clone_vec->insert(clone_vec->cend(), vec->cbegin(), vec->cend());')
content.append( ' }')

elif (classname == 'class_defn') and (method == 'Deriveds'):
Expand All @@ -279,6 +275,7 @@ def _get_DeepClone_implementation(model, models):
content.append( ' clone_vec->push_back(obj->DeepClone(clone, context));')
content.append( ' }')
content.append( ' }')

if modeltype != 'class_def':
content.append(f' elaboratorContext->m_elaborator.leave{Classname}(clone, nullptr);')

Expand Down
Loading

0 comments on commit 6bc980b

Please sign in to comment.