From 8e3726eb98791c8629b9c9b8c15c8bb88c467225 Mon Sep 17 00:00:00 2001 From: Derek Bankieris Date: Wed, 10 Feb 2021 16:05:02 -0600 Subject: [PATCH 1/2] Mark references as such in ICG --- .../codegen/Interface_Code_Gen/FieldDescription.cpp | 9 +++++++++ .../codegen/Interface_Code_Gen/FieldDescription.hh | 5 +++++ trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp | 6 +++--- .../codegen/Interface_Code_Gen/PrintFileContents10.cpp | 2 +- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp index 8505c393..f1519ff2 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldDescription.cpp @@ -57,6 +57,7 @@ FieldDescription::FieldDescription( is_stl(0) , has_stl_clear(1) , is_static(0) , + is_reference(0) , num_dims(0) , array_sizes() {} ; @@ -543,6 +544,14 @@ bool FieldDescription::isStatic() { return is_static ; } +void FieldDescription::setReference(bool yes_no) { + is_reference = yes_no ; +} + +bool FieldDescription::isReference() { + return is_reference ; +} + unsigned int FieldDescription::getNumDims() { return num_dims ; } diff --git a/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh b/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh index dff5fe86..28e2a745 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh +++ b/trick_source/codegen/Interface_Code_Gen/FieldDescription.hh @@ -87,6 +87,8 @@ class FieldDescription : public ConstructValues { bool hasSTLClear() ; void setStatic( bool yes_no ) ; bool isStatic() ; + void setReference( bool yes_no ) ; + bool isReference() ; void setInherited( bool yes_no ) ; bool isInherited() ; void setVirtualInherited( bool yes_no ) ; @@ -184,6 +186,9 @@ class FieldDescription : public ConstructValues { /** is this field declared static */ bool is_static ; + /** is this field a reference type */ + bool is_reference ; + /** map of strings to io numbers. One copy for all fields */ static std::map io_map ; diff --git a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp index 8c46bb1f..79bf2af8 100644 --- a/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp +++ b/trick_source/codegen/Interface_Code_Gen/FieldVisitor.cpp @@ -43,12 +43,12 @@ bool FieldVisitor::VisitType(clang::Type *t) { std::cout << "FieldVisitor VisitType Type = " << t->getTypeClassName() << std::endl ; t->dump() ; } - // If this type is a reference, set IO to 0 if ( t->isReferenceType() ) { if ( debug_level >= 3 ) { - std::cout << "FieldVisitor VisitType found reference, setIO = 0 " << std::endl ; + std::cout << "FieldVisitor VisitType found reference, setIO = 3 " << std::endl ; } - fdes->setIO(0) ; + fdes->setIO(3) ; + fdes->setReference(true) ; } return true; } diff --git a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp index 4ba5d12a..533a16f7 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintFileContents10.cpp @@ -76,7 +76,7 @@ void PrintFileContents10::print_field_attr(std::ostream & ostream , FieldDescri ostream << ", sizeof(" << fdes.getTypeName() << ")" ; } ostream << ", 0, 0, Language_CPP" ; // range_min, range_max, language - ostream << ", " << (fdes.isStatic() << 1) + (fdes.isDashDashUnits() << 2) << "," << std::endl ; // mods + ostream << ", " << fdes.isReference() + (fdes.isStatic() << 1) + (fdes.isDashDashUnits() << 2) << "," << std::endl ; // mods if ( fdes.isBitField() ) { // For bitfields we need the offset to start on 4 byte boundaries because that is what our // insert and extract bitfield routines work with. From c428bce49d83a1b1e40b5e40178c3300a9732206 Mon Sep 17 00:00:00 2001 From: Derek Bankieris Date: Wed, 10 Feb 2021 16:06:07 -0600 Subject: [PATCH 2/2] Add support for references in MM::ref_name Add an AO_DEREFERENCE ADDRESS_NODE to R->address_path and dereference the address for REF2->address --- .../codegen/Interface_Code_Gen/PrintFileContentsBase.cpp | 8 ++++++++ .../MemoryManager/MemoryManager_ref_name.cpp | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/trick_source/codegen/Interface_Code_Gen/PrintFileContentsBase.cpp b/trick_source/codegen/Interface_Code_Gen/PrintFileContentsBase.cpp index 4718f3dc..25d65650 100644 --- a/trick_source/codegen/Interface_Code_Gen/PrintFileContentsBase.cpp +++ b/trick_source/codegen/Interface_Code_Gen/PrintFileContentsBase.cpp @@ -63,6 +63,14 @@ bool PrintFileContentsBase::isPrintable( ClassValues * c , FieldDescription * fd if ( fdes->isSTL() and fdes->getNumDims() ) { return false; } + /** + * It is not possible to take the address of a reference as the referred-to variable's address + * is always returned. As such, the init_attr function cannot obtain the absolute address for + * static reference variables. + */ + if ( fdes->isStatic() && fdes->isReference() ) { + return false; + } if ( fdes->getAccess() == clang::AS_public || (!fdes->isStatic() && !global_compat15 && !c->isCompat15())) { return true; } diff --git a/trick_source/sim_services/MemoryManager/MemoryManager_ref_name.cpp b/trick_source/sim_services/MemoryManager/MemoryManager_ref_name.cpp index 5c5464ea..f22143ab 100644 --- a/trick_source/sim_services/MemoryManager/MemoryManager_ref_name.cpp +++ b/trick_source/sim_services/MemoryManager/MemoryManager_ref_name.cpp @@ -99,6 +99,15 @@ int Trick::MemoryManager::ref_name(REF2 * R, char *name) { } } + if (attr->mods & 1) { + ADDRESS_NODE * address_node = new ADDRESS_NODE ; + address_node->operator_ = AO_DEREFERENCE ; + address_node->operand.address = NULL ; + DLL_AddTail(address_node , R->address_path) ; + + addr = *(char**)addr; + } + /* Save the address and next attributes in the REF structure. If the attributes are dynamically-allocated, reference attributes then free them so we don't leak memory.