1998-11-04 00:28:49 +01:00
|
|
|
#ifndef __Module_H
|
|
|
|
|
#define __Module_H
|
|
|
|
|
/*
|
2012-05-07 00:11:26 +02:00
|
|
|
* Copyright (c) 1998-2010,2012 Stephen Williams (steve@icarus.com)
|
1998-11-04 00:28:49 +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
|
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
|
*/
|
2008-02-25 04:40:54 +01:00
|
|
|
|
1998-11-04 00:28:49 +01:00
|
|
|
|
|
|
|
|
# include <list>
|
1999-02-21 18:01:57 +01:00
|
|
|
# include <map>
|
2008-11-03 05:08:38 +01:00
|
|
|
# include <vector>
|
2008-06-28 18:30:09 +02:00
|
|
|
# include <utility>
|
2004-02-18 18:11:54 +01:00
|
|
|
# include "StringHeap.h"
|
2001-12-03 05:47:14 +01:00
|
|
|
# include "HName.h"
|
2000-01-09 06:50:48 +01:00
|
|
|
# include "named.h"
|
2008-02-14 04:59:05 +01:00
|
|
|
# include "PScope.h"
|
2001-10-31 04:11:15 +01:00
|
|
|
# include "LineInfo.h"
|
2004-06-13 06:56:53 +02:00
|
|
|
# include "netlist.h"
|
2007-05-24 06:07:11 +02:00
|
|
|
# include "pform_types.h"
|
1999-02-21 18:01:57 +01:00
|
|
|
class PExpr;
|
2000-05-16 06:05:15 +02:00
|
|
|
class PEIdent;
|
1998-11-04 00:28:49 +01:00
|
|
|
class PGate;
|
2006-04-10 02:37:42 +02:00
|
|
|
class PGenerate;
|
2006-09-23 06:57:19 +02:00
|
|
|
class PSpecPath;
|
1999-07-03 04:12:51 +02:00
|
|
|
class PTask;
|
1999-07-31 21:14:47 +02:00
|
|
|
class PFunction;
|
1998-11-04 00:28:49 +01:00
|
|
|
class PWire;
|
|
|
|
|
class PProcess;
|
|
|
|
|
class Design;
|
1999-11-27 20:07:57 +01:00
|
|
|
class NetScope;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A module is a named container and scope. A module holds a bunch of
|
|
|
|
|
* semantic quantities such as wires and gates. The module is
|
|
|
|
|
* therefore the handle for grasping the described circuit.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-03-11 21:18:24 +01:00
|
|
|
class Module : public PScopeExtra, public LineInfo {
|
1999-08-03 06:14:49 +02:00
|
|
|
|
|
|
|
|
/* The module ports are in general a vector of port_t
|
|
|
|
|
objects. Each port has a name and an ordered list of
|
|
|
|
|
wires. The name is the means that the outside uses to
|
|
|
|
|
access the port, the wires are the internal connections to
|
|
|
|
|
the port. */
|
|
|
|
|
public:
|
|
|
|
|
struct port_t {
|
2004-02-20 07:22:56 +01:00
|
|
|
perm_string name;
|
2008-11-03 05:08:38 +01:00
|
|
|
vector<PEIdent*> expr;
|
1999-08-03 06:14:49 +02:00
|
|
|
};
|
|
|
|
|
|
1998-11-04 00:28:49 +01:00
|
|
|
public:
|
2003-03-06 05:37:12 +01:00
|
|
|
/* The name passed here is the module name, not the instance
|
|
|
|
|
name. This make must be a permallocated string. */
|
2012-05-10 04:35:11 +02:00
|
|
|
explicit Module(LexicalScope*parent, perm_string name);
|
2001-10-20 07:21:51 +02:00
|
|
|
~Module();
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2007-04-19 04:52:53 +02:00
|
|
|
/* Initially false. This is set to true if the module has been
|
|
|
|
|
declared as a library module. This makes the module
|
|
|
|
|
ineligible for being chosen as an implicit root. It has no
|
|
|
|
|
other effect. */
|
|
|
|
|
bool library_flag;
|
|
|
|
|
|
2009-05-21 23:41:58 +02:00
|
|
|
bool is_cell;
|
|
|
|
|
|
2012-05-01 06:12:59 +02:00
|
|
|
/* This is true if the module represents a program block
|
|
|
|
|
instead of a module/cell. Program blocks have content
|
|
|
|
|
restrictions and slightly modify scheduling semantics. */
|
|
|
|
|
bool program_block;
|
|
|
|
|
|
2009-05-27 22:41:54 +02:00
|
|
|
enum UCDriveType { UCD_NONE, UCD_PULL0, UCD_PULL1 };
|
|
|
|
|
UCDriveType uc_drive;
|
|
|
|
|
|
2012-05-07 00:11:26 +02:00
|
|
|
/* specparams are simpler than other parameters, in that they
|
|
|
|
|
can have a range, but not an explicit type. The restrictions
|
|
|
|
|
are enforced by the parser. */
|
|
|
|
|
map<perm_string,param_expr_t>specparams;
|
2003-02-27 07:45:11 +01:00
|
|
|
|
2000-03-08 05:36:53 +01:00
|
|
|
/* The module also has defparam assignments which don't create
|
|
|
|
|
new parameters within the module, but may be used to set
|
|
|
|
|
values within this module (when instantiated) or in other
|
|
|
|
|
instantiated modules. */
|
2008-06-28 18:30:09 +02:00
|
|
|
typedef pair<pform_name_t,PExpr*> named_expr_t;
|
|
|
|
|
list<named_expr_t>defparms;
|
2009-08-06 23:42:13 +02:00
|
|
|
static list<named_expr_t>user_defparms;
|
2000-03-08 05:36:53 +01:00
|
|
|
|
1999-08-23 18:48:39 +02:00
|
|
|
/* Parameters may be overridden at instantiation time;
|
|
|
|
|
the overrides do not contain explicit parameter names,
|
|
|
|
|
but rather refer to parameters in the order they
|
|
|
|
|
appear in the instantiated module. Therefore a
|
|
|
|
|
list of names in module-order is needed to pass from
|
|
|
|
|
a parameter-index to its name. */
|
2004-02-20 07:22:56 +01:00
|
|
|
list<perm_string> param_names;
|
1999-08-23 18:48:39 +02:00
|
|
|
|
2002-05-20 01:37:28 +02:00
|
|
|
/* This is an array of port descriptors, which is in turn a
|
|
|
|
|
named array of PEident pointers. */
|
2008-11-03 05:08:38 +01:00
|
|
|
vector<port_t*> ports;
|
2002-05-20 01:37:28 +02:00
|
|
|
|
2004-02-20 19:53:33 +01:00
|
|
|
map<perm_string,PExpr*> attributes;
|
2003-06-20 02:53:19 +02:00
|
|
|
|
2000-07-23 00:09:03 +02:00
|
|
|
/* These are the timescale for this module. The default is
|
|
|
|
|
set by the `timescale directive. */
|
|
|
|
|
int time_unit, time_precision;
|
2009-04-14 03:06:17 +02:00
|
|
|
bool time_from_timescale;
|
2009-05-22 20:03:36 +02:00
|
|
|
bool timescale_warn_done;
|
2000-04-01 21:31:57 +02:00
|
|
|
|
2010-01-12 21:11:01 +01:00
|
|
|
/* The module has a list of generate schemes that appear in
|
2006-04-10 02:37:42 +02:00
|
|
|
the module definition. These are used at elaboration time. */
|
|
|
|
|
list<PGenerate*> generate_schemes;
|
|
|
|
|
|
2012-05-10 04:35:11 +02:00
|
|
|
/* Nested modules are placed here, and are not elaborated
|
|
|
|
|
unless they are instantiated, implicitly or explicitly. */
|
|
|
|
|
std::map<perm_string,Module*> nested_modules;
|
|
|
|
|
|
2006-09-23 06:57:19 +02:00
|
|
|
list<PSpecPath*> specify_paths;
|
|
|
|
|
|
2008-02-14 04:59:05 +01:00
|
|
|
// The mod_name() is the name of the module type.
|
|
|
|
|
perm_string mod_name() const { return pscope_name(); }
|
1998-11-04 00:28:49 +01:00
|
|
|
|
|
|
|
|
void add_gate(PGate*gate);
|
|
|
|
|
|
1999-08-03 06:14:49 +02:00
|
|
|
unsigned port_count() const;
|
2008-11-03 05:08:38 +01:00
|
|
|
const vector<PEIdent*>& get_port(unsigned idx) const;
|
2004-02-20 07:22:56 +01:00
|
|
|
unsigned find_port(const char*name) const;
|
1999-08-03 06:14:49 +02:00
|
|
|
|
2012-06-04 21:43:33 +02:00
|
|
|
// Return port name ("" for undeclared port)
|
|
|
|
|
perm_string get_port_name(unsigned idx) const;
|
|
|
|
|
|
2004-02-18 18:11:54 +01:00
|
|
|
PGate* get_gate(perm_string name);
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2000-03-12 18:09:40 +01:00
|
|
|
const list<PGate*>& get_gates() const;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
1999-07-03 04:12:51 +02:00
|
|
|
void dump(ostream&out) const;
|
2000-03-08 05:36:53 +01:00
|
|
|
bool elaborate(Design*, NetScope*scope) const;
|
|
|
|
|
|
2010-12-05 22:28:17 +01:00
|
|
|
typedef map<perm_string,PExpr*> replace_t;
|
2008-06-28 18:30:09 +02:00
|
|
|
bool elaborate_scope(Design*, NetScope*scope, const replace_t&rep);
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2000-05-02 18:27:38 +02:00
|
|
|
bool elaborate_sig(Design*, NetScope*scope) const;
|
|
|
|
|
|
1998-11-04 00:28:49 +01:00
|
|
|
private:
|
2012-05-07 00:11:26 +02:00
|
|
|
void dump_specparams_(ostream&out, unsigned indent) const;
|
1998-11-04 00:28:49 +01:00
|
|
|
list<PGate*> gates_;
|
|
|
|
|
|
|
|
|
|
private: // Not implemented
|
|
|
|
|
Module(const Module&);
|
|
|
|
|
Module& operator= (const Module&);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|