2014-07-23 22:39:29 +02:00
|
|
|
#ifndef IVL_HName_H
|
|
|
|
|
#define IVL_HName_H
|
2001-12-03 05:47:14 +01:00
|
|
|
/*
|
2014-03-31 02:20:42 +02:00
|
|
|
* Copyright (c) 2001-2014 Stephen Williams (steve@icarus.com)
|
2001-12-03 05:47:14 +01:00
|
|
|
*
|
|
|
|
|
* This source code is free software; you can redistribute it
|
|
|
|
|
* and/or modify it in source code form under the terms of the GNU
|
|
|
|
|
* General Public License as published by the Free Software
|
|
|
|
|
* Foundation; either version 2 of the License, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2001-12-03 05:47:14 +01:00
|
|
|
*/
|
|
|
|
|
|
2002-06-14 05:25:51 +02:00
|
|
|
# include <iostream>
|
2008-06-26 07:02:22 +02:00
|
|
|
# include <list>
|
2014-03-31 02:20:42 +02:00
|
|
|
# include <vector>
|
2007-04-26 05:06:21 +02:00
|
|
|
# include "StringHeap.h"
|
2014-03-31 02:20:42 +02:00
|
|
|
|
|
|
|
|
# include <cassert>
|
2001-12-03 05:47:14 +01:00
|
|
|
|
|
|
|
|
/*
|
2007-06-02 05:42:12 +02:00
|
|
|
* This class represents a component of a Verilog hierarchical name. A
|
2008-01-25 22:34:51 +01:00
|
|
|
* hierarchical component contains a name string (represented here
|
2007-06-02 05:42:12 +02:00
|
|
|
* with a perm_string) and an optional signed number. This signed
|
|
|
|
|
* number is used if the scope is part of an array, for example an
|
|
|
|
|
* array of module instances or a loop generated scope.
|
2001-12-03 05:47:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
class hname_t {
|
|
|
|
|
|
2014-03-31 02:20:42 +02:00
|
|
|
friend ostream& operator<< (ostream&out, const hname_t&that);
|
|
|
|
|
|
2001-12-03 05:47:14 +01:00
|
|
|
public:
|
|
|
|
|
hname_t ();
|
2007-04-26 05:06:21 +02:00
|
|
|
explicit hname_t (perm_string text);
|
2007-06-02 05:42:12 +02:00
|
|
|
explicit hname_t (perm_string text, int num);
|
2015-09-30 02:44:28 +02:00
|
|
|
explicit hname_t (perm_string text, const std::vector<int>&nums);
|
2001-12-03 05:47:14 +01:00
|
|
|
hname_t (const hname_t&that);
|
|
|
|
|
~hname_t();
|
|
|
|
|
|
2007-06-02 05:42:12 +02:00
|
|
|
hname_t& operator= (const hname_t&);
|
2001-12-03 05:47:14 +01:00
|
|
|
|
2014-03-31 02:20:42 +02:00
|
|
|
bool operator == (const hname_t&that) const;
|
|
|
|
|
bool operator < (const hname_t&that) const;
|
|
|
|
|
|
2007-06-02 05:42:12 +02:00
|
|
|
// Return the string part of the hname_t.
|
|
|
|
|
perm_string peek_name(void) const;
|
2002-11-02 04:27:51 +01:00
|
|
|
|
2014-03-31 02:20:42 +02:00
|
|
|
size_t has_numbers() const;
|
|
|
|
|
int peek_number(size_t idx) const;
|
2015-09-30 02:44:28 +02:00
|
|
|
const std::vector<int>&peek_numbers() const;
|
2001-12-03 05:47:14 +01:00
|
|
|
|
|
|
|
|
private:
|
2007-06-02 05:42:12 +02:00
|
|
|
perm_string name_;
|
2015-09-30 02:44:28 +02:00
|
|
|
// If this vector has size, then the numbers all together make
|
|
|
|
|
// up part of the hierarchical name.
|
2014-03-31 02:20:42 +02:00
|
|
|
std::vector<int> number_;
|
2007-04-26 05:06:21 +02:00
|
|
|
|
2001-12-03 05:47:14 +01:00
|
|
|
private: // not implemented
|
|
|
|
|
};
|
|
|
|
|
|
2009-12-09 00:14:55 +01:00
|
|
|
inline hname_t::~hname_t()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline perm_string hname_t::peek_name(void) const
|
|
|
|
|
{
|
|
|
|
|
return name_;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-31 02:20:42 +02:00
|
|
|
inline int hname_t::peek_number(size_t idx) const
|
2009-12-09 00:14:55 +01:00
|
|
|
{
|
2014-03-31 02:20:42 +02:00
|
|
|
assert(number_.size() > idx);
|
|
|
|
|
return number_[idx];
|
2009-12-09 00:14:55 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-30 02:44:28 +02:00
|
|
|
inline const std::vector<int>& hname_t::peek_numbers(void) const
|
|
|
|
|
{
|
|
|
|
|
return number_;
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-31 02:20:42 +02:00
|
|
|
inline size_t hname_t::has_numbers() const
|
2009-12-09 00:14:55 +01:00
|
|
|
{
|
2014-03-31 02:20:42 +02:00
|
|
|
return number_.size();
|
2009-12-09 00:14:55 +01:00
|
|
|
}
|
|
|
|
|
|
2007-06-02 05:42:12 +02:00
|
|
|
extern ostream& operator<< (ostream&, const hname_t&);
|
2001-12-03 05:47:14 +01:00
|
|
|
|
2009-12-09 00:14:55 +01:00
|
|
|
inline bool operator != (const hname_t&l, const hname_t&r)
|
|
|
|
|
{ return ! (l == r); }
|
|
|
|
|
|
2008-06-26 07:02:22 +02:00
|
|
|
inline ostream& operator<< (ostream&out, const list<hname_t>&ll)
|
|
|
|
|
{
|
|
|
|
|
list<hname_t>::const_iterator cur = ll.begin();
|
|
|
|
|
out << *cur;
|
2010-10-23 23:57:59 +02:00
|
|
|
++ cur;
|
2008-06-26 07:02:22 +02:00
|
|
|
while (cur != ll.end()) {
|
|
|
|
|
out << "." << *cur;
|
2010-10-23 23:57:59 +02:00
|
|
|
++ cur;
|
2008-06-26 07:02:22 +02:00
|
|
|
}
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-23 22:39:29 +02:00
|
|
|
#endif /* IVL_HName_H */
|