1 #ifndef IVL_netenum_H
2 #define IVL_netenum_H
3 /*
4 * Copyright (c) 2010-2014 Stephen Williams (steve@icarus.com)
5 *
6 * This source code is free software; you can redistribute it
7 * and/or modify it in source code form under the terms of the GNU
8 * General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21
22 # include "ivl_target.h"
23 # include "nettypes.h"
24 # include "verinum.h"
25 # include "StringHeap.h"
26 # include "LineInfo.h"
27 # include <vector>
28 # include <map>
29
30 class NetScope;
31
32 struct enum_type_t;
33
34 class netenum_t : public LineInfo, public ivl_type_s {
35
36 public:
37 explicit netenum_t(ivl_variable_type_t base_type, bool signed_flag,
38 bool isint_flag, long msb, long lsb,
39 size_t name_count, enum_type_t*enum_type);
40 ~netenum_t();
41
42 virtual ivl_variable_type_t base_type() const;
43 virtual bool packed() const;
44 virtual long packed_width() const;
45 std::vector<netrange_t> slice_dimensions() const;
46 bool get_signed() const;
47 bool get_isint() const;
48
49 // The size() is the number of enumeration literals.
50 size_t size() const;
51
52 // Insert the name (and value) at the specific place in the
53 // enumeration. This must be done exactly once for each
54 // enumeration value.
55 bool insert_name(size_t idx, perm_string name, const verinum&val);
56
57 // Indicate that there will be no more names to insert.
58 void insert_name_close(void);
59
60 typedef std::map<perm_string,verinum>::const_iterator iterator;
61 iterator find_name(perm_string name) const;
62 iterator end_name() const;
63 perm_string find_value(const verinum&val) const;
64
65 // These methods roughly match the .first() and .last() methods.
66 iterator first_name() const;
67 iterator last_name() const;
68
69 perm_string name_at(size_t idx) const;
70 perm_string bits_at(size_t idx) const;
71
72 // Check if two enumerations have the same definition.
73 bool matches(const netenum_t*other) const;
74
75 private:
76 ivl_variable_type_t base_type_;
77 enum_type_t*enum_type_;
78 bool signed_flag_;
79 bool integer_flag_;
80 long msb_, lsb_;
81
82 std::map<perm_string,verinum> names_map_;
83 std::vector<perm_string> names_;
84 std::vector<perm_string> bits_;
85 };
86
base_type()87 inline ivl_variable_type_t netenum_t::base_type() const
88 { return base_type_; }
89
size()90 inline size_t netenum_t::size() const { return names_.size(); }
91
92 #endif /* IVL_netenum_H */
93