Files
iverilog/PWire.h
T

148 lines
4.5 KiB
C++
Raw Normal View History

#ifndef IVL_PWire_H
#define IVL_PWire_H
1998-11-03 23:28:49 +00:00
/*
2025-10-13 13:14:57 -07:00
* Copyright (c) 1998-2025 Stephen Williams ([email protected])
1998-11-03 23:28:49 +00: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-28 18:41:23 -07:00
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1998-11-03 23:28:49 +00:00
*/
# include "netlist.h"
# include "PNamedItem.h"
# include <list>
2001-01-16 02:44:17 +00:00
# include <map>
2007-04-26 03:06:21 +00:00
# include "StringHeap.h"
2001-01-16 02:44:17 +00:00
#ifdef HAVE_IOSFWD
# include <iosfwd>
#else
# include <iostream>
2001-01-16 02:44:17 +00:00
#endif
1998-11-03 23:28:49 +00:00
class PExpr;
class Design;
2012-07-13 18:41:41 -07:00
class netdarray_t;
1998-11-03 23:28:49 +00:00
/*
* The different type of PWire::set_range() calls.
*/
enum PWSRType {SR_PORT, SR_NET, SR_BOTH};
1998-11-03 23:28:49 +00:00
/*
* Wires include nets, registers and ports. A net or register becomes
2003-01-30 16:23:07 +00:00
* a port by declaration, so ports are not separate. The module
1998-11-03 23:28:49 +00:00
* identifies a port by keeping it in its port list.
*
* The hname parameter to the constructor is a hierarchical name. It
* is the name of the wire within a module, so does not include the
* current scope or any instances. Modules contain all the wires, so
* from that perspective, sub-scopes within the module are a part of
* the wire name.
1998-11-03 23:28:49 +00:00
*/
class PWire : public PNamedItem {
1998-11-03 23:28:49 +00:00
public:
2008-02-24 19:40:54 -08:00
PWire(perm_string name,
unsigned lexical_pos,
2005-07-07 16:22:49 +00:00
NetNet::Type t,
NetNet::PortType pt,
2022-03-13 09:50:52 +01:00
PWSRType rt = SR_NET);
1998-11-03 23:28:49 +00:00
// Return a hierarchical name.
2008-02-24 19:40:54 -08:00
perm_string basename() const;
1998-11-03 23:28:49 +00:00
1999-06-17 05:34:42 +00:00
NetNet::Type get_wire_type() const;
bool set_wire_type(NetNet::Type);
NetNet::PortType get_port_type() const;
bool set_port_type(NetNet::PortType);
2022-01-03 21:24:23 +01:00
void set_const(bool is_const) { is_const_ = is_const; };
bool get_const() const { return is_const_; };
2000-12-11 00:31:43 +00:00
void set_signed(bool flag);
bool get_signed() const;
2012-04-10 14:29:28 -07:00
void set_range(const std::list<pform_range_t>&ranges, PWSRType type);
1999-06-17 05:34:42 +00:00
2012-05-25 15:58:29 -07:00
void set_unpacked_idx(const std::list<pform_range_t>&ranges);
2012-11-11 17:42:31 -08:00
void set_data_type(data_type_t*type);
2010-10-31 11:26:09 -07:00
void set_discipline(ivl_discipline_t);
ivl_discipline_t get_discipline(void) const;
2008-05-11 17:30:33 -07:00
std::map<perm_string,PExpr*> attributes;
1998-11-23 00:20:22 +00:00
1998-11-03 23:28:49 +00:00
// Write myself to the specified stream.
void dump(std::ostream&out, unsigned ind=4) const;
1998-11-03 23:28:49 +00:00
NetNet* elaborate_sig(Design*, NetScope*scope);
1998-11-03 23:28:49 +00:00
2025-10-13 13:14:57 -07:00
SymbolType symbol_type() const override;
2022-03-13 09:50:52 +01:00
bool is_net() const { return net_set_; };
bool is_port() const { return port_set_; };
void set_net(NetNet::Type t);
void set_port(NetNet::PortType pt);
1999-06-17 05:34:42 +00:00
private:
2008-02-24 19:40:54 -08:00
perm_string name_;
1999-06-17 05:34:42 +00:00
NetNet::Type type_;
NetNet::PortType port_type_;
2000-12-11 00:31:43 +00:00
bool signed_;
1999-06-17 05:34:42 +00:00
2022-01-03 21:24:23 +01:00
// Whether the wire is variable declared with the const keyword.
bool is_const_ = false;
bool is_elaborating_ = false;
1999-06-17 05:34:42 +00:00
// These members hold expressions for the bit width of the
// wire. If they do not exist, the wire is 1 bit wide. If they
// do exist, they represent the packed dimensions of the
// bit. The first item in the list is the first range, and so
// on. For example "reg [3:0][7:0] ..." will contains the
// range_t object for [3:0] first and [7:0] last.
2012-04-10 14:29:28 -07:00
std::list<pform_range_t>port_;
bool port_set_;
2012-04-10 14:29:28 -07:00
std::list<pform_range_t>net_;
bool net_set_;
bool is_scalar_;
unsigned error_cnt_;
1999-06-17 05:34:42 +00:00
// If this wire is actually a memory, these indices will give
2012-05-25 15:58:29 -07:00
// me the size and address ranges of the memory.
std::list<pform_range_t>unpacked_;
1999-06-17 05:34:42 +00:00
2012-11-11 17:42:31 -08:00
// This is the complex type of the wire. the data_type_ may
// modify how this is interpreted.
std::unique_ptr<data_type_t> set_data_type_;
2010-10-31 11:26:09 -07:00
ivl_discipline_t discipline_;
2008-05-11 17:30:33 -07:00
1998-11-03 23:28:49 +00:00
private: // not implemented
PWire(const PWire&);
PWire& operator= (const PWire&);
ivl_type_t elaborate_type(Design*des, NetScope*scope,
2022-01-06 15:24:20 +01:00
const netranges_t &packed_dimensions) const;
ivl_type_t elaborate_darray_type(Design*des, NetScope*scope,
const char *darray_type,
2022-01-06 15:24:20 +01:00
const netranges_t &packed_dimensions)
const;
1998-11-03 23:28:49 +00:00
};
#endif /* IVL_PWire_H */