Bitstream Interpretation Library (BIL)  0.1
XDLRCParserImp5.cpp
Go to the documentation of this file.
1 
6 #include <algorithm>
11 
12 using namespace bil;
13 using namespace bil::xdlrcparser_detail;
14 
15 
16 void XDLRCParserImp::clearAll()
17 {
18  // second pass not possible after clearing temp data
19  m_secondPassEnabled = false;
20 
21  // clear all temporary data of the parser
22  m_tileMap.clear();
23  m_tileTypeMap.clear();
24  m_tileTypesEx.clear();
25  m_primitiveTypeMap.clear();
26  m_pinMaps.clear();
27 
28  // clear all pointers
29  m_tok = 0;
30  m_device = 0;
31  m_tiles = 0;
32  m_tileTypes = 0;
33  m_primitiveTypes = 0;
34  resetTempPointers();
35 }
36 
37 
38 void XDLRCParserImp::resetTempPointers()
39 {
40  // reset pointers for safety (excluding the ones that must preserved)
41  m_tile = 0;
42  m_sites = 0;
43  m_tileType = 0;
44  m_siteTypes = 0;
45  m_siteType = 0;
46  m_pinWires = 0;
47  m_wires = 0;
48  m_connections = 0;
49  m_pips = 0;
50  m_primitiveType = 0;
51  m_pins = 0;
52  m_pin = 0;
53  m_elements = 0;
54  m_tileTypeEx = 0;
55  m_wireMap = 0;
56  m_pipSet = 0;
57  m_pinMap = 0;
58 }
59 
60 
61 void XDLRCParserImp::setupSyntax()
62 {
63  m_tok->resetSyntax();
64  m_tok->commentChar('#');
65  m_tok->whitespaceChar(' ');
66  m_tok->whitespaceChar('\t');
67  m_tok->whitespaceChar('\n');
68  m_tok->whitespaceChar('\r');
69  m_tok->wordChars('a', 'z');
70  m_tok->wordChars('A', 'Z');
71  m_tok->wordChars('0', '9');
72  m_tok->wordChar('_');
73  m_tok->wordChar('-');
74  m_tok->wordChar('.');
75 }
76 
77 
78 void XDLRCParserImp::addTile(const char* tileName)
79 {
80  // check, if given name is not already in use
81  tileMap_t::iterator lb = m_tileMap.lower_bound(tileName);
82  if ((m_tileMap.end() != lb) && (tileName == lb->first)) throw Exception();
83 
84  // create new tile, set its name, cache pointer to its sites
85  size_t count = m_tiles->size();
86  m_tiles->push_back(Tile());
87  m_tile = &((*m_tiles)[count]);
88  (m_tile->name()).assign(tileName);
89  m_sites = &(m_tile->primitiveSites());
90 
91  // insert tile name and index into map
92  m_tileMap.insert(lb, std::make_pair(tileName, count));
93 }
94 
95 
96 void XDLRCParserImp::addTileType(const char* typeName)
97 {
98  // Check, if given type already exists: if not, create it.
99  tileTypeMap_t::iterator lb = m_tileTypeMap.lower_bound(typeName);
100  if ((m_tileTypeMap.end() == lb) || (typeName != lb->first))
101  {
102  // create a new tile type
103  size_t count = m_tileTypes->size();
104  m_tileTypes->push_back(TileType());
105  m_tileType = &((*m_tileTypes)[count]);
106  // set its name and tag it with its type index
107  (m_tileType->name()).assign(typeName);
108  m_tileType->tag(count);
109 
110  // create also extended info for it
111  m_tileTypesEx.push_back(TileTypeEx());
112  m_tileTypeEx = &(m_tileTypesEx[count]);
113  m_tileTypeEx->writeSiteTypes = true;
114 
115  // create a new entry in tile type map
116  tileTypeMap_t::iterator it =
117  m_tileTypeMap.insert(lb, std::make_pair(typeName, count));
118  }
119  else
120  {
121  // fetch tile type index from map
122  size_t tileTypeIndex = lb->second;
123  // get pointers to tile type and its extended info
124  m_tileType = &((*m_tileTypes)[tileTypeIndex]);
125  m_tileTypeEx = &(m_tileTypesEx[tileTypeIndex]);
126  }
127 
128  // cache pointers to wires and pips of current tile type
129  m_wires = &(m_tileType->wires());
130  m_pips = &(m_tileType->pips());
131  // cache pointers to wire and pip maps
132  m_wireMap = &(m_tileTypeEx->wireMap);
133  m_pipSet = &(m_tileTypeEx->pipSet);
134 }
135 
136 
137 void XDLRCParserImp::addWire(const char* wireName)
138 {
139  // Check, if a wire with given name already exists: if not, create it.
140  wireMap_t::iterator lb = m_wireMap->lower_bound(wireName);
141  if ((m_wireMap->end() != lb) && (wireName == lb->first)) return;
142 
143  // create a new wire and set its name
144  size_t count = m_wires->size();
145  m_wires->push_back(Wire());
146  Wire& wire = (*m_wires)[count];
147  (wire.name()).assign(wireName);
148 
149  // create a new entry for that wire in map
150  m_wireMap->insert(lb, std::make_pair(wireName, count));
151 }
152 
153 
154 void XDLRCParserImp::addConnection(WireConnection& connection)
155 {
156  // add connection, if not already in list
157  WireConnections::const_iterator itBegin = m_connections->begin();
158  WireConnections::const_iterator itEnd = m_connections->end();
159  if (std::find(itBegin, itEnd, connection) == itEnd)
160  m_connections->push_back(connection);
161 }
162 
163 
164 void XDLRCParserImp::addPIP(const PIP& pip)
165 {
166  // check, if given PIP is already in PIP set
167  pipSet_t::iterator lb = m_pipSet->lower_bound(pip);
168  if ((m_pipSet->end() != lb) && (pip == (*lb))) return;
169 
170  // if not, copy it to PIP list and add it to set
171  m_pips->push_back(pip);
172  m_pipSet->insert(lb, pip);
173 }
174 
175 
176 void XDLRCParserImp::addPrimitiveType(const char* typeName)
177 {
178  // check, if given type name is not already in use
179  primitiveTypeMap_t::iterator lb = m_primitiveTypeMap.lower_bound(typeName);
180  if ((m_primitiveTypeMap.end() != lb) && (typeName == lb->first)) throw Exception();
181 
182  // create new primitive type
183  size_t count = m_primitiveTypes->size();
184  m_primitiveTypes->push_back(PrimitiveType());
185  m_primitiveType = &((*m_primitiveTypes)[count]);
186 
187  // set its name and tag it with its type index
188  (m_primitiveType->name()).assign(typeName);
189  m_primitiveType->tag(count);
190 
191  // create also pin map for it
192  m_pinMaps.push_back(pinMap_t());
193 
194  // insert primitive type name and index into map
195  m_primitiveTypeMap.insert(lb, std::make_pair(typeName, count));
196 
197  // cache pointers to pins and elements of current primitive type
198  m_pins = &(m_primitiveType->pins());
199  m_elements = &(m_primitiveType->elements());
200  // cache pointers to pin map
201  m_pinMap = &(m_pinMaps[count]);
202 }
203 
204 
205 void XDLRCParserImp::addPin(const char* pinName)
206 {
207  // check, if given pin name is not already in use
208  pinMap_t::iterator lb = m_pinMap->lower_bound(pinName);
209  if ((m_pinMap->end() != lb) && (pinName == lb->first)) throw Exception();
210 
211  // create a new pin and set its name
212  size_t count = m_pins->size();
213  m_pins->push_back(Pin());
214  m_pin = &((*m_pins)[count]);
215  (m_pin->externalName()).assign(pinName);
216 
217  // create a new entry for that pin in map
218  m_pinMap->insert(lb, std::make_pair(pinName, count));
219 }
220 
221 
222 size_t XDLRCParserImp::findTile(const char* tileName)
223 {
224  // search for tile with given name
225  tileMap_t::const_iterator it = m_tileMap.find(tileName);
226  if (m_tileMap.end() == it) throw Exception();
227  // return index of found tile
228  return (it->second);
229 }
230 
231 
232 size_t XDLRCParserImp::findWire(const char* wireName, wireMap_t& wireMap)
233 {
234  // search for wire with given name
235  wireMap_t::const_iterator it = wireMap.find(wireName);
236  if (wireMap.end() == it) throw Exception();
237  // return index of found wire
238  return it->second;
239 }
240 
241 
242 size_t XDLRCParserImp::findPrimitiveType(const char* typeName)
243 {
244  // search for primitive type with given name
245  primitiveTypeMap_t::const_iterator it = m_primitiveTypeMap.find(typeName);
246  if (m_primitiveTypeMap.end() == it) throw Exception();
247  // return index of found primitive type
248  return it->second;
249 }
250 
251 
252 size_t XDLRCParserImp::findPin(const char* pinName)
253 {
254  // search for pin with given name
255  pinMap_t::const_iterator it = m_pinMap->find(pinName);
256  if (m_pinMap->end() == it) throw Exception();
257  // return index of found pin
258  return it->second;
259 }