My Project
 All Classes Files Functions Variables Enumerations Enumerator Friends Macros Pages
arraymap.h
1 #ifndef arraymap_h
2 #define arraymap_h
3 
4 #include "regmap.h"
5 #include "hash.h"
6 #include "netbuf.h"
7 #include "input.h"
8 #include "output.h"
9 
10 #include <map>
11 
12 #define KLUDGE
13 
14 /* ***** PLEASE READ BEFORE MAKING MODIFICATIONS *****
15  * The following define must be incremented by 1 whenever a
16  * modification to the array map declarations makes
17  * the register template incompatible with older archived array
18  * maps. This number is recorded with archived array maps for
19  * subsequent comparison against the current value.
20  */
21 #define ARRAYMAP_REVISION 1
22 
23 #define USE_HASH 1
24 
25 /*
26  * Define type aliases for the structures that are being declared
27  * below.
28  */
29 typedef struct ArrayMap ArrayMap;
30 typedef struct ArrRegMap ArrRegMap;
31 typedef struct ArrRegMapReg ArrRegMapReg;
32 /*
33  * A structure of the following type is used to encapsulate a single
34  * register block from an array map
35  */
36 struct ArrRegMapReg {
37  int regmap; // The index of the specified regmap in the array map
38  RegMapReg reg;
39 };
40 
41 int find_ArrRegMapReg(ArrayMap* arraymap,
42  std::string regmap_name, std::string board_name, std::string block_name,
43  RegAspect facet, unsigned index, unsigned n,
44  ArrRegMapReg *reg);
45 
46 int init_ArrRegMapReg(ArrayMap* arraymap,
47  unsigned regmap, unsigned board, unsigned block,
48  unsigned index, unsigned nreg, RegAspect aspect,
49  ArrRegMapReg *reg);
50 
51 RegValidity input_ArrRegMapReg(InputStream *stream, int tell,
52  ArrayMap* arraymap, RegInputMode mode,
53  int extend, ArrRegMapReg *reg);
54 
55 int output_ArrRegMapReg(OutputStream *stream, ArrayMap* arraymap,
56  RegOutputMode mode, ArrRegMapReg *reg);
57 
58 void clr_ArrRegMapReg(ArrRegMapReg *reg);
59 
60 /*
61  * Collect information about a register map.
62  */
63 struct ArrRegMap {
64  char name[REG_NAME_LEN+1]; // An unambiguous name for the register map
65  std::string* comment_;
66 
67  unsigned number; // The index of this register map in the
68  // parent array map
69  int slot; // The start index of this register map
70  // in the archive array
71  unsigned iSlot_; // The start index of this register map
72  // in the slot array
73  int iArcSlot_; // The start index of this register map
74  // in the archive slot array
75  unsigned iByte_; // The sequential byte index of this
76  // register map in the array map
77  int iArcByte_; // The sequential byte index of this
78  // register map in the archived array
79  // map, or -1 if this register map
80  // contains no archived registers in the
81  // archive byte array
82  RegMap *regmap; // Pointer to the register map
83 
84  // Constructor
85 
86  ArrRegMap(ArrayMap* parent, void* vregtemp, unsigned iRegMap, bool addDefaults=true);
87 
88  ArrRegMap();
89 
90  // Destructor
91 
92  ~ArrRegMap();
93 
94  // Return the byte offset in the ArrayMap of this ArrRegMap
95 
96  int byteOffsetInArcArrayMap() {
97  return iArcByte_;
98  };
99 
100  int byteOffsetInWholeArrayMap() {
101  return iByte_;
102  };
103 
104  // Convenience method for the above
105 
106  int byteOffsetInArrayMap(bool archivedOnly) {
107  return archivedOnly ? byteOffsetInArcArrayMap() :
108  byteOffsetInWholeArrayMap();
109  }
110 
111  // Return the byte offset in the ArrayMap of the named block
112 
113  int byteOffsetInArcArrayMapOf(RegMapBlock* block, gcp::util::Coord* coord=0);
114  int byteOffsetInWholeArrayMapOf(RegMapBlock* block, gcp::util::Coord* coord=0);
115 
116  // Convenience method
117 
118  int byteOffsetInArrayMapOf(bool archivedOnly,
119  RegMapBlock* block, gcp::util::Coord* coord=0)
120  {
121  return archivedOnly ? byteOffsetInArcArrayMapOf(block, coord) :
122  byteOffsetInWholeArrayMapOf(block, coord);
123  }
124 
125  // Return the slot offset in the ArrayMap of this ArrRegMap
126 
127  int slotOffsetInArcArrayMap() {
128  return iArcSlot_;
129  };
130 
131  int slotOffsetInWholeArrayMap() {
132  return iSlot_;
133  };
134 
135  // Convenience method for the above
136 
137  int slotOffsetInArrayMap(bool archivedOnly) {
138  return archivedOnly ? slotOffsetInArcArrayMap() :
139  slotOffsetInWholeArrayMap();
140  }
141 
142  // Return the slot offset in the ArrayMap of the named block
143 
144  int slotOffsetInArcArrayMapOf(RegMapBlock* block, gcp::util::Coord* coord=0);
145  int slotOffsetInWholeArrayMapOf(RegMapBlock* block, gcp::util::Coord* coord=0);
146 
147  // Convenience method
148 
149  int slotOffsetInArrayMapOf(bool archivedOnly,
150  RegMapBlock* block, gcp::util::Coord* coord=0)
151  {
152  return archivedOnly ? slotOffsetInArcArrayMapOf(block, coord) :
153  slotOffsetInWholeArrayMapOf(block, coord);
154  }
155 
156  // Return byte statistics for this register map
157 
158  unsigned nByte() {return regmap->nByte();};
159  unsigned nArcByte() {return regmap->nArcByte();};
160 
161  // Convenience method for the above
162 
163  int nByte(bool archivedOnly) {
164  return archivedOnly ? nArcByte() : nByte();
165  }
166 
167  // Return a vector of boards matching the input string
168 
169  std::vector<RegMapBoard*> matchRegMapBoard(std::string regExpString);
170  std::vector<RegMapBoard*> matchRegMapBoard(std::string regExpString,
171  gcp::util::CoordRange& range);
172 };
173 
174 /*
175  * Collect information about all register maps.
176  */
177 struct ArrayMap {
178  unsigned ref_count; /* Reference counter */
179  std::vector<ArrRegMap*> regmaps; /* All register maps in this array */
180  int nregmap; /* The number of register maps */
181 
182 #if USE_HASH
183  HashTable *hash; /* Symbol table of register maps */
184  HashMemory *hash_mem; /* Memory for hash tables */
185 #else
186  std::map<std::string, ArrRegMap*> mapOfRegmaps_;
187 #endif
188 
189  unsigned nreg; /* The total number of registers */
190  unsigned narchive; /* The total number of archived registers */
191  unsigned nByte_; /* The total number of bytes */
192  unsigned nArcByte_; /* The total number of archived bytes */
193 
194  // Constructor
195 
196  ArrayMap(void* vtmp, bool addDefaults=true);
197 
198  // Destructor
199 
200  ~ArrayMap();
201 
202  // Return the offset, in bytes_ of the named board and block from
203  // the start of the archived array
204 
205  int byteOffsetInArcArrayMapOf(std::string regmap, std::string board,
206  std::string block,
207  gcp::util::Coord* coord=0);
208 
209  int byteOffsetInWholeArrayMapOf(std::string regmap, std::string board,
210  std::string block,
211  gcp::util::Coord* coord=0);
212 
213  // Convenience method
214 
215  int byteOffsetOf(bool archivedOnly, std::string regmap, std::string board,
216  std::string block,
217  gcp::util::Coord* coord=0)
218  {
219  return archivedOnly ?
220  byteOffsetInArcArrayMapOf(regmap, board, block, coord) :
221  byteOffsetInWholeArrayMapOf(regmap, board, block, coord);
222  }
223 
224  // Byte offsets
225 
226  int byteOffsetInArcArrayMapOf(ArrRegMap* aregmap, RegMapBlock* block,
227  gcp::util::Coord* coord=0);
228 
229  int byteOffsetInWholeArrayMapOf(ArrRegMap* aregmap, RegMapBlock* block,
230  gcp::util::Coord* coord=0);
231 
232  // Convenience method
233 
234  int byteOffsetOf(bool archivedOnly, ArrRegMap* aregmap, RegMapBlock* block,
235  gcp::util::Coord* coord=0)
236  {
237  return archivedOnly ? byteOffsetInArcArrayMapOf(aregmap, block, coord) :
238  byteOffsetInWholeArrayMapOf(aregmap, block, coord);
239  }
240 
241  // Slot offsets
242 
243  int slotOffsetInArcArrayMapOf(ArrRegMap* aregmap, RegMapBlock* block,
244  gcp::util::Coord* coord=0);
245 
246  int slotOffsetInWholeArrayMapOf(ArrRegMap* aregmap, RegMapBlock* block,
247  gcp::util::Coord* coord=0);
248 
249  // Convenience method
250 
251  int slotOffsetOf(bool archivedOnly, ArrRegMap* aregmap, RegMapBlock* block,
252  gcp::util::Coord* coord=0) {
253  return archivedOnly ? slotOffsetInArcArrayMapOf(aregmap, block, coord) :
254  slotOffsetInWholeArrayMapOf(aregmap, block, coord);
255  }
256 
257  // Return the slot offset in the ArrayMap of the named block
258 
259  int slotOffsetInArcArrayMapOf(std::string regmap, std::string board,
260  std::string block,
261  gcp::util::Coord* coord=0);
262  int slotOffsetInWholeArrayMapOf(std::string regmap, std::string board,
263  std::string block,
264  gcp::util::Coord* coord=0);
265 
266  // Convenience method
267 
268  int slotOffsetOf(bool archivedOnly,
269  std::string regmap, std::string board, std::string block,
270  gcp::util::Coord* coord=0)
271  {
272  return archivedOnly ?
273  slotOffsetInArcArrayMapOf(regmap, board, block, coord) :
274  slotOffsetInWholeArrayMapOf(regmap, board, block, coord);
275  }
276 
277  // Return the number of bytes in this array map
278 
279  int nByte(bool archivedOnly) {
280  return archivedOnly ? nArcByte_ : nByte_;
281  }
282 
283  // Return the number of registers in this array map
284 
285  int nReg(bool archivedOnly) {
286  return archivedOnly ? narchive : nreg;
287  }
288 
289  // Find the named block
290 
291  RegMapBlock* findArrayMapBlock(std::string regmap_name, std::string board_name,
292  std::string block_name,
293  bool doThrow=false);
294  // Find the named board
295 
296  RegMapBoard* findArrayMapBoard(std::string regmap_name,
297  std::string board_name,
298  bool doThrow=false);
299 
300  // Find the named register map
301 
302  RegMap* findRegMap(std::string regmap_name,
303  bool doThrow=false);
304 
305  // Return the arregmap associated wtih a register map
306 
307  ArrRegMap* findArrRegMap(RegMap* regmapPtr);
308  ArrRegMap* findArrRegMap(std::string regmapName);
309 
310  // Return a vector of regmaps which match the input string
311 
312  std::vector<ArrRegMap*> matchArrRegMap(std::string regExpString);
313 
314  void print(bool archivedOnly);
315 
316  std::vector<std::string> getRegisters(bool archivedOnly);
317 };
318 
319 /* Allocate a readonly alias to a given register map. */
320 /* When no longer required this should be discarded by calling */
321 /* del_RegMap(). */
322 
323 ArrayMap *alias_ArrayMap(ArrayMap *arrayMap);
324 
325 /* Delete a register map or one of its aliases. */
326 
327 ArrayMap *del_ArrayMap(ArrayMap *arrayMap);
328 
329 /* Return non-zero if two register maps are equivalent. */
330 
331 int equiv_ArrayMap(ArrayMap *arrayMap1, ArrayMap *arrayMap2);
332 
333 ArrRegMap* find_ArrRegMap(ArrayMap *arrayMap, std::string regMapName);
334 
335 RegMapBlock* find_ArrayMapBlock(ArrayMap *arraymap, std::string regmap_name,
336  std::string board_name, std::string block_name);
337 
338 #endif
Definition: hash.h:119
Definition: hash.h:76
ArrayMap(void *vtmp, bool addDefaults=true)
Definition: arraymap.c:30
int slotOffsetInWholeArrayMapOf(RegMapBlock *block, gcp::util::Coord *coord=0)
Definition: arraymap.c:1567
Definition: input.h:87
Definition: arraymap.h:63
Definition: Coord.h:21
Definition: CoordRange.h:20
~ArrayMap()
Definition: arraymap.c:132
ArrRegMap * findArrRegMap(RegMap *regmapPtr)
Definition: arraymap.c:1327
ArrRegMap()
Definition: arraymap.c:1429
int byteOffsetInArcArrayMapOf(RegMapBlock *block, gcp::util::Coord *coord=0)
Definition: arraymap.c:1540
int slotOffsetInArcArrayMapOf(ArrRegMap *aregmap, RegMapBlock *block, gcp::util::Coord *coord=0)
Definition: arraymap.c:1222
std::vector< ArrRegMap * > matchArrRegMap(std::string regExpString)
Definition: arraymap.c:224
Definition: arraymap.h:36
RegMap * findRegMap(std::string regmap_name, bool doThrow=false)
Definition: arraymap.c:1351
int slotOffsetInArcArrayMapOf(RegMapBlock *block, gcp::util::Coord *coord=0)
Definition: arraymap.c:1558
int slotOffsetInWholeArrayMapOf(ArrRegMap *aregmap, RegMapBlock *block, gcp::util::Coord *coord=0)
Definition: arraymap.c:1238
Definition: output.h:40
RegMapBlock * findArrayMapBlock(std::string regmap_name, std::string board_name, std::string block_name, bool doThrow=false)
Definition: arraymap.c:1289
~ArrRegMap()
Definition: arraymap.c:1446
RegMapBoard * findArrayMapBoard(std::string regmap_name, std::string board_name, bool doThrow=false)
Definition: arraymap.c:1307
int byteOffsetInWholeArrayMapOf(RegMapBlock *block, gcp::util::Coord *coord=0)
Definition: arraymap.c:1549
Definition: arraymap.h:177