<commit_before>/*
 * Copyright (c) 1998-2000 <NAME> (<EMAIL>)
 *
 *    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
 */
#ifdef HAVE_CVS_IDENT
#ident "$Id: Module.cc,v 1.20 2003/03/06 04:37:12 steve Exp $"
#endif

# include "config.h"

# include  "Module.h"
# include  "PGate.h"
# include  "PWire.h"
# include  <assert.h>

/* n is a permallocated string. */
Module::Module(const char*n)
: name_(n)
{
}

Module::~Module()
{
}

void Module::add_gate(PGate*gate)
{
      gates_.push_back(gate);
}

void Module::add_task(const string&name, PTask*task)
{
      tasks_[name] = task;
}

void Module::add_function(const string &name, PFunction *func)
{
      funcs_[name] = func;
}

PWire* Module::add_wire(PWire*wire)
{
      PWire*&ep = wires_[wire->path()];
      if (ep) return ep;

      assert(ep == 0);
      ep = wire;
      return wire;
}

void Module::add_behavior(PProcess*b)
{
      behaviors_.push_back(b);
}

unsigned Module::port_count() const
{
      return ports.count();
}

/*
 * Return the array of PEIdent object that are at this port of the
 * module. If the port is internally unconnected, return an empty
 * array. 
 */
const svector<PEIdent*>& Module::get_port(unsigned idx) const
{
      assert(idx < ports.count());
      static svector<PEIdent*> zero;

      if (ports[idx])
	    return ports[idx]->expr;
      else
	    return zero;
}

unsigned Module::find_port(const string&name) const
{
      assert(name != "");
      for (unsigned idx = 0 ;  idx < ports.count() ;  idx += 1)
	    if (ports[idx]->name == name)
		  return idx;

      return ports.count();
}


PWire* Module::get_wire(const hname_t&name) const
{
      map<hname_t,PWire*>::const_iterator obj = wires_.find(name);
      if (obj == wires_.end())
	    return 0;
      else
	    return (*obj).second;
}

PGate* Module::get_gate(const string&name)
{
      for (list<PGate*>::iterator cur = gates_.begin()
		 ; cur != gates_.end()
		 ; cur ++ ) {

	    if ((*cur)->get_name() == name)
		  return *cur;
      }

      return 0;
}

const map<hname_t,PWire*>& Module::get_wires() const
{
      return wires_;
}

const list<PGate*>& Module::get_gates() const
{
      return gates_;
}

const list<PProcess*>& Module::get_behaviors() const
{
      return behaviors_;
}


/*
 * $Log: Module.cc,v $
 * Revision 1.20  2003/03/06 04:37:12  steve
 *  lex_strings.add module names earlier.
 *
 * Revision 1.19  2002/08/12 01:34:58  steve
 *  conditional ident string using autoconfig.
 *
 * Revision 1.18  2002/05/19 23:37:28  steve
 *  Parse port_declaration_lists from the 2001 Standard.
 *
 * Revision 1.17  2001/12/03 04:47:14  steve
 *  Parser and pform use hierarchical names as hname_t
 *  objects instead of encoded strings.
 *
 * Revision 1.16  2001/10/20 05:21:51  steve
 *  Scope/module names are char* instead of string.
 *
 * Revision 1.15  2001/07/25 03:10:48  steve
 *  Create a config.h.in file to hold all the config
 *  junk, and support gcc 3.0. (<NAME>)
 *
 * Revision 1.14  2000/11/15 20:31:05  steve
 *  Fix warning about temporaries.
 *<commit_msg> Cope with empty module ports while binding by name.<commit_after>/*
 * Copyright (c) 1998-2000 <NAME> (<EMAIL>)
 *
 *    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
 */
#ifdef HAVE_CVS_IDENT
#ident "$Id: Module.cc,v 1.21 2003/04/02 03:00:14 steve Exp $"
#endif

# include "config.h"

