Permalink
Browse files

Add the lex_strings string handler, and put

 scope names and system task/function names
 into this table. Also, permallocate event
 names from the beginning.
  • Loading branch information...
1 parent 4110981 commit 4c67de5ca7044096913e851049f067e53050c196 steve committed Mar 1, 2003
Showing with 274 additions and 141 deletions.
  1. +10 −4 PEvent.cc
  2. +11 −4 PEvent.h
  3. +65 −2 StringHeap.cc
  4. +42 −2 StringHeap.h
  5. +11 −1 compiler.h
  6. +9 −3 elaborate.cc
  7. +23 −83 main.cc
  8. +14 −6 net_event.cc
  9. +11 −5 net_expr.cc
  10. +12 −7 net_scope.cc
  11. +12 −5 netlist.cc
  12. +18 −9 netlist.h
  13. +8 −2 pform.cc
  14. +9 −2 t-dll-expr.cc
  15. +9 −2 t-dll-proc.cc
  16. +10 −4 t-dll.h
View
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 200Stephen Williams (steve@icarus.com)
+ * Copyright (c) 2003 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@@ -17,14 +17,14 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: PEvent.cc,v 1.3 2002/08/12 01:34:58 steve Exp $"
+#ident "$Id: PEvent.cc,v 1.4 2003/03/01 06:25:30 steve Exp $"
#endif
# include "config.h"
# include "PEvent.h"
-PEvent::PEvent(const string&n)
+PEvent::PEvent(const char*n)
: name_(n)
{
}
@@ -33,13 +33,19 @@ PEvent::~PEvent()
{
}
-string PEvent::name() const
+const char* PEvent::name() const
{
return name_;
}
/*
* $Log: PEvent.cc,v $
+ * Revision 1.4 2003/03/01 06:25:30 steve
+ * Add the lex_strings string handler, and put
+ * scope names and system task/function names
+ * into this table. Also, permallocate event
+ * names from the beginning.
+ *
* Revision 1.3 2002/08/12 01:34:58 steve
* conditional ident string using autoconfig.
*
View
@@ -19,7 +19,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: PEvent.h,v 1.7 2003/01/30 16:23:07 steve Exp $"
+#ident "$Id: PEvent.h,v 1.8 2003/03/01 06:25:30 steve Exp $"
#endif
# include "LineInfo.h"
@@ -36,15 +36,16 @@ class NetScope;
class PEvent : public LineInfo {
public:
- explicit PEvent(const string&name);
+ // The name is a perm-allocated string.
+ explicit PEvent(const char*name);
~PEvent();
- string name() const;
+ const char* name() const;
void elaborate_scope(Design*des, NetScope*scope) const;
private:
- string name_;
+ const char* name_;
private: // not implemented
PEvent(const PEvent&);
@@ -53,6 +54,12 @@ class PEvent : public LineInfo {
/*
* $Log: PEvent.h,v $
+ * Revision 1.8 2003/03/01 06:25:30 steve
+ * Add the lex_strings string handler, and put
+ * scope names and system task/function names
+ * into this table. Also, permallocate event
+ * names from the beginning.
+ *
* Revision 1.7 2003/01/30 16:23:07 steve
* Spelling fixes.
*
View
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2002 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 2002-2003 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: StringHeap.cc,v 1.4 2003/01/27 05:09:17 steve Exp $"
+#ident "$Id: StringHeap.cc,v 1.5 2003/03/01 06:25:30 steve Exp $"
#endif
# include "StringHeap.h"
@@ -64,8 +64,71 @@ const char* StringHeap::add(const char*text)
return res;
}
+
+StringHeapLex::StringHeapLex()
+{
+ hit_count_ = 0;
+ add_count_ = 0;
+
+ for (unsigned idx = 0 ; idx < HASH_SIZE ; idx += 1)
+ hash_table_[idx] = 0;
+}
+
+StringHeapLex::~StringHeapLex()
+{
+}
+
+unsigned StringHeapLex::add_hit_count() const
+{
+ return hit_count_;
+}
+
+unsigned StringHeapLex::add_count() const
+{
+ return add_count_;
+}
+
+static unsigned hash_string(const char*text)
+{
+ unsigned h = 0;
+
+ while (*text) {
+ h = (h << 4) ^ (h >> 28) ^ *text;
+ text += 1;
+ }
+ return h;
+}
+
+const char* StringHeapLex::add(const char*text)
+{
+ unsigned hash_value = hash_string(text) % HASH_SIZE;
+
+ /* If we easily find the string in the hash table, then return
+ that and be done. */
+ if (hash_table_[hash_value]
+ && (strcmp(hash_table_[hash_value], text) == 0)) {
+ hit_count_ += 1;
+ return hash_table_[hash_value];
+ }
+
+ /* The existing hash entry is not a match. Replace it with the
+ newly allocated value, and return the new pointer as the
+ result to the add. */
+ const char*res = StringHeap::add(text);
+ hash_table_[hash_value] = res;
+ add_count_ += 1;
+
+ return res;
+}
+
/*
* $Log: StringHeap.cc,v $
+ * Revision 1.5 2003/03/01 06:25:30 steve
+ * Add the lex_strings string handler, and put
+ * scope names and system task/function names
+ * into this table. Also, permallocate event
+ * names from the beginning.
+ *
* Revision 1.4 2003/01/27 05:09:17 steve
* Spelling fixes.
*
View
@@ -1,7 +1,7 @@
#ifndef __StringHeap_H
#define __StringHeap_H
/*
- * Copyright (c) 2002 Stephen Williams (steve@icarus.com)
+ * Copyright (c) 2002-2003 Stephen Williams (steve@icarus.com)
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
@@ -19,9 +19,14 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: StringHeap.h,v 1.3 2003/01/16 21:44:46 steve Exp $"
+#ident "$Id: StringHeap.h,v 1.4 2003/03/01 06:25:30 steve Exp $"
#endif
+/*
+ * The string heap is a way to permanently allocate strings
+ * efficiently. They only take up the space of the string characters
+ * and the terminating nul, there is no malloc overhead.
+ */
class StringHeap {
public:
@@ -43,7 +48,42 @@ class StringHeap {
};
/*
+ * A lexical string heap is a string heap that makes an effort to
+ * return the same pointer for identical strings. This saves further
+ * space by not allocating duplicate strings, so in a system with lots
+ * of identifiers, this can theoretically save more space.
+ */
+class StringHeapLex : private StringHeap {
+
+ public:
+ StringHeapLex();
+ ~StringHeapLex();
+
+ const char*add(const char*);
+
+ unsigned add_count() const;
+ unsigned add_hit_count() const;
+
+ private:
+ enum { HASH_SIZE = 4096 };
+ const char*hash_table_[HASH_SIZE];
+
+ unsigned add_count_;
+ unsigned hit_count_;
+
+ private: // not implemented
+ StringHeapLex(const StringHeapLex&);
+ StringHeapLex& operator= (const StringHeapLex&);
+};
+
+/*
* $Log: StringHeap.h,v $
+ * Revision 1.4 2003/03/01 06:25:30 steve
+ * Add the lex_strings string handler, and put
+ * scope names and system task/function names
+ * into this table. Also, permallocate event
+ * names from the beginning.
+ *
* Revision 1.3 2003/01/16 21:44:46 steve
* Keep some debugging status.
*
View
@@ -19,10 +19,11 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: compiler.h,v 1.15 2003/02/22 04:12:49 steve Exp $"
+#ident "$Id: compiler.h,v 1.16 2003/03/01 06:25:30 steve Exp $"
#endif
# include <list>
+# include "StringHeap.h"
/*
* This defines constants and defaults for the compiler in general.
@@ -96,8 +97,17 @@ extern generation_t generation_flag;
/* This is the string to use to invoke the preprocessor. */
extern char*ivlpp_string;
+
+extern StringHeapLex lex_strings;
+
/*
* $Log: compiler.h,v $
+ * Revision 1.16 2003/03/01 06:25:30 steve
+ * Add the lex_strings string handler, and put
+ * scope names and system task/function names
+ * into this table. Also, permallocate event
+ * names from the beginning.
+ *
* Revision 1.15 2003/02/22 04:12:49 steve
* Add the portbind warning.
*
View
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#ifdef HAVE_CVS_IDENT
-#ident "$Id: elaborate.cc,v 1.274 2003/02/22 04:12:49 steve Exp $"
+#ident "$Id: elaborate.cc,v 1.275 2003/03/01 06:25:30 steve Exp $"
#endif
# include "config.h"
@@ -1806,7 +1806,7 @@ NetProc* PEventStatement::elaborate_st(Design*des, NetScope*scope,
/* Create a NetEvent object to manage this event. Note
that the NetEvent object's name has no hierarchy. */
- NetEvent*ev = new NetEvent(scope->local_symbol());
+ NetEvent*ev = new NetEvent(lex_strings.add(scope->local_symbol().c_str()));
scope->add_event(ev);
NetEvWait*we = new NetEvWait(0);
@@ -1866,7 +1866,7 @@ NetProc* PEventStatement::elaborate_st(Design*des, NetScope*scope,
list. The NetEvProbe objects all refer back to the NetEvent
object. */
- NetEvent*ev = new NetEvent(scope->local_symbol());
+ NetEvent*ev = new NetEvent(lex_strings.add(scope->local_symbol().c_str()));
ev->set_line(*this);
unsigned expr_count = 0;
@@ -2502,6 +2502,12 @@ Design* elaborate(list<const char*>roots)
/*
* $Log: elaborate.cc,v $
+ * Revision 1.275 2003/03/01 06:25:30 steve
+ * Add the lex_strings string handler, and put
+ * scope names and system task/function names
+ * into this table. Also, permallocate event
+ * names from the beginning.
+ *
* Revision 1.274 2003/02/22 04:12:49 steve
* Add the portbind warning.
*
Oops, something went wrong.

0 comments on commit 4c67de5

Please sign in to comment.