Bitstream Interpretation Library (BIL)  0.1
XDLParserImp1.cpp
Go to the documentation of this file.
1 
9 
10 using namespace bil;
11 using namespace bil::xdlparser_detail;
12 
13 const size_t INSTANCES_PREALLOCATION_COUNT = 8000;
14 const size_t NETS_PREALLOCATION_COUNT = 8000;
15 
16 
17 void XDLParserImp::parseHeader(StreamTokenizer& tokenizer, Design& design)
18 {
19  // clear out parser
20  clearAll();
21 
22  // save stream tokenizer pointer and prepare it
23  m_tok = &tokenizer;
24  setupSyntax();
25 
26  // save design pointer and clear out design
27  m_design = &design;
28  m_instances = &(design.instances());
29  m_nets = &(design.nets());
30  design.clear();
31 
32  // skip keyword
33  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
34  if (strcmp(m_tok->wordToken(), XDLKeywords::DESIGN) != 0) throw Exception();
35 
36  // read design name
37  parseQuotedString();
38  (design.name()).assign(m_quoteBuffer);
39 
40  // read target device name
41  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
42  (design.deviceName()).assign(m_tok->wordToken());
43 
44  // read NCD version string
45  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
46  (design.ncdVersion()).assign(m_tok->wordToken());
47 
48  // skip comma
49  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
50  if (',' != m_tok->separatorToken()) throw Exception();
51 
52  // skip keyword
53  if (StreamTokenizer::TT_WORD != m_tok->nextToken()) throw Exception();
54  if (strcmp(m_tok->wordToken(), XDLKeywords::CFG) != 0) throw Exception();
55 
56  // read design attributes
57  parseQuotedString();
58  (design.attributes()).assign(m_quoteBuffer);
59 
60  // skip semicolon
61  if (StreamTokenizer::TT_SEPARATOR != m_tok->nextToken()) throw Exception();
62  if (';' != m_tok->separatorToken()) throw Exception();
63 
64  // success
65  m_headerParsed = true;
66 }
67 
68 
69 void XDLParserImp::parseBody(const Device& device)
70 {
71  // check if body can no be parsed
72  if (!m_headerParsed) throw Exception();
73  m_headerParsed = false;
74 
75  // prepare stream tokenizer
76  setupSyntax();
77 
78  // save pointer and fill device lookup structures
79  m_device = &device;
80  m_tiles = &(device.tiles());
81  fillDeviceLookups();
82 
83  // preallocate memory for instances and nets
84  m_instances->reserve(INSTANCES_PREALLOCATION_COUNT);
85  m_nets->reserve(NETS_PREALLOCATION_COUNT);
86 
87  // parse instances
88  StreamTokenizer::token_t tokenType;
89  const char* keyword = 0;
90  for (;;)
91  {
92  // get next token
93  tokenType = m_tok->nextToken();
94  if (StreamTokenizer::TT_WORD != tokenType) break;
95  keyword = m_tok->wordToken();
96 
97  // check if current token is instance keyword
98  if ((strcmp(keyword, XDLKeywords::INST) != 0) &&
99  (strcmp(keyword, XDLKeywords::INSTANCE) != 0)) break;
100 
101  // if so, parse instance
102  parseInstance();
103  }
104 
105  // parse nets
106  for (;;)
107  {
108  // check if current token is net keyword
109  if (StreamTokenizer::TT_WORD != tokenType) break;
110  if (strcmp(keyword, XDLKeywords::NET) != 0) break;
111 
112  // if so, parse net
113  parseNet();
114 
115  // get next token
116  tokenType = m_tok->nextToken();
117  if (StreamTokenizer::TT_WORD != tokenType) break;
118  keyword = m_tok->wordToken();
119  }
120 
121  // check end of file
122  if (StreamTokenizer::TT_EOF != tokenType) throw Exception();
123 
124  // reset parser
125  clearAll();
126 }