yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
RTLIL::IdString Struct Reference

#include <rtlil.h>

+ Collaboration diagram for RTLIL::IdString:

Data Structures

struct  char_ptr_cmp
 
struct  compare_ptr_by_name
 
struct  destruct_guard_t
 

Public Member Functions

 IdString ()
 
 IdString (const char *str)
 
 IdString (const IdString &str)
 
 IdString (const std::string &str)
 
 ~IdString ()
 
void operator= (const IdString &rhs)
 
void operator= (const char *rhs)
 
void operator= (const std::string &rhs)
 
const char * c_str () const
 
std::string str () const
 
bool operator< (IdString rhs) const
 
bool operator== (IdString rhs) const
 
bool operator!= (IdString rhs) const
 
bool operator== (const std::string &rhs) const
 
bool operator!= (const std::string &rhs) const
 
bool operator== (const char *rhs) const
 
bool operator!= (const char *rhs) const
 
char operator[] (size_t i) const
 
std::string substr (size_t pos=0, size_t len=std::string::npos) const
 
size_t size () const
 
bool empty () const
 
void clear ()
 
template<typename T , typename... Args>
bool in (T first, Args...rest)
 
bool in (IdString rhs)
 
bool in (const char *rhs)
 
bool in (const std::string &rhs)
 
bool in (const std::set< IdString > &rhs)
 

Static Public Member Functions

static int get_reference (int idx)
 
static int get_reference (const char *p)
 
static void put_reference (int idx)
 

Data Fields

int index_
 

Static Public Attributes

static struct
RTLIL::IdString::destruct_guard_t 
destruct_guard
 
static std::vector< int > global_refcount_storage_
 
static std::vector< char * > global_id_storage_
 
static std::map< char *, int,
char_ptr_cmp
global_id_index_
 
static std::vector< int > global_free_idx_list_
 

Detailed Description

Definition at line 75 of file rtlil.h.

Constructor & Destructor Documentation

RTLIL::IdString::IdString ( )
inline

Definition at line 157 of file rtlil.h.

157 : index_(get_reference("")) { }
static int get_reference(int idx)
Definition: rtlil.h:99

+ Here is the caller graph for this function:

RTLIL::IdString::IdString ( const char *  str)
inline

Definition at line 158 of file rtlil.h.

158 : index_(get_reference(str)) { }
std::string str() const
Definition: rtlil.h:182
static int get_reference(int idx)
Definition: rtlil.h:99
RTLIL::IdString::IdString ( const IdString str)
inline

Definition at line 159 of file rtlil.h.

159 : index_(get_reference(str.index_)) { }
std::string str() const
Definition: rtlil.h:182
static int get_reference(int idx)
Definition: rtlil.h:99
RTLIL::IdString::IdString ( const std::string &  str)
inline

Definition at line 160 of file rtlil.h.

160 : index_(get_reference(str.c_str())) { }
std::string str() const
Definition: rtlil.h:182
static int get_reference(int idx)
Definition: rtlil.h:99
RTLIL::IdString::~IdString ( )
inline

Definition at line 161 of file rtlil.h.

161 { put_reference(index_); }
static void put_reference(int idx)
Definition: rtlil.h:135

+ Here is the call graph for this function:

Member Function Documentation

const char* RTLIL::IdString::c_str ( ) const
inline

Definition at line 178 of file rtlil.h.

178  {
179  return global_id_storage_.at(index_);
180  }
static std::vector< char * > global_id_storage_
Definition: rtlil.h:95
void RTLIL::IdString::clear ( )
inline

Definition at line 223 of file rtlil.h.

