Regenerate.
[oota-llvm.git] / tools / llvm-upgrade / UpgradeParser.y.cvs
1 //===-- UpgradeParser.y - Upgrade parser for llvm assmbly -------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by Reid Spencer and is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 //  This file implements the bison parser for LLVM 1.9 assembly language.
11 //
12 //===----------------------------------------------------------------------===//
13
14 %{
15 #include "ParserInternals.h"
16 #include <llvm/ADT/StringExtras.h>
17 #include <algorithm>
18 #include <map>
19 #include <utility>
20 #include <iostream>
21
22 #define YYERROR_VERBOSE 1
23 #define YYINCLUDED_STDLIB_H
24 #define YYDEBUG 1
25
26 int yylex();                       // declaration" of xxx warnings.
27 int yyparse();
28 extern int yydebug;
29
30 static std::string CurFilename;
31 static std::ostream *O = 0;
32 std::istream* LexInput = 0;
33 unsigned SizeOfPointer = 32;
34 static uint64_t unique = 1;
35
36 typedef std::vector<TypeInfo> TypeVector;
37 static TypeVector EnumeratedTypes;
38 typedef std::map<std::string,TypeInfo> TypeMap;
39 static TypeMap NamedTypes;
40
41 void destroy(ValueList* VL) {
42   while (!VL->empty()) {
43     ValueInfo& VI = VL->back();
44     VI.destroy();
45     VL->pop_back();
46   }
47   delete VL;
48 }
49
50 void UpgradeAssembly(const std::string &infile, std::istream& in, 
51                      std::ostream &out, bool debug)
52 {
53   Upgradelineno = 1; 
54   CurFilename = infile;
55   LexInput = &in;
56   yydebug = debug;
57   O = &out;
58
59   if (yyparse()) {
60     std::cerr << "Parse failed.\n";
61     exit(1);
62   }
63 }
64
65 static void ResolveType(TypeInfo& Ty) {
66   if (Ty.oldTy == UnresolvedTy) {
67     TypeMap::iterator I = NamedTypes.find(*Ty.newTy);
68     if (I != NamedTypes.end())
69       Ty.oldTy = I->second.oldTy;
70     else {
71       std::string msg("Can't resolve type: ");
72       msg += *Ty.newTy;
73       yyerror(msg.c_str());
74     }
75   } else if (Ty.oldTy == NumericTy) {
76     unsigned ref = atoi(&((Ty.newTy->c_str())[1])); // Skip the '\\'
77     if (ref < EnumeratedTypes.size()) {
78       Ty.oldTy = EnumeratedTypes[ref].oldTy;
79     } else {
80       std::string msg("Can't resolve type: ");
81       msg += *Ty.newTy;
82       yyerror(msg.c_str());
83     }
84   }
85   // otherwise its already resolved.
86 }
87
88 static const char* getCastOpcode(
89   std::string& Source, const TypeInfo& SrcTy, const TypeInfo& DstTy) 
90 {
91   unsigned SrcBits = SrcTy.getBitWidth();
92   unsigned DstBits = DstTy.getBitWidth();
93   const char* opcode = "bitcast";
94   // Run through the possibilities ...
95   if (DstTy.isIntegral()) {                        // Casting to integral
96     if (SrcTy.isIntegral()) {                      // Casting from integral
97       if (DstBits < SrcBits)
98         opcode = "trunc";
99       else if (DstBits > SrcBits) {                // its an extension
100         if (SrcTy.isSigned())
101           opcode ="sext";                          // signed -> SEXT
102         else
103           opcode = "zext";                         // unsigned -> ZEXT
104       } else {
105         opcode = "bitcast";                        // Same size, No-op cast
106       }
107     } else if (SrcTy.isFloatingPoint()) {          // Casting from floating pt
108       if (DstTy.isSigned()) 
109         opcode = "fptosi";                         // FP -> sint
110       else
111         opcode = "fptoui";                         // FP -> uint 
112     } else if (SrcTy.isPacked()) {
113       assert(DstBits == SrcTy.getBitWidth() &&
114                "Casting packed to integer of different width");
115         opcode = "bitcast";                        // same size, no-op cast
116     } else {
117       assert(SrcTy.isPointer() &&
118              "Casting from a value that is not first-class type");
119       opcode = "ptrtoint";                         // ptr -> int
120     }
121   } else if (DstTy.isFloatingPoint()) {           // Casting to floating pt
122     if (SrcTy.isIntegral()) {                     // Casting from integral
123       if (SrcTy.isSigned())
124         opcode = "sitofp";                         // sint -> FP
125       else
126         opcode = "uitofp";                         // uint -> FP
127     } else if (SrcTy.isFloatingPoint()) {         // Casting from floating pt
128       if (DstBits < SrcBits) {
129         opcode = "fptrunc";                        // FP -> smaller FP
130       } else if (DstBits > SrcBits) {
131         opcode = "fpext";                          // FP -> larger FP
132       } else  {
133         opcode ="bitcast";                         // same size, no-op cast
134       }
135     } else if (SrcTy.isPacked()) {
136       assert(DstBits == SrcTy.getBitWidth() &&
137              "Casting packed to floating point of different width");
138         opcode = "bitcast";                        // same size, no-op cast
139     } else {
140       assert(0 && "Casting pointer or non-first class to float");
141     }
142   } else if (DstTy.isPacked()) {
143     if (SrcTy.isPacked()) {
144       assert(DstTy.getBitWidth() == SrcTy.getBitWidth() &&
145              "Casting packed to packed of different widths");
146       opcode = "bitcast";                          // packed -> packed
147     } else if (DstTy.getBitWidth() == SrcBits) {
148       opcode = "bitcast";                          // float/int -> packed
149     } else {
150       assert(!"Illegal cast to packed (wrong type or size)");
151     }
152   } else if (DstTy.isPointer()) {
153     if (SrcTy.isPointer()) {
154       opcode = "bitcast";                          // ptr -> ptr
155     } else if (SrcTy.isIntegral()) {
156       opcode = "inttoptr";                         // int -> ptr
157     } else {
158       assert(!"Casting invalid type to pointer");
159     }
160   } else {
161     assert(!"Casting to type that is not first-class");
162   }
163   return opcode;
164 }
165
166 static std::string getCastUpgrade(
167   const std::string& Src, TypeInfo& SrcTy, TypeInfo& DstTy, bool isConst)
168 {
169   std::string Result;
170   std::string Source = Src;
171   if (SrcTy.isFloatingPoint() && DstTy.isPointer()) {
172     // fp -> ptr cast is no longer supported but we must upgrade this
173     // by doing a double cast: fp -> int -> ptr
174     if (isConst)
175       Source = "ulong fptoui(" + Source + " to ulong)";
176     else {
177       *O << "    %cast_upgrade" << unique << " = fptoui " << Source 
178          << " to ulong\n";
179       Source = "ulong %cast_upgrade" + llvm::utostr(unique);
180     }
181     // Update the SrcTy for the getCastOpcode call below
182     SrcTy.destroy();
183     SrcTy.newTy = new std::string("ulong");
184     SrcTy.oldTy = ULongTy;
185   } else if (DstTy.oldTy == BoolTy) {
186     // cast ptr %x to  bool was previously defined as setne ptr %x, null
187     // The ptrtoint semantic is to truncate, not compare so we must retain
188     // the original intent by replace the cast with a setne
189     const char* comparator = SrcTy.isPointer() ? ", null" : 
190       (SrcTy.isFloatingPoint() ? ", 0.0" : ", 0");
191     if (isConst) 
192       Result = "setne (" + Source + comparator + ")";
193     else
194       Result = "setne " + Source + comparator;
195     return Result; // skip cast processing below
196   }
197   ResolveType(SrcTy);
198   ResolveType(DstTy);
199   std::string Opcode(getCastOpcode(Source, SrcTy, DstTy));
200   if (isConst)
201     Result += Opcode + "( " + Source + " to " + *DstTy.newTy + ")";
202   else
203     Result += Opcode + " " + Source + " to " + *DstTy.newTy;
204   return Result;
205 }
206
207 %}
208
209 %file-prefix="UpgradeParser"
210
211 %union {
212   std::string*    String;
213   TypeInfo        Type;
214   ValueInfo       Value;
215   ConstInfo       Const;
216   ValueList*      ValList;
217 }
218
219 %token <Type>   VOID BOOL SBYTE UBYTE SHORT USHORT INT UINT LONG ULONG
220 %token <Type>   FLOAT DOUBLE LABEL 
221 %token <String> OPAQUE ESINT64VAL EUINT64VAL SINTVAL UINTVAL FPVAL
222 %token <String> NULL_TOK UNDEF ZEROINITIALIZER TRUETOK FALSETOK
223 %token <String> TYPE VAR_ID LABELSTR STRINGCONSTANT
224 %token <String> IMPLEMENTATION BEGINTOK ENDTOK
225 %token <String> DECLARE GLOBAL CONSTANT SECTION VOLATILE
226 %token <String> TO DOTDOTDOT CONST INTERNAL LINKONCE WEAK 
227 %token <String> DLLIMPORT DLLEXPORT EXTERN_WEAK APPENDING
228 %token <String> NOT EXTERNAL TARGET TRIPLE ENDIAN POINTERSIZE LITTLE BIG
229 %token <String> ALIGN
230 %token <String> DEPLIBS CALL TAIL ASM_TOK MODULE SIDEEFFECT
231 %token <String> CC_TOK CCC_TOK CSRETCC_TOK FASTCC_TOK COLDCC_TOK
232 %token <String> X86_STDCALLCC_TOK X86_FASTCALLCC_TOK
233 %token <String> DATALAYOUT
234 %token <String> RET BR SWITCH INVOKE UNWIND UNREACHABLE
235 %token <String> ADD SUB MUL UDIV SDIV FDIV UREM SREM FREM AND OR XOR
236 %token <String> SETLE SETGE SETLT SETGT SETEQ SETNE  // Binary Comparators
237 %token <String> MALLOC ALLOCA FREE LOAD STORE GETELEMENTPTR
238 %token <String> PHI_TOK SELECT SHL SHR ASHR LSHR VAARG
239 %token <String> EXTRACTELEMENT INSERTELEMENT SHUFFLEVECTOR
240 %token <String> CAST TRUNC ZEXT SEXT FPTRUNC FPEXT FPTOUI FPTOSI UITOFP SITOFP 
241 %token <String> PTRTOINT INTTOPTR BITCAST
242
243 %type <String> OptAssign OptLinkage OptCallingConv OptAlign OptCAlign 
244 %type <String> SectionString OptSection GlobalVarAttributes GlobalVarAttribute
245 %type <String> ArgTypeListI ConstExpr DefinitionList
246 %type <String> ConstPool TargetDefinition LibrariesDefinition LibList OptName
247 %type <String> ArgVal ArgListH ArgList FunctionHeaderH BEGIN FunctionHeader END
248 %type <String> Function FunctionProto BasicBlock TypeListI
249 %type <String> InstructionList BBTerminatorInst JumpTable Inst PHIList
250 %type <String> OptTailCall InstVal OptVolatile
251 %type <String> MemoryInst SymbolicValueRef OptSideEffect GlobalType
252 %type <String> FnDeclareLinkage BasicBlockList BigOrLittle AsmBlock
253 %type <String> Name ConstValueRef ConstVector
254 %type <String> ShiftOps SetCondOps LogicalOps ArithmeticOps CastOps 
255
256 %type <ValList> ValueRefList ValueRefListE IndexList
257
258 %type <Type> IntType SIntType UIntType FPType TypesV Types 
259 %type <Type> PrimType UpRTypesV UpRTypes
260
261 %type <String> IntVal EInt64Val 
262 %type <Const>  ConstVal
263
264 %type <Value> ValueRef ResolvedVal 
265
266 %start Module
267
268 %%
269
270 // Handle constant integer size restriction and conversion...
271 IntVal : SINTVAL | UINTVAL ;
272 EInt64Val : ESINT64VAL | EUINT64VAL;
273
274 // Operations that are notably excluded from this list include:
275 // RET, BR, & SWITCH because they end basic blocks and are treated specially.
276 ArithmeticOps: ADD | SUB | MUL | UDIV | SDIV | FDIV | UREM | SREM | FREM;
277 LogicalOps   : AND | OR | XOR;
278 SetCondOps   : SETLE | SETGE | SETLT | SETGT | SETEQ | SETNE;
279 ShiftOps     : SHL | SHR | ASHR | LSHR;
280 CastOps      : TRUNC | ZEXT | SEXT | FPTRUNC | FPEXT | FPTOUI | FPTOSI | 
281                UITOFP | SITOFP | PTRTOINT | INTTOPTR | BITCAST | CAST
282              ;
283
284 // These are some types that allow classification if we only want a particular 
285 // thing... for example, only a signed, unsigned, or integral type.
286 SIntType :  LONG |  INT |  SHORT | SBYTE;
287 UIntType : ULONG | UINT | USHORT | UBYTE;
288 IntType  : SIntType | UIntType;
289 FPType   : FLOAT | DOUBLE;
290
291 // OptAssign - Value producing statements have an optional assignment component
292 OptAssign : Name '=' {
293     $$ = $1;
294   }
295   | /*empty*/ {
296     $$ = new std::string(""); 
297   };
298
299 OptLinkage 
300   : INTERNAL | LINKONCE | WEAK | APPENDING | DLLIMPORT | DLLEXPORT 
301   | EXTERN_WEAK 
302   | /*empty*/   { $$ = new std::string(""); } ;
303
304 OptCallingConv 
305   : CCC_TOK | CSRETCC_TOK | FASTCC_TOK | COLDCC_TOK | X86_STDCALLCC_TOK 
306   | X86_FASTCALLCC_TOK 
307   | CC_TOK EUINT64VAL { 
308     *$1 += *$2; 
309     delete $2;
310     $$ = $1; 
311     }
312   | /*empty*/ { $$ = new std::string(""); } ;
313
314 // OptAlign/OptCAlign - An optional alignment, and an optional alignment with
315 // a comma before it.
316 OptAlign 
317   : /*empty*/        { $$ = new std::string(); }
318   | ALIGN EUINT64VAL { *$1 += " " + *$2; delete $2; $$ = $1; };
319          ;
320 OptCAlign 
321   : /*empty*/            { $$ = new std::string(); } 
322   | ',' ALIGN EUINT64VAL { 
323     $2->insert(0, ", "); 
324     *$2 += " " + *$3;
325     delete $3;
326     $$ = $2;
327   };
328
329 SectionString 
330   : SECTION STRINGCONSTANT { 
331     *$1 += " " + *$2;
332     delete $2;
333     $$ = $1;
334   };
335
336 OptSection : /*empty*/     { $$ = new std::string(); } 
337            | SectionString;
338
339 GlobalVarAttributes 
340     : /* empty */ { $$ = new std::string(); } 
341     | ',' GlobalVarAttribute GlobalVarAttributes  {
342       $2->insert(0, ", ");
343       if (!$3->empty())
344         *$2 += " " + *$3;
345       delete $3;
346       $$ = $2;
347     };
348
349 GlobalVarAttribute 
350     : SectionString 
351     | ALIGN EUINT64VAL {
352       *$1 += " " + *$2;
353       delete $2;
354       $$ = $1;
355     };
356
357 //===----------------------------------------------------------------------===//
358 // Types includes all predefined types... except void, because it can only be
359 // used in specific contexts (function returning void for example).  To have
360 // access to it, a user must explicitly use TypesV.
361 //
362
363 // TypesV includes all of 'Types', but it also includes the void type.
364 TypesV    : Types    | VOID ;
365 UpRTypesV : UpRTypes | VOID ; 
366 Types     : UpRTypes ;
367
368 // Derived types are added later...
369 //
370 PrimType : BOOL | SBYTE | UBYTE | SHORT  | USHORT | INT   | UINT ;
371 PrimType : LONG | ULONG | FLOAT | DOUBLE | LABEL;
372 UpRTypes 
373   : OPAQUE { 
374     $$.newTy = $1; 
375     $$.oldTy = OpaqueTy; 
376   } 
377   | SymbolicValueRef { 
378     $$.newTy = $1;
379     $$.oldTy = UnresolvedTy;
380   }
381   | PrimType 
382   ;
383
384 // Include derived types in the Types production.
385 //
386 UpRTypes : '\\' EUINT64VAL {                   // Type UpReference
387     $2->insert(0, "\\");
388     $$.newTy = $2;
389     $$.oldTy = NumericTy;
390   }
391   | UpRTypesV '(' ArgTypeListI ')' {           // Function derived type?
392     *$1.newTy += "( " + *$3 + " )";
393     delete $3;
394     $$.newTy = $1.newTy;
395     $$.oldTy = FunctionTy;
396   }
397   | '[' EUINT64VAL 'x' UpRTypes ']' {          // Sized array type?
398     $2->insert(0,"[ ");
399     *$2 += " x " + *$4.newTy + " ]";
400     delete $4.newTy;
401     $$.newTy = $2;
402     $$.oldTy = ArrayTy;
403   }
404   | '<' EUINT64VAL 'x' UpRTypes '>' {          // Packed array type?
405     $2->insert(0,"< ");
406     *$2 += " x " + *$4.newTy + " >";
407     delete $4.newTy;
408     $$.newTy = $2;
409     $$.oldTy = PackedTy;
410   }
411   | '{' TypeListI '}' {                        // Structure type?
412     $2->insert(0, "{ ");
413     *$2 += " }";
414     $$.newTy = $2;
415     $$.oldTy = StructTy;
416   }
417   | '{' '}' {                                  // Empty structure type?
418     $$.newTy = new std::string("{}");
419     $$.oldTy = StructTy;
420   }
421   | UpRTypes '*' {                             // Pointer type?
422     *$1.newTy += '*';
423     $1.oldTy = PointerTy;
424     $$ = $1;
425   };
426
427 // TypeList - Used for struct declarations and as a basis for function type 
428 // declaration type lists
429 //
430 TypeListI 
431   : UpRTypes {
432     $$ = $1.newTy;
433   }
434   | TypeListI ',' UpRTypes {
435     *$1 += ", " + *$3.newTy;
436     delete $3.newTy;
437     $$ = $1;
438   };
439
440 // ArgTypeList - List of types for a function type declaration...
441 ArgTypeListI 
442   : TypeListI 
443   | TypeListI ',' DOTDOTDOT {
444     *$1 += ", ...";
445     delete $3;
446     $$ = $1;
447   }
448   | DOTDOTDOT {
449     $$ = $1;
450   }
451   | /*empty*/ {
452     $$ = new std::string();
453   };
454
455 // ConstVal - The various declarations that go into the constant pool.  This
456 // production is used ONLY to represent constants that show up AFTER a 'const',
457 // 'constant' or 'global' token at global scope.  Constants that can be inlined
458 // into other expressions (such as integers and constexprs) are handled by the
459 // ResolvedVal, ValueRef and ConstValueRef productions.
460 //
461 ConstVal: Types '[' ConstVector ']' { // Nonempty unsized arr
462     $$.type = $1;
463     $$.cnst = new std::string(*$1.newTy);
464     *$$.cnst += " [ " + *$3 + " ]";
465     delete $3;
466   }
467   | Types '[' ']' {
468     $$.type = $1;
469     $$.cnst = new std::string(*$1.newTy);
470     *$$.cnst += "[ ]";
471   }
472   | Types 'c' STRINGCONSTANT {
473     $$.type = $1;
474     $$.cnst = new std::string(*$1.newTy);
475     *$$.cnst += " c" + *$3;
476     delete $3;
477   }
478   | Types '<' ConstVector '>' { // Nonempty unsized arr
479     $$.type = $1;
480     $$.cnst = new std::string(*$1.newTy);
481     *$$.cnst += " < " + *$3 + " >";
482     delete $3;
483   }
484   | Types '{' ConstVector '}' {
485     $$.type = $1;
486     $$.cnst = new std::string(*$1.newTy);
487     *$$.cnst += " { " + *$3 + " }";
488     delete $3;
489   }
490   | Types '{' '}' {
491     $$.type = $1;
492     $$.cnst = new std::string(*$1.newTy);
493     *$$.cnst += " {}";
494   }
495   | Types NULL_TOK {
496     $$.type = $1;
497     $$.cnst = new std::string(*$1.newTy);
498     *$$.cnst +=  " " + *$2;
499     delete $2;
500   }
501   | Types UNDEF {
502     $$.type = $1;
503     $$.cnst = new std::string(*$1.newTy);
504     *$$.cnst += " " + *$2;
505     delete $2;
506   }
507   | Types SymbolicValueRef {
508     $$.type = $1;
509     $$.cnst = new std::string(*$1.newTy);
510     *$$.cnst += " " + *$2;
511     delete $2;
512   }
513   | Types ConstExpr {
514     $$.type = $1;
515     $$.cnst = new std::string(*$1.newTy);
516     *$$.cnst += " " + *$2;
517     delete $2;
518   }
519   | Types ZEROINITIALIZER {
520     $$.type = $1;
521     $$.cnst = new std::string(*$1.newTy);
522     *$$.cnst += " " + *$2;
523     delete $2;
524   }
525   | SIntType EInt64Val {      // integral constants
526     $$.type = $1;
527     $$.cnst = new std::string(*$1.newTy);
528     *$$.cnst += " " + *$2;
529     delete $2;
530   }
531   | UIntType EUINT64VAL {            // integral constants
532     $$.type = $1;
533     $$.cnst = new std::string(*$1.newTy);
534     *$$.cnst += " " + *$2;
535     delete $2;
536   }
537   | BOOL TRUETOK {                      // Boolean constants
538     $$.type = $1;
539     $$.cnst = new std::string(*$1.newTy);
540     *$$.cnst += " " + *$2;
541     delete $2;
542   }
543   | BOOL FALSETOK {                     // Boolean constants
544     $$.type = $1;
545     $$.cnst = new std::string(*$1.newTy);
546     *$$.cnst += " " + *$2;
547     delete $2;
548   }
549   | FPType FPVAL {                   // Float & Double constants
550     $$.type = $1;
551     $$.cnst = new std::string(*$1.newTy);
552     *$$.cnst += " " + *$2;
553     delete $2;
554   };
555
556
557 ConstExpr: CastOps '(' ConstVal TO Types ')' {
558     std::string source = *$3.cnst;
559     TypeInfo DstTy = $5;
560     ResolveType(DstTy);
561     if (*$1 == "cast") {
562       // Call getCastUpgrade to upgrade the old cast
563       $$ = new std::string(getCastUpgrade(source, $3.type, $5, true));
564     } else {
565       // Nothing to upgrade, just create the cast constant expr
566       $$ = new std::string(*$1);
567       *$$ += "( " + source + " to " + *$5.newTy + ")";
568     }
569     delete $1; $3.destroy(); delete $4; $5.destroy();
570   }
571   | GETELEMENTPTR '(' ConstVal IndexList ')' {
572     *$1 += "(" + *$3.cnst;
573     for (unsigned i = 0; i < $4->size(); ++i) {
574       ValueInfo& VI = (*$4)[i];
575       *$1 += ", " + *VI.val;
576       VI.destroy();
577     }
578     *$1 += ")";
579     $$ = $1;
580     $3.destroy();
581     delete $4;
582   }
583   | SELECT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
584     *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
585     $3.destroy(); $5.destroy(); $7.destroy();
586     $$ = $1;
587   }
588   | ArithmeticOps '(' ConstVal ',' ConstVal ')' {
589     *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
590     $3.destroy(); $5.destroy();
591     $$ = $1;
592   }
593   | LogicalOps '(' ConstVal ',' ConstVal ')' {
594     *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
595     $3.destroy(); $5.destroy();
596     $$ = $1;
597   }
598   | SetCondOps '(' ConstVal ',' ConstVal ')' {
599     *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
600     $3.destroy(); $5.destroy();
601     $$ = $1;
602   }
603   | ShiftOps '(' ConstVal ',' ConstVal ')' {
604     const char* shiftop = $1->c_str();
605     if (*$1 == "shr")
606       shiftop = ($3.type.isUnsigned()) ? "lshr" : "ashr";
607     $$ = new std::string(shiftop);
608     *$$ += "(" + *$3.cnst + "," + *$5.cnst + ")";
609     delete $1; $3.destroy(); $5.destroy();
610   }
611   | EXTRACTELEMENT '(' ConstVal ',' ConstVal ')' {
612     *$1 += "(" + *$3.cnst + "," + *$5.cnst + ")";
613     $3.destroy(); $5.destroy();
614     $$ = $1;
615   }
616   | INSERTELEMENT '(' ConstVal ',' ConstVal ',' ConstVal ')' {
617     *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
618     $3.destroy(); $5.destroy(); $7.destroy();
619     $$ = $1;
620   }
621   | SHUFFLEVECTOR '(' ConstVal ',' ConstVal ',' ConstVal ')' {
622     *$1 += "(" + *$3.cnst + "," + *$5.cnst + "," + *$7.cnst + ")";
623     $3.destroy(); $5.destroy(); $7.destroy();
624     $$ = $1;
625   };
626
627
628 // ConstVector - A list of comma separated constants.
629
630 ConstVector 
631   : ConstVector ',' ConstVal {
632     *$1 += ", " + *$3.cnst;
633     $3.destroy();
634     $$ = $1;
635   }
636   | ConstVal { $$ = new std::string(*$1.cnst); $1.destroy(); }
637   ;
638
639
640 // GlobalType - Match either GLOBAL or CONSTANT for global declarations...
641 GlobalType : GLOBAL | CONSTANT ;
642
643
644 //===----------------------------------------------------------------------===//
645 //                             Rules to match Modules
646 //===----------------------------------------------------------------------===//
647
648 // Module rule: Capture the result of parsing the whole file into a result
649 // variable...
650 //
651 Module : DefinitionList {
652 };
653
654 // DefinitionList - Top level definitions
655 //
656 DefinitionList : DefinitionList Function {
657     $$ = 0;
658   } 
659   | DefinitionList FunctionProto {
660     *O << *$2 << "\n";
661     delete $2;
662     $$ = 0;
663   }
664   | DefinitionList MODULE ASM_TOK AsmBlock {
665     *O << "module asm " << " " << *$4 << "\n";
666     $$ = 0;
667   }  
668   | DefinitionList IMPLEMENTATION {
669     *O << "implementation\n";
670     $$ = 0;
671   }
672   | ConstPool { $$ = 0; }
673
674 // ConstPool - Constants with optional names assigned to them.
675 ConstPool : ConstPool OptAssign TYPE TypesV {
676     EnumeratedTypes.push_back($4);
677     if (!$2->empty()) {
678       NamedTypes[*$2].newTy = new std::string(*$4.newTy);
679       NamedTypes[*$2].oldTy = $4.oldTy;
680       *O << *$2 << " = ";
681     }
682     *O << "type " << *$4.newTy << "\n";
683     delete $2; delete $3; $4.destroy();
684     $$ = 0;
685   }
686   | ConstPool FunctionProto {       // Function prototypes can be in const pool
687     *O << *$2 << "\n";
688     delete $2;
689     $$ = 0;
690   }
691   | ConstPool MODULE ASM_TOK AsmBlock {  // Asm blocks can be in the const pool
692     *O << *$2 << " " << *$3 << " " << *$4 << "\n";
693     delete $2; delete $3; delete $4; 
694     $$ = 0;
695   }
696   | ConstPool OptAssign OptLinkage GlobalType ConstVal  GlobalVarAttributes {
697     if (!$2->empty())
698       *O << *$2 << " = ";
699     *O << *$3 << " " << *$4 << " " << *$5.cnst << " " << *$6 << "\n";
700     delete $2; delete $3; delete $4; $5.destroy(); delete $6; 
701     $$ = 0;
702   }
703   | ConstPool OptAssign EXTERNAL GlobalType Types  GlobalVarAttributes {
704     if (!$2->empty())
705       *O << *$2 << " = ";
706     *O <<  *$3 << " " << *$4 << " " << *$5.newTy << " " << *$6 << "\n";
707     delete $2; delete $3; delete $4; $5.destroy(); delete $6;
708     $$ = 0;
709   }
710   | ConstPool OptAssign DLLIMPORT GlobalType Types  GlobalVarAttributes {
711     if (!$2->empty())
712       *O << *$2 << " = ";
713     *O << *$3 << " " << *$4 << " " << *$5.newTy << " " << *$6 << "\n";
714     delete $2; delete $3; delete $4; $5.destroy(); delete $6;
715     $$ = 0;
716   }
717   | ConstPool OptAssign EXTERN_WEAK GlobalType Types  GlobalVarAttributes {
718     if (!$2->empty())
719       *O << *$2 << " = ";
720     *O << *$3 << " " << *$4 << " " << *$5.newTy << " " << *$6 << "\n";
721     delete $2; delete $3; delete $4; $5.destroy(); delete $6;
722     $$ = 0;
723   }
724   | ConstPool TARGET TargetDefinition { 
725     *O << *$2 << " " << *$3 << "\n";
726     delete $2; delete $3;
727     $$ = 0;
728   }
729   | ConstPool DEPLIBS '=' LibrariesDefinition {
730     *O << *$2 << " = " << *$4 << "\n";
731     delete $2; delete $4;
732     $$ = 0;
733   }
734   | /* empty: end of list */ { 
735     $$ = 0;
736   };
737
738
739 AsmBlock : STRINGCONSTANT ;
740
741 BigOrLittle : BIG | LITTLE 
742
743 TargetDefinition 
744   : ENDIAN '=' BigOrLittle {
745     *$1 += " = " + *$3;
746     delete $3;
747     $$ = $1;
748   }
749   | POINTERSIZE '=' EUINT64VAL {
750     *$1 += " = " + *$3;
751     if (*$3 == "64")
752       SizeOfPointer = 64;
753     delete $3;
754     $$ = $1;
755   }
756   | TRIPLE '=' STRINGCONSTANT {
757     *$1 += " = " + *$3;
758     delete $3;
759     $$ = $1;
760   }
761   | DATALAYOUT '=' STRINGCONSTANT {
762     *$1 += " = " + *$3;
763     delete $3;
764     $$ = $1;
765   };
766
767 LibrariesDefinition 
768   : '[' LibList ']' {
769     $2->insert(0, "[ ");
770     *$2 += " ]";
771     $$ = $2;
772   };
773
774 LibList 
775   : LibList ',' STRINGCONSTANT {
776     *$1 += ", " + *$3;
777     delete $3;
778     $$ = $1;
779   }
780   | STRINGCONSTANT 
781   | /* empty: end of list */ {
782     $$ = new std::string();
783   };
784
785 //===----------------------------------------------------------------------===//
786 //                       Rules to match Function Headers
787 //===----------------------------------------------------------------------===//
788
789 Name : VAR_ID | STRINGCONSTANT;
790 OptName : Name | /*empty*/ { $$ = new std::string(); };
791
792 ArgVal : Types OptName {
793   $$ = $1.newTy;
794   if (!$2->empty())
795     *$$ += " " + *$2;
796   delete $2;
797 };
798
799 ArgListH : ArgListH ',' ArgVal {
800     *$1 += ", " + *$3;
801     delete $3;
802   }
803   | ArgVal {
804     $$ = $1;
805   };
806
807 ArgList : ArgListH {
808     $$ = $1;
809   }
810   | ArgListH ',' DOTDOTDOT {
811     *$1 += ", ...";
812     $$ = $1;
813     delete $3;
814   }
815   | DOTDOTDOT {
816     $$ = $1;
817   }
818   | /* empty */ { $$ = new std::string(); };
819
820 FunctionHeaderH : OptCallingConv TypesV Name '(' ArgList ')' 
821                   OptSection OptAlign {
822     if (!$1->empty()) {
823       *$1 += " ";
824     }
825     *$1 += *$2.newTy + " " + *$3 + "(" + *$5 + ")";
826     if (!$7->empty()) {
827       *$1 += " " + *$7;
828     }
829     if (!$8->empty()) {
830       *$1 += " " + *$8;
831     }
832     $2.destroy();
833     delete $3;
834     delete $5;
835     delete $7;
836     delete $8;
837     $$ = $1;
838   };
839
840 BEGIN : BEGINTOK {
841     $$ = new std::string("begin");
842   }
843   | '{' { 
844     $$ = new std::string ("{");
845   }
846
847 FunctionHeader : OptLinkage FunctionHeaderH BEGIN {
848   if (!$1->empty()) {
849     *O << *$1 << " ";
850   }
851   *O << *$2 << " " << *$3 << "\n";
852   delete $1; delete $2; delete $3;
853   $$ = 0;
854 };
855
856 END : ENDTOK { $$ = new std::string("end"); }
857     | '}' { $$ = new std::string("}"); };
858
859 Function : FunctionHeader BasicBlockList END {
860   if ($2)
861     *O << *$2;
862   *O << '\n' << *$3 << "\n";
863   $$ = 0;
864 };
865
866 FnDeclareLinkage
867   : /*default*/ { $$ = new std::string(); }
868   | DLLIMPORT    
869   | EXTERN_WEAK 
870   ;
871   
872 FunctionProto 
873   : DECLARE FnDeclareLinkage FunctionHeaderH { 
874     if (!$2->empty())
875       *$1 += " " + *$2;
876     *$1 += " " + *$3;
877     delete $2;
878     delete $3;
879     $$ = $1;
880   };
881
882 //===----------------------------------------------------------------------===//
883 //                        Rules to match Basic Blocks
884 //===----------------------------------------------------------------------===//
885
886 OptSideEffect : /* empty */ { $$ = new std::string(); }
887   | SIDEEFFECT;
888
889 ConstValueRef 
890   : ESINT64VAL | EUINT64VAL | FPVAL | TRUETOK | FALSETOK | NULL_TOK | UNDEF
891   | ZEROINITIALIZER 
892   | '<' ConstVector '>' { 
893     $2->insert(0, "<");
894     *$2 += ">";
895     $$ = $2;
896   }
897   | ConstExpr 
898   | ASM_TOK OptSideEffect STRINGCONSTANT ',' STRINGCONSTANT {
899     if (!$2->empty()) {
900       *$1 += " " + *$2;
901     }
902     *$1 += " " + *$3 + ", " + *$5;
903     delete $2; delete $3; delete $5;
904     $$ = $1;
905   };
906
907 SymbolicValueRef : IntVal | Name ;
908
909 // ValueRef - A reference to a definition... either constant or symbolic
910 ValueRef 
911   : SymbolicValueRef {
912     $$.val = $1;
913     $$.constant = false;
914     $$.type.newTy = 0;
915     $$.type.oldTy = UnresolvedTy;
916   }
917   | ConstValueRef {
918     $$.val = $1;
919     $$.constant = true;
920     $$.type.newTy = 0;
921     $$.type.oldTy = UnresolvedTy;
922   }
923   ;
924
925 // ResolvedVal - a <type> <value> pair.  This is used only in cases where the
926 // type immediately preceeds the value reference, and allows complex constant
927 // pool references (for things like: 'ret [2 x int] [ int 12, int 42]')
928 ResolvedVal : Types ValueRef {
929     $$ = $2;
930     $$.type = $1;
931     $$.val->insert(0, *$1.newTy + " ");
932   };
933
934 BasicBlockList : BasicBlockList BasicBlock {
935     $$ = 0;
936   }
937   | BasicBlock { // Do not allow functions with 0 basic blocks   
938     $$ = 0;
939   };
940
941
942 // Basic blocks are terminated by branching instructions: 
943 // br, br/cc, switch, ret
944 //
945 BasicBlock : InstructionList BBTerminatorInst  {
946     $$ = 0;
947   };
948
949 InstructionList : InstructionList Inst {
950     *O << "    " << *$2 << "\n";
951     delete $2;
952     $$ = 0;
953   }
954   | /* empty */ {
955     $$ = 0;
956   }
957   | LABELSTR {
958     *O << *$1 << "\n";
959     delete $1;
960     $$ = 0;
961   };
962
963 BBTerminatorInst : RET ResolvedVal {              // Return with a result...
964     *O << "    " << *$1 << " " << *$2.val << "\n";
965     delete $1; $2.destroy();
966     $$ = 0;
967   }
968   | RET VOID {                                       // Return with no result...
969     *O << "    " << *$1 << " " << *$2.newTy << "\n";
970     delete $1; $2.destroy();
971     $$ = 0;
972   }
973   | BR LABEL ValueRef {                         // Unconditional Branch...
974     *O << "    " << *$1 << " " << *$2.newTy << " " << *$3.val << "\n";
975     delete $1; $2.destroy(); $3.destroy();
976     $$ = 0;
977   }                                                  // Conditional Branch...
978   | BR BOOL ValueRef ',' LABEL ValueRef ',' LABEL ValueRef {  
979     *O << "    " << *$1 << " " << *$2.newTy << " " << *$3.val << ", " 
980        << *$5.newTy << " " << *$6.val << ", " << *$8.newTy << " " 
981        << *$9.val << "\n";
982     delete $1; $2.destroy(); $3.destroy(); $5.destroy(); $6.destroy(); 
983     $8.destroy(); $9.destroy();
984     $$ = 0;
985   }
986   | SWITCH IntType ValueRef ',' LABEL ValueRef '[' JumpTable ']' {
987     *O << "    " << *$1 << " " << *$2.newTy << " " << *$3.val << ", " 
988        << *$5.newTy << " " << *$6.val << " [" << *$8 << " ]\n";
989     delete $1; $2.destroy(); $3.destroy(); $5.destroy(); $6.destroy(); 
990     delete $8;
991     $$ = 0;
992   }
993   | SWITCH IntType ValueRef ',' LABEL ValueRef '[' ']' {
994     *O << "    " << *$1 << " " << *$2.newTy << " " << *$3.val << ", " 
995        << *$5.newTy << " " << *$6.val << "[]\n";
996     delete $1; $2.destroy(); $3.destroy(); $5.destroy(); $6.destroy();
997     $$ = 0;
998   }
999   | OptAssign INVOKE OptCallingConv TypesV ValueRef '(' ValueRefListE ')'
1000     TO LABEL ValueRef UNWIND LABEL ValueRef {
1001     *O << "    ";
1002     if (!$1->empty())
1003       *O << *$1 << " = ";
1004     *O << *$2 << " " << *$3 << " " << *$4.newTy << " " << *$5.val << " (";
1005     for (unsigned i = 0; i < $7->size(); ++i) {
1006       ValueInfo& VI = (*$7)[i];
1007       *O << *VI.val;
1008       if (i+1 < $7->size())
1009         *O << ", ";
1010       VI.destroy();
1011     }
1012     *O << ") " << *$9 << " " << *$10.newTy << " " << *$11.val << " " 
1013        << *$12 << " " << *$13.newTy << " " << *$14.val << "\n";
1014     delete $1; delete $2; delete $3; $4.destroy(); $5.destroy(); delete $7; 
1015     delete $9; $10.destroy(); $11.destroy(); delete $12; $13.destroy(); 
1016     $14.destroy(); 
1017     $$ = 0;
1018   }
1019   | UNWIND {
1020     *O << "    " << *$1 << "\n";
1021     delete $1;
1022     $$ = 0;
1023   }
1024   | UNREACHABLE {
1025     *O << "    " << *$1 << "\n";
1026     delete $1;
1027     $$ = 0;
1028   };
1029
1030 JumpTable : JumpTable IntType ConstValueRef ',' LABEL ValueRef {
1031     *$1 += " " + *$2.newTy + " " + *$3 + ", " + *$5.newTy + " " + *$6.val;
1032     $2.destroy(); delete $3; $5.destroy(); $6.destroy();
1033     $$ = $1;
1034   }
1035   | IntType ConstValueRef ',' LABEL ValueRef {
1036     $2->insert(0, *$1.newTy + " " );
1037     *$2 += ", " + *$4.newTy + " " + *$5.val;
1038     $1.destroy(); $4.destroy(); $5.destroy();
1039     $$ = $2;
1040   };
1041
1042 Inst 
1043   : OptAssign InstVal {
1044     if (!$1->empty())
1045       *$1 += " = ";
1046     *$1 += *$2;
1047     delete $2;
1048     $$ = $1; 
1049   };
1050
1051 PHIList 
1052   : Types '[' ValueRef ',' ValueRef ']' {    // Used for PHI nodes
1053     $3.val->insert(0, *$1.newTy + "[");
1054     *$3.val += "," + *$5.val + "]";
1055     $1.destroy(); $5.destroy();
1056     $$ = new std::string(*$3.val);
1057     $3.destroy();
1058   }
1059   | PHIList ',' '[' ValueRef ',' ValueRef ']' {
1060     *$1 += ", [" + *$4.val + "," + *$6.val + "]";
1061     $4.destroy(); $6.destroy();
1062     $$ = $1;
1063   };
1064
1065
1066 ValueRefList 
1067   : ResolvedVal { 
1068     $$ = new ValueList();
1069     $$->push_back($1);
1070   }
1071   | ValueRefList ',' ResolvedVal {
1072     $1->push_back($3);
1073     $$ = $1;
1074   };
1075
1076 // ValueRefListE - Just like ValueRefList, except that it may also be empty!
1077 ValueRefListE 
1078   : ValueRefList  { $$ = $1; }
1079   | /*empty*/ { $$ = new ValueList(); }
1080   ;
1081
1082 OptTailCall 
1083   : TAIL CALL {
1084     *$1 += " " + *$2;
1085     delete $2;
1086     $$ = $1;
1087   }
1088   | CALL 
1089   ;
1090
1091 InstVal : ArithmeticOps Types ValueRef ',' ValueRef {
1092     *$1 += " " + *$2.newTy + " " + *$3.val + ", " + *$5.val;
1093     $2.destroy(); $3.destroy(); $5.destroy();
1094     $$ = $1;
1095   }
1096   | LogicalOps Types ValueRef ',' ValueRef {
1097     *$1 += " " + *$2.newTy + " " + *$3.val + ", " + *$5.val;
1098     $2.destroy(); $3.destroy(); $5.destroy();
1099     $$ = $1;
1100   }
1101   | SetCondOps Types ValueRef ',' ValueRef {
1102     *$1 += " " + *$2.newTy + " " + *$3.val + ", " + *$5.val;
1103     $2.destroy(); $3.destroy(); $5.destroy();
1104     $$ = $1;
1105   }
1106   | NOT ResolvedVal {
1107     *$1 += " " + *$2.val;
1108     $2.destroy();
1109     $$ = $1;
1110   }
1111   | ShiftOps ResolvedVal ',' ResolvedVal {
1112     const char* shiftop = $1->c_str();
1113     if (*$1 == "shr")
1114       shiftop = ($2.type.isUnsigned()) ? "lshr" : "ashr";
1115     $$ = new std::string(shiftop);
1116     *$$ += " " + *$2.val + ", " + *$4.val;
1117     delete $1; $2.destroy(); $4.destroy();
1118   }
1119   | CastOps ResolvedVal TO Types {
1120     std::string source = *$2.val;
1121     TypeInfo SrcTy = $2.type;
1122     TypeInfo DstTy = $4;
1123     ResolveType(DstTy);
1124     $$ = new std::string();
1125     if (*$1 == "cast") {
1126       *$$ +=  getCastUpgrade(source, SrcTy, DstTy, false);
1127     } else {
1128       *$$ += *$1 + " " + source + " to " + *DstTy.newTy;
1129     }
1130     delete $1; $2.destroy();
1131     delete $3; $4.destroy();
1132   }
1133   | SELECT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
1134     *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
1135     $2.destroy(); $4.destroy(); $6.destroy();
1136     $$ = $1;
1137   }
1138   | VAARG ResolvedVal ',' Types {
1139     *$1 += " " + *$2.val + ", " + *$4.newTy;
1140     $2.destroy(); $4.destroy();
1141     $$ = $1;
1142   }
1143   | EXTRACTELEMENT ResolvedVal ',' ResolvedVal {
1144     *$1 += " " + *$2.val + ", " + *$4.val;
1145     $2.destroy(); $4.destroy();
1146     $$ = $1;
1147   }
1148   | INSERTELEMENT ResolvedVal ',' ResolvedVal ',' ResolvedVal {
1149     *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
1150     $2.destroy(); $4.destroy(); $6.destroy();
1151     $$ = $1;
1152   }
1153   | SHUFFLEVECTOR ResolvedVal ',' ResolvedVal ',' ResolvedVal {
1154     *$1 += " " + *$2.val + ", " + *$4.val + ", " + *$6.val;
1155     $2.destroy(); $4.destroy(); $6.destroy();
1156     $$ = $1;
1157   }
1158   | PHI_TOK PHIList {
1159     *$1 += " " + *$2;
1160     delete $2;
1161     $$ = $1;
1162   }
1163   | OptTailCall OptCallingConv TypesV ValueRef '(' ValueRefListE ')'  {
1164     if (!$2->empty())
1165       *$1 += " " + *$2;
1166     if (!$1->empty())
1167       *$1 += " ";
1168     *$1 += *$3.newTy + " " + *$4.val + "(";
1169     for (unsigned i = 0; i < $6->size(); ++i) {
1170       ValueInfo& VI = (*$6)[i];
1171       *$1 += *VI.val;
1172       if (i+1 < $6->size())
1173         *$1 += ", ";
1174       VI.destroy();
1175     }
1176     *$1 += ")";
1177     delete $2; $3.destroy(); $4.destroy(); delete $6;
1178     $$ = $1;
1179   }
1180   | MemoryInst ;
1181
1182
1183 // IndexList - List of indices for GEP based instructions...
1184 IndexList 
1185   : ',' ValueRefList { $$ = $2; }
1186   | /* empty */ {  $$ = new ValueList(); }
1187   ;
1188
1189 OptVolatile 
1190   : VOLATILE 
1191   | /* empty */ { $$ = new std::string(); }
1192   ;
1193
1194 MemoryInst : MALLOC Types OptCAlign {
1195     *$1 += " " + *$2.newTy;
1196     if (!$3->empty())
1197       *$1 += " " + *$3;
1198     $2.destroy(); delete $3;
1199     $$ = $1;
1200   }
1201   | MALLOC Types ',' UINT ValueRef OptCAlign {
1202     *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5.val;
1203     if (!$6->empty())
1204       *$1 += " " + *$6;
1205     $2.destroy(); $4.destroy(); $5.destroy(); delete $6;
1206     $$ = $1;
1207   }
1208   | ALLOCA Types OptCAlign {
1209     *$1 += " " + *$2.newTy;
1210     if (!$3->empty())
1211       *$1 += " " + *$3;
1212     $2.destroy(); delete $3;
1213     $$ = $1;
1214   }
1215   | ALLOCA Types ',' UINT ValueRef OptCAlign {
1216     *$1 += " " + *$2.newTy + ", " + *$4.newTy + " " + *$5.val;
1217     if (!$6->empty())
1218       *$1 += " " + *$6;
1219     $2.destroy(); $4.destroy(); $5.destroy(); delete $6;
1220     $$ = $1;
1221   }
1222   | FREE ResolvedVal {
1223     *$1 += " " + *$2.val;
1224     $2.destroy();
1225     $$ = $1;
1226   }
1227   | OptVolatile LOAD Types ValueRef {
1228     if (!$1->empty())
1229       *$1 += " ";
1230     *$1 += *$2 + " " + *$3.newTy + " " + *$4.val;
1231     delete $2; $3.destroy(); $4.destroy();
1232     $$ = $1;
1233   }
1234   | OptVolatile STORE ResolvedVal ',' Types ValueRef {
1235     if (!$1->empty())
1236       *$1 += " ";
1237     *$1 += *$2 + " " + *$3.val + ", " + *$5.newTy + " " + *$6.val;
1238     delete $2; $3.destroy(); $5.destroy(); $6.destroy();
1239     $$ = $1;
1240   }
1241   | GETELEMENTPTR Types ValueRef IndexList {
1242     // Upgrade the indices
1243     for (unsigned i = 0; i < $4->size(); ++i) {
1244       ValueInfo& VI = (*$4)[i];
1245       if (VI.type.isUnsigned() && !VI.isConstant() && 
1246           VI.type.getBitWidth() < 64) {
1247         std::string* old = VI.val;
1248         *O << "    %gep_upgrade" << unique << " = zext " << *old 
1249            << " to ulong\n";
1250         VI.val = new std::string("ulong %gep_upgrade" + llvm::utostr(unique++));
1251         VI.type.oldTy = ULongTy;
1252         delete old;
1253       }
1254     }
1255     *$1 += " " + *$2.newTy + " " + *$3.val;
1256     for (unsigned i = 0; i < $4->size(); ++i) {
1257       ValueInfo& VI = (*$4)[i];
1258       *$1 += ", " + *VI.val;
1259       VI.destroy();
1260     }
1261     $2.destroy(); $3.destroy(); delete $4;
1262     $$ = $1;
1263   };
1264
1265 %%
1266
1267 int yyerror(const char *ErrorMsg) {
1268   std::string where 
1269     = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
1270                   + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
1271   std::string errMsg = std::string(ErrorMsg) + "\n" + where + " while reading ";
1272   if (yychar == YYEMPTY || yychar == 0)
1273     errMsg += "end-of-file.";
1274   else
1275     errMsg += "token: '" + std::string(Upgradetext, Upgradeleng) + "'";
1276   std::cerr << errMsg << '\n';
1277   exit(1);
1278 }