blob: e7d50322ef4d4514817a64d13827f9309ea2954f [file] [log] [blame]
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00001//===-- FileParser.y - Parser for TableGen files ----------------*- C++ -*-===//
John Criswell9583cfa2003-10-21 15:29:18 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Chris Lattnerf5bd1b72003-10-05 19:27:59 +00009//
10// This file implements the bison parser for Table Generator files...
11//
Chris Lattner44d2c352003-10-13 03:32:08 +000012//===----------------------------------------------------------------------===//
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000013
14%{
15#include "Record.h"
Reid Spencer7c16caa2004-09-01 22:55:40 +000016#include "llvm/ADT/StringExtras.h"
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000017#include <algorithm>
18#include <cstdio>
19#define YYERROR_VERBOSE 1
20
21int yyerror(const char *ErrorMsg);
22int yylex();
Brian Gaeke960707c2003-11-11 22:41:34 +000023
24namespace llvm {
25
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000026extern int Filelineno;
27static Record *CurRec = 0;
28
29typedef std::pair<Record*, std::vector<Init*>*> SubClassRefTy;
30
31struct LetRecord {
32 std::string Name;
33 std::vector<unsigned> Bits;
34 Init *Value;
35 bool HasBits;
36 LetRecord(const std::string &N, std::vector<unsigned> *B, Init *V)
37 : Name(N), Value(V), HasBits(B != 0) {
38 if (HasBits) Bits = *B;
39 }
40};
41
42static std::vector<std::vector<LetRecord> > LetStack;
43
44
45extern std::ostream &err();
46
47static void addValue(const RecordVal &RV) {
48 if (RecordVal *ERV = CurRec->getValue(RV.getName())) {
49 // The value already exists in the class, treat this as a set...
50 if (ERV->setValue(RV.getValue())) {
51 err() << "New definition of '" << RV.getName() << "' of type '"
52 << *RV.getType() << "' is incompatible with previous "
53 << "definition of type '" << *ERV->getType() << "'!\n";
Chris Lattner564251e2004-02-13 16:37:43 +000054 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000055 }
56 } else {
57 CurRec->addValue(RV);
58 }
59}
60
61static void addSuperClass(Record *SC) {
62 if (CurRec->isSubClassOf(SC)) {
63 err() << "Already subclass of '" << SC->getName() << "'!\n";
Chris Lattner564251e2004-02-13 16:37:43 +000064 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000065 }
66 CurRec->addSuperClass(SC);
67}
68
69static void setValue(const std::string &ValName,
70 std::vector<unsigned> *BitList, Init *V) {
Chris Lattner994f2d12004-02-28 17:31:28 +000071 if (!V) return;
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000072
73 RecordVal *RV = CurRec->getValue(ValName);
74 if (RV == 0) {
75 err() << "Value '" << ValName << "' unknown!\n";
Chris Lattner564251e2004-02-13 16:37:43 +000076 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000077 }
Chris Lattner994f2d12004-02-28 17:31:28 +000078
79 // Do not allow assignments like 'X = X'. This will just cause infinite loops
80 // in the resolution machinery.
81 if (!BitList)
82 if (VarInit *VI = dynamic_cast<VarInit*>(V))
83 if (VI->getName() == ValName)
84 return;
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000085
86 // If we are assigning to a subset of the bits in the value... then we must be
87 // assigning to a field of BitsRecTy, which must have a BitsInit
88 // initializer...
89 //
90 if (BitList) {
91 BitsInit *CurVal = dynamic_cast<BitsInit*>(RV->getValue());
92 if (CurVal == 0) {
93 err() << "Value '" << ValName << "' is not a bits type!\n";
Chris Lattner564251e2004-02-13 16:37:43 +000094 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +000095 }
96
97 // Convert the incoming value to a bits type of the appropriate size...
98 Init *BI = V->convertInitializerTo(new BitsRecTy(BitList->size()));
99 if (BI == 0) {
100 V->convertInitializerTo(new BitsRecTy(BitList->size()));
101 err() << "Initializer '" << *V << "' not compatible with bit range!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000102 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000103 }
104
105 // We should have a BitsInit type now...
106 assert(dynamic_cast<BitsInit*>(BI) != 0 || &(std::cerr << *BI) == 0);
107 BitsInit *BInit = (BitsInit*)BI;
108
109 BitsInit *NewVal = new BitsInit(CurVal->getNumBits());
110
111 // Loop over bits, assigning values as appropriate...
112 for (unsigned i = 0, e = BitList->size(); i != e; ++i) {
113 unsigned Bit = (*BitList)[i];
114 if (NewVal->getBit(Bit)) {
115 err() << "Cannot set bit #" << Bit << " of value '" << ValName
116 << "' more than once!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000117 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000118 }
119 NewVal->setBit(Bit, BInit->getBit(i));
120 }
121
122 for (unsigned i = 0, e = CurVal->getNumBits(); i != e; ++i)
123 if (NewVal->getBit(i) == 0)
124 NewVal->setBit(i, CurVal->getBit(i));
125
126 V = NewVal;
127 }
128
129 if (RV->setValue(V)) {
130 err() << "Value '" << ValName << "' of type '" << *RV->getType()
131 << "' is incompatible with initializer '" << *V << "'!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000132 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000133 }
134}
135
136static void addSubClass(Record *SC, const std::vector<Init*> &TemplateArgs) {
137 // Add all of the values in the subclass into the current class...
138 const std::vector<RecordVal> &Vals = SC->getValues();
139 for (unsigned i = 0, e = Vals.size(); i != e; ++i)
140 addValue(Vals[i]);
141
142 const std::vector<std::string> &TArgs = SC->getTemplateArgs();
143
144 // Ensure that an appropriate number of template arguments are specified...
145 if (TArgs.size() < TemplateArgs.size()) {
146 err() << "ERROR: More template args specified than expected!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000147 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000148 } else { // This class expects template arguments...
149 // Loop over all of the template arguments, setting them to the specified
150 // value or leaving them as the default as necessary.
151 for (unsigned i = 0, e = TArgs.size(); i != e; ++i) {
152 if (i < TemplateArgs.size()) { // A value is specified for this temp-arg?
153 // Set it now.
154 setValue(TArgs[i], 0, TemplateArgs[i]);
155 } else if (!CurRec->getValue(TArgs[i])->getValue()->isComplete()) {
156 err() << "ERROR: Value not specified for template argument #"
157 << i << " (" << TArgs[i] << ") of subclass '" << SC->getName()
158 << "'!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000159 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000160 }
161 }
162 }
163
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000164 // Since everything went well, we can now set the "superclass" list for the
165 // current record.
Chris Lattner994f2d12004-02-28 17:31:28 +0000166 const std::vector<Record*> &SCs = SC->getSuperClasses();
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000167 for (unsigned i = 0, e = SCs.size(); i != e; ++i)
168 addSuperClass(SCs[i]);
169 addSuperClass(SC);
170}
171
Brian Gaeke960707c2003-11-11 22:41:34 +0000172} // End llvm namespace
173
174using namespace llvm;
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000175
176%}
177
178%union {
Brian Gaeke960707c2003-11-11 22:41:34 +0000179 std::string* StrVal;
180 int IntVal;
181 llvm::RecTy* Ty;
182 llvm::Init* Initializer;
183 std::vector<llvm::Init*>* FieldList;
184 std::vector<unsigned>* BitList;
185 llvm::Record* Rec;
186 SubClassRefTy* SubClassRef;
187 std::vector<SubClassRefTy>* SubClassList;
188 std::vector<std::pair<llvm::Init*, std::string> >* DagValueList;
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000189};
190
191%token INT BIT STRING BITS LIST CODE DAG CLASS DEF FIELD LET IN
Chris Lattner101fc502005-04-19 01:11:03 +0000192%token SHLTOK SRATOK SRLTOK
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000193%token <IntVal> INTVAL
194%token <StrVal> ID VARNAME STRVAL CODEFRAGMENT
195
196%type <Ty> Type
197%type <Rec> ClassInst DefInst Object ObjectBody ClassID
198
199%type <SubClassRef> SubClassRef
200%type <SubClassList> ClassList ClassListNE
201%type <IntVal> OptPrefix
202%type <Initializer> Value OptValue
203%type <DagValueList> DagArgList DagArgListNE
204%type <FieldList> ValueList ValueListNE
205%type <BitList> BitList OptBitList RBitList
206%type <StrVal> Declaration OptID OptVarName
207
208%start File
Brian Gaeke960707c2003-11-11 22:41:34 +0000209
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000210%%
211
212ClassID : ID {
213 $$ = Records.getClass(*$1);
214 if ($$ == 0) {
215 err() << "Couldn't find class '" << *$1 << "'!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000216 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000217 }
218 delete $1;
219 };
220
221
222// TableGen types...
223Type : STRING { // string type
224 $$ = new StringRecTy();
225 } | BIT { // bit type
226 $$ = new BitRecTy();
227 } | BITS '<' INTVAL '>' { // bits<x> type
228 $$ = new BitsRecTy($3);
229 } | INT { // int type
230 $$ = new IntRecTy();
231 } | LIST '<' Type '>' { // list<x> type
232 $$ = new ListRecTy($3);
233 } | CODE { // code type
234 $$ = new CodeRecTy();
235 } | DAG { // dag type
236 $$ = new DagRecTy();
237 } | ClassID { // Record Type
238 $$ = new RecordRecTy($1);
239 };
240
241OptPrefix : /*empty*/ { $$ = 0; } | FIELD { $$ = 1; };
242
243OptValue : /*empty*/ { $$ = 0; } | '=' Value { $$ = $2; };
244
245Value : INTVAL {
246 $$ = new IntInit($1);
247 } | STRVAL {
248 $$ = new StringInit(*$1);
249 delete $1;
250 } | CODEFRAGMENT {
251 $$ = new CodeInit(*$1);
252 delete $1;
253 } | '?' {
254 $$ = new UnsetInit();
255 } | '{' ValueList '}' {
256 BitsInit *Init = new BitsInit($2->size());
257 for (unsigned i = 0, e = $2->size(); i != e; ++i) {
258 struct Init *Bit = (*$2)[i]->convertInitializerTo(new BitRecTy());
259 if (Bit == 0) {
260 err() << "Element #" << i << " (" << *(*$2)[i]
261 << ") is not convertable to a bit!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000262 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000263 }
264 Init->setBit($2->size()-i-1, Bit);
265 }
266 $$ = Init;
267 delete $2;
268 } | ID {
269 if (const RecordVal *RV = (CurRec ? CurRec->getValue(*$1) : 0)) {
270 $$ = new VarInit(*$1, RV->getType());
271 } else if (Record *D = Records.getDef(*$1)) {
272 $$ = new DefInit(D);
273 } else {
274 err() << "Variable not defined: '" << *$1 << "'!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000275 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000276 }
277
278 delete $1;
279 } | Value '{' BitList '}' {
280 $$ = $1->convertInitializerBitRange(*$3);
281 if ($$ == 0) {
282 err() << "Invalid bit range for value '" << *$1 << "'!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000283 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000284 }
285 delete $3;
286 } | '[' ValueList ']' {
287 $$ = new ListInit(*$2);
288 delete $2;
289 } | Value '.' ID {
290 if (!$1->getFieldType(*$3)) {
291 err() << "Cannot access field '" << *$3 << "' of value '" << *$1 << "!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000292 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000293 }
294 $$ = new FieldInit($1, *$3);
295 delete $3;
296 } | '(' ID DagArgList ')' {
297 Record *D = Records.getDef(*$2);
298 if (D == 0) {
299 err() << "Invalid def '" << *$2 << "'!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000300 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000301 }
302 $$ = new DagInit(D, *$3);
303 delete $2; delete $3;
Chris Lattner8bf9e062004-07-26 23:21:34 +0000304 } | Value '[' BitList ']' {
305 std::reverse($3->begin(), $3->end());
306 $$ = $1->convertInitListSlice(*$3);
307 if ($$ == 0) {
308 err() << "Invalid list slice for value '" << *$1 << "'!\n";
309 exit(1);
310 }
311 delete $3;
Chris Lattner101fc502005-04-19 01:11:03 +0000312 } | SHLTOK '(' Value ',' Value ')' {
313 $$ = $3->getBinaryOp(Init::SHL, $5);
314 if ($$ == 0) {
315 err() << "Cannot shift values '" << *$3 << "' and '" << *$5 << "'!\n";
316 exit(1);
317 }
318 } | SRATOK '(' Value ',' Value ')' {
319 $$ = $3->getBinaryOp(Init::SRA, $5);
320 if ($$ == 0) {
321 err() << "Cannot shift values '" << *$3 << "' and '" << *$5 << "'!\n";
322 exit(1);
323 }
324 } | SRLTOK '(' Value ',' Value ')' {
325 $$ = $3->getBinaryOp(Init::SRL, $5);
326 if ($$ == 0) {
327 err() << "Cannot shift values '" << *$3 << "' and '" << *$5 << "'!\n";
328 exit(1);
329 }
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000330 };
331
332OptVarName : /* empty */ {
333 $$ = new std::string();
334 }
335 | ':' VARNAME {
336 $$ = $2;
337 };
338
339DagArgListNE : Value OptVarName {
340 $$ = new std::vector<std::pair<Init*, std::string> >();
341 $$->push_back(std::make_pair($1, *$2));
342 delete $2;
343 }
344 | DagArgListNE ',' Value OptVarName {
345 $1->push_back(std::make_pair($3, *$4));
346 delete $4;
347 $$ = $1;
348 };
349
350DagArgList : /*empty*/ {
351 $$ = new std::vector<std::pair<Init*, std::string> >();
352 }
353 | DagArgListNE { $$ = $1; };
354
355
356RBitList : INTVAL {
357 $$ = new std::vector<unsigned>();
358 $$->push_back($1);
359 } | INTVAL '-' INTVAL {
Chris Lattner8bf9e062004-07-26 23:21:34 +0000360 if ($1 < 0 || $3 < 0) {
361 err() << "Invalid range: " << $1 << "-" << $3 << "!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000362 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000363 }
364 $$ = new std::vector<unsigned>();
Chris Lattner8bf9e062004-07-26 23:21:34 +0000365 if ($1 < $3) {
366 for (int i = $1; i <= $3; ++i)
367 $$->push_back(i);
368 } else {
369 for (int i = $1; i >= $3; --i)
370 $$->push_back(i);
371 }
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000372 } | INTVAL INTVAL {
373 $2 = -$2;
Chris Lattner8bf9e062004-07-26 23:21:34 +0000374 if ($1 < 0 || $2 < 0) {
375 err() << "Invalid range: " << $1 << "-" << $2 << "!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000376 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000377 }
378 $$ = new std::vector<unsigned>();
Chris Lattner8bf9e062004-07-26 23:21:34 +0000379 if ($1 < $2) {
380 for (int i = $1; i <= $2; ++i)
381 $$->push_back(i);
382 } else {
383 for (int i = $1; i >= $2; --i)
384 $$->push_back(i);
385 }
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000386 } | RBitList ',' INTVAL {
387 ($$=$1)->push_back($3);
388 } | RBitList ',' INTVAL '-' INTVAL {
Chris Lattner8bf9e062004-07-26 23:21:34 +0000389 if ($3 < 0 || $5 < 0) {
390 err() << "Invalid range: " << $3 << "-" << $5 << "!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000391 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000392 }
393 $$ = $1;
Chris Lattner8bf9e062004-07-26 23:21:34 +0000394 if ($3 < $5) {
395 for (int i = $3; i <= $5; ++i)
396 $$->push_back(i);
397 } else {
398 for (int i = $3; i >= $5; --i)
399 $$->push_back(i);
400 }
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000401 } | RBitList ',' INTVAL INTVAL {
402 $4 = -$4;
Chris Lattner8bf9e062004-07-26 23:21:34 +0000403 if ($3 < 0 || $4 < 0) {
404 err() << "Invalid range: " << $3 << "-" << $4 << "!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000405 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000406 }
407 $$ = $1;
Chris Lattner8bf9e062004-07-26 23:21:34 +0000408 if ($3 < $4) {
409 for (int i = $3; i <= $4; ++i)
410 $$->push_back(i);
411 } else {
412 for (int i = $3; i >= $4; --i)
413 $$->push_back(i);
414 }
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000415 };
416
417BitList : RBitList { $$ = $1; std::reverse($1->begin(), $1->end()); };
418
419OptBitList : /*empty*/ { $$ = 0; } | '{' BitList '}' { $$ = $2; };
420
421
422
423ValueList : /*empty*/ {
424 $$ = new std::vector<Init*>();
425 } | ValueListNE {
426 $$ = $1;
427 };
428
429ValueListNE : Value {
430 $$ = new std::vector<Init*>();
431 $$->push_back($1);
432 } | ValueListNE ',' Value {
433 ($$ = $1)->push_back($3);
434 };
435
436Declaration : OptPrefix Type ID OptValue {
437 addValue(RecordVal(*$3, $2, $1));
438 setValue(*$3, 0, $4);
439 $$ = $3;
440};
441
442BodyItem : Declaration ';' {
443 delete $1;
444} | LET ID OptBitList '=' Value ';' {
445 setValue(*$2, $3, $5);
446 delete $2;
447 delete $3;
448};
449
450BodyList : /*empty*/ | BodyList BodyItem;
451Body : ';' | '{' BodyList '}';
452
453SubClassRef : ClassID {
454 $$ = new SubClassRefTy($1, new std::vector<Init*>());
455 } | ClassID '<' ValueListNE '>' {
456 $$ = new SubClassRefTy($1, $3);
457 };
458
459ClassListNE : SubClassRef {
460 $$ = new std::vector<SubClassRefTy>();
461 $$->push_back(*$1);
462 delete $1;
463 }
464 | ClassListNE ',' SubClassRef {
465 ($$=$1)->push_back(*$3);
466 delete $3;
467 };
468
469ClassList : /*empty */ {
470 $$ = new std::vector<SubClassRefTy>();
471 }
472 | ':' ClassListNE {
473 $$ = $2;
474 };
475
476DeclListNE : Declaration {
477 CurRec->addTemplateArg(*$1);
478 delete $1;
479} | DeclListNE ',' Declaration {
480 CurRec->addTemplateArg(*$3);
481 delete $3;
482};
483
484TemplateArgList : '<' DeclListNE '>' {};
485OptTemplateArgList : /*empty*/ | TemplateArgList;
486
487OptID : ID { $$ = $1; } | /*empty*/ { $$ = new std::string(); };
488
489ObjectBody : OptID {
490 static unsigned AnonCounter = 0;
491 if ($1->empty())
492 *$1 = "anonymous."+utostr(AnonCounter++);
493 CurRec = new Record(*$1);
494 delete $1;
495 } OptTemplateArgList ClassList {
496 for (unsigned i = 0, e = $4->size(); i != e; ++i) {
497 addSubClass((*$4)[i].first, *(*$4)[i].second);
498 // Delete the template arg values for the class
499 delete (*$4)[i].second;
500 }
501
502 // Process any variables on the set stack...
503 for (unsigned i = 0, e = LetStack.size(); i != e; ++i)
504 for (unsigned j = 0, e = LetStack[i].size(); j != e; ++j)
505 setValue(LetStack[i][j].Name,
506 LetStack[i][j].HasBits ? &LetStack[i][j].Bits : 0,
507 LetStack[i][j].Value);
508 } Body {
509 CurRec->resolveReferences();
510
511 // Now that all of the references have been resolved, we can delete template
512 // arguments for superclasses, so they don't pollute our record, and so that
513 // their names won't conflict with later uses of the name...
514 for (unsigned i = 0, e = $4->size(); i != e; ++i) {
515 Record *SuperClass = (*$4)[i].first;
516 for (unsigned i = 0, e = SuperClass->getTemplateArgs().size(); i != e; ++i)
Chris Lattner36326de2004-02-28 17:41:48 +0000517 if (!CurRec->isTemplateArg(SuperClass->getTemplateArgs()[i]))
518 CurRec->removeValue(SuperClass->getTemplateArgs()[i]);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000519 }
520 delete $4; // Delete the class list...
521
522 $$ = CurRec;
523 CurRec = 0;
524};
525
526ClassInst : CLASS ObjectBody {
527 if (Records.getClass($2->getName())) {
528 err() << "Class '" << $2->getName() << "' already defined!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000529 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000530 }
531 Records.addClass($$ = $2);
532};
533
534DefInst : DEF ObjectBody {
535 if (!$2->getTemplateArgs().empty()) {
536 err() << "Def '" << $2->getName()
537 << "' is not permitted to have template arguments!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000538 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000539 }
540 // If ObjectBody has template arguments, it's an error.
541 if (Records.getDef($2->getName())) {
542 err() << "Def '" << $2->getName() << "' already defined!\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000543 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000544 }
545 Records.addDef($$ = $2);
546};
547
548
549Object : ClassInst | DefInst;
550
551LETItem : ID OptBitList '=' Value {
552 LetStack.back().push_back(LetRecord(*$1, $2, $4));
553 delete $1; delete $2;
554};
555
556LETList : LETItem | LETList ',' LETItem;
557
558// LETCommand - A 'LET' statement start...
559LETCommand : LET { LetStack.push_back(std::vector<LetRecord>()); } LETList IN;
560
561// Support Set commands wrapping objects... both with and without braces.
562Object : LETCommand '{' ObjectList '}' {
563 LetStack.pop_back();
564 }
565 | LETCommand Object {
566 LetStack.pop_back();
567 };
568
569ObjectList : Object {} | ObjectList Object {};
570
571File : ObjectList {};
572
573%%
574
575int yyerror(const char *ErrorMsg) {
576 err() << "Error parsing: " << ErrorMsg << "\n";
Chris Lattner564251e2004-02-13 16:37:43 +0000577 exit(1);
Chris Lattnerf5bd1b72003-10-05 19:27:59 +0000578}