223  {
224  *this = IdString();
225  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool RTLIL::IdString::empty ( ) const
inline

Definition at line 219 of file rtlil.h.

219  {
220  return c_str()[0] == 0;
221  }
const char * c_str() const
Definition: rtlil.h:178

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int RTLIL::IdString::get_reference ( int  idx)
inlinestatic

Definition at line 99 of file rtlil.h.

100  {
102  return idx;
103  }
static std::string idx(std::string str)
Definition: test_autotb.cc:57
static std::vector< int > global_refcount_storage_
Definition: rtlil.h:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int RTLIL::IdString::get_reference ( const char *  p)
inlinestatic

Definition at line 105 of file rtlil.h.

106  {
108 
109  if (p[0]) {
110  log_assert(p[1] != 0);
111  log_assert(p[0] == '$' || p[0] == '\\');
112  }
113 
114  auto it = global_id_index_.find((char*)p);
115  if (it != global_id_index_.end()) {
116  global_refcount_storage_.at(it->second)++;
117  return it->second;
118  }
119 
120  if (global_free_idx_list_.empty()) {
121  log_assert(global_id_storage_.size() < 0x40000000);
122  global_free_idx_list_.push_back(global_id_storage_.size());
123  global_id_storage_.push_back(nullptr);
124  global_refcount_storage_.push_back(0);
125  }
126 
127  int idx = global_free_idx_list_.back();
128  global_free_idx_list_.pop_back();
129  global_id_storage_.at(idx) = strdup(p);
131  global_refcount_storage_.at(idx)++;
132  return idx;
133  }
static std::string idx(std::string str)
Definition: test_autotb.cc:57
static std::vector< int > global_free_idx_list_
Definition: rtlil.h:97
#define log_assert(_assert_expr_)
Definition: log.h:85
static std::vector< char * > global_id_storage_
Definition: rtlil.h:95
static std::map< char *, int, char_ptr_cmp > global_id_index_
Definition: rtlil.h:96
static struct RTLIL::IdString::destruct_guard_t destruct_guard
Definition: rtlil.cc:30
static std::vector< int > global_refcount_storage_
Definition: rtlil.h:94

+ Here is the call graph for this function:

template<typename T , typename... Args>
bool RTLIL::IdString::in ( first,
Args...  rest 
)
inline

Definition at line 241 of file rtlil.h.

241  {
242  return in(first) || in(rest...);
243  }
bool in(T first, Args...rest)
Definition: rtlil.h:241

+ Here is the caller graph for this function:

bool RTLIL::IdString::in ( IdString  rhs)
inline

Definition at line 245 of file rtlil.h.

245 { return *this == rhs; }
bool RTLIL::IdString::in ( const char *  rhs)
inline

Definition at line 246 of file rtlil.h.

246 { return *this == rhs; }
bool RTLIL::IdString::in ( const std::string &  rhs)
inline

Definition at line 247 of file rtlil.h.

247 { return *this == rhs; }
bool RTLIL::IdString::in ( const std::set< IdString > &  rhs)
inline

Definition at line 248 of file rtlil.h.

248 { return rhs.count(*this) != 0; }
bool RTLIL::IdString::operator!= ( IdString  rhs) const
inline

Definition at line 191 of file rtlil.h.

191 { return index_ != rhs.index_; }
bool RTLIL::IdString::operator!= ( const std::string &  rhs) const
inline

Definition at line 196 of file rtlil.h.

196 { return str() != rhs; }
std::string str() const
Definition: rtlil.h:182

+ Here is the call graph for this function:

bool RTLIL::IdString::operator!= ( const char *  rhs) const
inline

Definition at line 199 of file rtlil.h.

199 { return strcmp(c_str(), rhs) != 0; }
const char * c_str() const
Definition: rtlil.h:178

+ Here is the call graph for this function:

bool RTLIL::IdString::operator< ( IdString  rhs) const
inline

Definition at line 186 of file rtlil.h.

186  {
187  return index_ < rhs.index_;
188  }
void RTLIL::IdString::operator= ( const IdString rhs)
inline

Definition at line 163 of file rtlil.h.

163  {
165  index_ = get_reference(rhs.index_);
166  }
static int get_reference(int idx)
Definition: rtlil.h:99
static void put_reference(int idx)
Definition: rtlil.h:135

+ Here is the call graph for this function:

void RTLIL::IdString::operator= ( const char *  rhs)
inline

Definition at line 168 of file rtlil.h.

168  {
169  IdString id(rhs);
170  *this = id;
171  }
std::string id(RTLIL::IdString internal_id, bool may_rename=true)

+ Here is the call graph for this function:

void RTLIL::IdString::operator= ( const std::string &  rhs)
inline

Definition at line 173 of file rtlil.h.

173  {
174  IdString id(rhs);
175  *this = id;
176  }
std::string id(RTLIL::IdString internal_id, bool may_rename=true)

+ Here is the call graph for this function:

bool RTLIL::IdString::operator== ( IdString  rhs) const
inline

Definition at line 190 of file rtlil.h.

190 { return index_ == rhs.index_; }
bool RTLIL::IdString::operator== ( const std::string &  rhs) const
inline

Definition at line 195 of file rtlil.h.

195 { return str() == rhs; }
std::string str() const
Definition: rtlil.h:182

+ Here is the call graph for this function:

bool RTLIL::IdString::operator== ( const char *  rhs) const
inline

Definition at line 198 of file rtlil.h.

198 { return strcmp(c_str(), rhs) == 0; }
const char * c_str() const
Definition: rtlil.h:178

+ Here is the call graph for this function:

char RTLIL::IdString::operator[] ( size_t  i) const
inline

Definition at line 201 of file rtlil.h.

201  {
202  const char *p = c_str();
203  for (; i != 0; i--, p++)
204  log_assert(*p != 0);
205  return *p;
206  }
const char * c_str() const
Definition: rtlil.h:178
#define log_assert(_assert_expr_)
Definition: log.h:85

+ Here is the call graph for this function:

static void RTLIL::IdString::put_reference ( int  idx)
inlinestatic

Definition at line 135 of file rtlil.h.

136  {
137  // put_reference() may be called from destructors after the destructor of
138  // global_refcount_storage_ has been run. in this case we simply do nothing.
139  if (!destruct_guard.ok)
140  return;
141 
143 
144  if (--global_refcount_storage_.at(idx) != 0)
145  return;
146 
149  global_id_storage_.at(idx) = nullptr;
150  global_free_idx_list_.push_back(idx);
151  }
void free(void *)
static std::string idx(std::string str)
Definition: test_autotb.cc:57
static std::vector< int > global_free_idx_list_
Definition: rtlil.h:97
#define log_assert(_assert_expr_)
Definition: log.h:85
static std::vector< char * > global_id_storage_
Definition: rtlil.h:95
static std::map< char *, int, char_ptr_cmp > global_id_index_
Definition: rtlil.h:96
static struct RTLIL::IdString::destruct_guard_t destruct_guard
Definition: rtlil.cc:30
static std::vector< int > global_refcount_storage_
Definition: rtlil.h:94

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

size_t RTLIL::IdString::size ( ) const
inline

Definition at line 215 of file rtlil.h.

215  {
216  return str().size();
217  }
std::string str() const
Definition: rtlil.h:182

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

std::string RTLIL::IdString::str ( ) const
inline

Definition at line 182 of file rtlil.h.

182  {
183  return std::string(global_id_storage_.at(index_));
184  }
static std::vector< char * > global_id_storage_
Definition: rtlil.h:95

+ Here is the caller graph for this function:

std::string RTLIL::IdString::substr ( size_t  pos = 0,
size_t  len = std::string::npos 
) const
inline

Definition at line 208 of file rtlil.h.

208  {
209  if (len == std::string::npos || len >= strlen(c_str() + pos))
210  return std::string(c_str() + pos);
211  else
212  return std::string(c_str() + pos, len);
213  }
const char * c_str() const
Definition: rtlil.h:178

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

YOSYS_NAMESPACE_BEGIN RTLIL::IdString::destruct_guard_t RTLIL::IdString::destruct_guard
static

Definition at line 30 of file rtlil.cc.

std::vector< int > RTLIL::IdString::global_free_idx_list_
static

Definition at line 97 of file rtlil.h.

std::map< char *, int, RTLIL::IdString::char_ptr_cmp > RTLIL::IdString::global_id_index_
static

Definition at line 96 of file rtlil.h.

std::vector< char * > RTLIL::IdString::global_id_storage_
static

Definition at line 95 of file rtlil.h.

std::vector< int > RTLIL::IdString::global_refcount_storage_
static

Definition at line 94 of file rtlil.h.

int RTLIL::IdString::index_

Definition at line 155 of file rtlil.h.


The documentation for this struct was generated from the following files: