Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 132 lines (112 sloc) 3.393 kb
5b5a6b0 Stephen Williams Test type correctness during elaboration.
authored
1 /*
6184871 Cary R. Remove cppcheck warnings in ivl code.
caryr authored
2 * Copyright (c) 2010-2011 Stephen Williams (steve@icarus.com)
5b5a6b0 Stephen Williams Test type correctness during elaboration.
authored
3 *
4 * This source code is free software; you can redistribute it
5 * and/or modify it in source code form under the terms of the GNU
6 * General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
f5aafc3 Arun Persaud updated FSF-address
arunpersaud authored
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
5b5a6b0 Stephen Williams Test type correctness during elaboration.
authored
18 */
19
20 # include "netenum.h"
de215f1 Stephen Williams Describe enum type to code generators
authored
21 # include "compiler.h"
5e2c0e5 Stephen Williams Better handling of width of enum literals in expressions.
authored
22 # include <cassert>
5b5a6b0 Stephen Williams Test type correctness during elaboration.
authored
23
de215f1 Stephen Williams Describe enum type to code generators
authored
24 netenum_t::netenum_t(ivl_variable_type_t btype, bool signed_flag,
25 long msb, long lsb, size_t name_count)
26 : base_type_(btype), signed_flag_(signed_flag), msb_(msb), lsb_(lsb),
27 names_(name_count), bits_(name_count)
5b5a6b0 Stephen Williams Test type correctness during elaboration.
authored
28 {
29 }
30
31 netenum_t::~netenum_t()
32 {
33 }
34
0bdabab Stephen Williams Rework packed dimensions handling
authored
35 long netenum_t::packed_width() const
36 {
37 if (msb_ >= lsb_)
38 return msb_ - lsb_ + 1;
39 else
40 return lsb_ - msb_ + 1;
41 }
42
de215f1 Stephen Williams Describe enum type to code generators
authored
43 bool netenum_t::insert_name(size_t name_idx, perm_string name, const verinum&val)
5b5a6b0 Stephen Williams Test type correctness during elaboration.
authored
44 {
d37126b Stephen Williams Implement enum first/last/num methods.
authored
45 std::pair<std::map<perm_string,verinum>::iterator, bool> res;
46
d0b063b Cary R. Fix enum compile warnings and update ivl.def (windows compile).
caryr authored
47 assert((msb_-lsb_+1) > 0);
48 assert(val.has_len() && val.len() == (unsigned)(msb_-lsb_+1));
5e2c0e5 Stephen Williams Better handling of width of enum literals in expressions.
authored
49
de215f1 Stephen Williams Describe enum type to code generators
authored
50 // Insert a map of the name to the value. This also gets a
51 // flag that returns true if the name is unique, or false
52 // otherwise.
d37126b Stephen Williams Implement enum first/last/num methods.
authored
53 res = names_map_.insert( make_pair(name,val) );
de215f1 Stephen Williams Describe enum type to code generators
authored
54
55 assert(name_idx < names_.size() && names_[name_idx] == 0);
56 names_[name_idx] = name;
d37126b Stephen Williams Implement enum first/last/num methods.
authored
57
58 return res.second;
5b5a6b0 Stephen Williams Test type correctness during elaboration.
authored
59 }
60
61 netenum_t::iterator netenum_t::find_name(perm_string name) const
62 {
d37126b Stephen Williams Implement enum first/last/num methods.
authored
63 return names_map_.find(name);
5b5a6b0 Stephen Williams Test type correctness during elaboration.
authored
64 }
65
3b6e26a Cary R. An enumeration cannot have duplicate values.
caryr authored
66 /*
67 * Check to see if the given value is already in the enumeration mapping.
68 */
69 perm_string netenum_t::find_value(const verinum&val) const
70 {
71 perm_string res;
72 for(netenum_t::iterator cur = names_map_.begin();
6184871 Cary R. Remove cppcheck warnings in ivl code.
caryr authored
73 cur != names_map_.end(); ++ cur) {
3b6e26a Cary R. An enumeration cannot have duplicate values.
caryr authored
74 if (cur->second == val) {
75 res = cur->first;
76 break;
77 }
78 }
79 return res;
80 }
81
5b5a6b0 Stephen Williams Test type correctness during elaboration.
authored
82 netenum_t::iterator netenum_t::end_name() const
83 {
d37126b Stephen Williams Implement enum first/last/num methods.
authored
84 return names_map_.end();
85 }
86
87 netenum_t::iterator netenum_t::first_name() const
88 {
89 return names_map_.find(names_.front());
90 }
91
92 netenum_t::iterator netenum_t::last_name() const
93 {
94 return names_map_.find(names_.back());
5b5a6b0 Stephen Williams Test type correctness during elaboration.
authored
95 }
de215f1 Stephen Williams Describe enum type to code generators
authored
96
97 perm_string netenum_t::name_at(size_t idx) const
98 {
99 assert(idx < names_.size());
100 return names_[idx];
101 }
102
103 perm_string netenum_t::bits_at(size_t idx)
104 {
105 assert(idx < names_.size());
106
107 if (bits_[idx] == 0) {
108 netenum_t::iterator cur = names_map_.find(names_[idx]);
109
110 vector<char>str (cur->second.len() + 1);
111 for (unsigned bit = 0 ; bit < cur->second.len() ; bit += 1) {
112 switch (cur->second.get(bit)) {
113 case verinum::V0:
114 str[bit] = '0';
115 break;
116 case verinum::V1:
117 str[bit] = '1';
118 break;
119 case verinum::Vx:
120 str[bit] = 'x';
121 break;
122 case verinum::Vz:
123 str[bit] = 'z';
124 break;
125 }
126 }
127 bits_[idx] = bits_strings.make(&str[0]);
128 }
129
130 return bits_[idx];
131 }
Something went wrong with that request. Please try again.