# include  "Module.h"
# include  "PGate.h"
# include  "PWire.h"
# include  <assert.h>

/* n is a permallocated string. */
Module::Module(const char*n)
: name_(n)
{
}

Module::~Module()
{
}

void Module::add_gate(PGate*gate)
{
      gates_.push_back(gate);
}

void Module::add_task(const string&name, PTask*task)
{
      tasks_[name] = task;
}

void Module::add_function(const string &name, PFunction *func)
{
      funcs_[name] = func;
}

PWire* Module::add_wire(PWire*wire)
{
      PWire*&ep = wires_[wire->path()];
      if (ep) return ep;

      assert(ep == 0);
      ep = wire;
      return wire;
}

void Module::add_behavior(PProcess*b)
{
      behaviors_.push_back(b);
}

unsigned Module::port_count() const
{
      return ports.count();
}

/*
 * Return the array of PEIdent object that are at this port of the
 * module. If the port is internally unconnected, return an empty
 * array. 
 */
const svector<PEIdent*>& Module::get_port(unsigned idx) const
{
      assert(idx < ports.count());
      static svector<PEIdent*> zero;

      if (ports[idx])
	    return ports[idx]->expr;
      else
	    return zero;
}

unsigned Module::find_port(const string&name) const
{
      assert(name != "");
      for (unsigned idx = 0 ;  idx < ports.count() ;  idx += 1) {
	    if (ports[idx] == 0) {
		    /* It is possible to have undeclared ports. These
		       are ports that are skipped in the declaration,
		       for example like so: module foo(x ,, y); The
		       port between x and y is unnamed and thus
		       inaccessible to binding by name. */
		  continue;
	    }
	    assert(ports[idx]);
	    if (ports[idx]->name == name)
		  return idx;
      }

      return ports.count();
}


PWire* Module::get_wire(const hname_t&name) const
{
      map<hname_t,PWire*>::const_iterator obj = wires_.find(name);
      if (obj == wires_.end())
	    return 0;
      else
	    return (*obj).second;
}

PGate* Module::get_gate(const string&name)
{
      for (list<PGate*>::iterator cur = gates_.begin()
		 ; cur != gates_.end()
		 ; cur ++ ) {

	    if ((*cur)->get_name() == name)
		  return *cur;
      }

      return 0;
}

const map<hname_t,PWire*>& Module::get_wires() const
{
      return wires_;
}

const list<PGate*>& Module::get_gates() const
{
      return gates_;
}

const list<PProcess*>& Module::get_behaviors() const
{
      return behaviors_;
}


/*
 * $Log: Module.cc,v $
 * Revision 1.21  2003/04/02 03:00:14  steve
 *  Cope with empty module ports while binding by name.
 *
 * Revision 1.20  2003/03/06 04:37:12  steve
 *  lex_strings.add module names earlier.
 *
 * Revision 1.19  2002/08/12 01:34:58  steve
 *  conditional ident string using autoconfig.
 *
 * Revision 1.18  2002/05/19 23:37:28  steve
 *  Parse port_declaration_lists from the 2001 Standard.
 *
 * Revision 1.17  2001/12/03 04:47:14  steve
 *  Parser and pform use hierarchical names as hname_t
 *  objects instead of encoded strings.
 *
 * Revision 1.16  2001/10/20 05:21:51  steve
 *  Scope/module names are char* instead of string.
 *
 * Revision 1.15  2001/07/25 03:10:48  steve
 *  Create a config.h.in file to hold all the config
 *  junk, and support gcc 3.0. (<NAME>)
 *
 * Revision 1.14  2000/11/15 20:31:05  steve
 *  Fix warning about temporaries.
 *
{'fraction_non_alphanumeric': 0.12203939167289952, 'fraction_numerical': 0.04462727499376714, 'mean_word_length': 3.0115, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4831998', 'n_tokens_mistral': 3009, 'n_tokens_neox': 2667, 'n_words': 856}