From db3739682d7c54839b627ff8f7a4448a9dc99987 Mon Sep 17 00:00:00 2001 From: Andreas Hansson Date: Thu, 16 Oct 2014 05:49:49 -0400 Subject: mem: Use shared_ptr for Ruby Message classes This patch transitions the Ruby Message and its derived classes from the ad-hoc RefCountingPtr to the c++11 shared_ptr. There are no changes in behaviour, and the code modifications are mainly replacing "new" with "make_shared". The cloning of derived messages is slightly changed as they previously relied on overriding the base-class through covariant return types. --- src/mem/slicc/ast/EnqueueStatementAST.py | 4 ++-- src/mem/slicc/symbols/Type.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) (limited to 'src/mem/slicc') diff --git a/src/mem/slicc/ast/EnqueueStatementAST.py b/src/mem/slicc/ast/EnqueueStatementAST.py index c4f2ac06c..e08e49808 100644 --- a/src/mem/slicc/ast/EnqueueStatementAST.py +++ b/src/mem/slicc/ast/EnqueueStatementAST.py @@ -54,8 +54,8 @@ class EnqueueStatementAST(StatementAST): self.symtab.newSymbol(v) # Declare message - code("${{msg_type.ident}} *out_msg = "\ - "new ${{msg_type.ident}}(clockEdge());") + code("std::shared_ptr<${{msg_type.ident}}> out_msg = "\ + "std::make_shared<${{msg_type.ident}}>(clockEdge());") # The other statements t = self.statements.generate(code, None) diff --git a/src/mem/slicc/symbols/Type.py b/src/mem/slicc/symbols/Type.py index d9bd85c01..2afd9958c 100644 --- a/src/mem/slicc/symbols/Type.py +++ b/src/mem/slicc/symbols/Type.py @@ -283,7 +283,16 @@ $klass ${{self.c_ident}}$parent code('}') # create a clone member - code(''' + if self.isMessage: + code(''' +MsgPtr +clone() const +{ + return std::shared_ptr(new ${{self.c_ident}}(*this)); +} +''') + else: + code(''' ${{self.c_ident}}* clone() const { @@ -391,6 +400,7 @@ operator<<(std::ostream& out, const ${{self.c_ident}}& obj) */ #include +#include #include "mem/protocol/${{self.c_ident}}.hh" #include "mem/ruby/common/Global.hh" -- cgit v1.2.3