Permalink
Browse files

Parser and pform use hierarchical names as hname_t

 objects instead of encoded strings.
  • Loading branch information...
1 parent 33c7c47 commit ab6c8cb4b883846f83b388c158a49bd014a39e6d steve committed Dec 3, 2001
Showing with 963 additions and 561 deletions.
  1. +257 −0 HName.cc
  2. +86 −0 HName.h
  3. +3 −3 Makefile.in
  4. +9 −5 Module.cc
  5. +10 −5 Module.h
  6. +7 −2 PEvent.h
  7. +21 −14 PExpr.cc
  8. +11 −7 PExpr.h
  9. +24 −3 PWire.cc
  10. +16 −5 PWire.h
  11. +14 −5 Statement.cc
  12. +13 −8 Statement.h
  13. +6 −2 design_dump.cc
  14. +9 −5 elab_anet.cc
  15. +29 −25 elab_expr.cc
  16. +9 −5 elab_lval.cc
  17. +28 −22 elab_net.cc
  18. +12 −8 elab_pexpr.cc
  19. +11 −6 elab_scope.cc
  20. +52 −40 elab_sig.cc
  21. +23 −17 elaborate.cc
  22. +7 −3 eval.cc
  23. +8 −3 eval_tree.cc
  24. +1 −14 lexor.lex
  25. +62 −87 net_design.cc
  26. +33 −3 net_scope.cc
  27. +6 −2 netlist.cc
  28. +27 −18 netlist.h
  29. +78 −76 parse.y
  30. +55 −54 pform.cc
  31. +16 −9 pform.h
  32. +15 −10 pform_dump.cc
  33. +0 −74 util.cc
  34. +5 −21 util.h
