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