Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 108 lines (90 sloc) 2.882 kb
5b5a6b0 Stephen Williams Test type correctness during elaboration.
steveicarus authored
1 /*
2 * Copyright (c) 2010 Stephen Williams (steve@icarus.com)
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
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 */
19
20 # include "netenum.h"
de215f1 Stephen Williams Describe enum type to code generators
steveicarus authored
21 # include "compiler.h"
5e2c0e5 Stephen Williams Better handling of width of enum literals in expressions.
steveicarus authored
22 # include <cassert>
5b5a6b0 Stephen Williams Test type correctness during elaboration.
steveicarus authored
23
de215f1 Stephen Williams Describe enum type to code generators
steveicarus 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.
steveicarus authored
28 {
29 }
30
31 netenum_t::~netenum_t()
32 {
33 }
34
de215f1 Stephen Williams Describe enum type to code generators
steveicarus authored
35 bool netenum_t::insert_name(size_t name_idx, perm_string name, const verinum&val)
5b5a6b0 Stephen Williams Test type correctness during elaboration.
steveicarus authored
36 {
d37126b Stephen Williams Implement enum first/last/num methods.
steveicarus authored
37 std::pair<std::map<perm_string,verinum>::iterator, bool> res;
38
d0b063b Cary R. Fix enum compile warnings and update ivl.def (windows compile).
caryr authored
39 assert((msb_-lsb_+1) > 0);
40 assert(val.has_len() && val.len() == (unsigned)(msb_-lsb_+1));
5e2c0e5 Stephen Williams Better handling of width of enum literals in expressions.
steveicarus authored
41
de215f1 Stephen Williams Describe enum type to code generators
steveicarus authored
42 // Insert a map of the name to the value. This also gets a
43 // flag that returns true if the name is unique, or false
44 // otherwise.
d37126b Stephen Williams Implement enum first/last/num methods.
steveicarus authored
45 res = names_map_.insert( make_pair(name,val) );
de215f1 Stephen Williams Describe enum type to code generators
steveicarus authored
46
47 assert(name_idx < names_.size() && names_[name_idx] == 0);
48 names_[name_idx] = name;
d37126b Stephen Williams Implement enum first/last/num methods.
steveicarus authored
49
50 return res.second;
5b5a6b0 Stephen Williams Test type correctness during elaboration.
steveicarus authored
51 }
52
53 netenum_t::iterator netenum_t::find_name(perm_string name) const
54 {
d37126b Stephen Williams Implement enum first/last/num methods.
steveicarus authored
55 return names_map_.find(name);
5b5a6b0 Stephen Williams Test type correctness during elaboration.
steveicarus authored
56 }
57
58 netenum_t::iterator netenum_t::end_name() const
59 {
d37126b Stephen Williams Implement enum first/last/num methods.
steveicarus authored
60 return names_map_.end();
61 }
62
63 netenum_t::iterator netenum_t::first_name() const
64 {
65 return names_map_.find(names_.front());
66 }
67
68 netenum_t::iterator netenum_t::last_name() const
69 {
70 return names_map_.find(names_.back());
5b5a6b0 Stephen Williams Test type correctness during elaboration.
steveicarus authored
71 }
de215f1 Stephen Williams Describe enum type to code generators
steveicarus authored
72
73 perm_string netenum_t::name_at(size_t idx) const
74 {
75 assert(idx < names_.size());
76 return names_[idx];
77 }
78
79 perm_string netenum_t::bits_at(size_t idx)
80 {
81 assert(idx < names_.size());
82
83 if (bits_[idx] == 0) {
84 netenum_t::iterator cur = names_map_.find(names_[idx]);
85
86 vector<char>str (cur->second.len() + 1);
87 for (unsigned bit = 0 ; bit < cur->second.len() ; bit += 1) {
88 switch (cur->second.get(bit)) {
89 case verinum::V0:
90 str[bit] = '0';
91 break;
92 case verinum::V1:
93 str[bit] = '1';
94 break;
95 case verinum::Vx:
96 str[bit] = 'x';
97 break;
98 case verinum::Vz:
99 str[bit] = 'z';
100 break;
101 }
102 }
103 bits_[idx] = bits_strings.make(&str[0]);
104 }
105
106 return bits_[idx];
107 }
Something went wrong with that request. Please try again.