Loader: Use address mask provided to load*Symbols when loading the symbols from the...
[gem5.git] / src / base / timebuf.hh
index f6b5b2781cbf4d710318d09443c4e0986b75f0cc..b6f709d719472b92458ac4a63c2bd7b59bdd50d4 100644 (file)
  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Nathan Binkert
+ *          Kevin Lim
  */
 
 #ifndef __BASE_TIMEBUF_HH__
 #define __BASE_TIMEBUF_HH__
 
+#include <cassert>
+#include <cstring>
 #include <vector>
 
 template <class T>
@@ -37,11 +42,12 @@ class TimeBuffer
   protected:
     int past;
     int future;
-    int size;
+    unsigned size;
+    int _id;
 
     char *data;
     std::vector<char *> index;
-    int base;
+    unsigned base;
 
     void valid(int idx)
     {
@@ -132,17 +138,19 @@ class TimeBuffer
 
   public:
     TimeBuffer(int p, int f)
-        : past(p), future(f), size(past + future + 1),
+        : past(p), future(f), size(past + future + 1), 
           data(new char[size * sizeof(T)]), index(size), base(0)
     {
         assert(past >= 0 && future >= 0);
         char *ptr = data;
-        for (int i = 0; i < size; i++) {
+        for (unsigned i = 0; i < size; i++) {
             index[i] = ptr;
-            memset(ptr, 0, sizeof(T));
+            std::memset(ptr, 0, sizeof(T));
             new (ptr) T;
             ptr += sizeof(T);
         }
+
+        _id = -1;
     }
 
     TimeBuffer()
@@ -152,11 +160,21 @@ class TimeBuffer
 
     ~TimeBuffer()
     {
-        for (int i = 0; i < size; ++i)
+        for (unsigned i = 0; i < size; ++i)
             (reinterpret_cast<T *>(index[i]))->~T();
         delete [] data;
     }
 
+    void id(int id)
+    {
+        _id = id;
+    }
+
+    int id()
+    {
+        return _id;
+    }
+
     void
     advance()
     {
@@ -164,10 +182,10 @@ class TimeBuffer
             base = 0;
 
         int ptr = base + future;
-        if (ptr >= size)
+        if (ptr >= (int)size)
             ptr -= size;
         (reinterpret_cast<T *>(index[ptr]))->~T();
-        memset(index[ptr], 0, sizeof(T));
+        std::memset(index[ptr], 0, sizeof(T));
         new (index[ptr]) T;
     }
 
@@ -177,7 +195,7 @@ class TimeBuffer
         valid(idx);
 
         int vector_index = idx + base;
-        if (vector_index >= size) {
+        if (vector_index >= (int)size) {
             vector_index -= size;
         } else if (vector_index < 0) {
             vector_index += size;
@@ -192,7 +210,7 @@ class TimeBuffer
         valid(idx);
 
         int vector_index = idx + base;
-        if (vector_index >= size) {
+        if (vector_index >= (int)size) {
             vector_index -= size;
         } else if (vector_index < 0) {
             vector_index += size;
@@ -212,6 +230,11 @@ class TimeBuffer
     {
         return wire(this, 0);
     }
+
+    unsigned getSize()
+    {
+        return size;
+    }
 };
 
 #endif // __BASE_TIMEBUF_HH__