Regenerate.
[oota-llvm.git] / tools / llvm-upgrade / UpgradeParser.cpp.cvs
1 /* A Bison parser, made by GNU Bison 2.1.  */
2
3 /* Skeleton parser for Yacc-like parsing with Bison,
4    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 2, or (at your option)
9    any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor,
19    Boston, MA 02110-1301, USA.  */
20
21 /* As a special exception, when this file is copied by Bison into a
22    Bison output file, you may use that output file without restriction.
23    This special exception was added by the Free Software Foundation
24    in version 1.24 of Bison.  */
25
26 /* Written by Richard Stallman by simplifying the original so called
27    ``semantic'' parser.  */
28
29 /* All symbols defined below should begin with yy or YY, to avoid
30    infringing on user name space.  This should be done even for local
31    variables, as they might otherwise be expanded by user macros.
32    There are some unavoidable exceptions within include files to
33    define necessary library symbols; they are noted "INFRINGES ON
34    USER NAME SPACE" below.  */
35
36 /* Identify Bison output.  */
37 #define YYBISON 1
38
39 /* Bison version.  */
40 #define YYBISON_VERSION "2.1"
41
42 /* Skeleton name.  */
43 #define YYSKELETON_NAME "yacc.c"
44
45 /* Pure parsers.  */
46 #define YYPURE 0
47
48 /* Using locations.  */
49 #define YYLSP_NEEDED 0
50
51 /* Substitute the variable and function names.  */
52 #define yyparse Upgradeparse
53 #define yylex   Upgradelex
54 #define yyerror Upgradeerror
55 #define yylval  Upgradelval
56 #define yychar  Upgradechar
57 #define yydebug Upgradedebug
58 #define yynerrs Upgradenerrs
59
60
61 /* Tokens.  */
62 #ifndef YYTOKENTYPE
63 # define YYTOKENTYPE
64    /* Put the tokens into the symbol table, so that GDB and other debuggers
65       know about them.  */
66    enum yytokentype {
67      ESINT64VAL = 258,
68      EUINT64VAL = 259,
69      SINTVAL = 260,
70      UINTVAL = 261,
71      FPVAL = 262,
72      VOID = 263,
73      BOOL = 264,
74      SBYTE = 265,
75      UBYTE = 266,
76      SHORT = 267,
77      USHORT = 268,
78      INT = 269,
79      UINT = 270,
80      LONG = 271,
81      ULONG = 272,
82      FLOAT = 273,
83      DOUBLE = 274,
84      TYPE = 275,
85      LABEL = 276,
86      VAR_ID = 277,
87      LABELSTR = 278,
88      STRINGCONSTANT = 279,
89      IMPLEMENTATION = 280,
90      ZEROINITIALIZER = 281,
91      TRUETOK = 282,
92      FALSETOK = 283,
93      BEGINTOK = 284,
94      ENDTOK = 285,
95      DECLARE = 286,
96      GLOBAL = 287,
97      CONSTANT = 288,
98      SECTION = 289,
99      VOLATILE = 290,
100      TO = 291,
101      DOTDOTDOT = 292,
102      NULL_TOK = 293,
103      UNDEF = 294,
104      CONST = 295,
105      INTERNAL = 296,
106      LINKONCE = 297,
107      WEAK = 298,
108      APPENDING = 299,
109      DLLIMPORT = 300,
110      DLLEXPORT = 301,
111      EXTERN_WEAK = 302,
112      OPAQUE = 303,
113      NOT = 304,
114      EXTERNAL = 305,
115      TARGET = 306,
116      TRIPLE = 307,
117      ENDIAN = 308,
118      POINTERSIZE = 309,
119      LITTLE = 310,
120      BIG = 311,
121      ALIGN = 312,
122      DEPLIBS = 313,
123      CALL = 314,
124      TAIL = 315,
125      ASM_TOK = 316,
126      MODULE = 317,
127      SIDEEFFECT = 318,
128      CC_TOK = 319,
129      CCC_TOK = 320,
130      CSRETCC_TOK = 321,
131      FASTCC_TOK = 322,
132      COLDCC_TOK = 323,
133      X86_STDCALLCC_TOK = 324,
134      X86_FASTCALLCC_TOK = 325,
135      DATALAYOUT = 326,
136      RET = 327,
137      BR = 328,
138      SWITCH = 329,
139      INVOKE = 330,
140      UNREACHABLE = 331,
141      UNWIND = 332,
142      EXCEPT = 333,
143      ADD = 334,
144      SUB = 335,
145      MUL = 336,
146      DIV = 337,
147      UDIV = 338,
148      SDIV = 339,
149      FDIV = 340,
150      REM = 341,
151      UREM = 342,
152      SREM = 343,
153      FREM = 344,
154      AND = 345,
155      OR = 346,
156      XOR = 347,
157      SHL = 348,
158      SHR = 349,
159      ASHR = 350,
160      LSHR = 351,
161      SETLE = 352,
162      SETGE = 353,
163      SETLT = 354,
164      SETGT = 355,
165      SETEQ = 356,
166      SETNE = 357,
167      ICMP = 358,
168      FCMP = 359,
169      MALLOC = 360,
170      ALLOCA = 361,
171      FREE = 362,
172      LOAD = 363,
173      STORE = 364,
174      GETELEMENTPTR = 365,
175      PHI_TOK = 366,
176      SELECT = 367,
177      VAARG = 368,
178      EXTRACTELEMENT = 369,
179      INSERTELEMENT = 370,
180      SHUFFLEVECTOR = 371,
181      VAARG_old = 372,
182      VANEXT_old = 373,
183      EQ = 374,
184      NE = 375,
185      SLT = 376,
186      SGT = 377,
187      SLE = 378,
188      SGE = 379,
189      ULT = 380,
190      UGT = 381,
191      ULE = 382,
192      UGE = 383,
193      OEQ = 384,
194      ONE = 385,
195      OLT = 386,
196      OGT = 387,
197      OLE = 388,
198      OGE = 389,
199      ORD = 390,
200      UNO = 391,
201      UEQ = 392,
202      UNE = 393,
203      CAST = 394,
204      TRUNC = 395,
205      ZEXT = 396,
206      SEXT = 397,
207      FPTRUNC = 398,
208      FPEXT = 399,
209      FPTOUI = 400,
210      FPTOSI = 401,
211      UITOFP = 402,
212      SITOFP = 403,
213      PTRTOINT = 404,
214      INTTOPTR = 405,
215      BITCAST = 406
216    };
217 #endif
218 /* Tokens.  */
219 #define ESINT64VAL 258
220 #define EUINT64VAL 259
221 #define SINTVAL 260
222 #define UINTVAL 261
223 #define FPVAL 262
224 #define VOID 263
225 #define BOOL 264
226 #define SBYTE 265
227 #define UBYTE 266
228 #define SHORT 267
229 #define USHORT 268
230 #define INT 269
231 #define UINT 270
232 #define LONG 271
233 #define ULONG 272
234 #define FLOAT 273
235 #define DOUBLE 274
236 #define TYPE 275
237 #define LABEL 276
238 #define VAR_ID 277
239 #define LABELSTR 278
240 #define STRINGCONSTANT 279
241 #define IMPLEMENTATION 280
242 #define ZEROINITIALIZER 281
243 #define TRUETOK 282
244 #define FALSETOK 283
245 #define BEGINTOK 284
246 #define ENDTOK 285
247 #define DECLARE 286
248 #define GLOBAL 287
249 #define CONSTANT 288
250 #define SECTION 289
251 #define VOLATILE 290
252 #define TO 291
253 #define DOTDOTDOT 292
254 #define NULL_TOK 293
255 #define UNDEF 294
256 #define CONST 295
257 #define INTERNAL 296
258 #define LINKONCE 297
259 #define WEAK 298
260 #define APPENDING 299
261 #define DLLIMPORT 300
262 #define DLLEXPORT 301
263 #define EXTERN_WEAK 302
264 #define OPAQUE 303
265 #define NOT 304
266 #define EXTERNAL 305
267 #define TARGET 306
268 #define TRIPLE 307
269 #define ENDIAN 308
270 #define POINTERSIZE 309
271 #define LITTLE 310
272 #define BIG 311
273 #define ALIGN 312
274 #define DEPLIBS 313
275 #define CALL 314
276 #define TAIL 315
277 #define ASM_TOK 316
278 #define MODULE 317
279 #define SIDEEFFECT 318
280 #define CC_TOK 319
281 #define CCC_TOK 320
282 #define CSRETCC_TOK 321
283 #define FASTCC_TOK 322
284 #define COLDCC_TOK 323
285 #define X86_STDCALLCC_TOK 324
286 #define X86_FASTCALLCC_TOK 325
287 #define DATALAYOUT 326
288 #define RET 327
289 #define BR 328
290 #define SWITCH 329
291 #define INVOKE 330
292 #define UNREACHABLE 331
293 #define UNWIND 332
294 #define EXCEPT 333
295 #define ADD 334
296 #define SUB 335
297 #define MUL 336
298 #define DIV 337
299 #define UDIV 338
300 #define SDIV 339
301 #define FDIV 340
302 #define REM 341
303 #define UREM 342
304 #define SREM 343
305 #define FREM 344
306 #define AND 345
307 #define OR 346
308 #define XOR 347
309 #define SHL 348
310 #define SHR 349
311 #define ASHR 350
312 #define LSHR 351
313 #define SETLE 352
314 #define SETGE 353
315 #define SETLT 354
316 #define SETGT 355
317 #define SETEQ 356
318 #define SETNE 357
319 #define ICMP 358
320 #define FCMP 359
321 #define MALLOC 360
322 #define ALLOCA 361
323 #define FREE 362
324 #define LOAD 363
325 #define STORE 364
326 #define GETELEMENTPTR 365
327 #define PHI_TOK 366
328 #define SELECT 367
329 #define VAARG 368
330 #define EXTRACTELEMENT 369
331 #define INSERTELEMENT 370
332 #define SHUFFLEVECTOR 371
333 #define VAARG_old 372
334 #define VANEXT_old 373
335 #define EQ 374
336 #define NE 375
337 #define SLT 376
338 #define SGT 377
339 #define SLE 378
340 #define SGE 379
341 #define ULT 380
342 #define UGT 381
343 #define ULE 382
344 #define UGE 383
345 #define OEQ 384
346 #define ONE 385
347 #define OLT 386
348 #define OGT 387
349 #define OLE 388
350 #define OGE 389
351 #define ORD 390
352 #define UNO 391
353 #define UEQ 392
354 #define UNE 393
355 #define CAST 394
356 #define TRUNC 395
357 #define ZEXT 396
358 #define SEXT 397
359 #define FPTRUNC 398
360 #define FPEXT 399
361 #define FPTOUI 400
362 #define FPTOSI 401
363 #define UITOFP 402
364 #define SITOFP 403
365 #define PTRTOINT 404
366 #define INTTOPTR 405
367 #define BITCAST 406
368
369
370
371
372 /* Copy the first part of user declarations.  */
373 #line 14 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
374
375 #include "UpgradeInternals.h"
376 #include "llvm/CallingConv.h"
377 #include "llvm/InlineAsm.h"
378 #include "llvm/Instructions.h"
379 #include "llvm/Module.h"
380 #include "llvm/ValueSymbolTable.h"
381 #include "llvm/Support/GetElementPtrTypeIterator.h"
382 #include "llvm/ADT/STLExtras.h"
383 #include "llvm/Support/MathExtras.h"
384 #include <algorithm>
385 #include <iostream>
386 #include <map>
387 #include <list>
388 #include <utility>
389
390 // DEBUG_UPREFS - Define this symbol if you want to enable debugging output
391 // relating to upreferences in the input stream.
392 //
393 //#define DEBUG_UPREFS 1
394 #ifdef DEBUG_UPREFS
395 #define UR_OUT(X) std::cerr << X
396 #else
397 #define UR_OUT(X)
398 #endif
399
400 #define YYERROR_VERBOSE 1
401 #define YYINCLUDED_STDLIB_H
402 #define YYDEBUG 1
403
404 int yylex();
405 int yyparse();
406
407 int yyerror(const char*);
408 static void warning(const std::string& WarningMsg);
409
410 namespace llvm {
411
412 std::istream* LexInput;
413 static std::string CurFilename;
414
415 // This bool controls whether attributes are ever added to function declarations
416 // definitions and calls.
417 static bool AddAttributes = false;
418
419 static Module *ParserResult;
420 static bool ObsoleteVarArgs;
421 static bool NewVarArgs;
422 static BasicBlock *CurBB;
423 static GlobalVariable *CurGV;
424
425 // This contains info used when building the body of a function.  It is
426 // destroyed when the function is completed.
427 //
428 typedef std::vector<Value *> ValueList;           // Numbered defs
429
430 typedef std::pair<std::string,TypeInfo> RenameMapKey;
431 typedef std::map<RenameMapKey,std::string> RenameMapType;
432
433 static void 
434 ResolveDefinitions(std::map<const Type *,ValueList> &LateResolvers,
435                    std::map<const Type *,ValueList> *FutureLateResolvers = 0);
436
437 static struct PerModuleInfo {
438   Module *CurrentModule;
439   std::map<const Type *, ValueList> Values; // Module level numbered definitions
440   std::map<const Type *,ValueList> LateResolveValues;
441   std::vector<PATypeHolder> Types;
442   std::vector<Signedness> TypeSigns;
443   std::map<std::string,Signedness> NamedTypeSigns;
444   std::map<std::string,Signedness> NamedValueSigns;
445   std::map<ValID, PATypeHolder> LateResolveTypes;
446   static Module::Endianness Endian;
447   static Module::PointerSize PointerSize;
448   RenameMapType RenameMap;
449
450   /// PlaceHolderInfo - When temporary placeholder objects are created, remember
451   /// how they were referenced and on which line of the input they came from so
452   /// that we can resolve them later and print error messages as appropriate.
453   std::map<Value*, std::pair<ValID, int> > PlaceHolderInfo;
454
455   // GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
456   // references to global values.  Global values may be referenced before they
457   // are defined, and if so, the temporary object that they represent is held
458   // here.  This is used for forward references of GlobalValues.
459   //
460   typedef std::map<std::pair<const PointerType *, ValID>, GlobalValue*> 
461     GlobalRefsType;
462   GlobalRefsType GlobalRefs;
463
464   void ModuleDone() {
465     // If we could not resolve some functions at function compilation time
466     // (calls to functions before they are defined), resolve them now...  Types
467     // are resolved when the constant pool has been completely parsed.
468     //
469     ResolveDefinitions(LateResolveValues);
470
471     // Check to make sure that all global value forward references have been
472     // resolved!
473     //
474     if (!GlobalRefs.empty()) {
475       std::string UndefinedReferences = "Unresolved global references exist:\n";
476
477       for (GlobalRefsType::iterator I = GlobalRefs.begin(), E =GlobalRefs.end();
478            I != E; ++I) {
479         UndefinedReferences += "  " + I->first.first->getDescription() + " " +
480                                I->first.second.getName() + "\n";
481       }
482       error(UndefinedReferences);
483       return;
484     }
485
486     if (CurrentModule->getDataLayout().empty()) {
487       std::string dataLayout;
488       if (Endian != Module::AnyEndianness)
489         dataLayout.append(Endian == Module::BigEndian ? "E" : "e");
490       if (PointerSize != Module::AnyPointerSize) {
491         if (!dataLayout.empty())
492           dataLayout += "-";
493         dataLayout.append(PointerSize == Module::Pointer64 ? 
494                           "p:64:64" : "p:32:32");
495       }
496       CurrentModule->setDataLayout(dataLayout);
497     }
498
499     Values.clear();         // Clear out function local definitions
500     Types.clear();
501     TypeSigns.clear();
502     NamedTypeSigns.clear();
503     NamedValueSigns.clear();
504     CurrentModule = 0;
505   }
506
507   // GetForwardRefForGlobal - Check to see if there is a forward reference
508   // for this global.  If so, remove it from the GlobalRefs map and return it.
509   // If not, just return null.
510   GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ValID ID) {
511     // Check to see if there is a forward reference to this global variable...
512     // if there is, eliminate it and patch the reference to use the new def'n.
513     GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PTy, ID));
514     GlobalValue *Ret = 0;
515     if (I != GlobalRefs.end()) {
516       Ret = I->second;
517       GlobalRefs.erase(I);
518     }
519     return Ret;
520   }
521   void setEndianness(Module::Endianness E) { Endian = E; }
522   void setPointerSize(Module::PointerSize sz) { PointerSize = sz; }
523 } CurModule;
524
525 Module::Endianness  PerModuleInfo::Endian = Module::AnyEndianness;
526 Module::PointerSize PerModuleInfo::PointerSize = Module::AnyPointerSize;
527
528 static struct PerFunctionInfo {
529   Function *CurrentFunction;     // Pointer to current function being created
530
531   std::map<const Type*, ValueList> Values; // Keep track of #'d definitions
532   std::map<const Type*, ValueList> LateResolveValues;
533   bool isDeclare;                   // Is this function a forward declararation?
534   GlobalValue::LinkageTypes Linkage;// Linkage for forward declaration.
535
536   /// BBForwardRefs - When we see forward references to basic blocks, keep
537   /// track of them here.
538   std::map<BasicBlock*, std::pair<ValID, int> > BBForwardRefs;
539   std::vector<BasicBlock*> NumberedBlocks;
540   RenameMapType RenameMap;
541   unsigned NextBBNum;
542
543   inline PerFunctionInfo() {
544     CurrentFunction = 0;
545     isDeclare = false;
546     Linkage = GlobalValue::ExternalLinkage;    
547   }
548
549   inline void FunctionStart(Function *M) {
550     CurrentFunction = M;
551     NextBBNum = 0;
552   }
553
554   void FunctionDone() {
555     NumberedBlocks.clear();
556
557     // Any forward referenced blocks left?
558     if (!BBForwardRefs.empty()) {
559       error("Undefined reference to label " + 
560             BBForwardRefs.begin()->first->getName());
561       return;
562     }
563
564     // Resolve all forward references now.
565     ResolveDefinitions(LateResolveValues, &CurModule.LateResolveValues);
566
567     Values.clear();         // Clear out function local definitions
568     RenameMap.clear();
569     CurrentFunction = 0;
570     isDeclare = false;
571     Linkage = GlobalValue::ExternalLinkage;
572   }
573 } CurFun;  // Info for the current function...
574
575 static bool inFunctionScope() { return CurFun.CurrentFunction != 0; }
576
577 /// This function is just a utility to make a Key value for the rename map.
578 /// The Key is a combination of the name, type, Signedness of the original 
579 /// value (global/function). This just constructs the key and ensures that
580 /// named Signedness values are resolved to the actual Signedness.
581 /// @brief Make a key for the RenameMaps
582 static RenameMapKey makeRenameMapKey(const std::string &Name, const Type* Ty, 
583                                      const Signedness &Sign) {
584   TypeInfo TI; 
585   TI.T = Ty; 
586   if (Sign.isNamed())
587     // Don't allow Named Signedness nodes because they won't match. The actual
588     // Signedness must be looked up in the NamedTypeSigns map.
589     TI.S.copy(CurModule.NamedTypeSigns[Sign.getName()]);
590   else
591     TI.S.copy(Sign);
592   return std::make_pair(Name, TI);
593 }
594
595
596 //===----------------------------------------------------------------------===//
597 //               Code to handle definitions of all the types
598 //===----------------------------------------------------------------------===//
599
600 static int InsertValue(Value *V,
601                   std::map<const Type*,ValueList> &ValueTab = CurFun.Values) {
602   if (V->hasName()) return -1;           // Is this a numbered definition?
603
604   // Yes, insert the value into the value table...
605   ValueList &List = ValueTab[V->getType()];
606   List.push_back(V);
607   return List.size()-1;
608 }
609
610 static const Type *getType(const ValID &D, bool DoNotImprovise = false) {
611   switch (D.Type) {
612   case ValID::NumberVal:               // Is it a numbered definition?
613     // Module constants occupy the lowest numbered slots...
614     if ((unsigned)D.Num < CurModule.Types.size()) {
615       return CurModule.Types[(unsigned)D.Num];
616     }
617     break;
618   case ValID::NameVal:                 // Is it a named definition?
619     if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) {
620       return N;
621     }
622     break;
623   default:
624     error("Internal parser error: Invalid symbol type reference");
625     return 0;
626   }
627
628   // If we reached here, we referenced either a symbol that we don't know about
629   // or an id number that hasn't been read yet.  We may be referencing something
630   // forward, so just create an entry to be resolved later and get to it...
631   //
632   if (DoNotImprovise) return 0;  // Do we just want a null to be returned?
633
634   if (inFunctionScope()) {
635     if (D.Type == ValID::NameVal) {
636       error("Reference to an undefined type: '" + D.getName() + "'");
637       return 0;
638     } else {
639       error("Reference to an undefined type: #" + itostr(D.Num));
640       return 0;
641     }
642   }
643
644   std::map<ValID, PATypeHolder>::iterator I =CurModule.LateResolveTypes.find(D);
645   if (I != CurModule.LateResolveTypes.end())
646     return I->second;
647
648   Type *Typ = OpaqueType::get();
649   CurModule.LateResolveTypes.insert(std::make_pair(D, Typ));
650   return Typ;
651 }
652
653 /// This is like the getType method except that instead of looking up the type
654 /// for a given ID, it looks up that type's sign.
655 /// @brief Get the signedness of a referenced type
656 static Signedness getTypeSign(const ValID &D) {
657   switch (D.Type) {
658   case ValID::NumberVal:               // Is it a numbered definition?
659     // Module constants occupy the lowest numbered slots...
660     if ((unsigned)D.Num < CurModule.TypeSigns.size()) {
661       return CurModule.TypeSigns[(unsigned)D.Num];
662     }
663     break;
664   case ValID::NameVal: {               // Is it a named definition?
665     std::map<std::string,Signedness>::const_iterator I = 
666       CurModule.NamedTypeSigns.find(D.Name);
667     if (I != CurModule.NamedTypeSigns.end())
668       return I->second;
669     // Perhaps its a named forward .. just cache the name
670     Signedness S;
671     S.makeNamed(D.Name);
672     return S;
673   }
674   default: 
675     break;
676   }
677   // If we don't find it, its signless
678   Signedness S;
679   S.makeSignless();
680   return S;
681 }
682
683 /// This function is analagous to getElementType in LLVM. It provides the same
684 /// function except that it looks up the Signedness instead of the type. This is
685 /// used when processing GEP instructions that need to extract the type of an
686 /// indexed struct/array/ptr member. 
687 /// @brief Look up an element's sign.
688 static Signedness getElementSign(const ValueInfo& VI, 
689                                  const std::vector<Value*> &Indices) {
690   const Type *Ptr = VI.V->getType();
691   assert(isa<PointerType>(Ptr) && "Need pointer type");
692
693   unsigned CurIdx = 0;
694   Signedness S(VI.S);
695   while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) {
696     if (CurIdx == Indices.size())
697       break;
698
699     Value *Index = Indices[CurIdx++];
700     assert(!isa<PointerType>(CT) || CurIdx == 1 && "Invalid type");
701     Ptr = CT->getTypeAtIndex(Index);
702     if (const Type* Ty = Ptr->getForwardedType())
703       Ptr = Ty;
704     assert(S.isComposite() && "Bad Signedness type");
705     if (isa<StructType>(CT)) {
706       S = S.get(cast<ConstantInt>(Index)->getZExtValue());
707     } else {
708       S = S.get(0UL);
709     }
710     if (S.isNamed())
711       S = CurModule.NamedTypeSigns[S.getName()];
712   }
713   Signedness Result;
714   Result.makeComposite(S);
715   return Result;
716 }
717
718 /// This function just translates a ConstantInfo into a ValueInfo and calls
719 /// getElementSign(ValueInfo,...). Its just a convenience.
720 /// @brief ConstantInfo version of getElementSign.
721 static Signedness getElementSign(const ConstInfo& CI, 
722                                  const std::vector<Constant*> &Indices) {
723   ValueInfo VI;
724   VI.V = CI.C;
725   VI.S.copy(CI.S);
726   std::vector<Value*> Idx;
727   for (unsigned i = 0; i < Indices.size(); ++i)
728     Idx.push_back(Indices[i]);
729   Signedness result = getElementSign(VI, Idx);
730   VI.destroy();
731   return result;
732 }
733
734 /// This function determines if two function types differ only in their use of
735 /// the sret parameter attribute in the first argument. If they are identical 
736 /// in all other respects, it returns true. Otherwise, it returns false.
737 static bool FuncTysDifferOnlyBySRet(const FunctionType *F1, 
738                                     const FunctionType *F2) {
739   if (F1->getReturnType() != F2->getReturnType() ||
740       F1->getNumParams() != F2->getNumParams() ||
741       F1->getParamAttrs(0) != F2->getParamAttrs(0))
742     return false;
743   unsigned SRetMask = ~unsigned(FunctionType::StructRetAttribute);
744   for (unsigned i = 0; i < F1->getNumParams(); ++i) {
745     if (F1->getParamType(i) != F2->getParamType(i) ||
746         unsigned(F1->getParamAttrs(i+1)) & SRetMask !=
747         unsigned(F2->getParamAttrs(i+1)) & SRetMask)
748       return false;
749   }
750   return true;
751 }
752
753 /// This function determines if the type of V and Ty differ only by the SRet
754 /// parameter attribute. This is a more generalized case of
755 /// FuncTysDIfferOnlyBySRet since it doesn't require FunctionType arguments.
756 static bool TypesDifferOnlyBySRet(Value *V, const Type* Ty) {
757   if (V->getType() == Ty)
758     return true;
759   const PointerType *PF1 = dyn_cast<PointerType>(Ty);
760   const PointerType *PF2 = dyn_cast<PointerType>(V->getType());
761   if (PF1 && PF2) {
762     const FunctionType* FT1 = dyn_cast<FunctionType>(PF1->getElementType());
763     const FunctionType* FT2 = dyn_cast<FunctionType>(PF2->getElementType());
764     if (FT1 && FT2)
765       return FuncTysDifferOnlyBySRet(FT1, FT2);
766   }
767   return false;
768 }
769
770 // The upgrade of csretcc to sret param attribute may have caused a function 
771 // to not be found because the param attribute changed the type of the called 
772 // function. This helper function, used in getExistingValue, detects that
773 // situation and bitcasts the function to the correct type.
774 static Value* handleSRetFuncTypeMerge(Value *V, const Type* Ty) {
775   // Handle degenerate cases
776   if (!V)
777     return 0;
778   if (V->getType() == Ty)
779     return V;
780
781   const PointerType *PF1 = dyn_cast<PointerType>(Ty);
782   const PointerType *PF2 = dyn_cast<PointerType>(V->getType());
783   if (PF1 && PF2) {
784     const FunctionType *FT1 = dyn_cast<FunctionType>(PF1->getElementType());
785     const FunctionType *FT2 = dyn_cast<FunctionType>(PF2->getElementType());
786     if (FT1 && FT2 && FuncTysDifferOnlyBySRet(FT1, FT2))
787       if (FT2->paramHasAttr(1, FunctionType::StructRetAttribute))
788         return V;
789       else if (Constant *C = dyn_cast<Constant>(V))
790         return ConstantExpr::getBitCast(C, PF1);
791       else
792         return new BitCastInst(V, PF1, "upgrd.cast", CurBB);
793       
794   }
795   return 0;
796 }
797
798 // getExistingValue - Look up the value specified by the provided type and
799 // the provided ValID.  If the value exists and has already been defined, return
800 // it.  Otherwise return null.
801 //
802 static Value *getExistingValue(const Type *Ty, const ValID &D) {
803   if (isa<FunctionType>(Ty)) {
804     error("Functions are not values and must be referenced as pointers");
805   }
806
807   switch (D.Type) {
808   case ValID::NumberVal: {                 // Is it a numbered definition?
809     unsigned Num = (unsigned)D.Num;
810
811     // Module constants occupy the lowest numbered slots...
812     std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
813     if (VI != CurModule.Values.end()) {
814       if (Num < VI->second.size())
815         return VI->second[Num];
816       Num -= VI->second.size();
817     }
818
819     // Make sure that our type is within bounds
820     VI = CurFun.Values.find(Ty);
821     if (VI == CurFun.Values.end()) return 0;
822
823     // Check that the number is within bounds...
824     if (VI->second.size() <= Num) return 0;
825
826     return VI->second[Num];
827   }
828
829   case ValID::NameVal: {                // Is it a named definition?
830     // Get the name out of the ID
831     RenameMapKey Key = makeRenameMapKey(D.Name, Ty, D.S);
832     Value *V = 0;
833     if (inFunctionScope()) {
834       // See if the name was renamed
835       RenameMapType::const_iterator I = CurFun.RenameMap.find(Key);
836       std::string LookupName;
837       if (I != CurFun.RenameMap.end())
838         LookupName = I->second;
839       else
840         LookupName = D.Name;
841       ValueSymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable();
842       V = SymTab.lookup(LookupName);
843       if (V && V->getType() != Ty)
844         V = handleSRetFuncTypeMerge(V, Ty);
845       assert((!V || TypesDifferOnlyBySRet(V, Ty)) && "Found wrong type");
846     }
847     if (!V) {
848       RenameMapType::const_iterator I = CurModule.RenameMap.find(Key);
849       std::string LookupName;
850       if (I != CurModule.RenameMap.end())
851         LookupName = I->second;
852       else
853         LookupName = D.Name;
854       V = CurModule.CurrentModule->getValueSymbolTable().lookup(LookupName);
855       if (V && V->getType() != Ty)
856         V = handleSRetFuncTypeMerge(V, Ty);
857       assert((!V || TypesDifferOnlyBySRet(V, Ty)) && "Found wrong type");
858     }
859     if (!V) 
860       return 0;
861
862     D.destroy();  // Free old strdup'd memory...
863     return V;
864   }
865
866   // Check to make sure that "Ty" is an integral type, and that our
867   // value will fit into the specified type...
868   case ValID::ConstSIntVal:    // Is it a constant pool reference??
869     if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
870       error("Signed integral constant '" + itostr(D.ConstPool64) + 
871             "' is invalid for type '" + Ty->getDescription() + "'");
872     }
873     return ConstantInt::get(Ty, D.ConstPool64);
874
875   case ValID::ConstUIntVal:     // Is it an unsigned const pool reference?
876     if (!ConstantInt::isValueValidForType(Ty, D.UConstPool64)) {
877       if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64))
878         error("Integral constant '" + utostr(D.UConstPool64) + 
879               "' is invalid or out of range");
880       else     // This is really a signed reference.  Transmogrify.
881         return ConstantInt::get(Ty, D.ConstPool64);
882     } else
883       return ConstantInt::get(Ty, D.UConstPool64);
884
885   case ValID::ConstFPVal:        // Is it a floating point const pool reference?
886     if (!ConstantFP::isValueValidForType(Ty, D.ConstPoolFP))
887       error("FP constant invalid for type");
888     return ConstantFP::get(Ty, D.ConstPoolFP);
889
890   case ValID::ConstNullVal:      // Is it a null value?
891     if (!isa<PointerType>(Ty))
892       error("Cannot create a a non pointer null");
893     return ConstantPointerNull::get(cast<PointerType>(Ty));
894
895   case ValID::ConstUndefVal:      // Is it an undef value?
896     return UndefValue::get(Ty);
897
898   case ValID::ConstZeroVal:      // Is it a zero value?
899     return Constant::getNullValue(Ty);
900     
901   case ValID::ConstantVal:       // Fully resolved constant?
902     if (D.ConstantValue->getType() != Ty) 
903       error("Constant expression type different from required type");
904     return D.ConstantValue;
905
906   case ValID::InlineAsmVal: {    // Inline asm expression
907     const PointerType *PTy = dyn_cast<PointerType>(Ty);
908     const FunctionType *FTy =
909       PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
910     if (!FTy || !InlineAsm::Verify(FTy, D.IAD->Constraints))
911       error("Invalid type for asm constraint string");
912     InlineAsm *IA = InlineAsm::get(FTy, D.IAD->AsmString, D.IAD->Constraints,
913                                    D.IAD->HasSideEffects);
914     D.destroy();   // Free InlineAsmDescriptor.
915     return IA;
916   }
917   default:
918     assert(0 && "Unhandled case");
919     return 0;
920   }   // End of switch
921
922   assert(0 && "Unhandled case");
923   return 0;
924 }
925
926 // getVal - This function is identical to getExistingValue, except that if a
927 // value is not already defined, it "improvises" by creating a placeholder var
928 // that looks and acts just like the requested variable.  When the value is
929 // defined later, all uses of the placeholder variable are replaced with the
930 // real thing.
931 //
932 static Value *getVal(const Type *Ty, const ValID &ID) {
933   if (Ty == Type::LabelTy)
934     error("Cannot use a basic block here");
935
936   // See if the value has already been defined.
937   Value *V = getExistingValue(Ty, ID);
938   if (V) return V;
939
940   if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty))
941     error("Invalid use of a composite type");
942
943   // If we reached here, we referenced either a symbol that we don't know about
944   // or an id number that hasn't been read yet.  We may be referencing something
945   // forward, so just create an entry to be resolved later and get to it...
946   V = new Argument(Ty);
947
948   // Remember where this forward reference came from.  FIXME, shouldn't we try
949   // to recycle these things??
950   CurModule.PlaceHolderInfo.insert(
951     std::make_pair(V, std::make_pair(ID, Upgradelineno)));
952
953   if (inFunctionScope())
954     InsertValue(V, CurFun.LateResolveValues);
955   else
956     InsertValue(V, CurModule.LateResolveValues);
957   return V;
958 }
959
960 /// @brief This just makes any name given to it unique, up to MAX_UINT times.
961 static std::string makeNameUnique(const std::string& Name) {
962   static unsigned UniqueNameCounter = 1;
963   std::string Result(Name);
964   Result += ".upgrd." + llvm::utostr(UniqueNameCounter++);
965   return Result;
966 }
967
968 /// getBBVal - This is used for two purposes:
969 ///  * If isDefinition is true, a new basic block with the specified ID is being
970 ///    defined.
971 ///  * If isDefinition is true, this is a reference to a basic block, which may
972 ///    or may not be a forward reference.
973 ///
974 static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
975   assert(inFunctionScope() && "Can't get basic block at global scope");
976
977   std::string Name;
978   BasicBlock *BB = 0;
979   switch (ID.Type) {
980   default: 
981     error("Illegal label reference " + ID.getName());
982     break;
983   case ValID::NumberVal:                // Is it a numbered definition?
984     if (unsigned(ID.Num) >= CurFun.NumberedBlocks.size())
985       CurFun.NumberedBlocks.resize(ID.Num+1);
986     BB = CurFun.NumberedBlocks[ID.Num];
987     break;
988   case ValID::NameVal:                  // Is it a named definition?
989     Name = ID.Name;
990     if (Value *N = CurFun.CurrentFunction->getValueSymbolTable().lookup(Name)) {
991       if (N->getType() != Type::LabelTy) {
992         // Register names didn't use to conflict with basic block names
993         // because of type planes. Now they all have to be unique. So, we just
994         // rename the register and treat this name as if no basic block
995         // had been found.
996         RenameMapKey Key = makeRenameMapKey(ID.Name, N->getType(), ID.S);
997         N->setName(makeNameUnique(N->getName()));
998         CurModule.RenameMap[Key] = N->getName();
999         BB = 0;
1000       } else {
1001         BB = cast<BasicBlock>(N);
1002       }
1003     }
1004     break;
1005   }
1006
1007   // See if the block has already been defined.
1008   if (BB) {
1009     // If this is the definition of the block, make sure the existing value was
1010     // just a forward reference.  If it was a forward reference, there will be
1011     // an entry for it in the PlaceHolderInfo map.
1012     if (isDefinition && !CurFun.BBForwardRefs.erase(BB))
1013       // The existing value was a definition, not a forward reference.
1014       error("Redefinition of label " + ID.getName());
1015
1016     ID.destroy();                       // Free strdup'd memory.
1017     return BB;
1018   }
1019
1020   // Otherwise this block has not been seen before.
1021   BB = new BasicBlock("", CurFun.CurrentFunction);
1022   if (ID.Type == ValID::NameVal) {
1023     BB->setName(ID.Name);
1024   } else {
1025     CurFun.NumberedBlocks[ID.Num] = BB;
1026   }
1027
1028   // If this is not a definition, keep track of it so we can use it as a forward
1029   // reference.
1030   if (!isDefinition) {
1031     // Remember where this forward reference came from.
1032     CurFun.BBForwardRefs[BB] = std::make_pair(ID, Upgradelineno);
1033   } else {
1034     // The forward declaration could have been inserted anywhere in the
1035     // function: insert it into the correct place now.
1036     CurFun.CurrentFunction->getBasicBlockList().remove(BB);
1037     CurFun.CurrentFunction->getBasicBlockList().push_back(BB);
1038   }
1039   ID.destroy();
1040   return BB;
1041 }
1042
1043
1044 //===----------------------------------------------------------------------===//
1045 //              Code to handle forward references in instructions
1046 //===----------------------------------------------------------------------===//
1047 //
1048 // This code handles the late binding needed with statements that reference
1049 // values not defined yet... for example, a forward branch, or the PHI node for
1050 // a loop body.
1051 //
1052 // This keeps a table (CurFun.LateResolveValues) of all such forward references
1053 // and back patchs after we are done.
1054 //
1055
1056 // ResolveDefinitions - If we could not resolve some defs at parsing
1057 // time (forward branches, phi functions for loops, etc...) resolve the
1058 // defs now...
1059 //
1060 static void 
1061 ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
1062                    std::map<const Type*,ValueList> *FutureLateResolvers) {
1063
1064   // Loop over LateResolveDefs fixing up stuff that couldn't be resolved
1065   for (std::map<const Type*,ValueList>::iterator LRI = LateResolvers.begin(),
1066          E = LateResolvers.end(); LRI != E; ++LRI) {
1067     const Type* Ty = LRI->first;
1068     ValueList &List = LRI->second;
1069     while (!List.empty()) {
1070       Value *V = List.back();
1071       List.pop_back();
1072
1073       std::map<Value*, std::pair<ValID, int> >::iterator PHI =
1074         CurModule.PlaceHolderInfo.find(V);
1075       assert(PHI != CurModule.PlaceHolderInfo.end() && "Placeholder error");
1076
1077       ValID &DID = PHI->second.first;
1078
1079       Value *TheRealValue = getExistingValue(Ty, DID);
1080       if (TheRealValue) {
1081         V->replaceAllUsesWith(TheRealValue);
1082         delete V;
1083         CurModule.PlaceHolderInfo.erase(PHI);
1084       } else if (FutureLateResolvers) {
1085         // Functions have their unresolved items forwarded to the module late
1086         // resolver table
1087         InsertValue(V, *FutureLateResolvers);
1088       } else {
1089         if (DID.Type == ValID::NameVal) {
1090           error("Reference to an invalid definition: '" + DID.getName() +
1091                 "' of type '" + V->getType()->getDescription() + "'",
1092                 PHI->second.second);
1093             return;
1094         } else {
1095           error("Reference to an invalid definition: #" +
1096                 itostr(DID.Num) + " of type '" + 
1097                 V->getType()->getDescription() + "'", PHI->second.second);
1098           return;
1099         }
1100       }
1101     }
1102   }
1103
1104   LateResolvers.clear();
1105 }
1106
1107 /// This function is used for type resolution and upref handling. When a type
1108 /// becomes concrete, this function is called to adjust the signedness for the
1109 /// concrete type.
1110 static void ResolveTypeSign(const Type* oldTy, const Signedness &Sign) {
1111   std::string TyName = CurModule.CurrentModule->getTypeName(oldTy);
1112   if (!TyName.empty())
1113     CurModule.NamedTypeSigns[TyName] = Sign;
1114 }
1115
1116 /// ResolveTypeTo - A brand new type was just declared.  This means that (if
1117 /// name is not null) things referencing Name can be resolved.  Otherwise, 
1118 /// things refering to the number can be resolved.  Do this now.
1119 static void ResolveTypeTo(char *Name, const Type *ToTy, const Signedness& Sign){
1120   ValID D;
1121   if (Name)
1122     D = ValID::create(Name);
1123   else      
1124     D = ValID::create((int)CurModule.Types.size());
1125   D.S.copy(Sign);
1126
1127   CurModule.NamedTypeSigns[Name] = Sign;
1128
1129   std::map<ValID, PATypeHolder>::iterator I =
1130     CurModule.LateResolveTypes.find(D);
1131   if (I != CurModule.LateResolveTypes.end()) {
1132     const Type *OldTy = I->second.get();
1133     ((DerivedType*)OldTy)->refineAbstractTypeTo(ToTy);
1134     CurModule.LateResolveTypes.erase(I);
1135   }
1136 }
1137
1138 /// This is the implementation portion of TypeHasInteger. It traverses the
1139 /// type given, avoiding recursive types, and returns true as soon as it finds
1140 /// an integer type. If no integer type is found, it returns false.
1141 static bool TypeHasIntegerI(const Type *Ty, std::vector<const Type*> Stack) {
1142   // Handle some easy cases
1143   if (Ty->isPrimitiveType() || (Ty->getTypeID() == Type::OpaqueTyID))
1144     return false;
1145   if (Ty->isInteger())
1146     return true;
1147   if (const SequentialType *STy = dyn_cast<SequentialType>(Ty))
1148     return STy->getElementType()->isInteger();
1149
1150   // Avoid type structure recursion
1151   for (std::vector<const Type*>::iterator I = Stack.begin(), E = Stack.end();
1152        I != E; ++I)
1153     if (Ty == *I)
1154       return false;
1155
1156   // Push us on the type stack
1157   Stack.push_back(Ty);
1158
1159   if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
1160     if (TypeHasIntegerI(FTy->getReturnType(), Stack)) 
1161       return true;
1162     FunctionType::param_iterator I = FTy->param_begin();
1163     FunctionType::param_iterator E = FTy->param_end();
1164     for (; I != E; ++I)
1165       if (TypeHasIntegerI(*I, Stack))
1166         return true;
1167     return false;
1168   } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
1169     StructType::element_iterator I = STy->element_begin();
1170     StructType::element_iterator E = STy->element_end();
1171     for (; I != E; ++I) {
1172       if (TypeHasIntegerI(*I, Stack))
1173         return true;
1174     }
1175     return false;
1176   }
1177   // There shouldn't be anything else, but its definitely not integer
1178   assert(0 && "What type is this?");
1179   return false;
1180 }
1181
1182 /// This is the interface to TypeHasIntegerI. It just provides the type stack,
1183 /// to avoid recursion, and then calls TypeHasIntegerI.
1184 static inline bool TypeHasInteger(const Type *Ty) {
1185   std::vector<const Type*> TyStack;
1186   return TypeHasIntegerI(Ty, TyStack);
1187 }
1188
1189 // setValueName - Set the specified value to the name given.  The name may be
1190 // null potentially, in which case this is a noop.  The string passed in is
1191 // assumed to be a malloc'd string buffer, and is free'd by this function.
1192 //
1193 static void setValueName(const ValueInfo &V, char *NameStr) {
1194   if (NameStr) {
1195     std::string Name(NameStr);      // Copy string
1196     free(NameStr);                  // Free old string
1197
1198     if (V.V->getType() == Type::VoidTy) {
1199       error("Can't assign name '" + Name + "' to value with void type");
1200       return;
1201     }
1202
1203     assert(inFunctionScope() && "Must be in function scope");
1204
1205     // Search the function's symbol table for an existing value of this name
1206     ValueSymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
1207     Value* Existing = ST.lookup(Name);
1208     if (Existing) {
1209       // An existing value of the same name was found. This might have happened
1210       // because of the integer type planes collapsing in LLVM 2.0. 
1211       if (Existing->getType() == V.V->getType() &&
1212           !TypeHasInteger(Existing->getType())) {
1213         // If the type does not contain any integers in them then this can't be
1214         // a type plane collapsing issue. It truly is a redefinition and we 
1215         // should error out as the assembly is invalid.
1216         error("Redefinition of value named '" + Name + "' of type '" +
1217               V.V->getType()->getDescription() + "'");
1218         return;
1219       } 
1220       // In LLVM 2.0 we don't allow names to be re-used for any values in a 
1221       // function, regardless of Type. Previously re-use of names was okay as 
1222       // long as they were distinct types. With type planes collapsing because
1223       // of the signedness change and because of PR411, this can no longer be
1224       // supported. We must search the entire symbol table for a conflicting
1225       // name and make the name unique. No warning is needed as this can't 
1226       // cause a problem.
1227       std::string NewName = makeNameUnique(Name);
1228       // We're changing the name but it will probably be used by other 
1229       // instructions as operands later on. Consequently we have to retain
1230       // a mapping of the renaming that we're doing.
1231       RenameMapKey Key = makeRenameMapKey(Name, V.V->getType(), V.S);
1232       CurFun.RenameMap[Key] = NewName;
1233       Name = NewName;
1234     }
1235
1236     // Set the name.
1237     V.V->setName(Name);
1238   }
1239 }
1240
1241 /// ParseGlobalVariable - Handle parsing of a global.  If Initializer is null,
1242 /// this is a declaration, otherwise it is a definition.
1243 static GlobalVariable *
1244 ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
1245                     bool isConstantGlobal, const Type *Ty,
1246                     Constant *Initializer,
1247                     const Signedness &Sign) {
1248   if (isa<FunctionType>(Ty))
1249     error("Cannot declare global vars of function type");
1250
1251   const PointerType *PTy = PointerType::get(Ty);
1252
1253   std::string Name;
1254   if (NameStr) {
1255     Name = NameStr;      // Copy string
1256     free(NameStr);       // Free old string
1257   }
1258
1259   // See if this global value was forward referenced.  If so, recycle the
1260   // object.
1261   ValID ID;
1262   if (!Name.empty()) {
1263     ID = ValID::create((char*)Name.c_str());
1264   } else {
1265     ID = ValID::create((int)CurModule.Values[PTy].size());
1266   }
1267   ID.S.makeComposite(Sign);
1268
1269   if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) {
1270     // Move the global to the end of the list, from whereever it was
1271     // previously inserted.
1272     GlobalVariable *GV = cast<GlobalVariable>(FWGV);
1273     CurModule.CurrentModule->getGlobalList().remove(GV);
1274     CurModule.CurrentModule->getGlobalList().push_back(GV);
1275     GV->setInitializer(Initializer);
1276     GV->setLinkage(Linkage);
1277     GV->setConstant(isConstantGlobal);
1278     InsertValue(GV, CurModule.Values);
1279     return GV;
1280   }
1281
1282   // If this global has a name, check to see if there is already a definition
1283   // of this global in the module and emit warnings if there are conflicts.
1284   if (!Name.empty()) {
1285     // The global has a name. See if there's an existing one of the same name.
1286     if (CurModule.CurrentModule->getNamedGlobal(Name)) {
1287       // We found an existing global ov the same name. This isn't allowed 
1288       // in LLVM 2.0. Consequently, we must alter the name of the global so it
1289       // can at least compile. This can happen because of type planes 
1290       // There is alread a global of the same name which means there is a
1291       // conflict. Let's see what we can do about it.
1292       std::string NewName(makeNameUnique(Name));
1293       if (Linkage != GlobalValue::InternalLinkage) {
1294         // The linkage of this gval is external so we can't reliably rename 
1295         // it because it could potentially create a linking problem.  
1296         // However, we can't leave the name conflict in the output either or 
1297         // it won't assemble with LLVM 2.0.  So, all we can do is rename 
1298         // this one to something unique and emit a warning about the problem.
1299         warning("Renaming global variable '" + Name + "' to '" + NewName + 
1300                   "' may cause linkage errors");
1301       }
1302
1303       // Put the renaming in the global rename map
1304       RenameMapKey Key = makeRenameMapKey(Name, PointerType::get(Ty), ID.S);
1305       CurModule.RenameMap[Key] = NewName;
1306
1307       // Rename it
1308       Name = NewName;
1309     }
1310   }
1311
1312   // Otherwise there is no existing GV to use, create one now.
1313   GlobalVariable *GV =
1314     new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name,
1315                        CurModule.CurrentModule);
1316   InsertValue(GV, CurModule.Values);
1317   // Remember the sign of this global.
1318   CurModule.NamedValueSigns[Name] = ID.S;
1319   return GV;
1320 }
1321
1322 // setTypeName - Set the specified type to the name given.  The name may be
1323 // null potentially, in which case this is a noop.  The string passed in is
1324 // assumed to be a malloc'd string buffer, and is freed by this function.
1325 //
1326 // This function returns true if the type has already been defined, but is
1327 // allowed to be redefined in the specified context.  If the name is a new name
1328 // for the type plane, it is inserted and false is returned.
1329 static bool setTypeName(const PATypeInfo& TI, char *NameStr) {
1330   assert(!inFunctionScope() && "Can't give types function-local names");
1331   if (NameStr == 0) return false;
1332  
1333   std::string Name(NameStr);      // Copy string
1334   free(NameStr);                  // Free old string
1335
1336   const Type* Ty = TI.PAT->get();
1337
1338   // We don't allow assigning names to void type
1339   if (Ty == Type::VoidTy) {
1340     error("Can't assign name '" + Name + "' to the void type");
1341     return false;
1342   }
1343
1344   // Set the type name, checking for conflicts as we do so.
1345   bool AlreadyExists = CurModule.CurrentModule->addTypeName(Name, Ty);
1346
1347   // Save the sign information for later use 
1348   CurModule.NamedTypeSigns[Name] = TI.S;
1349
1350   if (AlreadyExists) {   // Inserting a name that is already defined???
1351     const Type *Existing = CurModule.CurrentModule->getTypeByName(Name);
1352     assert(Existing && "Conflict but no matching type?");
1353
1354     // There is only one case where this is allowed: when we are refining an
1355     // opaque type.  In this case, Existing will be an opaque type.
1356     if (const OpaqueType *OpTy = dyn_cast<OpaqueType>(Existing)) {
1357       // We ARE replacing an opaque type!
1358       const_cast<OpaqueType*>(OpTy)->refineAbstractTypeTo(Ty);
1359       return true;
1360     }
1361
1362     // Otherwise, this is an attempt to redefine a type. That's okay if
1363     // the redefinition is identical to the original. This will be so if
1364     // Existing and T point to the same Type object. In this one case we
1365     // allow the equivalent redefinition.
1366     if (Existing == Ty) return true;  // Yes, it's equal.
1367
1368     // Any other kind of (non-equivalent) redefinition is an error.
1369     error("Redefinition of type named '" + Name + "' in the '" +
1370           Ty->getDescription() + "' type plane");
1371   }
1372
1373   return false;
1374 }
1375
1376 //===----------------------------------------------------------------------===//
1377 // Code for handling upreferences in type names...
1378 //
1379
1380 // TypeContains - Returns true if Ty directly contains E in it.
1381 //
1382 static bool TypeContains(const Type *Ty, const Type *E) {
1383   return std::find(Ty->subtype_begin(), Ty->subtype_end(),
1384                    E) != Ty->subtype_end();
1385 }
1386
1387 namespace {
1388   struct UpRefRecord {
1389     // NestingLevel - The number of nesting levels that need to be popped before
1390     // this type is resolved.
1391     unsigned NestingLevel;
1392
1393     // LastContainedTy - This is the type at the current binding level for the
1394     // type.  Every time we reduce the nesting level, this gets updated.
1395     const Type *LastContainedTy;
1396
1397     // UpRefTy - This is the actual opaque type that the upreference is
1398     // represented with.
1399     OpaqueType *UpRefTy;
1400
1401     UpRefRecord(unsigned NL, OpaqueType *URTy)
1402       : NestingLevel(NL), LastContainedTy(URTy), UpRefTy(URTy) { }
1403   };
1404 }
1405
1406 // UpRefs - A list of the outstanding upreferences that need to be resolved.
1407 static std::vector<UpRefRecord> UpRefs;
1408
1409 /// HandleUpRefs - Every time we finish a new layer of types, this function is
1410 /// called.  It loops through the UpRefs vector, which is a list of the
1411 /// currently active types.  For each type, if the up reference is contained in
1412 /// the newly completed type, we decrement the level count.  When the level
1413 /// count reaches zero, the upreferenced type is the type that is passed in:
1414 /// thus we can complete the cycle.
1415 ///
1416 static PATypeHolder HandleUpRefs(const Type *ty, const Signedness& Sign) {
1417   // If Ty isn't abstract, or if there are no up-references in it, then there is
1418   // nothing to resolve here.
1419   if (!ty->isAbstract() || UpRefs.empty()) return ty;
1420   
1421   PATypeHolder Ty(ty);
1422   UR_OUT("Type '" << Ty->getDescription() <<
1423          "' newly formed.  Resolving upreferences.\n" <<
1424          UpRefs.size() << " upreferences active!\n");
1425
1426   // If we find any resolvable upreferences (i.e., those whose NestingLevel goes
1427   // to zero), we resolve them all together before we resolve them to Ty.  At
1428   // the end of the loop, if there is anything to resolve to Ty, it will be in
1429   // this variable.
1430   OpaqueType *TypeToResolve = 0;
1431
1432   unsigned i = 0;
1433   for (; i != UpRefs.size(); ++i) {
1434     UR_OUT("  UR#" << i << " - TypeContains(" << Ty->getDescription() << ", "
1435            << UpRefs[i].UpRefTy->getDescription() << ") = "
1436            << (TypeContains(Ty, UpRefs[i].UpRefTy) ? "true" : "false") << "\n");
1437     if (TypeContains(Ty, UpRefs[i].LastContainedTy)) {
1438       // Decrement level of upreference
1439       unsigned Level = --UpRefs[i].NestingLevel;
1440       UpRefs[i].LastContainedTy = Ty;
1441       UR_OUT("  Uplevel Ref Level = " << Level << "\n");
1442       if (Level == 0) {                     // Upreference should be resolved!
1443         if (!TypeToResolve) {
1444           TypeToResolve = UpRefs[i].UpRefTy;
1445         } else {
1446           UR_OUT("  * Resolving upreference for "
1447                  << UpRefs[i].UpRefTy->getDescription() << "\n";
1448           std::string OldName = UpRefs[i].UpRefTy->getDescription());
1449           ResolveTypeSign(UpRefs[i].UpRefTy, Sign);
1450           UpRefs[i].UpRefTy->refineAbstractTypeTo(TypeToResolve);
1451           UR_OUT("  * Type '" << OldName << "' refined upreference to: "
1452                  << (const void*)Ty << ", " << Ty->getDescription() << "\n");
1453         }
1454         UpRefs.erase(UpRefs.begin()+i);     // Remove from upreference list...
1455         --i;                                // Do not skip the next element...
1456       }
1457     }
1458   }
1459
1460   if (TypeToResolve) {
1461     UR_OUT("  * Resolving upreference for "
1462            << UpRefs[i].UpRefTy->getDescription() << "\n";
1463            std::string OldName = TypeToResolve->getDescription());
1464     ResolveTypeSign(TypeToResolve, Sign);
1465     TypeToResolve->refineAbstractTypeTo(Ty);
1466   }
1467
1468   return Ty;
1469 }
1470
1471 bool Signedness::operator<(const Signedness &that) const {
1472   if (isNamed()) {
1473     if (that.isNamed()) 
1474       return *(this->name) < *(that.name);
1475     else
1476       return CurModule.NamedTypeSigns[*name] < that;
1477   } else if (that.isNamed()) {
1478     return *this < CurModule.NamedTypeSigns[*that.name];
1479   }
1480
1481   if (isComposite() && that.isComposite()) {
1482     if (sv->size() == that.sv->size()) {
1483       SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1484       SignVector::const_iterator thatI = that.sv->begin(), 
1485                                  thatE = that.sv->end();
1486       for (; thisI != thisE; ++thisI, ++thatI) {
1487         if (*thisI < *thatI)
1488           return true;
1489         else if (!(*thisI == *thatI))
1490           return false;
1491       }
1492       return false;
1493     }
1494     return sv->size() < that.sv->size();
1495   }  
1496   return kind < that.kind;
1497 }
1498
1499 bool Signedness::operator==(const Signedness &that) const {
1500   if (isNamed())
1501     if (that.isNamed())
1502       return *(this->name) == *(that.name);
1503     else 
1504       return CurModule.NamedTypeSigns[*(this->name)] == that;
1505   else if (that.isNamed())
1506     return *this == CurModule.NamedTypeSigns[*(that.name)];
1507   if (isComposite() && that.isComposite()) {
1508     if (sv->size() == that.sv->size()) {
1509       SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1510       SignVector::const_iterator thatI = that.sv->begin(), 
1511                                  thatE = that.sv->end();
1512       for (; thisI != thisE; ++thisI, ++thatI) {
1513         if (!(*thisI == *thatI))
1514           return false;
1515       }
1516       return true;
1517     }
1518     return false;
1519   }
1520   return kind == that.kind;
1521 }
1522
1523 void Signedness::copy(const Signedness &that) {
1524   if (that.isNamed()) {
1525     kind = Named;
1526     name = new std::string(*that.name);
1527   } else if (that.isComposite()) {
1528     kind = Composite;
1529     sv = new SignVector();
1530     *sv = *that.sv;
1531   } else {
1532     kind = that.kind;
1533     sv = 0;
1534   }
1535 }
1536
1537 void Signedness::destroy() {
1538   if (isNamed()) {
1539     delete name;
1540   } else if (isComposite()) {
1541     delete sv;
1542   } 
1543 }
1544
1545 void Signedness::dump() const {
1546   if (isComposite()) {
1547     if (sv->size() == 1) {
1548       (*sv)[0].dump();
1549       std::cerr << "*";
1550     } else {
1551       std::cerr << "{ " ;
1552       for (unsigned i = 0; i < sv->size(); ++i) {
1553         if (i != 0)
1554           std::cerr << ", ";
1555         (*sv)[i].dump();
1556       }
1557       std::cerr << "} " ;
1558     }
1559   } else if (isNamed()) {
1560     std::cerr << *name;
1561   } else if (isSigned()) {
1562     std::cerr << "S";
1563   } else if (isUnsigned()) {
1564     std::cerr << "U";
1565   } else
1566     std::cerr << ".";
1567 }
1568
1569 static inline Instruction::TermOps 
1570 getTermOp(TermOps op) {
1571   switch (op) {
1572     default           : assert(0 && "Invalid OldTermOp");
1573     case RetOp        : return Instruction::Ret;
1574     case BrOp         : return Instruction::Br;
1575     case SwitchOp     : return Instruction::Switch;
1576     case InvokeOp     : return Instruction::Invoke;
1577     case UnwindOp     : return Instruction::Unwind;
1578     case UnreachableOp: return Instruction::Unreachable;
1579   }
1580 }
1581
1582 static inline Instruction::BinaryOps 
1583 getBinaryOp(BinaryOps op, const Type *Ty, const Signedness& Sign) {
1584   switch (op) {
1585     default     : assert(0 && "Invalid OldBinaryOps");
1586     case SetEQ  : 
1587     case SetNE  : 
1588     case SetLE  :
1589     case SetGE  :
1590     case SetLT  :
1591     case SetGT  : assert(0 && "Should use getCompareOp");
1592     case AddOp  : return Instruction::Add;
1593     case SubOp  : return Instruction::Sub;
1594     case MulOp  : return Instruction::Mul;
1595     case DivOp  : {
1596       // This is an obsolete instruction so we must upgrade it based on the
1597       // types of its operands.
1598       bool isFP = Ty->isFloatingPoint();
1599       if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
1600         // If its a vector type we want to use the element type
1601         isFP = PTy->getElementType()->isFloatingPoint();
1602       if (isFP)
1603         return Instruction::FDiv;
1604       else if (Sign.isSigned())
1605         return Instruction::SDiv;
1606       return Instruction::UDiv;
1607     }
1608     case UDivOp : return Instruction::UDiv;
1609     case SDivOp : return Instruction::SDiv;
1610     case FDivOp : return Instruction::FDiv;
1611     case RemOp  : {
1612       // This is an obsolete instruction so we must upgrade it based on the
1613       // types of its operands.
1614       bool isFP = Ty->isFloatingPoint();
1615       if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
1616         // If its a vector type we want to use the element type
1617         isFP = PTy->getElementType()->isFloatingPoint();
1618       // Select correct opcode
1619       if (isFP)
1620         return Instruction::FRem;
1621       else if (Sign.isSigned())
1622         return Instruction::SRem;
1623       return Instruction::URem;
1624     }
1625     case URemOp : return Instruction::URem;
1626     case SRemOp : return Instruction::SRem;
1627     case FRemOp : return Instruction::FRem;
1628     case LShrOp : return Instruction::LShr;
1629     case AShrOp : return Instruction::AShr;
1630     case ShlOp  : return Instruction::Shl;
1631     case ShrOp  : 
1632       if (Sign.isSigned())
1633         return Instruction::AShr;
1634       return Instruction::LShr;
1635     case AndOp  : return Instruction::And;
1636     case OrOp   : return Instruction::Or;
1637     case XorOp  : return Instruction::Xor;
1638   }
1639 }
1640
1641 static inline Instruction::OtherOps 
1642 getCompareOp(BinaryOps op, unsigned short &predicate, const Type* &Ty,
1643              const Signedness &Sign) {
1644   bool isSigned = Sign.isSigned();
1645   bool isFP = Ty->isFloatingPoint();
1646   switch (op) {
1647     default     : assert(0 && "Invalid OldSetCC");
1648     case SetEQ  : 
1649       if (isFP) {
1650         predicate = FCmpInst::FCMP_OEQ;
1651         return Instruction::FCmp;
1652       } else {
1653         predicate = ICmpInst::ICMP_EQ;
1654         return Instruction::ICmp;
1655       }
1656     case SetNE  : 
1657       if (isFP) {
1658         predicate = FCmpInst::FCMP_UNE;
1659         return Instruction::FCmp;
1660       } else {
1661         predicate = ICmpInst::ICMP_NE;
1662         return Instruction::ICmp;
1663       }
1664     case SetLE  : 
1665       if (isFP) {
1666         predicate = FCmpInst::FCMP_OLE;
1667         return Instruction::FCmp;
1668       } else {
1669         if (isSigned)
1670           predicate = ICmpInst::ICMP_SLE;
1671         else
1672           predicate = ICmpInst::ICMP_ULE;
1673         return Instruction::ICmp;
1674       }
1675     case SetGE  : 
1676       if (isFP) {
1677         predicate = FCmpInst::FCMP_OGE;
1678         return Instruction::FCmp;
1679       } else {
1680         if (isSigned)
1681           predicate = ICmpInst::ICMP_SGE;
1682         else
1683           predicate = ICmpInst::ICMP_UGE;
1684         return Instruction::ICmp;
1685       }
1686     case SetLT  : 
1687       if (isFP) {
1688         predicate = FCmpInst::FCMP_OLT;
1689         return Instruction::FCmp;
1690       } else {
1691         if (isSigned)
1692           predicate = ICmpInst::ICMP_SLT;
1693         else
1694           predicate = ICmpInst::ICMP_ULT;
1695         return Instruction::ICmp;
1696       }
1697     case SetGT  : 
1698       if (isFP) {
1699         predicate = FCmpInst::FCMP_OGT;
1700         return Instruction::FCmp;
1701       } else {
1702         if (isSigned)
1703           predicate = ICmpInst::ICMP_SGT;
1704         else
1705           predicate = ICmpInst::ICMP_UGT;
1706         return Instruction::ICmp;
1707       }
1708   }
1709 }
1710
1711 static inline Instruction::MemoryOps getMemoryOp(MemoryOps op) {
1712   switch (op) {
1713     default              : assert(0 && "Invalid OldMemoryOps");
1714     case MallocOp        : return Instruction::Malloc;
1715     case FreeOp          : return Instruction::Free;
1716     case AllocaOp        : return Instruction::Alloca;
1717     case LoadOp          : return Instruction::Load;
1718     case StoreOp         : return Instruction::Store;
1719     case GetElementPtrOp : return Instruction::GetElementPtr;
1720   }
1721 }
1722
1723 static inline Instruction::OtherOps 
1724 getOtherOp(OtherOps op, const Signedness &Sign) {
1725   switch (op) {
1726     default               : assert(0 && "Invalid OldOtherOps");
1727     case PHIOp            : return Instruction::PHI;
1728     case CallOp           : return Instruction::Call;
1729     case SelectOp         : return Instruction::Select;
1730     case UserOp1          : return Instruction::UserOp1;
1731     case UserOp2          : return Instruction::UserOp2;
1732     case VAArg            : return Instruction::VAArg;
1733     case ExtractElementOp : return Instruction::ExtractElement;
1734     case InsertElementOp  : return Instruction::InsertElement;
1735     case ShuffleVectorOp  : return Instruction::ShuffleVector;
1736     case ICmpOp           : return Instruction::ICmp;
1737     case FCmpOp           : return Instruction::FCmp;
1738   };
1739 }
1740
1741 static inline Value*
1742 getCast(CastOps op, Value *Src, const Signedness &SrcSign, const Type *DstTy, 
1743         const Signedness &DstSign, bool ForceInstruction = false) {
1744   Instruction::CastOps Opcode;
1745   const Type* SrcTy = Src->getType();
1746   if (op == CastOp) {
1747     if (SrcTy->isFloatingPoint() && isa<PointerType>(DstTy)) {
1748       // fp -> ptr cast is no longer supported but we must upgrade this
1749       // by doing a double cast: fp -> int -> ptr
1750       SrcTy = Type::Int64Ty;
1751       Opcode = Instruction::IntToPtr;
1752       if (isa<Constant>(Src)) {
1753         Src = ConstantExpr::getCast(Instruction::FPToUI, 
1754                                      cast<Constant>(Src), SrcTy);
1755       } else {
1756         std::string NewName(makeNameUnique(Src->getName()));
1757         Src = new FPToUIInst(Src, SrcTy, NewName, CurBB);
1758       }
1759     } else if (isa<IntegerType>(DstTy) &&
1760                cast<IntegerType>(DstTy)->getBitWidth() == 1) {
1761       // cast type %x to bool was previously defined as setne type %x, null
1762       // The cast semantic is now to truncate, not compare so we must retain
1763       // the original intent by replacing the cast with a setne
1764       Constant* Null = Constant::getNullValue(SrcTy);
1765       Instruction::OtherOps Opcode = Instruction::ICmp;
1766       unsigned short predicate = ICmpInst::ICMP_NE;
1767       if (SrcTy->isFloatingPoint()) {
1768         Opcode = Instruction::FCmp;
1769         predicate = FCmpInst::FCMP_ONE;
1770       } else if (!SrcTy->isInteger() && !isa<PointerType>(SrcTy)) {
1771         error("Invalid cast to bool");
1772       }
1773       if (isa<Constant>(Src) && !ForceInstruction)
1774         return ConstantExpr::getCompare(predicate, cast<Constant>(Src), Null);
1775       else
1776         return CmpInst::create(Opcode, predicate, Src, Null);
1777     }
1778     // Determine the opcode to use by calling CastInst::getCastOpcode
1779     Opcode = 
1780       CastInst::getCastOpcode(Src, SrcSign.isSigned(), DstTy, 
1781                               DstSign.isSigned());
1782
1783   } else switch (op) {
1784     default: assert(0 && "Invalid cast token");
1785     case TruncOp:    Opcode = Instruction::Trunc; break;
1786     case ZExtOp:     Opcode = Instruction::ZExt; break;
1787     case SExtOp:     Opcode = Instruction::SExt; break;
1788     case FPTruncOp:  Opcode = Instruction::FPTrunc; break;
1789     case FPExtOp:    Opcode = Instruction::FPExt; break;
1790     case FPToUIOp:   Opcode = Instruction::FPToUI; break;
1791     case FPToSIOp:   Opcode = Instruction::FPToSI; break;
1792     case UIToFPOp:   Opcode = Instruction::UIToFP; break;
1793     case SIToFPOp:   Opcode = Instruction::SIToFP; break;
1794     case PtrToIntOp: Opcode = Instruction::PtrToInt; break;
1795     case IntToPtrOp: Opcode = Instruction::IntToPtr; break;
1796     case BitCastOp:  Opcode = Instruction::BitCast; break;
1797   }
1798
1799   if (isa<Constant>(Src) && !ForceInstruction)
1800     return ConstantExpr::getCast(Opcode, cast<Constant>(Src), DstTy);
1801   return CastInst::create(Opcode, Src, DstTy);
1802 }
1803
1804 static Instruction *
1805 upgradeIntrinsicCall(const Type* RetTy, const ValID &ID, 
1806                      std::vector<Value*>& Args) {
1807
1808   std::string Name = ID.Type == ValID::NameVal ? ID.Name : "";
1809   if (Name == "llvm.isunordered.f32" || Name == "llvm.isunordered.f64") {
1810     if (Args.size() != 2)
1811       error("Invalid prototype for " + Name + " prototype");
1812     return new FCmpInst(FCmpInst::FCMP_UNO, Args[0], Args[1]);
1813   } else {
1814     const Type* PtrTy = PointerType::get(Type::Int8Ty);
1815     std::vector<const Type*> Params;
1816     if (Name == "llvm.va_start" || Name == "llvm.va_end") {
1817       if (Args.size() != 1)
1818         error("Invalid prototype for " + Name + " prototype");
1819       Params.push_back(PtrTy);
1820       const FunctionType *FTy = FunctionType::get(Type::VoidTy, Params, false);
1821       const PointerType *PFTy = PointerType::get(FTy);
1822       Value* Func = getVal(PFTy, ID);
1823       Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
1824       return new CallInst(Func, &Args[0], Args.size());
1825     } else if (Name == "llvm.va_copy") {
1826       if (Args.size() != 2)
1827         error("Invalid prototype for " + Name + " prototype");
1828       Params.push_back(PtrTy);
1829       Params.push_back(PtrTy);
1830       const FunctionType *FTy = FunctionType::get(Type::VoidTy, Params, false);
1831       const PointerType *PFTy = PointerType::get(FTy);
1832       Value* Func = getVal(PFTy, ID);
1833       std::string InstName0(makeNameUnique("va0"));
1834       std::string InstName1(makeNameUnique("va1"));
1835       Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
1836       Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
1837       return new CallInst(Func, &Args[0], Args.size());
1838     }
1839   }
1840   return 0;
1841 }
1842
1843 const Type* upgradeGEPIndices(const Type* PTy, 
1844                        std::vector<ValueInfo> *Indices, 
1845                        std::vector<Value*>    &VIndices, 
1846                        std::vector<Constant*> *CIndices = 0) {
1847   // Traverse the indices with a gep_type_iterator so we can build the list
1848   // of constant and value indices for use later. Also perform upgrades
1849   VIndices.clear();
1850   if (CIndices) CIndices->clear();
1851   for (unsigned i = 0, e = Indices->size(); i != e; ++i)
1852     VIndices.push_back((*Indices)[i].V);
1853   generic_gep_type_iterator<std::vector<Value*>::iterator>
1854     GTI = gep_type_begin(PTy, VIndices.begin(),  VIndices.end()),
1855     GTE = gep_type_end(PTy,  VIndices.begin(),  VIndices.end());
1856   for (unsigned i = 0, e = Indices->size(); i != e && GTI != GTE; ++i, ++GTI) {
1857     Value *Index = VIndices[i];
1858     if (CIndices && !isa<Constant>(Index))
1859       error("Indices to constant getelementptr must be constants");
1860     // LLVM 1.2 and earlier used ubyte struct indices.  Convert any ubyte 
1861     // struct indices to i32 struct indices with ZExt for compatibility.
1862     else if (isa<StructType>(*GTI)) {        // Only change struct indices
1863       if (ConstantInt *CUI = dyn_cast<ConstantInt>(Index))
1864         if (CUI->getType()->getBitWidth() == 8)
1865           Index = 
1866             ConstantExpr::getCast(Instruction::ZExt, CUI, Type::Int32Ty);
1867     } else {
1868       // Make sure that unsigned SequentialType indices are zext'd to 
1869       // 64-bits if they were smaller than that because LLVM 2.0 will sext 
1870       // all indices for SequentialType elements. We must retain the same 
1871       // semantic (zext) for unsigned types.
1872       if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType()))
1873         if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
1874           if (CIndices)
1875             Index = ConstantExpr::getCast(Instruction::ZExt, 
1876               cast<Constant>(Index), Type::Int64Ty);
1877           else
1878             Index = CastInst::create(Instruction::ZExt, Index, Type::Int64Ty,
1879               makeNameUnique("gep"), CurBB);
1880           VIndices[i] = Index;
1881         }
1882     }
1883     // Add to the CIndices list, if requested.
1884     if (CIndices)
1885       CIndices->push_back(cast<Constant>(Index));
1886   }
1887
1888   const Type *IdxTy =
1889     GetElementPtrInst::getIndexedType(PTy, &VIndices[0], VIndices.size(), true);
1890     if (!IdxTy)
1891       error("Index list invalid for constant getelementptr");
1892   return IdxTy;
1893 }
1894
1895 unsigned upgradeCallingConv(unsigned CC) {
1896   switch (CC) {
1897     case OldCallingConv::C           : return CallingConv::C;
1898     case OldCallingConv::CSRet       : return CallingConv::C;
1899     case OldCallingConv::Fast        : return CallingConv::Fast;
1900     case OldCallingConv::Cold        : return CallingConv::Cold;
1901     case OldCallingConv::X86_StdCall : return CallingConv::X86_StdCall;
1902     case OldCallingConv::X86_FastCall: return CallingConv::X86_FastCall;
1903     default:
1904       return CC;
1905   }
1906 }
1907
1908 Module* UpgradeAssembly(const std::string &infile, std::istream& in, 
1909                               bool debug, bool addAttrs)
1910 {
1911   Upgradelineno = 1; 
1912   CurFilename = infile;
1913   LexInput = &in;
1914   yydebug = debug;
1915   AddAttributes = addAttrs;
1916   ObsoleteVarArgs = false;
1917   NewVarArgs = false;
1918
1919   CurModule.CurrentModule = new Module(CurFilename);
1920
1921   // Check to make sure the parser succeeded
1922   if (yyparse()) {
1923     if (ParserResult)
1924       delete ParserResult;
1925     std::cerr << "llvm-upgrade: parse failed.\n";
1926     return 0;
1927   }
1928
1929   // Check to make sure that parsing produced a result
1930   if (!ParserResult) {
1931     std::cerr << "llvm-upgrade: no parse result.\n";
1932     return 0;
1933   }
1934
1935   // Reset ParserResult variable while saving its value for the result.
1936   Module *Result = ParserResult;
1937   ParserResult = 0;
1938
1939   //Not all functions use vaarg, so make a second check for ObsoleteVarArgs
1940   {
1941     Function* F;
1942     if ((F = Result->getFunction("llvm.va_start"))
1943         && F->getFunctionType()->getNumParams() == 0)
1944       ObsoleteVarArgs = true;
1945     if((F = Result->getFunction("llvm.va_copy"))
1946        && F->getFunctionType()->getNumParams() == 1)
1947       ObsoleteVarArgs = true;
1948   }
1949
1950   if (ObsoleteVarArgs && NewVarArgs) {
1951     error("This file is corrupt: it uses both new and old style varargs");
1952     return 0;
1953   }
1954
1955   if(ObsoleteVarArgs) {
1956     if(Function* F = Result->getFunction("llvm.va_start")) {
1957       if (F->arg_size() != 0) {
1958         error("Obsolete va_start takes 0 argument");
1959         return 0;
1960       }
1961       
1962       //foo = va_start()
1963       // ->
1964       //bar = alloca typeof(foo)
1965       //va_start(bar)
1966       //foo = load bar
1967
1968       const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1969       const Type* ArgTy = F->getFunctionType()->getReturnType();
1970       const Type* ArgTyPtr = PointerType::get(ArgTy);
1971       Function* NF = cast<Function>(Result->getOrInsertFunction(
1972         "llvm.va_start", RetTy, ArgTyPtr, (Type *)0));
1973
1974       while (!F->use_empty()) {
1975         CallInst* CI = cast<CallInst>(F->use_back());
1976         AllocaInst* bar = new AllocaInst(ArgTy, 0, "vastart.fix.1", CI);
1977         new CallInst(NF, bar, "", CI);
1978         Value* foo = new LoadInst(bar, "vastart.fix.2", CI);
1979         CI->replaceAllUsesWith(foo);
1980         CI->getParent()->getInstList().erase(CI);
1981       }
1982       Result->getFunctionList().erase(F);
1983     }
1984     
1985     if(Function* F = Result->getFunction("llvm.va_end")) {
1986       if(F->arg_size() != 1) {
1987         error("Obsolete va_end takes 1 argument");
1988         return 0;
1989       }
1990
1991       //vaend foo
1992       // ->
1993       //bar = alloca 1 of typeof(foo)
1994       //vaend bar
1995       const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1996       const Type* ArgTy = F->getFunctionType()->getParamType(0);
1997       const Type* ArgTyPtr = PointerType::get(ArgTy);
1998       Function* NF = cast<Function>(Result->getOrInsertFunction(
1999         "llvm.va_end", RetTy, ArgTyPtr, (Type *)0));
2000
2001       while (!F->use_empty()) {
2002         CallInst* CI = cast<CallInst>(F->use_back());
2003         AllocaInst* bar = new AllocaInst(ArgTy, 0, "vaend.fix.1", CI);
2004         new StoreInst(CI->getOperand(1), bar, CI);
2005         new CallInst(NF, bar, "", CI);
2006         CI->getParent()->getInstList().erase(CI);
2007       }
2008       Result->getFunctionList().erase(F);
2009     }
2010
2011     if(Function* F = Result->getFunction("llvm.va_copy")) {
2012       if(F->arg_size() != 1) {
2013         error("Obsolete va_copy takes 1 argument");
2014         return 0;
2015       }
2016       //foo = vacopy(bar)
2017       // ->
2018       //a = alloca 1 of typeof(foo)
2019       //b = alloca 1 of typeof(foo)
2020       //store bar -> b
2021       //vacopy(a, b)
2022       //foo = load a
2023       
2024       const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2025       const Type* ArgTy = F->getFunctionType()->getReturnType();
2026       const Type* ArgTyPtr = PointerType::get(ArgTy);
2027       Function* NF = cast<Function>(Result->getOrInsertFunction(
2028         "llvm.va_copy", RetTy, ArgTyPtr, ArgTyPtr, (Type *)0));
2029
2030       while (!F->use_empty()) {
2031         CallInst* CI = cast<CallInst>(F->use_back());
2032         AllocaInst* a = new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI);
2033         AllocaInst* b = new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI);
2034         new StoreInst(CI->getOperand(1), b, CI);
2035         new CallInst(NF, a, b, "", CI);
2036         Value* foo = new LoadInst(a, "vacopy.fix.3", CI);
2037         CI->replaceAllUsesWith(foo);
2038         CI->getParent()->getInstList().erase(CI);
2039       }
2040       Result->getFunctionList().erase(F);
2041     }
2042   }
2043
2044   return Result;
2045 }
2046
2047 } // end llvm namespace
2048
2049 using namespace llvm;
2050
2051
2052
2053 /* Enabling traces.  */
2054 #ifndef YYDEBUG
2055 # define YYDEBUG 0
2056 #endif
2057
2058 /* Enabling verbose error messages.  */
2059 #ifdef YYERROR_VERBOSE
2060 # undef YYERROR_VERBOSE
2061 # define YYERROR_VERBOSE 1
2062 #else
2063 # define YYERROR_VERBOSE 0
2064 #endif
2065
2066 /* Enabling the token table.  */
2067 #ifndef YYTOKEN_TABLE
2068 # define YYTOKEN_TABLE 0
2069 #endif
2070
2071 #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
2072 #line 1693 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
2073 typedef union YYSTYPE {
2074   llvm::Module                           *ModuleVal;
2075   llvm::Function                         *FunctionVal;
2076   std::pair<llvm::PATypeInfo, char*>     *ArgVal;
2077   llvm::BasicBlock                       *BasicBlockVal;
2078   llvm::TermInstInfo                     TermInstVal;
2079   llvm::InstrInfo                        InstVal;
2080   llvm::ConstInfo                        ConstVal;
2081   llvm::ValueInfo                        ValueVal;
2082   llvm::PATypeInfo                       TypeVal;
2083   llvm::TypeInfo                         PrimType;
2084   llvm::PHIListInfo                      PHIList;
2085   std::list<llvm::PATypeInfo>            *TypeList;
2086   std::vector<llvm::ValueInfo>           *ValueList;
2087   std::vector<llvm::ConstInfo>           *ConstVector;
2088
2089
2090   std::vector<std::pair<llvm::PATypeInfo,char*> > *ArgList;
2091   // Represent the RHS of PHI node
2092   std::vector<std::pair<llvm::Constant*, llvm::BasicBlock*> > *JumpTable;
2093
2094   llvm::GlobalValue::LinkageTypes         Linkage;
2095   int64_t                           SInt64Val;
2096   uint64_t                          UInt64Val;
2097   int                               SIntVal;
2098   unsigned                          UIntVal;
2099   double                            FPVal;
2100   bool                              BoolVal;
2101
2102   char                             *StrVal;   // This memory is strdup'd!
2103   llvm::ValID                       ValIDVal; // strdup'd memory maybe!
2104
2105   llvm::BinaryOps                   BinaryOpVal;
2106   llvm::TermOps                     TermOpVal;
2107   llvm::MemoryOps                   MemOpVal;
2108   llvm::OtherOps                    OtherOpVal;
2109   llvm::CastOps                     CastOpVal;
2110   llvm::ICmpInst::Predicate         IPred;
2111   llvm::FCmpInst::Predicate         FPred;
2112   llvm::Module::Endianness          Endianness;
2113 } YYSTYPE;
2114 /* Line 196 of yacc.c.  */
2115 #line 2116 "UpgradeParser.tab.c"
2116 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
2117 # define YYSTYPE_IS_DECLARED 1
2118 # define YYSTYPE_IS_TRIVIAL 1
2119 #endif
2120
2121
2122
2123 /* Copy the second part of user declarations.  */
2124
2125
2126 /* Line 219 of yacc.c.  */
2127 #line 2128 "UpgradeParser.tab.c"
2128
2129 #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
2130 # define YYSIZE_T __SIZE_TYPE__
2131 #endif
2132 #if ! defined (YYSIZE_T) && defined (size_t)
2133 # define YYSIZE_T size_t
2134 #endif
2135 #if ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus))
2136 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
2137 # define YYSIZE_T size_t
2138 #endif
2139 #if ! defined (YYSIZE_T)
2140 # define YYSIZE_T unsigned int
2141 #endif
2142
2143 #ifndef YY_
2144 # if YYENABLE_NLS
2145 #  if ENABLE_NLS
2146 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
2147 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
2148 #  endif
2149 # endif
2150 # ifndef YY_
2151 #  define YY_(msgid) msgid
2152 # endif
2153 #endif
2154
2155 #if ! defined (yyoverflow) || YYERROR_VERBOSE
2156
2157 /* The parser invokes alloca or malloc; define the necessary symbols.  */
2158
2159 # ifdef YYSTACK_USE_ALLOCA
2160 #  if YYSTACK_USE_ALLOCA
2161 #   ifdef __GNUC__
2162 #    define YYSTACK_ALLOC __builtin_alloca
2163 #   else
2164 #    define YYSTACK_ALLOC alloca
2165 #    if defined (__STDC__) || defined (__cplusplus)
2166 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
2167 #     define YYINCLUDED_STDLIB_H
2168 #    endif
2169 #   endif
2170 #  endif
2171 # endif
2172
2173 # ifdef YYSTACK_ALLOC
2174    /* Pacify GCC's `empty if-body' warning. */
2175 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
2176 #  ifndef YYSTACK_ALLOC_MAXIMUM
2177     /* The OS might guarantee only one guard page at the bottom of the stack,
2178        and a page size can be as small as 4096 bytes.  So we cannot safely
2179        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
2180        to allow for a few compiler-allocated temporary stack slots.  */
2181 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2005 */
2182 #  endif
2183 # else
2184 #  define YYSTACK_ALLOC YYMALLOC
2185 #  define YYSTACK_FREE YYFREE
2186 #  ifndef YYSTACK_ALLOC_MAXIMUM
2187 #   define YYSTACK_ALLOC_MAXIMUM ((YYSIZE_T) -1)
2188 #  endif
2189 #  ifdef __cplusplus
2190 extern "C" {
2191 #  endif
2192 #  ifndef YYMALLOC
2193 #   define YYMALLOC malloc
2194 #   if (! defined (malloc) && ! defined (YYINCLUDED_STDLIB_H) \
2195         && (defined (__STDC__) || defined (__cplusplus)))
2196 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
2197 #   endif
2198 #  endif
2199 #  ifndef YYFREE
2200 #   define YYFREE free
2201 #   if (! defined (free) && ! defined (YYINCLUDED_STDLIB_H) \
2202         && (defined (__STDC__) || defined (__cplusplus)))
2203 void free (void *); /* INFRINGES ON USER NAME SPACE */
2204 #   endif
2205 #  endif
2206 #  ifdef __cplusplus
2207 }
2208 #  endif
2209 # endif
2210 #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
2211
2212
2213 #if (! defined (yyoverflow) \
2214      && (! defined (__cplusplus) \
2215          || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
2216
2217 /* A type that is properly aligned for any stack member.  */
2218 union yyalloc
2219 {
2220   short int yyss;
2221   YYSTYPE yyvs;
2222   };
2223
2224 /* The size of the maximum gap between one aligned stack and the next.  */
2225 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
2226
2227 /* The size of an array large to enough to hold all stacks, each with
2228    N elements.  */
2229 # define YYSTACK_BYTES(N) \
2230      ((N) * (sizeof (short int) + sizeof (YYSTYPE))                     \
2231       + YYSTACK_GAP_MAXIMUM)
2232
2233 /* Copy COUNT objects from FROM to TO.  The source and destination do
2234    not overlap.  */
2235 # ifndef YYCOPY
2236 #  if defined (__GNUC__) && 1 < __GNUC__
2237 #   define YYCOPY(To, From, Count) \
2238       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
2239 #  else
2240 #   define YYCOPY(To, From, Count)              \
2241       do                                        \
2242         {                                       \
2243           YYSIZE_T yyi;                         \
2244           for (yyi = 0; yyi < (Count); yyi++)   \
2245             (To)[yyi] = (From)[yyi];            \
2246         }                                       \
2247       while (0)
2248 #  endif
2249 # endif
2250
2251 /* Relocate STACK from its old location to the new one.  The
2252    local variables YYSIZE and YYSTACKSIZE give the old and new number of
2253    elements in the stack, and YYPTR gives the new location of the
2254    stack.  Advance YYPTR to a properly aligned location for the next
2255    stack.  */
2256 # define YYSTACK_RELOCATE(Stack)                                        \
2257     do                                                                  \
2258       {                                                                 \
2259         YYSIZE_T yynewbytes;                                            \
2260         YYCOPY (&yyptr->Stack, Stack, yysize);                          \
2261         Stack = &yyptr->Stack;                                          \
2262         yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
2263         yyptr += yynewbytes / sizeof (*yyptr);                          \
2264       }                                                                 \
2265     while (0)
2266
2267 #endif
2268
2269 #if defined (__STDC__) || defined (__cplusplus)
2270    typedef signed char yysigned_char;
2271 #else
2272    typedef short int yysigned_char;
2273 #endif
2274
2275 /* YYFINAL -- State number of the termination state. */
2276 #define YYFINAL  4
2277 /* YYLAST -- Last index in YYTABLE.  */
2278 #define YYLAST   1630
2279
2280 /* YYNTOKENS -- Number of terminals. */
2281 #define YYNTOKENS  166
2282 /* YYNNTS -- Number of nonterminals. */
2283 #define YYNNTS  81
2284 /* YYNRULES -- Number of rules. */
2285 #define YYNRULES  310
2286 /* YYNRULES -- Number of states. */
2287 #define YYNSTATES  606
2288
2289 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
2290 #define YYUNDEFTOK  2
2291 #define YYMAXUTOK   406
2292
2293 #define YYTRANSLATE(YYX)                                                \
2294   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
2295
2296 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
2297 static const unsigned char yytranslate[] =
2298 {
2299        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2300        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2301        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2302        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2303      155,   156,   164,     2,   153,     2,     2,     2,     2,     2,
2304        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2305      160,   152,   161,     2,     2,     2,     2,     2,     2,     2,
2306        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2307        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2308        2,   157,   154,   159,     2,     2,     2,     2,     2,   165,
2309        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2310        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2311      158,     2,     2,   162,     2,   163,     2,     2,     2,     2,
2312        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2313        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2314        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2315        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2316        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2317        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2318        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2319        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2320        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2321        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2322        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2323        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
2324        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
2325        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
2326       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
2327       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
2328       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
2329       45,    46,    47,    48,    49,    50,    51,    52,    53,    54,
2330       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
2331       65,    66,    67,    68,    69,    70,    71,    72,    73,    74,
2332       75,    76,    77,    78,    79,    80,    81,    82,    83,    84,
2333       85,    86,    87,    88,    89,    90,    91,    92,    93,    94,
2334       95,    96,    97,    98,    99,   100,   101,   102,   103,   104,
2335      105,   106,   107,   108,   109,   110,   111,   112,   113,   114,
2336      115,   116,   117,   118,   119,   120,   121,   122,   123,   124,
2337      125,   126,   127,   128,   129,   130,   131,   132,   133,   134,
2338      135,   136,   137,   138,   139,   140,   141,   142,   143,   144,
2339      145,   146,   147,   148,   149,   150,   151
2340 };
2341
2342 #if YYDEBUG
2343 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
2344    YYRHS.  */
2345 static const unsigned short int yyprhs[] =
2346 {
2347        0,     0,     3,     5,     7,     9,    11,    13,    15,    17,
2348       19,    21,    23,    25,    27,    29,    31,    33,    35,    37,
2349       39,    41,    43,    45,    47,    49,    51,    53,    55,    57,
2350       59,    61,    63,    65,    67,    69,    71,    73,    75,    77,
2351       79,    81,    83,    85,    87,    89,    91,    93,    95,    97,
2352       99,   101,   103,   105,   107,   109,   111,   113,   115,   117,
2353      119,   121,   123,   125,   127,   129,   131,   133,   135,   137,
2354      139,   141,   143,   145,   147,   149,   151,   153,   155,   157,
2355      159,   161,   164,   165,   167,   169,   171,   173,   175,   177,
2356      179,   180,   181,   183,   185,   187,   189,   191,   193,   196,
2357      197,   200,   201,   205,   208,   209,   211,   212,   216,   218,
2358      221,   223,   225,   227,   229,   231,   233,   235,   237,   239,
2359      241,   243,   245,   247,   249,   251,   253,   255,   257,   259,
2360      261,   264,   269,   275,   281,   285,   288,   294,   299,   302,
2361      304,   308,   310,   314,   316,   317,   322,   326,   330,   335,
2362      340,   344,   351,   357,   360,   363,   366,   369,   372,   375,
2363      378,   381,   384,   387,   394,   400,   409,   416,   423,   430,
2364      438,   446,   453,   460,   469,   478,   482,   484,   486,   488,
2365      490,   493,   496,   501,   504,   506,   511,   514,   519,   520,
2366      528,   529,   537,   538,   546,   547,   555,   559,   564,   565,
2367      567,   569,   571,   575,   579,   583,   587,   591,   595,   597,
2368      598,   600,   602,   604,   605,   608,   612,   614,   616,   620,
2369      622,   623,   632,   634,   636,   637,   642,   644,   646,   649,
2370      650,   652,   654,   655,   656,   662,   663,   665,   667,   669,
2371      671,   673,   675,   677,   679,   681,   685,   687,   693,   695,
2372      697,   699,   701,   704,   707,   710,   714,   717,   718,   720,
2373      722,   724,   727,   730,   734,   744,   754,   763,   777,   779,
2374      781,   788,   794,   797,   804,   812,   814,   818,   820,   821,
2375      824,   826,   832,   838,   844,   851,   858,   861,   866,   871,
2376      878,   883,   888,   893,   898,   905,   912,   915,   923,   925,
2377      928,   929,   931,   932,   936,   943,   947,   954,   957,   962,
2378      969
2379 };
2380
2381 /* YYRHS -- A `-1'-separated list of the rules' RHS. */
2382 static const short int yyrhs[] =
2383 {
2384      200,     0,    -1,     5,    -1,     6,    -1,     3,    -1,     4,
2385       -1,    79,    -1,    80,    -1,    81,    -1,    82,    -1,    83,
2386       -1,    84,    -1,    85,    -1,    86,    -1,    87,    -1,    88,
2387       -1,    89,    -1,    90,    -1,    91,    -1,    92,    -1,    97,
2388       -1,    98,    -1,    99,    -1,   100,    -1,   101,    -1,   102,
2389       -1,   119,    -1,   120,    -1,   121,    -1,   122,    -1,   123,
2390       -1,   124,    -1,   125,    -1,   126,    -1,   127,    -1,   128,
2391       -1,   129,    -1,   130,    -1,   131,    -1,   132,    -1,   133,
2392       -1,   134,    -1,   135,    -1,   136,    -1,   137,    -1,   138,
2393       -1,   125,    -1,   126,    -1,   127,    -1,   128,    -1,    27,
2394       -1,    28,    -1,    93,    -1,    94,    -1,    95,    -1,    96,
2395       -1,   140,    -1,   141,    -1,   142,    -1,   143,    -1,   144,
2396       -1,   145,    -1,   146,    -1,   147,    -1,   148,    -1,   149,
2397       -1,   150,    -1,   151,    -1,   139,    -1,    16,    -1,    14,
2398       -1,    12,    -1,    10,    -1,    17,    -1,    15,    -1,    13,
2399       -1,    11,    -1,   176,    -1,   177,    -1,    18,    -1,    19,
2400       -1,   212,   152,    -1,    -1,    41,    -1,    42,    -1,    43,
2401       -1,    44,    -1,    45,    -1,    46,    -1,    47,    -1,    -1,
2402       -1,    65,    -1,    66,    -1,    67,    -1,    68,    -1,    69,
2403       -1,    70,    -1,    64,     4,    -1,    -1,    57,     4,    -1,
2404       -1,   153,    57,     4,    -1,    34,    24,    -1,    -1,   185,
2405       -1,    -1,   153,   188,   187,    -1,   185,    -1,    57,     4,
2406       -1,   191,    -1,     8,    -1,   193,    -1,     8,    -1,   193,
2407       -1,     9,    -1,    10,    -1,    11,    -1,    12,    -1,    13,
2408       -1,    14,    -1,    15,    -1,    16,    -1,    17,    -1,    18,
2409       -1,    19,    -1,    21,    -1,   192,    -1,    48,    -1,   229,
2410       -1,   154,     4,    -1,   190,   155,   195,   156,    -1,   157,
2411        4,   158,   193,   159,    -1,   160,     4,   158,   193,   161,
2412       -1,   162,   194,   163,    -1,   162,   163,    -1,   160,   162,
2413      194,   163,   161,    -1,   160,   162,   163,   161,    -1,   193,
2414      164,    -1,   193,    -1,   194,   153,   193,    -1,   194,    -1,
2415      194,   153,    37,    -1,    37,    -1,    -1,   191,   157,   198,
2416      159,    -1,   191,   157,   159,    -1,   191,   165,    24,    -1,
2417      191,   160,   198,   161,    -1,   191,   162,   198,   163,    -1,
2418      191,   162,   163,    -1,   191,   160,   162,   198,   163,   161,
2419       -1,   191,   160,   162,   163,   161,    -1,   191,    38,    -1,
2420      191,    39,    -1,   191,   229,    -1,   191,   197,    -1,   191,
2421       26,    -1,   176,   168,    -1,   177,     4,    -1,     9,    27,
2422       -1,     9,    28,    -1,   179,     7,    -1,   175,   155,   196,
2423       36,   191,   156,    -1,   110,   155,   196,   244,   156,    -1,
2424      112,   155,   196,   153,   196,   153,   196,   156,    -1,   169,
2425      155,   196,   153,   196,   156,    -1,   170,   155,   196,   153,
2426      196,   156,    -1,   171,   155,   196,   153,   196,   156,    -1,
2427      103,   172,   155,   196,   153,   196,   156,    -1,   104,   173,
2428      155,   196,   153,   196,   156,    -1,   174,   155,   196,   153,
2429      196,   156,    -1,   114,   155,   196,   153,   196,   156,    -1,
2430      115,   155,   196,   153,   196,   153,   196,   156,    -1,   116,
2431      155,   196,   153,   196,   153,   196,   156,    -1,   198,   153,
2432      196,    -1,   196,    -1,    32,    -1,    33,    -1,   201,    -1,
2433      201,   222,    -1,   201,   224,    -1,   201,    62,    61,   207,
2434       -1,   201,    25,    -1,   202,    -1,   202,   180,    20,   189,
2435       -1,   202,   224,    -1,   202,    62,    61,   207,    -1,    -1,
2436      202,   180,   181,   199,   196,   203,   187,    -1,    -1,   202,
2437      180,    50,   199,   191,   204,   187,    -1,    -1,   202,   180,
2438       45,   199,   191,   205,   187,    -1,    -1,   202,   180,    47,
2439      199,   191,   206,   187,    -1,   202,    51,   209,    -1,   202,
2440       58,   152,   210,    -1,    -1,    24,    -1,    56,    -1,    55,
2441       -1,    53,   152,   208,    -1,    54,   152,     4,    -1,    52,
2442      152,    24,    -1,    71,   152,    24,    -1,   157,   211,   159,
2443       -1,   211,   153,    24,    -1,    24,    -1,    -1,    22,    -1,
2444       24,    -1,   212,    -1,    -1,   191,   213,    -1,   215,   153,
2445      214,    -1,   214,    -1,   215,    -1,   215,   153,    37,    -1,
2446       37,    -1,    -1,   182,   189,   212,   155,   216,   156,   186,
2447      183,    -1,    29,    -1,   162,    -1,    -1,   181,   220,   217,
2448      218,    -1,    30,    -1,   163,    -1,   232,   221,    -1,    -1,
2449       45,    -1,    47,    -1,    -1,    -1,    31,   225,   223,   226,
2450      217,    -1,    -1,    63,    -1,     3,    -1,     4,    -1,     7,
2451       -1,    27,    -1,    28,    -1,    38,    -1,    39,    -1,    26,
2452       -1,   160,   198,   161,    -1,   197,    -1,    61,   227,    24,
2453      153,    24,    -1,   167,    -1,   212,    -1,   229,    -1,   228,
2454       -1,   191,   230,    -1,   232,   233,    -1,   219,   233,    -1,
2455      234,   180,   236,    -1,   234,   238,    -1,    -1,    23,    -1,
2456       77,    -1,    78,    -1,    72,   231,    -1,    72,     8,    -1,
2457       73,    21,   230,    -1,    73,     9,   230,   153,    21,   230,
2458      153,    21,   230,    -1,    74,   178,   230,   153,    21,   230,
2459      157,   237,   159,    -1,    74,   178,   230,   153,    21,   230,
2460      157,   159,    -1,    75,   182,   189,   230,   155,   241,   156,
2461       36,    21,   230,   235,    21,   230,    -1,   235,    -1,    76,
2462       -1,   237,   178,   228,   153,    21,   230,    -1,   178,   228,
2463      153,    21,   230,    -1,   180,   243,    -1,   191,   157,   230,
2464      153,   230,   159,    -1,   239,   153,   157,   230,   153,   230,
2465      159,    -1,   231,    -1,   240,   153,   231,    -1,   240,    -1,
2466       -1,    60,    59,    -1,    59,    -1,   169,   191,   230,   153,
2467      230,    -1,   170,   191,   230,   153,   230,    -1,   171,   191,
2468      230,   153,   230,    -1,   103,   172,   191,   230,   153,   230,
2469       -1,   104,   173,   191,   230,   153,   230,    -1,    49,   231,
2470       -1,   174,   231,   153,   231,    -1,   175,   231,    36,   191,
2471       -1,   112,   231,   153,   231,   153,   231,    -1,   113,   231,
2472      153,   191,    -1,   117,   231,   153,   191,    -1,   118,   231,
2473      153,   191,    -1,   114,   231,   153,   231,    -1,   115,   231,
2474      153,   231,   153,   231,    -1,   116,   231,   153,   231,   153,
2475      231,    -1,   111,   239,    -1,   242,   182,   189,   230,   155,
2476      241,   156,    -1,   246,    -1,   153,   240,    -1,    -1,    35,
2477       -1,    -1,   105,   191,   184,    -1,   105,   191,   153,    15,
2478      230,   184,    -1,   106,   191,   184,    -1,   106,   191,   153,
2479       15,   230,   184,    -1,   107,   231,    -1,   245,   108,   191,
2480      230,    -1,   245,   109,   231,   153,   191,   230,    -1,   110,
2481      191,   230,   244,    -1
2482 };
2483
2484 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
2485 static const unsigned short int yyrline[] =
2486 {
2487        0,  1833,  1833,  1834,  1842,  1843,  1853,  1853,  1853,  1853,
2488     1853,  1853,  1853,  1853,  1853,  1853,  1853,  1857,  1857,  1857,
2489     1861,  1861,  1861,  1861,  1861,  1861,  1865,  1865,  1866,  1866,
2490     1867,  1867,  1868,  1868,  1869,  1869,  1873,  1873,  1874,  1874,
2491     1875,  1875,  1876,  1876,  1877,  1877,  1878,  1878,  1879,  1879,
2492     1880,  1881,  1884,  1884,  1884,  1884,  1888,  1888,  1888,  1888,
2493     1888,  1888,  1888,  1889,  1889,  1889,  1889,  1889,  1889,  1895,
2494     1895,  1895,  1895,  1899,  1899,  1899,  1899,  1903,  1903,  1907,
2495     1907,  1912,  1915,  1920,  1921,  1922,  1923,  1924,  1925,  1926,
2496     1927,  1931,  1932,  1933,  1934,  1935,  1936,  1937,  1938,  1948,
2497     1949,  1957,  1958,  1966,  1975,  1976,  1983,  1984,  1988,  1992,
2498     2008,  2009,  2016,  2017,  2024,  2032,  2032,  2032,  2032,  2032,
2499     2032,  2032,  2033,  2033,  2033,  2033,  2033,  2038,  2042,  2046,
2500     2051,  2060,  2078,  2084,  2097,  2108,  2112,  2125,  2129,  2143,
2501     2147,  2154,  2155,  2161,  2168,  2180,  2210,  2223,  2246,  2274,
2502     2296,  2307,  2329,  2340,  2349,  2354,  2413,  2420,  2428,  2435,
2503     2442,  2446,  2450,  2459,  2474,  2487,  2496,  2524,  2537,  2546,
2504     2552,  2558,  2569,  2575,  2581,  2592,  2593,  2602,  2603,  2615,
2505     2624,  2625,  2626,  2627,  2628,  2644,  2664,  2666,  2668,  2668,
2506     2675,  2675,  2683,  2683,  2691,  2691,  2700,  2702,  2704,  2709,
2507     2723,  2724,  2728,  2731,  2739,  2743,  2750,  2754,  2758,  2762,
2508     2770,  2770,  2774,  2775,  2779,  2787,  2792,  2800,  2801,  2808,
2509     2815,  2819,  3000,  3000,  3004,  3004,  3014,  3014,  3018,  3023,
2510     3024,  3025,  3029,  3030,  3029,  3042,  3043,  3048,  3049,  3050,
2511     3051,  3055,  3059,  3060,  3061,  3062,  3083,  3087,  3101,  3102,
2512     3107,  3107,  3115,  3125,  3128,  3137,  3148,  3153,  3162,  3173,
2513     3173,  3176,  3180,  3184,  3189,  3199,  3217,  3226,  3291,  3295,
2514     3302,  3314,  3329,  3359,  3369,  3379,  3383,  3390,  3391,  3395,
2515     3398,  3404,  3423,  3441,  3457,  3471,  3485,  3496,  3514,  3523,
2516     3532,  3539,  3560,  3584,  3590,  3596,  3602,  3618,  3702,  3710,
2517     3711,  3715,  3716,  3720,  3726,  3733,  3739,  3746,  3753,  3766,
2518     3792
2519 };
2520 #endif
2521
2522 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
2523 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
2524    First, the terminals, then, starting at YYNTOKENS, nonterminals. */
2525 static const char *const yytname[] =
2526 {
2527   "$end", "error", "$undefined", "ESINT64VAL", "EUINT64VAL", "SINTVAL",
2528   "UINTVAL", "FPVAL", "VOID", "BOOL", "SBYTE", "UBYTE", "SHORT", "USHORT",
2529   "INT", "UINT", "LONG", "ULONG", "FLOAT", "DOUBLE", "TYPE", "LABEL",
2530   "VAR_ID", "LABELSTR", "STRINGCONSTANT", "IMPLEMENTATION",
2531   "ZEROINITIALIZER", "TRUETOK", "FALSETOK", "BEGINTOK", "ENDTOK",
2532   "DECLARE", "GLOBAL", "CONSTANT", "SECTION", "VOLATILE", "TO",
2533   "DOTDOTDOT", "NULL_TOK", "UNDEF", "CONST", "INTERNAL", "LINKONCE",
2534   "WEAK", "APPENDING", "DLLIMPORT", "DLLEXPORT", "EXTERN_WEAK", "OPAQUE",
2535   "NOT", "EXTERNAL", "TARGET", "TRIPLE", "ENDIAN", "POINTERSIZE", "LITTLE",
2536   "BIG", "ALIGN", "DEPLIBS", "CALL", "TAIL", "ASM_TOK", "MODULE",
2537   "SIDEEFFECT", "CC_TOK", "CCC_TOK", "CSRETCC_TOK", "FASTCC_TOK",
2538   "COLDCC_TOK", "X86_STDCALLCC_TOK", "X86_FASTCALLCC_TOK", "DATALAYOUT",
2539   "RET", "BR", "SWITCH", "INVOKE", "UNREACHABLE", "UNWIND", "EXCEPT",
2540   "ADD", "SUB", "MUL", "DIV", "UDIV", "SDIV", "FDIV", "REM", "UREM",
2541   "SREM", "FREM", "AND", "OR", "XOR", "SHL", "SHR", "ASHR", "LSHR",
2542   "SETLE", "SETGE", "SETLT", "SETGT", "SETEQ", "SETNE", "ICMP", "FCMP",
2543   "MALLOC", "ALLOCA", "FREE", "LOAD", "STORE", "GETELEMENTPTR", "PHI_TOK",
2544   "SELECT", "VAARG", "EXTRACTELEMENT", "INSERTELEMENT", "SHUFFLEVECTOR",
2545   "VAARG_old", "VANEXT_old", "EQ", "NE", "SLT", "SGT", "SLE", "SGE", "ULT",
2546   "UGT", "ULE", "UGE", "OEQ", "ONE", "OLT", "OGT", "OLE", "OGE", "ORD",
2547   "UNO", "UEQ", "UNE", "CAST", "TRUNC", "ZEXT", "SEXT", "FPTRUNC", "FPEXT",
2548   "FPTOUI", "FPTOSI", "UITOFP", "SITOFP", "PTRTOINT", "INTTOPTR",
2549   "BITCAST", "'='", "','", "'\\\\'", "'('", "')'", "'['", "'x'", "']'",
2550   "'<'", "'>'", "'{'", "'}'", "'*'", "'c'", "$accept", "INTVAL",
2551   "EINT64VAL", "ArithmeticOps", "LogicalOps", "SetCondOps", "IPredicates",
2552   "FPredicates", "ShiftOps", "CastOps", "SIntType", "UIntType", "IntType",
2553   "FPType", "OptAssign", "OptLinkage", "OptCallingConv", "OptAlign",
2554   "OptCAlign", "SectionString", "OptSection", "GlobalVarAttributes",
2555   "GlobalVarAttribute", "TypesV", "UpRTypesV", "Types", "PrimType",
2556   "UpRTypes", "TypeListI", "ArgTypeListI", "ConstVal", "ConstExpr",
2557   "ConstVector", "GlobalType", "Module", "FunctionList", "ConstPool", "@1",
2558   "@2", "@3", "@4", "AsmBlock", "BigOrLittle", "TargetDefinition",
2559   "LibrariesDefinition", "LibList", "Name", "OptName", "ArgVal",
2560   "ArgListH", "ArgList", "FunctionHeaderH", "BEGIN", "FunctionHeader",
2561   "@5", "END", "Function", "FnDeclareLinkage", "FunctionProto", "@6", "@7",
2562   "OptSideEffect", "ConstValueRef", "SymbolicValueRef", "ValueRef",
2563   "ResolvedVal", "BasicBlockList", "BasicBlock", "InstructionList",
2564   "Unwind", "BBTerminatorInst", "JumpTable", "Inst", "PHIList",
2565   "ValueRefList", "ValueRefListE", "OptTailCall", "InstVal", "IndexList",
2566   "OptVolatile", "MemoryInst", 0
2567 };
2568 #endif
2569
2570 # ifdef YYPRINT
2571 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
2572    token YYLEX-NUM.  */
2573 static const unsigned short int yytoknum[] =
2574 {
2575        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
2576      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
2577      275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
2578      285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
2579      295,   296,   297,   298,   299,   300,   301,   302,   303,   304,
2580      305,   306,   307,   308,   309,   310,   311,   312,   313,   314,
2581      315,   316,   317,   318,   319,   320,   321,   322,   323,   324,
2582      325,   326,   327,   328,   329,   330,   331,   332,   333,   334,
2583      335,   336,   337,   338,   339,   340,   341,   342,   343,   344,
2584      345,   346,   347,   348,   349,   350,   351,   352,   353,   354,
2585      355,   356,   357,   358,   359,   360,   361,   362,   363,   364,
2586      365,   366,   367,   368,   369,   370,   371,   372,   373,   374,
2587      375,   376,   377,   378,   379,   380,   381,   382,   383,   384,
2588      385,   386,   387,   388,   389,   390,   391,   392,   393,   394,
2589      395,   396,   397,   398,   399,   400,   401,   402,   403,   404,
2590      405,   406,    61,    44,    92,    40,    41,    91,   120,    93,
2591       60,    62,   123,   125,    42,    99
2592 };
2593 # endif
2594
2595 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
2596 static const unsigned char yyr1[] =
2597 {
2598        0,   166,   167,   167,   168,   168,   169,   169,   169,   169,
2599      169,   169,   169,   169,   169,   169,   169,   170,   170,   170,
2600      171,   171,   171,   171,   171,   171,   172,   172,   172,   172,
2601      172,   172,   172,   172,   172,   172,   173,   173,   173,   173,
2602      173,   173,   173,   173,   173,   173,   173,   173,   173,   173,
2603      173,   173,   174,   174,   174,   174,   175,   175,   175,   175,
2604      175,   175,   175,   175,   175,   175,   175,   175,   175,   176,
2605      176,   176,   176,   177,   177,   177,   177,   178,   178,   179,
2606      179,   180,   180,   181,   181,   181,   181,   181,   181,   181,
2607      181,   182,   182,   182,   182,   182,   182,   182,   182,   183,
2608      183,   184,   184,   185,   186,   186,   187,   187,   188,   188,
2609      189,   189,   190,   190,   191,   192,   192,   192,   192,   192,
2610      192,   192,   192,   192,   192,   192,   192,   193,   193,   193,
2611      193,   193,   193,   193,   193,   193,   193,   193,   193,   194,
2612      194,   195,   195,   195,   195,   196,   196,   196,   196,   196,
2613      196,   196,   196,   196,   196,   196,   196,   196,   196,   196,
2614      196,   196,   196,   197,   197,   197,   197,   197,   197,   197,
2615      197,   197,   197,   197,   197,   198,   198,   199,   199,   200,
2616      201,   201,   201,   201,   201,   202,   202,   202,   203,   202,
2617      204,   202,   205,   202,   206,   202,   202,   202,   202,   207,
2618      208,   208,   209,   209,   209,   209,   210,   211,   211,   211,
2619      212,   212,   213,   213,   214,   215,   215,   216,   216,   216,
2620      216,   217,   218,   218,   220,   219,   221,   221,   222,   223,
2621      223,   223,   225,   226,   224,   227,   227,   228,   228,   228,
2622      228,   228,   228,   228,   228,   228,   228,   228,   229,   229,
2623      230,   230,   231,   232,   232,   233,   234,   234,   234,   235,
2624      235,   236,   236,   236,   236,   236,   236,   236,   236,   236,
2625      237,   237,   238,   239,   239,   240,   240,   241,   241,   242,
2626      242,   243,   243,   243,   243,   243,   243,   243,   243,   243,
2627      243,   243,   243,   243,   243,   243,   243,   243,   243,   244,
2628      244,   245,   245,   246,   246,   246,   246,   246,   246,   246,
2629      246
2630 };
2631
2632 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
2633 static const unsigned char yyr2[] =
2634 {
2635        0,     2,     1,     1,     1,     1,     1,     1,     1,     1,
2636        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
2637        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
2638        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
2639        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
2640        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
2641        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
2642        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
2643        1,     2,     0,     1,     1,     1,     1,     1,     1,     1,
2644        0,     0,     1,     1,     1,     1,     1,     1,     2,     0,
2645        2,     0,     3,     2,     0,     1,     0,     3,     1,     2,
2646        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
2647        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
2648        2,     4,     5,     5,     3,     2,     5,     4,     2,     1,
2649        3,     1,     3,     1,     0,     4,     3,     3,     4,     4,
2650        3,     6,     5,     2,     2,     2,     2,     2,     2,     2,
2651        2,     2,     2,     6,     5,     8,     6,     6,     6,     7,
2652        7,     6,     6,     8,     8,     3,     1,     1,     1,     1,
2653        2,     2,     4,     2,     1,     4,     2,     4,     0,     7,
2654        0,     7,     0,     7,     0,     7,     3,     4,     0,     1,
2655        1,     1,     3,     3,     3,     3,     3,     3,     1,     0,
2656        1,     1,     1,     0,     2,     3,     1,     1,     3,     1,
2657        0,     8,     1,     1,     0,     4,     1,     1,     2,     0,
2658        1,     1,     0,     0,     5,     0,     1,     1,     1,     1,
2659        1,     1,     1,     1,     1,     3,     1,     5,     1,     1,
2660        1,     1,     2,     2,     2,     3,     2,     0,     1,     1,
2661        1,     2,     2,     3,     9,     9,     8,    13,     1,     1,
2662        6,     5,     2,     6,     7,     1,     3,     1,     0,     2,
2663        1,     5,     5,     5,     6,     6,     2,     4,     4,     6,
2664        4,     4,     4,     4,     6,     6,     2,     7,     1,     2,
2665        0,     1,     0,     3,     6,     3,     6,     2,     4,     6,
2666        4
2667 };
2668
2669 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
2670    STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
2671    means the default is an error.  */
2672 static const unsigned short int yydefact[] =
2673 {
2674      198,     0,    90,   184,     1,   183,   232,    83,    84,    85,
2675       86,    87,    88,    89,     0,   224,   257,   180,   181,   257,
2676      210,   211,     0,     0,     0,    90,     0,   186,   229,     0,
2677       91,   258,   254,    82,   226,   227,   228,   253,     0,     0,
2678        0,     0,   196,     0,     0,     0,     0,     0,     0,     0,
2679       81,   230,   231,   233,   199,   182,     0,    92,    93,    94,
2680       95,    96,    97,     0,     0,   302,   256,     0,     0,     0,
2681        0,   209,   197,   187,     2,     3,   111,   115,   116,   117,
2682      118,   119,   120,   121,   122,   123,   124,   125,   126,   128,
2683        0,     0,     0,     0,   248,   185,     0,   110,   127,   114,
2684      249,   129,   177,   178,     0,     0,     0,     0,    91,    98,
2685        0,   222,   223,   225,   301,     0,   280,     0,     0,     0,
2686        0,    91,   269,   259,   260,     6,     7,     8,     9,    10,
2687       11,    12,    13,    14,    15,    16,    17,    18,    19,    52,
2688       53,    54,    55,    20,    21,    22,    23,    24,    25,     0,
2689        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2690        0,     0,     0,    68,    56,    57,    58,    59,    60,    61,
2691       62,    63,    64,    65,    66,    67,     0,     0,     0,     0,
2692        0,   268,   255,    91,   272,     0,   298,   204,   201,   200,
2693      202,   203,   205,   208,     0,   130,     0,     0,     0,   113,
2694      135,   139,     0,   144,   138,   192,   194,   190,   115,   116,
2695      117,   118,   119,   120,   121,   122,   123,   124,   125,     0,
2696        0,     0,     0,   188,   234,     0,     0,   286,   279,   262,
2697      261,     0,     0,    72,    76,    71,    75,    70,    74,    69,
2698       73,    77,    78,     0,     0,    26,    27,    28,    29,    30,
2699       31,    32,    33,    34,    35,     0,    50,    51,    46,    47,
2700       48,    49,    36,    37,    38,    39,    40,    41,    42,    43,
2701       44,    45,     0,   101,   101,   307,     0,     0,   296,     0,
2702        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2703        0,     0,     0,     0,     0,   206,     0,     0,     0,     0,
2704        0,   134,   143,   141,     0,   106,   106,   106,   160,   161,
2705        4,     5,   158,   159,   162,   157,   153,   154,     0,     0,
2706        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2707        0,     0,     0,     0,   156,   155,   106,   220,   237,   238,
2708      239,   244,   240,   241,   242,   243,   235,     0,   246,   251,
2709      250,   252,     0,   263,     0,     0,     0,     0,     0,   303,
2710        0,   305,   300,     0,     0,     0,     0,     0,     0,     0,
2711        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2712      207,   112,   112,   137,     0,   140,     0,   131,     0,   193,
2713      195,   191,     0,     0,     0,     0,     0,     0,     0,   146,
2714      176,     0,     0,     0,   150,     0,   147,     0,     0,     0,
2715        0,     0,   189,   219,   213,   216,   217,     0,   236,     0,
2716        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2717      310,     0,     0,     0,   290,   293,     0,     0,   291,   292,
2718        0,     0,     0,   287,   288,     0,   308,     0,   132,   133,
2719      136,   142,     0,     0,   108,   106,     0,     0,   300,     0,
2720        0,     0,     0,     0,   145,   135,   114,     0,   148,   149,
2721        0,     0,     0,     0,     0,   212,   214,     0,   104,     0,
2722      245,     0,     0,   278,     0,     0,   101,   102,   101,   275,
2723      299,     0,     0,     0,     0,     0,   281,   282,   283,   278,
2724        0,   103,   109,   107,     0,     0,     0,     0,     0,     0,
2725        0,   175,   152,     0,     0,     0,     0,     0,     0,   218,
2726      215,   105,    99,     0,     0,     0,   277,     0,   284,   285,
2727        0,   304,   306,     0,     0,     0,   289,   294,   295,     0,
2728      309,     0,     0,   164,     0,     0,     0,     0,   151,     0,
2729        0,     0,     0,     0,     0,   221,   247,     0,     0,     0,
2730      276,   273,     0,   297,     0,     0,     0,   172,     0,     0,
2731      166,   167,   168,   171,   163,   100,     0,   266,     0,     0,
2732        0,   274,   169,   170,     0,     0,     0,   264,     0,   265,
2733        0,     0,   165,   173,   174,     0,     0,     0,     0,     0,
2734        0,   271,     0,     0,   270,   267
2735 };
2736
2737 /* YYDEFGOTO[NTERM-NUM]. */
2738 static const short int yydefgoto[] =
2739 {
2740       -1,    94,   312,   329,   330,   331,   255,   272,   332,   333,
2741      219,   220,   243,   221,    25,    15,    63,   555,   359,   454,
2742      522,   389,   455,    95,    96,   222,    98,    99,   202,   304,
2743      400,   348,   401,   104,     1,     2,     3,   336,   307,   305,
2744      306,    55,   190,    42,    72,   194,   100,   476,   415,   416,
2745      417,    64,   113,    16,    30,    36,    17,    53,    18,    28,
2746      108,   419,   349,   101,   351,   489,    19,    32,    33,   181,
2747      182,   579,    66,   278,   526,   527,   183,   184,   430,   185,
2748      186
2749 };
2750
2751 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
2752    STATE-NUM.  */
2753 #define YYPACT_NINF -542
2754 static const short int yypact[] =
2755 {
2756     -542,    13,   162,   567,  -542,  -542,  -542,  -542,  -542,  -542,
2757     -542,  -542,  -542,  -542,    83,  -542,    19,  -542,  -542,   -14,
2758     -542,  -542,    50,   -87,    87,   233,    27,  -542,   123,   141,
2759      175,  -542,  -542,    98,  -542,  -542,  -542,  -542,    33,    40,
2760       66,    68,  -542,    14,   141,  1265,   156,   156,   156,   156,
2761     -542,  -542,  -542,  -542,  -542,  -542,   221,  -542,  -542,  -542,
2762     -542,  -542,  -542,  1265,   -19,  1479,  -542,   204,   135,   226,
2763      227,   235,  -542,  -542,  -542,  -542,    81,  -542,  -542,  -542,
2764     -542,  -542,  -542,  -542,  -542,  -542,  -542,  -542,  -542,  -542,
2765      256,   257,     4,    15,  -542,  -542,   108,  -542,  -542,    12,
2766     -542,  -542,  -542,  -542,  1306,  1306,  1306,  1326,   175,  -542,
2767       98,  -542,  -542,  -542,  -542,  1306,  -542,   205,  1367,   116,
2768      479,   175,  -542,  -542,  -542,  -542,  -542,  -542,  -542,  -542,
2769     -542,  -542,  -542,  -542,  -542,  -542,  -542,  -542,  -542,  -542,
2770     -542,  -542,  -542,  -542,  -542,  -542,  -542,  -542,  -542,   355,
2771      429,  1306,  1306,  1306,  1306,  1306,  1306,  1306,  1306,  1306,
2772     1306,  1306,  1306,  -542,  -542,  -542,  -542,  -542,  -542,  -542,
2773     -542,  -542,  -542,  -542,  -542,  -542,  1306,  1306,  1306,  1306,
2774     1306,  -542,  -542,   175,  -542,    86,  -542,  -542,  -542,  -542,
2775     -542,  -542,  -542,  -542,   -13,  -542,   110,   111,    75,  -542,
2776     -542,    12,   -81,  1046,  -542,  -542,  -542,  -542,   174,   208,
2777      266,   210,   267,   212,   268,   230,   277,   275,   278,   246,
2778      280,   279,   566,  -542,  -542,   136,   766,  -542,  -542,    81,
2779     -542,   766,   766,  -542,  -542,  -542,  -542,  -542,  -542,  -542,
2780     -542,  -542,  -542,   766,  1265,  -542,  -542,  -542,  -542,  -542,
2781     -542,  -542,  -542,  -542,  -542,  1306,  -542,  -542,  -542,  -542,
2782     -542,  -542,  -542,  -542,  -542,  -542,  -542,  -542,  -542,  -542,
2783     -542,  -542,  1306,   137,   145,  -542,   766,   132,   146,   147,
2784      148,   149,   151,   152,   158,   160,   766,   766,   766,   161,
2785      281,  1265,  1306,  1306,   291,  -542,  1306,  1306,   155,   -27,
2786     1306,  -542,  -542,   165,   163,   176,   176,   176,  -542,  -542,
2787     -542,  -542,  -542,  -542,  -542,  -542,  -542,  -542,   355,   429,
2788      172,   177,   178,   179,   182,  1087,  1387,   529,   311,   184,
2789      185,   186,   188,   189,  -542,  -542,   176,  1107,  -542,  -542,
2790     -542,  -542,  -542,  -542,  -542,  -542,   282,  1326,  -542,  -542,
2791     -542,  -542,   193,  -542,   194,   766,   766,   766,     7,  -542,
2792       20,  -542,   195,   766,   192,  1306,  1306,  1306,  1306,  1306,
2793     1306,  1306,   200,   201,   206,  1306,  1306,   766,   766,   207,
2794     -542,   -59,  -149,  -542,   196,    12,  1148,  -542,    44,  -542,
2795     -542,  -542,   203,   211,  1326,  1326,  1326,  1326,  1326,  -542,
2796     -542,    -8,   741,   -82,  -542,    10,  -542,  1326,  1326,  1326,
2797     1326,  1326,  -542,  -542,    98,  -542,   214,   209,  -542,   337,
2798      -34,   342,   348,   215,   218,   219,   766,   371,   766,  1306,
2799     -542,   223,   766,   224,  -542,  -542,   225,   234,  -542,  -542,
2800      766,   766,   766,  -542,  -542,   228,  -542,  1306,  -542,  -542,
2801     -542,  -542,   362,   375,  -542,   176,  1326,  1326,   195,   236,
2802      237,   240,   243,  1326,  -542,   238,   -25,    11,  -542,  -542,
2803      244,   245,   247,   250,   352,  -542,  -542,  1205,   370,   252,
2804     -542,   766,   766,  1306,   766,   766,   258,  -542,   258,  -542,
2805      259,   766,   264,  1306,  1306,  1306,  -542,  -542,  -542,  1306,
2806      766,  -542,  -542,  -542,   270,   271,   263,  1326,  1326,  1326,
2807     1326,  -542,  -542,   260,  1326,  1326,  1326,  1326,  1306,  -542,
2808     -542,  -542,   368,   402,   274,   276,   259,   287,  -542,  -542,
2809      374,  -542,  -542,  1306,   285,   766,  -542,  -542,  -542,   290,
2810     -542,  1326,  1326,  -542,   283,   295,   284,   294,  -542,   296,
2811      297,   299,   302,   303,   430,  -542,  -542,   414,    41,   425,
2812     -542,  -542,   305,  -542,   306,   310,  1326,  -542,  1326,  1326,
2813     -542,  -542,  -542,  -542,  -542,  -542,   766,  -542,   893,   144,
2814      448,  -542,  -542,  -542,   314,   315,   316,  -542,   331,  -542,
2815      893,   766,  -542,  -542,  -542,   464,   334,   180,   766,   481,
2816      482,  -542,   766,   766,  -542,  -542
2817 };
2818
2819 /* YYPGOTO[NTERM-NUM].  */
2820 static const short int yypgoto[] =
2821 {
2822     -542,  -542,  -542,   435,   439,   441,   191,   197,   442,   445,
2823     -119,  -116,  -541,  -542,   478,   489,  -107,  -542,  -267,    37,
2824     -542,  -238,  -542,   -60,  -542,   -45,  -542,   -74,   -51,  -542,
2825     -101,   300,  -252,   134,  -542,  -542,  -542,  -542,  -542,  -542,
2826     -542,   473,  -542,  -542,  -542,  -542,     8,  -542,    46,  -542,
2827     -542,   410,  -542,  -542,  -542,  -542,  -542,  -542,   518,  -542,
2828     -542,  -542,  -528,   142,   -90,  -113,  -542,   505,  -542,   -72,
2829     -542,  -542,  -542,  -542,    97,    28,  -542,  -542,    70,  -542,
2830     -542
2831 };
2832
2833 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
2834    positive, shift that token.  If negative, reduce the rule which
2835    number is the opposite.  If zero, do what YYDEFACT says.
2836    If YYTABLE_NINF, syntax error.  */
2837 #define YYTABLE_NINF -180
2838 static const short int yytable[] =
2839 {
2840       97,   241,   227,   110,   242,   230,   223,   361,   197,    31,
2841      111,    26,   449,     4,   244,   204,    34,   578,    97,   201,
2842       74,    75,   426,   199,    77,    78,    79,    80,    81,    82,
2843       83,    84,    85,    86,    87,   428,    88,    20,   590,    21,
2844      275,    26,    31,   279,   280,   281,   282,   283,   284,   285,
2845      588,   233,   234,   235,   236,   237,   238,   239,   240,   205,
2846      206,   207,   596,    89,   427,    43,   289,   290,   390,   391,
2847      226,   463,   300,   226,   403,   405,   291,   427,   452,   468,
2848       74,    75,   301,   199,    77,    78,    79,    80,    81,    82,
2849       83,    84,    85,    86,    87,   420,    88,    20,   412,    21,
2850      448,   453,    38,    39,    40,   204,   273,   274,   226,   276,
2851      277,   226,   226,   226,   226,   226,   226,   226,   225,   463,
2852       20,    41,    21,    89,   201,   231,   300,   480,  -139,   201,
2853     -112,   286,   287,   288,   226,   226,   384,   232,  -139,   204,
2854      294,   352,   353,   112,    29,   463,   295,   299,    44,    35,
2855      467,   464,   303,   354,   233,   234,   235,   236,   237,   238,
2856      239,   240,  -179,   463,   463,    54,   198,  -112,    51,    90,
2857       52,    71,    91,   469,   513,    92,   204,    93,   200,    50,
2858      379,   105,   106,   107,   355,    67,   362,     5,   102,   103,
2859      188,   189,    68,     6,   292,   293,   372,   373,   374,    97,
2860      577,   308,   309,     7,     8,     9,    10,    11,    12,    13,
2861      356,   -72,   -72,   -71,   -71,   -70,   -70,   503,    69,   531,
2862       70,   532,   381,   382,    14,   109,   385,   357,   187,    90,
2863      191,   377,    91,   -69,   -69,    92,  -113,    93,   298,    56,
2864       57,    58,    59,    60,    61,    62,    97,   378,   226,   310,
2865      311,   192,   433,    45,   435,   436,   437,   123,   124,   193,
2866      195,   196,   443,   203,   228,   423,   424,   425,   296,   297,
2867      -76,   -75,   -74,   431,     7,     8,     9,    10,    46,    12,
2868       47,   -73,   -79,    48,   313,   -80,   314,   445,   446,   363,
2869      358,   337,   414,   458,   459,   460,   461,   462,   360,   364,
2870      365,   366,   367,   589,   368,   369,   470,   471,   472,   473,
2871      474,   370,   385,   371,   375,   380,   383,   376,   386,   387,
2872      226,   434,   226,   226,   226,   438,   439,   394,   466,   388,
2873      226,   444,   395,   396,   397,   406,   486,   398,   488,   407,
2874      408,   409,   492,   410,   411,   418,   421,   422,   429,   432,
2875      496,   497,   498,   440,   441,   504,   505,   450,   456,   442,
2876      447,   479,   511,   481,   335,   478,   457,   477,   350,   482,
2877      483,   484,   485,   350,   350,   487,   491,   493,   494,   502,
2878      536,   537,   538,   499,   226,   350,   501,   495,   518,   507,
2879      508,   524,   525,   509,   528,   529,   510,   514,   515,   512,
2880      516,   534,   500,   517,   452,   523,   544,   545,   546,   547,
2881      540,   530,   533,   549,   550,   551,   552,   535,   350,   543,
2882      560,   548,   475,   541,   542,   554,   556,   557,   350,   350,
2883      350,   427,   414,   558,   575,   576,   566,   568,   226,   241,
2884      564,   565,   242,   559,   561,   562,   563,   569,   226,   226,
2885      226,   567,   570,   571,   226,   572,   256,   257,   573,   574,
2886      241,   580,   582,   242,   581,   584,   583,   585,   586,   591,
2887      592,   593,   594,   553,   245,   246,   247,   248,   249,   250,
2888      251,   252,   253,   254,   595,   598,   587,   599,   226,   233,
2889      234,   235,   236,   237,   238,   239,   240,   350,   350,   350,
2890      176,   597,   602,   603,   177,   350,   178,   179,   601,   392,
2891      180,    65,   604,   605,    49,   521,   393,    73,   224,   350,
2892      350,    27,   334,   520,    37,   600,   490,   539,   506,     0,
2893        0,     0,     0,     0,    74,    75,     0,   199,   208,   209,
2894      210,   211,   212,   213,   214,   215,   216,   217,   218,     0,
2895       88,    20,     0,    21,   258,   259,   260,   261,   262,   263,
2896      264,   265,   266,   267,   268,   269,   270,   271,   350,     0,
2897      350,    74,    75,     0,   350,     0,     0,    89,     0,     0,
2898        0,     0,   350,   350,   350,     0,     0,   -82,    20,    20,
2899       21,    21,   315,     0,     0,     0,     0,     0,     6,   -82,
2900      -82,     0,     0,     0,   316,   317,     0,     0,   -82,   -82,
2901      -82,   -82,   -82,   -82,   -82,     0,     0,   -82,    22,     0,
2902        0,     0,     0,   350,   350,    23,   350,   350,     0,    24,
2903        0,     0,     0,   350,     0,     0,     0,     0,     0,     0,
2904        0,     0,   350,     0,     0,   125,   126,   127,   128,   129,
2905      130,   131,   132,   133,   134,   135,   136,   137,   138,   139,
2906      140,   141,   142,   143,   144,   145,   146,   147,   148,   318,
2907      319,     0,     0,     0,     0,     0,   320,   350,   321,     0,
2908      322,   323,   324,    90,     0,     0,    91,     0,     0,    92,
2909        0,    93,   404,     0,     0,     0,     0,     0,     0,     0,
2910        0,     0,     0,     0,     0,   163,   164,   165,   166,   167,
2911      168,   169,   170,   171,   172,   173,   174,   175,   350,     0,
2912        0,     0,     0,   325,     0,     0,   326,     0,   327,     0,
2913        0,   328,     0,   350,     0,     0,     0,     0,     0,     0,
2914      350,     0,     0,     0,   350,   350,    74,    75,     0,   199,
2915      208,   209,   210,   211,   212,   213,   214,   215,   216,   217,
2916      218,     0,    88,    20,     0,    21,     0,     0,     0,   338,
2917      339,    74,    75,   340,     0,     0,     0,     0,     0,     0,
2918        0,     0,     0,     0,     0,     0,     0,     0,    20,    89,
2919       21,     0,   341,   342,   343,     0,     0,     0,     0,     0,
2920        0,     0,     0,     0,   344,   345,     0,     0,     0,     0,
2921        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2922        0,     0,     0,     0,     0,     0,     0,   346,     0,     0,
2923        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2924        0,     0,     0,     0,     0,   125,   126,   127,   128,   129,
2925      130,   131,   132,   133,   134,   135,   136,   137,   138,   139,
2926      140,   141,   142,   143,   144,   145,   146,   147,   148,   318,
2927      319,     0,     0,     0,     0,     0,   320,     0,   321,     0,
2928      322,   323,   324,     0,     0,     0,     0,     0,     0,     0,
2929        0,     0,     0,     0,     0,    90,   338,   339,    91,     0,
2930      340,    92,     0,    93,   465,   163,   164,   165,   166,   167,
2931      168,   169,   170,   171,   172,   173,   174,   175,     0,   341,
2932      342,   343,     0,     0,     0,     0,   347,     0,     0,     0,
2933        0,   344,   345,     0,     0,     0,     0,     0,     0,     0,
2934        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2935        0,     0,     0,     0,   346,     0,     0,     0,     0,     0,
2936        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2937        0,     0,   125,   126,   127,   128,   129,   130,   131,   132,
2938      133,   134,   135,   136,   137,   138,   139,   140,   141,   142,
2939      143,   144,   145,   146,   147,   148,   318,   319,     0,     0,
2940        0,     0,     0,   320,     0,   321,     0,   322,   323,   324,
2941        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2942        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2943        0,     0,   163,   164,   165,   166,   167,   168,   169,   170,
2944      171,   172,   173,   174,   175,     0,     0,     0,     0,     0,
2945        0,    74,    75,   347,   199,    77,    78,    79,    80,    81,
2946       82,    83,    84,    85,    86,    87,     0,    88,    20,     0,
2947       21,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2948        0,     0,     0,   302,     0,     0,     0,     0,     0,     0,
2949        0,     0,    74,    75,    89,   199,   208,   209,   210,   211,
2950      212,   213,   214,   215,   216,   217,   218,     0,    88,    20,
2951        0,    21,    74,    75,     0,   199,    77,    78,    79,    80,
2952       81,    82,    83,    84,    85,    86,    87,     0,    88,    20,
2953        0,    21,     0,     0,     0,    89,     0,     0,     0,     0,
2954        0,     0,     0,     0,   413,     0,     0,     0,     0,     0,
2955        0,     0,     0,    74,    75,    89,   199,    77,    78,    79,
2956       80,    81,    82,    83,    84,    85,    86,    87,     0,    88,
2957       20,     0,    21,     0,     0,     0,     0,     0,     0,     0,
2958        0,     0,     0,     0,     0,   451,     0,     0,     0,     0,
2959        0,     0,     0,     0,     0,     0,    89,     0,     0,     0,
2960       90,     0,     0,    91,     0,     0,    92,     0,    93,     0,
2961       74,    75,     0,   199,    77,    78,    79,    80,    81,    82,
2962       83,    84,    85,    86,    87,     0,    88,    20,     0,    21,
2963        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2964        0,    90,   519,     0,    91,     0,   399,    92,     0,    93,
2965        0,     0,     0,    89,     0,     0,     0,     0,     0,     0,
2966        0,    90,     0,     0,    91,     0,     0,    92,     0,    93,
2967       74,    75,     0,    76,    77,    78,    79,    80,    81,    82,
2968       83,    84,    85,    86,    87,     0,    88,    20,     0,    21,
2969        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2970        0,     0,    90,     0,     0,    91,     0,     0,    92,     0,
2971       93,    74,    75,    89,   199,    77,    78,    79,    80,    81,
2972       82,    83,    84,    85,    86,    87,     0,    88,    20,     0,
2973       21,    74,    75,     0,   199,   208,   209,   210,   211,   212,
2974      213,   214,   215,   216,   217,   218,     0,    88,    20,     0,
2975       21,     0,     0,     0,    89,     0,     0,     0,     0,    90,
2976        0,     0,    91,     0,     0,    92,     0,    93,     0,     0,
2977        0,     0,    74,    75,    89,   229,    77,    78,    79,    80,
2978       81,    82,    83,    84,    85,    86,    87,     0,    88,    20,
2979        0,    21,    74,    75,     0,   199,   208,   209,   210,   211,
2980      212,   213,   214,   215,   216,   217,   218,     0,    88,    20,
2981        0,    21,     0,     0,     0,    89,     0,     0,     0,    90,
2982        0,     0,    91,     0,     0,    92,     0,    93,     0,     0,
2983        0,     0,     0,     0,     0,    89,     0,     0,     0,     0,
2984        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2985        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2986       90,     0,     0,    91,     0,     0,    92,     0,    93,     0,
2987        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2988       90,     0,     0,    91,     0,     0,    92,     0,    93,     0,
2989        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2990        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
2991        0,     0,     0,     0,   114,     0,     0,     0,     0,     0,
2992        0,    90,     0,     0,    91,     0,     0,    92,   115,    93,
2993        0,     0,     0,     0,     0,     0,     0,     0,   116,   117,
2994        0,    90,     0,     0,    91,     0,     0,    92,     0,   402,
2995        0,   118,   119,   120,   121,   122,   123,   124,   125,   126,
2996      127,   128,   129,   130,   131,   132,   133,   134,   135,   136,
2997      137,   138,   139,   140,   141,   142,   143,   144,   145,   146,
2998      147,   148,   149,   150,   151,   152,   153,     0,     0,   154,
2999      155,   156,   157,   158,   159,   160,   161,   162,     0,     0,
3000        0,     0,     0,     0,     0,     0,     0,     0,     0,     0,
3001        0,     0,     0,     0,     0,     0,     0,     0,   163,   164,
3002      165,   166,   167,   168,   169,   170,   171,   172,   173,   174,
3003      175
3004 };
3005
3006 static const short int yycheck[] =
3007 {
3008       45,   120,   115,    63,   120,   118,   107,   274,     4,    23,
3009       29,     3,   161,     0,   121,   164,    30,   558,    63,    93,
3010        5,     6,    15,     8,     9,    10,    11,    12,    13,    14,
3011       15,    16,    17,    18,    19,    15,    21,    22,   579,    24,
3012      153,    33,    23,   156,   157,   158,   159,   160,   161,   162,
3013      578,    10,    11,    12,    13,    14,    15,    16,    17,   104,
3014      105,   106,   590,    48,    57,   152,   179,   180,   306,   307,
3015      115,   153,   153,   118,   326,   327,   183,    57,    34,   161,
3016        5,     6,   163,     8,     9,    10,    11,    12,    13,    14,
3017       15,    16,    17,    18,    19,   347,    21,    22,   336,    24,
3018      159,    57,    52,    53,    54,   164,   151,   152,   153,   154,
3019      155,   156,   157,   158,   159,   160,   161,   162,   110,   153,
3020       22,    71,    24,    48,   198,     9,   153,   161,   153,   203,
3021      155,   176,   177,   178,   179,   180,   163,    21,   163,   164,
3022      153,   231,   232,   162,    61,   153,   159,   198,    61,   163,
3023      402,   159,   203,   243,    10,    11,    12,    13,    14,    15,
3024       16,    17,     0,   153,   153,    24,   162,   155,    45,   154,
3025       47,   157,   157,   163,   163,   160,   164,   162,   163,   152,
3026      293,    47,    48,    49,   244,   152,   276,    25,    32,    33,
3027       55,    56,   152,    31,   108,   109,   286,   287,   288,   244,
3028      159,    27,    28,    41,    42,    43,    44,    45,    46,    47,
3029      255,     3,     4,     3,     4,     3,     4,   455,   152,   486,
3030      152,   488,   296,   297,    62,     4,   300,   272,    24,   154,
3031        4,   291,   157,     3,     4,   160,   155,   162,   163,    64,
3032       65,    66,    67,    68,    69,    70,   291,   292,   293,     3,
3033        4,    24,   365,    20,   367,   368,   369,    77,    78,    24,
3034        4,     4,   375,   155,    59,   355,   356,   357,   158,   158,
3035        4,     4,     4,   363,    41,    42,    43,    44,    45,    46,
3036       47,     4,     7,    50,     4,     7,     7,   377,   378,   157,
3037      153,   155,   337,   394,   395,   396,   397,   398,   153,   153,
3038      153,   153,   153,   159,   153,   153,   407,   408,   409,   410,
3039      411,   153,   386,   153,   153,    24,   161,    36,   153,   156,
3040      365,   366,   367,   368,   369,   370,   371,   155,   402,   153,
3041      375,   376,   155,   155,   155,    24,   426,   155,   428,   155,
3042      155,   155,   432,   155,   155,    63,   153,   153,   153,   157,
3043      440,   441,   442,   153,   153,   456,   457,   161,   155,   153,
3044      153,    24,   463,    21,   222,   156,   155,   153,   226,    21,
3045      155,   153,   153,   231,   232,     4,   153,   153,   153,     4,
3046      493,   494,   495,   155,   429,   243,    24,   153,    36,   153,
3047      153,   481,   482,   153,   484,   485,   153,   153,   153,   161,
3048      153,   491,   447,   153,    34,   153,   507,   508,   509,   510,
3049      500,   153,   153,   514,   515,   516,   517,   153,   276,   156,
3050      533,   161,   414,   153,   153,    57,    24,   153,   286,   287,
3051      288,    57,   477,   157,     4,    21,   153,   153,   483,   558,
3052      541,   542,   558,   156,   159,   535,   156,   153,   493,   494,
3053      495,   156,   156,   156,   499,   156,    27,    28,   156,   156,
3054      579,    36,   156,   579,   159,   566,   156,   568,   569,    21,
3055      156,   156,   156,   518,   119,   120,   121,   122,   123,   124,
3056      125,   126,   127,   128,   153,    21,   576,   153,   533,    10,
3057       11,    12,    13,    14,    15,    16,    17,   355,   356,   357,
3058       65,   591,    21,    21,    65,   363,    65,    65,   598,   318,
3059       65,    33,   602,   603,    25,   478,   319,    44,   108,   377,
3060      378,     3,   222,   477,    19,   597,   429,   499,   458,    -1,
3061       -1,    -1,    -1,    -1,     5,     6,    -1,     8,     9,    10,
3062       11,    12,    13,    14,    15,    16,    17,    18,    19,    -1,
3063       21,    22,    -1,    24,   125,   126,   127,   128,   129,   130,
3064      131,   132,   133,   134,   135,   136,   137,   138,   426,    -1,
3065      428,     5,     6,    -1,   432,    -1,    -1,    48,    -1,    -1,
3066       -1,    -1,   440,   441,   442,    -1,    -1,    20,    22,    22,
3067       24,    24,    26,    -1,    -1,    -1,    -1,    -1,    31,    32,
3068       33,    -1,    -1,    -1,    38,    39,    -1,    -1,    41,    42,
3069       43,    44,    45,    46,    47,    -1,    -1,    50,    51,    -1,
3070       -1,    -1,    -1,   481,   482,    58,   484,   485,    -1,    62,
3071       -1,    -1,    -1,   491,    -1,    -1,    -1,    -1,    -1,    -1,
3072       -1,    -1,   500,    -1,    -1,    79,    80,    81,    82,    83,
3073       84,    85,    86,    87,    88,    89,    90,    91,    92,    93,
3074       94,    95,    96,    97,    98,    99,   100,   101,   102,   103,
3075      104,    -1,    -1,    -1,    -1,    -1,   110,   535,   112,    -1,
3076      114,   115,   116,   154,    -1,    -1,   157,    -1,    -1,   160,
3077       -1,   162,   163,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3078       -1,    -1,    -1,    -1,    -1,   139,   140,   141,   142,   143,
3079      144,   145,   146,   147,   148,   149,   150,   151,   576,    -1,
3080       -1,    -1,    -1,   157,    -1,    -1,   160,    -1,   162,    -1,
3081       -1,   165,    -1,   591,    -1,    -1,    -1,    -1,    -1,    -1,
3082      598,    -1,    -1,    -1,   602,   603,     5,     6,    -1,     8,
3083        9,    10,    11,    12,    13,    14,    15,    16,    17,    18,
3084       19,    -1,    21,    22,    -1,    24,    -1,    -1,    -1,     3,
3085        4,     5,     6,     7,    -1,    -1,    -1,    -1,    -1,    -1,
3086       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    22,    48,
3087       24,    -1,    26,    27,    28,    -1,    -1,    -1,    -1,    -1,
3088       -1,    -1,    -1,    -1,    38,    39,    -1,    -1,    -1,    -1,
3089       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3090       -1,    -1,    -1,    -1,    -1,    -1,    -1,    61,    -1,    -1,
3091       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3092       -1,    -1,    -1,    -1,    -1,    79,    80,    81,    82,    83,
3093       84,    85,    86,    87,    88,    89,    90,    91,    92,    93,
3094       94,    95,    96,    97,    98,    99,   100,   101,   102,   103,
3095      104,    -1,    -1,    -1,    -1,    -1,   110,    -1,   112,    -1,
3096      114,   115,   116,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3097       -1,    -1,    -1,    -1,    -1,   154,     3,     4,   157,    -1,
3098        7,   160,    -1,   162,   163,   139,   140,   141,   142,   143,
3099      144,   145,   146,   147,   148,   149,   150,   151,    -1,    26,
3100       27,    28,    -1,    -1,    -1,    -1,   160,    -1,    -1,    -1,
3101       -1,    38,    39,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3102       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3103       -1,    -1,    -1,    -1,    61,    -1,    -1,    -1,    -1,    -1,
3104       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3105       -1,    -1,    79,    80,    81,    82,    83,    84,    85,    86,
3106       87,    88,    89,    90,    91,    92,    93,    94,    95,    96,
3107       97,    98,    99,   100,   101,   102,   103,   104,    -1,    -1,
3108       -1,    -1,    -1,   110,    -1,   112,    -1,   114,   115,   116,
3109       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3110       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3111       -1,    -1,   139,   140,   141,   142,   143,   144,   145,   146,
3112      147,   148,   149,   150,   151,    -1,    -1,    -1,    -1,    -1,
3113       -1,     5,     6,   160,     8,     9,    10,    11,    12,    13,
3114       14,    15,    16,    17,    18,    19,    -1,    21,    22,    -1,
3115       24,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3116       -1,    -1,    -1,    37,    -1,    -1,    -1,    -1,    -1,    -1,
3117       -1,    -1,     5,     6,    48,     8,     9,    10,    11,    12,
3118       13,    14,    15,    16,    17,    18,    19,    -1,    21,    22,
3119       -1,    24,     5,     6,    -1,     8,     9,    10,    11,    12,
3120       13,    14,    15,    16,    17,    18,    19,    -1,    21,    22,
3121       -1,    24,    -1,    -1,    -1,    48,    -1,    -1,    -1,    -1,
3122       -1,    -1,    -1,    -1,    37,    -1,    -1,    -1,    -1,    -1,
3123       -1,    -1,    -1,     5,     6,    48,     8,     9,    10,    11,
3124       12,    13,    14,    15,    16,    17,    18,    19,    -1,    21,
3125       22,    -1,    24,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3126       -1,    -1,    -1,    -1,    -1,    37,    -1,    -1,    -1,    -1,
3127       -1,    -1,    -1,    -1,    -1,    -1,    48,    -1,    -1,    -1,
3128      154,    -1,    -1,   157,    -1,    -1,   160,    -1,   162,    -1,
3129        5,     6,    -1,     8,     9,    10,    11,    12,    13,    14,
3130       15,    16,    17,    18,    19,    -1,    21,    22,    -1,    24,
3131       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3132       -1,   154,    37,    -1,   157,    -1,   159,   160,    -1,   162,
3133       -1,    -1,    -1,    48,    -1,    -1,    -1,    -1,    -1,    -1,
3134       -1,   154,    -1,    -1,   157,    -1,    -1,   160,    -1,   162,
3135        5,     6,    -1,     8,     9,    10,    11,    12,    13,    14,
3136       15,    16,    17,    18,    19,    -1,    21,    22,    -1,    24,
3137       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3138       -1,    -1,   154,    -1,    -1,   157,    -1,    -1,   160,    -1,
3139      162,     5,     6,    48,     8,     9,    10,    11,    12,    13,
3140       14,    15,    16,    17,    18,    19,    -1,    21,    22,    -1,
3141       24,     5,     6,    -1,     8,     9,    10,    11,    12,    13,
3142       14,    15,    16,    17,    18,    19,    -1,    21,    22,    -1,
3143       24,    -1,    -1,    -1,    48,    -1,    -1,    -1,    -1,   154,
3144       -1,    -1,   157,    -1,    -1,   160,    -1,   162,    -1,    -1,
3145       -1,    -1,     5,     6,    48,     8,     9,    10,    11,    12,
3146       13,    14,    15,    16,    17,    18,    19,    -1,    21,    22,
3147       -1,    24,     5,     6,    -1,     8,     9,    10,    11,    12,
3148       13,    14,    15,    16,    17,    18,    19,    -1,    21,    22,
3149       -1,    24,    -1,    -1,    -1,    48,    -1,    -1,    -1,   154,
3150       -1,    -1,   157,    -1,    -1,   160,    -1,   162,    -1,    -1,
3151       -1,    -1,    -1,    -1,    -1,    48,    -1,    -1,    -1,    -1,
3152       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3153       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3154      154,    -1,    -1,   157,    -1,    -1,   160,    -1,   162,    -1,
3155       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3156      154,    -1,    -1,   157,    -1,    -1,   160,    -1,   162,    -1,
3157       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3158       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3159       -1,    -1,    -1,    -1,    35,    -1,    -1,    -1,    -1,    -1,
3160       -1,   154,    -1,    -1,   157,    -1,    -1,   160,    49,   162,
3161       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    59,    60,
3162       -1,   154,    -1,    -1,   157,    -1,    -1,   160,    -1,   162,
3163       -1,    72,    73,    74,    75,    76,    77,    78,    79,    80,
3164       81,    82,    83,    84,    85,    86,    87,    88,    89,    90,
3165       91,    92,    93,    94,    95,    96,    97,    98,    99,   100,
3166      101,   102,   103,   104,   105,   106,   107,    -1,    -1,   110,
3167      111,   112,   113,   114,   115,   116,   117,   118,    -1,    -1,
3168       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
3169       -1,    -1,    -1,    -1,    -1,    -1,    -1,    -1,   139,   140,
3170      141,   142,   143,   144,   145,   146,   147,   148,   149,   150,
3171      151
3172 };
3173
3174 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
3175    symbol of state STATE-NUM.  */
3176 static const unsigned char yystos[] =
3177 {
3178        0,   200,   201,   202,     0,    25,    31,    41,    42,    43,
3179       44,    45,    46,    47,    62,   181,   219,   222,   224,   232,
3180       22,    24,    51,    58,    62,   180,   212,   224,   225,    61,
3181      220,    23,   233,   234,    30,   163,   221,   233,    52,    53,
3182       54,    71,   209,   152,    61,    20,    45,    47,    50,   181,
3183      152,    45,    47,   223,    24,   207,    64,    65,    66,    67,
3184       68,    69,    70,   182,   217,   180,   238,   152,   152,   152,
3185      152,   157,   210,   207,     5,     6,     8,     9,    10,    11,
3186       12,    13,    14,    15,    16,    17,    18,    19,    21,    48,
3187      154,   157,   160,   162,   167,   189,   190,   191,   192,   193,
3188      212,   229,    32,    33,   199,   199,   199,   199,   226,     4,
3189      189,    29,   162,   218,    35,    49,    59,    60,    72,    73,
3190       74,    75,    76,    77,    78,    79,    80,    81,    82,    83,
3191       84,    85,    86,    87,    88,    89,    90,    91,    92,    93,
3192       94,    95,    96,    97,    98,    99,   100,   101,   102,   103,
3193      104,   105,   106,   107,   110,   111,   112,   113,   114,   115,
3194      116,   117,   118,   139,   140,   141,   142,   143,   144,   145,
3195      146,   147,   148,   149,   150,   151,   169,   170,   171,   174,
3196      175,   235,   236,   242,   243,   245,   246,    24,    55,    56,
3197      208,     4,    24,    24,   211,     4,     4,     4,   162,     8,
3198      163,   193,   194,   155,   164,   191,   191,   191,     9,    10,
3199       11,    12,    13,    14,    15,    16,    17,    18,    19,   176,
3200      177,   179,   191,   196,   217,   212,   191,   231,    59,     8,
3201      231,     9,    21,    10,    11,    12,    13,    14,    15,    16,
3202       17,   176,   177,   178,   182,   119,   120,   121,   122,   123,
3203      124,   125,   126,   127,   128,   172,    27,    28,   125,   126,
3204      127,   128,   129,   130,   131,   132,   133,   134,   135,   136,
3205      137,   138,   173,   191,   191,   231,   191,   191,   239,   231,
3206      231,   231,   231,   231,   231,   231,   191,   191,   191,   231,
3207      231,   182,   108,   109,   153,   159,   158,   158,   163,   194,
3208      153,   163,    37,   194,   195,   205,   206,   204,    27,    28,
3209        3,     4,   168,     4,     7,    26,    38,    39,   103,   104,
3210      110,   112,   114,   115,   116,   157,   160,   162,   165,   169,
3211      170,   171,   174,   175,   197,   229,   203,   155,     3,     4,
3212        7,    26,    27,    28,    38,    39,    61,   160,   197,   228,
3213      229,   230,   230,   230,   230,   189,   191,   191,   153,   184,
3214      153,   184,   230,   157,   153,   153,   153,   153,   153,   153,
3215      153,   153,   230,   230,   230,   153,    36,   189,   191,   231,
3216       24,   193,   193,   161,   163,   193,   153,   156,   153,   187,
3217      187,   187,   172,   173,   155,   155,   155,   155,   155,   159,
3218      196,   198,   162,   198,   163,   198,    24,   155,   155,   155,
3219      155,   155,   187,    37,   191,   214,   215,   216,    63,   227,
3220      198,   153,   153,   230,   230,   230,    15,    57,    15,   153,
3221      244,   230,   157,   231,   191,   231,   231,   231,   191,   191,
3222      153,   153,   153,   231,   191,   230,   230,   153,   159,   161,
3223      161,    37,    34,    57,   185,   188,   155,   155,   196,   196,
3224      196,   196,   196,   153,   159,   163,   193,   198,   161,   163,
3225      196,   196,   196,   196,   196,   212,   213,   153,   156,    24,
3226      161,    21,    21,   155,   153,   153,   230,     4,   230,   231,
3227      240,   153,   230,   153,   153,   153,   230,   230,   230,   155,
3228      191,    24,     4,   187,   196,   196,   244,   153,   153,   153,
3229      153,   196,   161,   163,   153,   153,   153,   153,    36,    37,
3230      214,   185,   186,   153,   230,   230,   240,   241,   230,   230,
3231      153,   184,   184,   153,   230,   153,   231,   231,   231,   241,
3232      230,   153,   153,   156,   196,   196,   196,   196,   161,   196,
3233      196,   196,   196,   191,    57,   183,    24,   153,   157,   156,
3234      231,   159,   230,   156,   196,   196,   153,   156,   153,   153,
3235      156,   156,   156,   156,   156,     4,    21,   159,   178,   237,
3236       36,   159,   156,   156,   196,   196,   196,   230,   228,   159,
3237      178,    21,   156,   156,   156,   153,   228,   230,    21,   153,
3238      235,   230,    21,    21,   230,   230
3239 };
3240
3241 #define yyerrok         (yyerrstatus = 0)
3242 #define yyclearin       (yychar = YYEMPTY)
3243 #define YYEMPTY         (-2)
3244 #define YYEOF           0
3245
3246 #define YYACCEPT        goto yyacceptlab
3247 #define YYABORT         goto yyabortlab
3248 #define YYERROR         goto yyerrorlab
3249
3250
3251 /* Like YYERROR except do call yyerror.  This remains here temporarily
3252    to ease the transition to the new meaning of YYERROR, for GCC.
3253    Once GCC version 2 has supplanted version 1, this can go.  */
3254
3255 #define YYFAIL          goto yyerrlab
3256
3257 #define YYRECOVERING()  (!!yyerrstatus)
3258
3259 #define YYBACKUP(Token, Value)                                  \
3260 do                                                              \
3261   if (yychar == YYEMPTY && yylen == 1)                          \
3262     {                                                           \
3263       yychar = (Token);                                         \
3264       yylval = (Value);                                         \
3265       yytoken = YYTRANSLATE (yychar);                           \
3266       YYPOPSTACK;                                               \
3267       goto yybackup;                                            \
3268     }                                                           \
3269   else                                                          \
3270     {                                                           \
3271       yyerror (YY_("syntax error: cannot back up")); \
3272       YYERROR;                                                  \
3273     }                                                           \
3274 while (0)
3275
3276
3277 #define YYTERROR        1
3278 #define YYERRCODE       256
3279
3280
3281 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
3282    If N is 0, then set CURRENT to the empty location which ends
3283    the previous symbol: RHS[0] (always defined).  */
3284
3285 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
3286 #ifndef YYLLOC_DEFAULT
3287 # define YYLLOC_DEFAULT(Current, Rhs, N)                                \
3288     do                                                                  \
3289       if (N)                                                            \
3290         {                                                               \
3291           (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;        \
3292           (Current).first_column = YYRHSLOC (Rhs, 1).first_column;      \
3293           (Current).last_line    = YYRHSLOC (Rhs, N).last_line;         \
3294           (Current).last_column  = YYRHSLOC (Rhs, N).last_column;       \
3295         }                                                               \
3296       else                                                              \
3297         {                                                               \
3298           (Current).first_line   = (Current).last_line   =              \
3299             YYRHSLOC (Rhs, 0).last_line;                                \
3300           (Current).first_column = (Current).last_column =              \
3301             YYRHSLOC (Rhs, 0).last_column;                              \
3302         }                                                               \
3303     while (0)
3304 #endif
3305
3306
3307 /* YY_LOCATION_PRINT -- Print the location on the stream.
3308    This macro was not mandated originally: define only if we know
3309    we won't break user code: when these are the locations we know.  */
3310
3311 #ifndef YY_LOCATION_PRINT
3312 # if YYLTYPE_IS_TRIVIAL
3313 #  define YY_LOCATION_PRINT(File, Loc)                  \
3314      fprintf (File, "%d.%d-%d.%d",                      \
3315               (Loc).first_line, (Loc).first_column,     \
3316               (Loc).last_line,  (Loc).last_column)
3317 # else
3318 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
3319 # endif
3320 #endif
3321
3322
3323 /* YYLEX -- calling `yylex' with the right arguments.  */
3324
3325 #ifdef YYLEX_PARAM
3326 # define YYLEX yylex (YYLEX_PARAM)
3327 #else
3328 # define YYLEX yylex ()
3329 #endif
3330
3331 /* Enable debugging if requested.  */
3332 #if YYDEBUG
3333
3334 # ifndef YYFPRINTF
3335 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
3336 #  define YYFPRINTF fprintf
3337 # endif
3338
3339 # define YYDPRINTF(Args)                        \
3340 do {                                            \
3341   if (yydebug)                                  \
3342     YYFPRINTF Args;                             \
3343 } while (0)
3344
3345 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)          \
3346 do {                                                            \
3347   if (yydebug)                                                  \
3348     {                                                           \
3349       YYFPRINTF (stderr, "%s ", Title);                         \
3350       yysymprint (stderr,                                       \
3351                   Type, Value); \
3352       YYFPRINTF (stderr, "\n");                                 \
3353     }                                                           \
3354 } while (0)
3355
3356 /*------------------------------------------------------------------.
3357 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
3358 | TOP (included).                                                   |
3359 `------------------------------------------------------------------*/
3360
3361 #if defined (__STDC__) || defined (__cplusplus)
3362 static void
3363 yy_stack_print (short int *bottom, short int *top)
3364 #else
3365 static void
3366 yy_stack_print (bottom, top)
3367     short int *bottom;
3368     short int *top;
3369 #endif
3370 {
3371   YYFPRINTF (stderr, "Stack now");
3372   for (/* Nothing. */; bottom <= top; ++bottom)
3373     YYFPRINTF (stderr, " %d", *bottom);
3374   YYFPRINTF (stderr, "\n");
3375 }
3376
3377 # define YY_STACK_PRINT(Bottom, Top)                            \
3378 do {                                                            \
3379   if (yydebug)                                                  \
3380     yy_stack_print ((Bottom), (Top));                           \
3381 } while (0)
3382
3383
3384 /*------------------------------------------------.
3385 | Report that the YYRULE is going to be reduced.  |
3386 `------------------------------------------------*/
3387
3388 #if defined (__STDC__) || defined (__cplusplus)
3389 static void
3390 yy_reduce_print (int yyrule)
3391 #else
3392 static void
3393 yy_reduce_print (yyrule)
3394     int yyrule;
3395 #endif
3396 {
3397   int yyi;
3398   unsigned long int yylno = yyrline[yyrule];
3399   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu), ",
3400              yyrule - 1, yylno);
3401   /* Print the symbols being reduced, and their result.  */
3402   for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
3403     YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
3404   YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyrule]]);
3405 }
3406
3407 # define YY_REDUCE_PRINT(Rule)          \
3408 do {                                    \
3409   if (yydebug)                          \
3410     yy_reduce_print (Rule);             \
3411 } while (0)
3412
3413 /* Nonzero means print parse trace.  It is left uninitialized so that
3414    multiple parsers can coexist.  */
3415 int yydebug;
3416 #else /* !YYDEBUG */
3417 # define YYDPRINTF(Args)
3418 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
3419 # define YY_STACK_PRINT(Bottom, Top)
3420 # define YY_REDUCE_PRINT(Rule)
3421 #endif /* !YYDEBUG */
3422
3423
3424 /* YYINITDEPTH -- initial size of the parser's stacks.  */
3425 #ifndef YYINITDEPTH
3426 # define YYINITDEPTH 200
3427 #endif
3428
3429 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
3430    if the built-in stack extension method is used).
3431
3432    Do not make this value too large; the results are undefined if
3433    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
3434    evaluated with infinite-precision integer arithmetic.  */
3435
3436 #ifndef YYMAXDEPTH
3437 # define YYMAXDEPTH 10000
3438 #endif
3439
3440 \f
3441
3442 #if YYERROR_VERBOSE
3443
3444 # ifndef yystrlen
3445 #  if defined (__GLIBC__) && defined (_STRING_H)
3446 #   define yystrlen strlen
3447 #  else
3448 /* Return the length of YYSTR.  */
3449 static YYSIZE_T
3450 #   if defined (__STDC__) || defined (__cplusplus)
3451 yystrlen (const char *yystr)
3452 #   else
3453 yystrlen (yystr)
3454      const char *yystr;
3455 #   endif
3456 {
3457   const char *yys = yystr;
3458
3459   while (*yys++ != '\0')
3460     continue;
3461
3462   return yys - yystr - 1;
3463 }
3464 #  endif
3465 # endif
3466
3467 # ifndef yystpcpy
3468 #  if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
3469 #   define yystpcpy stpcpy
3470 #  else
3471 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
3472    YYDEST.  */
3473 static char *
3474 #   if defined (__STDC__) || defined (__cplusplus)
3475 yystpcpy (char *yydest, const char *yysrc)
3476 #   else
3477 yystpcpy (yydest, yysrc)
3478      char *yydest;
3479      const char *yysrc;
3480 #   endif
3481 {
3482   char *yyd = yydest;
3483   const char *yys = yysrc;
3484
3485   while ((*yyd++ = *yys++) != '\0')
3486     continue;
3487
3488   return yyd - 1;
3489 }
3490 #  endif
3491 # endif
3492
3493 # ifndef yytnamerr
3494 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
3495    quotes and backslashes, so that it's suitable for yyerror.  The
3496    heuristic is that double-quoting is unnecessary unless the string
3497    contains an apostrophe, a comma, or backslash (other than
3498    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
3499    null, do not copy; instead, return the length of what the result
3500    would have been.  */
3501 static YYSIZE_T
3502 yytnamerr (char *yyres, const char *yystr)
3503 {
3504   if (*yystr == '"')
3505     {
3506       size_t yyn = 0;
3507       char const *yyp = yystr;
3508
3509       for (;;)
3510         switch (*++yyp)
3511           {
3512           case '\'':
3513           case ',':
3514             goto do_not_strip_quotes;
3515
3516           case '\\':
3517             if (*++yyp != '\\')
3518               goto do_not_strip_quotes;
3519             /* Fall through.  */
3520           default:
3521             if (yyres)
3522               yyres[yyn] = *yyp;
3523             yyn++;
3524             break;
3525
3526           case '"':
3527             if (yyres)
3528               yyres[yyn] = '\0';
3529             return yyn;
3530           }
3531     do_not_strip_quotes: ;
3532     }
3533
3534   if (! yyres)
3535     return yystrlen (yystr);
3536
3537   return yystpcpy (yyres, yystr) - yyres;
3538 }
3539 # endif
3540
3541 #endif /* YYERROR_VERBOSE */
3542
3543 \f
3544
3545 #if YYDEBUG
3546 /*--------------------------------.
3547 | Print this symbol on YYOUTPUT.  |
3548 `--------------------------------*/
3549
3550 #if defined (__STDC__) || defined (__cplusplus)
3551 static void
3552 yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
3553 #else
3554 static void
3555 yysymprint (yyoutput, yytype, yyvaluep)
3556     FILE *yyoutput;
3557     int yytype;
3558     YYSTYPE *yyvaluep;
3559 #endif
3560 {
3561   /* Pacify ``unused variable'' warnings.  */
3562   (void) yyvaluep;
3563
3564   if (yytype < YYNTOKENS)
3565     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
3566   else
3567     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
3568
3569
3570 # ifdef YYPRINT
3571   if (yytype < YYNTOKENS)
3572     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
3573 # endif
3574   switch (yytype)
3575     {
3576       default:
3577         break;
3578     }
3579   YYFPRINTF (yyoutput, ")");
3580 }
3581
3582 #endif /* ! YYDEBUG */
3583 /*-----------------------------------------------.
3584 | Release the memory associated to this symbol.  |
3585 `-----------------------------------------------*/
3586
3587 #if defined (__STDC__) || defined (__cplusplus)
3588 static void
3589 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
3590 #else
3591 static void
3592 yydestruct (yymsg, yytype, yyvaluep)
3593     const char *yymsg;
3594     int yytype;
3595     YYSTYPE *yyvaluep;
3596 #endif
3597 {
3598   /* Pacify ``unused variable'' warnings.  */
3599   (void) yyvaluep;
3600
3601   if (!yymsg)
3602     yymsg = "Deleting";
3603   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
3604
3605   switch (yytype)
3606     {
3607
3608       default:
3609         break;
3610     }
3611 }
3612 \f
3613
3614 /* Prevent warnings from -Wmissing-prototypes.  */
3615
3616 #ifdef YYPARSE_PARAM
3617 # if defined (__STDC__) || defined (__cplusplus)
3618 int yyparse (void *YYPARSE_PARAM);
3619 # else
3620 int yyparse ();
3621 # endif
3622 #else /* ! YYPARSE_PARAM */
3623 #if defined (__STDC__) || defined (__cplusplus)
3624 int yyparse (void);
3625 #else
3626 int yyparse ();
3627 #endif
3628 #endif /* ! YYPARSE_PARAM */
3629
3630
3631
3632 /* The look-ahead symbol.  */
3633 int yychar;
3634
3635 /* The semantic value of the look-ahead symbol.  */
3636 YYSTYPE yylval;
3637
3638 /* Number of syntax errors so far.  */
3639 int yynerrs;
3640
3641
3642
3643 /*----------.
3644 | yyparse.  |
3645 `----------*/
3646
3647 #ifdef YYPARSE_PARAM
3648 # if defined (__STDC__) || defined (__cplusplus)
3649 int yyparse (void *YYPARSE_PARAM)
3650 # else
3651 int yyparse (YYPARSE_PARAM)
3652   void *YYPARSE_PARAM;
3653 # endif
3654 #else /* ! YYPARSE_PARAM */
3655 #if defined (__STDC__) || defined (__cplusplus)
3656 int
3657 yyparse (void)
3658 #else
3659 int
3660 yyparse ()
3661
3662 #endif
3663 #endif
3664 {
3665   
3666   int yystate;
3667   int yyn;
3668   int yyresult;
3669   /* Number of tokens to shift before error messages enabled.  */
3670   int yyerrstatus;
3671   /* Look-ahead token as an internal (translated) token number.  */
3672   int yytoken = 0;
3673
3674   /* Three stacks and their tools:
3675      `yyss': related to states,
3676      `yyvs': related to semantic values,
3677      `yyls': related to locations.
3678
3679      Refer to the stacks thru separate pointers, to allow yyoverflow
3680      to reallocate them elsewhere.  */
3681
3682   /* The state stack.  */
3683   short int yyssa[YYINITDEPTH];
3684   short int *yyss = yyssa;
3685   short int *yyssp;
3686
3687   /* The semantic value stack.  */
3688   YYSTYPE yyvsa[YYINITDEPTH];
3689   YYSTYPE *yyvs = yyvsa;
3690   YYSTYPE *yyvsp;
3691
3692
3693
3694 #define YYPOPSTACK   (yyvsp--, yyssp--)
3695
3696   YYSIZE_T yystacksize = YYINITDEPTH;
3697
3698   /* The variables used to return semantic value and location from the
3699      action routines.  */
3700   YYSTYPE yyval;
3701
3702
3703   /* When reducing, the number of symbols on the RHS of the reduced
3704      rule.  */
3705   int yylen;
3706
3707   YYDPRINTF ((stderr, "Starting parse\n"));
3708
3709   yystate = 0;
3710   yyerrstatus = 0;
3711   yynerrs = 0;
3712   yychar = YYEMPTY;             /* Cause a token to be read.  */
3713
3714   /* Initialize stack pointers.
3715      Waste one element of value and location stack
3716      so that they stay on the same level as the state stack.
3717      The wasted elements are never initialized.  */
3718
3719   yyssp = yyss;
3720   yyvsp = yyvs;
3721
3722   goto yysetstate;
3723
3724 /*------------------------------------------------------------.
3725 | yynewstate -- Push a new state, which is found in yystate.  |
3726 `------------------------------------------------------------*/
3727  yynewstate:
3728   /* In all cases, when you get here, the value and location stacks
3729      have just been pushed. so pushing a state here evens the stacks.
3730      */
3731   yyssp++;
3732
3733  yysetstate:
3734   *yyssp = yystate;
3735
3736   if (yyss + yystacksize - 1 <= yyssp)
3737     {
3738       /* Get the current used size of the three stacks, in elements.  */
3739       YYSIZE_T yysize = yyssp - yyss + 1;
3740
3741 #ifdef yyoverflow
3742       {
3743         /* Give user a chance to reallocate the stack. Use copies of
3744            these so that the &'s don't force the real ones into
3745            memory.  */
3746         YYSTYPE *yyvs1 = yyvs;
3747         short int *yyss1 = yyss;
3748
3749
3750         /* Each stack pointer address is followed by the size of the
3751            data in use in that stack, in bytes.  This used to be a
3752            conditional around just the two extra args, but that might
3753            be undefined if yyoverflow is a macro.  */
3754         yyoverflow (YY_("memory exhausted"),
3755                     &yyss1, yysize * sizeof (*yyssp),
3756                     &yyvs1, yysize * sizeof (*yyvsp),
3757
3758                     &yystacksize);
3759
3760         yyss = yyss1;
3761         yyvs = yyvs1;
3762       }
3763 #else /* no yyoverflow */
3764 # ifndef YYSTACK_RELOCATE
3765       goto yyexhaustedlab;
3766 # else
3767       /* Extend the stack our own way.  */
3768       if (YYMAXDEPTH <= yystacksize)
3769         goto yyexhaustedlab;
3770       yystacksize *= 2;
3771       if (YYMAXDEPTH < yystacksize)
3772         yystacksize = YYMAXDEPTH;
3773
3774       {
3775         short int *yyss1 = yyss;
3776         union yyalloc *yyptr =
3777           (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
3778         if (! yyptr)
3779           goto yyexhaustedlab;
3780         YYSTACK_RELOCATE (yyss);
3781         YYSTACK_RELOCATE (yyvs);
3782
3783 #  undef YYSTACK_RELOCATE
3784         if (yyss1 != yyssa)
3785           YYSTACK_FREE (yyss1);
3786       }
3787 # endif
3788 #endif /* no yyoverflow */
3789
3790       yyssp = yyss + yysize - 1;
3791       yyvsp = yyvs + yysize - 1;
3792
3793
3794       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
3795                   (unsigned long int) yystacksize));
3796
3797       if (yyss + yystacksize - 1 <= yyssp)
3798         YYABORT;
3799     }
3800
3801   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
3802
3803   goto yybackup;
3804
3805 /*-----------.
3806 | yybackup.  |
3807 `-----------*/
3808 yybackup:
3809
3810 /* Do appropriate processing given the current state.  */
3811 /* Read a look-ahead token if we need one and don't already have one.  */
3812 /* yyresume: */
3813
3814   /* First try to decide what to do without reference to look-ahead token.  */
3815
3816   yyn = yypact[yystate];
3817   if (yyn == YYPACT_NINF)
3818     goto yydefault;
3819
3820   /* Not known => get a look-ahead token if don't already have one.  */
3821
3822   /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
3823   if (yychar == YYEMPTY)
3824     {
3825       YYDPRINTF ((stderr, "Reading a token: "));
3826       yychar = YYLEX;
3827     }
3828
3829   if (yychar <= YYEOF)
3830     {
3831       yychar = yytoken = YYEOF;
3832       YYDPRINTF ((stderr, "Now at end of input.\n"));
3833     }
3834   else
3835     {
3836       yytoken = YYTRANSLATE (yychar);
3837       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
3838     }
3839
3840   /* If the proper action on seeing token YYTOKEN is to reduce or to
3841      detect an error, take that action.  */
3842   yyn += yytoken;
3843   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
3844     goto yydefault;
3845   yyn = yytable[yyn];
3846   if (yyn <= 0)
3847     {
3848       if (yyn == 0 || yyn == YYTABLE_NINF)
3849         goto yyerrlab;
3850       yyn = -yyn;
3851       goto yyreduce;
3852     }
3853
3854   if (yyn == YYFINAL)
3855     YYACCEPT;
3856
3857   /* Shift the look-ahead token.  */
3858   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
3859
3860   /* Discard the token being shifted unless it is eof.  */
3861   if (yychar != YYEOF)
3862     yychar = YYEMPTY;
3863
3864   *++yyvsp = yylval;
3865
3866
3867   /* Count tokens shifted since error; after three, turn off error
3868      status.  */
3869   if (yyerrstatus)
3870     yyerrstatus--;
3871
3872   yystate = yyn;
3873   goto yynewstate;
3874
3875
3876 /*-----------------------------------------------------------.
3877 | yydefault -- do the default action for the current state.  |
3878 `-----------------------------------------------------------*/
3879 yydefault:
3880   yyn = yydefact[yystate];
3881   if (yyn == 0)
3882     goto yyerrlab;
3883   goto yyreduce;
3884
3885
3886 /*-----------------------------.
3887 | yyreduce -- Do a reduction.  |
3888 `-----------------------------*/
3889 yyreduce:
3890   /* yyn is the number of a rule to reduce with.  */
3891   yylen = yyr2[yyn];
3892
3893   /* If YYLEN is nonzero, implement the default value of the action:
3894      `$$ = $1'.
3895
3896      Otherwise, the following line sets YYVAL to garbage.
3897      This behavior is undocumented and Bison
3898      users should not rely upon it.  Assigning to YYVAL
3899      unconditionally makes the parser a bit smaller, and it avoids a
3900      GCC warning that YYVAL may be used uninitialized.  */
3901   yyval = yyvsp[1-yylen];
3902
3903
3904   YY_REDUCE_PRINT (yyn);
3905   switch (yyn)
3906     {
3907         case 3:
3908 #line 1834 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3909     {
3910     if ((yyvsp[0].UIntVal) > (uint32_t)INT32_MAX)     // Outside of my range!
3911       error("Value too large for type");
3912     (yyval.SIntVal) = (int32_t)(yyvsp[0].UIntVal);
3913   ;}
3914     break;
3915
3916   case 5:
3917 #line 1843 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3918     {
3919     if ((yyvsp[0].UInt64Val) > (uint64_t)INT64_MAX)     // Outside of my range!
3920       error("Value too large for type");
3921     (yyval.SInt64Val) = (int64_t)(yyvsp[0].UInt64Val);
3922   ;}
3923     break;
3924
3925   case 26:
3926 #line 1865 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3927     { (yyval.IPred) = ICmpInst::ICMP_EQ; ;}
3928     break;
3929
3930   case 27:
3931 #line 1865 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3932     { (yyval.IPred) = ICmpInst::ICMP_NE; ;}
3933     break;
3934
3935   case 28:
3936 #line 1866 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3937     { (yyval.IPred) = ICmpInst::ICMP_SLT; ;}
3938     break;
3939
3940   case 29:
3941 #line 1866 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3942     { (yyval.IPred) = ICmpInst::ICMP_SGT; ;}
3943     break;
3944
3945   case 30:
3946 #line 1867 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3947     { (yyval.IPred) = ICmpInst::ICMP_SLE; ;}
3948     break;
3949
3950   case 31:
3951 #line 1867 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3952     { (yyval.IPred) = ICmpInst::ICMP_SGE; ;}
3953     break;
3954
3955   case 32:
3956 #line 1868 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3957     { (yyval.IPred) = ICmpInst::ICMP_ULT; ;}
3958     break;
3959
3960   case 33:
3961 #line 1868 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3962     { (yyval.IPred) = ICmpInst::ICMP_UGT; ;}
3963     break;
3964
3965   case 34:
3966 #line 1869 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3967     { (yyval.IPred) = ICmpInst::ICMP_ULE; ;}
3968     break;
3969
3970   case 35:
3971 #line 1869 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3972     { (yyval.IPred) = ICmpInst::ICMP_UGE; ;}
3973     break;
3974
3975   case 36:
3976 #line 1873 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3977     { (yyval.FPred) = FCmpInst::FCMP_OEQ; ;}
3978     break;
3979
3980   case 37:
3981 #line 1873 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3982     { (yyval.FPred) = FCmpInst::FCMP_ONE; ;}
3983     break;
3984
3985   case 38:
3986 #line 1874 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3987     { (yyval.FPred) = FCmpInst::FCMP_OLT; ;}
3988     break;
3989
3990   case 39:
3991 #line 1874 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3992     { (yyval.FPred) = FCmpInst::FCMP_OGT; ;}
3993     break;
3994
3995   case 40:
3996 #line 1875 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
3997     { (yyval.FPred) = FCmpInst::FCMP_OLE; ;}
3998     break;
3999
4000   case 41:
4001 #line 1875 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4002     { (yyval.FPred) = FCmpInst::FCMP_OGE; ;}
4003     break;
4004
4005   case 42:
4006 #line 1876 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4007     { (yyval.FPred) = FCmpInst::FCMP_ORD; ;}
4008     break;
4009
4010   case 43:
4011 #line 1876 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4012     { (yyval.FPred) = FCmpInst::FCMP_UNO; ;}
4013     break;
4014
4015   case 44:
4016 #line 1877 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4017     { (yyval.FPred) = FCmpInst::FCMP_UEQ; ;}
4018     break;
4019
4020   case 45:
4021 #line 1877 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4022     { (yyval.FPred) = FCmpInst::FCMP_UNE; ;}
4023     break;
4024
4025   case 46:
4026 #line 1878 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4027     { (yyval.FPred) = FCmpInst::FCMP_ULT; ;}
4028     break;
4029
4030   case 47:
4031 #line 1878 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4032     { (yyval.FPred) = FCmpInst::FCMP_UGT; ;}
4033     break;
4034
4035   case 48:
4036 #line 1879 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4037     { (yyval.FPred) = FCmpInst::FCMP_ULE; ;}
4038     break;
4039
4040   case 49:
4041 #line 1879 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4042     { (yyval.FPred) = FCmpInst::FCMP_UGE; ;}
4043     break;
4044
4045   case 50:
4046 #line 1880 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4047     { (yyval.FPred) = FCmpInst::FCMP_TRUE; ;}
4048     break;
4049
4050   case 51:
4051 #line 1881 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4052     { (yyval.FPred) = FCmpInst::FCMP_FALSE; ;}
4053     break;
4054
4055   case 81:
4056 #line 1912 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4057     {
4058     (yyval.StrVal) = (yyvsp[-1].StrVal);
4059   ;}
4060     break;
4061
4062   case 82:
4063 #line 1915 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4064     {
4065     (yyval.StrVal) = 0;
4066   ;}
4067     break;
4068
4069   case 83:
4070 #line 1920 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4071     { (yyval.Linkage) = GlobalValue::InternalLinkage; ;}
4072     break;
4073
4074   case 84:
4075 #line 1921 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4076     { (yyval.Linkage) = GlobalValue::LinkOnceLinkage; ;}
4077     break;
4078
4079   case 85:
4080 #line 1922 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4081     { (yyval.Linkage) = GlobalValue::WeakLinkage; ;}
4082     break;
4083
4084   case 86:
4085 #line 1923 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4086     { (yyval.Linkage) = GlobalValue::AppendingLinkage; ;}
4087     break;
4088
4089   case 87:
4090 #line 1924 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4091     { (yyval.Linkage) = GlobalValue::DLLImportLinkage; ;}
4092     break;
4093
4094   case 88:
4095 #line 1925 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4096     { (yyval.Linkage) = GlobalValue::DLLExportLinkage; ;}
4097     break;
4098
4099   case 89:
4100 #line 1926 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4101     { (yyval.Linkage) = GlobalValue::ExternalWeakLinkage; ;}
4102     break;
4103
4104   case 90:
4105 #line 1927 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4106     { (yyval.Linkage) = GlobalValue::ExternalLinkage; ;}
4107     break;
4108
4109   case 91:
4110 #line 1931 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4111     { (yyval.UIntVal) = OldCallingConv::C; ;}
4112     break;
4113
4114   case 92:
4115 #line 1932 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4116     { (yyval.UIntVal) = OldCallingConv::C; ;}
4117     break;
4118
4119   case 93:
4120 #line 1933 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4121     { (yyval.UIntVal) = OldCallingConv::CSRet; ;}
4122     break;
4123
4124   case 94:
4125 #line 1934 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4126     { (yyval.UIntVal) = OldCallingConv::Fast; ;}
4127     break;
4128
4129   case 95:
4130 #line 1935 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4131     { (yyval.UIntVal) = OldCallingConv::Cold; ;}
4132     break;
4133
4134   case 96:
4135 #line 1936 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4136     { (yyval.UIntVal) = OldCallingConv::X86_StdCall; ;}
4137     break;
4138
4139   case 97:
4140 #line 1937 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4141     { (yyval.UIntVal) = OldCallingConv::X86_FastCall; ;}
4142     break;
4143
4144   case 98:
4145 #line 1938 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4146     {
4147     if ((unsigned)(yyvsp[0].UInt64Val) != (yyvsp[0].UInt64Val))
4148       error("Calling conv too large");
4149     (yyval.UIntVal) = (yyvsp[0].UInt64Val);
4150   ;}
4151     break;
4152
4153   case 99:
4154 #line 1948 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4155     { (yyval.UIntVal) = 0; ;}
4156     break;
4157
4158   case 100:
4159 #line 1949 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4160     {
4161     (yyval.UIntVal) = (yyvsp[0].UInt64Val);
4162     if ((yyval.UIntVal) != 0 && !isPowerOf2_32((yyval.UIntVal)))
4163       error("Alignment must be a power of two");
4164   ;}
4165     break;
4166
4167   case 101:
4168 #line 1957 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4169     { (yyval.UIntVal) = 0; ;}
4170     break;
4171
4172   case 102:
4173 #line 1958 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4174     {
4175     (yyval.UIntVal) = (yyvsp[0].UInt64Val);
4176     if ((yyval.UIntVal) != 0 && !isPowerOf2_32((yyval.UIntVal)))
4177       error("Alignment must be a power of two");
4178   ;}
4179     break;
4180
4181   case 103:
4182 #line 1966 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4183     {
4184     for (unsigned i = 0, e = strlen((yyvsp[0].StrVal)); i != e; ++i)
4185       if ((yyvsp[0].StrVal)[i] == '"' || (yyvsp[0].StrVal)[i] == '\\')
4186         error("Invalid character in section name");
4187     (yyval.StrVal) = (yyvsp[0].StrVal);
4188   ;}
4189     break;
4190
4191   case 104:
4192 #line 1975 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4193     { (yyval.StrVal) = 0; ;}
4194     break;
4195
4196   case 105:
4197 #line 1976 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4198     { (yyval.StrVal) = (yyvsp[0].StrVal); ;}
4199     break;
4200
4201   case 106:
4202 #line 1983 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4203     {;}
4204     break;
4205
4206   case 107:
4207 #line 1984 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4208     {;}
4209     break;
4210
4211   case 108:
4212 #line 1988 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4213     {
4214     CurGV->setSection((yyvsp[0].StrVal));
4215     free((yyvsp[0].StrVal));
4216   ;}
4217     break;
4218
4219   case 109:
4220 #line 1992 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4221     {
4222     if ((yyvsp[0].UInt64Val) != 0 && !isPowerOf2_32((yyvsp[0].UInt64Val)))
4223       error("Alignment must be a power of two");
4224     CurGV->setAlignment((yyvsp[0].UInt64Val));
4225     
4226   ;}
4227     break;
4228
4229   case 111:
4230 #line 2009 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4231     { 
4232     (yyval.TypeVal).PAT = new PATypeHolder((yyvsp[0].PrimType).T); 
4233     (yyval.TypeVal).S.makeSignless();
4234   ;}
4235     break;
4236
4237   case 113:
4238 #line 2017 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4239     { 
4240     (yyval.TypeVal).PAT = new PATypeHolder((yyvsp[0].PrimType).T); 
4241     (yyval.TypeVal).S.makeSignless();
4242   ;}
4243     break;
4244
4245   case 114:
4246 #line 2024 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4247     {
4248     if (!UpRefs.empty())
4249       error("Invalid upreference in type: " + (*(yyvsp[0].TypeVal).PAT)->getDescription());
4250     (yyval.TypeVal) = (yyvsp[0].TypeVal);
4251   ;}
4252     break;
4253
4254   case 127:
4255 #line 2038 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4256     { 
4257     (yyval.TypeVal).PAT = new PATypeHolder((yyvsp[0].PrimType).T);
4258     (yyval.TypeVal).S.copy((yyvsp[0].PrimType).S);
4259   ;}
4260     break;
4261
4262   case 128:
4263 #line 2042 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4264     {
4265     (yyval.TypeVal).PAT = new PATypeHolder(OpaqueType::get());
4266     (yyval.TypeVal).S.makeSignless();
4267   ;}
4268     break;
4269
4270   case 129:
4271 #line 2046 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4272     {            // Named types are also simple types...
4273     (yyval.TypeVal).S.copy(getTypeSign((yyvsp[0].ValIDVal)));
4274     const Type* tmp = getType((yyvsp[0].ValIDVal));
4275     (yyval.TypeVal).PAT = new PATypeHolder(tmp);
4276   ;}
4277     break;
4278
4279   case 130:
4280 #line 2051 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4281     {                   // Type UpReference
4282     if ((yyvsp[0].UInt64Val) > (uint64_t)~0U) 
4283       error("Value out of range");
4284     OpaqueType *OT = OpaqueType::get();        // Use temporary placeholder
4285     UpRefs.push_back(UpRefRecord((unsigned)(yyvsp[0].UInt64Val), OT));  // Add to vector...
4286     (yyval.TypeVal).PAT = new PATypeHolder(OT);
4287     (yyval.TypeVal).S.makeSignless();
4288     UR_OUT("New Upreference!\n");
4289   ;}
4290     break;
4291
4292   case 131:
4293 #line 2060 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4294     {           // Function derived type?
4295     (yyval.TypeVal).S.makeComposite((yyvsp[-3].TypeVal).S);
4296     std::vector<const Type*> Params;
4297     for (std::list<llvm::PATypeInfo>::iterator I = (yyvsp[-1].TypeList)->begin(),
4298            E = (yyvsp[-1].TypeList)->end(); I != E; ++I) {
4299       Params.push_back(I->PAT->get());
4300       (yyval.TypeVal).S.add(I->S);
4301     }
4302     FunctionType::ParamAttrsList ParamAttrs;
4303     bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
4304     if (isVarArg) Params.pop_back();
4305
4306     (yyval.TypeVal).PAT = new PATypeHolder(
4307       HandleUpRefs(FunctionType::get((yyvsp[-3].TypeVal).PAT->get(), Params, isVarArg, 
4308                    ParamAttrs), (yyval.TypeVal).S));
4309     delete (yyvsp[-3].TypeVal).PAT;  // Delete the return type handle
4310     delete (yyvsp[-1].TypeList);      // Delete the argument list
4311   ;}
4312     break;
4313
4314   case 132:
4315 #line 2078 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4316     {          // Sized array type?
4317     (yyval.TypeVal).S.makeComposite((yyvsp[-1].TypeVal).S);
4318     (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(ArrayType::get((yyvsp[-1].TypeVal).PAT->get(), 
4319                                            (unsigned)(yyvsp[-3].UInt64Val)), (yyval.TypeVal).S));
4320     delete (yyvsp[-1].TypeVal).PAT;
4321   ;}
4322     break;
4323
4324   case 133:
4325 #line 2084 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4326     {          // Vector type?
4327     const llvm::Type* ElemTy = (yyvsp[-1].TypeVal).PAT->get();
4328     if ((unsigned)(yyvsp[-3].UInt64Val) != (yyvsp[-3].UInt64Val))
4329        error("Unsigned result not equal to signed result");
4330     if (!(ElemTy->isInteger() || ElemTy->isFloatingPoint()))
4331        error("Elements of a VectorType must be integer or floating point");
4332     if (!isPowerOf2_32((yyvsp[-3].UInt64Val)))
4333       error("VectorType length should be a power of 2");
4334     (yyval.TypeVal).S.makeComposite((yyvsp[-1].TypeVal).S);
4335     (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(VectorType::get(ElemTy, 
4336                                          (unsigned)(yyvsp[-3].UInt64Val)), (yyval.TypeVal).S));
4337     delete (yyvsp[-1].TypeVal).PAT;
4338   ;}
4339     break;
4340
4341   case 134:
4342 #line 2097 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4343     {                        // Structure type?
4344     std::vector<const Type*> Elements;
4345     (yyval.TypeVal).S.makeComposite();
4346     for (std::list<llvm::PATypeInfo>::iterator I = (yyvsp[-1].TypeList)->begin(),
4347            E = (yyvsp[-1].TypeList)->end(); I != E; ++I) {
4348       Elements.push_back(I->PAT->get());
4349       (yyval.TypeVal).S.add(I->S);
4350     }
4351     (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements), (yyval.TypeVal).S));
4352     delete (yyvsp[-1].TypeList);
4353   ;}
4354     break;
4355
4356   case 135:
4357 #line 2108 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4358     {                                  // Empty structure type?
4359     (yyval.TypeVal).PAT = new PATypeHolder(StructType::get(std::vector<const Type*>()));
4360     (yyval.TypeVal).S.makeComposite();
4361   ;}
4362     break;
4363
4364   case 136:
4365 #line 2112 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4366     {                // Packed Structure type?
4367     (yyval.TypeVal).S.makeComposite();
4368     std::vector<const Type*> Elements;
4369     for (std::list<llvm::PATypeInfo>::iterator I = (yyvsp[-2].TypeList)->begin(),
4370            E = (yyvsp[-2].TypeList)->end(); I != E; ++I) {
4371       Elements.push_back(I->PAT->get());
4372       (yyval.TypeVal).S.add(I->S);
4373       delete I->PAT;
4374     }
4375     (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements, true), 
4376                                            (yyval.TypeVal).S));
4377     delete (yyvsp[-2].TypeList);
4378   ;}
4379     break;
4380
4381   case 137:
4382 #line 2125 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4383     {                          // Empty packed structure type?
4384     (yyval.TypeVal).PAT = new PATypeHolder(StructType::get(std::vector<const Type*>(),true));
4385     (yyval.TypeVal).S.makeComposite();
4386   ;}
4387     break;
4388
4389   case 138:
4390 #line 2129 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4391     {                             // Pointer type?
4392     if ((yyvsp[-1].TypeVal).PAT->get() == Type::LabelTy)
4393       error("Cannot form a pointer to a basic block");
4394     (yyval.TypeVal).S.makeComposite((yyvsp[-1].TypeVal).S);
4395     (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(PointerType::get((yyvsp[-1].TypeVal).PAT->get()),
4396                                            (yyval.TypeVal).S));
4397     delete (yyvsp[-1].TypeVal).PAT;
4398   ;}
4399     break;
4400
4401   case 139:
4402 #line 2143 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4403     {
4404     (yyval.TypeList) = new std::list<PATypeInfo>();
4405     (yyval.TypeList)->push_back((yyvsp[0].TypeVal)); 
4406   ;}
4407     break;
4408
4409   case 140:
4410 #line 2147 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4411     {
4412     ((yyval.TypeList)=(yyvsp[-2].TypeList))->push_back((yyvsp[0].TypeVal));
4413   ;}
4414     break;
4415
4416   case 142:
4417 #line 2155 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4418     {
4419     PATypeInfo VoidTI;
4420     VoidTI.PAT = new PATypeHolder(Type::VoidTy);
4421     VoidTI.S.makeSignless();
4422     ((yyval.TypeList)=(yyvsp[-2].TypeList))->push_back(VoidTI);
4423   ;}
4424     break;
4425
4426   case 143:
4427 #line 2161 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4428     {
4429     (yyval.TypeList) = new std::list<PATypeInfo>();
4430     PATypeInfo VoidTI;
4431     VoidTI.PAT = new PATypeHolder(Type::VoidTy);
4432     VoidTI.S.makeSignless();
4433     (yyval.TypeList)->push_back(VoidTI);
4434   ;}
4435     break;
4436
4437   case 144:
4438 #line 2168 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4439     {
4440     (yyval.TypeList) = new std::list<PATypeInfo>();
4441   ;}
4442     break;
4443
4444   case 145:
4445 #line 2180 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4446     { // Nonempty unsized arr
4447     const ArrayType *ATy = dyn_cast<ArrayType>((yyvsp[-3].TypeVal).PAT->get());
4448     if (ATy == 0)
4449       error("Cannot make array constant with type: '" + 
4450             (yyvsp[-3].TypeVal).PAT->get()->getDescription() + "'");
4451     const Type *ETy = ATy->getElementType();
4452     int NumElements = ATy->getNumElements();
4453
4454     // Verify that we have the correct size...
4455     if (NumElements != -1 && NumElements != (int)(yyvsp[-1].ConstVector)->size())
4456       error("Type mismatch: constant sized array initialized with " +
4457             utostr((yyvsp[-1].ConstVector)->size()) +  " arguments, but has size of " + 
4458             itostr(NumElements) + "");
4459
4460     // Verify all elements are correct type!
4461     std::vector<Constant*> Elems;
4462     for (unsigned i = 0; i < (yyvsp[-1].ConstVector)->size(); i++) {
4463       Constant *C = (*(yyvsp[-1].ConstVector))[i].C;
4464       const Type* ValTy = C->getType();
4465       if (ETy != ValTy)
4466         error("Element #" + utostr(i) + " is not of type '" + 
4467               ETy->getDescription() +"' as required!\nIt is of type '"+
4468               ValTy->getDescription() + "'");
4469       Elems.push_back(C);
4470     }
4471     (yyval.ConstVal).C = ConstantArray::get(ATy, Elems);
4472     (yyval.ConstVal).S.copy((yyvsp[-3].TypeVal).S);
4473     delete (yyvsp[-3].TypeVal).PAT; 
4474     delete (yyvsp[-1].ConstVector);
4475   ;}
4476     break;
4477
4478   case 146:
4479 #line 2210 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4480     {
4481     const ArrayType *ATy = dyn_cast<ArrayType>((yyvsp[-2].TypeVal).PAT->get());
4482     if (ATy == 0)
4483       error("Cannot make array constant with type: '" + 
4484             (yyvsp[-2].TypeVal).PAT->get()->getDescription() + "'");
4485     int NumElements = ATy->getNumElements();
4486     if (NumElements != -1 && NumElements != 0) 
4487       error("Type mismatch: constant sized array initialized with 0"
4488             " arguments, but has size of " + itostr(NumElements) +"");
4489     (yyval.ConstVal).C = ConstantArray::get(ATy, std::vector<Constant*>());
4490     (yyval.ConstVal).S.copy((yyvsp[-2].TypeVal).S);
4491     delete (yyvsp[-2].TypeVal).PAT;
4492   ;}
4493     break;
4494
4495   case 147:
4496 #line 2223 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4497     {
4498     const ArrayType *ATy = dyn_cast<ArrayType>((yyvsp[-2].TypeVal).PAT->get());
4499     if (ATy == 0)
4500       error("Cannot make array constant with type: '" + 
4501             (yyvsp[-2].TypeVal).PAT->get()->getDescription() + "'");
4502     int NumElements = ATy->getNumElements();
4503     const Type *ETy = dyn_cast<IntegerType>(ATy->getElementType());
4504     if (!ETy || cast<IntegerType>(ETy)->getBitWidth() != 8)
4505       error("String arrays require type i8, not '" + ETy->getDescription() + 
4506             "'");
4507     char *EndStr = UnEscapeLexed((yyvsp[0].StrVal), true);
4508     if (NumElements != -1 && NumElements != (EndStr-(yyvsp[0].StrVal)))
4509       error("Can't build string constant of size " + 
4510             itostr((int)(EndStr-(yyvsp[0].StrVal))) + " when array has size " + 
4511             itostr(NumElements) + "");
4512     std::vector<Constant*> Vals;
4513     for (char *C = (char *)(yyvsp[0].StrVal); C != (char *)EndStr; ++C)
4514       Vals.push_back(ConstantInt::get(ETy, *C));
4515     free((yyvsp[0].StrVal));
4516     (yyval.ConstVal).C = ConstantArray::get(ATy, Vals);
4517     (yyval.ConstVal).S.copy((yyvsp[-2].TypeVal).S);
4518     delete (yyvsp[-2].TypeVal).PAT;
4519   ;}
4520     break;
4521
4522   case 148:
4523 #line 2246 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4524     { // Nonempty unsized arr
4525     const VectorType *PTy = dyn_cast<VectorType>((yyvsp[-3].TypeVal).PAT->get());
4526     if (PTy == 0)
4527       error("Cannot make packed constant with type: '" + 
4528             (yyvsp[-3].TypeVal).PAT->get()->getDescription() + "'");
4529     const Type *ETy = PTy->getElementType();
4530     int NumElements = PTy->getNumElements();
4531     // Verify that we have the correct size...
4532     if (NumElements != -1 && NumElements != (int)(yyvsp[-1].ConstVector)->size())
4533       error("Type mismatch: constant sized packed initialized with " +
4534             utostr((yyvsp[-1].ConstVector)->size()) +  " arguments, but has size of " + 
4535             itostr(NumElements) + "");
4536     // Verify all elements are correct type!
4537     std::vector<Constant*> Elems;
4538     for (unsigned i = 0; i < (yyvsp[-1].ConstVector)->size(); i++) {
4539       Constant *C = (*(yyvsp[-1].ConstVector))[i].C;
4540       const Type* ValTy = C->getType();
4541       if (ETy != ValTy)
4542         error("Element #" + utostr(i) + " is not of type '" + 
4543               ETy->getDescription() +"' as required!\nIt is of type '"+
4544               ValTy->getDescription() + "'");
4545       Elems.push_back(C);
4546     }
4547     (yyval.ConstVal).C = ConstantVector::get(PTy, Elems);
4548     (yyval.ConstVal).S.copy((yyvsp[-3].TypeVal).S);
4549     delete (yyvsp[-3].TypeVal).PAT;
4550     delete (yyvsp[-1].ConstVector);
4551   ;}
4552     break;
4553
4554   case 149:
4555 #line 2274 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4556     {
4557     const StructType *STy = dyn_cast<StructType>((yyvsp[-3].TypeVal).PAT->get());
4558     if (STy == 0)
4559       error("Cannot make struct constant with type: '" + 
4560             (yyvsp[-3].TypeVal).PAT->get()->getDescription() + "'");
4561     if ((yyvsp[-1].ConstVector)->size() != STy->getNumContainedTypes())
4562       error("Illegal number of initializers for structure type");
4563
4564     // Check to ensure that constants are compatible with the type initializer!
4565     std::vector<Constant*> Fields;
4566     for (unsigned i = 0, e = (yyvsp[-1].ConstVector)->size(); i != e; ++i) {
4567       Constant *C = (*(yyvsp[-1].ConstVector))[i].C;
4568       if (C->getType() != STy->getElementType(i))
4569         error("Expected type '" + STy->getElementType(i)->getDescription() +
4570               "' for element #" + utostr(i) + " of structure initializer");
4571       Fields.push_back(C);
4572     }
4573     (yyval.ConstVal).C = ConstantStruct::get(STy, Fields);
4574     (yyval.ConstVal).S.copy((yyvsp[-3].TypeVal).S);
4575     delete (yyvsp[-3].TypeVal).PAT;
4576     delete (yyvsp[-1].ConstVector);
4577   ;}
4578     break;
4579
4580   case 150:
4581 #line 2296 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4582     {
4583     const StructType *STy = dyn_cast<StructType>((yyvsp[-2].TypeVal).PAT->get());
4584     if (STy == 0)
4585       error("Cannot make struct constant with type: '" + 
4586               (yyvsp[-2].TypeVal).PAT->get()->getDescription() + "'");
4587     if (STy->getNumContainedTypes() != 0)
4588       error("Illegal number of initializers for structure type");
4589     (yyval.ConstVal).C = ConstantStruct::get(STy, std::vector<Constant*>());
4590     (yyval.ConstVal).S.copy((yyvsp[-2].TypeVal).S);
4591     delete (yyvsp[-2].TypeVal).PAT;
4592   ;}
4593     break;
4594
4595   case 151:
4596 #line 2307 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4597     {
4598     const StructType *STy = dyn_cast<StructType>((yyvsp[-5].TypeVal).PAT->get());
4599     if (STy == 0)
4600       error("Cannot make packed struct constant with type: '" + 
4601             (yyvsp[-5].TypeVal).PAT->get()->getDescription() + "'");
4602     if ((yyvsp[-2].ConstVector)->size() != STy->getNumContainedTypes())
4603       error("Illegal number of initializers for packed structure type");
4604
4605     // Check to ensure that constants are compatible with the type initializer!
4606     std::vector<Constant*> Fields;
4607     for (unsigned i = 0, e = (yyvsp[-2].ConstVector)->size(); i != e; ++i) {
4608       Constant *C = (*(yyvsp[-2].ConstVector))[i].C;
4609       if (C->getType() != STy->getElementType(i))
4610         error("Expected type '" + STy->getElementType(i)->getDescription() +
4611               "' for element #" + utostr(i) + " of packed struct initializer");
4612       Fields.push_back(C);
4613     }
4614     (yyval.ConstVal).C = ConstantStruct::get(STy, Fields);
4615     (yyval.ConstVal).S.copy((yyvsp[-5].TypeVal).S);
4616     delete (yyvsp[-5].TypeVal).PAT; 
4617     delete (yyvsp[-2].ConstVector);
4618   ;}
4619     break;
4620
4621   case 152:
4622 #line 2329 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4623     {
4624     const StructType *STy = dyn_cast<StructType>((yyvsp[-4].TypeVal).PAT->get());
4625     if (STy == 0)
4626       error("Cannot make packed struct constant with type: '" + 
4627               (yyvsp[-4].TypeVal).PAT->get()->getDescription() + "'");
4628     if (STy->getNumContainedTypes() != 0)
4629       error("Illegal number of initializers for packed structure type");
4630     (yyval.ConstVal).C = ConstantStruct::get(STy, std::vector<Constant*>());
4631     (yyval.ConstVal).S.copy((yyvsp[-4].TypeVal).S);
4632     delete (yyvsp[-4].TypeVal).PAT;
4633   ;}
4634     break;
4635
4636   case 153:
4637 #line 2340 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4638     {
4639     const PointerType *PTy = dyn_cast<PointerType>((yyvsp[-1].TypeVal).PAT->get());
4640     if (PTy == 0)
4641       error("Cannot make null pointer constant with type: '" + 
4642             (yyvsp[-1].TypeVal).PAT->get()->getDescription() + "'");
4643     (yyval.ConstVal).C = ConstantPointerNull::get(PTy);
4644     (yyval.ConstVal).S.copy((yyvsp[-1].TypeVal).S);
4645     delete (yyvsp[-1].TypeVal).PAT;
4646   ;}
4647     break;
4648
4649   case 154:
4650 #line 2349 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4651     {
4652     (yyval.ConstVal).C = UndefValue::get((yyvsp[-1].TypeVal).PAT->get());
4653     (yyval.ConstVal).S.copy((yyvsp[-1].TypeVal).S);
4654     delete (yyvsp[-1].TypeVal).PAT;
4655   ;}
4656     break;
4657
4658   case 155:
4659 #line 2354 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4660     {
4661     const PointerType *Ty = dyn_cast<PointerType>((yyvsp[-1].TypeVal).PAT->get());
4662     if (Ty == 0)
4663       error("Global const reference must be a pointer type, not" +
4664             (yyvsp[-1].TypeVal).PAT->get()->getDescription());
4665
4666     // ConstExprs can exist in the body of a function, thus creating
4667     // GlobalValues whenever they refer to a variable.  Because we are in
4668     // the context of a function, getExistingValue will search the functions
4669     // symbol table instead of the module symbol table for the global symbol,
4670     // which throws things all off.  To get around this, we just tell
4671     // getExistingValue that we are at global scope here.
4672     //
4673     Function *SavedCurFn = CurFun.CurrentFunction;
4674     CurFun.CurrentFunction = 0;
4675     (yyvsp[0].ValIDVal).S.copy((yyvsp[-1].TypeVal).S);
4676     Value *V = getExistingValue(Ty, (yyvsp[0].ValIDVal));
4677     CurFun.CurrentFunction = SavedCurFn;
4678
4679     // If this is an initializer for a constant pointer, which is referencing a
4680     // (currently) undefined variable, create a stub now that shall be replaced
4681     // in the future with the right type of variable.
4682     //
4683     if (V == 0) {
4684       assert(isa<PointerType>(Ty) && "Globals may only be used as pointers");
4685       const PointerType *PT = cast<PointerType>(Ty);
4686
4687       // First check to see if the forward references value is already created!
4688       PerModuleInfo::GlobalRefsType::iterator I =
4689         CurModule.GlobalRefs.find(std::make_pair(PT, (yyvsp[0].ValIDVal)));
4690     
4691       if (I != CurModule.GlobalRefs.end()) {
4692         V = I->second;             // Placeholder already exists, use it...
4693         (yyvsp[0].ValIDVal).destroy();
4694       } else {
4695         std::string Name;
4696         if ((yyvsp[0].ValIDVal).Type == ValID::NameVal) Name = (yyvsp[0].ValIDVal).Name;
4697
4698         // Create the forward referenced global.
4699         GlobalValue *GV;
4700         if (const FunctionType *FTy = 
4701                  dyn_cast<FunctionType>(PT->getElementType())) {
4702           GV = new Function(FTy, GlobalValue::ExternalLinkage, Name,
4703                             CurModule.CurrentModule);
4704         } else {
4705           GV = new GlobalVariable(PT->getElementType(), false,
4706                                   GlobalValue::ExternalLinkage, 0,
4707                                   Name, CurModule.CurrentModule);
4708         }
4709
4710         // Keep track of the fact that we have a forward ref to recycle it
4711         CurModule.GlobalRefs.insert(std::make_pair(std::make_pair(PT, (yyvsp[0].ValIDVal)), GV));
4712         V = GV;
4713       }
4714     }
4715     (yyval.ConstVal).C = cast<GlobalValue>(V);
4716     (yyval.ConstVal).S.copy((yyvsp[-1].TypeVal).S);
4717     delete (yyvsp[-1].TypeVal).PAT;            // Free the type handle
4718   ;}
4719     break;
4720
4721   case 156:
4722 #line 2413 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4723     {
4724     if ((yyvsp[-1].TypeVal).PAT->get() != (yyvsp[0].ConstVal).C->getType())
4725       error("Mismatched types for constant expression");
4726     (yyval.ConstVal) = (yyvsp[0].ConstVal);
4727     (yyval.ConstVal).S.copy((yyvsp[-1].TypeVal).S);
4728     delete (yyvsp[-1].TypeVal).PAT;
4729   ;}
4730     break;
4731
4732   case 157:
4733 #line 2420 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4734     {
4735     const Type *Ty = (yyvsp[-1].TypeVal).PAT->get();
4736     if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
4737       error("Cannot create a null initialized value of this type");
4738     (yyval.ConstVal).C = Constant::getNullValue(Ty);
4739     (yyval.ConstVal).S.copy((yyvsp[-1].TypeVal).S);
4740     delete (yyvsp[-1].TypeVal).PAT;
4741   ;}
4742     break;
4743
4744   case 158:
4745 #line 2428 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4746     {      // integral constants
4747     const Type *Ty = (yyvsp[-1].PrimType).T;
4748     if (!ConstantInt::isValueValidForType(Ty, (yyvsp[0].SInt64Val)))
4749       error("Constant value doesn't fit in type");
4750     (yyval.ConstVal).C = ConstantInt::get(Ty, (yyvsp[0].SInt64Val));
4751     (yyval.ConstVal).S.makeSigned();
4752   ;}
4753     break;
4754
4755   case 159:
4756 #line 2435 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4757     {            // integral constants
4758     const Type *Ty = (yyvsp[-1].PrimType).T;
4759     if (!ConstantInt::isValueValidForType(Ty, (yyvsp[0].UInt64Val)))
4760       error("Constant value doesn't fit in type");
4761     (yyval.ConstVal).C = ConstantInt::get(Ty, (yyvsp[0].UInt64Val));
4762     (yyval.ConstVal).S.makeUnsigned();
4763   ;}
4764     break;
4765
4766   case 160:
4767 #line 2442 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4768     {                      // Boolean constants
4769     (yyval.ConstVal).C = ConstantInt::get(Type::Int1Ty, true);
4770     (yyval.ConstVal).S.makeUnsigned();
4771   ;}
4772     break;
4773
4774   case 161:
4775 #line 2446 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4776     {                     // Boolean constants
4777     (yyval.ConstVal).C = ConstantInt::get(Type::Int1Ty, false);
4778     (yyval.ConstVal).S.makeUnsigned();
4779   ;}
4780     break;
4781
4782   case 162:
4783 #line 2450 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4784     {                   // Float & Double constants
4785     if (!ConstantFP::isValueValidForType((yyvsp[-1].PrimType).T, (yyvsp[0].FPVal)))
4786       error("Floating point constant invalid for type");
4787     (yyval.ConstVal).C = ConstantFP::get((yyvsp[-1].PrimType).T, (yyvsp[0].FPVal));
4788     (yyval.ConstVal).S.makeSignless();
4789   ;}
4790     break;
4791
4792   case 163:
4793 #line 2459 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4794     {
4795     const Type* SrcTy = (yyvsp[-3].ConstVal).C->getType();
4796     const Type* DstTy = (yyvsp[-1].TypeVal).PAT->get();
4797     Signedness SrcSign((yyvsp[-3].ConstVal).S);
4798     Signedness DstSign((yyvsp[-1].TypeVal).S);
4799     if (!SrcTy->isFirstClassType())
4800       error("cast constant expression from a non-primitive type: '" +
4801             SrcTy->getDescription() + "'");
4802     if (!DstTy->isFirstClassType())
4803       error("cast constant expression to a non-primitive type: '" +
4804             DstTy->getDescription() + "'");
4805     (yyval.ConstVal).C = cast<Constant>(getCast((yyvsp[-5].CastOpVal), (yyvsp[-3].ConstVal).C, SrcSign, DstTy, DstSign));
4806     (yyval.ConstVal).S.copy(DstSign);
4807     delete (yyvsp[-1].TypeVal).PAT;
4808   ;}
4809     break;
4810
4811   case 164:
4812 #line 2474 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4813     {
4814     const Type *Ty = (yyvsp[-2].ConstVal).C->getType();
4815     if (!isa<PointerType>(Ty))
4816       error("GetElementPtr requires a pointer operand");
4817
4818     std::vector<Value*> VIndices;
4819     std::vector<Constant*> CIndices;
4820     upgradeGEPIndices((yyvsp[-2].ConstVal).C->getType(), (yyvsp[-1].ValueList), VIndices, &CIndices);
4821
4822     delete (yyvsp[-1].ValueList);
4823     (yyval.ConstVal).C = ConstantExpr::getGetElementPtr((yyvsp[-2].ConstVal).C, &CIndices[0], CIndices.size());
4824     (yyval.ConstVal).S.copy(getElementSign((yyvsp[-2].ConstVal), CIndices));
4825   ;}
4826     break;
4827
4828   case 165:
4829 #line 2487 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4830     {
4831     if (!(yyvsp[-5].ConstVal).C->getType()->isInteger() ||
4832         cast<IntegerType>((yyvsp[-5].ConstVal).C->getType())->getBitWidth() != 1)
4833       error("Select condition must be bool type");
4834     if ((yyvsp[-3].ConstVal).C->getType() != (yyvsp[-1].ConstVal).C->getType())
4835       error("Select operand types must match");
4836     (yyval.ConstVal).C = ConstantExpr::getSelect((yyvsp[-5].ConstVal).C, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
4837     (yyval.ConstVal).S.copy((yyvsp[-3].ConstVal).S);
4838   ;}
4839     break;
4840
4841   case 166:
4842 #line 2496 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4843     {
4844     const Type *Ty = (yyvsp[-3].ConstVal).C->getType();
4845     if (Ty != (yyvsp[-1].ConstVal).C->getType())
4846       error("Binary operator types must match");
4847     // First, make sure we're dealing with the right opcode by upgrading from
4848     // obsolete versions.
4849     Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[-5].BinaryOpVal), Ty, (yyvsp[-3].ConstVal).S);
4850
4851     // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs.
4852     // To retain backward compatibility with these early compilers, we emit a
4853     // cast to the appropriate integer type automatically if we are in the
4854     // broken case.  See PR424 for more information.
4855     if (!isa<PointerType>(Ty)) {
4856       (yyval.ConstVal).C = ConstantExpr::get(Opcode, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
4857     } else {
4858       const Type *IntPtrTy = 0;
4859       switch (CurModule.CurrentModule->getPointerSize()) {
4860       case Module::Pointer32: IntPtrTy = Type::Int32Ty; break;
4861       case Module::Pointer64: IntPtrTy = Type::Int64Ty; break;
4862       default: error("invalid pointer binary constant expr");
4863       }
4864       (yyval.ConstVal).C = ConstantExpr::get(Opcode, 
4865              ConstantExpr::getCast(Instruction::PtrToInt, (yyvsp[-3].ConstVal).C, IntPtrTy),
4866              ConstantExpr::getCast(Instruction::PtrToInt, (yyvsp[-1].ConstVal).C, IntPtrTy));
4867       (yyval.ConstVal).C = ConstantExpr::getCast(Instruction::IntToPtr, (yyval.ConstVal).C, Ty);
4868     }
4869     (yyval.ConstVal).S.copy((yyvsp[-3].ConstVal).S); 
4870   ;}
4871     break;
4872
4873   case 167:
4874 #line 2524 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4875     {
4876     const Type* Ty = (yyvsp[-3].ConstVal).C->getType();
4877     if (Ty != (yyvsp[-1].ConstVal).C->getType())
4878       error("Logical operator types must match");
4879     if (!Ty->isInteger()) {
4880       if (!isa<VectorType>(Ty) || 
4881           !cast<VectorType>(Ty)->getElementType()->isInteger())
4882         error("Logical operator requires integer operands");
4883     }
4884     Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[-5].BinaryOpVal), Ty, (yyvsp[-3].ConstVal).S);
4885     (yyval.ConstVal).C = ConstantExpr::get(Opcode, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
4886     (yyval.ConstVal).S.copy((yyvsp[-3].ConstVal).S);
4887   ;}
4888     break;
4889
4890   case 168:
4891 #line 2537 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4892     {
4893     const Type* Ty = (yyvsp[-3].ConstVal).C->getType();
4894     if (Ty != (yyvsp[-1].ConstVal).C->getType())
4895       error("setcc operand types must match");
4896     unsigned short pred;
4897     Instruction::OtherOps Opcode = getCompareOp((yyvsp[-5].BinaryOpVal), pred, Ty, (yyvsp[-3].ConstVal).S);
4898     (yyval.ConstVal).C = ConstantExpr::getCompare(Opcode, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
4899     (yyval.ConstVal).S.makeUnsigned();
4900   ;}
4901     break;
4902
4903   case 169:
4904 #line 2546 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4905     {
4906     if ((yyvsp[-3].ConstVal).C->getType() != (yyvsp[-1].ConstVal).C->getType()) 
4907       error("icmp operand types must match");
4908     (yyval.ConstVal).C = ConstantExpr::getCompare((yyvsp[-5].IPred), (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
4909     (yyval.ConstVal).S.makeUnsigned();
4910   ;}
4911     break;
4912
4913   case 170:
4914 #line 2552 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4915     {
4916     if ((yyvsp[-3].ConstVal).C->getType() != (yyvsp[-1].ConstVal).C->getType()) 
4917       error("fcmp operand types must match");
4918     (yyval.ConstVal).C = ConstantExpr::getCompare((yyvsp[-5].FPred), (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
4919     (yyval.ConstVal).S.makeUnsigned();
4920   ;}
4921     break;
4922
4923   case 171:
4924 #line 2558 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4925     {
4926     if (!(yyvsp[-1].ConstVal).C->getType()->isInteger() ||
4927         cast<IntegerType>((yyvsp[-1].ConstVal).C->getType())->getBitWidth() != 8)
4928       error("Shift count for shift constant must be unsigned byte");
4929     const Type* Ty = (yyvsp[-3].ConstVal).C->getType();
4930     if (!(yyvsp[-3].ConstVal).C->getType()->isInteger())
4931       error("Shift constant expression requires integer operand");
4932     Constant *ShiftAmt = ConstantExpr::getZExt((yyvsp[-1].ConstVal).C, Ty);
4933     (yyval.ConstVal).C = ConstantExpr::get(getBinaryOp((yyvsp[-5].BinaryOpVal), Ty, (yyvsp[-3].ConstVal).S), (yyvsp[-3].ConstVal).C, ShiftAmt);
4934     (yyval.ConstVal).S.copy((yyvsp[-3].ConstVal).S);
4935   ;}
4936     break;
4937
4938   case 172:
4939 #line 2569 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4940     {
4941     if (!ExtractElementInst::isValidOperands((yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C))
4942       error("Invalid extractelement operands");
4943     (yyval.ConstVal).C = ConstantExpr::getExtractElement((yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
4944     (yyval.ConstVal).S.copy((yyvsp[-3].ConstVal).S.get(0));
4945   ;}
4946     break;
4947
4948   case 173:
4949 #line 2575 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4950     {
4951     if (!InsertElementInst::isValidOperands((yyvsp[-5].ConstVal).C, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C))
4952       error("Invalid insertelement operands");
4953     (yyval.ConstVal).C = ConstantExpr::getInsertElement((yyvsp[-5].ConstVal).C, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
4954     (yyval.ConstVal).S.copy((yyvsp[-5].ConstVal).S);
4955   ;}
4956     break;
4957
4958   case 174:
4959 #line 2581 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4960     {
4961     if (!ShuffleVectorInst::isValidOperands((yyvsp[-5].ConstVal).C, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C))
4962       error("Invalid shufflevector operands");
4963     (yyval.ConstVal).C = ConstantExpr::getShuffleVector((yyvsp[-5].ConstVal).C, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
4964     (yyval.ConstVal).S.copy((yyvsp[-5].ConstVal).S);
4965   ;}
4966     break;
4967
4968   case 175:
4969 #line 2592 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4970     { ((yyval.ConstVector) = (yyvsp[-2].ConstVector))->push_back((yyvsp[0].ConstVal)); ;}
4971     break;
4972
4973   case 176:
4974 #line 2593 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4975     {
4976     (yyval.ConstVector) = new std::vector<ConstInfo>();
4977     (yyval.ConstVector)->push_back((yyvsp[0].ConstVal));
4978   ;}
4979     break;
4980
4981   case 177:
4982 #line 2602 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4983     { (yyval.BoolVal) = false; ;}
4984     break;
4985
4986   case 178:
4987 #line 2603 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4988     { (yyval.BoolVal) = true; ;}
4989     break;
4990
4991   case 179:
4992 #line 2615 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
4993     {
4994     (yyval.ModuleVal) = ParserResult = (yyvsp[0].ModuleVal);
4995     CurModule.ModuleDone();
4996   ;}
4997     break;
4998
4999   case 180:
5000 #line 2624 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5001     { (yyval.ModuleVal) = (yyvsp[-1].ModuleVal); CurFun.FunctionDone(); ;}
5002     break;
5003
5004   case 181:
5005 #line 2625 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5006     { (yyval.ModuleVal) = (yyvsp[-1].ModuleVal); ;}
5007     break;
5008
5009   case 182:
5010 #line 2626 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5011     { (yyval.ModuleVal) = (yyvsp[-3].ModuleVal); ;}
5012     break;
5013
5014   case 183:
5015 #line 2627 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5016     { (yyval.ModuleVal) = (yyvsp[-1].ModuleVal); ;}
5017     break;
5018
5019   case 184:
5020 #line 2628 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5021     {
5022     (yyval.ModuleVal) = CurModule.CurrentModule;
5023     // Emit an error if there are any unresolved types left.
5024     if (!CurModule.LateResolveTypes.empty()) {
5025       const ValID &DID = CurModule.LateResolveTypes.begin()->first;
5026       if (DID.Type == ValID::NameVal) {
5027         error("Reference to an undefined type: '"+DID.getName() + "'");
5028       } else {
5029         error("Reference to an undefined type: #" + itostr(DID.Num));
5030       }
5031     }
5032   ;}
5033     break;
5034
5035   case 185:
5036 #line 2644 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5037     {
5038     // Eagerly resolve types.  This is not an optimization, this is a
5039     // requirement that is due to the fact that we could have this:
5040     //
5041     // %list = type { %list * }
5042     // %list = type { %list * }    ; repeated type decl
5043     //
5044     // If types are not resolved eagerly, then the two types will not be
5045     // determined to be the same type!
5046     //
5047     ResolveTypeTo((yyvsp[-2].StrVal), (yyvsp[0].TypeVal).PAT->get(), (yyvsp[0].TypeVal).S);
5048
5049     if (!setTypeName((yyvsp[0].TypeVal), (yyvsp[-2].StrVal)) && !(yyvsp[-2].StrVal)) {
5050       // If this is a numbered type that is not a redefinition, add it to the 
5051       // slot table.
5052       CurModule.Types.push_back((yyvsp[0].TypeVal).PAT->get());
5053       CurModule.TypeSigns.push_back((yyvsp[0].TypeVal).S);
5054     }
5055     delete (yyvsp[0].TypeVal).PAT;
5056   ;}
5057     break;
5058
5059   case 186:
5060 #line 2664 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5061     {       // Function prototypes can be in const pool
5062   ;}
5063     break;
5064
5065   case 187:
5066 #line 2666 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5067     {  // Asm blocks can be in the const pool
5068   ;}
5069     break;
5070
5071   case 188:
5072 #line 2668 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5073     {
5074     if ((yyvsp[0].ConstVal).C == 0) 
5075       error("Global value initializer is not a constant");
5076     CurGV = ParseGlobalVariable((yyvsp[-3].StrVal), (yyvsp[-2].Linkage), (yyvsp[-1].BoolVal), (yyvsp[0].ConstVal).C->getType(), (yyvsp[0].ConstVal).C, (yyvsp[0].ConstVal).S);
5077   ;}
5078     break;
5079
5080   case 189:
5081 #line 2672 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5082     {
5083     CurGV = 0;
5084   ;}
5085     break;
5086
5087   case 190:
5088 #line 2675 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5089     {
5090     const Type *Ty = (yyvsp[0].TypeVal).PAT->get();
5091     CurGV = ParseGlobalVariable((yyvsp[-3].StrVal), GlobalValue::ExternalLinkage, (yyvsp[-1].BoolVal), Ty, 0,
5092                                 (yyvsp[0].TypeVal).S);
5093     delete (yyvsp[0].TypeVal).PAT;
5094   ;}
5095     break;
5096
5097   case 191:
5098 #line 2680 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5099     {
5100     CurGV = 0;
5101   ;}
5102     break;
5103
5104   case 192:
5105 #line 2683 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5106     {
5107     const Type *Ty = (yyvsp[0].TypeVal).PAT->get();
5108     CurGV = ParseGlobalVariable((yyvsp[-3].StrVal), GlobalValue::DLLImportLinkage, (yyvsp[-1].BoolVal), Ty, 0,
5109                                 (yyvsp[0].TypeVal).S);
5110     delete (yyvsp[0].TypeVal).PAT;
5111   ;}
5112     break;
5113
5114   case 193:
5115 #line 2688 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5116     {
5117     CurGV = 0;
5118   ;}
5119     break;
5120
5121   case 194:
5122 #line 2691 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5123     {
5124     const Type *Ty = (yyvsp[0].TypeVal).PAT->get();
5125     CurGV = 
5126       ParseGlobalVariable((yyvsp[-3].StrVal), GlobalValue::ExternalWeakLinkage, (yyvsp[-1].BoolVal), Ty, 0, 
5127                           (yyvsp[0].TypeVal).S);
5128     delete (yyvsp[0].TypeVal).PAT;
5129   ;}
5130     break;
5131
5132   case 195:
5133 #line 2697 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5134     {
5135     CurGV = 0;
5136   ;}
5137     break;
5138
5139   case 196:
5140 #line 2700 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5141     { 
5142   ;}
5143     break;
5144
5145   case 197:
5146 #line 2702 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5147     {
5148   ;}
5149     break;
5150
5151   case 198:
5152 #line 2704 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5153     { 
5154   ;}
5155     break;
5156
5157   case 199:
5158 #line 2709 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5159     {
5160     const std::string &AsmSoFar = CurModule.CurrentModule->getModuleInlineAsm();
5161     char *EndStr = UnEscapeLexed((yyvsp[0].StrVal), true);
5162     std::string NewAsm((yyvsp[0].StrVal), EndStr);
5163     free((yyvsp[0].StrVal));
5164
5165     if (AsmSoFar.empty())
5166       CurModule.CurrentModule->setModuleInlineAsm(NewAsm);
5167     else
5168       CurModule.CurrentModule->setModuleInlineAsm(AsmSoFar+"\n"+NewAsm);
5169   ;}
5170     break;
5171
5172   case 200:
5173 #line 2723 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5174     { (yyval.Endianness) = Module::BigEndian; ;}
5175     break;
5176
5177   case 201:
5178 #line 2724 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5179     { (yyval.Endianness) = Module::LittleEndian; ;}
5180     break;
5181
5182   case 202:
5183 #line 2728 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5184     {
5185     CurModule.setEndianness((yyvsp[0].Endianness));
5186   ;}
5187     break;
5188
5189   case 203:
5190 #line 2731 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5191     {
5192     if ((yyvsp[0].UInt64Val) == 32)
5193       CurModule.setPointerSize(Module::Pointer32);
5194     else if ((yyvsp[0].UInt64Val) == 64)
5195       CurModule.setPointerSize(Module::Pointer64);
5196     else
5197       error("Invalid pointer size: '" + utostr((yyvsp[0].UInt64Val)) + "'");
5198   ;}
5199     break;
5200
5201   case 204:
5202 #line 2739 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5203     {
5204     CurModule.CurrentModule->setTargetTriple((yyvsp[0].StrVal));
5205     free((yyvsp[0].StrVal));
5206   ;}
5207     break;
5208
5209   case 205:
5210 #line 2743 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5211     {
5212     CurModule.CurrentModule->setDataLayout((yyvsp[0].StrVal));
5213     free((yyvsp[0].StrVal));
5214   ;}
5215     break;
5216
5217   case 207:
5218 #line 2754 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5219     {
5220       CurModule.CurrentModule->addLibrary((yyvsp[0].StrVal));
5221       free((yyvsp[0].StrVal));
5222   ;}
5223     break;
5224
5225   case 208:
5226 #line 2758 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5227     {
5228     CurModule.CurrentModule->addLibrary((yyvsp[0].StrVal));
5229     free((yyvsp[0].StrVal));
5230   ;}
5231     break;
5232
5233   case 209:
5234 #line 2762 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5235     { ;}
5236     break;
5237
5238   case 213:
5239 #line 2775 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5240     { (yyval.StrVal) = 0; ;}
5241     break;
5242
5243   case 214:
5244 #line 2779 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5245     {
5246     if ((yyvsp[-1].TypeVal).PAT->get() == Type::VoidTy)
5247       error("void typed arguments are invalid");
5248     (yyval.ArgVal) = new std::pair<PATypeInfo, char*>((yyvsp[-1].TypeVal), (yyvsp[0].StrVal));
5249   ;}
5250     break;
5251
5252   case 215:
5253 #line 2787 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5254     {
5255     (yyval.ArgList) = (yyvsp[-2].ArgList);
5256     (yyval.ArgList)->push_back(*(yyvsp[0].ArgVal));
5257     delete (yyvsp[0].ArgVal);
5258   ;}
5259     break;
5260
5261   case 216:
5262 #line 2792 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5263     {
5264     (yyval.ArgList) = new std::vector<std::pair<PATypeInfo,char*> >();
5265     (yyval.ArgList)->push_back(*(yyvsp[0].ArgVal));
5266     delete (yyvsp[0].ArgVal);
5267   ;}
5268     break;
5269
5270   case 217:
5271 #line 2800 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5272     { (yyval.ArgList) = (yyvsp[0].ArgList); ;}
5273     break;
5274
5275   case 218:
5276 #line 2801 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5277     {
5278     (yyval.ArgList) = (yyvsp[-2].ArgList);
5279     PATypeInfo VoidTI;
5280     VoidTI.PAT = new PATypeHolder(Type::VoidTy);
5281     VoidTI.S.makeSignless();
5282     (yyval.ArgList)->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
5283   ;}
5284     break;
5285
5286   case 219:
5287 #line 2808 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5288     {
5289     (yyval.ArgList) = new std::vector<std::pair<PATypeInfo,char*> >();
5290     PATypeInfo VoidTI;
5291     VoidTI.PAT = new PATypeHolder(Type::VoidTy);
5292     VoidTI.S.makeSignless();
5293     (yyval.ArgList)->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
5294   ;}
5295     break;
5296
5297   case 220:
5298 #line 2815 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5299     { (yyval.ArgList) = 0; ;}
5300     break;
5301
5302   case 221:
5303 #line 2819 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5304     {
5305     UnEscapeLexed((yyvsp[-5].StrVal));
5306     std::string FunctionName((yyvsp[-5].StrVal));
5307     free((yyvsp[-5].StrVal));  // Free strdup'd memory!
5308
5309     const Type* RetTy = (yyvsp[-6].TypeVal).PAT->get();
5310     
5311     if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
5312       error("LLVM functions cannot return aggregate types");
5313
5314     Signedness FTySign;
5315     FTySign.makeComposite((yyvsp[-6].TypeVal).S);
5316     std::vector<const Type*> ParamTyList;
5317
5318     // In LLVM 2.0 the signatures of three varargs intrinsics changed to take
5319     // i8*. We check here for those names and override the parameter list
5320     // types to ensure the prototype is correct.
5321     if (FunctionName == "llvm.va_start" || FunctionName == "llvm.va_end") {
5322       ParamTyList.push_back(PointerType::get(Type::Int8Ty));
5323     } else if (FunctionName == "llvm.va_copy") {
5324       ParamTyList.push_back(PointerType::get(Type::Int8Ty));
5325       ParamTyList.push_back(PointerType::get(Type::Int8Ty));
5326     } else if ((yyvsp[-3].ArgList)) {   // If there are arguments...
5327       for (std::vector<std::pair<PATypeInfo,char*> >::iterator 
5328            I = (yyvsp[-3].ArgList)->begin(), E = (yyvsp[-3].ArgList)->end(); I != E; ++I) {
5329         const Type *Ty = I->first.PAT->get();
5330         ParamTyList.push_back(Ty);
5331         FTySign.add(I->first.S);
5332       }
5333     }
5334
5335     bool isVarArg = ParamTyList.size() && ParamTyList.back() == Type::VoidTy;
5336     if (isVarArg) 
5337       ParamTyList.pop_back();
5338
5339     // Convert the CSRet calling convention into the corresponding parameter
5340     // attribute.
5341     FunctionType::ParamAttrsList ParamAttrs;
5342     if ((yyvsp[-7].UIntVal) == OldCallingConv::CSRet) {
5343       ParamAttrs.push_back(FunctionType::NoAttributeSet);     // result
5344       ParamAttrs.push_back(FunctionType::StructRetAttribute); // first arg
5345     }
5346
5347     const FunctionType *FT = FunctionType::get(RetTy, ParamTyList, isVarArg,
5348                                                ParamAttrs);
5349     const PointerType *PFT = PointerType::get(FT);
5350     delete (yyvsp[-6].TypeVal).PAT;
5351
5352     ValID ID;
5353     if (!FunctionName.empty()) {
5354       ID = ValID::create((char*)FunctionName.c_str());
5355     } else {
5356       ID = ValID::create((int)CurModule.Values[PFT].size());
5357     }
5358     ID.S.makeComposite(FTySign);
5359
5360     Function *Fn = 0;
5361     Module* M = CurModule.CurrentModule;
5362
5363     // See if this function was forward referenced.  If so, recycle the object.
5364     if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, ID)) {
5365       // Move the function to the end of the list, from whereever it was 
5366       // previously inserted.
5367       Fn = cast<Function>(FWRef);
5368       M->getFunctionList().remove(Fn);
5369       M->getFunctionList().push_back(Fn);
5370     } else if (!FunctionName.empty()) {
5371       GlobalValue *Conflict = M->getFunction(FunctionName);
5372       if (!Conflict)
5373         Conflict = M->getNamedGlobal(FunctionName);
5374       if (Conflict && PFT == Conflict->getType()) {
5375         if (!CurFun.isDeclare && !Conflict->isDeclaration()) {
5376           // We have two function definitions that conflict, same type, same
5377           // name. We should really check to make sure that this is the result
5378           // of integer type planes collapsing and generate an error if it is
5379           // not, but we'll just rename on the assumption that it is. However,
5380           // let's do it intelligently and rename the internal linkage one
5381           // if there is one.
5382           std::string NewName(makeNameUnique(FunctionName));
5383           if (Conflict->hasInternalLinkage()) {
5384             Conflict->setName(NewName);
5385             RenameMapKey Key = 
5386               makeRenameMapKey(FunctionName, Conflict->getType(), ID.S);
5387             CurModule.RenameMap[Key] = NewName;
5388             Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5389             InsertValue(Fn, CurModule.Values);
5390           } else {
5391             Fn = new Function(FT, CurFun.Linkage, NewName, M);
5392             InsertValue(Fn, CurModule.Values);
5393             RenameMapKey Key = 
5394               makeRenameMapKey(FunctionName, PFT, ID.S);
5395             CurModule.RenameMap[Key] = NewName;
5396           }
5397         } else {
5398           // If they are not both definitions, then just use the function we
5399           // found since the types are the same.
5400           Fn = cast<Function>(Conflict);
5401
5402           // Make sure to strip off any argument names so we can't get 
5403           // conflicts.
5404           if (Fn->isDeclaration())
5405             for (Function::arg_iterator AI = Fn->arg_begin(), 
5406                  AE = Fn->arg_end(); AI != AE; ++AI)
5407               AI->setName("");
5408         }
5409       } else if (Conflict) {
5410         // We have two globals with the same name and  different types. 
5411         // Previously, this was permitted because the symbol table had 
5412         // "type planes" and names only needed to be distinct within a 
5413         // type plane. After PR411 was fixed, this is no loner the case. 
5414         // To resolve this we must rename one of the two. 
5415         if (Conflict->hasInternalLinkage()) {
5416           // We can safely rename the Conflict.
5417           RenameMapKey Key = 
5418             makeRenameMapKey(Conflict->getName(), Conflict->getType(), 
5419               CurModule.NamedValueSigns[Conflict->getName()]);
5420           Conflict->setName(makeNameUnique(Conflict->getName()));
5421           CurModule.RenameMap[Key] = Conflict->getName();
5422           Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5423           InsertValue(Fn, CurModule.Values);
5424         } else { 
5425           // We can't quietly rename either of these things, but we must
5426           // rename one of them. Only if the function's linkage is internal can
5427           // we forgo a warning message about the renamed function. 
5428           std::string NewName = makeNameUnique(FunctionName);
5429           if (CurFun.Linkage != GlobalValue::InternalLinkage) {
5430             warning("Renaming function '" + FunctionName + "' as '" + NewName +
5431                     "' may cause linkage errors");
5432           }
5433           // Elect to rename the thing we're now defining.
5434           Fn = new Function(FT, CurFun.Linkage, NewName, M);
5435           InsertValue(Fn, CurModule.Values);
5436           RenameMapKey Key = makeRenameMapKey(FunctionName, PFT, ID.S);
5437           CurModule.RenameMap[Key] = NewName;
5438         } 
5439       } else {
5440         // There's no conflict, just define the function
5441         Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5442         InsertValue(Fn, CurModule.Values);
5443       }
5444     }
5445
5446     CurFun.FunctionStart(Fn);
5447
5448     if (CurFun.isDeclare) {
5449       // If we have declaration, always overwrite linkage.  This will allow us 
5450       // to correctly handle cases, when pointer to function is passed as 
5451       // argument to another function.
5452       Fn->setLinkage(CurFun.Linkage);
5453     }
5454     Fn->setCallingConv(upgradeCallingConv((yyvsp[-7].UIntVal)));
5455     Fn->setAlignment((yyvsp[0].UIntVal));
5456     if ((yyvsp[-1].StrVal)) {
5457       Fn->setSection((yyvsp[-1].StrVal));
5458       free((yyvsp[-1].StrVal));
5459     }
5460
5461     // Add all of the arguments we parsed to the function...
5462     if ((yyvsp[-3].ArgList)) {                     // Is null if empty...
5463       if (isVarArg) {  // Nuke the last entry
5464         assert((yyvsp[-3].ArgList)->back().first.PAT->get() == Type::VoidTy && 
5465                (yyvsp[-3].ArgList)->back().second == 0 && "Not a varargs marker");
5466         delete (yyvsp[-3].ArgList)->back().first.PAT;
5467         (yyvsp[-3].ArgList)->pop_back();  // Delete the last entry
5468       }
5469       Function::arg_iterator ArgIt = Fn->arg_begin();
5470       Function::arg_iterator ArgEnd = Fn->arg_end();
5471       std::vector<std::pair<PATypeInfo,char*> >::iterator I = (yyvsp[-3].ArgList)->begin();
5472       std::vector<std::pair<PATypeInfo,char*> >::iterator E = (yyvsp[-3].ArgList)->end();
5473       for ( ; I != E && ArgIt != ArgEnd; ++I, ++ArgIt) {
5474         delete I->first.PAT;                      // Delete the typeholder...
5475         ValueInfo VI; VI.V = ArgIt; VI.S.copy(I->first.S); 
5476         setValueName(VI, I->second);           // Insert arg into symtab...
5477         InsertValue(ArgIt);
5478       }
5479       delete (yyvsp[-3].ArgList);                     // We're now done with the argument list
5480     }
5481   ;}
5482     break;
5483
5484   case 224:
5485 #line 3004 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5486     { CurFun.Linkage = (yyvsp[0].Linkage); ;}
5487     break;
5488
5489   case 225:
5490 #line 3004 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5491     {
5492     (yyval.FunctionVal) = CurFun.CurrentFunction;
5493
5494     // Make sure that we keep track of the linkage type even if there was a
5495     // previous "declare".
5496     (yyval.FunctionVal)->setLinkage((yyvsp[-3].Linkage));
5497   ;}
5498     break;
5499
5500   case 228:
5501 #line 3018 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5502     {
5503     (yyval.FunctionVal) = (yyvsp[-1].FunctionVal);
5504   ;}
5505     break;
5506
5507   case 229:
5508 #line 3023 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5509     { (yyval.Linkage) = GlobalValue::ExternalLinkage; ;}
5510     break;
5511
5512   case 230:
5513 #line 3024 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5514     { (yyval.Linkage) = GlobalValue::DLLImportLinkage; ;}
5515     break;
5516
5517   case 231:
5518 #line 3025 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5519     { (yyval.Linkage) = GlobalValue::ExternalWeakLinkage; ;}
5520     break;
5521
5522   case 232:
5523 #line 3029 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5524     { CurFun.isDeclare = true; ;}
5525     break;
5526
5527   case 233:
5528 #line 3030 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5529     { CurFun.Linkage = (yyvsp[0].Linkage); ;}
5530     break;
5531
5532   case 234:
5533 #line 3030 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5534     {
5535     (yyval.FunctionVal) = CurFun.CurrentFunction;
5536     CurFun.FunctionDone();
5537     
5538   ;}
5539     break;
5540
5541   case 235:
5542 #line 3042 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5543     { (yyval.BoolVal) = false; ;}
5544     break;
5545
5546   case 236:
5547 #line 3043 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5548     { (yyval.BoolVal) = true; ;}
5549     break;
5550
5551   case 237:
5552 #line 3048 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5553     { (yyval.ValIDVal) = ValID::create((yyvsp[0].SInt64Val)); ;}
5554     break;
5555
5556   case 238:
5557 #line 3049 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5558     { (yyval.ValIDVal) = ValID::create((yyvsp[0].UInt64Val)); ;}
5559     break;
5560
5561   case 239:
5562 #line 3050 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5563     { (yyval.ValIDVal) = ValID::create((yyvsp[0].FPVal)); ;}
5564     break;
5565
5566   case 240:
5567 #line 3051 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5568     { 
5569     (yyval.ValIDVal) = ValID::create(ConstantInt::get(Type::Int1Ty, true));
5570     (yyval.ValIDVal).S.makeUnsigned();
5571   ;}
5572     break;
5573
5574   case 241:
5575 #line 3055 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5576     { 
5577     (yyval.ValIDVal) = ValID::create(ConstantInt::get(Type::Int1Ty, false)); 
5578     (yyval.ValIDVal).S.makeUnsigned();
5579   ;}
5580     break;
5581
5582   case 242:
5583 #line 3059 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5584     { (yyval.ValIDVal) = ValID::createNull(); ;}
5585     break;
5586
5587   case 243:
5588 #line 3060 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5589     { (yyval.ValIDVal) = ValID::createUndef(); ;}
5590     break;
5591
5592   case 244:
5593 #line 3061 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5594     { (yyval.ValIDVal) = ValID::createZeroInit(); ;}
5595     break;
5596
5597   case 245:
5598 #line 3062 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5599     { // Nonempty unsized packed vector
5600     const Type *ETy = (*(yyvsp[-1].ConstVector))[0].C->getType();
5601     int NumElements = (yyvsp[-1].ConstVector)->size(); 
5602     VectorType* pt = VectorType::get(ETy, NumElements);
5603     (yyval.ValIDVal).S.makeComposite((*(yyvsp[-1].ConstVector))[0].S);
5604     PATypeHolder* PTy = new PATypeHolder(HandleUpRefs(pt, (yyval.ValIDVal).S));
5605     
5606     // Verify all elements are correct type!
5607     std::vector<Constant*> Elems;
5608     for (unsigned i = 0; i < (yyvsp[-1].ConstVector)->size(); i++) {
5609       Constant *C = (*(yyvsp[-1].ConstVector))[i].C;
5610       const Type *CTy = C->getType();
5611       if (ETy != CTy)
5612         error("Element #" + utostr(i) + " is not of type '" + 
5613               ETy->getDescription() +"' as required!\nIt is of type '" +
5614               CTy->getDescription() + "'");
5615       Elems.push_back(C);
5616     }
5617     (yyval.ValIDVal) = ValID::create(ConstantVector::get(pt, Elems));
5618     delete PTy; delete (yyvsp[-1].ConstVector);
5619   ;}
5620     break;
5621
5622   case 246:
5623 #line 3083 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5624     {
5625     (yyval.ValIDVal) = ValID::create((yyvsp[0].ConstVal).C);
5626     (yyval.ValIDVal).S.copy((yyvsp[0].ConstVal).S);
5627   ;}
5628     break;
5629
5630   case 247:
5631 #line 3087 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5632     {
5633     char *End = UnEscapeLexed((yyvsp[-2].StrVal), true);
5634     std::string AsmStr = std::string((yyvsp[-2].StrVal), End);
5635     End = UnEscapeLexed((yyvsp[0].StrVal), true);
5636     std::string Constraints = std::string((yyvsp[0].StrVal), End);
5637     (yyval.ValIDVal) = ValID::createInlineAsm(AsmStr, Constraints, (yyvsp[-3].BoolVal));
5638     free((yyvsp[-2].StrVal));
5639     free((yyvsp[0].StrVal));
5640   ;}
5641     break;
5642
5643   case 248:
5644 #line 3101 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5645     {  (yyval.ValIDVal) = ValID::create((yyvsp[0].SIntVal)); (yyval.ValIDVal).S.makeSignless(); ;}
5646     break;
5647
5648   case 249:
5649 #line 3102 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5650     {  (yyval.ValIDVal) = ValID::create((yyvsp[0].StrVal)); (yyval.ValIDVal).S.makeSignless(); ;}
5651     break;
5652
5653   case 252:
5654 #line 3115 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5655     { 
5656     const Type *Ty = (yyvsp[-1].TypeVal).PAT->get();
5657     (yyvsp[0].ValIDVal).S.copy((yyvsp[-1].TypeVal).S);
5658     (yyval.ValueVal).V = getVal(Ty, (yyvsp[0].ValIDVal)); 
5659     (yyval.ValueVal).S.copy((yyvsp[-1].TypeVal).S);
5660     delete (yyvsp[-1].TypeVal).PAT;
5661   ;}
5662     break;
5663
5664   case 253:
5665 #line 3125 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5666     {
5667     (yyval.FunctionVal) = (yyvsp[-1].FunctionVal);
5668   ;}
5669     break;
5670
5671   case 254:
5672 #line 3128 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5673     { // Do not allow functions with 0 basic blocks   
5674     (yyval.FunctionVal) = (yyvsp[-1].FunctionVal);
5675   ;}
5676     break;
5677
5678   case 255:
5679 #line 3137 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5680     {
5681     ValueInfo VI; VI.V = (yyvsp[0].TermInstVal).TI; VI.S.copy((yyvsp[0].TermInstVal).S);
5682     setValueName(VI, (yyvsp[-1].StrVal));
5683     InsertValue((yyvsp[0].TermInstVal).TI);
5684     (yyvsp[-2].BasicBlockVal)->getInstList().push_back((yyvsp[0].TermInstVal).TI);
5685     InsertValue((yyvsp[-2].BasicBlockVal));
5686     (yyval.BasicBlockVal) = (yyvsp[-2].BasicBlockVal);
5687   ;}
5688     break;
5689
5690   case 256:
5691 #line 3148 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5692     {
5693     if ((yyvsp[0].InstVal).I)
5694       (yyvsp[-1].BasicBlockVal)->getInstList().push_back((yyvsp[0].InstVal).I);
5695     (yyval.BasicBlockVal) = (yyvsp[-1].BasicBlockVal);
5696   ;}
5697     break;
5698
5699   case 257:
5700 #line 3153 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5701     {
5702     (yyval.BasicBlockVal) = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++),true);
5703     // Make sure to move the basic block to the correct location in the
5704     // function, instead of leaving it inserted wherever it was first
5705     // referenced.
5706     Function::BasicBlockListType &BBL = 
5707       CurFun.CurrentFunction->getBasicBlockList();
5708     BBL.splice(BBL.end(), BBL, (yyval.BasicBlockVal));
5709   ;}
5710     break;
5711
5712   case 258:
5713 #line 3162 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5714     {
5715     (yyval.BasicBlockVal) = CurBB = getBBVal(ValID::create((yyvsp[0].StrVal)), true);
5716     // Make sure to move the basic block to the correct location in the
5717     // function, instead of leaving it inserted wherever it was first
5718     // referenced.
5719     Function::BasicBlockListType &BBL = 
5720       CurFun.CurrentFunction->getBasicBlockList();
5721     BBL.splice(BBL.end(), BBL, (yyval.BasicBlockVal));
5722   ;}
5723     break;
5724
5725   case 261:
5726 #line 3176 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5727     {              // Return with a result...
5728     (yyval.TermInstVal).TI = new ReturnInst((yyvsp[0].ValueVal).V);
5729     (yyval.TermInstVal).S.makeSignless();
5730   ;}
5731     break;
5732
5733   case 262:
5734 #line 3180 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5735     {                                       // Return with no result...
5736     (yyval.TermInstVal).TI = new ReturnInst();
5737     (yyval.TermInstVal).S.makeSignless();
5738   ;}
5739     break;
5740
5741   case 263:
5742 #line 3184 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5743     {                         // Unconditional Branch...
5744     BasicBlock* tmpBB = getBBVal((yyvsp[0].ValIDVal));
5745     (yyval.TermInstVal).TI = new BranchInst(tmpBB);
5746     (yyval.TermInstVal).S.makeSignless();
5747   ;}
5748     break;
5749
5750   case 264:
5751 #line 3189 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5752     {  
5753     (yyvsp[-3].ValIDVal).S.makeSignless();
5754     (yyvsp[0].ValIDVal).S.makeSignless();
5755     BasicBlock* tmpBBA = getBBVal((yyvsp[-3].ValIDVal));
5756     BasicBlock* tmpBBB = getBBVal((yyvsp[0].ValIDVal));
5757     (yyvsp[-6].ValIDVal).S.makeUnsigned();
5758     Value* tmpVal = getVal(Type::Int1Ty, (yyvsp[-6].ValIDVal));
5759     (yyval.TermInstVal).TI = new BranchInst(tmpBBA, tmpBBB, tmpVal);
5760     (yyval.TermInstVal).S.makeSignless();
5761   ;}
5762     break;
5763
5764   case 265:
5765 #line 3199 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5766     {
5767     (yyvsp[-6].ValIDVal).S.copy((yyvsp[-7].PrimType).S);
5768     Value* tmpVal = getVal((yyvsp[-7].PrimType).T, (yyvsp[-6].ValIDVal));
5769     (yyvsp[-3].ValIDVal).S.makeSignless();
5770     BasicBlock* tmpBB = getBBVal((yyvsp[-3].ValIDVal));
5771     SwitchInst *S = new SwitchInst(tmpVal, tmpBB, (yyvsp[-1].JumpTable)->size());
5772     (yyval.TermInstVal).TI = S;
5773     (yyval.TermInstVal).S.makeSignless();
5774     std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = (yyvsp[-1].JumpTable)->begin(),
5775       E = (yyvsp[-1].JumpTable)->end();
5776     for (; I != E; ++I) {
5777       if (ConstantInt *CI = dyn_cast<ConstantInt>(I->first))
5778           S->addCase(CI, I->second);
5779       else
5780         error("Switch case is constant, but not a simple integer");
5781     }
5782     delete (yyvsp[-1].JumpTable);
5783   ;}
5784     break;
5785
5786   case 266:
5787 #line 3217 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5788     {
5789     (yyvsp[-5].ValIDVal).S.copy((yyvsp[-6].PrimType).S);
5790     Value* tmpVal = getVal((yyvsp[-6].PrimType).T, (yyvsp[-5].ValIDVal));
5791     (yyvsp[-2].ValIDVal).S.makeSignless();
5792     BasicBlock* tmpBB = getBBVal((yyvsp[-2].ValIDVal));
5793     SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0);
5794     (yyval.TermInstVal).TI = S;
5795     (yyval.TermInstVal).S.makeSignless();
5796   ;}
5797     break;
5798
5799   case 267:
5800 #line 3227 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5801     {
5802     const PointerType *PFTy;
5803     const FunctionType *Ty;
5804     Signedness FTySign;
5805
5806     if (!(PFTy = dyn_cast<PointerType>((yyvsp[-10].TypeVal).PAT->get())) ||
5807         !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
5808       // Pull out the types of all of the arguments...
5809       std::vector<const Type*> ParamTypes;
5810       FTySign.makeComposite((yyvsp[-10].TypeVal).S);
5811       if ((yyvsp[-7].ValueList)) {
5812         for (std::vector<ValueInfo>::iterator I = (yyvsp[-7].ValueList)->begin(), E = (yyvsp[-7].ValueList)->end();
5813              I != E; ++I) {
5814           ParamTypes.push_back((*I).V->getType());
5815           FTySign.add(I->S);
5816         }
5817       }
5818       FunctionType::ParamAttrsList ParamAttrs;
5819       if ((yyvsp[-11].UIntVal) == OldCallingConv::CSRet) {
5820         ParamAttrs.push_back(FunctionType::NoAttributeSet);
5821         ParamAttrs.push_back(FunctionType::StructRetAttribute);
5822       }
5823       bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
5824       if (isVarArg) ParamTypes.pop_back();
5825       Ty = FunctionType::get((yyvsp[-10].TypeVal).PAT->get(), ParamTypes, isVarArg, ParamAttrs);
5826       PFTy = PointerType::get(Ty);
5827       (yyval.TermInstVal).S.copy((yyvsp[-10].TypeVal).S);
5828     } else {
5829       FTySign = (yyvsp[-10].TypeVal).S;
5830       (yyval.TermInstVal).S.copy((yyvsp[-10].TypeVal).S.get(0)); // 0th element of FuncTy sign is result ty
5831     }
5832     (yyvsp[-9].ValIDVal).S.makeComposite(FTySign);
5833     Value *V = getVal(PFTy, (yyvsp[-9].ValIDVal));   // Get the function we're calling...
5834     BasicBlock *Normal = getBBVal((yyvsp[-3].ValIDVal));
5835     BasicBlock *Except = getBBVal((yyvsp[0].ValIDVal));
5836
5837     // Create the call node...
5838     if (!(yyvsp[-7].ValueList)) {                                   // Has no arguments?
5839       (yyval.TermInstVal).TI = new InvokeInst(V, Normal, Except, 0, 0);
5840     } else {                                     // Has arguments?
5841       // Loop through FunctionType's arguments and ensure they are specified
5842       // correctly!
5843       //
5844       FunctionType::param_iterator I = Ty->param_begin();
5845       FunctionType::param_iterator E = Ty->param_end();
5846       std::vector<ValueInfo>::iterator ArgI = (yyvsp[-7].ValueList)->begin(), ArgE = (yyvsp[-7].ValueList)->end();
5847
5848       std::vector<Value*> Args;
5849       for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
5850         if ((*ArgI).V->getType() != *I)
5851           error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
5852                 (*I)->getDescription() + "'");
5853         Args.push_back((*ArgI).V);
5854       }
5855
5856       if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
5857         error("Invalid number of parameters detected");
5858
5859       (yyval.TermInstVal).TI = new InvokeInst(V, Normal, Except, &Args[0], Args.size());
5860     }
5861     cast<InvokeInst>((yyval.TermInstVal).TI)->setCallingConv(upgradeCallingConv((yyvsp[-11].UIntVal)));
5862     delete (yyvsp[-10].TypeVal).PAT;
5863     delete (yyvsp[-7].ValueList);
5864   ;}
5865     break;
5866
5867   case 268:
5868 #line 3291 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5869     {
5870     (yyval.TermInstVal).TI = new UnwindInst();
5871     (yyval.TermInstVal).S.makeSignless();
5872   ;}
5873     break;
5874
5875   case 269:
5876 #line 3295 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5877     {
5878     (yyval.TermInstVal).TI = new UnreachableInst();
5879     (yyval.TermInstVal).S.makeSignless();
5880   ;}
5881     break;
5882
5883   case 270:
5884 #line 3302 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5885     {
5886     (yyval.JumpTable) = (yyvsp[-5].JumpTable);
5887     (yyvsp[-3].ValIDVal).S.copy((yyvsp[-4].PrimType).S);
5888     Constant *V = cast<Constant>(getExistingValue((yyvsp[-4].PrimType).T, (yyvsp[-3].ValIDVal)));
5889     
5890     if (V == 0)
5891       error("May only switch on a constant pool value");
5892
5893     (yyvsp[0].ValIDVal).S.makeSignless();
5894     BasicBlock* tmpBB = getBBVal((yyvsp[0].ValIDVal));
5895     (yyval.JumpTable)->push_back(std::make_pair(V, tmpBB));
5896   ;}
5897     break;
5898
5899   case 271:
5900 #line 3314 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5901     {
5902     (yyval.JumpTable) = new std::vector<std::pair<Constant*, BasicBlock*> >();
5903     (yyvsp[-3].ValIDVal).S.copy((yyvsp[-4].PrimType).S);
5904     Constant *V = cast<Constant>(getExistingValue((yyvsp[-4].PrimType).T, (yyvsp[-3].ValIDVal)));
5905
5906     if (V == 0)
5907       error("May only switch on a constant pool value");
5908
5909     (yyvsp[0].ValIDVal).S.makeSignless();
5910     BasicBlock* tmpBB = getBBVal((yyvsp[0].ValIDVal));
5911     (yyval.JumpTable)->push_back(std::make_pair(V, tmpBB)); 
5912   ;}
5913     break;
5914
5915   case 272:
5916 #line 3329 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5917     {
5918     bool omit = false;
5919     if ((yyvsp[-1].StrVal))
5920       if (BitCastInst *BCI = dyn_cast<BitCastInst>((yyvsp[0].InstVal).I))
5921         if (BCI->getSrcTy() == BCI->getDestTy() && 
5922             BCI->getOperand(0)->getName() == (yyvsp[-1].StrVal))
5923           // This is a useless bit cast causing a name redefinition. It is
5924           // a bit cast from a type to the same type of an operand with the
5925           // same name as the name we would give this instruction. Since this
5926           // instruction results in no code generation, it is safe to omit
5927           // the instruction. This situation can occur because of collapsed
5928           // type planes. For example:
5929           //   %X = add int %Y, %Z
5930           //   %X = cast int %Y to uint
5931           // After upgrade, this looks like:
5932           //   %X = add i32 %Y, %Z
5933           //   %X = bitcast i32 to i32
5934           // The bitcast is clearly useless so we omit it.
5935           omit = true;
5936     if (omit) {
5937       (yyval.InstVal).I = 0;
5938       (yyval.InstVal).S.makeSignless();
5939     } else {
5940       ValueInfo VI; VI.V = (yyvsp[0].InstVal).I; VI.S.copy((yyvsp[0].InstVal).S);
5941       setValueName(VI, (yyvsp[-1].StrVal));
5942       InsertValue((yyvsp[0].InstVal).I);
5943       (yyval.InstVal) = (yyvsp[0].InstVal);
5944     }
5945   ;}
5946     break;
5947
5948   case 273:
5949 #line 3359 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5950     {    // Used for PHI nodes
5951     (yyval.PHIList).P = new std::list<std::pair<Value*, BasicBlock*> >();
5952     (yyval.PHIList).S.copy((yyvsp[-5].TypeVal).S);
5953     (yyvsp[-3].ValIDVal).S.copy((yyvsp[-5].TypeVal).S);
5954     Value* tmpVal = getVal((yyvsp[-5].TypeVal).PAT->get(), (yyvsp[-3].ValIDVal));
5955     (yyvsp[-1].ValIDVal).S.makeSignless();
5956     BasicBlock* tmpBB = getBBVal((yyvsp[-1].ValIDVal));
5957     (yyval.PHIList).P->push_back(std::make_pair(tmpVal, tmpBB));
5958     delete (yyvsp[-5].TypeVal).PAT;
5959   ;}
5960     break;
5961
5962   case 274:
5963 #line 3369 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5964     {
5965     (yyval.PHIList) = (yyvsp[-6].PHIList);
5966     (yyvsp[-3].ValIDVal).S.copy((yyvsp[-6].PHIList).S);
5967     Value* tmpVal = getVal((yyvsp[-6].PHIList).P->front().first->getType(), (yyvsp[-3].ValIDVal));
5968     (yyvsp[-1].ValIDVal).S.makeSignless();
5969     BasicBlock* tmpBB = getBBVal((yyvsp[-1].ValIDVal));
5970     (yyvsp[-6].PHIList).P->push_back(std::make_pair(tmpVal, tmpBB));
5971   ;}
5972     break;
5973
5974   case 275:
5975 #line 3379 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5976     {    // Used for call statements, and memory insts...
5977     (yyval.ValueList) = new std::vector<ValueInfo>();
5978     (yyval.ValueList)->push_back((yyvsp[0].ValueVal));
5979   ;}
5980     break;
5981
5982   case 276:
5983 #line 3383 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5984     {
5985     (yyval.ValueList) = (yyvsp[-2].ValueList);
5986     (yyvsp[-2].ValueList)->push_back((yyvsp[0].ValueVal));
5987   ;}
5988     break;
5989
5990   case 278:
5991 #line 3391 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5992     { (yyval.ValueList) = 0; ;}
5993     break;
5994
5995   case 279:
5996 #line 3395 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
5997     {
5998     (yyval.BoolVal) = true;
5999   ;}
6000     break;
6001
6002   case 280:
6003 #line 3398 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6004     {
6005     (yyval.BoolVal) = false;
6006   ;}
6007     break;
6008
6009   case 281:
6010 #line 3404 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6011     {
6012     (yyvsp[-2].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6013     (yyvsp[0].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6014     const Type* Ty = (yyvsp[-3].TypeVal).PAT->get();
6015     if (!Ty->isInteger() && !Ty->isFloatingPoint() && !isa<VectorType>(Ty))
6016       error("Arithmetic operator requires integer, FP, or packed operands");
6017     if (isa<VectorType>(Ty) && 
6018         ((yyvsp[-4].BinaryOpVal) == URemOp || (yyvsp[-4].BinaryOpVal) == SRemOp || (yyvsp[-4].BinaryOpVal) == FRemOp || (yyvsp[-4].BinaryOpVal) == RemOp))
6019       error("Remainder not supported on vector types");
6020     // Upgrade the opcode from obsolete versions before we do anything with it.
6021     Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[-4].BinaryOpVal), Ty, (yyvsp[-3].TypeVal).S);
6022     Value* val1 = getVal(Ty, (yyvsp[-2].ValIDVal)); 
6023     Value* val2 = getVal(Ty, (yyvsp[0].ValIDVal));
6024     (yyval.InstVal).I = BinaryOperator::create(Opcode, val1, val2);
6025     if ((yyval.InstVal).I == 0)
6026       error("binary operator returned null");
6027     (yyval.InstVal).S.copy((yyvsp[-3].TypeVal).S);
6028     delete (yyvsp[-3].TypeVal).PAT;
6029   ;}
6030     break;
6031
6032   case 282:
6033 #line 3423 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6034     {
6035     (yyvsp[-2].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6036     (yyvsp[0].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6037     const Type *Ty = (yyvsp[-3].TypeVal).PAT->get();
6038     if (!Ty->isInteger()) {
6039       if (!isa<VectorType>(Ty) ||
6040           !cast<VectorType>(Ty)->getElementType()->isInteger())
6041         error("Logical operator requires integral operands");
6042     }
6043     Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[-4].BinaryOpVal), Ty, (yyvsp[-3].TypeVal).S);
6044     Value* tmpVal1 = getVal(Ty, (yyvsp[-2].ValIDVal));
6045     Value* tmpVal2 = getVal(Ty, (yyvsp[0].ValIDVal));
6046     (yyval.InstVal).I = BinaryOperator::create(Opcode, tmpVal1, tmpVal2);
6047     if ((yyval.InstVal).I == 0)
6048       error("binary operator returned null");
6049     (yyval.InstVal).S.copy((yyvsp[-3].TypeVal).S);
6050     delete (yyvsp[-3].TypeVal).PAT;
6051   ;}
6052     break;
6053
6054   case 283:
6055 #line 3441 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6056     {
6057     (yyvsp[-2].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6058     (yyvsp[0].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6059     const Type* Ty = (yyvsp[-3].TypeVal).PAT->get();
6060     if(isa<VectorType>(Ty))
6061       error("VectorTypes currently not supported in setcc instructions");
6062     unsigned short pred;
6063     Instruction::OtherOps Opcode = getCompareOp((yyvsp[-4].BinaryOpVal), pred, Ty, (yyvsp[-3].TypeVal).S);
6064     Value* tmpVal1 = getVal(Ty, (yyvsp[-2].ValIDVal));
6065     Value* tmpVal2 = getVal(Ty, (yyvsp[0].ValIDVal));
6066     (yyval.InstVal).I = CmpInst::create(Opcode, pred, tmpVal1, tmpVal2);
6067     if ((yyval.InstVal).I == 0)
6068       error("binary operator returned null");
6069     (yyval.InstVal).S.makeUnsigned();
6070     delete (yyvsp[-3].TypeVal).PAT;
6071   ;}
6072     break;
6073
6074   case 284:
6075 #line 3457 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6076     {
6077     (yyvsp[-2].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6078     (yyvsp[0].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6079     const Type *Ty = (yyvsp[-3].TypeVal).PAT->get();
6080     if (isa<VectorType>(Ty)) 
6081       error("VectorTypes currently not supported in icmp instructions");
6082     else if (!Ty->isInteger() && !isa<PointerType>(Ty))
6083       error("icmp requires integer or pointer typed operands");
6084     Value* tmpVal1 = getVal(Ty, (yyvsp[-2].ValIDVal));
6085     Value* tmpVal2 = getVal(Ty, (yyvsp[0].ValIDVal));
6086     (yyval.InstVal).I = new ICmpInst((yyvsp[-4].IPred), tmpVal1, tmpVal2);
6087     (yyval.InstVal).S.makeUnsigned();
6088     delete (yyvsp[-3].TypeVal).PAT;
6089   ;}
6090     break;
6091
6092   case 285:
6093 #line 3471 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6094     {
6095     (yyvsp[-2].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6096     (yyvsp[0].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6097     const Type *Ty = (yyvsp[-3].TypeVal).PAT->get();
6098     if (isa<VectorType>(Ty))
6099       error("VectorTypes currently not supported in fcmp instructions");
6100     else if (!Ty->isFloatingPoint())
6101       error("fcmp instruction requires floating point operands");
6102     Value* tmpVal1 = getVal(Ty, (yyvsp[-2].ValIDVal));
6103     Value* tmpVal2 = getVal(Ty, (yyvsp[0].ValIDVal));
6104     (yyval.InstVal).I = new FCmpInst((yyvsp[-4].FPred), tmpVal1, tmpVal2);
6105     (yyval.InstVal).S.makeUnsigned();
6106     delete (yyvsp[-3].TypeVal).PAT;
6107   ;}
6108     break;
6109
6110   case 286:
6111 #line 3485 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6112     {
6113     warning("Use of obsolete 'not' instruction: Replacing with 'xor");
6114     const Type *Ty = (yyvsp[0].ValueVal).V->getType();
6115     Value *Ones = ConstantInt::getAllOnesValue(Ty);
6116     if (Ones == 0)
6117       error("Expected integral type for not instruction");
6118     (yyval.InstVal).I = BinaryOperator::create(Instruction::Xor, (yyvsp[0].ValueVal).V, Ones);
6119     if ((yyval.InstVal).I == 0)
6120       error("Could not create a xor instruction");
6121     (yyval.InstVal).S.copy((yyvsp[0].ValueVal).S);
6122   ;}
6123     break;
6124
6125   case 287:
6126 #line 3496 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6127     {
6128     if (!(yyvsp[0].ValueVal).V->getType()->isInteger() ||
6129         cast<IntegerType>((yyvsp[0].ValueVal).V->getType())->getBitWidth() != 8)
6130       error("Shift amount must be int8");
6131     const Type* Ty = (yyvsp[-2].ValueVal).V->getType();
6132     if (!Ty->isInteger())
6133       error("Shift constant expression requires integer operand");
6134     Value* ShiftAmt = 0;
6135     if (cast<IntegerType>(Ty)->getBitWidth() > Type::Int8Ty->getBitWidth())
6136       if (Constant *C = dyn_cast<Constant>((yyvsp[0].ValueVal).V))
6137         ShiftAmt = ConstantExpr::getZExt(C, Ty);
6138       else
6139         ShiftAmt = new ZExtInst((yyvsp[0].ValueVal).V, Ty, makeNameUnique("shift"), CurBB);
6140     else
6141       ShiftAmt = (yyvsp[0].ValueVal).V;
6142     (yyval.InstVal).I = BinaryOperator::create(getBinaryOp((yyvsp[-3].BinaryOpVal), Ty, (yyvsp[-2].ValueVal).S), (yyvsp[-2].ValueVal).V, ShiftAmt);
6143     (yyval.InstVal).S.copy((yyvsp[-2].ValueVal).S);
6144   ;}
6145     break;
6146
6147   case 288:
6148 #line 3514 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6149     {
6150     const Type *DstTy = (yyvsp[0].TypeVal).PAT->get();
6151     if (!DstTy->isFirstClassType())
6152       error("cast instruction to a non-primitive type: '" +
6153             DstTy->getDescription() + "'");
6154     (yyval.InstVal).I = cast<Instruction>(getCast((yyvsp[-3].CastOpVal), (yyvsp[-2].ValueVal).V, (yyvsp[-2].ValueVal).S, DstTy, (yyvsp[0].TypeVal).S, true));
6155     (yyval.InstVal).S.copy((yyvsp[0].TypeVal).S);
6156     delete (yyvsp[0].TypeVal).PAT;
6157   ;}
6158     break;
6159
6160   case 289:
6161 #line 3523 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6162     {
6163     if (!(yyvsp[-4].ValueVal).V->getType()->isInteger() ||
6164         cast<IntegerType>((yyvsp[-4].ValueVal).V->getType())->getBitWidth() != 1)
6165       error("select condition must be bool");
6166     if ((yyvsp[-2].ValueVal).V->getType() != (yyvsp[0].ValueVal).V->getType())
6167       error("select value types should match");
6168     (yyval.InstVal).I = new SelectInst((yyvsp[-4].ValueVal).V, (yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V);
6169     (yyval.InstVal).S.copy((yyvsp[-2].ValueVal).S);
6170   ;}
6171     break;
6172
6173   case 290:
6174 #line 3532 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6175     {
6176     const Type *Ty = (yyvsp[0].TypeVal).PAT->get();
6177     NewVarArgs = true;
6178     (yyval.InstVal).I = new VAArgInst((yyvsp[-2].ValueVal).V, Ty);
6179     (yyval.InstVal).S.copy((yyvsp[0].TypeVal).S);
6180     delete (yyvsp[0].TypeVal).PAT;
6181   ;}
6182     break;
6183
6184   case 291:
6185 #line 3539 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6186     {
6187     const Type* ArgTy = (yyvsp[-2].ValueVal).V->getType();
6188     const Type* DstTy = (yyvsp[0].TypeVal).PAT->get();
6189     ObsoleteVarArgs = true;
6190     Function* NF = cast<Function>(CurModule.CurrentModule->
6191       getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
6192
6193     //b = vaarg a, t -> 
6194     //foo = alloca 1 of t
6195     //bar = vacopy a 
6196     //store bar -> foo
6197     //b = vaarg foo, t
6198     AllocaInst* foo = new AllocaInst(ArgTy, 0, "vaarg.fix");
6199     CurBB->getInstList().push_back(foo);
6200     CallInst* bar = new CallInst(NF, (yyvsp[-2].ValueVal).V);
6201     CurBB->getInstList().push_back(bar);
6202     CurBB->getInstList().push_back(new StoreInst(bar, foo));
6203     (yyval.InstVal).I = new VAArgInst(foo, DstTy);
6204     (yyval.InstVal).S.copy((yyvsp[0].TypeVal).S);
6205     delete (yyvsp[0].TypeVal).PAT;
6206   ;}
6207     break;
6208
6209   case 292:
6210 #line 3560 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6211     {
6212     const Type* ArgTy = (yyvsp[-2].ValueVal).V->getType();
6213     const Type* DstTy = (yyvsp[0].TypeVal).PAT->get();
6214     ObsoleteVarArgs = true;
6215     Function* NF = cast<Function>(CurModule.CurrentModule->
6216       getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
6217
6218     //b = vanext a, t ->
6219     //foo = alloca 1 of t
6220     //bar = vacopy a
6221     //store bar -> foo
6222     //tmp = vaarg foo, t
6223     //b = load foo
6224     AllocaInst* foo = new AllocaInst(ArgTy, 0, "vanext.fix");
6225     CurBB->getInstList().push_back(foo);
6226     CallInst* bar = new CallInst(NF, (yyvsp[-2].ValueVal).V);
6227     CurBB->getInstList().push_back(bar);
6228     CurBB->getInstList().push_back(new StoreInst(bar, foo));
6229     Instruction* tmp = new VAArgInst(foo, DstTy);
6230     CurBB->getInstList().push_back(tmp);
6231     (yyval.InstVal).I = new LoadInst(foo);
6232     (yyval.InstVal).S.copy((yyvsp[0].TypeVal).S);
6233     delete (yyvsp[0].TypeVal).PAT;
6234   ;}
6235     break;
6236
6237   case 293:
6238 #line 3584 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6239     {
6240     if (!ExtractElementInst::isValidOperands((yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V))
6241       error("Invalid extractelement operands");
6242     (yyval.InstVal).I = new ExtractElementInst((yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V);
6243     (yyval.InstVal).S.copy((yyvsp[-2].ValueVal).S.get(0));
6244   ;}
6245     break;
6246
6247   case 294:
6248 #line 3590 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6249     {
6250     if (!InsertElementInst::isValidOperands((yyvsp[-4].ValueVal).V, (yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V))
6251       error("Invalid insertelement operands");
6252     (yyval.InstVal).I = new InsertElementInst((yyvsp[-4].ValueVal).V, (yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V);
6253     (yyval.InstVal).S.copy((yyvsp[-4].ValueVal).S);
6254   ;}
6255     break;
6256
6257   case 295:
6258 #line 3596 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6259     {
6260     if (!ShuffleVectorInst::isValidOperands((yyvsp[-4].ValueVal).V, (yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V))
6261       error("Invalid shufflevector operands");
6262     (yyval.InstVal).I = new ShuffleVectorInst((yyvsp[-4].ValueVal).V, (yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V);
6263     (yyval.InstVal).S.copy((yyvsp[-4].ValueVal).S);
6264   ;}
6265     break;
6266
6267   case 296:
6268 #line 3602 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6269     {
6270     const Type *Ty = (yyvsp[0].PHIList).P->front().first->getType();
6271     if (!Ty->isFirstClassType())
6272       error("PHI node operands must be of first class type");
6273     PHINode *PHI = new PHINode(Ty);
6274     PHI->reserveOperandSpace((yyvsp[0].PHIList).P->size());
6275     while ((yyvsp[0].PHIList).P->begin() != (yyvsp[0].PHIList).P->end()) {
6276       if ((yyvsp[0].PHIList).P->front().first->getType() != Ty) 
6277         error("All elements of a PHI node must be of the same type");
6278       PHI->addIncoming((yyvsp[0].PHIList).P->front().first, (yyvsp[0].PHIList).P->front().second);
6279       (yyvsp[0].PHIList).P->pop_front();
6280     }
6281     (yyval.InstVal).I = PHI;
6282     (yyval.InstVal).S.copy((yyvsp[0].PHIList).S);
6283     delete (yyvsp[0].PHIList).P;  // Free the list...
6284   ;}
6285     break;
6286
6287   case 297:
6288 #line 3618 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6289     {
6290     // Handle the short call syntax
6291     const PointerType *PFTy;
6292     const FunctionType *FTy;
6293     Signedness FTySign;
6294     if (!(PFTy = dyn_cast<PointerType>((yyvsp[-4].TypeVal).PAT->get())) ||
6295         !(FTy = dyn_cast<FunctionType>(PFTy->getElementType()))) {
6296       // Pull out the types of all of the arguments...
6297       std::vector<const Type*> ParamTypes;
6298       FTySign.makeComposite((yyvsp[-4].TypeVal).S);
6299       if ((yyvsp[-1].ValueList)) {
6300         for (std::vector<ValueInfo>::iterator I = (yyvsp[-1].ValueList)->begin(), E = (yyvsp[-1].ValueList)->end();
6301              I != E; ++I) {
6302           ParamTypes.push_back((*I).V->getType());
6303           FTySign.add(I->S);
6304         }
6305       }
6306
6307       FunctionType::ParamAttrsList ParamAttrs;
6308       if ((yyvsp[-5].UIntVal) == OldCallingConv::CSRet) {
6309         ParamAttrs.push_back(FunctionType::NoAttributeSet);
6310         ParamAttrs.push_back(FunctionType::StructRetAttribute);
6311       }
6312       bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
6313       if (isVarArg) ParamTypes.pop_back();
6314
6315       const Type *RetTy = (yyvsp[-4].TypeVal).PAT->get();
6316       if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
6317         error("Functions cannot return aggregate types");
6318
6319       FTy = FunctionType::get(RetTy, ParamTypes, isVarArg, ParamAttrs);
6320       PFTy = PointerType::get(FTy);
6321       (yyval.InstVal).S.copy((yyvsp[-4].TypeVal).S);
6322     } else {
6323       FTySign = (yyvsp[-4].TypeVal).S;
6324       (yyval.InstVal).S.copy((yyvsp[-4].TypeVal).S.get(0)); // 0th element of FuncTy signedness is result sign
6325     }
6326     (yyvsp[-3].ValIDVal).S.makeComposite(FTySign);
6327
6328     // First upgrade any intrinsic calls.
6329     std::vector<Value*> Args;
6330     if ((yyvsp[-1].ValueList))
6331       for (unsigned i = 0, e = (yyvsp[-1].ValueList)->size(); i < e; ++i) 
6332         Args.push_back((*(yyvsp[-1].ValueList))[i].V);
6333     Instruction *Inst = upgradeIntrinsicCall(FTy, (yyvsp[-3].ValIDVal), Args);
6334
6335     // If we got an upgraded intrinsic
6336     if (Inst) {
6337       (yyval.InstVal).I = Inst;
6338     } else {
6339       // Get the function we're calling
6340       Value *V = getVal(PFTy, (yyvsp[-3].ValIDVal));
6341
6342       // Check the argument values match
6343       if (!(yyvsp[-1].ValueList)) {                                   // Has no arguments?
6344         // Make sure no arguments is a good thing!
6345         if (FTy->getNumParams() != 0)
6346           error("No arguments passed to a function that expects arguments");
6347       } else {                                     // Has arguments?
6348         // Loop through FunctionType's arguments and ensure they are specified
6349         // correctly!
6350         //
6351         FunctionType::param_iterator I = FTy->param_begin();
6352         FunctionType::param_iterator E = FTy->param_end();
6353         std::vector<ValueInfo>::iterator ArgI = (yyvsp[-1].ValueList)->begin(), ArgE = (yyvsp[-1].ValueList)->end();
6354
6355         for (; ArgI != ArgE && I != E; ++ArgI, ++I)
6356           if ((*ArgI).V->getType() != *I)
6357             error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
6358                   (*I)->getDescription() + "'");
6359
6360         if (I != E || (ArgI != ArgE && !FTy->isVarArg()))
6361           error("Invalid number of parameters detected");
6362       }
6363
6364       // Create the call instruction
6365       CallInst *CI = new CallInst(V, &Args[0], Args.size());
6366       CI->setTailCall((yyvsp[-6].BoolVal));
6367       CI->setCallingConv(upgradeCallingConv((yyvsp[-5].UIntVal)));
6368       (yyval.InstVal).I = CI;
6369     }
6370     delete (yyvsp[-4].TypeVal).PAT;
6371     delete (yyvsp[-1].ValueList);
6372   ;}
6373     break;
6374
6375   case 298:
6376 #line 3702 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6377     {
6378     (yyval.InstVal) = (yyvsp[0].InstVal);
6379   ;}
6380     break;
6381
6382   case 299:
6383 #line 3710 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6384     { (yyval.ValueList) = (yyvsp[0].ValueList); ;}
6385     break;
6386
6387   case 300:
6388 #line 3711 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6389     { (yyval.ValueList) = new std::vector<ValueInfo>(); ;}
6390     break;
6391
6392   case 301:
6393 #line 3715 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6394     { (yyval.BoolVal) = true; ;}
6395     break;
6396
6397   case 302:
6398 #line 3716 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6399     { (yyval.BoolVal) = false; ;}
6400     break;
6401
6402   case 303:
6403 #line 3720 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6404     {
6405     const Type *Ty = (yyvsp[-1].TypeVal).PAT->get();
6406     (yyval.InstVal).S.makeComposite((yyvsp[-1].TypeVal).S);
6407     (yyval.InstVal).I = new MallocInst(Ty, 0, (yyvsp[0].UIntVal));
6408     delete (yyvsp[-1].TypeVal).PAT;
6409   ;}
6410     break;
6411
6412   case 304:
6413 #line 3726 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6414     {
6415     const Type *Ty = (yyvsp[-4].TypeVal).PAT->get();
6416     (yyvsp[-1].ValIDVal).S.makeUnsigned();
6417     (yyval.InstVal).S.makeComposite((yyvsp[-4].TypeVal).S);
6418     (yyval.InstVal).I = new MallocInst(Ty, getVal((yyvsp[-2].PrimType).T, (yyvsp[-1].ValIDVal)), (yyvsp[0].UIntVal));
6419     delete (yyvsp[-4].TypeVal).PAT;
6420   ;}
6421     break;
6422
6423   case 305:
6424 #line 3733 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6425     {
6426     const Type *Ty = (yyvsp[-1].TypeVal).PAT->get();
6427     (yyval.InstVal).S.makeComposite((yyvsp[-1].TypeVal).S);
6428     (yyval.InstVal).I = new AllocaInst(Ty, 0, (yyvsp[0].UIntVal));
6429     delete (yyvsp[-1].TypeVal).PAT;
6430   ;}
6431     break;
6432
6433   case 306:
6434 #line 3739 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6435     {
6436     const Type *Ty = (yyvsp[-4].TypeVal).PAT->get();
6437     (yyvsp[-1].ValIDVal).S.makeUnsigned();
6438     (yyval.InstVal).S.makeComposite((yyvsp[-2].PrimType).S);
6439     (yyval.InstVal).I = new AllocaInst(Ty, getVal((yyvsp[-2].PrimType).T, (yyvsp[-1].ValIDVal)), (yyvsp[0].UIntVal));
6440     delete (yyvsp[-4].TypeVal).PAT;
6441   ;}
6442     break;
6443
6444   case 307:
6445 #line 3746 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6446     {
6447     const Type *PTy = (yyvsp[0].ValueVal).V->getType();
6448     if (!isa<PointerType>(PTy))
6449       error("Trying to free nonpointer type '" + PTy->getDescription() + "'");
6450     (yyval.InstVal).I = new FreeInst((yyvsp[0].ValueVal).V);
6451     (yyval.InstVal).S.makeSignless();
6452   ;}
6453     break;
6454
6455   case 308:
6456 #line 3753 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6457     {
6458     const Type* Ty = (yyvsp[-1].TypeVal).PAT->get();
6459     (yyvsp[0].ValIDVal).S.copy((yyvsp[-1].TypeVal).S);
6460     if (!isa<PointerType>(Ty))
6461       error("Can't load from nonpointer type: " + Ty->getDescription());
6462     if (!cast<PointerType>(Ty)->getElementType()->isFirstClassType())
6463       error("Can't load from pointer of non-first-class type: " +
6464                      Ty->getDescription());
6465     Value* tmpVal = getVal(Ty, (yyvsp[0].ValIDVal));
6466     (yyval.InstVal).I = new LoadInst(tmpVal, "", (yyvsp[-3].BoolVal));
6467     (yyval.InstVal).S.copy((yyvsp[-1].TypeVal).S.get(0));
6468     delete (yyvsp[-1].TypeVal).PAT;
6469   ;}
6470     break;
6471
6472   case 309:
6473 #line 3766 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6474     {
6475     (yyvsp[0].ValIDVal).S.copy((yyvsp[-1].TypeVal).S);
6476     const PointerType *PTy = dyn_cast<PointerType>((yyvsp[-1].TypeVal).PAT->get());
6477     if (!PTy)
6478       error("Can't store to a nonpointer type: " + 
6479              (yyvsp[-1].TypeVal).PAT->get()->getDescription());
6480     const Type *ElTy = PTy->getElementType();
6481     Value *StoreVal = (yyvsp[-3].ValueVal).V;
6482     Value* tmpVal = getVal(PTy, (yyvsp[0].ValIDVal));
6483     if (ElTy != (yyvsp[-3].ValueVal).V->getType()) {
6484       StoreVal = handleSRetFuncTypeMerge((yyvsp[-3].ValueVal).V, ElTy);
6485       if (!StoreVal)
6486         error("Can't store '" + (yyvsp[-3].ValueVal).V->getType()->getDescription() +
6487               "' into space of type '" + ElTy->getDescription() + "'");
6488       else {
6489         PTy = PointerType::get(StoreVal->getType());
6490         if (Constant *C = dyn_cast<Constant>(tmpVal))
6491           tmpVal = ConstantExpr::getBitCast(C, PTy);
6492         else
6493           tmpVal = new BitCastInst(tmpVal, PTy, "upgrd.cast", CurBB);
6494       }
6495     }
6496     (yyval.InstVal).I = new StoreInst(StoreVal, tmpVal, (yyvsp[-5].BoolVal));
6497     (yyval.InstVal).S.makeSignless();
6498     delete (yyvsp[-1].TypeVal).PAT;
6499   ;}
6500     break;
6501
6502   case 310:
6503 #line 3792 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6504     {
6505     (yyvsp[-1].ValIDVal).S.copy((yyvsp[-2].TypeVal).S);
6506     const Type* Ty = (yyvsp[-2].TypeVal).PAT->get();
6507     if (!isa<PointerType>(Ty))
6508       error("getelementptr insn requires pointer operand");
6509
6510     std::vector<Value*> VIndices;
6511     upgradeGEPIndices(Ty, (yyvsp[0].ValueList), VIndices);
6512
6513     Value* tmpVal = getVal(Ty, (yyvsp[-1].ValIDVal));
6514     (yyval.InstVal).I = new GetElementPtrInst(tmpVal, &VIndices[0], VIndices.size());
6515     ValueInfo VI; VI.V = tmpVal; VI.S.copy((yyvsp[-2].TypeVal).S);
6516     (yyval.InstVal).S.copy(getElementSign(VI, VIndices));
6517     delete (yyvsp[-2].TypeVal).PAT;
6518     delete (yyvsp[0].ValueList);
6519   ;}
6520     break;
6521
6522
6523       default: break;
6524     }
6525
6526 /* Line 1126 of yacc.c.  */
6527 #line 6528 "UpgradeParser.tab.c"
6528 \f
6529   yyvsp -= yylen;
6530   yyssp -= yylen;
6531
6532
6533   YY_STACK_PRINT (yyss, yyssp);
6534
6535   *++yyvsp = yyval;
6536
6537
6538   /* Now `shift' the result of the reduction.  Determine what state
6539      that goes to, based on the state we popped back to and the rule
6540      number reduced by.  */
6541
6542   yyn = yyr1[yyn];
6543
6544   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
6545   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
6546     yystate = yytable[yystate];
6547   else
6548     yystate = yydefgoto[yyn - YYNTOKENS];
6549
6550   goto yynewstate;
6551
6552
6553 /*------------------------------------.
6554 | yyerrlab -- here on detecting error |
6555 `------------------------------------*/
6556 yyerrlab:
6557   /* If not already recovering from an error, report this error.  */
6558   if (!yyerrstatus)
6559     {
6560       ++yynerrs;
6561 #if YYERROR_VERBOSE
6562       yyn = yypact[yystate];
6563
6564       if (YYPACT_NINF < yyn && yyn < YYLAST)
6565         {
6566           int yytype = YYTRANSLATE (yychar);
6567           YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
6568           YYSIZE_T yysize = yysize0;
6569           YYSIZE_T yysize1;
6570           int yysize_overflow = 0;
6571           char *yymsg = 0;
6572 #         define YYERROR_VERBOSE_ARGS_MAXIMUM 5
6573           char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
6574           int yyx;
6575
6576 #if 0
6577           /* This is so xgettext sees the translatable formats that are
6578              constructed on the fly.  */
6579           YY_("syntax error, unexpected %s");
6580           YY_("syntax error, unexpected %s, expecting %s");
6581           YY_("syntax error, unexpected %s, expecting %s or %s");
6582           YY_("syntax error, unexpected %s, expecting %s or %s or %s");
6583           YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
6584 #endif
6585           char *yyfmt;
6586           char const *yyf;
6587           static char const yyunexpected[] = "syntax error, unexpected %s";
6588           static char const yyexpecting[] = ", expecting %s";
6589           static char const yyor[] = " or %s";
6590           char yyformat[sizeof yyunexpected
6591                         + sizeof yyexpecting - 1
6592                         + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
6593                            * (sizeof yyor - 1))];
6594           char const *yyprefix = yyexpecting;
6595
6596           /* Start YYX at -YYN if negative to avoid negative indexes in
6597              YYCHECK.  */
6598           int yyxbegin = yyn < 0 ? -yyn : 0;
6599
6600           /* Stay within bounds of both yycheck and yytname.  */
6601           int yychecklim = YYLAST - yyn;
6602           int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
6603           int yycount = 1;
6604
6605           yyarg[0] = yytname[yytype];
6606           yyfmt = yystpcpy (yyformat, yyunexpected);
6607
6608           for (yyx = yyxbegin; yyx < yyxend; ++yyx)
6609             if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
6610               {
6611                 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
6612                   {
6613                     yycount = 1;
6614                     yysize = yysize0;
6615                     yyformat[sizeof yyunexpected - 1] = '\0';
6616                     break;
6617                   }
6618                 yyarg[yycount++] = yytname[yyx];
6619                 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
6620                 yysize_overflow |= yysize1 < yysize;
6621                 yysize = yysize1;
6622                 yyfmt = yystpcpy (yyfmt, yyprefix);
6623                 yyprefix = yyor;
6624               }
6625
6626           yyf = YY_(yyformat);
6627           yysize1 = yysize + yystrlen (yyf);
6628           yysize_overflow |= yysize1 < yysize;
6629           yysize = yysize1;
6630
6631           if (!yysize_overflow && yysize <= YYSTACK_ALLOC_MAXIMUM)
6632             yymsg = (char *) YYSTACK_ALLOC (yysize);
6633           if (yymsg)
6634             {
6635               /* Avoid sprintf, as that infringes on the user's name space.
6636                  Don't have undefined behavior even if the translation
6637                  produced a string with the wrong number of "%s"s.  */
6638               char *yyp = yymsg;
6639               int yyi = 0;
6640               while ((*yyp = *yyf))
6641                 {
6642                   if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
6643                     {
6644                       yyp += yytnamerr (yyp, yyarg[yyi++]);
6645                       yyf += 2;
6646                     }
6647                   else
6648                     {
6649                       yyp++;
6650                       yyf++;
6651                     }
6652                 }
6653               yyerror (yymsg);
6654               YYSTACK_FREE (yymsg);
6655             }
6656           else
6657             {
6658               yyerror (YY_("syntax error"));
6659               goto yyexhaustedlab;
6660             }
6661         }
6662       else
6663 #endif /* YYERROR_VERBOSE */
6664         yyerror (YY_("syntax error"));
6665     }
6666
6667
6668
6669   if (yyerrstatus == 3)
6670     {
6671       /* If just tried and failed to reuse look-ahead token after an
6672          error, discard it.  */
6673
6674       if (yychar <= YYEOF)
6675         {
6676           /* Return failure if at end of input.  */
6677           if (yychar == YYEOF)
6678             YYABORT;
6679         }
6680       else
6681         {
6682           yydestruct ("Error: discarding", yytoken, &yylval);
6683           yychar = YYEMPTY;
6684         }
6685     }
6686
6687   /* Else will try to reuse look-ahead token after shifting the error
6688      token.  */
6689   goto yyerrlab1;
6690
6691
6692 /*---------------------------------------------------.
6693 | yyerrorlab -- error raised explicitly by YYERROR.  |
6694 `---------------------------------------------------*/
6695 yyerrorlab:
6696
6697   /* Pacify compilers like GCC when the user code never invokes
6698      YYERROR and the label yyerrorlab therefore never appears in user
6699      code.  */
6700   if (0)
6701      goto yyerrorlab;
6702
6703 yyvsp -= yylen;
6704   yyssp -= yylen;
6705   yystate = *yyssp;
6706   goto yyerrlab1;
6707
6708
6709 /*-------------------------------------------------------------.
6710 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
6711 `-------------------------------------------------------------*/
6712 yyerrlab1:
6713   yyerrstatus = 3;      /* Each real token shifted decrements this.  */
6714
6715   for (;;)
6716     {
6717       yyn = yypact[yystate];
6718       if (yyn != YYPACT_NINF)
6719         {
6720           yyn += YYTERROR;
6721           if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
6722             {
6723               yyn = yytable[yyn];
6724               if (0 < yyn)
6725                 break;
6726             }
6727         }
6728
6729       /* Pop the current state because it cannot handle the error token.  */
6730       if (yyssp == yyss)
6731         YYABORT;
6732
6733
6734       yydestruct ("Error: popping", yystos[yystate], yyvsp);
6735       YYPOPSTACK;
6736       yystate = *yyssp;
6737       YY_STACK_PRINT (yyss, yyssp);
6738     }
6739
6740   if (yyn == YYFINAL)
6741     YYACCEPT;
6742
6743   *++yyvsp = yylval;
6744
6745
6746   /* Shift the error token. */
6747   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
6748
6749   yystate = yyn;
6750   goto yynewstate;
6751
6752
6753 /*-------------------------------------.
6754 | yyacceptlab -- YYACCEPT comes here.  |
6755 `-------------------------------------*/
6756 yyacceptlab:
6757   yyresult = 0;
6758   goto yyreturn;
6759
6760 /*-----------------------------------.
6761 | yyabortlab -- YYABORT comes here.  |
6762 `-----------------------------------*/
6763 yyabortlab:
6764   yyresult = 1;
6765   goto yyreturn;
6766
6767 #ifndef yyoverflow
6768 /*-------------------------------------------------.
6769 | yyexhaustedlab -- memory exhaustion comes here.  |
6770 `-------------------------------------------------*/
6771 yyexhaustedlab:
6772   yyerror (YY_("memory exhausted"));
6773   yyresult = 2;
6774   /* Fall through.  */
6775 #endif
6776
6777 yyreturn:
6778   if (yychar != YYEOF && yychar != YYEMPTY)
6779      yydestruct ("Cleanup: discarding lookahead",
6780                  yytoken, &yylval);
6781   while (yyssp != yyss)
6782     {
6783       yydestruct ("Cleanup: popping",
6784                   yystos[*yyssp], yyvsp);
6785       YYPOPSTACK;
6786     }
6787 #ifndef yyoverflow
6788   if (yyss != yyssa)
6789     YYSTACK_FREE (yyss);
6790 #endif
6791   return yyresult;
6792 }
6793
6794
6795 #line 3810 "/proj/llvm/llvm-1/tools/llvm-upgrade/UpgradeParser.y"
6796
6797
6798 int yyerror(const char *ErrorMsg) {
6799   std::string where 
6800     = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
6801                   + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
6802   std::string errMsg = where + "error: " + std::string(ErrorMsg);
6803   if (yychar != YYEMPTY && yychar != 0)
6804     errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
6805               "'.";
6806   std::cerr << "llvm-upgrade: " << errMsg << '\n';
6807   std::cout << "llvm-upgrade: parse failed.\n";
6808   exit(1);
6809 }
6810
6811 void warning(const std::string& ErrorMsg) {
6812   std::string where 
6813     = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
6814                   + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
6815   std::string errMsg = where + "warning: " + std::string(ErrorMsg);
6816   if (yychar != YYEMPTY && yychar != 0)
6817     errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
6818               "'.";
6819   std::cerr << "llvm-upgrade: " << errMsg << '\n';
6820 }
6821
6822 void error(const std::string& ErrorMsg, int LineNo) {
6823   if (LineNo == -1) LineNo = Upgradelineno;
6824   Upgradelineno = LineNo;
6825   yyerror(ErrorMsg.c_str());
6826 }
6827
6828