blob: 6bddc3091702ff5a00f1a7d77334bac7747a94c7 [file] [log] [blame]
Chris Lattnera62e8e42007-12-29 20:47:37 +00001/* A Bison parser, made by GNU Bison 2.3. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002
Chris Lattnera62e8e42007-12-29 20:47:37 +00003/* Skeleton implementation for Bison's Yacc-like parsers in C
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004
Chris Lattnera62e8e42007-12-29 20:47:37 +00005 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, Inc.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007
Chris Lattnera62e8e42007-12-29 20:47:37 +00008 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22
23/* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work
25 under terms of your choice, so long as that work isn't itself a
26 parser generator using the skeleton or a modified version thereof
27 as a parser skeleton. Alternatively, if you modify or redistribute
28 the parser skeleton itself, you may (at your option) remove this
29 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public
31 License without this special exception.
32
33 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */
35
36/* C LALR(1) parser skeleton written by Richard Stallman, by
37 simplifying the original so-called "semantic" parser. */
38
39/* All symbols defined below should begin with yy or YY, to avoid
40 infringing on user name space. This should be done even for local
41 variables, as they might otherwise be expanded by user macros.
42 There are some unavoidable exceptions within include files to
43 define necessary library symbols; they are noted "INFRINGES ON
44 USER NAME SPACE" below. */
45
46/* Identify Bison output. */
47#define YYBISON 1
48
49/* Bison version. */
50#define YYBISON_VERSION "2.3"
51
52/* Skeleton name. */
53#define YYSKELETON_NAME "yacc.c"
54
55/* Pure parsers. */
56#define YYPURE 0
57
58/* Using locations. */
59#define YYLSP_NEEDED 0
60
61/* Substitute the variable and function names. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +000062#define yyparse Upgradeparse
Chris Lattnera62e8e42007-12-29 20:47:37 +000063#define yylex Upgradelex
Dan Gohmanf17a25c2007-07-18 16:29:46 +000064#define yyerror Upgradeerror
Chris Lattnera62e8e42007-12-29 20:47:37 +000065#define yylval Upgradelval
66#define yychar Upgradechar
Dan Gohmanf17a25c2007-07-18 16:29:46 +000067#define yydebug Upgradedebug
68#define yynerrs Upgradenerrs
69
Chris Lattnera62e8e42007-12-29 20:47:37 +000070
71/* Tokens. */
72#ifndef YYTOKENTYPE
73# define YYTOKENTYPE
74 /* Put the tokens into the symbol table, so that GDB and other debuggers
75 know about them. */
76 enum yytokentype {
77 ESINT64VAL = 258,
78 EUINT64VAL = 259,
79 SINTVAL = 260,
80 UINTVAL = 261,
81 FPVAL = 262,
82 VOID = 263,
83 BOOL = 264,
84 SBYTE = 265,
85 UBYTE = 266,
86 SHORT = 267,
87 USHORT = 268,
88 INT = 269,
89 UINT = 270,
90 LONG = 271,
91 ULONG = 272,
92 FLOAT = 273,
93 DOUBLE = 274,
94 TYPE = 275,
95 LABEL = 276,
96 VAR_ID = 277,
97 LABELSTR = 278,
98 STRINGCONSTANT = 279,
99 IMPLEMENTATION = 280,
100 ZEROINITIALIZER = 281,
101 TRUETOK = 282,
102 FALSETOK = 283,
103 BEGINTOK = 284,
104 ENDTOK = 285,
105 DECLARE = 286,
106 GLOBAL = 287,
107 CONSTANT = 288,
108 SECTION = 289,
109 VOLATILE = 290,
110 TO = 291,
111 DOTDOTDOT = 292,
112 NULL_TOK = 293,
113 UNDEF = 294,
114 CONST = 295,
115 INTERNAL = 296,
116 LINKONCE = 297,
117 WEAK = 298,
118 APPENDING = 299,
119 DLLIMPORT = 300,
120 DLLEXPORT = 301,
121 EXTERN_WEAK = 302,
122 OPAQUE = 303,
123 NOT = 304,
124 EXTERNAL = 305,
125 TARGET = 306,
126 TRIPLE = 307,
127 ENDIAN = 308,
128 POINTERSIZE = 309,
129 LITTLE = 310,
130 BIG = 311,
131 ALIGN = 312,
132 DEPLIBS = 313,
133 CALL = 314,
134 TAIL = 315,
135 ASM_TOK = 316,
136 MODULE = 317,
137 SIDEEFFECT = 318,
138 CC_TOK = 319,
139 CCC_TOK = 320,
140 CSRETCC_TOK = 321,
141 FASTCC_TOK = 322,
142 COLDCC_TOK = 323,
143 X86_STDCALLCC_TOK = 324,
144 X86_FASTCALLCC_TOK = 325,
145 DATALAYOUT = 326,
146 RET = 327,
147 BR = 328,
148 SWITCH = 329,
149 INVOKE = 330,
150 UNREACHABLE = 331,
151 UNWIND = 332,
152 EXCEPT = 333,
153 ADD = 334,
154 SUB = 335,
155 MUL = 336,
156 DIV = 337,
157 UDIV = 338,
158 SDIV = 339,
159 FDIV = 340,
160 REM = 341,
161 UREM = 342,
162 SREM = 343,
163 FREM = 344,
164 AND = 345,
165 OR = 346,
166 XOR = 347,
167 SHL = 348,
168 SHR = 349,
169 ASHR = 350,
170 LSHR = 351,
171 SETLE = 352,
172 SETGE = 353,
173 SETLT = 354,
174 SETGT = 355,
175 SETEQ = 356,
176 SETNE = 357,
177 ICMP = 358,
178 FCMP = 359,
179 MALLOC = 360,
180 ALLOCA = 361,
181 FREE = 362,
182 LOAD = 363,
183 STORE = 364,
184 GETELEMENTPTR = 365,
185 PHI_TOK = 366,
186 SELECT = 367,
187 VAARG = 368,
188 EXTRACTELEMENT = 369,
189 INSERTELEMENT = 370,
190 SHUFFLEVECTOR = 371,
191 VAARG_old = 372,
192 VANEXT_old = 373,
193 EQ = 374,
194 NE = 375,
195 SLT = 376,
196 SGT = 377,
197 SLE = 378,
198 SGE = 379,
199 ULT = 380,
200 UGT = 381,
201 ULE = 382,
202 UGE = 383,
203 OEQ = 384,
204 ONE = 385,
205 OLT = 386,
206 OGT = 387,
207 OLE = 388,
208 OGE = 389,
209 ORD = 390,
210 UNO = 391,
211 UEQ = 392,
212 UNE = 393,
213 CAST = 394,
214 TRUNC = 395,
215 ZEXT = 396,
216 SEXT = 397,
217 FPTRUNC = 398,
218 FPEXT = 399,
219 FPTOUI = 400,
220 FPTOSI = 401,
221 UITOFP = 402,
222 SITOFP = 403,
223 PTRTOINT = 404,
224 INTTOPTR = 405,
225 BITCAST = 406
226 };
227#endif
228/* Tokens. */
229#define ESINT64VAL 258
230#define EUINT64VAL 259
231#define SINTVAL 260
232#define UINTVAL 261
233#define FPVAL 262
234#define VOID 263
235#define BOOL 264
236#define SBYTE 265
237#define UBYTE 266
238#define SHORT 267
239#define USHORT 268
240#define INT 269
241#define UINT 270
242#define LONG 271
243#define ULONG 272
244#define FLOAT 273
245#define DOUBLE 274
246#define TYPE 275
247#define LABEL 276
248#define VAR_ID 277
249#define LABELSTR 278
250#define STRINGCONSTANT 279
251#define IMPLEMENTATION 280
252#define ZEROINITIALIZER 281
253#define TRUETOK 282
254#define FALSETOK 283
255#define BEGINTOK 284
256#define ENDTOK 285
257#define DECLARE 286
258#define GLOBAL 287
259#define CONSTANT 288
260#define SECTION 289
261#define VOLATILE 290
262#define TO 291
263#define DOTDOTDOT 292
264#define NULL_TOK 293
265#define UNDEF 294
266#define CONST 295
267#define INTERNAL 296
268#define LINKONCE 297
269#define WEAK 298
270#define APPENDING 299
271#define DLLIMPORT 300
272#define DLLEXPORT 301
273#define EXTERN_WEAK 302
274#define OPAQUE 303
275#define NOT 304
276#define EXTERNAL 305
277#define TARGET 306
278#define TRIPLE 307
279#define ENDIAN 308
280#define POINTERSIZE 309
281#define LITTLE 310
282#define BIG 311
283#define ALIGN 312
284#define DEPLIBS 313
285#define CALL 314
286#define TAIL 315
287#define ASM_TOK 316
288#define MODULE 317
289#define SIDEEFFECT 318
290#define CC_TOK 319
291#define CCC_TOK 320
292#define CSRETCC_TOK 321
293#define FASTCC_TOK 322
294#define COLDCC_TOK 323
295#define X86_STDCALLCC_TOK 324
296#define X86_FASTCALLCC_TOK 325
297#define DATALAYOUT 326
298#define RET 327
299#define BR 328
300#define SWITCH 329
301#define INVOKE 330
302#define UNREACHABLE 331
303#define UNWIND 332
304#define EXCEPT 333
305#define ADD 334
306#define SUB 335
307#define MUL 336
308#define DIV 337
309#define UDIV 338
310#define SDIV 339
311#define FDIV 340
312#define REM 341
313#define UREM 342
314#define SREM 343
315#define FREM 344
316#define AND 345
317#define OR 346
318#define XOR 347
319#define SHL 348
320#define SHR 349
321#define ASHR 350
322#define LSHR 351
323#define SETLE 352
324#define SETGE 353
325#define SETLT 354
326#define SETGT 355
327#define SETEQ 356
328#define SETNE 357
329#define ICMP 358
330#define FCMP 359
331#define MALLOC 360
332#define ALLOCA 361
333#define FREE 362
334#define LOAD 363
335#define STORE 364
336#define GETELEMENTPTR 365
337#define PHI_TOK 366
338#define SELECT 367
339#define VAARG 368
340#define EXTRACTELEMENT 369
341#define INSERTELEMENT 370
342#define SHUFFLEVECTOR 371
343#define VAARG_old 372
344#define VANEXT_old 373
345#define EQ 374
346#define NE 375
347#define SLT 376
348#define SGT 377
349#define SLE 378
350#define SGE 379
351#define ULT 380
352#define UGT 381
353#define ULE 382
354#define UGE 383
355#define OEQ 384
356#define ONE 385
357#define OLT 386
358#define OGT 387
359#define OLE 388
360#define OGE 389
361#define ORD 390
362#define UNO 391
363#define UEQ 392
364#define UNE 393
365#define CAST 394
366#define TRUNC 395
367#define ZEXT 396
368#define SEXT 397
369#define FPTRUNC 398
370#define FPEXT 399
371#define FPTOUI 400
372#define FPTOSI 401
373#define UITOFP 402
374#define SITOFP 403
375#define PTRTOINT 404
376#define INTTOPTR 405
377#define BITCAST 406
378
379
380
381
382/* Copy the first part of user declarations. */
Chris Lattner1c8733e2008-03-12 17:45:29 +0000383#line 14 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000384
385#include "UpgradeInternals.h"
386#include "llvm/CallingConv.h"
387#include "llvm/InlineAsm.h"
388#include "llvm/Instructions.h"
389#include "llvm/Module.h"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000390#include "llvm/ValueSymbolTable.h"
391#include "llvm/Support/GetElementPtrTypeIterator.h"
392#include "llvm/ADT/STLExtras.h"
393#include "llvm/Support/MathExtras.h"
394#include <algorithm>
395#include <iostream>
396#include <map>
397#include <list>
398#include <utility>
399
400// DEBUG_UPREFS - Define this symbol if you want to enable debugging output
401// relating to upreferences in the input stream.
402//
403//#define DEBUG_UPREFS 1
404#ifdef DEBUG_UPREFS
405#define UR_OUT(X) std::cerr << X
406#else
407#define UR_OUT(X)
408#endif
409
410#define YYERROR_VERBOSE 1
411#define YYINCLUDED_STDLIB_H
412#define YYDEBUG 1
413
414int yylex();
415int yyparse();
416
417int yyerror(const char*);
418static void warning(const std::string& WarningMsg);
419
420namespace llvm {
421
422std::istream* LexInput;
423static std::string CurFilename;
424
425// This bool controls whether attributes are ever added to function declarations
426// definitions and calls.
427static bool AddAttributes = false;
428
429static Module *ParserResult;
430static bool ObsoleteVarArgs;
431static bool NewVarArgs;
432static BasicBlock *CurBB;
433static GlobalVariable *CurGV;
434static unsigned lastCallingConv;
435
436// This contains info used when building the body of a function. It is
437// destroyed when the function is completed.
438//
439typedef std::vector<Value *> ValueList; // Numbered defs
440
441typedef std::pair<std::string,TypeInfo> RenameMapKey;
442typedef std::map<RenameMapKey,std::string> RenameMapType;
443
444static void
445ResolveDefinitions(std::map<const Type *,ValueList> &LateResolvers,
446 std::map<const Type *,ValueList> *FutureLateResolvers = 0);
447
448static struct PerModuleInfo {
449 Module *CurrentModule;
450 std::map<const Type *, ValueList> Values; // Module level numbered definitions
451 std::map<const Type *,ValueList> LateResolveValues;
452 std::vector<PATypeHolder> Types;
453 std::vector<Signedness> TypeSigns;
454 std::map<std::string,Signedness> NamedTypeSigns;
455 std::map<std::string,Signedness> NamedValueSigns;
456 std::map<ValID, PATypeHolder> LateResolveTypes;
457 static Module::Endianness Endian;
458 static Module::PointerSize PointerSize;
459 RenameMapType RenameMap;
460
461 /// PlaceHolderInfo - When temporary placeholder objects are created, remember
462 /// how they were referenced and on which line of the input they came from so
463 /// that we can resolve them later and print error messages as appropriate.
464 std::map<Value*, std::pair<ValID, int> > PlaceHolderInfo;
465
466 // GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
467 // references to global values. Global values may be referenced before they
468 // are defined, and if so, the temporary object that they represent is held
469 // here. This is used for forward references of GlobalValues.
470 //
471 typedef std::map<std::pair<const PointerType *, ValID>, GlobalValue*>
472 GlobalRefsType;
473 GlobalRefsType GlobalRefs;
474
475 void ModuleDone() {
476 // If we could not resolve some functions at function compilation time
477 // (calls to functions before they are defined), resolve them now... Types
478 // are resolved when the constant pool has been completely parsed.
479 //
480 ResolveDefinitions(LateResolveValues);
481
482 // Check to make sure that all global value forward references have been
483 // resolved!
484 //
485 if (!GlobalRefs.empty()) {
486 std::string UndefinedReferences = "Unresolved global references exist:\n";
487
488 for (GlobalRefsType::iterator I = GlobalRefs.begin(), E =GlobalRefs.end();
489 I != E; ++I) {
490 UndefinedReferences += " " + I->first.first->getDescription() + " " +
491 I->first.second.getName() + "\n";
492 }
493 error(UndefinedReferences);
494 return;
495 }
496
497 if (CurrentModule->getDataLayout().empty()) {
498 std::string dataLayout;
499 if (Endian != Module::AnyEndianness)
500 dataLayout.append(Endian == Module::BigEndian ? "E" : "e");
501 if (PointerSize != Module::AnyPointerSize) {
502 if (!dataLayout.empty())
503 dataLayout += "-";
504 dataLayout.append(PointerSize == Module::Pointer64 ?
505 "p:64:64" : "p:32:32");
506 }
507 CurrentModule->setDataLayout(dataLayout);
508 }
509
510 Values.clear(); // Clear out function local definitions
511 Types.clear();
512 TypeSigns.clear();
513 NamedTypeSigns.clear();
514 NamedValueSigns.clear();
515 CurrentModule = 0;
516 }
517
518 // GetForwardRefForGlobal - Check to see if there is a forward reference
519 // for this global. If so, remove it from the GlobalRefs map and return it.
520 // If not, just return null.
521 GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ValID ID) {
522 // Check to see if there is a forward reference to this global variable...
523 // if there is, eliminate it and patch the reference to use the new def'n.
524 GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PTy, ID));
525 GlobalValue *Ret = 0;
526 if (I != GlobalRefs.end()) {
527 Ret = I->second;
528 GlobalRefs.erase(I);
529 }
530 return Ret;
531 }
532 void setEndianness(Module::Endianness E) { Endian = E; }
533 void setPointerSize(Module::PointerSize sz) { PointerSize = sz; }
534} CurModule;
535
536Module::Endianness PerModuleInfo::Endian = Module::AnyEndianness;
537Module::PointerSize PerModuleInfo::PointerSize = Module::AnyPointerSize;
538
539static struct PerFunctionInfo {
540 Function *CurrentFunction; // Pointer to current function being created
541
542 std::map<const Type*, ValueList> Values; // Keep track of #'d definitions
543 std::map<const Type*, ValueList> LateResolveValues;
544 bool isDeclare; // Is this function a forward declararation?
545 GlobalValue::LinkageTypes Linkage;// Linkage for forward declaration.
546
547 /// BBForwardRefs - When we see forward references to basic blocks, keep
548 /// track of them here.
549 std::map<BasicBlock*, std::pair<ValID, int> > BBForwardRefs;
550 std::vector<BasicBlock*> NumberedBlocks;
551 RenameMapType RenameMap;
552 unsigned NextBBNum;
553
554 inline PerFunctionInfo() {
555 CurrentFunction = 0;
556 isDeclare = false;
557 Linkage = GlobalValue::ExternalLinkage;
558 }
559
560 inline void FunctionStart(Function *M) {
561 CurrentFunction = M;
562 NextBBNum = 0;
563 }
564
565 void FunctionDone() {
566 NumberedBlocks.clear();
567
568 // Any forward referenced blocks left?
569 if (!BBForwardRefs.empty()) {
570 error("Undefined reference to label " +
571 BBForwardRefs.begin()->first->getName());
572 return;
573 }
574
575 // Resolve all forward references now.
576 ResolveDefinitions(LateResolveValues, &CurModule.LateResolveValues);
577
578 Values.clear(); // Clear out function local definitions
579 RenameMap.clear();
580 CurrentFunction = 0;
581 isDeclare = false;
582 Linkage = GlobalValue::ExternalLinkage;
583 }
584} CurFun; // Info for the current function...
585
586static bool inFunctionScope() { return CurFun.CurrentFunction != 0; }
587
588/// This function is just a utility to make a Key value for the rename map.
589/// The Key is a combination of the name, type, Signedness of the original
590/// value (global/function). This just constructs the key and ensures that
591/// named Signedness values are resolved to the actual Signedness.
592/// @brief Make a key for the RenameMaps
593static RenameMapKey makeRenameMapKey(const std::string &Name, const Type* Ty,
594 const Signedness &Sign) {
595 TypeInfo TI;
596 TI.T = Ty;
597 if (Sign.isNamed())
598 // Don't allow Named Signedness nodes because they won't match. The actual
599 // Signedness must be looked up in the NamedTypeSigns map.
600 TI.S.copy(CurModule.NamedTypeSigns[Sign.getName()]);
601 else
602 TI.S.copy(Sign);
603 return std::make_pair(Name, TI);
604}
605
606
607//===----------------------------------------------------------------------===//
608// Code to handle definitions of all the types
609//===----------------------------------------------------------------------===//
610
611static int InsertValue(Value *V,
612 std::map<const Type*,ValueList> &ValueTab = CurFun.Values) {
613 if (V->hasName()) return -1; // Is this a numbered definition?
614
615 // Yes, insert the value into the value table...
616 ValueList &List = ValueTab[V->getType()];
617 List.push_back(V);
618 return List.size()-1;
619}
620
621static const Type *getType(const ValID &D, bool DoNotImprovise = false) {
622 switch (D.Type) {
623 case ValID::NumberVal: // Is it a numbered definition?
624 // Module constants occupy the lowest numbered slots...
625 if ((unsigned)D.Num < CurModule.Types.size()) {
626 return CurModule.Types[(unsigned)D.Num];
627 }
628 break;
629 case ValID::NameVal: // Is it a named definition?
630 if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) {
631 return N;
632 }
633 break;
634 default:
635 error("Internal parser error: Invalid symbol type reference");
636 return 0;
637 }
638
639 // If we reached here, we referenced either a symbol that we don't know about
640 // or an id number that hasn't been read yet. We may be referencing something
641 // forward, so just create an entry to be resolved later and get to it...
642 //
643 if (DoNotImprovise) return 0; // Do we just want a null to be returned?
644
645 if (inFunctionScope()) {
646 if (D.Type == ValID::NameVal) {
647 error("Reference to an undefined type: '" + D.getName() + "'");
648 return 0;
649 } else {
650 error("Reference to an undefined type: #" + itostr(D.Num));
651 return 0;
652 }
653 }
654
655 std::map<ValID, PATypeHolder>::iterator I =CurModule.LateResolveTypes.find(D);
656 if (I != CurModule.LateResolveTypes.end())
657 return I->second;
658
659 Type *Typ = OpaqueType::get();
660 CurModule.LateResolveTypes.insert(std::make_pair(D, Typ));
661 return Typ;
662}
663
664/// This is like the getType method except that instead of looking up the type
665/// for a given ID, it looks up that type's sign.
666/// @brief Get the signedness of a referenced type
667static Signedness getTypeSign(const ValID &D) {
668 switch (D.Type) {
669 case ValID::NumberVal: // Is it a numbered definition?
670 // Module constants occupy the lowest numbered slots...
671 if ((unsigned)D.Num < CurModule.TypeSigns.size()) {
672 return CurModule.TypeSigns[(unsigned)D.Num];
673 }
674 break;
675 case ValID::NameVal: { // Is it a named definition?
676 std::map<std::string,Signedness>::const_iterator I =
677 CurModule.NamedTypeSigns.find(D.Name);
678 if (I != CurModule.NamedTypeSigns.end())
679 return I->second;
680 // Perhaps its a named forward .. just cache the name
681 Signedness S;
682 S.makeNamed(D.Name);
683 return S;
684 }
685 default:
686 break;
687 }
688 // If we don't find it, its signless
689 Signedness S;
690 S.makeSignless();
691 return S;
692}
693
694/// This function is analagous to getElementType in LLVM. It provides the same
695/// function except that it looks up the Signedness instead of the type. This is
696/// used when processing GEP instructions that need to extract the type of an
697/// indexed struct/array/ptr member.
698/// @brief Look up an element's sign.
699static Signedness getElementSign(const ValueInfo& VI,
700 const std::vector<Value*> &Indices) {
701 const Type *Ptr = VI.V->getType();
702 assert(isa<PointerType>(Ptr) && "Need pointer type");
703
704 unsigned CurIdx = 0;
705 Signedness S(VI.S);
706 while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) {
707 if (CurIdx == Indices.size())
708 break;
709
710 Value *Index = Indices[CurIdx++];
711 assert(!isa<PointerType>(CT) || CurIdx == 1 && "Invalid type");
712 Ptr = CT->getTypeAtIndex(Index);
713 if (const Type* Ty = Ptr->getForwardedType())
714 Ptr = Ty;
715 assert(S.isComposite() && "Bad Signedness type");
716 if (isa<StructType>(CT)) {
717 S = S.get(cast<ConstantInt>(Index)->getZExtValue());
718 } else {
719 S = S.get(0UL);
720 }
721 if (S.isNamed())
722 S = CurModule.NamedTypeSigns[S.getName()];
723 }
724 Signedness Result;
725 Result.makeComposite(S);
726 return Result;
727}
728
729/// This function just translates a ConstantInfo into a ValueInfo and calls
730/// getElementSign(ValueInfo,...). Its just a convenience.
731/// @brief ConstantInfo version of getElementSign.
732static Signedness getElementSign(const ConstInfo& CI,
733 const std::vector<Constant*> &Indices) {
734 ValueInfo VI;
735 VI.V = CI.C;
736 VI.S.copy(CI.S);
737 std::vector<Value*> Idx;
738 for (unsigned i = 0; i < Indices.size(); ++i)
739 Idx.push_back(Indices[i]);
740 Signedness result = getElementSign(VI, Idx);
741 VI.destroy();
742 return result;
743}
744
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000745// getExistingValue - Look up the value specified by the provided type and
746// the provided ValID. If the value exists and has already been defined, return
747// it. Otherwise return null.
748//
749static Value *getExistingValue(const Type *Ty, const ValID &D) {
750 if (isa<FunctionType>(Ty)) {
751 error("Functions are not values and must be referenced as pointers");
752 }
753
754 switch (D.Type) {
755 case ValID::NumberVal: { // Is it a numbered definition?
756 unsigned Num = (unsigned)D.Num;
757
758 // Module constants occupy the lowest numbered slots...
759 std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
760 if (VI != CurModule.Values.end()) {
761 if (Num < VI->second.size())
762 return VI->second[Num];
763 Num -= VI->second.size();
764 }
765
766 // Make sure that our type is within bounds
767 VI = CurFun.Values.find(Ty);
768 if (VI == CurFun.Values.end()) return 0;
769
770 // Check that the number is within bounds...
771 if (VI->second.size() <= Num) return 0;
772
773 return VI->second[Num];
774 }
775
776 case ValID::NameVal: { // Is it a named definition?
777 // Get the name out of the ID
778 RenameMapKey Key = makeRenameMapKey(D.Name, Ty, D.S);
779 Value *V = 0;
780 if (inFunctionScope()) {
781 // See if the name was renamed
782 RenameMapType::const_iterator I = CurFun.RenameMap.find(Key);
783 std::string LookupName;
784 if (I != CurFun.RenameMap.end())
785 LookupName = I->second;
786 else
787 LookupName = D.Name;
788 ValueSymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable();
789 V = SymTab.lookup(LookupName);
790 if (V && V->getType() != Ty)
Duncan Sandsf5588dc2007-11-27 13:23:08 +0000791 V = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000792 }
793 if (!V) {
794 RenameMapType::const_iterator I = CurModule.RenameMap.find(Key);
795 std::string LookupName;
796 if (I != CurModule.RenameMap.end())
797 LookupName = I->second;
798 else
799 LookupName = D.Name;
800 V = CurModule.CurrentModule->getValueSymbolTable().lookup(LookupName);
801 if (V && V->getType() != Ty)
Duncan Sandsf5588dc2007-11-27 13:23:08 +0000802 V = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000803 }
804 if (!V)
805 return 0;
806
807 D.destroy(); // Free old strdup'd memory...
808 return V;
809 }
810
811 // Check to make sure that "Ty" is an integral type, and that our
812 // value will fit into the specified type...
813 case ValID::ConstSIntVal: // Is it a constant pool reference??
814 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
815 error("Signed integral constant '" + itostr(D.ConstPool64) +
816 "' is invalid for type '" + Ty->getDescription() + "'");
817 }
818 return ConstantInt::get(Ty, D.ConstPool64);
819
820 case ValID::ConstUIntVal: // Is it an unsigned const pool reference?
821 if (!ConstantInt::isValueValidForType(Ty, D.UConstPool64)) {
822 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64))
823 error("Integral constant '" + utostr(D.UConstPool64) +
824 "' is invalid or out of range");
825 else // This is really a signed reference. Transmogrify.
826 return ConstantInt::get(Ty, D.ConstPool64);
827 } else
828 return ConstantInt::get(Ty, D.UConstPool64);
829
830 case ValID::ConstFPVal: // Is it a floating point const pool reference?
Dale Johannesen3afee192007-09-07 21:07:57 +0000831 if (!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000832 error("FP constant invalid for type");
Dale Johannesen3afee192007-09-07 21:07:57 +0000833 // Lexer has no type info, so builds all FP constants as double.
834 // Fix this here.
835 if (Ty==Type::FloatTy)
836 D.ConstPoolFP->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
837 return ConstantFP::get(Ty, *D.ConstPoolFP);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000838
839 case ValID::ConstNullVal: // Is it a null value?
840 if (!isa<PointerType>(Ty))
841 error("Cannot create a a non pointer null");
842 return ConstantPointerNull::get(cast<PointerType>(Ty));
843
844 case ValID::ConstUndefVal: // Is it an undef value?
845 return UndefValue::get(Ty);
846
847 case ValID::ConstZeroVal: // Is it a zero value?
848 return Constant::getNullValue(Ty);
849
850 case ValID::ConstantVal: // Fully resolved constant?
851 if (D.ConstantValue->getType() != Ty)
852 error("Constant expression type different from required type");
853 return D.ConstantValue;
854
855 case ValID::InlineAsmVal: { // Inline asm expression
856 const PointerType *PTy = dyn_cast<PointerType>(Ty);
857 const FunctionType *FTy =
858 PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
859 if (!FTy || !InlineAsm::Verify(FTy, D.IAD->Constraints))
860 error("Invalid type for asm constraint string");
861 InlineAsm *IA = InlineAsm::get(FTy, D.IAD->AsmString, D.IAD->Constraints,
862 D.IAD->HasSideEffects);
863 D.destroy(); // Free InlineAsmDescriptor.
864 return IA;
865 }
866 default:
867 assert(0 && "Unhandled case");
868 return 0;
869 } // End of switch
870
871 assert(0 && "Unhandled case");
872 return 0;
873}
874
875// getVal - This function is identical to getExistingValue, except that if a
876// value is not already defined, it "improvises" by creating a placeholder var
877// that looks and acts just like the requested variable. When the value is
878// defined later, all uses of the placeholder variable are replaced with the
879// real thing.
880//
881static Value *getVal(const Type *Ty, const ValID &ID) {
882 if (Ty == Type::LabelTy)
883 error("Cannot use a basic block here");
884
885 // See if the value has already been defined.
886 Value *V = getExistingValue(Ty, ID);
887 if (V) return V;
888
889 if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty))
890 error("Invalid use of a composite type");
891
892 // If we reached here, we referenced either a symbol that we don't know about
893 // or an id number that hasn't been read yet. We may be referencing something
894 // forward, so just create an entry to be resolved later and get to it...
895 V = new Argument(Ty);
896
897 // Remember where this forward reference came from. FIXME, shouldn't we try
898 // to recycle these things??
899 CurModule.PlaceHolderInfo.insert(
900 std::make_pair(V, std::make_pair(ID, Upgradelineno)));
901
902 if (inFunctionScope())
903 InsertValue(V, CurFun.LateResolveValues);
904 else
905 InsertValue(V, CurModule.LateResolveValues);
906 return V;
907}
908
909/// @brief This just makes any name given to it unique, up to MAX_UINT times.
910static std::string makeNameUnique(const std::string& Name) {
911 static unsigned UniqueNameCounter = 1;
912 std::string Result(Name);
913 Result += ".upgrd." + llvm::utostr(UniqueNameCounter++);
914 return Result;
915}
916
917/// getBBVal - This is used for two purposes:
918/// * If isDefinition is true, a new basic block with the specified ID is being
919/// defined.
920/// * If isDefinition is true, this is a reference to a basic block, which may
921/// or may not be a forward reference.
922///
923static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
924 assert(inFunctionScope() && "Can't get basic block at global scope");
925
926 std::string Name;
927 BasicBlock *BB = 0;
928 switch (ID.Type) {
929 default:
930 error("Illegal label reference " + ID.getName());
931 break;
932 case ValID::NumberVal: // Is it a numbered definition?
933 if (unsigned(ID.Num) >= CurFun.NumberedBlocks.size())
934 CurFun.NumberedBlocks.resize(ID.Num+1);
935 BB = CurFun.NumberedBlocks[ID.Num];
936 break;
937 case ValID::NameVal: // Is it a named definition?
938 Name = ID.Name;
939 if (Value *N = CurFun.CurrentFunction->getValueSymbolTable().lookup(Name)) {
940 if (N->getType() != Type::LabelTy) {
941 // Register names didn't use to conflict with basic block names
942 // because of type planes. Now they all have to be unique. So, we just
943 // rename the register and treat this name as if no basic block
944 // had been found.
945 RenameMapKey Key = makeRenameMapKey(ID.Name, N->getType(), ID.S);
946 N->setName(makeNameUnique(N->getName()));
947 CurModule.RenameMap[Key] = N->getName();
948 BB = 0;
949 } else {
950 BB = cast<BasicBlock>(N);
951 }
952 }
953 break;
954 }
955
956 // See if the block has already been defined.
957 if (BB) {
958 // If this is the definition of the block, make sure the existing value was
959 // just a forward reference. If it was a forward reference, there will be
960 // an entry for it in the PlaceHolderInfo map.
961 if (isDefinition && !CurFun.BBForwardRefs.erase(BB))
962 // The existing value was a definition, not a forward reference.
963 error("Redefinition of label " + ID.getName());
964
965 ID.destroy(); // Free strdup'd memory.
966 return BB;
967 }
968
969 // Otherwise this block has not been seen before.
970 BB = new BasicBlock("", CurFun.CurrentFunction);
971 if (ID.Type == ValID::NameVal) {
972 BB->setName(ID.Name);
973 } else {
974 CurFun.NumberedBlocks[ID.Num] = BB;
975 }
976
977 // If this is not a definition, keep track of it so we can use it as a forward
978 // reference.
979 if (!isDefinition) {
980 // Remember where this forward reference came from.
981 CurFun.BBForwardRefs[BB] = std::make_pair(ID, Upgradelineno);
982 } else {
983 // The forward declaration could have been inserted anywhere in the
984 // function: insert it into the correct place now.
985 CurFun.CurrentFunction->getBasicBlockList().remove(BB);
986 CurFun.CurrentFunction->getBasicBlockList().push_back(BB);
987 }
988 ID.destroy();
989 return BB;
990}
991
992
993//===----------------------------------------------------------------------===//
994// Code to handle forward references in instructions
995//===----------------------------------------------------------------------===//
996//
997// This code handles the late binding needed with statements that reference
998// values not defined yet... for example, a forward branch, or the PHI node for
999// a loop body.
1000//
1001// This keeps a table (CurFun.LateResolveValues) of all such forward references
1002// and back patchs after we are done.
1003//
1004
1005// ResolveDefinitions - If we could not resolve some defs at parsing
1006// time (forward branches, phi functions for loops, etc...) resolve the
1007// defs now...
1008//
1009static void
1010ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
1011 std::map<const Type*,ValueList> *FutureLateResolvers) {
1012
1013 // Loop over LateResolveDefs fixing up stuff that couldn't be resolved
1014 for (std::map<const Type*,ValueList>::iterator LRI = LateResolvers.begin(),
1015 E = LateResolvers.end(); LRI != E; ++LRI) {
1016 const Type* Ty = LRI->first;
1017 ValueList &List = LRI->second;
1018 while (!List.empty()) {
1019 Value *V = List.back();
1020 List.pop_back();
1021
1022 std::map<Value*, std::pair<ValID, int> >::iterator PHI =
1023 CurModule.PlaceHolderInfo.find(V);
1024 assert(PHI != CurModule.PlaceHolderInfo.end() && "Placeholder error");
1025
1026 ValID &DID = PHI->second.first;
1027
1028 Value *TheRealValue = getExistingValue(Ty, DID);
1029 if (TheRealValue) {
1030 V->replaceAllUsesWith(TheRealValue);
1031 delete V;
1032 CurModule.PlaceHolderInfo.erase(PHI);
1033 } else if (FutureLateResolvers) {
1034 // Functions have their unresolved items forwarded to the module late
1035 // resolver table
1036 InsertValue(V, *FutureLateResolvers);
1037 } else {
1038 if (DID.Type == ValID::NameVal) {
1039 error("Reference to an invalid definition: '" + DID.getName() +
1040 "' of type '" + V->getType()->getDescription() + "'",
1041 PHI->second.second);
1042 return;
1043 } else {
1044 error("Reference to an invalid definition: #" +
1045 itostr(DID.Num) + " of type '" +
1046 V->getType()->getDescription() + "'", PHI->second.second);
1047 return;
1048 }
1049 }
1050 }
1051 }
1052
1053 LateResolvers.clear();
1054}
1055
1056/// This function is used for type resolution and upref handling. When a type
1057/// becomes concrete, this function is called to adjust the signedness for the
1058/// concrete type.
1059static void ResolveTypeSign(const Type* oldTy, const Signedness &Sign) {
1060 std::string TyName = CurModule.CurrentModule->getTypeName(oldTy);
1061 if (!TyName.empty())
1062 CurModule.NamedTypeSigns[TyName] = Sign;
1063}
1064
1065/// ResolveTypeTo - A brand new type was just declared. This means that (if
1066/// name is not null) things referencing Name can be resolved. Otherwise,
1067/// things refering to the number can be resolved. Do this now.
1068static void ResolveTypeTo(char *Name, const Type *ToTy, const Signedness& Sign){
1069 ValID D;
1070 if (Name)
1071 D = ValID::create(Name);
1072 else
1073 D = ValID::create((int)CurModule.Types.size());
1074 D.S.copy(Sign);
1075
1076 if (Name)
1077 CurModule.NamedTypeSigns[Name] = Sign;
1078
1079 std::map<ValID, PATypeHolder>::iterator I =
1080 CurModule.LateResolveTypes.find(D);
1081 if (I != CurModule.LateResolveTypes.end()) {
1082 const Type *OldTy = I->second.get();
1083 ((DerivedType*)OldTy)->refineAbstractTypeTo(ToTy);
1084 CurModule.LateResolveTypes.erase(I);
1085 }
1086}
1087
1088/// This is the implementation portion of TypeHasInteger. It traverses the
1089/// type given, avoiding recursive types, and returns true as soon as it finds
1090/// an integer type. If no integer type is found, it returns false.
1091static bool TypeHasIntegerI(const Type *Ty, std::vector<const Type*> Stack) {
1092 // Handle some easy cases
1093 if (Ty->isPrimitiveType() || (Ty->getTypeID() == Type::OpaqueTyID))
1094 return false;
1095 if (Ty->isInteger())
1096 return true;
1097 if (const SequentialType *STy = dyn_cast<SequentialType>(Ty))
1098 return STy->getElementType()->isInteger();
1099
1100 // Avoid type structure recursion
1101 for (std::vector<const Type*>::iterator I = Stack.begin(), E = Stack.end();
1102 I != E; ++I)
1103 if (Ty == *I)
1104 return false;
1105
1106 // Push us on the type stack
1107 Stack.push_back(Ty);
1108
1109 if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
1110 if (TypeHasIntegerI(FTy->getReturnType(), Stack))
1111 return true;
1112 FunctionType::param_iterator I = FTy->param_begin();
1113 FunctionType::param_iterator E = FTy->param_end();
1114 for (; I != E; ++I)
1115 if (TypeHasIntegerI(*I, Stack))
1116 return true;
1117 return false;
1118 } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
1119 StructType::element_iterator I = STy->element_begin();
1120 StructType::element_iterator E = STy->element_end();
1121 for (; I != E; ++I) {
1122 if (TypeHasIntegerI(*I, Stack))
1123 return true;
1124 }
1125 return false;
1126 }
1127 // There shouldn't be anything else, but its definitely not integer
1128 assert(0 && "What type is this?");
1129 return false;
1130}
1131
1132/// This is the interface to TypeHasIntegerI. It just provides the type stack,
1133/// to avoid recursion, and then calls TypeHasIntegerI.
1134static inline bool TypeHasInteger(const Type *Ty) {
1135 std::vector<const Type*> TyStack;
1136 return TypeHasIntegerI(Ty, TyStack);
1137}
1138
1139// setValueName - Set the specified value to the name given. The name may be
1140// null potentially, in which case this is a noop. The string passed in is
1141// assumed to be a malloc'd string buffer, and is free'd by this function.
1142//
1143static void setValueName(const ValueInfo &V, char *NameStr) {
1144 if (NameStr) {
1145 std::string Name(NameStr); // Copy string
1146 free(NameStr); // Free old string
1147
1148 if (V.V->getType() == Type::VoidTy) {
1149 error("Can't assign name '" + Name + "' to value with void type");
1150 return;
1151 }
1152
1153 assert(inFunctionScope() && "Must be in function scope");
1154
1155 // Search the function's symbol table for an existing value of this name
1156 ValueSymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
1157 Value* Existing = ST.lookup(Name);
1158 if (Existing) {
1159 // An existing value of the same name was found. This might have happened
1160 // because of the integer type planes collapsing in LLVM 2.0.
1161 if (Existing->getType() == V.V->getType() &&
1162 !TypeHasInteger(Existing->getType())) {
1163 // If the type does not contain any integers in them then this can't be
1164 // a type plane collapsing issue. It truly is a redefinition and we
1165 // should error out as the assembly is invalid.
1166 error("Redefinition of value named '" + Name + "' of type '" +
1167 V.V->getType()->getDescription() + "'");
1168 return;
1169 }
1170 // In LLVM 2.0 we don't allow names to be re-used for any values in a
1171 // function, regardless of Type. Previously re-use of names was okay as
1172 // long as they were distinct types. With type planes collapsing because
1173 // of the signedness change and because of PR411, this can no longer be
1174 // supported. We must search the entire symbol table for a conflicting
1175 // name and make the name unique. No warning is needed as this can't
1176 // cause a problem.
1177 std::string NewName = makeNameUnique(Name);
1178 // We're changing the name but it will probably be used by other
1179 // instructions as operands later on. Consequently we have to retain
1180 // a mapping of the renaming that we're doing.
1181 RenameMapKey Key = makeRenameMapKey(Name, V.V->getType(), V.S);
1182 CurFun.RenameMap[Key] = NewName;
1183 Name = NewName;
1184 }
1185
1186 // Set the name.
1187 V.V->setName(Name);
1188 }
1189}
1190
1191/// ParseGlobalVariable - Handle parsing of a global. If Initializer is null,
1192/// this is a declaration, otherwise it is a definition.
1193static GlobalVariable *
1194ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
1195 bool isConstantGlobal, const Type *Ty,
1196 Constant *Initializer,
1197 const Signedness &Sign) {
1198 if (isa<FunctionType>(Ty))
1199 error("Cannot declare global vars of function type");
1200
Christopher Lambfb623c62007-12-17 01:17:35 +00001201 const PointerType *PTy = PointerType::getUnqual(Ty);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001202
1203 std::string Name;
1204 if (NameStr) {
1205 Name = NameStr; // Copy string
1206 free(NameStr); // Free old string
1207 }
1208
1209 // See if this global value was forward referenced. If so, recycle the
1210 // object.
1211 ValID ID;
1212 if (!Name.empty()) {
1213 ID = ValID::create((char*)Name.c_str());
1214 } else {
1215 ID = ValID::create((int)CurModule.Values[PTy].size());
1216 }
1217 ID.S.makeComposite(Sign);
1218
1219 if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) {
1220 // Move the global to the end of the list, from whereever it was
1221 // previously inserted.
1222 GlobalVariable *GV = cast<GlobalVariable>(FWGV);
1223 CurModule.CurrentModule->getGlobalList().remove(GV);
1224 CurModule.CurrentModule->getGlobalList().push_back(GV);
1225 GV->setInitializer(Initializer);
1226 GV->setLinkage(Linkage);
1227 GV->setConstant(isConstantGlobal);
1228 InsertValue(GV, CurModule.Values);
1229 return GV;
1230 }
1231
1232 // If this global has a name, check to see if there is already a definition
1233 // of this global in the module and emit warnings if there are conflicts.
1234 if (!Name.empty()) {
1235 // The global has a name. See if there's an existing one of the same name.
1236 if (CurModule.CurrentModule->getNamedGlobal(Name) ||
1237 CurModule.CurrentModule->getFunction(Name)) {
1238 // We found an existing global of the same name. This isn't allowed
1239 // in LLVM 2.0. Consequently, we must alter the name of the global so it
1240 // can at least compile. This can happen because of type planes
1241 // There is alread a global of the same name which means there is a
1242 // conflict. Let's see what we can do about it.
1243 std::string NewName(makeNameUnique(Name));
1244 if (Linkage != GlobalValue::InternalLinkage) {
1245 // The linkage of this gval is external so we can't reliably rename
1246 // it because it could potentially create a linking problem.
1247 // However, we can't leave the name conflict in the output either or
1248 // it won't assemble with LLVM 2.0. So, all we can do is rename
1249 // this one to something unique and emit a warning about the problem.
1250 warning("Renaming global variable '" + Name + "' to '" + NewName +
1251 "' may cause linkage errors");
1252 }
1253
1254 // Put the renaming in the global rename map
Christopher Lambfb623c62007-12-17 01:17:35 +00001255 RenameMapKey Key =
1256 makeRenameMapKey(Name, PointerType::getUnqual(Ty), ID.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001257 CurModule.RenameMap[Key] = NewName;
1258
1259 // Rename it
1260 Name = NewName;
1261 }
1262 }
1263
1264 // Otherwise there is no existing GV to use, create one now.
1265 GlobalVariable *GV =
1266 new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name,
1267 CurModule.CurrentModule);
1268 InsertValue(GV, CurModule.Values);
1269 // Remember the sign of this global.
1270 CurModule.NamedValueSigns[Name] = ID.S;
1271 return GV;
1272}
1273
1274// setTypeName - Set the specified type to the name given. The name may be
1275// null potentially, in which case this is a noop. The string passed in is
1276// assumed to be a malloc'd string buffer, and is freed by this function.
1277//
1278// This function returns true if the type has already been defined, but is
1279// allowed to be redefined in the specified context. If the name is a new name
1280// for the type plane, it is inserted and false is returned.
1281static bool setTypeName(const PATypeInfo& TI, char *NameStr) {
1282 assert(!inFunctionScope() && "Can't give types function-local names");
1283 if (NameStr == 0) return false;
1284
1285 std::string Name(NameStr); // Copy string
1286 free(NameStr); // Free old string
1287
1288 const Type* Ty = TI.PAT->get();
1289
1290 // We don't allow assigning names to void type
1291 if (Ty == Type::VoidTy) {
1292 error("Can't assign name '" + Name + "' to the void type");
1293 return false;
1294 }
1295
1296 // Set the type name, checking for conflicts as we do so.
1297 bool AlreadyExists = CurModule.CurrentModule->addTypeName(Name, Ty);
1298
1299 // Save the sign information for later use
1300 CurModule.NamedTypeSigns[Name] = TI.S;
1301
1302 if (AlreadyExists) { // Inserting a name that is already defined???
1303 const Type *Existing = CurModule.CurrentModule->getTypeByName(Name);
1304 assert(Existing && "Conflict but no matching type?");
1305
1306 // There is only one case where this is allowed: when we are refining an
1307 // opaque type. In this case, Existing will be an opaque type.
1308 if (const OpaqueType *OpTy = dyn_cast<OpaqueType>(Existing)) {
1309 // We ARE replacing an opaque type!
1310 const_cast<OpaqueType*>(OpTy)->refineAbstractTypeTo(Ty);
1311 return true;
1312 }
1313
1314 // Otherwise, this is an attempt to redefine a type. That's okay if
1315 // the redefinition is identical to the original. This will be so if
1316 // Existing and T point to the same Type object. In this one case we
1317 // allow the equivalent redefinition.
1318 if (Existing == Ty) return true; // Yes, it's equal.
1319
1320 // Any other kind of (non-equivalent) redefinition is an error.
1321 error("Redefinition of type named '" + Name + "' in the '" +
1322 Ty->getDescription() + "' type plane");
1323 }
1324
1325 return false;
1326}
1327
1328//===----------------------------------------------------------------------===//
1329// Code for handling upreferences in type names...
1330//
1331
1332// TypeContains - Returns true if Ty directly contains E in it.
1333//
1334static bool TypeContains(const Type *Ty, const Type *E) {
1335 return std::find(Ty->subtype_begin(), Ty->subtype_end(),
1336 E) != Ty->subtype_end();
1337}
1338
1339namespace {
1340 struct UpRefRecord {
1341 // NestingLevel - The number of nesting levels that need to be popped before
1342 // this type is resolved.
1343 unsigned NestingLevel;
1344
1345 // LastContainedTy - This is the type at the current binding level for the
1346 // type. Every time we reduce the nesting level, this gets updated.
1347 const Type *LastContainedTy;
1348
1349 // UpRefTy - This is the actual opaque type that the upreference is
1350 // represented with.
1351 OpaqueType *UpRefTy;
1352
1353 UpRefRecord(unsigned NL, OpaqueType *URTy)
1354 : NestingLevel(NL), LastContainedTy(URTy), UpRefTy(URTy) { }
1355 };
1356}
1357
1358// UpRefs - A list of the outstanding upreferences that need to be resolved.
1359static std::vector<UpRefRecord> UpRefs;
1360
1361/// HandleUpRefs - Every time we finish a new layer of types, this function is
1362/// called. It loops through the UpRefs vector, which is a list of the
1363/// currently active types. For each type, if the up reference is contained in
1364/// the newly completed type, we decrement the level count. When the level
1365/// count reaches zero, the upreferenced type is the type that is passed in:
1366/// thus we can complete the cycle.
1367///
1368static PATypeHolder HandleUpRefs(const Type *ty, const Signedness& Sign) {
1369 // If Ty isn't abstract, or if there are no up-references in it, then there is
1370 // nothing to resolve here.
1371 if (!ty->isAbstract() || UpRefs.empty()) return ty;
1372
1373 PATypeHolder Ty(ty);
1374 UR_OUT("Type '" << Ty->getDescription() <<
1375 "' newly formed. Resolving upreferences.\n" <<
1376 UpRefs.size() << " upreferences active!\n");
1377
1378 // If we find any resolvable upreferences (i.e., those whose NestingLevel goes
1379 // to zero), we resolve them all together before we resolve them to Ty. At
1380 // the end of the loop, if there is anything to resolve to Ty, it will be in
1381 // this variable.
1382 OpaqueType *TypeToResolve = 0;
1383
1384 unsigned i = 0;
1385 for (; i != UpRefs.size(); ++i) {
1386 UR_OUT(" UR#" << i << " - TypeContains(" << Ty->getDescription() << ", "
1387 << UpRefs[i].UpRefTy->getDescription() << ") = "
1388 << (TypeContains(Ty, UpRefs[i].UpRefTy) ? "true" : "false") << "\n");
1389 if (TypeContains(Ty, UpRefs[i].LastContainedTy)) {
1390 // Decrement level of upreference
1391 unsigned Level = --UpRefs[i].NestingLevel;
1392 UpRefs[i].LastContainedTy = Ty;
1393 UR_OUT(" Uplevel Ref Level = " << Level << "\n");
1394 if (Level == 0) { // Upreference should be resolved!
1395 if (!TypeToResolve) {
1396 TypeToResolve = UpRefs[i].UpRefTy;
1397 } else {
1398 UR_OUT(" * Resolving upreference for "
1399 << UpRefs[i].UpRefTy->getDescription() << "\n";
1400 std::string OldName = UpRefs[i].UpRefTy->getDescription());
1401 ResolveTypeSign(UpRefs[i].UpRefTy, Sign);
1402 UpRefs[i].UpRefTy->refineAbstractTypeTo(TypeToResolve);
1403 UR_OUT(" * Type '" << OldName << "' refined upreference to: "
1404 << (const void*)Ty << ", " << Ty->getDescription() << "\n");
1405 }
1406 UpRefs.erase(UpRefs.begin()+i); // Remove from upreference list...
1407 --i; // Do not skip the next element...
1408 }
1409 }
1410 }
1411
1412 if (TypeToResolve) {
1413 UR_OUT(" * Resolving upreference for "
1414 << UpRefs[i].UpRefTy->getDescription() << "\n";
1415 std::string OldName = TypeToResolve->getDescription());
1416 ResolveTypeSign(TypeToResolve, Sign);
1417 TypeToResolve->refineAbstractTypeTo(Ty);
1418 }
1419
1420 return Ty;
1421}
1422
1423bool Signedness::operator<(const Signedness &that) const {
1424 if (isNamed()) {
1425 if (that.isNamed())
1426 return *(this->name) < *(that.name);
1427 else
1428 return CurModule.NamedTypeSigns[*name] < that;
1429 } else if (that.isNamed()) {
1430 return *this < CurModule.NamedTypeSigns[*that.name];
1431 }
1432
1433 if (isComposite() && that.isComposite()) {
1434 if (sv->size() == that.sv->size()) {
1435 SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1436 SignVector::const_iterator thatI = that.sv->begin(),
1437 thatE = that.sv->end();
1438 for (; thisI != thisE; ++thisI, ++thatI) {
1439 if (*thisI < *thatI)
1440 return true;
1441 else if (!(*thisI == *thatI))
1442 return false;
1443 }
1444 return false;
1445 }
1446 return sv->size() < that.sv->size();
1447 }
1448 return kind < that.kind;
1449}
1450
1451bool Signedness::operator==(const Signedness &that) const {
1452 if (isNamed())
1453 if (that.isNamed())
1454 return *(this->name) == *(that.name);
1455 else
1456 return CurModule.NamedTypeSigns[*(this->name)] == that;
1457 else if (that.isNamed())
1458 return *this == CurModule.NamedTypeSigns[*(that.name)];
1459 if (isComposite() && that.isComposite()) {
1460 if (sv->size() == that.sv->size()) {
1461 SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1462 SignVector::const_iterator thatI = that.sv->begin(),
1463 thatE = that.sv->end();
1464 for (; thisI != thisE; ++thisI, ++thatI) {
1465 if (!(*thisI == *thatI))
1466 return false;
1467 }
1468 return true;
1469 }
1470 return false;
1471 }
1472 return kind == that.kind;
1473}
1474
1475void Signedness::copy(const Signedness &that) {
1476 if (that.isNamed()) {
1477 kind = Named;
1478 name = new std::string(*that.name);
1479 } else if (that.isComposite()) {
1480 kind = Composite;
1481 sv = new SignVector();
1482 *sv = *that.sv;
1483 } else {
1484 kind = that.kind;
1485 sv = 0;
1486 }
1487}
1488
1489void Signedness::destroy() {
1490 if (isNamed()) {
1491 delete name;
1492 } else if (isComposite()) {
1493 delete sv;
1494 }
1495}
1496
1497#ifndef NDEBUG
1498void Signedness::dump() const {
1499 if (isComposite()) {
1500 if (sv->size() == 1) {
1501 (*sv)[0].dump();
1502 std::cerr << "*";
1503 } else {
1504 std::cerr << "{ " ;
1505 for (unsigned i = 0; i < sv->size(); ++i) {
1506 if (i != 0)
1507 std::cerr << ", ";
1508 (*sv)[i].dump();
1509 }
1510 std::cerr << "} " ;
1511 }
1512 } else if (isNamed()) {
1513 std::cerr << *name;
1514 } else if (isSigned()) {
1515 std::cerr << "S";
1516 } else if (isUnsigned()) {
1517 std::cerr << "U";
1518 } else
1519 std::cerr << ".";
1520}
1521#endif
1522
1523static inline Instruction::TermOps
1524getTermOp(TermOps op) {
1525 switch (op) {
1526 default : assert(0 && "Invalid OldTermOp");
1527 case RetOp : return Instruction::Ret;
1528 case BrOp : return Instruction::Br;
1529 case SwitchOp : return Instruction::Switch;
1530 case InvokeOp : return Instruction::Invoke;
1531 case UnwindOp : return Instruction::Unwind;
1532 case UnreachableOp: return Instruction::Unreachable;
1533 }
1534}
1535
1536static inline Instruction::BinaryOps
1537getBinaryOp(BinaryOps op, const Type *Ty, const Signedness& Sign) {
1538 switch (op) {
1539 default : assert(0 && "Invalid OldBinaryOps");
1540 case SetEQ :
1541 case SetNE :
1542 case SetLE :
1543 case SetGE :
1544 case SetLT :
1545 case SetGT : assert(0 && "Should use getCompareOp");
1546 case AddOp : return Instruction::Add;
1547 case SubOp : return Instruction::Sub;
1548 case MulOp : return Instruction::Mul;
1549 case DivOp : {
1550 // This is an obsolete instruction so we must upgrade it based on the
1551 // types of its operands.
1552 bool isFP = Ty->isFloatingPoint();
1553 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
1554 // If its a vector type we want to use the element type
1555 isFP = PTy->getElementType()->isFloatingPoint();
1556 if (isFP)
1557 return Instruction::FDiv;
1558 else if (Sign.isSigned())
1559 return Instruction::SDiv;
1560 return Instruction::UDiv;
1561 }
1562 case UDivOp : return Instruction::UDiv;
1563 case SDivOp : return Instruction::SDiv;
1564 case FDivOp : return Instruction::FDiv;
1565 case RemOp : {
1566 // This is an obsolete instruction so we must upgrade it based on the
1567 // types of its operands.
1568 bool isFP = Ty->isFloatingPoint();
1569 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
1570 // If its a vector type we want to use the element type
1571 isFP = PTy->getElementType()->isFloatingPoint();
1572 // Select correct opcode
1573 if (isFP)
1574 return Instruction::FRem;
1575 else if (Sign.isSigned())
1576 return Instruction::SRem;
1577 return Instruction::URem;
1578 }
1579 case URemOp : return Instruction::URem;
1580 case SRemOp : return Instruction::SRem;
1581 case FRemOp : return Instruction::FRem;
1582 case LShrOp : return Instruction::LShr;
1583 case AShrOp : return Instruction::AShr;
1584 case ShlOp : return Instruction::Shl;
1585 case ShrOp :
1586 if (Sign.isSigned())
1587 return Instruction::AShr;
1588 return Instruction::LShr;
1589 case AndOp : return Instruction::And;
1590 case OrOp : return Instruction::Or;
1591 case XorOp : return Instruction::Xor;
1592 }
1593}
1594
1595static inline Instruction::OtherOps
1596getCompareOp(BinaryOps op, unsigned short &predicate, const Type* &Ty,
1597 const Signedness &Sign) {
1598 bool isSigned = Sign.isSigned();
1599 bool isFP = Ty->isFloatingPoint();
1600 switch (op) {
1601 default : assert(0 && "Invalid OldSetCC");
1602 case SetEQ :
1603 if (isFP) {
1604 predicate = FCmpInst::FCMP_OEQ;
1605 return Instruction::FCmp;
1606 } else {
1607 predicate = ICmpInst::ICMP_EQ;
1608 return Instruction::ICmp;
1609 }
1610 case SetNE :
1611 if (isFP) {
1612 predicate = FCmpInst::FCMP_UNE;
1613 return Instruction::FCmp;
1614 } else {
1615 predicate = ICmpInst::ICMP_NE;
1616 return Instruction::ICmp;
1617 }
1618 case SetLE :
1619 if (isFP) {
1620 predicate = FCmpInst::FCMP_OLE;
1621 return Instruction::FCmp;
1622 } else {
1623 if (isSigned)
1624 predicate = ICmpInst::ICMP_SLE;
1625 else
1626 predicate = ICmpInst::ICMP_ULE;
1627 return Instruction::ICmp;
1628 }
1629 case SetGE :
1630 if (isFP) {
1631 predicate = FCmpInst::FCMP_OGE;
1632 return Instruction::FCmp;
1633 } else {
1634 if (isSigned)
1635 predicate = ICmpInst::ICMP_SGE;
1636 else
1637 predicate = ICmpInst::ICMP_UGE;
1638 return Instruction::ICmp;
1639 }
1640 case SetLT :
1641 if (isFP) {
1642 predicate = FCmpInst::FCMP_OLT;
1643 return Instruction::FCmp;
1644 } else {
1645 if (isSigned)
1646 predicate = ICmpInst::ICMP_SLT;
1647 else
1648 predicate = ICmpInst::ICMP_ULT;
1649 return Instruction::ICmp;
1650 }
1651 case SetGT :
1652 if (isFP) {
1653 predicate = FCmpInst::FCMP_OGT;
1654 return Instruction::FCmp;
1655 } else {
1656 if (isSigned)
1657 predicate = ICmpInst::ICMP_SGT;
1658 else
1659 predicate = ICmpInst::ICMP_UGT;
1660 return Instruction::ICmp;
1661 }
1662 }
1663}
1664
1665static inline Instruction::MemoryOps getMemoryOp(MemoryOps op) {
1666 switch (op) {
1667 default : assert(0 && "Invalid OldMemoryOps");
1668 case MallocOp : return Instruction::Malloc;
1669 case FreeOp : return Instruction::Free;
1670 case AllocaOp : return Instruction::Alloca;
1671 case LoadOp : return Instruction::Load;
1672 case StoreOp : return Instruction::Store;
1673 case GetElementPtrOp : return Instruction::GetElementPtr;
1674 }
1675}
1676
1677static inline Instruction::OtherOps
1678getOtherOp(OtherOps op, const Signedness &Sign) {
1679 switch (op) {
1680 default : assert(0 && "Invalid OldOtherOps");
1681 case PHIOp : return Instruction::PHI;
1682 case CallOp : return Instruction::Call;
1683 case SelectOp : return Instruction::Select;
1684 case UserOp1 : return Instruction::UserOp1;
1685 case UserOp2 : return Instruction::UserOp2;
1686 case VAArg : return Instruction::VAArg;
1687 case ExtractElementOp : return Instruction::ExtractElement;
1688 case InsertElementOp : return Instruction::InsertElement;
1689 case ShuffleVectorOp : return Instruction::ShuffleVector;
1690 case ICmpOp : return Instruction::ICmp;
1691 case FCmpOp : return Instruction::FCmp;
1692 };
1693}
1694
1695static inline Value*
1696getCast(CastOps op, Value *Src, const Signedness &SrcSign, const Type *DstTy,
1697 const Signedness &DstSign, bool ForceInstruction = false) {
1698 Instruction::CastOps Opcode;
1699 const Type* SrcTy = Src->getType();
1700 if (op == CastOp) {
1701 if (SrcTy->isFloatingPoint() && isa<PointerType>(DstTy)) {
1702 // fp -> ptr cast is no longer supported but we must upgrade this
1703 // by doing a double cast: fp -> int -> ptr
1704 SrcTy = Type::Int64Ty;
1705 Opcode = Instruction::IntToPtr;
1706 if (isa<Constant>(Src)) {
1707 Src = ConstantExpr::getCast(Instruction::FPToUI,
1708 cast<Constant>(Src), SrcTy);
1709 } else {
1710 std::string NewName(makeNameUnique(Src->getName()));
1711 Src = new FPToUIInst(Src, SrcTy, NewName, CurBB);
1712 }
1713 } else if (isa<IntegerType>(DstTy) &&
1714 cast<IntegerType>(DstTy)->getBitWidth() == 1) {
1715 // cast type %x to bool was previously defined as setne type %x, null
1716 // The cast semantic is now to truncate, not compare so we must retain
1717 // the original intent by replacing the cast with a setne
1718 Constant* Null = Constant::getNullValue(SrcTy);
1719 Instruction::OtherOps Opcode = Instruction::ICmp;
1720 unsigned short predicate = ICmpInst::ICMP_NE;
1721 if (SrcTy->isFloatingPoint()) {
1722 Opcode = Instruction::FCmp;
1723 predicate = FCmpInst::FCMP_ONE;
1724 } else if (!SrcTy->isInteger() && !isa<PointerType>(SrcTy)) {
1725 error("Invalid cast to bool");
1726 }
1727 if (isa<Constant>(Src) && !ForceInstruction)
1728 return ConstantExpr::getCompare(predicate, cast<Constant>(Src), Null);
1729 else
1730 return CmpInst::create(Opcode, predicate, Src, Null);
1731 }
1732 // Determine the opcode to use by calling CastInst::getCastOpcode
1733 Opcode =
1734 CastInst::getCastOpcode(Src, SrcSign.isSigned(), DstTy,
1735 DstSign.isSigned());
1736
1737 } else switch (op) {
1738 default: assert(0 && "Invalid cast token");
1739 case TruncOp: Opcode = Instruction::Trunc; break;
1740 case ZExtOp: Opcode = Instruction::ZExt; break;
1741 case SExtOp: Opcode = Instruction::SExt; break;
1742 case FPTruncOp: Opcode = Instruction::FPTrunc; break;
1743 case FPExtOp: Opcode = Instruction::FPExt; break;
1744 case FPToUIOp: Opcode = Instruction::FPToUI; break;
1745 case FPToSIOp: Opcode = Instruction::FPToSI; break;
1746 case UIToFPOp: Opcode = Instruction::UIToFP; break;
1747 case SIToFPOp: Opcode = Instruction::SIToFP; break;
1748 case PtrToIntOp: Opcode = Instruction::PtrToInt; break;
1749 case IntToPtrOp: Opcode = Instruction::IntToPtr; break;
1750 case BitCastOp: Opcode = Instruction::BitCast; break;
1751 }
1752
1753 if (isa<Constant>(Src) && !ForceInstruction)
1754 return ConstantExpr::getCast(Opcode, cast<Constant>(Src), DstTy);
1755 return CastInst::create(Opcode, Src, DstTy);
1756}
1757
1758static Instruction *
1759upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
1760 std::vector<Value*>& Args) {
1761
1762 std::string Name = ID.Type == ValID::NameVal ? ID.Name : "";
1763 if (Name.length() <= 5 || Name[0] != 'l' || Name[1] != 'l' ||
1764 Name[2] != 'v' || Name[3] != 'm' || Name[4] != '.')
1765 return 0;
1766
1767 switch (Name[5]) {
1768 case 'i':
1769 if (Name == "llvm.isunordered.f32" || Name == "llvm.isunordered.f64") {
1770 if (Args.size() != 2)
1771 error("Invalid prototype for " + Name);
1772 return new FCmpInst(FCmpInst::FCMP_UNO, Args[0], Args[1]);
1773 }
1774 break;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001775
1776 case 'v' : {
Christopher Lambfb623c62007-12-17 01:17:35 +00001777 const Type* PtrTy = PointerType::getUnqual(Type::Int8Ty);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001778 std::vector<const Type*> Params;
1779 if (Name == "llvm.va_start" || Name == "llvm.va_end") {
1780 if (Args.size() != 1)
1781 error("Invalid prototype for " + Name + " prototype");
1782 Params.push_back(PtrTy);
1783 const FunctionType *FTy =
1784 FunctionType::get(Type::VoidTy, Params, false);
Christopher Lambfb623c62007-12-17 01:17:35 +00001785 const PointerType *PFTy = PointerType::getUnqual(FTy);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001786 Value* Func = getVal(PFTy, ID);
1787 Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
David Greene9145dd22007-08-01 03:59:32 +00001788 return new CallInst(Func, Args.begin(), Args.end());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001789 } else if (Name == "llvm.va_copy") {
1790 if (Args.size() != 2)
1791 error("Invalid prototype for " + Name + " prototype");
1792 Params.push_back(PtrTy);
1793 Params.push_back(PtrTy);
1794 const FunctionType *FTy =
1795 FunctionType::get(Type::VoidTy, Params, false);
Christopher Lambfb623c62007-12-17 01:17:35 +00001796 const PointerType *PFTy = PointerType::getUnqual(FTy);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001797 Value* Func = getVal(PFTy, ID);
1798 std::string InstName0(makeNameUnique("va0"));
1799 std::string InstName1(makeNameUnique("va1"));
1800 Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
1801 Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
David Greene9145dd22007-08-01 03:59:32 +00001802 return new CallInst(Func, Args.begin(), Args.end());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001803 }
1804 }
1805 }
1806 return 0;
1807}
1808
1809const Type* upgradeGEPCEIndices(const Type* PTy,
1810 std::vector<ValueInfo> *Indices,
1811 std::vector<Constant*> &Result) {
1812 const Type *Ty = PTy;
1813 Result.clear();
1814 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1815 Constant *Index = cast<Constant>((*Indices)[i].V);
1816
1817 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1818 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1819 // struct indices to i32 struct indices with ZExt for compatibility.
1820 if (CI->getBitWidth() < 32)
1821 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1822 }
1823
1824 if (isa<SequentialType>(Ty)) {
1825 // Make sure that unsigned SequentialType indices are zext'd to
1826 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1827 // all indices for SequentialType elements. We must retain the same
1828 // semantic (zext) for unsigned types.
1829 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
1830 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
1831 Index = ConstantExpr::getCast(Instruction::ZExt, Index,Type::Int64Ty);
1832 }
1833 }
1834 }
1835 Result.push_back(Index);
David Greene48556392007-09-04 18:46:50 +00001836 Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(),
1837 Result.end(),true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001838 if (!Ty)
1839 error("Index list invalid for constant getelementptr");
1840 }
1841 return Ty;
1842}
1843
1844const Type* upgradeGEPInstIndices(const Type* PTy,
1845 std::vector<ValueInfo> *Indices,
1846 std::vector<Value*> &Result) {
1847 const Type *Ty = PTy;
1848 Result.clear();
1849 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1850 Value *Index = (*Indices)[i].V;
1851
1852 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1853 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1854 // struct indices to i32 struct indices with ZExt for compatibility.
1855 if (CI->getBitWidth() < 32)
1856 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1857 }
1858
1859
1860 if (isa<StructType>(Ty)) { // Only change struct indices
1861 if (!isa<Constant>(Index)) {
1862 error("Invalid non-constant structure index");
1863 return 0;
1864 }
1865 } else {
1866 // Make sure that unsigned SequentialType indices are zext'd to
1867 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1868 // all indices for SequentialType elements. We must retain the same
1869 // semantic (zext) for unsigned types.
1870 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
1871 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
1872 if (isa<Constant>(Index))
1873 Index = ConstantExpr::getCast(Instruction::ZExt,
1874 cast<Constant>(Index), Type::Int64Ty);
1875 else
1876 Index = CastInst::create(Instruction::ZExt, Index, Type::Int64Ty,
1877 makeNameUnique("gep"), CurBB);
1878 }
1879 }
1880 }
1881 Result.push_back(Index);
David Greene48556392007-09-04 18:46:50 +00001882 Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(),
1883 Result.end(),true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001884 if (!Ty)
1885 error("Index list invalid for constant getelementptr");
1886 }
1887 return Ty;
1888}
1889
1890unsigned upgradeCallingConv(unsigned CC) {
1891 switch (CC) {
1892 case OldCallingConv::C : return CallingConv::C;
1893 case OldCallingConv::CSRet : return CallingConv::C;
1894 case OldCallingConv::Fast : return CallingConv::Fast;
1895 case OldCallingConv::Cold : return CallingConv::Cold;
1896 case OldCallingConv::X86_StdCall : return CallingConv::X86_StdCall;
1897 case OldCallingConv::X86_FastCall: return CallingConv::X86_FastCall;
1898 default:
1899 return CC;
1900 }
1901}
1902
1903Module* UpgradeAssembly(const std::string &infile, std::istream& in,
1904 bool debug, bool addAttrs)
1905{
1906 Upgradelineno = 1;
1907 CurFilename = infile;
1908 LexInput = &in;
1909 yydebug = debug;
1910 AddAttributes = addAttrs;
1911 ObsoleteVarArgs = false;
1912 NewVarArgs = false;
1913
1914 CurModule.CurrentModule = new Module(CurFilename);
1915
1916 // Check to make sure the parser succeeded
1917 if (yyparse()) {
1918 if (ParserResult)
1919 delete ParserResult;
1920 std::cerr << "llvm-upgrade: parse failed.\n";
1921 return 0;
1922 }
1923
1924 // Check to make sure that parsing produced a result
1925 if (!ParserResult) {
1926 std::cerr << "llvm-upgrade: no parse result.\n";
1927 return 0;
1928 }
1929
1930 // Reset ParserResult variable while saving its value for the result.
1931 Module *Result = ParserResult;
1932 ParserResult = 0;
1933
1934 //Not all functions use vaarg, so make a second check for ObsoleteVarArgs
1935 {
1936 Function* F;
1937 if ((F = Result->getFunction("llvm.va_start"))
1938 && F->getFunctionType()->getNumParams() == 0)
1939 ObsoleteVarArgs = true;
1940 if((F = Result->getFunction("llvm.va_copy"))
1941 && F->getFunctionType()->getNumParams() == 1)
1942 ObsoleteVarArgs = true;
1943 }
1944
1945 if (ObsoleteVarArgs && NewVarArgs) {
1946 error("This file is corrupt: it uses both new and old style varargs");
1947 return 0;
1948 }
1949
1950 if(ObsoleteVarArgs) {
1951 if(Function* F = Result->getFunction("llvm.va_start")) {
1952 if (F->arg_size() != 0) {
1953 error("Obsolete va_start takes 0 argument");
1954 return 0;
1955 }
1956
1957 //foo = va_start()
1958 // ->
1959 //bar = alloca typeof(foo)
1960 //va_start(bar)
1961 //foo = load bar
1962
1963 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1964 const Type* ArgTy = F->getFunctionType()->getReturnType();
Christopher Lambfb623c62007-12-17 01:17:35 +00001965 const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001966 Function* NF = cast<Function>(Result->getOrInsertFunction(
1967 "llvm.va_start", RetTy, ArgTyPtr, (Type *)0));
1968
1969 while (!F->use_empty()) {
1970 CallInst* CI = cast<CallInst>(F->use_back());
1971 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vastart.fix.1", CI);
1972 new CallInst(NF, bar, "", CI);
1973 Value* foo = new LoadInst(bar, "vastart.fix.2", CI);
1974 CI->replaceAllUsesWith(foo);
1975 CI->getParent()->getInstList().erase(CI);
1976 }
1977 Result->getFunctionList().erase(F);
1978 }
1979
1980 if(Function* F = Result->getFunction("llvm.va_end")) {
1981 if(F->arg_size() != 1) {
1982 error("Obsolete va_end takes 1 argument");
1983 return 0;
1984 }
1985
1986 //vaend foo
1987 // ->
1988 //bar = alloca 1 of typeof(foo)
1989 //vaend bar
1990 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1991 const Type* ArgTy = F->getFunctionType()->getParamType(0);
Christopher Lambfb623c62007-12-17 01:17:35 +00001992 const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001993 Function* NF = cast<Function>(Result->getOrInsertFunction(
1994 "llvm.va_end", RetTy, ArgTyPtr, (Type *)0));
1995
1996 while (!F->use_empty()) {
1997 CallInst* CI = cast<CallInst>(F->use_back());
1998 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vaend.fix.1", CI);
1999 new StoreInst(CI->getOperand(1), bar, CI);
2000 new CallInst(NF, bar, "", CI);
2001 CI->getParent()->getInstList().erase(CI);
2002 }
2003 Result->getFunctionList().erase(F);
2004 }
2005
2006 if(Function* F = Result->getFunction("llvm.va_copy")) {
2007 if(F->arg_size() != 1) {
2008 error("Obsolete va_copy takes 1 argument");
2009 return 0;
2010 }
2011 //foo = vacopy(bar)
2012 // ->
2013 //a = alloca 1 of typeof(foo)
2014 //b = alloca 1 of typeof(foo)
2015 //store bar -> b
2016 //vacopy(a, b)
2017 //foo = load a
2018
2019 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2020 const Type* ArgTy = F->getFunctionType()->getReturnType();
Christopher Lambfb623c62007-12-17 01:17:35 +00002021 const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002022 Function* NF = cast<Function>(Result->getOrInsertFunction(
2023 "llvm.va_copy", RetTy, ArgTyPtr, ArgTyPtr, (Type *)0));
2024
2025 while (!F->use_empty()) {
2026 CallInst* CI = cast<CallInst>(F->use_back());
David Greene48556392007-09-04 18:46:50 +00002027 Value *Args[2] = {
2028 new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI),
2029 new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI)
2030 };
David Greene9145dd22007-08-01 03:59:32 +00002031 new StoreInst(CI->getOperand(1), Args[1], CI);
David Greene48556392007-09-04 18:46:50 +00002032 new CallInst(NF, Args, Args + 2, "", CI);
David Greene9145dd22007-08-01 03:59:32 +00002033 Value* foo = new LoadInst(Args[0], "vacopy.fix.3", CI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002034 CI->replaceAllUsesWith(foo);
2035 CI->getParent()->getInstList().erase(CI);
2036 }
2037 Result->getFunctionList().erase(F);
2038 }
2039 }
2040
2041 return Result;
2042}
2043
2044} // end llvm namespace
2045
2046using namespace llvm;
2047
2048
Chris Lattnera62e8e42007-12-29 20:47:37 +00002049
2050/* Enabling traces. */
2051#ifndef YYDEBUG
2052# define YYDEBUG 0
2053#endif
2054
2055/* Enabling verbose error messages. */
2056#ifdef YYERROR_VERBOSE
2057# undef YYERROR_VERBOSE
2058# define YYERROR_VERBOSE 1
2059#else
2060# define YYERROR_VERBOSE 0
2061#endif
2062
2063/* Enabling the token table. */
2064#ifndef YYTOKEN_TABLE
2065# define YYTOKEN_TABLE 0
2066#endif
2067
2068#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
2069typedef union YYSTYPE
Chris Lattner1c8733e2008-03-12 17:45:29 +00002070#line 1680 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00002071{
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002072 llvm::Module *ModuleVal;
2073 llvm::Function *FunctionVal;
2074 std::pair<llvm::PATypeInfo, char*> *ArgVal;
2075 llvm::BasicBlock *BasicBlockVal;
2076 llvm::TermInstInfo TermInstVal;
2077 llvm::InstrInfo InstVal;
2078 llvm::ConstInfo ConstVal;
2079 llvm::ValueInfo ValueVal;
2080 llvm::PATypeInfo TypeVal;
2081 llvm::TypeInfo PrimType;
2082 llvm::PHIListInfo PHIList;
2083 std::list<llvm::PATypeInfo> *TypeList;
2084 std::vector<llvm::ValueInfo> *ValueList;
2085 std::vector<llvm::ConstInfo> *ConstVector;
2086
2087
2088 std::vector<std::pair<llvm::PATypeInfo,char*> > *ArgList;
2089 // Represent the RHS of PHI node
2090 std::vector<std::pair<llvm::Constant*, llvm::BasicBlock*> > *JumpTable;
2091
2092 llvm::GlobalValue::LinkageTypes Linkage;
2093 int64_t SInt64Val;
2094 uint64_t UInt64Val;
2095 int SIntVal;
2096 unsigned UIntVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00002097 llvm::APFloat *FPVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002098 bool BoolVal;
2099
2100 char *StrVal; // This memory is strdup'd!
2101 llvm::ValID ValIDVal; // strdup'd memory maybe!
2102
2103 llvm::BinaryOps BinaryOpVal;
2104 llvm::TermOps TermOpVal;
2105 llvm::MemoryOps MemOpVal;
2106 llvm::OtherOps OtherOpVal;
2107 llvm::CastOps CastOpVal;
2108 llvm::ICmpInst::Predicate IPred;
2109 llvm::FCmpInst::Predicate FPred;
2110 llvm::Module::Endianness Endianness;
Chris Lattnera62e8e42007-12-29 20:47:37 +00002111}
2112/* Line 193 of yacc.c. */
Chris Lattner1c8733e2008-03-12 17:45:29 +00002113#line 2114 "UpgradeParser.tab.c"
Chris Lattnera62e8e42007-12-29 20:47:37 +00002114 YYSTYPE;
2115# define yystype YYSTYPE /* obsolescent; will be withdrawn */
2116# define YYSTYPE_IS_DECLARED 1
2117# define YYSTYPE_IS_TRIVIAL 1
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002118#endif
2119
2120
2121
Chris Lattnera62e8e42007-12-29 20:47:37 +00002122/* Copy the second part of user declarations. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002123
2124
Chris Lattnera62e8e42007-12-29 20:47:37 +00002125/* Line 216 of yacc.c. */
Chris Lattner1c8733e2008-03-12 17:45:29 +00002126#line 2127 "UpgradeParser.tab.c"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002127
Chris Lattnera62e8e42007-12-29 20:47:37 +00002128#ifdef short
2129# undef short
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002130#endif
2131
Chris Lattnera62e8e42007-12-29 20:47:37 +00002132#ifdef YYTYPE_UINT8
2133typedef YYTYPE_UINT8 yytype_uint8;
David Greene48556392007-09-04 18:46:50 +00002134#else
Chris Lattnera62e8e42007-12-29 20:47:37 +00002135typedef unsigned char yytype_uint8;
David Greene48556392007-09-04 18:46:50 +00002136#endif
2137
Chris Lattnera62e8e42007-12-29 20:47:37 +00002138#ifdef YYTYPE_INT8
2139typedef YYTYPE_INT8 yytype_int8;
2140#elif (defined __STDC__ || defined __C99__FUNC__ \
2141 || defined __cplusplus || defined _MSC_VER)
2142typedef signed char yytype_int8;
2143#else
2144typedef short int yytype_int8;
2145#endif
2146
2147#ifdef YYTYPE_UINT16
2148typedef YYTYPE_UINT16 yytype_uint16;
2149#else
2150typedef unsigned short int yytype_uint16;
2151#endif
2152
2153#ifdef YYTYPE_INT16
2154typedef YYTYPE_INT16 yytype_int16;
2155#else
2156typedef short int yytype_int16;
2157#endif
2158
2159#ifndef YYSIZE_T
2160# ifdef __SIZE_TYPE__
2161# define YYSIZE_T __SIZE_TYPE__
2162# elif defined size_t
2163# define YYSIZE_T size_t
2164# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
2165 || defined __cplusplus || defined _MSC_VER)
2166# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
2167# define YYSIZE_T size_t
2168# else
2169# define YYSIZE_T unsigned int
2170# endif
2171#endif
2172
2173#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
2174
2175#ifndef YY_
2176# if defined YYENABLE_NLS && YYENABLE_NLS
2177# if ENABLE_NLS
2178# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
2179# define YY_(msgid) dgettext ("bison-runtime", msgid)
2180# endif
2181# endif
2182# ifndef YY_
2183# define YY_(msgid) msgid
2184# endif
2185#endif
2186
2187/* Suppress unused-variable warnings by "using" E. */
2188#if ! defined lint || defined __GNUC__
2189# define YYUSE(e) ((void) (e))
2190#else
2191# define YYUSE(e) /* empty */
2192#endif
2193
2194/* Identity function, used to suppress warnings about constant conditions. */
2195#ifndef lint
2196# define YYID(n) (n)
2197#else
2198#if (defined __STDC__ || defined __C99__FUNC__ \
2199 || defined __cplusplus || defined _MSC_VER)
2200static int
2201YYID (int i)
2202#else
2203static int
2204YYID (i)
2205 int i;
2206#endif
2207{
2208 return i;
2209}
2210#endif
2211
2212#if ! defined yyoverflow || YYERROR_VERBOSE
2213
2214/* The parser invokes alloca or malloc; define the necessary symbols. */
2215
2216# ifdef YYSTACK_USE_ALLOCA
2217# if YYSTACK_USE_ALLOCA
2218# ifdef __GNUC__
2219# define YYSTACK_ALLOC __builtin_alloca
2220# elif defined __BUILTIN_VA_ARG_INCR
2221# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
2222# elif defined _AIX
2223# define YYSTACK_ALLOC __alloca
2224# elif defined _MSC_VER
2225# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
2226# define alloca _alloca
2227# else
2228# define YYSTACK_ALLOC alloca
2229# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
2230 || defined __cplusplus || defined _MSC_VER)
2231# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
2232# ifndef _STDLIB_H
2233# define _STDLIB_H 1
2234# endif
2235# endif
2236# endif
2237# endif
2238# endif
2239
2240# ifdef YYSTACK_ALLOC
2241 /* Pacify GCC's `empty if-body' warning. */
2242# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
2243# ifndef YYSTACK_ALLOC_MAXIMUM
2244 /* The OS might guarantee only one guard page at the bottom of the stack,
2245 and a page size can be as small as 4096 bytes. So we cannot safely
2246 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
2247 to allow for a few compiler-allocated temporary stack slots. */
2248# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
2249# endif
2250# else
2251# define YYSTACK_ALLOC YYMALLOC
2252# define YYSTACK_FREE YYFREE
2253# ifndef YYSTACK_ALLOC_MAXIMUM
2254# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
2255# endif
2256# if (defined __cplusplus && ! defined _STDLIB_H \
2257 && ! ((defined YYMALLOC || defined malloc) \
2258 && (defined YYFREE || defined free)))
2259# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
2260# ifndef _STDLIB_H
2261# define _STDLIB_H 1
2262# endif
2263# endif
2264# ifndef YYMALLOC
2265# define YYMALLOC malloc
2266# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
2267 || defined __cplusplus || defined _MSC_VER)
2268void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
2269# endif
2270# endif
2271# ifndef YYFREE
2272# define YYFREE free
2273# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
2274 || defined __cplusplus || defined _MSC_VER)
2275void free (void *); /* INFRINGES ON USER NAME SPACE */
2276# endif
2277# endif
2278# endif
2279#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
2280
2281
2282#if (! defined yyoverflow \
2283 && (! defined __cplusplus \
2284 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
2285
2286/* A type that is properly aligned for any stack member. */
2287union yyalloc
2288{
2289 yytype_int16 yyss;
2290 YYSTYPE yyvs;
2291 };
2292
2293/* The size of the maximum gap between one aligned stack and the next. */
2294# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
2295
2296/* The size of an array large to enough to hold all stacks, each with
2297 N elements. */
2298# define YYSTACK_BYTES(N) \
2299 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
2300 + YYSTACK_GAP_MAXIMUM)
2301
2302/* Copy COUNT objects from FROM to TO. The source and destination do
2303 not overlap. */
2304# ifndef YYCOPY
2305# if defined __GNUC__ && 1 < __GNUC__
2306# define YYCOPY(To, From, Count) \
2307 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
2308# else
2309# define YYCOPY(To, From, Count) \
2310 do \
2311 { \
2312 YYSIZE_T yyi; \
2313 for (yyi = 0; yyi < (Count); yyi++) \
2314 (To)[yyi] = (From)[yyi]; \
2315 } \
2316 while (YYID (0))
2317# endif
2318# endif
2319
2320/* Relocate STACK from its old location to the new one. The
2321 local variables YYSIZE and YYSTACKSIZE give the old and new number of
2322 elements in the stack, and YYPTR gives the new location of the
2323 stack. Advance YYPTR to a properly aligned location for the next
2324 stack. */
2325# define YYSTACK_RELOCATE(Stack) \
2326 do \
2327 { \
2328 YYSIZE_T yynewbytes; \
2329 YYCOPY (&yyptr->Stack, Stack, yysize); \
2330 Stack = &yyptr->Stack; \
2331 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
2332 yyptr += yynewbytes / sizeof (*yyptr); \
2333 } \
2334 while (YYID (0))
2335
2336#endif
2337
2338/* YYFINAL -- State number of the termination state. */
2339#define YYFINAL 4
2340/* YYLAST -- Last index in YYTABLE. */
2341#define YYLAST 1630
2342
2343/* YYNTOKENS -- Number of terminals. */
2344#define YYNTOKENS 166
2345/* YYNNTS -- Number of nonterminals. */
2346#define YYNNTS 81
2347/* YYNRULES -- Number of rules. */
2348#define YYNRULES 310
2349/* YYNRULES -- Number of states. */
2350#define YYNSTATES 606
2351
2352/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
2353#define YYUNDEFTOK 2
2354#define YYMAXUTOK 406
2355
2356#define YYTRANSLATE(YYX) \
2357 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
2358
2359/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
2360static const yytype_uint8 yytranslate[] =
2361{
2362 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2363 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2364 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2365 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2366 155, 156, 164, 2, 153, 2, 2, 2, 2, 2,
2367 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2368 160, 152, 161, 2, 2, 2, 2, 2, 2, 2,
2369 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2370 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2371 2, 157, 154, 159, 2, 2, 2, 2, 2, 165,
2372 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2373 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2374 158, 2, 2, 162, 2, 163, 2, 2, 2, 2,
2375 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2376 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2377 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2378 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2379 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2380 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2381 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2382 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2383 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2384 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2385 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2386 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2387 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
2388 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
2389 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
2390 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
2391 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
2392 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
2393 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
2394 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
2395 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
2396 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
2397 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
2398 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
2399 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
2400 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
2401 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
2402 145, 146, 147, 148, 149, 150, 151
2403};
2404
2405#if YYDEBUG
2406/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
2407 YYRHS. */
2408static const yytype_uint16 yyprhs[] =
2409{
2410 0, 0, 3, 5, 7, 9, 11, 13, 15, 17,
2411 19, 21, 23, 25, 27, 29, 31, 33, 35, 37,
2412 39, 41, 43, 45, 47, 49, 51, 53, 55, 57,
2413 59, 61, 63, 65, 67, 69, 71, 73, 75, 77,
2414 79, 81, 83, 85, 87, 89, 91, 93, 95, 97,
2415 99, 101, 103, 105, 107, 109, 111, 113, 115, 117,
2416 119, 121, 123, 125, 127, 129, 131, 133, 135, 137,
2417 139, 141, 143, 145, 147, 149, 151, 153, 155, 157,
2418 159, 161, 164, 165, 167, 169, 171, 173, 175, 177,
2419 179, 180, 181, 183, 185, 187, 189, 191, 193, 196,
2420 197, 200, 201, 205, 208, 209, 211, 212, 216, 218,
2421 221, 223, 225, 227, 229, 231, 233, 235, 237, 239,
2422 241, 243, 245, 247, 249, 251, 253, 255, 257, 259,
2423 261, 264, 269, 275, 281, 285, 288, 294, 299, 302,
2424 304, 308, 310, 314, 316, 317, 322, 326, 330, 335,
2425 340, 344, 351, 357, 360, 363, 366, 369, 372, 375,
2426 378, 381, 384, 387, 394, 400, 409, 416, 423, 430,
2427 438, 446, 453, 460, 469, 478, 482, 484, 486, 488,
2428 490, 493, 496, 501, 504, 506, 511, 514, 519, 520,
2429 528, 529, 537, 538, 546, 547, 555, 559, 564, 565,
2430 567, 569, 571, 575, 579, 583, 587, 591, 595, 597,
2431 598, 600, 602, 604, 605, 608, 612, 614, 616, 620,
2432 622, 623, 632, 634, 636, 637, 642, 644, 646, 649,
2433 650, 652, 654, 655, 656, 662, 663, 665, 667, 669,
2434 671, 673, 675, 677, 679, 681, 685, 687, 693, 695,
2435 697, 699, 701, 704, 707, 710, 714, 717, 718, 720,
2436 722, 724, 727, 730, 734, 744, 754, 763, 777, 779,
2437 781, 788, 794, 797, 804, 812, 814, 818, 820, 821,
2438 824, 826, 832, 838, 844, 851, 858, 861, 866, 871,
2439 878, 883, 888, 893, 898, 905, 912, 915, 923, 925,
2440 928, 929, 931, 932, 936, 943, 947, 954, 957, 962,
2441 969
2442};
2443
2444/* YYRHS -- A `-1'-separated list of the rules' RHS. */
2445static const yytype_int16 yyrhs[] =
2446{
2447 200, 0, -1, 5, -1, 6, -1, 3, -1, 4,
2448 -1, 79, -1, 80, -1, 81, -1, 82, -1, 83,
2449 -1, 84, -1, 85, -1, 86, -1, 87, -1, 88,
2450 -1, 89, -1, 90, -1, 91, -1, 92, -1, 97,
2451 -1, 98, -1, 99, -1, 100, -1, 101, -1, 102,
2452 -1, 119, -1, 120, -1, 121, -1, 122, -1, 123,
2453 -1, 124, -1, 125, -1, 126, -1, 127, -1, 128,
2454 -1, 129, -1, 130, -1, 131, -1, 132, -1, 133,
2455 -1, 134, -1, 135, -1, 136, -1, 137, -1, 138,
2456 -1, 125, -1, 126, -1, 127, -1, 128, -1, 27,
2457 -1, 28, -1, 93, -1, 94, -1, 95, -1, 96,
2458 -1, 140, -1, 141, -1, 142, -1, 143, -1, 144,
2459 -1, 145, -1, 146, -1, 147, -1, 148, -1, 149,
2460 -1, 150, -1, 151, -1, 139, -1, 16, -1, 14,
2461 -1, 12, -1, 10, -1, 17, -1, 15, -1, 13,
2462 -1, 11, -1, 176, -1, 177, -1, 18, -1, 19,
2463 -1, 212, 152, -1, -1, 41, -1, 42, -1, 43,
2464 -1, 44, -1, 45, -1, 46, -1, 47, -1, -1,
2465 -1, 65, -1, 66, -1, 67, -1, 68, -1, 69,
2466 -1, 70, -1, 64, 4, -1, -1, 57, 4, -1,
2467 -1, 153, 57, 4, -1, 34, 24, -1, -1, 185,
2468 -1, -1, 153, 188, 187, -1, 185, -1, 57, 4,
2469 -1, 191, -1, 8, -1, 193, -1, 8, -1, 193,
2470 -1, 9, -1, 10, -1, 11, -1, 12, -1, 13,
2471 -1, 14, -1, 15, -1, 16, -1, 17, -1, 18,
2472 -1, 19, -1, 21, -1, 192, -1, 48, -1, 229,
2473 -1, 154, 4, -1, 190, 155, 195, 156, -1, 157,
2474 4, 158, 193, 159, -1, 160, 4, 158, 193, 161,
2475 -1, 162, 194, 163, -1, 162, 163, -1, 160, 162,
2476 194, 163, 161, -1, 160, 162, 163, 161, -1, 193,
2477 164, -1, 193, -1, 194, 153, 193, -1, 194, -1,
2478 194, 153, 37, -1, 37, -1, -1, 191, 157, 198,
2479 159, -1, 191, 157, 159, -1, 191, 165, 24, -1,
2480 191, 160, 198, 161, -1, 191, 162, 198, 163, -1,
2481 191, 162, 163, -1, 191, 160, 162, 198, 163, 161,
2482 -1, 191, 160, 162, 163, 161, -1, 191, 38, -1,
2483 191, 39, -1, 191, 229, -1, 191, 197, -1, 191,
2484 26, -1, 176, 168, -1, 177, 4, -1, 9, 27,
2485 -1, 9, 28, -1, 179, 7, -1, 175, 155, 196,
2486 36, 191, 156, -1, 110, 155, 196, 244, 156, -1,
2487 112, 155, 196, 153, 196, 153, 196, 156, -1, 169,
2488 155, 196, 153, 196, 156, -1, 170, 155, 196, 153,
2489 196, 156, -1, 171, 155, 196, 153, 196, 156, -1,
2490 103, 172, 155, 196, 153, 196, 156, -1, 104, 173,
2491 155, 196, 153, 196, 156, -1, 174, 155, 196, 153,
2492 196, 156, -1, 114, 155, 196, 153, 196, 156, -1,
2493 115, 155, 196, 153, 196, 153, 196, 156, -1, 116,
2494 155, 196, 153, 196, 153, 196, 156, -1, 198, 153,
2495 196, -1, 196, -1, 32, -1, 33, -1, 201, -1,
2496 201, 222, -1, 201, 224, -1, 201, 62, 61, 207,
2497 -1, 201, 25, -1, 202, -1, 202, 180, 20, 189,
2498 -1, 202, 224, -1, 202, 62, 61, 207, -1, -1,
2499 202, 180, 181, 199, 196, 203, 187, -1, -1, 202,
2500 180, 50, 199, 191, 204, 187, -1, -1, 202, 180,
2501 45, 199, 191, 205, 187, -1, -1, 202, 180, 47,
2502 199, 191, 206, 187, -1, 202, 51, 209, -1, 202,
2503 58, 152, 210, -1, -1, 24, -1, 56, -1, 55,
2504 -1, 53, 152, 208, -1, 54, 152, 4, -1, 52,
2505 152, 24, -1, 71, 152, 24, -1, 157, 211, 159,
2506 -1, 211, 153, 24, -1, 24, -1, -1, 22, -1,
2507 24, -1, 212, -1, -1, 191, 213, -1, 215, 153,
2508 214, -1, 214, -1, 215, -1, 215, 153, 37, -1,
2509 37, -1, -1, 182, 189, 212, 155, 216, 156, 186,
2510 183, -1, 29, -1, 162, -1, -1, 181, 220, 217,
2511 218, -1, 30, -1, 163, -1, 232, 221, -1, -1,
2512 45, -1, 47, -1, -1, -1, 31, 225, 223, 226,
2513 217, -1, -1, 63, -1, 3, -1, 4, -1, 7,
2514 -1, 27, -1, 28, -1, 38, -1, 39, -1, 26,
2515 -1, 160, 198, 161, -1, 197, -1, 61, 227, 24,
2516 153, 24, -1, 167, -1, 212, -1, 229, -1, 228,
2517 -1, 191, 230, -1, 232, 233, -1, 219, 233, -1,
2518 234, 180, 236, -1, 234, 238, -1, -1, 23, -1,
2519 77, -1, 78, -1, 72, 231, -1, 72, 8, -1,
2520 73, 21, 230, -1, 73, 9, 230, 153, 21, 230,
2521 153, 21, 230, -1, 74, 178, 230, 153, 21, 230,
2522 157, 237, 159, -1, 74, 178, 230, 153, 21, 230,
2523 157, 159, -1, 75, 182, 189, 230, 155, 241, 156,
2524 36, 21, 230, 235, 21, 230, -1, 235, -1, 76,
2525 -1, 237, 178, 228, 153, 21, 230, -1, 178, 228,
2526 153, 21, 230, -1, 180, 243, -1, 191, 157, 230,
2527 153, 230, 159, -1, 239, 153, 157, 230, 153, 230,
2528 159, -1, 231, -1, 240, 153, 231, -1, 240, -1,
2529 -1, 60, 59, -1, 59, -1, 169, 191, 230, 153,
2530 230, -1, 170, 191, 230, 153, 230, -1, 171, 191,
2531 230, 153, 230, -1, 103, 172, 191, 230, 153, 230,
2532 -1, 104, 173, 191, 230, 153, 230, -1, 49, 231,
2533 -1, 174, 231, 153, 231, -1, 175, 231, 36, 191,
2534 -1, 112, 231, 153, 231, 153, 231, -1, 113, 231,
2535 153, 191, -1, 117, 231, 153, 191, -1, 118, 231,
2536 153, 191, -1, 114, 231, 153, 231, -1, 115, 231,
2537 153, 231, 153, 231, -1, 116, 231, 153, 231, 153,
2538 231, -1, 111, 239, -1, 242, 182, 189, 230, 155,
2539 241, 156, -1, 246, -1, 153, 240, -1, -1, 35,
2540 -1, -1, 105, 191, 184, -1, 105, 191, 153, 15,
2541 230, 184, -1, 106, 191, 184, -1, 106, 191, 153,
2542 15, 230, 184, -1, 107, 231, -1, 245, 108, 191,
2543 230, -1, 245, 109, 231, 153, 191, 230, -1, 110,
2544 191, 230, 244, -1
2545};
2546
2547/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
2548static const yytype_uint16 yyrline[] =
2549{
Chris Lattner1c8733e2008-03-12 17:45:29 +00002550 0, 1820, 1820, 1821, 1829, 1830, 1840, 1840, 1840, 1840,
2551 1840, 1840, 1840, 1840, 1840, 1840, 1840, 1844, 1844, 1844,
2552 1848, 1848, 1848, 1848, 1848, 1848, 1852, 1852, 1853, 1853,
2553 1854, 1854, 1855, 1855, 1856, 1856, 1860, 1860, 1861, 1861,
2554 1862, 1862, 1863, 1863, 1864, 1864, 1865, 1865, 1866, 1866,
2555 1867, 1868, 1871, 1871, 1871, 1871, 1875, 1875, 1875, 1875,
2556 1875, 1875, 1875, 1876, 1876, 1876, 1876, 1876, 1876, 1882,
2557 1882, 1882, 1882, 1886, 1886, 1886, 1886, 1890, 1890, 1894,
2558 1894, 1899, 1902, 1907, 1908, 1909, 1910, 1911, 1912, 1913,
2559 1914, 1918, 1919, 1920, 1921, 1922, 1923, 1924, 1925, 1935,
2560 1936, 1944, 1945, 1953, 1962, 1963, 1970, 1971, 1975, 1979,
2561 1995, 1996, 2003, 2004, 2011, 2019, 2019, 2019, 2019, 2019,
2562 2019, 2019, 2020, 2020, 2020, 2020, 2020, 2025, 2029, 2033,
2563 2038, 2047, 2072, 2078, 2091, 2102, 2106, 2119, 2123, 2138,
2564 2142, 2149, 2150, 2156, 2163, 2175, 2205, 2218, 2241, 2269,
2565 2291, 2302, 2324, 2335, 2344, 2349, 2408, 2415, 2423, 2430,
2566 2437, 2441, 2445, 2459, 2474, 2486, 2495, 2523, 2536, 2545,
2567 2551, 2557, 2568, 2574, 2580, 2591, 2592, 2601, 2602, 2614,
2568 2623, 2624, 2625, 2626, 2627, 2643, 2663, 2665, 2667, 2667,
2569 2674, 2674, 2682, 2682, 2690, 2690, 2699, 2701, 2703, 2708,
2570 2722, 2723, 2727, 2730, 2738, 2742, 2749, 2753, 2757, 2761,
2571 2769, 2769, 2773, 2774, 2778, 2786, 2791, 2799, 2800, 2807,
2572 2814, 2818, 3004, 3004, 3008, 3008, 3018, 3018, 3022, 3027,
2573 3028, 3029, 3033, 3034, 3033, 3046, 3047, 3052, 3053, 3054,
2574 3055, 3059, 3063, 3064, 3065, 3066, 3087, 3091, 3106, 3107,
2575 3112, 3112, 3120, 3130, 3133, 3142, 3153, 3158, 3167, 3178,
2576 3178, 3181, 3185, 3189, 3194, 3204, 3222, 3231, 3302, 3306,
2577 3313, 3325, 3340, 3370, 3380, 3390, 3394, 3401, 3402, 3406,
2578 3409, 3415, 3434, 3452, 3468, 3482, 3496, 3507, 3525, 3534,
2579 3543, 3550, 3571, 3595, 3601, 3607, 3613, 3629, 3719, 3727,
2580 3728, 3732, 3733, 3737, 3743, 3750, 3756, 3763, 3770, 3783,
2581 3803
Chris Lattnera62e8e42007-12-29 20:47:37 +00002582};
2583#endif
2584
2585#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
2586/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
2587 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
2588static const char *const yytname[] =
2589{
2590 "$end", "error", "$undefined", "ESINT64VAL", "EUINT64VAL", "SINTVAL",
2591 "UINTVAL", "FPVAL", "VOID", "BOOL", "SBYTE", "UBYTE", "SHORT", "USHORT",
2592 "INT", "UINT", "LONG", "ULONG", "FLOAT", "DOUBLE", "TYPE", "LABEL",
2593 "VAR_ID", "LABELSTR", "STRINGCONSTANT", "IMPLEMENTATION",
2594 "ZEROINITIALIZER", "TRUETOK", "FALSETOK", "BEGINTOK", "ENDTOK",
2595 "DECLARE", "GLOBAL", "CONSTANT", "SECTION", "VOLATILE", "TO",
2596 "DOTDOTDOT", "NULL_TOK", "UNDEF", "CONST", "INTERNAL", "LINKONCE",
2597 "WEAK", "APPENDING", "DLLIMPORT", "DLLEXPORT", "EXTERN_WEAK", "OPAQUE",
2598 "NOT", "EXTERNAL", "TARGET", "TRIPLE", "ENDIAN", "POINTERSIZE", "LITTLE",
2599 "BIG", "ALIGN", "DEPLIBS", "CALL", "TAIL", "ASM_TOK", "MODULE",
2600 "SIDEEFFECT", "CC_TOK", "CCC_TOK", "CSRETCC_TOK", "FASTCC_TOK",
2601 "COLDCC_TOK", "X86_STDCALLCC_TOK", "X86_FASTCALLCC_TOK", "DATALAYOUT",
2602 "RET", "BR", "SWITCH", "INVOKE", "UNREACHABLE", "UNWIND", "EXCEPT",
2603 "ADD", "SUB", "MUL", "DIV", "UDIV", "SDIV", "FDIV", "REM", "UREM",
2604 "SREM", "FREM", "AND", "OR", "XOR", "SHL", "SHR", "ASHR", "LSHR",
2605 "SETLE", "SETGE", "SETLT", "SETGT", "SETEQ", "SETNE", "ICMP", "FCMP",
2606 "MALLOC", "ALLOCA", "FREE", "LOAD", "STORE", "GETELEMENTPTR", "PHI_TOK",
2607 "SELECT", "VAARG", "EXTRACTELEMENT", "INSERTELEMENT", "SHUFFLEVECTOR",
2608 "VAARG_old", "VANEXT_old", "EQ", "NE", "SLT", "SGT", "SLE", "SGE", "ULT",
2609 "UGT", "ULE", "UGE", "OEQ", "ONE", "OLT", "OGT", "OLE", "OGE", "ORD",
2610 "UNO", "UEQ", "UNE", "CAST", "TRUNC", "ZEXT", "SEXT", "FPTRUNC", "FPEXT",
2611 "FPTOUI", "FPTOSI", "UITOFP", "SITOFP", "PTRTOINT", "INTTOPTR",
2612 "BITCAST", "'='", "','", "'\\\\'", "'('", "')'", "'['", "'x'", "']'",
2613 "'<'", "'>'", "'{'", "'}'", "'*'", "'c'", "$accept", "INTVAL",
2614 "EINT64VAL", "ArithmeticOps", "LogicalOps", "SetCondOps", "IPredicates",
2615 "FPredicates", "ShiftOps", "CastOps", "SIntType", "UIntType", "IntType",
2616 "FPType", "OptAssign", "OptLinkage", "OptCallingConv", "OptAlign",
2617 "OptCAlign", "SectionString", "OptSection", "GlobalVarAttributes",
2618 "GlobalVarAttribute", "TypesV", "UpRTypesV", "Types", "PrimType",
2619 "UpRTypes", "TypeListI", "ArgTypeListI", "ConstVal", "ConstExpr",
2620 "ConstVector", "GlobalType", "Module", "FunctionList", "ConstPool", "@1",
2621 "@2", "@3", "@4", "AsmBlock", "BigOrLittle", "TargetDefinition",
2622 "LibrariesDefinition", "LibList", "Name", "OptName", "ArgVal",
2623 "ArgListH", "ArgList", "FunctionHeaderH", "BEGIN", "FunctionHeader",
2624 "@5", "END", "Function", "FnDeclareLinkage", "FunctionProto", "@6", "@7",
2625 "OptSideEffect", "ConstValueRef", "SymbolicValueRef", "ValueRef",
2626 "ResolvedVal", "BasicBlockList", "BasicBlock", "InstructionList",
2627 "Unwind", "BBTerminatorInst", "JumpTable", "Inst", "PHIList",
2628 "ValueRefList", "ValueRefListE", "OptTailCall", "InstVal", "IndexList",
2629 "OptVolatile", "MemoryInst", 0
2630};
2631#endif
2632
2633# ifdef YYPRINT
2634/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
2635 token YYLEX-NUM. */
2636static const yytype_uint16 yytoknum[] =
2637{
2638 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
2639 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
2640 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
2641 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
2642 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
2643 305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
2644 315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
2645 325, 326, 327, 328, 329, 330, 331, 332, 333, 334,
2646 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
2647 345, 346, 347, 348, 349, 350, 351, 352, 353, 354,
2648 355, 356, 357, 358, 359, 360, 361, 362, 363, 364,
2649 365, 366, 367, 368, 369, 370, 371, 372, 373, 374,
2650 375, 376, 377, 378, 379, 380, 381, 382, 383, 384,
2651 385, 386, 387, 388, 389, 390, 391, 392, 393, 394,
2652 395, 396, 397, 398, 399, 400, 401, 402, 403, 404,
2653 405, 406, 61, 44, 92, 40, 41, 91, 120, 93,
2654 60, 62, 123, 125, 42, 99
2655};
2656# endif
2657
2658/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
2659static const yytype_uint8 yyr1[] =
2660{
2661 0, 166, 167, 167, 168, 168, 169, 169, 169, 169,
2662 169, 169, 169, 169, 169, 169, 169, 170, 170, 170,
2663 171, 171, 171, 171, 171, 171, 172, 172, 172, 172,
2664 172, 172, 172, 172, 172, 172, 173, 173, 173, 173,
2665 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
2666 173, 173, 174, 174, 174, 174, 175, 175, 175, 175,
2667 175, 175, 175, 175, 175, 175, 175, 175, 175, 176,
2668 176, 176, 176, 177, 177, 177, 177, 178, 178, 179,
2669 179, 180, 180, 181, 181, 181, 181, 181, 181, 181,
2670 181, 182, 182, 182, 182, 182, 182, 182, 182, 183,
2671 183, 184, 184, 185, 186, 186, 187, 187, 188, 188,
2672 189, 189, 190, 190, 191, 192, 192, 192, 192, 192,
2673 192, 192, 192, 192, 192, 192, 192, 193, 193, 193,
2674 193, 193, 193, 193, 193, 193, 193, 193, 193, 194,
2675 194, 195, 195, 195, 195, 196, 196, 196, 196, 196,
2676 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
2677 196, 196, 196, 197, 197, 197, 197, 197, 197, 197,
2678 197, 197, 197, 197, 197, 198, 198, 199, 199, 200,
2679 201, 201, 201, 201, 201, 202, 202, 202, 203, 202,
2680 204, 202, 205, 202, 206, 202, 202, 202, 202, 207,
2681 208, 208, 209, 209, 209, 209, 210, 211, 211, 211,
2682 212, 212, 213, 213, 214, 215, 215, 216, 216, 216,
2683 216, 217, 218, 218, 220, 219, 221, 221, 222, 223,
2684 223, 223, 225, 226, 224, 227, 227, 228, 228, 228,
2685 228, 228, 228, 228, 228, 228, 228, 228, 229, 229,
2686 230, 230, 231, 232, 232, 233, 234, 234, 234, 235,
2687 235, 236, 236, 236, 236, 236, 236, 236, 236, 236,
2688 237, 237, 238, 239, 239, 240, 240, 241, 241, 242,
2689 242, 243, 243, 243, 243, 243, 243, 243, 243, 243,
2690 243, 243, 243, 243, 243, 243, 243, 243, 243, 244,
2691 244, 245, 245, 246, 246, 246, 246, 246, 246, 246,
2692 246
2693};
2694
2695/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
2696static const yytype_uint8 yyr2[] =
2697{
2698 0, 2, 1, 1, 1, 1, 1, 1, 1, 1,
2699 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2700 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2701 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2702 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2703 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2704 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2705 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2706 1, 2, 0, 1, 1, 1, 1, 1, 1, 1,
2707 0, 0, 1, 1, 1, 1, 1, 1, 2, 0,
2708 2, 0, 3, 2, 0, 1, 0, 3, 1, 2,
2709 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2710 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2711 2, 4, 5, 5, 3, 2, 5, 4, 2, 1,
2712 3, 1, 3, 1, 0, 4, 3, 3, 4, 4,
2713 3, 6, 5, 2, 2, 2, 2, 2, 2, 2,
2714 2, 2, 2, 6, 5, 8, 6, 6, 6, 7,
2715 7, 6, 6, 8, 8, 3, 1, 1, 1, 1,
2716 2, 2, 4, 2, 1, 4, 2, 4, 0, 7,
2717 0, 7, 0, 7, 0, 7, 3, 4, 0, 1,
2718 1, 1, 3, 3, 3, 3, 3, 3, 1, 0,
2719 1, 1, 1, 0, 2, 3, 1, 1, 3, 1,
2720 0, 8, 1, 1, 0, 4, 1, 1, 2, 0,
2721 1, 1, 0, 0, 5, 0, 1, 1, 1, 1,
2722 1, 1, 1, 1, 1, 3, 1, 5, 1, 1,
2723 1, 1, 2, 2, 2, 3, 2, 0, 1, 1,
2724 1, 2, 2, 3, 9, 9, 8, 13, 1, 1,
2725 6, 5, 2, 6, 7, 1, 3, 1, 0, 2,
2726 1, 5, 5, 5, 6, 6, 2, 4, 4, 6,
2727 4, 4, 4, 4, 6, 6, 2, 7, 1, 2,
2728 0, 1, 0, 3, 6, 3, 6, 2, 4, 6,
2729 4
2730};
2731
2732/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
2733 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
2734 means the default is an error. */
2735static const yytype_uint16 yydefact[] =
2736{
2737 198, 0, 90, 184, 1, 183, 232, 83, 84, 85,
2738 86, 87, 88, 89, 0, 224, 257, 180, 181, 257,
2739 210, 211, 0, 0, 0, 90, 0, 186, 229, 0,
2740 91, 258, 254, 82, 226, 227, 228, 253, 0, 0,
2741 0, 0, 196, 0, 0, 0, 0, 0, 0, 0,
2742 81, 230, 231, 233, 199, 182, 0, 92, 93, 94,
2743 95, 96, 97, 0, 0, 302, 256, 0, 0, 0,
2744 0, 209, 197, 187, 2, 3, 111, 115, 116, 117,
2745 118, 119, 120, 121, 122, 123, 124, 125, 126, 128,
2746 0, 0, 0, 0, 248, 185, 0, 110, 127, 114,
2747 249, 129, 177, 178, 0, 0, 0, 0, 91, 98,
2748 0, 222, 223, 225, 301, 0, 280, 0, 0, 0,
2749 0, 91, 269, 259, 260, 6, 7, 8, 9, 10,
2750 11, 12, 13, 14, 15, 16, 17, 18, 19, 52,
2751 53, 54, 55, 20, 21, 22, 23, 24, 25, 0,
2752 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2753 0, 0, 0, 68, 56, 57, 58, 59, 60, 61,
2754 62, 63, 64, 65, 66, 67, 0, 0, 0, 0,
2755 0, 268, 255, 91, 272, 0, 298, 204, 201, 200,
2756 202, 203, 205, 208, 0, 130, 0, 0, 0, 113,
2757 135, 139, 0, 144, 138, 192, 194, 190, 115, 116,
2758 117, 118, 119, 120, 121, 122, 123, 124, 125, 0,
2759 0, 0, 0, 188, 234, 0, 0, 286, 279, 262,
2760 261, 0, 0, 72, 76, 71, 75, 70, 74, 69,
2761 73, 77, 78, 0, 0, 26, 27, 28, 29, 30,
2762 31, 32, 33, 34, 35, 0, 50, 51, 46, 47,
2763 48, 49, 36, 37, 38, 39, 40, 41, 42, 43,
2764 44, 45, 0, 101, 101, 307, 0, 0, 296, 0,
2765 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2766 0, 0, 0, 0, 0, 206, 0, 0, 0, 0,
2767 0, 134, 143, 141, 0, 106, 106, 106, 160, 161,
2768 4, 5, 158, 159, 162, 157, 153, 154, 0, 0,
2769 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2770 0, 0, 0, 0, 156, 155, 106, 220, 237, 238,
2771 239, 244, 240, 241, 242, 243, 235, 0, 246, 251,
2772 250, 252, 0, 263, 0, 0, 0, 0, 0, 303,
2773 0, 305, 300, 0, 0, 0, 0, 0, 0, 0,
2774 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2775 207, 112, 112, 137, 0, 140, 0, 131, 0, 193,
2776 195, 191, 0, 0, 0, 0, 0, 0, 0, 146,
2777 176, 0, 0, 0, 150, 0, 147, 0, 0, 0,
2778 0, 0, 189, 219, 213, 216, 217, 0, 236, 0,
2779 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2780 310, 0, 0, 0, 290, 293, 0, 0, 291, 292,
2781 0, 0, 0, 287, 288, 0, 308, 0, 132, 133,
2782 136, 142, 0, 0, 108, 106, 0, 0, 300, 0,
2783 0, 0, 0, 0, 145, 135, 114, 0, 148, 149,
2784 0, 0, 0, 0, 0, 212, 214, 0, 104, 0,
2785 245, 0, 0, 278, 0, 0, 101, 102, 101, 275,
2786 299, 0, 0, 0, 0, 0, 281, 282, 283, 278,
2787 0, 103, 109, 107, 0, 0, 0, 0, 0, 0,
2788 0, 175, 152, 0, 0, 0, 0, 0, 0, 218,
2789 215, 105, 99, 0, 0, 0, 277, 0, 284, 285,
2790 0, 304, 306, 0, 0, 0, 289, 294, 295, 0,
2791 309, 0, 0, 164, 0, 0, 0, 0, 151, 0,
2792 0, 0, 0, 0, 0, 221, 247, 0, 0, 0,
2793 276, 273, 0, 297, 0, 0, 0, 172, 0, 0,
2794 166, 167, 168, 171, 163, 100, 0, 266, 0, 0,
2795 0, 274, 169, 170, 0, 0, 0, 264, 0, 265,
2796 0, 0, 165, 173, 174, 0, 0, 0, 0, 0,
2797 0, 271, 0, 0, 270, 267
2798};
2799
2800/* YYDEFGOTO[NTERM-NUM]. */
2801static const yytype_int16 yydefgoto[] =
2802{
2803 -1, 94, 312, 329, 330, 331, 255, 272, 332, 333,
2804 219, 220, 243, 221, 25, 15, 63, 555, 359, 454,
2805 522, 389, 455, 95, 96, 222, 98, 99, 202, 304,
2806 400, 348, 401, 104, 1, 2, 3, 336, 307, 305,
2807 306, 55, 190, 42, 72, 194, 100, 476, 415, 416,
2808 417, 64, 113, 16, 30, 36, 17, 53, 18, 28,
2809 108, 419, 349, 101, 351, 489, 19, 32, 33, 181,
2810 182, 579, 66, 278, 526, 527, 183, 184, 430, 185,
2811 186
2812};
2813
2814/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
2815 STATE-NUM. */
2816#define YYPACT_NINF -542
2817static const yytype_int16 yypact[] =
2818{
2819 -542, 13, 162, 567, -542, -542, -542, -542, -542, -542,
2820 -542, -542, -542, -542, 83, -542, 19, -542, -542, -14,
2821 -542, -542, 50, -87, 87, 233, 27, -542, 123, 141,
2822 175, -542, -542, 98, -542, -542, -542, -542, 33, 40,
2823 66, 68, -542, 14, 141, 1265, 156, 156, 156, 156,
2824 -542, -542, -542, -542, -542, -542, 221, -542, -542, -542,
2825 -542, -542, -542, 1265, -19, 1479, -542, 204, 135, 226,
2826 227, 235, -542, -542, -542, -542, 81, -542, -542, -542,
2827 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2828 256, 257, 4, 15, -542, -542, 108, -542, -542, 12,
2829 -542, -542, -542, -542, 1306, 1306, 1306, 1326, 175, -542,
2830 98, -542, -542, -542, -542, 1306, -542, 205, 1367, 116,
2831 479, 175, -542, -542, -542, -542, -542, -542, -542, -542,
2832 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2833 -542, -542, -542, -542, -542, -542, -542, -542, -542, 355,
2834 429, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306,
2835 1306, 1306, 1306, -542, -542, -542, -542, -542, -542, -542,
2836 -542, -542, -542, -542, -542, -542, 1306, 1306, 1306, 1306,
2837 1306, -542, -542, 175, -542, 86, -542, -542, -542, -542,
2838 -542, -542, -542, -542, -13, -542, 110, 111, 75, -542,
2839 -542, 12, -81, 1046, -542, -542, -542, -542, 174, 208,
2840 266, 210, 267, 212, 268, 230, 277, 275, 278, 246,
2841 280, 279, 566, -542, -542, 136, 766, -542, -542, 81,
2842 -542, 766, 766, -542, -542, -542, -542, -542, -542, -542,
2843 -542, -542, -542, 766, 1265, -542, -542, -542, -542, -542,
2844 -542, -542, -542, -542, -542, 1306, -542, -542, -542, -542,
2845 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2846 -542, -542, 1306, 137, 145, -542, 766, 132, 146, 147,
2847 148, 149, 151, 152, 158, 160, 766, 766, 766, 161,
2848 281, 1265, 1306, 1306, 291, -542, 1306, 1306, 155, -27,
2849 1306, -542, -542, 165, 163, 176, 176, 176, -542, -542,
2850 -542, -542, -542, -542, -542, -542, -542, -542, 355, 429,
2851 172, 177, 178, 179, 182, 1087, 1387, 529, 311, 184,
2852 185, 186, 188, 189, -542, -542, 176, 1107, -542, -542,
2853 -542, -542, -542, -542, -542, -542, 282, 1326, -542, -542,
2854 -542, -542, 193, -542, 194, 766, 766, 766, 7, -542,
2855 20, -542, 195, 766, 192, 1306, 1306, 1306, 1306, 1306,
2856 1306, 1306, 200, 201, 206, 1306, 1306, 766, 766, 207,
2857 -542, -59, -149, -542, 196, 12, 1148, -542, 44, -542,
2858 -542, -542, 203, 211, 1326, 1326, 1326, 1326, 1326, -542,
2859 -542, -8, 741, -82, -542, 10, -542, 1326, 1326, 1326,
2860 1326, 1326, -542, -542, 98, -542, 214, 209, -542, 337,
2861 -34, 342, 348, 215, 218, 219, 766, 371, 766, 1306,
2862 -542, 223, 766, 224, -542, -542, 225, 234, -542, -542,
2863 766, 766, 766, -542, -542, 228, -542, 1306, -542, -542,
2864 -542, -542, 362, 375, -542, 176, 1326, 1326, 195, 236,
2865 237, 240, 243, 1326, -542, 238, -25, 11, -542, -542,
2866 244, 245, 247, 250, 352, -542, -542, 1205, 370, 252,
2867 -542, 766, 766, 1306, 766, 766, 258, -542, 258, -542,
2868 259, 766, 264, 1306, 1306, 1306, -542, -542, -542, 1306,
2869 766, -542, -542, -542, 270, 271, 263, 1326, 1326, 1326,
2870 1326, -542, -542, 260, 1326, 1326, 1326, 1326, 1306, -542,
2871 -542, -542, 368, 402, 274, 276, 259, 287, -542, -542,
2872 374, -542, -542, 1306, 285, 766, -542, -542, -542, 290,
2873 -542, 1326, 1326, -542, 283, 295, 284, 294, -542, 296,
2874 297, 299, 302, 303, 430, -542, -542, 414, 41, 425,
2875 -542, -542, 305, -542, 306, 310, 1326, -542, 1326, 1326,
2876 -542, -542, -542, -542, -542, -542, 766, -542, 893, 144,
2877 448, -542, -542, -542, 314, 315, 316, -542, 331, -542,
2878 893, 766, -542, -542, -542, 464, 334, 180, 766, 481,
2879 482, -542, 766, 766, -542, -542
2880};
2881
2882/* YYPGOTO[NTERM-NUM]. */
2883static const yytype_int16 yypgoto[] =
2884{
2885 -542, -542, -542, 435, 439, 441, 191, 197, 442, 445,
2886 -119, -116, -541, -542, 478, 489, -107, -542, -267, 37,
2887 -542, -238, -542, -60, -542, -45, -542, -74, -51, -542,
2888 -101, 300, -252, 134, -542, -542, -542, -542, -542, -542,
2889 -542, 473, -542, -542, -542, -542, 8, -542, 46, -542,
2890 -542, 410, -542, -542, -542, -542, -542, -542, 518, -542,
2891 -542, -542, -528, 142, -90, -113, -542, 505, -542, -72,
2892 -542, -542, -542, -542, 97, 28, -542, -542, 70, -542,
2893 -542
2894};
2895
2896/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
2897 positive, shift that token. If negative, reduce the rule which
2898 number is the opposite. If zero, do what YYDEFACT says.
2899 If YYTABLE_NINF, syntax error. */
2900#define YYTABLE_NINF -180
2901static const yytype_int16 yytable[] =
2902{
2903 97, 241, 227, 110, 242, 230, 223, 361, 197, 31,
2904 111, 26, 449, 4, 244, 204, 34, 578, 97, 201,
2905 74, 75, 426, 199, 77, 78, 79, 80, 81, 82,
2906 83, 84, 85, 86, 87, 428, 88, 20, 590, 21,
2907 275, 26, 31, 279, 280, 281, 282, 283, 284, 285,
2908 588, 233, 234, 235, 236, 237, 238, 239, 240, 205,
2909 206, 207, 596, 89, 427, 43, 289, 290, 390, 391,
2910 226, 463, 300, 226, 403, 405, 291, 427, 452, 468,
2911 74, 75, 301, 199, 77, 78, 79, 80, 81, 82,
2912 83, 84, 85, 86, 87, 420, 88, 20, 412, 21,
2913 448, 453, 38, 39, 40, 204, 273, 274, 226, 276,
2914 277, 226, 226, 226, 226, 226, 226, 226, 225, 463,
2915 20, 41, 21, 89, 201, 231, 300, 480, -139, 201,
2916 -112, 286, 287, 288, 226, 226, 384, 232, -139, 204,
2917 294, 352, 353, 112, 29, 463, 295, 299, 44, 35,
2918 467, 464, 303, 354, 233, 234, 235, 236, 237, 238,
2919 239, 240, -179, 463, 463, 54, 198, -112, 51, 90,
2920 52, 71, 91, 469, 513, 92, 204, 93, 200, 50,
2921 379, 105, 106, 107, 355, 67, 362, 5, 102, 103,
2922 188, 189, 68, 6, 292, 293, 372, 373, 374, 97,
2923 577, 308, 309, 7, 8, 9, 10, 11, 12, 13,
2924 356, -72, -72, -71, -71, -70, -70, 503, 69, 531,
2925 70, 532, 381, 382, 14, 109, 385, 357, 187, 90,
2926 191, 377, 91, -69, -69, 92, -113, 93, 298, 56,
2927 57, 58, 59, 60, 61, 62, 97, 378, 226, 310,
2928 311, 192, 433, 45, 435, 436, 437, 123, 124, 193,
2929 195, 196, 443, 203, 228, 423, 424, 425, 296, 297,
2930 -76, -75, -74, 431, 7, 8, 9, 10, 46, 12,
2931 47, -73, -79, 48, 313, -80, 314, 445, 446, 363,
2932 358, 337, 414, 458, 459, 460, 461, 462, 360, 364,
2933 365, 366, 367, 589, 368, 369, 470, 471, 472, 473,
2934 474, 370, 385, 371, 375, 380, 383, 376, 386, 387,
2935 226, 434, 226, 226, 226, 438, 439, 394, 466, 388,
2936 226, 444, 395, 396, 397, 406, 486, 398, 488, 407,
2937 408, 409, 492, 410, 411, 418, 421, 422, 429, 432,
2938 496, 497, 498, 440, 441, 504, 505, 450, 456, 442,
2939 447, 479, 511, 481, 335, 478, 457, 477, 350, 482,
2940 483, 484, 485, 350, 350, 487, 491, 493, 494, 502,
2941 536, 537, 538, 499, 226, 350, 501, 495, 518, 507,
2942 508, 524, 525, 509, 528, 529, 510, 514, 515, 512,
2943 516, 534, 500, 517, 452, 523, 544, 545, 546, 547,
2944 540, 530, 533, 549, 550, 551, 552, 535, 350, 543,
2945 560, 548, 475, 541, 542, 554, 556, 557, 350, 350,
2946 350, 427, 414, 558, 575, 576, 566, 568, 226, 241,
2947 564, 565, 242, 559, 561, 562, 563, 569, 226, 226,
2948 226, 567, 570, 571, 226, 572, 256, 257, 573, 574,
2949 241, 580, 582, 242, 581, 584, 583, 585, 586, 591,
2950 592, 593, 594, 553, 245, 246, 247, 248, 249, 250,
2951 251, 252, 253, 254, 595, 598, 587, 599, 226, 233,
2952 234, 235, 236, 237, 238, 239, 240, 350, 350, 350,
2953 176, 597, 602, 603, 177, 350, 178, 179, 601, 392,
2954 180, 65, 604, 605, 49, 521, 393, 73, 224, 350,
2955 350, 27, 334, 520, 37, 600, 490, 539, 506, 0,
2956 0, 0, 0, 0, 74, 75, 0, 199, 208, 209,
2957 210, 211, 212, 213, 214, 215, 216, 217, 218, 0,
2958 88, 20, 0, 21, 258, 259, 260, 261, 262, 263,
2959 264, 265, 266, 267, 268, 269, 270, 271, 350, 0,
2960 350, 74, 75, 0, 350, 0, 0, 89, 0, 0,
2961 0, 0, 350, 350, 350, 0, 0, -82, 20, 20,
2962 21, 21, 315, 0, 0, 0, 0, 0, 6, -82,
2963 -82, 0, 0, 0, 316, 317, 0, 0, -82, -82,
2964 -82, -82, -82, -82, -82, 0, 0, -82, 22, 0,
2965 0, 0, 0, 350, 350, 23, 350, 350, 0, 24,
2966 0, 0, 0, 350, 0, 0, 0, 0, 0, 0,
2967 0, 0, 350, 0, 0, 125, 126, 127, 128, 129,
2968 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
2969 140, 141, 142, 143, 144, 145, 146, 147, 148, 318,
2970 319, 0, 0, 0, 0, 0, 320, 350, 321, 0,
2971 322, 323, 324, 90, 0, 0, 91, 0, 0, 92,
2972 0, 93, 404, 0, 0, 0, 0, 0, 0, 0,
2973 0, 0, 0, 0, 0, 163, 164, 165, 166, 167,
2974 168, 169, 170, 171, 172, 173, 174, 175, 350, 0,
2975 0, 0, 0, 325, 0, 0, 326, 0, 327, 0,
2976 0, 328, 0, 350, 0, 0, 0, 0, 0, 0,
2977 350, 0, 0, 0, 350, 350, 74, 75, 0, 199,
2978 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
2979 218, 0, 88, 20, 0, 21, 0, 0, 0, 338,
2980 339, 74, 75, 340, 0, 0, 0, 0, 0, 0,
2981 0, 0, 0, 0, 0, 0, 0, 0, 20, 89,
2982 21, 0, 341, 342, 343, 0, 0, 0, 0, 0,
2983 0, 0, 0, 0, 344, 345, 0, 0, 0, 0,
2984 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2985 0, 0, 0, 0, 0, 0, 0, 346, 0, 0,
2986 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2987 0, 0, 0, 0, 0, 125, 126, 127, 128, 129,
2988 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
2989 140, 141, 142, 143, 144, 145, 146, 147, 148, 318,
2990 319, 0, 0, 0, 0, 0, 320, 0, 321, 0,
2991 322, 323, 324, 0, 0, 0, 0, 0, 0, 0,
2992 0, 0, 0, 0, 0, 90, 338, 339, 91, 0,
2993 340, 92, 0, 93, 465, 163, 164, 165, 166, 167,
2994 168, 169, 170, 171, 172, 173, 174, 175, 0, 341,
2995 342, 343, 0, 0, 0, 0, 347, 0, 0, 0,
2996 0, 344, 345, 0, 0, 0, 0, 0, 0, 0,
2997 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2998 0, 0, 0, 0, 346, 0, 0, 0, 0, 0,
2999 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3000 0, 0, 125, 126, 127, 128, 129, 130, 131, 132,
3001 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
3002 143, 144, 145, 146, 147, 148, 318, 319, 0, 0,
3003 0, 0, 0, 320, 0, 321, 0, 322, 323, 324,
3004 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3005 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3006 0, 0, 163, 164, 165, 166, 167, 168, 169, 170,
3007 171, 172, 173, 174, 175, 0, 0, 0, 0, 0,
3008 0, 74, 75, 347, 199, 77, 78, 79, 80, 81,
3009 82, 83, 84, 85, 86, 87, 0, 88, 20, 0,
3010 21, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3011 0, 0, 0, 302, 0, 0, 0, 0, 0, 0,
3012 0, 0, 74, 75, 89, 199, 208, 209, 210, 211,
3013 212, 213, 214, 215, 216, 217, 218, 0, 88, 20,
3014 0, 21, 74, 75, 0, 199, 77, 78, 79, 80,
3015 81, 82, 83, 84, 85, 86, 87, 0, 88, 20,
3016 0, 21, 0, 0, 0, 89, 0, 0, 0, 0,
3017 0, 0, 0, 0, 413, 0, 0, 0, 0, 0,
3018 0, 0, 0, 74, 75, 89, 199, 77, 78, 79,
3019 80, 81, 82, 83, 84, 85, 86, 87, 0, 88,
3020 20, 0, 21, 0, 0, 0, 0, 0, 0, 0,
3021 0, 0, 0, 0, 0, 451, 0, 0, 0, 0,
3022 0, 0, 0, 0, 0, 0, 89, 0, 0, 0,
3023 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
3024 74, 75, 0, 199, 77, 78, 79, 80, 81, 82,
3025 83, 84, 85, 86, 87, 0, 88, 20, 0, 21,
3026 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3027 0, 90, 519, 0, 91, 0, 399, 92, 0, 93,
3028 0, 0, 0, 89, 0, 0, 0, 0, 0, 0,
3029 0, 90, 0, 0, 91, 0, 0, 92, 0, 93,
3030 74, 75, 0, 76, 77, 78, 79, 80, 81, 82,
3031 83, 84, 85, 86, 87, 0, 88, 20, 0, 21,
3032 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3033 0, 0, 90, 0, 0, 91, 0, 0, 92, 0,
3034 93, 74, 75, 89, 199, 77, 78, 79, 80, 81,
3035 82, 83, 84, 85, 86, 87, 0, 88, 20, 0,
3036 21, 74, 75, 0, 199, 208, 209, 210, 211, 212,
3037 213, 214, 215, 216, 217, 218, 0, 88, 20, 0,
3038 21, 0, 0, 0, 89, 0, 0, 0, 0, 90,
3039 0, 0, 91, 0, 0, 92, 0, 93, 0, 0,
3040 0, 0, 74, 75, 89, 229, 77, 78, 79, 80,
3041 81, 82, 83, 84, 85, 86, 87, 0, 88, 20,
3042 0, 21, 74, 75, 0, 199, 208, 209, 210, 211,
3043 212, 213, 214, 215, 216, 217, 218, 0, 88, 20,
3044 0, 21, 0, 0, 0, 89, 0, 0, 0, 90,
3045 0, 0, 91, 0, 0, 92, 0, 93, 0, 0,
3046 0, 0, 0, 0, 0, 89, 0, 0, 0, 0,
3047 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3048 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3049 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
3050 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3051 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
3052 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3053 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3054 0, 0, 0, 0, 114, 0, 0, 0, 0, 0,
3055 0, 90, 0, 0, 91, 0, 0, 92, 115, 93,
3056 0, 0, 0, 0, 0, 0, 0, 0, 116, 117,
3057 0, 90, 0, 0, 91, 0, 0, 92, 0, 402,
3058 0, 118, 119, 120, 121, 122, 123, 124, 125, 126,
3059 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
3060 137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
3061 147, 148, 149, 150, 151, 152, 153, 0, 0, 154,
3062 155, 156, 157, 158, 159, 160, 161, 162, 0, 0,
3063 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3064 0, 0, 0, 0, 0, 0, 0, 0, 163, 164,
3065 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
3066 175
3067};
3068
3069static const yytype_int16 yycheck[] =
3070{
3071 45, 120, 115, 63, 120, 118, 107, 274, 4, 23,
3072 29, 3, 161, 0, 121, 164, 30, 558, 63, 93,
3073 5, 6, 15, 8, 9, 10, 11, 12, 13, 14,
3074 15, 16, 17, 18, 19, 15, 21, 22, 579, 24,
3075 153, 33, 23, 156, 157, 158, 159, 160, 161, 162,
3076 578, 10, 11, 12, 13, 14, 15, 16, 17, 104,
3077 105, 106, 590, 48, 57, 152, 179, 180, 306, 307,
3078 115, 153, 153, 118, 326, 327, 183, 57, 34, 161,
3079 5, 6, 163, 8, 9, 10, 11, 12, 13, 14,
3080 15, 16, 17, 18, 19, 347, 21, 22, 336, 24,
3081 159, 57, 52, 53, 54, 164, 151, 152, 153, 154,
3082 155, 156, 157, 158, 159, 160, 161, 162, 110, 153,
3083 22, 71, 24, 48, 198, 9, 153, 161, 153, 203,
3084 155, 176, 177, 178, 179, 180, 163, 21, 163, 164,
3085 153, 231, 232, 162, 61, 153, 159, 198, 61, 163,
3086 402, 159, 203, 243, 10, 11, 12, 13, 14, 15,
3087 16, 17, 0, 153, 153, 24, 162, 155, 45, 154,
3088 47, 157, 157, 163, 163, 160, 164, 162, 163, 152,
3089 293, 47, 48, 49, 244, 152, 276, 25, 32, 33,
3090 55, 56, 152, 31, 108, 109, 286, 287, 288, 244,
3091 159, 27, 28, 41, 42, 43, 44, 45, 46, 47,
3092 255, 3, 4, 3, 4, 3, 4, 455, 152, 486,
3093 152, 488, 296, 297, 62, 4, 300, 272, 24, 154,
3094 4, 291, 157, 3, 4, 160, 155, 162, 163, 64,
3095 65, 66, 67, 68, 69, 70, 291, 292, 293, 3,
3096 4, 24, 365, 20, 367, 368, 369, 77, 78, 24,
3097 4, 4, 375, 155, 59, 355, 356, 357, 158, 158,
3098 4, 4, 4, 363, 41, 42, 43, 44, 45, 46,
3099 47, 4, 7, 50, 4, 7, 7, 377, 378, 157,
3100 153, 155, 337, 394, 395, 396, 397, 398, 153, 153,
3101 153, 153, 153, 159, 153, 153, 407, 408, 409, 410,
3102 411, 153, 386, 153, 153, 24, 161, 36, 153, 156,
3103 365, 366, 367, 368, 369, 370, 371, 155, 402, 153,
3104 375, 376, 155, 155, 155, 24, 426, 155, 428, 155,
3105 155, 155, 432, 155, 155, 63, 153, 153, 153, 157,
3106 440, 441, 442, 153, 153, 456, 457, 161, 155, 153,
3107 153, 24, 463, 21, 222, 156, 155, 153, 226, 21,
3108 155, 153, 153, 231, 232, 4, 153, 153, 153, 4,
3109 493, 494, 495, 155, 429, 243, 24, 153, 36, 153,
3110 153, 481, 482, 153, 484, 485, 153, 153, 153, 161,
3111 153, 491, 447, 153, 34, 153, 507, 508, 509, 510,
3112 500, 153, 153, 514, 515, 516, 517, 153, 276, 156,
3113 533, 161, 414, 153, 153, 57, 24, 153, 286, 287,
3114 288, 57, 477, 157, 4, 21, 153, 153, 483, 558,
3115 541, 542, 558, 156, 159, 535, 156, 153, 493, 494,
3116 495, 156, 156, 156, 499, 156, 27, 28, 156, 156,
3117 579, 36, 156, 579, 159, 566, 156, 568, 569, 21,
3118 156, 156, 156, 518, 119, 120, 121, 122, 123, 124,
3119 125, 126, 127, 128, 153, 21, 576, 153, 533, 10,
3120 11, 12, 13, 14, 15, 16, 17, 355, 356, 357,
3121 65, 591, 21, 21, 65, 363, 65, 65, 598, 318,
3122 65, 33, 602, 603, 25, 478, 319, 44, 108, 377,
3123 378, 3, 222, 477, 19, 597, 429, 499, 458, -1,
3124 -1, -1, -1, -1, 5, 6, -1, 8, 9, 10,
3125 11, 12, 13, 14, 15, 16, 17, 18, 19, -1,
3126 21, 22, -1, 24, 125, 126, 127, 128, 129, 130,
3127 131, 132, 133, 134, 135, 136, 137, 138, 426, -1,
3128 428, 5, 6, -1, 432, -1, -1, 48, -1, -1,
3129 -1, -1, 440, 441, 442, -1, -1, 20, 22, 22,
3130 24, 24, 26, -1, -1, -1, -1, -1, 31, 32,
3131 33, -1, -1, -1, 38, 39, -1, -1, 41, 42,
3132 43, 44, 45, 46, 47, -1, -1, 50, 51, -1,
3133 -1, -1, -1, 481, 482, 58, 484, 485, -1, 62,
3134 -1, -1, -1, 491, -1, -1, -1, -1, -1, -1,
3135 -1, -1, 500, -1, -1, 79, 80, 81, 82, 83,
3136 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3137 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3138 104, -1, -1, -1, -1, -1, 110, 535, 112, -1,
3139 114, 115, 116, 154, -1, -1, 157, -1, -1, 160,
3140 -1, 162, 163, -1, -1, -1, -1, -1, -1, -1,
3141 -1, -1, -1, -1, -1, 139, 140, 141, 142, 143,
3142 144, 145, 146, 147, 148, 149, 150, 151, 576, -1,
3143 -1, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3144 -1, 165, -1, 591, -1, -1, -1, -1, -1, -1,
3145 598, -1, -1, -1, 602, 603, 5, 6, -1, 8,
3146 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
3147 19, -1, 21, 22, -1, 24, -1, -1, -1, 3,
3148 4, 5, 6, 7, -1, -1, -1, -1, -1, -1,
3149 -1, -1, -1, -1, -1, -1, -1, -1, 22, 48,
3150 24, -1, 26, 27, 28, -1, -1, -1, -1, -1,
3151 -1, -1, -1, -1, 38, 39, -1, -1, -1, -1,
3152 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3153 -1, -1, -1, -1, -1, -1, -1, 61, -1, -1,
3154 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3155 -1, -1, -1, -1, -1, 79, 80, 81, 82, 83,
3156 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3157 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3158 104, -1, -1, -1, -1, -1, 110, -1, 112, -1,
3159 114, 115, 116, -1, -1, -1, -1, -1, -1, -1,
3160 -1, -1, -1, -1, -1, 154, 3, 4, 157, -1,
3161 7, 160, -1, 162, 163, 139, 140, 141, 142, 143,
3162 144, 145, 146, 147, 148, 149, 150, 151, -1, 26,
3163 27, 28, -1, -1, -1, -1, 160, -1, -1, -1,
3164 -1, 38, 39, -1, -1, -1, -1, -1, -1, -1,
3165 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3166 -1, -1, -1, -1, 61, -1, -1, -1, -1, -1,
3167 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3168 -1, -1, 79, 80, 81, 82, 83, 84, 85, 86,
3169 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
3170 97, 98, 99, 100, 101, 102, 103, 104, -1, -1,
3171 -1, -1, -1, 110, -1, 112, -1, 114, 115, 116,
3172 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3173 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3174 -1, -1, 139, 140, 141, 142, 143, 144, 145, 146,
3175 147, 148, 149, 150, 151, -1, -1, -1, -1, -1,
3176 -1, 5, 6, 160, 8, 9, 10, 11, 12, 13,
3177 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3178 24, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3179 -1, -1, -1, 37, -1, -1, -1, -1, -1, -1,
3180 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
3181 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3182 -1, 24, 5, 6, -1, 8, 9, 10, 11, 12,
3183 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3184 -1, 24, -1, -1, -1, 48, -1, -1, -1, -1,
3185 -1, -1, -1, -1, 37, -1, -1, -1, -1, -1,
3186 -1, -1, -1, 5, 6, 48, 8, 9, 10, 11,
3187 12, 13, 14, 15, 16, 17, 18, 19, -1, 21,
3188 22, -1, 24, -1, -1, -1, -1, -1, -1, -1,
3189 -1, -1, -1, -1, -1, 37, -1, -1, -1, -1,
3190 -1, -1, -1, -1, -1, -1, 48, -1, -1, -1,
3191 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3192 5, 6, -1, 8, 9, 10, 11, 12, 13, 14,
3193 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
3194 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3195 -1, 154, 37, -1, 157, -1, 159, 160, -1, 162,
3196 -1, -1, -1, 48, -1, -1, -1, -1, -1, -1,
3197 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
3198 5, 6, -1, 8, 9, 10, 11, 12, 13, 14,
3199 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
3200 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3201 -1, -1, 154, -1, -1, 157, -1, -1, 160, -1,
3202 162, 5, 6, 48, 8, 9, 10, 11, 12, 13,
3203 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3204 24, 5, 6, -1, 8, 9, 10, 11, 12, 13,
3205 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3206 24, -1, -1, -1, 48, -1, -1, -1, -1, 154,
3207 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
3208 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
3209 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3210 -1, 24, 5, 6, -1, 8, 9, 10, 11, 12,
3211 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3212 -1, 24, -1, -1, -1, 48, -1, -1, -1, 154,
3213 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
3214 -1, -1, -1, -1, -1, 48, -1, -1, -1, -1,
3215 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3216 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3217 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3218 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3219 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3220 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3221 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3222 -1, -1, -1, -1, 35, -1, -1, -1, -1, -1,
3223 -1, 154, -1, -1, 157, -1, -1, 160, 49, 162,
3224 -1, -1, -1, -1, -1, -1, -1, -1, 59, 60,
3225 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
3226 -1, 72, 73, 74, 75, 76, 77, 78, 79, 80,
3227 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
3228 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
3229 101, 102, 103, 104, 105, 106, 107, -1, -1, 110,
3230 111, 112, 113, 114, 115, 116, 117, 118, -1, -1,
3231 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3232 -1, -1, -1, -1, -1, -1, -1, -1, 139, 140,
3233 141, 142, 143, 144, 145, 146, 147, 148, 149, 150,
3234 151
3235};
3236
3237/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
3238 symbol of state STATE-NUM. */
3239static const yytype_uint8 yystos[] =
3240{
3241 0, 200, 201, 202, 0, 25, 31, 41, 42, 43,
3242 44, 45, 46, 47, 62, 181, 219, 222, 224, 232,
3243 22, 24, 51, 58, 62, 180, 212, 224, 225, 61,
3244 220, 23, 233, 234, 30, 163, 221, 233, 52, 53,
3245 54, 71, 209, 152, 61, 20, 45, 47, 50, 181,
3246 152, 45, 47, 223, 24, 207, 64, 65, 66, 67,
3247 68, 69, 70, 182, 217, 180, 238, 152, 152, 152,
3248 152, 157, 210, 207, 5, 6, 8, 9, 10, 11,
3249 12, 13, 14, 15, 16, 17, 18, 19, 21, 48,
3250 154, 157, 160, 162, 167, 189, 190, 191, 192, 193,
3251 212, 229, 32, 33, 199, 199, 199, 199, 226, 4,
3252 189, 29, 162, 218, 35, 49, 59, 60, 72, 73,
3253 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
3254 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3255 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3256 104, 105, 106, 107, 110, 111, 112, 113, 114, 115,
3257 116, 117, 118, 139, 140, 141, 142, 143, 144, 145,
3258 146, 147, 148, 149, 150, 151, 169, 170, 171, 174,
3259 175, 235, 236, 242, 243, 245, 246, 24, 55, 56,
3260 208, 4, 24, 24, 211, 4, 4, 4, 162, 8,
3261 163, 193, 194, 155, 164, 191, 191, 191, 9, 10,
3262 11, 12, 13, 14, 15, 16, 17, 18, 19, 176,
3263 177, 179, 191, 196, 217, 212, 191, 231, 59, 8,
3264 231, 9, 21, 10, 11, 12, 13, 14, 15, 16,
3265 17, 176, 177, 178, 182, 119, 120, 121, 122, 123,
3266 124, 125, 126, 127, 128, 172, 27, 28, 125, 126,
3267 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
3268 137, 138, 173, 191, 191, 231, 191, 191, 239, 231,
3269 231, 231, 231, 231, 231, 231, 191, 191, 191, 231,
3270 231, 182, 108, 109, 153, 159, 158, 158, 163, 194,
3271 153, 163, 37, 194, 195, 205, 206, 204, 27, 28,
3272 3, 4, 168, 4, 7, 26, 38, 39, 103, 104,
3273 110, 112, 114, 115, 116, 157, 160, 162, 165, 169,
3274 170, 171, 174, 175, 197, 229, 203, 155, 3, 4,
3275 7, 26, 27, 28, 38, 39, 61, 160, 197, 228,
3276 229, 230, 230, 230, 230, 189, 191, 191, 153, 184,
3277 153, 184, 230, 157, 153, 153, 153, 153, 153, 153,
3278 153, 153, 230, 230, 230, 153, 36, 189, 191, 231,
3279 24, 193, 193, 161, 163, 193, 153, 156, 153, 187,
3280 187, 187, 172, 173, 155, 155, 155, 155, 155, 159,
3281 196, 198, 162, 198, 163, 198, 24, 155, 155, 155,
3282 155, 155, 187, 37, 191, 214, 215, 216, 63, 227,
3283 198, 153, 153, 230, 230, 230, 15, 57, 15, 153,
3284 244, 230, 157, 231, 191, 231, 231, 231, 191, 191,
3285 153, 153, 153, 231, 191, 230, 230, 153, 159, 161,
3286 161, 37, 34, 57, 185, 188, 155, 155, 196, 196,
3287 196, 196, 196, 153, 159, 163, 193, 198, 161, 163,
3288 196, 196, 196, 196, 196, 212, 213, 153, 156, 24,
3289 161, 21, 21, 155, 153, 153, 230, 4, 230, 231,
3290 240, 153, 230, 153, 153, 153, 230, 230, 230, 155,
3291 191, 24, 4, 187, 196, 196, 244, 153, 153, 153,
3292 153, 196, 161, 163, 153, 153, 153, 153, 36, 37,
3293 214, 185, 186, 153, 230, 230, 240, 241, 230, 230,
3294 153, 184, 184, 153, 230, 153, 231, 231, 231, 241,
3295 230, 153, 153, 156, 196, 196, 196, 196, 161, 196,
3296 196, 196, 196, 191, 57, 183, 24, 153, 157, 156,
3297 231, 159, 230, 156, 196, 196, 153, 156, 153, 153,
3298 156, 156, 156, 156, 156, 4, 21, 159, 178, 237,
3299 36, 159, 156, 156, 196, 196, 196, 230, 228, 159,
3300 178, 21, 156, 156, 156, 153, 228, 230, 21, 153,
3301 235, 230, 21, 21, 230, 230
3302};
David Greene48556392007-09-04 18:46:50 +00003303
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003304#define yyerrok (yyerrstatus = 0)
3305#define yyclearin (yychar = YYEMPTY)
Chris Lattnera62e8e42007-12-29 20:47:37 +00003306#define YYEMPTY (-2)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003307#define YYEOF 0
Chris Lattnera62e8e42007-12-29 20:47:37 +00003308
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003309#define YYACCEPT goto yyacceptlab
Chris Lattnera62e8e42007-12-29 20:47:37 +00003310#define YYABORT goto yyabortlab
3311#define YYERROR goto yyerrorlab
3312
3313
3314/* Like YYERROR except do call yyerror. This remains here temporarily
3315 to ease the transition to the new meaning of YYERROR, for GCC.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003316 Once GCC version 2 has supplanted version 1, this can go. */
Chris Lattnera62e8e42007-12-29 20:47:37 +00003317
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003318#define YYFAIL goto yyerrlab
Chris Lattnera62e8e42007-12-29 20:47:37 +00003319
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003320#define YYRECOVERING() (!!yyerrstatus)
Chris Lattnera62e8e42007-12-29 20:47:37 +00003321
3322#define YYBACKUP(Token, Value) \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003323do \
3324 if (yychar == YYEMPTY && yylen == 1) \
Chris Lattnera62e8e42007-12-29 20:47:37 +00003325 { \
3326 yychar = (Token); \
3327 yylval = (Value); \
3328 yytoken = YYTRANSLATE (yychar); \
3329 YYPOPSTACK (1); \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003330 goto yybackup; \
3331 } \
3332 else \
Chris Lattnera62e8e42007-12-29 20:47:37 +00003333 { \
3334 yyerror (YY_("syntax error: cannot back up")); \
3335 YYERROR; \
3336 } \
3337while (YYID (0))
3338
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003339
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003340#define YYTERROR 1
3341#define YYERRCODE 256
3342
Chris Lattnera62e8e42007-12-29 20:47:37 +00003343
3344/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
3345 If N is 0, then set CURRENT to the empty location which ends
3346 the previous symbol: RHS[0] (always defined). */
3347
3348#define YYRHSLOC(Rhs, K) ((Rhs)[K])
3349#ifndef YYLLOC_DEFAULT
3350# define YYLLOC_DEFAULT(Current, Rhs, N) \
3351 do \
3352 if (YYID (N)) \
3353 { \
3354 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
3355 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
3356 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
3357 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
3358 } \
3359 else \
3360 { \
3361 (Current).first_line = (Current).last_line = \
3362 YYRHSLOC (Rhs, 0).last_line; \
3363 (Current).first_column = (Current).last_column = \
3364 YYRHSLOC (Rhs, 0).last_column; \
3365 } \
3366 while (YYID (0))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003367#endif
3368
Chris Lattnera62e8e42007-12-29 20:47:37 +00003369
3370/* YY_LOCATION_PRINT -- Print the location on the stream.
3371 This macro was not mandated originally: define only if we know
3372 we won't break user code: when these are the locations we know. */
3373
3374#ifndef YY_LOCATION_PRINT
3375# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
3376# define YY_LOCATION_PRINT(File, Loc) \
3377 fprintf (File, "%d.%d-%d.%d", \
3378 (Loc).first_line, (Loc).first_column, \
3379 (Loc).last_line, (Loc).last_column)
3380# else
3381# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
3382# endif
3383#endif
3384
3385
3386/* YYLEX -- calling `yylex' with the right arguments. */
3387
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003388#ifdef YYLEX_PARAM
Chris Lattnera62e8e42007-12-29 20:47:37 +00003389# define YYLEX yylex (YYLEX_PARAM)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003390#else
Chris Lattnera62e8e42007-12-29 20:47:37 +00003391# define YYLEX yylex ()
Christopher Lambfb623c62007-12-17 01:17:35 +00003392#endif
Chris Lattnera62e8e42007-12-29 20:47:37 +00003393
3394/* Enable debugging if requested. */
3395#if YYDEBUG
3396
3397# ifndef YYFPRINTF
3398# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
3399# define YYFPRINTF fprintf
3400# endif
3401
3402# define YYDPRINTF(Args) \
3403do { \
3404 if (yydebug) \
3405 YYFPRINTF Args; \
3406} while (YYID (0))
3407
3408# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
3409do { \
3410 if (yydebug) \
3411 { \
3412 YYFPRINTF (stderr, "%s ", Title); \
3413 yy_symbol_print (stderr, \
3414 Type, Value); \
3415 YYFPRINTF (stderr, "\n"); \
3416 } \
3417} while (YYID (0))
3418
3419
3420/*--------------------------------.
3421| Print this symbol on YYOUTPUT. |
3422`--------------------------------*/
3423
3424/*ARGSUSED*/
3425#if (defined __STDC__ || defined __C99__FUNC__ \
3426 || defined __cplusplus || defined _MSC_VER)
3427static void
3428yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
Christopher Lambfb623c62007-12-17 01:17:35 +00003429#else
Chris Lattnera62e8e42007-12-29 20:47:37 +00003430static void
3431yy_symbol_value_print (yyoutput, yytype, yyvaluep)
3432 FILE *yyoutput;
3433 int yytype;
3434 YYSTYPE const * const yyvaluep;
Christopher Lambfb623c62007-12-17 01:17:35 +00003435#endif
Chris Lattnera62e8e42007-12-29 20:47:37 +00003436{
3437 if (!yyvaluep)
3438 return;
3439# ifdef YYPRINT
3440 if (yytype < YYNTOKENS)
3441 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
3442# else
3443 YYUSE (yyoutput);
3444# endif
3445 switch (yytype)
3446 {
3447 default:
3448 break;
3449 }
3450}
3451
3452
3453/*--------------------------------.
3454| Print this symbol on YYOUTPUT. |
3455`--------------------------------*/
3456
3457#if (defined __STDC__ || defined __C99__FUNC__ \
3458 || defined __cplusplus || defined _MSC_VER)
3459static void
3460yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
3461#else
3462static void
3463yy_symbol_print (yyoutput, yytype, yyvaluep)
3464 FILE *yyoutput;
3465 int yytype;
3466 YYSTYPE const * const yyvaluep;
Dale Johannesen3afee192007-09-07 21:07:57 +00003467#endif
Chris Lattnera62e8e42007-12-29 20:47:37 +00003468{
3469 if (yytype < YYNTOKENS)
3470 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
3471 else
3472 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
Duncan Sandsf5588dc2007-11-27 13:23:08 +00003473
Chris Lattnera62e8e42007-12-29 20:47:37 +00003474 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
3475 YYFPRINTF (yyoutput, ")");
3476}
Duncan Sandsf5588dc2007-11-27 13:23:08 +00003477
Chris Lattnera62e8e42007-12-29 20:47:37 +00003478/*------------------------------------------------------------------.
3479| yy_stack_print -- Print the state stack from its BOTTOM up to its |
3480| TOP (included). |
3481`------------------------------------------------------------------*/
Duncan Sandsf5588dc2007-11-27 13:23:08 +00003482
Chris Lattnera62e8e42007-12-29 20:47:37 +00003483#if (defined __STDC__ || defined __C99__FUNC__ \
3484 || defined __cplusplus || defined _MSC_VER)
3485static void
3486yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
3487#else
3488static void
3489yy_stack_print (bottom, top)
3490 yytype_int16 *bottom;
3491 yytype_int16 *top;
Dale Johannesen3afee192007-09-07 21:07:57 +00003492#endif
Chris Lattnera62e8e42007-12-29 20:47:37 +00003493{
3494 YYFPRINTF (stderr, "Stack now");
3495 for (; bottom <= top; ++bottom)
3496 YYFPRINTF (stderr, " %d", *bottom);
3497 YYFPRINTF (stderr, "\n");
3498}
Duncan Sandsf5588dc2007-11-27 13:23:08 +00003499
Chris Lattnera62e8e42007-12-29 20:47:37 +00003500# define YY_STACK_PRINT(Bottom, Top) \
3501do { \
3502 if (yydebug) \
3503 yy_stack_print ((Bottom), (Top)); \
3504} while (YYID (0))
Duncan Sandsf5588dc2007-11-27 13:23:08 +00003505
Chris Lattnera62e8e42007-12-29 20:47:37 +00003506
3507/*------------------------------------------------.
3508| Report that the YYRULE is going to be reduced. |
3509`------------------------------------------------*/
3510
3511#if (defined __STDC__ || defined __C99__FUNC__ \
3512 || defined __cplusplus || defined _MSC_VER)
3513static void
3514yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
3515#else
3516static void
3517yy_reduce_print (yyvsp, yyrule)
3518 YYSTYPE *yyvsp;
3519 int yyrule;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003520#endif
Chris Lattnera62e8e42007-12-29 20:47:37 +00003521{
3522 int yynrhs = yyr2[yyrule];
3523 int yyi;
3524 unsigned long int yylno = yyrline[yyrule];
3525 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
3526 yyrule - 1, yylno);
3527 /* The symbols being reduced. */
3528 for (yyi = 0; yyi < yynrhs; yyi++)
3529 {
3530 fprintf (stderr, " $%d = ", yyi + 1);
3531 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
3532 &(yyvsp[(yyi + 1) - (yynrhs)])
3533 );
3534 fprintf (stderr, "\n");
3535 }
3536}
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003537
Chris Lattnera62e8e42007-12-29 20:47:37 +00003538# define YY_REDUCE_PRINT(Rule) \
3539do { \
3540 if (yydebug) \
3541 yy_reduce_print (yyvsp, Rule); \
3542} while (YYID (0))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003543
Chris Lattnera62e8e42007-12-29 20:47:37 +00003544/* Nonzero means print parse trace. It is left uninitialized so that
3545 multiple parsers can coexist. */
3546int yydebug;
3547#else /* !YYDEBUG */
3548# define YYDPRINTF(Args)
3549# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
3550# define YY_STACK_PRINT(Bottom, Top)
3551# define YY_REDUCE_PRINT(Rule)
3552#endif /* !YYDEBUG */
3553
3554
3555/* YYINITDEPTH -- initial size of the parser's stacks. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003556#ifndef YYINITDEPTH
Chris Lattnera62e8e42007-12-29 20:47:37 +00003557# define YYINITDEPTH 200
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003558#endif
3559
Chris Lattnera62e8e42007-12-29 20:47:37 +00003560/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
3561 if the built-in stack extension method is used).
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003562
Chris Lattnera62e8e42007-12-29 20:47:37 +00003563 Do not make this value too large; the results are undefined if
3564 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
3565 evaluated with infinite-precision integer arithmetic. */
David Greene48556392007-09-04 18:46:50 +00003566
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003567#ifndef YYMAXDEPTH
Chris Lattnera62e8e42007-12-29 20:47:37 +00003568# define YYMAXDEPTH 10000
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003569#endif
Chris Lattnera62e8e42007-12-29 20:47:37 +00003570
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003571
3572
Chris Lattnera62e8e42007-12-29 20:47:37 +00003573#if YYERROR_VERBOSE
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003574
Chris Lattnera62e8e42007-12-29 20:47:37 +00003575# ifndef yystrlen
3576# if defined __GLIBC__ && defined _STRING_H
3577# define yystrlen strlen
3578# else
3579/* Return the length of YYSTR. */
3580#if (defined __STDC__ || defined __C99__FUNC__ \
3581 || defined __cplusplus || defined _MSC_VER)
3582static YYSIZE_T
3583yystrlen (const char *yystr)
Duncan Sandsf5588dc2007-11-27 13:23:08 +00003584#else
Chris Lattnera62e8e42007-12-29 20:47:37 +00003585static YYSIZE_T
3586yystrlen (yystr)
3587 const char *yystr;
3588#endif
3589{
3590 YYSIZE_T yylen;
3591 for (yylen = 0; yystr[yylen]; yylen++)
3592 continue;
3593 return yylen;
3594}
3595# endif
3596# endif
3597
3598# ifndef yystpcpy
3599# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
3600# define yystpcpy stpcpy
3601# else
3602/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
3603 YYDEST. */
3604#if (defined __STDC__ || defined __C99__FUNC__ \
3605 || defined __cplusplus || defined _MSC_VER)
3606static char *
3607yystpcpy (char *yydest, const char *yysrc)
3608#else
3609static char *
3610yystpcpy (yydest, yysrc)
3611 char *yydest;
3612 const char *yysrc;
3613#endif
3614{
3615 char *yyd = yydest;
3616 const char *yys = yysrc;
3617
3618 while ((*yyd++ = *yys++) != '\0')
3619 continue;
3620
3621 return yyd - 1;
3622}
3623# endif
3624# endif
3625
3626# ifndef yytnamerr
3627/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
3628 quotes and backslashes, so that it's suitable for yyerror. The
3629 heuristic is that double-quoting is unnecessary unless the string
3630 contains an apostrophe, a comma, or backslash (other than
3631 backslash-backslash). YYSTR is taken from yytname. If YYRES is
3632 null, do not copy; instead, return the length of what the result
3633 would have been. */
3634static YYSIZE_T
3635yytnamerr (char *yyres, const char *yystr)
3636{
3637 if (*yystr == '"')
3638 {
3639 YYSIZE_T yyn = 0;
3640 char const *yyp = yystr;
3641
3642 for (;;)
3643 switch (*++yyp)
3644 {
3645 case '\'':
3646 case ',':
3647 goto do_not_strip_quotes;
3648
3649 case '\\':
3650 if (*++yyp != '\\')
3651 goto do_not_strip_quotes;
3652 /* Fall through. */
3653 default:
3654 if (yyres)
3655 yyres[yyn] = *yyp;
3656 yyn++;
3657 break;
3658
3659 case '"':
3660 if (yyres)
3661 yyres[yyn] = '\0';
3662 return yyn;
3663 }
3664 do_not_strip_quotes: ;
3665 }
3666
3667 if (! yyres)
3668 return yystrlen (yystr);
3669
3670 return yystpcpy (yyres, yystr) - yyres;
3671}
3672# endif
3673
3674/* Copy into YYRESULT an error message about the unexpected token
3675 YYCHAR while in state YYSTATE. Return the number of bytes copied,
3676 including the terminating null byte. If YYRESULT is null, do not
3677 copy anything; just return the number of bytes that would be
3678 copied. As a special case, return 0 if an ordinary "syntax error"
3679 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
3680 size calculation. */
3681static YYSIZE_T
3682yysyntax_error (char *yyresult, int yystate, int yychar)
3683{
3684 int yyn = yypact[yystate];
3685
3686 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
3687 return 0;
3688 else
3689 {
3690 int yytype = YYTRANSLATE (yychar);
3691 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
3692 YYSIZE_T yysize = yysize0;
3693 YYSIZE_T yysize1;
3694 int yysize_overflow = 0;
3695 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
3696 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
3697 int yyx;
3698
3699# if 0
3700 /* This is so xgettext sees the translatable formats that are
3701 constructed on the fly. */
3702 YY_("syntax error, unexpected %s");
3703 YY_("syntax error, unexpected %s, expecting %s");
3704 YY_("syntax error, unexpected %s, expecting %s or %s");
3705 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
3706 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
3707# endif
3708 char *yyfmt;
3709 char const *yyf;
3710 static char const yyunexpected[] = "syntax error, unexpected %s";
3711 static char const yyexpecting[] = ", expecting %s";
3712 static char const yyor[] = " or %s";
3713 char yyformat[sizeof yyunexpected
3714 + sizeof yyexpecting - 1
3715 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
3716 * (sizeof yyor - 1))];
3717 char const *yyprefix = yyexpecting;
3718
3719 /* Start YYX at -YYN if negative to avoid negative indexes in
3720 YYCHECK. */
3721 int yyxbegin = yyn < 0 ? -yyn : 0;
3722
3723 /* Stay within bounds of both yycheck and yytname. */
3724 int yychecklim = YYLAST - yyn + 1;
3725 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
3726 int yycount = 1;
3727
3728 yyarg[0] = yytname[yytype];
3729 yyfmt = yystpcpy (yyformat, yyunexpected);
3730
3731 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
3732 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
3733 {
3734 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
3735 {
3736 yycount = 1;
3737 yysize = yysize0;
3738 yyformat[sizeof yyunexpected - 1] = '\0';
3739 break;
3740 }
3741 yyarg[yycount++] = yytname[yyx];
3742 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
3743 yysize_overflow |= (yysize1 < yysize);
3744 yysize = yysize1;
3745 yyfmt = yystpcpy (yyfmt, yyprefix);
3746 yyprefix = yyor;
3747 }
3748
3749 yyf = YY_(yyformat);
3750 yysize1 = yysize + yystrlen (yyf);
3751 yysize_overflow |= (yysize1 < yysize);
3752 yysize = yysize1;
3753
3754 if (yysize_overflow)
3755 return YYSIZE_MAXIMUM;
3756
3757 if (yyresult)
3758 {
3759 /* Avoid sprintf, as that infringes on the user's name space.
3760 Don't have undefined behavior even if the translation
3761 produced a string with the wrong number of "%s"s. */
3762 char *yyp = yyresult;
3763 int yyi = 0;
3764 while ((*yyp = *yyf) != '\0')
3765 {
3766 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
3767 {
3768 yyp += yytnamerr (yyp, yyarg[yyi++]);
3769 yyf += 2;
3770 }
3771 else
3772 {
3773 yyp++;
3774 yyf++;
3775 }
3776 }
3777 }
3778 return yysize;
3779 }
3780}
3781#endif /* YYERROR_VERBOSE */
3782
3783
3784/*-----------------------------------------------.
3785| Release the memory associated to this symbol. |
3786`-----------------------------------------------*/
3787
3788/*ARGSUSED*/
3789#if (defined __STDC__ || defined __C99__FUNC__ \
3790 || defined __cplusplus || defined _MSC_VER)
3791static void
3792yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
3793#else
3794static void
3795yydestruct (yymsg, yytype, yyvaluep)
3796 const char *yymsg;
3797 int yytype;
3798 YYSTYPE *yyvaluep;
3799#endif
3800{
3801 YYUSE (yyvaluep);
3802
3803 if (!yymsg)
3804 yymsg = "Deleting";
3805 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
3806
3807 switch (yytype)
3808 {
3809
3810 default:
3811 break;
3812 }
3813}
3814
3815
3816/* Prevent warnings from -Wmissing-prototypes. */
3817
3818#ifdef YYPARSE_PARAM
3819#if defined __STDC__ || defined __cplusplus
3820int yyparse (void *YYPARSE_PARAM);
3821#else
3822int yyparse ();
3823#endif
3824#else /* ! YYPARSE_PARAM */
3825#if defined __STDC__ || defined __cplusplus
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003826int yyparse (void);
Christopher Lambfb623c62007-12-17 01:17:35 +00003827#else
Chris Lattnera62e8e42007-12-29 20:47:37 +00003828int yyparse ();
Dale Johannesen3afee192007-09-07 21:07:57 +00003829#endif
Chris Lattnera62e8e42007-12-29 20:47:37 +00003830#endif /* ! YYPARSE_PARAM */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003831
Duncan Sandsf5588dc2007-11-27 13:23:08 +00003832
Chris Lattnera62e8e42007-12-29 20:47:37 +00003833
3834/* The look-ahead symbol. */
3835int yychar;
3836
3837/* The semantic value of the look-ahead symbol. */
3838YYSTYPE yylval;
3839
3840/* Number of syntax errors so far. */
3841int yynerrs;
3842
3843
3844
3845/*----------.
3846| yyparse. |
3847`----------*/
3848
3849#ifdef YYPARSE_PARAM
3850#if (defined __STDC__ || defined __C99__FUNC__ \
3851 || defined __cplusplus || defined _MSC_VER)
3852int
3853yyparse (void *YYPARSE_PARAM)
3854#else
3855int
3856yyparse (YYPARSE_PARAM)
3857 void *YYPARSE_PARAM;
3858#endif
3859#else /* ! YYPARSE_PARAM */
3860#if (defined __STDC__ || defined __C99__FUNC__ \
3861 || defined __cplusplus || defined _MSC_VER)
3862int
3863yyparse (void)
3864#else
3865int
3866yyparse ()
3867
Christopher Lambfb623c62007-12-17 01:17:35 +00003868#endif
3869#endif
Chris Lattnera62e8e42007-12-29 20:47:37 +00003870{
3871
3872 int yystate;
3873 int yyn;
3874 int yyresult;
3875 /* Number of tokens to shift before error messages enabled. */
3876 int yyerrstatus;
3877 /* Look-ahead token as an internal (translated) token number. */
3878 int yytoken = 0;
3879#if YYERROR_VERBOSE
3880 /* Buffer for error messages, and its allocated size. */
3881 char yymsgbuf[128];
3882 char *yymsg = yymsgbuf;
3883 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
Christopher Lambfb623c62007-12-17 01:17:35 +00003884#endif
Duncan Sandsf5588dc2007-11-27 13:23:08 +00003885
Chris Lattnera62e8e42007-12-29 20:47:37 +00003886 /* Three stacks and their tools:
3887 `yyss': related to states,
3888 `yyvs': related to semantic values,
3889 `yyls': related to locations.
3890
3891 Refer to the stacks thru separate pointers, to allow yyoverflow
3892 to reallocate them elsewhere. */
3893
3894 /* The state stack. */
3895 yytype_int16 yyssa[YYINITDEPTH];
3896 yytype_int16 *yyss = yyssa;
3897 yytype_int16 *yyssp;
3898
3899 /* The semantic value stack. */
3900 YYSTYPE yyvsa[YYINITDEPTH];
3901 YYSTYPE *yyvs = yyvsa;
3902 YYSTYPE *yyvsp;
3903
3904
3905
3906#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
3907
3908 YYSIZE_T yystacksize = YYINITDEPTH;
3909
3910 /* The variables used to return semantic value and location from the
3911 action routines. */
3912 YYSTYPE yyval;
3913
3914
3915 /* The number of symbols on the RHS of the reduced rule.
3916 Keep to zero when no symbol should be popped. */
3917 int yylen = 0;
3918
3919 YYDPRINTF ((stderr, "Starting parse\n"));
3920
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003921 yystate = 0;
3922 yyerrstatus = 0;
3923 yynerrs = 0;
3924 yychar = YYEMPTY; /* Cause a token to be read. */
3925
3926 /* Initialize stack pointers.
3927 Waste one element of value and location stack
3928 so that they stay on the same level as the state stack.
3929 The wasted elements are never initialized. */
3930
Chris Lattnera62e8e42007-12-29 20:47:37 +00003931 yyssp = yyss;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003932 yyvsp = yyvs;
3933
Chris Lattnera62e8e42007-12-29 20:47:37 +00003934 goto yysetstate;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003935
Chris Lattnera62e8e42007-12-29 20:47:37 +00003936/*------------------------------------------------------------.
3937| yynewstate -- Push a new state, which is found in yystate. |
3938`------------------------------------------------------------*/
3939 yynewstate:
3940 /* In all cases, when you get here, the value and location stacks
3941 have just been pushed. So pushing a state here evens the stacks. */
3942 yyssp++;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003943
Chris Lattnera62e8e42007-12-29 20:47:37 +00003944 yysetstate:
3945 *yyssp = yystate;
3946
3947 if (yyss + yystacksize - 1 <= yyssp)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003948 {
3949 /* Get the current used size of the three stacks, in elements. */
Chris Lattnera62e8e42007-12-29 20:47:37 +00003950 YYSIZE_T yysize = yyssp - yyss + 1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003951
3952#ifdef yyoverflow
Chris Lattnera62e8e42007-12-29 20:47:37 +00003953 {
3954 /* Give user a chance to reallocate the stack. Use copies of
3955 these so that the &'s don't force the real ones into
3956 memory. */
3957 YYSTYPE *yyvs1 = yyvs;
3958 yytype_int16 *yyss1 = yyss;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003959
Chris Lattnera62e8e42007-12-29 20:47:37 +00003960
3961 /* Each stack pointer address is followed by the size of the
3962 data in use in that stack, in bytes. This used to be a
3963 conditional around just the two extra args, but that might
3964 be undefined if yyoverflow is a macro. */
3965 yyoverflow (YY_("memory exhausted"),
3966 &yyss1, yysize * sizeof (*yyssp),
3967 &yyvs1, yysize * sizeof (*yyvsp),
3968
3969 &yystacksize);
3970
3971 yyss = yyss1;
3972 yyvs = yyvs1;
3973 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003974#else /* no yyoverflow */
Chris Lattnera62e8e42007-12-29 20:47:37 +00003975# ifndef YYSTACK_RELOCATE
3976 goto yyexhaustedlab;
3977# else
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003978 /* Extend the stack our own way. */
Chris Lattnera62e8e42007-12-29 20:47:37 +00003979 if (YYMAXDEPTH <= yystacksize)
3980 goto yyexhaustedlab;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003981 yystacksize *= 2;
Chris Lattnera62e8e42007-12-29 20:47:37 +00003982 if (YYMAXDEPTH < yystacksize)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003983 yystacksize = YYMAXDEPTH;
Chris Lattnera62e8e42007-12-29 20:47:37 +00003984
3985 {
3986 yytype_int16 *yyss1 = yyss;
3987 union yyalloc *yyptr =
3988 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
3989 if (! yyptr)
3990 goto yyexhaustedlab;
3991 YYSTACK_RELOCATE (yyss);
3992 YYSTACK_RELOCATE (yyvs);
3993
3994# undef YYSTACK_RELOCATE
3995 if (yyss1 != yyssa)
3996 YYSTACK_FREE (yyss1);
3997 }
3998# endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003999#endif /* no yyoverflow */
4000
Chris Lattnera62e8e42007-12-29 20:47:37 +00004001 yyssp = yyss + yysize - 1;
4002 yyvsp = yyvs + yysize - 1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004003
4004
Chris Lattnera62e8e42007-12-29 20:47:37 +00004005 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
4006 (unsigned long int) yystacksize));
4007
4008 if (yyss + yystacksize - 1 <= yyssp)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004009 YYABORT;
4010 }
4011
Chris Lattnera62e8e42007-12-29 20:47:37 +00004012 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004013
4014 goto yybackup;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004015
Chris Lattnera62e8e42007-12-29 20:47:37 +00004016/*-----------.
4017| yybackup. |
4018`-----------*/
4019yybackup:
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004020
Chris Lattnera62e8e42007-12-29 20:47:37 +00004021 /* Do appropriate processing given the current state. Read a
4022 look-ahead token if we need one and don't already have one. */
David Greene48556392007-09-04 18:46:50 +00004023
Chris Lattnera62e8e42007-12-29 20:47:37 +00004024 /* First try to decide what to do without reference to look-ahead token. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004025 yyn = yypact[yystate];
Chris Lattnera62e8e42007-12-29 20:47:37 +00004026 if (yyn == YYPACT_NINF)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004027 goto yydefault;
4028
Chris Lattnera62e8e42007-12-29 20:47:37 +00004029 /* Not known => get a look-ahead token if don't already have one. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004030
Chris Lattnera62e8e42007-12-29 20:47:37 +00004031 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004032 if (yychar == YYEMPTY)
4033 {
Chris Lattnera62e8e42007-12-29 20:47:37 +00004034 YYDPRINTF ((stderr, "Reading a token: "));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004035 yychar = YYLEX;
4036 }
4037
Chris Lattnera62e8e42007-12-29 20:47:37 +00004038 if (yychar <= YYEOF)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004039 {
Chris Lattnera62e8e42007-12-29 20:47:37 +00004040 yychar = yytoken = YYEOF;
4041 YYDPRINTF ((stderr, "Now at end of input.\n"));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004042 }
4043 else
4044 {
Chris Lattnera62e8e42007-12-29 20:47:37 +00004045 yytoken = YYTRANSLATE (yychar);
4046 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004047 }
4048
Chris Lattnera62e8e42007-12-29 20:47:37 +00004049 /* If the proper action on seeing token YYTOKEN is to reduce or to
4050 detect an error, take that action. */
4051 yyn += yytoken;
4052 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004053 goto yydefault;
4054 yyn = yytable[yyn];
Chris Lattnera62e8e42007-12-29 20:47:37 +00004055 if (yyn <= 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004056 {
Chris Lattnera62e8e42007-12-29 20:47:37 +00004057 if (yyn == 0 || yyn == YYTABLE_NINF)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004058 goto yyerrlab;
4059 yyn = -yyn;
4060 goto yyreduce;
4061 }
4062
4063 if (yyn == YYFINAL)
4064 YYACCEPT;
4065
Chris Lattnera62e8e42007-12-29 20:47:37 +00004066 /* Count tokens shifted since error; after three, turn off error
4067 status. */
4068 if (yyerrstatus)
4069 yyerrstatus--;
Dale Johannesen3afee192007-09-07 21:07:57 +00004070
Chris Lattnera62e8e42007-12-29 20:47:37 +00004071 /* Shift the look-ahead token. */
4072 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
David Greene48556392007-09-04 18:46:50 +00004073
Chris Lattnera62e8e42007-12-29 20:47:37 +00004074 /* Discard the shifted token unless it is eof. */
David Greene48556392007-09-04 18:46:50 +00004075 if (yychar != YYEOF)
4076 yychar = YYEMPTY;
4077
Christopher Lambfb623c62007-12-17 01:17:35 +00004078 yystate = yyn;
Chris Lattnera62e8e42007-12-29 20:47:37 +00004079 *++yyvsp = yylval;
4080
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004081 goto yynewstate;
4082
Christopher Lambfb623c62007-12-17 01:17:35 +00004083
Chris Lattnera62e8e42007-12-29 20:47:37 +00004084/*-----------------------------------------------------------.
4085| yydefault -- do the default action for the current state. |
4086`-----------------------------------------------------------*/
4087yydefault:
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004088 yyn = yydefact[yystate];
4089 if (yyn == 0)
4090 goto yyerrlab;
Chris Lattnera62e8e42007-12-29 20:47:37 +00004091 goto yyreduce;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004092
Chris Lattnera62e8e42007-12-29 20:47:37 +00004093
4094/*-----------------------------.
4095| yyreduce -- Do a reduction. |
4096`-----------------------------*/
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004097yyreduce:
Chris Lattnera62e8e42007-12-29 20:47:37 +00004098 /* yyn is the number of a rule to reduce with. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004099 yylen = yyr2[yyn];
4100
Chris Lattnera62e8e42007-12-29 20:47:37 +00004101 /* If YYLEN is nonzero, implement the default value of the action:
4102 `$$ = $1'.
4103
4104 Otherwise, the following line sets YYVAL to garbage.
4105 This behavior is undocumented and Bison
4106 users should not rely upon it. Assigning to YYVAL
4107 unconditionally makes the parser a bit smaller, and it avoids a
4108 GCC warning that YYVAL may be used uninitialized. */
4109 yyval = yyvsp[1-yylen];
4110
4111
4112 YY_REDUCE_PRINT (yyn);
4113 switch (yyn)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004114 {
Chris Lattnera62e8e42007-12-29 20:47:37 +00004115 case 3:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004116#line 1821 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004117 {
4118 if ((yyvsp[(1) - (1)].UIntVal) > (uint32_t)INT32_MAX) // Outside of my range!
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004119 error("Value too large for type");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004120 (yyval.SIntVal) = (int32_t)(yyvsp[(1) - (1)].UIntVal);
4121 ;}
4122 break;
4123
4124 case 5:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004125#line 1830 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004126 {
4127 if ((yyvsp[(1) - (1)].UInt64Val) > (uint64_t)INT64_MAX) // Outside of my range!
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004128 error("Value too large for type");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004129 (yyval.SInt64Val) = (int64_t)(yyvsp[(1) - (1)].UInt64Val);
4130 ;}
4131 break;
4132
4133 case 26:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004134#line 1852 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004135 { (yyval.IPred) = ICmpInst::ICMP_EQ; ;}
4136 break;
4137
4138 case 27:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004139#line 1852 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004140 { (yyval.IPred) = ICmpInst::ICMP_NE; ;}
4141 break;
4142
4143 case 28:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004144#line 1853 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004145 { (yyval.IPred) = ICmpInst::ICMP_SLT; ;}
4146 break;
4147
4148 case 29:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004149#line 1853 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004150 { (yyval.IPred) = ICmpInst::ICMP_SGT; ;}
4151 break;
4152
4153 case 30:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004154#line 1854 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004155 { (yyval.IPred) = ICmpInst::ICMP_SLE; ;}
4156 break;
4157
4158 case 31:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004159#line 1854 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004160 { (yyval.IPred) = ICmpInst::ICMP_SGE; ;}
4161 break;
4162
4163 case 32:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004164#line 1855 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004165 { (yyval.IPred) = ICmpInst::ICMP_ULT; ;}
4166 break;
4167
4168 case 33:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004169#line 1855 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004170 { (yyval.IPred) = ICmpInst::ICMP_UGT; ;}
4171 break;
4172
4173 case 34:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004174#line 1856 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004175 { (yyval.IPred) = ICmpInst::ICMP_ULE; ;}
4176 break;
4177
4178 case 35:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004179#line 1856 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004180 { (yyval.IPred) = ICmpInst::ICMP_UGE; ;}
4181 break;
4182
4183 case 36:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004184#line 1860 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004185 { (yyval.FPred) = FCmpInst::FCMP_OEQ; ;}
4186 break;
4187
4188 case 37:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004189#line 1860 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004190 { (yyval.FPred) = FCmpInst::FCMP_ONE; ;}
4191 break;
4192
4193 case 38:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004194#line 1861 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004195 { (yyval.FPred) = FCmpInst::FCMP_OLT; ;}
4196 break;
4197
4198 case 39:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004199#line 1861 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004200 { (yyval.FPred) = FCmpInst::FCMP_OGT; ;}
4201 break;
4202
4203 case 40:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004204#line 1862 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004205 { (yyval.FPred) = FCmpInst::FCMP_OLE; ;}
4206 break;
4207
4208 case 41:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004209#line 1862 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004210 { (yyval.FPred) = FCmpInst::FCMP_OGE; ;}
4211 break;
4212
4213 case 42:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004214#line 1863 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004215 { (yyval.FPred) = FCmpInst::FCMP_ORD; ;}
4216 break;
4217
4218 case 43:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004219#line 1863 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004220 { (yyval.FPred) = FCmpInst::FCMP_UNO; ;}
4221 break;
4222
4223 case 44:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004224#line 1864 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004225 { (yyval.FPred) = FCmpInst::FCMP_UEQ; ;}
4226 break;
4227
4228 case 45:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004229#line 1864 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004230 { (yyval.FPred) = FCmpInst::FCMP_UNE; ;}
4231 break;
4232
4233 case 46:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004234#line 1865 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004235 { (yyval.FPred) = FCmpInst::FCMP_ULT; ;}
4236 break;
4237
4238 case 47:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004239#line 1865 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004240 { (yyval.FPred) = FCmpInst::FCMP_UGT; ;}
4241 break;
4242
4243 case 48:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004244#line 1866 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004245 { (yyval.FPred) = FCmpInst::FCMP_ULE; ;}
4246 break;
4247
4248 case 49:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004249#line 1866 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004250 { (yyval.FPred) = FCmpInst::FCMP_UGE; ;}
4251 break;
4252
4253 case 50:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004254#line 1867 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004255 { (yyval.FPred) = FCmpInst::FCMP_TRUE; ;}
4256 break;
4257
4258 case 51:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004259#line 1868 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004260 { (yyval.FPred) = FCmpInst::FCMP_FALSE; ;}
4261 break;
4262
4263 case 81:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004264#line 1899 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004265 {
4266 (yyval.StrVal) = (yyvsp[(1) - (2)].StrVal);
4267 ;}
4268 break;
4269
4270 case 82:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004271#line 1902 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004272 {
4273 (yyval.StrVal) = 0;
4274 ;}
4275 break;
4276
4277 case 83:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004278#line 1907 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004279 { (yyval.Linkage) = GlobalValue::InternalLinkage; ;}
4280 break;
4281
4282 case 84:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004283#line 1908 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004284 { (yyval.Linkage) = GlobalValue::LinkOnceLinkage; ;}
4285 break;
4286
4287 case 85:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004288#line 1909 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004289 { (yyval.Linkage) = GlobalValue::WeakLinkage; ;}
4290 break;
4291
4292 case 86:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004293#line 1910 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004294 { (yyval.Linkage) = GlobalValue::AppendingLinkage; ;}
4295 break;
4296
4297 case 87:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004298#line 1911 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004299 { (yyval.Linkage) = GlobalValue::DLLImportLinkage; ;}
4300 break;
4301
4302 case 88:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004303#line 1912 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004304 { (yyval.Linkage) = GlobalValue::DLLExportLinkage; ;}
4305 break;
4306
4307 case 89:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004308#line 1913 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004309 { (yyval.Linkage) = GlobalValue::ExternalWeakLinkage; ;}
4310 break;
4311
4312 case 90:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004313#line 1914 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004314 { (yyval.Linkage) = GlobalValue::ExternalLinkage; ;}
4315 break;
4316
4317 case 91:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004318#line 1918 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004319 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::C; ;}
4320 break;
4321
4322 case 92:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004323#line 1919 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004324 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::C; ;}
4325 break;
4326
4327 case 93:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004328#line 1920 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004329 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::CSRet; ;}
4330 break;
4331
4332 case 94:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004333#line 1921 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004334 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::Fast; ;}
4335 break;
4336
4337 case 95:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004338#line 1922 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004339 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::Cold; ;}
4340 break;
4341
4342 case 96:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004343#line 1923 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004344 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::X86_StdCall; ;}
4345 break;
4346
4347 case 97:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004348#line 1924 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004349 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::X86_FastCall; ;}
4350 break;
4351
4352 case 98:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004353#line 1925 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004354 {
4355 if ((unsigned)(yyvsp[(2) - (2)].UInt64Val) != (yyvsp[(2) - (2)].UInt64Val))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004356 error("Calling conv too large");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004357 (yyval.UIntVal) = lastCallingConv = (yyvsp[(2) - (2)].UInt64Val);
4358 ;}
4359 break;
4360
4361 case 99:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004362#line 1935 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004363 { (yyval.UIntVal) = 0; ;}
4364 break;
4365
4366 case 100:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004367#line 1936 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004368 {
4369 (yyval.UIntVal) = (yyvsp[(2) - (2)].UInt64Val);
4370 if ((yyval.UIntVal) != 0 && !isPowerOf2_32((yyval.UIntVal)))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004371 error("Alignment must be a power of two");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004372 ;}
4373 break;
4374
4375 case 101:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004376#line 1944 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004377 { (yyval.UIntVal) = 0; ;}
4378 break;
4379
4380 case 102:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004381#line 1945 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004382 {
4383 (yyval.UIntVal) = (yyvsp[(3) - (3)].UInt64Val);
4384 if ((yyval.UIntVal) != 0 && !isPowerOf2_32((yyval.UIntVal)))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004385 error("Alignment must be a power of two");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004386 ;}
4387 break;
4388
4389 case 103:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004390#line 1953 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004391 {
4392 for (unsigned i = 0, e = strlen((yyvsp[(2) - (2)].StrVal)); i != e; ++i)
4393 if ((yyvsp[(2) - (2)].StrVal)[i] == '"' || (yyvsp[(2) - (2)].StrVal)[i] == '\\')
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004394 error("Invalid character in section name");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004395 (yyval.StrVal) = (yyvsp[(2) - (2)].StrVal);
4396 ;}
4397 break;
4398
4399 case 104:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004400#line 1962 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004401 { (yyval.StrVal) = 0; ;}
4402 break;
4403
4404 case 105:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004405#line 1963 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004406 { (yyval.StrVal) = (yyvsp[(1) - (1)].StrVal); ;}
4407 break;
4408
4409 case 106:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004410#line 1970 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004411 {;}
4412 break;
4413
4414 case 107:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004415#line 1971 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004416 {;}
4417 break;
4418
4419 case 108:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004420#line 1975 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004421 {
4422 CurGV->setSection((yyvsp[(1) - (1)].StrVal));
4423 free((yyvsp[(1) - (1)].StrVal));
4424 ;}
4425 break;
4426
4427 case 109:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004428#line 1979 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004429 {
4430 if ((yyvsp[(2) - (2)].UInt64Val) != 0 && !isPowerOf2_32((yyvsp[(2) - (2)].UInt64Val)))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004431 error("Alignment must be a power of two");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004432 CurGV->setAlignment((yyvsp[(2) - (2)].UInt64Val));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004433
Chris Lattnera62e8e42007-12-29 20:47:37 +00004434 ;}
4435 break;
4436
4437 case 111:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004438#line 1996 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004439 {
4440 (yyval.TypeVal).PAT = new PATypeHolder((yyvsp[(1) - (1)].PrimType).T);
4441 (yyval.TypeVal).S.makeSignless();
4442 ;}
4443 break;
4444
4445 case 113:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004446#line 2004 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004447 {
4448 (yyval.TypeVal).PAT = new PATypeHolder((yyvsp[(1) - (1)].PrimType).T);
4449 (yyval.TypeVal).S.makeSignless();
4450 ;}
4451 break;
4452
4453 case 114:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004454#line 2011 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004455 {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004456 if (!UpRefs.empty())
Chris Lattnera62e8e42007-12-29 20:47:37 +00004457 error("Invalid upreference in type: " + (*(yyvsp[(1) - (1)].TypeVal).PAT)->getDescription());
4458 (yyval.TypeVal) = (yyvsp[(1) - (1)].TypeVal);
4459 ;}
4460 break;
4461
4462 case 127:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004463#line 2025 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004464 {
4465 (yyval.TypeVal).PAT = new PATypeHolder((yyvsp[(1) - (1)].PrimType).T);
4466 (yyval.TypeVal).S.copy((yyvsp[(1) - (1)].PrimType).S);
4467 ;}
4468 break;
4469
4470 case 128:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004471#line 2029 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004472 {
4473 (yyval.TypeVal).PAT = new PATypeHolder(OpaqueType::get());
4474 (yyval.TypeVal).S.makeSignless();
4475 ;}
4476 break;
4477
4478 case 129:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004479#line 2033 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004480 { // Named types are also simple types...
4481 (yyval.TypeVal).S.copy(getTypeSign((yyvsp[(1) - (1)].ValIDVal)));
4482 const Type* tmp = getType((yyvsp[(1) - (1)].ValIDVal));
4483 (yyval.TypeVal).PAT = new PATypeHolder(tmp);
4484 ;}
4485 break;
4486
4487 case 130:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004488#line 2038 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004489 { // Type UpReference
4490 if ((yyvsp[(2) - (2)].UInt64Val) > (uint64_t)~0U)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004491 error("Value out of range");
4492 OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder
Chris Lattnera62e8e42007-12-29 20:47:37 +00004493 UpRefs.push_back(UpRefRecord((unsigned)(yyvsp[(2) - (2)].UInt64Val), OT)); // Add to vector...
4494 (yyval.TypeVal).PAT = new PATypeHolder(OT);
4495 (yyval.TypeVal).S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004496 UR_OUT("New Upreference!\n");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004497 ;}
4498 break;
4499
4500 case 131:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004501#line 2047 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004502 { // Function derived type?
4503 (yyval.TypeVal).S.makeComposite((yyvsp[(1) - (4)].TypeVal).S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004504 std::vector<const Type*> Params;
Chris Lattnera62e8e42007-12-29 20:47:37 +00004505 for (std::list<llvm::PATypeInfo>::iterator I = (yyvsp[(3) - (4)].TypeList)->begin(),
4506 E = (yyvsp[(3) - (4)].TypeList)->end(); I != E; ++I) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004507 Params.push_back(I->PAT->get());
Chris Lattnera62e8e42007-12-29 20:47:37 +00004508 (yyval.TypeVal).S.add(I->S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004509 }
4510 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
4511 if (isVarArg) Params.pop_back();
4512
Chris Lattner1c8733e2008-03-12 17:45:29 +00004513 PAListPtr PAL;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004514 if (lastCallingConv == OldCallingConv::CSRet) {
Chris Lattner1c8733e2008-03-12 17:45:29 +00004515 ParamAttrsWithIndex PAWI =
4516 ParamAttrsWithIndex::get(1, ParamAttr::StructRet);
4517 PAL = PAListPtr::get(&PAWI, 1);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004518 }
4519
4520 const FunctionType *FTy =
Chris Lattnera62e8e42007-12-29 20:47:37 +00004521 FunctionType::get((yyvsp[(1) - (4)].TypeVal).PAT->get(), Params, isVarArg);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004522
Chris Lattnera62e8e42007-12-29 20:47:37 +00004523 (yyval.TypeVal).PAT = new PATypeHolder( HandleUpRefs(FTy, (yyval.TypeVal).S) );
4524 delete (yyvsp[(1) - (4)].TypeVal).PAT; // Delete the return type handle
4525 delete (yyvsp[(3) - (4)].TypeList); // Delete the argument list
4526 ;}
4527 break;
4528
4529 case 132:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004530#line 2072 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004531 { // Sized array type?
4532 (yyval.TypeVal).S.makeComposite((yyvsp[(4) - (5)].TypeVal).S);
4533 (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(ArrayType::get((yyvsp[(4) - (5)].TypeVal).PAT->get(),
4534 (unsigned)(yyvsp[(2) - (5)].UInt64Val)), (yyval.TypeVal).S));
4535 delete (yyvsp[(4) - (5)].TypeVal).PAT;
4536 ;}
4537 break;
4538
4539 case 133:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004540#line 2078 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004541 { // Vector type?
4542 const llvm::Type* ElemTy = (yyvsp[(4) - (5)].TypeVal).PAT->get();
4543 if ((unsigned)(yyvsp[(2) - (5)].UInt64Val) != (yyvsp[(2) - (5)].UInt64Val))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004544 error("Unsigned result not equal to signed result");
4545 if (!(ElemTy->isInteger() || ElemTy->isFloatingPoint()))
4546 error("Elements of a VectorType must be integer or floating point");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004547 if (!isPowerOf2_32((yyvsp[(2) - (5)].UInt64Val)))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004548 error("VectorType length should be a power of 2");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004549 (yyval.TypeVal).S.makeComposite((yyvsp[(4) - (5)].TypeVal).S);
4550 (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(VectorType::get(ElemTy,
4551 (unsigned)(yyvsp[(2) - (5)].UInt64Val)), (yyval.TypeVal).S));
4552 delete (yyvsp[(4) - (5)].TypeVal).PAT;
4553 ;}
4554 break;
4555
4556 case 134:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004557#line 2091 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004558 { // Structure type?
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004559 std::vector<const Type*> Elements;
Chris Lattnera62e8e42007-12-29 20:47:37 +00004560 (yyval.TypeVal).S.makeComposite();
4561 for (std::list<llvm::PATypeInfo>::iterator I = (yyvsp[(2) - (3)].TypeList)->begin(),
4562 E = (yyvsp[(2) - (3)].TypeList)->end(); I != E; ++I) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004563 Elements.push_back(I->PAT->get());
Chris Lattnera62e8e42007-12-29 20:47:37 +00004564 (yyval.TypeVal).S.add(I->S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004565 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00004566 (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements), (yyval.TypeVal).S));
4567 delete (yyvsp[(2) - (3)].TypeList);
4568 ;}
4569 break;
4570
4571 case 135:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004572#line 2102 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004573 { // Empty structure type?
4574 (yyval.TypeVal).PAT = new PATypeHolder(StructType::get(std::vector<const Type*>()));
4575 (yyval.TypeVal).S.makeComposite();
4576 ;}
4577 break;
4578
4579 case 136:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004580#line 2106 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004581 { // Packed Structure type?
4582 (yyval.TypeVal).S.makeComposite();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004583 std::vector<const Type*> Elements;
Chris Lattnera62e8e42007-12-29 20:47:37 +00004584 for (std::list<llvm::PATypeInfo>::iterator I = (yyvsp[(3) - (5)].TypeList)->begin(),
4585 E = (yyvsp[(3) - (5)].TypeList)->end(); I != E; ++I) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004586 Elements.push_back(I->PAT->get());
Chris Lattnera62e8e42007-12-29 20:47:37 +00004587 (yyval.TypeVal).S.add(I->S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004588 delete I->PAT;
4589 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00004590 (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements, true),
4591 (yyval.TypeVal).S));
4592 delete (yyvsp[(3) - (5)].TypeList);
4593 ;}
4594 break;
4595
4596 case 137:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004597#line 2119 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004598 { // Empty packed structure type?
4599 (yyval.TypeVal).PAT = new PATypeHolder(StructType::get(std::vector<const Type*>(),true));
4600 (yyval.TypeVal).S.makeComposite();
4601 ;}
4602 break;
4603
4604 case 138:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004605#line 2123 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004606 { // Pointer type?
4607 if ((yyvsp[(1) - (2)].TypeVal).PAT->get() == Type::LabelTy)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004608 error("Cannot form a pointer to a basic block");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004609 (yyval.TypeVal).S.makeComposite((yyvsp[(1) - (2)].TypeVal).S);
4610 (yyval.TypeVal).PAT = new
4611 PATypeHolder(HandleUpRefs(PointerType::getUnqual((yyvsp[(1) - (2)].TypeVal).PAT->get()),
4612 (yyval.TypeVal).S));
4613 delete (yyvsp[(1) - (2)].TypeVal).PAT;
4614 ;}
4615 break;
4616
4617 case 139:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004618#line 2138 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004619 {
4620 (yyval.TypeList) = new std::list<PATypeInfo>();
4621 (yyval.TypeList)->push_back((yyvsp[(1) - (1)].TypeVal));
4622 ;}
4623 break;
4624
4625 case 140:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004626#line 2142 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004627 {
4628 ((yyval.TypeList)=(yyvsp[(1) - (3)].TypeList))->push_back((yyvsp[(3) - (3)].TypeVal));
4629 ;}
4630 break;
4631
4632 case 142:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004633#line 2150 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004634 {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004635 PATypeInfo VoidTI;
4636 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
4637 VoidTI.S.makeSignless();
Chris Lattnera62e8e42007-12-29 20:47:37 +00004638 ((yyval.TypeList)=(yyvsp[(1) - (3)].TypeList))->push_back(VoidTI);
4639 ;}
4640 break;
4641
4642 case 143:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004643#line 2156 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004644 {
4645 (yyval.TypeList) = new std::list<PATypeInfo>();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004646 PATypeInfo VoidTI;
4647 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
4648 VoidTI.S.makeSignless();
Chris Lattnera62e8e42007-12-29 20:47:37 +00004649 (yyval.TypeList)->push_back(VoidTI);
4650 ;}
4651 break;
4652
4653 case 144:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004654#line 2163 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004655 {
4656 (yyval.TypeList) = new std::list<PATypeInfo>();
4657 ;}
4658 break;
4659
4660 case 145:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004661#line 2175 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004662 { // Nonempty unsized arr
4663 const ArrayType *ATy = dyn_cast<ArrayType>((yyvsp[(1) - (4)].TypeVal).PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004664 if (ATy == 0)
4665 error("Cannot make array constant with type: '" +
Chris Lattnera62e8e42007-12-29 20:47:37 +00004666 (yyvsp[(1) - (4)].TypeVal).PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004667 const Type *ETy = ATy->getElementType();
4668 int NumElements = ATy->getNumElements();
4669
4670 // Verify that we have the correct size...
Chris Lattnera62e8e42007-12-29 20:47:37 +00004671 if (NumElements != -1 && NumElements != (int)(yyvsp[(3) - (4)].ConstVector)->size())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004672 error("Type mismatch: constant sized array initialized with " +
Chris Lattnera62e8e42007-12-29 20:47:37 +00004673 utostr((yyvsp[(3) - (4)].ConstVector)->size()) + " arguments, but has size of " +
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004674 itostr(NumElements) + "");
4675
4676 // Verify all elements are correct type!
4677 std::vector<Constant*> Elems;
Chris Lattnera62e8e42007-12-29 20:47:37 +00004678 for (unsigned i = 0; i < (yyvsp[(3) - (4)].ConstVector)->size(); i++) {
4679 Constant *C = (*(yyvsp[(3) - (4)].ConstVector))[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004680 const Type* ValTy = C->getType();
4681 if (ETy != ValTy)
4682 error("Element #" + utostr(i) + " is not of type '" +
4683 ETy->getDescription() +"' as required!\nIt is of type '"+
4684 ValTy->getDescription() + "'");
4685 Elems.push_back(C);
4686 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00004687 (yyval.ConstVal).C = ConstantArray::get(ATy, Elems);
4688 (yyval.ConstVal).S.copy((yyvsp[(1) - (4)].TypeVal).S);
4689 delete (yyvsp[(1) - (4)].TypeVal).PAT;
4690 delete (yyvsp[(3) - (4)].ConstVector);
4691 ;}
4692 break;
4693
4694 case 146:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004695#line 2205 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004696 {
4697 const ArrayType *ATy = dyn_cast<ArrayType>((yyvsp[(1) - (3)].TypeVal).PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004698 if (ATy == 0)
4699 error("Cannot make array constant with type: '" +
Chris Lattnera62e8e42007-12-29 20:47:37 +00004700 (yyvsp[(1) - (3)].TypeVal).PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004701 int NumElements = ATy->getNumElements();
4702 if (NumElements != -1 && NumElements != 0)
4703 error("Type mismatch: constant sized array initialized with 0"
4704 " arguments, but has size of " + itostr(NumElements) +"");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004705 (yyval.ConstVal).C = ConstantArray::get(ATy, std::vector<Constant*>());
4706 (yyval.ConstVal).S.copy((yyvsp[(1) - (3)].TypeVal).S);
4707 delete (yyvsp[(1) - (3)].TypeVal).PAT;
4708 ;}
4709 break;
4710
4711 case 147:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004712#line 2218 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004713 {
4714 const ArrayType *ATy = dyn_cast<ArrayType>((yyvsp[(1) - (3)].TypeVal).PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004715 if (ATy == 0)
4716 error("Cannot make array constant with type: '" +
Chris Lattnera62e8e42007-12-29 20:47:37 +00004717 (yyvsp[(1) - (3)].TypeVal).PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004718 int NumElements = ATy->getNumElements();
4719 const Type *ETy = dyn_cast<IntegerType>(ATy->getElementType());
4720 if (!ETy || cast<IntegerType>(ETy)->getBitWidth() != 8)
4721 error("String arrays require type i8, not '" + ETy->getDescription() +
4722 "'");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004723 char *EndStr = UnEscapeLexed((yyvsp[(3) - (3)].StrVal), true);
4724 if (NumElements != -1 && NumElements != (EndStr-(yyvsp[(3) - (3)].StrVal)))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004725 error("Can't build string constant of size " +
Chris Lattnera62e8e42007-12-29 20:47:37 +00004726 itostr((int)(EndStr-(yyvsp[(3) - (3)].StrVal))) + " when array has size " +
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004727 itostr(NumElements) + "");
4728 std::vector<Constant*> Vals;
Chris Lattnera62e8e42007-12-29 20:47:37 +00004729 for (char *C = (char *)(yyvsp[(3) - (3)].StrVal); C != (char *)EndStr; ++C)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004730 Vals.push_back(ConstantInt::get(ETy, *C));
Chris Lattnera62e8e42007-12-29 20:47:37 +00004731 free((yyvsp[(3) - (3)].StrVal));
4732 (yyval.ConstVal).C = ConstantArray::get(ATy, Vals);
4733 (yyval.ConstVal).S.copy((yyvsp[(1) - (3)].TypeVal).S);
4734 delete (yyvsp[(1) - (3)].TypeVal).PAT;
4735 ;}
4736 break;
4737
4738 case 148:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004739#line 2241 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004740 { // Nonempty unsized arr
4741 const VectorType *PTy = dyn_cast<VectorType>((yyvsp[(1) - (4)].TypeVal).PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004742 if (PTy == 0)
4743 error("Cannot make packed constant with type: '" +
Chris Lattnera62e8e42007-12-29 20:47:37 +00004744 (yyvsp[(1) - (4)].TypeVal).PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004745 const Type *ETy = PTy->getElementType();
4746 int NumElements = PTy->getNumElements();
4747 // Verify that we have the correct size...
Chris Lattnera62e8e42007-12-29 20:47:37 +00004748 if (NumElements != -1 && NumElements != (int)(yyvsp[(3) - (4)].ConstVector)->size())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004749 error("Type mismatch: constant sized packed initialized with " +
Chris Lattnera62e8e42007-12-29 20:47:37 +00004750 utostr((yyvsp[(3) - (4)].ConstVector)->size()) + " arguments, but has size of " +
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004751 itostr(NumElements) + "");
4752 // Verify all elements are correct type!
4753 std::vector<Constant*> Elems;
Chris Lattnera62e8e42007-12-29 20:47:37 +00004754 for (unsigned i = 0; i < (yyvsp[(3) - (4)].ConstVector)->size(); i++) {
4755 Constant *C = (*(yyvsp[(3) - (4)].ConstVector))[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004756 const Type* ValTy = C->getType();
4757 if (ETy != ValTy)
4758 error("Element #" + utostr(i) + " is not of type '" +
4759 ETy->getDescription() +"' as required!\nIt is of type '"+
4760 ValTy->getDescription() + "'");
4761 Elems.push_back(C);
4762 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00004763 (yyval.ConstVal).C = ConstantVector::get(PTy, Elems);
4764 (yyval.ConstVal).S.copy((yyvsp[(1) - (4)].TypeVal).S);
4765 delete (yyvsp[(1) - (4)].TypeVal).PAT;
4766 delete (yyvsp[(3) - (4)].ConstVector);
4767 ;}
4768 break;
4769
4770 case 149:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004771#line 2269 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004772 {
4773 const StructType *STy = dyn_cast<StructType>((yyvsp[(1) - (4)].TypeVal).PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004774 if (STy == 0)
4775 error("Cannot make struct constant with type: '" +
Chris Lattnera62e8e42007-12-29 20:47:37 +00004776 (yyvsp[(1) - (4)].TypeVal).PAT->get()->getDescription() + "'");
4777 if ((yyvsp[(3) - (4)].ConstVector)->size() != STy->getNumContainedTypes())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004778 error("Illegal number of initializers for structure type");
4779
4780 // Check to ensure that constants are compatible with the type initializer!
4781 std::vector<Constant*> Fields;
Chris Lattnera62e8e42007-12-29 20:47:37 +00004782 for (unsigned i = 0, e = (yyvsp[(3) - (4)].ConstVector)->size(); i != e; ++i) {
4783 Constant *C = (*(yyvsp[(3) - (4)].ConstVector))[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004784 if (C->getType() != STy->getElementType(i))
4785 error("Expected type '" + STy->getElementType(i)->getDescription() +
4786 "' for element #" + utostr(i) + " of structure initializer");
4787 Fields.push_back(C);
4788 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00004789 (yyval.ConstVal).C = ConstantStruct::get(STy, Fields);
4790 (yyval.ConstVal).S.copy((yyvsp[(1) - (4)].TypeVal).S);
4791 delete (yyvsp[(1) - (4)].TypeVal).PAT;
4792 delete (yyvsp[(3) - (4)].ConstVector);
4793 ;}
4794 break;
4795
4796 case 150:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004797#line 2291 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004798 {
4799 const StructType *STy = dyn_cast<StructType>((yyvsp[(1) - (3)].TypeVal).PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004800 if (STy == 0)
4801 error("Cannot make struct constant with type: '" +
Chris Lattnera62e8e42007-12-29 20:47:37 +00004802 (yyvsp[(1) - (3)].TypeVal).PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004803 if (STy->getNumContainedTypes() != 0)
4804 error("Illegal number of initializers for structure type");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004805 (yyval.ConstVal).C = ConstantStruct::get(STy, std::vector<Constant*>());
4806 (yyval.ConstVal).S.copy((yyvsp[(1) - (3)].TypeVal).S);
4807 delete (yyvsp[(1) - (3)].TypeVal).PAT;
4808 ;}
4809 break;
4810
4811 case 151:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004812#line 2302 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004813 {
4814 const StructType *STy = dyn_cast<StructType>((yyvsp[(1) - (6)].TypeVal).PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004815 if (STy == 0)
4816 error("Cannot make packed struct constant with type: '" +
Chris Lattnera62e8e42007-12-29 20:47:37 +00004817 (yyvsp[(1) - (6)].TypeVal).PAT->get()->getDescription() + "'");
4818 if ((yyvsp[(4) - (6)].ConstVector)->size() != STy->getNumContainedTypes())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004819 error("Illegal number of initializers for packed structure type");
4820
4821 // Check to ensure that constants are compatible with the type initializer!
4822 std::vector<Constant*> Fields;
Chris Lattnera62e8e42007-12-29 20:47:37 +00004823 for (unsigned i = 0, e = (yyvsp[(4) - (6)].ConstVector)->size(); i != e; ++i) {
4824 Constant *C = (*(yyvsp[(4) - (6)].ConstVector))[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004825 if (C->getType() != STy->getElementType(i))
4826 error("Expected type '" + STy->getElementType(i)->getDescription() +
4827 "' for element #" + utostr(i) + " of packed struct initializer");
4828 Fields.push_back(C);
4829 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00004830 (yyval.ConstVal).C = ConstantStruct::get(STy, Fields);
4831 (yyval.ConstVal).S.copy((yyvsp[(1) - (6)].TypeVal).S);
4832 delete (yyvsp[(1) - (6)].TypeVal).PAT;
4833 delete (yyvsp[(4) - (6)].ConstVector);
4834 ;}
4835 break;
4836
4837 case 152:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004838#line 2324 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004839 {
4840 const StructType *STy = dyn_cast<StructType>((yyvsp[(1) - (5)].TypeVal).PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004841 if (STy == 0)
4842 error("Cannot make packed struct constant with type: '" +
Chris Lattnera62e8e42007-12-29 20:47:37 +00004843 (yyvsp[(1) - (5)].TypeVal).PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004844 if (STy->getNumContainedTypes() != 0)
4845 error("Illegal number of initializers for packed structure type");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004846 (yyval.ConstVal).C = ConstantStruct::get(STy, std::vector<Constant*>());
4847 (yyval.ConstVal).S.copy((yyvsp[(1) - (5)].TypeVal).S);
4848 delete (yyvsp[(1) - (5)].TypeVal).PAT;
4849 ;}
4850 break;
4851
4852 case 153:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004853#line 2335 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004854 {
4855 const PointerType *PTy = dyn_cast<PointerType>((yyvsp[(1) - (2)].TypeVal).PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004856 if (PTy == 0)
4857 error("Cannot make null pointer constant with type: '" +
Chris Lattnera62e8e42007-12-29 20:47:37 +00004858 (yyvsp[(1) - (2)].TypeVal).PAT->get()->getDescription() + "'");
4859 (yyval.ConstVal).C = ConstantPointerNull::get(PTy);
4860 (yyval.ConstVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
4861 delete (yyvsp[(1) - (2)].TypeVal).PAT;
4862 ;}
4863 break;
4864
4865 case 154:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004866#line 2344 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004867 {
4868 (yyval.ConstVal).C = UndefValue::get((yyvsp[(1) - (2)].TypeVal).PAT->get());
4869 (yyval.ConstVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
4870 delete (yyvsp[(1) - (2)].TypeVal).PAT;
4871 ;}
4872 break;
4873
4874 case 155:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004875#line 2349 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004876 {
4877 const PointerType *Ty = dyn_cast<PointerType>((yyvsp[(1) - (2)].TypeVal).PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004878 if (Ty == 0)
4879 error("Global const reference must be a pointer type, not" +
Chris Lattnera62e8e42007-12-29 20:47:37 +00004880 (yyvsp[(1) - (2)].TypeVal).PAT->get()->getDescription());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004881
4882 // ConstExprs can exist in the body of a function, thus creating
4883 // GlobalValues whenever they refer to a variable. Because we are in
4884 // the context of a function, getExistingValue will search the functions
4885 // symbol table instead of the module symbol table for the global symbol,
4886 // which throws things all off. To get around this, we just tell
4887 // getExistingValue that we are at global scope here.
4888 //
4889 Function *SavedCurFn = CurFun.CurrentFunction;
4890 CurFun.CurrentFunction = 0;
Chris Lattnera62e8e42007-12-29 20:47:37 +00004891 (yyvsp[(2) - (2)].ValIDVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
4892 Value *V = getExistingValue(Ty, (yyvsp[(2) - (2)].ValIDVal));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004893 CurFun.CurrentFunction = SavedCurFn;
4894
4895 // If this is an initializer for a constant pointer, which is referencing a
4896 // (currently) undefined variable, create a stub now that shall be replaced
4897 // in the future with the right type of variable.
4898 //
4899 if (V == 0) {
4900 assert(isa<PointerType>(Ty) && "Globals may only be used as pointers");
4901 const PointerType *PT = cast<PointerType>(Ty);
4902
4903 // First check to see if the forward references value is already created!
4904 PerModuleInfo::GlobalRefsType::iterator I =
Chris Lattnera62e8e42007-12-29 20:47:37 +00004905 CurModule.GlobalRefs.find(std::make_pair(PT, (yyvsp[(2) - (2)].ValIDVal)));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004906
4907 if (I != CurModule.GlobalRefs.end()) {
4908 V = I->second; // Placeholder already exists, use it...
Chris Lattnera62e8e42007-12-29 20:47:37 +00004909 (yyvsp[(2) - (2)].ValIDVal).destroy();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004910 } else {
4911 std::string Name;
Chris Lattnera62e8e42007-12-29 20:47:37 +00004912 if ((yyvsp[(2) - (2)].ValIDVal).Type == ValID::NameVal) Name = (yyvsp[(2) - (2)].ValIDVal).Name;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004913
4914 // Create the forward referenced global.
4915 GlobalValue *GV;
4916 if (const FunctionType *FTy =
4917 dyn_cast<FunctionType>(PT->getElementType())) {
4918 GV = new Function(FTy, GlobalValue::ExternalLinkage, Name,
4919 CurModule.CurrentModule);
4920 } else {
4921 GV = new GlobalVariable(PT->getElementType(), false,
4922 GlobalValue::ExternalLinkage, 0,
4923 Name, CurModule.CurrentModule);
4924 }
4925
4926 // Keep track of the fact that we have a forward ref to recycle it
Chris Lattnera62e8e42007-12-29 20:47:37 +00004927 CurModule.GlobalRefs.insert(std::make_pair(std::make_pair(PT, (yyvsp[(2) - (2)].ValIDVal)), GV));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004928 V = GV;
4929 }
4930 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00004931 (yyval.ConstVal).C = cast<GlobalValue>(V);
4932 (yyval.ConstVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
4933 delete (yyvsp[(1) - (2)].TypeVal).PAT; // Free the type handle
4934 ;}
4935 break;
4936
4937 case 156:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004938#line 2408 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004939 {
4940 if ((yyvsp[(1) - (2)].TypeVal).PAT->get() != (yyvsp[(2) - (2)].ConstVal).C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004941 error("Mismatched types for constant expression");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004942 (yyval.ConstVal) = (yyvsp[(2) - (2)].ConstVal);
4943 (yyval.ConstVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
4944 delete (yyvsp[(1) - (2)].TypeVal).PAT;
4945 ;}
4946 break;
4947
4948 case 157:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004949#line 2415 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004950 {
4951 const Type *Ty = (yyvsp[(1) - (2)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004952 if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
4953 error("Cannot create a null initialized value of this type");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004954 (yyval.ConstVal).C = Constant::getNullValue(Ty);
4955 (yyval.ConstVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
4956 delete (yyvsp[(1) - (2)].TypeVal).PAT;
4957 ;}
4958 break;
4959
4960 case 158:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004961#line 2423 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004962 { // integral constants
4963 const Type *Ty = (yyvsp[(1) - (2)].PrimType).T;
4964 if (!ConstantInt::isValueValidForType(Ty, (yyvsp[(2) - (2)].SInt64Val)))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004965 error("Constant value doesn't fit in type");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004966 (yyval.ConstVal).C = ConstantInt::get(Ty, (yyvsp[(2) - (2)].SInt64Val));
4967 (yyval.ConstVal).S.makeSigned();
4968 ;}
4969 break;
4970
4971 case 159:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004972#line 2430 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004973 { // integral constants
4974 const Type *Ty = (yyvsp[(1) - (2)].PrimType).T;
4975 if (!ConstantInt::isValueValidForType(Ty, (yyvsp[(2) - (2)].UInt64Val)))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004976 error("Constant value doesn't fit in type");
Chris Lattnera62e8e42007-12-29 20:47:37 +00004977 (yyval.ConstVal).C = ConstantInt::get(Ty, (yyvsp[(2) - (2)].UInt64Val));
4978 (yyval.ConstVal).S.makeUnsigned();
4979 ;}
4980 break;
4981
4982 case 160:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004983#line 2437 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004984 { // Boolean constants
4985 (yyval.ConstVal).C = ConstantInt::get(Type::Int1Ty, true);
4986 (yyval.ConstVal).S.makeUnsigned();
4987 ;}
4988 break;
4989
4990 case 161:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004991#line 2441 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00004992 { // Boolean constants
4993 (yyval.ConstVal).C = ConstantInt::get(Type::Int1Ty, false);
4994 (yyval.ConstVal).S.makeUnsigned();
4995 ;}
4996 break;
4997
4998 case 162:
Chris Lattner1c8733e2008-03-12 17:45:29 +00004999#line 2445 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005000 { // Float & Double constants
5001 if (!ConstantFP::isValueValidForType((yyvsp[(1) - (2)].PrimType).T, *(yyvsp[(2) - (2)].FPVal)))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005002 error("Floating point constant invalid for type");
Dale Johannesen3afee192007-09-07 21:07:57 +00005003 // Lexer has no type info, so builds all FP constants as double.
5004 // Fix this here.
Chris Lattnera62e8e42007-12-29 20:47:37 +00005005 if ((yyvsp[(1) - (2)].PrimType).T==Type::FloatTy)
5006 (yyvsp[(2) - (2)].FPVal)->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
5007 (yyval.ConstVal).C = ConstantFP::get((yyvsp[(1) - (2)].PrimType).T, *(yyvsp[(2) - (2)].FPVal));
5008 delete (yyvsp[(2) - (2)].FPVal);
5009 (yyval.ConstVal).S.makeSignless();
5010 ;}
5011 break;
5012
5013 case 163:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005014#line 2459 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005015 {
5016 const Type* SrcTy = (yyvsp[(3) - (6)].ConstVal).C->getType();
5017 const Type* DstTy = (yyvsp[(5) - (6)].TypeVal).PAT->get();
5018 Signedness SrcSign((yyvsp[(3) - (6)].ConstVal).S);
5019 Signedness DstSign((yyvsp[(5) - (6)].TypeVal).S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005020 if (!SrcTy->isFirstClassType())
5021 error("cast constant expression from a non-primitive type: '" +
5022 SrcTy->getDescription() + "'");
5023 if (!DstTy->isFirstClassType())
5024 error("cast constant expression to a non-primitive type: '" +
5025 DstTy->getDescription() + "'");
Chris Lattnera62e8e42007-12-29 20:47:37 +00005026 (yyval.ConstVal).C = cast<Constant>(getCast((yyvsp[(1) - (6)].CastOpVal), (yyvsp[(3) - (6)].ConstVal).C, SrcSign, DstTy, DstSign));
5027 (yyval.ConstVal).S.copy(DstSign);
5028 delete (yyvsp[(5) - (6)].TypeVal).PAT;
5029 ;}
5030 break;
5031
5032 case 164:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005033#line 2474 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005034 {
5035 const Type *Ty = (yyvsp[(3) - (5)].ConstVal).C->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005036 if (!isa<PointerType>(Ty))
5037 error("GetElementPtr requires a pointer operand");
5038
5039 std::vector<Constant*> CIndices;
Chris Lattnera62e8e42007-12-29 20:47:37 +00005040 upgradeGEPCEIndices((yyvsp[(3) - (5)].ConstVal).C->getType(), (yyvsp[(4) - (5)].ValueList), CIndices);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005041
Chris Lattnera62e8e42007-12-29 20:47:37 +00005042 delete (yyvsp[(4) - (5)].ValueList);
5043 (yyval.ConstVal).C = ConstantExpr::getGetElementPtr((yyvsp[(3) - (5)].ConstVal).C, &CIndices[0], CIndices.size());
5044 (yyval.ConstVal).S.copy(getElementSign((yyvsp[(3) - (5)].ConstVal), CIndices));
5045 ;}
5046 break;
5047
5048 case 165:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005049#line 2486 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005050 {
5051 if (!(yyvsp[(3) - (8)].ConstVal).C->getType()->isInteger() ||
5052 cast<IntegerType>((yyvsp[(3) - (8)].ConstVal).C->getType())->getBitWidth() != 1)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005053 error("Select condition must be bool type");
Chris Lattnera62e8e42007-12-29 20:47:37 +00005054 if ((yyvsp[(5) - (8)].ConstVal).C->getType() != (yyvsp[(7) - (8)].ConstVal).C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005055 error("Select operand types must match");
Chris Lattnera62e8e42007-12-29 20:47:37 +00005056 (yyval.ConstVal).C = ConstantExpr::getSelect((yyvsp[(3) - (8)].ConstVal).C, (yyvsp[(5) - (8)].ConstVal).C, (yyvsp[(7) - (8)].ConstVal).C);
5057 (yyval.ConstVal).S.copy((yyvsp[(5) - (8)].ConstVal).S);
5058 ;}
5059 break;
5060
5061 case 166:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005062#line 2495 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005063 {
5064 const Type *Ty = (yyvsp[(3) - (6)].ConstVal).C->getType();
5065 if (Ty != (yyvsp[(5) - (6)].ConstVal).C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005066 error("Binary operator types must match");
5067 // First, make sure we're dealing with the right opcode by upgrading from
5068 // obsolete versions.
Chris Lattnera62e8e42007-12-29 20:47:37 +00005069 Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[(1) - (6)].BinaryOpVal), Ty, (yyvsp[(3) - (6)].ConstVal).S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005070
5071 // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs.
5072 // To retain backward compatibility with these early compilers, we emit a
5073 // cast to the appropriate integer type automatically if we are in the
5074 // broken case. See PR424 for more information.
5075 if (!isa<PointerType>(Ty)) {
Chris Lattnera62e8e42007-12-29 20:47:37 +00005076 (yyval.ConstVal).C = ConstantExpr::get(Opcode, (yyvsp[(3) - (6)].ConstVal).C, (yyvsp[(5) - (6)].ConstVal).C);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005077 } else {
5078 const Type *IntPtrTy = 0;
5079 switch (CurModule.CurrentModule->getPointerSize()) {
5080 case Module::Pointer32: IntPtrTy = Type::Int32Ty; break;
5081 case Module::Pointer64: IntPtrTy = Type::Int64Ty; break;
5082 default: error("invalid pointer binary constant expr");
5083 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00005084 (yyval.ConstVal).C = ConstantExpr::get(Opcode,
5085 ConstantExpr::getCast(Instruction::PtrToInt, (yyvsp[(3) - (6)].ConstVal).C, IntPtrTy),
5086 ConstantExpr::getCast(Instruction::PtrToInt, (yyvsp[(5) - (6)].ConstVal).C, IntPtrTy));
5087 (yyval.ConstVal).C = ConstantExpr::getCast(Instruction::IntToPtr, (yyval.ConstVal).C, Ty);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005088 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00005089 (yyval.ConstVal).S.copy((yyvsp[(3) - (6)].ConstVal).S);
5090 ;}
5091 break;
5092
5093 case 167:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005094#line 2523 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005095 {
5096 const Type* Ty = (yyvsp[(3) - (6)].ConstVal).C->getType();
5097 if (Ty != (yyvsp[(5) - (6)].ConstVal).C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005098 error("Logical operator types must match");
5099 if (!Ty->isInteger()) {
5100 if (!isa<VectorType>(Ty) ||
5101 !cast<VectorType>(Ty)->getElementType()->isInteger())
5102 error("Logical operator requires integer operands");
5103 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00005104 Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[(1) - (6)].BinaryOpVal), Ty, (yyvsp[(3) - (6)].ConstVal).S);
5105 (yyval.ConstVal).C = ConstantExpr::get(Opcode, (yyvsp[(3) - (6)].ConstVal).C, (yyvsp[(5) - (6)].ConstVal).C);
5106 (yyval.ConstVal).S.copy((yyvsp[(3) - (6)].ConstVal).S);
5107 ;}
5108 break;
5109
5110 case 168:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005111#line 2536 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005112 {
5113 const Type* Ty = (yyvsp[(3) - (6)].ConstVal).C->getType();
5114 if (Ty != (yyvsp[(5) - (6)].ConstVal).C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005115 error("setcc operand types must match");
5116 unsigned short pred;
Chris Lattnera62e8e42007-12-29 20:47:37 +00005117 Instruction::OtherOps Opcode = getCompareOp((yyvsp[(1) - (6)].BinaryOpVal), pred, Ty, (yyvsp[(3) - (6)].ConstVal).S);
5118 (yyval.ConstVal).C = ConstantExpr::getCompare(Opcode, (yyvsp[(3) - (6)].ConstVal).C, (yyvsp[(5) - (6)].ConstVal).C);
5119 (yyval.ConstVal).S.makeUnsigned();
5120 ;}
5121 break;
5122
5123 case 169:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005124#line 2545 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005125 {
5126 if ((yyvsp[(4) - (7)].ConstVal).C->getType() != (yyvsp[(6) - (7)].ConstVal).C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005127 error("icmp operand types must match");
Chris Lattnera62e8e42007-12-29 20:47:37 +00005128 (yyval.ConstVal).C = ConstantExpr::getCompare((yyvsp[(2) - (7)].IPred), (yyvsp[(4) - (7)].ConstVal).C, (yyvsp[(6) - (7)].ConstVal).C);
5129 (yyval.ConstVal).S.makeUnsigned();
5130 ;}
5131 break;
5132
5133 case 170:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005134#line 2551 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005135 {
5136 if ((yyvsp[(4) - (7)].ConstVal).C->getType() != (yyvsp[(6) - (7)].ConstVal).C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005137 error("fcmp operand types must match");
Chris Lattnera62e8e42007-12-29 20:47:37 +00005138 (yyval.ConstVal).C = ConstantExpr::getCompare((yyvsp[(2) - (7)].FPred), (yyvsp[(4) - (7)].ConstVal).C, (yyvsp[(6) - (7)].ConstVal).C);
5139 (yyval.ConstVal).S.makeUnsigned();
5140 ;}
5141 break;
5142
5143 case 171:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005144#line 2557 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005145 {
5146 if (!(yyvsp[(5) - (6)].ConstVal).C->getType()->isInteger() ||
5147 cast<IntegerType>((yyvsp[(5) - (6)].ConstVal).C->getType())->getBitWidth() != 8)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005148 error("Shift count for shift constant must be unsigned byte");
Chris Lattnera62e8e42007-12-29 20:47:37 +00005149 const Type* Ty = (yyvsp[(3) - (6)].ConstVal).C->getType();
5150 if (!(yyvsp[(3) - (6)].ConstVal).C->getType()->isInteger())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005151 error("Shift constant expression requires integer operand");
Chris Lattnera62e8e42007-12-29 20:47:37 +00005152 Constant *ShiftAmt = ConstantExpr::getZExt((yyvsp[(5) - (6)].ConstVal).C, Ty);
5153 (yyval.ConstVal).C = ConstantExpr::get(getBinaryOp((yyvsp[(1) - (6)].BinaryOpVal), Ty, (yyvsp[(3) - (6)].ConstVal).S), (yyvsp[(3) - (6)].ConstVal).C, ShiftAmt);
5154 (yyval.ConstVal).S.copy((yyvsp[(3) - (6)].ConstVal).S);
5155 ;}
5156 break;
5157
5158 case 172:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005159#line 2568 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005160 {
5161 if (!ExtractElementInst::isValidOperands((yyvsp[(3) - (6)].ConstVal).C, (yyvsp[(5) - (6)].ConstVal).C))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005162 error("Invalid extractelement operands");
Chris Lattnera62e8e42007-12-29 20:47:37 +00005163 (yyval.ConstVal).C = ConstantExpr::getExtractElement((yyvsp[(3) - (6)].ConstVal).C, (yyvsp[(5) - (6)].ConstVal).C);
5164 (yyval.ConstVal).S.copy((yyvsp[(3) - (6)].ConstVal).S.get(0));
5165 ;}
5166 break;
5167
5168 case 173:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005169#line 2574 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005170 {
5171 if (!InsertElementInst::isValidOperands((yyvsp[(3) - (8)].ConstVal).C, (yyvsp[(5) - (8)].ConstVal).C, (yyvsp[(7) - (8)].ConstVal).C))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005172 error("Invalid insertelement operands");
Chris Lattnera62e8e42007-12-29 20:47:37 +00005173 (yyval.ConstVal).C = ConstantExpr::getInsertElement((yyvsp[(3) - (8)].ConstVal).C, (yyvsp[(5) - (8)].ConstVal).C, (yyvsp[(7) - (8)].ConstVal).C);
5174 (yyval.ConstVal).S.copy((yyvsp[(3) - (8)].ConstVal).S);
5175 ;}
5176 break;
5177
5178 case 174:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005179#line 2580 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005180 {
5181 if (!ShuffleVectorInst::isValidOperands((yyvsp[(3) - (8)].ConstVal).C, (yyvsp[(5) - (8)].ConstVal).C, (yyvsp[(7) - (8)].ConstVal).C))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005182 error("Invalid shufflevector operands");
Chris Lattnera62e8e42007-12-29 20:47:37 +00005183 (yyval.ConstVal).C = ConstantExpr::getShuffleVector((yyvsp[(3) - (8)].ConstVal).C, (yyvsp[(5) - (8)].ConstVal).C, (yyvsp[(7) - (8)].ConstVal).C);
5184 (yyval.ConstVal).S.copy((yyvsp[(3) - (8)].ConstVal).S);
5185 ;}
5186 break;
5187
5188 case 175:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005189#line 2591 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005190 { ((yyval.ConstVector) = (yyvsp[(1) - (3)].ConstVector))->push_back((yyvsp[(3) - (3)].ConstVal)); ;}
5191 break;
5192
5193 case 176:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005194#line 2592 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005195 {
5196 (yyval.ConstVector) = new std::vector<ConstInfo>();
5197 (yyval.ConstVector)->push_back((yyvsp[(1) - (1)].ConstVal));
5198 ;}
5199 break;
5200
5201 case 177:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005202#line 2601 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005203 { (yyval.BoolVal) = false; ;}
5204 break;
5205
5206 case 178:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005207#line 2602 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005208 { (yyval.BoolVal) = true; ;}
5209 break;
5210
5211 case 179:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005212#line 2614 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005213 {
5214 (yyval.ModuleVal) = ParserResult = (yyvsp[(1) - (1)].ModuleVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005215 CurModule.ModuleDone();
Chris Lattnera62e8e42007-12-29 20:47:37 +00005216 ;}
5217 break;
5218
5219 case 180:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005220#line 2623 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005221 { (yyval.ModuleVal) = (yyvsp[(1) - (2)].ModuleVal); CurFun.FunctionDone(); ;}
5222 break;
5223
5224 case 181:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005225#line 2624 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005226 { (yyval.ModuleVal) = (yyvsp[(1) - (2)].ModuleVal); ;}
5227 break;
5228
5229 case 182:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005230#line 2625 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005231 { (yyval.ModuleVal) = (yyvsp[(1) - (4)].ModuleVal); ;}
5232 break;
5233
5234 case 183:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005235#line 2626 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005236 { (yyval.ModuleVal) = (yyvsp[(1) - (2)].ModuleVal); ;}
5237 break;
5238
5239 case 184:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005240#line 2627 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005241 {
5242 (yyval.ModuleVal) = CurModule.CurrentModule;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005243 // Emit an error if there are any unresolved types left.
5244 if (!CurModule.LateResolveTypes.empty()) {
5245 const ValID &DID = CurModule.LateResolveTypes.begin()->first;
5246 if (DID.Type == ValID::NameVal) {
5247 error("Reference to an undefined type: '"+DID.getName() + "'");
5248 } else {
5249 error("Reference to an undefined type: #" + itostr(DID.Num));
5250 }
5251 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00005252 ;}
5253 break;
5254
5255 case 185:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005256#line 2643 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005257 {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005258 // Eagerly resolve types. This is not an optimization, this is a
5259 // requirement that is due to the fact that we could have this:
5260 //
5261 // %list = type { %list * }
5262 // %list = type { %list * } ; repeated type decl
5263 //
5264 // If types are not resolved eagerly, then the two types will not be
5265 // determined to be the same type!
5266 //
Chris Lattnera62e8e42007-12-29 20:47:37 +00005267 ResolveTypeTo((yyvsp[(2) - (4)].StrVal), (yyvsp[(4) - (4)].TypeVal).PAT->get(), (yyvsp[(4) - (4)].TypeVal).S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005268
Chris Lattnera62e8e42007-12-29 20:47:37 +00005269 if (!setTypeName((yyvsp[(4) - (4)].TypeVal), (yyvsp[(2) - (4)].StrVal)) && !(yyvsp[(2) - (4)].StrVal)) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005270 // If this is a numbered type that is not a redefinition, add it to the
5271 // slot table.
Chris Lattnera62e8e42007-12-29 20:47:37 +00005272 CurModule.Types.push_back((yyvsp[(4) - (4)].TypeVal).PAT->get());
5273 CurModule.TypeSigns.push_back((yyvsp[(4) - (4)].TypeVal).S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005274 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00005275 delete (yyvsp[(4) - (4)].TypeVal).PAT;
5276 ;}
5277 break;
5278
5279 case 186:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005280#line 2663 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005281 { // Function prototypes can be in const pool
5282 ;}
5283 break;
5284
5285 case 187:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005286#line 2665 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005287 { // Asm blocks can be in the const pool
5288 ;}
5289 break;
5290
5291 case 188:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005292#line 2667 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005293 {
5294 if ((yyvsp[(5) - (5)].ConstVal).C == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005295 error("Global value initializer is not a constant");
Chris Lattnera62e8e42007-12-29 20:47:37 +00005296 CurGV = ParseGlobalVariable((yyvsp[(2) - (5)].StrVal), (yyvsp[(3) - (5)].Linkage), (yyvsp[(4) - (5)].BoolVal), (yyvsp[(5) - (5)].ConstVal).C->getType(), (yyvsp[(5) - (5)].ConstVal).C, (yyvsp[(5) - (5)].ConstVal).S);
5297 ;}
5298 break;
5299
5300 case 189:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005301#line 2671 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005302 {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005303 CurGV = 0;
Chris Lattnera62e8e42007-12-29 20:47:37 +00005304 ;}
5305 break;
5306
5307 case 190:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005308#line 2674 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005309 {
5310 const Type *Ty = (yyvsp[(5) - (5)].TypeVal).PAT->get();
5311 CurGV = ParseGlobalVariable((yyvsp[(2) - (5)].StrVal), GlobalValue::ExternalLinkage, (yyvsp[(4) - (5)].BoolVal), Ty, 0,
5312 (yyvsp[(5) - (5)].TypeVal).S);
5313 delete (yyvsp[(5) - (5)].TypeVal).PAT;
5314 ;}
5315 break;
5316
5317 case 191:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005318#line 2679 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005319 {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005320 CurGV = 0;
Chris Lattnera62e8e42007-12-29 20:47:37 +00005321 ;}
5322 break;
5323
5324 case 192:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005325#line 2682 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005326 {
5327 const Type *Ty = (yyvsp[(5) - (5)].TypeVal).PAT->get();
5328 CurGV = ParseGlobalVariable((yyvsp[(2) - (5)].StrVal), GlobalValue::DLLImportLinkage, (yyvsp[(4) - (5)].BoolVal), Ty, 0,
5329 (yyvsp[(5) - (5)].TypeVal).S);
5330 delete (yyvsp[(5) - (5)].TypeVal).PAT;
5331 ;}
5332 break;
5333
5334 case 193:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005335#line 2687 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005336 {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005337 CurGV = 0;
Chris Lattnera62e8e42007-12-29 20:47:37 +00005338 ;}
5339 break;
5340
5341 case 194:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005342#line 2690 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005343 {
5344 const Type *Ty = (yyvsp[(5) - (5)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005345 CurGV =
Chris Lattnera62e8e42007-12-29 20:47:37 +00005346 ParseGlobalVariable((yyvsp[(2) - (5)].StrVal), GlobalValue::ExternalWeakLinkage, (yyvsp[(4) - (5)].BoolVal), Ty, 0,
5347 (yyvsp[(5) - (5)].TypeVal).S);
5348 delete (yyvsp[(5) - (5)].TypeVal).PAT;
5349 ;}
5350 break;
5351
5352 case 195:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005353#line 2696 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005354 {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005355 CurGV = 0;
Chris Lattnera62e8e42007-12-29 20:47:37 +00005356 ;}
5357 break;
5358
5359 case 196:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005360#line 2699 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005361 {
5362 ;}
5363 break;
5364
5365 case 197:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005366#line 2701 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005367 {
5368 ;}
5369 break;
5370
5371 case 198:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005372#line 2703 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005373 {
5374 ;}
5375 break;
5376
5377 case 199:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005378#line 2708 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005379 {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005380 const std::string &AsmSoFar = CurModule.CurrentModule->getModuleInlineAsm();
Chris Lattnera62e8e42007-12-29 20:47:37 +00005381 char *EndStr = UnEscapeLexed((yyvsp[(1) - (1)].StrVal), true);
5382 std::string NewAsm((yyvsp[(1) - (1)].StrVal), EndStr);
5383 free((yyvsp[(1) - (1)].StrVal));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005384
5385 if (AsmSoFar.empty())
5386 CurModule.CurrentModule->setModuleInlineAsm(NewAsm);
5387 else
5388 CurModule.CurrentModule->setModuleInlineAsm(AsmSoFar+"\n"+NewAsm);
Chris Lattnera62e8e42007-12-29 20:47:37 +00005389 ;}
5390 break;
5391
5392 case 200:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005393#line 2722 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005394 { (yyval.Endianness) = Module::BigEndian; ;}
5395 break;
5396
5397 case 201:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005398#line 2723 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005399 { (yyval.Endianness) = Module::LittleEndian; ;}
5400 break;
5401
5402 case 202:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005403#line 2727 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005404 {
5405 CurModule.setEndianness((yyvsp[(3) - (3)].Endianness));
5406 ;}
5407 break;
5408
5409 case 203:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005410#line 2730 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005411 {
5412 if ((yyvsp[(3) - (3)].UInt64Val) == 32)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005413 CurModule.setPointerSize(Module::Pointer32);
Chris Lattnera62e8e42007-12-29 20:47:37 +00005414 else if ((yyvsp[(3) - (3)].UInt64Val) == 64)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005415 CurModule.setPointerSize(Module::Pointer64);
5416 else
Chris Lattnera62e8e42007-12-29 20:47:37 +00005417 error("Invalid pointer size: '" + utostr((yyvsp[(3) - (3)].UInt64Val)) + "'");
5418 ;}
5419 break;
Duncan Sandsf5588dc2007-11-27 13:23:08 +00005420
Chris Lattnera62e8e42007-12-29 20:47:37 +00005421 case 204:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005422#line 2738 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005423 {
5424 CurModule.CurrentModule->setTargetTriple((yyvsp[(3) - (3)].StrVal));
5425 free((yyvsp[(3) - (3)].StrVal));
5426 ;}
5427 break;
5428
5429 case 205:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005430#line 2742 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005431 {
5432 CurModule.CurrentModule->setDataLayout((yyvsp[(3) - (3)].StrVal));
5433 free((yyvsp[(3) - (3)].StrVal));
5434 ;}
5435 break;
5436
5437 case 207:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005438#line 2753 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005439 {
5440 CurModule.CurrentModule->addLibrary((yyvsp[(3) - (3)].StrVal));
5441 free((yyvsp[(3) - (3)].StrVal));
5442 ;}
5443 break;
5444
5445 case 208:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005446#line 2757 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005447 {
5448 CurModule.CurrentModule->addLibrary((yyvsp[(1) - (1)].StrVal));
5449 free((yyvsp[(1) - (1)].StrVal));
5450 ;}
5451 break;
5452
5453 case 209:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005454#line 2761 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005455 { ;}
5456 break;
5457
5458 case 213:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005459#line 2774 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005460 { (yyval.StrVal) = 0; ;}
5461 break;
5462
5463 case 214:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005464#line 2778 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005465 {
5466 if ((yyvsp[(1) - (2)].TypeVal).PAT->get() == Type::VoidTy)
5467 error("void typed arguments are invalid");
5468 (yyval.ArgVal) = new std::pair<PATypeInfo, char*>((yyvsp[(1) - (2)].TypeVal), (yyvsp[(2) - (2)].StrVal));
5469 ;}
5470 break;
5471
5472 case 215:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005473#line 2786 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005474 {
5475 (yyval.ArgList) = (yyvsp[(1) - (3)].ArgList);
5476 (yyval.ArgList)->push_back(*(yyvsp[(3) - (3)].ArgVal));
5477 delete (yyvsp[(3) - (3)].ArgVal);
5478 ;}
5479 break;
5480
5481 case 216:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005482#line 2791 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005483 {
5484 (yyval.ArgList) = new std::vector<std::pair<PATypeInfo,char*> >();
5485 (yyval.ArgList)->push_back(*(yyvsp[(1) - (1)].ArgVal));
5486 delete (yyvsp[(1) - (1)].ArgVal);
5487 ;}
5488 break;
5489
5490 case 217:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005491#line 2799 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005492 { (yyval.ArgList) = (yyvsp[(1) - (1)].ArgList); ;}
5493 break;
5494
5495 case 218:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005496#line 2800 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005497 {
5498 (yyval.ArgList) = (yyvsp[(1) - (3)].ArgList);
5499 PATypeInfo VoidTI;
5500 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
5501 VoidTI.S.makeSignless();
5502 (yyval.ArgList)->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
5503 ;}
5504 break;
5505
5506 case 219:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005507#line 2807 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005508 {
5509 (yyval.ArgList) = new std::vector<std::pair<PATypeInfo,char*> >();
5510 PATypeInfo VoidTI;
5511 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
5512 VoidTI.S.makeSignless();
5513 (yyval.ArgList)->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
5514 ;}
5515 break;
5516
5517 case 220:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005518#line 2814 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005519 { (yyval.ArgList) = 0; ;}
5520 break;
5521
5522 case 221:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005523#line 2818 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005524 {
5525 UnEscapeLexed((yyvsp[(3) - (8)].StrVal));
5526 std::string FunctionName((yyvsp[(3) - (8)].StrVal));
5527 free((yyvsp[(3) - (8)].StrVal)); // Free strdup'd memory!
5528
5529 const Type* RetTy = (yyvsp[(2) - (8)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005530
5531 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
5532 error("LLVM functions cannot return aggregate types");
5533
5534 Signedness FTySign;
Chris Lattnera62e8e42007-12-29 20:47:37 +00005535 FTySign.makeComposite((yyvsp[(2) - (8)].TypeVal).S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005536 std::vector<const Type*> ParamTyList;
5537
5538 // In LLVM 2.0 the signatures of three varargs intrinsics changed to take
5539 // i8*. We check here for those names and override the parameter list
5540 // types to ensure the prototype is correct.
5541 if (FunctionName == "llvm.va_start" || FunctionName == "llvm.va_end") {
Christopher Lambfb623c62007-12-17 01:17:35 +00005542 ParamTyList.push_back(PointerType::getUnqual(Type::Int8Ty));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005543 } else if (FunctionName == "llvm.va_copy") {
Christopher Lambfb623c62007-12-17 01:17:35 +00005544 ParamTyList.push_back(PointerType::getUnqual(Type::Int8Ty));
5545 ParamTyList.push_back(PointerType::getUnqual(Type::Int8Ty));
Chris Lattnera62e8e42007-12-29 20:47:37 +00005546 } else if ((yyvsp[(5) - (8)].ArgList)) { // If there are arguments...
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005547 for (std::vector<std::pair<PATypeInfo,char*> >::iterator
Chris Lattnera62e8e42007-12-29 20:47:37 +00005548 I = (yyvsp[(5) - (8)].ArgList)->begin(), E = (yyvsp[(5) - (8)].ArgList)->end(); I != E; ++I) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005549 const Type *Ty = I->first.PAT->get();
5550 ParamTyList.push_back(Ty);
5551 FTySign.add(I->first.S);
5552 }
5553 }
5554
5555 bool isVarArg = ParamTyList.size() && ParamTyList.back() == Type::VoidTy;
5556 if (isVarArg)
5557 ParamTyList.pop_back();
5558
Duncan Sandsf5588dc2007-11-27 13:23:08 +00005559 const FunctionType *FT = FunctionType::get(RetTy, ParamTyList, isVarArg);
Christopher Lambfb623c62007-12-17 01:17:35 +00005560 const PointerType *PFT = PointerType::getUnqual(FT);
Chris Lattnera62e8e42007-12-29 20:47:37 +00005561 delete (yyvsp[(2) - (8)].TypeVal).PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005562
5563 ValID ID;
5564 if (!FunctionName.empty()) {
5565 ID = ValID::create((char*)FunctionName.c_str());
5566 } else {
5567 ID = ValID::create((int)CurModule.Values[PFT].size());
5568 }
5569 ID.S.makeComposite(FTySign);
5570
5571 Function *Fn = 0;
5572 Module* M = CurModule.CurrentModule;
5573
5574 // See if this function was forward referenced. If so, recycle the object.
5575 if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, ID)) {
5576 // Move the function to the end of the list, from whereever it was
5577 // previously inserted.
5578 Fn = cast<Function>(FWRef);
5579 M->getFunctionList().remove(Fn);
5580 M->getFunctionList().push_back(Fn);
5581 } else if (!FunctionName.empty()) {
5582 GlobalValue *Conflict = M->getFunction(FunctionName);
5583 if (!Conflict)
5584 Conflict = M->getNamedGlobal(FunctionName);
5585 if (Conflict && PFT == Conflict->getType()) {
5586 if (!CurFun.isDeclare && !Conflict->isDeclaration()) {
5587 // We have two function definitions that conflict, same type, same
5588 // name. We should really check to make sure that this is the result
5589 // of integer type planes collapsing and generate an error if it is
5590 // not, but we'll just rename on the assumption that it is. However,
5591 // let's do it intelligently and rename the internal linkage one
5592 // if there is one.
5593 std::string NewName(makeNameUnique(FunctionName));
5594 if (Conflict->hasInternalLinkage()) {
5595 Conflict->setName(NewName);
5596 RenameMapKey Key =
5597 makeRenameMapKey(FunctionName, Conflict->getType(), ID.S);
5598 CurModule.RenameMap[Key] = NewName;
5599 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5600 InsertValue(Fn, CurModule.Values);
5601 } else {
5602 Fn = new Function(FT, CurFun.Linkage, NewName, M);
5603 InsertValue(Fn, CurModule.Values);
5604 RenameMapKey Key =
5605 makeRenameMapKey(FunctionName, PFT, ID.S);
5606 CurModule.RenameMap[Key] = NewName;
5607 }
5608 } else {
5609 // If they are not both definitions, then just use the function we
5610 // found since the types are the same.
5611 Fn = cast<Function>(Conflict);
5612
5613 // Make sure to strip off any argument names so we can't get
5614 // conflicts.
5615 if (Fn->isDeclaration())
5616 for (Function::arg_iterator AI = Fn->arg_begin(),
5617 AE = Fn->arg_end(); AI != AE; ++AI)
5618 AI->setName("");
5619 }
5620 } else if (Conflict) {
5621 // We have two globals with the same name and different types.
5622 // Previously, this was permitted because the symbol table had
5623 // "type planes" and names only needed to be distinct within a
5624 // type plane. After PR411 was fixed, this is no loner the case.
5625 // To resolve this we must rename one of the two.
5626 if (Conflict->hasInternalLinkage()) {
5627 // We can safely rename the Conflict.
5628 RenameMapKey Key =
5629 makeRenameMapKey(Conflict->getName(), Conflict->getType(),
5630 CurModule.NamedValueSigns[Conflict->getName()]);
5631 Conflict->setName(makeNameUnique(Conflict->getName()));
5632 CurModule.RenameMap[Key] = Conflict->getName();
5633 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5634 InsertValue(Fn, CurModule.Values);
5635 } else {
5636 // We can't quietly rename either of these things, but we must
5637 // rename one of them. Only if the function's linkage is internal can
5638 // we forgo a warning message about the renamed function.
5639 std::string NewName = makeNameUnique(FunctionName);
5640 if (CurFun.Linkage != GlobalValue::InternalLinkage) {
5641 warning("Renaming function '" + FunctionName + "' as '" + NewName +
5642 "' may cause linkage errors");
5643 }
5644 // Elect to rename the thing we're now defining.
5645 Fn = new Function(FT, CurFun.Linkage, NewName, M);
5646 InsertValue(Fn, CurModule.Values);
5647 RenameMapKey Key = makeRenameMapKey(FunctionName, PFT, ID.S);
5648 CurModule.RenameMap[Key] = NewName;
5649 }
5650 } else {
5651 // There's no conflict, just define the function
5652 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5653 InsertValue(Fn, CurModule.Values);
5654 }
5655 } else {
5656 // There's no conflict, just define the function
5657 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5658 InsertValue(Fn, CurModule.Values);
5659 }
5660
5661
5662 CurFun.FunctionStart(Fn);
5663
5664 if (CurFun.isDeclare) {
5665 // If we have declaration, always overwrite linkage. This will allow us
5666 // to correctly handle cases, when pointer to function is passed as
5667 // argument to another function.
5668 Fn->setLinkage(CurFun.Linkage);
5669 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00005670 Fn->setCallingConv(upgradeCallingConv((yyvsp[(1) - (8)].UIntVal)));
5671 Fn->setAlignment((yyvsp[(8) - (8)].UIntVal));
5672 if ((yyvsp[(7) - (8)].StrVal)) {
5673 Fn->setSection((yyvsp[(7) - (8)].StrVal));
5674 free((yyvsp[(7) - (8)].StrVal));
Duncan Sandsf5588dc2007-11-27 13:23:08 +00005675 }
5676
5677 // Convert the CSRet calling convention into the corresponding parameter
5678 // attribute.
Chris Lattnera62e8e42007-12-29 20:47:37 +00005679 if ((yyvsp[(1) - (8)].UIntVal) == OldCallingConv::CSRet) {
Chris Lattner1c8733e2008-03-12 17:45:29 +00005680 ParamAttrsWithIndex PAWI =
5681 ParamAttrsWithIndex::get(1, ParamAttr::StructRet); // first arg
5682 Fn->setParamAttrs(PAListPtr::get(&PAWI, 1));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005683 }
5684
5685 // Add all of the arguments we parsed to the function...
Chris Lattnera62e8e42007-12-29 20:47:37 +00005686 if ((yyvsp[(5) - (8)].ArgList)) { // Is null if empty...
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005687 if (isVarArg) { // Nuke the last entry
Chris Lattnera62e8e42007-12-29 20:47:37 +00005688 assert((yyvsp[(5) - (8)].ArgList)->back().first.PAT->get() == Type::VoidTy &&
5689 (yyvsp[(5) - (8)].ArgList)->back().second == 0 && "Not a varargs marker");
5690 delete (yyvsp[(5) - (8)].ArgList)->back().first.PAT;
5691 (yyvsp[(5) - (8)].ArgList)->pop_back(); // Delete the last entry
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005692 }
5693 Function::arg_iterator ArgIt = Fn->arg_begin();
5694 Function::arg_iterator ArgEnd = Fn->arg_end();
Chris Lattnera62e8e42007-12-29 20:47:37 +00005695 std::vector<std::pair<PATypeInfo,char*> >::iterator I = (yyvsp[(5) - (8)].ArgList)->begin();
5696 std::vector<std::pair<PATypeInfo,char*> >::iterator E = (yyvsp[(5) - (8)].ArgList)->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005697 for ( ; I != E && ArgIt != ArgEnd; ++I, ++ArgIt) {
5698 delete I->first.PAT; // Delete the typeholder...
5699 ValueInfo VI; VI.V = ArgIt; VI.S.copy(I->first.S);
5700 setValueName(VI, I->second); // Insert arg into symtab...
5701 InsertValue(ArgIt);
5702 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00005703 delete (yyvsp[(5) - (8)].ArgList); // We're now done with the argument list
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005704 }
5705 lastCallingConv = OldCallingConv::C;
Chris Lattnera62e8e42007-12-29 20:47:37 +00005706 ;}
5707 break;
5708
5709 case 224:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005710#line 3008 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005711 { CurFun.Linkage = (yyvsp[(1) - (1)].Linkage); ;}
5712 break;
5713
5714 case 225:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005715#line 3008 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005716 {
5717 (yyval.FunctionVal) = CurFun.CurrentFunction;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005718
5719 // Make sure that we keep track of the linkage type even if there was a
5720 // previous "declare".
Chris Lattnera62e8e42007-12-29 20:47:37 +00005721 (yyval.FunctionVal)->setLinkage((yyvsp[(1) - (4)].Linkage));
5722 ;}
5723 break;
5724
5725 case 228:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005726#line 3022 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005727 {
5728 (yyval.FunctionVal) = (yyvsp[(1) - (2)].FunctionVal);
5729 ;}
5730 break;
5731
5732 case 229:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005733#line 3027 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005734 { (yyval.Linkage) = GlobalValue::ExternalLinkage; ;}
5735 break;
5736
5737 case 230:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005738#line 3028 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005739 { (yyval.Linkage) = GlobalValue::DLLImportLinkage; ;}
5740 break;
5741
5742 case 231:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005743#line 3029 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005744 { (yyval.Linkage) = GlobalValue::ExternalWeakLinkage; ;}
5745 break;
5746
5747 case 232:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005748#line 3033 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005749 { CurFun.isDeclare = true; ;}
5750 break;
5751
5752 case 233:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005753#line 3034 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005754 { CurFun.Linkage = (yyvsp[(3) - (3)].Linkage); ;}
5755 break;
5756
5757 case 234:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005758#line 3034 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005759 {
5760 (yyval.FunctionVal) = CurFun.CurrentFunction;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005761 CurFun.FunctionDone();
5762
Chris Lattnera62e8e42007-12-29 20:47:37 +00005763 ;}
5764 break;
5765
5766 case 235:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005767#line 3046 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005768 { (yyval.BoolVal) = false; ;}
5769 break;
5770
5771 case 236:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005772#line 3047 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005773 { (yyval.BoolVal) = true; ;}
5774 break;
5775
5776 case 237:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005777#line 3052 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005778 { (yyval.ValIDVal) = ValID::create((yyvsp[(1) - (1)].SInt64Val)); ;}
5779 break;
5780
5781 case 238:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005782#line 3053 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005783 { (yyval.ValIDVal) = ValID::create((yyvsp[(1) - (1)].UInt64Val)); ;}
5784 break;
5785
5786 case 239:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005787#line 3054 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005788 { (yyval.ValIDVal) = ValID::create((yyvsp[(1) - (1)].FPVal)); ;}
5789 break;
5790
5791 case 240:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005792#line 3055 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005793 {
5794 (yyval.ValIDVal) = ValID::create(ConstantInt::get(Type::Int1Ty, true));
5795 (yyval.ValIDVal).S.makeUnsigned();
5796 ;}
5797 break;
5798
5799 case 241:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005800#line 3059 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005801 {
5802 (yyval.ValIDVal) = ValID::create(ConstantInt::get(Type::Int1Ty, false));
5803 (yyval.ValIDVal).S.makeUnsigned();
5804 ;}
5805 break;
5806
5807 case 242:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005808#line 3063 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005809 { (yyval.ValIDVal) = ValID::createNull(); ;}
5810 break;
5811
5812 case 243:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005813#line 3064 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005814 { (yyval.ValIDVal) = ValID::createUndef(); ;}
5815 break;
5816
5817 case 244:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005818#line 3065 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005819 { (yyval.ValIDVal) = ValID::createZeroInit(); ;}
5820 break;
5821
5822 case 245:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005823#line 3066 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005824 { // Nonempty unsized packed vector
5825 const Type *ETy = (*(yyvsp[(2) - (3)].ConstVector))[0].C->getType();
5826 int NumElements = (yyvsp[(2) - (3)].ConstVector)->size();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005827 VectorType* pt = VectorType::get(ETy, NumElements);
Chris Lattnera62e8e42007-12-29 20:47:37 +00005828 (yyval.ValIDVal).S.makeComposite((*(yyvsp[(2) - (3)].ConstVector))[0].S);
5829 PATypeHolder* PTy = new PATypeHolder(HandleUpRefs(pt, (yyval.ValIDVal).S));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005830
5831 // Verify all elements are correct type!
5832 std::vector<Constant*> Elems;
Chris Lattnera62e8e42007-12-29 20:47:37 +00005833 for (unsigned i = 0; i < (yyvsp[(2) - (3)].ConstVector)->size(); i++) {
5834 Constant *C = (*(yyvsp[(2) - (3)].ConstVector))[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005835 const Type *CTy = C->getType();
5836 if (ETy != CTy)
5837 error("Element #" + utostr(i) + " is not of type '" +
5838 ETy->getDescription() +"' as required!\nIt is of type '" +
5839 CTy->getDescription() + "'");
5840 Elems.push_back(C);
5841 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00005842 (yyval.ValIDVal) = ValID::create(ConstantVector::get(pt, Elems));
5843 delete PTy; delete (yyvsp[(2) - (3)].ConstVector);
5844 ;}
5845 break;
5846
5847 case 246:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005848#line 3087 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005849 {
5850 (yyval.ValIDVal) = ValID::create((yyvsp[(1) - (1)].ConstVal).C);
5851 (yyval.ValIDVal).S.copy((yyvsp[(1) - (1)].ConstVal).S);
5852 ;}
5853 break;
5854
5855 case 247:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005856#line 3091 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005857 {
5858 char *End = UnEscapeLexed((yyvsp[(3) - (5)].StrVal), true);
5859 std::string AsmStr = std::string((yyvsp[(3) - (5)].StrVal), End);
5860 End = UnEscapeLexed((yyvsp[(5) - (5)].StrVal), true);
5861 std::string Constraints = std::string((yyvsp[(5) - (5)].StrVal), End);
5862 (yyval.ValIDVal) = ValID::createInlineAsm(AsmStr, Constraints, (yyvsp[(2) - (5)].BoolVal));
5863 free((yyvsp[(3) - (5)].StrVal));
5864 free((yyvsp[(5) - (5)].StrVal));
5865 ;}
5866 break;
5867
5868 case 248:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005869#line 3106 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005870 { (yyval.ValIDVal) = ValID::create((yyvsp[(1) - (1)].SIntVal)); (yyval.ValIDVal).S.makeSignless(); ;}
5871 break;
5872
5873 case 249:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005874#line 3107 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005875 { (yyval.ValIDVal) = ValID::create((yyvsp[(1) - (1)].StrVal)); (yyval.ValIDVal).S.makeSignless(); ;}
5876 break;
5877
5878 case 252:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005879#line 3120 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005880 {
5881 const Type *Ty = (yyvsp[(1) - (2)].TypeVal).PAT->get();
5882 (yyvsp[(2) - (2)].ValIDVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
5883 (yyval.ValueVal).V = getVal(Ty, (yyvsp[(2) - (2)].ValIDVal));
5884 (yyval.ValueVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
5885 delete (yyvsp[(1) - (2)].TypeVal).PAT;
5886 ;}
5887 break;
5888
5889 case 253:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005890#line 3130 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005891 {
5892 (yyval.FunctionVal) = (yyvsp[(1) - (2)].FunctionVal);
5893 ;}
5894 break;
5895
5896 case 254:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005897#line 3133 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005898 { // Do not allow functions with 0 basic blocks
5899 (yyval.FunctionVal) = (yyvsp[(1) - (2)].FunctionVal);
5900 ;}
5901 break;
5902
5903 case 255:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005904#line 3142 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005905 {
5906 ValueInfo VI; VI.V = (yyvsp[(3) - (3)].TermInstVal).TI; VI.S.copy((yyvsp[(3) - (3)].TermInstVal).S);
5907 setValueName(VI, (yyvsp[(2) - (3)].StrVal));
5908 InsertValue((yyvsp[(3) - (3)].TermInstVal).TI);
5909 (yyvsp[(1) - (3)].BasicBlockVal)->getInstList().push_back((yyvsp[(3) - (3)].TermInstVal).TI);
5910 InsertValue((yyvsp[(1) - (3)].BasicBlockVal));
5911 (yyval.BasicBlockVal) = (yyvsp[(1) - (3)].BasicBlockVal);
5912 ;}
5913 break;
5914
5915 case 256:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005916#line 3153 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005917 {
5918 if ((yyvsp[(2) - (2)].InstVal).I)
5919 (yyvsp[(1) - (2)].BasicBlockVal)->getInstList().push_back((yyvsp[(2) - (2)].InstVal).I);
5920 (yyval.BasicBlockVal) = (yyvsp[(1) - (2)].BasicBlockVal);
5921 ;}
5922 break;
5923
5924 case 257:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005925#line 3158 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005926 {
5927 (yyval.BasicBlockVal) = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++),true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005928 // Make sure to move the basic block to the correct location in the
5929 // function, instead of leaving it inserted wherever it was first
5930 // referenced.
5931 Function::BasicBlockListType &BBL =
5932 CurFun.CurrentFunction->getBasicBlockList();
Chris Lattnera62e8e42007-12-29 20:47:37 +00005933 BBL.splice(BBL.end(), BBL, (yyval.BasicBlockVal));
5934 ;}
5935 break;
5936
5937 case 258:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005938#line 3167 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005939 {
5940 (yyval.BasicBlockVal) = CurBB = getBBVal(ValID::create((yyvsp[(1) - (1)].StrVal)), true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005941 // Make sure to move the basic block to the correct location in the
5942 // function, instead of leaving it inserted wherever it was first
5943 // referenced.
5944 Function::BasicBlockListType &BBL =
5945 CurFun.CurrentFunction->getBasicBlockList();
Chris Lattnera62e8e42007-12-29 20:47:37 +00005946 BBL.splice(BBL.end(), BBL, (yyval.BasicBlockVal));
5947 ;}
5948 break;
5949
5950 case 261:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005951#line 3181 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005952 { // Return with a result...
5953 (yyval.TermInstVal).TI = new ReturnInst((yyvsp[(2) - (2)].ValueVal).V);
5954 (yyval.TermInstVal).S.makeSignless();
5955 ;}
5956 break;
5957
5958 case 262:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005959#line 3185 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005960 { // Return with no result...
5961 (yyval.TermInstVal).TI = new ReturnInst();
5962 (yyval.TermInstVal).S.makeSignless();
5963 ;}
5964 break;
5965
5966 case 263:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005967#line 3189 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005968 { // Unconditional Branch...
5969 BasicBlock* tmpBB = getBBVal((yyvsp[(3) - (3)].ValIDVal));
5970 (yyval.TermInstVal).TI = new BranchInst(tmpBB);
5971 (yyval.TermInstVal).S.makeSignless();
5972 ;}
5973 break;
5974
5975 case 264:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005976#line 3194 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005977 {
5978 (yyvsp[(6) - (9)].ValIDVal).S.makeSignless();
5979 (yyvsp[(9) - (9)].ValIDVal).S.makeSignless();
5980 BasicBlock* tmpBBA = getBBVal((yyvsp[(6) - (9)].ValIDVal));
5981 BasicBlock* tmpBBB = getBBVal((yyvsp[(9) - (9)].ValIDVal));
5982 (yyvsp[(3) - (9)].ValIDVal).S.makeUnsigned();
5983 Value* tmpVal = getVal(Type::Int1Ty, (yyvsp[(3) - (9)].ValIDVal));
5984 (yyval.TermInstVal).TI = new BranchInst(tmpBBA, tmpBBB, tmpVal);
5985 (yyval.TermInstVal).S.makeSignless();
5986 ;}
5987 break;
5988
5989 case 265:
Chris Lattner1c8733e2008-03-12 17:45:29 +00005990#line 3204 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00005991 {
5992 (yyvsp[(3) - (9)].ValIDVal).S.copy((yyvsp[(2) - (9)].PrimType).S);
5993 Value* tmpVal = getVal((yyvsp[(2) - (9)].PrimType).T, (yyvsp[(3) - (9)].ValIDVal));
5994 (yyvsp[(6) - (9)].ValIDVal).S.makeSignless();
5995 BasicBlock* tmpBB = getBBVal((yyvsp[(6) - (9)].ValIDVal));
5996 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, (yyvsp[(8) - (9)].JumpTable)->size());
5997 (yyval.TermInstVal).TI = S;
5998 (yyval.TermInstVal).S.makeSignless();
5999 std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = (yyvsp[(8) - (9)].JumpTable)->begin(),
6000 E = (yyvsp[(8) - (9)].JumpTable)->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006001 for (; I != E; ++I) {
6002 if (ConstantInt *CI = dyn_cast<ConstantInt>(I->first))
6003 S->addCase(CI, I->second);
6004 else
6005 error("Switch case is constant, but not a simple integer");
6006 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00006007 delete (yyvsp[(8) - (9)].JumpTable);
6008 ;}
6009 break;
6010
6011 case 266:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006012#line 3222 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006013 {
6014 (yyvsp[(3) - (8)].ValIDVal).S.copy((yyvsp[(2) - (8)].PrimType).S);
6015 Value* tmpVal = getVal((yyvsp[(2) - (8)].PrimType).T, (yyvsp[(3) - (8)].ValIDVal));
6016 (yyvsp[(6) - (8)].ValIDVal).S.makeSignless();
6017 BasicBlock* tmpBB = getBBVal((yyvsp[(6) - (8)].ValIDVal));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006018 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0);
Chris Lattnera62e8e42007-12-29 20:47:37 +00006019 (yyval.TermInstVal).TI = S;
6020 (yyval.TermInstVal).S.makeSignless();
6021 ;}
6022 break;
6023
6024 case 267:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006025#line 3232 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006026 {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006027 const PointerType *PFTy;
6028 const FunctionType *Ty;
6029 Signedness FTySign;
6030
Chris Lattnera62e8e42007-12-29 20:47:37 +00006031 if (!(PFTy = dyn_cast<PointerType>((yyvsp[(3) - (13)].TypeVal).PAT->get())) ||
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006032 !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
6033 // Pull out the types of all of the arguments...
6034 std::vector<const Type*> ParamTypes;
Chris Lattnera62e8e42007-12-29 20:47:37 +00006035 FTySign.makeComposite((yyvsp[(3) - (13)].TypeVal).S);
6036 if ((yyvsp[(6) - (13)].ValueList)) {
6037 for (std::vector<ValueInfo>::iterator I = (yyvsp[(6) - (13)].ValueList)->begin(), E = (yyvsp[(6) - (13)].ValueList)->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006038 I != E; ++I) {
6039 ParamTypes.push_back((*I).V->getType());
6040 FTySign.add(I->S);
6041 }
6042 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006043 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
6044 if (isVarArg) ParamTypes.pop_back();
Chris Lattnera62e8e42007-12-29 20:47:37 +00006045 Ty = FunctionType::get((yyvsp[(3) - (13)].TypeVal).PAT->get(), ParamTypes, isVarArg);
Christopher Lambfb623c62007-12-17 01:17:35 +00006046 PFTy = PointerType::getUnqual(Ty);
Chris Lattnera62e8e42007-12-29 20:47:37 +00006047 (yyval.TermInstVal).S.copy((yyvsp[(3) - (13)].TypeVal).S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006048 } else {
Chris Lattnera62e8e42007-12-29 20:47:37 +00006049 FTySign = (yyvsp[(3) - (13)].TypeVal).S;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006050 // Get the signedness of the result type. $3 is the pointer to the
6051 // function type so we get the 0th element to extract the function type,
6052 // and then the 0th element again to get the result type.
Chris Lattnera62e8e42007-12-29 20:47:37 +00006053 (yyval.TermInstVal).S.copy((yyvsp[(3) - (13)].TypeVal).S.get(0).get(0));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006054 }
6055
Chris Lattnera62e8e42007-12-29 20:47:37 +00006056 (yyvsp[(4) - (13)].ValIDVal).S.makeComposite(FTySign);
6057 Value *V = getVal(PFTy, (yyvsp[(4) - (13)].ValIDVal)); // Get the function we're calling...
6058 BasicBlock *Normal = getBBVal((yyvsp[(10) - (13)].ValIDVal));
6059 BasicBlock *Except = getBBVal((yyvsp[(13) - (13)].ValIDVal));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006060
6061 // Create the call node...
Chris Lattnera62e8e42007-12-29 20:47:37 +00006062 if (!(yyvsp[(6) - (13)].ValueList)) { // Has no arguments?
David Greene48556392007-09-04 18:46:50 +00006063 std::vector<Value*> Args;
Chris Lattnera62e8e42007-12-29 20:47:37 +00006064 (yyval.TermInstVal).TI = new InvokeInst(V, Normal, Except, Args.begin(), Args.end());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006065 } else { // Has arguments?
6066 // Loop through FunctionType's arguments and ensure they are specified
6067 // correctly!
6068 //
6069 FunctionType::param_iterator I = Ty->param_begin();
6070 FunctionType::param_iterator E = Ty->param_end();
Chris Lattnera62e8e42007-12-29 20:47:37 +00006071 std::vector<ValueInfo>::iterator ArgI = (yyvsp[(6) - (13)].ValueList)->begin(), ArgE = (yyvsp[(6) - (13)].ValueList)->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006072
6073 std::vector<Value*> Args;
6074 for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
6075 if ((*ArgI).V->getType() != *I)
6076 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
6077 (*I)->getDescription() + "'");
6078 Args.push_back((*ArgI).V);
6079 }
6080
6081 if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
6082 error("Invalid number of parameters detected");
6083
Chris Lattnera62e8e42007-12-29 20:47:37 +00006084 (yyval.TermInstVal).TI = new InvokeInst(V, Normal, Except, Args.begin(), Args.end());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006085 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00006086 cast<InvokeInst>((yyval.TermInstVal).TI)->setCallingConv(upgradeCallingConv((yyvsp[(2) - (13)].UIntVal)));
6087 if ((yyvsp[(2) - (13)].UIntVal) == OldCallingConv::CSRet) {
Chris Lattner1c8733e2008-03-12 17:45:29 +00006088 ParamAttrsWithIndex PAWI =
6089 ParamAttrsWithIndex::get(1, ParamAttr::StructRet); // first arg
6090 cast<InvokeInst>((yyval.TermInstVal).TI)->setParamAttrs(PAListPtr::get(&PAWI, 1));
Duncan Sandsf5588dc2007-11-27 13:23:08 +00006091 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00006092 delete (yyvsp[(3) - (13)].TypeVal).PAT;
6093 delete (yyvsp[(6) - (13)].ValueList);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006094 lastCallingConv = OldCallingConv::C;
Chris Lattnera62e8e42007-12-29 20:47:37 +00006095 ;}
6096 break;
6097
6098 case 268:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006099#line 3302 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006100 {
6101 (yyval.TermInstVal).TI = new UnwindInst();
6102 (yyval.TermInstVal).S.makeSignless();
6103 ;}
6104 break;
6105
6106 case 269:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006107#line 3306 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006108 {
6109 (yyval.TermInstVal).TI = new UnreachableInst();
6110 (yyval.TermInstVal).S.makeSignless();
6111 ;}
6112 break;
6113
6114 case 270:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006115#line 3313 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006116 {
6117 (yyval.JumpTable) = (yyvsp[(1) - (6)].JumpTable);
6118 (yyvsp[(3) - (6)].ValIDVal).S.copy((yyvsp[(2) - (6)].PrimType).S);
6119 Constant *V = cast<Constant>(getExistingValue((yyvsp[(2) - (6)].PrimType).T, (yyvsp[(3) - (6)].ValIDVal)));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006120
6121 if (V == 0)
6122 error("May only switch on a constant pool value");
6123
Chris Lattnera62e8e42007-12-29 20:47:37 +00006124 (yyvsp[(6) - (6)].ValIDVal).S.makeSignless();
6125 BasicBlock* tmpBB = getBBVal((yyvsp[(6) - (6)].ValIDVal));
6126 (yyval.JumpTable)->push_back(std::make_pair(V, tmpBB));
6127 ;}
6128 break;
6129
6130 case 271:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006131#line 3325 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006132 {
6133 (yyval.JumpTable) = new std::vector<std::pair<Constant*, BasicBlock*> >();
6134 (yyvsp[(2) - (5)].ValIDVal).S.copy((yyvsp[(1) - (5)].PrimType).S);
6135 Constant *V = cast<Constant>(getExistingValue((yyvsp[(1) - (5)].PrimType).T, (yyvsp[(2) - (5)].ValIDVal)));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006136
6137 if (V == 0)
6138 error("May only switch on a constant pool value");
6139
Chris Lattnera62e8e42007-12-29 20:47:37 +00006140 (yyvsp[(5) - (5)].ValIDVal).S.makeSignless();
6141 BasicBlock* tmpBB = getBBVal((yyvsp[(5) - (5)].ValIDVal));
6142 (yyval.JumpTable)->push_back(std::make_pair(V, tmpBB));
6143 ;}
6144 break;
6145
6146 case 272:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006147#line 3340 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006148 {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006149 bool omit = false;
Chris Lattnera62e8e42007-12-29 20:47:37 +00006150 if ((yyvsp[(1) - (2)].StrVal))
6151 if (BitCastInst *BCI = dyn_cast<BitCastInst>((yyvsp[(2) - (2)].InstVal).I))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006152 if (BCI->getSrcTy() == BCI->getDestTy() &&
Chris Lattnera62e8e42007-12-29 20:47:37 +00006153 BCI->getOperand(0)->getName() == (yyvsp[(1) - (2)].StrVal))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006154 // This is a useless bit cast causing a name redefinition. It is
6155 // a bit cast from a type to the same type of an operand with the
6156 // same name as the name we would give this instruction. Since this
6157 // instruction results in no code generation, it is safe to omit
6158 // the instruction. This situation can occur because of collapsed
6159 // type planes. For example:
6160 // %X = add int %Y, %Z
6161 // %X = cast int %Y to uint
6162 // After upgrade, this looks like:
6163 // %X = add i32 %Y, %Z
6164 // %X = bitcast i32 to i32
6165 // The bitcast is clearly useless so we omit it.
6166 omit = true;
6167 if (omit) {
Chris Lattnera62e8e42007-12-29 20:47:37 +00006168 (yyval.InstVal).I = 0;
6169 (yyval.InstVal).S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006170 } else {
Chris Lattnera62e8e42007-12-29 20:47:37 +00006171 ValueInfo VI; VI.V = (yyvsp[(2) - (2)].InstVal).I; VI.S.copy((yyvsp[(2) - (2)].InstVal).S);
6172 setValueName(VI, (yyvsp[(1) - (2)].StrVal));
6173 InsertValue((yyvsp[(2) - (2)].InstVal).I);
6174 (yyval.InstVal) = (yyvsp[(2) - (2)].InstVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006175 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00006176 ;}
6177 break;
6178
6179 case 273:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006180#line 3370 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006181 { // Used for PHI nodes
6182 (yyval.PHIList).P = new std::list<std::pair<Value*, BasicBlock*> >();
6183 (yyval.PHIList).S.copy((yyvsp[(1) - (6)].TypeVal).S);
6184 (yyvsp[(3) - (6)].ValIDVal).S.copy((yyvsp[(1) - (6)].TypeVal).S);
6185 Value* tmpVal = getVal((yyvsp[(1) - (6)].TypeVal).PAT->get(), (yyvsp[(3) - (6)].ValIDVal));
6186 (yyvsp[(5) - (6)].ValIDVal).S.makeSignless();
6187 BasicBlock* tmpBB = getBBVal((yyvsp[(5) - (6)].ValIDVal));
6188 (yyval.PHIList).P->push_back(std::make_pair(tmpVal, tmpBB));
6189 delete (yyvsp[(1) - (6)].TypeVal).PAT;
6190 ;}
6191 break;
6192
6193 case 274:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006194#line 3380 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006195 {
6196 (yyval.PHIList) = (yyvsp[(1) - (7)].PHIList);
6197 (yyvsp[(4) - (7)].ValIDVal).S.copy((yyvsp[(1) - (7)].PHIList).S);
6198 Value* tmpVal = getVal((yyvsp[(1) - (7)].PHIList).P->front().first->getType(), (yyvsp[(4) - (7)].ValIDVal));
6199 (yyvsp[(6) - (7)].ValIDVal).S.makeSignless();
6200 BasicBlock* tmpBB = getBBVal((yyvsp[(6) - (7)].ValIDVal));
6201 (yyvsp[(1) - (7)].PHIList).P->push_back(std::make_pair(tmpVal, tmpBB));
6202 ;}
6203 break;
6204
6205 case 275:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006206#line 3390 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006207 { // Used for call statements, and memory insts...
6208 (yyval.ValueList) = new std::vector<ValueInfo>();
6209 (yyval.ValueList)->push_back((yyvsp[(1) - (1)].ValueVal));
6210 ;}
6211 break;
6212
6213 case 276:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006214#line 3394 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006215 {
6216 (yyval.ValueList) = (yyvsp[(1) - (3)].ValueList);
6217 (yyvsp[(1) - (3)].ValueList)->push_back((yyvsp[(3) - (3)].ValueVal));
6218 ;}
6219 break;
6220
6221 case 278:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006222#line 3402 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006223 { (yyval.ValueList) = 0; ;}
6224 break;
6225
6226 case 279:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006227#line 3406 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006228 {
6229 (yyval.BoolVal) = true;
6230 ;}
6231 break;
6232
6233 case 280:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006234#line 3409 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006235 {
6236 (yyval.BoolVal) = false;
6237 ;}
6238 break;
6239
6240 case 281:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006241#line 3415 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006242 {
6243 (yyvsp[(3) - (5)].ValIDVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6244 (yyvsp[(5) - (5)].ValIDVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6245 const Type* Ty = (yyvsp[(2) - (5)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006246 if (!Ty->isInteger() && !Ty->isFloatingPoint() && !isa<VectorType>(Ty))
6247 error("Arithmetic operator requires integer, FP, or packed operands");
6248 if (isa<VectorType>(Ty) &&
Chris Lattnera62e8e42007-12-29 20:47:37 +00006249 ((yyvsp[(1) - (5)].BinaryOpVal) == URemOp || (yyvsp[(1) - (5)].BinaryOpVal) == SRemOp || (yyvsp[(1) - (5)].BinaryOpVal) == FRemOp || (yyvsp[(1) - (5)].BinaryOpVal) == RemOp))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006250 error("Remainder not supported on vector types");
6251 // Upgrade the opcode from obsolete versions before we do anything with it.
Chris Lattnera62e8e42007-12-29 20:47:37 +00006252 Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[(1) - (5)].BinaryOpVal), Ty, (yyvsp[(2) - (5)].TypeVal).S);
6253 Value* val1 = getVal(Ty, (yyvsp[(3) - (5)].ValIDVal));
6254 Value* val2 = getVal(Ty, (yyvsp[(5) - (5)].ValIDVal));
6255 (yyval.InstVal).I = BinaryOperator::create(Opcode, val1, val2);
6256 if ((yyval.InstVal).I == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006257 error("binary operator returned null");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006258 (yyval.InstVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6259 delete (yyvsp[(2) - (5)].TypeVal).PAT;
6260 ;}
6261 break;
6262
6263 case 282:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006264#line 3434 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006265 {
6266 (yyvsp[(3) - (5)].ValIDVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6267 (yyvsp[(5) - (5)].ValIDVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6268 const Type *Ty = (yyvsp[(2) - (5)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006269 if (!Ty->isInteger()) {
6270 if (!isa<VectorType>(Ty) ||
6271 !cast<VectorType>(Ty)->getElementType()->isInteger())
6272 error("Logical operator requires integral operands");
6273 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00006274 Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[(1) - (5)].BinaryOpVal), Ty, (yyvsp[(2) - (5)].TypeVal).S);
6275 Value* tmpVal1 = getVal(Ty, (yyvsp[(3) - (5)].ValIDVal));
6276 Value* tmpVal2 = getVal(Ty, (yyvsp[(5) - (5)].ValIDVal));
6277 (yyval.InstVal).I = BinaryOperator::create(Opcode, tmpVal1, tmpVal2);
6278 if ((yyval.InstVal).I == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006279 error("binary operator returned null");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006280 (yyval.InstVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6281 delete (yyvsp[(2) - (5)].TypeVal).PAT;
6282 ;}
6283 break;
6284
6285 case 283:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006286#line 3452 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006287 {
6288 (yyvsp[(3) - (5)].ValIDVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6289 (yyvsp[(5) - (5)].ValIDVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6290 const Type* Ty = (yyvsp[(2) - (5)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006291 if(isa<VectorType>(Ty))
6292 error("VectorTypes currently not supported in setcc instructions");
6293 unsigned short pred;
Chris Lattnera62e8e42007-12-29 20:47:37 +00006294 Instruction::OtherOps Opcode = getCompareOp((yyvsp[(1) - (5)].BinaryOpVal), pred, Ty, (yyvsp[(2) - (5)].TypeVal).S);
6295 Value* tmpVal1 = getVal(Ty, (yyvsp[(3) - (5)].ValIDVal));
6296 Value* tmpVal2 = getVal(Ty, (yyvsp[(5) - (5)].ValIDVal));
6297 (yyval.InstVal).I = CmpInst::create(Opcode, pred, tmpVal1, tmpVal2);
6298 if ((yyval.InstVal).I == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006299 error("binary operator returned null");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006300 (yyval.InstVal).S.makeUnsigned();
6301 delete (yyvsp[(2) - (5)].TypeVal).PAT;
6302 ;}
6303 break;
6304
6305 case 284:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006306#line 3468 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006307 {
6308 (yyvsp[(4) - (6)].ValIDVal).S.copy((yyvsp[(3) - (6)].TypeVal).S);
6309 (yyvsp[(6) - (6)].ValIDVal).S.copy((yyvsp[(3) - (6)].TypeVal).S);
6310 const Type *Ty = (yyvsp[(3) - (6)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006311 if (isa<VectorType>(Ty))
6312 error("VectorTypes currently not supported in icmp instructions");
6313 else if (!Ty->isInteger() && !isa<PointerType>(Ty))
6314 error("icmp requires integer or pointer typed operands");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006315 Value* tmpVal1 = getVal(Ty, (yyvsp[(4) - (6)].ValIDVal));
6316 Value* tmpVal2 = getVal(Ty, (yyvsp[(6) - (6)].ValIDVal));
6317 (yyval.InstVal).I = new ICmpInst((yyvsp[(2) - (6)].IPred), tmpVal1, tmpVal2);
6318 (yyval.InstVal).S.makeUnsigned();
6319 delete (yyvsp[(3) - (6)].TypeVal).PAT;
6320 ;}
6321 break;
6322
6323 case 285:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006324#line 3482 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006325 {
6326 (yyvsp[(4) - (6)].ValIDVal).S.copy((yyvsp[(3) - (6)].TypeVal).S);
6327 (yyvsp[(6) - (6)].ValIDVal).S.copy((yyvsp[(3) - (6)].TypeVal).S);
6328 const Type *Ty = (yyvsp[(3) - (6)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006329 if (isa<VectorType>(Ty))
6330 error("VectorTypes currently not supported in fcmp instructions");
6331 else if (!Ty->isFloatingPoint())
6332 error("fcmp instruction requires floating point operands");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006333 Value* tmpVal1 = getVal(Ty, (yyvsp[(4) - (6)].ValIDVal));
6334 Value* tmpVal2 = getVal(Ty, (yyvsp[(6) - (6)].ValIDVal));
6335 (yyval.InstVal).I = new FCmpInst((yyvsp[(2) - (6)].FPred), tmpVal1, tmpVal2);
6336 (yyval.InstVal).S.makeUnsigned();
6337 delete (yyvsp[(3) - (6)].TypeVal).PAT;
6338 ;}
6339 break;
6340
6341 case 286:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006342#line 3496 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006343 {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006344 warning("Use of obsolete 'not' instruction: Replacing with 'xor");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006345 const Type *Ty = (yyvsp[(2) - (2)].ValueVal).V->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006346 Value *Ones = ConstantInt::getAllOnesValue(Ty);
6347 if (Ones == 0)
6348 error("Expected integral type for not instruction");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006349 (yyval.InstVal).I = BinaryOperator::create(Instruction::Xor, (yyvsp[(2) - (2)].ValueVal).V, Ones);
6350 if ((yyval.InstVal).I == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006351 error("Could not create a xor instruction");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006352 (yyval.InstVal).S.copy((yyvsp[(2) - (2)].ValueVal).S);
6353 ;}
6354 break;
6355
6356 case 287:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006357#line 3507 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006358 {
6359 if (!(yyvsp[(4) - (4)].ValueVal).V->getType()->isInteger() ||
6360 cast<IntegerType>((yyvsp[(4) - (4)].ValueVal).V->getType())->getBitWidth() != 8)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006361 error("Shift amount must be int8");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006362 const Type* Ty = (yyvsp[(2) - (4)].ValueVal).V->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006363 if (!Ty->isInteger())
6364 error("Shift constant expression requires integer operand");
6365 Value* ShiftAmt = 0;
6366 if (cast<IntegerType>(Ty)->getBitWidth() > Type::Int8Ty->getBitWidth())
Chris Lattnera62e8e42007-12-29 20:47:37 +00006367 if (Constant *C = dyn_cast<Constant>((yyvsp[(4) - (4)].ValueVal).V))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006368 ShiftAmt = ConstantExpr::getZExt(C, Ty);
6369 else
Chris Lattnera62e8e42007-12-29 20:47:37 +00006370 ShiftAmt = new ZExtInst((yyvsp[(4) - (4)].ValueVal).V, Ty, makeNameUnique("shift"), CurBB);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006371 else
Chris Lattnera62e8e42007-12-29 20:47:37 +00006372 ShiftAmt = (yyvsp[(4) - (4)].ValueVal).V;
6373 (yyval.InstVal).I = BinaryOperator::create(getBinaryOp((yyvsp[(1) - (4)].BinaryOpVal), Ty, (yyvsp[(2) - (4)].ValueVal).S), (yyvsp[(2) - (4)].ValueVal).V, ShiftAmt);
6374 (yyval.InstVal).S.copy((yyvsp[(2) - (4)].ValueVal).S);
6375 ;}
6376 break;
6377
6378 case 288:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006379#line 3525 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006380 {
6381 const Type *DstTy = (yyvsp[(4) - (4)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006382 if (!DstTy->isFirstClassType())
6383 error("cast instruction to a non-primitive type: '" +
6384 DstTy->getDescription() + "'");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006385 (yyval.InstVal).I = cast<Instruction>(getCast((yyvsp[(1) - (4)].CastOpVal), (yyvsp[(2) - (4)].ValueVal).V, (yyvsp[(2) - (4)].ValueVal).S, DstTy, (yyvsp[(4) - (4)].TypeVal).S, true));
6386 (yyval.InstVal).S.copy((yyvsp[(4) - (4)].TypeVal).S);
6387 delete (yyvsp[(4) - (4)].TypeVal).PAT;
6388 ;}
6389 break;
6390
6391 case 289:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006392#line 3534 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006393 {
6394 if (!(yyvsp[(2) - (6)].ValueVal).V->getType()->isInteger() ||
6395 cast<IntegerType>((yyvsp[(2) - (6)].ValueVal).V->getType())->getBitWidth() != 1)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006396 error("select condition must be bool");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006397 if ((yyvsp[(4) - (6)].ValueVal).V->getType() != (yyvsp[(6) - (6)].ValueVal).V->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006398 error("select value types should match");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006399 (yyval.InstVal).I = new SelectInst((yyvsp[(2) - (6)].ValueVal).V, (yyvsp[(4) - (6)].ValueVal).V, (yyvsp[(6) - (6)].ValueVal).V);
6400 (yyval.InstVal).S.copy((yyvsp[(4) - (6)].ValueVal).S);
6401 ;}
6402 break;
6403
6404 case 290:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006405#line 3543 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006406 {
6407 const Type *Ty = (yyvsp[(4) - (4)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006408 NewVarArgs = true;
Chris Lattnera62e8e42007-12-29 20:47:37 +00006409 (yyval.InstVal).I = new VAArgInst((yyvsp[(2) - (4)].ValueVal).V, Ty);
6410 (yyval.InstVal).S.copy((yyvsp[(4) - (4)].TypeVal).S);
6411 delete (yyvsp[(4) - (4)].TypeVal).PAT;
6412 ;}
6413 break;
6414
6415 case 291:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006416#line 3550 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006417 {
6418 const Type* ArgTy = (yyvsp[(2) - (4)].ValueVal).V->getType();
6419 const Type* DstTy = (yyvsp[(4) - (4)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006420 ObsoleteVarArgs = true;
6421 Function* NF = cast<Function>(CurModule.CurrentModule->
6422 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
6423
6424 //b = vaarg a, t ->
6425 //foo = alloca 1 of t
6426 //bar = vacopy a
6427 //store bar -> foo
6428 //b = vaarg foo, t
6429 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vaarg.fix");
6430 CurBB->getInstList().push_back(foo);
Chris Lattnera62e8e42007-12-29 20:47:37 +00006431 CallInst* bar = new CallInst(NF, (yyvsp[(2) - (4)].ValueVal).V);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006432 CurBB->getInstList().push_back(bar);
6433 CurBB->getInstList().push_back(new StoreInst(bar, foo));
Chris Lattnera62e8e42007-12-29 20:47:37 +00006434 (yyval.InstVal).I = new VAArgInst(foo, DstTy);
6435 (yyval.InstVal).S.copy((yyvsp[(4) - (4)].TypeVal).S);
6436 delete (yyvsp[(4) - (4)].TypeVal).PAT;
6437 ;}
6438 break;
6439
6440 case 292:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006441#line 3571 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006442 {
6443 const Type* ArgTy = (yyvsp[(2) - (4)].ValueVal).V->getType();
6444 const Type* DstTy = (yyvsp[(4) - (4)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006445 ObsoleteVarArgs = true;
6446 Function* NF = cast<Function>(CurModule.CurrentModule->
6447 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
6448
6449 //b = vanext a, t ->
6450 //foo = alloca 1 of t
6451 //bar = vacopy a
6452 //store bar -> foo
6453 //tmp = vaarg foo, t
6454 //b = load foo
6455 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vanext.fix");
6456 CurBB->getInstList().push_back(foo);
Chris Lattnera62e8e42007-12-29 20:47:37 +00006457 CallInst* bar = new CallInst(NF, (yyvsp[(2) - (4)].ValueVal).V);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006458 CurBB->getInstList().push_back(bar);
6459 CurBB->getInstList().push_back(new StoreInst(bar, foo));
6460 Instruction* tmp = new VAArgInst(foo, DstTy);
6461 CurBB->getInstList().push_back(tmp);
Chris Lattnera62e8e42007-12-29 20:47:37 +00006462 (yyval.InstVal).I = new LoadInst(foo);
6463 (yyval.InstVal).S.copy((yyvsp[(4) - (4)].TypeVal).S);
6464 delete (yyvsp[(4) - (4)].TypeVal).PAT;
6465 ;}
6466 break;
6467
6468 case 293:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006469#line 3595 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006470 {
6471 if (!ExtractElementInst::isValidOperands((yyvsp[(2) - (4)].ValueVal).V, (yyvsp[(4) - (4)].ValueVal).V))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006472 error("Invalid extractelement operands");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006473 (yyval.InstVal).I = new ExtractElementInst((yyvsp[(2) - (4)].ValueVal).V, (yyvsp[(4) - (4)].ValueVal).V);
6474 (yyval.InstVal).S.copy((yyvsp[(2) - (4)].ValueVal).S.get(0));
6475 ;}
6476 break;
6477
6478 case 294:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006479#line 3601 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006480 {
6481 if (!InsertElementInst::isValidOperands((yyvsp[(2) - (6)].ValueVal).V, (yyvsp[(4) - (6)].ValueVal).V, (yyvsp[(6) - (6)].ValueVal).V))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006482 error("Invalid insertelement operands");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006483 (yyval.InstVal).I = new InsertElementInst((yyvsp[(2) - (6)].ValueVal).V, (yyvsp[(4) - (6)].ValueVal).V, (yyvsp[(6) - (6)].ValueVal).V);
6484 (yyval.InstVal).S.copy((yyvsp[(2) - (6)].ValueVal).S);
6485 ;}
6486 break;
6487
6488 case 295:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006489#line 3607 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006490 {
6491 if (!ShuffleVectorInst::isValidOperands((yyvsp[(2) - (6)].ValueVal).V, (yyvsp[(4) - (6)].ValueVal).V, (yyvsp[(6) - (6)].ValueVal).V))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006492 error("Invalid shufflevector operands");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006493 (yyval.InstVal).I = new ShuffleVectorInst((yyvsp[(2) - (6)].ValueVal).V, (yyvsp[(4) - (6)].ValueVal).V, (yyvsp[(6) - (6)].ValueVal).V);
6494 (yyval.InstVal).S.copy((yyvsp[(2) - (6)].ValueVal).S);
6495 ;}
6496 break;
6497
6498 case 296:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006499#line 3613 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006500 {
6501 const Type *Ty = (yyvsp[(2) - (2)].PHIList).P->front().first->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006502 if (!Ty->isFirstClassType())
6503 error("PHI node operands must be of first class type");
6504 PHINode *PHI = new PHINode(Ty);
Chris Lattnera62e8e42007-12-29 20:47:37 +00006505 PHI->reserveOperandSpace((yyvsp[(2) - (2)].PHIList).P->size());
6506 while ((yyvsp[(2) - (2)].PHIList).P->begin() != (yyvsp[(2) - (2)].PHIList).P->end()) {
6507 if ((yyvsp[(2) - (2)].PHIList).P->front().first->getType() != Ty)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006508 error("All elements of a PHI node must be of the same type");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006509 PHI->addIncoming((yyvsp[(2) - (2)].PHIList).P->front().first, (yyvsp[(2) - (2)].PHIList).P->front().second);
6510 (yyvsp[(2) - (2)].PHIList).P->pop_front();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006511 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00006512 (yyval.InstVal).I = PHI;
6513 (yyval.InstVal).S.copy((yyvsp[(2) - (2)].PHIList).S);
6514 delete (yyvsp[(2) - (2)].PHIList).P; // Free the list...
6515 ;}
6516 break;
6517
6518 case 297:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006519#line 3629 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006520 {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006521 // Handle the short call syntax
6522 const PointerType *PFTy;
6523 const FunctionType *FTy;
6524 Signedness FTySign;
Chris Lattnera62e8e42007-12-29 20:47:37 +00006525 if (!(PFTy = dyn_cast<PointerType>((yyvsp[(3) - (7)].TypeVal).PAT->get())) ||
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006526 !(FTy = dyn_cast<FunctionType>(PFTy->getElementType()))) {
6527 // Pull out the types of all of the arguments...
6528 std::vector<const Type*> ParamTypes;
Chris Lattnera62e8e42007-12-29 20:47:37 +00006529 FTySign.makeComposite((yyvsp[(3) - (7)].TypeVal).S);
6530 if ((yyvsp[(6) - (7)].ValueList)) {
6531 for (std::vector<ValueInfo>::iterator I = (yyvsp[(6) - (7)].ValueList)->begin(), E = (yyvsp[(6) - (7)].ValueList)->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006532 I != E; ++I) {
6533 ParamTypes.push_back((*I).V->getType());
6534 FTySign.add(I->S);
6535 }
6536 }
6537
6538 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
6539 if (isVarArg) ParamTypes.pop_back();
6540
Chris Lattnera62e8e42007-12-29 20:47:37 +00006541 const Type *RetTy = (yyvsp[(3) - (7)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006542 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
6543 error("Functions cannot return aggregate types");
6544
Duncan Sandsf5588dc2007-11-27 13:23:08 +00006545 FTy = FunctionType::get(RetTy, ParamTypes, isVarArg);
Christopher Lambfb623c62007-12-17 01:17:35 +00006546 PFTy = PointerType::getUnqual(FTy);
Chris Lattnera62e8e42007-12-29 20:47:37 +00006547 (yyval.InstVal).S.copy((yyvsp[(3) - (7)].TypeVal).S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006548 } else {
Chris Lattnera62e8e42007-12-29 20:47:37 +00006549 FTySign = (yyvsp[(3) - (7)].TypeVal).S;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006550 // Get the signedness of the result type. $3 is the pointer to the
6551 // function type so we get the 0th element to extract the function type,
6552 // and then the 0th element again to get the result type.
Chris Lattnera62e8e42007-12-29 20:47:37 +00006553 (yyval.InstVal).S.copy((yyvsp[(3) - (7)].TypeVal).S.get(0).get(0));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006554 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00006555 (yyvsp[(4) - (7)].ValIDVal).S.makeComposite(FTySign);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006556
6557 // First upgrade any intrinsic calls.
6558 std::vector<Value*> Args;
Chris Lattnera62e8e42007-12-29 20:47:37 +00006559 if ((yyvsp[(6) - (7)].ValueList))
6560 for (unsigned i = 0, e = (yyvsp[(6) - (7)].ValueList)->size(); i < e; ++i)
6561 Args.push_back((*(yyvsp[(6) - (7)].ValueList))[i].V);
6562 Instruction *Inst = upgradeIntrinsicCall(FTy->getReturnType(), (yyvsp[(4) - (7)].ValIDVal), Args);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006563
6564 // If we got an upgraded intrinsic
6565 if (Inst) {
Chris Lattnera62e8e42007-12-29 20:47:37 +00006566 (yyval.InstVal).I = Inst;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006567 } else {
6568 // Get the function we're calling
Chris Lattnera62e8e42007-12-29 20:47:37 +00006569 Value *V = getVal(PFTy, (yyvsp[(4) - (7)].ValIDVal));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006570
6571 // Check the argument values match
Chris Lattnera62e8e42007-12-29 20:47:37 +00006572 if (!(yyvsp[(6) - (7)].ValueList)) { // Has no arguments?
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006573 // Make sure no arguments is a good thing!
6574 if (FTy->getNumParams() != 0)
6575 error("No arguments passed to a function that expects arguments");
6576 } else { // Has arguments?
6577 // Loop through FunctionType's arguments and ensure they are specified
6578 // correctly!
6579 //
6580 FunctionType::param_iterator I = FTy->param_begin();
6581 FunctionType::param_iterator E = FTy->param_end();
Chris Lattnera62e8e42007-12-29 20:47:37 +00006582 std::vector<ValueInfo>::iterator ArgI = (yyvsp[(6) - (7)].ValueList)->begin(), ArgE = (yyvsp[(6) - (7)].ValueList)->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006583
6584 for (; ArgI != ArgE && I != E; ++ArgI, ++I)
6585 if ((*ArgI).V->getType() != *I)
6586 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
6587 (*I)->getDescription() + "'");
6588
6589 if (I != E || (ArgI != ArgE && !FTy->isVarArg()))
6590 error("Invalid number of parameters detected");
6591 }
6592
6593 // Create the call instruction
David Greene9145dd22007-08-01 03:59:32 +00006594 CallInst *CI = new CallInst(V, Args.begin(), Args.end());
Chris Lattnera62e8e42007-12-29 20:47:37 +00006595 CI->setTailCall((yyvsp[(1) - (7)].BoolVal));
6596 CI->setCallingConv(upgradeCallingConv((yyvsp[(2) - (7)].UIntVal)));
Duncan Sandsf5588dc2007-11-27 13:23:08 +00006597
Chris Lattnera62e8e42007-12-29 20:47:37 +00006598 (yyval.InstVal).I = CI;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006599 }
Duncan Sandsf5588dc2007-11-27 13:23:08 +00006600 // Deal with CSRetCC
Chris Lattnera62e8e42007-12-29 20:47:37 +00006601 if ((yyvsp[(2) - (7)].UIntVal) == OldCallingConv::CSRet) {
Chris Lattner1c8733e2008-03-12 17:45:29 +00006602 ParamAttrsWithIndex PAWI =
6603 ParamAttrsWithIndex::get(1, ParamAttr::StructRet); // first arg
6604 cast<CallInst>((yyval.InstVal).I)->setParamAttrs(PAListPtr::get(&PAWI, 1));
Duncan Sandsf5588dc2007-11-27 13:23:08 +00006605 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00006606 delete (yyvsp[(3) - (7)].TypeVal).PAT;
6607 delete (yyvsp[(6) - (7)].ValueList);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006608 lastCallingConv = OldCallingConv::C;
Chris Lattnera62e8e42007-12-29 20:47:37 +00006609 ;}
6610 break;
6611
6612 case 298:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006613#line 3719 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006614 {
6615 (yyval.InstVal) = (yyvsp[(1) - (1)].InstVal);
6616 ;}
6617 break;
6618
6619 case 299:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006620#line 3727 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006621 { (yyval.ValueList) = (yyvsp[(2) - (2)].ValueList); ;}
6622 break;
6623
6624 case 300:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006625#line 3728 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006626 { (yyval.ValueList) = new std::vector<ValueInfo>(); ;}
6627 break;
6628
6629 case 301:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006630#line 3732 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006631 { (yyval.BoolVal) = true; ;}
6632 break;
6633
6634 case 302:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006635#line 3733 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006636 { (yyval.BoolVal) = false; ;}
6637 break;
6638
6639 case 303:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006640#line 3737 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006641 {
6642 const Type *Ty = (yyvsp[(2) - (3)].TypeVal).PAT->get();
6643 (yyval.InstVal).S.makeComposite((yyvsp[(2) - (3)].TypeVal).S);
6644 (yyval.InstVal).I = new MallocInst(Ty, 0, (yyvsp[(3) - (3)].UIntVal));
6645 delete (yyvsp[(2) - (3)].TypeVal).PAT;
6646 ;}
6647 break;
6648
6649 case 304:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006650#line 3743 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006651 {
6652 const Type *Ty = (yyvsp[(2) - (6)].TypeVal).PAT->get();
6653 (yyvsp[(5) - (6)].ValIDVal).S.makeUnsigned();
6654 (yyval.InstVal).S.makeComposite((yyvsp[(2) - (6)].TypeVal).S);
6655 (yyval.InstVal).I = new MallocInst(Ty, getVal((yyvsp[(4) - (6)].PrimType).T, (yyvsp[(5) - (6)].ValIDVal)), (yyvsp[(6) - (6)].UIntVal));
6656 delete (yyvsp[(2) - (6)].TypeVal).PAT;
6657 ;}
6658 break;
6659
6660 case 305:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006661#line 3750 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006662 {
6663 const Type *Ty = (yyvsp[(2) - (3)].TypeVal).PAT->get();
6664 (yyval.InstVal).S.makeComposite((yyvsp[(2) - (3)].TypeVal).S);
6665 (yyval.InstVal).I = new AllocaInst(Ty, 0, (yyvsp[(3) - (3)].UIntVal));
6666 delete (yyvsp[(2) - (3)].TypeVal).PAT;
6667 ;}
6668 break;
6669
6670 case 306:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006671#line 3756 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006672 {
6673 const Type *Ty = (yyvsp[(2) - (6)].TypeVal).PAT->get();
6674 (yyvsp[(5) - (6)].ValIDVal).S.makeUnsigned();
6675 (yyval.InstVal).S.makeComposite((yyvsp[(4) - (6)].PrimType).S);
6676 (yyval.InstVal).I = new AllocaInst(Ty, getVal((yyvsp[(4) - (6)].PrimType).T, (yyvsp[(5) - (6)].ValIDVal)), (yyvsp[(6) - (6)].UIntVal));
6677 delete (yyvsp[(2) - (6)].TypeVal).PAT;
6678 ;}
6679 break;
6680
6681 case 307:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006682#line 3763 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006683 {
6684 const Type *PTy = (yyvsp[(2) - (2)].ValueVal).V->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006685 if (!isa<PointerType>(PTy))
6686 error("Trying to free nonpointer type '" + PTy->getDescription() + "'");
Chris Lattnera62e8e42007-12-29 20:47:37 +00006687 (yyval.InstVal).I = new FreeInst((yyvsp[(2) - (2)].ValueVal).V);
6688 (yyval.InstVal).S.makeSignless();
6689 ;}
6690 break;
6691
6692 case 308:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006693#line 3770 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006694 {
6695 const Type* Ty = (yyvsp[(3) - (4)].TypeVal).PAT->get();
6696 (yyvsp[(4) - (4)].ValIDVal).S.copy((yyvsp[(3) - (4)].TypeVal).S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006697 if (!isa<PointerType>(Ty))
6698 error("Can't load from nonpointer type: " + Ty->getDescription());
6699 if (!cast<PointerType>(Ty)->getElementType()->isFirstClassType())
6700 error("Can't load from pointer of non-first-class type: " +
6701 Ty->getDescription());
Chris Lattnera62e8e42007-12-29 20:47:37 +00006702 Value* tmpVal = getVal(Ty, (yyvsp[(4) - (4)].ValIDVal));
6703 (yyval.InstVal).I = new LoadInst(tmpVal, "", (yyvsp[(1) - (4)].BoolVal));
6704 (yyval.InstVal).S.copy((yyvsp[(3) - (4)].TypeVal).S.get(0));
6705 delete (yyvsp[(3) - (4)].TypeVal).PAT;
6706 ;}
6707 break;
6708
6709 case 309:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006710#line 3783 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006711 {
6712 (yyvsp[(6) - (6)].ValIDVal).S.copy((yyvsp[(5) - (6)].TypeVal).S);
6713 const PointerType *PTy = dyn_cast<PointerType>((yyvsp[(5) - (6)].TypeVal).PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006714 if (!PTy)
6715 error("Can't store to a nonpointer type: " +
Chris Lattnera62e8e42007-12-29 20:47:37 +00006716 (yyvsp[(5) - (6)].TypeVal).PAT->get()->getDescription());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006717 const Type *ElTy = PTy->getElementType();
Chris Lattnera62e8e42007-12-29 20:47:37 +00006718 Value *StoreVal = (yyvsp[(3) - (6)].ValueVal).V;
6719 Value* tmpVal = getVal(PTy, (yyvsp[(6) - (6)].ValIDVal));
6720 if (ElTy != (yyvsp[(3) - (6)].ValueVal).V->getType()) {
Christopher Lambfb623c62007-12-17 01:17:35 +00006721 PTy = PointerType::getUnqual(StoreVal->getType());
Duncan Sandsf5588dc2007-11-27 13:23:08 +00006722 if (Constant *C = dyn_cast<Constant>(tmpVal))
6723 tmpVal = ConstantExpr::getBitCast(C, PTy);
6724 else
6725 tmpVal = new BitCastInst(tmpVal, PTy, "upgrd.cast", CurBB);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006726 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00006727 (yyval.InstVal).I = new StoreInst(StoreVal, tmpVal, (yyvsp[(1) - (6)].BoolVal));
6728 (yyval.InstVal).S.makeSignless();
6729 delete (yyvsp[(5) - (6)].TypeVal).PAT;
6730 ;}
6731 break;
6732
6733 case 310:
Chris Lattner1c8733e2008-03-12 17:45:29 +00006734#line 3803 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006735 {
6736 (yyvsp[(3) - (4)].ValIDVal).S.copy((yyvsp[(2) - (4)].TypeVal).S);
6737 const Type* Ty = (yyvsp[(2) - (4)].TypeVal).PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006738 if (!isa<PointerType>(Ty))
6739 error("getelementptr insn requires pointer operand");
6740
6741 std::vector<Value*> VIndices;
Chris Lattnera62e8e42007-12-29 20:47:37 +00006742 upgradeGEPInstIndices(Ty, (yyvsp[(4) - (4)].ValueList), VIndices);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006743
Chris Lattnera62e8e42007-12-29 20:47:37 +00006744 Value* tmpVal = getVal(Ty, (yyvsp[(3) - (4)].ValIDVal));
6745 (yyval.InstVal).I = new GetElementPtrInst(tmpVal, VIndices.begin(), VIndices.end());
6746 ValueInfo VI; VI.V = tmpVal; VI.S.copy((yyvsp[(2) - (4)].TypeVal).S);
6747 (yyval.InstVal).S.copy(getElementSign(VI, VIndices));
6748 delete (yyvsp[(2) - (4)].TypeVal).PAT;
6749 delete (yyvsp[(4) - (4)].ValueList);
6750 ;}
6751 break;
David Greene48556392007-09-04 18:46:50 +00006752
Chris Lattnera62e8e42007-12-29 20:47:37 +00006753
6754/* Line 1267 of yacc.c. */
Chris Lattner1c8733e2008-03-12 17:45:29 +00006755#line 6756 "UpgradeParser.tab.c"
Chris Lattnera62e8e42007-12-29 20:47:37 +00006756 default: break;
Dale Johannesen3afee192007-09-07 21:07:57 +00006757 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00006758 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
6759
6760 YYPOPSTACK (yylen);
6761 yylen = 0;
6762 YY_STACK_PRINT (yyss, yyssp);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006763
6764 *++yyvsp = yyval;
6765
6766
Chris Lattnera62e8e42007-12-29 20:47:37 +00006767 /* Now `shift' the result of the reduction. Determine what state
6768 that goes to, based on the state we popped back to and the rule
6769 number reduced by. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006770
6771 yyn = yyr1[yyn];
6772
Chris Lattnera62e8e42007-12-29 20:47:37 +00006773 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
6774 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006775 yystate = yytable[yystate];
6776 else
Chris Lattnera62e8e42007-12-29 20:47:37 +00006777 yystate = yydefgoto[yyn - YYNTOKENS];
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006778
6779 goto yynewstate;
6780
6781
Chris Lattnera62e8e42007-12-29 20:47:37 +00006782/*------------------------------------.
6783| yyerrlab -- here on detecting error |
6784`------------------------------------*/
6785yyerrlab:
6786 /* If not already recovering from an error, report this error. */
6787 if (!yyerrstatus)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006788 {
6789 ++yynerrs;
Chris Lattnera62e8e42007-12-29 20:47:37 +00006790#if ! YYERROR_VERBOSE
6791 yyerror (YY_("syntax error"));
6792#else
6793 {
6794 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
6795 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
6796 {
6797 YYSIZE_T yyalloc = 2 * yysize;
6798 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
6799 yyalloc = YYSTACK_ALLOC_MAXIMUM;
6800 if (yymsg != yymsgbuf)
6801 YYSTACK_FREE (yymsg);
6802 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
6803 if (yymsg)
6804 yymsg_alloc = yyalloc;
6805 else
6806 {
6807 yymsg = yymsgbuf;
6808 yymsg_alloc = sizeof yymsgbuf;
6809 }
6810 }
Dale Johannesen3afee192007-09-07 21:07:57 +00006811
Chris Lattnera62e8e42007-12-29 20:47:37 +00006812 if (0 < yysize && yysize <= yymsg_alloc)
6813 {
6814 (void) yysyntax_error (yymsg, yystate, yychar);
6815 yyerror (yymsg);
6816 }
6817 else
6818 {
6819 yyerror (YY_("syntax error"));
6820 if (yysize != 0)
6821 goto yyexhaustedlab;
6822 }
6823 }
6824#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006825 }
6826
Chris Lattnera62e8e42007-12-29 20:47:37 +00006827
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006828
6829 if (yyerrstatus == 3)
6830 {
Chris Lattnera62e8e42007-12-29 20:47:37 +00006831 /* If just tried and failed to reuse look-ahead token after an
6832 error, discard it. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006833
Chris Lattnera62e8e42007-12-29 20:47:37 +00006834 if (yychar <= YYEOF)
6835 {
6836 /* Return failure if at end of input. */
6837 if (yychar == YYEOF)
6838 YYABORT;
6839 }
6840 else
6841 {
6842 yydestruct ("Error: discarding",
6843 yytoken, &yylval);
6844 yychar = YYEMPTY;
6845 }
6846 }
6847
6848 /* Else will try to reuse look-ahead token after shifting the error
6849 token. */
6850 goto yyerrlab1;
6851
6852
6853/*---------------------------------------------------.
6854| yyerrorlab -- error raised explicitly by YYERROR. |
6855`---------------------------------------------------*/
6856yyerrorlab:
6857
6858 /* Pacify compilers like GCC when the user code never invokes
6859 YYERROR and the label yyerrorlab therefore never appears in user
6860 code. */
6861 if (/*CONSTCOND*/ 0)
6862 goto yyerrorlab;
6863
6864 /* Do not reclaim the symbols of the rule which action triggered
6865 this YYERROR. */
6866 YYPOPSTACK (yylen);
6867 yylen = 0;
6868 YY_STACK_PRINT (yyss, yyssp);
6869 yystate = *yyssp;
6870 goto yyerrlab1;
6871
6872
6873/*-------------------------------------------------------------.
6874| yyerrlab1 -- common code for both syntax error and YYERROR. |
6875`-------------------------------------------------------------*/
6876yyerrlab1:
6877 yyerrstatus = 3; /* Each real token shifted decrements this. */
6878
6879 for (;;)
6880 {
6881 yyn = yypact[yystate];
6882 if (yyn != YYPACT_NINF)
6883 {
6884 yyn += YYTERROR;
6885 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
6886 {
6887 yyn = yytable[yyn];
6888 if (0 < yyn)
6889 break;
6890 }
6891 }
6892
6893 /* Pop the current state because it cannot handle the error token. */
6894 if (yyssp == yyss)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006895 YYABORT;
6896
Dale Johannesen3afee192007-09-07 21:07:57 +00006897
Chris Lattnera62e8e42007-12-29 20:47:37 +00006898 yydestruct ("Error: popping",
6899 yystos[yystate], yyvsp);
6900 YYPOPSTACK (1);
6901 yystate = *yyssp;
6902 YY_STACK_PRINT (yyss, yyssp);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006903 }
6904
6905 if (yyn == YYFINAL)
6906 YYACCEPT;
6907
6908 *++yyvsp = yylval;
Chris Lattnera62e8e42007-12-29 20:47:37 +00006909
6910
6911 /* Shift the error token. */
6912 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006913
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006914 yystate = yyn;
6915 goto yynewstate;
6916
Christopher Lambfb623c62007-12-17 01:17:35 +00006917
Chris Lattnera62e8e42007-12-29 20:47:37 +00006918/*-------------------------------------.
6919| yyacceptlab -- YYACCEPT comes here. |
6920`-------------------------------------*/
6921yyacceptlab:
6922 yyresult = 0;
6923 goto yyreturn;
6924
6925/*-----------------------------------.
6926| yyabortlab -- YYABORT comes here. |
6927`-----------------------------------*/
6928yyabortlab:
6929 yyresult = 1;
6930 goto yyreturn;
6931
6932#ifndef yyoverflow
6933/*-------------------------------------------------.
6934| yyexhaustedlab -- memory exhaustion comes here. |
6935`-------------------------------------------------*/
6936yyexhaustedlab:
6937 yyerror (YY_("memory exhausted"));
6938 yyresult = 2;
6939 /* Fall through. */
Duncan Sandsf5588dc2007-11-27 13:23:08 +00006940#endif
Chris Lattnera62e8e42007-12-29 20:47:37 +00006941
6942yyreturn:
6943 if (yychar != YYEOF && yychar != YYEMPTY)
6944 yydestruct ("Cleanup: discarding lookahead",
6945 yytoken, &yylval);
6946 /* Do not reclaim the symbols of the rule which action triggered
6947 this YYABORT or YYACCEPT. */
6948 YYPOPSTACK (yylen);
6949 YY_STACK_PRINT (yyss, yyssp);
6950 while (yyssp != yyss)
6951 {
6952 yydestruct ("Cleanup: popping",
6953 yystos[*yyssp], yyvsp);
6954 YYPOPSTACK (1);
Christopher Lambfb623c62007-12-17 01:17:35 +00006955 }
Chris Lattnera62e8e42007-12-29 20:47:37 +00006956#ifndef yyoverflow
6957 if (yyss != yyssa)
6958 YYSTACK_FREE (yyss);
6959#endif
6960#if YYERROR_VERBOSE
6961 if (yymsg != yymsgbuf)
6962 YYSTACK_FREE (yymsg);
6963#endif
6964 /* Make sure YYID is used. */
6965 return YYID (yyresult);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006966}
Chris Lattnera62e8e42007-12-29 20:47:37 +00006967
6968
Chris Lattner1c8733e2008-03-12 17:45:29 +00006969#line 3821 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006970
6971
6972int yyerror(const char *ErrorMsg) {
6973 std::string where
6974 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
6975 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
6976 std::string errMsg = where + "error: " + std::string(ErrorMsg);
6977 if (yychar != YYEMPTY && yychar != 0)
6978 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
6979 "'.";
6980 std::cerr << "llvm-upgrade: " << errMsg << '\n';
6981 std::cout << "llvm-upgrade: parse failed.\n";
6982 exit(1);
6983}
6984
6985void warning(const std::string& ErrorMsg) {
6986 std::string where
6987 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
6988 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
6989 std::string errMsg = where + "warning: " + std::string(ErrorMsg);
6990 if (yychar != YYEMPTY && yychar != 0)
6991 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
6992 "'.";
6993 std::cerr << "llvm-upgrade: " << errMsg << '\n';
6994}
6995
6996void error(const std::string& ErrorMsg, int LineNo) {
6997 if (LineNo == -1) LineNo = Upgradelineno;
6998 Upgradelineno = LineNo;
6999 yyerror(ErrorMsg.c_str());
7000}
7001
Chris Lattnera62e8e42007-12-29 20:47:37 +00007002