Bitstream Interpretation Library (BIL)  0.1
XDLRCParserImp1.cpp
Go to the documentation of this file.
1 
10 #include <xdlrc/util/NameSplit.hpp>
11 
12 using namespace bil;
13 using namespace bil::xdlrcparser_detail;
14 
15 
16 void XDLRCParserImp::parse1stTiles()
17 {
18  // read row count
19  unsigned rows;
20  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
21  if (!m_tok->uintToken(rows)) throw Exception();
22 
23  // read column count
24  unsigned cols;
25  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
26  if (!m_tok->uintToken(cols)) throw Exception();
27 
28  // reserve tile memory
29  m_tiles->reserve(rows * cols);
30 
31  // parse tiles
32  for (;;)
33  {
34  // skip opening parenthesis
35  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
36  if (')' == m_tok->separatorToken()) return;
37  if ('(' != m_tok->separatorToken()) throw Exception();
38 
39  // skip keyword
40  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
41  if (strcmp(m_tok->wordToken(), XDLRCKeywords::TILE) != 0) throw Exception();
42  parse1stTile();
43  }
44 }
45 
46 
47 void XDLRCParserImp::parse1stTile()
48 {
49  // read row position
50  unsigned x;
51  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
52  if (!m_tok->uintToken(x)) throw Exception();
53 
54  // read column position
55  unsigned y;
56  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
57  if (!m_tok->uintToken(y)) throw Exception();
58 
59  // read tile name and create new tile from it
60  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
61  addTile(m_tok->wordToken());
62  m_tile->row(static_cast<unsigned short>(x));
63  m_tile->column(static_cast<unsigned short>(y));
64  if (!extractPosition(m_tok->wordToken(), x, y)) throw Exception();
65  m_tile->siteX(static_cast<unsigned short>(x));
66  m_tile->siteY(static_cast<unsigned short>(y));
67 
68  // read tile type name and create/find corresponding type
69  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
70  addTileType(m_tok->wordToken());
71  // set tile type
72  m_tile->typeIndex(static_cast<unsigned short>(m_tileType->tag()));
73 
74  // read primitive site count and reserve site names
75  size_t count;
76  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
77  if (!m_tok->uintToken(count)) throw Exception();
78  m_sites->reserve(count);
79 
80  // parse primitive sites
81  for (;;)
82  {
83  // skip parenthesis
84  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
85  if (')' == m_tok->separatorToken()) return;
86  if ('(' != m_tok->separatorToken()) throw Exception();
87 
88  // parse primitive site if keyword matches
89  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
90  if (strcmp(m_tok->wordToken(), XDLRCKeywords::PRIMITIVE_SITE) != 0) break;
91  parse1stPrimitiveSite();
92  }
93 
94  // parse wires
95  for (;;)
96  {
97  // parse a wire if keyword matches
98  if (strcmp(m_tok->wordToken(), XDLRCKeywords::WIRE) != 0) break;
99  parse1stWire();
100 
101  // skip parenthesis
102  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
103  if (')' == m_tok->separatorToken()) return;
104  if ('(' != m_tok->separatorToken()) throw Exception();
105 
106  // skip keyword
107  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
108  }
109 
110  // parse PIPs
111  for (;;)
112  {
113  // parse a PIP if keyword matches
114  if (strcmp(m_tok->wordToken(), XDLRCKeywords::PIP) != 0) break;
115  parse1stPIP();
116 
117  // skip parenthesis
118  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
119  if (')' == m_tok->separatorToken()) return;
120  if ('(' != m_tok->separatorToken()) throw Exception();
121 
122  // skip keyword
123  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
124  }
125 
126  // skip keyword
127  if (strcmp(m_tok->wordToken(), XDLRCKeywords::TILE_SUMMARY) != 0) throw Exception();
128  // parse tile summary
129  parseTileSummary();
130 
131  // skip closing parenthesis
132  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
133  if (')' != m_tok->separatorToken()) throw Exception();
134 }
135 
136 
137 void XDLRCParserImp::parse1stPrimitiveSite()
138 {
139  // create new primitive site
140  size_t count = m_sites->size();
141  m_sites->push_back(PrimitiveSite());
142  PrimitiveSite& primitiveSite = ((*m_sites)[count]);
143 
144  // read site name and set it
145  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
146  (primitiveSite.name()).assign(m_tok->wordToken());
147 
148  // skip site type
149  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
150 
151  // read bonded flag and set it
152  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
153  const char* s = m_tok->wordToken();
154  if (strcmp(s, XDLRCKeywords::INTERNAL) == 0) primitiveSite.isBonded(false);
155  else if (strcmp(s, XDLRCKeywords::BONDED) == 0) primitiveSite.isBonded(true);
156  else if (strcmp(s, XDLRCKeywords::UNBONDED) == 0) primitiveSite.isBonded(false);
157  else throw Exception();
158 
159  // skip pin wire count
160  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
161  if (!m_tok->uintToken(count)) throw Exception();
162 
163  // pin wires
164  for (;;)
165  {
166  // skip parenthesis
167  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
168  if (')' == m_tok->separatorToken()) return;
169  if ('(' != m_tok->separatorToken()) throw Exception();
170 
171  // skip keyword
172  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
173  if (strcmp(m_tok->wordToken(), XDLRCKeywords::PINWIRE) != 0) throw Exception();
174 
175  // skip pin name
176  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
177 
178  // skip in/out keyword
179  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
180  s = m_tok->wordToken();
181  if ((strcmp(s, XDLRCKeywords::INPUT) != 0) &&
182  (strcmp(s, XDLRCKeywords::OUTPUT) != 0))
183  throw Exception();
184 
185  // skip wire name
186  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
187 
188  // skip closing parenthesis
189  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
190  if (')' != m_tok->separatorToken()) throw Exception();
191  }
192 }
193 
194 
195 void XDLRCParserImp::parse1stWire()
196 {
197  // read wire name and create/find it
198  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
199  addWire(m_tok->wordToken());
200 
201  // skip connection count
202  size_t count;
203  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
204  if (!m_tok->uintToken(count)) throw Exception();
205 
206  // connections
207  for (;;)
208  {
209  // skip parenthesis
210  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
211  if (')' == m_tok->separatorToken()) return;
212  if ('(' != m_tok->separatorToken()) throw Exception();
213 
214  // skip keyword
215  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
216  if (strcmp(m_tok->wordToken(), XDLRCKeywords::CONN) != 0) throw Exception();
217 
218  // skip destination tile name
219  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
220 
221  // skip destination wire name
222  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
223 
224  // skip closing parenthesis
225  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
226  if (')' != m_tok->separatorToken()) throw Exception();
227  }
228 }
229 
230 
231 void XDLRCParserImp::parse1stPIP()
232 {
233  // skip tile name
234  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
235 
236  // read start wire and search for it on current tile
237  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
238  size_t startWireIndex = findWire(m_tok->wordToken(), *m_wireMap);
239 
240  // read PIP direction keyword
241  m_tok->wordChar('=');
242  m_tok->wordChar('>');
243  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
244  PIPDirection::direction_t dir = PIPDirection::fromString(m_tok->wordToken());
245  m_tok->separatorChar('=');
246  m_tok->separatorChar('>');
247 
248  // read end wire and search for it on current tile
249  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
250  size_t endWireIndex = findWire(m_tok->wordToken(), *m_wireMap);
251 
252  // create new PIP
253  PIP pip;
254  pip.startWireIndex(static_cast<unsigned short>(startWireIndex));
255  pip.direction(dir);
256  pip.endWireIndex(static_cast<unsigned short>(endWireIndex));
257  // add it (if not already present)
258  addPIP(pip);
259 
260  // skip parenthesis
261  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
262  if (')' == m_tok->separatorToken()) return;
263  if ('(' != m_tok->separatorToken()) throw Exception();
264 
265  // skip route-through name
266  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
267  // skip route-through site type
268  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
269  // skip closing parenthesis
270  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
271  if (')' != m_tok->separatorToken()) throw Exception();
272  // skip closing parenthesis
273  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
274  if (')' != m_tok->separatorToken()) throw Exception();
275 }