2014-07-23 22:39:29 +02:00
|
|
|
#ifndef IVL_nettypes_H
|
|
|
|
|
#define IVL_nettypes_H
|
2012-03-26 02:59:05 +02:00
|
|
|
/*
|
2021-01-30 09:47:16 +01:00
|
|
|
* Copyright (c) 2012-2021 Stephen Williams (steve@icarus.com)
|
2012-03-26 02:59:05 +02: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.
|
2012-03-26 02:59:05 +02:00
|
|
|
*/
|
|
|
|
|
|
2012-09-15 19:27:43 +02:00
|
|
|
# include "ivl_target.h"
|
2012-09-30 00:13:45 +02:00
|
|
|
# include <list>
|
|
|
|
|
# include <vector>
|
|
|
|
|
# include <climits>
|
|
|
|
|
# include <ostream>
|
|
|
|
|
# include <cassert>
|
|
|
|
|
|
|
|
|
|
class netrange_t;
|
2020-12-25 03:12:06 +01:00
|
|
|
class LineInfo;
|
2012-07-14 03:41:41 +02:00
|
|
|
|
2022-01-06 15:24:20 +01:00
|
|
|
typedef std::vector<netrange_t> netranges_t;
|
|
|
|
|
|
2012-07-14 03:41:41 +02:00
|
|
|
/*
|
|
|
|
|
* This is a fully abstract type that is a type that can be attached
|
|
|
|
|
* to a NetNet object.
|
|
|
|
|
*/
|
2012-09-23 18:28:49 +02:00
|
|
|
class ivl_type_s {
|
2012-07-14 03:41:41 +02:00
|
|
|
public:
|
2012-09-23 18:28:49 +02:00
|
|
|
virtual ~ivl_type_s() =0;
|
2013-11-29 21:43:34 +01:00
|
|
|
virtual bool packed(void) const;
|
2012-08-06 01:28:40 +02:00
|
|
|
virtual long packed_width(void) const;
|
2022-01-06 15:24:20 +01:00
|
|
|
virtual netranges_t slice_dimensions() const;
|
2012-09-15 19:27:43 +02:00
|
|
|
|
2013-09-29 03:31:22 +02:00
|
|
|
// Some types have a base variable type. This is the bit type
|
|
|
|
|
// for packed data types, or IVL_VT_DARRAY or IVL_VT_CLASS for
|
|
|
|
|
// those specific types.
|
2012-09-15 19:27:43 +02:00
|
|
|
virtual ivl_variable_type_t base_type() const;
|
2012-09-16 02:16:05 +02:00
|
|
|
virtual bool get_signed() const;
|
2022-03-19 14:46:18 +01:00
|
|
|
virtual bool get_scalar() const;
|
2012-09-16 02:16:05 +02:00
|
|
|
|
2022-09-17 19:37:47 +02:00
|
|
|
// Return true if "that" type is assignment compatible with this
|
|
|
|
|
// type.
|
2013-09-29 23:48:42 +02:00
|
|
|
bool type_compatible(ivl_type_t that) const;
|
2022-09-17 19:37:47 +02:00
|
|
|
// Return true if "that" type is equivalent with this type as defined by
|
|
|
|
|
// the standard
|
|
|
|
|
bool type_equivalent(ivl_type_t that) const;
|
2013-09-29 23:48:42 +02:00
|
|
|
|
2012-09-16 02:16:05 +02:00
|
|
|
virtual std::ostream& debug_dump(std::ostream&) const;
|
2013-09-29 23:48:42 +02:00
|
|
|
|
|
|
|
|
private:
|
2022-09-17 19:37:47 +02:00
|
|
|
// The "type_compatible" and "type_equivalent" methods uses this virtual
|
|
|
|
|
// method to invoke type-specific tests of compatibility.
|
2013-09-29 23:48:42 +02:00
|
|
|
virtual bool test_compatibility(ivl_type_t that) const;
|
2022-09-17 19:37:47 +02:00
|
|
|
virtual bool test_equivalence(ivl_type_t that) const;
|
2012-07-14 03:41:41 +02:00
|
|
|
};
|
2012-03-26 02:59:05 +02:00
|
|
|
|
2020-12-31 22:04:56 +01:00
|
|
|
/*
|
|
|
|
|
* Convenience functions for making ivl_type_t objects from various inputs.
|
|
|
|
|
*/
|
2021-01-30 09:47:16 +01:00
|
|
|
extern ivl_type_t make_ivl_type(ivl_variable_type_t vt,
|
2022-01-06 15:24:20 +01:00
|
|
|
const netranges_t&packed_dimensions,
|
2020-12-31 22:04:56 +01:00
|
|
|
bool signed_flag =false, bool isint_flag =false);
|
|
|
|
|
|
2012-09-30 19:34:09 +02:00
|
|
|
/*
|
|
|
|
|
* There are a couple types of array types. This class represents the
|
|
|
|
|
* common bits of array types.
|
|
|
|
|
*/
|
|
|
|
|
class netarray_t : public ivl_type_s {
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
inline explicit netarray_t(ivl_type_t etype) : element_type_(etype) { }
|
|
|
|
|
~netarray_t();
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// Some virtual methods have a common implementation for arrays.
|
2014-09-14 06:12:39 +02:00
|
|
|
|
|
|
|
|
// The base_type() for arrays is the base_Typeof the element.
|
2012-09-30 19:34:09 +02:00
|
|
|
ivl_variable_type_t base_type() const;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
inline ivl_type_t element_type() const { return element_type_; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
ivl_type_t element_type_;
|
|
|
|
|
};
|
|
|
|
|
|
2012-09-23 18:28:49 +02:00
|
|
|
inline static std::ostream& operator << (std::ostream&out, const ivl_type_s&obj)
|
2012-09-16 02:16:05 +02:00
|
|
|
{
|
|
|
|
|
return obj.debug_dump(out);
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-26 02:59:05 +02:00
|
|
|
class netrange_t {
|
|
|
|
|
|
|
|
|
|
public:
|
2012-07-14 03:41:41 +02:00
|
|
|
// Create an undefined range. An undefined range is a range
|
|
|
|
|
// used to declare dynamic arrays, etc.
|
|
|
|
|
inline netrange_t() : msb_(LONG_MAX), lsb_(LONG_MAX) { }
|
|
|
|
|
// Create a properly defined netrange
|
|
|
|
|
inline netrange_t(long m, long l) : msb_(m), lsb_(l) { }
|
2015-04-13 18:23:43 +02:00
|
|
|
// Copy constructor.
|
2012-03-26 02:59:05 +02:00
|
|
|
inline netrange_t(const netrange_t&that)
|
2012-07-14 03:41:41 +02:00
|
|
|
: msb_(that.msb_), lsb_(that.lsb_) { }
|
2012-03-26 02:59:05 +02:00
|
|
|
|
|
|
|
|
inline netrange_t& operator = (const netrange_t&that)
|
2012-07-14 03:41:41 +02:00
|
|
|
{ msb_ = that.msb_; lsb_ = that.lsb_; return *this; }
|
2012-03-26 02:59:05 +02:00
|
|
|
|
2012-07-14 03:41:41 +02:00
|
|
|
inline bool defined() const
|
2012-08-08 21:21:24 +02:00
|
|
|
{ return msb_!=LONG_MAX || lsb_!= LONG_MAX; }
|
2012-03-26 02:59:05 +02:00
|
|
|
|
|
|
|
|
inline unsigned long width()const
|
2012-07-14 03:41:41 +02:00
|
|
|
{ if (!defined()) return 0;
|
|
|
|
|
else if (msb_ >= lsb_) return msb_-lsb_+1;
|
|
|
|
|
else return lsb_-msb_+1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline long get_msb() const { assert(defined()); return msb_; }
|
|
|
|
|
inline long get_lsb() const { assert(defined()); return lsb_; }
|
|
|
|
|
|
2013-09-29 23:48:42 +02:00
|
|
|
inline bool operator == (const netrange_t&that) const
|
|
|
|
|
{ if (msb_ != that.msb_) return false;
|
|
|
|
|
if (lsb_ != that.lsb_) return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline bool operator != (const netrange_t&that) const
|
|
|
|
|
{ if (msb_ != that.msb_) return true;
|
|
|
|
|
if (lsb_ != that.lsb_) return true;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-12 22:13:25 +02:00
|
|
|
bool equivalent(const netrange_t &that) const {
|
|
|
|
|
return width() == that.width();
|
|
|
|
|
}
|
|
|
|
|
|
2012-07-14 03:41:41 +02:00
|
|
|
private:
|
|
|
|
|
long msb_;
|
|
|
|
|
long lsb_;
|
2012-03-26 02:59:05 +02:00
|
|
|
};
|
|
|
|
|
|
2022-01-06 15:24:20 +01:00
|
|
|
extern std::ostream&operator << (std::ostream&out, const netranges_t&rlist);
|
2012-09-30 00:13:45 +02:00
|
|
|
|
2022-01-06 15:24:20 +01:00
|
|
|
extern unsigned long netrange_width(const netranges_t &dims,
|
2023-07-23 17:00:53 +02:00
|
|
|
unsigned int base_width = 1);
|
2022-01-06 15:24:20 +01:00
|
|
|
extern bool netrange_equivalent(const netranges_t &a, const netranges_t &b);
|
2012-03-26 02:59:05 +02:00
|
|
|
|
2020-12-25 03:12:06 +01:00
|
|
|
/*
|
|
|
|
|
* There are a few cases where we need to know about the single-level
|
|
|
|
|
* dimensions of a parameter declaration, for example:
|
|
|
|
|
*
|
|
|
|
|
* parameter [msv:lsv] foo ...;
|
|
|
|
|
*/
|
|
|
|
|
extern bool calculate_param_range(const LineInfo&line, ivl_type_t par_type,
|
|
|
|
|
long&par_msv, long&par_lsv, long length);
|
|
|
|
|
|
2012-03-26 02:59:05 +02:00
|
|
|
/*
|
|
|
|
|
* Take as input a list of packed dimensions and a list of prefix
|
|
|
|
|
* indices, and calculate the offset/width of the resulting slice into
|
|
|
|
|
* the packed array.
|
|
|
|
|
*/
|
2022-01-06 15:24:20 +01:00
|
|
|
extern bool prefix_to_slice(const netranges_t&dims,
|
2012-03-26 02:59:05 +02:00
|
|
|
const std::list<long>&prefix, long sb,
|
|
|
|
|
long&loff, unsigned long&lwid);
|
|
|
|
|
|
2022-09-17 19:37:47 +02:00
|
|
|
|
|
|
|
|
extern bool packed_types_equivalent(ivl_type_t a, ivl_type_t b);
|
|
|
|
|
extern bool packed_type_compatible(ivl_type_t type);
|
|
|
|
|
|
2014-07-23 22:39:29 +02:00
|
|
|
#endif /* IVL_nettypes_H */
|