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