2014-07-23 22:39:29 +02:00
|
|
|
#ifndef IVL_Module_H
|
|
|
|
|
#define IVL_Module_H
|
1998-11-04 00:28:49 +01:00
|
|
|
/*
|
2025-10-13 22:14:57 +02:00
|
|
|
* Copyright (c) 1998-2025 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
|
2012-08-29 03:41:23 +02:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
1998-11-04 00:28:49 +01:00
|
|
|
*/
|
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"
|
2019-09-24 00:17:31 +02:00
|
|
|
# include "PNamedItem.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;
|
2015-01-10 12:09:42 +01:00
|
|
|
class PModport;
|
2006-09-23 06:57:19 +02:00
|
|
|
class PSpecPath;
|
2023-07-05 16:22:08 +02:00
|
|
|
class PTimingCheck;
|
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.
|
2014-12-20 00:10:14 +01:00
|
|
|
*
|
|
|
|
|
* SystemVerilog introduces program blocks and interfaces. These have
|
|
|
|
|
* much in common with modules, so the Module class is used to represent
|
|
|
|
|
* these containers as well.
|
1998-11-04 00:28:49 +01:00
|
|
|
*/
|
|
|
|
|
|
2019-09-24 00:17:31 +02:00
|
|
|
class Module : public PScopeExtra, public PNamedItem {
|
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
|
2021-03-10 09:21:42 +01:00
|
|
|
the port. In SystemVerilog, input ports may also have a
|
|
|
|
|
default value. */
|
1999-08-03 06:14:49 +02:00
|
|
|
public:
|
|
|
|
|
struct port_t {
|
2004-02-20 07:22:56 +01:00
|
|
|
perm_string name;
|
2021-11-04 17:12:04 +01:00
|
|
|
std::vector<PEIdent*> expr;
|
2021-03-10 09:21:42 +01:00
|
|
|
PExpr*default_value;
|
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
|
2015-01-10 12:09:42 +01:00
|
|
|
name. This name must be a permallocated string. */
|
2012-05-10 04:35:11 +02:00
|
|
|
explicit Module(LexicalScope*parent, perm_string name);
|
2025-10-13 22:14:57 +02:00
|
|
|
~Module() override;
|
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;
|
|
|
|
|
|
2014-12-20 00:10:14 +01:00
|
|
|
/* This is true if the module represents a interface
|
|
|
|
|
instead of a module/cell. Interfaces have different
|
|
|
|
|
content restrictions and some extra allowed items. */
|
|
|
|
|
bool is_interface;
|
|
|
|
|
|
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. */
|
2021-11-04 17:12:04 +01:00
|
|
|
std::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. */
|
2021-11-04 17:12:04 +01:00
|
|
|
typedef std::pair<pform_name_t,PExpr*> named_expr_t;
|
|
|
|
|
std::list<named_expr_t>defparms;
|
|
|
|
|
static std::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. */
|
2021-11-04 17:12:04 +01:00
|
|
|
std::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. */
|
2021-11-04 17:12:04 +01:00
|
|
|
std::vector<port_t*> ports;
|
2002-05-20 01:37:28 +02:00
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
std::map<perm_string,PExpr*> attributes;
|
2003-06-20 02:53:19 +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. */
|
2021-11-04 17:12:04 +01:00
|
|
|
std::list<PGenerate*> generate_schemes;
|
2006-04-10 02:37:42 +02:00
|
|
|
|
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;
|
|
|
|
|
|
2015-01-10 12:09:42 +01:00
|
|
|
/* An interface can contain one or more named modport lists.
|
|
|
|
|
The parser will ensure these don't appear in modules or
|
|
|
|
|
program blocks. */
|
2021-11-04 17:12:04 +01:00
|
|
|
std::map<perm_string,PModport*> modports;
|
2015-01-10 12:09:42 +01:00
|
|
|
|
2023-07-05 16:22:08 +02:00
|
|
|
/* List for specify paths and timing checks */
|
2021-11-04 17:12:04 +01:00
|
|
|
std::list<PSpecPath*> specify_paths;
|
2023-07-05 16:22:08 +02:00
|
|
|
std::list<PTimingCheck*> timing_checks;
|
2006-09-23 06:57:19 +02:00
|
|
|
|
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;
|
2021-11-04 17:12:04 +01:00
|
|
|
const std::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;
|
|
|
|
|
|
2021-03-10 09:21:42 +01:00
|
|
|
PExpr* get_port_default_value(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
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
const std::list<PGate*>& get_gates() const;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
void dump(std::ostream&out) const;
|
2000-03-08 05:36:53 +01:00
|
|
|
bool elaborate(Design*, NetScope*scope) const;
|
|
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
typedef std::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;
|
|
|
|
|
|
2025-10-13 22:14:57 +02:00
|
|
|
SymbolType symbol_type() const override;
|
2019-09-24 00:17:31 +02:00
|
|
|
|
2022-02-10 14:03:46 +01:00
|
|
|
bool can_be_toplevel() const;
|
|
|
|
|
|
1998-11-04 00:28:49 +01:00
|
|
|
private:
|
2021-11-04 17:12:04 +01:00
|
|
|
void dump_specparams_(std::ostream&out, unsigned indent) const;
|
2023-07-05 16:22:08 +02:00
|
|
|
void dump_timingchecks_(std::ostream&out, unsigned indent) const;
|
2021-11-04 17:12:04 +01:00
|
|
|
std::list<PGate*> gates_;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
|
|
|
|
private: // Not implemented
|
|
|
|
|
Module(const Module&);
|
|
|
|
|
Module& operator= (const Module&);
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-23 22:39:29 +02:00
|
|
|
#endif /* IVL_Module_H */
|