1 using System;
2
3
4
5 namespace IntermediateCodeTokens
6 {
7 public const int END = 0;
8
9 public const int CU = 1;
10
11 public const int ID = 2;
12
13 public const int TYPES = 3;
14
15 public const int DATA = 4;
16
17 public const int FUNCTION = 5;
18
19 public const int ONCE = 6;
20
21 public const int STORE = 7;
22
23 public const int ARG = 8;
24
25 public const int JMP = 9;
26
27 public const int BRANCH = 10;
28
29 public const int CALL = 11;
30
31 public const int RET = 12;
32
33 public const int SWITCH = 13;
34
35 public const int NOP = 14;
36
37 public const int SAVE = 15;
38
39 public const int NOT = 16;
40
41 public const int NEG = 17;
42
43 public const int SIGNEXTEND = 18;
44
45 public const int ZEROEXTEND = 19;
46
47 public const int TRUNCATE = 20;
48
49 public const int BITCAST = 21;
50
51 public const int INTTOFLOAT = 22;
52
53 public const int FLOATTOINT = 23;
54
55 public const int INTTOPTR = 24;
56
57 public const int PTRTOINT = 25;
58
59 public const int ADD = 26;
60
61 public const int SUB = 27;
62
63 public const int MUL = 28;
64
65 public const int DIV = 29;
66
67 public const int MOD = 30;
68
69 public const int AND = 31;
70
71 public const int OR = 32;
72
73 public const int XOR = 33;
74
75 public const int SHL = 34;
76
77 public const int SHR = 35;
78
79 public const int EQUAL = 36;
80
81 public const int LESS = 37;
82
83 public const int PARAM = 38;
84
85 public const int LOCAL = 39;
86
87 public const int LOAD = 40;
88
89 public const int ELEMADDR = 41;
90
91 public const int PTROFFSET = 42;
92
93 public const int PTRDIFF = 43;
94
95 public const int TRAP = 44;
96
97 public const int TYPE = 45;
98
99 public const int OFFSET = 46;
100
101 public const int SIZE = 47;
102
103 public const int ALIGNMENT = 48;
104
105 public const int VOID = 49;
106
107 public const int BOOL = 50;
108
109 public const int SBYTE = 51;
110
111 public const int BYTE = 52;
112
113 public const int SHORT = 53;
114
115 public const int USHORT = 54;
116
117 public const int INT = 55;
118
119 public const int UINT = 56;
120
121 public const int LONG = 57;
122
123 public const int ULONG = 58;
124
125 public const int FLOAT = 59;
126
127 public const int DOUBLE = 60;
128
129 public const int TRUE = 61;
130
131 public const int FALSE = 62;
132
133 public const int NULL = 63;
134
135 public const int CONV = 64;
136
137 public const int METADATA = 65;
138
139 public const int LPAREN = 66;
140
141 public const int RPAREN = 67;
142
143 public const int COMMA = 68;
144
145 public const int LBRACE = 69;
146
147 public const int RBRACE = 70;
148
149 public const int AST = 71;
150
151 public const int COLON = 72;
152
153 public const int SEMICOLON = 73;
154
155 public const int LBRACKET = 74;
156
157 public const int RBRACKET = 75;
158
159 public const int ASSIGN = 76;
160
161 public const int AT = 77;
162
163 public const int DOLLAR = 78;
164
165 public const int EXCLAMATION = 79;
166
167 public const int TYPEID = 80;
168
169 public const int CLSID = 81;
170
171 public const int STRING = 82;
172
173 public const int NUMBER = 83;
174
175 public const int HEXNUM = 84;
176
177 internal class TokenMap
178 {
179 static TokenMap() :
180 instance(new TokenMap())
181 {
182 }
183 public static TokenMap& Instance()
184 {
185 return *instance;
186 }
187 public int GetTokenId(const ustring& tokenName)
188 {
189 System.Collections.Map<ustring, int>.ConstIterator it = tokenIdMap.CFind(tokenName);
190 if (it != tokenIdMap.CEnd())
191 {
192 return it->second;
193 }
194 else
195 {
196 return -1;
197 }
198 }
199 public ustring GetTokenName(int tokenId)
200 {
201 return tokenNameList[tokenId];
202 }
203 public ustring GetTokenInfo(int tokenId)
204 {
205 return tokenInfoList[tokenId];
206 }
207 private TokenMap()
208 {
209 tokenIdMap[u"ADD"] = 26;
210 tokenIdMap[u"ALIGNMENT"] = 48;
211 tokenIdMap[u"AND"] = 31;
212 tokenIdMap[u"ARG"] = 8;
213 tokenIdMap[u"ASSIGN"] = 76;
214 tokenIdMap[u"AST"] = 71;
215 tokenIdMap[u"AT"] = 77;
216 tokenIdMap[u"BITCAST"] = 21;
217 tokenIdMap[u"BOOL"] = 50;
218 tokenIdMap[u"BRANCH"] = 10;
219 tokenIdMap[u"BYTE"] = 52;
220 tokenIdMap[u"CALL"] = 11;
221 tokenIdMap[u"CLSID"] = 81;
222 tokenIdMap[u"COLON"] = 72;
223 tokenIdMap[u"COMMA"] = 68;
224 tokenIdMap[u"CONV"] = 64;
225 tokenIdMap[u"CU"] = 1;
226 tokenIdMap[u"DATA"] = 4;
227 tokenIdMap[u"DIV"] = 29;
228 tokenIdMap[u"DOLLAR"] = 78;
229 tokenIdMap[u"DOUBLE"] = 60;
230 tokenIdMap[u"ELEMADDR"] = 41;
231 tokenIdMap[u"EQUAL"] = 36;
232 tokenIdMap[u"EXCLAMATION"] = 79;
233 tokenIdMap[u"FALSE"] = 62;
234 tokenIdMap[u"FLOAT"] = 59;
235 tokenIdMap[u"FLOATTOINT"] = 23;
236 tokenIdMap[u"FUNCTION"] = 5;
237 tokenIdMap[u"HEXNUM"] = 84;
238 tokenIdMap[u"ID"] = 2;
239 tokenIdMap[u"INT"] = 55;
240 tokenIdMap[u"INTTOFLOAT"] = 22;
241 tokenIdMap[u"INTTOPTR"] = 24;
242 tokenIdMap[u"JMP"] = 9;
243 tokenIdMap[u"LBRACE"] = 69;
244 tokenIdMap[u"LBRACKET"] = 74;
245 tokenIdMap[u"LESS"] = 37;
246 tokenIdMap[u"LOAD"] = 40;
247 tokenIdMap[u"LOCAL"] = 39;
248 tokenIdMap[u"LONG"] = 57;
249 tokenIdMap[u"LPAREN"] = 66;
250 tokenIdMap[u"METADATA"] = 65;
251 tokenIdMap[u"MOD"] = 30;
252 tokenIdMap[u"MUL"] = 28;
253 tokenIdMap[u"NEG"] = 17;
254 tokenIdMap[u"NOP"] = 14;
255 tokenIdMap[u"NOT"] = 16;
256 tokenIdMap[u"NULL"] = 63;
257 tokenIdMap[u"NUMBER"] = 83;
258 tokenIdMap[u"OFFSET"] = 46;
259 tokenIdMap[u"ONCE"] = 6;
260 tokenIdMap[u"OR"] = 32;
261 tokenIdMap[u"PARAM"] = 38;
262 tokenIdMap[u"PTRDIFF"] = 43;
263 tokenIdMap[u"PTROFFSET"] = 42;
264 tokenIdMap[u"PTRTOINT"] = 25;
265 tokenIdMap[u"RBRACE"] = 70;
266 tokenIdMap[u"RBRACKET"] = 75;
267 tokenIdMap[u"RET"] = 12;
268 tokenIdMap[u"RPAREN"] = 67;
269 tokenIdMap[u"SAVE"] = 15;
270 tokenIdMap[u"SBYTE"] = 51;
271 tokenIdMap[u"SEMICOLON"] = 73;
272 tokenIdMap[u"SHL"] = 34;
273 tokenIdMap[u"SHORT"] = 53;
274 tokenIdMap[u"SHR"] = 35;
275 tokenIdMap[u"SIGNEXTEND"] = 18;
276 tokenIdMap[u"SIZE"] = 47;
277 tokenIdMap[u"STORE"] = 7;
278 tokenIdMap[u"STRING"] = 82;
279 tokenIdMap[u"SUB"] = 27;
280 tokenIdMap[u"SWITCH"] = 13;
281 tokenIdMap[u"TRAP"] = 44;
282 tokenIdMap[u"TRUE"] = 61;
283 tokenIdMap[u"TRUNCATE"] = 20;
284 tokenIdMap[u"TYPE"] = 45;
285 tokenIdMap[u"TYPEID"] = 80;
286 tokenIdMap[u"TYPES"] = 3;
287 tokenIdMap[u"UINT"] = 56;
288 tokenIdMap[u"ULONG"] = 58;
289 tokenIdMap[u"USHORT"] = 54;
290 tokenIdMap[u"VOID"] = 49;
291 tokenIdMap[u"XOR"] = 33;
292 tokenIdMap[u"ZEROEXTEND"] = 19;
293 tokenNameList.Add(u"END");
294 tokenInfoList.Add(u"end of file");
295 tokenNameList.Add(u"CU");
296 tokenInfoList.Add(u"'cu'");
297 tokenNameList.Add(u"ID");
298 tokenInfoList.Add(u"identifier");
299 tokenNameList.Add(u"TYPES");
300 tokenInfoList.Add(u"'types'");
301 tokenNameList.Add(u"DATA");
302 tokenInfoList.Add(u"'data'");
303 tokenNameList.Add(u"FUNCTION");
304 tokenInfoList.Add(u"'function'");
305 tokenNameList.Add(u"ONCE");
306 tokenInfoList.Add(u"'once'");
307 tokenNameList.Add(u"STORE");
308 tokenInfoList.Add(u"'store'");
309 tokenNameList.Add(u"ARG");
310 tokenInfoList.Add(u"'arg'");
311 tokenNameList.Add(u"JMP");
312 tokenInfoList.Add(u"'jmp'");
313 tokenNameList.Add(u"BRANCH");
314 tokenInfoList.Add(u"'branch'");
315 tokenNameList.Add(u"CALL");
316 tokenInfoList.Add(u"'call'");
317 tokenNameList.Add(u"RET");
318 tokenInfoList.Add(u"'ret'");
319 tokenNameList.Add(u"SWITCH");
320 tokenInfoList.Add(u"'switch'");
321 tokenNameList.Add(u"NOP");
322 tokenInfoList.Add(u"'nop'");
323 tokenNameList.Add(u"SAVE");
324 tokenInfoList.Add(u"'save'");
325 tokenNameList.Add(u"NOT");
326 tokenInfoList.Add(u"'not'");
327 tokenNameList.Add(u"NEG");
328 tokenInfoList.Add(u"'neg'");
329 tokenNameList.Add(u"SIGNEXTEND");
330 tokenInfoList.Add(u"'signextend'");
331 tokenNameList.Add(u"ZEROEXTEND");
332 tokenInfoList.Add(u"'zeroextend'");
333 tokenNameList.Add(u"TRUNCATE");
334 tokenInfoList.Add(u"'truncate'");
335 tokenNameList.Add(u"BITCAST");
336 tokenInfoList.Add(u"'bitcast'");
337 tokenNameList.Add(u"INTTOFLOAT");
338 tokenInfoList.Add(u"'inttofloat'");
339 tokenNameList.Add(u"FLOATTOINT");
340 tokenInfoList.Add(u"'floattoint'");
341 tokenNameList.Add(u"INTTOPTR");
342 tokenInfoList.Add(u"'inttoptr'");
343 tokenNameList.Add(u"PTRTOINT");
344 tokenInfoList.Add(u"'ptrtoint'");
345 tokenNameList.Add(u"ADD");
346 tokenInfoList.Add(u"'add'");
347 tokenNameList.Add(u"SUB");
348 tokenInfoList.Add(u"'sub'");
349 tokenNameList.Add(u"MUL");
350 tokenInfoList.Add(u"'mul'");
351 tokenNameList.Add(u"DIV");
352 tokenInfoList.Add(u"'div'");
353 tokenNameList.Add(u"MOD");
354 tokenInfoList.Add(u"'mod'");
355 tokenNameList.Add(u"AND");
356 tokenInfoList.Add(u"'and'");
357 tokenNameList.Add(u"OR");
358 tokenInfoList.Add(u"'or'");
359 tokenNameList.Add(u"XOR");
360 tokenInfoList.Add(u"'xor'");
361 tokenNameList.Add(u"SHL");
362 tokenInfoList.Add(u"'shl'");
363 tokenNameList.Add(u"SHR");
364 tokenInfoList.Add(u"'shr'");
365 tokenNameList.Add(u"EQUAL");
366 tokenInfoList.Add(u"'equal'");
367 tokenNameList.Add(u"LESS");
368 tokenInfoList.Add(u"'less'");
369 tokenNameList.Add(u"PARAM");
370 tokenInfoList.Add(u"'param'");
371 tokenNameList.Add(u"LOCAL");
372 tokenInfoList.Add(u"'local'");
373 tokenNameList.Add(u"LOAD");
374 tokenInfoList.Add(u"'load'");
375 tokenNameList.Add(u"ELEMADDR");
376 tokenInfoList.Add(u"'elemaddr'");
377 tokenNameList.Add(u"PTROFFSET");
378 tokenInfoList.Add(u"'ptroffset'");
379 tokenNameList.Add(u"PTRDIFF");
380 tokenInfoList.Add(u"'ptrdiff'");
381 tokenNameList.Add(u"TRAP");
382 tokenInfoList.Add(u"'trap'");
383 tokenNameList.Add(u"TYPE");
384 tokenInfoList.Add(u"'type'");
385 tokenNameList.Add(u"OFFSET");
386 tokenInfoList.Add(u"'offset'");
387 tokenNameList.Add(u"SIZE");
388 tokenInfoList.Add(u"'size'");
389 tokenNameList.Add(u"ALIGNMENT");
390 tokenInfoList.Add(u"'alignment'");
391 tokenNameList.Add(u"VOID");
392 tokenInfoList.Add(u"'void'");
393 tokenNameList.Add(u"BOOL");
394 tokenInfoList.Add(u"'bool'");
395 tokenNameList.Add(u"SBYTE");
396 tokenInfoList.Add(u"'sbyte'");
397 tokenNameList.Add(u"BYTE");
398 tokenInfoList.Add(u"'byte'");
399 tokenNameList.Add(u"SHORT");
400 tokenInfoList.Add(u"'short'");
401 tokenNameList.Add(u"USHORT");
402 tokenInfoList.Add(u"'ushort'");
403 tokenNameList.Add(u"INT");
404 tokenInfoList.Add(u"'int'");
405 tokenNameList.Add(u"UINT");
406 tokenInfoList.Add(u"'uint'");
407 tokenNameList.Add(u"LONG");
408 tokenInfoList.Add(u"'long'");
409 tokenNameList.Add(u"ULONG");
410 tokenInfoList.Add(u"'ulong'");
411 tokenNameList.Add(u"FLOAT");
412 tokenInfoList.Add(u"'float'");
413 tokenNameList.Add(u"DOUBLE");
414 tokenInfoList.Add(u"'double'");
415 tokenNameList.Add(u"TRUE");
416 tokenInfoList.Add(u"'true'");
417 tokenNameList.Add(u"FALSE");
418 tokenInfoList.Add(u"'false'");
419 tokenNameList.Add(u"NULL");
420 tokenInfoList.Add(u"'null'");
421 tokenNameList.Add(u"CONV");
422 tokenInfoList.Add(u"'conv'");
423 tokenNameList.Add(u"METADATA");
424 tokenInfoList.Add(u"'metadata'");
425 tokenNameList.Add(u"LPAREN");
426 tokenInfoList.Add(u"'('");
427 tokenNameList.Add(u"RPAREN");
428 tokenInfoList.Add(u"')'");
429 tokenNameList.Add(u"COMMA");
430 tokenInfoList.Add(u"','");
431 tokenNameList.Add(u"LBRACE");
432 tokenInfoList.Add(u"'{'");
433 tokenNameList.Add(u"RBRACE");
434 tokenInfoList.Add(u"'}'");
435 tokenNameList.Add(u"AST");
436 tokenInfoList.Add(u"'*'");
437 tokenNameList.Add(u"COLON");
438 tokenInfoList.Add(u"':'");
439 tokenNameList.Add(u"SEMICOLON");
440 tokenInfoList.Add(u"';'");
441 tokenNameList.Add(u"LBRACKET");
442 tokenInfoList.Add(u"'['");
443 tokenNameList.Add(u"RBRACKET");
444 tokenInfoList.Add(u"']'");
445 tokenNameList.Add(u"ASSIGN");
446 tokenInfoList.Add(u"'='");
447 tokenNameList.Add(u"AT");
448 tokenInfoList.Add(u"'@'");
449 tokenNameList.Add(u"DOLLAR");
450 tokenInfoList.Add(u"'$'");
451 tokenNameList.Add(u"EXCLAMATION");
452 tokenInfoList.Add(u"'!'");
453 tokenNameList.Add(u"TYPEID");
454 tokenInfoList.Add(u"type identifier");
455 tokenNameList.Add(u"CLSID");
456 tokenInfoList.Add(u"class identifier");
457 tokenNameList.Add(u"STRING");
458 tokenInfoList.Add(u"string");
459 tokenNameList.Add(u"NUMBER");
460 tokenInfoList.Add(u"number");
461 tokenNameList.Add(u"HEXNUM");
462 tokenInfoList.Add(u"hex number");
463 }
464 private static System.UniquePtr<TokenMap> instance;
465 private System.Collections.Map<ustring, int> tokenIdMap;
466 private System.Collections.List<ustring> tokenNameList;
467 private System.Collections.List<ustring> tokenInfoList;
468 }
469 public int GetTokenId(const ustring& tokenName)
470 {
471 return TokenMap.Instance().GetTokenId(tokenName);
472 }
473
474 public ustring GetTokenName(int tokenId)
475 {
476 return TokenMap.Instance().GetTokenName(tokenId);
477 }
478
479 public ustring GetTokenInfo(int tokenId)
480 {
481 return TokenMap.Instance().GetTokenInfo(tokenId);
482 }
483 }