blob: c7935bcc21b498ea2cc9e12ed35f9f90603a9669 [file] [log] [blame]
David Greene9145dd22007-08-01 03:59:32 +00001/* A Bison parser, made by GNU Bison 1.875c. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002
3/* Skeleton parser for Yacc-like parsing with Bison,
David Greene9145dd22007-08-01 03:59:32 +00004 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005
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
David Greene9145dd22007-08-01 03:59:32 +000018 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +000020
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
Dan Gohmanf17a25c2007-07-18 16:29:46 +000039/* Skeleton name. */
40#define YYSKELETON_NAME "yacc.c"
41
42/* Pure parsers. */
43#define YYPURE 0
44
45/* Using locations. */
46#define YYLSP_NEEDED 0
47
David Greene9145dd22007-08-01 03:59:32 +000048/* If NAME_PREFIX is specified substitute the variables and functions
49 names. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +000050#define yyparse Upgradeparse
51#define yylex Upgradelex
52#define yyerror Upgradeerror
53#define yylval Upgradelval
54#define yychar Upgradechar
55#define yydebug Upgradedebug
56#define yynerrs Upgradenerrs
57
58
59/* Tokens. */
60#ifndef YYTOKENTYPE
61# define YYTOKENTYPE
62 /* Put the tokens into the symbol table, so that GDB and other debuggers
63 know about them. */
64 enum yytokentype {
65 ESINT64VAL = 258,
66 EUINT64VAL = 259,
67 SINTVAL = 260,
68 UINTVAL = 261,
69 FPVAL = 262,
70 VOID = 263,
71 BOOL = 264,
72 SBYTE = 265,
73 UBYTE = 266,
74 SHORT = 267,
75 USHORT = 268,
76 INT = 269,
77 UINT = 270,
78 LONG = 271,
79 ULONG = 272,
80 FLOAT = 273,
81 DOUBLE = 274,
82 TYPE = 275,
83 LABEL = 276,
84 VAR_ID = 277,
85 LABELSTR = 278,
86 STRINGCONSTANT = 279,
87 IMPLEMENTATION = 280,
88 ZEROINITIALIZER = 281,
89 TRUETOK = 282,
90 FALSETOK = 283,
91 BEGINTOK = 284,
92 ENDTOK = 285,
93 DECLARE = 286,
94 GLOBAL = 287,
95 CONSTANT = 288,
96 SECTION = 289,
97 VOLATILE = 290,
98 TO = 291,
99 DOTDOTDOT = 292,
100 NULL_TOK = 293,
101 UNDEF = 294,
102 CONST = 295,
103 INTERNAL = 296,
104 LINKONCE = 297,
105 WEAK = 298,
106 APPENDING = 299,
107 DLLIMPORT = 300,
108 DLLEXPORT = 301,
109 EXTERN_WEAK = 302,
110 OPAQUE = 303,
111 NOT = 304,
112 EXTERNAL = 305,
113 TARGET = 306,
114 TRIPLE = 307,
115 ENDIAN = 308,
116 POINTERSIZE = 309,
117 LITTLE = 310,
118 BIG = 311,
119 ALIGN = 312,
120 DEPLIBS = 313,
121 CALL = 314,
122 TAIL = 315,
123 ASM_TOK = 316,
124 MODULE = 317,
125 SIDEEFFECT = 318,
126 CC_TOK = 319,
127 CCC_TOK = 320,
128 CSRETCC_TOK = 321,
129 FASTCC_TOK = 322,
130 COLDCC_TOK = 323,
131 X86_STDCALLCC_TOK = 324,
132 X86_FASTCALLCC_TOK = 325,
133 DATALAYOUT = 326,
134 RET = 327,
135 BR = 328,
136 SWITCH = 329,
137 INVOKE = 330,
138 UNREACHABLE = 331,
139 UNWIND = 332,
140 EXCEPT = 333,
141 ADD = 334,
142 SUB = 335,
143 MUL = 336,
144 DIV = 337,
145 UDIV = 338,
146 SDIV = 339,
147 FDIV = 340,
148 REM = 341,
149 UREM = 342,
150 SREM = 343,
151 FREM = 344,
152 AND = 345,
153 OR = 346,
154 XOR = 347,
155 SHL = 348,
156 SHR = 349,
157 ASHR = 350,
158 LSHR = 351,
159 SETLE = 352,
160 SETGE = 353,
161 SETLT = 354,
162 SETGT = 355,
163 SETEQ = 356,
164 SETNE = 357,
165 ICMP = 358,
166 FCMP = 359,
167 MALLOC = 360,
168 ALLOCA = 361,
169 FREE = 362,
170 LOAD = 363,
171 STORE = 364,
172 GETELEMENTPTR = 365,
173 PHI_TOK = 366,
174 SELECT = 367,
175 VAARG = 368,
176 EXTRACTELEMENT = 369,
177 INSERTELEMENT = 370,
178 SHUFFLEVECTOR = 371,
179 VAARG_old = 372,
180 VANEXT_old = 373,
181 EQ = 374,
182 NE = 375,
183 SLT = 376,
184 SGT = 377,
185 SLE = 378,
186 SGE = 379,
187 ULT = 380,
188 UGT = 381,
189 ULE = 382,
190 UGE = 383,
191 OEQ = 384,
192 ONE = 385,
193 OLT = 386,
194 OGT = 387,
195 OLE = 388,
196 OGE = 389,
197 ORD = 390,
198 UNO = 391,
199 UEQ = 392,
200 UNE = 393,
201 CAST = 394,
202 TRUNC = 395,
203 ZEXT = 396,
204 SEXT = 397,
205 FPTRUNC = 398,
206 FPEXT = 399,
207 FPTOUI = 400,
208 FPTOSI = 401,
209 UITOFP = 402,
210 SITOFP = 403,
211 PTRTOINT = 404,
212 INTTOPTR = 405,
213 BITCAST = 406
214 };
215#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000216#define ESINT64VAL 258
217#define EUINT64VAL 259
218#define SINTVAL 260
219#define UINTVAL 261
220#define FPVAL 262
221#define VOID 263
222#define BOOL 264
223#define SBYTE 265
224#define UBYTE 266
225#define SHORT 267
226#define USHORT 268
227#define INT 269
228#define UINT 270
229#define LONG 271
230#define ULONG 272
231#define FLOAT 273
232#define DOUBLE 274
233#define TYPE 275
234#define LABEL 276
235#define VAR_ID 277
236#define LABELSTR 278
237#define STRINGCONSTANT 279
238#define IMPLEMENTATION 280
239#define ZEROINITIALIZER 281
240#define TRUETOK 282
241#define FALSETOK 283
242#define BEGINTOK 284
243#define ENDTOK 285
244#define DECLARE 286
245#define GLOBAL 287
246#define CONSTANT 288
247#define SECTION 289
248#define VOLATILE 290
249#define TO 291
250#define DOTDOTDOT 292
251#define NULL_TOK 293
252#define UNDEF 294
253#define CONST 295
254#define INTERNAL 296
255#define LINKONCE 297
256#define WEAK 298
257#define APPENDING 299
258#define DLLIMPORT 300
259#define DLLEXPORT 301
260#define EXTERN_WEAK 302
261#define OPAQUE 303
262#define NOT 304
263#define EXTERNAL 305
264#define TARGET 306
265#define TRIPLE 307
266#define ENDIAN 308
267#define POINTERSIZE 309
268#define LITTLE 310
269#define BIG 311
270#define ALIGN 312
271#define DEPLIBS 313
272#define CALL 314
273#define TAIL 315
274#define ASM_TOK 316
275#define MODULE 317
276#define SIDEEFFECT 318
277#define CC_TOK 319
278#define CCC_TOK 320
279#define CSRETCC_TOK 321
280#define FASTCC_TOK 322
281#define COLDCC_TOK 323
282#define X86_STDCALLCC_TOK 324
283#define X86_FASTCALLCC_TOK 325
284#define DATALAYOUT 326
285#define RET 327
286#define BR 328
287#define SWITCH 329
288#define INVOKE 330
289#define UNREACHABLE 331
290#define UNWIND 332
291#define EXCEPT 333
292#define ADD 334
293#define SUB 335
294#define MUL 336
295#define DIV 337
296#define UDIV 338
297#define SDIV 339
298#define FDIV 340
299#define REM 341
300#define UREM 342
301#define SREM 343
302#define FREM 344
303#define AND 345
304#define OR 346
305#define XOR 347
306#define SHL 348
307#define SHR 349
308#define ASHR 350
309#define LSHR 351
310#define SETLE 352
311#define SETGE 353
312#define SETLT 354
313#define SETGT 355
314#define SETEQ 356
315#define SETNE 357
316#define ICMP 358
317#define FCMP 359
318#define MALLOC 360
319#define ALLOCA 361
320#define FREE 362
321#define LOAD 363
322#define STORE 364
323#define GETELEMENTPTR 365
324#define PHI_TOK 366
325#define SELECT 367
326#define VAARG 368
327#define EXTRACTELEMENT 369
328#define INSERTELEMENT 370
329#define SHUFFLEVECTOR 371
330#define VAARG_old 372
331#define VANEXT_old 373
332#define EQ 374
333#define NE 375
334#define SLT 376
335#define SGT 377
336#define SLE 378
337#define SGE 379
338#define ULT 380
339#define UGT 381
340#define ULE 382
341#define UGE 383
342#define OEQ 384
343#define ONE 385
344#define OLT 386
345#define OGT 387
346#define OLE 388
347#define OGE 389
348#define ORD 390
349#define UNO 391
350#define UEQ 392
351#define UNE 393
352#define CAST 394
353#define TRUNC 395
354#define ZEXT 396
355#define SEXT 397
356#define FPTRUNC 398
357#define FPEXT 399
358#define FPTOUI 400
359#define FPTOSI 401
360#define UITOFP 402
361#define SITOFP 403
362#define PTRTOINT 404
363#define INTTOPTR 405
364#define BITCAST 406
365
366
367
368
369/* Copy the first part of user declarations. */
David Greene9145dd22007-08-01 03:59:32 +0000370#line 14 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000371
372#include "UpgradeInternals.h"
373#include "llvm/CallingConv.h"
374#include "llvm/InlineAsm.h"
375#include "llvm/Instructions.h"
376#include "llvm/Module.h"
377#include "llvm/ParameterAttributes.h"
378#include "llvm/ValueSymbolTable.h"
379#include "llvm/Support/GetElementPtrTypeIterator.h"
380#include "llvm/ADT/STLExtras.h"
381#include "llvm/Support/MathExtras.h"
382#include <algorithm>
383#include <iostream>
384#include <map>
385#include <list>
386#include <utility>
387
388// DEBUG_UPREFS - Define this symbol if you want to enable debugging output
389// relating to upreferences in the input stream.
390//
391//#define DEBUG_UPREFS 1
392#ifdef DEBUG_UPREFS
393#define UR_OUT(X) std::cerr << X
394#else
395#define UR_OUT(X)
396#endif
397
398#define YYERROR_VERBOSE 1
399#define YYINCLUDED_STDLIB_H
400#define YYDEBUG 1
401
402int yylex();
403int yyparse();
404
405int yyerror(const char*);
406static void warning(const std::string& WarningMsg);
407
408namespace llvm {
409
410std::istream* LexInput;
411static std::string CurFilename;
412
413// This bool controls whether attributes are ever added to function declarations
414// definitions and calls.
415static bool AddAttributes = false;
416
417static Module *ParserResult;
418static bool ObsoleteVarArgs;
419static bool NewVarArgs;
420static BasicBlock *CurBB;
421static GlobalVariable *CurGV;
422static unsigned lastCallingConv;
423
424// This contains info used when building the body of a function. It is
425// destroyed when the function is completed.
426//
427typedef std::vector<Value *> ValueList; // Numbered defs
428
429typedef std::pair<std::string,TypeInfo> RenameMapKey;
430typedef std::map<RenameMapKey,std::string> RenameMapType;
431
432static void
433ResolveDefinitions(std::map<const Type *,ValueList> &LateResolvers,
434 std::map<const Type *,ValueList> *FutureLateResolvers = 0);
435
436static struct PerModuleInfo {
437 Module *CurrentModule;
438 std::map<const Type *, ValueList> Values; // Module level numbered definitions
439 std::map<const Type *,ValueList> LateResolveValues;
440 std::vector<PATypeHolder> Types;
441 std::vector<Signedness> TypeSigns;
442 std::map<std::string,Signedness> NamedTypeSigns;
443 std::map<std::string,Signedness> NamedValueSigns;
444 std::map<ValID, PATypeHolder> LateResolveTypes;
445 static Module::Endianness Endian;
446 static Module::PointerSize PointerSize;
447 RenameMapType RenameMap;
448
449 /// PlaceHolderInfo - When temporary placeholder objects are created, remember
450 /// how they were referenced and on which line of the input they came from so
451 /// that we can resolve them later and print error messages as appropriate.
452 std::map<Value*, std::pair<ValID, int> > PlaceHolderInfo;
453
454 // GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
455 // references to global values. Global values may be referenced before they
456 // are defined, and if so, the temporary object that they represent is held
457 // here. This is used for forward references of GlobalValues.
458 //
459 typedef std::map<std::pair<const PointerType *, ValID>, GlobalValue*>
460 GlobalRefsType;
461 GlobalRefsType GlobalRefs;
462
463 void ModuleDone() {
464 // If we could not resolve some functions at function compilation time
465 // (calls to functions before they are defined), resolve them now... Types
466 // are resolved when the constant pool has been completely parsed.
467 //
468 ResolveDefinitions(LateResolveValues);
469
470 // Check to make sure that all global value forward references have been
471 // resolved!
472 //
473 if (!GlobalRefs.empty()) {
474 std::string UndefinedReferences = "Unresolved global references exist:\n";
475
476 for (GlobalRefsType::iterator I = GlobalRefs.begin(), E =GlobalRefs.end();
477 I != E; ++I) {
478 UndefinedReferences += " " + I->first.first->getDescription() + " " +
479 I->first.second.getName() + "\n";
480 }
481 error(UndefinedReferences);
482 return;
483 }
484
485 if (CurrentModule->getDataLayout().empty()) {
486 std::string dataLayout;
487 if (Endian != Module::AnyEndianness)
488 dataLayout.append(Endian == Module::BigEndian ? "E" : "e");
489 if (PointerSize != Module::AnyPointerSize) {
490 if (!dataLayout.empty())
491 dataLayout += "-";
492 dataLayout.append(PointerSize == Module::Pointer64 ?
493 "p:64:64" : "p:32:32");
494 }
495 CurrentModule->setDataLayout(dataLayout);
496 }
497
498 Values.clear(); // Clear out function local definitions
499 Types.clear();
500 TypeSigns.clear();
501 NamedTypeSigns.clear();
502 NamedValueSigns.clear();
503 CurrentModule = 0;
504 }
505
506 // GetForwardRefForGlobal - Check to see if there is a forward reference
507 // for this global. If so, remove it from the GlobalRefs map and return it.
508 // If not, just return null.
509 GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ValID ID) {
510 // Check to see if there is a forward reference to this global variable...
511 // if there is, eliminate it and patch the reference to use the new def'n.
512 GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PTy, ID));
513 GlobalValue *Ret = 0;
514 if (I != GlobalRefs.end()) {
515 Ret = I->second;
516 GlobalRefs.erase(I);
517 }
518 return Ret;
519 }
520 void setEndianness(Module::Endianness E) { Endian = E; }
521 void setPointerSize(Module::PointerSize sz) { PointerSize = sz; }
522} CurModule;
523
524Module::Endianness PerModuleInfo::Endian = Module::AnyEndianness;
525Module::PointerSize PerModuleInfo::PointerSize = Module::AnyPointerSize;
526
527static struct PerFunctionInfo {
528 Function *CurrentFunction; // Pointer to current function being created
529
530 std::map<const Type*, ValueList> Values; // Keep track of #'d definitions
531 std::map<const Type*, ValueList> LateResolveValues;
532 bool isDeclare; // Is this function a forward declararation?
533 GlobalValue::LinkageTypes Linkage;// Linkage for forward declaration.
534
535 /// BBForwardRefs - When we see forward references to basic blocks, keep
536 /// track of them here.
537 std::map<BasicBlock*, std::pair<ValID, int> > BBForwardRefs;
538 std::vector<BasicBlock*> NumberedBlocks;
539 RenameMapType RenameMap;
540 unsigned NextBBNum;
541
542 inline PerFunctionInfo() {
543 CurrentFunction = 0;
544 isDeclare = false;
545 Linkage = GlobalValue::ExternalLinkage;
546 }
547
548 inline void FunctionStart(Function *M) {
549 CurrentFunction = M;
550 NextBBNum = 0;
551 }
552
553 void FunctionDone() {
554 NumberedBlocks.clear();
555
556 // Any forward referenced blocks left?
557 if (!BBForwardRefs.empty()) {
558 error("Undefined reference to label " +
559 BBForwardRefs.begin()->first->getName());
560 return;
561 }
562
563 // Resolve all forward references now.
564 ResolveDefinitions(LateResolveValues, &CurModule.LateResolveValues);
565
566 Values.clear(); // Clear out function local definitions
567 RenameMap.clear();
568 CurrentFunction = 0;
569 isDeclare = false;
570 Linkage = GlobalValue::ExternalLinkage;
571 }
572} CurFun; // Info for the current function...
573
574static bool inFunctionScope() { return CurFun.CurrentFunction != 0; }
575
576/// This function is just a utility to make a Key value for the rename map.
577/// The Key is a combination of the name, type, Signedness of the original
578/// value (global/function). This just constructs the key and ensures that
579/// named Signedness values are resolved to the actual Signedness.
580/// @brief Make a key for the RenameMaps
581static RenameMapKey makeRenameMapKey(const std::string &Name, const Type* Ty,
582 const Signedness &Sign) {
583 TypeInfo TI;
584 TI.T = Ty;
585 if (Sign.isNamed())
586 // Don't allow Named Signedness nodes because they won't match. The actual
587 // Signedness must be looked up in the NamedTypeSigns map.
588 TI.S.copy(CurModule.NamedTypeSigns[Sign.getName()]);
589 else
590 TI.S.copy(Sign);
591 return std::make_pair(Name, TI);
592}
593
594
595//===----------------------------------------------------------------------===//
596// Code to handle definitions of all the types
597//===----------------------------------------------------------------------===//
598
599static int InsertValue(Value *V,
600 std::map<const Type*,ValueList> &ValueTab = CurFun.Values) {
601 if (V->hasName()) return -1; // Is this a numbered definition?
602
603 // Yes, insert the value into the value table...
604 ValueList &List = ValueTab[V->getType()];
605 List.push_back(V);
606 return List.size()-1;
607}
608
609static const Type *getType(const ValID &D, bool DoNotImprovise = false) {
610 switch (D.Type) {
611 case ValID::NumberVal: // Is it a numbered definition?
612 // Module constants occupy the lowest numbered slots...
613 if ((unsigned)D.Num < CurModule.Types.size()) {
614 return CurModule.Types[(unsigned)D.Num];
615 }
616 break;
617 case ValID::NameVal: // Is it a named definition?
618 if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) {
619 return N;
620 }
621 break;
622 default:
623 error("Internal parser error: Invalid symbol type reference");
624 return 0;
625 }
626
627 // If we reached here, we referenced either a symbol that we don't know about
628 // or an id number that hasn't been read yet. We may be referencing something
629 // forward, so just create an entry to be resolved later and get to it...
630 //
631 if (DoNotImprovise) return 0; // Do we just want a null to be returned?
632
633 if (inFunctionScope()) {
634 if (D.Type == ValID::NameVal) {
635 error("Reference to an undefined type: '" + D.getName() + "'");
636 return 0;
637 } else {
638 error("Reference to an undefined type: #" + itostr(D.Num));
639 return 0;
640 }
641 }
642
643 std::map<ValID, PATypeHolder>::iterator I =CurModule.LateResolveTypes.find(D);
644 if (I != CurModule.LateResolveTypes.end())
645 return I->second;
646
647 Type *Typ = OpaqueType::get();
648 CurModule.LateResolveTypes.insert(std::make_pair(D, Typ));
649 return Typ;
650}
651
652/// This is like the getType method except that instead of looking up the type
653/// for a given ID, it looks up that type's sign.
654/// @brief Get the signedness of a referenced type
655static Signedness getTypeSign(const ValID &D) {
656 switch (D.Type) {
657 case ValID::NumberVal: // Is it a numbered definition?
658 // Module constants occupy the lowest numbered slots...
659 if ((unsigned)D.Num < CurModule.TypeSigns.size()) {
660 return CurModule.TypeSigns[(unsigned)D.Num];
661 }
662 break;
663 case ValID::NameVal: { // Is it a named definition?
664 std::map<std::string,Signedness>::const_iterator I =
665 CurModule.NamedTypeSigns.find(D.Name);
666 if (I != CurModule.NamedTypeSigns.end())
667 return I->second;
668 // Perhaps its a named forward .. just cache the name
669 Signedness S;
670 S.makeNamed(D.Name);
671 return S;
672 }
673 default:
674 break;
675 }
676 // If we don't find it, its signless
677 Signedness S;
678 S.makeSignless();
679 return S;
680}
681
682/// This function is analagous to getElementType in LLVM. It provides the same
683/// function except that it looks up the Signedness instead of the type. This is
684/// used when processing GEP instructions that need to extract the type of an
685/// indexed struct/array/ptr member.
686/// @brief Look up an element's sign.
687static Signedness getElementSign(const ValueInfo& VI,
688 const std::vector<Value*> &Indices) {
689 const Type *Ptr = VI.V->getType();
690 assert(isa<PointerType>(Ptr) && "Need pointer type");
691
692 unsigned CurIdx = 0;
693 Signedness S(VI.S);
694 while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) {
695 if (CurIdx == Indices.size())
696 break;
697
698 Value *Index = Indices[CurIdx++];
699 assert(!isa<PointerType>(CT) || CurIdx == 1 && "Invalid type");
700 Ptr = CT->getTypeAtIndex(Index);
701 if (const Type* Ty = Ptr->getForwardedType())
702 Ptr = Ty;
703 assert(S.isComposite() && "Bad Signedness type");
704 if (isa<StructType>(CT)) {
705 S = S.get(cast<ConstantInt>(Index)->getZExtValue());
706 } else {
707 S = S.get(0UL);
708 }
709 if (S.isNamed())
710 S = CurModule.NamedTypeSigns[S.getName()];
711 }
712 Signedness Result;
713 Result.makeComposite(S);
714 return Result;
715}
716
717/// This function just translates a ConstantInfo into a ValueInfo and calls
718/// getElementSign(ValueInfo,...). Its just a convenience.
719/// @brief ConstantInfo version of getElementSign.
720static Signedness getElementSign(const ConstInfo& CI,
721 const std::vector<Constant*> &Indices) {
722 ValueInfo VI;
723 VI.V = CI.C;
724 VI.S.copy(CI.S);
725 std::vector<Value*> Idx;
726 for (unsigned i = 0; i < Indices.size(); ++i)
727 Idx.push_back(Indices[i]);
728 Signedness result = getElementSign(VI, Idx);
729 VI.destroy();
730 return result;
731}
732
733/// This function determines if two function types differ only in their use of
734/// the sret parameter attribute in the first argument. If they are identical
735/// in all other respects, it returns true. Otherwise, it returns false.
736static bool FuncTysDifferOnlyBySRet(const FunctionType *F1,
737 const FunctionType *F2) {
738 if (F1->getReturnType() != F2->getReturnType() ||
739 F1->getNumParams() != F2->getNumParams())
740 return false;
741 const ParamAttrsList *PAL1 = F1->getParamAttrs();
742 const ParamAttrsList *PAL2 = F2->getParamAttrs();
743 if (PAL1 && !PAL2 || PAL2 && !PAL1)
744 return false;
745 if (PAL1 && PAL2 && ((PAL1->size() != PAL2->size()) ||
746 (PAL1->getParamAttrs(0) != PAL2->getParamAttrs(0))))
747 return false;
748 unsigned SRetMask = ~unsigned(ParamAttr::StructRet);
749 for (unsigned i = 0; i < F1->getNumParams(); ++i) {
750 if (F1->getParamType(i) != F2->getParamType(i) || (PAL1 && PAL2 &&
751 (unsigned(PAL1->getParamAttrs(i+1)) & SRetMask !=
752 unsigned(PAL2->getParamAttrs(i+1)) & SRetMask)))
753 return false;
754 }
755 return true;
756}
757
758/// This function determines if the type of V and Ty differ only by the SRet
759/// parameter attribute. This is a more generalized case of
760/// FuncTysDIfferOnlyBySRet since it doesn't require FunctionType arguments.
761static bool TypesDifferOnlyBySRet(Value *V, const Type* Ty) {
762 if (V->getType() == Ty)
763 return true;
764 const PointerType *PF1 = dyn_cast<PointerType>(Ty);
765 const PointerType *PF2 = dyn_cast<PointerType>(V->getType());
766 if (PF1 && PF2) {
767 const FunctionType* FT1 = dyn_cast<FunctionType>(PF1->getElementType());
768 const FunctionType* FT2 = dyn_cast<FunctionType>(PF2->getElementType());
769 if (FT1 && FT2)
770 return FuncTysDifferOnlyBySRet(FT1, FT2);
771 }
772 return false;
773}
774
775// The upgrade of csretcc to sret param attribute may have caused a function
776// to not be found because the param attribute changed the type of the called
777// function. This helper function, used in getExistingValue, detects that
778// situation and bitcasts the function to the correct type.
779static Value* handleSRetFuncTypeMerge(Value *V, const Type* Ty) {
780 // Handle degenerate cases
781 if (!V)
782 return 0;
783 if (V->getType() == Ty)
784 return V;
785
786 const PointerType *PF1 = dyn_cast<PointerType>(Ty);
787 const PointerType *PF2 = dyn_cast<PointerType>(V->getType());
788 if (PF1 && PF2) {
789 const FunctionType *FT1 = dyn_cast<FunctionType>(PF1->getElementType());
790 const FunctionType *FT2 = dyn_cast<FunctionType>(PF2->getElementType());
791 if (FT1 && FT2 && FuncTysDifferOnlyBySRet(FT1, FT2)) {
792 const ParamAttrsList *PAL2 = FT2->getParamAttrs();
793 if (PAL2 && PAL2->paramHasAttr(1, ParamAttr::StructRet))
794 return V;
795 else if (Constant *C = dyn_cast<Constant>(V))
796 return ConstantExpr::getBitCast(C, PF1);
797 else
798 return new BitCastInst(V, PF1, "upgrd.cast", CurBB);
799 }
800
801 }
802 return 0;
803}
804
805// getExistingValue - Look up the value specified by the provided type and
806// the provided ValID. If the value exists and has already been defined, return
807// it. Otherwise return null.
808//
809static Value *getExistingValue(const Type *Ty, const ValID &D) {
810 if (isa<FunctionType>(Ty)) {
811 error("Functions are not values and must be referenced as pointers");
812 }
813
814 switch (D.Type) {
815 case ValID::NumberVal: { // Is it a numbered definition?
816 unsigned Num = (unsigned)D.Num;
817
818 // Module constants occupy the lowest numbered slots...
819 std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
820 if (VI != CurModule.Values.end()) {
821 if (Num < VI->second.size())
822 return VI->second[Num];
823 Num -= VI->second.size();
824 }
825
826 // Make sure that our type is within bounds
827 VI = CurFun.Values.find(Ty);
828 if (VI == CurFun.Values.end()) return 0;
829
830 // Check that the number is within bounds...
831 if (VI->second.size() <= Num) return 0;
832
833 return VI->second[Num];
834 }
835
836 case ValID::NameVal: { // Is it a named definition?
837 // Get the name out of the ID
838 RenameMapKey Key = makeRenameMapKey(D.Name, Ty, D.S);
839 Value *V = 0;
840 if (inFunctionScope()) {
841 // See if the name was renamed
842 RenameMapType::const_iterator I = CurFun.RenameMap.find(Key);
843 std::string LookupName;
844 if (I != CurFun.RenameMap.end())
845 LookupName = I->second;
846 else
847 LookupName = D.Name;
848 ValueSymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable();
849 V = SymTab.lookup(LookupName);
850 if (V && V->getType() != Ty)
851 V = handleSRetFuncTypeMerge(V, Ty);
852 assert((!V || TypesDifferOnlyBySRet(V, Ty)) && "Found wrong type");
853 }
854 if (!V) {
855 RenameMapType::const_iterator I = CurModule.RenameMap.find(Key);
856 std::string LookupName;
857 if (I != CurModule.RenameMap.end())
858 LookupName = I->second;
859 else
860 LookupName = D.Name;
861 V = CurModule.CurrentModule->getValueSymbolTable().lookup(LookupName);
862 if (V && V->getType() != Ty)
863 V = handleSRetFuncTypeMerge(V, Ty);
864 assert((!V || TypesDifferOnlyBySRet(V, Ty)) && "Found wrong type");
865 }
866 if (!V)
867 return 0;
868
869 D.destroy(); // Free old strdup'd memory...
870 return V;
871 }
872
873 // Check to make sure that "Ty" is an integral type, and that our
874 // value will fit into the specified type...
875 case ValID::ConstSIntVal: // Is it a constant pool reference??
876 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
877 error("Signed integral constant '" + itostr(D.ConstPool64) +
878 "' is invalid for type '" + Ty->getDescription() + "'");
879 }
880 return ConstantInt::get(Ty, D.ConstPool64);
881
882 case ValID::ConstUIntVal: // Is it an unsigned const pool reference?
883 if (!ConstantInt::isValueValidForType(Ty, D.UConstPool64)) {
884 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64))
885 error("Integral constant '" + utostr(D.UConstPool64) +
886 "' is invalid or out of range");
887 else // This is really a signed reference. Transmogrify.
888 return ConstantInt::get(Ty, D.ConstPool64);
889 } else
890 return ConstantInt::get(Ty, D.UConstPool64);
891
892 case ValID::ConstFPVal: // Is it a floating point const pool reference?
893 if (!ConstantFP::isValueValidForType(Ty, D.ConstPoolFP))
894 error("FP constant invalid for type");
895 return ConstantFP::get(Ty, D.ConstPoolFP);
896
897 case ValID::ConstNullVal: // Is it a null value?
898 if (!isa<PointerType>(Ty))
899 error("Cannot create a a non pointer null");
900 return ConstantPointerNull::get(cast<PointerType>(Ty));
901
902 case ValID::ConstUndefVal: // Is it an undef value?
903 return UndefValue::get(Ty);
904
905 case ValID::ConstZeroVal: // Is it a zero value?
906 return Constant::getNullValue(Ty);
907
908 case ValID::ConstantVal: // Fully resolved constant?
909 if (D.ConstantValue->getType() != Ty)
910 error("Constant expression type different from required type");
911 return D.ConstantValue;
912
913 case ValID::InlineAsmVal: { // Inline asm expression
914 const PointerType *PTy = dyn_cast<PointerType>(Ty);
915 const FunctionType *FTy =
916 PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
917 if (!FTy || !InlineAsm::Verify(FTy, D.IAD->Constraints))
918 error("Invalid type for asm constraint string");
919 InlineAsm *IA = InlineAsm::get(FTy, D.IAD->AsmString, D.IAD->Constraints,
920 D.IAD->HasSideEffects);
921 D.destroy(); // Free InlineAsmDescriptor.
922 return IA;
923 }
924 default:
925 assert(0 && "Unhandled case");
926 return 0;
927 } // End of switch
928
929 assert(0 && "Unhandled case");
930 return 0;
931}
932
933// getVal - This function is identical to getExistingValue, except that if a
934// value is not already defined, it "improvises" by creating a placeholder var
935// that looks and acts just like the requested variable. When the value is
936// defined later, all uses of the placeholder variable are replaced with the
937// real thing.
938//
939static Value *getVal(const Type *Ty, const ValID &ID) {
940 if (Ty == Type::LabelTy)
941 error("Cannot use a basic block here");
942
943 // See if the value has already been defined.
944 Value *V = getExistingValue(Ty, ID);
945 if (V) return V;
946
947 if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty))
948 error("Invalid use of a composite type");
949
950 // If we reached here, we referenced either a symbol that we don't know about
951 // or an id number that hasn't been read yet. We may be referencing something
952 // forward, so just create an entry to be resolved later and get to it...
953 V = new Argument(Ty);
954
955 // Remember where this forward reference came from. FIXME, shouldn't we try
956 // to recycle these things??
957 CurModule.PlaceHolderInfo.insert(
958 std::make_pair(V, std::make_pair(ID, Upgradelineno)));
959
960 if (inFunctionScope())
961 InsertValue(V, CurFun.LateResolveValues);
962 else
963 InsertValue(V, CurModule.LateResolveValues);
964 return V;
965}
966
967/// @brief This just makes any name given to it unique, up to MAX_UINT times.
968static std::string makeNameUnique(const std::string& Name) {
969 static unsigned UniqueNameCounter = 1;
970 std::string Result(Name);
971 Result += ".upgrd." + llvm::utostr(UniqueNameCounter++);
972 return Result;
973}
974
975/// getBBVal - This is used for two purposes:
976/// * If isDefinition is true, a new basic block with the specified ID is being
977/// defined.
978/// * If isDefinition is true, this is a reference to a basic block, which may
979/// or may not be a forward reference.
980///
981static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
982 assert(inFunctionScope() && "Can't get basic block at global scope");
983
984 std::string Name;
985 BasicBlock *BB = 0;
986 switch (ID.Type) {
987 default:
988 error("Illegal label reference " + ID.getName());
989 break;
990 case ValID::NumberVal: // Is it a numbered definition?
991 if (unsigned(ID.Num) >= CurFun.NumberedBlocks.size())
992 CurFun.NumberedBlocks.resize(ID.Num+1);
993 BB = CurFun.NumberedBlocks[ID.Num];
994 break;
995 case ValID::NameVal: // Is it a named definition?
996 Name = ID.Name;
997 if (Value *N = CurFun.CurrentFunction->getValueSymbolTable().lookup(Name)) {
998 if (N->getType() != Type::LabelTy) {
999 // Register names didn't use to conflict with basic block names
1000 // because of type planes. Now they all have to be unique. So, we just
1001 // rename the register and treat this name as if no basic block
1002 // had been found.
1003 RenameMapKey Key = makeRenameMapKey(ID.Name, N->getType(), ID.S);
1004 N->setName(makeNameUnique(N->getName()));
1005 CurModule.RenameMap[Key] = N->getName();
1006 BB = 0;
1007 } else {
1008 BB = cast<BasicBlock>(N);
1009 }
1010 }
1011 break;
1012 }
1013
1014 // See if the block has already been defined.
1015 if (BB) {
1016 // If this is the definition of the block, make sure the existing value was
1017 // just a forward reference. If it was a forward reference, there will be
1018 // an entry for it in the PlaceHolderInfo map.
1019 if (isDefinition && !CurFun.BBForwardRefs.erase(BB))
1020 // The existing value was a definition, not a forward reference.
1021 error("Redefinition of label " + ID.getName());
1022
1023 ID.destroy(); // Free strdup'd memory.
1024 return BB;
1025 }
1026
1027 // Otherwise this block has not been seen before.
1028 BB = new BasicBlock("", CurFun.CurrentFunction);
1029 if (ID.Type == ValID::NameVal) {
1030 BB->setName(ID.Name);
1031 } else {
1032 CurFun.NumberedBlocks[ID.Num] = BB;
1033 }
1034
1035 // If this is not a definition, keep track of it so we can use it as a forward
1036 // reference.
1037 if (!isDefinition) {
1038 // Remember where this forward reference came from.
1039 CurFun.BBForwardRefs[BB] = std::make_pair(ID, Upgradelineno);
1040 } else {
1041 // The forward declaration could have been inserted anywhere in the
1042 // function: insert it into the correct place now.
1043 CurFun.CurrentFunction->getBasicBlockList().remove(BB);
1044 CurFun.CurrentFunction->getBasicBlockList().push_back(BB);
1045 }
1046 ID.destroy();
1047 return BB;
1048}
1049
1050
1051//===----------------------------------------------------------------------===//
1052// Code to handle forward references in instructions
1053//===----------------------------------------------------------------------===//
1054//
1055// This code handles the late binding needed with statements that reference
1056// values not defined yet... for example, a forward branch, or the PHI node for
1057// a loop body.
1058//
1059// This keeps a table (CurFun.LateResolveValues) of all such forward references
1060// and back patchs after we are done.
1061//
1062
1063// ResolveDefinitions - If we could not resolve some defs at parsing
1064// time (forward branches, phi functions for loops, etc...) resolve the
1065// defs now...
1066//
1067static void
1068ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
1069 std::map<const Type*,ValueList> *FutureLateResolvers) {
1070
1071 // Loop over LateResolveDefs fixing up stuff that couldn't be resolved
1072 for (std::map<const Type*,ValueList>::iterator LRI = LateResolvers.begin(),
1073 E = LateResolvers.end(); LRI != E; ++LRI) {
1074 const Type* Ty = LRI->first;
1075 ValueList &List = LRI->second;
1076 while (!List.empty()) {
1077 Value *V = List.back();
1078 List.pop_back();
1079
1080 std::map<Value*, std::pair<ValID, int> >::iterator PHI =
1081 CurModule.PlaceHolderInfo.find(V);
1082 assert(PHI != CurModule.PlaceHolderInfo.end() && "Placeholder error");
1083
1084 ValID &DID = PHI->second.first;
1085
1086 Value *TheRealValue = getExistingValue(Ty, DID);
1087 if (TheRealValue) {
1088 V->replaceAllUsesWith(TheRealValue);
1089 delete V;
1090 CurModule.PlaceHolderInfo.erase(PHI);
1091 } else if (FutureLateResolvers) {
1092 // Functions have their unresolved items forwarded to the module late
1093 // resolver table
1094 InsertValue(V, *FutureLateResolvers);
1095 } else {
1096 if (DID.Type == ValID::NameVal) {
1097 error("Reference to an invalid definition: '" + DID.getName() +
1098 "' of type '" + V->getType()->getDescription() + "'",
1099 PHI->second.second);
1100 return;
1101 } else {
1102 error("Reference to an invalid definition: #" +
1103 itostr(DID.Num) + " of type '" +
1104 V->getType()->getDescription() + "'", PHI->second.second);
1105 return;
1106 }
1107 }
1108 }
1109 }
1110
1111 LateResolvers.clear();
1112}
1113
1114/// This function is used for type resolution and upref handling. When a type
1115/// becomes concrete, this function is called to adjust the signedness for the
1116/// concrete type.
1117static void ResolveTypeSign(const Type* oldTy, const Signedness &Sign) {
1118 std::string TyName = CurModule.CurrentModule->getTypeName(oldTy);
1119 if (!TyName.empty())
1120 CurModule.NamedTypeSigns[TyName] = Sign;
1121}
1122
1123/// ResolveTypeTo - A brand new type was just declared. This means that (if
1124/// name is not null) things referencing Name can be resolved. Otherwise,
1125/// things refering to the number can be resolved. Do this now.
1126static void ResolveTypeTo(char *Name, const Type *ToTy, const Signedness& Sign){
1127 ValID D;
1128 if (Name)
1129 D = ValID::create(Name);
1130 else
1131 D = ValID::create((int)CurModule.Types.size());
1132 D.S.copy(Sign);
1133
1134 if (Name)
1135 CurModule.NamedTypeSigns[Name] = Sign;
1136
1137 std::map<ValID, PATypeHolder>::iterator I =
1138 CurModule.LateResolveTypes.find(D);
1139 if (I != CurModule.LateResolveTypes.end()) {
1140 const Type *OldTy = I->second.get();
1141 ((DerivedType*)OldTy)->refineAbstractTypeTo(ToTy);
1142 CurModule.LateResolveTypes.erase(I);
1143 }
1144}
1145
1146/// This is the implementation portion of TypeHasInteger. It traverses the
1147/// type given, avoiding recursive types, and returns true as soon as it finds
1148/// an integer type. If no integer type is found, it returns false.
1149static bool TypeHasIntegerI(const Type *Ty, std::vector<const Type*> Stack) {
1150 // Handle some easy cases
1151 if (Ty->isPrimitiveType() || (Ty->getTypeID() == Type::OpaqueTyID))
1152 return false;
1153 if (Ty->isInteger())
1154 return true;
1155 if (const SequentialType *STy = dyn_cast<SequentialType>(Ty))
1156 return STy->getElementType()->isInteger();
1157
1158 // Avoid type structure recursion
1159 for (std::vector<const Type*>::iterator I = Stack.begin(), E = Stack.end();
1160 I != E; ++I)
1161 if (Ty == *I)
1162 return false;
1163
1164 // Push us on the type stack
1165 Stack.push_back(Ty);
1166
1167 if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
1168 if (TypeHasIntegerI(FTy->getReturnType(), Stack))
1169 return true;
1170 FunctionType::param_iterator I = FTy->param_begin();
1171 FunctionType::param_iterator E = FTy->param_end();
1172 for (; I != E; ++I)
1173 if (TypeHasIntegerI(*I, Stack))
1174 return true;
1175 return false;
1176 } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
1177 StructType::element_iterator I = STy->element_begin();
1178 StructType::element_iterator E = STy->element_end();
1179 for (; I != E; ++I) {
1180 if (TypeHasIntegerI(*I, Stack))
1181 return true;
1182 }
1183 return false;
1184 }
1185 // There shouldn't be anything else, but its definitely not integer
1186 assert(0 && "What type is this?");
1187 return false;
1188}
1189
1190/// This is the interface to TypeHasIntegerI. It just provides the type stack,
1191/// to avoid recursion, and then calls TypeHasIntegerI.
1192static inline bool TypeHasInteger(const Type *Ty) {
1193 std::vector<const Type*> TyStack;
1194 return TypeHasIntegerI(Ty, TyStack);
1195}
1196
1197// setValueName - Set the specified value to the name given. The name may be
1198// null potentially, in which case this is a noop. The string passed in is
1199// assumed to be a malloc'd string buffer, and is free'd by this function.
1200//
1201static void setValueName(const ValueInfo &V, char *NameStr) {
1202 if (NameStr) {
1203 std::string Name(NameStr); // Copy string
1204 free(NameStr); // Free old string
1205
1206 if (V.V->getType() == Type::VoidTy) {
1207 error("Can't assign name '" + Name + "' to value with void type");
1208 return;
1209 }
1210
1211 assert(inFunctionScope() && "Must be in function scope");
1212
1213 // Search the function's symbol table for an existing value of this name
1214 ValueSymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
1215 Value* Existing = ST.lookup(Name);
1216 if (Existing) {
1217 // An existing value of the same name was found. This might have happened
1218 // because of the integer type planes collapsing in LLVM 2.0.
1219 if (Existing->getType() == V.V->getType() &&
1220 !TypeHasInteger(Existing->getType())) {
1221 // If the type does not contain any integers in them then this can't be
1222 // a type plane collapsing issue. It truly is a redefinition and we
1223 // should error out as the assembly is invalid.
1224 error("Redefinition of value named '" + Name + "' of type '" +
1225 V.V->getType()->getDescription() + "'");
1226 return;
1227 }
1228 // In LLVM 2.0 we don't allow names to be re-used for any values in a
1229 // function, regardless of Type. Previously re-use of names was okay as
1230 // long as they were distinct types. With type planes collapsing because
1231 // of the signedness change and because of PR411, this can no longer be
1232 // supported. We must search the entire symbol table for a conflicting
1233 // name and make the name unique. No warning is needed as this can't
1234 // cause a problem.
1235 std::string NewName = makeNameUnique(Name);
1236 // We're changing the name but it will probably be used by other
1237 // instructions as operands later on. Consequently we have to retain
1238 // a mapping of the renaming that we're doing.
1239 RenameMapKey Key = makeRenameMapKey(Name, V.V->getType(), V.S);
1240 CurFun.RenameMap[Key] = NewName;
1241 Name = NewName;
1242 }
1243
1244 // Set the name.
1245 V.V->setName(Name);
1246 }
1247}
1248
1249/// ParseGlobalVariable - Handle parsing of a global. If Initializer is null,
1250/// this is a declaration, otherwise it is a definition.
1251static GlobalVariable *
1252ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
1253 bool isConstantGlobal, const Type *Ty,
1254 Constant *Initializer,
1255 const Signedness &Sign) {
1256 if (isa<FunctionType>(Ty))
1257 error("Cannot declare global vars of function type");
1258
1259 const PointerType *PTy = PointerType::get(Ty);
1260
1261 std::string Name;
1262 if (NameStr) {
1263 Name = NameStr; // Copy string
1264 free(NameStr); // Free old string
1265 }
1266
1267 // See if this global value was forward referenced. If so, recycle the
1268 // object.
1269 ValID ID;
1270 if (!Name.empty()) {
1271 ID = ValID::create((char*)Name.c_str());
1272 } else {
1273 ID = ValID::create((int)CurModule.Values[PTy].size());
1274 }
1275 ID.S.makeComposite(Sign);
1276
1277 if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) {
1278 // Move the global to the end of the list, from whereever it was
1279 // previously inserted.
1280 GlobalVariable *GV = cast<GlobalVariable>(FWGV);
1281 CurModule.CurrentModule->getGlobalList().remove(GV);
1282 CurModule.CurrentModule->getGlobalList().push_back(GV);
1283 GV->setInitializer(Initializer);
1284 GV->setLinkage(Linkage);
1285 GV->setConstant(isConstantGlobal);
1286 InsertValue(GV, CurModule.Values);
1287 return GV;
1288 }
1289
1290 // If this global has a name, check to see if there is already a definition
1291 // of this global in the module and emit warnings if there are conflicts.
1292 if (!Name.empty()) {
1293 // The global has a name. See if there's an existing one of the same name.
1294 if (CurModule.CurrentModule->getNamedGlobal(Name) ||
1295 CurModule.CurrentModule->getFunction(Name)) {
1296 // We found an existing global of the same name. This isn't allowed
1297 // in LLVM 2.0. Consequently, we must alter the name of the global so it
1298 // can at least compile. This can happen because of type planes
1299 // There is alread a global of the same name which means there is a
1300 // conflict. Let's see what we can do about it.
1301 std::string NewName(makeNameUnique(Name));
1302 if (Linkage != GlobalValue::InternalLinkage) {
1303 // The linkage of this gval is external so we can't reliably rename
1304 // it because it could potentially create a linking problem.
1305 // However, we can't leave the name conflict in the output either or
1306 // it won't assemble with LLVM 2.0. So, all we can do is rename
1307 // this one to something unique and emit a warning about the problem.
1308 warning("Renaming global variable '" + Name + "' to '" + NewName +
1309 "' may cause linkage errors");
1310 }
1311
1312 // Put the renaming in the global rename map
1313 RenameMapKey Key = makeRenameMapKey(Name, PointerType::get(Ty), ID.S);
1314 CurModule.RenameMap[Key] = NewName;
1315
1316 // Rename it
1317 Name = NewName;
1318 }
1319 }
1320
1321 // Otherwise there is no existing GV to use, create one now.
1322 GlobalVariable *GV =
1323 new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name,
1324 CurModule.CurrentModule);
1325 InsertValue(GV, CurModule.Values);
1326 // Remember the sign of this global.
1327 CurModule.NamedValueSigns[Name] = ID.S;
1328 return GV;
1329}
1330
1331// setTypeName - Set the specified type to the name given. The name may be
1332// null potentially, in which case this is a noop. The string passed in is
1333// assumed to be a malloc'd string buffer, and is freed by this function.
1334//
1335// This function returns true if the type has already been defined, but is
1336// allowed to be redefined in the specified context. If the name is a new name
1337// for the type plane, it is inserted and false is returned.
1338static bool setTypeName(const PATypeInfo& TI, char *NameStr) {
1339 assert(!inFunctionScope() && "Can't give types function-local names");
1340 if (NameStr == 0) return false;
1341
1342 std::string Name(NameStr); // Copy string
1343 free(NameStr); // Free old string
1344
1345 const Type* Ty = TI.PAT->get();
1346
1347 // We don't allow assigning names to void type
1348 if (Ty == Type::VoidTy) {
1349 error("Can't assign name '" + Name + "' to the void type");
1350 return false;
1351 }
1352
1353 // Set the type name, checking for conflicts as we do so.
1354 bool AlreadyExists = CurModule.CurrentModule->addTypeName(Name, Ty);
1355
1356 // Save the sign information for later use
1357 CurModule.NamedTypeSigns[Name] = TI.S;
1358
1359 if (AlreadyExists) { // Inserting a name that is already defined???
1360 const Type *Existing = CurModule.CurrentModule->getTypeByName(Name);
1361 assert(Existing && "Conflict but no matching type?");
1362
1363 // There is only one case where this is allowed: when we are refining an
1364 // opaque type. In this case, Existing will be an opaque type.
1365 if (const OpaqueType *OpTy = dyn_cast<OpaqueType>(Existing)) {
1366 // We ARE replacing an opaque type!
1367 const_cast<OpaqueType*>(OpTy)->refineAbstractTypeTo(Ty);
1368 return true;
1369 }
1370
1371 // Otherwise, this is an attempt to redefine a type. That's okay if
1372 // the redefinition is identical to the original. This will be so if
1373 // Existing and T point to the same Type object. In this one case we
1374 // allow the equivalent redefinition.
1375 if (Existing == Ty) return true; // Yes, it's equal.
1376
1377 // Any other kind of (non-equivalent) redefinition is an error.
1378 error("Redefinition of type named '" + Name + "' in the '" +
1379 Ty->getDescription() + "' type plane");
1380 }
1381
1382 return false;
1383}
1384
1385//===----------------------------------------------------------------------===//
1386// Code for handling upreferences in type names...
1387//
1388
1389// TypeContains - Returns true if Ty directly contains E in it.
1390//
1391static bool TypeContains(const Type *Ty, const Type *E) {
1392 return std::find(Ty->subtype_begin(), Ty->subtype_end(),
1393 E) != Ty->subtype_end();
1394}
1395
1396namespace {
1397 struct UpRefRecord {
1398 // NestingLevel - The number of nesting levels that need to be popped before
1399 // this type is resolved.
1400 unsigned NestingLevel;
1401
1402 // LastContainedTy - This is the type at the current binding level for the
1403 // type. Every time we reduce the nesting level, this gets updated.
1404 const Type *LastContainedTy;
1405
1406 // UpRefTy - This is the actual opaque type that the upreference is
1407 // represented with.
1408 OpaqueType *UpRefTy;
1409
1410 UpRefRecord(unsigned NL, OpaqueType *URTy)
1411 : NestingLevel(NL), LastContainedTy(URTy), UpRefTy(URTy) { }
1412 };
1413}
1414
1415// UpRefs - A list of the outstanding upreferences that need to be resolved.
1416static std::vector<UpRefRecord> UpRefs;
1417
1418/// HandleUpRefs - Every time we finish a new layer of types, this function is
1419/// called. It loops through the UpRefs vector, which is a list of the
1420/// currently active types. For each type, if the up reference is contained in
1421/// the newly completed type, we decrement the level count. When the level
1422/// count reaches zero, the upreferenced type is the type that is passed in:
1423/// thus we can complete the cycle.
1424///
1425static PATypeHolder HandleUpRefs(const Type *ty, const Signedness& Sign) {
1426 // If Ty isn't abstract, or if there are no up-references in it, then there is
1427 // nothing to resolve here.
1428 if (!ty->isAbstract() || UpRefs.empty()) return ty;
1429
1430 PATypeHolder Ty(ty);
1431 UR_OUT("Type '" << Ty->getDescription() <<
1432 "' newly formed. Resolving upreferences.\n" <<
1433 UpRefs.size() << " upreferences active!\n");
1434
1435 // If we find any resolvable upreferences (i.e., those whose NestingLevel goes
1436 // to zero), we resolve them all together before we resolve them to Ty. At
1437 // the end of the loop, if there is anything to resolve to Ty, it will be in
1438 // this variable.
1439 OpaqueType *TypeToResolve = 0;
1440
1441 unsigned i = 0;
1442 for (; i != UpRefs.size(); ++i) {
1443 UR_OUT(" UR#" << i << " - TypeContains(" << Ty->getDescription() << ", "
1444 << UpRefs[i].UpRefTy->getDescription() << ") = "
1445 << (TypeContains(Ty, UpRefs[i].UpRefTy) ? "true" : "false") << "\n");
1446 if (TypeContains(Ty, UpRefs[i].LastContainedTy)) {
1447 // Decrement level of upreference
1448 unsigned Level = --UpRefs[i].NestingLevel;
1449 UpRefs[i].LastContainedTy = Ty;
1450 UR_OUT(" Uplevel Ref Level = " << Level << "\n");
1451 if (Level == 0) { // Upreference should be resolved!
1452 if (!TypeToResolve) {
1453 TypeToResolve = UpRefs[i].UpRefTy;
1454 } else {
1455 UR_OUT(" * Resolving upreference for "
1456 << UpRefs[i].UpRefTy->getDescription() << "\n";
1457 std::string OldName = UpRefs[i].UpRefTy->getDescription());
1458 ResolveTypeSign(UpRefs[i].UpRefTy, Sign);
1459 UpRefs[i].UpRefTy->refineAbstractTypeTo(TypeToResolve);
1460 UR_OUT(" * Type '" << OldName << "' refined upreference to: "
1461 << (const void*)Ty << ", " << Ty->getDescription() << "\n");
1462 }
1463 UpRefs.erase(UpRefs.begin()+i); // Remove from upreference list...
1464 --i; // Do not skip the next element...
1465 }
1466 }
1467 }
1468
1469 if (TypeToResolve) {
1470 UR_OUT(" * Resolving upreference for "
1471 << UpRefs[i].UpRefTy->getDescription() << "\n";
1472 std::string OldName = TypeToResolve->getDescription());
1473 ResolveTypeSign(TypeToResolve, Sign);
1474 TypeToResolve->refineAbstractTypeTo(Ty);
1475 }
1476
1477 return Ty;
1478}
1479
1480bool Signedness::operator<(const Signedness &that) const {
1481 if (isNamed()) {
1482 if (that.isNamed())
1483 return *(this->name) < *(that.name);
1484 else
1485 return CurModule.NamedTypeSigns[*name] < that;
1486 } else if (that.isNamed()) {
1487 return *this < CurModule.NamedTypeSigns[*that.name];
1488 }
1489
1490 if (isComposite() && that.isComposite()) {
1491 if (sv->size() == that.sv->size()) {
1492 SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1493 SignVector::const_iterator thatI = that.sv->begin(),
1494 thatE = that.sv->end();
1495 for (; thisI != thisE; ++thisI, ++thatI) {
1496 if (*thisI < *thatI)
1497 return true;
1498 else if (!(*thisI == *thatI))
1499 return false;
1500 }
1501 return false;
1502 }
1503 return sv->size() < that.sv->size();
1504 }
1505 return kind < that.kind;
1506}
1507
1508bool Signedness::operator==(const Signedness &that) const {
1509 if (isNamed())
1510 if (that.isNamed())
1511 return *(this->name) == *(that.name);
1512 else
1513 return CurModule.NamedTypeSigns[*(this->name)] == that;
1514 else if (that.isNamed())
1515 return *this == CurModule.NamedTypeSigns[*(that.name)];
1516 if (isComposite() && that.isComposite()) {
1517 if (sv->size() == that.sv->size()) {
1518 SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1519 SignVector::const_iterator thatI = that.sv->begin(),
1520 thatE = that.sv->end();
1521 for (; thisI != thisE; ++thisI, ++thatI) {
1522 if (!(*thisI == *thatI))
1523 return false;
1524 }
1525 return true;
1526 }
1527 return false;
1528 }
1529 return kind == that.kind;
1530}
1531
1532void Signedness::copy(const Signedness &that) {
1533 if (that.isNamed()) {
1534 kind = Named;
1535 name = new std::string(*that.name);
1536 } else if (that.isComposite()) {
1537 kind = Composite;
1538 sv = new SignVector();
1539 *sv = *that.sv;
1540 } else {
1541 kind = that.kind;
1542 sv = 0;
1543 }
1544}
1545
1546void Signedness::destroy() {
1547 if (isNamed()) {
1548 delete name;
1549 } else if (isComposite()) {
1550 delete sv;
1551 }
1552}
1553
1554#ifndef NDEBUG
1555void Signedness::dump() const {
1556 if (isComposite()) {
1557 if (sv->size() == 1) {
1558 (*sv)[0].dump();
1559 std::cerr << "*";
1560 } else {
1561 std::cerr << "{ " ;
1562 for (unsigned i = 0; i < sv->size(); ++i) {
1563 if (i != 0)
1564 std::cerr << ", ";
1565 (*sv)[i].dump();
1566 }
1567 std::cerr << "} " ;
1568 }
1569 } else if (isNamed()) {
1570 std::cerr << *name;
1571 } else if (isSigned()) {
1572 std::cerr << "S";
1573 } else if (isUnsigned()) {
1574 std::cerr << "U";
1575 } else
1576 std::cerr << ".";
1577}
1578#endif
1579
1580static inline Instruction::TermOps
1581getTermOp(TermOps op) {
1582 switch (op) {
1583 default : assert(0 && "Invalid OldTermOp");
1584 case RetOp : return Instruction::Ret;
1585 case BrOp : return Instruction::Br;
1586 case SwitchOp : return Instruction::Switch;
1587 case InvokeOp : return Instruction::Invoke;
1588 case UnwindOp : return Instruction::Unwind;
1589 case UnreachableOp: return Instruction::Unreachable;
1590 }
1591}
1592
1593static inline Instruction::BinaryOps
1594getBinaryOp(BinaryOps op, const Type *Ty, const Signedness& Sign) {
1595 switch (op) {
1596 default : assert(0 && "Invalid OldBinaryOps");
1597 case SetEQ :
1598 case SetNE :
1599 case SetLE :
1600 case SetGE :
1601 case SetLT :
1602 case SetGT : assert(0 && "Should use getCompareOp");
1603 case AddOp : return Instruction::Add;
1604 case SubOp : return Instruction::Sub;
1605 case MulOp : return Instruction::Mul;
1606 case DivOp : {
1607 // This is an obsolete instruction so we must upgrade it based on the
1608 // types of its operands.
1609 bool isFP = Ty->isFloatingPoint();
1610 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
1611 // If its a vector type we want to use the element type
1612 isFP = PTy->getElementType()->isFloatingPoint();
1613 if (isFP)
1614 return Instruction::FDiv;
1615 else if (Sign.isSigned())
1616 return Instruction::SDiv;
1617 return Instruction::UDiv;
1618 }
1619 case UDivOp : return Instruction::UDiv;
1620 case SDivOp : return Instruction::SDiv;
1621 case FDivOp : return Instruction::FDiv;
1622 case RemOp : {
1623 // This is an obsolete instruction so we must upgrade it based on the
1624 // types of its operands.
1625 bool isFP = Ty->isFloatingPoint();
1626 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
1627 // If its a vector type we want to use the element type
1628 isFP = PTy->getElementType()->isFloatingPoint();
1629 // Select correct opcode
1630 if (isFP)
1631 return Instruction::FRem;
1632 else if (Sign.isSigned())
1633 return Instruction::SRem;
1634 return Instruction::URem;
1635 }
1636 case URemOp : return Instruction::URem;
1637 case SRemOp : return Instruction::SRem;
1638 case FRemOp : return Instruction::FRem;
1639 case LShrOp : return Instruction::LShr;
1640 case AShrOp : return Instruction::AShr;
1641 case ShlOp : return Instruction::Shl;
1642 case ShrOp :
1643 if (Sign.isSigned())
1644 return Instruction::AShr;
1645 return Instruction::LShr;
1646 case AndOp : return Instruction::And;
1647 case OrOp : return Instruction::Or;
1648 case XorOp : return Instruction::Xor;
1649 }
1650}
1651
1652static inline Instruction::OtherOps
1653getCompareOp(BinaryOps op, unsigned short &predicate, const Type* &Ty,
1654 const Signedness &Sign) {
1655 bool isSigned = Sign.isSigned();
1656 bool isFP = Ty->isFloatingPoint();
1657 switch (op) {
1658 default : assert(0 && "Invalid OldSetCC");
1659 case SetEQ :
1660 if (isFP) {
1661 predicate = FCmpInst::FCMP_OEQ;
1662 return Instruction::FCmp;
1663 } else {
1664 predicate = ICmpInst::ICMP_EQ;
1665 return Instruction::ICmp;
1666 }
1667 case SetNE :
1668 if (isFP) {
1669 predicate = FCmpInst::FCMP_UNE;
1670 return Instruction::FCmp;
1671 } else {
1672 predicate = ICmpInst::ICMP_NE;
1673 return Instruction::ICmp;
1674 }
1675 case SetLE :
1676 if (isFP) {
1677 predicate = FCmpInst::FCMP_OLE;
1678 return Instruction::FCmp;
1679 } else {
1680 if (isSigned)
1681 predicate = ICmpInst::ICMP_SLE;
1682 else
1683 predicate = ICmpInst::ICMP_ULE;
1684 return Instruction::ICmp;
1685 }
1686 case SetGE :
1687 if (isFP) {
1688 predicate = FCmpInst::FCMP_OGE;
1689 return Instruction::FCmp;
1690 } else {
1691 if (isSigned)
1692 predicate = ICmpInst::ICMP_SGE;
1693 else
1694 predicate = ICmpInst::ICMP_UGE;
1695 return Instruction::ICmp;
1696 }
1697 case SetLT :
1698 if (isFP) {
1699 predicate = FCmpInst::FCMP_OLT;
1700 return Instruction::FCmp;
1701 } else {
1702 if (isSigned)
1703 predicate = ICmpInst::ICMP_SLT;
1704 else
1705 predicate = ICmpInst::ICMP_ULT;
1706 return Instruction::ICmp;
1707 }
1708 case SetGT :
1709 if (isFP) {
1710 predicate = FCmpInst::FCMP_OGT;
1711 return Instruction::FCmp;
1712 } else {
1713 if (isSigned)
1714 predicate = ICmpInst::ICMP_SGT;
1715 else
1716 predicate = ICmpInst::ICMP_UGT;
1717 return Instruction::ICmp;
1718 }
1719 }
1720}
1721
1722static inline Instruction::MemoryOps getMemoryOp(MemoryOps op) {
1723 switch (op) {
1724 default : assert(0 && "Invalid OldMemoryOps");
1725 case MallocOp : return Instruction::Malloc;
1726 case FreeOp : return Instruction::Free;
1727 case AllocaOp : return Instruction::Alloca;
1728 case LoadOp : return Instruction::Load;
1729 case StoreOp : return Instruction::Store;
1730 case GetElementPtrOp : return Instruction::GetElementPtr;
1731 }
1732}
1733
1734static inline Instruction::OtherOps
1735getOtherOp(OtherOps op, const Signedness &Sign) {
1736 switch (op) {
1737 default : assert(0 && "Invalid OldOtherOps");
1738 case PHIOp : return Instruction::PHI;
1739 case CallOp : return Instruction::Call;
1740 case SelectOp : return Instruction::Select;
1741 case UserOp1 : return Instruction::UserOp1;
1742 case UserOp2 : return Instruction::UserOp2;
1743 case VAArg : return Instruction::VAArg;
1744 case ExtractElementOp : return Instruction::ExtractElement;
1745 case InsertElementOp : return Instruction::InsertElement;
1746 case ShuffleVectorOp : return Instruction::ShuffleVector;
1747 case ICmpOp : return Instruction::ICmp;
1748 case FCmpOp : return Instruction::FCmp;
1749 };
1750}
1751
1752static inline Value*
1753getCast(CastOps op, Value *Src, const Signedness &SrcSign, const Type *DstTy,
1754 const Signedness &DstSign, bool ForceInstruction = false) {
1755 Instruction::CastOps Opcode;
1756 const Type* SrcTy = Src->getType();
1757 if (op == CastOp) {
1758 if (SrcTy->isFloatingPoint() && isa<PointerType>(DstTy)) {
1759 // fp -> ptr cast is no longer supported but we must upgrade this
1760 // by doing a double cast: fp -> int -> ptr
1761 SrcTy = Type::Int64Ty;
1762 Opcode = Instruction::IntToPtr;
1763 if (isa<Constant>(Src)) {
1764 Src = ConstantExpr::getCast(Instruction::FPToUI,
1765 cast<Constant>(Src), SrcTy);
1766 } else {
1767 std::string NewName(makeNameUnique(Src->getName()));
1768 Src = new FPToUIInst(Src, SrcTy, NewName, CurBB);
1769 }
1770 } else if (isa<IntegerType>(DstTy) &&
1771 cast<IntegerType>(DstTy)->getBitWidth() == 1) {
1772 // cast type %x to bool was previously defined as setne type %x, null
1773 // The cast semantic is now to truncate, not compare so we must retain
1774 // the original intent by replacing the cast with a setne
1775 Constant* Null = Constant::getNullValue(SrcTy);
1776 Instruction::OtherOps Opcode = Instruction::ICmp;
1777 unsigned short predicate = ICmpInst::ICMP_NE;
1778 if (SrcTy->isFloatingPoint()) {
1779 Opcode = Instruction::FCmp;
1780 predicate = FCmpInst::FCMP_ONE;
1781 } else if (!SrcTy->isInteger() && !isa<PointerType>(SrcTy)) {
1782 error("Invalid cast to bool");
1783 }
1784 if (isa<Constant>(Src) && !ForceInstruction)
1785 return ConstantExpr::getCompare(predicate, cast<Constant>(Src), Null);
1786 else
1787 return CmpInst::create(Opcode, predicate, Src, Null);
1788 }
1789 // Determine the opcode to use by calling CastInst::getCastOpcode
1790 Opcode =
1791 CastInst::getCastOpcode(Src, SrcSign.isSigned(), DstTy,
1792 DstSign.isSigned());
1793
1794 } else switch (op) {
1795 default: assert(0 && "Invalid cast token");
1796 case TruncOp: Opcode = Instruction::Trunc; break;
1797 case ZExtOp: Opcode = Instruction::ZExt; break;
1798 case SExtOp: Opcode = Instruction::SExt; break;
1799 case FPTruncOp: Opcode = Instruction::FPTrunc; break;
1800 case FPExtOp: Opcode = Instruction::FPExt; break;
1801 case FPToUIOp: Opcode = Instruction::FPToUI; break;
1802 case FPToSIOp: Opcode = Instruction::FPToSI; break;
1803 case UIToFPOp: Opcode = Instruction::UIToFP; break;
1804 case SIToFPOp: Opcode = Instruction::SIToFP; break;
1805 case PtrToIntOp: Opcode = Instruction::PtrToInt; break;
1806 case IntToPtrOp: Opcode = Instruction::IntToPtr; break;
1807 case BitCastOp: Opcode = Instruction::BitCast; break;
1808 }
1809
1810 if (isa<Constant>(Src) && !ForceInstruction)
1811 return ConstantExpr::getCast(Opcode, cast<Constant>(Src), DstTy);
1812 return CastInst::create(Opcode, Src, DstTy);
1813}
1814
1815static Instruction *
1816upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
1817 std::vector<Value*>& Args) {
1818
1819 std::string Name = ID.Type == ValID::NameVal ? ID.Name : "";
1820 if (Name.length() <= 5 || Name[0] != 'l' || Name[1] != 'l' ||
1821 Name[2] != 'v' || Name[3] != 'm' || Name[4] != '.')
1822 return 0;
1823
1824 switch (Name[5]) {
1825 case 'i':
1826 if (Name == "llvm.isunordered.f32" || Name == "llvm.isunordered.f64") {
1827 if (Args.size() != 2)
1828 error("Invalid prototype for " + Name);
1829 return new FCmpInst(FCmpInst::FCMP_UNO, Args[0], Args[1]);
1830 }
1831 break;
1832 case 'b':
1833 if (Name.length() == 14 && !memcmp(&Name[5], "bswap.i", 7)) {
1834 const Type* ArgTy = Args[0]->getType();
1835 Name += ".i" + utostr(cast<IntegerType>(ArgTy)->getBitWidth());
1836 Function *F = cast<Function>(
1837 CurModule.CurrentModule->getOrInsertFunction(Name, RetTy, ArgTy,
1838 (void*)0));
1839 return new CallInst(F, Args[0]);
1840 }
1841 break;
1842 case 'c':
1843 if ((Name.length() <= 14 && !memcmp(&Name[5], "ctpop.i", 7)) ||
1844 (Name.length() <= 13 && !memcmp(&Name[5], "ctlz.i", 6)) ||
1845 (Name.length() <= 13 && !memcmp(&Name[5], "cttz.i", 6))) {
1846 // These intrinsics changed their result type.
1847 const Type* ArgTy = Args[0]->getType();
1848 Function *OldF = CurModule.CurrentModule->getFunction(Name);
1849 if (OldF)
1850 OldF->setName("upgrd.rm." + Name);
1851
1852 Function *NewF = cast<Function>(
1853 CurModule.CurrentModule->getOrInsertFunction(Name, Type::Int32Ty,
1854 ArgTy, (void*)0));
1855
1856 Instruction *Call = new CallInst(NewF, Args[0], "", CurBB);
1857 return CastInst::createIntegerCast(Call, RetTy, false);
1858 }
1859 break;
1860
1861 case 'v' : {
1862 const Type* PtrTy = PointerType::get(Type::Int8Ty);
1863 std::vector<const Type*> Params;
1864 if (Name == "llvm.va_start" || Name == "llvm.va_end") {
1865 if (Args.size() != 1)
1866 error("Invalid prototype for " + Name + " prototype");
1867 Params.push_back(PtrTy);
1868 const FunctionType *FTy =
1869 FunctionType::get(Type::VoidTy, Params, false);
1870 const PointerType *PFTy = PointerType::get(FTy);
1871 Value* Func = getVal(PFTy, ID);
1872 Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
David Greene9145dd22007-08-01 03:59:32 +00001873 return new CallInst(Func, Args.begin(), Args.end());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001874 } else if (Name == "llvm.va_copy") {
1875 if (Args.size() != 2)
1876 error("Invalid prototype for " + Name + " prototype");
1877 Params.push_back(PtrTy);
1878 Params.push_back(PtrTy);
1879 const FunctionType *FTy =
1880 FunctionType::get(Type::VoidTy, Params, false);
1881 const PointerType *PFTy = PointerType::get(FTy);
1882 Value* Func = getVal(PFTy, ID);
1883 std::string InstName0(makeNameUnique("va0"));
1884 std::string InstName1(makeNameUnique("va1"));
1885 Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
1886 Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
David Greene9145dd22007-08-01 03:59:32 +00001887 return new CallInst(Func, Args.begin(), Args.end());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001888 }
1889 }
1890 }
1891 return 0;
1892}
1893
1894const Type* upgradeGEPCEIndices(const Type* PTy,
1895 std::vector<ValueInfo> *Indices,
1896 std::vector<Constant*> &Result) {
1897 const Type *Ty = PTy;
1898 Result.clear();
1899 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1900 Constant *Index = cast<Constant>((*Indices)[i].V);
1901
1902 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1903 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1904 // struct indices to i32 struct indices with ZExt for compatibility.
1905 if (CI->getBitWidth() < 32)
1906 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1907 }
1908
1909 if (isa<SequentialType>(Ty)) {
1910 // Make sure that unsigned SequentialType indices are zext'd to
1911 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1912 // all indices for SequentialType elements. We must retain the same
1913 // semantic (zext) for unsigned types.
1914 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
1915 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
1916 Index = ConstantExpr::getCast(Instruction::ZExt, Index,Type::Int64Ty);
1917 }
1918 }
1919 }
1920 Result.push_back(Index);
1921 Ty = GetElementPtrInst::getIndexedType(PTy, (Value**)&Result[0],
1922 Result.size(),true);
1923 if (!Ty)
1924 error("Index list invalid for constant getelementptr");
1925 }
1926 return Ty;
1927}
1928
1929const Type* upgradeGEPInstIndices(const Type* PTy,
1930 std::vector<ValueInfo> *Indices,
1931 std::vector<Value*> &Result) {
1932 const Type *Ty = PTy;
1933 Result.clear();
1934 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1935 Value *Index = (*Indices)[i].V;
1936
1937 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1938 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1939 // struct indices to i32 struct indices with ZExt for compatibility.
1940 if (CI->getBitWidth() < 32)
1941 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1942 }
1943
1944
1945 if (isa<StructType>(Ty)) { // Only change struct indices
1946 if (!isa<Constant>(Index)) {
1947 error("Invalid non-constant structure index");
1948 return 0;
1949 }
1950 } else {
1951 // Make sure that unsigned SequentialType indices are zext'd to
1952 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1953 // all indices for SequentialType elements. We must retain the same
1954 // semantic (zext) for unsigned types.
1955 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
1956 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
1957 if (isa<Constant>(Index))
1958 Index = ConstantExpr::getCast(Instruction::ZExt,
1959 cast<Constant>(Index), Type::Int64Ty);
1960 else
1961 Index = CastInst::create(Instruction::ZExt, Index, Type::Int64Ty,
1962 makeNameUnique("gep"), CurBB);
1963 }
1964 }
1965 }
1966 Result.push_back(Index);
1967 Ty = GetElementPtrInst::getIndexedType(PTy, &Result[0], Result.size(),true);
1968 if (!Ty)
1969 error("Index list invalid for constant getelementptr");
1970 }
1971 return Ty;
1972}
1973
1974unsigned upgradeCallingConv(unsigned CC) {
1975 switch (CC) {
1976 case OldCallingConv::C : return CallingConv::C;
1977 case OldCallingConv::CSRet : return CallingConv::C;
1978 case OldCallingConv::Fast : return CallingConv::Fast;
1979 case OldCallingConv::Cold : return CallingConv::Cold;
1980 case OldCallingConv::X86_StdCall : return CallingConv::X86_StdCall;
1981 case OldCallingConv::X86_FastCall: return CallingConv::X86_FastCall;
1982 default:
1983 return CC;
1984 }
1985}
1986
1987Module* UpgradeAssembly(const std::string &infile, std::istream& in,
1988 bool debug, bool addAttrs)
1989{
1990 Upgradelineno = 1;
1991 CurFilename = infile;
1992 LexInput = &in;
1993 yydebug = debug;
1994 AddAttributes = addAttrs;
1995 ObsoleteVarArgs = false;
1996 NewVarArgs = false;
1997
1998 CurModule.CurrentModule = new Module(CurFilename);
1999
2000 // Check to make sure the parser succeeded
2001 if (yyparse()) {
2002 if (ParserResult)
2003 delete ParserResult;
2004 std::cerr << "llvm-upgrade: parse failed.\n";
2005 return 0;
2006 }
2007
2008 // Check to make sure that parsing produced a result
2009 if (!ParserResult) {
2010 std::cerr << "llvm-upgrade: no parse result.\n";
2011 return 0;
2012 }
2013
2014 // Reset ParserResult variable while saving its value for the result.
2015 Module *Result = ParserResult;
2016 ParserResult = 0;
2017
2018 //Not all functions use vaarg, so make a second check for ObsoleteVarArgs
2019 {
2020 Function* F;
2021 if ((F = Result->getFunction("llvm.va_start"))
2022 && F->getFunctionType()->getNumParams() == 0)
2023 ObsoleteVarArgs = true;
2024 if((F = Result->getFunction("llvm.va_copy"))
2025 && F->getFunctionType()->getNumParams() == 1)
2026 ObsoleteVarArgs = true;
2027 }
2028
2029 if (ObsoleteVarArgs && NewVarArgs) {
2030 error("This file is corrupt: it uses both new and old style varargs");
2031 return 0;
2032 }
2033
2034 if(ObsoleteVarArgs) {
2035 if(Function* F = Result->getFunction("llvm.va_start")) {
2036 if (F->arg_size() != 0) {
2037 error("Obsolete va_start takes 0 argument");
2038 return 0;
2039 }
2040
2041 //foo = va_start()
2042 // ->
2043 //bar = alloca typeof(foo)
2044 //va_start(bar)
2045 //foo = load bar
2046
2047 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2048 const Type* ArgTy = F->getFunctionType()->getReturnType();
2049 const Type* ArgTyPtr = PointerType::get(ArgTy);
2050 Function* NF = cast<Function>(Result->getOrInsertFunction(
2051 "llvm.va_start", RetTy, ArgTyPtr, (Type *)0));
2052
2053 while (!F->use_empty()) {
2054 CallInst* CI = cast<CallInst>(F->use_back());
2055 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vastart.fix.1", CI);
2056 new CallInst(NF, bar, "", CI);
2057 Value* foo = new LoadInst(bar, "vastart.fix.2", CI);
2058 CI->replaceAllUsesWith(foo);
2059 CI->getParent()->getInstList().erase(CI);
2060 }
2061 Result->getFunctionList().erase(F);
2062 }
2063
2064 if(Function* F = Result->getFunction("llvm.va_end")) {
2065 if(F->arg_size() != 1) {
2066 error("Obsolete va_end takes 1 argument");
2067 return 0;
2068 }
2069
2070 //vaend foo
2071 // ->
2072 //bar = alloca 1 of typeof(foo)
2073 //vaend bar
2074 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2075 const Type* ArgTy = F->getFunctionType()->getParamType(0);
2076 const Type* ArgTyPtr = PointerType::get(ArgTy);
2077 Function* NF = cast<Function>(Result->getOrInsertFunction(
2078 "llvm.va_end", RetTy, ArgTyPtr, (Type *)0));
2079
2080 while (!F->use_empty()) {
2081 CallInst* CI = cast<CallInst>(F->use_back());
2082 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vaend.fix.1", CI);
2083 new StoreInst(CI->getOperand(1), bar, CI);
2084 new CallInst(NF, bar, "", CI);
2085 CI->getParent()->getInstList().erase(CI);
2086 }
2087 Result->getFunctionList().erase(F);
2088 }
2089
2090 if(Function* F = Result->getFunction("llvm.va_copy")) {
2091 if(F->arg_size() != 1) {
2092 error("Obsolete va_copy takes 1 argument");
2093 return 0;
2094 }
2095 //foo = vacopy(bar)
2096 // ->
2097 //a = alloca 1 of typeof(foo)
2098 //b = alloca 1 of typeof(foo)
2099 //store bar -> b
2100 //vacopy(a, b)
2101 //foo = load a
2102
2103 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2104 const Type* ArgTy = F->getFunctionType()->getReturnType();
2105 const Type* ArgTyPtr = PointerType::get(ArgTy);
2106 Function* NF = cast<Function>(Result->getOrInsertFunction(
2107 "llvm.va_copy", RetTy, ArgTyPtr, ArgTyPtr, (Type *)0));
2108
2109 while (!F->use_empty()) {
2110 CallInst* CI = cast<CallInst>(F->use_back());
David Greene9145dd22007-08-01 03:59:32 +00002111 SmallVector<Value *, 2> Args;
2112 Args.push_back(new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI));
2113 Args.push_back(new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI));
2114 new StoreInst(CI->getOperand(1), Args[1], CI);
2115 new CallInst(NF, Args.begin(), Args.end(), "", CI);
2116 Value* foo = new LoadInst(Args[0], "vacopy.fix.3", CI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002117 CI->replaceAllUsesWith(foo);
2118 CI->getParent()->getInstList().erase(CI);
2119 }
2120 Result->getFunctionList().erase(F);
2121 }
2122 }
2123
2124 return Result;
2125}
2126
2127} // end llvm namespace
2128
2129using namespace llvm;
2130
2131
2132
2133/* Enabling traces. */
2134#ifndef YYDEBUG
2135# define YYDEBUG 0
2136#endif
2137
2138/* Enabling verbose error messages. */
2139#ifdef YYERROR_VERBOSE
2140# undef YYERROR_VERBOSE
2141# define YYERROR_VERBOSE 1
2142#else
2143# define YYERROR_VERBOSE 0
2144#endif
2145
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002146#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
David Greene9145dd22007-08-01 03:59:32 +00002147#line 1776 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002148typedef union YYSTYPE {
2149 llvm::Module *ModuleVal;
2150 llvm::Function *FunctionVal;
2151 std::pair<llvm::PATypeInfo, char*> *ArgVal;
2152 llvm::BasicBlock *BasicBlockVal;
2153 llvm::TermInstInfo TermInstVal;
2154 llvm::InstrInfo InstVal;
2155 llvm::ConstInfo ConstVal;
2156 llvm::ValueInfo ValueVal;
2157 llvm::PATypeInfo TypeVal;
2158 llvm::TypeInfo PrimType;
2159 llvm::PHIListInfo PHIList;
2160 std::list<llvm::PATypeInfo> *TypeList;
2161 std::vector<llvm::ValueInfo> *ValueList;
2162 std::vector<llvm::ConstInfo> *ConstVector;
2163
2164
2165 std::vector<std::pair<llvm::PATypeInfo,char*> > *ArgList;
2166 // Represent the RHS of PHI node
2167 std::vector<std::pair<llvm::Constant*, llvm::BasicBlock*> > *JumpTable;
2168
2169 llvm::GlobalValue::LinkageTypes Linkage;
2170 int64_t SInt64Val;
2171 uint64_t UInt64Val;
2172 int SIntVal;
2173 unsigned UIntVal;
2174 double FPVal;
2175 bool BoolVal;
2176
2177 char *StrVal; // This memory is strdup'd!
2178 llvm::ValID ValIDVal; // strdup'd memory maybe!
2179
2180 llvm::BinaryOps BinaryOpVal;
2181 llvm::TermOps TermOpVal;
2182 llvm::MemoryOps MemOpVal;
2183 llvm::OtherOps OtherOpVal;
2184 llvm::CastOps CastOpVal;
2185 llvm::ICmpInst::Predicate IPred;
2186 llvm::FCmpInst::Predicate FPred;
2187 llvm::Module::Endianness Endianness;
2188} YYSTYPE;
David Greene9145dd22007-08-01 03:59:32 +00002189/* Line 191 of yacc.c. */
2190#line 2191 "UpgradeParser.tab.c"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002191# define yystype YYSTYPE /* obsolescent; will be withdrawn */
2192# define YYSTYPE_IS_DECLARED 1
2193# define YYSTYPE_IS_TRIVIAL 1
2194#endif
2195
2196
2197
2198/* Copy the second part of user declarations. */
2199
2200
David Greene9145dd22007-08-01 03:59:32 +00002201/* Line 214 of yacc.c. */
2202#line 2203 "UpgradeParser.tab.c"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002203
2204#if ! defined (yyoverflow) || YYERROR_VERBOSE
2205
2206/* The parser invokes alloca or malloc; define the necessary symbols. */
2207
2208# ifdef YYSTACK_USE_ALLOCA
2209# if YYSTACK_USE_ALLOCA
David Greene9145dd22007-08-01 03:59:32 +00002210# define YYSTACK_ALLOC alloca
2211# endif
2212# else
2213# if defined (alloca) || defined (_ALLOCA_H)
2214# define YYSTACK_ALLOC alloca
2215# else
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002216# ifdef __GNUC__
2217# define YYSTACK_ALLOC __builtin_alloca
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002218# endif
2219# endif
2220# endif
2221
2222# ifdef YYSTACK_ALLOC
2223 /* Pacify GCC's `empty if-body' warning. */
2224# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002225# else
David Greene9145dd22007-08-01 03:59:32 +00002226# if defined (__STDC__) || defined (__cplusplus)
2227# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
2228# define YYSIZE_T size_t
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002229# endif
David Greene9145dd22007-08-01 03:59:32 +00002230# define YYSTACK_ALLOC malloc
2231# define YYSTACK_FREE free
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002232# endif
2233#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
2234
2235
2236#if (! defined (yyoverflow) \
2237 && (! defined (__cplusplus) \
2238 || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
2239
2240/* A type that is properly aligned for any stack member. */
2241union yyalloc
2242{
David Greene9145dd22007-08-01 03:59:32 +00002243 short yyss;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002244 YYSTYPE yyvs;
2245 };
2246
2247/* The size of the maximum gap between one aligned stack and the next. */
2248# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
2249
2250/* The size of an array large to enough to hold all stacks, each with
2251 N elements. */
2252# define YYSTACK_BYTES(N) \
David Greene9145dd22007-08-01 03:59:32 +00002253 ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002254 + YYSTACK_GAP_MAXIMUM)
2255
2256/* Copy COUNT objects from FROM to TO. The source and destination do
2257 not overlap. */
2258# ifndef YYCOPY
2259# if defined (__GNUC__) && 1 < __GNUC__
2260# define YYCOPY(To, From, Count) \
2261 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
2262# else
2263# define YYCOPY(To, From, Count) \
2264 do \
2265 { \
David Greene9145dd22007-08-01 03:59:32 +00002266 register YYSIZE_T yyi; \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002267 for (yyi = 0; yyi < (Count); yyi++) \
2268 (To)[yyi] = (From)[yyi]; \
2269 } \
2270 while (0)
2271# endif
2272# endif
2273
2274/* Relocate STACK from its old location to the new one. The
2275 local variables YYSIZE and YYSTACKSIZE give the old and new number of
2276 elements in the stack, and YYPTR gives the new location of the
2277 stack. Advance YYPTR to a properly aligned location for the next
2278 stack. */
2279# define YYSTACK_RELOCATE(Stack) \
2280 do \
2281 { \
2282 YYSIZE_T yynewbytes; \
2283 YYCOPY (&yyptr->Stack, Stack, yysize); \
2284 Stack = &yyptr->Stack; \
2285 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
2286 yyptr += yynewbytes / sizeof (*yyptr); \
2287 } \
2288 while (0)
2289
2290#endif
2291
2292#if defined (__STDC__) || defined (__cplusplus)
2293 typedef signed char yysigned_char;
2294#else
David Greene9145dd22007-08-01 03:59:32 +00002295 typedef short yysigned_char;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002296#endif
2297
2298/* YYFINAL -- State number of the termination state. */
2299#define YYFINAL 4
2300/* YYLAST -- Last index in YYTABLE. */
2301#define YYLAST 1630
2302
2303/* YYNTOKENS -- Number of terminals. */
2304#define YYNTOKENS 166
2305/* YYNNTS -- Number of nonterminals. */
2306#define YYNNTS 81
2307/* YYNRULES -- Number of rules. */
2308#define YYNRULES 310
2309/* YYNRULES -- Number of states. */
2310#define YYNSTATES 606
2311
2312/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
2313#define YYUNDEFTOK 2
2314#define YYMAXUTOK 406
2315
David Greene9145dd22007-08-01 03:59:32 +00002316#define YYTRANSLATE(YYX) \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002317 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
2318
2319/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
2320static const unsigned char yytranslate[] =
2321{
2322 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2323 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2324 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2325 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2326 155, 156, 164, 2, 153, 2, 2, 2, 2, 2,
2327 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2328 160, 152, 161, 2, 2, 2, 2, 2, 2, 2,
2329 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2330 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2331 2, 157, 154, 159, 2, 2, 2, 2, 2, 165,
2332 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2333 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2334 158, 2, 2, 162, 2, 163, 2, 2, 2, 2,
2335 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2336 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2337 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2338 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2339 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2340 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2341 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2342 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2343 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2344 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2345 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2346 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2347 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
2348 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
2349 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
2350 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
2351 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
2352 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
2353 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
2354 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
2355 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
2356 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
2357 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
2358 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
2359 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
2360 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
2361 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
2362 145, 146, 147, 148, 149, 150, 151
2363};
2364
2365#if YYDEBUG
2366/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
2367 YYRHS. */
David Greene9145dd22007-08-01 03:59:32 +00002368static const unsigned short yyprhs[] =
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002369{
2370 0, 0, 3, 5, 7, 9, 11, 13, 15, 17,
2371 19, 21, 23, 25, 27, 29, 31, 33, 35, 37,
2372 39, 41, 43, 45, 47, 49, 51, 53, 55, 57,
2373 59, 61, 63, 65, 67, 69, 71, 73, 75, 77,
2374 79, 81, 83, 85, 87, 89, 91, 93, 95, 97,
2375 99, 101, 103, 105, 107, 109, 111, 113, 115, 117,
2376 119, 121, 123, 125, 127, 129, 131, 133, 135, 137,
2377 139, 141, 143, 145, 147, 149, 151, 153, 155, 157,
2378 159, 161, 164, 165, 167, 169, 171, 173, 175, 177,
2379 179, 180, 181, 183, 185, 187, 189, 191, 193, 196,
2380 197, 200, 201, 205, 208, 209, 211, 212, 216, 218,
2381 221, 223, 225, 227, 229, 231, 233, 235, 237, 239,
2382 241, 243, 245, 247, 249, 251, 253, 255, 257, 259,
2383 261, 264, 269, 275, 281, 285, 288, 294, 299, 302,
2384 304, 308, 310, 314, 316, 317, 322, 326, 330, 335,
2385 340, 344, 351, 357, 360, 363, 366, 369, 372, 375,
2386 378, 381, 384, 387, 394, 400, 409, 416, 423, 430,
2387 438, 446, 453, 460, 469, 478, 482, 484, 486, 488,
2388 490, 493, 496, 501, 504, 506, 511, 514, 519, 520,
2389 528, 529, 537, 538, 546, 547, 555, 559, 564, 565,
2390 567, 569, 571, 575, 579, 583, 587, 591, 595, 597,
2391 598, 600, 602, 604, 605, 608, 612, 614, 616, 620,
2392 622, 623, 632, 634, 636, 637, 642, 644, 646, 649,
2393 650, 652, 654, 655, 656, 662, 663, 665, 667, 669,
2394 671, 673, 675, 677, 679, 681, 685, 687, 693, 695,
2395 697, 699, 701, 704, 707, 710, 714, 717, 718, 720,
2396 722, 724, 727, 730, 734, 744, 754, 763, 777, 779,
2397 781, 788, 794, 797, 804, 812, 814, 818, 820, 821,
2398 824, 826, 832, 838, 844, 851, 858, 861, 866, 871,
2399 878, 883, 888, 893, 898, 905, 912, 915, 923, 925,
2400 928, 929, 931, 932, 936, 943, 947, 954, 957, 962,
2401 969
2402};
2403
2404/* YYRHS -- A `-1'-separated list of the rules' RHS. */
David Greene9145dd22007-08-01 03:59:32 +00002405static const short yyrhs[] =
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002406{
2407 200, 0, -1, 5, -1, 6, -1, 3, -1, 4,
2408 -1, 79, -1, 80, -1, 81, -1, 82, -1, 83,
2409 -1, 84, -1, 85, -1, 86, -1, 87, -1, 88,
2410 -1, 89, -1, 90, -1, 91, -1, 92, -1, 97,
2411 -1, 98, -1, 99, -1, 100, -1, 101, -1, 102,
2412 -1, 119, -1, 120, -1, 121, -1, 122, -1, 123,
2413 -1, 124, -1, 125, -1, 126, -1, 127, -1, 128,
2414 -1, 129, -1, 130, -1, 131, -1, 132, -1, 133,
2415 -1, 134, -1, 135, -1, 136, -1, 137, -1, 138,
2416 -1, 125, -1, 126, -1, 127, -1, 128, -1, 27,
2417 -1, 28, -1, 93, -1, 94, -1, 95, -1, 96,
2418 -1, 140, -1, 141, -1, 142, -1, 143, -1, 144,
2419 -1, 145, -1, 146, -1, 147, -1, 148, -1, 149,
2420 -1, 150, -1, 151, -1, 139, -1, 16, -1, 14,
2421 -1, 12, -1, 10, -1, 17, -1, 15, -1, 13,
2422 -1, 11, -1, 176, -1, 177, -1, 18, -1, 19,
2423 -1, 212, 152, -1, -1, 41, -1, 42, -1, 43,
2424 -1, 44, -1, 45, -1, 46, -1, 47, -1, -1,
2425 -1, 65, -1, 66, -1, 67, -1, 68, -1, 69,
2426 -1, 70, -1, 64, 4, -1, -1, 57, 4, -1,
2427 -1, 153, 57, 4, -1, 34, 24, -1, -1, 185,
2428 -1, -1, 153, 188, 187, -1, 185, -1, 57, 4,
2429 -1, 191, -1, 8, -1, 193, -1, 8, -1, 193,
2430 -1, 9, -1, 10, -1, 11, -1, 12, -1, 13,
2431 -1, 14, -1, 15, -1, 16, -1, 17, -1, 18,
2432 -1, 19, -1, 21, -1, 192, -1, 48, -1, 229,
2433 -1, 154, 4, -1, 190, 155, 195, 156, -1, 157,
2434 4, 158, 193, 159, -1, 160, 4, 158, 193, 161,
2435 -1, 162, 194, 163, -1, 162, 163, -1, 160, 162,
2436 194, 163, 161, -1, 160, 162, 163, 161, -1, 193,
2437 164, -1, 193, -1, 194, 153, 193, -1, 194, -1,
2438 194, 153, 37, -1, 37, -1, -1, 191, 157, 198,
2439 159, -1, 191, 157, 159, -1, 191, 165, 24, -1,
2440 191, 160, 198, 161, -1, 191, 162, 198, 163, -1,
2441 191, 162, 163, -1, 191, 160, 162, 198, 163, 161,
2442 -1, 191, 160, 162, 163, 161, -1, 191, 38, -1,
2443 191, 39, -1, 191, 229, -1, 191, 197, -1, 191,
2444 26, -1, 176, 168, -1, 177, 4, -1, 9, 27,
2445 -1, 9, 28, -1, 179, 7, -1, 175, 155, 196,
2446 36, 191, 156, -1, 110, 155, 196, 244, 156, -1,
2447 112, 155, 196, 153, 196, 153, 196, 156, -1, 169,
2448 155, 196, 153, 196, 156, -1, 170, 155, 196, 153,
2449 196, 156, -1, 171, 155, 196, 153, 196, 156, -1,
2450 103, 172, 155, 196, 153, 196, 156, -1, 104, 173,
2451 155, 196, 153, 196, 156, -1, 174, 155, 196, 153,
2452 196, 156, -1, 114, 155, 196, 153, 196, 156, -1,
2453 115, 155, 196, 153, 196, 153, 196, 156, -1, 116,
2454 155, 196, 153, 196, 153, 196, 156, -1, 198, 153,
2455 196, -1, 196, -1, 32, -1, 33, -1, 201, -1,
2456 201, 222, -1, 201, 224, -1, 201, 62, 61, 207,
2457 -1, 201, 25, -1, 202, -1, 202, 180, 20, 189,
2458 -1, 202, 224, -1, 202, 62, 61, 207, -1, -1,
2459 202, 180, 181, 199, 196, 203, 187, -1, -1, 202,
2460 180, 50, 199, 191, 204, 187, -1, -1, 202, 180,
2461 45, 199, 191, 205, 187, -1, -1, 202, 180, 47,
2462 199, 191, 206, 187, -1, 202, 51, 209, -1, 202,
2463 58, 152, 210, -1, -1, 24, -1, 56, -1, 55,
2464 -1, 53, 152, 208, -1, 54, 152, 4, -1, 52,
2465 152, 24, -1, 71, 152, 24, -1, 157, 211, 159,
2466 -1, 211, 153, 24, -1, 24, -1, -1, 22, -1,
2467 24, -1, 212, -1, -1, 191, 213, -1, 215, 153,
2468 214, -1, 214, -1, 215, -1, 215, 153, 37, -1,
2469 37, -1, -1, 182, 189, 212, 155, 216, 156, 186,
2470 183, -1, 29, -1, 162, -1, -1, 181, 220, 217,
2471 218, -1, 30, -1, 163, -1, 232, 221, -1, -1,
2472 45, -1, 47, -1, -1, -1, 31, 225, 223, 226,
2473 217, -1, -1, 63, -1, 3, -1, 4, -1, 7,
2474 -1, 27, -1, 28, -1, 38, -1, 39, -1, 26,
2475 -1, 160, 198, 161, -1, 197, -1, 61, 227, 24,
2476 153, 24, -1, 167, -1, 212, -1, 229, -1, 228,
2477 -1, 191, 230, -1, 232, 233, -1, 219, 233, -1,
2478 234, 180, 236, -1, 234, 238, -1, -1, 23, -1,
2479 77, -1, 78, -1, 72, 231, -1, 72, 8, -1,
2480 73, 21, 230, -1, 73, 9, 230, 153, 21, 230,
2481 153, 21, 230, -1, 74, 178, 230, 153, 21, 230,
2482 157, 237, 159, -1, 74, 178, 230, 153, 21, 230,
2483 157, 159, -1, 75, 182, 189, 230, 155, 241, 156,
2484 36, 21, 230, 235, 21, 230, -1, 235, -1, 76,
2485 -1, 237, 178, 228, 153, 21, 230, -1, 178, 228,
2486 153, 21, 230, -1, 180, 243, -1, 191, 157, 230,
2487 153, 230, 159, -1, 239, 153, 157, 230, 153, 230,
2488 159, -1, 231, -1, 240, 153, 231, -1, 240, -1,
2489 -1, 60, 59, -1, 59, -1, 169, 191, 230, 153,
2490 230, -1, 170, 191, 230, 153, 230, -1, 171, 191,
2491 230, 153, 230, -1, 103, 172, 191, 230, 153, 230,
2492 -1, 104, 173, 191, 230, 153, 230, -1, 49, 231,
2493 -1, 174, 231, 153, 231, -1, 175, 231, 36, 191,
2494 -1, 112, 231, 153, 231, 153, 231, -1, 113, 231,
2495 153, 191, -1, 117, 231, 153, 191, -1, 118, 231,
2496 153, 191, -1, 114, 231, 153, 231, -1, 115, 231,
2497 153, 231, 153, 231, -1, 116, 231, 153, 231, 153,
2498 231, -1, 111, 239, -1, 242, 182, 189, 230, 155,
2499 241, 156, -1, 246, -1, 153, 240, -1, -1, 35,
2500 -1, -1, 105, 191, 184, -1, 105, 191, 153, 15,
2501 230, 184, -1, 106, 191, 184, -1, 106, 191, 153,
2502 15, 230, 184, -1, 107, 231, -1, 245, 108, 191,
2503 230, -1, 245, 109, 231, 153, 191, 230, -1, 110,
2504 191, 230, 244, -1
2505};
2506
2507/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
David Greene9145dd22007-08-01 03:59:32 +00002508static const unsigned short yyrline[] =
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002509{
David Greene9145dd22007-08-01 03:59:32 +00002510 0, 1916, 1916, 1917, 1925, 1926, 1936, 1936, 1936, 1936,
2511 1936, 1936, 1936, 1936, 1936, 1936, 1936, 1940, 1940, 1940,
2512 1944, 1944, 1944, 1944, 1944, 1944, 1948, 1948, 1949, 1949,
2513 1950, 1950, 1951, 1951, 1952, 1952, 1956, 1956, 1957, 1957,
2514 1958, 1958, 1959, 1959, 1960, 1960, 1961, 1961, 1962, 1962,
2515 1963, 1964, 1967, 1967, 1967, 1967, 1971, 1971, 1971, 1971,
2516 1971, 1971, 1971, 1972, 1972, 1972, 1972, 1972, 1972, 1978,
2517 1978, 1978, 1978, 1982, 1982, 1982, 1982, 1986, 1986, 1990,
2518 1990, 1995, 1998, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
2519 2010, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2031,
2520 2032, 2040, 2041, 2049, 2058, 2059, 2066, 2067, 2071, 2075,
2521 2091, 2092, 2099, 2100, 2107, 2115, 2115, 2115, 2115, 2115,
2522 2115, 2115, 2116, 2116, 2116, 2116, 2116, 2121, 2125, 2129,
2523 2134, 2143, 2170, 2176, 2189, 2200, 2204, 2217, 2221, 2235,
2524 2239, 2246, 2247, 2253, 2260, 2272, 2302, 2315, 2338, 2366,
2525 2388, 2399, 2421, 2432, 2441, 2446, 2505, 2512, 2520, 2527,
2526 2534, 2538, 2542, 2551, 2566, 2578, 2587, 2615, 2628, 2637,
2527 2643, 2649, 2660, 2666, 2672, 2683, 2684, 2693, 2694, 2706,
2528 2715, 2716, 2717, 2718, 2719, 2735, 2755, 2757, 2759, 2759,
2529 2766, 2766, 2774, 2774, 2782, 2782, 2791, 2793, 2795, 2800,
2530 2814, 2815, 2819, 2822, 2830, 2834, 2841, 2845, 2849, 2853,
2531 2861, 2861, 2865, 2866, 2870, 2878, 2883, 2891, 2892, 2899,
2532 2906, 2910, 3100, 3100, 3104, 3104, 3114, 3114, 3118, 3123,
2533 3124, 3125, 3129, 3130, 3129, 3142, 3143, 3148, 3149, 3150,
2534 3151, 3155, 3159, 3160, 3161, 3162, 3183, 3187, 3201, 3202,
2535 3207, 3207, 3215, 3225, 3228, 3237, 3248, 3253, 3262, 3273,
2536 3273, 3276, 3280, 3284, 3289, 3299, 3317, 3326, 3399, 3403,
2537 3410, 3422, 3437, 3467, 3477, 3487, 3491, 3498, 3499, 3503,
2538 3506, 3512, 3531, 3549, 3565, 3579, 3593, 3604, 3622, 3631,
2539 3640, 3647, 3668, 3692, 3698, 3704, 3710, 3726, 3819, 3827,
2540 3828, 3832, 3833, 3837, 3843, 3850, 3856, 3863, 3870, 3883,
2541 3909
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002542};
2543#endif
2544
David Greene9145dd22007-08-01 03:59:32 +00002545#if YYDEBUG || YYERROR_VERBOSE
2546/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002547 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
2548static const char *const yytname[] =
2549{
2550 "$end", "error", "$undefined", "ESINT64VAL", "EUINT64VAL", "SINTVAL",
2551 "UINTVAL", "FPVAL", "VOID", "BOOL", "SBYTE", "UBYTE", "SHORT", "USHORT",
2552 "INT", "UINT", "LONG", "ULONG", "FLOAT", "DOUBLE", "TYPE", "LABEL",
2553 "VAR_ID", "LABELSTR", "STRINGCONSTANT", "IMPLEMENTATION",
2554 "ZEROINITIALIZER", "TRUETOK", "FALSETOK", "BEGINTOK", "ENDTOK",
2555 "DECLARE", "GLOBAL", "CONSTANT", "SECTION", "VOLATILE", "TO",
2556 "DOTDOTDOT", "NULL_TOK", "UNDEF", "CONST", "INTERNAL", "LINKONCE",
2557 "WEAK", "APPENDING", "DLLIMPORT", "DLLEXPORT", "EXTERN_WEAK", "OPAQUE",
2558 "NOT", "EXTERNAL", "TARGET", "TRIPLE", "ENDIAN", "POINTERSIZE", "LITTLE",
2559 "BIG", "ALIGN", "DEPLIBS", "CALL", "TAIL", "ASM_TOK", "MODULE",
2560 "SIDEEFFECT", "CC_TOK", "CCC_TOK", "CSRETCC_TOK", "FASTCC_TOK",
2561 "COLDCC_TOK", "X86_STDCALLCC_TOK", "X86_FASTCALLCC_TOK", "DATALAYOUT",
2562 "RET", "BR", "SWITCH", "INVOKE", "UNREACHABLE", "UNWIND", "EXCEPT",
2563 "ADD", "SUB", "MUL", "DIV", "UDIV", "SDIV", "FDIV", "REM", "UREM",
2564 "SREM", "FREM", "AND", "OR", "XOR", "SHL", "SHR", "ASHR", "LSHR",
2565 "SETLE", "SETGE", "SETLT", "SETGT", "SETEQ", "SETNE", "ICMP", "FCMP",
2566 "MALLOC", "ALLOCA", "FREE", "LOAD", "STORE", "GETELEMENTPTR", "PHI_TOK",
2567 "SELECT", "VAARG", "EXTRACTELEMENT", "INSERTELEMENT", "SHUFFLEVECTOR",
2568 "VAARG_old", "VANEXT_old", "EQ", "NE", "SLT", "SGT", "SLE", "SGE", "ULT",
2569 "UGT", "ULE", "UGE", "OEQ", "ONE", "OLT", "OGT", "OLE", "OGE", "ORD",
2570 "UNO", "UEQ", "UNE", "CAST", "TRUNC", "ZEXT", "SEXT", "FPTRUNC", "FPEXT",
2571 "FPTOUI", "FPTOSI", "UITOFP", "SITOFP", "PTRTOINT", "INTTOPTR",
2572 "BITCAST", "'='", "','", "'\\\\'", "'('", "')'", "'['", "'x'", "']'",
2573 "'<'", "'>'", "'{'", "'}'", "'*'", "'c'", "$accept", "INTVAL",
2574 "EINT64VAL", "ArithmeticOps", "LogicalOps", "SetCondOps", "IPredicates",
2575 "FPredicates", "ShiftOps", "CastOps", "SIntType", "UIntType", "IntType",
2576 "FPType", "OptAssign", "OptLinkage", "OptCallingConv", "OptAlign",
2577 "OptCAlign", "SectionString", "OptSection", "GlobalVarAttributes",
2578 "GlobalVarAttribute", "TypesV", "UpRTypesV", "Types", "PrimType",
2579 "UpRTypes", "TypeListI", "ArgTypeListI", "ConstVal", "ConstExpr",
2580 "ConstVector", "GlobalType", "Module", "FunctionList", "ConstPool", "@1",
2581 "@2", "@3", "@4", "AsmBlock", "BigOrLittle", "TargetDefinition",
2582 "LibrariesDefinition", "LibList", "Name", "OptName", "ArgVal",
2583 "ArgListH", "ArgList", "FunctionHeaderH", "BEGIN", "FunctionHeader",
2584 "@5", "END", "Function", "FnDeclareLinkage", "FunctionProto", "@6", "@7",
2585 "OptSideEffect", "ConstValueRef", "SymbolicValueRef", "ValueRef",
2586 "ResolvedVal", "BasicBlockList", "BasicBlock", "InstructionList",
2587 "Unwind", "BBTerminatorInst", "JumpTable", "Inst", "PHIList",
2588 "ValueRefList", "ValueRefListE", "OptTailCall", "InstVal", "IndexList",
2589 "OptVolatile", "MemoryInst", 0
2590};
2591#endif
2592
2593# ifdef YYPRINT
2594/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
2595 token YYLEX-NUM. */
David Greene9145dd22007-08-01 03:59:32 +00002596static const unsigned short yytoknum[] =
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002597{
2598 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
2599 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
2600 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
2601 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
2602 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
2603 305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
2604 315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
2605 325, 326, 327, 328, 329, 330, 331, 332, 333, 334,
2606 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
2607 345, 346, 347, 348, 349, 350, 351, 352, 353, 354,
2608 355, 356, 357, 358, 359, 360, 361, 362, 363, 364,
2609 365, 366, 367, 368, 369, 370, 371, 372, 373, 374,
2610 375, 376, 377, 378, 379, 380, 381, 382, 383, 384,
2611 385, 386, 387, 388, 389, 390, 391, 392, 393, 394,
2612 395, 396, 397, 398, 399, 400, 401, 402, 403, 404,
2613 405, 406, 61, 44, 92, 40, 41, 91, 120, 93,
2614 60, 62, 123, 125, 42, 99
2615};
2616# endif
2617
2618/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
2619static const unsigned char yyr1[] =
2620{
2621 0, 166, 167, 167, 168, 168, 169, 169, 169, 169,
2622 169, 169, 169, 169, 169, 169, 169, 170, 170, 170,
2623 171, 171, 171, 171, 171, 171, 172, 172, 172, 172,
2624 172, 172, 172, 172, 172, 172, 173, 173, 173, 173,
2625 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
2626 173, 173, 174, 174, 174, 174, 175, 175, 175, 175,
2627 175, 175, 175, 175, 175, 175, 175, 175, 175, 176,
2628 176, 176, 176, 177, 177, 177, 177, 178, 178, 179,
2629 179, 180, 180, 181, 181, 181, 181, 181, 181, 181,
2630 181, 182, 182, 182, 182, 182, 182, 182, 182, 183,
2631 183, 184, 184, 185, 186, 186, 187, 187, 188, 188,
2632 189, 189, 190, 190, 191, 192, 192, 192, 192, 192,
2633 192, 192, 192, 192, 192, 192, 192, 193, 193, 193,
2634 193, 193, 193, 193, 193, 193, 193, 193, 193, 194,
2635 194, 195, 195, 195, 195, 196, 196, 196, 196, 196,
2636 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
2637 196, 196, 196, 197, 197, 197, 197, 197, 197, 197,
2638 197, 197, 197, 197, 197, 198, 198, 199, 199, 200,
2639 201, 201, 201, 201, 201, 202, 202, 202, 203, 202,
2640 204, 202, 205, 202, 206, 202, 202, 202, 202, 207,
2641 208, 208, 209, 209, 209, 209, 210, 211, 211, 211,
2642 212, 212, 213, 213, 214, 215, 215, 216, 216, 216,
2643 216, 217, 218, 218, 220, 219, 221, 221, 222, 223,
2644 223, 223, 225, 226, 224, 227, 227, 228, 228, 228,
2645 228, 228, 228, 228, 228, 228, 228, 228, 229, 229,
2646 230, 230, 231, 232, 232, 233, 234, 234, 234, 235,
2647 235, 236, 236, 236, 236, 236, 236, 236, 236, 236,
2648 237, 237, 238, 239, 239, 240, 240, 241, 241, 242,
2649 242, 243, 243, 243, 243, 243, 243, 243, 243, 243,
2650 243, 243, 243, 243, 243, 243, 243, 243, 243, 244,
2651 244, 245, 245, 246, 246, 246, 246, 246, 246, 246,
2652 246
2653};
2654
2655/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
2656static const unsigned char yyr2[] =
2657{
2658 0, 2, 1, 1, 1, 1, 1, 1, 1, 1,
2659 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2660 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2661 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2662 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2663 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2664 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2665 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2666 1, 2, 0, 1, 1, 1, 1, 1, 1, 1,
2667 0, 0, 1, 1, 1, 1, 1, 1, 2, 0,
2668 2, 0, 3, 2, 0, 1, 0, 3, 1, 2,
2669 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2670 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2671 2, 4, 5, 5, 3, 2, 5, 4, 2, 1,
2672 3, 1, 3, 1, 0, 4, 3, 3, 4, 4,
2673 3, 6, 5, 2, 2, 2, 2, 2, 2, 2,
2674 2, 2, 2, 6, 5, 8, 6, 6, 6, 7,
2675 7, 6, 6, 8, 8, 3, 1, 1, 1, 1,
2676 2, 2, 4, 2, 1, 4, 2, 4, 0, 7,
2677 0, 7, 0, 7, 0, 7, 3, 4, 0, 1,
2678 1, 1, 3, 3, 3, 3, 3, 3, 1, 0,
2679 1, 1, 1, 0, 2, 3, 1, 1, 3, 1,
2680 0, 8, 1, 1, 0, 4, 1, 1, 2, 0,
2681 1, 1, 0, 0, 5, 0, 1, 1, 1, 1,
2682 1, 1, 1, 1, 1, 3, 1, 5, 1, 1,
2683 1, 1, 2, 2, 2, 3, 2, 0, 1, 1,
2684 1, 2, 2, 3, 9, 9, 8, 13, 1, 1,
2685 6, 5, 2, 6, 7, 1, 3, 1, 0, 2,
2686 1, 5, 5, 5, 6, 6, 2, 4, 4, 6,
2687 4, 4, 4, 4, 6, 6, 2, 7, 1, 2,
2688 0, 1, 0, 3, 6, 3, 6, 2, 4, 6,
2689 4
2690};
2691
2692/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
2693 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
2694 means the default is an error. */
David Greene9145dd22007-08-01 03:59:32 +00002695static const unsigned short yydefact[] =
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002696{
2697 198, 0, 90, 184, 1, 183, 232, 83, 84, 85,
2698 86, 87, 88, 89, 0, 224, 257, 180, 181, 257,
2699 210, 211, 0, 0, 0, 90, 0, 186, 229, 0,
2700 91, 258, 254, 82, 226, 227, 228, 253, 0, 0,
2701 0, 0, 196, 0, 0, 0, 0, 0, 0, 0,
2702 81, 230, 231, 233, 199, 182, 0, 92, 93, 94,
2703 95, 96, 97, 0, 0, 302, 256, 0, 0, 0,
2704 0, 209, 197, 187, 2, 3, 111, 115, 116, 117,
2705 118, 119, 120, 121, 122, 123, 124, 125, 126, 128,
2706 0, 0, 0, 0, 248, 185, 0, 110, 127, 114,
2707 249, 129, 177, 178, 0, 0, 0, 0, 91, 98,
2708 0, 222, 223, 225, 301, 0, 280, 0, 0, 0,
2709 0, 91, 269, 259, 260, 6, 7, 8, 9, 10,
2710 11, 12, 13, 14, 15, 16, 17, 18, 19, 52,
2711 53, 54, 55, 20, 21, 22, 23, 24, 25, 0,
2712 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2713 0, 0, 0, 68, 56, 57, 58, 59, 60, 61,
2714 62, 63, 64, 65, 66, 67, 0, 0, 0, 0,
2715 0, 268, 255, 91, 272, 0, 298, 204, 201, 200,
2716 202, 203, 205, 208, 0, 130, 0, 0, 0, 113,
2717 135, 139, 0, 144, 138, 192, 194, 190, 115, 116,
2718 117, 118, 119, 120, 121, 122, 123, 124, 125, 0,
2719 0, 0, 0, 188, 234, 0, 0, 286, 279, 262,
2720 261, 0, 0, 72, 76, 71, 75, 70, 74, 69,
2721 73, 77, 78, 0, 0, 26, 27, 28, 29, 30,
2722 31, 32, 33, 34, 35, 0, 50, 51, 46, 47,
2723 48, 49, 36, 37, 38, 39, 40, 41, 42, 43,
2724 44, 45, 0, 101, 101, 307, 0, 0, 296, 0,
2725 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2726 0, 0, 0, 0, 0, 206, 0, 0, 0, 0,
2727 0, 134, 143, 141, 0, 106, 106, 106, 160, 161,
2728 4, 5, 158, 159, 162, 157, 153, 154, 0, 0,
2729 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2730 0, 0, 0, 0, 156, 155, 106, 220, 237, 238,
2731 239, 244, 240, 241, 242, 243, 235, 0, 246, 251,
2732 250, 252, 0, 263, 0, 0, 0, 0, 0, 303,
2733 0, 305, 300, 0, 0, 0, 0, 0, 0, 0,
2734 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2735 207, 112, 112, 137, 0, 140, 0, 131, 0, 193,
2736 195, 191, 0, 0, 0, 0, 0, 0, 0, 146,
2737 176, 0, 0, 0, 150, 0, 147, 0, 0, 0,
2738 0, 0, 189, 219, 213, 216, 217, 0, 236, 0,
2739 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2740 310, 0, 0, 0, 290, 293, 0, 0, 291, 292,
2741 0, 0, 0, 287, 288, 0, 308, 0, 132, 133,
2742 136, 142, 0, 0, 108, 106, 0, 0, 300, 0,
2743 0, 0, 0, 0, 145, 135, 114, 0, 148, 149,
2744 0, 0, 0, 0, 0, 212, 214, 0, 104, 0,
2745 245, 0, 0, 278, 0, 0, 101, 102, 101, 275,
2746 299, 0, 0, 0, 0, 0, 281, 282, 283, 278,
2747 0, 103, 109, 107, 0, 0, 0, 0, 0, 0,
2748 0, 175, 152, 0, 0, 0, 0, 0, 0, 218,
2749 215, 105, 99, 0, 0, 0, 277, 0, 284, 285,
2750 0, 304, 306, 0, 0, 0, 289, 294, 295, 0,
2751 309, 0, 0, 164, 0, 0, 0, 0, 151, 0,
2752 0, 0, 0, 0, 0, 221, 247, 0, 0, 0,
2753 276, 273, 0, 297, 0, 0, 0, 172, 0, 0,
2754 166, 167, 168, 171, 163, 100, 0, 266, 0, 0,
2755 0, 274, 169, 170, 0, 0, 0, 264, 0, 265,
2756 0, 0, 165, 173, 174, 0, 0, 0, 0, 0,
2757 0, 271, 0, 0, 270, 267
2758};
2759
2760/* YYDEFGOTO[NTERM-NUM]. */
David Greene9145dd22007-08-01 03:59:32 +00002761static const short yydefgoto[] =
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002762{
2763 -1, 94, 312, 329, 330, 331, 255, 272, 332, 333,
2764 219, 220, 243, 221, 25, 15, 63, 555, 359, 454,
2765 522, 389, 455, 95, 96, 222, 98, 99, 202, 304,
2766 400, 348, 401, 104, 1, 2, 3, 336, 307, 305,
2767 306, 55, 190, 42, 72, 194, 100, 476, 415, 416,
2768 417, 64, 113, 16, 30, 36, 17, 53, 18, 28,
2769 108, 419, 349, 101, 351, 489, 19, 32, 33, 181,
2770 182, 579, 66, 278, 526, 527, 183, 184, 430, 185,
2771 186
2772};
2773
2774/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
2775 STATE-NUM. */
2776#define YYPACT_NINF -542
David Greene9145dd22007-08-01 03:59:32 +00002777static const short yypact[] =
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002778{
2779 -542, 13, 162, 567, -542, -542, -542, -542, -542, -542,
2780 -542, -542, -542, -542, 83, -542, 19, -542, -542, -14,
2781 -542, -542, 50, -87, 87, 233, 27, -542, 123, 141,
2782 175, -542, -542, 98, -542, -542, -542, -542, 33, 40,
2783 66, 68, -542, 14, 141, 1265, 156, 156, 156, 156,
2784 -542, -542, -542, -542, -542, -542, 221, -542, -542, -542,
2785 -542, -542, -542, 1265, -19, 1479, -542, 204, 135, 226,
2786 227, 235, -542, -542, -542, -542, 81, -542, -542, -542,
2787 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2788 256, 257, 4, 15, -542, -542, 108, -542, -542, 12,
2789 -542, -542, -542, -542, 1306, 1306, 1306, 1326, 175, -542,
2790 98, -542, -542, -542, -542, 1306, -542, 205, 1367, 116,
2791 479, 175, -542, -542, -542, -542, -542, -542, -542, -542,
2792 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2793 -542, -542, -542, -542, -542, -542, -542, -542, -542, 355,
2794 429, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306,
2795 1306, 1306, 1306, -542, -542, -542, -542, -542, -542, -542,
2796 -542, -542, -542, -542, -542, -542, 1306, 1306, 1306, 1306,
2797 1306, -542, -542, 175, -542, 86, -542, -542, -542, -542,
2798 -542, -542, -542, -542, -13, -542, 110, 111, 75, -542,
2799 -542, 12, -81, 1046, -542, -542, -542, -542, 174, 208,
2800 266, 210, 267, 212, 268, 230, 277, 275, 278, 246,
2801 280, 279, 566, -542, -542, 136, 766, -542, -542, 81,
2802 -542, 766, 766, -542, -542, -542, -542, -542, -542, -542,
2803 -542, -542, -542, 766, 1265, -542, -542, -542, -542, -542,
2804 -542, -542, -542, -542, -542, 1306, -542, -542, -542, -542,
2805 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2806 -542, -542, 1306, 137, 145, -542, 766, 132, 146, 147,
2807 148, 149, 151, 152, 158, 160, 766, 766, 766, 161,
2808 281, 1265, 1306, 1306, 291, -542, 1306, 1306, 155, -27,
2809 1306, -542, -542, 165, 163, 176, 176, 176, -542, -542,
2810 -542, -542, -542, -542, -542, -542, -542, -542, 355, 429,
2811 172, 177, 178, 179, 182, 1087, 1387, 529, 311, 184,
2812 185, 186, 188, 189, -542, -542, 176, 1107, -542, -542,
2813 -542, -542, -542, -542, -542, -542, 282, 1326, -542, -542,
2814 -542, -542, 193, -542, 194, 766, 766, 766, 7, -542,
2815 20, -542, 195, 766, 192, 1306, 1306, 1306, 1306, 1306,
2816 1306, 1306, 200, 201, 206, 1306, 1306, 766, 766, 207,
2817 -542, -59, -149, -542, 196, 12, 1148, -542, 44, -542,
2818 -542, -542, 203, 211, 1326, 1326, 1326, 1326, 1326, -542,
2819 -542, -8, 741, -82, -542, 10, -542, 1326, 1326, 1326,
2820 1326, 1326, -542, -542, 98, -542, 214, 209, -542, 337,
2821 -34, 342, 348, 215, 218, 219, 766, 371, 766, 1306,
2822 -542, 223, 766, 224, -542, -542, 225, 234, -542, -542,
2823 766, 766, 766, -542, -542, 228, -542, 1306, -542, -542,
2824 -542, -542, 362, 375, -542, 176, 1326, 1326, 195, 236,
2825 237, 240, 243, 1326, -542, 238, -25, 11, -542, -542,
2826 244, 245, 247, 250, 352, -542, -542, 1205, 370, 252,
2827 -542, 766, 766, 1306, 766, 766, 258, -542, 258, -542,
2828 259, 766, 264, 1306, 1306, 1306, -542, -542, -542, 1306,
2829 766, -542, -542, -542, 270, 271, 263, 1326, 1326, 1326,
2830 1326, -542, -542, 260, 1326, 1326, 1326, 1326, 1306, -542,
2831 -542, -542, 368, 402, 274, 276, 259, 287, -542, -542,
2832 374, -542, -542, 1306, 285, 766, -542, -542, -542, 290,
2833 -542, 1326, 1326, -542, 283, 295, 284, 294, -542, 296,
2834 297, 299, 302, 303, 430, -542, -542, 414, 41, 425,
2835 -542, -542, 305, -542, 306, 310, 1326, -542, 1326, 1326,
2836 -542, -542, -542, -542, -542, -542, 766, -542, 893, 144,
2837 448, -542, -542, -542, 314, 315, 316, -542, 331, -542,
2838 893, 766, -542, -542, -542, 464, 334, 180, 766, 481,
2839 482, -542, 766, 766, -542, -542
2840};
2841
2842/* YYPGOTO[NTERM-NUM]. */
David Greene9145dd22007-08-01 03:59:32 +00002843static const short yypgoto[] =
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002844{
2845 -542, -542, -542, 435, 439, 441, 191, 197, 442, 445,
2846 -119, -116, -541, -542, 478, 489, -107, -542, -267, 37,
2847 -542, -238, -542, -60, -542, -45, -542, -74, -51, -542,
2848 -101, 300, -252, 134, -542, -542, -542, -542, -542, -542,
2849 -542, 473, -542, -542, -542, -542, 8, -542, 46, -542,
2850 -542, 410, -542, -542, -542, -542, -542, -542, 518, -542,
2851 -542, -542, -528, 142, -90, -113, -542, 505, -542, -72,
2852 -542, -542, -542, -542, 97, 28, -542, -542, 70, -542,
2853 -542
2854};
2855
2856/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
2857 positive, shift that token. If negative, reduce the rule which
2858 number is the opposite. If zero, do what YYDEFACT says.
2859 If YYTABLE_NINF, syntax error. */
2860#define YYTABLE_NINF -180
David Greene9145dd22007-08-01 03:59:32 +00002861static const short yytable[] =
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002862{
2863 97, 241, 227, 110, 242, 230, 223, 361, 197, 31,
2864 111, 26, 449, 4, 244, 204, 34, 578, 97, 201,
2865 74, 75, 426, 199, 77, 78, 79, 80, 81, 82,
2866 83, 84, 85, 86, 87, 428, 88, 20, 590, 21,
2867 275, 26, 31, 279, 280, 281, 282, 283, 284, 285,
2868 588, 233, 234, 235, 236, 237, 238, 239, 240, 205,
2869 206, 207, 596, 89, 427, 43, 289, 290, 390, 391,
2870 226, 463, 300, 226, 403, 405, 291, 427, 452, 468,
2871 74, 75, 301, 199, 77, 78, 79, 80, 81, 82,
2872 83, 84, 85, 86, 87, 420, 88, 20, 412, 21,
2873 448, 453, 38, 39, 40, 204, 273, 274, 226, 276,
2874 277, 226, 226, 226, 226, 226, 226, 226, 225, 463,
2875 20, 41, 21, 89, 201, 231, 300, 480, -139, 201,
2876 -112, 286, 287, 288, 226, 226, 384, 232, -139, 204,
2877 294, 352, 353, 112, 29, 463, 295, 299, 44, 35,
2878 467, 464, 303, 354, 233, 234, 235, 236, 237, 238,
2879 239, 240, -179, 463, 463, 54, 198, -112, 51, 90,
2880 52, 71, 91, 469, 513, 92, 204, 93, 200, 50,
2881 379, 105, 106, 107, 355, 67, 362, 5, 102, 103,
2882 188, 189, 68, 6, 292, 293, 372, 373, 374, 97,
2883 577, 308, 309, 7, 8, 9, 10, 11, 12, 13,
2884 356, -72, -72, -71, -71, -70, -70, 503, 69, 531,
2885 70, 532, 381, 382, 14, 109, 385, 357, 187, 90,
2886 191, 377, 91, -69, -69, 92, -113, 93, 298, 56,
2887 57, 58, 59, 60, 61, 62, 97, 378, 226, 310,
2888 311, 192, 433, 45, 435, 436, 437, 123, 124, 193,
2889 195, 196, 443, 203, 228, 423, 424, 425, 296, 297,
2890 -76, -75, -74, 431, 7, 8, 9, 10, 46, 12,
2891 47, -73, -79, 48, 313, -80, 314, 445, 446, 363,
2892 358, 337, 414, 458, 459, 460, 461, 462, 360, 364,
2893 365, 366, 367, 589, 368, 369, 470, 471, 472, 473,
2894 474, 370, 385, 371, 375, 380, 383, 376, 386, 387,
2895 226, 434, 226, 226, 226, 438, 439, 394, 466, 388,
2896 226, 444, 395, 396, 397, 406, 486, 398, 488, 407,
2897 408, 409, 492, 410, 411, 418, 421, 422, 429, 432,
2898 496, 497, 498, 440, 441, 504, 505, 450, 456, 442,
2899 447, 479, 511, 481, 335, 478, 457, 477, 350, 482,
2900 483, 484, 485, 350, 350, 487, 491, 493, 494, 502,
2901 536, 537, 538, 499, 226, 350, 501, 495, 518, 507,
2902 508, 524, 525, 509, 528, 529, 510, 514, 515, 512,
2903 516, 534, 500, 517, 452, 523, 544, 545, 546, 547,
2904 540, 530, 533, 549, 550, 551, 552, 535, 350, 543,
2905 560, 548, 475, 541, 542, 554, 556, 557, 350, 350,
2906 350, 427, 414, 558, 575, 576, 566, 568, 226, 241,
2907 564, 565, 242, 559, 561, 562, 563, 569, 226, 226,
2908 226, 567, 570, 571, 226, 572, 256, 257, 573, 574,
2909 241, 580, 582, 242, 581, 584, 583, 585, 586, 591,
2910 592, 593, 594, 553, 245, 246, 247, 248, 249, 250,
2911 251, 252, 253, 254, 595, 598, 587, 599, 226, 233,
2912 234, 235, 236, 237, 238, 239, 240, 350, 350, 350,
2913 176, 597, 602, 603, 177, 350, 178, 179, 601, 392,
2914 180, 65, 604, 605, 49, 521, 393, 73, 224, 350,
2915 350, 27, 334, 520, 37, 600, 490, 539, 506, 0,
2916 0, 0, 0, 0, 74, 75, 0, 199, 208, 209,
2917 210, 211, 212, 213, 214, 215, 216, 217, 218, 0,
2918 88, 20, 0, 21, 258, 259, 260, 261, 262, 263,
2919 264, 265, 266, 267, 268, 269, 270, 271, 350, 0,
2920 350, 74, 75, 0, 350, 0, 0, 89, 0, 0,
2921 0, 0, 350, 350, 350, 0, 0, -82, 20, 20,
2922 21, 21, 315, 0, 0, 0, 0, 0, 6, -82,
2923 -82, 0, 0, 0, 316, 317, 0, 0, -82, -82,
2924 -82, -82, -82, -82, -82, 0, 0, -82, 22, 0,
2925 0, 0, 0, 350, 350, 23, 350, 350, 0, 24,
2926 0, 0, 0, 350, 0, 0, 0, 0, 0, 0,
2927 0, 0, 350, 0, 0, 125, 126, 127, 128, 129,
2928 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
2929 140, 141, 142, 143, 144, 145, 146, 147, 148, 318,
2930 319, 0, 0, 0, 0, 0, 320, 350, 321, 0,
2931 322, 323, 324, 90, 0, 0, 91, 0, 0, 92,
2932 0, 93, 404, 0, 0, 0, 0, 0, 0, 0,
2933 0, 0, 0, 0, 0, 163, 164, 165, 166, 167,
2934 168, 169, 170, 171, 172, 173, 174, 175, 350, 0,
2935 0, 0, 0, 325, 0, 0, 326, 0, 327, 0,
2936 0, 328, 0, 350, 0, 0, 0, 0, 0, 0,
2937 350, 0, 0, 0, 350, 350, 74, 75, 0, 199,
2938 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
2939 218, 0, 88, 20, 0, 21, 0, 0, 0, 338,
2940 339, 74, 75, 340, 0, 0, 0, 0, 0, 0,
2941 0, 0, 0, 0, 0, 0, 0, 0, 20, 89,
2942 21, 0, 341, 342, 343, 0, 0, 0, 0, 0,
2943 0, 0, 0, 0, 344, 345, 0, 0, 0, 0,
2944 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2945 0, 0, 0, 0, 0, 0, 0, 346, 0, 0,
2946 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2947 0, 0, 0, 0, 0, 125, 126, 127, 128, 129,
2948 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
2949 140, 141, 142, 143, 144, 145, 146, 147, 148, 318,
2950 319, 0, 0, 0, 0, 0, 320, 0, 321, 0,
2951 322, 323, 324, 0, 0, 0, 0, 0, 0, 0,
2952 0, 0, 0, 0, 0, 90, 338, 339, 91, 0,
2953 340, 92, 0, 93, 465, 163, 164, 165, 166, 167,
2954 168, 169, 170, 171, 172, 173, 174, 175, 0, 341,
2955 342, 343, 0, 0, 0, 0, 347, 0, 0, 0,
2956 0, 344, 345, 0, 0, 0, 0, 0, 0, 0,
2957 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2958 0, 0, 0, 0, 346, 0, 0, 0, 0, 0,
2959 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2960 0, 0, 125, 126, 127, 128, 129, 130, 131, 132,
2961 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
2962 143, 144, 145, 146, 147, 148, 318, 319, 0, 0,
2963 0, 0, 0, 320, 0, 321, 0, 322, 323, 324,
2964 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2965 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2966 0, 0, 163, 164, 165, 166, 167, 168, 169, 170,
2967 171, 172, 173, 174, 175, 0, 0, 0, 0, 0,
2968 0, 74, 75, 347, 199, 77, 78, 79, 80, 81,
2969 82, 83, 84, 85, 86, 87, 0, 88, 20, 0,
2970 21, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2971 0, 0, 0, 302, 0, 0, 0, 0, 0, 0,
2972 0, 0, 74, 75, 89, 199, 208, 209, 210, 211,
2973 212, 213, 214, 215, 216, 217, 218, 0, 88, 20,
2974 0, 21, 74, 75, 0, 199, 77, 78, 79, 80,
2975 81, 82, 83, 84, 85, 86, 87, 0, 88, 20,
2976 0, 21, 0, 0, 0, 89, 0, 0, 0, 0,
2977 0, 0, 0, 0, 413, 0, 0, 0, 0, 0,
2978 0, 0, 0, 74, 75, 89, 199, 77, 78, 79,
2979 80, 81, 82, 83, 84, 85, 86, 87, 0, 88,
2980 20, 0, 21, 0, 0, 0, 0, 0, 0, 0,
2981 0, 0, 0, 0, 0, 451, 0, 0, 0, 0,
2982 0, 0, 0, 0, 0, 0, 89, 0, 0, 0,
2983 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
2984 74, 75, 0, 199, 77, 78, 79, 80, 81, 82,
2985 83, 84, 85, 86, 87, 0, 88, 20, 0, 21,
2986 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2987 0, 90, 519, 0, 91, 0, 399, 92, 0, 93,
2988 0, 0, 0, 89, 0, 0, 0, 0, 0, 0,
2989 0, 90, 0, 0, 91, 0, 0, 92, 0, 93,
2990 74, 75, 0, 76, 77, 78, 79, 80, 81, 82,
2991 83, 84, 85, 86, 87, 0, 88, 20, 0, 21,
2992 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2993 0, 0, 90, 0, 0, 91, 0, 0, 92, 0,
2994 93, 74, 75, 89, 199, 77, 78, 79, 80, 81,
2995 82, 83, 84, 85, 86, 87, 0, 88, 20, 0,
2996 21, 74, 75, 0, 199, 208, 209, 210, 211, 212,
2997 213, 214, 215, 216, 217, 218, 0, 88, 20, 0,
2998 21, 0, 0, 0, 89, 0, 0, 0, 0, 90,
2999 0, 0, 91, 0, 0, 92, 0, 93, 0, 0,
3000 0, 0, 74, 75, 89, 229, 77, 78, 79, 80,
3001 81, 82, 83, 84, 85, 86, 87, 0, 88, 20,
3002 0, 21, 74, 75, 0, 199, 208, 209, 210, 211,
3003 212, 213, 214, 215, 216, 217, 218, 0, 88, 20,
3004 0, 21, 0, 0, 0, 89, 0, 0, 0, 90,
3005 0, 0, 91, 0, 0, 92, 0, 93, 0, 0,
3006 0, 0, 0, 0, 0, 89, 0, 0, 0, 0,
3007 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3008 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3009 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
3010 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3011 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
3012 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3013 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3014 0, 0, 0, 0, 114, 0, 0, 0, 0, 0,
3015 0, 90, 0, 0, 91, 0, 0, 92, 115, 93,
3016 0, 0, 0, 0, 0, 0, 0, 0, 116, 117,
3017 0, 90, 0, 0, 91, 0, 0, 92, 0, 402,
3018 0, 118, 119, 120, 121, 122, 123, 124, 125, 126,
3019 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
3020 137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
3021 147, 148, 149, 150, 151, 152, 153, 0, 0, 154,
3022 155, 156, 157, 158, 159, 160, 161, 162, 0, 0,
3023 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3024 0, 0, 0, 0, 0, 0, 0, 0, 163, 164,
3025 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
3026 175
3027};
3028
David Greene9145dd22007-08-01 03:59:32 +00003029static const short yycheck[] =
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003030{
3031 45, 120, 115, 63, 120, 118, 107, 274, 4, 23,
3032 29, 3, 161, 0, 121, 164, 30, 558, 63, 93,
3033 5, 6, 15, 8, 9, 10, 11, 12, 13, 14,
3034 15, 16, 17, 18, 19, 15, 21, 22, 579, 24,
3035 153, 33, 23, 156, 157, 158, 159, 160, 161, 162,
3036 578, 10, 11, 12, 13, 14, 15, 16, 17, 104,
3037 105, 106, 590, 48, 57, 152, 179, 180, 306, 307,
3038 115, 153, 153, 118, 326, 327, 183, 57, 34, 161,
3039 5, 6, 163, 8, 9, 10, 11, 12, 13, 14,
3040 15, 16, 17, 18, 19, 347, 21, 22, 336, 24,
3041 159, 57, 52, 53, 54, 164, 151, 152, 153, 154,
3042 155, 156, 157, 158, 159, 160, 161, 162, 110, 153,
3043 22, 71, 24, 48, 198, 9, 153, 161, 153, 203,
3044 155, 176, 177, 178, 179, 180, 163, 21, 163, 164,
3045 153, 231, 232, 162, 61, 153, 159, 198, 61, 163,
3046 402, 159, 203, 243, 10, 11, 12, 13, 14, 15,
3047 16, 17, 0, 153, 153, 24, 162, 155, 45, 154,
3048 47, 157, 157, 163, 163, 160, 164, 162, 163, 152,
3049 293, 47, 48, 49, 244, 152, 276, 25, 32, 33,
3050 55, 56, 152, 31, 108, 109, 286, 287, 288, 244,
3051 159, 27, 28, 41, 42, 43, 44, 45, 46, 47,
3052 255, 3, 4, 3, 4, 3, 4, 455, 152, 486,
3053 152, 488, 296, 297, 62, 4, 300, 272, 24, 154,
3054 4, 291, 157, 3, 4, 160, 155, 162, 163, 64,
3055 65, 66, 67, 68, 69, 70, 291, 292, 293, 3,
3056 4, 24, 365, 20, 367, 368, 369, 77, 78, 24,
3057 4, 4, 375, 155, 59, 355, 356, 357, 158, 158,
3058 4, 4, 4, 363, 41, 42, 43, 44, 45, 46,
3059 47, 4, 7, 50, 4, 7, 7, 377, 378, 157,
3060 153, 155, 337, 394, 395, 396, 397, 398, 153, 153,
3061 153, 153, 153, 159, 153, 153, 407, 408, 409, 410,
3062 411, 153, 386, 153, 153, 24, 161, 36, 153, 156,
3063 365, 366, 367, 368, 369, 370, 371, 155, 402, 153,
3064 375, 376, 155, 155, 155, 24, 426, 155, 428, 155,
3065 155, 155, 432, 155, 155, 63, 153, 153, 153, 157,
3066 440, 441, 442, 153, 153, 456, 457, 161, 155, 153,
3067 153, 24, 463, 21, 222, 156, 155, 153, 226, 21,
3068 155, 153, 153, 231, 232, 4, 153, 153, 153, 4,
3069 493, 494, 495, 155, 429, 243, 24, 153, 36, 153,
3070 153, 481, 482, 153, 484, 485, 153, 153, 153, 161,
3071 153, 491, 447, 153, 34, 153, 507, 508, 509, 510,
3072 500, 153, 153, 514, 515, 516, 517, 153, 276, 156,
3073 533, 161, 414, 153, 153, 57, 24, 153, 286, 287,
3074 288, 57, 477, 157, 4, 21, 153, 153, 483, 558,
3075 541, 542, 558, 156, 159, 535, 156, 153, 493, 494,
3076 495, 156, 156, 156, 499, 156, 27, 28, 156, 156,
3077 579, 36, 156, 579, 159, 566, 156, 568, 569, 21,
3078 156, 156, 156, 518, 119, 120, 121, 122, 123, 124,
3079 125, 126, 127, 128, 153, 21, 576, 153, 533, 10,
3080 11, 12, 13, 14, 15, 16, 17, 355, 356, 357,
3081 65, 591, 21, 21, 65, 363, 65, 65, 598, 318,
3082 65, 33, 602, 603, 25, 478, 319, 44, 108, 377,
3083 378, 3, 222, 477, 19, 597, 429, 499, 458, -1,
3084 -1, -1, -1, -1, 5, 6, -1, 8, 9, 10,
3085 11, 12, 13, 14, 15, 16, 17, 18, 19, -1,
3086 21, 22, -1, 24, 125, 126, 127, 128, 129, 130,
3087 131, 132, 133, 134, 135, 136, 137, 138, 426, -1,
3088 428, 5, 6, -1, 432, -1, -1, 48, -1, -1,
3089 -1, -1, 440, 441, 442, -1, -1, 20, 22, 22,
3090 24, 24, 26, -1, -1, -1, -1, -1, 31, 32,
3091 33, -1, -1, -1, 38, 39, -1, -1, 41, 42,
3092 43, 44, 45, 46, 47, -1, -1, 50, 51, -1,
3093 -1, -1, -1, 481, 482, 58, 484, 485, -1, 62,
3094 -1, -1, -1, 491, -1, -1, -1, -1, -1, -1,
3095 -1, -1, 500, -1, -1, 79, 80, 81, 82, 83,
3096 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3097 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3098 104, -1, -1, -1, -1, -1, 110, 535, 112, -1,
3099 114, 115, 116, 154, -1, -1, 157, -1, -1, 160,
3100 -1, 162, 163, -1, -1, -1, -1, -1, -1, -1,
3101 -1, -1, -1, -1, -1, 139, 140, 141, 142, 143,
3102 144, 145, 146, 147, 148, 149, 150, 151, 576, -1,
3103 -1, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3104 -1, 165, -1, 591, -1, -1, -1, -1, -1, -1,
3105 598, -1, -1, -1, 602, 603, 5, 6, -1, 8,
3106 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
3107 19, -1, 21, 22, -1, 24, -1, -1, -1, 3,
3108 4, 5, 6, 7, -1, -1, -1, -1, -1, -1,
3109 -1, -1, -1, -1, -1, -1, -1, -1, 22, 48,
3110 24, -1, 26, 27, 28, -1, -1, -1, -1, -1,
3111 -1, -1, -1, -1, 38, 39, -1, -1, -1, -1,
3112 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3113 -1, -1, -1, -1, -1, -1, -1, 61, -1, -1,
3114 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3115 -1, -1, -1, -1, -1, 79, 80, 81, 82, 83,
3116 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3117 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3118 104, -1, -1, -1, -1, -1, 110, -1, 112, -1,
3119 114, 115, 116, -1, -1, -1, -1, -1, -1, -1,
3120 -1, -1, -1, -1, -1, 154, 3, 4, 157, -1,
3121 7, 160, -1, 162, 163, 139, 140, 141, 142, 143,
3122 144, 145, 146, 147, 148, 149, 150, 151, -1, 26,
3123 27, 28, -1, -1, -1, -1, 160, -1, -1, -1,
3124 -1, 38, 39, -1, -1, -1, -1, -1, -1, -1,
3125 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3126 -1, -1, -1, -1, 61, -1, -1, -1, -1, -1,
3127 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3128 -1, -1, 79, 80, 81, 82, 83, 84, 85, 86,
3129 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
3130 97, 98, 99, 100, 101, 102, 103, 104, -1, -1,
3131 -1, -1, -1, 110, -1, 112, -1, 114, 115, 116,
3132 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3133 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3134 -1, -1, 139, 140, 141, 142, 143, 144, 145, 146,
3135 147, 148, 149, 150, 151, -1, -1, -1, -1, -1,
3136 -1, 5, 6, 160, 8, 9, 10, 11, 12, 13,
3137 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3138 24, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3139 -1, -1, -1, 37, -1, -1, -1, -1, -1, -1,
3140 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
3141 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3142 -1, 24, 5, 6, -1, 8, 9, 10, 11, 12,
3143 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3144 -1, 24, -1, -1, -1, 48, -1, -1, -1, -1,
3145 -1, -1, -1, -1, 37, -1, -1, -1, -1, -1,
3146 -1, -1, -1, 5, 6, 48, 8, 9, 10, 11,
3147 12, 13, 14, 15, 16, 17, 18, 19, -1, 21,
3148 22, -1, 24, -1, -1, -1, -1, -1, -1, -1,
3149 -1, -1, -1, -1, -1, 37, -1, -1, -1, -1,
3150 -1, -1, -1, -1, -1, -1, 48, -1, -1, -1,
3151 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3152 5, 6, -1, 8, 9, 10, 11, 12, 13, 14,
3153 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
3154 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3155 -1, 154, 37, -1, 157, -1, 159, 160, -1, 162,
3156 -1, -1, -1, 48, -1, -1, -1, -1, -1, -1,
3157 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
3158 5, 6, -1, 8, 9, 10, 11, 12, 13, 14,
3159 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
3160 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3161 -1, -1, 154, -1, -1, 157, -1, -1, 160, -1,
3162 162, 5, 6, 48, 8, 9, 10, 11, 12, 13,
3163 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3164 24, 5, 6, -1, 8, 9, 10, 11, 12, 13,
3165 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3166 24, -1, -1, -1, 48, -1, -1, -1, -1, 154,
3167 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
3168 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
3169 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3170 -1, 24, 5, 6, -1, 8, 9, 10, 11, 12,
3171 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3172 -1, 24, -1, -1, -1, 48, -1, -1, -1, 154,
3173 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
3174 -1, -1, -1, -1, -1, 48, -1, -1, -1, -1,
3175 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3176 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3177 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3178 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3179 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3180 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3181 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3182 -1, -1, -1, -1, 35, -1, -1, -1, -1, -1,
3183 -1, 154, -1, -1, 157, -1, -1, 160, 49, 162,
3184 -1, -1, -1, -1, -1, -1, -1, -1, 59, 60,
3185 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
3186 -1, 72, 73, 74, 75, 76, 77, 78, 79, 80,
3187 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
3188 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
3189 101, 102, 103, 104, 105, 106, 107, -1, -1, 110,
3190 111, 112, 113, 114, 115, 116, 117, 118, -1, -1,
3191 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3192 -1, -1, -1, -1, -1, -1, -1, -1, 139, 140,
3193 141, 142, 143, 144, 145, 146, 147, 148, 149, 150,
3194 151
3195};
3196
3197/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
3198 symbol of state STATE-NUM. */
3199static const unsigned char yystos[] =
3200{
3201 0, 200, 201, 202, 0, 25, 31, 41, 42, 43,
3202 44, 45, 46, 47, 62, 181, 219, 222, 224, 232,
3203 22, 24, 51, 58, 62, 180, 212, 224, 225, 61,
3204 220, 23, 233, 234, 30, 163, 221, 233, 52, 53,
3205 54, 71, 209, 152, 61, 20, 45, 47, 50, 181,
3206 152, 45, 47, 223, 24, 207, 64, 65, 66, 67,
3207 68, 69, 70, 182, 217, 180, 238, 152, 152, 152,
3208 152, 157, 210, 207, 5, 6, 8, 9, 10, 11,
3209 12, 13, 14, 15, 16, 17, 18, 19, 21, 48,
3210 154, 157, 160, 162, 167, 189, 190, 191, 192, 193,
3211 212, 229, 32, 33, 199, 199, 199, 199, 226, 4,
3212 189, 29, 162, 218, 35, 49, 59, 60, 72, 73,
3213 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
3214 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3215 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3216 104, 105, 106, 107, 110, 111, 112, 113, 114, 115,
3217 116, 117, 118, 139, 140, 141, 142, 143, 144, 145,
3218 146, 147, 148, 149, 150, 151, 169, 170, 171, 174,
3219 175, 235, 236, 242, 243, 245, 246, 24, 55, 56,
3220 208, 4, 24, 24, 211, 4, 4, 4, 162, 8,
3221 163, 193, 194, 155, 164, 191, 191, 191, 9, 10,
3222 11, 12, 13, 14, 15, 16, 17, 18, 19, 176,
3223 177, 179, 191, 196, 217, 212, 191, 231, 59, 8,
3224 231, 9, 21, 10, 11, 12, 13, 14, 15, 16,
3225 17, 176, 177, 178, 182, 119, 120, 121, 122, 123,
3226 124, 125, 126, 127, 128, 172, 27, 28, 125, 126,
3227 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
3228 137, 138, 173, 191, 191, 231, 191, 191, 239, 231,
3229 231, 231, 231, 231, 231, 231, 191, 191, 191, 231,
3230 231, 182, 108, 109, 153, 159, 158, 158, 163, 194,
3231 153, 163, 37, 194, 195, 205, 206, 204, 27, 28,
3232 3, 4, 168, 4, 7, 26, 38, 39, 103, 104,
3233 110, 112, 114, 115, 116, 157, 160, 162, 165, 169,
3234 170, 171, 174, 175, 197, 229, 203, 155, 3, 4,
3235 7, 26, 27, 28, 38, 39, 61, 160, 197, 228,
3236 229, 230, 230, 230, 230, 189, 191, 191, 153, 184,
3237 153, 184, 230, 157, 153, 153, 153, 153, 153, 153,
3238 153, 153, 230, 230, 230, 153, 36, 189, 191, 231,
3239 24, 193, 193, 161, 163, 193, 153, 156, 153, 187,
3240 187, 187, 172, 173, 155, 155, 155, 155, 155, 159,
3241 196, 198, 162, 198, 163, 198, 24, 155, 155, 155,
3242 155, 155, 187, 37, 191, 214, 215, 216, 63, 227,
3243 198, 153, 153, 230, 230, 230, 15, 57, 15, 153,
3244 244, 230, 157, 231, 191, 231, 231, 231, 191, 191,
3245 153, 153, 153, 231, 191, 230, 230, 153, 159, 161,
3246 161, 37, 34, 57, 185, 188, 155, 155, 196, 196,
3247 196, 196, 196, 153, 159, 163, 193, 198, 161, 163,
3248 196, 196, 196, 196, 196, 212, 213, 153, 156, 24,
3249 161, 21, 21, 155, 153, 153, 230, 4, 230, 231,
3250 240, 153, 230, 153, 153, 153, 230, 230, 230, 155,
3251 191, 24, 4, 187, 196, 196, 244, 153, 153, 153,
3252 153, 196, 161, 163, 153, 153, 153, 153, 36, 37,
3253 214, 185, 186, 153, 230, 230, 240, 241, 230, 230,
3254 153, 184, 184, 153, 230, 153, 231, 231, 231, 241,
3255 230, 153, 153, 156, 196, 196, 196, 196, 161, 196,
3256 196, 196, 196, 191, 57, 183, 24, 153, 157, 156,
3257 231, 159, 230, 156, 196, 196, 153, 156, 153, 153,
3258 156, 156, 156, 156, 156, 4, 21, 159, 178, 237,
3259 36, 159, 156, 156, 196, 196, 196, 230, 228, 159,
3260 178, 21, 156, 156, 156, 153, 228, 230, 21, 153,
3261 235, 230, 21, 21, 230, 230
3262};
3263
David Greene9145dd22007-08-01 03:59:32 +00003264#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
3265# define YYSIZE_T __SIZE_TYPE__
3266#endif
3267#if ! defined (YYSIZE_T) && defined (size_t)
3268# define YYSIZE_T size_t
3269#endif
3270#if ! defined (YYSIZE_T)
3271# if defined (__STDC__) || defined (__cplusplus)
3272# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
3273# define YYSIZE_T size_t
3274# endif
3275#endif
3276#if ! defined (YYSIZE_T)
3277# define YYSIZE_T unsigned int
3278#endif
3279
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003280#define yyerrok (yyerrstatus = 0)
3281#define yyclearin (yychar = YYEMPTY)
3282#define YYEMPTY (-2)
3283#define YYEOF 0
3284
3285#define YYACCEPT goto yyacceptlab
3286#define YYABORT goto yyabortlab
3287#define YYERROR goto yyerrorlab
3288
3289
3290/* Like YYERROR except do call yyerror. This remains here temporarily
3291 to ease the transition to the new meaning of YYERROR, for GCC.
3292 Once GCC version 2 has supplanted version 1, this can go. */
3293
3294#define YYFAIL goto yyerrlab
3295
3296#define YYRECOVERING() (!!yyerrstatus)
3297
3298#define YYBACKUP(Token, Value) \
3299do \
3300 if (yychar == YYEMPTY && yylen == 1) \
3301 { \
3302 yychar = (Token); \
3303 yylval = (Value); \
3304 yytoken = YYTRANSLATE (yychar); \
3305 YYPOPSTACK; \
3306 goto yybackup; \
3307 } \
3308 else \
David Greene9145dd22007-08-01 03:59:32 +00003309 { \
3310 yyerror ("syntax error: cannot back up");\
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003311 YYERROR; \
3312 } \
3313while (0)
3314
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003315#define YYTERROR 1
3316#define YYERRCODE 256
3317
David Greene9145dd22007-08-01 03:59:32 +00003318/* YYLLOC_DEFAULT -- Compute the default location (before the actions
3319 are run). */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003320
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003321#ifndef YYLLOC_DEFAULT
David Greene9145dd22007-08-01 03:59:32 +00003322# define YYLLOC_DEFAULT(Current, Rhs, N) \
3323 ((Current).first_line = (Rhs)[1].first_line, \
3324 (Current).first_column = (Rhs)[1].first_column, \
3325 (Current).last_line = (Rhs)[N].last_line, \
3326 (Current).last_column = (Rhs)[N].last_column)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003327#endif
3328
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003329/* YYLEX -- calling `yylex' with the right arguments. */
3330
3331#ifdef YYLEX_PARAM
3332# define YYLEX yylex (YYLEX_PARAM)
3333#else
3334# define YYLEX yylex ()
3335#endif
3336
3337/* Enable debugging if requested. */
3338#if YYDEBUG
3339
3340# ifndef YYFPRINTF
3341# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
3342# define YYFPRINTF fprintf
3343# endif
3344
3345# define YYDPRINTF(Args) \
3346do { \
3347 if (yydebug) \
3348 YYFPRINTF Args; \
3349} while (0)
3350
David Greene9145dd22007-08-01 03:59:32 +00003351# define YYDSYMPRINT(Args) \
3352do { \
3353 if (yydebug) \
3354 yysymprint Args; \
3355} while (0)
3356
3357# define YYDSYMPRINTF(Title, Token, Value, Location) \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003358do { \
3359 if (yydebug) \
3360 { \
3361 YYFPRINTF (stderr, "%s ", Title); \
David Greene9145dd22007-08-01 03:59:32 +00003362 yysymprint (stderr, \
3363 Token, Value); \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003364 YYFPRINTF (stderr, "\n"); \
3365 } \
3366} while (0)
3367
3368/*------------------------------------------------------------------.
3369| yy_stack_print -- Print the state stack from its BOTTOM up to its |
3370| TOP (included). |
3371`------------------------------------------------------------------*/
3372
3373#if defined (__STDC__) || defined (__cplusplus)
3374static void
David Greene9145dd22007-08-01 03:59:32 +00003375yy_stack_print (short *bottom, short *top)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003376#else
3377static void
3378yy_stack_print (bottom, top)
David Greene9145dd22007-08-01 03:59:32 +00003379 short *bottom;
3380 short *top;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003381#endif
3382{
3383 YYFPRINTF (stderr, "Stack now");
3384 for (/* Nothing. */; bottom <= top; ++bottom)
3385 YYFPRINTF (stderr, " %d", *bottom);
3386 YYFPRINTF (stderr, "\n");
3387}
3388
3389# define YY_STACK_PRINT(Bottom, Top) \
3390do { \
3391 if (yydebug) \
3392 yy_stack_print ((Bottom), (Top)); \
3393} while (0)
3394
3395
3396/*------------------------------------------------.
3397| Report that the YYRULE is going to be reduced. |
3398`------------------------------------------------*/
3399
3400#if defined (__STDC__) || defined (__cplusplus)
3401static void
3402yy_reduce_print (int yyrule)
3403#else
3404static void
3405yy_reduce_print (yyrule)
3406 int yyrule;
3407#endif
3408{
3409 int yyi;
David Greene9145dd22007-08-01 03:59:32 +00003410 unsigned int yylno = yyrline[yyrule];
3411 YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003412 yyrule - 1, yylno);
3413 /* Print the symbols being reduced, and their result. */
3414 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
David Greene9145dd22007-08-01 03:59:32 +00003415 YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
3416 YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003417}
3418
3419# define YY_REDUCE_PRINT(Rule) \
3420do { \
3421 if (yydebug) \
3422 yy_reduce_print (Rule); \
3423} while (0)
3424
3425/* Nonzero means print parse trace. It is left uninitialized so that
3426 multiple parsers can coexist. */
3427int yydebug;
3428#else /* !YYDEBUG */
3429# define YYDPRINTF(Args)
David Greene9145dd22007-08-01 03:59:32 +00003430# define YYDSYMPRINT(Args)
3431# define YYDSYMPRINTF(Title, Token, Value, Location)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003432# define YY_STACK_PRINT(Bottom, Top)
3433# define YY_REDUCE_PRINT(Rule)
3434#endif /* !YYDEBUG */
3435
3436
3437/* YYINITDEPTH -- initial size of the parser's stacks. */
3438#ifndef YYINITDEPTH
3439# define YYINITDEPTH 200
3440#endif
3441
3442/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
3443 if the built-in stack extension method is used).
3444
3445 Do not make this value too large; the results are undefined if
David Greene9145dd22007-08-01 03:59:32 +00003446 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003447 evaluated with infinite-precision integer arithmetic. */
3448
David Greene9145dd22007-08-01 03:59:32 +00003449#if defined (YYMAXDEPTH) && YYMAXDEPTH == 0
3450# undef YYMAXDEPTH
3451#endif
3452
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003453#ifndef YYMAXDEPTH
3454# define YYMAXDEPTH 10000
3455#endif
3456
3457
3458
3459#if YYERROR_VERBOSE
3460
3461# ifndef yystrlen
3462# if defined (__GLIBC__) && defined (_STRING_H)
3463# define yystrlen strlen
3464# else
3465/* Return the length of YYSTR. */
3466static YYSIZE_T
3467# if defined (__STDC__) || defined (__cplusplus)
3468yystrlen (const char *yystr)
3469# else
3470yystrlen (yystr)
3471 const char *yystr;
3472# endif
3473{
David Greene9145dd22007-08-01 03:59:32 +00003474 register const char *yys = yystr;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003475
3476 while (*yys++ != '\0')
3477 continue;
3478
3479 return yys - yystr - 1;
3480}
3481# endif
3482# endif
3483
3484# ifndef yystpcpy
3485# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
3486# define yystpcpy stpcpy
3487# else
3488/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
3489 YYDEST. */
3490static char *
3491# if defined (__STDC__) || defined (__cplusplus)
3492yystpcpy (char *yydest, const char *yysrc)
3493# else
3494yystpcpy (yydest, yysrc)
3495 char *yydest;
3496 const char *yysrc;
3497# endif
3498{
David Greene9145dd22007-08-01 03:59:32 +00003499 register char *yyd = yydest;
3500 register const char *yys = yysrc;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003501
3502 while ((*yyd++ = *yys++) != '\0')
3503 continue;
3504
3505 return yyd - 1;
3506}
3507# endif
3508# endif
3509
David Greene9145dd22007-08-01 03:59:32 +00003510#endif /* !YYERROR_VERBOSE */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003511
3512
3513
3514#if YYDEBUG
3515/*--------------------------------.
3516| Print this symbol on YYOUTPUT. |
3517`--------------------------------*/
3518
3519#if defined (__STDC__) || defined (__cplusplus)
3520static void
3521yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
3522#else
3523static void
3524yysymprint (yyoutput, yytype, yyvaluep)
3525 FILE *yyoutput;
3526 int yytype;
3527 YYSTYPE *yyvaluep;
3528#endif
3529{
3530 /* Pacify ``unused variable'' warnings. */
3531 (void) yyvaluep;
3532
3533 if (yytype < YYNTOKENS)
David Greene9145dd22007-08-01 03:59:32 +00003534 {
3535 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
3536# ifdef YYPRINT
3537 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
3538# endif
3539 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003540 else
3541 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
3542
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003543 switch (yytype)
3544 {
3545 default:
3546 break;
3547 }
3548 YYFPRINTF (yyoutput, ")");
3549}
3550
3551#endif /* ! YYDEBUG */
3552/*-----------------------------------------------.
3553| Release the memory associated to this symbol. |
3554`-----------------------------------------------*/
3555
3556#if defined (__STDC__) || defined (__cplusplus)
3557static void
David Greene9145dd22007-08-01 03:59:32 +00003558yydestruct (int yytype, YYSTYPE *yyvaluep)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003559#else
3560static void
David Greene9145dd22007-08-01 03:59:32 +00003561yydestruct (yytype, yyvaluep)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003562 int yytype;
3563 YYSTYPE *yyvaluep;
3564#endif
3565{
3566 /* Pacify ``unused variable'' warnings. */
3567 (void) yyvaluep;
3568
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003569 switch (yytype)
3570 {
3571
3572 default:
3573 break;
3574 }
3575}
3576
3577
3578/* Prevent warnings from -Wmissing-prototypes. */
3579
3580#ifdef YYPARSE_PARAM
3581# if defined (__STDC__) || defined (__cplusplus)
3582int yyparse (void *YYPARSE_PARAM);
3583# else
3584int yyparse ();
3585# endif
3586#else /* ! YYPARSE_PARAM */
3587#if defined (__STDC__) || defined (__cplusplus)
3588int yyparse (void);
3589#else
3590int yyparse ();
3591#endif
3592#endif /* ! YYPARSE_PARAM */
3593
3594
3595
David Greene9145dd22007-08-01 03:59:32 +00003596/* The lookahead symbol. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003597int yychar;
3598
David Greene9145dd22007-08-01 03:59:32 +00003599/* The semantic value of the lookahead symbol. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003600YYSTYPE yylval;
3601
3602/* Number of syntax errors so far. */
3603int yynerrs;
3604
3605
3606
3607/*----------.
3608| yyparse. |
3609`----------*/
3610
3611#ifdef YYPARSE_PARAM
3612# if defined (__STDC__) || defined (__cplusplus)
3613int yyparse (void *YYPARSE_PARAM)
3614# else
3615int yyparse (YYPARSE_PARAM)
3616 void *YYPARSE_PARAM;
3617# endif
3618#else /* ! YYPARSE_PARAM */
3619#if defined (__STDC__) || defined (__cplusplus)
3620int
3621yyparse (void)
3622#else
3623int
3624yyparse ()
3625
3626#endif
3627#endif
3628{
3629
David Greene9145dd22007-08-01 03:59:32 +00003630 register int yystate;
3631 register int yyn;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003632 int yyresult;
3633 /* Number of tokens to shift before error messages enabled. */
3634 int yyerrstatus;
David Greene9145dd22007-08-01 03:59:32 +00003635 /* Lookahead token as an internal (translated) token number. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003636 int yytoken = 0;
3637
3638 /* Three stacks and their tools:
3639 `yyss': related to states,
3640 `yyvs': related to semantic values,
3641 `yyls': related to locations.
3642
3643 Refer to the stacks thru separate pointers, to allow yyoverflow
3644 to reallocate them elsewhere. */
3645
3646 /* The state stack. */
David Greene9145dd22007-08-01 03:59:32 +00003647 short yyssa[YYINITDEPTH];
3648 short *yyss = yyssa;
3649 register short *yyssp;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003650
3651 /* The semantic value stack. */
3652 YYSTYPE yyvsa[YYINITDEPTH];
3653 YYSTYPE *yyvs = yyvsa;
David Greene9145dd22007-08-01 03:59:32 +00003654 register YYSTYPE *yyvsp;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003655
3656
3657
3658#define YYPOPSTACK (yyvsp--, yyssp--)
3659
3660 YYSIZE_T yystacksize = YYINITDEPTH;
3661
3662 /* The variables used to return semantic value and location from the
3663 action routines. */
3664 YYSTYPE yyval;
3665
3666
3667 /* When reducing, the number of symbols on the RHS of the reduced
3668 rule. */
3669 int yylen;
3670
3671 YYDPRINTF ((stderr, "Starting parse\n"));
3672
3673 yystate = 0;
3674 yyerrstatus = 0;
3675 yynerrs = 0;
3676 yychar = YYEMPTY; /* Cause a token to be read. */
3677
3678 /* Initialize stack pointers.
3679 Waste one element of value and location stack
3680 so that they stay on the same level as the state stack.
3681 The wasted elements are never initialized. */
3682
3683 yyssp = yyss;
3684 yyvsp = yyvs;
3685
3686 goto yysetstate;
3687
3688/*------------------------------------------------------------.
3689| yynewstate -- Push a new state, which is found in yystate. |
3690`------------------------------------------------------------*/
3691 yynewstate:
3692 /* In all cases, when you get here, the value and location stacks
3693 have just been pushed. so pushing a state here evens the stacks.
3694 */
3695 yyssp++;
3696
3697 yysetstate:
3698 *yyssp = yystate;
3699
3700 if (yyss + yystacksize - 1 <= yyssp)
3701 {
3702 /* Get the current used size of the three stacks, in elements. */
3703 YYSIZE_T yysize = yyssp - yyss + 1;
3704
3705#ifdef yyoverflow
3706 {
3707 /* Give user a chance to reallocate the stack. Use copies of
3708 these so that the &'s don't force the real ones into
3709 memory. */
3710 YYSTYPE *yyvs1 = yyvs;
David Greene9145dd22007-08-01 03:59:32 +00003711 short *yyss1 = yyss;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003712
3713
3714 /* Each stack pointer address is followed by the size of the
3715 data in use in that stack, in bytes. This used to be a
3716 conditional around just the two extra args, but that might
3717 be undefined if yyoverflow is a macro. */
David Greene9145dd22007-08-01 03:59:32 +00003718 yyoverflow ("parser stack overflow",
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003719 &yyss1, yysize * sizeof (*yyssp),
3720 &yyvs1, yysize * sizeof (*yyvsp),
3721
3722 &yystacksize);
3723
3724 yyss = yyss1;
3725 yyvs = yyvs1;
3726 }
3727#else /* no yyoverflow */
3728# ifndef YYSTACK_RELOCATE
David Greene9145dd22007-08-01 03:59:32 +00003729 goto yyoverflowlab;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003730# else
3731 /* Extend the stack our own way. */
3732 if (YYMAXDEPTH <= yystacksize)
David Greene9145dd22007-08-01 03:59:32 +00003733 goto yyoverflowlab;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003734 yystacksize *= 2;
3735 if (YYMAXDEPTH < yystacksize)
3736 yystacksize = YYMAXDEPTH;
3737
3738 {
David Greene9145dd22007-08-01 03:59:32 +00003739 short *yyss1 = yyss;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003740 union yyalloc *yyptr =
3741 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
3742 if (! yyptr)
David Greene9145dd22007-08-01 03:59:32 +00003743 goto yyoverflowlab;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003744 YYSTACK_RELOCATE (yyss);
3745 YYSTACK_RELOCATE (yyvs);
3746
3747# undef YYSTACK_RELOCATE
3748 if (yyss1 != yyssa)
3749 YYSTACK_FREE (yyss1);
3750 }
3751# endif
3752#endif /* no yyoverflow */
3753
3754 yyssp = yyss + yysize - 1;
3755 yyvsp = yyvs + yysize - 1;
3756
3757
3758 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
3759 (unsigned long int) yystacksize));
3760
3761 if (yyss + yystacksize - 1 <= yyssp)
3762 YYABORT;
3763 }
3764
3765 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
3766
3767 goto yybackup;
3768
3769/*-----------.
3770| yybackup. |
3771`-----------*/
3772yybackup:
3773
3774/* Do appropriate processing given the current state. */
David Greene9145dd22007-08-01 03:59:32 +00003775/* Read a lookahead token if we need one and don't already have one. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003776/* yyresume: */
3777
David Greene9145dd22007-08-01 03:59:32 +00003778 /* First try to decide what to do without reference to lookahead token. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003779
3780 yyn = yypact[yystate];
3781 if (yyn == YYPACT_NINF)
3782 goto yydefault;
3783
David Greene9145dd22007-08-01 03:59:32 +00003784 /* Not known => get a lookahead token if don't already have one. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003785
David Greene9145dd22007-08-01 03:59:32 +00003786 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003787 if (yychar == YYEMPTY)
3788 {
3789 YYDPRINTF ((stderr, "Reading a token: "));
3790 yychar = YYLEX;
3791 }
3792
3793 if (yychar <= YYEOF)
3794 {
3795 yychar = yytoken = YYEOF;
3796 YYDPRINTF ((stderr, "Now at end of input.\n"));
3797 }
3798 else
3799 {
3800 yytoken = YYTRANSLATE (yychar);
David Greene9145dd22007-08-01 03:59:32 +00003801 YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003802 }
3803
3804 /* If the proper action on seeing token YYTOKEN is to reduce or to
3805 detect an error, take that action. */
3806 yyn += yytoken;
3807 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
3808 goto yydefault;
3809 yyn = yytable[yyn];
3810 if (yyn <= 0)
3811 {
3812 if (yyn == 0 || yyn == YYTABLE_NINF)
3813 goto yyerrlab;
3814 yyn = -yyn;
3815 goto yyreduce;
3816 }
3817
3818 if (yyn == YYFINAL)
3819 YYACCEPT;
3820
David Greene9145dd22007-08-01 03:59:32 +00003821 /* Shift the lookahead token. */
3822 YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003823
3824 /* Discard the token being shifted unless it is eof. */
3825 if (yychar != YYEOF)
3826 yychar = YYEMPTY;
3827
3828 *++yyvsp = yylval;
3829
3830
3831 /* Count tokens shifted since error; after three, turn off error
3832 status. */
3833 if (yyerrstatus)
3834 yyerrstatus--;
3835
3836 yystate = yyn;
3837 goto yynewstate;
3838
3839
3840/*-----------------------------------------------------------.
3841| yydefault -- do the default action for the current state. |
3842`-----------------------------------------------------------*/
3843yydefault:
3844 yyn = yydefact[yystate];
3845 if (yyn == 0)
3846 goto yyerrlab;
3847 goto yyreduce;
3848
3849
3850/*-----------------------------.
3851| yyreduce -- Do a reduction. |
3852`-----------------------------*/
3853yyreduce:
3854 /* yyn is the number of a rule to reduce with. */
3855 yylen = yyr2[yyn];
3856
3857 /* If YYLEN is nonzero, implement the default value of the action:
3858 `$$ = $1'.
3859
3860 Otherwise, the following line sets YYVAL to garbage.
3861 This behavior is undocumented and Bison
3862 users should not rely upon it. Assigning to YYVAL
3863 unconditionally makes the parser a bit smaller, and it avoids a
3864 GCC warning that YYVAL may be used uninitialized. */
3865 yyval = yyvsp[1-yylen];
3866
3867
3868 YY_REDUCE_PRINT (yyn);
3869 switch (yyn)
3870 {
3871 case 3:
David Greene9145dd22007-08-01 03:59:32 +00003872#line 1917 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003873 {
David Greene9145dd22007-08-01 03:59:32 +00003874 if (yyvsp[0].UIntVal > (uint32_t)INT32_MAX) // Outside of my range!
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003875 error("Value too large for type");
David Greene9145dd22007-08-01 03:59:32 +00003876 yyval.SIntVal = (int32_t)yyvsp[0].UIntVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003877 ;}
3878 break;
3879
3880 case 5:
David Greene9145dd22007-08-01 03:59:32 +00003881#line 1926 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003882 {
David Greene9145dd22007-08-01 03:59:32 +00003883 if (yyvsp[0].UInt64Val > (uint64_t)INT64_MAX) // Outside of my range!
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003884 error("Value too large for type");
David Greene9145dd22007-08-01 03:59:32 +00003885 yyval.SInt64Val = (int64_t)yyvsp[0].UInt64Val;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003886 ;}
3887 break;
3888
3889 case 26:
David Greene9145dd22007-08-01 03:59:32 +00003890#line 1948 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3891 { yyval.IPred = ICmpInst::ICMP_EQ; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003892 break;
3893
3894 case 27:
David Greene9145dd22007-08-01 03:59:32 +00003895#line 1948 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3896 { yyval.IPred = ICmpInst::ICMP_NE; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003897 break;
3898
3899 case 28:
David Greene9145dd22007-08-01 03:59:32 +00003900#line 1949 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3901 { yyval.IPred = ICmpInst::ICMP_SLT; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003902 break;
3903
3904 case 29:
David Greene9145dd22007-08-01 03:59:32 +00003905#line 1949 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3906 { yyval.IPred = ICmpInst::ICMP_SGT; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003907 break;
3908
3909 case 30:
David Greene9145dd22007-08-01 03:59:32 +00003910#line 1950 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3911 { yyval.IPred = ICmpInst::ICMP_SLE; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003912 break;
3913
3914 case 31:
David Greene9145dd22007-08-01 03:59:32 +00003915#line 1950 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3916 { yyval.IPred = ICmpInst::ICMP_SGE; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003917 break;
3918
3919 case 32:
David Greene9145dd22007-08-01 03:59:32 +00003920#line 1951 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3921 { yyval.IPred = ICmpInst::ICMP_ULT; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003922 break;
3923
3924 case 33:
David Greene9145dd22007-08-01 03:59:32 +00003925#line 1951 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3926 { yyval.IPred = ICmpInst::ICMP_UGT; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003927 break;
3928
3929 case 34:
David Greene9145dd22007-08-01 03:59:32 +00003930#line 1952 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3931 { yyval.IPred = ICmpInst::ICMP_ULE; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003932 break;
3933
3934 case 35:
David Greene9145dd22007-08-01 03:59:32 +00003935#line 1952 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3936 { yyval.IPred = ICmpInst::ICMP_UGE; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003937 break;
3938
3939 case 36:
David Greene9145dd22007-08-01 03:59:32 +00003940#line 1956 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3941 { yyval.FPred = FCmpInst::FCMP_OEQ; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003942 break;
3943
3944 case 37:
David Greene9145dd22007-08-01 03:59:32 +00003945#line 1956 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3946 { yyval.FPred = FCmpInst::FCMP_ONE; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003947 break;
3948
3949 case 38:
David Greene9145dd22007-08-01 03:59:32 +00003950#line 1957 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3951 { yyval.FPred = FCmpInst::FCMP_OLT; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003952 break;
3953
3954 case 39:
David Greene9145dd22007-08-01 03:59:32 +00003955#line 1957 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3956 { yyval.FPred = FCmpInst::FCMP_OGT; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003957 break;
3958
3959 case 40:
David Greene9145dd22007-08-01 03:59:32 +00003960#line 1958 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3961 { yyval.FPred = FCmpInst::FCMP_OLE; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003962 break;
3963
3964 case 41:
David Greene9145dd22007-08-01 03:59:32 +00003965#line 1958 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3966 { yyval.FPred = FCmpInst::FCMP_OGE; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003967 break;
3968
3969 case 42:
David Greene9145dd22007-08-01 03:59:32 +00003970#line 1959 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3971 { yyval.FPred = FCmpInst::FCMP_ORD; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003972 break;
3973
3974 case 43:
David Greene9145dd22007-08-01 03:59:32 +00003975#line 1959 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3976 { yyval.FPred = FCmpInst::FCMP_UNO; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003977 break;
3978
3979 case 44:
David Greene9145dd22007-08-01 03:59:32 +00003980#line 1960 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3981 { yyval.FPred = FCmpInst::FCMP_UEQ; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003982 break;
3983
3984 case 45:
David Greene9145dd22007-08-01 03:59:32 +00003985#line 1960 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3986 { yyval.FPred = FCmpInst::FCMP_UNE; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003987 break;
3988
3989 case 46:
David Greene9145dd22007-08-01 03:59:32 +00003990#line 1961 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3991 { yyval.FPred = FCmpInst::FCMP_ULT; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003992 break;
3993
3994 case 47:
David Greene9145dd22007-08-01 03:59:32 +00003995#line 1961 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3996 { yyval.FPred = FCmpInst::FCMP_UGT; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003997 break;
3998
3999 case 48:
David Greene9145dd22007-08-01 03:59:32 +00004000#line 1962 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4001 { yyval.FPred = FCmpInst::FCMP_ULE; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004002 break;
4003
4004 case 49:
David Greene9145dd22007-08-01 03:59:32 +00004005#line 1962 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4006 { yyval.FPred = FCmpInst::FCMP_UGE; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004007 break;
4008
4009 case 50:
David Greene9145dd22007-08-01 03:59:32 +00004010#line 1963 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4011 { yyval.FPred = FCmpInst::FCMP_TRUE; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004012 break;
4013
4014 case 51:
David Greene9145dd22007-08-01 03:59:32 +00004015#line 1964 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4016 { yyval.FPred = FCmpInst::FCMP_FALSE; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004017 break;
4018
4019 case 81:
David Greene9145dd22007-08-01 03:59:32 +00004020#line 1995 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004021 {
David Greene9145dd22007-08-01 03:59:32 +00004022 yyval.StrVal = yyvsp[-1].StrVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004023 ;}
4024 break;
4025
4026 case 82:
David Greene9145dd22007-08-01 03:59:32 +00004027#line 1998 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004028 {
David Greene9145dd22007-08-01 03:59:32 +00004029 yyval.StrVal = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004030 ;}
4031 break;
4032
4033 case 83:
David Greene9145dd22007-08-01 03:59:32 +00004034#line 2003 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4035 { yyval.Linkage = GlobalValue::InternalLinkage; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004036 break;
4037
4038 case 84:
David Greene9145dd22007-08-01 03:59:32 +00004039#line 2004 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4040 { yyval.Linkage = GlobalValue::LinkOnceLinkage; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004041 break;
4042
4043 case 85:
David Greene9145dd22007-08-01 03:59:32 +00004044#line 2005 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4045 { yyval.Linkage = GlobalValue::WeakLinkage; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004046 break;
4047
4048 case 86:
David Greene9145dd22007-08-01 03:59:32 +00004049#line 2006 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4050 { yyval.Linkage = GlobalValue::AppendingLinkage; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004051 break;
4052
4053 case 87:
David Greene9145dd22007-08-01 03:59:32 +00004054#line 2007 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4055 { yyval.Linkage = GlobalValue::DLLImportLinkage; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004056 break;
4057
4058 case 88:
David Greene9145dd22007-08-01 03:59:32 +00004059#line 2008 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4060 { yyval.Linkage = GlobalValue::DLLExportLinkage; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004061 break;
4062
4063 case 89:
David Greene9145dd22007-08-01 03:59:32 +00004064#line 2009 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4065 { yyval.Linkage = GlobalValue::ExternalWeakLinkage; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004066 break;
4067
4068 case 90:
David Greene9145dd22007-08-01 03:59:32 +00004069#line 2010 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4070 { yyval.Linkage = GlobalValue::ExternalLinkage; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004071 break;
4072
4073 case 91:
David Greene9145dd22007-08-01 03:59:32 +00004074#line 2014 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4075 { yyval.UIntVal = lastCallingConv = OldCallingConv::C; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004076 break;
4077
4078 case 92:
David Greene9145dd22007-08-01 03:59:32 +00004079#line 2015 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4080 { yyval.UIntVal = lastCallingConv = OldCallingConv::C; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004081 break;
4082
4083 case 93:
David Greene9145dd22007-08-01 03:59:32 +00004084#line 2016 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4085 { yyval.UIntVal = lastCallingConv = OldCallingConv::CSRet; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004086 break;
4087
4088 case 94:
David Greene9145dd22007-08-01 03:59:32 +00004089#line 2017 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4090 { yyval.UIntVal = lastCallingConv = OldCallingConv::Fast; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004091 break;
4092
4093 case 95:
David Greene9145dd22007-08-01 03:59:32 +00004094#line 2018 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4095 { yyval.UIntVal = lastCallingConv = OldCallingConv::Cold; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004096 break;
4097
4098 case 96:
David Greene9145dd22007-08-01 03:59:32 +00004099#line 2019 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4100 { yyval.UIntVal = lastCallingConv = OldCallingConv::X86_StdCall; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004101 break;
4102
4103 case 97:
David Greene9145dd22007-08-01 03:59:32 +00004104#line 2020 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4105 { yyval.UIntVal = lastCallingConv = OldCallingConv::X86_FastCall; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004106 break;
4107
4108 case 98:
David Greene9145dd22007-08-01 03:59:32 +00004109#line 2021 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004110 {
David Greene9145dd22007-08-01 03:59:32 +00004111 if ((unsigned)yyvsp[0].UInt64Val != yyvsp[0].UInt64Val)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004112 error("Calling conv too large");
David Greene9145dd22007-08-01 03:59:32 +00004113 yyval.UIntVal = lastCallingConv = yyvsp[0].UInt64Val;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004114 ;}
4115 break;
4116
4117 case 99:
David Greene9145dd22007-08-01 03:59:32 +00004118#line 2031 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4119 { yyval.UIntVal = 0; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004120 break;
4121
4122 case 100:
David Greene9145dd22007-08-01 03:59:32 +00004123#line 2032 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004124 {
David Greene9145dd22007-08-01 03:59:32 +00004125 yyval.UIntVal = yyvsp[0].UInt64Val;
4126 if (yyval.UIntVal != 0 && !isPowerOf2_32(yyval.UIntVal))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004127 error("Alignment must be a power of two");
4128 ;}
4129 break;
4130
4131 case 101:
David Greene9145dd22007-08-01 03:59:32 +00004132#line 2040 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4133 { yyval.UIntVal = 0; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004134 break;
4135
4136 case 102:
David Greene9145dd22007-08-01 03:59:32 +00004137#line 2041 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004138 {
David Greene9145dd22007-08-01 03:59:32 +00004139 yyval.UIntVal = yyvsp[0].UInt64Val;
4140 if (yyval.UIntVal != 0 && !isPowerOf2_32(yyval.UIntVal))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004141 error("Alignment must be a power of two");
4142 ;}
4143 break;
4144
4145 case 103:
David Greene9145dd22007-08-01 03:59:32 +00004146#line 2049 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004147 {
David Greene9145dd22007-08-01 03:59:32 +00004148 for (unsigned i = 0, e = strlen(yyvsp[0].StrVal); i != e; ++i)
4149 if (yyvsp[0].StrVal[i] == '"' || yyvsp[0].StrVal[i] == '\\')
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004150 error("Invalid character in section name");
David Greene9145dd22007-08-01 03:59:32 +00004151 yyval.StrVal = yyvsp[0].StrVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004152 ;}
4153 break;
4154
4155 case 104:
David Greene9145dd22007-08-01 03:59:32 +00004156#line 2058 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4157 { yyval.StrVal = 0; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004158 break;
4159
4160 case 105:
David Greene9145dd22007-08-01 03:59:32 +00004161#line 2059 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4162 { yyval.StrVal = yyvsp[0].StrVal; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004163 break;
4164
4165 case 106:
David Greene9145dd22007-08-01 03:59:32 +00004166#line 2066 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004167 {;}
4168 break;
4169
4170 case 107:
David Greene9145dd22007-08-01 03:59:32 +00004171#line 2067 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004172 {;}
4173 break;
4174
4175 case 108:
David Greene9145dd22007-08-01 03:59:32 +00004176#line 2071 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004177 {
David Greene9145dd22007-08-01 03:59:32 +00004178 CurGV->setSection(yyvsp[0].StrVal);
4179 free(yyvsp[0].StrVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004180 ;}
4181 break;
4182
4183 case 109:
David Greene9145dd22007-08-01 03:59:32 +00004184#line 2075 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004185 {
David Greene9145dd22007-08-01 03:59:32 +00004186 if (yyvsp[0].UInt64Val != 0 && !isPowerOf2_32(yyvsp[0].UInt64Val))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004187 error("Alignment must be a power of two");
David Greene9145dd22007-08-01 03:59:32 +00004188 CurGV->setAlignment(yyvsp[0].UInt64Val);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004189
4190 ;}
4191 break;
4192
4193 case 111:
David Greene9145dd22007-08-01 03:59:32 +00004194#line 2092 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004195 {
David Greene9145dd22007-08-01 03:59:32 +00004196 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
4197 yyval.TypeVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004198 ;}
4199 break;
4200
4201 case 113:
David Greene9145dd22007-08-01 03:59:32 +00004202#line 2100 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004203 {
David Greene9145dd22007-08-01 03:59:32 +00004204 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
4205 yyval.TypeVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004206 ;}
4207 break;
4208
4209 case 114:
David Greene9145dd22007-08-01 03:59:32 +00004210#line 2107 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004211 {
4212 if (!UpRefs.empty())
David Greene9145dd22007-08-01 03:59:32 +00004213 error("Invalid upreference in type: " + (*yyvsp[0].TypeVal.PAT)->getDescription());
4214 yyval.TypeVal = yyvsp[0].TypeVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004215 ;}
4216 break;
4217
4218 case 127:
David Greene9145dd22007-08-01 03:59:32 +00004219#line 2121 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004220 {
David Greene9145dd22007-08-01 03:59:32 +00004221 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
4222 yyval.TypeVal.S.copy(yyvsp[0].PrimType.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004223 ;}
4224 break;
4225
4226 case 128:
David Greene9145dd22007-08-01 03:59:32 +00004227#line 2125 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004228 {
David Greene9145dd22007-08-01 03:59:32 +00004229 yyval.TypeVal.PAT = new PATypeHolder(OpaqueType::get());
4230 yyval.TypeVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004231 ;}
4232 break;
4233
4234 case 129:
David Greene9145dd22007-08-01 03:59:32 +00004235#line 2129 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004236 { // Named types are also simple types...
David Greene9145dd22007-08-01 03:59:32 +00004237 yyval.TypeVal.S.copy(getTypeSign(yyvsp[0].ValIDVal));
4238 const Type* tmp = getType(yyvsp[0].ValIDVal);
4239 yyval.TypeVal.PAT = new PATypeHolder(tmp);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004240 ;}
4241 break;
4242
4243 case 130:
David Greene9145dd22007-08-01 03:59:32 +00004244#line 2134 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004245 { // Type UpReference
David Greene9145dd22007-08-01 03:59:32 +00004246 if (yyvsp[0].UInt64Val > (uint64_t)~0U)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004247 error("Value out of range");
4248 OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder
David Greene9145dd22007-08-01 03:59:32 +00004249 UpRefs.push_back(UpRefRecord((unsigned)yyvsp[0].UInt64Val, OT)); // Add to vector...
4250 yyval.TypeVal.PAT = new PATypeHolder(OT);
4251 yyval.TypeVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004252 UR_OUT("New Upreference!\n");
4253 ;}
4254 break;
4255
4256 case 131:
David Greene9145dd22007-08-01 03:59:32 +00004257#line 2143 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004258 { // Function derived type?
David Greene9145dd22007-08-01 03:59:32 +00004259 yyval.TypeVal.S.makeComposite(yyvsp[-3].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004260 std::vector<const Type*> Params;
David Greene9145dd22007-08-01 03:59:32 +00004261 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-1].TypeList->begin(),
4262 E = yyvsp[-1].TypeList->end(); I != E; ++I) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004263 Params.push_back(I->PAT->get());
David Greene9145dd22007-08-01 03:59:32 +00004264 yyval.TypeVal.S.add(I->S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004265 }
4266 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
4267 if (isVarArg) Params.pop_back();
4268
4269 ParamAttrsList *PAL = 0;
4270 if (lastCallingConv == OldCallingConv::CSRet) {
4271 ParamAttrsVector Attrs;
4272 ParamAttrsWithIndex PAWI;
4273 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
4274 Attrs.push_back(PAWI);
4275 PAL = ParamAttrsList::get(Attrs);
4276 }
4277
4278 const FunctionType *FTy =
David Greene9145dd22007-08-01 03:59:32 +00004279 FunctionType::get(yyvsp[-3].TypeVal.PAT->get(), Params, isVarArg, PAL);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004280
David Greene9145dd22007-08-01 03:59:32 +00004281 yyval.TypeVal.PAT = new PATypeHolder( HandleUpRefs(FTy, yyval.TypeVal.S) );
4282 delete yyvsp[-3].TypeVal.PAT; // Delete the return type handle
4283 delete yyvsp[-1].TypeList; // Delete the argument list
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004284 ;}
4285 break;
4286
4287 case 132:
David Greene9145dd22007-08-01 03:59:32 +00004288#line 2170 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004289 { // Sized array type?
David Greene9145dd22007-08-01 03:59:32 +00004290 yyval.TypeVal.S.makeComposite(yyvsp[-1].TypeVal.S);
4291 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(ArrayType::get(yyvsp[-1].TypeVal.PAT->get(),
4292 (unsigned)yyvsp[-3].UInt64Val), yyval.TypeVal.S));
4293 delete yyvsp[-1].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004294 ;}
4295 break;
4296
4297 case 133:
David Greene9145dd22007-08-01 03:59:32 +00004298#line 2176 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004299 { // Vector type?
David Greene9145dd22007-08-01 03:59:32 +00004300 const llvm::Type* ElemTy = yyvsp[-1].TypeVal.PAT->get();
4301 if ((unsigned)yyvsp[-3].UInt64Val != yyvsp[-3].UInt64Val)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004302 error("Unsigned result not equal to signed result");
4303 if (!(ElemTy->isInteger() || ElemTy->isFloatingPoint()))
4304 error("Elements of a VectorType must be integer or floating point");
David Greene9145dd22007-08-01 03:59:32 +00004305 if (!isPowerOf2_32(yyvsp[-3].UInt64Val))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004306 error("VectorType length should be a power of 2");
David Greene9145dd22007-08-01 03:59:32 +00004307 yyval.TypeVal.S.makeComposite(yyvsp[-1].TypeVal.S);
4308 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(VectorType::get(ElemTy,
4309 (unsigned)yyvsp[-3].UInt64Val), yyval.TypeVal.S));
4310 delete yyvsp[-1].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004311 ;}
4312 break;
4313
4314 case 134:
David Greene9145dd22007-08-01 03:59:32 +00004315#line 2189 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004316 { // Structure type?
4317 std::vector<const Type*> Elements;
David Greene9145dd22007-08-01 03:59:32 +00004318 yyval.TypeVal.S.makeComposite();
4319 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-1].TypeList->begin(),
4320 E = yyvsp[-1].TypeList->end(); I != E; ++I) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004321 Elements.push_back(I->PAT->get());
David Greene9145dd22007-08-01 03:59:32 +00004322 yyval.TypeVal.S.add(I->S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004323 }
David Greene9145dd22007-08-01 03:59:32 +00004324 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements), yyval.TypeVal.S));
4325 delete yyvsp[-1].TypeList;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004326 ;}
4327 break;
4328
4329 case 135:
David Greene9145dd22007-08-01 03:59:32 +00004330#line 2200 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004331 { // Empty structure type?
David Greene9145dd22007-08-01 03:59:32 +00004332 yyval.TypeVal.PAT = new PATypeHolder(StructType::get(std::vector<const Type*>()));
4333 yyval.TypeVal.S.makeComposite();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004334 ;}
4335 break;
4336
4337 case 136:
David Greene9145dd22007-08-01 03:59:32 +00004338#line 2204 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004339 { // Packed Structure type?
David Greene9145dd22007-08-01 03:59:32 +00004340 yyval.TypeVal.S.makeComposite();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004341 std::vector<const Type*> Elements;
David Greene9145dd22007-08-01 03:59:32 +00004342 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-2].TypeList->begin(),
4343 E = yyvsp[-2].TypeList->end(); I != E; ++I) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004344 Elements.push_back(I->PAT->get());
David Greene9145dd22007-08-01 03:59:32 +00004345 yyval.TypeVal.S.add(I->S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004346 delete I->PAT;
4347 }
David Greene9145dd22007-08-01 03:59:32 +00004348 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements, true),
4349 yyval.TypeVal.S));
4350 delete yyvsp[-2].TypeList;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004351 ;}
4352 break;
4353
4354 case 137:
David Greene9145dd22007-08-01 03:59:32 +00004355#line 2217 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004356 { // Empty packed structure type?
David Greene9145dd22007-08-01 03:59:32 +00004357 yyval.TypeVal.PAT = new PATypeHolder(StructType::get(std::vector<const Type*>(),true));
4358 yyval.TypeVal.S.makeComposite();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004359 ;}
4360 break;
4361
4362 case 138:
David Greene9145dd22007-08-01 03:59:32 +00004363#line 2221 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004364 { // Pointer type?
David Greene9145dd22007-08-01 03:59:32 +00004365 if (yyvsp[-1].TypeVal.PAT->get() == Type::LabelTy)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004366 error("Cannot form a pointer to a basic block");
David Greene9145dd22007-08-01 03:59:32 +00004367 yyval.TypeVal.S.makeComposite(yyvsp[-1].TypeVal.S);
4368 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(PointerType::get(yyvsp[-1].TypeVal.PAT->get()),
4369 yyval.TypeVal.S));
4370 delete yyvsp[-1].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004371 ;}
4372 break;
4373
4374 case 139:
David Greene9145dd22007-08-01 03:59:32 +00004375#line 2235 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004376 {
David Greene9145dd22007-08-01 03:59:32 +00004377 yyval.TypeList = new std::list<PATypeInfo>();
4378 yyval.TypeList->push_back(yyvsp[0].TypeVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004379 ;}
4380 break;
4381
4382 case 140:
David Greene9145dd22007-08-01 03:59:32 +00004383#line 2239 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004384 {
David Greene9145dd22007-08-01 03:59:32 +00004385 (yyval.TypeList=yyvsp[-2].TypeList)->push_back(yyvsp[0].TypeVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004386 ;}
4387 break;
4388
4389 case 142:
David Greene9145dd22007-08-01 03:59:32 +00004390#line 2247 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004391 {
4392 PATypeInfo VoidTI;
4393 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
4394 VoidTI.S.makeSignless();
David Greene9145dd22007-08-01 03:59:32 +00004395 (yyval.TypeList=yyvsp[-2].TypeList)->push_back(VoidTI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004396 ;}
4397 break;
4398
4399 case 143:
David Greene9145dd22007-08-01 03:59:32 +00004400#line 2253 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004401 {
David Greene9145dd22007-08-01 03:59:32 +00004402 yyval.TypeList = new std::list<PATypeInfo>();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004403 PATypeInfo VoidTI;
4404 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
4405 VoidTI.S.makeSignless();
David Greene9145dd22007-08-01 03:59:32 +00004406 yyval.TypeList->push_back(VoidTI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004407 ;}
4408 break;
4409
4410 case 144:
David Greene9145dd22007-08-01 03:59:32 +00004411#line 2260 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004412 {
David Greene9145dd22007-08-01 03:59:32 +00004413 yyval.TypeList = new std::list<PATypeInfo>();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004414 ;}
4415 break;
4416
4417 case 145:
David Greene9145dd22007-08-01 03:59:32 +00004418#line 2272 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004419 { // Nonempty unsized arr
David Greene9145dd22007-08-01 03:59:32 +00004420 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-3].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004421 if (ATy == 0)
4422 error("Cannot make array constant with type: '" +
David Greene9145dd22007-08-01 03:59:32 +00004423 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004424 const Type *ETy = ATy->getElementType();
4425 int NumElements = ATy->getNumElements();
4426
4427 // Verify that we have the correct size...
David Greene9145dd22007-08-01 03:59:32 +00004428 if (NumElements != -1 && NumElements != (int)yyvsp[-1].ConstVector->size())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004429 error("Type mismatch: constant sized array initialized with " +
David Greene9145dd22007-08-01 03:59:32 +00004430 utostr(yyvsp[-1].ConstVector->size()) + " arguments, but has size of " +
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004431 itostr(NumElements) + "");
4432
4433 // Verify all elements are correct type!
4434 std::vector<Constant*> Elems;
David Greene9145dd22007-08-01 03:59:32 +00004435 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
4436 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004437 const Type* ValTy = C->getType();
4438 if (ETy != ValTy)
4439 error("Element #" + utostr(i) + " is not of type '" +
4440 ETy->getDescription() +"' as required!\nIt is of type '"+
4441 ValTy->getDescription() + "'");
4442 Elems.push_back(C);
4443 }
David Greene9145dd22007-08-01 03:59:32 +00004444 yyval.ConstVal.C = ConstantArray::get(ATy, Elems);
4445 yyval.ConstVal.S.copy(yyvsp[-3].TypeVal.S);
4446 delete yyvsp[-3].TypeVal.PAT;
4447 delete yyvsp[-1].ConstVector;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004448 ;}
4449 break;
4450
4451 case 146:
David Greene9145dd22007-08-01 03:59:32 +00004452#line 2302 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004453 {
David Greene9145dd22007-08-01 03:59:32 +00004454 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-2].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004455 if (ATy == 0)
4456 error("Cannot make array constant with type: '" +
David Greene9145dd22007-08-01 03:59:32 +00004457 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004458 int NumElements = ATy->getNumElements();
4459 if (NumElements != -1 && NumElements != 0)
4460 error("Type mismatch: constant sized array initialized with 0"
4461 " arguments, but has size of " + itostr(NumElements) +"");
David Greene9145dd22007-08-01 03:59:32 +00004462 yyval.ConstVal.C = ConstantArray::get(ATy, std::vector<Constant*>());
4463 yyval.ConstVal.S.copy(yyvsp[-2].TypeVal.S);
4464 delete yyvsp[-2].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004465 ;}
4466 break;
4467
4468 case 147:
David Greene9145dd22007-08-01 03:59:32 +00004469#line 2315 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004470 {
David Greene9145dd22007-08-01 03:59:32 +00004471 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-2].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004472 if (ATy == 0)
4473 error("Cannot make array constant with type: '" +
David Greene9145dd22007-08-01 03:59:32 +00004474 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004475 int NumElements = ATy->getNumElements();
4476 const Type *ETy = dyn_cast<IntegerType>(ATy->getElementType());
4477 if (!ETy || cast<IntegerType>(ETy)->getBitWidth() != 8)
4478 error("String arrays require type i8, not '" + ETy->getDescription() +
4479 "'");
David Greene9145dd22007-08-01 03:59:32 +00004480 char *EndStr = UnEscapeLexed(yyvsp[0].StrVal, true);
4481 if (NumElements != -1 && NumElements != (EndStr-yyvsp[0].StrVal))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004482 error("Can't build string constant of size " +
David Greene9145dd22007-08-01 03:59:32 +00004483 itostr((int)(EndStr-yyvsp[0].StrVal)) + " when array has size " +
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004484 itostr(NumElements) + "");
4485 std::vector<Constant*> Vals;
David Greene9145dd22007-08-01 03:59:32 +00004486 for (char *C = (char *)yyvsp[0].StrVal; C != (char *)EndStr; ++C)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004487 Vals.push_back(ConstantInt::get(ETy, *C));
David Greene9145dd22007-08-01 03:59:32 +00004488 free(yyvsp[0].StrVal);
4489 yyval.ConstVal.C = ConstantArray::get(ATy, Vals);
4490 yyval.ConstVal.S.copy(yyvsp[-2].TypeVal.S);
4491 delete yyvsp[-2].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004492 ;}
4493 break;
4494
4495 case 148:
David Greene9145dd22007-08-01 03:59:32 +00004496#line 2338 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004497 { // Nonempty unsized arr
David Greene9145dd22007-08-01 03:59:32 +00004498 const VectorType *PTy = dyn_cast<VectorType>(yyvsp[-3].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004499 if (PTy == 0)
4500 error("Cannot make packed constant with type: '" +
David Greene9145dd22007-08-01 03:59:32 +00004501 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004502 const Type *ETy = PTy->getElementType();
4503 int NumElements = PTy->getNumElements();
4504 // Verify that we have the correct size...
David Greene9145dd22007-08-01 03:59:32 +00004505 if (NumElements != -1 && NumElements != (int)yyvsp[-1].ConstVector->size())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004506 error("Type mismatch: constant sized packed initialized with " +
David Greene9145dd22007-08-01 03:59:32 +00004507 utostr(yyvsp[-1].ConstVector->size()) + " arguments, but has size of " +
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004508 itostr(NumElements) + "");
4509 // Verify all elements are correct type!
4510 std::vector<Constant*> Elems;
David Greene9145dd22007-08-01 03:59:32 +00004511 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
4512 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004513 const Type* ValTy = C->getType();
4514 if (ETy != ValTy)
4515 error("Element #" + utostr(i) + " is not of type '" +
4516 ETy->getDescription() +"' as required!\nIt is of type '"+
4517 ValTy->getDescription() + "'");
4518 Elems.push_back(C);
4519 }
David Greene9145dd22007-08-01 03:59:32 +00004520 yyval.ConstVal.C = ConstantVector::get(PTy, Elems);
4521 yyval.ConstVal.S.copy(yyvsp[-3].TypeVal.S);
4522 delete yyvsp[-3].TypeVal.PAT;
4523 delete yyvsp[-1].ConstVector;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004524 ;}
4525 break;
4526
4527 case 149:
David Greene9145dd22007-08-01 03:59:32 +00004528#line 2366 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004529 {
David Greene9145dd22007-08-01 03:59:32 +00004530 const StructType *STy = dyn_cast<StructType>(yyvsp[-3].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004531 if (STy == 0)
4532 error("Cannot make struct constant with type: '" +
David Greene9145dd22007-08-01 03:59:32 +00004533 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
4534 if (yyvsp[-1].ConstVector->size() != STy->getNumContainedTypes())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004535 error("Illegal number of initializers for structure type");
4536
4537 // Check to ensure that constants are compatible with the type initializer!
4538 std::vector<Constant*> Fields;
David Greene9145dd22007-08-01 03:59:32 +00004539 for (unsigned i = 0, e = yyvsp[-1].ConstVector->size(); i != e; ++i) {
4540 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004541 if (C->getType() != STy->getElementType(i))
4542 error("Expected type '" + STy->getElementType(i)->getDescription() +
4543 "' for element #" + utostr(i) + " of structure initializer");
4544 Fields.push_back(C);
4545 }
David Greene9145dd22007-08-01 03:59:32 +00004546 yyval.ConstVal.C = ConstantStruct::get(STy, Fields);
4547 yyval.ConstVal.S.copy(yyvsp[-3].TypeVal.S);
4548 delete yyvsp[-3].TypeVal.PAT;
4549 delete yyvsp[-1].ConstVector;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004550 ;}
4551 break;
4552
4553 case 150:
David Greene9145dd22007-08-01 03:59:32 +00004554#line 2388 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004555 {
David Greene9145dd22007-08-01 03:59:32 +00004556 const StructType *STy = dyn_cast<StructType>(yyvsp[-2].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004557 if (STy == 0)
4558 error("Cannot make struct constant with type: '" +
David Greene9145dd22007-08-01 03:59:32 +00004559 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004560 if (STy->getNumContainedTypes() != 0)
4561 error("Illegal number of initializers for structure type");
David Greene9145dd22007-08-01 03:59:32 +00004562 yyval.ConstVal.C = ConstantStruct::get(STy, std::vector<Constant*>());
4563 yyval.ConstVal.S.copy(yyvsp[-2].TypeVal.S);
4564 delete yyvsp[-2].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004565 ;}
4566 break;
4567
4568 case 151:
David Greene9145dd22007-08-01 03:59:32 +00004569#line 2399 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004570 {
David Greene9145dd22007-08-01 03:59:32 +00004571 const StructType *STy = dyn_cast<StructType>(yyvsp[-5].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004572 if (STy == 0)
4573 error("Cannot make packed struct constant with type: '" +
David Greene9145dd22007-08-01 03:59:32 +00004574 yyvsp[-5].TypeVal.PAT->get()->getDescription() + "'");
4575 if (yyvsp[-2].ConstVector->size() != STy->getNumContainedTypes())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004576 error("Illegal number of initializers for packed structure type");
4577
4578 // Check to ensure that constants are compatible with the type initializer!
4579 std::vector<Constant*> Fields;
David Greene9145dd22007-08-01 03:59:32 +00004580 for (unsigned i = 0, e = yyvsp[-2].ConstVector->size(); i != e; ++i) {
4581 Constant *C = (*yyvsp[-2].ConstVector)[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004582 if (C->getType() != STy->getElementType(i))
4583 error("Expected type '" + STy->getElementType(i)->getDescription() +
4584 "' for element #" + utostr(i) + " of packed struct initializer");
4585 Fields.push_back(C);
4586 }
David Greene9145dd22007-08-01 03:59:32 +00004587 yyval.ConstVal.C = ConstantStruct::get(STy, Fields);
4588 yyval.ConstVal.S.copy(yyvsp[-5].TypeVal.S);
4589 delete yyvsp[-5].TypeVal.PAT;
4590 delete yyvsp[-2].ConstVector;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004591 ;}
4592 break;
4593
4594 case 152:
David Greene9145dd22007-08-01 03:59:32 +00004595#line 2421 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004596 {
David Greene9145dd22007-08-01 03:59:32 +00004597 const StructType *STy = dyn_cast<StructType>(yyvsp[-4].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004598 if (STy == 0)
4599 error("Cannot make packed struct constant with type: '" +
David Greene9145dd22007-08-01 03:59:32 +00004600 yyvsp[-4].TypeVal.PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004601 if (STy->getNumContainedTypes() != 0)
4602 error("Illegal number of initializers for packed structure type");
David Greene9145dd22007-08-01 03:59:32 +00004603 yyval.ConstVal.C = ConstantStruct::get(STy, std::vector<Constant*>());
4604 yyval.ConstVal.S.copy(yyvsp[-4].TypeVal.S);
4605 delete yyvsp[-4].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004606 ;}
4607 break;
4608
4609 case 153:
David Greene9145dd22007-08-01 03:59:32 +00004610#line 2432 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004611 {
David Greene9145dd22007-08-01 03:59:32 +00004612 const PointerType *PTy = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004613 if (PTy == 0)
4614 error("Cannot make null pointer constant with type: '" +
David Greene9145dd22007-08-01 03:59:32 +00004615 yyvsp[-1].TypeVal.PAT->get()->getDescription() + "'");
4616 yyval.ConstVal.C = ConstantPointerNull::get(PTy);
4617 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4618 delete yyvsp[-1].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004619 ;}
4620 break;
4621
4622 case 154:
David Greene9145dd22007-08-01 03:59:32 +00004623#line 2441 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004624 {
David Greene9145dd22007-08-01 03:59:32 +00004625 yyval.ConstVal.C = UndefValue::get(yyvsp[-1].TypeVal.PAT->get());
4626 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4627 delete yyvsp[-1].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004628 ;}
4629 break;
4630
4631 case 155:
David Greene9145dd22007-08-01 03:59:32 +00004632#line 2446 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004633 {
David Greene9145dd22007-08-01 03:59:32 +00004634 const PointerType *Ty = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004635 if (Ty == 0)
4636 error("Global const reference must be a pointer type, not" +
David Greene9145dd22007-08-01 03:59:32 +00004637 yyvsp[-1].TypeVal.PAT->get()->getDescription());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004638
4639 // ConstExprs can exist in the body of a function, thus creating
4640 // GlobalValues whenever they refer to a variable. Because we are in
4641 // the context of a function, getExistingValue will search the functions
4642 // symbol table instead of the module symbol table for the global symbol,
4643 // which throws things all off. To get around this, we just tell
4644 // getExistingValue that we are at global scope here.
4645 //
4646 Function *SavedCurFn = CurFun.CurrentFunction;
4647 CurFun.CurrentFunction = 0;
David Greene9145dd22007-08-01 03:59:32 +00004648 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
4649 Value *V = getExistingValue(Ty, yyvsp[0].ValIDVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004650 CurFun.CurrentFunction = SavedCurFn;
4651
4652 // If this is an initializer for a constant pointer, which is referencing a
4653 // (currently) undefined variable, create a stub now that shall be replaced
4654 // in the future with the right type of variable.
4655 //
4656 if (V == 0) {
4657 assert(isa<PointerType>(Ty) && "Globals may only be used as pointers");
4658 const PointerType *PT = cast<PointerType>(Ty);
4659
4660 // First check to see if the forward references value is already created!
4661 PerModuleInfo::GlobalRefsType::iterator I =
David Greene9145dd22007-08-01 03:59:32 +00004662 CurModule.GlobalRefs.find(std::make_pair(PT, yyvsp[0].ValIDVal));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004663
4664 if (I != CurModule.GlobalRefs.end()) {
4665 V = I->second; // Placeholder already exists, use it...
David Greene9145dd22007-08-01 03:59:32 +00004666 yyvsp[0].ValIDVal.destroy();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004667 } else {
4668 std::string Name;
David Greene9145dd22007-08-01 03:59:32 +00004669 if (yyvsp[0].ValIDVal.Type == ValID::NameVal) Name = yyvsp[0].ValIDVal.Name;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004670
4671 // Create the forward referenced global.
4672 GlobalValue *GV;
4673 if (const FunctionType *FTy =
4674 dyn_cast<FunctionType>(PT->getElementType())) {
4675 GV = new Function(FTy, GlobalValue::ExternalLinkage, Name,
4676 CurModule.CurrentModule);
4677 } else {
4678 GV = new GlobalVariable(PT->getElementType(), false,
4679 GlobalValue::ExternalLinkage, 0,
4680 Name, CurModule.CurrentModule);
4681 }
4682
4683 // Keep track of the fact that we have a forward ref to recycle it
David Greene9145dd22007-08-01 03:59:32 +00004684 CurModule.GlobalRefs.insert(std::make_pair(std::make_pair(PT, yyvsp[0].ValIDVal), GV));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004685 V = GV;
4686 }
4687 }
David Greene9145dd22007-08-01 03:59:32 +00004688 yyval.ConstVal.C = cast<GlobalValue>(V);
4689 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4690 delete yyvsp[-1].TypeVal.PAT; // Free the type handle
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004691 ;}
4692 break;
4693
4694 case 156:
David Greene9145dd22007-08-01 03:59:32 +00004695#line 2505 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004696 {
David Greene9145dd22007-08-01 03:59:32 +00004697 if (yyvsp[-1].TypeVal.PAT->get() != yyvsp[0].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004698 error("Mismatched types for constant expression");
David Greene9145dd22007-08-01 03:59:32 +00004699 yyval.ConstVal = yyvsp[0].ConstVal;
4700 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4701 delete yyvsp[-1].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004702 ;}
4703 break;
4704
4705 case 157:
David Greene9145dd22007-08-01 03:59:32 +00004706#line 2512 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004707 {
David Greene9145dd22007-08-01 03:59:32 +00004708 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004709 if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
4710 error("Cannot create a null initialized value of this type");
David Greene9145dd22007-08-01 03:59:32 +00004711 yyval.ConstVal.C = Constant::getNullValue(Ty);
4712 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4713 delete yyvsp[-1].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004714 ;}
4715 break;
4716
4717 case 158:
David Greene9145dd22007-08-01 03:59:32 +00004718#line 2520 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004719 { // integral constants
David Greene9145dd22007-08-01 03:59:32 +00004720 const Type *Ty = yyvsp[-1].PrimType.T;
4721 if (!ConstantInt::isValueValidForType(Ty, yyvsp[0].SInt64Val))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004722 error("Constant value doesn't fit in type");
David Greene9145dd22007-08-01 03:59:32 +00004723 yyval.ConstVal.C = ConstantInt::get(Ty, yyvsp[0].SInt64Val);
4724 yyval.ConstVal.S.makeSigned();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004725 ;}
4726 break;
4727
4728 case 159:
David Greene9145dd22007-08-01 03:59:32 +00004729#line 2527 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004730 { // integral constants
David Greene9145dd22007-08-01 03:59:32 +00004731 const Type *Ty = yyvsp[-1].PrimType.T;
4732 if (!ConstantInt::isValueValidForType(Ty, yyvsp[0].UInt64Val))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004733 error("Constant value doesn't fit in type");
David Greene9145dd22007-08-01 03:59:32 +00004734 yyval.ConstVal.C = ConstantInt::get(Ty, yyvsp[0].UInt64Val);
4735 yyval.ConstVal.S.makeUnsigned();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004736 ;}
4737 break;
4738
4739 case 160:
David Greene9145dd22007-08-01 03:59:32 +00004740#line 2534 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004741 { // Boolean constants
David Greene9145dd22007-08-01 03:59:32 +00004742 yyval.ConstVal.C = ConstantInt::get(Type::Int1Ty, true);
4743 yyval.ConstVal.S.makeUnsigned();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004744 ;}
4745 break;
4746
4747 case 161:
David Greene9145dd22007-08-01 03:59:32 +00004748#line 2538 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004749 { // Boolean constants
David Greene9145dd22007-08-01 03:59:32 +00004750 yyval.ConstVal.C = ConstantInt::get(Type::Int1Ty, false);
4751 yyval.ConstVal.S.makeUnsigned();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004752 ;}
4753 break;
4754
4755 case 162:
David Greene9145dd22007-08-01 03:59:32 +00004756#line 2542 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004757 { // Float & Double constants
David Greene9145dd22007-08-01 03:59:32 +00004758 if (!ConstantFP::isValueValidForType(yyvsp[-1].PrimType.T, yyvsp[0].FPVal))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004759 error("Floating point constant invalid for type");
David Greene9145dd22007-08-01 03:59:32 +00004760 yyval.ConstVal.C = ConstantFP::get(yyvsp[-1].PrimType.T, yyvsp[0].FPVal);
4761 yyval.ConstVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004762 ;}
4763 break;
4764
4765 case 163:
David Greene9145dd22007-08-01 03:59:32 +00004766#line 2551 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004767 {
David Greene9145dd22007-08-01 03:59:32 +00004768 const Type* SrcTy = yyvsp[-3].ConstVal.C->getType();
4769 const Type* DstTy = yyvsp[-1].TypeVal.PAT->get();
4770 Signedness SrcSign(yyvsp[-3].ConstVal.S);
4771 Signedness DstSign(yyvsp[-1].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004772 if (!SrcTy->isFirstClassType())
4773 error("cast constant expression from a non-primitive type: '" +
4774 SrcTy->getDescription() + "'");
4775 if (!DstTy->isFirstClassType())
4776 error("cast constant expression to a non-primitive type: '" +
4777 DstTy->getDescription() + "'");
David Greene9145dd22007-08-01 03:59:32 +00004778 yyval.ConstVal.C = cast<Constant>(getCast(yyvsp[-5].CastOpVal, yyvsp[-3].ConstVal.C, SrcSign, DstTy, DstSign));
4779 yyval.ConstVal.S.copy(DstSign);
4780 delete yyvsp[-1].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004781 ;}
4782 break;
4783
4784 case 164:
David Greene9145dd22007-08-01 03:59:32 +00004785#line 2566 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004786 {
David Greene9145dd22007-08-01 03:59:32 +00004787 const Type *Ty = yyvsp[-2].ConstVal.C->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004788 if (!isa<PointerType>(Ty))
4789 error("GetElementPtr requires a pointer operand");
4790
4791 std::vector<Constant*> CIndices;
David Greene9145dd22007-08-01 03:59:32 +00004792 upgradeGEPCEIndices(yyvsp[-2].ConstVal.C->getType(), yyvsp[-1].ValueList, CIndices);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004793
David Greene9145dd22007-08-01 03:59:32 +00004794 delete yyvsp[-1].ValueList;
4795 yyval.ConstVal.C = ConstantExpr::getGetElementPtr(yyvsp[-2].ConstVal.C, &CIndices[0], CIndices.size());
4796 yyval.ConstVal.S.copy(getElementSign(yyvsp[-2].ConstVal, CIndices));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004797 ;}
4798 break;
4799
4800 case 165:
David Greene9145dd22007-08-01 03:59:32 +00004801#line 2578 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004802 {
David Greene9145dd22007-08-01 03:59:32 +00004803 if (!yyvsp[-5].ConstVal.C->getType()->isInteger() ||
4804 cast<IntegerType>(yyvsp[-5].ConstVal.C->getType())->getBitWidth() != 1)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004805 error("Select condition must be bool type");
David Greene9145dd22007-08-01 03:59:32 +00004806 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004807 error("Select operand types must match");
David Greene9145dd22007-08-01 03:59:32 +00004808 yyval.ConstVal.C = ConstantExpr::getSelect(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4809 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004810 ;}
4811 break;
4812
4813 case 166:
David Greene9145dd22007-08-01 03:59:32 +00004814#line 2587 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004815 {
David Greene9145dd22007-08-01 03:59:32 +00004816 const Type *Ty = yyvsp[-3].ConstVal.C->getType();
4817 if (Ty != yyvsp[-1].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004818 error("Binary operator types must match");
4819 // First, make sure we're dealing with the right opcode by upgrading from
4820 // obsolete versions.
David Greene9145dd22007-08-01 03:59:32 +00004821 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004822
4823 // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs.
4824 // To retain backward compatibility with these early compilers, we emit a
4825 // cast to the appropriate integer type automatically if we are in the
4826 // broken case. See PR424 for more information.
4827 if (!isa<PointerType>(Ty)) {
David Greene9145dd22007-08-01 03:59:32 +00004828 yyval.ConstVal.C = ConstantExpr::get(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004829 } else {
4830 const Type *IntPtrTy = 0;
4831 switch (CurModule.CurrentModule->getPointerSize()) {
4832 case Module::Pointer32: IntPtrTy = Type::Int32Ty; break;
4833 case Module::Pointer64: IntPtrTy = Type::Int64Ty; break;
4834 default: error("invalid pointer binary constant expr");
4835 }
David Greene9145dd22007-08-01 03:59:32 +00004836 yyval.ConstVal.C = ConstantExpr::get(Opcode,
4837 ConstantExpr::getCast(Instruction::PtrToInt, yyvsp[-3].ConstVal.C, IntPtrTy),
4838 ConstantExpr::getCast(Instruction::PtrToInt, yyvsp[-1].ConstVal.C, IntPtrTy));
4839 yyval.ConstVal.C = ConstantExpr::getCast(Instruction::IntToPtr, yyval.ConstVal.C, Ty);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004840 }
David Greene9145dd22007-08-01 03:59:32 +00004841 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004842 ;}
4843 break;
4844
4845 case 167:
David Greene9145dd22007-08-01 03:59:32 +00004846#line 2615 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004847 {
David Greene9145dd22007-08-01 03:59:32 +00004848 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
4849 if (Ty != yyvsp[-1].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004850 error("Logical operator types must match");
4851 if (!Ty->isInteger()) {
4852 if (!isa<VectorType>(Ty) ||
4853 !cast<VectorType>(Ty)->getElementType()->isInteger())
4854 error("Logical operator requires integer operands");
4855 }
David Greene9145dd22007-08-01 03:59:32 +00004856 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S);
4857 yyval.ConstVal.C = ConstantExpr::get(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4858 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004859 ;}
4860 break;
4861
4862 case 168:
David Greene9145dd22007-08-01 03:59:32 +00004863#line 2628 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004864 {
David Greene9145dd22007-08-01 03:59:32 +00004865 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
4866 if (Ty != yyvsp[-1].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004867 error("setcc operand types must match");
4868 unsigned short pred;
David Greene9145dd22007-08-01 03:59:32 +00004869 Instruction::OtherOps Opcode = getCompareOp(yyvsp[-5].BinaryOpVal, pred, Ty, yyvsp[-3].ConstVal.S);
4870 yyval.ConstVal.C = ConstantExpr::getCompare(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4871 yyval.ConstVal.S.makeUnsigned();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004872 ;}
4873 break;
4874
4875 case 169:
David Greene9145dd22007-08-01 03:59:32 +00004876#line 2637 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004877 {
David Greene9145dd22007-08-01 03:59:32 +00004878 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004879 error("icmp operand types must match");
David Greene9145dd22007-08-01 03:59:32 +00004880 yyval.ConstVal.C = ConstantExpr::getCompare(yyvsp[-5].IPred, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4881 yyval.ConstVal.S.makeUnsigned();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004882 ;}
4883 break;
4884
4885 case 170:
David Greene9145dd22007-08-01 03:59:32 +00004886#line 2643 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004887 {
David Greene9145dd22007-08-01 03:59:32 +00004888 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004889 error("fcmp operand types must match");
David Greene9145dd22007-08-01 03:59:32 +00004890 yyval.ConstVal.C = ConstantExpr::getCompare(yyvsp[-5].FPred, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4891 yyval.ConstVal.S.makeUnsigned();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004892 ;}
4893 break;
4894
4895 case 171:
David Greene9145dd22007-08-01 03:59:32 +00004896#line 2649 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004897 {
David Greene9145dd22007-08-01 03:59:32 +00004898 if (!yyvsp[-1].ConstVal.C->getType()->isInteger() ||
4899 cast<IntegerType>(yyvsp[-1].ConstVal.C->getType())->getBitWidth() != 8)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004900 error("Shift count for shift constant must be unsigned byte");
David Greene9145dd22007-08-01 03:59:32 +00004901 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
4902 if (!yyvsp[-3].ConstVal.C->getType()->isInteger())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004903 error("Shift constant expression requires integer operand");
David Greene9145dd22007-08-01 03:59:32 +00004904 Constant *ShiftAmt = ConstantExpr::getZExt(yyvsp[-1].ConstVal.C, Ty);
4905 yyval.ConstVal.C = ConstantExpr::get(getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S), yyvsp[-3].ConstVal.C, ShiftAmt);
4906 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004907 ;}
4908 break;
4909
4910 case 172:
David Greene9145dd22007-08-01 03:59:32 +00004911#line 2660 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004912 {
David Greene9145dd22007-08-01 03:59:32 +00004913 if (!ExtractElementInst::isValidOperands(yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004914 error("Invalid extractelement operands");
David Greene9145dd22007-08-01 03:59:32 +00004915 yyval.ConstVal.C = ConstantExpr::getExtractElement(yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4916 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S.get(0));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004917 ;}
4918 break;
4919
4920 case 173:
David Greene9145dd22007-08-01 03:59:32 +00004921#line 2666 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004922 {
David Greene9145dd22007-08-01 03:59:32 +00004923 if (!InsertElementInst::isValidOperands(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004924 error("Invalid insertelement operands");
David Greene9145dd22007-08-01 03:59:32 +00004925 yyval.ConstVal.C = ConstantExpr::getInsertElement(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4926 yyval.ConstVal.S.copy(yyvsp[-5].ConstVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004927 ;}
4928 break;
4929
4930 case 174:
David Greene9145dd22007-08-01 03:59:32 +00004931#line 2672 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004932 {
David Greene9145dd22007-08-01 03:59:32 +00004933 if (!ShuffleVectorInst::isValidOperands(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004934 error("Invalid shufflevector operands");
David Greene9145dd22007-08-01 03:59:32 +00004935 yyval.ConstVal.C = ConstantExpr::getShuffleVector(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4936 yyval.ConstVal.S.copy(yyvsp[-5].ConstVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004937 ;}
4938 break;
4939
4940 case 175:
David Greene9145dd22007-08-01 03:59:32 +00004941#line 2683 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4942 { (yyval.ConstVector = yyvsp[-2].ConstVector)->push_back(yyvsp[0].ConstVal); ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004943 break;
4944
4945 case 176:
David Greene9145dd22007-08-01 03:59:32 +00004946#line 2684 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004947 {
David Greene9145dd22007-08-01 03:59:32 +00004948 yyval.ConstVector = new std::vector<ConstInfo>();
4949 yyval.ConstVector->push_back(yyvsp[0].ConstVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004950 ;}
4951 break;
4952
4953 case 177:
David Greene9145dd22007-08-01 03:59:32 +00004954#line 2693 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4955 { yyval.BoolVal = false; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004956 break;
4957
4958 case 178:
David Greene9145dd22007-08-01 03:59:32 +00004959#line 2694 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4960 { yyval.BoolVal = true; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004961 break;
4962
4963 case 179:
David Greene9145dd22007-08-01 03:59:32 +00004964#line 2706 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004965 {
David Greene9145dd22007-08-01 03:59:32 +00004966 yyval.ModuleVal = ParserResult = yyvsp[0].ModuleVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004967 CurModule.ModuleDone();
4968 ;}
4969 break;
4970
4971 case 180:
David Greene9145dd22007-08-01 03:59:32 +00004972#line 2715 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4973 { yyval.ModuleVal = yyvsp[-1].ModuleVal; CurFun.FunctionDone(); ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004974 break;
4975
4976 case 181:
David Greene9145dd22007-08-01 03:59:32 +00004977#line 2716 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4978 { yyval.ModuleVal = yyvsp[-1].ModuleVal; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004979 break;
4980
4981 case 182:
David Greene9145dd22007-08-01 03:59:32 +00004982#line 2717 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4983 { yyval.ModuleVal = yyvsp[-3].ModuleVal; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004984 break;
4985
4986 case 183:
David Greene9145dd22007-08-01 03:59:32 +00004987#line 2718 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4988 { yyval.ModuleVal = yyvsp[-1].ModuleVal; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004989 break;
4990
4991 case 184:
David Greene9145dd22007-08-01 03:59:32 +00004992#line 2719 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004993 {
David Greene9145dd22007-08-01 03:59:32 +00004994 yyval.ModuleVal = CurModule.CurrentModule;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004995 // Emit an error if there are any unresolved types left.
4996 if (!CurModule.LateResolveTypes.empty()) {
4997 const ValID &DID = CurModule.LateResolveTypes.begin()->first;
4998 if (DID.Type == ValID::NameVal) {
4999 error("Reference to an undefined type: '"+DID.getName() + "'");
5000 } else {
5001 error("Reference to an undefined type: #" + itostr(DID.Num));
5002 }
5003 }
5004 ;}
5005 break;
5006
5007 case 185:
David Greene9145dd22007-08-01 03:59:32 +00005008#line 2735 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005009 {
5010 // Eagerly resolve types. This is not an optimization, this is a
5011 // requirement that is due to the fact that we could have this:
5012 //
5013 // %list = type { %list * }
5014 // %list = type { %list * } ; repeated type decl
5015 //
5016 // If types are not resolved eagerly, then the two types will not be
5017 // determined to be the same type!
5018 //
David Greene9145dd22007-08-01 03:59:32 +00005019 ResolveTypeTo(yyvsp[-2].StrVal, yyvsp[0].TypeVal.PAT->get(), yyvsp[0].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005020
David Greene9145dd22007-08-01 03:59:32 +00005021 if (!setTypeName(yyvsp[0].TypeVal, yyvsp[-2].StrVal) && !yyvsp[-2].StrVal) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005022 // If this is a numbered type that is not a redefinition, add it to the
5023 // slot table.
David Greene9145dd22007-08-01 03:59:32 +00005024 CurModule.Types.push_back(yyvsp[0].TypeVal.PAT->get());
5025 CurModule.TypeSigns.push_back(yyvsp[0].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005026 }
David Greene9145dd22007-08-01 03:59:32 +00005027 delete yyvsp[0].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005028 ;}
5029 break;
5030
5031 case 186:
David Greene9145dd22007-08-01 03:59:32 +00005032#line 2755 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005033 { // Function prototypes can be in const pool
5034 ;}
5035 break;
5036
5037 case 187:
David Greene9145dd22007-08-01 03:59:32 +00005038#line 2757 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005039 { // Asm blocks can be in the const pool
5040 ;}
5041 break;
5042
5043 case 188:
David Greene9145dd22007-08-01 03:59:32 +00005044#line 2759 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005045 {
David Greene9145dd22007-08-01 03:59:32 +00005046 if (yyvsp[0].ConstVal.C == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005047 error("Global value initializer is not a constant");
David Greene9145dd22007-08-01 03:59:32 +00005048 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, yyvsp[-2].Linkage, yyvsp[-1].BoolVal, yyvsp[0].ConstVal.C->getType(), yyvsp[0].ConstVal.C, yyvsp[0].ConstVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005049 ;}
5050 break;
5051
5052 case 189:
David Greene9145dd22007-08-01 03:59:32 +00005053#line 2763 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005054 {
5055 CurGV = 0;
5056 ;}
5057 break;
5058
5059 case 190:
David Greene9145dd22007-08-01 03:59:32 +00005060#line 2766 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005061 {
David Greene9145dd22007-08-01 03:59:32 +00005062 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
5063 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::ExternalLinkage, yyvsp[-1].BoolVal, Ty, 0,
5064 yyvsp[0].TypeVal.S);
5065 delete yyvsp[0].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005066 ;}
5067 break;
5068
5069 case 191:
David Greene9145dd22007-08-01 03:59:32 +00005070#line 2771 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005071 {
5072 CurGV = 0;
5073 ;}
5074 break;
5075
5076 case 192:
David Greene9145dd22007-08-01 03:59:32 +00005077#line 2774 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005078 {
David Greene9145dd22007-08-01 03:59:32 +00005079 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
5080 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::DLLImportLinkage, yyvsp[-1].BoolVal, Ty, 0,
5081 yyvsp[0].TypeVal.S);
5082 delete yyvsp[0].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005083 ;}
5084 break;
5085
5086 case 193:
David Greene9145dd22007-08-01 03:59:32 +00005087#line 2779 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005088 {
5089 CurGV = 0;
5090 ;}
5091 break;
5092
5093 case 194:
David Greene9145dd22007-08-01 03:59:32 +00005094#line 2782 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005095 {
David Greene9145dd22007-08-01 03:59:32 +00005096 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005097 CurGV =
David Greene9145dd22007-08-01 03:59:32 +00005098 ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::ExternalWeakLinkage, yyvsp[-1].BoolVal, Ty, 0,
5099 yyvsp[0].TypeVal.S);
5100 delete yyvsp[0].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005101 ;}
5102 break;
5103
5104 case 195:
David Greene9145dd22007-08-01 03:59:32 +00005105#line 2788 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005106 {
5107 CurGV = 0;
5108 ;}
5109 break;
5110
5111 case 196:
David Greene9145dd22007-08-01 03:59:32 +00005112#line 2791 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005113 {
5114 ;}
5115 break;
5116
5117 case 197:
David Greene9145dd22007-08-01 03:59:32 +00005118#line 2793 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005119 {
5120 ;}
5121 break;
5122
5123 case 198:
David Greene9145dd22007-08-01 03:59:32 +00005124#line 2795 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005125 {
5126 ;}
5127 break;
5128
5129 case 199:
David Greene9145dd22007-08-01 03:59:32 +00005130#line 2800 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005131 {
5132 const std::string &AsmSoFar = CurModule.CurrentModule->getModuleInlineAsm();
David Greene9145dd22007-08-01 03:59:32 +00005133 char *EndStr = UnEscapeLexed(yyvsp[0].StrVal, true);
5134 std::string NewAsm(yyvsp[0].StrVal, EndStr);
5135 free(yyvsp[0].StrVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005136
5137 if (AsmSoFar.empty())
5138 CurModule.CurrentModule->setModuleInlineAsm(NewAsm);
5139 else
5140 CurModule.CurrentModule->setModuleInlineAsm(AsmSoFar+"\n"+NewAsm);
5141 ;}
5142 break;
5143
5144 case 200:
David Greene9145dd22007-08-01 03:59:32 +00005145#line 2814 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5146 { yyval.Endianness = Module::BigEndian; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005147 break;
5148
5149 case 201:
David Greene9145dd22007-08-01 03:59:32 +00005150#line 2815 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5151 { yyval.Endianness = Module::LittleEndian; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005152 break;
5153
5154 case 202:
David Greene9145dd22007-08-01 03:59:32 +00005155#line 2819 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005156 {
David Greene9145dd22007-08-01 03:59:32 +00005157 CurModule.setEndianness(yyvsp[0].Endianness);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005158 ;}
5159 break;
5160
5161 case 203:
David Greene9145dd22007-08-01 03:59:32 +00005162#line 2822 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005163 {
David Greene9145dd22007-08-01 03:59:32 +00005164 if (yyvsp[0].UInt64Val == 32)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005165 CurModule.setPointerSize(Module::Pointer32);
David Greene9145dd22007-08-01 03:59:32 +00005166 else if (yyvsp[0].UInt64Val == 64)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005167 CurModule.setPointerSize(Module::Pointer64);
5168 else
David Greene9145dd22007-08-01 03:59:32 +00005169 error("Invalid pointer size: '" + utostr(yyvsp[0].UInt64Val) + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005170 ;}
5171 break;
5172
5173 case 204:
David Greene9145dd22007-08-01 03:59:32 +00005174#line 2830 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005175 {
David Greene9145dd22007-08-01 03:59:32 +00005176 CurModule.CurrentModule->setTargetTriple(yyvsp[0].StrVal);
5177 free(yyvsp[0].StrVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005178 ;}
5179 break;
5180
5181 case 205:
David Greene9145dd22007-08-01 03:59:32 +00005182#line 2834 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005183 {
David Greene9145dd22007-08-01 03:59:32 +00005184 CurModule.CurrentModule->setDataLayout(yyvsp[0].StrVal);
5185 free(yyvsp[0].StrVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005186 ;}
5187 break;
5188
5189 case 207:
David Greene9145dd22007-08-01 03:59:32 +00005190#line 2845 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005191 {
David Greene9145dd22007-08-01 03:59:32 +00005192 CurModule.CurrentModule->addLibrary(yyvsp[0].StrVal);
5193 free(yyvsp[0].StrVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005194 ;}
5195 break;
5196
5197 case 208:
David Greene9145dd22007-08-01 03:59:32 +00005198#line 2849 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005199 {
David Greene9145dd22007-08-01 03:59:32 +00005200 CurModule.CurrentModule->addLibrary(yyvsp[0].StrVal);
5201 free(yyvsp[0].StrVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005202 ;}
5203 break;
5204
5205 case 209:
David Greene9145dd22007-08-01 03:59:32 +00005206#line 2853 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005207 { ;}
5208 break;
5209
5210 case 213:
David Greene9145dd22007-08-01 03:59:32 +00005211#line 2866 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5212 { yyval.StrVal = 0; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005213 break;
5214
5215 case 214:
David Greene9145dd22007-08-01 03:59:32 +00005216#line 2870 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005217 {
David Greene9145dd22007-08-01 03:59:32 +00005218 if (yyvsp[-1].TypeVal.PAT->get() == Type::VoidTy)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005219 error("void typed arguments are invalid");
David Greene9145dd22007-08-01 03:59:32 +00005220 yyval.ArgVal = new std::pair<PATypeInfo, char*>(yyvsp[-1].TypeVal, yyvsp[0].StrVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005221 ;}
5222 break;
5223
5224 case 215:
David Greene9145dd22007-08-01 03:59:32 +00005225#line 2878 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005226 {
David Greene9145dd22007-08-01 03:59:32 +00005227 yyval.ArgList = yyvsp[-2].ArgList;
5228 yyval.ArgList->push_back(*yyvsp[0].ArgVal);
5229 delete yyvsp[0].ArgVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005230 ;}
5231 break;
5232
5233 case 216:
David Greene9145dd22007-08-01 03:59:32 +00005234#line 2883 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005235 {
David Greene9145dd22007-08-01 03:59:32 +00005236 yyval.ArgList = new std::vector<std::pair<PATypeInfo,char*> >();
5237 yyval.ArgList->push_back(*yyvsp[0].ArgVal);
5238 delete yyvsp[0].ArgVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005239 ;}
5240 break;
5241
5242 case 217:
David Greene9145dd22007-08-01 03:59:32 +00005243#line 2891 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5244 { yyval.ArgList = yyvsp[0].ArgList; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005245 break;
5246
5247 case 218:
David Greene9145dd22007-08-01 03:59:32 +00005248#line 2892 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005249 {
David Greene9145dd22007-08-01 03:59:32 +00005250 yyval.ArgList = yyvsp[-2].ArgList;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005251 PATypeInfo VoidTI;
5252 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
5253 VoidTI.S.makeSignless();
David Greene9145dd22007-08-01 03:59:32 +00005254 yyval.ArgList->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005255 ;}
5256 break;
5257
5258 case 219:
David Greene9145dd22007-08-01 03:59:32 +00005259#line 2899 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005260 {
David Greene9145dd22007-08-01 03:59:32 +00005261 yyval.ArgList = new std::vector<std::pair<PATypeInfo,char*> >();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005262 PATypeInfo VoidTI;
5263 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
5264 VoidTI.S.makeSignless();
David Greene9145dd22007-08-01 03:59:32 +00005265 yyval.ArgList->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005266 ;}
5267 break;
5268
5269 case 220:
David Greene9145dd22007-08-01 03:59:32 +00005270#line 2906 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5271 { yyval.ArgList = 0; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005272 break;
5273
5274 case 221:
David Greene9145dd22007-08-01 03:59:32 +00005275#line 2910 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005276 {
David Greene9145dd22007-08-01 03:59:32 +00005277 UnEscapeLexed(yyvsp[-5].StrVal);
5278 std::string FunctionName(yyvsp[-5].StrVal);
5279 free(yyvsp[-5].StrVal); // Free strdup'd memory!
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005280
David Greene9145dd22007-08-01 03:59:32 +00005281 const Type* RetTy = yyvsp[-6].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005282
5283 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
5284 error("LLVM functions cannot return aggregate types");
5285
5286 Signedness FTySign;
David Greene9145dd22007-08-01 03:59:32 +00005287 FTySign.makeComposite(yyvsp[-6].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005288 std::vector<const Type*> ParamTyList;
5289
5290 // In LLVM 2.0 the signatures of three varargs intrinsics changed to take
5291 // i8*. We check here for those names and override the parameter list
5292 // types to ensure the prototype is correct.
5293 if (FunctionName == "llvm.va_start" || FunctionName == "llvm.va_end") {
5294 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
5295 } else if (FunctionName == "llvm.va_copy") {
5296 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
5297 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
David Greene9145dd22007-08-01 03:59:32 +00005298 } else if (yyvsp[-3].ArgList) { // If there are arguments...
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005299 for (std::vector<std::pair<PATypeInfo,char*> >::iterator
David Greene9145dd22007-08-01 03:59:32 +00005300 I = yyvsp[-3].ArgList->begin(), E = yyvsp[-3].ArgList->end(); I != E; ++I) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005301 const Type *Ty = I->first.PAT->get();
5302 ParamTyList.push_back(Ty);
5303 FTySign.add(I->first.S);
5304 }
5305 }
5306
5307 bool isVarArg = ParamTyList.size() && ParamTyList.back() == Type::VoidTy;
5308 if (isVarArg)
5309 ParamTyList.pop_back();
5310
5311 // Convert the CSRet calling convention into the corresponding parameter
5312 // attribute.
5313 ParamAttrsList *PAL = 0;
David Greene9145dd22007-08-01 03:59:32 +00005314 if (yyvsp[-7].UIntVal == OldCallingConv::CSRet) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005315 ParamAttrsVector Attrs;
5316 ParamAttrsWithIndex PAWI;
5317 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
5318 Attrs.push_back(PAWI);
5319 PAL = ParamAttrsList::get(Attrs);
5320 }
5321
5322 const FunctionType *FT =
5323 FunctionType::get(RetTy, ParamTyList, isVarArg, PAL);
5324 const PointerType *PFT = PointerType::get(FT);
David Greene9145dd22007-08-01 03:59:32 +00005325 delete yyvsp[-6].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005326
5327 ValID ID;
5328 if (!FunctionName.empty()) {
5329 ID = ValID::create((char*)FunctionName.c_str());
5330 } else {
5331 ID = ValID::create((int)CurModule.Values[PFT].size());
5332 }
5333 ID.S.makeComposite(FTySign);
5334
5335 Function *Fn = 0;
5336 Module* M = CurModule.CurrentModule;
5337
5338 // See if this function was forward referenced. If so, recycle the object.
5339 if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, ID)) {
5340 // Move the function to the end of the list, from whereever it was
5341 // previously inserted.
5342 Fn = cast<Function>(FWRef);
5343 M->getFunctionList().remove(Fn);
5344 M->getFunctionList().push_back(Fn);
5345 } else if (!FunctionName.empty()) {
5346 GlobalValue *Conflict = M->getFunction(FunctionName);
5347 if (!Conflict)
5348 Conflict = M->getNamedGlobal(FunctionName);
5349 if (Conflict && PFT == Conflict->getType()) {
5350 if (!CurFun.isDeclare && !Conflict->isDeclaration()) {
5351 // We have two function definitions that conflict, same type, same
5352 // name. We should really check to make sure that this is the result
5353 // of integer type planes collapsing and generate an error if it is
5354 // not, but we'll just rename on the assumption that it is. However,
5355 // let's do it intelligently and rename the internal linkage one
5356 // if there is one.
5357 std::string NewName(makeNameUnique(FunctionName));
5358 if (Conflict->hasInternalLinkage()) {
5359 Conflict->setName(NewName);
5360 RenameMapKey Key =
5361 makeRenameMapKey(FunctionName, Conflict->getType(), ID.S);
5362 CurModule.RenameMap[Key] = NewName;
5363 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5364 InsertValue(Fn, CurModule.Values);
5365 } else {
5366 Fn = new Function(FT, CurFun.Linkage, NewName, M);
5367 InsertValue(Fn, CurModule.Values);
5368 RenameMapKey Key =
5369 makeRenameMapKey(FunctionName, PFT, ID.S);
5370 CurModule.RenameMap[Key] = NewName;
5371 }
5372 } else {
5373 // If they are not both definitions, then just use the function we
5374 // found since the types are the same.
5375 Fn = cast<Function>(Conflict);
5376
5377 // Make sure to strip off any argument names so we can't get
5378 // conflicts.
5379 if (Fn->isDeclaration())
5380 for (Function::arg_iterator AI = Fn->arg_begin(),
5381 AE = Fn->arg_end(); AI != AE; ++AI)
5382 AI->setName("");
5383 }
5384 } else if (Conflict) {
5385 // We have two globals with the same name and different types.
5386 // Previously, this was permitted because the symbol table had
5387 // "type planes" and names only needed to be distinct within a
5388 // type plane. After PR411 was fixed, this is no loner the case.
5389 // To resolve this we must rename one of the two.
5390 if (Conflict->hasInternalLinkage()) {
5391 // We can safely rename the Conflict.
5392 RenameMapKey Key =
5393 makeRenameMapKey(Conflict->getName(), Conflict->getType(),
5394 CurModule.NamedValueSigns[Conflict->getName()]);
5395 Conflict->setName(makeNameUnique(Conflict->getName()));
5396 CurModule.RenameMap[Key] = Conflict->getName();
5397 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5398 InsertValue(Fn, CurModule.Values);
5399 } else {
5400 // We can't quietly rename either of these things, but we must
5401 // rename one of them. Only if the function's linkage is internal can
5402 // we forgo a warning message about the renamed function.
5403 std::string NewName = makeNameUnique(FunctionName);
5404 if (CurFun.Linkage != GlobalValue::InternalLinkage) {
5405 warning("Renaming function '" + FunctionName + "' as '" + NewName +
5406 "' may cause linkage errors");
5407 }
5408 // Elect to rename the thing we're now defining.
5409 Fn = new Function(FT, CurFun.Linkage, NewName, M);
5410 InsertValue(Fn, CurModule.Values);
5411 RenameMapKey Key = makeRenameMapKey(FunctionName, PFT, ID.S);
5412 CurModule.RenameMap[Key] = NewName;
5413 }
5414 } else {
5415 // There's no conflict, just define the function
5416 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5417 InsertValue(Fn, CurModule.Values);
5418 }
5419 } else {
5420 // There's no conflict, just define the function
5421 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5422 InsertValue(Fn, CurModule.Values);
5423 }
5424
5425
5426 CurFun.FunctionStart(Fn);
5427
5428 if (CurFun.isDeclare) {
5429 // If we have declaration, always overwrite linkage. This will allow us
5430 // to correctly handle cases, when pointer to function is passed as
5431 // argument to another function.
5432 Fn->setLinkage(CurFun.Linkage);
5433 }
David Greene9145dd22007-08-01 03:59:32 +00005434 Fn->setCallingConv(upgradeCallingConv(yyvsp[-7].UIntVal));
5435 Fn->setAlignment(yyvsp[0].UIntVal);
5436 if (yyvsp[-1].StrVal) {
5437 Fn->setSection(yyvsp[-1].StrVal);
5438 free(yyvsp[-1].StrVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005439 }
5440
5441 // Add all of the arguments we parsed to the function...
David Greene9145dd22007-08-01 03:59:32 +00005442 if (yyvsp[-3].ArgList) { // Is null if empty...
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005443 if (isVarArg) { // Nuke the last entry
David Greene9145dd22007-08-01 03:59:32 +00005444 assert(yyvsp[-3].ArgList->back().first.PAT->get() == Type::VoidTy &&
5445 yyvsp[-3].ArgList->back().second == 0 && "Not a varargs marker");
5446 delete yyvsp[-3].ArgList->back().first.PAT;
5447 yyvsp[-3].ArgList->pop_back(); // Delete the last entry
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005448 }
5449 Function::arg_iterator ArgIt = Fn->arg_begin();
5450 Function::arg_iterator ArgEnd = Fn->arg_end();
David Greene9145dd22007-08-01 03:59:32 +00005451 std::vector<std::pair<PATypeInfo,char*> >::iterator I = yyvsp[-3].ArgList->begin();
5452 std::vector<std::pair<PATypeInfo,char*> >::iterator E = yyvsp[-3].ArgList->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005453 for ( ; I != E && ArgIt != ArgEnd; ++I, ++ArgIt) {
5454 delete I->first.PAT; // Delete the typeholder...
5455 ValueInfo VI; VI.V = ArgIt; VI.S.copy(I->first.S);
5456 setValueName(VI, I->second); // Insert arg into symtab...
5457 InsertValue(ArgIt);
5458 }
David Greene9145dd22007-08-01 03:59:32 +00005459 delete yyvsp[-3].ArgList; // We're now done with the argument list
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005460 }
5461 lastCallingConv = OldCallingConv::C;
5462 ;}
5463 break;
5464
5465 case 224:
David Greene9145dd22007-08-01 03:59:32 +00005466#line 3104 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5467 { CurFun.Linkage = yyvsp[0].Linkage; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005468 break;
5469
5470 case 225:
David Greene9145dd22007-08-01 03:59:32 +00005471#line 3104 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005472 {
David Greene9145dd22007-08-01 03:59:32 +00005473 yyval.FunctionVal = CurFun.CurrentFunction;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005474
5475 // Make sure that we keep track of the linkage type even if there was a
5476 // previous "declare".
David Greene9145dd22007-08-01 03:59:32 +00005477 yyval.FunctionVal->setLinkage(yyvsp[-3].Linkage);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005478 ;}
5479 break;
5480
5481 case 228:
David Greene9145dd22007-08-01 03:59:32 +00005482#line 3118 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005483 {
David Greene9145dd22007-08-01 03:59:32 +00005484 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005485 ;}
5486 break;
5487
5488 case 229:
David Greene9145dd22007-08-01 03:59:32 +00005489#line 3123 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5490 { yyval.Linkage = GlobalValue::ExternalLinkage; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005491 break;
5492
5493 case 230:
David Greene9145dd22007-08-01 03:59:32 +00005494#line 3124 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5495 { yyval.Linkage = GlobalValue::DLLImportLinkage; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005496 break;
5497
5498 case 231:
David Greene9145dd22007-08-01 03:59:32 +00005499#line 3125 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5500 { yyval.Linkage = GlobalValue::ExternalWeakLinkage; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005501 break;
5502
5503 case 232:
David Greene9145dd22007-08-01 03:59:32 +00005504#line 3129 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005505 { CurFun.isDeclare = true; ;}
5506 break;
5507
5508 case 233:
David Greene9145dd22007-08-01 03:59:32 +00005509#line 3130 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5510 { CurFun.Linkage = yyvsp[0].Linkage; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005511 break;
5512
5513 case 234:
David Greene9145dd22007-08-01 03:59:32 +00005514#line 3130 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005515 {
David Greene9145dd22007-08-01 03:59:32 +00005516 yyval.FunctionVal = CurFun.CurrentFunction;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005517 CurFun.FunctionDone();
5518
5519 ;}
5520 break;
5521
5522 case 235:
David Greene9145dd22007-08-01 03:59:32 +00005523#line 3142 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5524 { yyval.BoolVal = false; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005525 break;
5526
5527 case 236:
David Greene9145dd22007-08-01 03:59:32 +00005528#line 3143 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5529 { yyval.BoolVal = true; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005530 break;
5531
5532 case 237:
David Greene9145dd22007-08-01 03:59:32 +00005533#line 3148 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5534 { yyval.ValIDVal = ValID::create(yyvsp[0].SInt64Val); ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005535 break;
5536
5537 case 238:
David Greene9145dd22007-08-01 03:59:32 +00005538#line 3149 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5539 { yyval.ValIDVal = ValID::create(yyvsp[0].UInt64Val); ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005540 break;
5541
5542 case 239:
David Greene9145dd22007-08-01 03:59:32 +00005543#line 3150 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5544 { yyval.ValIDVal = ValID::create(yyvsp[0].FPVal); ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005545 break;
5546
5547 case 240:
David Greene9145dd22007-08-01 03:59:32 +00005548#line 3151 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005549 {
David Greene9145dd22007-08-01 03:59:32 +00005550 yyval.ValIDVal = ValID::create(ConstantInt::get(Type::Int1Ty, true));
5551 yyval.ValIDVal.S.makeUnsigned();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005552 ;}
5553 break;
5554
5555 case 241:
David Greene9145dd22007-08-01 03:59:32 +00005556#line 3155 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005557 {
David Greene9145dd22007-08-01 03:59:32 +00005558 yyval.ValIDVal = ValID::create(ConstantInt::get(Type::Int1Ty, false));
5559 yyval.ValIDVal.S.makeUnsigned();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005560 ;}
5561 break;
5562
5563 case 242:
David Greene9145dd22007-08-01 03:59:32 +00005564#line 3159 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5565 { yyval.ValIDVal = ValID::createNull(); ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005566 break;
5567
5568 case 243:
David Greene9145dd22007-08-01 03:59:32 +00005569#line 3160 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5570 { yyval.ValIDVal = ValID::createUndef(); ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005571 break;
5572
5573 case 244:
David Greene9145dd22007-08-01 03:59:32 +00005574#line 3161 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5575 { yyval.ValIDVal = ValID::createZeroInit(); ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005576 break;
5577
5578 case 245:
David Greene9145dd22007-08-01 03:59:32 +00005579#line 3162 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005580 { // Nonempty unsized packed vector
David Greene9145dd22007-08-01 03:59:32 +00005581 const Type *ETy = (*yyvsp[-1].ConstVector)[0].C->getType();
5582 int NumElements = yyvsp[-1].ConstVector->size();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005583 VectorType* pt = VectorType::get(ETy, NumElements);
David Greene9145dd22007-08-01 03:59:32 +00005584 yyval.ValIDVal.S.makeComposite((*yyvsp[-1].ConstVector)[0].S);
5585 PATypeHolder* PTy = new PATypeHolder(HandleUpRefs(pt, yyval.ValIDVal.S));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005586
5587 // Verify all elements are correct type!
5588 std::vector<Constant*> Elems;
David Greene9145dd22007-08-01 03:59:32 +00005589 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
5590 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005591 const Type *CTy = C->getType();
5592 if (ETy != CTy)
5593 error("Element #" + utostr(i) + " is not of type '" +
5594 ETy->getDescription() +"' as required!\nIt is of type '" +
5595 CTy->getDescription() + "'");
5596 Elems.push_back(C);
5597 }
David Greene9145dd22007-08-01 03:59:32 +00005598 yyval.ValIDVal = ValID::create(ConstantVector::get(pt, Elems));
5599 delete PTy; delete yyvsp[-1].ConstVector;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005600 ;}
5601 break;
5602
5603 case 246:
David Greene9145dd22007-08-01 03:59:32 +00005604#line 3183 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005605 {
David Greene9145dd22007-08-01 03:59:32 +00005606 yyval.ValIDVal = ValID::create(yyvsp[0].ConstVal.C);
5607 yyval.ValIDVal.S.copy(yyvsp[0].ConstVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005608 ;}
5609 break;
5610
5611 case 247:
David Greene9145dd22007-08-01 03:59:32 +00005612#line 3187 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005613 {
David Greene9145dd22007-08-01 03:59:32 +00005614 char *End = UnEscapeLexed(yyvsp[-2].StrVal, true);
5615 std::string AsmStr = std::string(yyvsp[-2].StrVal, End);
5616 End = UnEscapeLexed(yyvsp[0].StrVal, true);
5617 std::string Constraints = std::string(yyvsp[0].StrVal, End);
5618 yyval.ValIDVal = ValID::createInlineAsm(AsmStr, Constraints, yyvsp[-3].BoolVal);
5619 free(yyvsp[-2].StrVal);
5620 free(yyvsp[0].StrVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005621 ;}
5622 break;
5623
5624 case 248:
David Greene9145dd22007-08-01 03:59:32 +00005625#line 3201 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5626 { yyval.ValIDVal = ValID::create(yyvsp[0].SIntVal); yyval.ValIDVal.S.makeSignless(); ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005627 break;
5628
5629 case 249:
David Greene9145dd22007-08-01 03:59:32 +00005630#line 3202 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5631 { yyval.ValIDVal = ValID::create(yyvsp[0].StrVal); yyval.ValIDVal.S.makeSignless(); ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005632 break;
5633
5634 case 252:
David Greene9145dd22007-08-01 03:59:32 +00005635#line 3215 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005636 {
David Greene9145dd22007-08-01 03:59:32 +00005637 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
5638 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
5639 yyval.ValueVal.V = getVal(Ty, yyvsp[0].ValIDVal);
5640 yyval.ValueVal.S.copy(yyvsp[-1].TypeVal.S);
5641 delete yyvsp[-1].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005642 ;}
5643 break;
5644
5645 case 253:
David Greene9145dd22007-08-01 03:59:32 +00005646#line 3225 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005647 {
David Greene9145dd22007-08-01 03:59:32 +00005648 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005649 ;}
5650 break;
5651
5652 case 254:
David Greene9145dd22007-08-01 03:59:32 +00005653#line 3228 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005654 { // Do not allow functions with 0 basic blocks
David Greene9145dd22007-08-01 03:59:32 +00005655 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005656 ;}
5657 break;
5658
5659 case 255:
David Greene9145dd22007-08-01 03:59:32 +00005660#line 3237 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005661 {
David Greene9145dd22007-08-01 03:59:32 +00005662 ValueInfo VI; VI.V = yyvsp[0].TermInstVal.TI; VI.S.copy(yyvsp[0].TermInstVal.S);
5663 setValueName(VI, yyvsp[-1].StrVal);
5664 InsertValue(yyvsp[0].TermInstVal.TI);
5665 yyvsp[-2].BasicBlockVal->getInstList().push_back(yyvsp[0].TermInstVal.TI);
5666 InsertValue(yyvsp[-2].BasicBlockVal);
5667 yyval.BasicBlockVal = yyvsp[-2].BasicBlockVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005668 ;}
5669 break;
5670
5671 case 256:
David Greene9145dd22007-08-01 03:59:32 +00005672#line 3248 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005673 {
David Greene9145dd22007-08-01 03:59:32 +00005674 if (yyvsp[0].InstVal.I)
5675 yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].InstVal.I);
5676 yyval.BasicBlockVal = yyvsp[-1].BasicBlockVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005677 ;}
5678 break;
5679
5680 case 257:
David Greene9145dd22007-08-01 03:59:32 +00005681#line 3253 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005682 {
David Greene9145dd22007-08-01 03:59:32 +00005683 yyval.BasicBlockVal = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++),true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005684 // Make sure to move the basic block to the correct location in the
5685 // function, instead of leaving it inserted wherever it was first
5686 // referenced.
5687 Function::BasicBlockListType &BBL =
5688 CurFun.CurrentFunction->getBasicBlockList();
David Greene9145dd22007-08-01 03:59:32 +00005689 BBL.splice(BBL.end(), BBL, yyval.BasicBlockVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005690 ;}
5691 break;
5692
5693 case 258:
David Greene9145dd22007-08-01 03:59:32 +00005694#line 3262 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005695 {
David Greene9145dd22007-08-01 03:59:32 +00005696 yyval.BasicBlockVal = CurBB = getBBVal(ValID::create(yyvsp[0].StrVal), true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005697 // Make sure to move the basic block to the correct location in the
5698 // function, instead of leaving it inserted wherever it was first
5699 // referenced.
5700 Function::BasicBlockListType &BBL =
5701 CurFun.CurrentFunction->getBasicBlockList();
David Greene9145dd22007-08-01 03:59:32 +00005702 BBL.splice(BBL.end(), BBL, yyval.BasicBlockVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005703 ;}
5704 break;
5705
5706 case 261:
David Greene9145dd22007-08-01 03:59:32 +00005707#line 3276 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005708 { // Return with a result...
David Greene9145dd22007-08-01 03:59:32 +00005709 yyval.TermInstVal.TI = new ReturnInst(yyvsp[0].ValueVal.V);
5710 yyval.TermInstVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005711 ;}
5712 break;
5713
5714 case 262:
David Greene9145dd22007-08-01 03:59:32 +00005715#line 3280 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005716 { // Return with no result...
David Greene9145dd22007-08-01 03:59:32 +00005717 yyval.TermInstVal.TI = new ReturnInst();
5718 yyval.TermInstVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005719 ;}
5720 break;
5721
5722 case 263:
David Greene9145dd22007-08-01 03:59:32 +00005723#line 3284 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005724 { // Unconditional Branch...
David Greene9145dd22007-08-01 03:59:32 +00005725 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
5726 yyval.TermInstVal.TI = new BranchInst(tmpBB);
5727 yyval.TermInstVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005728 ;}
5729 break;
5730
5731 case 264:
David Greene9145dd22007-08-01 03:59:32 +00005732#line 3289 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005733 {
David Greene9145dd22007-08-01 03:59:32 +00005734 yyvsp[-3].ValIDVal.S.makeSignless();
5735 yyvsp[0].ValIDVal.S.makeSignless();
5736 BasicBlock* tmpBBA = getBBVal(yyvsp[-3].ValIDVal);
5737 BasicBlock* tmpBBB = getBBVal(yyvsp[0].ValIDVal);
5738 yyvsp[-6].ValIDVal.S.makeUnsigned();
5739 Value* tmpVal = getVal(Type::Int1Ty, yyvsp[-6].ValIDVal);
5740 yyval.TermInstVal.TI = new BranchInst(tmpBBA, tmpBBB, tmpVal);
5741 yyval.TermInstVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005742 ;}
5743 break;
5744
5745 case 265:
David Greene9145dd22007-08-01 03:59:32 +00005746#line 3299 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005747 {
David Greene9145dd22007-08-01 03:59:32 +00005748 yyvsp[-6].ValIDVal.S.copy(yyvsp[-7].PrimType.S);
5749 Value* tmpVal = getVal(yyvsp[-7].PrimType.T, yyvsp[-6].ValIDVal);
5750 yyvsp[-3].ValIDVal.S.makeSignless();
5751 BasicBlock* tmpBB = getBBVal(yyvsp[-3].ValIDVal);
5752 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, yyvsp[-1].JumpTable->size());
5753 yyval.TermInstVal.TI = S;
5754 yyval.TermInstVal.S.makeSignless();
5755 std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = yyvsp[-1].JumpTable->begin(),
5756 E = yyvsp[-1].JumpTable->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005757 for (; I != E; ++I) {
5758 if (ConstantInt *CI = dyn_cast<ConstantInt>(I->first))
5759 S->addCase(CI, I->second);
5760 else
5761 error("Switch case is constant, but not a simple integer");
5762 }
David Greene9145dd22007-08-01 03:59:32 +00005763 delete yyvsp[-1].JumpTable;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005764 ;}
5765 break;
5766
5767 case 266:
David Greene9145dd22007-08-01 03:59:32 +00005768#line 3317 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005769 {
David Greene9145dd22007-08-01 03:59:32 +00005770 yyvsp[-5].ValIDVal.S.copy(yyvsp[-6].PrimType.S);
5771 Value* tmpVal = getVal(yyvsp[-6].PrimType.T, yyvsp[-5].ValIDVal);
5772 yyvsp[-2].ValIDVal.S.makeSignless();
5773 BasicBlock* tmpBB = getBBVal(yyvsp[-2].ValIDVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005774 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0);
David Greene9145dd22007-08-01 03:59:32 +00005775 yyval.TermInstVal.TI = S;
5776 yyval.TermInstVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005777 ;}
5778 break;
5779
5780 case 267:
David Greene9145dd22007-08-01 03:59:32 +00005781#line 3327 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005782 {
5783 const PointerType *PFTy;
5784 const FunctionType *Ty;
5785 Signedness FTySign;
5786
David Greene9145dd22007-08-01 03:59:32 +00005787 if (!(PFTy = dyn_cast<PointerType>(yyvsp[-10].TypeVal.PAT->get())) ||
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005788 !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
5789 // Pull out the types of all of the arguments...
5790 std::vector<const Type*> ParamTypes;
David Greene9145dd22007-08-01 03:59:32 +00005791 FTySign.makeComposite(yyvsp[-10].TypeVal.S);
5792 if (yyvsp[-7].ValueList) {
5793 for (std::vector<ValueInfo>::iterator I = yyvsp[-7].ValueList->begin(), E = yyvsp[-7].ValueList->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005794 I != E; ++I) {
5795 ParamTypes.push_back((*I).V->getType());
5796 FTySign.add(I->S);
5797 }
5798 }
5799 ParamAttrsList *PAL = 0;
David Greene9145dd22007-08-01 03:59:32 +00005800 if (yyvsp[-11].UIntVal == OldCallingConv::CSRet) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005801 ParamAttrsVector Attrs;
5802 ParamAttrsWithIndex PAWI;
5803 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
5804 Attrs.push_back(PAWI);
5805 PAL = ParamAttrsList::get(Attrs);
5806 }
5807 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
5808 if (isVarArg) ParamTypes.pop_back();
David Greene9145dd22007-08-01 03:59:32 +00005809 Ty = FunctionType::get(yyvsp[-10].TypeVal.PAT->get(), ParamTypes, isVarArg, PAL);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005810 PFTy = PointerType::get(Ty);
David Greene9145dd22007-08-01 03:59:32 +00005811 yyval.TermInstVal.S.copy(yyvsp[-10].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005812 } else {
David Greene9145dd22007-08-01 03:59:32 +00005813 FTySign = yyvsp[-10].TypeVal.S;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005814 // Get the signedness of the result type. $3 is the pointer to the
5815 // function type so we get the 0th element to extract the function type,
5816 // and then the 0th element again to get the result type.
David Greene9145dd22007-08-01 03:59:32 +00005817 yyval.TermInstVal.S.copy(yyvsp[-10].TypeVal.S.get(0).get(0));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005818 }
5819
David Greene9145dd22007-08-01 03:59:32 +00005820 yyvsp[-9].ValIDVal.S.makeComposite(FTySign);
5821 Value *V = getVal(PFTy, yyvsp[-9].ValIDVal); // Get the function we're calling...
5822 BasicBlock *Normal = getBBVal(yyvsp[-3].ValIDVal);
5823 BasicBlock *Except = getBBVal(yyvsp[0].ValIDVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005824
5825 // Create the call node...
David Greene9145dd22007-08-01 03:59:32 +00005826 if (!yyvsp[-7].ValueList) { // Has no arguments?
5827 yyval.TermInstVal.TI = new InvokeInst(V, Normal, Except, 0, 0);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005828 } else { // Has arguments?
5829 // Loop through FunctionType's arguments and ensure they are specified
5830 // correctly!
5831 //
5832 FunctionType::param_iterator I = Ty->param_begin();
5833 FunctionType::param_iterator E = Ty->param_end();
David Greene9145dd22007-08-01 03:59:32 +00005834 std::vector<ValueInfo>::iterator ArgI = yyvsp[-7].ValueList->begin(), ArgE = yyvsp[-7].ValueList->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005835
5836 std::vector<Value*> Args;
5837 for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
5838 if ((*ArgI).V->getType() != *I)
5839 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
5840 (*I)->getDescription() + "'");
5841 Args.push_back((*ArgI).V);
5842 }
5843
5844 if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
5845 error("Invalid number of parameters detected");
5846
David Greene9145dd22007-08-01 03:59:32 +00005847 yyval.TermInstVal.TI = new InvokeInst(V, Normal, Except, &Args[0], Args.size());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005848 }
David Greene9145dd22007-08-01 03:59:32 +00005849 cast<InvokeInst>(yyval.TermInstVal.TI)->setCallingConv(upgradeCallingConv(yyvsp[-11].UIntVal));
5850 delete yyvsp[-10].TypeVal.PAT;
5851 delete yyvsp[-7].ValueList;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005852 lastCallingConv = OldCallingConv::C;
5853 ;}
5854 break;
5855
5856 case 268:
David Greene9145dd22007-08-01 03:59:32 +00005857#line 3399 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005858 {
David Greene9145dd22007-08-01 03:59:32 +00005859 yyval.TermInstVal.TI = new UnwindInst();
5860 yyval.TermInstVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005861 ;}
5862 break;
5863
5864 case 269:
David Greene9145dd22007-08-01 03:59:32 +00005865#line 3403 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005866 {
David Greene9145dd22007-08-01 03:59:32 +00005867 yyval.TermInstVal.TI = new UnreachableInst();
5868 yyval.TermInstVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005869 ;}
5870 break;
5871
5872 case 270:
David Greene9145dd22007-08-01 03:59:32 +00005873#line 3410 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005874 {
David Greene9145dd22007-08-01 03:59:32 +00005875 yyval.JumpTable = yyvsp[-5].JumpTable;
5876 yyvsp[-3].ValIDVal.S.copy(yyvsp[-4].PrimType.S);
5877 Constant *V = cast<Constant>(getExistingValue(yyvsp[-4].PrimType.T, yyvsp[-3].ValIDVal));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005878
5879 if (V == 0)
5880 error("May only switch on a constant pool value");
5881
David Greene9145dd22007-08-01 03:59:32 +00005882 yyvsp[0].ValIDVal.S.makeSignless();
5883 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
5884 yyval.JumpTable->push_back(std::make_pair(V, tmpBB));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005885 ;}
5886 break;
5887
5888 case 271:
David Greene9145dd22007-08-01 03:59:32 +00005889#line 3422 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005890 {
David Greene9145dd22007-08-01 03:59:32 +00005891 yyval.JumpTable = new std::vector<std::pair<Constant*, BasicBlock*> >();
5892 yyvsp[-3].ValIDVal.S.copy(yyvsp[-4].PrimType.S);
5893 Constant *V = cast<Constant>(getExistingValue(yyvsp[-4].PrimType.T, yyvsp[-3].ValIDVal));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005894
5895 if (V == 0)
5896 error("May only switch on a constant pool value");
5897
David Greene9145dd22007-08-01 03:59:32 +00005898 yyvsp[0].ValIDVal.S.makeSignless();
5899 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
5900 yyval.JumpTable->push_back(std::make_pair(V, tmpBB));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005901 ;}
5902 break;
5903
5904 case 272:
David Greene9145dd22007-08-01 03:59:32 +00005905#line 3437 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005906 {
5907 bool omit = false;
David Greene9145dd22007-08-01 03:59:32 +00005908 if (yyvsp[-1].StrVal)
5909 if (BitCastInst *BCI = dyn_cast<BitCastInst>(yyvsp[0].InstVal.I))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005910 if (BCI->getSrcTy() == BCI->getDestTy() &&
David Greene9145dd22007-08-01 03:59:32 +00005911 BCI->getOperand(0)->getName() == yyvsp[-1].StrVal)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005912 // This is a useless bit cast causing a name redefinition. It is
5913 // a bit cast from a type to the same type of an operand with the
5914 // same name as the name we would give this instruction. Since this
5915 // instruction results in no code generation, it is safe to omit
5916 // the instruction. This situation can occur because of collapsed
5917 // type planes. For example:
5918 // %X = add int %Y, %Z
5919 // %X = cast int %Y to uint
5920 // After upgrade, this looks like:
5921 // %X = add i32 %Y, %Z
5922 // %X = bitcast i32 to i32
5923 // The bitcast is clearly useless so we omit it.
5924 omit = true;
5925 if (omit) {
David Greene9145dd22007-08-01 03:59:32 +00005926 yyval.InstVal.I = 0;
5927 yyval.InstVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005928 } else {
David Greene9145dd22007-08-01 03:59:32 +00005929 ValueInfo VI; VI.V = yyvsp[0].InstVal.I; VI.S.copy(yyvsp[0].InstVal.S);
5930 setValueName(VI, yyvsp[-1].StrVal);
5931 InsertValue(yyvsp[0].InstVal.I);
5932 yyval.InstVal = yyvsp[0].InstVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005933 }
5934 ;}
5935 break;
5936
5937 case 273:
David Greene9145dd22007-08-01 03:59:32 +00005938#line 3467 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005939 { // Used for PHI nodes
David Greene9145dd22007-08-01 03:59:32 +00005940 yyval.PHIList.P = new std::list<std::pair<Value*, BasicBlock*> >();
5941 yyval.PHIList.S.copy(yyvsp[-5].TypeVal.S);
5942 yyvsp[-3].ValIDVal.S.copy(yyvsp[-5].TypeVal.S);
5943 Value* tmpVal = getVal(yyvsp[-5].TypeVal.PAT->get(), yyvsp[-3].ValIDVal);
5944 yyvsp[-1].ValIDVal.S.makeSignless();
5945 BasicBlock* tmpBB = getBBVal(yyvsp[-1].ValIDVal);
5946 yyval.PHIList.P->push_back(std::make_pair(tmpVal, tmpBB));
5947 delete yyvsp[-5].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005948 ;}
5949 break;
5950
5951 case 274:
David Greene9145dd22007-08-01 03:59:32 +00005952#line 3477 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005953 {
David Greene9145dd22007-08-01 03:59:32 +00005954 yyval.PHIList = yyvsp[-6].PHIList;
5955 yyvsp[-3].ValIDVal.S.copy(yyvsp[-6].PHIList.S);
5956 Value* tmpVal = getVal(yyvsp[-6].PHIList.P->front().first->getType(), yyvsp[-3].ValIDVal);
5957 yyvsp[-1].ValIDVal.S.makeSignless();
5958 BasicBlock* tmpBB = getBBVal(yyvsp[-1].ValIDVal);
5959 yyvsp[-6].PHIList.P->push_back(std::make_pair(tmpVal, tmpBB));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005960 ;}
5961 break;
5962
5963 case 275:
David Greene9145dd22007-08-01 03:59:32 +00005964#line 3487 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005965 { // Used for call statements, and memory insts...
David Greene9145dd22007-08-01 03:59:32 +00005966 yyval.ValueList = new std::vector<ValueInfo>();
5967 yyval.ValueList->push_back(yyvsp[0].ValueVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005968 ;}
5969 break;
5970
5971 case 276:
David Greene9145dd22007-08-01 03:59:32 +00005972#line 3491 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005973 {
David Greene9145dd22007-08-01 03:59:32 +00005974 yyval.ValueList = yyvsp[-2].ValueList;
5975 yyvsp[-2].ValueList->push_back(yyvsp[0].ValueVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005976 ;}
5977 break;
5978
5979 case 278:
David Greene9145dd22007-08-01 03:59:32 +00005980#line 3499 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5981 { yyval.ValueList = 0; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005982 break;
5983
5984 case 279:
David Greene9145dd22007-08-01 03:59:32 +00005985#line 3503 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005986 {
David Greene9145dd22007-08-01 03:59:32 +00005987 yyval.BoolVal = true;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005988 ;}
5989 break;
5990
5991 case 280:
David Greene9145dd22007-08-01 03:59:32 +00005992#line 3506 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005993 {
David Greene9145dd22007-08-01 03:59:32 +00005994 yyval.BoolVal = false;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005995 ;}
5996 break;
5997
5998 case 281:
David Greene9145dd22007-08-01 03:59:32 +00005999#line 3512 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006000 {
David Greene9145dd22007-08-01 03:59:32 +00006001 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6002 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6003 const Type* Ty = yyvsp[-3].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006004 if (!Ty->isInteger() && !Ty->isFloatingPoint() && !isa<VectorType>(Ty))
6005 error("Arithmetic operator requires integer, FP, or packed operands");
6006 if (isa<VectorType>(Ty) &&
David Greene9145dd22007-08-01 03:59:32 +00006007 (yyvsp[-4].BinaryOpVal == URemOp || yyvsp[-4].BinaryOpVal == SRemOp || yyvsp[-4].BinaryOpVal == FRemOp || yyvsp[-4].BinaryOpVal == RemOp))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006008 error("Remainder not supported on vector types");
6009 // Upgrade the opcode from obsolete versions before we do anything with it.
David Greene9145dd22007-08-01 03:59:32 +00006010 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-4].BinaryOpVal, Ty, yyvsp[-3].TypeVal.S);
6011 Value* val1 = getVal(Ty, yyvsp[-2].ValIDVal);
6012 Value* val2 = getVal(Ty, yyvsp[0].ValIDVal);
6013 yyval.InstVal.I = BinaryOperator::create(Opcode, val1, val2);
6014 if (yyval.InstVal.I == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006015 error("binary operator returned null");
David Greene9145dd22007-08-01 03:59:32 +00006016 yyval.InstVal.S.copy(yyvsp[-3].TypeVal.S);
6017 delete yyvsp[-3].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006018 ;}
6019 break;
6020
6021 case 282:
David Greene9145dd22007-08-01 03:59:32 +00006022#line 3531 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006023 {
David Greene9145dd22007-08-01 03:59:32 +00006024 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6025 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6026 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006027 if (!Ty->isInteger()) {
6028 if (!isa<VectorType>(Ty) ||
6029 !cast<VectorType>(Ty)->getElementType()->isInteger())
6030 error("Logical operator requires integral operands");
6031 }
David Greene9145dd22007-08-01 03:59:32 +00006032 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-4].BinaryOpVal, Ty, yyvsp[-3].TypeVal.S);
6033 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
6034 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
6035 yyval.InstVal.I = BinaryOperator::create(Opcode, tmpVal1, tmpVal2);
6036 if (yyval.InstVal.I == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006037 error("binary operator returned null");
David Greene9145dd22007-08-01 03:59:32 +00006038 yyval.InstVal.S.copy(yyvsp[-3].TypeVal.S);
6039 delete yyvsp[-3].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006040 ;}
6041 break;
6042
6043 case 283:
David Greene9145dd22007-08-01 03:59:32 +00006044#line 3549 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006045 {
David Greene9145dd22007-08-01 03:59:32 +00006046 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6047 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6048 const Type* Ty = yyvsp[-3].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006049 if(isa<VectorType>(Ty))
6050 error("VectorTypes currently not supported in setcc instructions");
6051 unsigned short pred;
David Greene9145dd22007-08-01 03:59:32 +00006052 Instruction::OtherOps Opcode = getCompareOp(yyvsp[-4].BinaryOpVal, pred, Ty, yyvsp[-3].TypeVal.S);
6053 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
6054 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
6055 yyval.InstVal.I = CmpInst::create(Opcode, pred, tmpVal1, tmpVal2);
6056 if (yyval.InstVal.I == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006057 error("binary operator returned null");
David Greene9145dd22007-08-01 03:59:32 +00006058 yyval.InstVal.S.makeUnsigned();
6059 delete yyvsp[-3].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006060 ;}
6061 break;
6062
6063 case 284:
David Greene9145dd22007-08-01 03:59:32 +00006064#line 3565 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006065 {
David Greene9145dd22007-08-01 03:59:32 +00006066 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6067 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6068 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006069 if (isa<VectorType>(Ty))
6070 error("VectorTypes currently not supported in icmp instructions");
6071 else if (!Ty->isInteger() && !isa<PointerType>(Ty))
6072 error("icmp requires integer or pointer typed operands");
David Greene9145dd22007-08-01 03:59:32 +00006073 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
6074 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
6075 yyval.InstVal.I = new ICmpInst(yyvsp[-4].IPred, tmpVal1, tmpVal2);
6076 yyval.InstVal.S.makeUnsigned();
6077 delete yyvsp[-3].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006078 ;}
6079 break;
6080
6081 case 285:
David Greene9145dd22007-08-01 03:59:32 +00006082#line 3579 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006083 {
David Greene9145dd22007-08-01 03:59:32 +00006084 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6085 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6086 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006087 if (isa<VectorType>(Ty))
6088 error("VectorTypes currently not supported in fcmp instructions");
6089 else if (!Ty->isFloatingPoint())
6090 error("fcmp instruction requires floating point operands");
David Greene9145dd22007-08-01 03:59:32 +00006091 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
6092 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
6093 yyval.InstVal.I = new FCmpInst(yyvsp[-4].FPred, tmpVal1, tmpVal2);
6094 yyval.InstVal.S.makeUnsigned();
6095 delete yyvsp[-3].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006096 ;}
6097 break;
6098
6099 case 286:
David Greene9145dd22007-08-01 03:59:32 +00006100#line 3593 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006101 {
6102 warning("Use of obsolete 'not' instruction: Replacing with 'xor");
David Greene9145dd22007-08-01 03:59:32 +00006103 const Type *Ty = yyvsp[0].ValueVal.V->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006104 Value *Ones = ConstantInt::getAllOnesValue(Ty);
6105 if (Ones == 0)
6106 error("Expected integral type for not instruction");
David Greene9145dd22007-08-01 03:59:32 +00006107 yyval.InstVal.I = BinaryOperator::create(Instruction::Xor, yyvsp[0].ValueVal.V, Ones);
6108 if (yyval.InstVal.I == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006109 error("Could not create a xor instruction");
David Greene9145dd22007-08-01 03:59:32 +00006110 yyval.InstVal.S.copy(yyvsp[0].ValueVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006111 ;}
6112 break;
6113
6114 case 287:
David Greene9145dd22007-08-01 03:59:32 +00006115#line 3604 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006116 {
David Greene9145dd22007-08-01 03:59:32 +00006117 if (!yyvsp[0].ValueVal.V->getType()->isInteger() ||
6118 cast<IntegerType>(yyvsp[0].ValueVal.V->getType())->getBitWidth() != 8)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006119 error("Shift amount must be int8");
David Greene9145dd22007-08-01 03:59:32 +00006120 const Type* Ty = yyvsp[-2].ValueVal.V->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006121 if (!Ty->isInteger())
6122 error("Shift constant expression requires integer operand");
6123 Value* ShiftAmt = 0;
6124 if (cast<IntegerType>(Ty)->getBitWidth() > Type::Int8Ty->getBitWidth())
David Greene9145dd22007-08-01 03:59:32 +00006125 if (Constant *C = dyn_cast<Constant>(yyvsp[0].ValueVal.V))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006126 ShiftAmt = ConstantExpr::getZExt(C, Ty);
6127 else
David Greene9145dd22007-08-01 03:59:32 +00006128 ShiftAmt = new ZExtInst(yyvsp[0].ValueVal.V, Ty, makeNameUnique("shift"), CurBB);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006129 else
David Greene9145dd22007-08-01 03:59:32 +00006130 ShiftAmt = yyvsp[0].ValueVal.V;
6131 yyval.InstVal.I = BinaryOperator::create(getBinaryOp(yyvsp[-3].BinaryOpVal, Ty, yyvsp[-2].ValueVal.S), yyvsp[-2].ValueVal.V, ShiftAmt);
6132 yyval.InstVal.S.copy(yyvsp[-2].ValueVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006133 ;}
6134 break;
6135
6136 case 288:
David Greene9145dd22007-08-01 03:59:32 +00006137#line 3622 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006138 {
David Greene9145dd22007-08-01 03:59:32 +00006139 const Type *DstTy = yyvsp[0].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006140 if (!DstTy->isFirstClassType())
6141 error("cast instruction to a non-primitive type: '" +
6142 DstTy->getDescription() + "'");
David Greene9145dd22007-08-01 03:59:32 +00006143 yyval.InstVal.I = cast<Instruction>(getCast(yyvsp[-3].CastOpVal, yyvsp[-2].ValueVal.V, yyvsp[-2].ValueVal.S, DstTy, yyvsp[0].TypeVal.S, true));
6144 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
6145 delete yyvsp[0].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006146 ;}
6147 break;
6148
6149 case 289:
David Greene9145dd22007-08-01 03:59:32 +00006150#line 3631 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006151 {
David Greene9145dd22007-08-01 03:59:32 +00006152 if (!yyvsp[-4].ValueVal.V->getType()->isInteger() ||
6153 cast<IntegerType>(yyvsp[-4].ValueVal.V->getType())->getBitWidth() != 1)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006154 error("select condition must be bool");
David Greene9145dd22007-08-01 03:59:32 +00006155 if (yyvsp[-2].ValueVal.V->getType() != yyvsp[0].ValueVal.V->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006156 error("select value types should match");
David Greene9145dd22007-08-01 03:59:32 +00006157 yyval.InstVal.I = new SelectInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
6158 yyval.InstVal.S.copy(yyvsp[-2].ValueVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006159 ;}
6160 break;
6161
6162 case 290:
David Greene9145dd22007-08-01 03:59:32 +00006163#line 3640 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006164 {
David Greene9145dd22007-08-01 03:59:32 +00006165 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006166 NewVarArgs = true;
David Greene9145dd22007-08-01 03:59:32 +00006167 yyval.InstVal.I = new VAArgInst(yyvsp[-2].ValueVal.V, Ty);
6168 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
6169 delete yyvsp[0].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006170 ;}
6171 break;
6172
6173 case 291:
David Greene9145dd22007-08-01 03:59:32 +00006174#line 3647 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006175 {
David Greene9145dd22007-08-01 03:59:32 +00006176 const Type* ArgTy = yyvsp[-2].ValueVal.V->getType();
6177 const Type* DstTy = yyvsp[0].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006178 ObsoleteVarArgs = true;
6179 Function* NF = cast<Function>(CurModule.CurrentModule->
6180 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
6181
6182 //b = vaarg a, t ->
6183 //foo = alloca 1 of t
6184 //bar = vacopy a
6185 //store bar -> foo
6186 //b = vaarg foo, t
6187 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vaarg.fix");
6188 CurBB->getInstList().push_back(foo);
David Greene9145dd22007-08-01 03:59:32 +00006189 CallInst* bar = new CallInst(NF, yyvsp[-2].ValueVal.V);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006190 CurBB->getInstList().push_back(bar);
6191 CurBB->getInstList().push_back(new StoreInst(bar, foo));
David Greene9145dd22007-08-01 03:59:32 +00006192 yyval.InstVal.I = new VAArgInst(foo, DstTy);
6193 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
6194 delete yyvsp[0].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006195 ;}
6196 break;
6197
6198 case 292:
David Greene9145dd22007-08-01 03:59:32 +00006199#line 3668 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006200 {
David Greene9145dd22007-08-01 03:59:32 +00006201 const Type* ArgTy = yyvsp[-2].ValueVal.V->getType();
6202 const Type* DstTy = yyvsp[0].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006203 ObsoleteVarArgs = true;
6204 Function* NF = cast<Function>(CurModule.CurrentModule->
6205 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
6206
6207 //b = vanext a, t ->
6208 //foo = alloca 1 of t
6209 //bar = vacopy a
6210 //store bar -> foo
6211 //tmp = vaarg foo, t
6212 //b = load foo
6213 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vanext.fix");
6214 CurBB->getInstList().push_back(foo);
David Greene9145dd22007-08-01 03:59:32 +00006215 CallInst* bar = new CallInst(NF, yyvsp[-2].ValueVal.V);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006216 CurBB->getInstList().push_back(bar);
6217 CurBB->getInstList().push_back(new StoreInst(bar, foo));
6218 Instruction* tmp = new VAArgInst(foo, DstTy);
6219 CurBB->getInstList().push_back(tmp);
David Greene9145dd22007-08-01 03:59:32 +00006220 yyval.InstVal.I = new LoadInst(foo);
6221 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
6222 delete yyvsp[0].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006223 ;}
6224 break;
6225
6226 case 293:
David Greene9145dd22007-08-01 03:59:32 +00006227#line 3692 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006228 {
David Greene9145dd22007-08-01 03:59:32 +00006229 if (!ExtractElementInst::isValidOperands(yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006230 error("Invalid extractelement operands");
David Greene9145dd22007-08-01 03:59:32 +00006231 yyval.InstVal.I = new ExtractElementInst(yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
6232 yyval.InstVal.S.copy(yyvsp[-2].ValueVal.S.get(0));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006233 ;}
6234 break;
6235
6236 case 294:
David Greene9145dd22007-08-01 03:59:32 +00006237#line 3698 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006238 {
David Greene9145dd22007-08-01 03:59:32 +00006239 if (!InsertElementInst::isValidOperands(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006240 error("Invalid insertelement operands");
David Greene9145dd22007-08-01 03:59:32 +00006241 yyval.InstVal.I = new InsertElementInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
6242 yyval.InstVal.S.copy(yyvsp[-4].ValueVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006243 ;}
6244 break;
6245
6246 case 295:
David Greene9145dd22007-08-01 03:59:32 +00006247#line 3704 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006248 {
David Greene9145dd22007-08-01 03:59:32 +00006249 if (!ShuffleVectorInst::isValidOperands(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006250 error("Invalid shufflevector operands");
David Greene9145dd22007-08-01 03:59:32 +00006251 yyval.InstVal.I = new ShuffleVectorInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
6252 yyval.InstVal.S.copy(yyvsp[-4].ValueVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006253 ;}
6254 break;
6255
6256 case 296:
David Greene9145dd22007-08-01 03:59:32 +00006257#line 3710 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006258 {
David Greene9145dd22007-08-01 03:59:32 +00006259 const Type *Ty = yyvsp[0].PHIList.P->front().first->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006260 if (!Ty->isFirstClassType())
6261 error("PHI node operands must be of first class type");
6262 PHINode *PHI = new PHINode(Ty);
David Greene9145dd22007-08-01 03:59:32 +00006263 PHI->reserveOperandSpace(yyvsp[0].PHIList.P->size());
6264 while (yyvsp[0].PHIList.P->begin() != yyvsp[0].PHIList.P->end()) {
6265 if (yyvsp[0].PHIList.P->front().first->getType() != Ty)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006266 error("All elements of a PHI node must be of the same type");
David Greene9145dd22007-08-01 03:59:32 +00006267 PHI->addIncoming(yyvsp[0].PHIList.P->front().first, yyvsp[0].PHIList.P->front().second);
6268 yyvsp[0].PHIList.P->pop_front();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006269 }
David Greene9145dd22007-08-01 03:59:32 +00006270 yyval.InstVal.I = PHI;
6271 yyval.InstVal.S.copy(yyvsp[0].PHIList.S);
6272 delete yyvsp[0].PHIList.P; // Free the list...
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006273 ;}
6274 break;
6275
6276 case 297:
David Greene9145dd22007-08-01 03:59:32 +00006277#line 3726 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006278 {
6279 // Handle the short call syntax
6280 const PointerType *PFTy;
6281 const FunctionType *FTy;
6282 Signedness FTySign;
David Greene9145dd22007-08-01 03:59:32 +00006283 if (!(PFTy = dyn_cast<PointerType>(yyvsp[-4].TypeVal.PAT->get())) ||
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006284 !(FTy = dyn_cast<FunctionType>(PFTy->getElementType()))) {
6285 // Pull out the types of all of the arguments...
6286 std::vector<const Type*> ParamTypes;
David Greene9145dd22007-08-01 03:59:32 +00006287 FTySign.makeComposite(yyvsp[-4].TypeVal.S);
6288 if (yyvsp[-1].ValueList) {
6289 for (std::vector<ValueInfo>::iterator I = yyvsp[-1].ValueList->begin(), E = yyvsp[-1].ValueList->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006290 I != E; ++I) {
6291 ParamTypes.push_back((*I).V->getType());
6292 FTySign.add(I->S);
6293 }
6294 }
6295
6296 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
6297 if (isVarArg) ParamTypes.pop_back();
6298
David Greene9145dd22007-08-01 03:59:32 +00006299 const Type *RetTy = yyvsp[-4].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006300 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
6301 error("Functions cannot return aggregate types");
6302
6303 // Deal with CSRetCC
6304 ParamAttrsList *PAL = 0;
David Greene9145dd22007-08-01 03:59:32 +00006305 if (yyvsp[-5].UIntVal == OldCallingConv::CSRet) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006306 ParamAttrsVector Attrs;
6307 ParamAttrsWithIndex PAWI;
6308 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
6309 Attrs.push_back(PAWI);
6310 PAL = ParamAttrsList::get(Attrs);
6311 }
6312
6313 FTy = FunctionType::get(RetTy, ParamTypes, isVarArg, PAL);
6314 PFTy = PointerType::get(FTy);
David Greene9145dd22007-08-01 03:59:32 +00006315 yyval.InstVal.S.copy(yyvsp[-4].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006316 } else {
David Greene9145dd22007-08-01 03:59:32 +00006317 FTySign = yyvsp[-4].TypeVal.S;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006318 // Get the signedness of the result type. $3 is the pointer to the
6319 // function type so we get the 0th element to extract the function type,
6320 // and then the 0th element again to get the result type.
David Greene9145dd22007-08-01 03:59:32 +00006321 yyval.InstVal.S.copy(yyvsp[-4].TypeVal.S.get(0).get(0));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006322 }
David Greene9145dd22007-08-01 03:59:32 +00006323 yyvsp[-3].ValIDVal.S.makeComposite(FTySign);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006324
6325 // First upgrade any intrinsic calls.
6326 std::vector<Value*> Args;
David Greene9145dd22007-08-01 03:59:32 +00006327 if (yyvsp[-1].ValueList)
6328 for (unsigned i = 0, e = yyvsp[-1].ValueList->size(); i < e; ++i)
6329 Args.push_back((*yyvsp[-1].ValueList)[i].V);
6330 Instruction *Inst = upgradeIntrinsicCall(FTy->getReturnType(), yyvsp[-3].ValIDVal, Args);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006331
6332 // If we got an upgraded intrinsic
6333 if (Inst) {
David Greene9145dd22007-08-01 03:59:32 +00006334 yyval.InstVal.I = Inst;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006335 } else {
6336 // Get the function we're calling
David Greene9145dd22007-08-01 03:59:32 +00006337 Value *V = getVal(PFTy, yyvsp[-3].ValIDVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006338
6339 // Check the argument values match
David Greene9145dd22007-08-01 03:59:32 +00006340 if (!yyvsp[-1].ValueList) { // Has no arguments?
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006341 // Make sure no arguments is a good thing!
6342 if (FTy->getNumParams() != 0)
6343 error("No arguments passed to a function that expects arguments");
6344 } else { // Has arguments?
6345 // Loop through FunctionType's arguments and ensure they are specified
6346 // correctly!
6347 //
6348 FunctionType::param_iterator I = FTy->param_begin();
6349 FunctionType::param_iterator E = FTy->param_end();
David Greene9145dd22007-08-01 03:59:32 +00006350 std::vector<ValueInfo>::iterator ArgI = yyvsp[-1].ValueList->begin(), ArgE = yyvsp[-1].ValueList->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006351
6352 for (; ArgI != ArgE && I != E; ++ArgI, ++I)
6353 if ((*ArgI).V->getType() != *I)
6354 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
6355 (*I)->getDescription() + "'");
6356
6357 if (I != E || (ArgI != ArgE && !FTy->isVarArg()))
6358 error("Invalid number of parameters detected");
6359 }
6360
6361 // Create the call instruction
David Greene9145dd22007-08-01 03:59:32 +00006362 CallInst *CI = new CallInst(V, Args.begin(), Args.end());
6363 CI->setTailCall(yyvsp[-6].BoolVal);
6364 CI->setCallingConv(upgradeCallingConv(yyvsp[-5].UIntVal));
6365 yyval.InstVal.I = CI;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006366 }
David Greene9145dd22007-08-01 03:59:32 +00006367 delete yyvsp[-4].TypeVal.PAT;
6368 delete yyvsp[-1].ValueList;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006369 lastCallingConv = OldCallingConv::C;
6370 ;}
6371 break;
6372
6373 case 298:
David Greene9145dd22007-08-01 03:59:32 +00006374#line 3819 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006375 {
David Greene9145dd22007-08-01 03:59:32 +00006376 yyval.InstVal = yyvsp[0].InstVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006377 ;}
6378 break;
6379
6380 case 299:
David Greene9145dd22007-08-01 03:59:32 +00006381#line 3827 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
6382 { yyval.ValueList = yyvsp[0].ValueList; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006383 break;
6384
6385 case 300:
David Greene9145dd22007-08-01 03:59:32 +00006386#line 3828 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
6387 { yyval.ValueList = new std::vector<ValueInfo>(); ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006388 break;
6389
6390 case 301:
David Greene9145dd22007-08-01 03:59:32 +00006391#line 3832 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
6392 { yyval.BoolVal = true; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006393 break;
6394
6395 case 302:
David Greene9145dd22007-08-01 03:59:32 +00006396#line 3833 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
6397 { yyval.BoolVal = false; ;}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006398 break;
6399
6400 case 303:
David Greene9145dd22007-08-01 03:59:32 +00006401#line 3837 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006402 {
David Greene9145dd22007-08-01 03:59:32 +00006403 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
6404 yyval.InstVal.S.makeComposite(yyvsp[-1].TypeVal.S);
6405 yyval.InstVal.I = new MallocInst(Ty, 0, yyvsp[0].UIntVal);
6406 delete yyvsp[-1].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006407 ;}
6408 break;
6409
6410 case 304:
David Greene9145dd22007-08-01 03:59:32 +00006411#line 3843 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006412 {
David Greene9145dd22007-08-01 03:59:32 +00006413 const Type *Ty = yyvsp[-4].TypeVal.PAT->get();
6414 yyvsp[-1].ValIDVal.S.makeUnsigned();
6415 yyval.InstVal.S.makeComposite(yyvsp[-4].TypeVal.S);
6416 yyval.InstVal.I = new MallocInst(Ty, getVal(yyvsp[-2].PrimType.T, yyvsp[-1].ValIDVal), yyvsp[0].UIntVal);
6417 delete yyvsp[-4].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006418 ;}
6419 break;
6420
6421 case 305:
David Greene9145dd22007-08-01 03:59:32 +00006422#line 3850 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006423 {
David Greene9145dd22007-08-01 03:59:32 +00006424 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
6425 yyval.InstVal.S.makeComposite(yyvsp[-1].TypeVal.S);
6426 yyval.InstVal.I = new AllocaInst(Ty, 0, yyvsp[0].UIntVal);
6427 delete yyvsp[-1].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006428 ;}
6429 break;
6430
6431 case 306:
David Greene9145dd22007-08-01 03:59:32 +00006432#line 3856 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006433 {
David Greene9145dd22007-08-01 03:59:32 +00006434 const Type *Ty = yyvsp[-4].TypeVal.PAT->get();
6435 yyvsp[-1].ValIDVal.S.makeUnsigned();
6436 yyval.InstVal.S.makeComposite(yyvsp[-2].PrimType.S);
6437 yyval.InstVal.I = new AllocaInst(Ty, getVal(yyvsp[-2].PrimType.T, yyvsp[-1].ValIDVal), yyvsp[0].UIntVal);
6438 delete yyvsp[-4].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006439 ;}
6440 break;
6441
6442 case 307:
David Greene9145dd22007-08-01 03:59:32 +00006443#line 3863 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006444 {
David Greene9145dd22007-08-01 03:59:32 +00006445 const Type *PTy = yyvsp[0].ValueVal.V->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006446 if (!isa<PointerType>(PTy))
6447 error("Trying to free nonpointer type '" + PTy->getDescription() + "'");
David Greene9145dd22007-08-01 03:59:32 +00006448 yyval.InstVal.I = new FreeInst(yyvsp[0].ValueVal.V);
6449 yyval.InstVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006450 ;}
6451 break;
6452
6453 case 308:
David Greene9145dd22007-08-01 03:59:32 +00006454#line 3870 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006455 {
David Greene9145dd22007-08-01 03:59:32 +00006456 const Type* Ty = yyvsp[-1].TypeVal.PAT->get();
6457 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006458 if (!isa<PointerType>(Ty))
6459 error("Can't load from nonpointer type: " + Ty->getDescription());
6460 if (!cast<PointerType>(Ty)->getElementType()->isFirstClassType())
6461 error("Can't load from pointer of non-first-class type: " +
6462 Ty->getDescription());
David Greene9145dd22007-08-01 03:59:32 +00006463 Value* tmpVal = getVal(Ty, yyvsp[0].ValIDVal);
6464 yyval.InstVal.I = new LoadInst(tmpVal, "", yyvsp[-3].BoolVal);
6465 yyval.InstVal.S.copy(yyvsp[-1].TypeVal.S.get(0));
6466 delete yyvsp[-1].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006467 ;}
6468 break;
6469
6470 case 309:
David Greene9145dd22007-08-01 03:59:32 +00006471#line 3883 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006472 {
David Greene9145dd22007-08-01 03:59:32 +00006473 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
6474 const PointerType *PTy = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006475 if (!PTy)
6476 error("Can't store to a nonpointer type: " +
David Greene9145dd22007-08-01 03:59:32 +00006477 yyvsp[-1].TypeVal.PAT->get()->getDescription());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006478 const Type *ElTy = PTy->getElementType();
David Greene9145dd22007-08-01 03:59:32 +00006479 Value *StoreVal = yyvsp[-3].ValueVal.V;
6480 Value* tmpVal = getVal(PTy, yyvsp[0].ValIDVal);
6481 if (ElTy != yyvsp[-3].ValueVal.V->getType()) {
6482 StoreVal = handleSRetFuncTypeMerge(yyvsp[-3].ValueVal.V, ElTy);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006483 if (!StoreVal)
David Greene9145dd22007-08-01 03:59:32 +00006484 error("Can't store '" + yyvsp[-3].ValueVal.V->getType()->getDescription() +
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006485 "' into space of type '" + ElTy->getDescription() + "'");
6486 else {
6487 PTy = PointerType::get(StoreVal->getType());
6488 if (Constant *C = dyn_cast<Constant>(tmpVal))
6489 tmpVal = ConstantExpr::getBitCast(C, PTy);
6490 else
6491 tmpVal = new BitCastInst(tmpVal, PTy, "upgrd.cast", CurBB);
6492 }
6493 }
David Greene9145dd22007-08-01 03:59:32 +00006494 yyval.InstVal.I = new StoreInst(StoreVal, tmpVal, yyvsp[-5].BoolVal);
6495 yyval.InstVal.S.makeSignless();
6496 delete yyvsp[-1].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006497 ;}
6498 break;
6499
6500 case 310:
David Greene9145dd22007-08-01 03:59:32 +00006501#line 3909 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006502 {
David Greene9145dd22007-08-01 03:59:32 +00006503 yyvsp[-1].ValIDVal.S.copy(yyvsp[-2].TypeVal.S);
6504 const Type* Ty = yyvsp[-2].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006505 if (!isa<PointerType>(Ty))
6506 error("getelementptr insn requires pointer operand");
6507
6508 std::vector<Value*> VIndices;
David Greene9145dd22007-08-01 03:59:32 +00006509 upgradeGEPInstIndices(Ty, yyvsp[0].ValueList, VIndices);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006510
David Greene9145dd22007-08-01 03:59:32 +00006511 Value* tmpVal = getVal(Ty, yyvsp[-1].ValIDVal);
6512 yyval.InstVal.I = new GetElementPtrInst(tmpVal, &VIndices[0], VIndices.size());
6513 ValueInfo VI; VI.V = tmpVal; VI.S.copy(yyvsp[-2].TypeVal.S);
6514 yyval.InstVal.S.copy(getElementSign(VI, VIndices));
6515 delete yyvsp[-2].TypeVal.PAT;
6516 delete yyvsp[0].ValueList;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006517 ;}
6518 break;
6519
6520
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006521 }
6522
David Greene9145dd22007-08-01 03:59:32 +00006523/* Line 993 of yacc.c. */
6524#line 6525 "UpgradeParser.tab.c"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006525
6526 yyvsp -= yylen;
6527 yyssp -= yylen;
6528
6529
6530 YY_STACK_PRINT (yyss, yyssp);
6531
6532 *++yyvsp = yyval;
6533
6534
6535 /* Now `shift' the result of the reduction. Determine what state
6536 that goes to, based on the state we popped back to and the rule
6537 number reduced by. */
6538
6539 yyn = yyr1[yyn];
6540
6541 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
6542 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
6543 yystate = yytable[yystate];
6544 else
6545 yystate = yydefgoto[yyn - YYNTOKENS];
6546
6547 goto yynewstate;
6548
6549
6550/*------------------------------------.
6551| yyerrlab -- here on detecting error |
6552`------------------------------------*/
6553yyerrlab:
6554 /* If not already recovering from an error, report this error. */
6555 if (!yyerrstatus)
6556 {
6557 ++yynerrs;
6558#if YYERROR_VERBOSE
6559 yyn = yypact[yystate];
6560
6561 if (YYPACT_NINF < yyn && yyn < YYLAST)
6562 {
David Greene9145dd22007-08-01 03:59:32 +00006563 YYSIZE_T yysize = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006564 int yytype = YYTRANSLATE (yychar);
David Greene9145dd22007-08-01 03:59:32 +00006565 const char* yyprefix;
6566 char *yymsg;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006567 int yyx;
6568
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006569 /* Start YYX at -YYN if negative to avoid negative indexes in
6570 YYCHECK. */
6571 int yyxbegin = yyn < 0 ? -yyn : 0;
6572
6573 /* Stay within bounds of both yycheck and yytname. */
6574 int yychecklim = YYLAST - yyn;
6575 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
David Greene9145dd22007-08-01 03:59:32 +00006576 int yycount = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006577
David Greene9145dd22007-08-01 03:59:32 +00006578 yyprefix = ", expecting ";
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006579 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
6580 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
6581 {
David Greene9145dd22007-08-01 03:59:32 +00006582 yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
6583 yycount += 1;
6584 if (yycount == 5)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006585 {
David Greene9145dd22007-08-01 03:59:32 +00006586 yysize = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006587 break;
6588 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006589 }
David Greene9145dd22007-08-01 03:59:32 +00006590 yysize += (sizeof ("syntax error, unexpected ")
6591 + yystrlen (yytname[yytype]));
6592 yymsg = (char *) YYSTACK_ALLOC (yysize);
6593 if (yymsg != 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006594 {
David Greene9145dd22007-08-01 03:59:32 +00006595 char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
6596 yyp = yystpcpy (yyp, yytname[yytype]);
6597
6598 if (yycount < 5)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006599 {
David Greene9145dd22007-08-01 03:59:32 +00006600 yyprefix = ", expecting ";
6601 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
6602 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
6603 {
6604 yyp = yystpcpy (yyp, yyprefix);
6605 yyp = yystpcpy (yyp, yytname[yyx]);
6606 yyprefix = " or ";
6607 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006608 }
6609 yyerror (yymsg);
6610 YYSTACK_FREE (yymsg);
6611 }
6612 else
David Greene9145dd22007-08-01 03:59:32 +00006613 yyerror ("syntax error; also virtual memory exhausted");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006614 }
6615 else
6616#endif /* YYERROR_VERBOSE */
David Greene9145dd22007-08-01 03:59:32 +00006617 yyerror ("syntax error");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006618 }
6619
6620
6621
6622 if (yyerrstatus == 3)
6623 {
David Greene9145dd22007-08-01 03:59:32 +00006624 /* If just tried and failed to reuse lookahead token after an
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006625 error, discard it. */
6626
6627 if (yychar <= YYEOF)
6628 {
David Greene9145dd22007-08-01 03:59:32 +00006629 /* If at end of input, pop the error token,
6630 then the rest of the stack, then return failure. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006631 if (yychar == YYEOF)
David Greene9145dd22007-08-01 03:59:32 +00006632 for (;;)
6633 {
6634 YYPOPSTACK;
6635 if (yyssp == yyss)
6636 YYABORT;
6637 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
6638 yydestruct (yystos[*yyssp], yyvsp);
6639 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006640 }
6641 else
6642 {
David Greene9145dd22007-08-01 03:59:32 +00006643 YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
6644 yydestruct (yytoken, &yylval);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006645 yychar = YYEMPTY;
David Greene9145dd22007-08-01 03:59:32 +00006646
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006647 }
6648 }
6649
David Greene9145dd22007-08-01 03:59:32 +00006650 /* Else will try to reuse lookahead token after shifting the error
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006651 token. */
6652 goto yyerrlab1;
6653
6654
6655/*---------------------------------------------------.
6656| yyerrorlab -- error raised explicitly by YYERROR. |
6657`---------------------------------------------------*/
6658yyerrorlab:
6659
David Greene9145dd22007-08-01 03:59:32 +00006660#ifdef __GNUC__
6661 /* Pacify GCC when the user code never invokes YYERROR and the label
6662 yyerrorlab therefore never appears in user code. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006663 if (0)
6664 goto yyerrorlab;
David Greene9145dd22007-08-01 03:59:32 +00006665#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006666
David Greene9145dd22007-08-01 03:59:32 +00006667 yyvsp -= yylen;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006668 yyssp -= yylen;
6669 yystate = *yyssp;
6670 goto yyerrlab1;
6671
6672
6673/*-------------------------------------------------------------.
6674| yyerrlab1 -- common code for both syntax error and YYERROR. |
6675`-------------------------------------------------------------*/
6676yyerrlab1:
6677 yyerrstatus = 3; /* Each real token shifted decrements this. */
6678
6679 for (;;)
6680 {
6681 yyn = yypact[yystate];
6682 if (yyn != YYPACT_NINF)
6683 {
6684 yyn += YYTERROR;
6685 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
6686 {
6687 yyn = yytable[yyn];
6688 if (0 < yyn)
6689 break;
6690 }
6691 }
6692
6693 /* Pop the current state because it cannot handle the error token. */
6694 if (yyssp == yyss)
6695 YYABORT;
6696
David Greene9145dd22007-08-01 03:59:32 +00006697 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
6698 yydestruct (yystos[yystate], yyvsp);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006699 YYPOPSTACK;
6700 yystate = *yyssp;
6701 YY_STACK_PRINT (yyss, yyssp);
6702 }
6703
6704 if (yyn == YYFINAL)
6705 YYACCEPT;
6706
David Greene9145dd22007-08-01 03:59:32 +00006707 YYDPRINTF ((stderr, "Shifting error token, "));
6708
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006709 *++yyvsp = yylval;
6710
6711
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006712 yystate = yyn;
6713 goto yynewstate;
6714
6715
6716/*-------------------------------------.
6717| yyacceptlab -- YYACCEPT comes here. |
6718`-------------------------------------*/
6719yyacceptlab:
6720 yyresult = 0;
6721 goto yyreturn;
6722
6723/*-----------------------------------.
6724| yyabortlab -- YYABORT comes here. |
6725`-----------------------------------*/
6726yyabortlab:
6727 yyresult = 1;
6728 goto yyreturn;
6729
6730#ifndef yyoverflow
David Greene9145dd22007-08-01 03:59:32 +00006731/*----------------------------------------------.
6732| yyoverflowlab -- parser overflow comes here. |
6733`----------------------------------------------*/
6734yyoverflowlab:
6735 yyerror ("parser stack overflow");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006736 yyresult = 2;
6737 /* Fall through. */
6738#endif
6739
6740yyreturn:
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006741#ifndef yyoverflow
6742 if (yyss != yyssa)
6743 YYSTACK_FREE (yyss);
6744#endif
6745 return yyresult;
6746}
6747
6748
David Greene9145dd22007-08-01 03:59:32 +00006749#line 3927 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006750
6751
6752int yyerror(const char *ErrorMsg) {
6753 std::string where
6754 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
6755 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
6756 std::string errMsg = where + "error: " + std::string(ErrorMsg);
6757 if (yychar != YYEMPTY && yychar != 0)
6758 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
6759 "'.";
6760 std::cerr << "llvm-upgrade: " << errMsg << '\n';
6761 std::cout << "llvm-upgrade: parse failed.\n";
6762 exit(1);
6763}
6764
6765void warning(const std::string& ErrorMsg) {
6766 std::string where
6767 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
6768 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
6769 std::string errMsg = where + "warning: " + std::string(ErrorMsg);
6770 if (yychar != YYEMPTY && yychar != 0)
6771 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
6772 "'.";
6773 std::cerr << "llvm-upgrade: " << errMsg << '\n';
6774}
6775
6776void error(const std::string& ErrorMsg, int LineNo) {
6777 if (LineNo == -1) LineNo = Upgradelineno;
6778 Upgradelineno = LineNo;
6779 yyerror(ErrorMsg.c_str());
6780}
6781
6782