2007-05-24 06:07:11 +02:00
|
|
|
#ifndef __pform_types_H
|
|
|
|
|
#define __pform_types_H
|
|
|
|
|
/*
|
2012-03-03 03:34:43 +01:00
|
|
|
* Copyright (c) 2007-2012 Stephen Williams (steve@icarus.com)
|
2007-05-24 06:07:11 +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.
|
2007-05-24 06:07:11 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// This for the perm_string type.
|
|
|
|
|
# include "StringHeap.h"
|
2011-09-01 23:29:40 +02:00
|
|
|
# include "LineInfo.h"
|
2010-10-31 19:26:09 +01:00
|
|
|
# include "verinum.h"
|
2010-11-04 04:11:19 +01:00
|
|
|
# include "named.h"
|
|
|
|
|
# include "ivl_target.h"
|
2007-05-24 06:07:11 +02:00
|
|
|
# include <iostream>
|
|
|
|
|
# include <list>
|
2010-10-31 19:26:09 +01:00
|
|
|
# include <map>
|
2010-11-24 17:02:50 +01:00
|
|
|
# include <memory>
|
2007-05-24 06:07:11 +02:00
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* parse-form types.
|
|
|
|
|
*/
|
|
|
|
|
|
2010-11-13 03:47:06 +01:00
|
|
|
class PExpr;
|
2010-11-04 04:11:19 +01:00
|
|
|
typedef named<verinum> named_number_t;
|
2010-11-13 03:47:06 +01:00
|
|
|
typedef named<PExpr*> named_pexpr_t;
|
2012-04-10 23:29:28 +02:00
|
|
|
typedef std::pair<PExpr*,PExpr*> pform_range_t;
|
2010-11-04 04:11:19 +01:00
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
struct index_component_t {
|
|
|
|
|
enum ctype_t { SEL_NONE, SEL_BIT, SEL_PART, SEL_IDX_UP, SEL_IDX_DO };
|
|
|
|
|
|
|
|
|
|
index_component_t() : sel(SEL_NONE), msb(0), lsb(0) { };
|
|
|
|
|
~index_component_t() { }
|
|
|
|
|
|
|
|
|
|
ctype_t sel;
|
|
|
|
|
class PExpr*msb;
|
|
|
|
|
class PExpr*lsb;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct name_component_t {
|
2007-06-04 04:19:07 +02:00
|
|
|
explicit name_component_t(perm_string n) : name(n) { }
|
2007-05-24 06:07:11 +02:00
|
|
|
~name_component_t() { }
|
|
|
|
|
|
|
|
|
|
perm_string name;
|
|
|
|
|
std::list<index_component_t>index;
|
|
|
|
|
};
|
|
|
|
|
|
2011-12-04 02:16:01 +01:00
|
|
|
struct decl_assignment_t {
|
|
|
|
|
perm_string name;
|
2012-04-10 23:29:28 +02:00
|
|
|
std::list<pform_range_t>index;
|
2011-12-04 02:16:01 +01:00
|
|
|
std::auto_ptr<PExpr> expr;
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-08 00:37:30 +01:00
|
|
|
/*
|
|
|
|
|
* This is the base class for data types that are matched by the
|
|
|
|
|
* "data_type" rule in the parse rule. We make the type virtual so
|
|
|
|
|
* that dynamic types will work.
|
|
|
|
|
*/
|
2012-08-03 05:14:55 +02:00
|
|
|
class data_type_t : public LineInfo {
|
|
|
|
|
public:
|
2012-01-08 00:37:30 +01:00
|
|
|
virtual ~data_type_t() = 0;
|
2012-08-03 05:14:55 +02:00
|
|
|
// This method is used to figure out the base type of a packed
|
|
|
|
|
// compound object. Return IVL_VT_NO_TYPE if the type is not packed.
|
|
|
|
|
virtual ivl_variable_type_t figure_packed_base_type(void)const;
|
2012-01-09 02:51:18 +01:00
|
|
|
// This method is used by the pform dumper to diagnostic dump.
|
|
|
|
|
virtual void pform_dump(std::ostream&out, unsigned indent) const;
|
2012-01-08 00:37:30 +01:00
|
|
|
};
|
|
|
|
|
|
2010-10-31 19:26:09 +01:00
|
|
|
/*
|
2010-11-04 04:11:19 +01:00
|
|
|
* The enum_type_t holds the parsed declaration to represent an
|
|
|
|
|
* enumeration. Since this is in the pform, it represents the type
|
|
|
|
|
* before elaboration to the range, for example, man not be complete
|
|
|
|
|
* until it is elaborated in a scope.
|
2010-10-31 19:26:09 +01:00
|
|
|
*/
|
2012-01-08 00:37:30 +01:00
|
|
|
struct enum_type_t : public data_type_t {
|
2010-11-04 04:11:19 +01:00
|
|
|
ivl_variable_type_t base_type;
|
|
|
|
|
bool signed_flag;
|
2012-04-10 23:29:28 +02:00
|
|
|
std::auto_ptr< list<pform_range_t> > range;
|
2010-11-24 17:02:50 +01:00
|
|
|
std::auto_ptr< list<named_pexpr_t> > names;
|
2011-09-01 23:29:40 +02:00
|
|
|
LineInfo li;
|
2010-11-04 04:11:19 +01:00
|
|
|
};
|
2010-10-31 19:26:09 +01:00
|
|
|
|
2011-12-04 02:16:01 +01:00
|
|
|
struct struct_member_t : public LineInfo {
|
|
|
|
|
ivl_variable_type_t type;
|
2012-04-10 23:29:28 +02:00
|
|
|
std::auto_ptr< list<pform_range_t> > range;
|
2011-12-04 02:16:01 +01:00
|
|
|
std::auto_ptr< list<decl_assignment_t*> > names;
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-08 00:37:30 +01:00
|
|
|
struct struct_type_t : public data_type_t {
|
2012-08-03 05:14:55 +02:00
|
|
|
virtual ivl_variable_type_t figure_packed_base_type(void)const;
|
2011-12-04 02:16:01 +01:00
|
|
|
bool packed_flag;
|
|
|
|
|
std::auto_ptr< list<struct_member_t*> > members;
|
|
|
|
|
};
|
2007-05-24 06:07:11 +02:00
|
|
|
|
2012-02-19 19:29:50 +01:00
|
|
|
struct atom2_type_t : public data_type_t {
|
|
|
|
|
inline explicit atom2_type_t(int tc, bool flag)
|
|
|
|
|
: type_code(tc), signed_flag(flag) { }
|
|
|
|
|
int type_code;
|
|
|
|
|
bool signed_flag;
|
|
|
|
|
};
|
|
|
|
|
|
2012-04-16 02:58:07 +02:00
|
|
|
/*
|
|
|
|
|
* The vector_type_t class represents types in the old Verilog
|
|
|
|
|
* way. Some typical examples:
|
|
|
|
|
*
|
|
|
|
|
* logic signed [7:0] foo
|
|
|
|
|
* bit unsigned foo
|
|
|
|
|
* reg foo
|
|
|
|
|
*
|
|
|
|
|
* There are a few special cases:
|
|
|
|
|
*
|
|
|
|
|
* For the most part, Verilog treats "logic" and "reg" as synonyms,
|
|
|
|
|
* but there are a few cases where the parser needs to know the
|
|
|
|
|
* difference. So "reg_flag" is set to true if the IVL_VT_LOGIC type
|
|
|
|
|
* is due to the "reg" keyword.
|
|
|
|
|
*
|
|
|
|
|
* If there are no reg/logic/bit/bool keywords, then Verilog will
|
|
|
|
|
* assume the type is logic, but the context may need to know about
|
|
|
|
|
* this case, so the implicit_flag member is set to true in that case.
|
|
|
|
|
*/
|
2012-02-26 07:05:00 +01:00
|
|
|
struct vector_type_t : public data_type_t {
|
2012-03-03 03:34:43 +01:00
|
|
|
inline explicit vector_type_t(ivl_variable_type_t bt, bool sf,
|
2012-04-10 23:29:28 +02:00
|
|
|
std::list<pform_range_t>*pd)
|
2012-04-16 02:58:07 +02:00
|
|
|
: base_type(bt), signed_flag(sf), reg_flag(false), implicit_flag(false), pdims(pd) { }
|
2012-08-03 05:14:55 +02:00
|
|
|
virtual ivl_variable_type_t figure_packed_base_type(void)const;
|
|
|
|
|
|
2012-02-26 07:05:00 +01:00
|
|
|
ivl_variable_type_t base_type;
|
|
|
|
|
bool signed_flag;
|
2012-04-16 02:58:07 +02:00
|
|
|
bool reg_flag; // True if "reg" was used
|
|
|
|
|
bool implicit_flag; // True if this type is implicitly logic/reg
|
2012-04-10 23:29:28 +02:00
|
|
|
std::auto_ptr< list<pform_range_t> > pdims;
|
2012-02-26 07:05:00 +01:00
|
|
|
};
|
|
|
|
|
|
2012-05-14 02:05:09 +02:00
|
|
|
/*
|
|
|
|
|
* The array_type_t is a generalization of the vector_type_t in that
|
2012-08-03 05:14:55 +02:00
|
|
|
* the base type is another general data type. Ultimately, the subtype
|
|
|
|
|
* must also be packed (as this is a packed array) but that may be
|
|
|
|
|
* worked out during elaboration.
|
2012-05-14 02:05:09 +02:00
|
|
|
*/
|
2012-08-03 05:14:55 +02:00
|
|
|
struct parray_type_t : public data_type_t {
|
|
|
|
|
inline explicit parray_type_t(data_type_t*btype, std::list<pform_range_t>*pd)
|
2012-05-14 02:05:09 +02:00
|
|
|
: base_type(btype), packed_dims(pd) { }
|
2012-08-03 05:14:55 +02:00
|
|
|
virtual ivl_variable_type_t figure_packed_base_type(void)const;
|
|
|
|
|
|
2012-05-14 02:05:09 +02:00
|
|
|
data_type_t*base_type;
|
|
|
|
|
std::auto_ptr< list<pform_range_t> > packed_dims;
|
|
|
|
|
};
|
|
|
|
|
|
2012-02-26 07:05:00 +01:00
|
|
|
struct real_type_t : public data_type_t {
|
2012-04-13 05:20:37 +02:00
|
|
|
enum type_t { REAL, SHORTREAL };
|
|
|
|
|
inline explicit real_type_t(type_t tc) : type_code(tc) { }
|
|
|
|
|
type_t type_code;
|
2012-02-26 07:05:00 +01:00
|
|
|
};
|
|
|
|
|
|
2012-06-18 03:22:50 +02:00
|
|
|
struct string_type_t : public data_type_t {
|
|
|
|
|
inline explicit string_type_t() { }
|
|
|
|
|
~string_type_t();
|
|
|
|
|
};
|
|
|
|
|
|
2012-03-03 06:16:53 +01:00
|
|
|
struct class_type_t : public data_type_t {
|
|
|
|
|
inline explicit class_type_t(perm_string n)
|
|
|
|
|
: name(n) { }
|
|
|
|
|
|
|
|
|
|
perm_string name;
|
|
|
|
|
};
|
|
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
/*
|
2008-06-22 03:36:46 +02:00
|
|
|
* The pform_name_t is the general form for a hierarchical
|
|
|
|
|
* identifier. It is an ordered list of name components. Each name
|
|
|
|
|
* component is an identifier and an optional list of bit/part
|
|
|
|
|
* selects. The simplest name component is a simple identifier:
|
|
|
|
|
*
|
|
|
|
|
* foo
|
|
|
|
|
*
|
|
|
|
|
* The bit/part selects come from the source and are made part of the
|
|
|
|
|
* name component. A bit select is a single number that may be a bit
|
|
|
|
|
* select of a vector or a word select of an array:
|
|
|
|
|
*
|
|
|
|
|
* foo[5] -- a bit select/word index
|
|
|
|
|
* foo[6:4] -- a part select
|
|
|
|
|
*
|
|
|
|
|
* The index components of a name component are collected into an
|
|
|
|
|
* ordered list, so there may be many, for example:
|
|
|
|
|
*
|
|
|
|
|
* foo[5][6:4] -- a part select of an array word
|
|
|
|
|
*
|
|
|
|
|
* The pform_name_t, then, is an ordered list of these name
|
|
|
|
|
* components. The list of names comes from a hierarchical name in the
|
|
|
|
|
* source, like this:
|
|
|
|
|
*
|
|
|
|
|
* foo[5].bar[6:4] -- a part select of a vector in sub-scope foo[5].
|
2007-05-24 06:07:11 +02:00
|
|
|
*/
|
|
|
|
|
typedef std::list<name_component_t> pform_name_t;
|
|
|
|
|
|
2008-06-22 03:36:46 +02:00
|
|
|
|
2007-05-24 06:07:11 +02:00
|
|
|
inline perm_string peek_head_name(const pform_name_t&that)
|
|
|
|
|
{
|
|
|
|
|
return that.front().name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inline perm_string peek_tail_name(const pform_name_t&that)
|
|
|
|
|
{
|
|
|
|
|
return that.back().name;
|
|
|
|
|
}
|
|
|
|
|
|
2007-06-04 04:19:07 +02:00
|
|
|
extern std::ostream& operator<< (std::ostream&out, const pform_name_t&);
|
|
|
|
|
extern std::ostream& operator<< (std::ostream&out, const name_component_t&that);
|
|
|
|
|
extern std::ostream& operator<< (std::ostream&out, const index_component_t&that);
|
2007-05-24 06:07:11 +02:00
|
|
|
|
|
|
|
|
#endif
|