View
257 HName.cc
@@ -0,0 +1,257 @@
+/*
+ * Copyright (c) 2001 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
+ * 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
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+#if !defined(WINNT)
+#ident "$Id: HName.cc,v 1.1 2001/12/03 04:47:14 steve Exp $"
+#endif
+
+# include "HName.h"
+# include <iostream>
+# include <string.h>
+# include <malloc.h>
+
+hname_t::hname_t()
+{
+ item_ = 0;
+ count_ = 0;
+}
+
+hname_t::hname_t(const char*text)
+{
+ item_ = strdup(text);
+ count_ = 1;
+}
+
+hname_t::hname_t(const hname_t&that)
+{
+ count_ = that.count_;
+ switch (count_) {
+ case 0:
+ item_ = 0;
+ break;
+ case 1:
+ item_ = strdup(that.item_);
+ break;
+ default:
+ array_ = new char*[count_];
+ for (unsigned idx = 0 ; idx < count_ ; idx += 1)
+ array_[idx] = strdup(that.array_[idx]);
+ break;
+ }
+}
+
+hname_t::~hname_t()
+{
+ switch (count_) {
+ case 0:
+ break;
+ case 1:
+ free(item_);
+ break;
+ default:
+ for (unsigned idx = 0 ; idx < count_ ; idx += 1)
+ free(array_[idx]);
+ delete[]array_;
+ break;
+ }
+}
+
+void hname_t::append(const char*text)
+{
+ char**tmp;
+
+ switch (count_) {
+ case 0:
+ count_ = 1;
+ item_ = strdup(text);
+ break;
+ case 1:
+ count_ = 2;
+ tmp = new char*[2];
+ tmp[0] = item_;
+ tmp[1] = strdup(text);
+ array_ = tmp;
+ break;
+ default:
+ tmp = new char*[count_+1];
+ for (unsigned idx = 0 ; idx < count_ ; idx += 1)
+ tmp[idx] = array_[idx];
+ delete[]array_;
+ array_ = tmp;
+ array_[count_] = strdup(text);
+ count_ += 1;
+ }
+}
+
+void hname_t::prepend(const char*text)
+{
+ char**tmp;
+
+ switch (count_) {
+ case 0:
+ count_ = 1;
+ item_ = strdup(text);
+ break;
+ case 1:
+ count_ = 2;
+ tmp = new char*[2];
+ tmp[0] = strdup(text);
+ tmp[1] = item_;
+ array_ = tmp;
+ break;
+ default:
+ tmp = new char*[count_+1];
+ tmp[0] = strdup(text);
+ for (unsigned idx = 0 ; idx < count_ ; idx += 1)
+ tmp[idx+1] = array_[idx];
+ delete[]array_;
+ array_ = tmp;
+ count_ += 1;
+ }
+}
+
+char* hname_t::remove_tail_name()
+{
+ if (count_ == 0)
+ return 0;
+
+ if (count_ == 1) {
+ char*tmp = item_;
+ count_ = 0;
+ item_ = 0;
+ return tmp;
+ }
+
+ if (count_ == 2) {
+ char*tmp1 = array_[0];
+ char*tmp2 = array_[1];
+ delete[]array_;
+ count_ = 1;
+ item_ = tmp1;
+ return tmp2;
+ }
+
+ char*tmpo = array_[count_-1];
+ char**tmpa = new char*[count_-1];
+ for (unsigned idx = 0 ; idx < count_-1 ; idx += 1)
+ tmpa[idx] = array_[idx];
+
+ delete[]array_;
+ array_ = tmpa;
+ count_ -= 1;
+ return tmpo;
+}
+
+const char* hname_t::peek_name(unsigned idx) const
+{
+ if (idx >= count_)
+ return 0;
+
+ if (count_ == 1)
+ return item_;
+
+ return array_[idx];
+}
+
+const char* hname_t::peek_tail_name() const
+{
+ switch (count_) {
+ case 0:
+ return 0;
+ case 1:
+ return item_;
+ default:
+ return array_[count_-1];
+ }
+}
+
+bool operator < (const hname_t&l, const hname_t&r)
+{
+ unsigned idx = 0;
+ const char*lc = l.peek_name(idx);
+ const char*rc = r.peek_name(idx);
+
+ while (lc && rc) {
+ int cmp = strcmp(lc, rc);
+ if (cmp < 0)
+ return true;
+ if (cmp > 0)
+ return false;
+ idx += 1;
+ lc = l.peek_name(idx);
+ rc = r.peek_name(idx);
+ }
+
+ if (lc && !rc)
+ return false;
+ if (rc && !lc)
+ return true;
+
+ // Must be ==
+ return false;
+}
+
+bool operator == (const hname_t&l, const hname_t&r)
+{
+ unsigned idx = 0;
+ const char*lc = l.peek_name(idx);
+ const char*rc = r.peek_name(idx);
+
+ while (lc && rc) {
+ int cmp = strcmp(lc, rc);
+ if (cmp != 0)
+ return false;
+ idx += 1;
+ lc = l.peek_name(idx);
+ rc = r.peek_name(idx);
+ }
+
+ if (lc || rc)
+ return false;
+
+ // Must be ==
+ return true;
+}
+
+ostream& operator<< (ostream&out, const hname_t&that)
+{
+ switch (that.count_) {
+ case 0:
+ out << "";
+ return out;
+ case 1:
+ out << that.item_;
+ return out;
+
+ default:
+ out << that.array_[0];
+ for (unsigned idx = 1 ; idx < that.count_ ; idx += 1)
+ out << "." << that.array_[idx];
+
+ return out;
+ }
+}
+
+/*
+ * $Log: HName.cc,v $
+ * Revision 1.1 2001/12/03 04:47:14 steve
+ * Parser and pform use hierarchical names as hname_t
+ * objects instead of encoded strings.
+ *
+ */
+
View
86 HName.h
@@ -0,0 +1,86 @@
+#ifndef __HName_H
+#define __HName_H
+/*
+ * Copyright (c) 2001 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
+ * 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
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ */
+#if !defined(WINNT)
+#ident "$Id: HName.h,v 1.1 2001/12/03 04:47:14 steve Exp $"
+#endif
+
+#ifdef HAVE_IOSFWD
+# include <iosfwd>
+#else
+class ostream;
+#endif
+
+/*
+ * This class represents a Verilog hierarchical name. A hierarchical
+ * name is an ordered list of simple names.
+ */
+
+class hname_t {
+
+ public:
+ hname_t ();
+ explicit hname_t (const char*text);
+ hname_t (const hname_t&that);
+ ~hname_t();
+
+ // This method adds a name to the end of the hierarchical
+ // path. This becomes a new base name.
+ void append(const char*text);
+
+ // This method adds a name to the *front* of the hierarchical
+ // path. The base name remains the same, unless this is the
+ // only component.
+ void prepend(const char*text);
+
+ // This method removes the tail name from the hierarchy, and
+ // returns a pointer to that tail name. That tail name now
+ // must be removed by the caller.
+ char* remove_tail_name();
+
+ // Return the given component in the hierarchical name. If the
+ // idx is too large, return 0.
+ const char*peek_name(unsigned idx) const;
+ const char*peek_tail_name() const;
+
+ friend ostream& operator<< (ostream&, const hname_t&);
+
+ private:
+ union {
+ char**array_;
+ char* item_;
+ };
+ unsigned count_;
+
+ private: // not implemented
+ hname_t& operator= (const hname_t&);
+};
+
+extern bool operator < (const hname_t&, const hname_t&);
+extern bool operator == (const hname_t&, const hname_t&);
+
+/*
+ * $Log: HName.h,v $
+ * Revision 1.1 2001/12/03 04:47:14 steve
+ * Parser and pform use hierarchical names as hname_t
+ * objects instead of encoded strings.
+ *
+ */
+#endif
View
@@ -16,7 +16,7 @@
# 59 Temple Place - Suite 330
# Boston, MA 02111-1307, USA
#
-#ident "$Id: Makefile.in,v 1.107 2001/10/20 23:02:39 steve Exp $"
+#ident "$Id: Makefile.in,v 1.108 2001/12/03 04:47:14 steve Exp $"
#
#
SHELL = /bin/sh
@@ -120,8 +120,8 @@ net_design.o net_event.o net_force.o net_link.o net_modulo.o net_proc.o \
net_scope.o net_udp.o pad_to_width.o \
parse.o parse_misc.o pform.o pform_dump.o \
set_width.o \
-verinum.o verireal.o target.o targets.o util.o \
-Attrib.o LineInfo.o Module.o PDelays.o PEvent.o \
+verinum.o verireal.o target.o targets.o \
+Attrib.o HName.o LineInfo.o Module.o PDelays.o PEvent.o \
PExpr.o PGate.o \
PTask.o PFunction.o PWire.o Statement.o \
$(FF) $(TT)
Oops, something went wrong.

0 comments on commit ab6c8cb

Please sign in to comment.