2014-07-23 22:39:29 +02:00
|
|
|
#ifndef IVL_PGate_H
|
|
|
|
|
#define IVL_PGate_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
|
|
|
*/
|
|
|
|
|
|
2004-02-18 18:11:54 +01:00
|
|
|
# include "StringHeap.h"
|
2000-01-09 06:50:48 +01:00
|
|
|
# include "named.h"
|
2019-09-24 00:17:31 +02:00
|
|
|
# include "PNamedItem.h"
|
1999-09-04 21:11:45 +02:00
|
|
|
# include "PDelays.h"
|
2007-09-10 06:14:52 +02:00
|
|
|
# include "netlist.h"
|
1999-12-11 06:45:41 +01:00
|
|
|
# include <map>
|
2010-10-26 04:36:44 +02:00
|
|
|
# include <list>
|
|
|
|
|
# include <vector>
|
1999-12-11 06:45:41 +01:00
|
|
|
# include <string>
|
1998-11-04 00:28:49 +01:00
|
|
|
class PExpr;
|
1998-12-01 01:42:13 +01:00
|
|
|
class PUdp;
|
1999-02-15 03:06:15 +01:00
|
|
|
class Module;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* A PGate represents a Verilog gate. The gate has a name and other
|
|
|
|
|
* properties, and a set of pins that connect to wires. It is known at
|
|
|
|
|
* the time a gate is constructed how many pins the gate has.
|
|
|
|
|
*
|
|
|
|
|
* This pins of a gate are connected to expressions. The elaboration
|
|
|
|
|
* step will need to convert expressions to a network of gates in
|
|
|
|
|
* order to elaborate expression inputs, but that can easily be done.
|
2000-05-06 17:41:56 +02:00
|
|
|
*
|
|
|
|
|
* The PGate base class also carries the strength0 and strength1
|
|
|
|
|
* strengths for those gates where the driver[s] can be described by a
|
|
|
|
|
* single strength pair. There is a strength of the 0 drive, and a
|
|
|
|
|
* strength of the 1 drive.
|
1998-11-04 00:28:49 +01:00
|
|
|
*/
|
2019-09-24 00:17:31 +02:00
|
|
|
class PGate : public PNamedItem {
|
2004-10-04 03:10:51 +02:00
|
|
|
|
1998-11-04 00:28:49 +01:00
|
|
|
public:
|
2021-11-04 17:12:04 +01:00
|
|
|
explicit PGate(perm_string name, std::list<PExpr*>*pins,
|
|
|
|
|
const std::list<PExpr*>*del);
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
explicit PGate(perm_string name, std::list<PExpr*>*pins,
|
1999-08-01 18:34:50 +02:00
|
|
|
PExpr*del);
|
|
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
explicit PGate(perm_string name, std::list<PExpr*>*pins);
|
1999-08-01 18:34:50 +02:00
|
|
|
|
2025-10-13 22:14:57 +02:00
|
|
|
virtual ~PGate() override;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2021-11-06 01:02:38 +01:00
|
|
|
void set_ranges(std::list<pform_range_t>*ranges);
|
|
|
|
|
bool is_array() const { return ranges_ != 0; }
|
|
|
|
|
|
2004-02-18 18:11:54 +01:00
|
|
|
perm_string get_name() const { return name_; }
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2006-01-02 06:33:19 +01:00
|
|
|
// This evaluates the delays as far as possible, but returns
|
|
|
|
|
// an expression, and do not signal errors.
|
|
|
|
|
void eval_delays(Design*des, NetScope*scope,
|
|
|
|
|
NetExpr*&rise_time,
|
|
|
|
|
NetExpr*&fall_time,
|
2006-01-03 06:22:14 +01:00
|
|
|
NetExpr*&decay_time,
|
|
|
|
|
bool as_net_flag =false) const;
|
2006-01-02 06:33:19 +01:00
|
|
|
|
2010-07-13 19:01:32 +02:00
|
|
|
unsigned delay_count() const;
|
|
|
|
|
|
2010-10-26 04:36:44 +02:00
|
|
|
unsigned pin_count() const { return pins_.size(); }
|
|
|
|
|
PExpr*pin(unsigned idx) const { return pins_[idx]; }
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2010-03-16 23:16:53 +01:00
|
|
|
ivl_drive_t strength0() const;
|
|
|
|
|
ivl_drive_t strength1() const;
|
2000-05-06 17:41:56 +02:00
|
|
|
|
2010-03-16 23:16:53 +01:00
|
|
|
void strength0(ivl_drive_t);
|
|
|
|
|
void strength1(ivl_drive_t);
|
2000-05-06 17:41:56 +02:00
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
std::map<perm_string,PExpr*> attributes;
|
1999-12-11 06:45:41 +01:00
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
virtual void dump(std::ostream&out, unsigned ind =4) const;
|
2001-11-22 07:20:59 +01:00
|
|
|
virtual void elaborate(Design*des, NetScope*scope) const;
|
2000-03-08 05:36:53 +01:00
|
|
|
virtual void elaborate_scope(Design*des, NetScope*sc) const;
|
2000-05-02 18:27:38 +02:00
|
|
|
virtual bool elaborate_sig(Design*des, NetScope*scope) const;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2025-10-13 22:14:57 +02:00
|
|
|
SymbolType symbol_type() const override;
|
2019-09-24 00:17:31 +02:00
|
|
|
|
1998-11-04 00:28:49 +01:00
|
|
|
protected:
|
2021-11-04 17:12:04 +01:00
|
|
|
const std::vector<PExpr*>& get_pins() const { return pins_; }
|
1999-05-29 04:36:17 +02:00
|
|
|
|
2021-11-06 01:02:38 +01:00
|
|
|
unsigned calculate_array_size_(Design*, NetScope*,
|
|
|
|
|
long&high, long&low) const;
|
|
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
void dump_pins(std::ostream&out) const;
|
|
|
|
|
void dump_delays(std::ostream&out) const;
|
2021-11-06 01:02:38 +01:00
|
|
|
void dump_ranges(std::ostream&out) const;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
|
|
|
|
private:
|
2004-02-18 18:11:54 +01:00
|
|
|
perm_string name_;
|
1999-09-04 21:11:45 +02:00
|
|
|
PDelays delay_;
|
2021-11-04 17:12:04 +01:00
|
|
|
std::vector<PExpr*>pins_;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2021-11-06 01:02:38 +01:00
|
|
|
std::list<pform_range_t>*ranges_;
|
|
|
|
|
|
2010-03-16 23:16:53 +01:00
|
|
|
ivl_drive_t str0_, str1_;
|
2000-05-06 17:41:56 +02:00
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
void set_pins_(std::list<PExpr*>*pins);
|
2010-10-26 04:36:44 +02:00
|
|
|
|
1998-11-04 00:28:49 +01:00
|
|
|
private: // not implemented
|
|
|
|
|
PGate(const PGate&);
|
|
|
|
|
PGate& operator= (const PGate&);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* A continuous assignment has a single output and a single input. The
|
|
|
|
|
input is passed directly to the output. This is different from a
|
|
|
|
|
BUF because elaboration may need to turn this into a vector of
|
|
|
|
|
gates. */
|
|
|
|
|
class PGAssign : public PGate {
|
|
|
|
|
|
|
|
|
|
public:
|
2021-11-04 17:12:04 +01:00
|
|
|
explicit PGAssign(std::list<PExpr*>*pins);
|
|
|
|
|
explicit PGAssign(std::list<PExpr*>*pins, std::list<PExpr*>*dels);
|
2025-10-13 22:14:57 +02:00
|
|
|
~PGAssign() override;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2025-10-13 22:14:57 +02:00
|
|
|
void dump(std::ostream&out, unsigned ind =4) const override;
|
|
|
|
|
virtual void elaborate(Design*des, NetScope*scope) const override;
|
|
|
|
|
virtual bool elaborate_sig(Design*des, NetScope*scope) const override;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
|
|
|
|
private:
|
2014-03-17 01:08:38 +01:00
|
|
|
void elaborate_unpacked_array_(Design*des, NetScope*scope, NetNet*lval) const;
|
1998-11-04 00:28:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
1999-02-15 03:06:15 +01:00
|
|
|
/*
|
|
|
|
|
* The Builtin class is specifically a gate with one of the builtin
|
|
|
|
|
* types. The parser recognizes these types during parse. These types
|
|
|
|
|
* have special properties that allow them to be treated specially.
|
|
|
|
|
*
|
|
|
|
|
* A PGBuiltin can be grouped into an array of devices. If this is
|
|
|
|
|
* done, the msb_ and lsb_ are set to the indices of the array
|
|
|
|
|
* range. Elaboration causes a gate to be created for each element of
|
|
|
|
|
* the array, and a name will be generated for each gate.
|
|
|
|
|
*/
|
1998-11-04 00:28:49 +01:00
|
|
|
class PGBuiltin : public PGate {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
enum Type { AND, NAND, OR, NOR, XOR, XNOR, BUF, BUFIF0, BUFIF1,
|
|
|
|
|
NOT, NOTIF0, NOTIF1, PULLDOWN, PULLUP, NMOS, RNMOS,
|
|
|
|
|
PMOS, RPMOS, CMOS, RCMOS, TRAN, RTRAN, TRANIF0,
|
|
|
|
|
TRANIF1, RTRANIF0, RTRANIF1 };
|
|
|
|
|
|
|
|
|
|
public:
|
2004-02-18 18:11:54 +01:00
|
|
|
explicit PGBuiltin(Type t, perm_string name,
|
2021-11-04 17:12:04 +01:00
|
|
|
std::list<PExpr*>*pins,
|
2025-10-23 18:58:49 +02:00
|
|
|
const std::list<PExpr*>*del);
|
2004-02-18 18:11:54 +01:00
|
|
|
explicit PGBuiltin(Type t, perm_string name,
|
2021-11-04 17:12:04 +01:00
|
|
|
std::list<PExpr*>*pins,
|
1999-08-01 18:34:50 +02:00
|
|
|
PExpr*del);
|
2025-10-13 22:14:57 +02:00
|
|
|
~PGBuiltin() override;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
|
|
|
|
Type type() const { return type_; }
|
2010-07-13 19:01:32 +02:00
|
|
|
const char * gate_name() const;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2025-10-13 22:14:57 +02:00
|
|
|
virtual void dump(std::ostream&out, unsigned ind =4) const override;
|
|
|
|
|
virtual void elaborate(Design*, NetScope*scope) const override;
|
|
|
|
|
virtual bool elaborate_sig(Design*des, NetScope*scope) const override;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
|
|
|
|
private:
|
2011-06-09 09:39:03 +02:00
|
|
|
void calculate_gate_and_lval_count_(unsigned&gate_count,
|
|
|
|
|
unsigned&lval_count) const;
|
1999-02-15 03:06:15 +01:00
|
|
|
|
2008-09-15 06:04:03 +02:00
|
|
|
NetNode* create_gate_for_output_(Design*, NetScope*,
|
|
|
|
|
perm_string gate_name,
|
|
|
|
|
unsigned instance_width) const;
|
|
|
|
|
|
2010-07-13 19:01:32 +02:00
|
|
|
bool check_delay_count(Design*des) const;
|
|
|
|
|
|
2008-09-15 06:04:03 +02:00
|
|
|
Type type_;
|
1998-11-04 00:28:49 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This kind of gate is an instantiation of a module. The stored type
|
1998-12-01 01:42:13 +01:00
|
|
|
* is the name of a module definition somewhere in the pform. This
|
1999-05-29 04:36:17 +02:00
|
|
|
* type also handles UDP devices, because it is generally not known at
|
1998-12-01 01:42:13 +01:00
|
|
|
* parse time whether a name belongs to a module or a UDP.
|
1998-11-04 00:28:49 +01:00
|
|
|
*/
|
|
|
|
|
class PGModule : public PGate {
|
|
|
|
|
|
|
|
|
|
public:
|
2004-02-18 18:11:54 +01:00
|
|
|
// The name is the *instance* name of the gate.
|
2003-03-06 05:37:12 +01:00
|
|
|
|
1999-05-29 04:36:17 +02:00
|
|
|
// If the binding of ports is by position, this constructor
|
|
|
|
|
// builds everything all at once.
|
2004-02-18 18:11:54 +01:00
|
|
|
explicit PGModule(perm_string type, perm_string name,
|
2021-11-04 17:12:04 +01:00
|
|
|
std::list<PExpr*>*pins);
|
1999-05-29 04:36:17 +02:00
|
|
|
|
|
|
|
|
// If the binding of ports is by name, this constructor takes
|
|
|
|
|
// the bindings and stores them for later elaboration.
|
2004-02-18 18:11:54 +01:00
|
|
|
explicit PGModule(perm_string type, perm_string name,
|
2023-01-03 03:43:03 +01:00
|
|
|
named_pexpr_t *pins, unsigned npins);
|
2000-01-09 06:50:48 +01:00
|
|
|
|
2012-05-10 04:35:11 +02:00
|
|
|
// If the module type is known by design, then use this
|
|
|
|
|
// constructor.
|
|
|
|
|
explicit PGModule(Module*type, perm_string name);
|
2000-01-09 06:50:48 +01:00
|
|
|
|
2025-10-13 22:14:57 +02:00
|
|
|
~PGModule() override;
|
2001-10-21 02:42:47 +02:00
|
|
|
|
2000-01-09 06:50:48 +01:00
|
|
|
// Parameter overrides can come as an ordered list, or a set
|
|
|
|
|
// of named expressions.
|
2021-11-04 17:12:04 +01:00
|
|
|
void set_parameters(std::list<PExpr*>*o);
|
2023-01-03 03:43:03 +01:00
|
|
|
void set_parameters(named_pexpr_t *pa, unsigned npa);
|
1999-05-29 04:36:17 +02:00
|
|
|
|
2021-11-04 17:12:04 +01:00
|
|
|
std::map<perm_string,PExpr*> attributes;
|
2017-03-16 15:41:10 +01:00
|
|
|
|
2025-10-13 22:14:57 +02:00
|
|
|
virtual void dump(std::ostream&out, unsigned ind =4) const override;
|
|
|
|
|
virtual void elaborate(Design*, NetScope*scope) const override;
|
|
|
|
|
virtual void elaborate_scope(Design*des, NetScope*sc) const override;
|
|
|
|
|
virtual bool elaborate_sig(Design*des, NetScope*scope) const override;
|
1998-11-04 00:28:49 +01:00
|
|
|
|
2003-03-06 05:37:12 +01:00
|
|
|
// This returns the module name of this module. It is a
|
|
|
|
|
// permallocated string.
|
2010-07-24 00:58:00 +02:00
|
|
|
perm_string get_type() const;
|
2001-10-19 03:55:32 +02:00
|
|
|
|
1998-11-04 00:28:49 +01:00
|
|
|
private:
|
2012-05-10 04:35:11 +02:00
|
|
|
Module*bound_type_;
|
2004-02-18 18:11:54 +01:00
|
|
|
perm_string type_;
|
2021-11-04 17:12:04 +01:00
|
|
|
std::list<PExpr*>*overrides_;
|
2023-01-03 03:43:03 +01:00
|
|
|
named_pexpr_t *pins_;
|
1999-05-29 04:36:17 +02:00
|
|
|
unsigned npins_;
|
1998-12-01 01:42:13 +01:00
|
|
|
|
2000-01-09 06:50:48 +01:00
|
|
|
// These members support parameter override by name
|
2023-01-03 03:43:03 +01:00
|
|
|
named_pexpr_t *parms_;
|
2000-01-09 06:50:48 +01:00
|
|
|
unsigned nparms_;
|
|
|
|
|
|
2008-06-25 07:03:28 +02:00
|
|
|
friend class delayed_elaborate_scope_mod_instances;
|
2001-11-22 07:20:59 +01:00
|
|
|
void elaborate_mod_(Design*, Module*mod, NetScope*scope) const;
|
|
|
|
|
void elaborate_udp_(Design*, PUdp *udp, NetScope*scope) const;
|
2000-03-08 05:36:53 +01:00
|
|
|
void elaborate_scope_mod_(Design*des, Module*mod, NetScope*sc) const;
|
2008-06-25 07:03:28 +02:00
|
|
|
void elaborate_scope_mod_instances_(Design*des, Module*mod, NetScope*sc) const;
|
2025-10-23 18:58:49 +02:00
|
|
|
bool elaborate_sig_mod_(Design*des, NetScope*scope, const Module*mod) const;
|
2010-11-01 22:37:06 +01:00
|
|
|
// Not currently used.
|
|
|
|
|
#if 0
|
2008-03-21 05:44:35 +01:00
|
|
|
bool elaborate_sig_udp_(Design*des, NetScope*scope, PUdp*udp) const;
|
2010-11-01 22:37:06 +01:00
|
|
|
#endif
|
2007-09-10 06:14:52 +02:00
|
|
|
|
|
|
|
|
NetNet*resize_net_to_port_(Design*des, NetScope*scope,
|
|
|
|
|
NetNet*sig, unsigned port_wid,
|
2008-10-03 03:38:53 +02:00
|
|
|
NetNet::PortType dir, bool as_signed) const;
|
1998-11-04 00:28:49 +01:00
|
|
|
};
|
|
|
|
|
|
2014-07-23 22:39:29 +02:00
|
|
|
#endif /* IVL_PGate_H */
|