2012-04-13 01:08:20 +00:00
|
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: List class with storage in existing classes
|
|
|
|
|
//
|
2008-04-25 12:14:27 +00:00
|
|
|
|
// Code available from: http://www.veripool.org/verilator
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2018-01-02 23:05:06 +00:00
|
|
|
|
// Copyright 2003-2018 by Wilson Snyder. This program is free software; you can
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 21:07:57 +00:00
|
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
// Verilator is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
|
|
#ifndef _V3LIST_H_
|
|
|
|
|
#define _V3LIST_H_ 1
|
2006-12-18 19:20:45 +00:00
|
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
template <class T> class V3List;
|
|
|
|
|
template <class T> class V3ListEnt;
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
class V3List {
|
|
|
|
|
// List container for linked list of elements of type *T (T is a pointer type)
|
|
|
|
|
private:
|
|
|
|
|
// STATE
|
|
|
|
|
T m_headp; // First element
|
|
|
|
|
T m_tailp; // Last element
|
|
|
|
|
friend class V3ListEnt<T>;
|
|
|
|
|
public:
|
|
|
|
|
V3List()
|
|
|
|
|
: m_headp(NULL), m_tailp(NULL) {}
|
|
|
|
|
~V3List() {}
|
|
|
|
|
// METHODS
|
|
|
|
|
T begin() const { return m_headp; }
|
|
|
|
|
T end() const { return NULL; }
|
|
|
|
|
bool empty() const { return m_headp==NULL; }
|
|
|
|
|
void reset() { m_headp=NULL; m_tailp=NULL; } // clear() without walking the list
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
|
class V3ListEnt {
|
|
|
|
|
// List entry for linked list of elements of type *T (T is a pointer type)
|
|
|
|
|
private:
|
|
|
|
|
// STATE
|
|
|
|
|
T m_nextp; // Pointer to next element, NULL=end
|
|
|
|
|
T m_prevp; // Pointer to previous element, NULL=beginning
|
|
|
|
|
friend class V3List<T>;
|
2011-08-05 01:58:45 +00:00
|
|
|
|
static V3ListEnt* baseToListEnt(void* newbasep, size_t offset) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// "this" must be a element inside of *basep
|
|
|
|
|
// Use that to determine a structure offset, then apply to the new base
|
|
|
|
|
// to get our new pointer information
|
2006-09-19 15:27:15 +00:00
|
|
|
|
return (V3ListEnt*) ( ((vluint8_t*)newbasep) + offset);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
public:
|
|
|
|
|
V3ListEnt()
|
|
|
|
|
: m_nextp(NULL), m_prevp(NULL) {}
|
|
|
|
|
~V3ListEnt() {
|
|
|
|
|
#ifdef VL_DEBUG
|
|
|
|
|
// Load bogus pointers so we can catch deletion bugs
|
|
|
|
|
m_nextp = (T)1;
|
|
|
|
|
m_prevp = (T)1;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
T nextp() const { return m_nextp; }
|
|
|
|
|
// METHODS
|
|
|
|
|
void pushBack (V3List<T>& listr, T newp) {
|
|
|
|
|
// "this" must be a element inside of *newp
|
2011-08-05 01:58:45 +00:00
|
|
|
|
// cppcheck-suppress thisSubtraction
|
2013-02-03 18:27:37 +00:00
|
|
|
|
size_t offset = (size_t)(vluint8_t*)(this) - (size_t)(vluint8_t*)(newp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_nextp = NULL;
|
|
|
|
|
if (!listr.m_headp) listr.m_headp = newp;
|
|
|
|
|
m_prevp = listr.m_tailp;
|
|
|
|
|
if (m_prevp) baseToListEnt(m_prevp,offset)->m_nextp = newp;
|
|
|
|
|
listr.m_tailp = newp;
|
|
|
|
|
}
|
|
|
|
|
void pushFront (V3List<T>& listr, T newp) {
|
|
|
|
|
// "this" must be a element inside of *newp
|
2011-08-05 01:58:45 +00:00
|
|
|
|
// cppcheck-suppress thisSubtraction
|
2013-02-03 18:27:37 +00:00
|
|
|
|
size_t offset = (size_t)(vluint8_t*)(this) - (size_t)(vluint8_t*)(newp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_nextp = listr.m_headp;
|
|
|
|
|
if (m_nextp) baseToListEnt(m_nextp,offset)->m_prevp = newp;
|
|
|
|
|
listr.m_headp = newp;
|
|
|
|
|
m_prevp = NULL;
|
|
|
|
|
if (!listr.m_tailp) listr.m_tailp = newp;
|
|
|
|
|
}
|
|
|
|
|
// Unlink from side
|
|
|
|
|
void unlink (V3List<T>& listr, T oldp) {
|
|
|
|
|
// "this" must be a element inside of *oldp
|
2011-08-05 01:58:45 +00:00
|
|
|
|
// cppcheck-suppress thisSubtraction
|
2013-02-03 18:27:37 +00:00
|
|
|
|
size_t offset = (size_t)(vluint8_t*)(this) - (size_t)(vluint8_t*)(oldp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
if (m_nextp) baseToListEnt(m_nextp,offset)->m_prevp = m_prevp;
|
|
|
|
|
else listr.m_tailp = m_prevp;
|
|
|
|
|
if (m_prevp) baseToListEnt(m_prevp,offset)->m_nextp = m_nextp;
|
|
|
|
|
else listr.m_headp = m_nextp;
|
|
|
|
|
m_prevp = m_nextp = NULL;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
|
|
#endif // Guard
|