1 #ifndef IVL_vvp_darray_H
2 #define IVL_vvp_darray_H
3 /*
4  * Copyright (c) 2012-2020 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  "vvp_object.h"
23 # include  "vvp_net.h"
24 # include  <deque>
25 # include  <string>
26 # include  <vector>
27 
28 class vvp_darray : public vvp_object {
29 
30     public:
vvp_darray()31       inline vvp_darray() { }
32       virtual ~vvp_darray();
33 
34       virtual size_t get_size(void) const =0;
35 
36       virtual void set_word(unsigned adr, const vvp_vector4_t&value);
37       virtual void get_word(unsigned adr, vvp_vector4_t&value);
38 
39       virtual void set_word(unsigned adr, double value);
40       virtual void get_word(unsigned adr, double&value);
41 
42       virtual void set_word(unsigned adr, const std::string&value);
43       virtual void get_word(unsigned adr, std::string&value);
44 
45       virtual void set_word(unsigned adr, const vvp_object_t&value);
46       virtual void get_word(unsigned adr, vvp_object_t&value);
47 
48       virtual void shallow_copy(const vvp_object*obj);
49 
50       virtual vvp_vector4_t get_bitstream(bool as_vec4);
51 };
52 
53 template <class TYPE> class vvp_darray_atom : public vvp_darray {
54 
55     public:
vvp_darray_atom(size_t siz)56       explicit inline vvp_darray_atom(size_t siz) : array_(siz) { }
57       ~vvp_darray_atom();
58 
59       size_t get_size(void) const;
60       void set_word(unsigned adr, const vvp_vector4_t&value);
61       void get_word(unsigned adr, vvp_vector4_t&value);
62       void shallow_copy(const vvp_object*obj);
63       vvp_vector4_t get_bitstream(bool as_vec4);
64 
65     private:
66       std::vector<TYPE> array_;
67 };
68 
69 class vvp_darray_vec4 : public vvp_darray {
70 
71     public:
vvp_darray_vec4(size_t siz,unsigned word_wid)72       inline vvp_darray_vec4(size_t siz, unsigned word_wid) :
73                              array_(siz), word_wid_(word_wid) { }
74       ~vvp_darray_vec4();
75 
76       size_t get_size(void) const;
77       void set_word(unsigned adr, const vvp_vector4_t&value);
78       void get_word(unsigned adr, vvp_vector4_t&value);
79       void shallow_copy(const vvp_object*obj);
80       vvp_vector4_t get_bitstream(bool as_vec4);
81 
82     private:
83       std::vector<vvp_vector4_t> array_;
84       unsigned word_wid_;
85 };
86 
87 class vvp_darray_vec2 : public vvp_darray {
88 
89     public:
vvp_darray_vec2(size_t siz,unsigned word_wid)90       inline vvp_darray_vec2(size_t siz, unsigned word_wid) :
91                              array_(siz), word_wid_(word_wid) { }
92       ~vvp_darray_vec2();
93 
94       size_t get_size(void) const;
95       void set_word(unsigned adr, const vvp_vector4_t&value);
96       void get_word(unsigned adr, vvp_vector4_t&value);
97       void shallow_copy(const vvp_object*obj);
98       vvp_vector4_t get_bitstream(bool as_vec4);
99 
100     private:
101       std::vector<vvp_vector2_t> array_;
102       unsigned word_wid_;
103 };
104 
105 class vvp_darray_real : public vvp_darray {
106 
107     public:
vvp_darray_real(size_t siz)108       explicit inline vvp_darray_real(size_t siz) : array_(siz) { }
109       ~vvp_darray_real();
110 
111       size_t get_size(void) const;
112       void set_word(unsigned adr, double value);
113       void get_word(unsigned adr, double&value);
114       void shallow_copy(const vvp_object*obj);
115       vvp_vector4_t get_bitstream(bool as_vec4);
116 
117     private:
118       std::vector<double> array_;
119 };
120 
121 class vvp_darray_string : public vvp_darray {
122 
123     public:
vvp_darray_string(size_t siz)124       explicit inline vvp_darray_string(size_t siz) : array_(siz) { }
125       ~vvp_darray_string();
126 
127       size_t get_size(void) const;
128       void set_word(unsigned adr, const std::string&value);
129       void get_word(unsigned adr, std::string&value);
130       void shallow_copy(const vvp_object*obj);
131 
132     private:
133       std::vector<std::string> array_;
134 };
135 
136 class vvp_darray_object : public vvp_darray {
137 
138     public:
vvp_darray_object(size_t siz)139       explicit inline vvp_darray_object(size_t siz) : array_(siz) { }
140       ~vvp_darray_object();
141 
142       size_t get_size(void) const;
143       void set_word(unsigned adr, const vvp_object_t&value);
144       void get_word(unsigned adr, vvp_object_t&value);
145       void shallow_copy(const vvp_object*obj);
146 
147     private:
148       std::vector<vvp_object_t> array_;
149 };
150 
151 class vvp_queue : public vvp_darray {
152 
153     public:
vvp_queue(void)154       inline vvp_queue(void) { }
155       ~vvp_queue();
156 
157       virtual size_t get_size(void) const =0;
158       virtual void copy_elems(vvp_object_t src, unsigned max_size);
159 
160       virtual void set_word_max(unsigned adr, const vvp_vector4_t&value, unsigned max_size);
161       virtual void insert(unsigned idx, const vvp_vector4_t&value, unsigned max_size);
162       virtual void push_back(const vvp_vector4_t&value, unsigned max_size);
163       virtual void push_front(const vvp_vector4_t&value, unsigned max_size);
164 
165       virtual void set_word_max(unsigned adr, double value, unsigned max_size);
166       virtual void insert(unsigned idx, double value, unsigned max_size);
167       virtual void push_back(double value, unsigned max_size);
168       virtual void push_front(double value, unsigned max_size);
169 
170       virtual void set_word_max(unsigned adr, const std::string&value, unsigned max_size);
171       virtual void insert(unsigned idx, const std::string&value, unsigned max_size);
172       virtual void push_back(const std::string&value, unsigned max_size);
173       virtual void push_front(const std::string&value, unsigned max_size);
174 
175       virtual void pop_back(void) =0;
176       virtual void pop_front(void)=0;
177       virtual void erase(unsigned idx)=0;
178       virtual void erase_tail(unsigned idx)=0;
179 };
180 
181 class vvp_queue_real : public vvp_queue {
182 
183     public:
184       ~vvp_queue_real();
185 
get_size(void)186       size_t get_size(void) const { return queue.size(); };
187       void copy_elems(vvp_object_t src, unsigned max_size);
188       void set_word_max(unsigned adr, double value, unsigned max_size);
189       void set_word(unsigned adr, double value);
190       void get_word(unsigned adr, double&value);
191       void insert(unsigned idx, double value, unsigned max_size);
192       void push_back(double value, unsigned max_size);
193       void push_front(double value, unsigned max_size);
pop_back(void)194       void pop_back(void) { queue.pop_back(); };
pop_front(void)195       void pop_front(void) { queue.pop_front(); };
196       void erase(unsigned idx);
197       void erase_tail(unsigned idx);
198 
199     private:
200       std::deque<double> queue;
201 };
202 
203 class vvp_queue_string : public vvp_queue {
204 
205     public:
206       ~vvp_queue_string();
207 
get_size(void)208       size_t get_size(void) const { return queue.size(); };
209       void copy_elems(vvp_object_t src, unsigned max_size);
210       void set_word_max(unsigned adr, const std::string&value, unsigned max_size);
211       void set_word(unsigned adr, const std::string&value);
212       void get_word(unsigned adr, std::string&value);
213       void insert(unsigned idx, const std::string&value, unsigned max_size);
214       void push_back(const std::string&value, unsigned max_size);
215       void push_front(const std::string&value, unsigned max_size);
pop_back(void)216       void pop_back(void) { queue.pop_back(); };
pop_front(void)217       void pop_front(void) { queue.pop_front(); };
218       void erase(unsigned idx);
219       void erase_tail(unsigned idx);
220 
221     private:
222       std::deque<std::string> queue;
223 };
224 
225 class vvp_queue_vec4 : public vvp_queue {
226 
227     public:
228       ~vvp_queue_vec4();
229 
get_size(void)230       size_t get_size(void) const { return queue.size(); };
231       void copy_elems(vvp_object_t src, unsigned max_size);
232       void set_word_max(unsigned adr, const vvp_vector4_t&value, unsigned max_size);
233       void set_word(unsigned adr, const vvp_vector4_t&value);
234       void get_word(unsigned adr, vvp_vector4_t&value);
235       void insert(unsigned idx, const vvp_vector4_t&value, unsigned max_size);
236       void push_back(const vvp_vector4_t&value, unsigned max_size);
237       void push_front(const vvp_vector4_t&value, unsigned max_size);
pop_back(void)238       void pop_back(void) { queue.pop_back(); };
pop_front(void)239       void pop_front(void) { queue.pop_front(); };
240       void erase(unsigned idx);
241       void erase_tail(unsigned idx);
242 
243     private:
244       std::deque<vvp_vector4_t> queue;
245 };
246 
247 extern string get_fileline();
248 
249 #endif /* IVL_vvp_darray_H */
250