summaryrefslogtreecommitdiff
path: root/src/mem/slicc/symbols
diff options
context:
space:
mode:
authorNathan Binkert <nate@binkert.org>2010-06-10 23:17:06 -0700
committerNathan Binkert <nate@binkert.org>2010-06-10 23:17:06 -0700
commitbc87fa30d72df7db6265be50b2c39dc218076f9f (patch)
tree9e27c5ec1bbdbee048f2e91fc450d71f47bdf88d /src/mem/slicc/symbols
parentaa7888797032bab49b5f0f637c859740497423d8 (diff)
downloadgem5-bc87fa30d72df7db6265be50b2c39dc218076f9f.tar.xz
ruby: get rid of RefCnt and Allocator stuff use base/refcnt.hh
This was somewhat tricky because the RefCnt API was somewhat odd. The biggest confusion was that the the RefCnt object's constructor that took a TYPE& cloned the object. I created an explicit virtual clone() function for things that took advantage of this version of the constructor. I was conservative and used clone() when I was in doubt of whether or not it was necessary. I still think that there are probably too many instances of clone(), but hopefully not too many. I converted several instances of const MsgPtr & to a simple MsgPtr. If the function wants to avoid the overhead of creating another reference, then it should just use a regular pointer instead of a ref counting ptr. There were a couple of instances where refcounted objects were created on the stack. This seems pretty dangerous since if you ever accidentally make a reference to that object with a ref counting pointer, bad things are bound to happen.
Diffstat (limited to 'src/mem/slicc/symbols')
-rw-r--r--src/mem/slicc/symbols/Type.py59
1 files changed, 25 insertions, 34 deletions
diff --git a/src/mem/slicc/symbols/Type.py b/src/mem/slicc/symbols/Type.py
index c4b4d4275..cefae16ae 100644
--- a/src/mem/slicc/symbols/Type.py
+++ b/src/mem/slicc/symbols/Type.py
@@ -205,7 +205,6 @@ class Type(Symbol):
#include <iostream>
#include "mem/ruby/common/Global.hh"
-#include "mem/gems_common/Allocator.hh"
''')
for dm in self.data_members.values():
@@ -242,6 +241,26 @@ $klass ${{self.c_ident}}$parent
code.dedent()
code('}')
+ # ******** Copy constructor ********
+ if not self.isGlobal:
+ code('${{self.c_ident}}(const ${{self.c_ident}}&other)')
+
+ # Call superclass constructor
+ if "interface" in self:
+ code(' : ${{self["interface"]}}(other)')
+
+ code('{')
+ code.indent()
+
+ for dm in self.data_members.values():
+ code('m_${{dm.ident}} = other.m_${{dm.ident}};')
+
+ if self.isMessage:
+ code('proc_id = other.proc_id;')
+
+ code.dedent()
+ code('}')
+
# ******** Full init constructor ********
if not self.isGlobal:
params = [ 'const %s& local_%s' % (dm.type.c_ident, dm.ident) \
@@ -270,44 +289,18 @@ $klass ${{self.c_ident}}$parent
code.dedent()
code('}')
- # create a static factory method
- if "interface" in self:
- code('''
-static ${{self["interface"]}}*
+ # create a static factory method and a clone member
+ code('''
+static ${{self.c_ident}}*
create()
{
return new ${{self.c_ident}}();
}
-''')
-
- # ******** Message member functions ********
- # FIXME: those should be moved into slicc file, slicc should
- # support more of the c++ class inheritance
- if self.isMessage:
- code('''
-Message *
+${{self.c_ident}}*
clone() const
{
- checkAllocator();
- return s_allocator_ptr->allocate(*this);
-}
-
-void
-destroy()
-{
- checkAllocator();
- s_allocator_ptr->deallocate(this);
-}
-
-static Allocator<${{self.c_ident}}>* s_allocator_ptr;
-
-static void
-checkAllocator()
-{
- if (s_allocator_ptr == NULL) {
- s_allocator_ptr = new Allocator<${{self.c_ident}}>;
- }
+ return new ${{self.c_ident}}(*this);
}
''')
@@ -414,8 +407,6 @@ operator<<(std::ostream& out, const ${{self.c_ident}}& obj)
using namespace std;
''')
- if self.isMessage:
- code('Allocator<${{self.c_ident}}>* ${{self.c_ident}}::s_allocator_ptr = NULL;')
code('''
/** \\brief Print the state of this object */
void