blob: d1ff80400c076f7347089351e6c5024bbfe3cecb [file] [log] [blame]
Chris Lattnercf786592007-12-29 20:47:37 +00001/* A Bison parser, made by GNU Bison 2.3. */
Reid Spencere7c3c602006-11-30 06:36:44 +00002
Chris Lattnercf786592007-12-29 20:47:37 +00003/* Skeleton implementation for Bison's Yacc-like parsers in C
Reid Spencere7c3c602006-11-30 06:36:44 +00004
Chris Lattnercf786592007-12-29 20:47:37 +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 Lattnercf786592007-12-29 20:47:37 +00008 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22
23/* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work
25 under terms of your choice, so long as that work isn't itself a
26 parser generator using the skeleton or a modified version thereof
27 as a parser skeleton. Alternatively, if you modify or redistribute
28 the parser skeleton itself, you may (at your option) remove this
29 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public
31 License without this special exception.
32
33 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */
35
36/* C LALR(1) parser skeleton written by Richard Stallman, by
37 simplifying the original so-called "semantic" parser. */
38
39/* All symbols defined below should begin with yy or YY, to avoid
40 infringing on user name space. This should be done even for local
41 variables, as they might otherwise be expanded by user macros.
42 There are some unavoidable exceptions within include files to
43 define necessary library symbols; they are noted "INFRINGES ON
44 USER NAME SPACE" below. */
45
46/* Identify Bison output. */
47#define YYBISON 1
48
49/* Bison version. */
50#define YYBISON_VERSION "2.3"
51
52/* Skeleton name. */
53#define YYSKELETON_NAME "yacc.c"
54
55/* Pure parsers. */
56#define YYPURE 0
57
58/* Using locations. */
59#define YYLSP_NEEDED 0
60
61/* Substitute the variable and function names. */
Reid Spencere7c3c602006-11-30 06:36:44 +000062#define yyparse Upgradeparse
Chris Lattnercf786592007-12-29 20:47:37 +000063#define yylex Upgradelex
Reid Spencere7c3c602006-11-30 06:36:44 +000064#define yyerror Upgradeerror
Chris Lattnercf786592007-12-29 20:47:37 +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 Lattnercf786592007-12-29 20:47:37 +000070
71/* Tokens. */
72#ifndef YYTOKENTYPE
73# define YYTOKENTYPE
74 /* Put the tokens into the symbol table, so that GDB and other debuggers
75 know about them. */
76 enum yytokentype {
77 ESINT64VAL = 258,
78 EUINT64VAL = 259,
79 SINTVAL = 260,
80 UINTVAL = 261,
81 FPVAL = 262,
82 VOID = 263,
83 BOOL = 264,
84 SBYTE = 265,
85 UBYTE = 266,
86 SHORT = 267,
87 USHORT = 268,
88 INT = 269,
89 UINT = 270,
90 LONG = 271,
91 ULONG = 272,
92 FLOAT = 273,
93 DOUBLE = 274,
94 TYPE = 275,
95 LABEL = 276,
96 VAR_ID = 277,
97 LABELSTR = 278,
98 STRINGCONSTANT = 279,
99 IMPLEMENTATION = 280,
100 ZEROINITIALIZER = 281,
101 TRUETOK = 282,
102 FALSETOK = 283,
103 BEGINTOK = 284,
104 ENDTOK = 285,
105 DECLARE = 286,
106 GLOBAL = 287,
107 CONSTANT = 288,
108 SECTION = 289,
109 VOLATILE = 290,
110 TO = 291,
111 DOTDOTDOT = 292,
112 NULL_TOK = 293,
113 UNDEF = 294,
114 CONST = 295,
115 INTERNAL = 296,
116 LINKONCE = 297,
117 WEAK = 298,
118 APPENDING = 299,
119 DLLIMPORT = 300,
120 DLLEXPORT = 301,
121 EXTERN_WEAK = 302,
122 OPAQUE = 303,
123 NOT = 304,
124 EXTERNAL = 305,
125 TARGET = 306,
126 TRIPLE = 307,
127 ENDIAN = 308,
128 POINTERSIZE = 309,
129 LITTLE = 310,
130 BIG = 311,
131 ALIGN = 312,
132 DEPLIBS = 313,
133 CALL = 314,
134 TAIL = 315,
135 ASM_TOK = 316,
136 MODULE = 317,
137 SIDEEFFECT = 318,
138 CC_TOK = 319,
139 CCC_TOK = 320,
140 CSRETCC_TOK = 321,
141 FASTCC_TOK = 322,
142 COLDCC_TOK = 323,
143 X86_STDCALLCC_TOK = 324,
144 X86_FASTCALLCC_TOK = 325,
145 DATALAYOUT = 326,
146 RET = 327,
147 BR = 328,
148 SWITCH = 329,
149 INVOKE = 330,
150 UNREACHABLE = 331,
151 UNWIND = 332,
152 EXCEPT = 333,
153 ADD = 334,
154 SUB = 335,
155 MUL = 336,
156 DIV = 337,
157 UDIV = 338,
158 SDIV = 339,
159 FDIV = 340,
160 REM = 341,
161 UREM = 342,
162 SREM = 343,
163 FREM = 344,
164 AND = 345,
165 OR = 346,
166 XOR = 347,
167 SHL = 348,
168 SHR = 349,
169 ASHR = 350,
170 LSHR = 351,
171 SETLE = 352,
172 SETGE = 353,
173 SETLT = 354,
174 SETGT = 355,
175 SETEQ = 356,
176 SETNE = 357,
177 ICMP = 358,
178 FCMP = 359,
179 MALLOC = 360,
180 ALLOCA = 361,
181 FREE = 362,
182 LOAD = 363,
183 STORE = 364,
184 GETELEMENTPTR = 365,
185 PHI_TOK = 366,
186 SELECT = 367,
187 VAARG = 368,
188 EXTRACTELEMENT = 369,
189 INSERTELEMENT = 370,
190 SHUFFLEVECTOR = 371,
191 VAARG_old = 372,
192 VANEXT_old = 373,
193 EQ = 374,
194 NE = 375,
195 SLT = 376,
196 SGT = 377,
197 SLE = 378,
198 SGE = 379,
199 ULT = 380,
200 UGT = 381,
201 ULE = 382,
202 UGE = 383,
203 OEQ = 384,
204 ONE = 385,
205 OLT = 386,
206 OGT = 387,
207 OLE = 388,
208 OGE = 389,
209 ORD = 390,
210 UNO = 391,
211 UEQ = 392,
212 UNE = 393,
213 CAST = 394,
214 TRUNC = 395,
215 ZEXT = 396,
216 SEXT = 397,
217 FPTRUNC = 398,
218 FPEXT = 399,
219 FPTOUI = 400,
220 FPTOSI = 401,
221 UITOFP = 402,
222 SITOFP = 403,
223 PTRTOINT = 404,
224 INTTOPTR = 405,
225 BITCAST = 406
226 };
227#endif
228/* Tokens. */
229#define ESINT64VAL 258
230#define EUINT64VAL 259
231#define SINTVAL 260
232#define UINTVAL 261
233#define FPVAL 262
234#define VOID 263
235#define BOOL 264
236#define SBYTE 265
237#define UBYTE 266
238#define SHORT 267
239#define USHORT 268
240#define INT 269
241#define UINT 270
242#define LONG 271
243#define ULONG 272
244#define FLOAT 273
245#define DOUBLE 274
246#define TYPE 275
247#define LABEL 276
248#define VAR_ID 277
249#define LABELSTR 278
250#define STRINGCONSTANT 279
251#define IMPLEMENTATION 280
252#define ZEROINITIALIZER 281
253#define TRUETOK 282
254#define FALSETOK 283
255#define BEGINTOK 284
256#define ENDTOK 285
257#define DECLARE 286
258#define GLOBAL 287
259#define CONSTANT 288
260#define SECTION 289
261#define VOLATILE 290
262#define TO 291
263#define DOTDOTDOT 292
264#define NULL_TOK 293
265#define UNDEF 294
266#define CONST 295
267#define INTERNAL 296
268#define LINKONCE 297
269#define WEAK 298
270#define APPENDING 299
271#define DLLIMPORT 300
272#define DLLEXPORT 301
273#define EXTERN_WEAK 302
274#define OPAQUE 303
275#define NOT 304
276#define EXTERNAL 305
277#define TARGET 306
278#define TRIPLE 307
279#define ENDIAN 308
280#define POINTERSIZE 309
281#define LITTLE 310
282#define BIG 311
283#define ALIGN 312
284#define DEPLIBS 313
285#define CALL 314
286#define TAIL 315
287#define ASM_TOK 316
288#define MODULE 317
289#define SIDEEFFECT 318
290#define CC_TOK 319
291#define CCC_TOK 320
292#define CSRETCC_TOK 321
293#define FASTCC_TOK 322
294#define COLDCC_TOK 323
295#define X86_STDCALLCC_TOK 324
296#define X86_FASTCALLCC_TOK 325
297#define DATALAYOUT 326
298#define RET 327
299#define BR 328
300#define SWITCH 329
301#define INVOKE 330
302#define UNREACHABLE 331
303#define UNWIND 332
304#define EXCEPT 333
305#define ADD 334
306#define SUB 335
307#define MUL 336
308#define DIV 337
309#define UDIV 338
310#define SDIV 339
311#define FDIV 340
312#define REM 341
313#define UREM 342
314#define SREM 343
315#define FREM 344
316#define AND 345
317#define OR 346
318#define XOR 347
319#define SHL 348
320#define SHR 349
321#define ASHR 350
322#define LSHR 351
323#define SETLE 352
324#define SETGE 353
325#define SETLT 354
326#define SETGT 355
327#define SETEQ 356
328#define SETNE 357
329#define ICMP 358
330#define FCMP 359
331#define MALLOC 360
332#define ALLOCA 361
333#define FREE 362
334#define LOAD 363
335#define STORE 364
336#define GETELEMENTPTR 365
337#define PHI_TOK 366
338#define SELECT 367
339#define VAARG 368
340#define EXTRACTELEMENT 369
341#define INSERTELEMENT 370
342#define SHUFFLEVECTOR 371
343#define VAARG_old 372
344#define VANEXT_old 373
345#define EQ 374
346#define NE 375
347#define SLT 376
348#define SGT 377
349#define SLE 378
350#define SGE 379
351#define ULT 380
352#define UGT 381
353#define ULE 382
354#define UGE 383
355#define OEQ 384
356#define ONE 385
357#define OLT 386
358#define OGT 387
359#define OLE 388
360#define OGE 389
361#define ORD 390
362#define UNO 391
363#define UEQ 392
364#define UNE 393
365#define CAST 394
366#define TRUNC 395
367#define ZEXT 396
368#define SEXT 397
369#define FPTRUNC 398
370#define FPEXT 399
371#define FPTOUI 400
372#define FPTOSI 401
373#define UITOFP 402
374#define SITOFP 403
375#define PTRTOINT 404
376#define INTTOPTR 405
377#define BITCAST 406
378
379
380
381
382/* Copy the first part of user declarations. */
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 Spencer7b5d4662007-04-09 06:16:21 +0000390#include "llvm/ParameterAttributes.h"
Reid Spenceref9b9a72007-02-05 20:47:22 +0000391#include "llvm/ValueSymbolTable.h"
Reid Spencer950bf602007-01-26 08:19:09 +0000392#include "llvm/Support/GetElementPtrTypeIterator.h"
393#include "llvm/ADT/STLExtras.h"
394#include "llvm/Support/MathExtras.h"
Reid Spencere7c3c602006-11-30 06:36:44 +0000395#include <algorithm>
Reid Spencere7c3c602006-11-30 06:36:44 +0000396#include <iostream>
Chris Lattner8adde282007-02-11 21:40:10 +0000397#include <map>
Reid Spencer950bf602007-01-26 08:19:09 +0000398#include <list>
399#include <utility>
400
401// DEBUG_UPREFS - Define this symbol if you want to enable debugging output
402// relating to upreferences in the input stream.
403//
404//#define DEBUG_UPREFS 1
405#ifdef DEBUG_UPREFS
406#define UR_OUT(X) std::cerr << X
407#else
408#define UR_OUT(X)
409#endif
Reid Spencere7c3c602006-11-30 06:36:44 +0000410
Reid Spencere77e35e2006-12-01 20:26:20 +0000411#define YYERROR_VERBOSE 1
Reid Spencer96839be2006-11-30 16:50:26 +0000412#define YYINCLUDED_STDLIB_H
Reid Spencere77e35e2006-12-01 20:26:20 +0000413#define YYDEBUG 1
Reid Spencere7c3c602006-11-30 06:36:44 +0000414
Reid Spencer950bf602007-01-26 08:19:09 +0000415int yylex();
Reid Spencere7c3c602006-11-30 06:36:44 +0000416int yyparse();
417
Reid Spencer950bf602007-01-26 08:19:09 +0000418int yyerror(const char*);
419static void warning(const std::string& WarningMsg);
420
421namespace llvm {
422
Reid Spencer950bf602007-01-26 08:19:09 +0000423std::istream* LexInput;
Reid Spencere7c3c602006-11-30 06:36:44 +0000424static std::string CurFilename;
Reid Spencer96839be2006-11-30 16:50:26 +0000425
Reid Spencer71d2ec92006-12-31 06:02:26 +0000426// This bool controls whether attributes are ever added to function declarations
427// definitions and calls.
428static bool AddAttributes = false;
429
Reid Spencer950bf602007-01-26 08:19:09 +0000430static Module *ParserResult;
431static bool ObsoleteVarArgs;
432static bool NewVarArgs;
433static BasicBlock *CurBB;
434static GlobalVariable *CurGV;
Reid Spencer7eea8ff2007-05-18 05:48:07 +0000435static unsigned lastCallingConv;
Reid Spencera50d5962006-12-02 04:11:07 +0000436
Reid Spencer950bf602007-01-26 08:19:09 +0000437// This contains info used when building the body of a function. It is
438// destroyed when the function is completed.
439//
440typedef std::vector<Value *> ValueList; // Numbered defs
441
Reid Spencerbb1fd572007-03-21 17:15:50 +0000442typedef std::pair<std::string,TypeInfo> RenameMapKey;
Reid Spencer950bf602007-01-26 08:19:09 +0000443typedef std::map<RenameMapKey,std::string> RenameMapType;
444
445static void
446ResolveDefinitions(std::map<const Type *,ValueList> &LateResolvers,
447 std::map<const Type *,ValueList> *FutureLateResolvers = 0);
448
449static struct PerModuleInfo {
450 Module *CurrentModule;
451 std::map<const Type *, ValueList> Values; // Module level numbered definitions
452 std::map<const Type *,ValueList> LateResolveValues;
Reid Spencerbb1fd572007-03-21 17:15:50 +0000453 std::vector<PATypeHolder> Types;
454 std::vector<Signedness> TypeSigns;
455 std::map<std::string,Signedness> NamedTypeSigns;
456 std::map<std::string,Signedness> NamedValueSigns;
Reid Spencer950bf602007-01-26 08:19:09 +0000457 std::map<ValID, PATypeHolder> LateResolveTypes;
458 static Module::Endianness Endian;
459 static Module::PointerSize PointerSize;
460 RenameMapType RenameMap;
461
462 /// PlaceHolderInfo - When temporary placeholder objects are created, remember
463 /// how they were referenced and on which line of the input they came from so
464 /// that we can resolve them later and print error messages as appropriate.
465 std::map<Value*, std::pair<ValID, int> > PlaceHolderInfo;
466
467 // GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
468 // references to global values. Global values may be referenced before they
469 // are defined, and if so, the temporary object that they represent is held
470 // here. This is used for forward references of GlobalValues.
471 //
472 typedef std::map<std::pair<const PointerType *, ValID>, GlobalValue*>
473 GlobalRefsType;
474 GlobalRefsType GlobalRefs;
475
476 void ModuleDone() {
477 // If we could not resolve some functions at function compilation time
478 // (calls to functions before they are defined), resolve them now... Types
479 // are resolved when the constant pool has been completely parsed.
480 //
481 ResolveDefinitions(LateResolveValues);
482
483 // Check to make sure that all global value forward references have been
484 // resolved!
485 //
486 if (!GlobalRefs.empty()) {
487 std::string UndefinedReferences = "Unresolved global references exist:\n";
488
489 for (GlobalRefsType::iterator I = GlobalRefs.begin(), E =GlobalRefs.end();
490 I != E; ++I) {
491 UndefinedReferences += " " + I->first.first->getDescription() + " " +
492 I->first.second.getName() + "\n";
493 }
494 error(UndefinedReferences);
495 return;
496 }
497
498 if (CurrentModule->getDataLayout().empty()) {
499 std::string dataLayout;
500 if (Endian != Module::AnyEndianness)
501 dataLayout.append(Endian == Module::BigEndian ? "E" : "e");
502 if (PointerSize != Module::AnyPointerSize) {
503 if (!dataLayout.empty())
504 dataLayout += "-";
505 dataLayout.append(PointerSize == Module::Pointer64 ?
506 "p:64:64" : "p:32:32");
507 }
508 CurrentModule->setDataLayout(dataLayout);
509 }
510
511 Values.clear(); // Clear out function local definitions
512 Types.clear();
Reid Spencerbb1fd572007-03-21 17:15:50 +0000513 TypeSigns.clear();
514 NamedTypeSigns.clear();
515 NamedValueSigns.clear();
Reid Spencer950bf602007-01-26 08:19:09 +0000516 CurrentModule = 0;
517 }
518
519 // GetForwardRefForGlobal - Check to see if there is a forward reference
520 // for this global. If so, remove it from the GlobalRefs map and return it.
521 // If not, just return null.
522 GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ValID ID) {
523 // Check to see if there is a forward reference to this global variable...
524 // if there is, eliminate it and patch the reference to use the new def'n.
525 GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PTy, ID));
526 GlobalValue *Ret = 0;
527 if (I != GlobalRefs.end()) {
528 Ret = I->second;
529 GlobalRefs.erase(I);
530 }
531 return Ret;
532 }
533 void setEndianness(Module::Endianness E) { Endian = E; }
534 void setPointerSize(Module::PointerSize sz) { PointerSize = sz; }
535} CurModule;
536
537Module::Endianness PerModuleInfo::Endian = Module::AnyEndianness;
538Module::PointerSize PerModuleInfo::PointerSize = Module::AnyPointerSize;
539
540static struct PerFunctionInfo {
541 Function *CurrentFunction; // Pointer to current function being created
542
543 std::map<const Type*, ValueList> Values; // Keep track of #'d definitions
544 std::map<const Type*, ValueList> LateResolveValues;
545 bool isDeclare; // Is this function a forward declararation?
546 GlobalValue::LinkageTypes Linkage;// Linkage for forward declaration.
547
548 /// BBForwardRefs - When we see forward references to basic blocks, keep
549 /// track of them here.
550 std::map<BasicBlock*, std::pair<ValID, int> > BBForwardRefs;
551 std::vector<BasicBlock*> NumberedBlocks;
552 RenameMapType RenameMap;
Reid Spencer950bf602007-01-26 08:19:09 +0000553 unsigned NextBBNum;
554
555 inline PerFunctionInfo() {
556 CurrentFunction = 0;
557 isDeclare = false;
558 Linkage = GlobalValue::ExternalLinkage;
559 }
560
561 inline void FunctionStart(Function *M) {
562 CurrentFunction = M;
563 NextBBNum = 0;
564 }
565
566 void FunctionDone() {
567 NumberedBlocks.clear();
568
569 // Any forward referenced blocks left?
570 if (!BBForwardRefs.empty()) {
571 error("Undefined reference to label " +
572 BBForwardRefs.begin()->first->getName());
573 return;
574 }
575
576 // Resolve all forward references now.
577 ResolveDefinitions(LateResolveValues, &CurModule.LateResolveValues);
578
579 Values.clear(); // Clear out function local definitions
580 RenameMap.clear();
Reid Spencer950bf602007-01-26 08:19:09 +0000581 CurrentFunction = 0;
582 isDeclare = false;
583 Linkage = GlobalValue::ExternalLinkage;
584 }
585} CurFun; // Info for the current function...
586
587static bool inFunctionScope() { return CurFun.CurrentFunction != 0; }
588
Reid Spencerbb1fd572007-03-21 17:15:50 +0000589/// This function is just a utility to make a Key value for the rename map.
590/// The Key is a combination of the name, type, Signedness of the original
591/// value (global/function). This just constructs the key and ensures that
592/// named Signedness values are resolved to the actual Signedness.
593/// @brief Make a key for the RenameMaps
594static RenameMapKey makeRenameMapKey(const std::string &Name, const Type* Ty,
595 const Signedness &Sign) {
596 TypeInfo TI;
597 TI.T = Ty;
598 if (Sign.isNamed())
599 // Don't allow Named Signedness nodes because they won't match. The actual
600 // Signedness must be looked up in the NamedTypeSigns map.
601 TI.S.copy(CurModule.NamedTypeSigns[Sign.getName()]);
602 else
603 TI.S.copy(Sign);
604 return std::make_pair(Name, TI);
605}
606
Reid Spencer950bf602007-01-26 08:19:09 +0000607
608//===----------------------------------------------------------------------===//
609// Code to handle definitions of all the types
610//===----------------------------------------------------------------------===//
611
612static int InsertValue(Value *V,
613 std::map<const Type*,ValueList> &ValueTab = CurFun.Values) {
614 if (V->hasName()) return -1; // Is this a numbered definition?
615
616 // Yes, insert the value into the value table...
617 ValueList &List = ValueTab[V->getType()];
618 List.push_back(V);
619 return List.size()-1;
620}
621
Reid Spencerd7c4f8c2007-01-26 19:59:25 +0000622static const Type *getType(const ValID &D, bool DoNotImprovise = false) {
Reid Spencer950bf602007-01-26 08:19:09 +0000623 switch (D.Type) {
624 case ValID::NumberVal: // Is it a numbered definition?
625 // Module constants occupy the lowest numbered slots...
626 if ((unsigned)D.Num < CurModule.Types.size()) {
627 return CurModule.Types[(unsigned)D.Num];
628 }
629 break;
630 case ValID::NameVal: // Is it a named definition?
631 if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) {
Reid Spencer950bf602007-01-26 08:19:09 +0000632 return N;
633 }
634 break;
635 default:
636 error("Internal parser error: Invalid symbol type reference");
637 return 0;
638 }
639
640 // If we reached here, we referenced either a symbol that we don't know about
641 // or an id number that hasn't been read yet. We may be referencing something
642 // forward, so just create an entry to be resolved later and get to it...
643 //
644 if (DoNotImprovise) return 0; // Do we just want a null to be returned?
645
Reid Spencer950bf602007-01-26 08:19:09 +0000646 if (inFunctionScope()) {
647 if (D.Type == ValID::NameVal) {
648 error("Reference to an undefined type: '" + D.getName() + "'");
649 return 0;
650 } else {
651 error("Reference to an undefined type: #" + itostr(D.Num));
652 return 0;
653 }
654 }
655
656 std::map<ValID, PATypeHolder>::iterator I =CurModule.LateResolveTypes.find(D);
657 if (I != CurModule.LateResolveTypes.end())
658 return I->second;
659
660 Type *Typ = OpaqueType::get();
661 CurModule.LateResolveTypes.insert(std::make_pair(D, Typ));
662 return Typ;
Reid Spencerbb1fd572007-03-21 17:15:50 +0000663}
664
665/// This is like the getType method except that instead of looking up the type
666/// for a given ID, it looks up that type's sign.
667/// @brief Get the signedness of a referenced type
668static Signedness getTypeSign(const ValID &D) {
669 switch (D.Type) {
670 case ValID::NumberVal: // Is it a numbered definition?
671 // Module constants occupy the lowest numbered slots...
672 if ((unsigned)D.Num < CurModule.TypeSigns.size()) {
673 return CurModule.TypeSigns[(unsigned)D.Num];
674 }
675 break;
676 case ValID::NameVal: { // Is it a named definition?
677 std::map<std::string,Signedness>::const_iterator I =
678 CurModule.NamedTypeSigns.find(D.Name);
679 if (I != CurModule.NamedTypeSigns.end())
680 return I->second;
681 // Perhaps its a named forward .. just cache the name
682 Signedness S;
683 S.makeNamed(D.Name);
684 return S;
685 }
686 default:
687 break;
688 }
689 // If we don't find it, its signless
690 Signedness S;
691 S.makeSignless();
692 return S;
693}
694
695/// This function is analagous to getElementType in LLVM. It provides the same
696/// function except that it looks up the Signedness instead of the type. This is
697/// used when processing GEP instructions that need to extract the type of an
698/// indexed struct/array/ptr member.
699/// @brief Look up an element's sign.
700static Signedness getElementSign(const ValueInfo& VI,
701 const std::vector<Value*> &Indices) {
702 const Type *Ptr = VI.V->getType();
703 assert(isa<PointerType>(Ptr) && "Need pointer type");
704
705 unsigned CurIdx = 0;
706 Signedness S(VI.S);
707 while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) {
708 if (CurIdx == Indices.size())
709 break;
710
711 Value *Index = Indices[CurIdx++];
712 assert(!isa<PointerType>(CT) || CurIdx == 1 && "Invalid type");
713 Ptr = CT->getTypeAtIndex(Index);
714 if (const Type* Ty = Ptr->getForwardedType())
715 Ptr = Ty;
716 assert(S.isComposite() && "Bad Signedness type");
717 if (isa<StructType>(CT)) {
718 S = S.get(cast<ConstantInt>(Index)->getZExtValue());
719 } else {
720 S = S.get(0UL);
721 }
722 if (S.isNamed())
723 S = CurModule.NamedTypeSigns[S.getName()];
724 }
725 Signedness Result;
726 Result.makeComposite(S);
727 return Result;
728}
729
730/// This function just translates a ConstantInfo into a ValueInfo and calls
731/// getElementSign(ValueInfo,...). Its just a convenience.
732/// @brief ConstantInfo version of getElementSign.
733static Signedness getElementSign(const ConstInfo& CI,
734 const std::vector<Constant*> &Indices) {
735 ValueInfo VI;
736 VI.V = CI.C;
737 VI.S.copy(CI.S);
738 std::vector<Value*> Idx;
739 for (unsigned i = 0; i < Indices.size(); ++i)
740 Idx.push_back(Indices[i]);
741 Signedness result = getElementSign(VI, Idx);
742 VI.destroy();
743 return result;
744}
Reid Spencer950bf602007-01-26 08:19:09 +0000745
746// getExistingValue - Look up the value specified by the provided type and
747// the provided ValID. If the value exists and has already been defined, return
748// it. Otherwise return null.
749//
750static Value *getExistingValue(const Type *Ty, const ValID &D) {
751 if (isa<FunctionType>(Ty)) {
752 error("Functions are not values and must be referenced as pointers");
753 }
754
755 switch (D.Type) {
756 case ValID::NumberVal: { // Is it a numbered definition?
757 unsigned Num = (unsigned)D.Num;
758
759 // Module constants occupy the lowest numbered slots...
760 std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
761 if (VI != CurModule.Values.end()) {
762 if (Num < VI->second.size())
763 return VI->second[Num];
764 Num -= VI->second.size();
765 }
766
767 // Make sure that our type is within bounds
768 VI = CurFun.Values.find(Ty);
769 if (VI == CurFun.Values.end()) return 0;
770
771 // Check that the number is within bounds...
772 if (VI->second.size() <= Num) return 0;
773
774 return VI->second[Num];
775 }
776
777 case ValID::NameVal: { // Is it a named definition?
778 // Get the name out of the ID
Reid Spencerbb1fd572007-03-21 17:15:50 +0000779 RenameMapKey Key = makeRenameMapKey(D.Name, Ty, D.S);
780 Value *V = 0;
Reid Spencer950bf602007-01-26 08:19:09 +0000781 if (inFunctionScope()) {
782 // See if the name was renamed
783 RenameMapType::const_iterator I = CurFun.RenameMap.find(Key);
784 std::string LookupName;
785 if (I != CurFun.RenameMap.end())
786 LookupName = I->second;
787 else
Reid Spencerbb1fd572007-03-21 17:15:50 +0000788 LookupName = D.Name;
Reid Spenceref9b9a72007-02-05 20:47:22 +0000789 ValueSymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable();
790 V = SymTab.lookup(LookupName);
Reid Spencerbb1fd572007-03-21 17:15:50 +0000791 if (V && V->getType() != Ty)
Duncan Sandsdc024672007-11-27 13:23:08 +0000792 V = 0;
Reid Spencer950bf602007-01-26 08:19:09 +0000793 }
794 if (!V) {
795 RenameMapType::const_iterator I = CurModule.RenameMap.find(Key);
796 std::string LookupName;
797 if (I != CurModule.RenameMap.end())
798 LookupName = I->second;
799 else
Reid Spencerbb1fd572007-03-21 17:15:50 +0000800 LookupName = D.Name;
Reid Spenceref9b9a72007-02-05 20:47:22 +0000801 V = CurModule.CurrentModule->getValueSymbolTable().lookup(LookupName);
Reid Spencerbb1fd572007-03-21 17:15:50 +0000802 if (V && V->getType() != Ty)
Duncan Sandsdc024672007-11-27 13:23:08 +0000803 V = 0;
Reid Spencer950bf602007-01-26 08:19:09 +0000804 }
Reid Spenceref9b9a72007-02-05 20:47:22 +0000805 if (!V)
Reid Spencer950bf602007-01-26 08:19:09 +0000806 return 0;
807
808 D.destroy(); // Free old strdup'd memory...
809 return V;
810 }
811
812 // Check to make sure that "Ty" is an integral type, and that our
813 // value will fit into the specified type...
814 case ValID::ConstSIntVal: // Is it a constant pool reference??
815 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
816 error("Signed integral constant '" + itostr(D.ConstPool64) +
817 "' is invalid for type '" + Ty->getDescription() + "'");
818 }
819 return ConstantInt::get(Ty, D.ConstPool64);
820
821 case ValID::ConstUIntVal: // Is it an unsigned const pool reference?
822 if (!ConstantInt::isValueValidForType(Ty, D.UConstPool64)) {
823 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64))
824 error("Integral constant '" + utostr(D.UConstPool64) +
825 "' is invalid or out of range");
826 else // This is really a signed reference. Transmogrify.
827 return ConstantInt::get(Ty, D.ConstPool64);
828 } else
829 return ConstantInt::get(Ty, D.UConstPool64);
830
831 case ValID::ConstFPVal: // Is it a floating point const pool reference?
Dale Johannesencdd509a2007-09-07 21:07:57 +0000832 if (!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP))
Reid Spencer950bf602007-01-26 08:19:09 +0000833 error("FP constant invalid for type");
Dale Johannesencdd509a2007-09-07 21:07:57 +0000834 // Lexer has no type info, so builds all FP constants as double.
835 // Fix this here.
836 if (Ty==Type::FloatTy)
837 D.ConstPoolFP->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
838 return ConstantFP::get(Ty, *D.ConstPoolFP);
Reid Spencer950bf602007-01-26 08:19:09 +0000839
840 case ValID::ConstNullVal: // Is it a null value?
841 if (!isa<PointerType>(Ty))
842 error("Cannot create a a non pointer null");
843 return ConstantPointerNull::get(cast<PointerType>(Ty));
844
845 case ValID::ConstUndefVal: // Is it an undef value?
846 return UndefValue::get(Ty);
847
848 case ValID::ConstZeroVal: // Is it a zero value?
849 return Constant::getNullValue(Ty);
850
851 case ValID::ConstantVal: // Fully resolved constant?
852 if (D.ConstantValue->getType() != Ty)
853 error("Constant expression type different from required type");
854 return D.ConstantValue;
855
856 case ValID::InlineAsmVal: { // Inline asm expression
857 const PointerType *PTy = dyn_cast<PointerType>(Ty);
858 const FunctionType *FTy =
859 PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
860 if (!FTy || !InlineAsm::Verify(FTy, D.IAD->Constraints))
861 error("Invalid type for asm constraint string");
862 InlineAsm *IA = InlineAsm::get(FTy, D.IAD->AsmString, D.IAD->Constraints,
863 D.IAD->HasSideEffects);
864 D.destroy(); // Free InlineAsmDescriptor.
865 return IA;
866 }
867 default:
868 assert(0 && "Unhandled case");
869 return 0;
870 } // End of switch
871
872 assert(0 && "Unhandled case");
873 return 0;
874}
875
876// getVal - This function is identical to getExistingValue, except that if a
877// value is not already defined, it "improvises" by creating a placeholder var
878// that looks and acts just like the requested variable. When the value is
879// defined later, all uses of the placeholder variable are replaced with the
880// real thing.
881//
882static Value *getVal(const Type *Ty, const ValID &ID) {
883 if (Ty == Type::LabelTy)
884 error("Cannot use a basic block here");
885
886 // See if the value has already been defined.
887 Value *V = getExistingValue(Ty, ID);
888 if (V) return V;
889
890 if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty))
891 error("Invalid use of a composite type");
892
893 // If we reached here, we referenced either a symbol that we don't know about
894 // or an id number that hasn't been read yet. We may be referencing something
895 // forward, so just create an entry to be resolved later and get to it...
Reid Spencer950bf602007-01-26 08:19:09 +0000896 V = new Argument(Ty);
897
898 // Remember where this forward reference came from. FIXME, shouldn't we try
899 // to recycle these things??
900 CurModule.PlaceHolderInfo.insert(
Reid Spenceref9b9a72007-02-05 20:47:22 +0000901 std::make_pair(V, std::make_pair(ID, Upgradelineno)));
Reid Spencer950bf602007-01-26 08:19:09 +0000902
903 if (inFunctionScope())
904 InsertValue(V, CurFun.LateResolveValues);
905 else
906 InsertValue(V, CurModule.LateResolveValues);
907 return V;
908}
909
Reid Spencered96d1e2007-02-08 09:08:52 +0000910/// @brief This just makes any name given to it unique, up to MAX_UINT times.
911static std::string makeNameUnique(const std::string& Name) {
912 static unsigned UniqueNameCounter = 1;
913 std::string Result(Name);
914 Result += ".upgrd." + llvm::utostr(UniqueNameCounter++);
915 return Result;
916}
917
Reid Spencer950bf602007-01-26 08:19:09 +0000918/// getBBVal - This is used for two purposes:
919/// * If isDefinition is true, a new basic block with the specified ID is being
920/// defined.
921/// * If isDefinition is true, this is a reference to a basic block, which may
922/// or may not be a forward reference.
923///
924static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
925 assert(inFunctionScope() && "Can't get basic block at global scope");
926
927 std::string Name;
928 BasicBlock *BB = 0;
929 switch (ID.Type) {
930 default:
931 error("Illegal label reference " + ID.getName());
932 break;
933 case ValID::NumberVal: // Is it a numbered definition?
934 if (unsigned(ID.Num) >= CurFun.NumberedBlocks.size())
935 CurFun.NumberedBlocks.resize(ID.Num+1);
936 BB = CurFun.NumberedBlocks[ID.Num];
937 break;
938 case ValID::NameVal: // Is it a named definition?
939 Name = ID.Name;
Reid Spencerbb1fd572007-03-21 17:15:50 +0000940 if (Value *N = CurFun.CurrentFunction->getValueSymbolTable().lookup(Name)) {
Reid Spencered96d1e2007-02-08 09:08:52 +0000941 if (N->getType() != Type::LabelTy) {
942 // Register names didn't use to conflict with basic block names
943 // because of type planes. Now they all have to be unique. So, we just
944 // rename the register and treat this name as if no basic block
945 // had been found.
Reid Spencerbb1fd572007-03-21 17:15:50 +0000946 RenameMapKey Key = makeRenameMapKey(ID.Name, N->getType(), ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +0000947 N->setName(makeNameUnique(N->getName()));
948 CurModule.RenameMap[Key] = N->getName();
949 BB = 0;
950 } else {
951 BB = cast<BasicBlock>(N);
952 }
Reid Spencer950bf602007-01-26 08:19:09 +0000953 }
954 break;
955 }
956
957 // See if the block has already been defined.
958 if (BB) {
959 // If this is the definition of the block, make sure the existing value was
960 // just a forward reference. If it was a forward reference, there will be
961 // an entry for it in the PlaceHolderInfo map.
962 if (isDefinition && !CurFun.BBForwardRefs.erase(BB))
963 // The existing value was a definition, not a forward reference.
964 error("Redefinition of label " + ID.getName());
965
966 ID.destroy(); // Free strdup'd memory.
967 return BB;
968 }
969
970 // Otherwise this block has not been seen before.
971 BB = new BasicBlock("", CurFun.CurrentFunction);
972 if (ID.Type == ValID::NameVal) {
973 BB->setName(ID.Name);
974 } else {
975 CurFun.NumberedBlocks[ID.Num] = BB;
976 }
977
978 // If this is not a definition, keep track of it so we can use it as a forward
979 // reference.
980 if (!isDefinition) {
981 // Remember where this forward reference came from.
982 CurFun.BBForwardRefs[BB] = std::make_pair(ID, Upgradelineno);
983 } else {
984 // The forward declaration could have been inserted anywhere in the
985 // function: insert it into the correct place now.
986 CurFun.CurrentFunction->getBasicBlockList().remove(BB);
987 CurFun.CurrentFunction->getBasicBlockList().push_back(BB);
988 }
989 ID.destroy();
990 return BB;
991}
992
993
994//===----------------------------------------------------------------------===//
995// Code to handle forward references in instructions
996//===----------------------------------------------------------------------===//
997//
998// This code handles the late binding needed with statements that reference
999// values not defined yet... for example, a forward branch, or the PHI node for
1000// a loop body.
1001//
1002// This keeps a table (CurFun.LateResolveValues) of all such forward references
1003// and back patchs after we are done.
1004//
1005
1006// ResolveDefinitions - If we could not resolve some defs at parsing
1007// time (forward branches, phi functions for loops, etc...) resolve the
1008// defs now...
1009//
1010static void
1011ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
1012 std::map<const Type*,ValueList> *FutureLateResolvers) {
Reid Spencered96d1e2007-02-08 09:08:52 +00001013
Reid Spencer950bf602007-01-26 08:19:09 +00001014 // Loop over LateResolveDefs fixing up stuff that couldn't be resolved
1015 for (std::map<const Type*,ValueList>::iterator LRI = LateResolvers.begin(),
1016 E = LateResolvers.end(); LRI != E; ++LRI) {
Reid Spencered96d1e2007-02-08 09:08:52 +00001017 const Type* Ty = LRI->first;
Reid Spencer950bf602007-01-26 08:19:09 +00001018 ValueList &List = LRI->second;
1019 while (!List.empty()) {
1020 Value *V = List.back();
1021 List.pop_back();
1022
1023 std::map<Value*, std::pair<ValID, int> >::iterator PHI =
1024 CurModule.PlaceHolderInfo.find(V);
1025 assert(PHI != CurModule.PlaceHolderInfo.end() && "Placeholder error");
1026
1027 ValID &DID = PHI->second.first;
1028
Reid Spencered96d1e2007-02-08 09:08:52 +00001029 Value *TheRealValue = getExistingValue(Ty, DID);
Reid Spencer950bf602007-01-26 08:19:09 +00001030 if (TheRealValue) {
1031 V->replaceAllUsesWith(TheRealValue);
1032 delete V;
1033 CurModule.PlaceHolderInfo.erase(PHI);
1034 } else if (FutureLateResolvers) {
1035 // Functions have their unresolved items forwarded to the module late
1036 // resolver table
1037 InsertValue(V, *FutureLateResolvers);
1038 } else {
1039 if (DID.Type == ValID::NameVal) {
Reid Spencered96d1e2007-02-08 09:08:52 +00001040 error("Reference to an invalid definition: '" + DID.getName() +
1041 "' of type '" + V->getType()->getDescription() + "'",
1042 PHI->second.second);
Reid Spencer7de2e012007-01-29 19:08:46 +00001043 return;
Reid Spencer950bf602007-01-26 08:19:09 +00001044 } else {
1045 error("Reference to an invalid definition: #" +
1046 itostr(DID.Num) + " of type '" +
1047 V->getType()->getDescription() + "'", PHI->second.second);
1048 return;
1049 }
1050 }
1051 }
1052 }
1053
1054 LateResolvers.clear();
1055}
1056
Reid Spencerbb1fd572007-03-21 17:15:50 +00001057/// This function is used for type resolution and upref handling. When a type
1058/// becomes concrete, this function is called to adjust the signedness for the
1059/// concrete type.
1060static void ResolveTypeSign(const Type* oldTy, const Signedness &Sign) {
1061 std::string TyName = CurModule.CurrentModule->getTypeName(oldTy);
1062 if (!TyName.empty())
1063 CurModule.NamedTypeSigns[TyName] = Sign;
1064}
1065
1066/// ResolveTypeTo - A brand new type was just declared. This means that (if
1067/// name is not null) things referencing Name can be resolved. Otherwise,
1068/// things refering to the number can be resolved. Do this now.
1069static void ResolveTypeTo(char *Name, const Type *ToTy, const Signedness& Sign){
Reid Spencer950bf602007-01-26 08:19:09 +00001070 ValID D;
Reid Spencerbb1fd572007-03-21 17:15:50 +00001071 if (Name)
1072 D = ValID::create(Name);
1073 else
1074 D = ValID::create((int)CurModule.Types.size());
1075 D.S.copy(Sign);
1076
Reid Spencerbaba98a2007-04-11 12:10:58 +00001077 if (Name)
1078 CurModule.NamedTypeSigns[Name] = Sign;
Reid Spencer950bf602007-01-26 08:19:09 +00001079
1080 std::map<ValID, PATypeHolder>::iterator I =
1081 CurModule.LateResolveTypes.find(D);
1082 if (I != CurModule.LateResolveTypes.end()) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00001083 const Type *OldTy = I->second.get();
1084 ((DerivedType*)OldTy)->refineAbstractTypeTo(ToTy);
Reid Spencer950bf602007-01-26 08:19:09 +00001085 CurModule.LateResolveTypes.erase(I);
1086 }
1087}
1088
Anton Korobeynikovce13b852007-01-28 15:25:24 +00001089/// This is the implementation portion of TypeHasInteger. It traverses the
1090/// type given, avoiding recursive types, and returns true as soon as it finds
1091/// an integer type. If no integer type is found, it returns false.
1092static bool TypeHasIntegerI(const Type *Ty, std::vector<const Type*> Stack) {
1093 // Handle some easy cases
1094 if (Ty->isPrimitiveType() || (Ty->getTypeID() == Type::OpaqueTyID))
1095 return false;
1096 if (Ty->isInteger())
1097 return true;
1098 if (const SequentialType *STy = dyn_cast<SequentialType>(Ty))
1099 return STy->getElementType()->isInteger();
1100
1101 // Avoid type structure recursion
1102 for (std::vector<const Type*>::iterator I = Stack.begin(), E = Stack.end();
1103 I != E; ++I)
1104 if (Ty == *I)
1105 return false;
1106
1107 // Push us on the type stack
1108 Stack.push_back(Ty);
1109
1110 if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
1111 if (TypeHasIntegerI(FTy->getReturnType(), Stack))
1112 return true;
1113 FunctionType::param_iterator I = FTy->param_begin();
1114 FunctionType::param_iterator E = FTy->param_end();
1115 for (; I != E; ++I)
1116 if (TypeHasIntegerI(*I, Stack))
1117 return true;
1118 return false;
1119 } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
1120 StructType::element_iterator I = STy->element_begin();
1121 StructType::element_iterator E = STy->element_end();
1122 for (; I != E; ++I) {
1123 if (TypeHasIntegerI(*I, Stack))
1124 return true;
1125 }
1126 return false;
1127 }
1128 // There shouldn't be anything else, but its definitely not integer
1129 assert(0 && "What type is this?");
1130 return false;
1131}
1132
1133/// This is the interface to TypeHasIntegerI. It just provides the type stack,
1134/// to avoid recursion, and then calls TypeHasIntegerI.
1135static inline bool TypeHasInteger(const Type *Ty) {
1136 std::vector<const Type*> TyStack;
1137 return TypeHasIntegerI(Ty, TyStack);
1138}
1139
Reid Spencer950bf602007-01-26 08:19:09 +00001140// setValueName - Set the specified value to the name given. The name may be
1141// null potentially, in which case this is a noop. The string passed in is
1142// assumed to be a malloc'd string buffer, and is free'd by this function.
1143//
Reid Spencerbb1fd572007-03-21 17:15:50 +00001144static void setValueName(const ValueInfo &V, char *NameStr) {
Reid Spencer950bf602007-01-26 08:19:09 +00001145 if (NameStr) {
1146 std::string Name(NameStr); // Copy string
1147 free(NameStr); // Free old string
1148
Reid Spencerbb1fd572007-03-21 17:15:50 +00001149 if (V.V->getType() == Type::VoidTy) {
Reid Spencer950bf602007-01-26 08:19:09 +00001150 error("Can't assign name '" + Name + "' to value with void type");
1151 return;
1152 }
1153
Reid Spencer950bf602007-01-26 08:19:09 +00001154 assert(inFunctionScope() && "Must be in function scope");
1155
1156 // Search the function's symbol table for an existing value of this name
Reid Spenceref9b9a72007-02-05 20:47:22 +00001157 ValueSymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
1158 Value* Existing = ST.lookup(Name);
Reid Spencer950bf602007-01-26 08:19:09 +00001159 if (Existing) {
Anton Korobeynikovce13b852007-01-28 15:25:24 +00001160 // An existing value of the same name was found. This might have happened
1161 // because of the integer type planes collapsing in LLVM 2.0.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001162 if (Existing->getType() == V.V->getType() &&
Anton Korobeynikovce13b852007-01-28 15:25:24 +00001163 !TypeHasInteger(Existing->getType())) {
1164 // If the type does not contain any integers in them then this can't be
1165 // a type plane collapsing issue. It truly is a redefinition and we
1166 // should error out as the assembly is invalid.
1167 error("Redefinition of value named '" + Name + "' of type '" +
Reid Spencerbb1fd572007-03-21 17:15:50 +00001168 V.V->getType()->getDescription() + "'");
Anton Korobeynikovce13b852007-01-28 15:25:24 +00001169 return;
Reid Spencer950bf602007-01-26 08:19:09 +00001170 }
1171 // In LLVM 2.0 we don't allow names to be re-used for any values in a
1172 // function, regardless of Type. Previously re-use of names was okay as
1173 // long as they were distinct types. With type planes collapsing because
1174 // of the signedness change and because of PR411, this can no longer be
1175 // supported. We must search the entire symbol table for a conflicting
1176 // name and make the name unique. No warning is needed as this can't
1177 // cause a problem.
1178 std::string NewName = makeNameUnique(Name);
1179 // We're changing the name but it will probably be used by other
1180 // instructions as operands later on. Consequently we have to retain
1181 // a mapping of the renaming that we're doing.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001182 RenameMapKey Key = makeRenameMapKey(Name, V.V->getType(), V.S);
Reid Spencer950bf602007-01-26 08:19:09 +00001183 CurFun.RenameMap[Key] = NewName;
1184 Name = NewName;
1185 }
1186
1187 // Set the name.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001188 V.V->setName(Name);
Reid Spencer950bf602007-01-26 08:19:09 +00001189 }
1190}
1191
1192/// ParseGlobalVariable - Handle parsing of a global. If Initializer is null,
1193/// this is a declaration, otherwise it is a definition.
1194static GlobalVariable *
1195ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
1196 bool isConstantGlobal, const Type *Ty,
Reid Spencerbb1fd572007-03-21 17:15:50 +00001197 Constant *Initializer,
1198 const Signedness &Sign) {
Reid Spencer950bf602007-01-26 08:19:09 +00001199 if (isa<FunctionType>(Ty))
1200 error("Cannot declare global vars of function type");
1201
Christopher Lamb4374f8e2007-12-17 01:17:35 +00001202 const PointerType *PTy = PointerType::getUnqual(Ty);
Reid Spencer950bf602007-01-26 08:19:09 +00001203
1204 std::string Name;
1205 if (NameStr) {
1206 Name = NameStr; // Copy string
1207 free(NameStr); // Free old string
1208 }
1209
1210 // See if this global value was forward referenced. If so, recycle the
1211 // object.
1212 ValID ID;
1213 if (!Name.empty()) {
Reid Spencer5eb77c72007-03-15 03:26:42 +00001214 ID = ValID::create((char*)Name.c_str());
Reid Spencer950bf602007-01-26 08:19:09 +00001215 } else {
Reid Spencer5eb77c72007-03-15 03:26:42 +00001216 ID = ValID::create((int)CurModule.Values[PTy].size());
Reid Spencer950bf602007-01-26 08:19:09 +00001217 }
Reid Spencerbb1fd572007-03-21 17:15:50 +00001218 ID.S.makeComposite(Sign);
Reid Spencer950bf602007-01-26 08:19:09 +00001219
1220 if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) {
1221 // Move the global to the end of the list, from whereever it was
1222 // previously inserted.
1223 GlobalVariable *GV = cast<GlobalVariable>(FWGV);
1224 CurModule.CurrentModule->getGlobalList().remove(GV);
1225 CurModule.CurrentModule->getGlobalList().push_back(GV);
1226 GV->setInitializer(Initializer);
1227 GV->setLinkage(Linkage);
1228 GV->setConstant(isConstantGlobal);
1229 InsertValue(GV, CurModule.Values);
1230 return GV;
1231 }
1232
1233 // If this global has a name, check to see if there is already a definition
1234 // of this global in the module and emit warnings if there are conflicts.
1235 if (!Name.empty()) {
1236 // The global has a name. See if there's an existing one of the same name.
Reid Spencere59f4932007-04-16 03:05:01 +00001237 if (CurModule.CurrentModule->getNamedGlobal(Name) ||
1238 CurModule.CurrentModule->getFunction(Name)) {
1239 // We found an existing global of the same name. This isn't allowed
Reid Spencer950bf602007-01-26 08:19:09 +00001240 // in LLVM 2.0. Consequently, we must alter the name of the global so it
1241 // can at least compile. This can happen because of type planes
1242 // There is alread a global of the same name which means there is a
1243 // conflict. Let's see what we can do about it.
1244 std::string NewName(makeNameUnique(Name));
Reid Spencerbb1fd572007-03-21 17:15:50 +00001245 if (Linkage != GlobalValue::InternalLinkage) {
Reid Spencer950bf602007-01-26 08:19:09 +00001246 // The linkage of this gval is external so we can't reliably rename
1247 // it because it could potentially create a linking problem.
1248 // However, we can't leave the name conflict in the output either or
1249 // it won't assemble with LLVM 2.0. So, all we can do is rename
1250 // this one to something unique and emit a warning about the problem.
1251 warning("Renaming global variable '" + Name + "' to '" + NewName +
1252 "' may cause linkage errors");
1253 }
1254
1255 // Put the renaming in the global rename map
Christopher Lamb4374f8e2007-12-17 01:17:35 +00001256 RenameMapKey Key =
1257 makeRenameMapKey(Name, PointerType::getUnqual(Ty), ID.S);
Reid Spencer950bf602007-01-26 08:19:09 +00001258 CurModule.RenameMap[Key] = NewName;
1259
1260 // Rename it
1261 Name = NewName;
1262 }
1263 }
1264
1265 // Otherwise there is no existing GV to use, create one now.
1266 GlobalVariable *GV =
1267 new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name,
1268 CurModule.CurrentModule);
1269 InsertValue(GV, CurModule.Values);
Reid Spencerbb1fd572007-03-21 17:15:50 +00001270 // Remember the sign of this global.
1271 CurModule.NamedValueSigns[Name] = ID.S;
Reid Spencer950bf602007-01-26 08:19:09 +00001272 return GV;
1273}
1274
1275// setTypeName - Set the specified type to the name given. The name may be
1276// null potentially, in which case this is a noop. The string passed in is
1277// assumed to be a malloc'd string buffer, and is freed by this function.
1278//
1279// This function returns true if the type has already been defined, but is
1280// allowed to be redefined in the specified context. If the name is a new name
1281// for the type plane, it is inserted and false is returned.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001282static bool setTypeName(const PATypeInfo& TI, char *NameStr) {
Reid Spencer950bf602007-01-26 08:19:09 +00001283 assert(!inFunctionScope() && "Can't give types function-local names");
1284 if (NameStr == 0) return false;
1285
1286 std::string Name(NameStr); // Copy string
1287 free(NameStr); // Free old string
1288
Reid Spencerbb1fd572007-03-21 17:15:50 +00001289 const Type* Ty = TI.PAT->get();
1290
Reid Spencer950bf602007-01-26 08:19:09 +00001291 // We don't allow assigning names to void type
Reid Spencerbb1fd572007-03-21 17:15:50 +00001292 if (Ty == Type::VoidTy) {
Reid Spencer950bf602007-01-26 08:19:09 +00001293 error("Can't assign name '" + Name + "' to the void type");
1294 return false;
1295 }
1296
1297 // Set the type name, checking for conflicts as we do so.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001298 bool AlreadyExists = CurModule.CurrentModule->addTypeName(Name, Ty);
1299
1300 // Save the sign information for later use
1301 CurModule.NamedTypeSigns[Name] = TI.S;
Reid Spencer950bf602007-01-26 08:19:09 +00001302
1303 if (AlreadyExists) { // Inserting a name that is already defined???
1304 const Type *Existing = CurModule.CurrentModule->getTypeByName(Name);
1305 assert(Existing && "Conflict but no matching type?");
1306
1307 // There is only one case where this is allowed: when we are refining an
1308 // opaque type. In this case, Existing will be an opaque type.
1309 if (const OpaqueType *OpTy = dyn_cast<OpaqueType>(Existing)) {
1310 // We ARE replacing an opaque type!
Reid Spencerbb1fd572007-03-21 17:15:50 +00001311 const_cast<OpaqueType*>(OpTy)->refineAbstractTypeTo(Ty);
Reid Spencer950bf602007-01-26 08:19:09 +00001312 return true;
1313 }
1314
1315 // Otherwise, this is an attempt to redefine a type. That's okay if
1316 // the redefinition is identical to the original. This will be so if
1317 // Existing and T point to the same Type object. In this one case we
1318 // allow the equivalent redefinition.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001319 if (Existing == Ty) return true; // Yes, it's equal.
Reid Spencer950bf602007-01-26 08:19:09 +00001320
1321 // Any other kind of (non-equivalent) redefinition is an error.
1322 error("Redefinition of type named '" + Name + "' in the '" +
Reid Spencerbb1fd572007-03-21 17:15:50 +00001323 Ty->getDescription() + "' type plane");
Reid Spencer950bf602007-01-26 08:19:09 +00001324 }
1325
1326 return false;
1327}
1328
1329//===----------------------------------------------------------------------===//
1330// Code for handling upreferences in type names...
1331//
1332
1333// TypeContains - Returns true if Ty directly contains E in it.
1334//
1335static bool TypeContains(const Type *Ty, const Type *E) {
1336 return std::find(Ty->subtype_begin(), Ty->subtype_end(),
1337 E) != Ty->subtype_end();
1338}
1339
1340namespace {
1341 struct UpRefRecord {
1342 // NestingLevel - The number of nesting levels that need to be popped before
1343 // this type is resolved.
1344 unsigned NestingLevel;
1345
1346 // LastContainedTy - This is the type at the current binding level for the
1347 // type. Every time we reduce the nesting level, this gets updated.
1348 const Type *LastContainedTy;
1349
1350 // UpRefTy - This is the actual opaque type that the upreference is
1351 // represented with.
1352 OpaqueType *UpRefTy;
1353
1354 UpRefRecord(unsigned NL, OpaqueType *URTy)
Reid Spencerbb1fd572007-03-21 17:15:50 +00001355 : NestingLevel(NL), LastContainedTy(URTy), UpRefTy(URTy) { }
Reid Spencer950bf602007-01-26 08:19:09 +00001356 };
1357}
1358
1359// UpRefs - A list of the outstanding upreferences that need to be resolved.
1360static std::vector<UpRefRecord> UpRefs;
1361
1362/// HandleUpRefs - Every time we finish a new layer of types, this function is
1363/// called. It loops through the UpRefs vector, which is a list of the
1364/// currently active types. For each type, if the up reference is contained in
1365/// the newly completed type, we decrement the level count. When the level
1366/// count reaches zero, the upreferenced type is the type that is passed in:
1367/// thus we can complete the cycle.
1368///
Reid Spencerbb1fd572007-03-21 17:15:50 +00001369static PATypeHolder HandleUpRefs(const Type *ty, const Signedness& Sign) {
Reid Spencer950bf602007-01-26 08:19:09 +00001370 // If Ty isn't abstract, or if there are no up-references in it, then there is
1371 // nothing to resolve here.
1372 if (!ty->isAbstract() || UpRefs.empty()) return ty;
1373
1374 PATypeHolder Ty(ty);
1375 UR_OUT("Type '" << Ty->getDescription() <<
1376 "' newly formed. Resolving upreferences.\n" <<
1377 UpRefs.size() << " upreferences active!\n");
1378
1379 // If we find any resolvable upreferences (i.e., those whose NestingLevel goes
1380 // to zero), we resolve them all together before we resolve them to Ty. At
1381 // the end of the loop, if there is anything to resolve to Ty, it will be in
1382 // this variable.
1383 OpaqueType *TypeToResolve = 0;
1384
Reid Spencerbb1fd572007-03-21 17:15:50 +00001385 unsigned i = 0;
1386 for (; i != UpRefs.size(); ++i) {
Reid Spencer950bf602007-01-26 08:19:09 +00001387 UR_OUT(" UR#" << i << " - TypeContains(" << Ty->getDescription() << ", "
Reid Spencerbb1fd572007-03-21 17:15:50 +00001388 << UpRefs[i].UpRefTy->getDescription() << ") = "
1389 << (TypeContains(Ty, UpRefs[i].UpRefTy) ? "true" : "false") << "\n");
Reid Spencer950bf602007-01-26 08:19:09 +00001390 if (TypeContains(Ty, UpRefs[i].LastContainedTy)) {
1391 // Decrement level of upreference
1392 unsigned Level = --UpRefs[i].NestingLevel;
1393 UpRefs[i].LastContainedTy = Ty;
1394 UR_OUT(" Uplevel Ref Level = " << Level << "\n");
1395 if (Level == 0) { // Upreference should be resolved!
1396 if (!TypeToResolve) {
1397 TypeToResolve = UpRefs[i].UpRefTy;
1398 } else {
1399 UR_OUT(" * Resolving upreference for "
Reid Spencerbb1fd572007-03-21 17:15:50 +00001400 << UpRefs[i].UpRefTy->getDescription() << "\n";
1401 std::string OldName = UpRefs[i].UpRefTy->getDescription());
1402 ResolveTypeSign(UpRefs[i].UpRefTy, Sign);
Reid Spencer950bf602007-01-26 08:19:09 +00001403 UpRefs[i].UpRefTy->refineAbstractTypeTo(TypeToResolve);
1404 UR_OUT(" * Type '" << OldName << "' refined upreference to: "
1405 << (const void*)Ty << ", " << Ty->getDescription() << "\n");
1406 }
1407 UpRefs.erase(UpRefs.begin()+i); // Remove from upreference list...
1408 --i; // Do not skip the next element...
1409 }
1410 }
1411 }
1412
1413 if (TypeToResolve) {
1414 UR_OUT(" * Resolving upreference for "
Reid Spencerbb1fd572007-03-21 17:15:50 +00001415 << UpRefs[i].UpRefTy->getDescription() << "\n";
Reid Spencer950bf602007-01-26 08:19:09 +00001416 std::string OldName = TypeToResolve->getDescription());
Reid Spencerbb1fd572007-03-21 17:15:50 +00001417 ResolveTypeSign(TypeToResolve, Sign);
Reid Spencer950bf602007-01-26 08:19:09 +00001418 TypeToResolve->refineAbstractTypeTo(Ty);
1419 }
1420
1421 return Ty;
1422}
1423
Reid Spencerbb1fd572007-03-21 17:15:50 +00001424bool Signedness::operator<(const Signedness &that) const {
1425 if (isNamed()) {
1426 if (that.isNamed())
1427 return *(this->name) < *(that.name);
1428 else
1429 return CurModule.NamedTypeSigns[*name] < that;
1430 } else if (that.isNamed()) {
1431 return *this < CurModule.NamedTypeSigns[*that.name];
1432 }
1433
1434 if (isComposite() && that.isComposite()) {
1435 if (sv->size() == that.sv->size()) {
1436 SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1437 SignVector::const_iterator thatI = that.sv->begin(),
1438 thatE = that.sv->end();
1439 for (; thisI != thisE; ++thisI, ++thatI) {
1440 if (*thisI < *thatI)
1441 return true;
1442 else if (!(*thisI == *thatI))
1443 return false;
1444 }
1445 return false;
1446 }
1447 return sv->size() < that.sv->size();
1448 }
1449 return kind < that.kind;
1450}
1451
1452bool Signedness::operator==(const Signedness &that) const {
1453 if (isNamed())
1454 if (that.isNamed())
1455 return *(this->name) == *(that.name);
1456 else
1457 return CurModule.NamedTypeSigns[*(this->name)] == that;
1458 else if (that.isNamed())
1459 return *this == CurModule.NamedTypeSigns[*(that.name)];
1460 if (isComposite() && that.isComposite()) {
1461 if (sv->size() == that.sv->size()) {
1462 SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1463 SignVector::const_iterator thatI = that.sv->begin(),
1464 thatE = that.sv->end();
1465 for (; thisI != thisE; ++thisI, ++thatI) {
1466 if (!(*thisI == *thatI))
1467 return false;
1468 }
1469 return true;
1470 }
1471 return false;
1472 }
1473 return kind == that.kind;
1474}
1475
1476void Signedness::copy(const Signedness &that) {
1477 if (that.isNamed()) {
1478 kind = Named;
1479 name = new std::string(*that.name);
1480 } else if (that.isComposite()) {
1481 kind = Composite;
1482 sv = new SignVector();
1483 *sv = *that.sv;
1484 } else {
1485 kind = that.kind;
1486 sv = 0;
1487 }
1488}
1489
1490void Signedness::destroy() {
1491 if (isNamed()) {
1492 delete name;
1493 } else if (isComposite()) {
1494 delete sv;
1495 }
1496}
1497
Evan Cheng2b484202007-03-22 07:43:51 +00001498#ifndef NDEBUG
Reid Spencerbb1fd572007-03-21 17:15:50 +00001499void Signedness::dump() const {
1500 if (isComposite()) {
1501 if (sv->size() == 1) {
1502 (*sv)[0].dump();
1503 std::cerr << "*";
1504 } else {
1505 std::cerr << "{ " ;
1506 for (unsigned i = 0; i < sv->size(); ++i) {
1507 if (i != 0)
1508 std::cerr << ", ";
1509 (*sv)[i].dump();
1510 }
1511 std::cerr << "} " ;
1512 }
1513 } else if (isNamed()) {
1514 std::cerr << *name;
1515 } else if (isSigned()) {
1516 std::cerr << "S";
1517 } else if (isUnsigned()) {
1518 std::cerr << "U";
1519 } else
1520 std::cerr << ".";
1521}
Evan Cheng2b484202007-03-22 07:43:51 +00001522#endif
Reid Spencerbb1fd572007-03-21 17:15:50 +00001523
Reid Spencer950bf602007-01-26 08:19:09 +00001524static inline Instruction::TermOps
1525getTermOp(TermOps op) {
1526 switch (op) {
1527 default : assert(0 && "Invalid OldTermOp");
1528 case RetOp : return Instruction::Ret;
1529 case BrOp : return Instruction::Br;
1530 case SwitchOp : return Instruction::Switch;
1531 case InvokeOp : return Instruction::Invoke;
1532 case UnwindOp : return Instruction::Unwind;
1533 case UnreachableOp: return Instruction::Unreachable;
1534 }
1535}
1536
1537static inline Instruction::BinaryOps
Reid Spencerbb1fd572007-03-21 17:15:50 +00001538getBinaryOp(BinaryOps op, const Type *Ty, const Signedness& Sign) {
Reid Spencer950bf602007-01-26 08:19:09 +00001539 switch (op) {
1540 default : assert(0 && "Invalid OldBinaryOps");
1541 case SetEQ :
1542 case SetNE :
1543 case SetLE :
1544 case SetGE :
1545 case SetLT :
1546 case SetGT : assert(0 && "Should use getCompareOp");
1547 case AddOp : return Instruction::Add;
1548 case SubOp : return Instruction::Sub;
1549 case MulOp : return Instruction::Mul;
1550 case DivOp : {
1551 // This is an obsolete instruction so we must upgrade it based on the
1552 // types of its operands.
1553 bool isFP = Ty->isFloatingPoint();
Reid Spencer9d6565a2007-02-15 02:26:10 +00001554 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
Chris Lattner4227bdb2007-02-19 07:34:02 +00001555 // If its a vector type we want to use the element type
Reid Spencer950bf602007-01-26 08:19:09 +00001556 isFP = PTy->getElementType()->isFloatingPoint();
1557 if (isFP)
1558 return Instruction::FDiv;
Reid Spencerbb1fd572007-03-21 17:15:50 +00001559 else if (Sign.isSigned())
Reid Spencer950bf602007-01-26 08:19:09 +00001560 return Instruction::SDiv;
1561 return Instruction::UDiv;
1562 }
1563 case UDivOp : return Instruction::UDiv;
1564 case SDivOp : return Instruction::SDiv;
1565 case FDivOp : return Instruction::FDiv;
1566 case RemOp : {
1567 // This is an obsolete instruction so we must upgrade it based on the
1568 // types of its operands.
1569 bool isFP = Ty->isFloatingPoint();
Reid Spencer9d6565a2007-02-15 02:26:10 +00001570 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
Chris Lattner4227bdb2007-02-19 07:34:02 +00001571 // If its a vector type we want to use the element type
Reid Spencer950bf602007-01-26 08:19:09 +00001572 isFP = PTy->getElementType()->isFloatingPoint();
1573 // Select correct opcode
1574 if (isFP)
1575 return Instruction::FRem;
Reid Spencerbb1fd572007-03-21 17:15:50 +00001576 else if (Sign.isSigned())
Reid Spencer950bf602007-01-26 08:19:09 +00001577 return Instruction::SRem;
1578 return Instruction::URem;
1579 }
1580 case URemOp : return Instruction::URem;
1581 case SRemOp : return Instruction::SRem;
1582 case FRemOp : return Instruction::FRem;
Reid Spencer832254e2007-02-02 02:16:23 +00001583 case LShrOp : return Instruction::LShr;
1584 case AShrOp : return Instruction::AShr;
1585 case ShlOp : return Instruction::Shl;
1586 case ShrOp :
Reid Spencerbb1fd572007-03-21 17:15:50 +00001587 if (Sign.isSigned())
Reid Spencer832254e2007-02-02 02:16:23 +00001588 return Instruction::AShr;
1589 return Instruction::LShr;
Reid Spencer950bf602007-01-26 08:19:09 +00001590 case AndOp : return Instruction::And;
1591 case OrOp : return Instruction::Or;
1592 case XorOp : return Instruction::Xor;
1593 }
1594}
1595
1596static inline Instruction::OtherOps
1597getCompareOp(BinaryOps op, unsigned short &predicate, const Type* &Ty,
Reid Spencerbb1fd572007-03-21 17:15:50 +00001598 const Signedness &Sign) {
1599 bool isSigned = Sign.isSigned();
Reid Spencer950bf602007-01-26 08:19:09 +00001600 bool isFP = Ty->isFloatingPoint();
1601 switch (op) {
1602 default : assert(0 && "Invalid OldSetCC");
1603 case SetEQ :
1604 if (isFP) {
1605 predicate = FCmpInst::FCMP_OEQ;
1606 return Instruction::FCmp;
1607 } else {
1608 predicate = ICmpInst::ICMP_EQ;
1609 return Instruction::ICmp;
1610 }
1611 case SetNE :
1612 if (isFP) {
1613 predicate = FCmpInst::FCMP_UNE;
1614 return Instruction::FCmp;
1615 } else {
1616 predicate = ICmpInst::ICMP_NE;
1617 return Instruction::ICmp;
1618 }
1619 case SetLE :
1620 if (isFP) {
1621 predicate = FCmpInst::FCMP_OLE;
1622 return Instruction::FCmp;
1623 } else {
1624 if (isSigned)
1625 predicate = ICmpInst::ICMP_SLE;
1626 else
1627 predicate = ICmpInst::ICMP_ULE;
1628 return Instruction::ICmp;
1629 }
1630 case SetGE :
1631 if (isFP) {
1632 predicate = FCmpInst::FCMP_OGE;
1633 return Instruction::FCmp;
1634 } else {
1635 if (isSigned)
1636 predicate = ICmpInst::ICMP_SGE;
1637 else
1638 predicate = ICmpInst::ICMP_UGE;
1639 return Instruction::ICmp;
1640 }
1641 case SetLT :
1642 if (isFP) {
1643 predicate = FCmpInst::FCMP_OLT;
1644 return Instruction::FCmp;
1645 } else {
1646 if (isSigned)
1647 predicate = ICmpInst::ICMP_SLT;
1648 else
1649 predicate = ICmpInst::ICMP_ULT;
1650 return Instruction::ICmp;
1651 }
1652 case SetGT :
1653 if (isFP) {
1654 predicate = FCmpInst::FCMP_OGT;
1655 return Instruction::FCmp;
1656 } else {
1657 if (isSigned)
1658 predicate = ICmpInst::ICMP_SGT;
1659 else
1660 predicate = ICmpInst::ICMP_UGT;
1661 return Instruction::ICmp;
1662 }
1663 }
1664}
1665
1666static inline Instruction::MemoryOps getMemoryOp(MemoryOps op) {
1667 switch (op) {
1668 default : assert(0 && "Invalid OldMemoryOps");
1669 case MallocOp : return Instruction::Malloc;
1670 case FreeOp : return Instruction::Free;
1671 case AllocaOp : return Instruction::Alloca;
1672 case LoadOp : return Instruction::Load;
1673 case StoreOp : return Instruction::Store;
1674 case GetElementPtrOp : return Instruction::GetElementPtr;
1675 }
1676}
1677
1678static inline Instruction::OtherOps
Reid Spencerbb1fd572007-03-21 17:15:50 +00001679getOtherOp(OtherOps op, const Signedness &Sign) {
Reid Spencer950bf602007-01-26 08:19:09 +00001680 switch (op) {
1681 default : assert(0 && "Invalid OldOtherOps");
1682 case PHIOp : return Instruction::PHI;
1683 case CallOp : return Instruction::Call;
Reid Spencer950bf602007-01-26 08:19:09 +00001684 case SelectOp : return Instruction::Select;
1685 case UserOp1 : return Instruction::UserOp1;
1686 case UserOp2 : return Instruction::UserOp2;
1687 case VAArg : return Instruction::VAArg;
1688 case ExtractElementOp : return Instruction::ExtractElement;
1689 case InsertElementOp : return Instruction::InsertElement;
1690 case ShuffleVectorOp : return Instruction::ShuffleVector;
1691 case ICmpOp : return Instruction::ICmp;
1692 case FCmpOp : return Instruction::FCmp;
Reid Spencer950bf602007-01-26 08:19:09 +00001693 };
1694}
1695
1696static inline Value*
Reid Spencerbb1fd572007-03-21 17:15:50 +00001697getCast(CastOps op, Value *Src, const Signedness &SrcSign, const Type *DstTy,
1698 const Signedness &DstSign, bool ForceInstruction = false) {
Reid Spencer950bf602007-01-26 08:19:09 +00001699 Instruction::CastOps Opcode;
1700 const Type* SrcTy = Src->getType();
1701 if (op == CastOp) {
1702 if (SrcTy->isFloatingPoint() && isa<PointerType>(DstTy)) {
1703 // fp -> ptr cast is no longer supported but we must upgrade this
1704 // by doing a double cast: fp -> int -> ptr
1705 SrcTy = Type::Int64Ty;
1706 Opcode = Instruction::IntToPtr;
1707 if (isa<Constant>(Src)) {
1708 Src = ConstantExpr::getCast(Instruction::FPToUI,
1709 cast<Constant>(Src), SrcTy);
1710 } else {
1711 std::string NewName(makeNameUnique(Src->getName()));
1712 Src = new FPToUIInst(Src, SrcTy, NewName, CurBB);
1713 }
1714 } else if (isa<IntegerType>(DstTy) &&
1715 cast<IntegerType>(DstTy)->getBitWidth() == 1) {
1716 // cast type %x to bool was previously defined as setne type %x, null
1717 // The cast semantic is now to truncate, not compare so we must retain
1718 // the original intent by replacing the cast with a setne
1719 Constant* Null = Constant::getNullValue(SrcTy);
1720 Instruction::OtherOps Opcode = Instruction::ICmp;
1721 unsigned short predicate = ICmpInst::ICMP_NE;
1722 if (SrcTy->isFloatingPoint()) {
1723 Opcode = Instruction::FCmp;
1724 predicate = FCmpInst::FCMP_ONE;
1725 } else if (!SrcTy->isInteger() && !isa<PointerType>(SrcTy)) {
1726 error("Invalid cast to bool");
1727 }
1728 if (isa<Constant>(Src) && !ForceInstruction)
1729 return ConstantExpr::getCompare(predicate, cast<Constant>(Src), Null);
1730 else
1731 return CmpInst::create(Opcode, predicate, Src, Null);
1732 }
1733 // Determine the opcode to use by calling CastInst::getCastOpcode
1734 Opcode =
Reid Spencerbb1fd572007-03-21 17:15:50 +00001735 CastInst::getCastOpcode(Src, SrcSign.isSigned(), DstTy,
1736 DstSign.isSigned());
Reid Spencer950bf602007-01-26 08:19:09 +00001737
1738 } else switch (op) {
1739 default: assert(0 && "Invalid cast token");
1740 case TruncOp: Opcode = Instruction::Trunc; break;
1741 case ZExtOp: Opcode = Instruction::ZExt; break;
1742 case SExtOp: Opcode = Instruction::SExt; break;
1743 case FPTruncOp: Opcode = Instruction::FPTrunc; break;
1744 case FPExtOp: Opcode = Instruction::FPExt; break;
1745 case FPToUIOp: Opcode = Instruction::FPToUI; break;
1746 case FPToSIOp: Opcode = Instruction::FPToSI; break;
1747 case UIToFPOp: Opcode = Instruction::UIToFP; break;
1748 case SIToFPOp: Opcode = Instruction::SIToFP; break;
1749 case PtrToIntOp: Opcode = Instruction::PtrToInt; break;
1750 case IntToPtrOp: Opcode = Instruction::IntToPtr; break;
1751 case BitCastOp: Opcode = Instruction::BitCast; break;
1752 }
1753
1754 if (isa<Constant>(Src) && !ForceInstruction)
1755 return ConstantExpr::getCast(Opcode, cast<Constant>(Src), DstTy);
1756 return CastInst::create(Opcode, Src, DstTy);
1757}
1758
1759static Instruction *
1760upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
1761 std::vector<Value*>& Args) {
1762
1763 std::string Name = ID.Type == ValID::NameVal ? ID.Name : "";
Reid Spencer7eea8ff2007-05-18 05:48:07 +00001764 if (Name.length() <= 5 || Name[0] != 'l' || Name[1] != 'l' ||
1765 Name[2] != 'v' || Name[3] != 'm' || Name[4] != '.')
1766 return 0;
1767
Reid Spencer41b213e2007-04-02 01:14:00 +00001768 switch (Name[5]) {
1769 case 'i':
1770 if (Name == "llvm.isunordered.f32" || Name == "llvm.isunordered.f64") {
1771 if (Args.size() != 2)
1772 error("Invalid prototype for " + Name);
1773 return new FCmpInst(FCmpInst::FCMP_UNO, Args[0], Args[1]);
1774 }
1775 break;
Reid Spencer8166a6c2007-04-02 02:08:35 +00001776
Reid Spencer41b213e2007-04-02 01:14:00 +00001777 case 'v' : {
Christopher Lamb4374f8e2007-12-17 01:17:35 +00001778 const Type* PtrTy = PointerType::getUnqual(Type::Int8Ty);
Reid Spencer41b213e2007-04-02 01:14:00 +00001779 std::vector<const Type*> Params;
1780 if (Name == "llvm.va_start" || Name == "llvm.va_end") {
1781 if (Args.size() != 1)
1782 error("Invalid prototype for " + Name + " prototype");
1783 Params.push_back(PtrTy);
1784 const FunctionType *FTy =
1785 FunctionType::get(Type::VoidTy, Params, false);
Christopher Lamb4374f8e2007-12-17 01:17:35 +00001786 const PointerType *PFTy = PointerType::getUnqual(FTy);
Reid Spencer41b213e2007-04-02 01:14:00 +00001787 Value* Func = getVal(PFTy, ID);
1788 Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
David Greene718fda32007-08-01 03:59:32 +00001789 return new CallInst(Func, Args.begin(), Args.end());
Reid Spencer41b213e2007-04-02 01:14:00 +00001790 } else if (Name == "llvm.va_copy") {
1791 if (Args.size() != 2)
1792 error("Invalid prototype for " + Name + " prototype");
1793 Params.push_back(PtrTy);
1794 Params.push_back(PtrTy);
1795 const FunctionType *FTy =
1796 FunctionType::get(Type::VoidTy, Params, false);
Christopher Lamb4374f8e2007-12-17 01:17:35 +00001797 const PointerType *PFTy = PointerType::getUnqual(FTy);
Reid Spencer41b213e2007-04-02 01:14:00 +00001798 Value* Func = getVal(PFTy, ID);
1799 std::string InstName0(makeNameUnique("va0"));
1800 std::string InstName1(makeNameUnique("va1"));
1801 Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
1802 Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
David Greene718fda32007-08-01 03:59:32 +00001803 return new CallInst(Func, Args.begin(), Args.end());
Reid Spencer41b213e2007-04-02 01:14:00 +00001804 }
Reid Spencer950bf602007-01-26 08:19:09 +00001805 }
1806 }
1807 return 0;
1808}
1809
Reid Spencerff0e4482007-04-16 00:40:57 +00001810const Type* upgradeGEPCEIndices(const Type* PTy,
1811 std::vector<ValueInfo> *Indices,
1812 std::vector<Constant*> &Result) {
1813 const Type *Ty = PTy;
1814 Result.clear();
1815 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1816 Constant *Index = cast<Constant>((*Indices)[i].V);
1817
1818 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1819 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1820 // struct indices to i32 struct indices with ZExt for compatibility.
1821 if (CI->getBitWidth() < 32)
1822 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1823 }
1824
1825 if (isa<SequentialType>(Ty)) {
1826 // Make sure that unsigned SequentialType indices are zext'd to
1827 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1828 // all indices for SequentialType elements. We must retain the same
1829 // semantic (zext) for unsigned types.
1830 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
1831 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
1832 Index = ConstantExpr::getCast(Instruction::ZExt, Index,Type::Int64Ty);
1833 }
1834 }
1835 }
1836 Result.push_back(Index);
David Greene5fd22a82007-09-04 18:46:50 +00001837 Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(),
1838 Result.end(),true);
Reid Spencerff0e4482007-04-16 00:40:57 +00001839 if (!Ty)
1840 error("Index list invalid for constant getelementptr");
1841 }
1842 return Ty;
1843}
1844
1845const Type* upgradeGEPInstIndices(const Type* PTy,
1846 std::vector<ValueInfo> *Indices,
1847 std::vector<Value*> &Result) {
1848 const Type *Ty = PTy;
1849 Result.clear();
1850 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1851 Value *Index = (*Indices)[i].V;
1852
1853 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1854 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1855 // struct indices to i32 struct indices with ZExt for compatibility.
1856 if (CI->getBitWidth() < 32)
1857 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1858 }
1859
1860
1861 if (isa<StructType>(Ty)) { // Only change struct indices
1862 if (!isa<Constant>(Index)) {
1863 error("Invalid non-constant structure index");
1864 return 0;
1865 }
Reid Spencer950bf602007-01-26 08:19:09 +00001866 } else {
1867 // Make sure that unsigned SequentialType indices are zext'd to
1868 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1869 // all indices for SequentialType elements. We must retain the same
1870 // semantic (zext) for unsigned types.
Reid Spencerff0e4482007-04-16 00:40:57 +00001871 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00001872 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
Reid Spencerff0e4482007-04-16 00:40:57 +00001873 if (isa<Constant>(Index))
Reid Spencer950bf602007-01-26 08:19:09 +00001874 Index = ConstantExpr::getCast(Instruction::ZExt,
1875 cast<Constant>(Index), Type::Int64Ty);
1876 else
1877 Index = CastInst::create(Instruction::ZExt, Index, Type::Int64Ty,
Reid Spencer832254e2007-02-02 02:16:23 +00001878 makeNameUnique("gep"), CurBB);
Reid Spencer38f682b2007-01-26 20:31:18 +00001879 }
Reid Spencerff0e4482007-04-16 00:40:57 +00001880 }
Reid Spencer950bf602007-01-26 08:19:09 +00001881 }
Reid Spencerff0e4482007-04-16 00:40:57 +00001882 Result.push_back(Index);
David Greene5fd22a82007-09-04 18:46:50 +00001883 Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(),
1884 Result.end(),true);
Reid Spencerff0e4482007-04-16 00:40:57 +00001885 if (!Ty)
Reid Spencer950bf602007-01-26 08:19:09 +00001886 error("Index list invalid for constant getelementptr");
Reid Spencerff0e4482007-04-16 00:40:57 +00001887 }
1888 return Ty;
Reid Spencer950bf602007-01-26 08:19:09 +00001889}
1890
Reid Spencerb7046c72007-01-29 05:41:34 +00001891unsigned upgradeCallingConv(unsigned CC) {
1892 switch (CC) {
1893 case OldCallingConv::C : return CallingConv::C;
1894 case OldCallingConv::CSRet : return CallingConv::C;
1895 case OldCallingConv::Fast : return CallingConv::Fast;
1896 case OldCallingConv::Cold : return CallingConv::Cold;
1897 case OldCallingConv::X86_StdCall : return CallingConv::X86_StdCall;
1898 case OldCallingConv::X86_FastCall: return CallingConv::X86_FastCall;
1899 default:
1900 return CC;
1901 }
1902}
1903
Reid Spencer950bf602007-01-26 08:19:09 +00001904Module* UpgradeAssembly(const std::string &infile, std::istream& in,
1905 bool debug, bool addAttrs)
Reid Spencere7c3c602006-11-30 06:36:44 +00001906{
1907 Upgradelineno = 1;
1908 CurFilename = infile;
Reid Spencer96839be2006-11-30 16:50:26 +00001909 LexInput = &in;
Reid Spencere77e35e2006-12-01 20:26:20 +00001910 yydebug = debug;
Reid Spencer71d2ec92006-12-31 06:02:26 +00001911 AddAttributes = addAttrs;
Reid Spencer950bf602007-01-26 08:19:09 +00001912 ObsoleteVarArgs = false;
1913 NewVarArgs = false;
Reid Spencere7c3c602006-11-30 06:36:44 +00001914
Reid Spencer950bf602007-01-26 08:19:09 +00001915 CurModule.CurrentModule = new Module(CurFilename);
1916
1917 // Check to make sure the parser succeeded
Reid Spencere7c3c602006-11-30 06:36:44 +00001918 if (yyparse()) {
Reid Spencer950bf602007-01-26 08:19:09 +00001919 if (ParserResult)
1920 delete ParserResult;
Reid Spencer30d0c582007-01-15 00:26:18 +00001921 std::cerr << "llvm-upgrade: parse failed.\n";
Reid Spencer30d0c582007-01-15 00:26:18 +00001922 return 0;
1923 }
1924
Reid Spencer950bf602007-01-26 08:19:09 +00001925 // Check to make sure that parsing produced a result
1926 if (!ParserResult) {
1927 std::cerr << "llvm-upgrade: no parse result.\n";
1928 return 0;
Reid Spencer30d0c582007-01-15 00:26:18 +00001929 }
1930
Reid Spencer950bf602007-01-26 08:19:09 +00001931 // Reset ParserResult variable while saving its value for the result.
1932 Module *Result = ParserResult;
1933 ParserResult = 0;
Reid Spencer30d0c582007-01-15 00:26:18 +00001934
Reid Spencer950bf602007-01-26 08:19:09 +00001935 //Not all functions use vaarg, so make a second check for ObsoleteVarArgs
Reid Spencer30d0c582007-01-15 00:26:18 +00001936 {
Reid Spencer950bf602007-01-26 08:19:09 +00001937 Function* F;
Reid Spencer688b0492007-02-05 21:19:13 +00001938 if ((F = Result->getFunction("llvm.va_start"))
Reid Spencer950bf602007-01-26 08:19:09 +00001939 && F->getFunctionType()->getNumParams() == 0)
1940 ObsoleteVarArgs = true;
Reid Spencer688b0492007-02-05 21:19:13 +00001941 if((F = Result->getFunction("llvm.va_copy"))
Reid Spencer950bf602007-01-26 08:19:09 +00001942 && F->getFunctionType()->getNumParams() == 1)
1943 ObsoleteVarArgs = true;
Reid Spencer280d8012006-12-01 23:40:53 +00001944 }
Reid Spencer319a7302007-01-05 17:20:02 +00001945
Reid Spencer950bf602007-01-26 08:19:09 +00001946 if (ObsoleteVarArgs && NewVarArgs) {
1947 error("This file is corrupt: it uses both new and old style varargs");
1948 return 0;
Reid Spencer319a7302007-01-05 17:20:02 +00001949 }
Reid Spencer319a7302007-01-05 17:20:02 +00001950
Reid Spencer950bf602007-01-26 08:19:09 +00001951 if(ObsoleteVarArgs) {
Reid Spencer688b0492007-02-05 21:19:13 +00001952 if(Function* F = Result->getFunction("llvm.va_start")) {
Reid Spencer950bf602007-01-26 08:19:09 +00001953 if (F->arg_size() != 0) {
1954 error("Obsolete va_start takes 0 argument");
Reid Spencer319a7302007-01-05 17:20:02 +00001955 return 0;
1956 }
Reid Spencer950bf602007-01-26 08:19:09 +00001957
1958 //foo = va_start()
1959 // ->
1960 //bar = alloca typeof(foo)
1961 //va_start(bar)
1962 //foo = load bar
Reid Spencer319a7302007-01-05 17:20:02 +00001963
Reid Spencer950bf602007-01-26 08:19:09 +00001964 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1965 const Type* ArgTy = F->getFunctionType()->getReturnType();
Christopher Lamb4374f8e2007-12-17 01:17:35 +00001966 const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
Reid Spencer950bf602007-01-26 08:19:09 +00001967 Function* NF = cast<Function>(Result->getOrInsertFunction(
1968 "llvm.va_start", RetTy, ArgTyPtr, (Type *)0));
1969
1970 while (!F->use_empty()) {
1971 CallInst* CI = cast<CallInst>(F->use_back());
1972 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vastart.fix.1", CI);
1973 new CallInst(NF, bar, "", CI);
1974 Value* foo = new LoadInst(bar, "vastart.fix.2", CI);
1975 CI->replaceAllUsesWith(foo);
1976 CI->getParent()->getInstList().erase(CI);
Reid Spencerf8383de2007-01-06 06:04:32 +00001977 }
Reid Spencer950bf602007-01-26 08:19:09 +00001978 Result->getFunctionList().erase(F);
Reid Spencerf8383de2007-01-06 06:04:32 +00001979 }
Reid Spencer950bf602007-01-26 08:19:09 +00001980
Reid Spencer688b0492007-02-05 21:19:13 +00001981 if(Function* F = Result->getFunction("llvm.va_end")) {
Reid Spencer950bf602007-01-26 08:19:09 +00001982 if(F->arg_size() != 1) {
1983 error("Obsolete va_end takes 1 argument");
1984 return 0;
Reid Spencerf8383de2007-01-06 06:04:32 +00001985 }
Reid Spencerf8383de2007-01-06 06:04:32 +00001986
Reid Spencer950bf602007-01-26 08:19:09 +00001987 //vaend foo
1988 // ->
1989 //bar = alloca 1 of typeof(foo)
1990 //vaend bar
1991 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1992 const Type* ArgTy = F->getFunctionType()->getParamType(0);
Christopher Lamb4374f8e2007-12-17 01:17:35 +00001993 const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
Reid Spencer950bf602007-01-26 08:19:09 +00001994 Function* NF = cast<Function>(Result->getOrInsertFunction(
1995 "llvm.va_end", RetTy, ArgTyPtr, (Type *)0));
Reid Spencerf8383de2007-01-06 06:04:32 +00001996
Reid Spencer950bf602007-01-26 08:19:09 +00001997 while (!F->use_empty()) {
1998 CallInst* CI = cast<CallInst>(F->use_back());
1999 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vaend.fix.1", CI);
2000 new StoreInst(CI->getOperand(1), bar, CI);
2001 new CallInst(NF, bar, "", CI);
2002 CI->getParent()->getInstList().erase(CI);
Reid Spencere77e35e2006-12-01 20:26:20 +00002003 }
Reid Spencer950bf602007-01-26 08:19:09 +00002004 Result->getFunctionList().erase(F);
Reid Spencere77e35e2006-12-01 20:26:20 +00002005 }
Reid Spencer950bf602007-01-26 08:19:09 +00002006
Reid Spencer688b0492007-02-05 21:19:13 +00002007 if(Function* F = Result->getFunction("llvm.va_copy")) {
Reid Spencer950bf602007-01-26 08:19:09 +00002008 if(F->arg_size() != 1) {
2009 error("Obsolete va_copy takes 1 argument");
2010 return 0;
Reid Spencere77e35e2006-12-01 20:26:20 +00002011 }
Reid Spencer950bf602007-01-26 08:19:09 +00002012 //foo = vacopy(bar)
2013 // ->
2014 //a = alloca 1 of typeof(foo)
2015 //b = alloca 1 of typeof(foo)
2016 //store bar -> b
2017 //vacopy(a, b)
2018 //foo = load a
2019
2020 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2021 const Type* ArgTy = F->getFunctionType()->getReturnType();
Christopher Lamb4374f8e2007-12-17 01:17:35 +00002022 const Type* ArgTyPtr = PointerType::getUnqual(ArgTy);
Reid Spencer950bf602007-01-26 08:19:09 +00002023 Function* NF = cast<Function>(Result->getOrInsertFunction(
2024 "llvm.va_copy", RetTy, ArgTyPtr, ArgTyPtr, (Type *)0));
Reid Spencere77e35e2006-12-01 20:26:20 +00002025
Reid Spencer950bf602007-01-26 08:19:09 +00002026 while (!F->use_empty()) {
2027 CallInst* CI = cast<CallInst>(F->use_back());
David Greene5fd22a82007-09-04 18:46:50 +00002028 Value *Args[2] = {
2029 new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI),
2030 new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI)
2031 };
David Greene718fda32007-08-01 03:59:32 +00002032 new StoreInst(CI->getOperand(1), Args[1], CI);
David Greene5fd22a82007-09-04 18:46:50 +00002033 new CallInst(NF, Args, Args + 2, "", CI);
David Greene718fda32007-08-01 03:59:32 +00002034 Value* foo = new LoadInst(Args[0], "vacopy.fix.3", CI);
Reid Spencer950bf602007-01-26 08:19:09 +00002035 CI->replaceAllUsesWith(foo);
2036 CI->getParent()->getInstList().erase(CI);
2037 }
2038 Result->getFunctionList().erase(F);
Reid Spencer319a7302007-01-05 17:20:02 +00002039 }
2040 }
2041
Reid Spencer52402b02007-01-02 05:45:11 +00002042 return Result;
2043}
2044
Reid Spencer950bf602007-01-26 08:19:09 +00002045} // end llvm namespace
Reid Spencer319a7302007-01-05 17:20:02 +00002046
Reid Spencer950bf602007-01-26 08:19:09 +00002047using namespace llvm;
Reid Spencer30d0c582007-01-15 00:26:18 +00002048
2049
Chris Lattnercf786592007-12-29 20:47:37 +00002050
2051/* Enabling traces. */
2052#ifndef YYDEBUG
2053# define YYDEBUG 0
2054#endif
2055
2056/* Enabling verbose error messages. */
2057#ifdef YYERROR_VERBOSE
2058# undef YYERROR_VERBOSE
2059# define YYERROR_VERBOSE 1
2060#else
2061# define YYERROR_VERBOSE 0
2062#endif
2063
2064/* Enabling the token table. */
2065#ifndef YYTOKEN_TABLE
2066# define YYTOKEN_TABLE 0
2067#endif
2068
2069#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
2070typedef union YYSTYPE
2071#line 1681 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
2072{
Reid Spencer950bf602007-01-26 08:19:09 +00002073 llvm::Module *ModuleVal;
2074 llvm::Function *FunctionVal;
2075 std::pair<llvm::PATypeInfo, char*> *ArgVal;
2076 llvm::BasicBlock *BasicBlockVal;
Reid Spencerbb1fd572007-03-21 17:15:50 +00002077 llvm::TermInstInfo TermInstVal;
Reid Spencer950bf602007-01-26 08:19:09 +00002078 llvm::InstrInfo InstVal;
2079 llvm::ConstInfo ConstVal;
2080 llvm::ValueInfo ValueVal;
2081 llvm::PATypeInfo TypeVal;
2082 llvm::TypeInfo PrimType;
2083 llvm::PHIListInfo PHIList;
2084 std::list<llvm::PATypeInfo> *TypeList;
2085 std::vector<llvm::ValueInfo> *ValueList;
2086 std::vector<llvm::ConstInfo> *ConstVector;
2087
2088
2089 std::vector<std::pair<llvm::PATypeInfo,char*> > *ArgList;
2090 // Represent the RHS of PHI node
2091 std::vector<std::pair<llvm::Constant*, llvm::BasicBlock*> > *JumpTable;
2092
2093 llvm::GlobalValue::LinkageTypes Linkage;
2094 int64_t SInt64Val;
2095 uint64_t UInt64Val;
2096 int SIntVal;
2097 unsigned UIntVal;
Dale Johannesencdd509a2007-09-07 21:07:57 +00002098 llvm::APFloat *FPVal;
Reid Spencer950bf602007-01-26 08:19:09 +00002099 bool BoolVal;
2100
2101 char *StrVal; // This memory is strdup'd!
2102 llvm::ValID ValIDVal; // strdup'd memory maybe!
2103
2104 llvm::BinaryOps BinaryOpVal;
2105 llvm::TermOps TermOpVal;
2106 llvm::MemoryOps MemOpVal;
2107 llvm::OtherOps OtherOpVal;
2108 llvm::CastOps CastOpVal;
2109 llvm::ICmpInst::Predicate IPred;
2110 llvm::FCmpInst::Predicate FPred;
2111 llvm::Module::Endianness Endianness;
Chris Lattnercf786592007-12-29 20:47:37 +00002112}
2113/* Line 193 of yacc.c. */
2114#line 2115 "UpgradeParser.tab.c"
2115 YYSTYPE;
2116# define yystype YYSTYPE /* obsolescent; will be withdrawn */
2117# define YYSTYPE_IS_DECLARED 1
2118# define YYSTYPE_IS_TRIVIAL 1
Reid Spencere7c3c602006-11-30 06:36:44 +00002119#endif
2120
Reid Spencer950bf602007-01-26 08:19:09 +00002121
Reid Spencere7c3c602006-11-30 06:36:44 +00002122
Chris Lattnercf786592007-12-29 20:47:37 +00002123/* Copy the second part of user declarations. */
Reid Spencere7c3c602006-11-30 06:36:44 +00002124
2125
Chris Lattnercf786592007-12-29 20:47:37 +00002126/* Line 216 of yacc.c. */
2127#line 2128 "UpgradeParser.tab.c"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002128
Chris Lattnercf786592007-12-29 20:47:37 +00002129#ifdef short
2130# undef short
Reid Spencere7c3c602006-11-30 06:36:44 +00002131#endif
2132
Chris Lattnercf786592007-12-29 20:47:37 +00002133#ifdef YYTYPE_UINT8
2134typedef YYTYPE_UINT8 yytype_uint8;
David Greene5fd22a82007-09-04 18:46:50 +00002135#else
Chris Lattnercf786592007-12-29 20:47:37 +00002136typedef unsigned char yytype_uint8;
David Greene5fd22a82007-09-04 18:46:50 +00002137#endif
2138
Chris Lattnercf786592007-12-29 20:47:37 +00002139#ifdef YYTYPE_INT8
2140typedef YYTYPE_INT8 yytype_int8;
2141#elif (defined __STDC__ || defined __C99__FUNC__ \
2142 || defined __cplusplus || defined _MSC_VER)
2143typedef signed char yytype_int8;
2144#else
2145typedef short int yytype_int8;
2146#endif
2147
2148#ifdef YYTYPE_UINT16
2149typedef YYTYPE_UINT16 yytype_uint16;
2150#else
2151typedef unsigned short int yytype_uint16;
2152#endif
2153
2154#ifdef YYTYPE_INT16
2155typedef YYTYPE_INT16 yytype_int16;
2156#else
2157typedef short int yytype_int16;
2158#endif
2159
2160#ifndef YYSIZE_T
2161# ifdef __SIZE_TYPE__
2162# define YYSIZE_T __SIZE_TYPE__
2163# elif defined size_t
2164# define YYSIZE_T size_t
2165# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
2166 || defined __cplusplus || defined _MSC_VER)
2167# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
2168# define YYSIZE_T size_t
2169# else
2170# define YYSIZE_T unsigned int
2171# endif
2172#endif
2173
2174#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
2175
2176#ifndef YY_
2177# if defined YYENABLE_NLS && YYENABLE_NLS
2178# if ENABLE_NLS
2179# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
2180# define YY_(msgid) dgettext ("bison-runtime", msgid)
2181# endif
2182# endif
2183# ifndef YY_
2184# define YY_(msgid) msgid
2185# endif
2186#endif
2187
2188/* Suppress unused-variable warnings by "using" E. */
2189#if ! defined lint || defined __GNUC__
2190# define YYUSE(e) ((void) (e))
2191#else
2192# define YYUSE(e) /* empty */
2193#endif
2194
2195/* Identity function, used to suppress warnings about constant conditions. */
2196#ifndef lint
2197# define YYID(n) (n)
2198#else
2199#if (defined __STDC__ || defined __C99__FUNC__ \
2200 || defined __cplusplus || defined _MSC_VER)
2201static int
2202YYID (int i)
2203#else
2204static int
2205YYID (i)
2206 int i;
2207#endif
2208{
2209 return i;
2210}
2211#endif
2212
2213#if ! defined yyoverflow || YYERROR_VERBOSE
2214
2215/* The parser invokes alloca or malloc; define the necessary symbols. */
2216
2217# ifdef YYSTACK_USE_ALLOCA
2218# if YYSTACK_USE_ALLOCA
2219# ifdef __GNUC__
2220# define YYSTACK_ALLOC __builtin_alloca
2221# elif defined __BUILTIN_VA_ARG_INCR
2222# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
2223# elif defined _AIX
2224# define YYSTACK_ALLOC __alloca
2225# elif defined _MSC_VER
2226# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
2227# define alloca _alloca
2228# else
2229# define YYSTACK_ALLOC alloca
2230# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
2231 || defined __cplusplus || defined _MSC_VER)
2232# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
2233# ifndef _STDLIB_H
2234# define _STDLIB_H 1
2235# endif
2236# endif
2237# endif
2238# endif
2239# endif
2240
2241# ifdef YYSTACK_ALLOC
2242 /* Pacify GCC's `empty if-body' warning. */
2243# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
2244# ifndef YYSTACK_ALLOC_MAXIMUM
2245 /* The OS might guarantee only one guard page at the bottom of the stack,
2246 and a page size can be as small as 4096 bytes. So we cannot safely
2247 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
2248 to allow for a few compiler-allocated temporary stack slots. */
2249# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
2250# endif
2251# else
2252# define YYSTACK_ALLOC YYMALLOC
2253# define YYSTACK_FREE YYFREE
2254# ifndef YYSTACK_ALLOC_MAXIMUM
2255# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
2256# endif
2257# if (defined __cplusplus && ! defined _STDLIB_H \
2258 && ! ((defined YYMALLOC || defined malloc) \
2259 && (defined YYFREE || defined free)))
2260# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
2261# ifndef _STDLIB_H
2262# define _STDLIB_H 1
2263# endif
2264# endif
2265# ifndef YYMALLOC
2266# define YYMALLOC malloc
2267# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
2268 || defined __cplusplus || defined _MSC_VER)
2269void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
2270# endif
2271# endif
2272# ifndef YYFREE
2273# define YYFREE free
2274# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
2275 || defined __cplusplus || defined _MSC_VER)
2276void free (void *); /* INFRINGES ON USER NAME SPACE */
2277# endif
2278# endif
2279# endif
2280#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
2281
2282
2283#if (! defined yyoverflow \
2284 && (! defined __cplusplus \
2285 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
2286
2287/* A type that is properly aligned for any stack member. */
2288union yyalloc
2289{
2290 yytype_int16 yyss;
2291 YYSTYPE yyvs;
2292 };
2293
2294/* The size of the maximum gap between one aligned stack and the next. */
2295# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
2296
2297/* The size of an array large to enough to hold all stacks, each with
2298 N elements. */
2299# define YYSTACK_BYTES(N) \
2300 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
2301 + YYSTACK_GAP_MAXIMUM)
2302
2303/* Copy COUNT objects from FROM to TO. The source and destination do
2304 not overlap. */
2305# ifndef YYCOPY
2306# if defined __GNUC__ && 1 < __GNUC__
2307# define YYCOPY(To, From, Count) \
2308 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
2309# else
2310# define YYCOPY(To, From, Count) \
2311 do \
2312 { \
2313 YYSIZE_T yyi; \
2314 for (yyi = 0; yyi < (Count); yyi++) \
2315 (To)[yyi] = (From)[yyi]; \
2316 } \
2317 while (YYID (0))
2318# endif
2319# endif
2320
2321/* Relocate STACK from its old location to the new one. The
2322 local variables YYSIZE and YYSTACKSIZE give the old and new number of
2323 elements in the stack, and YYPTR gives the new location of the
2324 stack. Advance YYPTR to a properly aligned location for the next
2325 stack. */
2326# define YYSTACK_RELOCATE(Stack) \
2327 do \
2328 { \
2329 YYSIZE_T yynewbytes; \
2330 YYCOPY (&yyptr->Stack, Stack, yysize); \
2331 Stack = &yyptr->Stack; \
2332 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
2333 yyptr += yynewbytes / sizeof (*yyptr); \
2334 } \
2335 while (YYID (0))
2336
2337#endif
2338
2339/* YYFINAL -- State number of the termination state. */
2340#define YYFINAL 4
2341/* YYLAST -- Last index in YYTABLE. */
2342#define YYLAST 1630
2343
2344/* YYNTOKENS -- Number of terminals. */
2345#define YYNTOKENS 166
2346/* YYNNTS -- Number of nonterminals. */
2347#define YYNNTS 81
2348/* YYNRULES -- Number of rules. */
2349#define YYNRULES 310
2350/* YYNRULES -- Number of states. */
2351#define YYNSTATES 606
2352
2353/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
2354#define YYUNDEFTOK 2
2355#define YYMAXUTOK 406
2356
2357#define YYTRANSLATE(YYX) \
2358 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
2359
2360/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
2361static const yytype_uint8 yytranslate[] =
2362{
2363 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2364 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2365 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2366 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2367 155, 156, 164, 2, 153, 2, 2, 2, 2, 2,
2368 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2369 160, 152, 161, 2, 2, 2, 2, 2, 2, 2,
2370 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2371 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2372 2, 157, 154, 159, 2, 2, 2, 2, 2, 165,
2373 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2374 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2375 158, 2, 2, 162, 2, 163, 2, 2, 2, 2,
2376 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2377 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2378 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2379 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2380 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2381 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2382 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2383 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2384 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2385 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2386 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2387 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2388 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
2389 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
2390 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
2391 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
2392 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
2393 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
2394 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
2395 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
2396 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
2397 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
2398 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
2399 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
2400 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
2401 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
2402 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
2403 145, 146, 147, 148, 149, 150, 151
2404};
2405
2406#if YYDEBUG
2407/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
2408 YYRHS. */
2409static const yytype_uint16 yyprhs[] =
2410{
2411 0, 0, 3, 5, 7, 9, 11, 13, 15, 17,
2412 19, 21, 23, 25, 27, 29, 31, 33, 35, 37,
2413 39, 41, 43, 45, 47, 49, 51, 53, 55, 57,
2414 59, 61, 63, 65, 67, 69, 71, 73, 75, 77,
2415 79, 81, 83, 85, 87, 89, 91, 93, 95, 97,
2416 99, 101, 103, 105, 107, 109, 111, 113, 115, 117,
2417 119, 121, 123, 125, 127, 129, 131, 133, 135, 137,
2418 139, 141, 143, 145, 147, 149, 151, 153, 155, 157,
2419 159, 161, 164, 165, 167, 169, 171, 173, 175, 177,
2420 179, 180, 181, 183, 185, 187, 189, 191, 193, 196,
2421 197, 200, 201, 205, 208, 209, 211, 212, 216, 218,
2422 221, 223, 225, 227, 229, 231, 233, 235, 237, 239,
2423 241, 243, 245, 247, 249, 251, 253, 255, 257, 259,
2424 261, 264, 269, 275, 281, 285, 288, 294, 299, 302,
2425 304, 308, 310, 314, 316, 317, 322, 326, 330, 335,
2426 340, 344, 351, 357, 360, 363, 366, 369, 372, 375,
2427 378, 381, 384, 387, 394, 400, 409, 416, 423, 430,
2428 438, 446, 453, 460, 469, 478, 482, 484, 486, 488,
2429 490, 493, 496, 501, 504, 506, 511, 514, 519, 520,
2430 528, 529, 537, 538, 546, 547, 555, 559, 564, 565,
2431 567, 569, 571, 575, 579, 583, 587, 591, 595, 597,
2432 598, 600, 602, 604, 605, 608, 612, 614, 616, 620,
2433 622, 623, 632, 634, 636, 637, 642, 644, 646, 649,
2434 650, 652, 654, 655, 656, 662, 663, 665, 667, 669,
2435 671, 673, 675, 677, 679, 681, 685, 687, 693, 695,
2436 697, 699, 701, 704, 707, 710, 714, 717, 718, 720,
2437 722, 724, 727, 730, 734, 744, 754, 763, 777, 779,
2438 781, 788, 794, 797, 804, 812, 814, 818, 820, 821,
2439 824, 826, 832, 838, 844, 851, 858, 861, 866, 871,
2440 878, 883, 888, 893, 898, 905, 912, 915, 923, 925,
2441 928, 929, 931, 932, 936, 943, 947, 954, 957, 962,
2442 969
2443};
2444
2445/* YYRHS -- A `-1'-separated list of the rules' RHS. */
2446static const yytype_int16 yyrhs[] =
2447{
2448 200, 0, -1, 5, -1, 6, -1, 3, -1, 4,
2449 -1, 79, -1, 80, -1, 81, -1, 82, -1, 83,
2450 -1, 84, -1, 85, -1, 86, -1, 87, -1, 88,
2451 -1, 89, -1, 90, -1, 91, -1, 92, -1, 97,
2452 -1, 98, -1, 99, -1, 100, -1, 101, -1, 102,
2453 -1, 119, -1, 120, -1, 121, -1, 122, -1, 123,
2454 -1, 124, -1, 125, -1, 126, -1, 127, -1, 128,
2455 -1, 129, -1, 130, -1, 131, -1, 132, -1, 133,
2456 -1, 134, -1, 135, -1, 136, -1, 137, -1, 138,
2457 -1, 125, -1, 126, -1, 127, -1, 128, -1, 27,
2458 -1, 28, -1, 93, -1, 94, -1, 95, -1, 96,
2459 -1, 140, -1, 141, -1, 142, -1, 143, -1, 144,
2460 -1, 145, -1, 146, -1, 147, -1, 148, -1, 149,
2461 -1, 150, -1, 151, -1, 139, -1, 16, -1, 14,
2462 -1, 12, -1, 10, -1, 17, -1, 15, -1, 13,
2463 -1, 11, -1, 176, -1, 177, -1, 18, -1, 19,
2464 -1, 212, 152, -1, -1, 41, -1, 42, -1, 43,
2465 -1, 44, -1, 45, -1, 46, -1, 47, -1, -1,
2466 -1, 65, -1, 66, -1, 67, -1, 68, -1, 69,
2467 -1, 70, -1, 64, 4, -1, -1, 57, 4, -1,
2468 -1, 153, 57, 4, -1, 34, 24, -1, -1, 185,
2469 -1, -1, 153, 188, 187, -1, 185, -1, 57, 4,
2470 -1, 191, -1, 8, -1, 193, -1, 8, -1, 193,
2471 -1, 9, -1, 10, -1, 11, -1, 12, -1, 13,
2472 -1, 14, -1, 15, -1, 16, -1, 17, -1, 18,
2473 -1, 19, -1, 21, -1, 192, -1, 48, -1, 229,
2474 -1, 154, 4, -1, 190, 155, 195, 156, -1, 157,
2475 4, 158, 193, 159, -1, 160, 4, 158, 193, 161,
2476 -1, 162, 194, 163, -1, 162, 163, -1, 160, 162,
2477 194, 163, 161, -1, 160, 162, 163, 161, -1, 193,
2478 164, -1, 193, -1, 194, 153, 193, -1, 194, -1,
2479 194, 153, 37, -1, 37, -1, -1, 191, 157, 198,
2480 159, -1, 191, 157, 159, -1, 191, 165, 24, -1,
2481 191, 160, 198, 161, -1, 191, 162, 198, 163, -1,
2482 191, 162, 163, -1, 191, 160, 162, 198, 163, 161,
2483 -1, 191, 160, 162, 163, 161, -1, 191, 38, -1,
2484 191, 39, -1, 191, 229, -1, 191, 197, -1, 191,
2485 26, -1, 176, 168, -1, 177, 4, -1, 9, 27,
2486 -1, 9, 28, -1, 179, 7, -1, 175, 155, 196,
2487 36, 191, 156, -1, 110, 155, 196, 244, 156, -1,
2488 112, 155, 196, 153, 196, 153, 196, 156, -1, 169,
2489 155, 196, 153, 196, 156, -1, 170, 155, 196, 153,
2490 196, 156, -1, 171, 155, 196, 153, 196, 156, -1,
2491 103, 172, 155, 196, 153, 196, 156, -1, 104, 173,
2492 155, 196, 153, 196, 156, -1, 174, 155, 196, 153,
2493 196, 156, -1, 114, 155, 196, 153, 196, 156, -1,
2494 115, 155, 196, 153, 196, 153, 196, 156, -1, 116,
2495 155, 196, 153, 196, 153, 196, 156, -1, 198, 153,
2496 196, -1, 196, -1, 32, -1, 33, -1, 201, -1,
2497 201, 222, -1, 201, 224, -1, 201, 62, 61, 207,
2498 -1, 201, 25, -1, 202, -1, 202, 180, 20, 189,
2499 -1, 202, 224, -1, 202, 62, 61, 207, -1, -1,
2500 202, 180, 181, 199, 196, 203, 187, -1, -1, 202,
2501 180, 50, 199, 191, 204, 187, -1, -1, 202, 180,
2502 45, 199, 191, 205, 187, -1, -1, 202, 180, 47,
2503 199, 191, 206, 187, -1, 202, 51, 209, -1, 202,
2504 58, 152, 210, -1, -1, 24, -1, 56, -1, 55,
2505 -1, 53, 152, 208, -1, 54, 152, 4, -1, 52,
2506 152, 24, -1, 71, 152, 24, -1, 157, 211, 159,
2507 -1, 211, 153, 24, -1, 24, -1, -1, 22, -1,
2508 24, -1, 212, -1, -1, 191, 213, -1, 215, 153,
2509 214, -1, 214, -1, 215, -1, 215, 153, 37, -1,
2510 37, -1, -1, 182, 189, 212, 155, 216, 156, 186,
2511 183, -1, 29, -1, 162, -1, -1, 181, 220, 217,
2512 218, -1, 30, -1, 163, -1, 232, 221, -1, -1,
2513 45, -1, 47, -1, -1, -1, 31, 225, 223, 226,
2514 217, -1, -1, 63, -1, 3, -1, 4, -1, 7,
2515 -1, 27, -1, 28, -1, 38, -1, 39, -1, 26,
2516 -1, 160, 198, 161, -1, 197, -1, 61, 227, 24,
2517 153, 24, -1, 167, -1, 212, -1, 229, -1, 228,
2518 -1, 191, 230, -1, 232, 233, -1, 219, 233, -1,
2519 234, 180, 236, -1, 234, 238, -1, -1, 23, -1,
2520 77, -1, 78, -1, 72, 231, -1, 72, 8, -1,
2521 73, 21, 230, -1, 73, 9, 230, 153, 21, 230,
2522 153, 21, 230, -1, 74, 178, 230, 153, 21, 230,
2523 157, 237, 159, -1, 74, 178, 230, 153, 21, 230,
2524 157, 159, -1, 75, 182, 189, 230, 155, 241, 156,
2525 36, 21, 230, 235, 21, 230, -1, 235, -1, 76,
2526 -1, 237, 178, 228, 153, 21, 230, -1, 178, 228,
2527 153, 21, 230, -1, 180, 243, -1, 191, 157, 230,
2528 153, 230, 159, -1, 239, 153, 157, 230, 153, 230,
2529 159, -1, 231, -1, 240, 153, 231, -1, 240, -1,
2530 -1, 60, 59, -1, 59, -1, 169, 191, 230, 153,
2531 230, -1, 170, 191, 230, 153, 230, -1, 171, 191,
2532 230, 153, 230, -1, 103, 172, 191, 230, 153, 230,
2533 -1, 104, 173, 191, 230, 153, 230, -1, 49, 231,
2534 -1, 174, 231, 153, 231, -1, 175, 231, 36, 191,
2535 -1, 112, 231, 153, 231, 153, 231, -1, 113, 231,
2536 153, 191, -1, 117, 231, 153, 191, -1, 118, 231,
2537 153, 191, -1, 114, 231, 153, 231, -1, 115, 231,
2538 153, 231, 153, 231, -1, 116, 231, 153, 231, 153,
2539 231, -1, 111, 239, -1, 242, 182, 189, 230, 155,
2540 241, 156, -1, 246, -1, 153, 240, -1, -1, 35,
2541 -1, -1, 105, 191, 184, -1, 105, 191, 153, 15,
2542 230, 184, -1, 106, 191, 184, -1, 106, 191, 153,
2543 15, 230, 184, -1, 107, 231, -1, 245, 108, 191,
2544 230, -1, 245, 109, 231, 153, 191, 230, -1, 110,
2545 191, 230, 244, -1
2546};
2547
2548/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
2549static const yytype_uint16 yyrline[] =
2550{
2551 0, 1821, 1821, 1822, 1830, 1831, 1841, 1841, 1841, 1841,
2552 1841, 1841, 1841, 1841, 1841, 1841, 1841, 1845, 1845, 1845,
2553 1849, 1849, 1849, 1849, 1849, 1849, 1853, 1853, 1854, 1854,
2554 1855, 1855, 1856, 1856, 1857, 1857, 1861, 1861, 1862, 1862,
2555 1863, 1863, 1864, 1864, 1865, 1865, 1866, 1866, 1867, 1867,
2556 1868, 1869, 1872, 1872, 1872, 1872, 1876, 1876, 1876, 1876,
2557 1876, 1876, 1876, 1877, 1877, 1877, 1877, 1877, 1877, 1883,
2558 1883, 1883, 1883, 1887, 1887, 1887, 1887, 1891, 1891, 1895,
2559 1895, 1900, 1903, 1908, 1909, 1910, 1911, 1912, 1913, 1914,
2560 1915, 1919, 1920, 1921, 1922, 1923, 1924, 1925, 1926, 1936,
2561 1937, 1945, 1946, 1954, 1963, 1964, 1971, 1972, 1976, 1980,
2562 1996, 1997, 2004, 2005, 2012, 2020, 2020, 2020, 2020, 2020,
2563 2020, 2020, 2021, 2021, 2021, 2021, 2021, 2026, 2030, 2034,
2564 2039, 2048, 2075, 2081, 2094, 2105, 2109, 2122, 2126, 2141,
2565 2145, 2152, 2153, 2159, 2166, 2178, 2208, 2221, 2244, 2272,
2566 2294, 2305, 2327, 2338, 2347, 2352, 2411, 2418, 2426, 2433,
2567 2440, 2444, 2448, 2462, 2477, 2489, 2498, 2526, 2539, 2548,
2568 2554, 2560, 2571, 2577, 2583, 2594, 2595, 2604, 2605, 2617,
2569 2626, 2627, 2628, 2629, 2630, 2646, 2666, 2668, 2670, 2670,
2570 2677, 2677, 2685, 2685, 2693, 2693, 2702, 2704, 2706, 2711,
2571 2725, 2726, 2730, 2733, 2741, 2745, 2752, 2756, 2760, 2764,
2572 2772, 2772, 2776, 2777, 2781, 2789, 2794, 2802, 2803, 2810,
2573 2817, 2821, 3009, 3009, 3013, 3013, 3023, 3023, 3027, 3032,
2574 3033, 3034, 3038, 3039, 3038, 3051, 3052, 3057, 3058, 3059,
2575 3060, 3064, 3068, 3069, 3070, 3071, 3092, 3096, 3111, 3112,
2576 3117, 3117, 3125, 3135, 3138, 3147, 3158, 3163, 3172, 3183,
2577 3183, 3186, 3190, 3194, 3199, 3209, 3227, 3236, 3309, 3313,
2578 3320, 3332, 3347, 3377, 3387, 3397, 3401, 3408, 3409, 3413,
2579 3416, 3422, 3441, 3459, 3475, 3489, 3503, 3514, 3532, 3541,
2580 3550, 3557, 3578, 3602, 3608, 3614, 3620, 3636, 3728, 3736,
2581 3737, 3741, 3742, 3746, 3752, 3759, 3765, 3772, 3779, 3792,
2582 3812
2583};
2584#endif
2585
2586#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
2587/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
2588 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
2589static const char *const yytname[] =
2590{
2591 "$end", "error", "$undefined", "ESINT64VAL", "EUINT64VAL", "SINTVAL",
2592 "UINTVAL", "FPVAL", "VOID", "BOOL", "SBYTE", "UBYTE", "SHORT", "USHORT",
2593 "INT", "UINT", "LONG", "ULONG", "FLOAT", "DOUBLE", "TYPE", "LABEL",
2594 "VAR_ID", "LABELSTR", "STRINGCONSTANT", "IMPLEMENTATION",
2595 "ZEROINITIALIZER", "TRUETOK", "FALSETOK", "BEGINTOK", "ENDTOK",
2596 "DECLARE", "GLOBAL", "CONSTANT", "SECTION", "VOLATILE", "TO",
2597 "DOTDOTDOT", "NULL_TOK", "UNDEF", "CONST", "INTERNAL", "LINKONCE",
2598 "WEAK", "APPENDING", "DLLIMPORT", "DLLEXPORT", "EXTERN_WEAK", "OPAQUE",
2599 "NOT", "EXTERNAL", "TARGET", "TRIPLE", "ENDIAN", "POINTERSIZE", "LITTLE",
2600 "BIG", "ALIGN", "DEPLIBS", "CALL", "TAIL", "ASM_TOK", "MODULE",
2601 "SIDEEFFECT", "CC_TOK", "CCC_TOK", "CSRETCC_TOK", "FASTCC_TOK",
2602 "COLDCC_TOK", "X86_STDCALLCC_TOK", "X86_FASTCALLCC_TOK", "DATALAYOUT",
2603 "RET", "BR", "SWITCH", "INVOKE", "UNREACHABLE", "UNWIND", "EXCEPT",
2604 "ADD", "SUB", "MUL", "DIV", "UDIV", "SDIV", "FDIV", "REM", "UREM",
2605 "SREM", "FREM", "AND", "OR", "XOR", "SHL", "SHR", "ASHR", "LSHR",
2606 "SETLE", "SETGE", "SETLT", "SETGT", "SETEQ", "SETNE", "ICMP", "FCMP",
2607 "MALLOC", "ALLOCA", "FREE", "LOAD", "STORE", "GETELEMENTPTR", "PHI_TOK",
2608 "SELECT", "VAARG", "EXTRACTELEMENT", "INSERTELEMENT", "SHUFFLEVECTOR",
2609 "VAARG_old", "VANEXT_old", "EQ", "NE", "SLT", "SGT", "SLE", "SGE", "ULT",
2610 "UGT", "ULE", "UGE", "OEQ", "ONE", "OLT", "OGT", "OLE", "OGE", "ORD",
2611 "UNO", "UEQ", "UNE", "CAST", "TRUNC", "ZEXT", "SEXT", "FPTRUNC", "FPEXT",
2612 "FPTOUI", "FPTOSI", "UITOFP", "SITOFP", "PTRTOINT", "INTTOPTR",
2613 "BITCAST", "'='", "','", "'\\\\'", "'('", "')'", "'['", "'x'", "']'",
2614 "'<'", "'>'", "'{'", "'}'", "'*'", "'c'", "$accept", "INTVAL",
2615 "EINT64VAL", "ArithmeticOps", "LogicalOps", "SetCondOps", "IPredicates",
2616 "FPredicates", "ShiftOps", "CastOps", "SIntType", "UIntType", "IntType",
2617 "FPType", "OptAssign", "OptLinkage", "OptCallingConv", "OptAlign",
2618 "OptCAlign", "SectionString", "OptSection", "GlobalVarAttributes",
2619 "GlobalVarAttribute", "TypesV", "UpRTypesV", "Types", "PrimType",
2620 "UpRTypes", "TypeListI", "ArgTypeListI", "ConstVal", "ConstExpr",
2621 "ConstVector", "GlobalType", "Module", "FunctionList", "ConstPool", "@1",
2622 "@2", "@3", "@4", "AsmBlock", "BigOrLittle", "TargetDefinition",
2623 "LibrariesDefinition", "LibList", "Name", "OptName", "ArgVal",
2624 "ArgListH", "ArgList", "FunctionHeaderH", "BEGIN", "FunctionHeader",
2625 "@5", "END", "Function", "FnDeclareLinkage", "FunctionProto", "@6", "@7",
2626 "OptSideEffect", "ConstValueRef", "SymbolicValueRef", "ValueRef",
2627 "ResolvedVal", "BasicBlockList", "BasicBlock", "InstructionList",
2628 "Unwind", "BBTerminatorInst", "JumpTable", "Inst", "PHIList",
2629 "ValueRefList", "ValueRefListE", "OptTailCall", "InstVal", "IndexList",
2630 "OptVolatile", "MemoryInst", 0
2631};
2632#endif
2633
2634# ifdef YYPRINT
2635/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
2636 token YYLEX-NUM. */
2637static const yytype_uint16 yytoknum[] =
2638{
2639 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
2640 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
2641 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
2642 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
2643 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
2644 305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
2645 315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
2646 325, 326, 327, 328, 329, 330, 331, 332, 333, 334,
2647 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
2648 345, 346, 347, 348, 349, 350, 351, 352, 353, 354,
2649 355, 356, 357, 358, 359, 360, 361, 362, 363, 364,
2650 365, 366, 367, 368, 369, 370, 371, 372, 373, 374,
2651 375, 376, 377, 378, 379, 380, 381, 382, 383, 384,
2652 385, 386, 387, 388, 389, 390, 391, 392, 393, 394,
2653 395, 396, 397, 398, 399, 400, 401, 402, 403, 404,
2654 405, 406, 61, 44, 92, 40, 41, 91, 120, 93,
2655 60, 62, 123, 125, 42, 99
2656};
2657# endif
2658
2659/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
2660static const yytype_uint8 yyr1[] =
2661{
2662 0, 166, 167, 167, 168, 168, 169, 169, 169, 169,
2663 169, 169, 169, 169, 169, 169, 169, 170, 170, 170,
2664 171, 171, 171, 171, 171, 171, 172, 172, 172, 172,
2665 172, 172, 172, 172, 172, 172, 173, 173, 173, 173,
2666 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
2667 173, 173, 174, 174, 174, 174, 175, 175, 175, 175,
2668 175, 175, 175, 175, 175, 175, 175, 175, 175, 176,
2669 176, 176, 176, 177, 177, 177, 177, 178, 178, 179,
2670 179, 180, 180, 181, 181, 181, 181, 181, 181, 181,
2671 181, 182, 182, 182, 182, 182, 182, 182, 182, 183,
2672 183, 184, 184, 185, 186, 186, 187, 187, 188, 188,
2673 189, 189, 190, 190, 191, 192, 192, 192, 192, 192,
2674 192, 192, 192, 192, 192, 192, 192, 193, 193, 193,
2675 193, 193, 193, 193, 193, 193, 193, 193, 193, 194,
2676 194, 195, 195, 195, 195, 196, 196, 196, 196, 196,
2677 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
2678 196, 196, 196, 197, 197, 197, 197, 197, 197, 197,
2679 197, 197, 197, 197, 197, 198, 198, 199, 199, 200,
2680 201, 201, 201, 201, 201, 202, 202, 202, 203, 202,
2681 204, 202, 205, 202, 206, 202, 202, 202, 202, 207,
2682 208, 208, 209, 209, 209, 209, 210, 211, 211, 211,
2683 212, 212, 213, 213, 214, 215, 215, 216, 216, 216,
2684 216, 217, 218, 218, 220, 219, 221, 221, 222, 223,
2685 223, 223, 225, 226, 224, 227, 227, 228, 228, 228,
2686 228, 228, 228, 228, 228, 228, 228, 228, 229, 229,
2687 230, 230, 231, 232, 232, 233, 234, 234, 234, 235,
2688 235, 236, 236, 236, 236, 236, 236, 236, 236, 236,
2689 237, 237, 238, 239, 239, 240, 240, 241, 241, 242,
2690 242, 243, 243, 243, 243, 243, 243, 243, 243, 243,
2691 243, 243, 243, 243, 243, 243, 243, 243, 243, 244,
2692 244, 245, 245, 246, 246, 246, 246, 246, 246, 246,
2693 246
2694};
2695
2696/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
2697static const yytype_uint8 yyr2[] =
2698{
2699 0, 2, 1, 1, 1, 1, 1, 1, 1, 1,
2700 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2701 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2702 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2703 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2704 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2705 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2706 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2707 1, 2, 0, 1, 1, 1, 1, 1, 1, 1,
2708 0, 0, 1, 1, 1, 1, 1, 1, 2, 0,
2709 2, 0, 3, 2, 0, 1, 0, 3, 1, 2,
2710 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2711 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2712 2, 4, 5, 5, 3, 2, 5, 4, 2, 1,
2713 3, 1, 3, 1, 0, 4, 3, 3, 4, 4,
2714 3, 6, 5, 2, 2, 2, 2, 2, 2, 2,
2715 2, 2, 2, 6, 5, 8, 6, 6, 6, 7,
2716 7, 6, 6, 8, 8, 3, 1, 1, 1, 1,
2717 2, 2, 4, 2, 1, 4, 2, 4, 0, 7,
2718 0, 7, 0, 7, 0, 7, 3, 4, 0, 1,
2719 1, 1, 3, 3, 3, 3, 3, 3, 1, 0,
2720 1, 1, 1, 0, 2, 3, 1, 1, 3, 1,
2721 0, 8, 1, 1, 0, 4, 1, 1, 2, 0,
2722 1, 1, 0, 0, 5, 0, 1, 1, 1, 1,
2723 1, 1, 1, 1, 1, 3, 1, 5, 1, 1,
2724 1, 1, 2, 2, 2, 3, 2, 0, 1, 1,
2725 1, 2, 2, 3, 9, 9, 8, 13, 1, 1,
2726 6, 5, 2, 6, 7, 1, 3, 1, 0, 2,
2727 1, 5, 5, 5, 6, 6, 2, 4, 4, 6,
2728 4, 4, 4, 4, 6, 6, 2, 7, 1, 2,
2729 0, 1, 0, 3, 6, 3, 6, 2, 4, 6,
2730 4
2731};
2732
2733/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
2734 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
2735 means the default is an error. */
2736static const yytype_uint16 yydefact[] =
2737{
2738 198, 0, 90, 184, 1, 183, 232, 83, 84, 85,
2739 86, 87, 88, 89, 0, 224, 257, 180, 181, 257,
2740 210, 211, 0, 0, 0, 90, 0, 186, 229, 0,
2741 91, 258, 254, 82, 226, 227, 228, 253, 0, 0,
2742 0, 0, 196, 0, 0, 0, 0, 0, 0, 0,
2743 81, 230, 231, 233, 199, 182, 0, 92, 93, 94,
2744 95, 96, 97, 0, 0, 302, 256, 0, 0, 0,
2745 0, 209, 197, 187, 2, 3, 111, 115, 116, 117,
2746 118, 119, 120, 121, 122, 123, 124, 125, 126, 128,
2747 0, 0, 0, 0, 248, 185, 0, 110, 127, 114,
2748 249, 129, 177, 178, 0, 0, 0, 0, 91, 98,
2749 0, 222, 223, 225, 301, 0, 280, 0, 0, 0,
2750 0, 91, 269, 259, 260, 6, 7, 8, 9, 10,
2751 11, 12, 13, 14, 15, 16, 17, 18, 19, 52,
2752 53, 54, 55, 20, 21, 22, 23, 24, 25, 0,
2753 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2754 0, 0, 0, 68, 56, 57, 58, 59, 60, 61,
2755 62, 63, 64, 65, 66, 67, 0, 0, 0, 0,
2756 0, 268, 255, 91, 272, 0, 298, 204, 201, 200,
2757 202, 203, 205, 208, 0, 130, 0, 0, 0, 113,
2758 135, 139, 0, 144, 138, 192, 194, 190, 115, 116,
2759 117, 118, 119, 120, 121, 122, 123, 124, 125, 0,
2760 0, 0, 0, 188, 234, 0, 0, 286, 279, 262,
2761 261, 0, 0, 72, 76, 71, 75, 70, 74, 69,
2762 73, 77, 78, 0, 0, 26, 27, 28, 29, 30,
2763 31, 32, 33, 34, 35, 0, 50, 51, 46, 47,
2764 48, 49, 36, 37, 38, 39, 40, 41, 42, 43,
2765 44, 45, 0, 101, 101, 307, 0, 0, 296, 0,
2766 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2767 0, 0, 0, 0, 0, 206, 0, 0, 0, 0,
2768 0, 134, 143, 141, 0, 106, 106, 106, 160, 161,
2769 4, 5, 158, 159, 162, 157, 153, 154, 0, 0,
2770 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2771 0, 0, 0, 0, 156, 155, 106, 220, 237, 238,
2772 239, 244, 240, 241, 242, 243, 235, 0, 246, 251,
2773 250, 252, 0, 263, 0, 0, 0, 0, 0, 303,
2774 0, 305, 300, 0, 0, 0, 0, 0, 0, 0,
2775 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2776 207, 112, 112, 137, 0, 140, 0, 131, 0, 193,
2777 195, 191, 0, 0, 0, 0, 0, 0, 0, 146,
2778 176, 0, 0, 0, 150, 0, 147, 0, 0, 0,
2779 0, 0, 189, 219, 213, 216, 217, 0, 236, 0,
2780 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2781 310, 0, 0, 0, 290, 293, 0, 0, 291, 292,
2782 0, 0, 0, 287, 288, 0, 308, 0, 132, 133,
2783 136, 142, 0, 0, 108, 106, 0, 0, 300, 0,
2784 0, 0, 0, 0, 145, 135, 114, 0, 148, 149,
2785 0, 0, 0, 0, 0, 212, 214, 0, 104, 0,
2786 245, 0, 0, 278, 0, 0, 101, 102, 101, 275,
2787 299, 0, 0, 0, 0, 0, 281, 282, 283, 278,
2788 0, 103, 109, 107, 0, 0, 0, 0, 0, 0,
2789 0, 175, 152, 0, 0, 0, 0, 0, 0, 218,
2790 215, 105, 99, 0, 0, 0, 277, 0, 284, 285,
2791 0, 304, 306, 0, 0, 0, 289, 294, 295, 0,
2792 309, 0, 0, 164, 0, 0, 0, 0, 151, 0,
2793 0, 0, 0, 0, 0, 221, 247, 0, 0, 0,
2794 276, 273, 0, 297, 0, 0, 0, 172, 0, 0,
2795 166, 167, 168, 171, 163, 100, 0, 266, 0, 0,
2796 0, 274, 169, 170, 0, 0, 0, 264, 0, 265,
2797 0, 0, 165, 173, 174, 0, 0, 0, 0, 0,
2798 0, 271, 0, 0, 270, 267
2799};
2800
2801/* YYDEFGOTO[NTERM-NUM]. */
2802static const yytype_int16 yydefgoto[] =
2803{
2804 -1, 94, 312, 329, 330, 331, 255, 272, 332, 333,
2805 219, 220, 243, 221, 25, 15, 63, 555, 359, 454,
2806 522, 389, 455, 95, 96, 222, 98, 99, 202, 304,
2807 400, 348, 401, 104, 1, 2, 3, 336, 307, 305,
2808 306, 55, 190, 42, 72, 194, 100, 476, 415, 416,
2809 417, 64, 113, 16, 30, 36, 17, 53, 18, 28,
2810 108, 419, 349, 101, 351, 489, 19, 32, 33, 181,
2811 182, 579, 66, 278, 526, 527, 183, 184, 430, 185,
2812 186
2813};
2814
2815/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
2816 STATE-NUM. */
2817#define YYPACT_NINF -542
2818static const yytype_int16 yypact[] =
2819{
2820 -542, 13, 162, 567, -542, -542, -542, -542, -542, -542,
2821 -542, -542, -542, -542, 83, -542, 19, -542, -542, -14,
2822 -542, -542, 50, -87, 87, 233, 27, -542, 123, 141,
2823 175, -542, -542, 98, -542, -542, -542, -542, 33, 40,
2824 66, 68, -542, 14, 141, 1265, 156, 156, 156, 156,
2825 -542, -542, -542, -542, -542, -542, 221, -542, -542, -542,
2826 -542, -542, -542, 1265, -19, 1479, -542, 204, 135, 226,
2827 227, 235, -542, -542, -542, -542, 81, -542, -542, -542,
2828 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2829 256, 257, 4, 15, -542, -542, 108, -542, -542, 12,
2830 -542, -542, -542, -542, 1306, 1306, 1306, 1326, 175, -542,
2831 98, -542, -542, -542, -542, 1306, -542, 205, 1367, 116,
2832 479, 175, -542, -542, -542, -542, -542, -542, -542, -542,
2833 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2834 -542, -542, -542, -542, -542, -542, -542, -542, -542, 355,
2835 429, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306,
2836 1306, 1306, 1306, -542, -542, -542, -542, -542, -542, -542,
2837 -542, -542, -542, -542, -542, -542, 1306, 1306, 1306, 1306,
2838 1306, -542, -542, 175, -542, 86, -542, -542, -542, -542,
2839 -542, -542, -542, -542, -13, -542, 110, 111, 75, -542,
2840 -542, 12, -81, 1046, -542, -542, -542, -542, 174, 208,
2841 266, 210, 267, 212, 268, 230, 277, 275, 278, 246,
2842 280, 279, 566, -542, -542, 136, 766, -542, -542, 81,
2843 -542, 766, 766, -542, -542, -542, -542, -542, -542, -542,
2844 -542, -542, -542, 766, 1265, -542, -542, -542, -542, -542,
2845 -542, -542, -542, -542, -542, 1306, -542, -542, -542, -542,
2846 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2847 -542, -542, 1306, 137, 145, -542, 766, 132, 146, 147,
2848 148, 149, 151, 152, 158, 160, 766, 766, 766, 161,
2849 281, 1265, 1306, 1306, 291, -542, 1306, 1306, 155, -27,
2850 1306, -542, -542, 165, 163, 176, 176, 176, -542, -542,
2851 -542, -542, -542, -542, -542, -542, -542, -542, 355, 429,
2852 172, 177, 178, 179, 182, 1087, 1387, 529, 311, 184,
2853 185, 186, 188, 189, -542, -542, 176, 1107, -542, -542,
2854 -542, -542, -542, -542, -542, -542, 282, 1326, -542, -542,
2855 -542, -542, 193, -542, 194, 766, 766, 766, 7, -542,
2856 20, -542, 195, 766, 192, 1306, 1306, 1306, 1306, 1306,
2857 1306, 1306, 200, 201, 206, 1306, 1306, 766, 766, 207,
2858 -542, -59, -149, -542, 196, 12, 1148, -542, 44, -542,
2859 -542, -542, 203, 211, 1326, 1326, 1326, 1326, 1326, -542,
2860 -542, -8, 741, -82, -542, 10, -542, 1326, 1326, 1326,
2861 1326, 1326, -542, -542, 98, -542, 214, 209, -542, 337,
2862 -34, 342, 348, 215, 218, 219, 766, 371, 766, 1306,
2863 -542, 223, 766, 224, -542, -542, 225, 234, -542, -542,
2864 766, 766, 766, -542, -542, 228, -542, 1306, -542, -542,
2865 -542, -542, 362, 375, -542, 176, 1326, 1326, 195, 236,
2866 237, 240, 243, 1326, -542, 238, -25, 11, -542, -542,
2867 244, 245, 247, 250, 352, -542, -542, 1205, 370, 252,
2868 -542, 766, 766, 1306, 766, 766, 258, -542, 258, -542,
2869 259, 766, 264, 1306, 1306, 1306, -542, -542, -542, 1306,
2870 766, -542, -542, -542, 270, 271, 263, 1326, 1326, 1326,
2871 1326, -542, -542, 260, 1326, 1326, 1326, 1326, 1306, -542,
2872 -542, -542, 368, 402, 274, 276, 259, 287, -542, -542,
2873 374, -542, -542, 1306, 285, 766, -542, -542, -542, 290,
2874 -542, 1326, 1326, -542, 283, 295, 284, 294, -542, 296,
2875 297, 299, 302, 303, 430, -542, -542, 414, 41, 425,
2876 -542, -542, 305, -542, 306, 310, 1326, -542, 1326, 1326,
2877 -542, -542, -542, -542, -542, -542, 766, -542, 893, 144,
2878 448, -542, -542, -542, 314, 315, 316, -542, 331, -542,
2879 893, 766, -542, -542, -542, 464, 334, 180, 766, 481,
2880 482, -542, 766, 766, -542, -542
2881};
2882
2883/* YYPGOTO[NTERM-NUM]. */
2884static const yytype_int16 yypgoto[] =
2885{
2886 -542, -542, -542, 435, 439, 441, 191, 197, 442, 445,
2887 -119, -116, -541, -542, 478, 489, -107, -542, -267, 37,
2888 -542, -238, -542, -60, -542, -45, -542, -74, -51, -542,
2889 -101, 300, -252, 134, -542, -542, -542, -542, -542, -542,
2890 -542, 473, -542, -542, -542, -542, 8, -542, 46, -542,
2891 -542, 410, -542, -542, -542, -542, -542, -542, 518, -542,
2892 -542, -542, -528, 142, -90, -113, -542, 505, -542, -72,
2893 -542, -542, -542, -542, 97, 28, -542, -542, 70, -542,
2894 -542
2895};
2896
2897/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
2898 positive, shift that token. If negative, reduce the rule which
2899 number is the opposite. If zero, do what YYDEFACT says.
2900 If YYTABLE_NINF, syntax error. */
2901#define YYTABLE_NINF -180
2902static const yytype_int16 yytable[] =
2903{
2904 97, 241, 227, 110, 242, 230, 223, 361, 197, 31,
2905 111, 26, 449, 4, 244, 204, 34, 578, 97, 201,
2906 74, 75, 426, 199, 77, 78, 79, 80, 81, 82,
2907 83, 84, 85, 86, 87, 428, 88, 20, 590, 21,
2908 275, 26, 31, 279, 280, 281, 282, 283, 284, 285,
2909 588, 233, 234, 235, 236, 237, 238, 239, 240, 205,
2910 206, 207, 596, 89, 427, 43, 289, 290, 390, 391,
2911 226, 463, 300, 226, 403, 405, 291, 427, 452, 468,
2912 74, 75, 301, 199, 77, 78, 79, 80, 81, 82,
2913 83, 84, 85, 86, 87, 420, 88, 20, 412, 21,
2914 448, 453, 38, 39, 40, 204, 273, 274, 226, 276,
2915 277, 226, 226, 226, 226, 226, 226, 226, 225, 463,
2916 20, 41, 21, 89, 201, 231, 300, 480, -139, 201,
2917 -112, 286, 287, 288, 226, 226, 384, 232, -139, 204,
2918 294, 352, 353, 112, 29, 463, 295, 299, 44, 35,
2919 467, 464, 303, 354, 233, 234, 235, 236, 237, 238,
2920 239, 240, -179, 463, 463, 54, 198, -112, 51, 90,
2921 52, 71, 91, 469, 513, 92, 204, 93, 200, 50,
2922 379, 105, 106, 107, 355, 67, 362, 5, 102, 103,
2923 188, 189, 68, 6, 292, 293, 372, 373, 374, 97,
2924 577, 308, 309, 7, 8, 9, 10, 11, 12, 13,
2925 356, -72, -72, -71, -71, -70, -70, 503, 69, 531,
2926 70, 532, 381, 382, 14, 109, 385, 357, 187, 90,
2927 191, 377, 91, -69, -69, 92, -113, 93, 298, 56,
2928 57, 58, 59, 60, 61, 62, 97, 378, 226, 310,
2929 311, 192, 433, 45, 435, 436, 437, 123, 124, 193,
2930 195, 196, 443, 203, 228, 423, 424, 425, 296, 297,
2931 -76, -75, -74, 431, 7, 8, 9, 10, 46, 12,
2932 47, -73, -79, 48, 313, -80, 314, 445, 446, 363,
2933 358, 337, 414, 458, 459, 460, 461, 462, 360, 364,
2934 365, 366, 367, 589, 368, 369, 470, 471, 472, 473,
2935 474, 370, 385, 371, 375, 380, 383, 376, 386, 387,
2936 226, 434, 226, 226, 226, 438, 439, 394, 466, 388,
2937 226, 444, 395, 396, 397, 406, 486, 398, 488, 407,
2938 408, 409, 492, 410, 411, 418, 421, 422, 429, 432,
2939 496, 497, 498, 440, 441, 504, 505, 450, 456, 442,
2940 447, 479, 511, 481, 335, 478, 457, 477, 350, 482,
2941 483, 484, 485, 350, 350, 487, 491, 493, 494, 502,
2942 536, 537, 538, 499, 226, 350, 501, 495, 518, 507,
2943 508, 524, 525, 509, 528, 529, 510, 514, 515, 512,
2944 516, 534, 500, 517, 452, 523, 544, 545, 546, 547,
2945 540, 530, 533, 549, 550, 551, 552, 535, 350, 543,
2946 560, 548, 475, 541, 542, 554, 556, 557, 350, 350,
2947 350, 427, 414, 558, 575, 576, 566, 568, 226, 241,
2948 564, 565, 242, 559, 561, 562, 563, 569, 226, 226,
2949 226, 567, 570, 571, 226, 572, 256, 257, 573, 574,
2950 241, 580, 582, 242, 581, 584, 583, 585, 586, 591,
2951 592, 593, 594, 553, 245, 246, 247, 248, 249, 250,
2952 251, 252, 253, 254, 595, 598, 587, 599, 226, 233,
2953 234, 235, 236, 237, 238, 239, 240, 350, 350, 350,
2954 176, 597, 602, 603, 177, 350, 178, 179, 601, 392,
2955 180, 65, 604, 605, 49, 521, 393, 73, 224, 350,
2956 350, 27, 334, 520, 37, 600, 490, 539, 506, 0,
2957 0, 0, 0, 0, 74, 75, 0, 199, 208, 209,
2958 210, 211, 212, 213, 214, 215, 216, 217, 218, 0,
2959 88, 20, 0, 21, 258, 259, 260, 261, 262, 263,
2960 264, 265, 266, 267, 268, 269, 270, 271, 350, 0,
2961 350, 74, 75, 0, 350, 0, 0, 89, 0, 0,
2962 0, 0, 350, 350, 350, 0, 0, -82, 20, 20,
2963 21, 21, 315, 0, 0, 0, 0, 0, 6, -82,
2964 -82, 0, 0, 0, 316, 317, 0, 0, -82, -82,
2965 -82, -82, -82, -82, -82, 0, 0, -82, 22, 0,
2966 0, 0, 0, 350, 350, 23, 350, 350, 0, 24,
2967 0, 0, 0, 350, 0, 0, 0, 0, 0, 0,
2968 0, 0, 350, 0, 0, 125, 126, 127, 128, 129,
2969 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
2970 140, 141, 142, 143, 144, 145, 146, 147, 148, 318,
2971 319, 0, 0, 0, 0, 0, 320, 350, 321, 0,
2972 322, 323, 324, 90, 0, 0, 91, 0, 0, 92,
2973 0, 93, 404, 0, 0, 0, 0, 0, 0, 0,
2974 0, 0, 0, 0, 0, 163, 164, 165, 166, 167,
2975 168, 169, 170, 171, 172, 173, 174, 175, 350, 0,
2976 0, 0, 0, 325, 0, 0, 326, 0, 327, 0,
2977 0, 328, 0, 350, 0, 0, 0, 0, 0, 0,
2978 350, 0, 0, 0, 350, 350, 74, 75, 0, 199,
2979 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
2980 218, 0, 88, 20, 0, 21, 0, 0, 0, 338,
2981 339, 74, 75, 340, 0, 0, 0, 0, 0, 0,
2982 0, 0, 0, 0, 0, 0, 0, 0, 20, 89,
2983 21, 0, 341, 342, 343, 0, 0, 0, 0, 0,
2984 0, 0, 0, 0, 344, 345, 0, 0, 0, 0,
2985 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2986 0, 0, 0, 0, 0, 0, 0, 346, 0, 0,
2987 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2988 0, 0, 0, 0, 0, 125, 126, 127, 128, 129,
2989 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
2990 140, 141, 142, 143, 144, 145, 146, 147, 148, 318,
2991 319, 0, 0, 0, 0, 0, 320, 0, 321, 0,
2992 322, 323, 324, 0, 0, 0, 0, 0, 0, 0,
2993 0, 0, 0, 0, 0, 90, 338, 339, 91, 0,
2994 340, 92, 0, 93, 465, 163, 164, 165, 166, 167,
2995 168, 169, 170, 171, 172, 173, 174, 175, 0, 341,
2996 342, 343, 0, 0, 0, 0, 347, 0, 0, 0,
2997 0, 344, 345, 0, 0, 0, 0, 0, 0, 0,
2998 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2999 0, 0, 0, 0, 346, 0, 0, 0, 0, 0,
3000 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3001 0, 0, 125, 126, 127, 128, 129, 130, 131, 132,
3002 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
3003 143, 144, 145, 146, 147, 148, 318, 319, 0, 0,
3004 0, 0, 0, 320, 0, 321, 0, 322, 323, 324,
3005 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3006 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3007 0, 0, 163, 164, 165, 166, 167, 168, 169, 170,
3008 171, 172, 173, 174, 175, 0, 0, 0, 0, 0,
3009 0, 74, 75, 347, 199, 77, 78, 79, 80, 81,
3010 82, 83, 84, 85, 86, 87, 0, 88, 20, 0,
3011 21, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3012 0, 0, 0, 302, 0, 0, 0, 0, 0, 0,
3013 0, 0, 74, 75, 89, 199, 208, 209, 210, 211,
3014 212, 213, 214, 215, 216, 217, 218, 0, 88, 20,
3015 0, 21, 74, 75, 0, 199, 77, 78, 79, 80,
3016 81, 82, 83, 84, 85, 86, 87, 0, 88, 20,
3017 0, 21, 0, 0, 0, 89, 0, 0, 0, 0,
3018 0, 0, 0, 0, 413, 0, 0, 0, 0, 0,
3019 0, 0, 0, 74, 75, 89, 199, 77, 78, 79,
3020 80, 81, 82, 83, 84, 85, 86, 87, 0, 88,
3021 20, 0, 21, 0, 0, 0, 0, 0, 0, 0,
3022 0, 0, 0, 0, 0, 451, 0, 0, 0, 0,
3023 0, 0, 0, 0, 0, 0, 89, 0, 0, 0,
3024 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
3025 74, 75, 0, 199, 77, 78, 79, 80, 81, 82,
3026 83, 84, 85, 86, 87, 0, 88, 20, 0, 21,
3027 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3028 0, 90, 519, 0, 91, 0, 399, 92, 0, 93,
3029 0, 0, 0, 89, 0, 0, 0, 0, 0, 0,
3030 0, 90, 0, 0, 91, 0, 0, 92, 0, 93,
3031 74, 75, 0, 76, 77, 78, 79, 80, 81, 82,
3032 83, 84, 85, 86, 87, 0, 88, 20, 0, 21,
3033 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3034 0, 0, 90, 0, 0, 91, 0, 0, 92, 0,
3035 93, 74, 75, 89, 199, 77, 78, 79, 80, 81,
3036 82, 83, 84, 85, 86, 87, 0, 88, 20, 0,
3037 21, 74, 75, 0, 199, 208, 209, 210, 211, 212,
3038 213, 214, 215, 216, 217, 218, 0, 88, 20, 0,
3039 21, 0, 0, 0, 89, 0, 0, 0, 0, 90,
3040 0, 0, 91, 0, 0, 92, 0, 93, 0, 0,
3041 0, 0, 74, 75, 89, 229, 77, 78, 79, 80,
3042 81, 82, 83, 84, 85, 86, 87, 0, 88, 20,
3043 0, 21, 74, 75, 0, 199, 208, 209, 210, 211,
3044 212, 213, 214, 215, 216, 217, 218, 0, 88, 20,
3045 0, 21, 0, 0, 0, 89, 0, 0, 0, 90,
3046 0, 0, 91, 0, 0, 92, 0, 93, 0, 0,
3047 0, 0, 0, 0, 0, 89, 0, 0, 0, 0,
3048 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3049 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3050 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
3051 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3052 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
3053 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3054 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3055 0, 0, 0, 0, 114, 0, 0, 0, 0, 0,
3056 0, 90, 0, 0, 91, 0, 0, 92, 115, 93,
3057 0, 0, 0, 0, 0, 0, 0, 0, 116, 117,
3058 0, 90, 0, 0, 91, 0, 0, 92, 0, 402,
3059 0, 118, 119, 120, 121, 122, 123, 124, 125, 126,
3060 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
3061 137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
3062 147, 148, 149, 150, 151, 152, 153, 0, 0, 154,
3063 155, 156, 157, 158, 159, 160, 161, 162, 0, 0,
3064 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3065 0, 0, 0, 0, 0, 0, 0, 0, 163, 164,
3066 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
3067 175
3068};
3069
3070static const yytype_int16 yycheck[] =
3071{
3072 45, 120, 115, 63, 120, 118, 107, 274, 4, 23,
3073 29, 3, 161, 0, 121, 164, 30, 558, 63, 93,
3074 5, 6, 15, 8, 9, 10, 11, 12, 13, 14,
3075 15, 16, 17, 18, 19, 15, 21, 22, 579, 24,
3076 153, 33, 23, 156, 157, 158, 159, 160, 161, 162,
3077 578, 10, 11, 12, 13, 14, 15, 16, 17, 104,
3078 105, 106, 590, 48, 57, 152, 179, 180, 306, 307,
3079 115, 153, 153, 118, 326, 327, 183, 57, 34, 161,
3080 5, 6, 163, 8, 9, 10, 11, 12, 13, 14,
3081 15, 16, 17, 18, 19, 347, 21, 22, 336, 24,
3082 159, 57, 52, 53, 54, 164, 151, 152, 153, 154,
3083 155, 156, 157, 158, 159, 160, 161, 162, 110, 153,
3084 22, 71, 24, 48, 198, 9, 153, 161, 153, 203,
3085 155, 176, 177, 178, 179, 180, 163, 21, 163, 164,
3086 153, 231, 232, 162, 61, 153, 159, 198, 61, 163,
3087 402, 159, 203, 243, 10, 11, 12, 13, 14, 15,
3088 16, 17, 0, 153, 153, 24, 162, 155, 45, 154,
3089 47, 157, 157, 163, 163, 160, 164, 162, 163, 152,
3090 293, 47, 48, 49, 244, 152, 276, 25, 32, 33,
3091 55, 56, 152, 31, 108, 109, 286, 287, 288, 244,
3092 159, 27, 28, 41, 42, 43, 44, 45, 46, 47,
3093 255, 3, 4, 3, 4, 3, 4, 455, 152, 486,
3094 152, 488, 296, 297, 62, 4, 300, 272, 24, 154,
3095 4, 291, 157, 3, 4, 160, 155, 162, 163, 64,
3096 65, 66, 67, 68, 69, 70, 291, 292, 293, 3,
3097 4, 24, 365, 20, 367, 368, 369, 77, 78, 24,
3098 4, 4, 375, 155, 59, 355, 356, 357, 158, 158,
3099 4, 4, 4, 363, 41, 42, 43, 44, 45, 46,
3100 47, 4, 7, 50, 4, 7, 7, 377, 378, 157,
3101 153, 155, 337, 394, 395, 396, 397, 398, 153, 153,
3102 153, 153, 153, 159, 153, 153, 407, 408, 409, 410,
3103 411, 153, 386, 153, 153, 24, 161, 36, 153, 156,
3104 365, 366, 367, 368, 369, 370, 371, 155, 402, 153,
3105 375, 376, 155, 155, 155, 24, 426, 155, 428, 155,
3106 155, 155, 432, 155, 155, 63, 153, 153, 153, 157,
3107 440, 441, 442, 153, 153, 456, 457, 161, 155, 153,
3108 153, 24, 463, 21, 222, 156, 155, 153, 226, 21,
3109 155, 153, 153, 231, 232, 4, 153, 153, 153, 4,
3110 493, 494, 495, 155, 429, 243, 24, 153, 36, 153,
3111 153, 481, 482, 153, 484, 485, 153, 153, 153, 161,
3112 153, 491, 447, 153, 34, 153, 507, 508, 509, 510,
3113 500, 153, 153, 514, 515, 516, 517, 153, 276, 156,
3114 533, 161, 414, 153, 153, 57, 24, 153, 286, 287,
3115 288, 57, 477, 157, 4, 21, 153, 153, 483, 558,
3116 541, 542, 558, 156, 159, 535, 156, 153, 493, 494,
3117 495, 156, 156, 156, 499, 156, 27, 28, 156, 156,
3118 579, 36, 156, 579, 159, 566, 156, 568, 569, 21,
3119 156, 156, 156, 518, 119, 120, 121, 122, 123, 124,
3120 125, 126, 127, 128, 153, 21, 576, 153, 533, 10,
3121 11, 12, 13, 14, 15, 16, 17, 355, 356, 357,
3122 65, 591, 21, 21, 65, 363, 65, 65, 598, 318,
3123 65, 33, 602, 603, 25, 478, 319, 44, 108, 377,
3124 378, 3, 222, 477, 19, 597, 429, 499, 458, -1,
3125 -1, -1, -1, -1, 5, 6, -1, 8, 9, 10,
3126 11, 12, 13, 14, 15, 16, 17, 18, 19, -1,
3127 21, 22, -1, 24, 125, 126, 127, 128, 129, 130,
3128 131, 132, 133, 134, 135, 136, 137, 138, 426, -1,
3129 428, 5, 6, -1, 432, -1, -1, 48, -1, -1,
3130 -1, -1, 440, 441, 442, -1, -1, 20, 22, 22,
3131 24, 24, 26, -1, -1, -1, -1, -1, 31, 32,
3132 33, -1, -1, -1, 38, 39, -1, -1, 41, 42,
3133 43, 44, 45, 46, 47, -1, -1, 50, 51, -1,
3134 -1, -1, -1, 481, 482, 58, 484, 485, -1, 62,
3135 -1, -1, -1, 491, -1, -1, -1, -1, -1, -1,
3136 -1, -1, 500, -1, -1, 79, 80, 81, 82, 83,
3137 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3138 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3139 104, -1, -1, -1, -1, -1, 110, 535, 112, -1,
3140 114, 115, 116, 154, -1, -1, 157, -1, -1, 160,
3141 -1, 162, 163, -1, -1, -1, -1, -1, -1, -1,
3142 -1, -1, -1, -1, -1, 139, 140, 141, 142, 143,
3143 144, 145, 146, 147, 148, 149, 150, 151, 576, -1,
3144 -1, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3145 -1, 165, -1, 591, -1, -1, -1, -1, -1, -1,
3146 598, -1, -1, -1, 602, 603, 5, 6, -1, 8,
3147 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
3148 19, -1, 21, 22, -1, 24, -1, -1, -1, 3,
3149 4, 5, 6, 7, -1, -1, -1, -1, -1, -1,
3150 -1, -1, -1, -1, -1, -1, -1, -1, 22, 48,
3151 24, -1, 26, 27, 28, -1, -1, -1, -1, -1,
3152 -1, -1, -1, -1, 38, 39, -1, -1, -1, -1,
3153 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3154 -1, -1, -1, -1, -1, -1, -1, 61, -1, -1,
3155 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3156 -1, -1, -1, -1, -1, 79, 80, 81, 82, 83,
3157 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3158 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3159 104, -1, -1, -1, -1, -1, 110, -1, 112, -1,
3160 114, 115, 116, -1, -1, -1, -1, -1, -1, -1,
3161 -1, -1, -1, -1, -1, 154, 3, 4, 157, -1,
3162 7, 160, -1, 162, 163, 139, 140, 141, 142, 143,
3163 144, 145, 146, 147, 148, 149, 150, 151, -1, 26,
3164 27, 28, -1, -1, -1, -1, 160, -1, -1, -1,
3165 -1, 38, 39, -1, -1, -1, -1, -1, -1, -1,
3166 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3167 -1, -1, -1, -1, 61, -1, -1, -1, -1, -1,
3168 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3169 -1, -1, 79, 80, 81, 82, 83, 84, 85, 86,
3170 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
3171 97, 98, 99, 100, 101, 102, 103, 104, -1, -1,
3172 -1, -1, -1, 110, -1, 112, -1, 114, 115, 116,
3173 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3174 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3175 -1, -1, 139, 140, 141, 142, 143, 144, 145, 146,
3176 147, 148, 149, 150, 151, -1, -1, -1, -1, -1,
3177 -1, 5, 6, 160, 8, 9, 10, 11, 12, 13,
3178 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3179 24, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3180 -1, -1, -1, 37, -1, -1, -1, -1, -1, -1,
3181 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
3182 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3183 -1, 24, 5, 6, -1, 8, 9, 10, 11, 12,
3184 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3185 -1, 24, -1, -1, -1, 48, -1, -1, -1, -1,
3186 -1, -1, -1, -1, 37, -1, -1, -1, -1, -1,
3187 -1, -1, -1, 5, 6, 48, 8, 9, 10, 11,
3188 12, 13, 14, 15, 16, 17, 18, 19, -1, 21,
3189 22, -1, 24, -1, -1, -1, -1, -1, -1, -1,
3190 -1, -1, -1, -1, -1, 37, -1, -1, -1, -1,
3191 -1, -1, -1, -1, -1, -1, 48, -1, -1, -1,
3192 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3193 5, 6, -1, 8, 9, 10, 11, 12, 13, 14,
3194 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
3195 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3196 -1, 154, 37, -1, 157, -1, 159, 160, -1, 162,
3197 -1, -1, -1, 48, -1, -1, -1, -1, -1, -1,
3198 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
3199 5, 6, -1, 8, 9, 10, 11, 12, 13, 14,
3200 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
3201 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3202 -1, -1, 154, -1, -1, 157, -1, -1, 160, -1,
3203 162, 5, 6, 48, 8, 9, 10, 11, 12, 13,
3204 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3205 24, 5, 6, -1, 8, 9, 10, 11, 12, 13,
3206 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3207 24, -1, -1, -1, 48, -1, -1, -1, -1, 154,
3208 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
3209 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
3210 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3211 -1, 24, 5, 6, -1, 8, 9, 10, 11, 12,
3212 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3213 -1, 24, -1, -1, -1, 48, -1, -1, -1, 154,
3214 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
3215 -1, -1, -1, -1, -1, 48, -1, -1, -1, -1,
3216 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3217 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3218 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3219 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3220 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3221 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3222 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3223 -1, -1, -1, -1, 35, -1, -1, -1, -1, -1,
3224 -1, 154, -1, -1, 157, -1, -1, 160, 49, 162,
3225 -1, -1, -1, -1, -1, -1, -1, -1, 59, 60,
3226 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
3227 -1, 72, 73, 74, 75, 76, 77, 78, 79, 80,
3228 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
3229 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
3230 101, 102, 103, 104, 105, 106, 107, -1, -1, 110,
3231 111, 112, 113, 114, 115, 116, 117, 118, -1, -1,
3232 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3233 -1, -1, -1, -1, -1, -1, -1, -1, 139, 140,
3234 141, 142, 143, 144, 145, 146, 147, 148, 149, 150,
3235 151
3236};
3237
3238/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
3239 symbol of state STATE-NUM. */
3240static const yytype_uint8 yystos[] =
3241{
3242 0, 200, 201, 202, 0, 25, 31, 41, 42, 43,
3243 44, 45, 46, 47, 62, 181, 219, 222, 224, 232,
3244 22, 24, 51, 58, 62, 180, 212, 224, 225, 61,
3245 220, 23, 233, 234, 30, 163, 221, 233, 52, 53,
3246 54, 71, 209, 152, 61, 20, 45, 47, 50, 181,
3247 152, 45, 47, 223, 24, 207, 64, 65, 66, 67,
3248 68, 69, 70, 182, 217, 180, 238, 152, 152, 152,
3249 152, 157, 210, 207, 5, 6, 8, 9, 10, 11,
3250 12, 13, 14, 15, 16, 17, 18, 19, 21, 48,
3251 154, 157, 160, 162, 167, 189, 190, 191, 192, 193,
3252 212, 229, 32, 33, 199, 199, 199, 199, 226, 4,
3253 189, 29, 162, 218, 35, 49, 59, 60, 72, 73,
3254 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
3255 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3256 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3257 104, 105, 106, 107, 110, 111, 112, 113, 114, 115,
3258 116, 117, 118, 139, 140, 141, 142, 143, 144, 145,
3259 146, 147, 148, 149, 150, 151, 169, 170, 171, 174,
3260 175, 235, 236, 242, 243, 245, 246, 24, 55, 56,
3261 208, 4, 24, 24, 211, 4, 4, 4, 162, 8,
3262 163, 193, 194, 155, 164, 191, 191, 191, 9, 10,
3263 11, 12, 13, 14, 15, 16, 17, 18, 19, 176,
3264 177, 179, 191, 196, 217, 212, 191, 231, 59, 8,
3265 231, 9, 21, 10, 11, 12, 13, 14, 15, 16,
3266 17, 176, 177, 178, 182, 119, 120, 121, 122, 123,
3267 124, 125, 126, 127, 128, 172, 27, 28, 125, 126,
3268 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
3269 137, 138, 173, 191, 191, 231, 191, 191, 239, 231,
3270 231, 231, 231, 231, 231, 231, 191, 191, 191, 231,
3271 231, 182, 108, 109, 153, 159, 158, 158, 163, 194,
3272 153, 163, 37, 194, 195, 205, 206, 204, 27, 28,
3273 3, 4, 168, 4, 7, 26, 38, 39, 103, 104,
3274 110, 112, 114, 115, 116, 157, 160, 162, 165, 169,
3275 170, 171, 174, 175, 197, 229, 203, 155, 3, 4,
3276 7, 26, 27, 28, 38, 39, 61, 160, 197, 228,
3277 229, 230, 230, 230, 230, 189, 191, 191, 153, 184,
3278 153, 184, 230, 157, 153, 153, 153, 153, 153, 153,
3279 153, 153, 230, 230, 230, 153, 36, 189, 191, 231,
3280 24, 193, 193, 161, 163, 193, 153, 156, 153, 187,
3281 187, 187, 172, 173, 155, 155, 155, 155, 155, 159,
3282 196, 198, 162, 198, 163, 198, 24, 155, 155, 155,
3283 155, 155, 187, 37, 191, 214, 215, 216, 63, 227,
3284 198, 153, 153, 230, 230, 230, 15, 57, 15, 153,
3285 244, 230, 157, 231, 191, 231, 231, 231, 191, 191,
3286 153, 153, 153, 231, 191, 230, 230, 153, 159, 161,
3287 161, 37, 34, 57, 185, 188, 155, 155, 196, 196,
3288 196, 196, 196, 153, 159, 163, 193, 198, 161, 163,
3289 196, 196, 196, 196, 196, 212, 213, 153, 156, 24,
3290 161, 21, 21, 155, 153, 153, 230, 4, 230, 231,
3291 240, 153, 230, 153, 153, 153, 230, 230, 230, 155,
3292 191, 24, 4, 187, 196, 196, 244, 153, 153, 153,
3293 153, 196, 161, 163, 153, 153, 153, 153, 36, 37,
3294 214, 185, 186, 153, 230, 230, 240, 241, 230, 230,
3295 153, 184, 184, 153, 230, 153, 231, 231, 231, 241,
3296 230, 153, 153, 156, 196, 196, 196, 196, 161, 196,
3297 196, 196, 196, 191, 57, 183, 24, 153, 157, 156,
3298 231, 159, 230, 156, 196, 196, 153, 156, 153, 153,
3299 156, 156, 156, 156, 156, 4, 21, 159, 178, 237,
3300 36, 159, 156, 156, 196, 196, 196, 230, 228, 159,
3301 178, 21, 156, 156, 156, 153, 228, 230, 21, 153,
3302 235, 230, 21, 21, 230, 230
3303};
David Greene5fd22a82007-09-04 18:46:50 +00003304
Reid Spencere7c3c602006-11-30 06:36:44 +00003305#define yyerrok (yyerrstatus = 0)
3306#define yyclearin (yychar = YYEMPTY)
Chris Lattnercf786592007-12-29 20:47:37 +00003307#define YYEMPTY (-2)
Reid Spencere7c3c602006-11-30 06:36:44 +00003308#define YYEOF 0
Chris Lattnercf786592007-12-29 20:47:37 +00003309
Reid Spencere7c3c602006-11-30 06:36:44 +00003310#define YYACCEPT goto yyacceptlab
Chris Lattnercf786592007-12-29 20:47:37 +00003311#define YYABORT goto yyabortlab
3312#define YYERROR goto yyerrorlab
3313
3314
3315/* Like YYERROR except do call yyerror. This remains here temporarily
3316 to ease the transition to the new meaning of YYERROR, for GCC.
Reid Spencere7c3c602006-11-30 06:36:44 +00003317 Once GCC version 2 has supplanted version 1, this can go. */
Chris Lattnercf786592007-12-29 20:47:37 +00003318
Reid Spencere7c3c602006-11-30 06:36:44 +00003319#define YYFAIL goto yyerrlab
Chris Lattnercf786592007-12-29 20:47:37 +00003320
Reid Spencere7c3c602006-11-30 06:36:44 +00003321#define YYRECOVERING() (!!yyerrstatus)
Chris Lattnercf786592007-12-29 20:47:37 +00003322
3323#define YYBACKUP(Token, Value) \
Reid Spencere7c3c602006-11-30 06:36:44 +00003324do \
3325 if (yychar == YYEMPTY && yylen == 1) \
Chris Lattnercf786592007-12-29 20:47:37 +00003326 { \
3327 yychar = (Token); \
3328 yylval = (Value); \
3329 yytoken = YYTRANSLATE (yychar); \
3330 YYPOPSTACK (1); \
Reid Spencere7c3c602006-11-30 06:36:44 +00003331 goto yybackup; \
3332 } \
3333 else \
Chris Lattnercf786592007-12-29 20:47:37 +00003334 { \
3335 yyerror (YY_("syntax error: cannot back up")); \
3336 YYERROR; \
3337 } \
3338while (YYID (0))
3339
Reid Spencere7c3c602006-11-30 06:36:44 +00003340
Reid Spencere7c3c602006-11-30 06:36:44 +00003341#define YYTERROR 1
3342#define YYERRCODE 256
3343
Chris Lattnercf786592007-12-29 20:47:37 +00003344
3345/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
3346 If N is 0, then set CURRENT to the empty location which ends
3347 the previous symbol: RHS[0] (always defined). */
3348
3349#define YYRHSLOC(Rhs, K) ((Rhs)[K])
3350#ifndef YYLLOC_DEFAULT
3351# define YYLLOC_DEFAULT(Current, Rhs, N) \
3352 do \
3353 if (YYID (N)) \
3354 { \
3355 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
3356 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
3357 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
3358 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
3359 } \
3360 else \
3361 { \
3362 (Current).first_line = (Current).last_line = \
3363 YYRHSLOC (Rhs, 0).last_line; \
3364 (Current).first_column = (Current).last_column = \
3365 YYRHSLOC (Rhs, 0).last_column; \
3366 } \
3367 while (YYID (0))
Reid Spencere7c3c602006-11-30 06:36:44 +00003368#endif
3369
Chris Lattnercf786592007-12-29 20:47:37 +00003370
3371/* YY_LOCATION_PRINT -- Print the location on the stream.
3372 This macro was not mandated originally: define only if we know
3373 we won't break user code: when these are the locations we know. */
3374
3375#ifndef YY_LOCATION_PRINT
3376# if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL
3377# define YY_LOCATION_PRINT(File, Loc) \
3378 fprintf (File, "%d.%d-%d.%d", \
3379 (Loc).first_line, (Loc).first_column, \
3380 (Loc).last_line, (Loc).last_column)
3381# else
3382# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
3383# endif
3384#endif
3385
3386
3387/* YYLEX -- calling `yylex' with the right arguments. */
3388
Reid Spencer950bf602007-01-26 08:19:09 +00003389#ifdef YYLEX_PARAM
Chris Lattnercf786592007-12-29 20:47:37 +00003390# define YYLEX yylex (YYLEX_PARAM)
Reid Spencer950bf602007-01-26 08:19:09 +00003391#else
Chris Lattnercf786592007-12-29 20:47:37 +00003392# define YYLEX yylex ()
Christopher Lamb4374f8e2007-12-17 01:17:35 +00003393#endif
Chris Lattnercf786592007-12-29 20:47:37 +00003394
3395/* Enable debugging if requested. */
3396#if YYDEBUG
3397
3398# ifndef YYFPRINTF
3399# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
3400# define YYFPRINTF fprintf
3401# endif
3402
3403# define YYDPRINTF(Args) \
3404do { \
3405 if (yydebug) \
3406 YYFPRINTF Args; \
3407} while (YYID (0))
3408
3409# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
3410do { \
3411 if (yydebug) \
3412 { \
3413 YYFPRINTF (stderr, "%s ", Title); \
3414 yy_symbol_print (stderr, \
3415 Type, Value); \
3416 YYFPRINTF (stderr, "\n"); \
3417 } \
3418} while (YYID (0))
3419
3420
3421/*--------------------------------.
3422| Print this symbol on YYOUTPUT. |
3423`--------------------------------*/
3424
3425/*ARGSUSED*/
3426#if (defined __STDC__ || defined __C99__FUNC__ \
3427 || defined __cplusplus || defined _MSC_VER)
3428static void
3429yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
Christopher Lamb4374f8e2007-12-17 01:17:35 +00003430#else
Chris Lattnercf786592007-12-29 20:47:37 +00003431static void
3432yy_symbol_value_print (yyoutput, yytype, yyvaluep)
3433 FILE *yyoutput;
3434 int yytype;
3435 YYSTYPE const * const yyvaluep;
Christopher Lamb4374f8e2007-12-17 01:17:35 +00003436#endif
Chris Lattnercf786592007-12-29 20:47:37 +00003437{
3438 if (!yyvaluep)
3439 return;
3440# ifdef YYPRINT
3441 if (yytype < YYNTOKENS)
3442 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
3443# else
3444 YYUSE (yyoutput);
3445# endif
3446 switch (yytype)
3447 {
3448 default:
3449 break;
3450 }
3451}
3452
3453
3454/*--------------------------------.
3455| Print this symbol on YYOUTPUT. |
3456`--------------------------------*/
3457
3458#if (defined __STDC__ || defined __C99__FUNC__ \
3459 || defined __cplusplus || defined _MSC_VER)
3460static void
3461yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
3462#else
3463static void
3464yy_symbol_print (yyoutput, yytype, yyvaluep)
3465 FILE *yyoutput;
3466 int yytype;
3467 YYSTYPE const * const yyvaluep;
Dale Johannesencdd509a2007-09-07 21:07:57 +00003468#endif
Chris Lattnercf786592007-12-29 20:47:37 +00003469{
3470 if (yytype < YYNTOKENS)
3471 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
3472 else
3473 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
Duncan Sandsdc024672007-11-27 13:23:08 +00003474
Chris Lattnercf786592007-12-29 20:47:37 +00003475 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
3476 YYFPRINTF (yyoutput, ")");
3477}
Duncan Sandsdc024672007-11-27 13:23:08 +00003478
Chris Lattnercf786592007-12-29 20:47:37 +00003479/*------------------------------------------------------------------.
3480| yy_stack_print -- Print the state stack from its BOTTOM up to its |
3481| TOP (included). |
3482`------------------------------------------------------------------*/
Duncan Sandsdc024672007-11-27 13:23:08 +00003483
Chris Lattnercf786592007-12-29 20:47:37 +00003484#if (defined __STDC__ || defined __C99__FUNC__ \
3485 || defined __cplusplus || defined _MSC_VER)
3486static void
3487yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
3488#else
3489static void
3490yy_stack_print (bottom, top)
3491 yytype_int16 *bottom;
3492 yytype_int16 *top;
Dale Johannesencdd509a2007-09-07 21:07:57 +00003493#endif
Chris Lattnercf786592007-12-29 20:47:37 +00003494{
3495 YYFPRINTF (stderr, "Stack now");
3496 for (; bottom <= top; ++bottom)
3497 YYFPRINTF (stderr, " %d", *bottom);
3498 YYFPRINTF (stderr, "\n");
3499}
Duncan Sandsdc024672007-11-27 13:23:08 +00003500
Chris Lattnercf786592007-12-29 20:47:37 +00003501# define YY_STACK_PRINT(Bottom, Top) \
3502do { \
3503 if (yydebug) \
3504 yy_stack_print ((Bottom), (Top)); \
3505} while (YYID (0))
Duncan Sandsdc024672007-11-27 13:23:08 +00003506
Chris Lattnercf786592007-12-29 20:47:37 +00003507
3508/*------------------------------------------------.
3509| Report that the YYRULE is going to be reduced. |
3510`------------------------------------------------*/
3511
3512#if (defined __STDC__ || defined __C99__FUNC__ \
3513 || defined __cplusplus || defined _MSC_VER)
3514static void
3515yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
3516#else
3517static void
3518yy_reduce_print (yyvsp, yyrule)
3519 YYSTYPE *yyvsp;
3520 int yyrule;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003521#endif
Chris Lattnercf786592007-12-29 20:47:37 +00003522{
3523 int yynrhs = yyr2[yyrule];
3524 int yyi;
3525 unsigned long int yylno = yyrline[yyrule];
3526 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
3527 yyrule - 1, yylno);
3528 /* The symbols being reduced. */
3529 for (yyi = 0; yyi < yynrhs; yyi++)
3530 {
3531 fprintf (stderr, " $%d = ", yyi + 1);
3532 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
3533 &(yyvsp[(yyi + 1) - (yynrhs)])
3534 );
3535 fprintf (stderr, "\n");
3536 }
3537}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003538
Chris Lattnercf786592007-12-29 20:47:37 +00003539# define YY_REDUCE_PRINT(Rule) \
3540do { \
3541 if (yydebug) \
3542 yy_reduce_print (yyvsp, Rule); \
3543} while (YYID (0))
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003544
Chris Lattnercf786592007-12-29 20:47:37 +00003545/* Nonzero means print parse trace. It is left uninitialized so that
3546 multiple parsers can coexist. */
3547int yydebug;
3548#else /* !YYDEBUG */
3549# define YYDPRINTF(Args)
3550# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
3551# define YY_STACK_PRINT(Bottom, Top)
3552# define YY_REDUCE_PRINT(Rule)
3553#endif /* !YYDEBUG */
3554
3555
3556/* YYINITDEPTH -- initial size of the parser's stacks. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003557#ifndef YYINITDEPTH
Chris Lattnercf786592007-12-29 20:47:37 +00003558# define YYINITDEPTH 200
Reid Spencere7c3c602006-11-30 06:36:44 +00003559#endif
3560
Chris Lattnercf786592007-12-29 20:47:37 +00003561/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
3562 if the built-in stack extension method is used).
Reid Spencere7c3c602006-11-30 06:36:44 +00003563
Chris Lattnercf786592007-12-29 20:47:37 +00003564 Do not make this value too large; the results are undefined if
3565 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
3566 evaluated with infinite-precision integer arithmetic. */
David Greene5fd22a82007-09-04 18:46:50 +00003567
Reid Spencere7c3c602006-11-30 06:36:44 +00003568#ifndef YYMAXDEPTH
Chris Lattnercf786592007-12-29 20:47:37 +00003569# define YYMAXDEPTH 10000
Reid Spencere7c3c602006-11-30 06:36:44 +00003570#endif
Chris Lattnercf786592007-12-29 20:47:37 +00003571
Reid Spencere7c3c602006-11-30 06:36:44 +00003572
3573
Chris Lattnercf786592007-12-29 20:47:37 +00003574#if YYERROR_VERBOSE
Reid Spencere7c3c602006-11-30 06:36:44 +00003575
Chris Lattnercf786592007-12-29 20:47:37 +00003576# ifndef yystrlen
3577# if defined __GLIBC__ && defined _STRING_H
3578# define yystrlen strlen
3579# else
3580/* Return the length of YYSTR. */
3581#if (defined __STDC__ || defined __C99__FUNC__ \
3582 || defined __cplusplus || defined _MSC_VER)
3583static YYSIZE_T
3584yystrlen (const char *yystr)
Duncan Sandsdc024672007-11-27 13:23:08 +00003585#else
Chris Lattnercf786592007-12-29 20:47:37 +00003586static YYSIZE_T
3587yystrlen (yystr)
3588 const char *yystr;
3589#endif
3590{
3591 YYSIZE_T yylen;
3592 for (yylen = 0; yystr[yylen]; yylen++)
3593 continue;
3594 return yylen;
3595}
3596# endif
3597# endif
3598
3599# ifndef yystpcpy
3600# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
3601# define yystpcpy stpcpy
3602# else
3603/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
3604 YYDEST. */
3605#if (defined __STDC__ || defined __C99__FUNC__ \
3606 || defined __cplusplus || defined _MSC_VER)
3607static char *
3608yystpcpy (char *yydest, const char *yysrc)
3609#else
3610static char *
3611yystpcpy (yydest, yysrc)
3612 char *yydest;
3613 const char *yysrc;
3614#endif
3615{
3616 char *yyd = yydest;
3617 const char *yys = yysrc;
3618
3619 while ((*yyd++ = *yys++) != '\0')
3620 continue;
3621
3622 return yyd - 1;
3623}
3624# endif
3625# endif
3626
3627# ifndef yytnamerr
3628/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
3629 quotes and backslashes, so that it's suitable for yyerror. The
3630 heuristic is that double-quoting is unnecessary unless the string
3631 contains an apostrophe, a comma, or backslash (other than
3632 backslash-backslash). YYSTR is taken from yytname. If YYRES is
3633 null, do not copy; instead, return the length of what the result
3634 would have been. */
3635static YYSIZE_T
3636yytnamerr (char *yyres, const char *yystr)
3637{
3638 if (*yystr == '"')
3639 {
3640 YYSIZE_T yyn = 0;
3641 char const *yyp = yystr;
3642
3643 for (;;)
3644 switch (*++yyp)
3645 {
3646 case '\'':
3647 case ',':
3648 goto do_not_strip_quotes;
3649
3650 case '\\':
3651 if (*++yyp != '\\')
3652 goto do_not_strip_quotes;
3653 /* Fall through. */
3654 default:
3655 if (yyres)
3656 yyres[yyn] = *yyp;
3657 yyn++;
3658 break;
3659
3660 case '"':
3661 if (yyres)
3662 yyres[yyn] = '\0';
3663 return yyn;
3664 }
3665 do_not_strip_quotes: ;
3666 }
3667
3668 if (! yyres)
3669 return yystrlen (yystr);
3670
3671 return yystpcpy (yyres, yystr) - yyres;
3672}
3673# endif
3674
3675/* Copy into YYRESULT an error message about the unexpected token
3676 YYCHAR while in state YYSTATE. Return the number of bytes copied,
3677 including the terminating null byte. If YYRESULT is null, do not
3678 copy anything; just return the number of bytes that would be
3679 copied. As a special case, return 0 if an ordinary "syntax error"
3680 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
3681 size calculation. */
3682static YYSIZE_T
3683yysyntax_error (char *yyresult, int yystate, int yychar)
3684{
3685 int yyn = yypact[yystate];
3686
3687 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
3688 return 0;
3689 else
3690 {
3691 int yytype = YYTRANSLATE (yychar);
3692 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
3693 YYSIZE_T yysize = yysize0;
3694 YYSIZE_T yysize1;
3695 int yysize_overflow = 0;
3696 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
3697 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
3698 int yyx;
3699
3700# if 0
3701 /* This is so xgettext sees the translatable formats that are
3702 constructed on the fly. */
3703 YY_("syntax error, unexpected %s");
3704 YY_("syntax error, unexpected %s, expecting %s");
3705 YY_("syntax error, unexpected %s, expecting %s or %s");
3706 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
3707 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
3708# endif
3709 char *yyfmt;
3710 char const *yyf;
3711 static char const yyunexpected[] = "syntax error, unexpected %s";
3712 static char const yyexpecting[] = ", expecting %s";
3713 static char const yyor[] = " or %s";
3714 char yyformat[sizeof yyunexpected
3715 + sizeof yyexpecting - 1
3716 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
3717 * (sizeof yyor - 1))];
3718 char const *yyprefix = yyexpecting;
3719
3720 /* Start YYX at -YYN if negative to avoid negative indexes in
3721 YYCHECK. */
3722 int yyxbegin = yyn < 0 ? -yyn : 0;
3723
3724 /* Stay within bounds of both yycheck and yytname. */
3725 int yychecklim = YYLAST - yyn + 1;
3726 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
3727 int yycount = 1;
3728
3729 yyarg[0] = yytname[yytype];
3730 yyfmt = yystpcpy (yyformat, yyunexpected);
3731
3732 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
3733 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
3734 {
3735 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
3736 {
3737 yycount = 1;
3738 yysize = yysize0;
3739 yyformat[sizeof yyunexpected - 1] = '\0';
3740 break;
3741 }
3742 yyarg[yycount++] = yytname[yyx];
3743 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
3744 yysize_overflow |= (yysize1 < yysize);
3745 yysize = yysize1;
3746 yyfmt = yystpcpy (yyfmt, yyprefix);
3747 yyprefix = yyor;
3748 }
3749
3750 yyf = YY_(yyformat);
3751 yysize1 = yysize + yystrlen (yyf);
3752 yysize_overflow |= (yysize1 < yysize);
3753 yysize = yysize1;
3754
3755 if (yysize_overflow)
3756 return YYSIZE_MAXIMUM;
3757
3758 if (yyresult)
3759 {
3760 /* Avoid sprintf, as that infringes on the user's name space.
3761 Don't have undefined behavior even if the translation
3762 produced a string with the wrong number of "%s"s. */
3763 char *yyp = yyresult;
3764 int yyi = 0;
3765 while ((*yyp = *yyf) != '\0')
3766 {
3767 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
3768 {
3769 yyp += yytnamerr (yyp, yyarg[yyi++]);
3770 yyf += 2;
3771 }
3772 else
3773 {
3774 yyp++;
3775 yyf++;
3776 }
3777 }
3778 }
3779 return yysize;
3780 }
3781}
3782#endif /* YYERROR_VERBOSE */
3783
3784
3785/*-----------------------------------------------.
3786| Release the memory associated to this symbol. |
3787`-----------------------------------------------*/
3788
3789/*ARGSUSED*/
3790#if (defined __STDC__ || defined __C99__FUNC__ \
3791 || defined __cplusplus || defined _MSC_VER)
3792static void
3793yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
3794#else
3795static void
3796yydestruct (yymsg, yytype, yyvaluep)
3797 const char *yymsg;
3798 int yytype;
3799 YYSTYPE *yyvaluep;
3800#endif
3801{
3802 YYUSE (yyvaluep);
3803
3804 if (!yymsg)
3805 yymsg = "Deleting";
3806 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
3807
3808 switch (yytype)
3809 {
3810
3811 default:
3812 break;
3813 }
3814}
3815
3816
3817/* Prevent warnings from -Wmissing-prototypes. */
3818
3819#ifdef YYPARSE_PARAM
3820#if defined __STDC__ || defined __cplusplus
3821int yyparse (void *YYPARSE_PARAM);
3822#else
3823int yyparse ();
3824#endif
3825#else /* ! YYPARSE_PARAM */
3826#if defined __STDC__ || defined __cplusplus
Reid Spencere7c3c602006-11-30 06:36:44 +00003827int yyparse (void);
Christopher Lamb4374f8e2007-12-17 01:17:35 +00003828#else
Chris Lattnercf786592007-12-29 20:47:37 +00003829int yyparse ();
Dale Johannesencdd509a2007-09-07 21:07:57 +00003830#endif
Chris Lattnercf786592007-12-29 20:47:37 +00003831#endif /* ! YYPARSE_PARAM */
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003832
Duncan Sandsdc024672007-11-27 13:23:08 +00003833
Chris Lattnercf786592007-12-29 20:47:37 +00003834
3835/* The look-ahead symbol. */
3836int yychar;
3837
3838/* The semantic value of the look-ahead symbol. */
3839YYSTYPE yylval;
3840
3841/* Number of syntax errors so far. */
3842int yynerrs;
3843
3844
3845
3846/*----------.
3847| yyparse. |
3848`----------*/
3849
3850#ifdef YYPARSE_PARAM
3851#if (defined __STDC__ || defined __C99__FUNC__ \
3852 || defined __cplusplus || defined _MSC_VER)
3853int
3854yyparse (void *YYPARSE_PARAM)
3855#else
3856int
3857yyparse (YYPARSE_PARAM)
3858 void *YYPARSE_PARAM;
3859#endif
3860#else /* ! YYPARSE_PARAM */
3861#if (defined __STDC__ || defined __C99__FUNC__ \
3862 || defined __cplusplus || defined _MSC_VER)
3863int
3864yyparse (void)
3865#else
3866int
3867yyparse ()
3868
Christopher Lamb4374f8e2007-12-17 01:17:35 +00003869#endif
3870#endif
Chris Lattnercf786592007-12-29 20:47:37 +00003871{
3872
3873 int yystate;
3874 int yyn;
3875 int yyresult;
3876 /* Number of tokens to shift before error messages enabled. */
3877 int yyerrstatus;
3878 /* Look-ahead token as an internal (translated) token number. */
3879 int yytoken = 0;
3880#if YYERROR_VERBOSE
3881 /* Buffer for error messages, and its allocated size. */
3882 char yymsgbuf[128];
3883 char *yymsg = yymsgbuf;
3884 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
Christopher Lamb4374f8e2007-12-17 01:17:35 +00003885#endif
Duncan Sandsdc024672007-11-27 13:23:08 +00003886
Chris Lattnercf786592007-12-29 20:47:37 +00003887 /* Three stacks and their tools:
3888 `yyss': related to states,
3889 `yyvs': related to semantic values,
3890 `yyls': related to locations.
3891
3892 Refer to the stacks thru separate pointers, to allow yyoverflow
3893 to reallocate them elsewhere. */
3894
3895 /* The state stack. */
3896 yytype_int16 yyssa[YYINITDEPTH];
3897 yytype_int16 *yyss = yyssa;
3898 yytype_int16 *yyssp;
3899
3900 /* The semantic value stack. */
3901 YYSTYPE yyvsa[YYINITDEPTH];
3902 YYSTYPE *yyvs = yyvsa;
3903 YYSTYPE *yyvsp;
3904
3905
3906
3907#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
3908
3909 YYSIZE_T yystacksize = YYINITDEPTH;
3910
3911 /* The variables used to return semantic value and location from the
3912 action routines. */
3913 YYSTYPE yyval;
3914
3915
3916 /* The number of symbols on the RHS of the reduced rule.
3917 Keep to zero when no symbol should be popped. */
3918 int yylen = 0;
3919
3920 YYDPRINTF ((stderr, "Starting parse\n"));
3921
Reid Spencere7c3c602006-11-30 06:36:44 +00003922 yystate = 0;
3923 yyerrstatus = 0;
3924 yynerrs = 0;
3925 yychar = YYEMPTY; /* Cause a token to be read. */
3926
3927 /* Initialize stack pointers.
3928 Waste one element of value and location stack
3929 so that they stay on the same level as the state stack.
3930 The wasted elements are never initialized. */
3931
Chris Lattnercf786592007-12-29 20:47:37 +00003932 yyssp = yyss;
Reid Spencere7c3c602006-11-30 06:36:44 +00003933 yyvsp = yyvs;
3934
Chris Lattnercf786592007-12-29 20:47:37 +00003935 goto yysetstate;
Reid Spencere7c3c602006-11-30 06:36:44 +00003936
Chris Lattnercf786592007-12-29 20:47:37 +00003937/*------------------------------------------------------------.
3938| yynewstate -- Push a new state, which is found in yystate. |
3939`------------------------------------------------------------*/
3940 yynewstate:
3941 /* In all cases, when you get here, the value and location stacks
3942 have just been pushed. So pushing a state here evens the stacks. */
3943 yyssp++;
Reid Spencere7c3c602006-11-30 06:36:44 +00003944
Chris Lattnercf786592007-12-29 20:47:37 +00003945 yysetstate:
3946 *yyssp = yystate;
3947
3948 if (yyss + yystacksize - 1 <= yyssp)
Reid Spencere7c3c602006-11-30 06:36:44 +00003949 {
3950 /* Get the current used size of the three stacks, in elements. */
Chris Lattnercf786592007-12-29 20:47:37 +00003951 YYSIZE_T yysize = yyssp - yyss + 1;
Reid Spencere7c3c602006-11-30 06:36:44 +00003952
3953#ifdef yyoverflow
Chris Lattnercf786592007-12-29 20:47:37 +00003954 {
3955 /* Give user a chance to reallocate the stack. Use copies of
3956 these so that the &'s don't force the real ones into
3957 memory. */
3958 YYSTYPE *yyvs1 = yyvs;
3959 yytype_int16 *yyss1 = yyss;
Reid Spencere7c3c602006-11-30 06:36:44 +00003960
Chris Lattnercf786592007-12-29 20:47:37 +00003961
3962 /* Each stack pointer address is followed by the size of the
3963 data in use in that stack, in bytes. This used to be a
3964 conditional around just the two extra args, but that might
3965 be undefined if yyoverflow is a macro. */
3966 yyoverflow (YY_("memory exhausted"),
3967 &yyss1, yysize * sizeof (*yyssp),
3968 &yyvs1, yysize * sizeof (*yyvsp),
3969
3970 &yystacksize);
3971
3972 yyss = yyss1;
3973 yyvs = yyvs1;
3974 }
Reid Spencere7c3c602006-11-30 06:36:44 +00003975#else /* no yyoverflow */
Chris Lattnercf786592007-12-29 20:47:37 +00003976# ifndef YYSTACK_RELOCATE
3977 goto yyexhaustedlab;
3978# else
Reid Spencere7c3c602006-11-30 06:36:44 +00003979 /* Extend the stack our own way. */
Chris Lattnercf786592007-12-29 20:47:37 +00003980 if (YYMAXDEPTH <= yystacksize)
3981 goto yyexhaustedlab;
Reid Spencere7c3c602006-11-30 06:36:44 +00003982 yystacksize *= 2;
Chris Lattnercf786592007-12-29 20:47:37 +00003983 if (YYMAXDEPTH < yystacksize)
Reid Spencere7c3c602006-11-30 06:36:44 +00003984 yystacksize = YYMAXDEPTH;
Chris Lattnercf786592007-12-29 20:47:37 +00003985
3986 {
3987 yytype_int16 *yyss1 = yyss;
3988 union yyalloc *yyptr =
3989 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
3990 if (! yyptr)
3991 goto yyexhaustedlab;
3992 YYSTACK_RELOCATE (yyss);
3993 YYSTACK_RELOCATE (yyvs);
3994
3995# undef YYSTACK_RELOCATE
3996 if (yyss1 != yyssa)
3997 YYSTACK_FREE (yyss1);
3998 }
3999# endif
Reid Spencere7c3c602006-11-30 06:36:44 +00004000#endif /* no yyoverflow */
4001
Chris Lattnercf786592007-12-29 20:47:37 +00004002 yyssp = yyss + yysize - 1;
4003 yyvsp = yyvs + yysize - 1;
Reid Spencere7c3c602006-11-30 06:36:44 +00004004
4005
Chris Lattnercf786592007-12-29 20:47:37 +00004006 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
4007 (unsigned long int) yystacksize));
4008
4009 if (yyss + yystacksize - 1 <= yyssp)
Reid Spencere7c3c602006-11-30 06:36:44 +00004010 YYABORT;
4011 }
4012
Chris Lattnercf786592007-12-29 20:47:37 +00004013 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
Reid Spencere7c3c602006-11-30 06:36:44 +00004014
4015 goto yybackup;
Reid Spencere7c3c602006-11-30 06:36:44 +00004016
Chris Lattnercf786592007-12-29 20:47:37 +00004017/*-----------.
4018| yybackup. |
4019`-----------*/
4020yybackup:
Reid Spencere7c3c602006-11-30 06:36:44 +00004021
Chris Lattnercf786592007-12-29 20:47:37 +00004022 /* Do appropriate processing given the current state. Read a
4023 look-ahead token if we need one and don't already have one. */
David Greene5fd22a82007-09-04 18:46:50 +00004024
Chris Lattnercf786592007-12-29 20:47:37 +00004025 /* First try to decide what to do without reference to look-ahead token. */
Reid Spencere7c3c602006-11-30 06:36:44 +00004026 yyn = yypact[yystate];
Chris Lattnercf786592007-12-29 20:47:37 +00004027 if (yyn == YYPACT_NINF)
Reid Spencere7c3c602006-11-30 06:36:44 +00004028 goto yydefault;
4029
Chris Lattnercf786592007-12-29 20:47:37 +00004030 /* Not known => get a look-ahead token if don't already have one. */
Reid Spencere7c3c602006-11-30 06:36:44 +00004031
Chris Lattnercf786592007-12-29 20:47:37 +00004032 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
Reid Spencere7c3c602006-11-30 06:36:44 +00004033 if (yychar == YYEMPTY)
4034 {
Chris Lattnercf786592007-12-29 20:47:37 +00004035 YYDPRINTF ((stderr, "Reading a token: "));
Reid Spencere7c3c602006-11-30 06:36:44 +00004036 yychar = YYLEX;
4037 }
4038
Chris Lattnercf786592007-12-29 20:47:37 +00004039 if (yychar <= YYEOF)
Reid Spencere7c3c602006-11-30 06:36:44 +00004040 {
Chris Lattnercf786592007-12-29 20:47:37 +00004041 yychar = yytoken = YYEOF;
4042 YYDPRINTF ((stderr, "Now at end of input.\n"));
Reid Spencere7c3c602006-11-30 06:36:44 +00004043 }
4044 else
4045 {
Chris Lattnercf786592007-12-29 20:47:37 +00004046 yytoken = YYTRANSLATE (yychar);
4047 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
Reid Spencere7c3c602006-11-30 06:36:44 +00004048 }
4049
Chris Lattnercf786592007-12-29 20:47:37 +00004050 /* If the proper action on seeing token YYTOKEN is to reduce or to
4051 detect an error, take that action. */
4052 yyn += yytoken;
4053 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
Reid Spencere7c3c602006-11-30 06:36:44 +00004054 goto yydefault;
4055 yyn = yytable[yyn];
Chris Lattnercf786592007-12-29 20:47:37 +00004056 if (yyn <= 0)
Reid Spencere7c3c602006-11-30 06:36:44 +00004057 {
Chris Lattnercf786592007-12-29 20:47:37 +00004058 if (yyn == 0 || yyn == YYTABLE_NINF)
Reid Spencere7c3c602006-11-30 06:36:44 +00004059 goto yyerrlab;
4060 yyn = -yyn;
4061 goto yyreduce;
4062 }
4063
4064 if (yyn == YYFINAL)
4065 YYACCEPT;
4066
Chris Lattnercf786592007-12-29 20:47:37 +00004067 /* Count tokens shifted since error; after three, turn off error
4068 status. */
4069 if (yyerrstatus)
4070 yyerrstatus--;
Dale Johannesencdd509a2007-09-07 21:07:57 +00004071
Chris Lattnercf786592007-12-29 20:47:37 +00004072 /* Shift the look-ahead token. */
4073 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
David Greene5fd22a82007-09-04 18:46:50 +00004074
Chris Lattnercf786592007-12-29 20:47:37 +00004075 /* Discard the shifted token unless it is eof. */
David Greene5fd22a82007-09-04 18:46:50 +00004076 if (yychar != YYEOF)
4077 yychar = YYEMPTY;
4078
Christopher Lamb4374f8e2007-12-17 01:17:35 +00004079 yystate = yyn;
Chris Lattnercf786592007-12-29 20:47:37 +00004080 *++yyvsp = yylval;
4081
Reid Spencere7c3c602006-11-30 06:36:44 +00004082 goto yynewstate;
4083
Christopher Lamb4374f8e2007-12-17 01:17:35 +00004084
Chris Lattnercf786592007-12-29 20:47:37 +00004085/*-----------------------------------------------------------.
4086| yydefault -- do the default action for the current state. |
4087`-----------------------------------------------------------*/
4088yydefault:
Reid Spencere7c3c602006-11-30 06:36:44 +00004089 yyn = yydefact[yystate];
4090 if (yyn == 0)
4091 goto yyerrlab;
Chris Lattnercf786592007-12-29 20:47:37 +00004092 goto yyreduce;
Reid Spencere7c3c602006-11-30 06:36:44 +00004093
Chris Lattnercf786592007-12-29 20:47:37 +00004094
4095/*-----------------------------.
4096| yyreduce -- Do a reduction. |
4097`-----------------------------*/
Reid Spencere7c3c602006-11-30 06:36:44 +00004098yyreduce:
Chris Lattnercf786592007-12-29 20:47:37 +00004099 /* yyn is the number of a rule to reduce with. */
Reid Spencere7c3c602006-11-30 06:36:44 +00004100 yylen = yyr2[yyn];
4101
Chris Lattnercf786592007-12-29 20:47:37 +00004102 /* If YYLEN is nonzero, implement the default value of the action:
4103 `$$ = $1'.
4104
4105 Otherwise, the following line sets YYVAL to garbage.
4106 This behavior is undocumented and Bison
4107 users should not rely upon it. Assigning to YYVAL
4108 unconditionally makes the parser a bit smaller, and it avoids a
4109 GCC warning that YYVAL may be used uninitialized. */
4110 yyval = yyvsp[1-yylen];
4111
4112
4113 YY_REDUCE_PRINT (yyn);
4114 switch (yyn)
Reid Spencere7c3c602006-11-30 06:36:44 +00004115 {
Chris Lattnercf786592007-12-29 20:47:37 +00004116 case 3:
4117#line 1822 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4118 {
4119 if ((yyvsp[(1) - (1)].UIntVal) > (uint32_t)INT32_MAX) // Outside of my range!
Reid Spencer950bf602007-01-26 08:19:09 +00004120 error("Value too large for type");
Chris Lattnercf786592007-12-29 20:47:37 +00004121 (yyval.SIntVal) = (int32_t)(yyvsp[(1) - (1)].UIntVal);
4122 ;}
4123 break;
4124
4125 case 5:
4126#line 1831 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4127 {
4128 if ((yyvsp[(1) - (1)].UInt64Val) > (uint64_t)INT64_MAX) // Outside of my range!
Reid Spencer950bf602007-01-26 08:19:09 +00004129 error("Value too large for type");
Chris Lattnercf786592007-12-29 20:47:37 +00004130 (yyval.SInt64Val) = (int64_t)(yyvsp[(1) - (1)].UInt64Val);
4131 ;}
4132 break;
4133
4134 case 26:
4135#line 1853 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4136 { (yyval.IPred) = ICmpInst::ICMP_EQ; ;}
4137 break;
4138
4139 case 27:
4140#line 1853 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4141 { (yyval.IPred) = ICmpInst::ICMP_NE; ;}
4142 break;
4143
4144 case 28:
4145#line 1854 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4146 { (yyval.IPred) = ICmpInst::ICMP_SLT; ;}
4147 break;
4148
4149 case 29:
4150#line 1854 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4151 { (yyval.IPred) = ICmpInst::ICMP_SGT; ;}
4152 break;
4153
4154 case 30:
4155#line 1855 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4156 { (yyval.IPred) = ICmpInst::ICMP_SLE; ;}
4157 break;
4158
4159 case 31:
4160#line 1855 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4161 { (yyval.IPred) = ICmpInst::ICMP_SGE; ;}
4162 break;
4163
4164 case 32:
4165#line 1856 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4166 { (yyval.IPred) = ICmpInst::ICMP_ULT; ;}
4167 break;
4168
4169 case 33:
4170#line 1856 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4171 { (yyval.IPred) = ICmpInst::ICMP_UGT; ;}
4172 break;
4173
4174 case 34:
4175#line 1857 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4176 { (yyval.IPred) = ICmpInst::ICMP_ULE; ;}
4177 break;
4178
4179 case 35:
4180#line 1857 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4181 { (yyval.IPred) = ICmpInst::ICMP_UGE; ;}
4182 break;
4183
4184 case 36:
4185#line 1861 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4186 { (yyval.FPred) = FCmpInst::FCMP_OEQ; ;}
4187 break;
4188
4189 case 37:
4190#line 1861 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4191 { (yyval.FPred) = FCmpInst::FCMP_ONE; ;}
4192 break;
4193
4194 case 38:
4195#line 1862 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4196 { (yyval.FPred) = FCmpInst::FCMP_OLT; ;}
4197 break;
4198
4199 case 39:
4200#line 1862 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4201 { (yyval.FPred) = FCmpInst::FCMP_OGT; ;}
4202 break;
4203
4204 case 40:
4205#line 1863 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4206 { (yyval.FPred) = FCmpInst::FCMP_OLE; ;}
4207 break;
4208
4209 case 41:
4210#line 1863 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4211 { (yyval.FPred) = FCmpInst::FCMP_OGE; ;}
4212 break;
4213
4214 case 42:
4215#line 1864 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4216 { (yyval.FPred) = FCmpInst::FCMP_ORD; ;}
4217 break;
4218
4219 case 43:
4220#line 1864 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4221 { (yyval.FPred) = FCmpInst::FCMP_UNO; ;}
4222 break;
4223
4224 case 44:
4225#line 1865 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4226 { (yyval.FPred) = FCmpInst::FCMP_UEQ; ;}
4227 break;
4228
4229 case 45:
4230#line 1865 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4231 { (yyval.FPred) = FCmpInst::FCMP_UNE; ;}
4232 break;
4233
4234 case 46:
4235#line 1866 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4236 { (yyval.FPred) = FCmpInst::FCMP_ULT; ;}
4237 break;
4238
4239 case 47:
4240#line 1866 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4241 { (yyval.FPred) = FCmpInst::FCMP_UGT; ;}
4242 break;
4243
4244 case 48:
4245#line 1867 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4246 { (yyval.FPred) = FCmpInst::FCMP_ULE; ;}
4247 break;
4248
4249 case 49:
4250#line 1867 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4251 { (yyval.FPred) = FCmpInst::FCMP_UGE; ;}
4252 break;
4253
4254 case 50:
4255#line 1868 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4256 { (yyval.FPred) = FCmpInst::FCMP_TRUE; ;}
4257 break;
4258
4259 case 51:
4260#line 1869 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4261 { (yyval.FPred) = FCmpInst::FCMP_FALSE; ;}
4262 break;
4263
4264 case 81:
4265#line 1900 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4266 {
4267 (yyval.StrVal) = (yyvsp[(1) - (2)].StrVal);
4268 ;}
4269 break;
4270
4271 case 82:
4272#line 1903 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4273 {
4274 (yyval.StrVal) = 0;
4275 ;}
4276 break;
4277
4278 case 83:
4279#line 1908 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4280 { (yyval.Linkage) = GlobalValue::InternalLinkage; ;}
4281 break;
4282
4283 case 84:
4284#line 1909 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4285 { (yyval.Linkage) = GlobalValue::LinkOnceLinkage; ;}
4286 break;
4287
4288 case 85:
4289#line 1910 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4290 { (yyval.Linkage) = GlobalValue::WeakLinkage; ;}
4291 break;
4292
4293 case 86:
4294#line 1911 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4295 { (yyval.Linkage) = GlobalValue::AppendingLinkage; ;}
4296 break;
4297
4298 case 87:
4299#line 1912 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4300 { (yyval.Linkage) = GlobalValue::DLLImportLinkage; ;}
4301 break;
4302
4303 case 88:
4304#line 1913 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4305 { (yyval.Linkage) = GlobalValue::DLLExportLinkage; ;}
4306 break;
4307
4308 case 89:
4309#line 1914 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4310 { (yyval.Linkage) = GlobalValue::ExternalWeakLinkage; ;}
4311 break;
4312
4313 case 90:
4314#line 1915 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4315 { (yyval.Linkage) = GlobalValue::ExternalLinkage; ;}
4316 break;
4317
4318 case 91:
4319#line 1919 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4320 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::C; ;}
4321 break;
4322
4323 case 92:
4324#line 1920 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4325 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::C; ;}
4326 break;
4327
4328 case 93:
4329#line 1921 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4330 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::CSRet; ;}
4331 break;
4332
4333 case 94:
4334#line 1922 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4335 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::Fast; ;}
4336 break;
4337
4338 case 95:
4339#line 1923 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4340 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::Cold; ;}
4341 break;
4342
4343 case 96:
4344#line 1924 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4345 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::X86_StdCall; ;}
4346 break;
4347
4348 case 97:
4349#line 1925 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4350 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::X86_FastCall; ;}
4351 break;
4352
4353 case 98:
4354#line 1926 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4355 {
4356 if ((unsigned)(yyvsp[(2) - (2)].UInt64Val) != (yyvsp[(2) - (2)].UInt64Val))
Reid Spencer950bf602007-01-26 08:19:09 +00004357 error("Calling conv too large");
Chris Lattnercf786592007-12-29 20:47:37 +00004358 (yyval.UIntVal) = lastCallingConv = (yyvsp[(2) - (2)].UInt64Val);
4359 ;}
4360 break;
4361
4362 case 99:
4363#line 1936 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4364 { (yyval.UIntVal) = 0; ;}
4365 break;
4366
4367 case 100:
4368#line 1937 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4369 {
4370 (yyval.UIntVal) = (yyvsp[(2) - (2)].UInt64Val);
4371 if ((yyval.UIntVal) != 0 && !isPowerOf2_32((yyval.UIntVal)))
Reid Spencer950bf602007-01-26 08:19:09 +00004372 error("Alignment must be a power of two");
Chris Lattnercf786592007-12-29 20:47:37 +00004373 ;}
4374 break;
4375
4376 case 101:
4377#line 1945 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4378 { (yyval.UIntVal) = 0; ;}
4379 break;
4380
4381 case 102:
4382#line 1946 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4383 {
4384 (yyval.UIntVal) = (yyvsp[(3) - (3)].UInt64Val);
4385 if ((yyval.UIntVal) != 0 && !isPowerOf2_32((yyval.UIntVal)))
Reid Spencer950bf602007-01-26 08:19:09 +00004386 error("Alignment must be a power of two");
Chris Lattnercf786592007-12-29 20:47:37 +00004387 ;}
4388 break;
4389
4390 case 103:
4391#line 1954 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4392 {
4393 for (unsigned i = 0, e = strlen((yyvsp[(2) - (2)].StrVal)); i != e; ++i)
4394 if ((yyvsp[(2) - (2)].StrVal)[i] == '"' || (yyvsp[(2) - (2)].StrVal)[i] == '\\')
Reid Spencer950bf602007-01-26 08:19:09 +00004395 error("Invalid character in section name");
Chris Lattnercf786592007-12-29 20:47:37 +00004396 (yyval.StrVal) = (yyvsp[(2) - (2)].StrVal);
4397 ;}
4398 break;
4399
4400 case 104:
4401#line 1963 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4402 { (yyval.StrVal) = 0; ;}
4403 break;
4404
4405 case 105:
4406#line 1964 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4407 { (yyval.StrVal) = (yyvsp[(1) - (1)].StrVal); ;}
4408 break;
4409
4410 case 106:
4411#line 1971 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4412 {;}
4413 break;
4414
4415 case 107:
4416#line 1972 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4417 {;}
4418 break;
4419
4420 case 108:
4421#line 1976 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4422 {
4423 CurGV->setSection((yyvsp[(1) - (1)].StrVal));
4424 free((yyvsp[(1) - (1)].StrVal));
4425 ;}
4426 break;
4427
4428 case 109:
4429#line 1980 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4430 {
4431 if ((yyvsp[(2) - (2)].UInt64Val) != 0 && !isPowerOf2_32((yyvsp[(2) - (2)].UInt64Val)))
Reid Spencer950bf602007-01-26 08:19:09 +00004432 error("Alignment must be a power of two");
Chris Lattnercf786592007-12-29 20:47:37 +00004433 CurGV->setAlignment((yyvsp[(2) - (2)].UInt64Val));
Reid Spencer950bf602007-01-26 08:19:09 +00004434
Chris Lattnercf786592007-12-29 20:47:37 +00004435 ;}
4436 break;
4437
4438 case 111:
4439#line 1997 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4440 {
4441 (yyval.TypeVal).PAT = new PATypeHolder((yyvsp[(1) - (1)].PrimType).T);
4442 (yyval.TypeVal).S.makeSignless();
4443 ;}
4444 break;
4445
4446 case 113:
4447#line 2005 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4448 {
4449 (yyval.TypeVal).PAT = new PATypeHolder((yyvsp[(1) - (1)].PrimType).T);
4450 (yyval.TypeVal).S.makeSignless();
4451 ;}
4452 break;
4453
4454 case 114:
4455#line 2012 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4456 {
Reid Spencer950bf602007-01-26 08:19:09 +00004457 if (!UpRefs.empty())
Chris Lattnercf786592007-12-29 20:47:37 +00004458 error("Invalid upreference in type: " + (*(yyvsp[(1) - (1)].TypeVal).PAT)->getDescription());
4459 (yyval.TypeVal) = (yyvsp[(1) - (1)].TypeVal);
4460 ;}
4461 break;
4462
4463 case 127:
4464#line 2026 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4465 {
4466 (yyval.TypeVal).PAT = new PATypeHolder((yyvsp[(1) - (1)].PrimType).T);
4467 (yyval.TypeVal).S.copy((yyvsp[(1) - (1)].PrimType).S);
4468 ;}
4469 break;
4470
4471 case 128:
4472#line 2030 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4473 {
4474 (yyval.TypeVal).PAT = new PATypeHolder(OpaqueType::get());
4475 (yyval.TypeVal).S.makeSignless();
4476 ;}
4477 break;
4478
4479 case 129:
4480#line 2034 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4481 { // Named types are also simple types...
4482 (yyval.TypeVal).S.copy(getTypeSign((yyvsp[(1) - (1)].ValIDVal)));
4483 const Type* tmp = getType((yyvsp[(1) - (1)].ValIDVal));
4484 (yyval.TypeVal).PAT = new PATypeHolder(tmp);
4485 ;}
4486 break;
4487
4488 case 130:
4489#line 2039 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4490 { // Type UpReference
4491 if ((yyvsp[(2) - (2)].UInt64Val) > (uint64_t)~0U)
Reid Spencer950bf602007-01-26 08:19:09 +00004492 error("Value out of range");
4493 OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder
Chris Lattnercf786592007-12-29 20:47:37 +00004494 UpRefs.push_back(UpRefRecord((unsigned)(yyvsp[(2) - (2)].UInt64Val), OT)); // Add to vector...
4495 (yyval.TypeVal).PAT = new PATypeHolder(OT);
4496 (yyval.TypeVal).S.makeSignless();
Reid Spencer950bf602007-01-26 08:19:09 +00004497 UR_OUT("New Upreference!\n");
Chris Lattnercf786592007-12-29 20:47:37 +00004498 ;}
4499 break;
4500
4501 case 131:
4502#line 2048 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4503 { // Function derived type?
4504 (yyval.TypeVal).S.makeComposite((yyvsp[(1) - (4)].TypeVal).S);
Reid Spencer950bf602007-01-26 08:19:09 +00004505 std::vector<const Type*> Params;
Chris Lattnercf786592007-12-29 20:47:37 +00004506 for (std::list<llvm::PATypeInfo>::iterator I = (yyvsp[(3) - (4)].TypeList)->begin(),
4507 E = (yyvsp[(3) - (4)].TypeList)->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004508 Params.push_back(I->PAT->get());
Chris Lattnercf786592007-12-29 20:47:37 +00004509 (yyval.TypeVal).S.add(I->S);
Reid Spencer52402b02007-01-02 05:45:11 +00004510 }
Reid Spencer950bf602007-01-26 08:19:09 +00004511 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
4512 if (isVarArg) Params.pop_back();
4513
Duncan Sandsafa3b6d2007-11-28 17:07:01 +00004514 const ParamAttrsList *PAL = 0;
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004515 if (lastCallingConv == OldCallingConv::CSRet) {
4516 ParamAttrsVector Attrs;
4517 ParamAttrsWithIndex PAWI;
4518 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
4519 Attrs.push_back(PAWI);
4520 PAL = ParamAttrsList::get(Attrs);
4521 }
4522
Reid Spencer7b5d4662007-04-09 06:16:21 +00004523 const FunctionType *FTy =
Chris Lattnercf786592007-12-29 20:47:37 +00004524 FunctionType::get((yyvsp[(1) - (4)].TypeVal).PAT->get(), Params, isVarArg);
Reid Spencer7b5d4662007-04-09 06:16:21 +00004525
Chris Lattnercf786592007-12-29 20:47:37 +00004526 (yyval.TypeVal).PAT = new PATypeHolder( HandleUpRefs(FTy, (yyval.TypeVal).S) );
4527 delete (yyvsp[(1) - (4)].TypeVal).PAT; // Delete the return type handle
4528 delete (yyvsp[(3) - (4)].TypeList); // Delete the argument list
4529 ;}
4530 break;
4531
4532 case 132:
4533#line 2075 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4534 { // Sized array type?
4535 (yyval.TypeVal).S.makeComposite((yyvsp[(4) - (5)].TypeVal).S);
4536 (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(ArrayType::get((yyvsp[(4) - (5)].TypeVal).PAT->get(),
4537 (unsigned)(yyvsp[(2) - (5)].UInt64Val)), (yyval.TypeVal).S));
4538 delete (yyvsp[(4) - (5)].TypeVal).PAT;
4539 ;}
4540 break;
4541
4542 case 133:
4543#line 2081 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4544 { // Vector type?
4545 const llvm::Type* ElemTy = (yyvsp[(4) - (5)].TypeVal).PAT->get();
4546 if ((unsigned)(yyvsp[(2) - (5)].UInt64Val) != (yyvsp[(2) - (5)].UInt64Val))
Reid Spencerbb1fd572007-03-21 17:15:50 +00004547 error("Unsigned result not equal to signed result");
4548 if (!(ElemTy->isInteger() || ElemTy->isFloatingPoint()))
4549 error("Elements of a VectorType must be integer or floating point");
Chris Lattnercf786592007-12-29 20:47:37 +00004550 if (!isPowerOf2_32((yyvsp[(2) - (5)].UInt64Val)))
Reid Spencerbb1fd572007-03-21 17:15:50 +00004551 error("VectorType length should be a power of 2");
Chris Lattnercf786592007-12-29 20:47:37 +00004552 (yyval.TypeVal).S.makeComposite((yyvsp[(4) - (5)].TypeVal).S);
4553 (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(VectorType::get(ElemTy,
4554 (unsigned)(yyvsp[(2) - (5)].UInt64Val)), (yyval.TypeVal).S));
4555 delete (yyvsp[(4) - (5)].TypeVal).PAT;
4556 ;}
4557 break;
4558
4559 case 134:
4560#line 2094 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4561 { // Structure type?
Reid Spencer950bf602007-01-26 08:19:09 +00004562 std::vector<const Type*> Elements;
Chris Lattnercf786592007-12-29 20:47:37 +00004563 (yyval.TypeVal).S.makeComposite();
4564 for (std::list<llvm::PATypeInfo>::iterator I = (yyvsp[(2) - (3)].TypeList)->begin(),
4565 E = (yyvsp[(2) - (3)].TypeList)->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004566 Elements.push_back(I->PAT->get());
Chris Lattnercf786592007-12-29 20:47:37 +00004567 (yyval.TypeVal).S.add(I->S);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004568 }
Chris Lattnercf786592007-12-29 20:47:37 +00004569 (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements), (yyval.TypeVal).S));
4570 delete (yyvsp[(2) - (3)].TypeList);
4571 ;}
4572 break;
4573
4574 case 135:
4575#line 2105 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4576 { // Empty structure type?
4577 (yyval.TypeVal).PAT = new PATypeHolder(StructType::get(std::vector<const Type*>()));
4578 (yyval.TypeVal).S.makeComposite();
4579 ;}
4580 break;
4581
4582 case 136:
4583#line 2109 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4584 { // Packed Structure type?
4585 (yyval.TypeVal).S.makeComposite();
Reid Spencer950bf602007-01-26 08:19:09 +00004586 std::vector<const Type*> Elements;
Chris Lattnercf786592007-12-29 20:47:37 +00004587 for (std::list<llvm::PATypeInfo>::iterator I = (yyvsp[(3) - (5)].TypeList)->begin(),
4588 E = (yyvsp[(3) - (5)].TypeList)->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004589 Elements.push_back(I->PAT->get());
Chris Lattnercf786592007-12-29 20:47:37 +00004590 (yyval.TypeVal).S.add(I->S);
Reid Spencered96d1e2007-02-08 09:08:52 +00004591 delete I->PAT;
Reid Spencer52402b02007-01-02 05:45:11 +00004592 }
Chris Lattnercf786592007-12-29 20:47:37 +00004593 (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements, true),
4594 (yyval.TypeVal).S));
4595 delete (yyvsp[(3) - (5)].TypeList);
4596 ;}
4597 break;
4598
4599 case 137:
4600#line 2122 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4601 { // Empty packed structure type?
4602 (yyval.TypeVal).PAT = new PATypeHolder(StructType::get(std::vector<const Type*>(),true));
4603 (yyval.TypeVal).S.makeComposite();
4604 ;}
4605 break;
4606
4607 case 138:
4608#line 2126 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4609 { // Pointer type?
4610 if ((yyvsp[(1) - (2)].TypeVal).PAT->get() == Type::LabelTy)
Reid Spencer950bf602007-01-26 08:19:09 +00004611 error("Cannot form a pointer to a basic block");
Chris Lattnercf786592007-12-29 20:47:37 +00004612 (yyval.TypeVal).S.makeComposite((yyvsp[(1) - (2)].TypeVal).S);
4613 (yyval.TypeVal).PAT = new
4614 PATypeHolder(HandleUpRefs(PointerType::getUnqual((yyvsp[(1) - (2)].TypeVal).PAT->get()),
4615 (yyval.TypeVal).S));
4616 delete (yyvsp[(1) - (2)].TypeVal).PAT;
4617 ;}
4618 break;
4619
4620 case 139:
4621#line 2141 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4622 {
4623 (yyval.TypeList) = new std::list<PATypeInfo>();
4624 (yyval.TypeList)->push_back((yyvsp[(1) - (1)].TypeVal));
4625 ;}
4626 break;
4627
4628 case 140:
4629#line 2145 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4630 {
4631 ((yyval.TypeList)=(yyvsp[(1) - (3)].TypeList))->push_back((yyvsp[(3) - (3)].TypeVal));
4632 ;}
4633 break;
4634
4635 case 142:
4636#line 2153 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4637 {
Reid Spencer950bf602007-01-26 08:19:09 +00004638 PATypeInfo VoidTI;
Reid Spencered96d1e2007-02-08 09:08:52 +00004639 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004640 VoidTI.S.makeSignless();
Chris Lattnercf786592007-12-29 20:47:37 +00004641 ((yyval.TypeList)=(yyvsp[(1) - (3)].TypeList))->push_back(VoidTI);
4642 ;}
4643 break;
4644
4645 case 143:
4646#line 2159 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4647 {
4648 (yyval.TypeList) = new std::list<PATypeInfo>();
Reid Spencer950bf602007-01-26 08:19:09 +00004649 PATypeInfo VoidTI;
Reid Spencered96d1e2007-02-08 09:08:52 +00004650 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004651 VoidTI.S.makeSignless();
Chris Lattnercf786592007-12-29 20:47:37 +00004652 (yyval.TypeList)->push_back(VoidTI);
4653 ;}
4654 break;
4655
4656 case 144:
4657#line 2166 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4658 {
4659 (yyval.TypeList) = new std::list<PATypeInfo>();
4660 ;}
4661 break;
4662
4663 case 145:
4664#line 2178 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4665 { // Nonempty unsized arr
4666 const ArrayType *ATy = dyn_cast<ArrayType>((yyvsp[(1) - (4)].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004667 if (ATy == 0)
4668 error("Cannot make array constant with type: '" +
Chris Lattnercf786592007-12-29 20:47:37 +00004669 (yyvsp[(1) - (4)].TypeVal).PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004670 const Type *ETy = ATy->getElementType();
4671 int NumElements = ATy->getNumElements();
4672
4673 // Verify that we have the correct size...
Chris Lattnercf786592007-12-29 20:47:37 +00004674 if (NumElements != -1 && NumElements != (int)(yyvsp[(3) - (4)].ConstVector)->size())
Reid Spencer950bf602007-01-26 08:19:09 +00004675 error("Type mismatch: constant sized array initialized with " +
Chris Lattnercf786592007-12-29 20:47:37 +00004676 utostr((yyvsp[(3) - (4)].ConstVector)->size()) + " arguments, but has size of " +
Reid Spencer950bf602007-01-26 08:19:09 +00004677 itostr(NumElements) + "");
4678
4679 // Verify all elements are correct type!
4680 std::vector<Constant*> Elems;
Chris Lattnercf786592007-12-29 20:47:37 +00004681 for (unsigned i = 0; i < (yyvsp[(3) - (4)].ConstVector)->size(); i++) {
4682 Constant *C = (*(yyvsp[(3) - (4)].ConstVector))[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004683 const Type* ValTy = C->getType();
4684 if (ETy != ValTy)
4685 error("Element #" + utostr(i) + " is not of type '" +
4686 ETy->getDescription() +"' as required!\nIt is of type '"+
4687 ValTy->getDescription() + "'");
4688 Elems.push_back(C);
4689 }
Chris Lattnercf786592007-12-29 20:47:37 +00004690 (yyval.ConstVal).C = ConstantArray::get(ATy, Elems);
4691 (yyval.ConstVal).S.copy((yyvsp[(1) - (4)].TypeVal).S);
4692 delete (yyvsp[(1) - (4)].TypeVal).PAT;
4693 delete (yyvsp[(3) - (4)].ConstVector);
4694 ;}
4695 break;
4696
4697 case 146:
4698#line 2208 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4699 {
4700 const ArrayType *ATy = dyn_cast<ArrayType>((yyvsp[(1) - (3)].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004701 if (ATy == 0)
4702 error("Cannot make array constant with type: '" +
Chris Lattnercf786592007-12-29 20:47:37 +00004703 (yyvsp[(1) - (3)].TypeVal).PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004704 int NumElements = ATy->getNumElements();
4705 if (NumElements != -1 && NumElements != 0)
4706 error("Type mismatch: constant sized array initialized with 0"
4707 " arguments, but has size of " + itostr(NumElements) +"");
Chris Lattnercf786592007-12-29 20:47:37 +00004708 (yyval.ConstVal).C = ConstantArray::get(ATy, std::vector<Constant*>());
4709 (yyval.ConstVal).S.copy((yyvsp[(1) - (3)].TypeVal).S);
4710 delete (yyvsp[(1) - (3)].TypeVal).PAT;
4711 ;}
4712 break;
4713
4714 case 147:
4715#line 2221 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4716 {
4717 const ArrayType *ATy = dyn_cast<ArrayType>((yyvsp[(1) - (3)].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004718 if (ATy == 0)
4719 error("Cannot make array constant with type: '" +
Chris Lattnercf786592007-12-29 20:47:37 +00004720 (yyvsp[(1) - (3)].TypeVal).PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004721 int NumElements = ATy->getNumElements();
4722 const Type *ETy = dyn_cast<IntegerType>(ATy->getElementType());
4723 if (!ETy || cast<IntegerType>(ETy)->getBitWidth() != 8)
4724 error("String arrays require type i8, not '" + ETy->getDescription() +
4725 "'");
Chris Lattnercf786592007-12-29 20:47:37 +00004726 char *EndStr = UnEscapeLexed((yyvsp[(3) - (3)].StrVal), true);
4727 if (NumElements != -1 && NumElements != (EndStr-(yyvsp[(3) - (3)].StrVal)))
Reid Spencer950bf602007-01-26 08:19:09 +00004728 error("Can't build string constant of size " +
Chris Lattnercf786592007-12-29 20:47:37 +00004729 itostr((int)(EndStr-(yyvsp[(3) - (3)].StrVal))) + " when array has size " +
Reid Spencer950bf602007-01-26 08:19:09 +00004730 itostr(NumElements) + "");
4731 std::vector<Constant*> Vals;
Chris Lattnercf786592007-12-29 20:47:37 +00004732 for (char *C = (char *)(yyvsp[(3) - (3)].StrVal); C != (char *)EndStr; ++C)
Reid Spencer950bf602007-01-26 08:19:09 +00004733 Vals.push_back(ConstantInt::get(ETy, *C));
Chris Lattnercf786592007-12-29 20:47:37 +00004734 free((yyvsp[(3) - (3)].StrVal));
4735 (yyval.ConstVal).C = ConstantArray::get(ATy, Vals);
4736 (yyval.ConstVal).S.copy((yyvsp[(1) - (3)].TypeVal).S);
4737 delete (yyvsp[(1) - (3)].TypeVal).PAT;
4738 ;}
4739 break;
4740
4741 case 148:
4742#line 2244 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4743 { // Nonempty unsized arr
4744 const VectorType *PTy = dyn_cast<VectorType>((yyvsp[(1) - (4)].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004745 if (PTy == 0)
4746 error("Cannot make packed constant with type: '" +
Chris Lattnercf786592007-12-29 20:47:37 +00004747 (yyvsp[(1) - (4)].TypeVal).PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004748 const Type *ETy = PTy->getElementType();
4749 int NumElements = PTy->getNumElements();
4750 // Verify that we have the correct size...
Chris Lattnercf786592007-12-29 20:47:37 +00004751 if (NumElements != -1 && NumElements != (int)(yyvsp[(3) - (4)].ConstVector)->size())
Reid Spencer950bf602007-01-26 08:19:09 +00004752 error("Type mismatch: constant sized packed initialized with " +
Chris Lattnercf786592007-12-29 20:47:37 +00004753 utostr((yyvsp[(3) - (4)].ConstVector)->size()) + " arguments, but has size of " +
Reid Spencer950bf602007-01-26 08:19:09 +00004754 itostr(NumElements) + "");
4755 // Verify all elements are correct type!
4756 std::vector<Constant*> Elems;
Chris Lattnercf786592007-12-29 20:47:37 +00004757 for (unsigned i = 0; i < (yyvsp[(3) - (4)].ConstVector)->size(); i++) {
4758 Constant *C = (*(yyvsp[(3) - (4)].ConstVector))[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004759 const Type* ValTy = C->getType();
4760 if (ETy != ValTy)
4761 error("Element #" + utostr(i) + " is not of type '" +
4762 ETy->getDescription() +"' as required!\nIt is of type '"+
4763 ValTy->getDescription() + "'");
4764 Elems.push_back(C);
4765 }
Chris Lattnercf786592007-12-29 20:47:37 +00004766 (yyval.ConstVal).C = ConstantVector::get(PTy, Elems);
4767 (yyval.ConstVal).S.copy((yyvsp[(1) - (4)].TypeVal).S);
4768 delete (yyvsp[(1) - (4)].TypeVal).PAT;
4769 delete (yyvsp[(3) - (4)].ConstVector);
4770 ;}
4771 break;
4772
4773 case 149:
4774#line 2272 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4775 {
4776 const StructType *STy = dyn_cast<StructType>((yyvsp[(1) - (4)].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004777 if (STy == 0)
4778 error("Cannot make struct constant with type: '" +
Chris Lattnercf786592007-12-29 20:47:37 +00004779 (yyvsp[(1) - (4)].TypeVal).PAT->get()->getDescription() + "'");
4780 if ((yyvsp[(3) - (4)].ConstVector)->size() != STy->getNumContainedTypes())
Reid Spencer950bf602007-01-26 08:19:09 +00004781 error("Illegal number of initializers for structure type");
4782
4783 // Check to ensure that constants are compatible with the type initializer!
4784 std::vector<Constant*> Fields;
Chris Lattnercf786592007-12-29 20:47:37 +00004785 for (unsigned i = 0, e = (yyvsp[(3) - (4)].ConstVector)->size(); i != e; ++i) {
4786 Constant *C = (*(yyvsp[(3) - (4)].ConstVector))[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004787 if (C->getType() != STy->getElementType(i))
4788 error("Expected type '" + STy->getElementType(i)->getDescription() +
4789 "' for element #" + utostr(i) + " of structure initializer");
4790 Fields.push_back(C);
4791 }
Chris Lattnercf786592007-12-29 20:47:37 +00004792 (yyval.ConstVal).C = ConstantStruct::get(STy, Fields);
4793 (yyval.ConstVal).S.copy((yyvsp[(1) - (4)].TypeVal).S);
4794 delete (yyvsp[(1) - (4)].TypeVal).PAT;
4795 delete (yyvsp[(3) - (4)].ConstVector);
4796 ;}
4797 break;
4798
4799 case 150:
4800#line 2294 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4801 {
4802 const StructType *STy = dyn_cast<StructType>((yyvsp[(1) - (3)].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004803 if (STy == 0)
4804 error("Cannot make struct constant with type: '" +
Chris Lattnercf786592007-12-29 20:47:37 +00004805 (yyvsp[(1) - (3)].TypeVal).PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004806 if (STy->getNumContainedTypes() != 0)
4807 error("Illegal number of initializers for structure type");
Chris Lattnercf786592007-12-29 20:47:37 +00004808 (yyval.ConstVal).C = ConstantStruct::get(STy, std::vector<Constant*>());
4809 (yyval.ConstVal).S.copy((yyvsp[(1) - (3)].TypeVal).S);
4810 delete (yyvsp[(1) - (3)].TypeVal).PAT;
4811 ;}
4812 break;
4813
4814 case 151:
4815#line 2305 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4816 {
4817 const StructType *STy = dyn_cast<StructType>((yyvsp[(1) - (6)].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004818 if (STy == 0)
4819 error("Cannot make packed struct constant with type: '" +
Chris Lattnercf786592007-12-29 20:47:37 +00004820 (yyvsp[(1) - (6)].TypeVal).PAT->get()->getDescription() + "'");
4821 if ((yyvsp[(4) - (6)].ConstVector)->size() != STy->getNumContainedTypes())
Reid Spencer950bf602007-01-26 08:19:09 +00004822 error("Illegal number of initializers for packed structure type");
4823
4824 // Check to ensure that constants are compatible with the type initializer!
4825 std::vector<Constant*> Fields;
Chris Lattnercf786592007-12-29 20:47:37 +00004826 for (unsigned i = 0, e = (yyvsp[(4) - (6)].ConstVector)->size(); i != e; ++i) {
4827 Constant *C = (*(yyvsp[(4) - (6)].ConstVector))[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004828 if (C->getType() != STy->getElementType(i))
4829 error("Expected type '" + STy->getElementType(i)->getDescription() +
4830 "' for element #" + utostr(i) + " of packed struct initializer");
4831 Fields.push_back(C);
4832 }
Chris Lattnercf786592007-12-29 20:47:37 +00004833 (yyval.ConstVal).C = ConstantStruct::get(STy, Fields);
4834 (yyval.ConstVal).S.copy((yyvsp[(1) - (6)].TypeVal).S);
4835 delete (yyvsp[(1) - (6)].TypeVal).PAT;
4836 delete (yyvsp[(4) - (6)].ConstVector);
4837 ;}
4838 break;
4839
4840 case 152:
4841#line 2327 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4842 {
4843 const StructType *STy = dyn_cast<StructType>((yyvsp[(1) - (5)].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004844 if (STy == 0)
4845 error("Cannot make packed struct constant with type: '" +
Chris Lattnercf786592007-12-29 20:47:37 +00004846 (yyvsp[(1) - (5)].TypeVal).PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004847 if (STy->getNumContainedTypes() != 0)
4848 error("Illegal number of initializers for packed structure type");
Chris Lattnercf786592007-12-29 20:47:37 +00004849 (yyval.ConstVal).C = ConstantStruct::get(STy, std::vector<Constant*>());
4850 (yyval.ConstVal).S.copy((yyvsp[(1) - (5)].TypeVal).S);
4851 delete (yyvsp[(1) - (5)].TypeVal).PAT;
4852 ;}
4853 break;
4854
4855 case 153:
4856#line 2338 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4857 {
4858 const PointerType *PTy = dyn_cast<PointerType>((yyvsp[(1) - (2)].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004859 if (PTy == 0)
4860 error("Cannot make null pointer constant with type: '" +
Chris Lattnercf786592007-12-29 20:47:37 +00004861 (yyvsp[(1) - (2)].TypeVal).PAT->get()->getDescription() + "'");
4862 (yyval.ConstVal).C = ConstantPointerNull::get(PTy);
4863 (yyval.ConstVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
4864 delete (yyvsp[(1) - (2)].TypeVal).PAT;
4865 ;}
4866 break;
4867
4868 case 154:
4869#line 2347 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4870 {
4871 (yyval.ConstVal).C = UndefValue::get((yyvsp[(1) - (2)].TypeVal).PAT->get());
4872 (yyval.ConstVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
4873 delete (yyvsp[(1) - (2)].TypeVal).PAT;
4874 ;}
4875 break;
4876
4877 case 155:
4878#line 2352 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4879 {
4880 const PointerType *Ty = dyn_cast<PointerType>((yyvsp[(1) - (2)].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004881 if (Ty == 0)
4882 error("Global const reference must be a pointer type, not" +
Chris Lattnercf786592007-12-29 20:47:37 +00004883 (yyvsp[(1) - (2)].TypeVal).PAT->get()->getDescription());
Reid Spencer950bf602007-01-26 08:19:09 +00004884
4885 // ConstExprs can exist in the body of a function, thus creating
4886 // GlobalValues whenever they refer to a variable. Because we are in
4887 // the context of a function, getExistingValue will search the functions
4888 // symbol table instead of the module symbol table for the global symbol,
4889 // which throws things all off. To get around this, we just tell
4890 // getExistingValue that we are at global scope here.
4891 //
4892 Function *SavedCurFn = CurFun.CurrentFunction;
4893 CurFun.CurrentFunction = 0;
Chris Lattnercf786592007-12-29 20:47:37 +00004894 (yyvsp[(2) - (2)].ValIDVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
4895 Value *V = getExistingValue(Ty, (yyvsp[(2) - (2)].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00004896 CurFun.CurrentFunction = SavedCurFn;
4897
4898 // If this is an initializer for a constant pointer, which is referencing a
4899 // (currently) undefined variable, create a stub now that shall be replaced
4900 // in the future with the right type of variable.
4901 //
4902 if (V == 0) {
4903 assert(isa<PointerType>(Ty) && "Globals may only be used as pointers");
4904 const PointerType *PT = cast<PointerType>(Ty);
4905
4906 // First check to see if the forward references value is already created!
4907 PerModuleInfo::GlobalRefsType::iterator I =
Chris Lattnercf786592007-12-29 20:47:37 +00004908 CurModule.GlobalRefs.find(std::make_pair(PT, (yyvsp[(2) - (2)].ValIDVal)));
Reid Spencer950bf602007-01-26 08:19:09 +00004909
4910 if (I != CurModule.GlobalRefs.end()) {
4911 V = I->second; // Placeholder already exists, use it...
Chris Lattnercf786592007-12-29 20:47:37 +00004912 (yyvsp[(2) - (2)].ValIDVal).destroy();
Reid Spencer950bf602007-01-26 08:19:09 +00004913 } else {
4914 std::string Name;
Chris Lattnercf786592007-12-29 20:47:37 +00004915 if ((yyvsp[(2) - (2)].ValIDVal).Type == ValID::NameVal) Name = (yyvsp[(2) - (2)].ValIDVal).Name;
Reid Spencer950bf602007-01-26 08:19:09 +00004916
4917 // Create the forward referenced global.
4918 GlobalValue *GV;
4919 if (const FunctionType *FTy =
4920 dyn_cast<FunctionType>(PT->getElementType())) {
4921 GV = new Function(FTy, GlobalValue::ExternalLinkage, Name,
4922 CurModule.CurrentModule);
4923 } else {
4924 GV = new GlobalVariable(PT->getElementType(), false,
4925 GlobalValue::ExternalLinkage, 0,
4926 Name, CurModule.CurrentModule);
4927 }
4928
4929 // Keep track of the fact that we have a forward ref to recycle it
Chris Lattnercf786592007-12-29 20:47:37 +00004930 CurModule.GlobalRefs.insert(std::make_pair(std::make_pair(PT, (yyvsp[(2) - (2)].ValIDVal)), GV));
Reid Spencer950bf602007-01-26 08:19:09 +00004931 V = GV;
4932 }
4933 }
Chris Lattnercf786592007-12-29 20:47:37 +00004934 (yyval.ConstVal).C = cast<GlobalValue>(V);
4935 (yyval.ConstVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
4936 delete (yyvsp[(1) - (2)].TypeVal).PAT; // Free the type handle
4937 ;}
4938 break;
4939
4940 case 156:
4941#line 2411 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4942 {
4943 if ((yyvsp[(1) - (2)].TypeVal).PAT->get() != (yyvsp[(2) - (2)].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004944 error("Mismatched types for constant expression");
Chris Lattnercf786592007-12-29 20:47:37 +00004945 (yyval.ConstVal) = (yyvsp[(2) - (2)].ConstVal);
4946 (yyval.ConstVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
4947 delete (yyvsp[(1) - (2)].TypeVal).PAT;
4948 ;}
4949 break;
4950
4951 case 157:
4952#line 2418 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4953 {
4954 const Type *Ty = (yyvsp[(1) - (2)].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00004955 if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
4956 error("Cannot create a null initialized value of this type");
Chris Lattnercf786592007-12-29 20:47:37 +00004957 (yyval.ConstVal).C = Constant::getNullValue(Ty);
4958 (yyval.ConstVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
4959 delete (yyvsp[(1) - (2)].TypeVal).PAT;
4960 ;}
4961 break;
4962
4963 case 158:
4964#line 2426 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4965 { // integral constants
4966 const Type *Ty = (yyvsp[(1) - (2)].PrimType).T;
4967 if (!ConstantInt::isValueValidForType(Ty, (yyvsp[(2) - (2)].SInt64Val)))
Reid Spencer950bf602007-01-26 08:19:09 +00004968 error("Constant value doesn't fit in type");
Chris Lattnercf786592007-12-29 20:47:37 +00004969 (yyval.ConstVal).C = ConstantInt::get(Ty, (yyvsp[(2) - (2)].SInt64Val));
4970 (yyval.ConstVal).S.makeSigned();
4971 ;}
4972 break;
4973
4974 case 159:
4975#line 2433 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4976 { // integral constants
4977 const Type *Ty = (yyvsp[(1) - (2)].PrimType).T;
4978 if (!ConstantInt::isValueValidForType(Ty, (yyvsp[(2) - (2)].UInt64Val)))
Reid Spencer950bf602007-01-26 08:19:09 +00004979 error("Constant value doesn't fit in type");
Chris Lattnercf786592007-12-29 20:47:37 +00004980 (yyval.ConstVal).C = ConstantInt::get(Ty, (yyvsp[(2) - (2)].UInt64Val));
4981 (yyval.ConstVal).S.makeUnsigned();
4982 ;}
4983 break;
4984
4985 case 160:
4986#line 2440 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4987 { // Boolean constants
4988 (yyval.ConstVal).C = ConstantInt::get(Type::Int1Ty, true);
4989 (yyval.ConstVal).S.makeUnsigned();
4990 ;}
4991 break;
4992
4993 case 161:
4994#line 2444 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
4995 { // Boolean constants
4996 (yyval.ConstVal).C = ConstantInt::get(Type::Int1Ty, false);
4997 (yyval.ConstVal).S.makeUnsigned();
4998 ;}
4999 break;
5000
5001 case 162:
5002#line 2448 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5003 { // Float & Double constants
5004 if (!ConstantFP::isValueValidForType((yyvsp[(1) - (2)].PrimType).T, *(yyvsp[(2) - (2)].FPVal)))
Reid Spencer950bf602007-01-26 08:19:09 +00005005 error("Floating point constant invalid for type");
Dale Johannesencdd509a2007-09-07 21:07:57 +00005006 // Lexer has no type info, so builds all FP constants as double.
5007 // Fix this here.
Chris Lattnercf786592007-12-29 20:47:37 +00005008 if ((yyvsp[(1) - (2)].PrimType).T==Type::FloatTy)
5009 (yyvsp[(2) - (2)].FPVal)->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
5010 (yyval.ConstVal).C = ConstantFP::get((yyvsp[(1) - (2)].PrimType).T, *(yyvsp[(2) - (2)].FPVal));
5011 delete (yyvsp[(2) - (2)].FPVal);
5012 (yyval.ConstVal).S.makeSignless();
5013 ;}
5014 break;
5015
5016 case 163:
5017#line 2462 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5018 {
5019 const Type* SrcTy = (yyvsp[(3) - (6)].ConstVal).C->getType();
5020 const Type* DstTy = (yyvsp[(5) - (6)].TypeVal).PAT->get();
5021 Signedness SrcSign((yyvsp[(3) - (6)].ConstVal).S);
5022 Signedness DstSign((yyvsp[(5) - (6)].TypeVal).S);
Reid Spencer950bf602007-01-26 08:19:09 +00005023 if (!SrcTy->isFirstClassType())
5024 error("cast constant expression from a non-primitive type: '" +
5025 SrcTy->getDescription() + "'");
5026 if (!DstTy->isFirstClassType())
5027 error("cast constant expression to a non-primitive type: '" +
5028 DstTy->getDescription() + "'");
Chris Lattnercf786592007-12-29 20:47:37 +00005029 (yyval.ConstVal).C = cast<Constant>(getCast((yyvsp[(1) - (6)].CastOpVal), (yyvsp[(3) - (6)].ConstVal).C, SrcSign, DstTy, DstSign));
5030 (yyval.ConstVal).S.copy(DstSign);
5031 delete (yyvsp[(5) - (6)].TypeVal).PAT;
5032 ;}
5033 break;
5034
5035 case 164:
5036#line 2477 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5037 {
5038 const Type *Ty = (yyvsp[(3) - (5)].ConstVal).C->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00005039 if (!isa<PointerType>(Ty))
5040 error("GetElementPtr requires a pointer operand");
5041
Reid Spencer950bf602007-01-26 08:19:09 +00005042 std::vector<Constant*> CIndices;
Chris Lattnercf786592007-12-29 20:47:37 +00005043 upgradeGEPCEIndices((yyvsp[(3) - (5)].ConstVal).C->getType(), (yyvsp[(4) - (5)].ValueList), CIndices);
Reid Spencer950bf602007-01-26 08:19:09 +00005044
Chris Lattnercf786592007-12-29 20:47:37 +00005045 delete (yyvsp[(4) - (5)].ValueList);
5046 (yyval.ConstVal).C = ConstantExpr::getGetElementPtr((yyvsp[(3) - (5)].ConstVal).C, &CIndices[0], CIndices.size());
5047 (yyval.ConstVal).S.copy(getElementSign((yyvsp[(3) - (5)].ConstVal), CIndices));
5048 ;}
5049 break;
5050
5051 case 165:
5052#line 2489 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5053 {
5054 if (!(yyvsp[(3) - (8)].ConstVal).C->getType()->isInteger() ||
5055 cast<IntegerType>((yyvsp[(3) - (8)].ConstVal).C->getType())->getBitWidth() != 1)
Reid Spencer950bf602007-01-26 08:19:09 +00005056 error("Select condition must be bool type");
Chris Lattnercf786592007-12-29 20:47:37 +00005057 if ((yyvsp[(5) - (8)].ConstVal).C->getType() != (yyvsp[(7) - (8)].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00005058 error("Select operand types must match");
Chris Lattnercf786592007-12-29 20:47:37 +00005059 (yyval.ConstVal).C = ConstantExpr::getSelect((yyvsp[(3) - (8)].ConstVal).C, (yyvsp[(5) - (8)].ConstVal).C, (yyvsp[(7) - (8)].ConstVal).C);
5060 (yyval.ConstVal).S.copy((yyvsp[(5) - (8)].ConstVal).S);
5061 ;}
5062 break;
5063
5064 case 166:
5065#line 2498 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5066 {
5067 const Type *Ty = (yyvsp[(3) - (6)].ConstVal).C->getType();
5068 if (Ty != (yyvsp[(5) - (6)].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00005069 error("Binary operator types must match");
5070 // First, make sure we're dealing with the right opcode by upgrading from
5071 // obsolete versions.
Chris Lattnercf786592007-12-29 20:47:37 +00005072 Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[(1) - (6)].BinaryOpVal), Ty, (yyvsp[(3) - (6)].ConstVal).S);
Reid Spencer950bf602007-01-26 08:19:09 +00005073
5074 // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs.
5075 // To retain backward compatibility with these early compilers, we emit a
5076 // cast to the appropriate integer type automatically if we are in the
5077 // broken case. See PR424 for more information.
5078 if (!isa<PointerType>(Ty)) {
Chris Lattnercf786592007-12-29 20:47:37 +00005079 (yyval.ConstVal).C = ConstantExpr::get(Opcode, (yyvsp[(3) - (6)].ConstVal).C, (yyvsp[(5) - (6)].ConstVal).C);
Reid Spencer950bf602007-01-26 08:19:09 +00005080 } else {
5081 const Type *IntPtrTy = 0;
5082 switch (CurModule.CurrentModule->getPointerSize()) {
5083 case Module::Pointer32: IntPtrTy = Type::Int32Ty; break;
5084 case Module::Pointer64: IntPtrTy = Type::Int64Ty; break;
5085 default: error("invalid pointer binary constant expr");
5086 }
Chris Lattnercf786592007-12-29 20:47:37 +00005087 (yyval.ConstVal).C = ConstantExpr::get(Opcode,
5088 ConstantExpr::getCast(Instruction::PtrToInt, (yyvsp[(3) - (6)].ConstVal).C, IntPtrTy),
5089 ConstantExpr::getCast(Instruction::PtrToInt, (yyvsp[(5) - (6)].ConstVal).C, IntPtrTy));
5090 (yyval.ConstVal).C = ConstantExpr::getCast(Instruction::IntToPtr, (yyval.ConstVal).C, Ty);
Reid Spencer950bf602007-01-26 08:19:09 +00005091 }
Chris Lattnercf786592007-12-29 20:47:37 +00005092 (yyval.ConstVal).S.copy((yyvsp[(3) - (6)].ConstVal).S);
5093 ;}
5094 break;
5095
5096 case 167:
5097#line 2526 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5098 {
5099 const Type* Ty = (yyvsp[(3) - (6)].ConstVal).C->getType();
5100 if (Ty != (yyvsp[(5) - (6)].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00005101 error("Logical operator types must match");
5102 if (!Ty->isInteger()) {
Reid Spencer9d6565a2007-02-15 02:26:10 +00005103 if (!isa<VectorType>(Ty) ||
5104 !cast<VectorType>(Ty)->getElementType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00005105 error("Logical operator requires integer operands");
5106 }
Chris Lattnercf786592007-12-29 20:47:37 +00005107 Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[(1) - (6)].BinaryOpVal), Ty, (yyvsp[(3) - (6)].ConstVal).S);
5108 (yyval.ConstVal).C = ConstantExpr::get(Opcode, (yyvsp[(3) - (6)].ConstVal).C, (yyvsp[(5) - (6)].ConstVal).C);
5109 (yyval.ConstVal).S.copy((yyvsp[(3) - (6)].ConstVal).S);
5110 ;}
5111 break;
5112
5113 case 168:
5114#line 2539 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5115 {
5116 const Type* Ty = (yyvsp[(3) - (6)].ConstVal).C->getType();
5117 if (Ty != (yyvsp[(5) - (6)].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00005118 error("setcc operand types must match");
5119 unsigned short pred;
Chris Lattnercf786592007-12-29 20:47:37 +00005120 Instruction::OtherOps Opcode = getCompareOp((yyvsp[(1) - (6)].BinaryOpVal), pred, Ty, (yyvsp[(3) - (6)].ConstVal).S);
5121 (yyval.ConstVal).C = ConstantExpr::getCompare(Opcode, (yyvsp[(3) - (6)].ConstVal).C, (yyvsp[(5) - (6)].ConstVal).C);
5122 (yyval.ConstVal).S.makeUnsigned();
5123 ;}
5124 break;
5125
5126 case 169:
5127#line 2548 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5128 {
5129 if ((yyvsp[(4) - (7)].ConstVal).C->getType() != (yyvsp[(6) - (7)].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00005130 error("icmp operand types must match");
Chris Lattnercf786592007-12-29 20:47:37 +00005131 (yyval.ConstVal).C = ConstantExpr::getCompare((yyvsp[(2) - (7)].IPred), (yyvsp[(4) - (7)].ConstVal).C, (yyvsp[(6) - (7)].ConstVal).C);
5132 (yyval.ConstVal).S.makeUnsigned();
5133 ;}
5134 break;
5135
5136 case 170:
5137#line 2554 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5138 {
5139 if ((yyvsp[(4) - (7)].ConstVal).C->getType() != (yyvsp[(6) - (7)].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00005140 error("fcmp operand types must match");
Chris Lattnercf786592007-12-29 20:47:37 +00005141 (yyval.ConstVal).C = ConstantExpr::getCompare((yyvsp[(2) - (7)].FPred), (yyvsp[(4) - (7)].ConstVal).C, (yyvsp[(6) - (7)].ConstVal).C);
5142 (yyval.ConstVal).S.makeUnsigned();
5143 ;}
5144 break;
5145
5146 case 171:
5147#line 2560 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5148 {
5149 if (!(yyvsp[(5) - (6)].ConstVal).C->getType()->isInteger() ||
5150 cast<IntegerType>((yyvsp[(5) - (6)].ConstVal).C->getType())->getBitWidth() != 8)
Reid Spencer950bf602007-01-26 08:19:09 +00005151 error("Shift count for shift constant must be unsigned byte");
Chris Lattnercf786592007-12-29 20:47:37 +00005152 const Type* Ty = (yyvsp[(3) - (6)].ConstVal).C->getType();
5153 if (!(yyvsp[(3) - (6)].ConstVal).C->getType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00005154 error("Shift constant expression requires integer operand");
Chris Lattnercf786592007-12-29 20:47:37 +00005155 Constant *ShiftAmt = ConstantExpr::getZExt((yyvsp[(5) - (6)].ConstVal).C, Ty);
5156 (yyval.ConstVal).C = ConstantExpr::get(getBinaryOp((yyvsp[(1) - (6)].BinaryOpVal), Ty, (yyvsp[(3) - (6)].ConstVal).S), (yyvsp[(3) - (6)].ConstVal).C, ShiftAmt);
5157 (yyval.ConstVal).S.copy((yyvsp[(3) - (6)].ConstVal).S);
5158 ;}
5159 break;
5160
5161 case 172:
5162#line 2571 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5163 {
5164 if (!ExtractElementInst::isValidOperands((yyvsp[(3) - (6)].ConstVal).C, (yyvsp[(5) - (6)].ConstVal).C))
Reid Spencer950bf602007-01-26 08:19:09 +00005165 error("Invalid extractelement operands");
Chris Lattnercf786592007-12-29 20:47:37 +00005166 (yyval.ConstVal).C = ConstantExpr::getExtractElement((yyvsp[(3) - (6)].ConstVal).C, (yyvsp[(5) - (6)].ConstVal).C);
5167 (yyval.ConstVal).S.copy((yyvsp[(3) - (6)].ConstVal).S.get(0));
5168 ;}
5169 break;
5170
5171 case 173:
5172#line 2577 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5173 {
5174 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 +00005175 error("Invalid insertelement operands");
Chris Lattnercf786592007-12-29 20:47:37 +00005176 (yyval.ConstVal).C = ConstantExpr::getInsertElement((yyvsp[(3) - (8)].ConstVal).C, (yyvsp[(5) - (8)].ConstVal).C, (yyvsp[(7) - (8)].ConstVal).C);
5177 (yyval.ConstVal).S.copy((yyvsp[(3) - (8)].ConstVal).S);
5178 ;}
5179 break;
5180
5181 case 174:
5182#line 2583 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5183 {
5184 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 +00005185 error("Invalid shufflevector operands");
Chris Lattnercf786592007-12-29 20:47:37 +00005186 (yyval.ConstVal).C = ConstantExpr::getShuffleVector((yyvsp[(3) - (8)].ConstVal).C, (yyvsp[(5) - (8)].ConstVal).C, (yyvsp[(7) - (8)].ConstVal).C);
5187 (yyval.ConstVal).S.copy((yyvsp[(3) - (8)].ConstVal).S);
5188 ;}
5189 break;
5190
5191 case 175:
5192#line 2594 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5193 { ((yyval.ConstVector) = (yyvsp[(1) - (3)].ConstVector))->push_back((yyvsp[(3) - (3)].ConstVal)); ;}
5194 break;
5195
5196 case 176:
5197#line 2595 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5198 {
5199 (yyval.ConstVector) = new std::vector<ConstInfo>();
5200 (yyval.ConstVector)->push_back((yyvsp[(1) - (1)].ConstVal));
5201 ;}
5202 break;
5203
5204 case 177:
5205#line 2604 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5206 { (yyval.BoolVal) = false; ;}
5207 break;
5208
5209 case 178:
5210#line 2605 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5211 { (yyval.BoolVal) = true; ;}
5212 break;
5213
5214 case 179:
5215#line 2617 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5216 {
5217 (yyval.ModuleVal) = ParserResult = (yyvsp[(1) - (1)].ModuleVal);
Reid Spencer950bf602007-01-26 08:19:09 +00005218 CurModule.ModuleDone();
Chris Lattnercf786592007-12-29 20:47:37 +00005219 ;}
5220 break;
5221
5222 case 180:
5223#line 2626 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5224 { (yyval.ModuleVal) = (yyvsp[(1) - (2)].ModuleVal); CurFun.FunctionDone(); ;}
5225 break;
5226
5227 case 181:
5228#line 2627 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5229 { (yyval.ModuleVal) = (yyvsp[(1) - (2)].ModuleVal); ;}
5230 break;
5231
5232 case 182:
5233#line 2628 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5234 { (yyval.ModuleVal) = (yyvsp[(1) - (4)].ModuleVal); ;}
5235 break;
5236
5237 case 183:
5238#line 2629 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5239 { (yyval.ModuleVal) = (yyvsp[(1) - (2)].ModuleVal); ;}
5240 break;
5241
5242 case 184:
5243#line 2630 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5244 {
5245 (yyval.ModuleVal) = CurModule.CurrentModule;
Reid Spencer950bf602007-01-26 08:19:09 +00005246 // Emit an error if there are any unresolved types left.
5247 if (!CurModule.LateResolveTypes.empty()) {
5248 const ValID &DID = CurModule.LateResolveTypes.begin()->first;
5249 if (DID.Type == ValID::NameVal) {
5250 error("Reference to an undefined type: '"+DID.getName() + "'");
5251 } else {
5252 error("Reference to an undefined type: #" + itostr(DID.Num));
5253 }
5254 }
Chris Lattnercf786592007-12-29 20:47:37 +00005255 ;}
5256 break;
5257
5258 case 185:
5259#line 2646 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5260 {
Reid Spencer950bf602007-01-26 08:19:09 +00005261 // Eagerly resolve types. This is not an optimization, this is a
5262 // requirement that is due to the fact that we could have this:
5263 //
5264 // %list = type { %list * }
5265 // %list = type { %list * } ; repeated type decl
5266 //
5267 // If types are not resolved eagerly, then the two types will not be
5268 // determined to be the same type!
5269 //
Chris Lattnercf786592007-12-29 20:47:37 +00005270 ResolveTypeTo((yyvsp[(2) - (4)].StrVal), (yyvsp[(4) - (4)].TypeVal).PAT->get(), (yyvsp[(4) - (4)].TypeVal).S);
Reid Spencer950bf602007-01-26 08:19:09 +00005271
Chris Lattnercf786592007-12-29 20:47:37 +00005272 if (!setTypeName((yyvsp[(4) - (4)].TypeVal), (yyvsp[(2) - (4)].StrVal)) && !(yyvsp[(2) - (4)].StrVal)) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00005273 // If this is a numbered type that is not a redefinition, add it to the
5274 // slot table.
Chris Lattnercf786592007-12-29 20:47:37 +00005275 CurModule.Types.push_back((yyvsp[(4) - (4)].TypeVal).PAT->get());
5276 CurModule.TypeSigns.push_back((yyvsp[(4) - (4)].TypeVal).S);
Reid Spencera50d5962006-12-02 04:11:07 +00005277 }
Chris Lattnercf786592007-12-29 20:47:37 +00005278 delete (yyvsp[(4) - (4)].TypeVal).PAT;
5279 ;}
5280 break;
5281
5282 case 186:
5283#line 2666 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5284 { // Function prototypes can be in const pool
5285 ;}
5286 break;
5287
5288 case 187:
5289#line 2668 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5290 { // Asm blocks can be in the const pool
5291 ;}
5292 break;
5293
5294 case 188:
5295#line 2670 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5296 {
5297 if ((yyvsp[(5) - (5)].ConstVal).C == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00005298 error("Global value initializer is not a constant");
Chris Lattnercf786592007-12-29 20:47:37 +00005299 CurGV = ParseGlobalVariable((yyvsp[(2) - (5)].StrVal), (yyvsp[(3) - (5)].Linkage), (yyvsp[(4) - (5)].BoolVal), (yyvsp[(5) - (5)].ConstVal).C->getType(), (yyvsp[(5) - (5)].ConstVal).C, (yyvsp[(5) - (5)].ConstVal).S);
5300 ;}
5301 break;
5302
5303 case 189:
5304#line 2674 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5305 {
Reid Spencer950bf602007-01-26 08:19:09 +00005306 CurGV = 0;
Chris Lattnercf786592007-12-29 20:47:37 +00005307 ;}
5308 break;
5309
5310 case 190:
5311#line 2677 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5312 {
5313 const Type *Ty = (yyvsp[(5) - (5)].TypeVal).PAT->get();
5314 CurGV = ParseGlobalVariable((yyvsp[(2) - (5)].StrVal), GlobalValue::ExternalLinkage, (yyvsp[(4) - (5)].BoolVal), Ty, 0,
5315 (yyvsp[(5) - (5)].TypeVal).S);
5316 delete (yyvsp[(5) - (5)].TypeVal).PAT;
5317 ;}
5318 break;
5319
5320 case 191:
5321#line 2682 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5322 {
Reid Spencer950bf602007-01-26 08:19:09 +00005323 CurGV = 0;
Chris Lattnercf786592007-12-29 20:47:37 +00005324 ;}
5325 break;
5326
5327 case 192:
5328#line 2685 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5329 {
5330 const Type *Ty = (yyvsp[(5) - (5)].TypeVal).PAT->get();
5331 CurGV = ParseGlobalVariable((yyvsp[(2) - (5)].StrVal), GlobalValue::DLLImportLinkage, (yyvsp[(4) - (5)].BoolVal), Ty, 0,
5332 (yyvsp[(5) - (5)].TypeVal).S);
5333 delete (yyvsp[(5) - (5)].TypeVal).PAT;
5334 ;}
5335 break;
5336
5337 case 193:
5338#line 2690 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5339 {
Reid Spencer950bf602007-01-26 08:19:09 +00005340 CurGV = 0;
Chris Lattnercf786592007-12-29 20:47:37 +00005341 ;}
5342 break;
5343
5344 case 194:
5345#line 2693 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5346 {
5347 const Type *Ty = (yyvsp[(5) - (5)].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005348 CurGV =
Chris Lattnercf786592007-12-29 20:47:37 +00005349 ParseGlobalVariable((yyvsp[(2) - (5)].StrVal), GlobalValue::ExternalWeakLinkage, (yyvsp[(4) - (5)].BoolVal), Ty, 0,
5350 (yyvsp[(5) - (5)].TypeVal).S);
5351 delete (yyvsp[(5) - (5)].TypeVal).PAT;
5352 ;}
5353 break;
5354
5355 case 195:
5356#line 2699 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5357 {
Reid Spencer950bf602007-01-26 08:19:09 +00005358 CurGV = 0;
Chris Lattnercf786592007-12-29 20:47:37 +00005359 ;}
5360 break;
5361
5362 case 196:
5363#line 2702 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5364 {
5365 ;}
5366 break;
5367
5368 case 197:
5369#line 2704 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5370 {
5371 ;}
5372 break;
5373
5374 case 198:
5375#line 2706 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5376 {
5377 ;}
5378 break;
5379
5380 case 199:
5381#line 2711 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5382 {
Reid Spencer950bf602007-01-26 08:19:09 +00005383 const std::string &AsmSoFar = CurModule.CurrentModule->getModuleInlineAsm();
Chris Lattnercf786592007-12-29 20:47:37 +00005384 char *EndStr = UnEscapeLexed((yyvsp[(1) - (1)].StrVal), true);
5385 std::string NewAsm((yyvsp[(1) - (1)].StrVal), EndStr);
5386 free((yyvsp[(1) - (1)].StrVal));
Reid Spencer950bf602007-01-26 08:19:09 +00005387
5388 if (AsmSoFar.empty())
5389 CurModule.CurrentModule->setModuleInlineAsm(NewAsm);
5390 else
5391 CurModule.CurrentModule->setModuleInlineAsm(AsmSoFar+"\n"+NewAsm);
Chris Lattnercf786592007-12-29 20:47:37 +00005392 ;}
5393 break;
5394
5395 case 200:
5396#line 2725 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5397 { (yyval.Endianness) = Module::BigEndian; ;}
5398 break;
5399
5400 case 201:
5401#line 2726 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5402 { (yyval.Endianness) = Module::LittleEndian; ;}
5403 break;
5404
5405 case 202:
5406#line 2730 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5407 {
5408 CurModule.setEndianness((yyvsp[(3) - (3)].Endianness));
5409 ;}
5410 break;
5411
5412 case 203:
5413#line 2733 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5414 {
5415 if ((yyvsp[(3) - (3)].UInt64Val) == 32)
Reid Spencer950bf602007-01-26 08:19:09 +00005416 CurModule.setPointerSize(Module::Pointer32);
Chris Lattnercf786592007-12-29 20:47:37 +00005417 else if ((yyvsp[(3) - (3)].UInt64Val) == 64)
Reid Spencer950bf602007-01-26 08:19:09 +00005418 CurModule.setPointerSize(Module::Pointer64);
5419 else
Chris Lattnercf786592007-12-29 20:47:37 +00005420 error("Invalid pointer size: '" + utostr((yyvsp[(3) - (3)].UInt64Val)) + "'");
5421 ;}
5422 break;
Duncan Sandsdc024672007-11-27 13:23:08 +00005423
Chris Lattnercf786592007-12-29 20:47:37 +00005424 case 204:
5425#line 2741 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5426 {
5427 CurModule.CurrentModule->setTargetTriple((yyvsp[(3) - (3)].StrVal));
5428 free((yyvsp[(3) - (3)].StrVal));
5429 ;}
5430 break;
5431
5432 case 205:
5433#line 2745 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5434 {
5435 CurModule.CurrentModule->setDataLayout((yyvsp[(3) - (3)].StrVal));
5436 free((yyvsp[(3) - (3)].StrVal));
5437 ;}
5438 break;
5439
5440 case 207:
5441#line 2756 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5442 {
5443 CurModule.CurrentModule->addLibrary((yyvsp[(3) - (3)].StrVal));
5444 free((yyvsp[(3) - (3)].StrVal));
5445 ;}
5446 break;
5447
5448 case 208:
5449#line 2760 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5450 {
5451 CurModule.CurrentModule->addLibrary((yyvsp[(1) - (1)].StrVal));
5452 free((yyvsp[(1) - (1)].StrVal));
5453 ;}
5454 break;
5455
5456 case 209:
5457#line 2764 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5458 { ;}
5459 break;
5460
5461 case 213:
5462#line 2777 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5463 { (yyval.StrVal) = 0; ;}
5464 break;
5465
5466 case 214:
5467#line 2781 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5468 {
5469 if ((yyvsp[(1) - (2)].TypeVal).PAT->get() == Type::VoidTy)
5470 error("void typed arguments are invalid");
5471 (yyval.ArgVal) = new std::pair<PATypeInfo, char*>((yyvsp[(1) - (2)].TypeVal), (yyvsp[(2) - (2)].StrVal));
5472 ;}
5473 break;
5474
5475 case 215:
5476#line 2789 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5477 {
5478 (yyval.ArgList) = (yyvsp[(1) - (3)].ArgList);
5479 (yyval.ArgList)->push_back(*(yyvsp[(3) - (3)].ArgVal));
5480 delete (yyvsp[(3) - (3)].ArgVal);
5481 ;}
5482 break;
5483
5484 case 216:
5485#line 2794 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5486 {
5487 (yyval.ArgList) = new std::vector<std::pair<PATypeInfo,char*> >();
5488 (yyval.ArgList)->push_back(*(yyvsp[(1) - (1)].ArgVal));
5489 delete (yyvsp[(1) - (1)].ArgVal);
5490 ;}
5491 break;
5492
5493 case 217:
5494#line 2802 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5495 { (yyval.ArgList) = (yyvsp[(1) - (1)].ArgList); ;}
5496 break;
5497
5498 case 218:
5499#line 2803 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5500 {
5501 (yyval.ArgList) = (yyvsp[(1) - (3)].ArgList);
5502 PATypeInfo VoidTI;
5503 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
5504 VoidTI.S.makeSignless();
5505 (yyval.ArgList)->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
5506 ;}
5507 break;
5508
5509 case 219:
5510#line 2810 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5511 {
5512 (yyval.ArgList) = new std::vector<std::pair<PATypeInfo,char*> >();
5513 PATypeInfo VoidTI;
5514 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
5515 VoidTI.S.makeSignless();
5516 (yyval.ArgList)->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
5517 ;}
5518 break;
5519
5520 case 220:
5521#line 2817 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5522 { (yyval.ArgList) = 0; ;}
5523 break;
5524
5525 case 221:
5526#line 2821 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5527 {
5528 UnEscapeLexed((yyvsp[(3) - (8)].StrVal));
5529 std::string FunctionName((yyvsp[(3) - (8)].StrVal));
5530 free((yyvsp[(3) - (8)].StrVal)); // Free strdup'd memory!
5531
5532 const Type* RetTy = (yyvsp[(2) - (8)].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005533
5534 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
5535 error("LLVM functions cannot return aggregate types");
5536
Reid Spencerbb1fd572007-03-21 17:15:50 +00005537 Signedness FTySign;
Chris Lattnercf786592007-12-29 20:47:37 +00005538 FTySign.makeComposite((yyvsp[(2) - (8)].TypeVal).S);
Reid Spenceref9b9a72007-02-05 20:47:22 +00005539 std::vector<const Type*> ParamTyList;
Reid Spencer950bf602007-01-26 08:19:09 +00005540
5541 // In LLVM 2.0 the signatures of three varargs intrinsics changed to take
5542 // i8*. We check here for those names and override the parameter list
5543 // types to ensure the prototype is correct.
5544 if (FunctionName == "llvm.va_start" || FunctionName == "llvm.va_end") {
Christopher Lamb4374f8e2007-12-17 01:17:35 +00005545 ParamTyList.push_back(PointerType::getUnqual(Type::Int8Ty));
Reid Spencer950bf602007-01-26 08:19:09 +00005546 } else if (FunctionName == "llvm.va_copy") {
Christopher Lamb4374f8e2007-12-17 01:17:35 +00005547 ParamTyList.push_back(PointerType::getUnqual(Type::Int8Ty));
5548 ParamTyList.push_back(PointerType::getUnqual(Type::Int8Ty));
Chris Lattnercf786592007-12-29 20:47:37 +00005549 } else if ((yyvsp[(5) - (8)].ArgList)) { // If there are arguments...
Reid Spencer950bf602007-01-26 08:19:09 +00005550 for (std::vector<std::pair<PATypeInfo,char*> >::iterator
Chris Lattnercf786592007-12-29 20:47:37 +00005551 I = (yyvsp[(5) - (8)].ArgList)->begin(), E = (yyvsp[(5) - (8)].ArgList)->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00005552 const Type *Ty = I->first.PAT->get();
Reid Spenceref9b9a72007-02-05 20:47:22 +00005553 ParamTyList.push_back(Ty);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005554 FTySign.add(I->first.S);
Reid Spencer950bf602007-01-26 08:19:09 +00005555 }
5556 }
5557
Reid Spenceref9b9a72007-02-05 20:47:22 +00005558 bool isVarArg = ParamTyList.size() && ParamTyList.back() == Type::VoidTy;
5559 if (isVarArg)
5560 ParamTyList.pop_back();
Reid Spencer950bf602007-01-26 08:19:09 +00005561
Duncan Sandsdc024672007-11-27 13:23:08 +00005562 const FunctionType *FT = FunctionType::get(RetTy, ParamTyList, isVarArg);
Christopher Lamb4374f8e2007-12-17 01:17:35 +00005563 const PointerType *PFT = PointerType::getUnqual(FT);
Chris Lattnercf786592007-12-29 20:47:37 +00005564 delete (yyvsp[(2) - (8)].TypeVal).PAT;
Reid Spencer950bf602007-01-26 08:19:09 +00005565
5566 ValID ID;
5567 if (!FunctionName.empty()) {
Reid Spencer5eb77c72007-03-15 03:26:42 +00005568 ID = ValID::create((char*)FunctionName.c_str());
Reid Spencer950bf602007-01-26 08:19:09 +00005569 } else {
Reid Spencer5eb77c72007-03-15 03:26:42 +00005570 ID = ValID::create((int)CurModule.Values[PFT].size());
Reid Spencer950bf602007-01-26 08:19:09 +00005571 }
Reid Spencerbb1fd572007-03-21 17:15:50 +00005572 ID.S.makeComposite(FTySign);
Reid Spencer950bf602007-01-26 08:19:09 +00005573
5574 Function *Fn = 0;
Reid Spencered96d1e2007-02-08 09:08:52 +00005575 Module* M = CurModule.CurrentModule;
5576
Reid Spencer950bf602007-01-26 08:19:09 +00005577 // See if this function was forward referenced. If so, recycle the object.
5578 if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, ID)) {
5579 // Move the function to the end of the list, from whereever it was
5580 // previously inserted.
5581 Fn = cast<Function>(FWRef);
Reid Spencered96d1e2007-02-08 09:08:52 +00005582 M->getFunctionList().remove(Fn);
5583 M->getFunctionList().push_back(Fn);
5584 } else if (!FunctionName.empty()) {
5585 GlobalValue *Conflict = M->getFunction(FunctionName);
5586 if (!Conflict)
5587 Conflict = M->getNamedGlobal(FunctionName);
5588 if (Conflict && PFT == Conflict->getType()) {
5589 if (!CurFun.isDeclare && !Conflict->isDeclaration()) {
5590 // We have two function definitions that conflict, same type, same
5591 // name. We should really check to make sure that this is the result
5592 // of integer type planes collapsing and generate an error if it is
5593 // not, but we'll just rename on the assumption that it is. However,
5594 // let's do it intelligently and rename the internal linkage one
5595 // if there is one.
5596 std::string NewName(makeNameUnique(FunctionName));
5597 if (Conflict->hasInternalLinkage()) {
5598 Conflict->setName(NewName);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005599 RenameMapKey Key =
5600 makeRenameMapKey(FunctionName, Conflict->getType(), ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00005601 CurModule.RenameMap[Key] = NewName;
5602 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5603 InsertValue(Fn, CurModule.Values);
5604 } else {
5605 Fn = new Function(FT, CurFun.Linkage, NewName, M);
5606 InsertValue(Fn, CurModule.Values);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005607 RenameMapKey Key =
5608 makeRenameMapKey(FunctionName, PFT, ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00005609 CurModule.RenameMap[Key] = NewName;
5610 }
5611 } else {
5612 // If they are not both definitions, then just use the function we
5613 // found since the types are the same.
5614 Fn = cast<Function>(Conflict);
Reid Spenceref9b9a72007-02-05 20:47:22 +00005615
Reid Spencered96d1e2007-02-08 09:08:52 +00005616 // Make sure to strip off any argument names so we can't get
5617 // conflicts.
5618 if (Fn->isDeclaration())
5619 for (Function::arg_iterator AI = Fn->arg_begin(),
5620 AE = Fn->arg_end(); AI != AE; ++AI)
5621 AI->setName("");
5622 }
5623 } else if (Conflict) {
Reid Spencere59f4932007-04-16 03:05:01 +00005624 // We have two globals with the same name and different types.
Reid Spencered96d1e2007-02-08 09:08:52 +00005625 // Previously, this was permitted because the symbol table had
5626 // "type planes" and names only needed to be distinct within a
5627 // type plane. After PR411 was fixed, this is no loner the case.
5628 // To resolve this we must rename one of the two.
5629 if (Conflict->hasInternalLinkage()) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00005630 // We can safely rename the Conflict.
5631 RenameMapKey Key =
5632 makeRenameMapKey(Conflict->getName(), Conflict->getType(),
5633 CurModule.NamedValueSigns[Conflict->getName()]);
Reid Spencered96d1e2007-02-08 09:08:52 +00005634 Conflict->setName(makeNameUnique(Conflict->getName()));
Reid Spencered96d1e2007-02-08 09:08:52 +00005635 CurModule.RenameMap[Key] = Conflict->getName();
5636 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5637 InsertValue(Fn, CurModule.Values);
Reid Spencerd2920cd2007-03-21 17:27:53 +00005638 } else {
Reid Spencered96d1e2007-02-08 09:08:52 +00005639 // We can't quietly rename either of these things, but we must
Reid Spencerd2920cd2007-03-21 17:27:53 +00005640 // rename one of them. Only if the function's linkage is internal can
5641 // we forgo a warning message about the renamed function.
Reid Spencered96d1e2007-02-08 09:08:52 +00005642 std::string NewName = makeNameUnique(FunctionName);
Reid Spencerd2920cd2007-03-21 17:27:53 +00005643 if (CurFun.Linkage != GlobalValue::InternalLinkage) {
5644 warning("Renaming function '" + FunctionName + "' as '" + NewName +
5645 "' may cause linkage errors");
5646 }
5647 // Elect to rename the thing we're now defining.
Reid Spencered96d1e2007-02-08 09:08:52 +00005648 Fn = new Function(FT, CurFun.Linkage, NewName, M);
5649 InsertValue(Fn, CurModule.Values);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005650 RenameMapKey Key = makeRenameMapKey(FunctionName, PFT, ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00005651 CurModule.RenameMap[Key] = NewName;
Reid Spencerd2920cd2007-03-21 17:27:53 +00005652 }
Reid Spenceref9b9a72007-02-05 20:47:22 +00005653 } else {
Reid Spencered96d1e2007-02-08 09:08:52 +00005654 // There's no conflict, just define the function
5655 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5656 InsertValue(Fn, CurModule.Values);
Reid Spenceref9b9a72007-02-05 20:47:22 +00005657 }
Reid Spencere59f4932007-04-16 03:05:01 +00005658 } else {
5659 // There's no conflict, just define the function
5660 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5661 InsertValue(Fn, CurModule.Values);
Reid Spencer950bf602007-01-26 08:19:09 +00005662 }
5663
Reid Spencere59f4932007-04-16 03:05:01 +00005664
Reid Spencer950bf602007-01-26 08:19:09 +00005665 CurFun.FunctionStart(Fn);
5666
5667 if (CurFun.isDeclare) {
5668 // If we have declaration, always overwrite linkage. This will allow us
5669 // to correctly handle cases, when pointer to function is passed as
5670 // argument to another function.
5671 Fn->setLinkage(CurFun.Linkage);
5672 }
Chris Lattnercf786592007-12-29 20:47:37 +00005673 Fn->setCallingConv(upgradeCallingConv((yyvsp[(1) - (8)].UIntVal)));
5674 Fn->setAlignment((yyvsp[(8) - (8)].UIntVal));
5675 if ((yyvsp[(7) - (8)].StrVal)) {
5676 Fn->setSection((yyvsp[(7) - (8)].StrVal));
5677 free((yyvsp[(7) - (8)].StrVal));
Duncan Sandsdc024672007-11-27 13:23:08 +00005678 }
5679
5680 // Convert the CSRet calling convention into the corresponding parameter
5681 // attribute.
Chris Lattnercf786592007-12-29 20:47:37 +00005682 if ((yyvsp[(1) - (8)].UIntVal) == OldCallingConv::CSRet) {
Duncan Sandsdc024672007-11-27 13:23:08 +00005683 ParamAttrsVector Attrs;
5684 ParamAttrsWithIndex PAWI;
5685 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
5686 Attrs.push_back(PAWI);
5687 Fn->setParamAttrs(ParamAttrsList::get(Attrs));
Reid Spencer950bf602007-01-26 08:19:09 +00005688 }
5689
5690 // Add all of the arguments we parsed to the function...
Chris Lattnercf786592007-12-29 20:47:37 +00005691 if ((yyvsp[(5) - (8)].ArgList)) { // Is null if empty...
Reid Spencer950bf602007-01-26 08:19:09 +00005692 if (isVarArg) { // Nuke the last entry
Chris Lattnercf786592007-12-29 20:47:37 +00005693 assert((yyvsp[(5) - (8)].ArgList)->back().first.PAT->get() == Type::VoidTy &&
5694 (yyvsp[(5) - (8)].ArgList)->back().second == 0 && "Not a varargs marker");
5695 delete (yyvsp[(5) - (8)].ArgList)->back().first.PAT;
5696 (yyvsp[(5) - (8)].ArgList)->pop_back(); // Delete the last entry
Reid Spencer950bf602007-01-26 08:19:09 +00005697 }
5698 Function::arg_iterator ArgIt = Fn->arg_begin();
Reid Spenceref9b9a72007-02-05 20:47:22 +00005699 Function::arg_iterator ArgEnd = Fn->arg_end();
Chris Lattnercf786592007-12-29 20:47:37 +00005700 std::vector<std::pair<PATypeInfo,char*> >::iterator I = (yyvsp[(5) - (8)].ArgList)->begin();
5701 std::vector<std::pair<PATypeInfo,char*> >::iterator E = (yyvsp[(5) - (8)].ArgList)->end();
Reid Spenceref9b9a72007-02-05 20:47:22 +00005702 for ( ; I != E && ArgIt != ArgEnd; ++I, ++ArgIt) {
Reid Spencered96d1e2007-02-08 09:08:52 +00005703 delete I->first.PAT; // Delete the typeholder...
Reid Spencerbb1fd572007-03-21 17:15:50 +00005704 ValueInfo VI; VI.V = ArgIt; VI.S.copy(I->first.S);
5705 setValueName(VI, I->second); // Insert arg into symtab...
Reid Spencer950bf602007-01-26 08:19:09 +00005706 InsertValue(ArgIt);
5707 }
Chris Lattnercf786592007-12-29 20:47:37 +00005708 delete (yyvsp[(5) - (8)].ArgList); // We're now done with the argument list
Reid Spencer950bf602007-01-26 08:19:09 +00005709 }
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005710 lastCallingConv = OldCallingConv::C;
Chris Lattnercf786592007-12-29 20:47:37 +00005711 ;}
5712 break;
5713
5714 case 224:
5715#line 3013 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5716 { CurFun.Linkage = (yyvsp[(1) - (1)].Linkage); ;}
5717 break;
5718
5719 case 225:
5720#line 3013 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5721 {
5722 (yyval.FunctionVal) = CurFun.CurrentFunction;
Reid Spencer950bf602007-01-26 08:19:09 +00005723
5724 // Make sure that we keep track of the linkage type even if there was a
5725 // previous "declare".
Chris Lattnercf786592007-12-29 20:47:37 +00005726 (yyval.FunctionVal)->setLinkage((yyvsp[(1) - (4)].Linkage));
5727 ;}
5728 break;
5729
5730 case 228:
5731#line 3027 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5732 {
5733 (yyval.FunctionVal) = (yyvsp[(1) - (2)].FunctionVal);
5734 ;}
5735 break;
5736
5737 case 229:
5738#line 3032 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5739 { (yyval.Linkage) = GlobalValue::ExternalLinkage; ;}
5740 break;
5741
5742 case 230:
5743#line 3033 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5744 { (yyval.Linkage) = GlobalValue::DLLImportLinkage; ;}
5745 break;
5746
5747 case 231:
5748#line 3034 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5749 { (yyval.Linkage) = GlobalValue::ExternalWeakLinkage; ;}
5750 break;
5751
5752 case 232:
5753#line 3038 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5754 { CurFun.isDeclare = true; ;}
5755 break;
5756
5757 case 233:
5758#line 3039 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5759 { CurFun.Linkage = (yyvsp[(3) - (3)].Linkage); ;}
5760 break;
5761
5762 case 234:
5763#line 3039 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5764 {
5765 (yyval.FunctionVal) = CurFun.CurrentFunction;
Reid Spencer950bf602007-01-26 08:19:09 +00005766 CurFun.FunctionDone();
5767
Chris Lattnercf786592007-12-29 20:47:37 +00005768 ;}
5769 break;
5770
5771 case 235:
5772#line 3051 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5773 { (yyval.BoolVal) = false; ;}
5774 break;
5775
5776 case 236:
5777#line 3052 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5778 { (yyval.BoolVal) = true; ;}
5779 break;
5780
5781 case 237:
5782#line 3057 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5783 { (yyval.ValIDVal) = ValID::create((yyvsp[(1) - (1)].SInt64Val)); ;}
5784 break;
5785
5786 case 238:
5787#line 3058 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5788 { (yyval.ValIDVal) = ValID::create((yyvsp[(1) - (1)].UInt64Val)); ;}
5789 break;
5790
5791 case 239:
5792#line 3059 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5793 { (yyval.ValIDVal) = ValID::create((yyvsp[(1) - (1)].FPVal)); ;}
5794 break;
5795
5796 case 240:
5797#line 3060 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5798 {
5799 (yyval.ValIDVal) = ValID::create(ConstantInt::get(Type::Int1Ty, true));
5800 (yyval.ValIDVal).S.makeUnsigned();
5801 ;}
5802 break;
5803
5804 case 241:
5805#line 3064 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5806 {
5807 (yyval.ValIDVal) = ValID::create(ConstantInt::get(Type::Int1Ty, false));
5808 (yyval.ValIDVal).S.makeUnsigned();
5809 ;}
5810 break;
5811
5812 case 242:
5813#line 3068 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5814 { (yyval.ValIDVal) = ValID::createNull(); ;}
5815 break;
5816
5817 case 243:
5818#line 3069 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5819 { (yyval.ValIDVal) = ValID::createUndef(); ;}
5820 break;
5821
5822 case 244:
5823#line 3070 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5824 { (yyval.ValIDVal) = ValID::createZeroInit(); ;}
5825 break;
5826
5827 case 245:
5828#line 3071 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5829 { // Nonempty unsized packed vector
5830 const Type *ETy = (*(yyvsp[(2) - (3)].ConstVector))[0].C->getType();
5831 int NumElements = (yyvsp[(2) - (3)].ConstVector)->size();
Reid Spencer9d6565a2007-02-15 02:26:10 +00005832 VectorType* pt = VectorType::get(ETy, NumElements);
Chris Lattnercf786592007-12-29 20:47:37 +00005833 (yyval.ValIDVal).S.makeComposite((*(yyvsp[(2) - (3)].ConstVector))[0].S);
5834 PATypeHolder* PTy = new PATypeHolder(HandleUpRefs(pt, (yyval.ValIDVal).S));
Reid Spencer950bf602007-01-26 08:19:09 +00005835
5836 // Verify all elements are correct type!
5837 std::vector<Constant*> Elems;
Chris Lattnercf786592007-12-29 20:47:37 +00005838 for (unsigned i = 0; i < (yyvsp[(2) - (3)].ConstVector)->size(); i++) {
5839 Constant *C = (*(yyvsp[(2) - (3)].ConstVector))[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00005840 const Type *CTy = C->getType();
5841 if (ETy != CTy)
5842 error("Element #" + utostr(i) + " is not of type '" +
5843 ETy->getDescription() +"' as required!\nIt is of type '" +
5844 CTy->getDescription() + "'");
5845 Elems.push_back(C);
Reid Spencere77e35e2006-12-01 20:26:20 +00005846 }
Chris Lattnercf786592007-12-29 20:47:37 +00005847 (yyval.ValIDVal) = ValID::create(ConstantVector::get(pt, Elems));
5848 delete PTy; delete (yyvsp[(2) - (3)].ConstVector);
5849 ;}
5850 break;
5851
5852 case 246:
5853#line 3092 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5854 {
5855 (yyval.ValIDVal) = ValID::create((yyvsp[(1) - (1)].ConstVal).C);
5856 (yyval.ValIDVal).S.copy((yyvsp[(1) - (1)].ConstVal).S);
5857 ;}
5858 break;
5859
5860 case 247:
5861#line 3096 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5862 {
5863 char *End = UnEscapeLexed((yyvsp[(3) - (5)].StrVal), true);
5864 std::string AsmStr = std::string((yyvsp[(3) - (5)].StrVal), End);
5865 End = UnEscapeLexed((yyvsp[(5) - (5)].StrVal), true);
5866 std::string Constraints = std::string((yyvsp[(5) - (5)].StrVal), End);
5867 (yyval.ValIDVal) = ValID::createInlineAsm(AsmStr, Constraints, (yyvsp[(2) - (5)].BoolVal));
5868 free((yyvsp[(3) - (5)].StrVal));
5869 free((yyvsp[(5) - (5)].StrVal));
5870 ;}
5871 break;
5872
5873 case 248:
5874#line 3111 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5875 { (yyval.ValIDVal) = ValID::create((yyvsp[(1) - (1)].SIntVal)); (yyval.ValIDVal).S.makeSignless(); ;}
5876 break;
5877
5878 case 249:
5879#line 3112 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5880 { (yyval.ValIDVal) = ValID::create((yyvsp[(1) - (1)].StrVal)); (yyval.ValIDVal).S.makeSignless(); ;}
5881 break;
5882
5883 case 252:
5884#line 3125 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5885 {
5886 const Type *Ty = (yyvsp[(1) - (2)].TypeVal).PAT->get();
5887 (yyvsp[(2) - (2)].ValIDVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
5888 (yyval.ValueVal).V = getVal(Ty, (yyvsp[(2) - (2)].ValIDVal));
5889 (yyval.ValueVal).S.copy((yyvsp[(1) - (2)].TypeVal).S);
5890 delete (yyvsp[(1) - (2)].TypeVal).PAT;
5891 ;}
5892 break;
5893
5894 case 253:
5895#line 3135 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5896 {
5897 (yyval.FunctionVal) = (yyvsp[(1) - (2)].FunctionVal);
5898 ;}
5899 break;
5900
5901 case 254:
5902#line 3138 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5903 { // Do not allow functions with 0 basic blocks
5904 (yyval.FunctionVal) = (yyvsp[(1) - (2)].FunctionVal);
5905 ;}
5906 break;
5907
5908 case 255:
5909#line 3147 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5910 {
5911 ValueInfo VI; VI.V = (yyvsp[(3) - (3)].TermInstVal).TI; VI.S.copy((yyvsp[(3) - (3)].TermInstVal).S);
5912 setValueName(VI, (yyvsp[(2) - (3)].StrVal));
5913 InsertValue((yyvsp[(3) - (3)].TermInstVal).TI);
5914 (yyvsp[(1) - (3)].BasicBlockVal)->getInstList().push_back((yyvsp[(3) - (3)].TermInstVal).TI);
5915 InsertValue((yyvsp[(1) - (3)].BasicBlockVal));
5916 (yyval.BasicBlockVal) = (yyvsp[(1) - (3)].BasicBlockVal);
5917 ;}
5918 break;
5919
5920 case 256:
5921#line 3158 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5922 {
5923 if ((yyvsp[(2) - (2)].InstVal).I)
5924 (yyvsp[(1) - (2)].BasicBlockVal)->getInstList().push_back((yyvsp[(2) - (2)].InstVal).I);
5925 (yyval.BasicBlockVal) = (yyvsp[(1) - (2)].BasicBlockVal);
5926 ;}
5927 break;
5928
5929 case 257:
5930#line 3163 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5931 {
5932 (yyval.BasicBlockVal) = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++),true);
Reid Spencer950bf602007-01-26 08:19:09 +00005933 // Make sure to move the basic block to the correct location in the
5934 // function, instead of leaving it inserted wherever it was first
5935 // referenced.
5936 Function::BasicBlockListType &BBL =
5937 CurFun.CurrentFunction->getBasicBlockList();
Chris Lattnercf786592007-12-29 20:47:37 +00005938 BBL.splice(BBL.end(), BBL, (yyval.BasicBlockVal));
5939 ;}
5940 break;
5941
5942 case 258:
5943#line 3172 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5944 {
5945 (yyval.BasicBlockVal) = CurBB = getBBVal(ValID::create((yyvsp[(1) - (1)].StrVal)), true);
Reid Spencer950bf602007-01-26 08:19:09 +00005946 // Make sure to move the basic block to the correct location in the
5947 // function, instead of leaving it inserted wherever it was first
5948 // referenced.
5949 Function::BasicBlockListType &BBL =
5950 CurFun.CurrentFunction->getBasicBlockList();
Chris Lattnercf786592007-12-29 20:47:37 +00005951 BBL.splice(BBL.end(), BBL, (yyval.BasicBlockVal));
5952 ;}
5953 break;
5954
5955 case 261:
5956#line 3186 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5957 { // Return with a result...
5958 (yyval.TermInstVal).TI = new ReturnInst((yyvsp[(2) - (2)].ValueVal).V);
5959 (yyval.TermInstVal).S.makeSignless();
5960 ;}
5961 break;
5962
5963 case 262:
5964#line 3190 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5965 { // Return with no result...
5966 (yyval.TermInstVal).TI = new ReturnInst();
5967 (yyval.TermInstVal).S.makeSignless();
5968 ;}
5969 break;
5970
5971 case 263:
5972#line 3194 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5973 { // Unconditional Branch...
5974 BasicBlock* tmpBB = getBBVal((yyvsp[(3) - (3)].ValIDVal));
5975 (yyval.TermInstVal).TI = new BranchInst(tmpBB);
5976 (yyval.TermInstVal).S.makeSignless();
5977 ;}
5978 break;
5979
5980 case 264:
5981#line 3199 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5982 {
5983 (yyvsp[(6) - (9)].ValIDVal).S.makeSignless();
5984 (yyvsp[(9) - (9)].ValIDVal).S.makeSignless();
5985 BasicBlock* tmpBBA = getBBVal((yyvsp[(6) - (9)].ValIDVal));
5986 BasicBlock* tmpBBB = getBBVal((yyvsp[(9) - (9)].ValIDVal));
5987 (yyvsp[(3) - (9)].ValIDVal).S.makeUnsigned();
5988 Value* tmpVal = getVal(Type::Int1Ty, (yyvsp[(3) - (9)].ValIDVal));
5989 (yyval.TermInstVal).TI = new BranchInst(tmpBBA, tmpBBB, tmpVal);
5990 (yyval.TermInstVal).S.makeSignless();
5991 ;}
5992 break;
5993
5994 case 265:
5995#line 3209 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
5996 {
5997 (yyvsp[(3) - (9)].ValIDVal).S.copy((yyvsp[(2) - (9)].PrimType).S);
5998 Value* tmpVal = getVal((yyvsp[(2) - (9)].PrimType).T, (yyvsp[(3) - (9)].ValIDVal));
5999 (yyvsp[(6) - (9)].ValIDVal).S.makeSignless();
6000 BasicBlock* tmpBB = getBBVal((yyvsp[(6) - (9)].ValIDVal));
6001 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, (yyvsp[(8) - (9)].JumpTable)->size());
6002 (yyval.TermInstVal).TI = S;
6003 (yyval.TermInstVal).S.makeSignless();
6004 std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = (yyvsp[(8) - (9)].JumpTable)->begin(),
6005 E = (yyvsp[(8) - (9)].JumpTable)->end();
Reid Spencer950bf602007-01-26 08:19:09 +00006006 for (; I != E; ++I) {
6007 if (ConstantInt *CI = dyn_cast<ConstantInt>(I->first))
6008 S->addCase(CI, I->second);
6009 else
6010 error("Switch case is constant, but not a simple integer");
6011 }
Chris Lattnercf786592007-12-29 20:47:37 +00006012 delete (yyvsp[(8) - (9)].JumpTable);
6013 ;}
6014 break;
6015
6016 case 266:
6017#line 3227 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6018 {
6019 (yyvsp[(3) - (8)].ValIDVal).S.copy((yyvsp[(2) - (8)].PrimType).S);
6020 Value* tmpVal = getVal((yyvsp[(2) - (8)].PrimType).T, (yyvsp[(3) - (8)].ValIDVal));
6021 (yyvsp[(6) - (8)].ValIDVal).S.makeSignless();
6022 BasicBlock* tmpBB = getBBVal((yyvsp[(6) - (8)].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00006023 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0);
Chris Lattnercf786592007-12-29 20:47:37 +00006024 (yyval.TermInstVal).TI = S;
6025 (yyval.TermInstVal).S.makeSignless();
6026 ;}
6027 break;
6028
6029 case 267:
6030#line 3237 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6031 {
Reid Spencer950bf602007-01-26 08:19:09 +00006032 const PointerType *PFTy;
6033 const FunctionType *Ty;
Reid Spencerbb1fd572007-03-21 17:15:50 +00006034 Signedness FTySign;
Reid Spencer950bf602007-01-26 08:19:09 +00006035
Chris Lattnercf786592007-12-29 20:47:37 +00006036 if (!(PFTy = dyn_cast<PointerType>((yyvsp[(3) - (13)].TypeVal).PAT->get())) ||
Reid Spencer950bf602007-01-26 08:19:09 +00006037 !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
6038 // Pull out the types of all of the arguments...
6039 std::vector<const Type*> ParamTypes;
Chris Lattnercf786592007-12-29 20:47:37 +00006040 FTySign.makeComposite((yyvsp[(3) - (13)].TypeVal).S);
6041 if ((yyvsp[(6) - (13)].ValueList)) {
6042 for (std::vector<ValueInfo>::iterator I = (yyvsp[(6) - (13)].ValueList)->begin(), E = (yyvsp[(6) - (13)].ValueList)->end();
Reid Spencerbb1fd572007-03-21 17:15:50 +00006043 I != E; ++I) {
Reid Spencer950bf602007-01-26 08:19:09 +00006044 ParamTypes.push_back((*I).V->getType());
Reid Spencerbb1fd572007-03-21 17:15:50 +00006045 FTySign.add(I->S);
6046 }
Reid Spencer950bf602007-01-26 08:19:09 +00006047 }
6048 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
6049 if (isVarArg) ParamTypes.pop_back();
Chris Lattnercf786592007-12-29 20:47:37 +00006050 Ty = FunctionType::get((yyvsp[(3) - (13)].TypeVal).PAT->get(), ParamTypes, isVarArg);
Christopher Lamb4374f8e2007-12-17 01:17:35 +00006051 PFTy = PointerType::getUnqual(Ty);
Chris Lattnercf786592007-12-29 20:47:37 +00006052 (yyval.TermInstVal).S.copy((yyvsp[(3) - (13)].TypeVal).S);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006053 } else {
Chris Lattnercf786592007-12-29 20:47:37 +00006054 FTySign = (yyvsp[(3) - (13)].TypeVal).S;
Reid Spencera3b12dd2007-04-07 16:14:01 +00006055 // Get the signedness of the result type. $3 is the pointer to the
6056 // function type so we get the 0th element to extract the function type,
6057 // and then the 0th element again to get the result type.
Chris Lattnercf786592007-12-29 20:47:37 +00006058 (yyval.TermInstVal).S.copy((yyvsp[(3) - (13)].TypeVal).S.get(0).get(0));
Reid Spencer950bf602007-01-26 08:19:09 +00006059 }
Reid Spencer7b5d4662007-04-09 06:16:21 +00006060
Chris Lattnercf786592007-12-29 20:47:37 +00006061 (yyvsp[(4) - (13)].ValIDVal).S.makeComposite(FTySign);
6062 Value *V = getVal(PFTy, (yyvsp[(4) - (13)].ValIDVal)); // Get the function we're calling...
6063 BasicBlock *Normal = getBBVal((yyvsp[(10) - (13)].ValIDVal));
6064 BasicBlock *Except = getBBVal((yyvsp[(13) - (13)].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00006065
6066 // Create the call node...
Chris Lattnercf786592007-12-29 20:47:37 +00006067 if (!(yyvsp[(6) - (13)].ValueList)) { // Has no arguments?
David Greene5fd22a82007-09-04 18:46:50 +00006068 std::vector<Value*> Args;
Chris Lattnercf786592007-12-29 20:47:37 +00006069 (yyval.TermInstVal).TI = new InvokeInst(V, Normal, Except, Args.begin(), Args.end());
Reid Spencer950bf602007-01-26 08:19:09 +00006070 } else { // Has arguments?
6071 // Loop through FunctionType's arguments and ensure they are specified
6072 // correctly!
6073 //
6074 FunctionType::param_iterator I = Ty->param_begin();
6075 FunctionType::param_iterator E = Ty->param_end();
Chris Lattnercf786592007-12-29 20:47:37 +00006076 std::vector<ValueInfo>::iterator ArgI = (yyvsp[(6) - (13)].ValueList)->begin(), ArgE = (yyvsp[(6) - (13)].ValueList)->end();
Reid Spencer950bf602007-01-26 08:19:09 +00006077
6078 std::vector<Value*> Args;
6079 for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
6080 if ((*ArgI).V->getType() != *I)
6081 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
6082 (*I)->getDescription() + "'");
6083 Args.push_back((*ArgI).V);
6084 }
6085
6086 if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
6087 error("Invalid number of parameters detected");
6088
Chris Lattnercf786592007-12-29 20:47:37 +00006089 (yyval.TermInstVal).TI = new InvokeInst(V, Normal, Except, Args.begin(), Args.end());
Reid Spencer950bf602007-01-26 08:19:09 +00006090 }
Chris Lattnercf786592007-12-29 20:47:37 +00006091 cast<InvokeInst>((yyval.TermInstVal).TI)->setCallingConv(upgradeCallingConv((yyvsp[(2) - (13)].UIntVal)));
6092 if ((yyvsp[(2) - (13)].UIntVal) == OldCallingConv::CSRet) {
Duncan Sandsdc024672007-11-27 13:23:08 +00006093 ParamAttrsVector Attrs;
6094 ParamAttrsWithIndex PAWI;
6095 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
6096 Attrs.push_back(PAWI);
Chris Lattnercf786592007-12-29 20:47:37 +00006097 cast<InvokeInst>((yyval.TermInstVal).TI)->setParamAttrs(ParamAttrsList::get(Attrs));
Duncan Sandsdc024672007-11-27 13:23:08 +00006098 }
Chris Lattnercf786592007-12-29 20:47:37 +00006099 delete (yyvsp[(3) - (13)].TypeVal).PAT;
6100 delete (yyvsp[(6) - (13)].ValueList);
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006101 lastCallingConv = OldCallingConv::C;
Chris Lattnercf786592007-12-29 20:47:37 +00006102 ;}
6103 break;
6104
6105 case 268:
6106#line 3309 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6107 {
6108 (yyval.TermInstVal).TI = new UnwindInst();
6109 (yyval.TermInstVal).S.makeSignless();
6110 ;}
6111 break;
6112
6113 case 269:
6114#line 3313 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6115 {
6116 (yyval.TermInstVal).TI = new UnreachableInst();
6117 (yyval.TermInstVal).S.makeSignless();
6118 ;}
6119 break;
6120
6121 case 270:
6122#line 3320 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6123 {
6124 (yyval.JumpTable) = (yyvsp[(1) - (6)].JumpTable);
6125 (yyvsp[(3) - (6)].ValIDVal).S.copy((yyvsp[(2) - (6)].PrimType).S);
6126 Constant *V = cast<Constant>(getExistingValue((yyvsp[(2) - (6)].PrimType).T, (yyvsp[(3) - (6)].ValIDVal)));
Reid Spencer950bf602007-01-26 08:19:09 +00006127
6128 if (V == 0)
6129 error("May only switch on a constant pool value");
6130
Chris Lattnercf786592007-12-29 20:47:37 +00006131 (yyvsp[(6) - (6)].ValIDVal).S.makeSignless();
6132 BasicBlock* tmpBB = getBBVal((yyvsp[(6) - (6)].ValIDVal));
6133 (yyval.JumpTable)->push_back(std::make_pair(V, tmpBB));
6134 ;}
6135 break;
6136
6137 case 271:
6138#line 3332 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6139 {
6140 (yyval.JumpTable) = new std::vector<std::pair<Constant*, BasicBlock*> >();
6141 (yyvsp[(2) - (5)].ValIDVal).S.copy((yyvsp[(1) - (5)].PrimType).S);
6142 Constant *V = cast<Constant>(getExistingValue((yyvsp[(1) - (5)].PrimType).T, (yyvsp[(2) - (5)].ValIDVal)));
Reid Spencer950bf602007-01-26 08:19:09 +00006143
6144 if (V == 0)
6145 error("May only switch on a constant pool value");
6146
Chris Lattnercf786592007-12-29 20:47:37 +00006147 (yyvsp[(5) - (5)].ValIDVal).S.makeSignless();
6148 BasicBlock* tmpBB = getBBVal((yyvsp[(5) - (5)].ValIDVal));
6149 (yyval.JumpTable)->push_back(std::make_pair(V, tmpBB));
6150 ;}
6151 break;
6152
6153 case 272:
6154#line 3347 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6155 {
Reid Spencer950bf602007-01-26 08:19:09 +00006156 bool omit = false;
Chris Lattnercf786592007-12-29 20:47:37 +00006157 if ((yyvsp[(1) - (2)].StrVal))
6158 if (BitCastInst *BCI = dyn_cast<BitCastInst>((yyvsp[(2) - (2)].InstVal).I))
Reid Spencer950bf602007-01-26 08:19:09 +00006159 if (BCI->getSrcTy() == BCI->getDestTy() &&
Chris Lattnercf786592007-12-29 20:47:37 +00006160 BCI->getOperand(0)->getName() == (yyvsp[(1) - (2)].StrVal))
Reid Spencer950bf602007-01-26 08:19:09 +00006161 // This is a useless bit cast causing a name redefinition. It is
6162 // a bit cast from a type to the same type of an operand with the
6163 // same name as the name we would give this instruction. Since this
6164 // instruction results in no code generation, it is safe to omit
6165 // the instruction. This situation can occur because of collapsed
6166 // type planes. For example:
6167 // %X = add int %Y, %Z
6168 // %X = cast int %Y to uint
6169 // After upgrade, this looks like:
6170 // %X = add i32 %Y, %Z
6171 // %X = bitcast i32 to i32
6172 // The bitcast is clearly useless so we omit it.
6173 omit = true;
6174 if (omit) {
Chris Lattnercf786592007-12-29 20:47:37 +00006175 (yyval.InstVal).I = 0;
6176 (yyval.InstVal).S.makeSignless();
Reid Spencer950bf602007-01-26 08:19:09 +00006177 } else {
Chris Lattnercf786592007-12-29 20:47:37 +00006178 ValueInfo VI; VI.V = (yyvsp[(2) - (2)].InstVal).I; VI.S.copy((yyvsp[(2) - (2)].InstVal).S);
6179 setValueName(VI, (yyvsp[(1) - (2)].StrVal));
6180 InsertValue((yyvsp[(2) - (2)].InstVal).I);
6181 (yyval.InstVal) = (yyvsp[(2) - (2)].InstVal);
Reid Spencer950bf602007-01-26 08:19:09 +00006182 }
Chris Lattnercf786592007-12-29 20:47:37 +00006183 ;}
6184 break;
6185
6186 case 273:
6187#line 3377 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6188 { // Used for PHI nodes
6189 (yyval.PHIList).P = new std::list<std::pair<Value*, BasicBlock*> >();
6190 (yyval.PHIList).S.copy((yyvsp[(1) - (6)].TypeVal).S);
6191 (yyvsp[(3) - (6)].ValIDVal).S.copy((yyvsp[(1) - (6)].TypeVal).S);
6192 Value* tmpVal = getVal((yyvsp[(1) - (6)].TypeVal).PAT->get(), (yyvsp[(3) - (6)].ValIDVal));
6193 (yyvsp[(5) - (6)].ValIDVal).S.makeSignless();
6194 BasicBlock* tmpBB = getBBVal((yyvsp[(5) - (6)].ValIDVal));
6195 (yyval.PHIList).P->push_back(std::make_pair(tmpVal, tmpBB));
6196 delete (yyvsp[(1) - (6)].TypeVal).PAT;
6197 ;}
6198 break;
6199
6200 case 274:
6201#line 3387 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6202 {
6203 (yyval.PHIList) = (yyvsp[(1) - (7)].PHIList);
6204 (yyvsp[(4) - (7)].ValIDVal).S.copy((yyvsp[(1) - (7)].PHIList).S);
6205 Value* tmpVal = getVal((yyvsp[(1) - (7)].PHIList).P->front().first->getType(), (yyvsp[(4) - (7)].ValIDVal));
6206 (yyvsp[(6) - (7)].ValIDVal).S.makeSignless();
6207 BasicBlock* tmpBB = getBBVal((yyvsp[(6) - (7)].ValIDVal));
6208 (yyvsp[(1) - (7)].PHIList).P->push_back(std::make_pair(tmpVal, tmpBB));
6209 ;}
6210 break;
6211
6212 case 275:
6213#line 3397 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6214 { // Used for call statements, and memory insts...
6215 (yyval.ValueList) = new std::vector<ValueInfo>();
6216 (yyval.ValueList)->push_back((yyvsp[(1) - (1)].ValueVal));
6217 ;}
6218 break;
6219
6220 case 276:
6221#line 3401 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6222 {
6223 (yyval.ValueList) = (yyvsp[(1) - (3)].ValueList);
6224 (yyvsp[(1) - (3)].ValueList)->push_back((yyvsp[(3) - (3)].ValueVal));
6225 ;}
6226 break;
6227
6228 case 278:
6229#line 3409 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6230 { (yyval.ValueList) = 0; ;}
6231 break;
6232
6233 case 279:
6234#line 3413 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6235 {
6236 (yyval.BoolVal) = true;
6237 ;}
6238 break;
6239
6240 case 280:
6241#line 3416 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6242 {
6243 (yyval.BoolVal) = false;
6244 ;}
6245 break;
6246
6247 case 281:
6248#line 3422 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6249 {
6250 (yyvsp[(3) - (5)].ValIDVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6251 (yyvsp[(5) - (5)].ValIDVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6252 const Type* Ty = (yyvsp[(2) - (5)].TypeVal).PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006253 if (!Ty->isInteger() && !Ty->isFloatingPoint() && !isa<VectorType>(Ty))
Reid Spencer950bf602007-01-26 08:19:09 +00006254 error("Arithmetic operator requires integer, FP, or packed operands");
Reid Spencer9d6565a2007-02-15 02:26:10 +00006255 if (isa<VectorType>(Ty) &&
Chris Lattnercf786592007-12-29 20:47:37 +00006256 ((yyvsp[(1) - (5)].BinaryOpVal) == URemOp || (yyvsp[(1) - (5)].BinaryOpVal) == SRemOp || (yyvsp[(1) - (5)].BinaryOpVal) == FRemOp || (yyvsp[(1) - (5)].BinaryOpVal) == RemOp))
Chris Lattner4227bdb2007-02-19 07:34:02 +00006257 error("Remainder not supported on vector types");
Reid Spencer950bf602007-01-26 08:19:09 +00006258 // Upgrade the opcode from obsolete versions before we do anything with it.
Chris Lattnercf786592007-12-29 20:47:37 +00006259 Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[(1) - (5)].BinaryOpVal), Ty, (yyvsp[(2) - (5)].TypeVal).S);
6260 Value* val1 = getVal(Ty, (yyvsp[(3) - (5)].ValIDVal));
6261 Value* val2 = getVal(Ty, (yyvsp[(5) - (5)].ValIDVal));
6262 (yyval.InstVal).I = BinaryOperator::create(Opcode, val1, val2);
6263 if ((yyval.InstVal).I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006264 error("binary operator returned null");
Chris Lattnercf786592007-12-29 20:47:37 +00006265 (yyval.InstVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6266 delete (yyvsp[(2) - (5)].TypeVal).PAT;
6267 ;}
6268 break;
6269
6270 case 282:
6271#line 3441 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6272 {
6273 (yyvsp[(3) - (5)].ValIDVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6274 (yyvsp[(5) - (5)].ValIDVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6275 const Type *Ty = (yyvsp[(2) - (5)].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006276 if (!Ty->isInteger()) {
Reid Spencer9d6565a2007-02-15 02:26:10 +00006277 if (!isa<VectorType>(Ty) ||
6278 !cast<VectorType>(Ty)->getElementType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00006279 error("Logical operator requires integral operands");
6280 }
Chris Lattnercf786592007-12-29 20:47:37 +00006281 Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[(1) - (5)].BinaryOpVal), Ty, (yyvsp[(2) - (5)].TypeVal).S);
6282 Value* tmpVal1 = getVal(Ty, (yyvsp[(3) - (5)].ValIDVal));
6283 Value* tmpVal2 = getVal(Ty, (yyvsp[(5) - (5)].ValIDVal));
6284 (yyval.InstVal).I = BinaryOperator::create(Opcode, tmpVal1, tmpVal2);
6285 if ((yyval.InstVal).I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006286 error("binary operator returned null");
Chris Lattnercf786592007-12-29 20:47:37 +00006287 (yyval.InstVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6288 delete (yyvsp[(2) - (5)].TypeVal).PAT;
6289 ;}
6290 break;
6291
6292 case 283:
6293#line 3459 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6294 {
6295 (yyvsp[(3) - (5)].ValIDVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6296 (yyvsp[(5) - (5)].ValIDVal).S.copy((yyvsp[(2) - (5)].TypeVal).S);
6297 const Type* Ty = (yyvsp[(2) - (5)].TypeVal).PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006298 if(isa<VectorType>(Ty))
6299 error("VectorTypes currently not supported in setcc instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00006300 unsigned short pred;
Chris Lattnercf786592007-12-29 20:47:37 +00006301 Instruction::OtherOps Opcode = getCompareOp((yyvsp[(1) - (5)].BinaryOpVal), pred, Ty, (yyvsp[(2) - (5)].TypeVal).S);
6302 Value* tmpVal1 = getVal(Ty, (yyvsp[(3) - (5)].ValIDVal));
6303 Value* tmpVal2 = getVal(Ty, (yyvsp[(5) - (5)].ValIDVal));
6304 (yyval.InstVal).I = CmpInst::create(Opcode, pred, tmpVal1, tmpVal2);
6305 if ((yyval.InstVal).I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006306 error("binary operator returned null");
Chris Lattnercf786592007-12-29 20:47:37 +00006307 (yyval.InstVal).S.makeUnsigned();
6308 delete (yyvsp[(2) - (5)].TypeVal).PAT;
6309 ;}
6310 break;
6311
6312 case 284:
6313#line 3475 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6314 {
6315 (yyvsp[(4) - (6)].ValIDVal).S.copy((yyvsp[(3) - (6)].TypeVal).S);
6316 (yyvsp[(6) - (6)].ValIDVal).S.copy((yyvsp[(3) - (6)].TypeVal).S);
6317 const Type *Ty = (yyvsp[(3) - (6)].TypeVal).PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006318 if (isa<VectorType>(Ty))
6319 error("VectorTypes currently not supported in icmp instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00006320 else if (!Ty->isInteger() && !isa<PointerType>(Ty))
6321 error("icmp requires integer or pointer typed operands");
Chris Lattnercf786592007-12-29 20:47:37 +00006322 Value* tmpVal1 = getVal(Ty, (yyvsp[(4) - (6)].ValIDVal));
6323 Value* tmpVal2 = getVal(Ty, (yyvsp[(6) - (6)].ValIDVal));
6324 (yyval.InstVal).I = new ICmpInst((yyvsp[(2) - (6)].IPred), tmpVal1, tmpVal2);
6325 (yyval.InstVal).S.makeUnsigned();
6326 delete (yyvsp[(3) - (6)].TypeVal).PAT;
6327 ;}
6328 break;
6329
6330 case 285:
6331#line 3489 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6332 {
6333 (yyvsp[(4) - (6)].ValIDVal).S.copy((yyvsp[(3) - (6)].TypeVal).S);
6334 (yyvsp[(6) - (6)].ValIDVal).S.copy((yyvsp[(3) - (6)].TypeVal).S);
6335 const Type *Ty = (yyvsp[(3) - (6)].TypeVal).PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006336 if (isa<VectorType>(Ty))
6337 error("VectorTypes currently not supported in fcmp instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00006338 else if (!Ty->isFloatingPoint())
6339 error("fcmp instruction requires floating point operands");
Chris Lattnercf786592007-12-29 20:47:37 +00006340 Value* tmpVal1 = getVal(Ty, (yyvsp[(4) - (6)].ValIDVal));
6341 Value* tmpVal2 = getVal(Ty, (yyvsp[(6) - (6)].ValIDVal));
6342 (yyval.InstVal).I = new FCmpInst((yyvsp[(2) - (6)].FPred), tmpVal1, tmpVal2);
6343 (yyval.InstVal).S.makeUnsigned();
6344 delete (yyvsp[(3) - (6)].TypeVal).PAT;
6345 ;}
6346 break;
6347
6348 case 286:
6349#line 3503 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6350 {
Reid Spencer950bf602007-01-26 08:19:09 +00006351 warning("Use of obsolete 'not' instruction: Replacing with 'xor");
Chris Lattnercf786592007-12-29 20:47:37 +00006352 const Type *Ty = (yyvsp[(2) - (2)].ValueVal).V->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00006353 Value *Ones = ConstantInt::getAllOnesValue(Ty);
6354 if (Ones == 0)
6355 error("Expected integral type for not instruction");
Chris Lattnercf786592007-12-29 20:47:37 +00006356 (yyval.InstVal).I = BinaryOperator::create(Instruction::Xor, (yyvsp[(2) - (2)].ValueVal).V, Ones);
6357 if ((yyval.InstVal).I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006358 error("Could not create a xor instruction");
Chris Lattnercf786592007-12-29 20:47:37 +00006359 (yyval.InstVal).S.copy((yyvsp[(2) - (2)].ValueVal).S);
6360 ;}
6361 break;
6362
6363 case 287:
6364#line 3514 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6365 {
6366 if (!(yyvsp[(4) - (4)].ValueVal).V->getType()->isInteger() ||
6367 cast<IntegerType>((yyvsp[(4) - (4)].ValueVal).V->getType())->getBitWidth() != 8)
Reid Spencer950bf602007-01-26 08:19:09 +00006368 error("Shift amount must be int8");
Chris Lattnercf786592007-12-29 20:47:37 +00006369 const Type* Ty = (yyvsp[(2) - (4)].ValueVal).V->getType();
Reid Spencer832254e2007-02-02 02:16:23 +00006370 if (!Ty->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00006371 error("Shift constant expression requires integer operand");
Reid Spencer832254e2007-02-02 02:16:23 +00006372 Value* ShiftAmt = 0;
6373 if (cast<IntegerType>(Ty)->getBitWidth() > Type::Int8Ty->getBitWidth())
Chris Lattnercf786592007-12-29 20:47:37 +00006374 if (Constant *C = dyn_cast<Constant>((yyvsp[(4) - (4)].ValueVal).V))
Reid Spencer832254e2007-02-02 02:16:23 +00006375 ShiftAmt = ConstantExpr::getZExt(C, Ty);
6376 else
Chris Lattnercf786592007-12-29 20:47:37 +00006377 ShiftAmt = new ZExtInst((yyvsp[(4) - (4)].ValueVal).V, Ty, makeNameUnique("shift"), CurBB);
Reid Spencer832254e2007-02-02 02:16:23 +00006378 else
Chris Lattnercf786592007-12-29 20:47:37 +00006379 ShiftAmt = (yyvsp[(4) - (4)].ValueVal).V;
6380 (yyval.InstVal).I = BinaryOperator::create(getBinaryOp((yyvsp[(1) - (4)].BinaryOpVal), Ty, (yyvsp[(2) - (4)].ValueVal).S), (yyvsp[(2) - (4)].ValueVal).V, ShiftAmt);
6381 (yyval.InstVal).S.copy((yyvsp[(2) - (4)].ValueVal).S);
6382 ;}
6383 break;
6384
6385 case 288:
6386#line 3532 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6387 {
6388 const Type *DstTy = (yyvsp[(4) - (4)].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006389 if (!DstTy->isFirstClassType())
6390 error("cast instruction to a non-primitive type: '" +
6391 DstTy->getDescription() + "'");
Chris Lattnercf786592007-12-29 20:47:37 +00006392 (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));
6393 (yyval.InstVal).S.copy((yyvsp[(4) - (4)].TypeVal).S);
6394 delete (yyvsp[(4) - (4)].TypeVal).PAT;
6395 ;}
6396 break;
6397
6398 case 289:
6399#line 3541 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6400 {
6401 if (!(yyvsp[(2) - (6)].ValueVal).V->getType()->isInteger() ||
6402 cast<IntegerType>((yyvsp[(2) - (6)].ValueVal).V->getType())->getBitWidth() != 1)
Reid Spencer950bf602007-01-26 08:19:09 +00006403 error("select condition must be bool");
Chris Lattnercf786592007-12-29 20:47:37 +00006404 if ((yyvsp[(4) - (6)].ValueVal).V->getType() != (yyvsp[(6) - (6)].ValueVal).V->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00006405 error("select value types should match");
Chris Lattnercf786592007-12-29 20:47:37 +00006406 (yyval.InstVal).I = new SelectInst((yyvsp[(2) - (6)].ValueVal).V, (yyvsp[(4) - (6)].ValueVal).V, (yyvsp[(6) - (6)].ValueVal).V);
6407 (yyval.InstVal).S.copy((yyvsp[(4) - (6)].ValueVal).S);
6408 ;}
6409 break;
6410
6411 case 290:
6412#line 3550 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6413 {
6414 const Type *Ty = (yyvsp[(4) - (4)].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006415 NewVarArgs = true;
Chris Lattnercf786592007-12-29 20:47:37 +00006416 (yyval.InstVal).I = new VAArgInst((yyvsp[(2) - (4)].ValueVal).V, Ty);
6417 (yyval.InstVal).S.copy((yyvsp[(4) - (4)].TypeVal).S);
6418 delete (yyvsp[(4) - (4)].TypeVal).PAT;
6419 ;}
6420 break;
6421
6422 case 291:
6423#line 3557 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6424 {
6425 const Type* ArgTy = (yyvsp[(2) - (4)].ValueVal).V->getType();
6426 const Type* DstTy = (yyvsp[(4) - (4)].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006427 ObsoleteVarArgs = true;
6428 Function* NF = cast<Function>(CurModule.CurrentModule->
6429 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
6430
6431 //b = vaarg a, t ->
6432 //foo = alloca 1 of t
6433 //bar = vacopy a
6434 //store bar -> foo
6435 //b = vaarg foo, t
6436 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vaarg.fix");
6437 CurBB->getInstList().push_back(foo);
Chris Lattnercf786592007-12-29 20:47:37 +00006438 CallInst* bar = new CallInst(NF, (yyvsp[(2) - (4)].ValueVal).V);
Reid Spencer950bf602007-01-26 08:19:09 +00006439 CurBB->getInstList().push_back(bar);
6440 CurBB->getInstList().push_back(new StoreInst(bar, foo));
Chris Lattnercf786592007-12-29 20:47:37 +00006441 (yyval.InstVal).I = new VAArgInst(foo, DstTy);
6442 (yyval.InstVal).S.copy((yyvsp[(4) - (4)].TypeVal).S);
6443 delete (yyvsp[(4) - (4)].TypeVal).PAT;
6444 ;}
6445 break;
6446
6447 case 292:
6448#line 3578 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6449 {
6450 const Type* ArgTy = (yyvsp[(2) - (4)].ValueVal).V->getType();
6451 const Type* DstTy = (yyvsp[(4) - (4)].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006452 ObsoleteVarArgs = true;
6453 Function* NF = cast<Function>(CurModule.CurrentModule->
6454 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
6455
6456 //b = vanext a, t ->
6457 //foo = alloca 1 of t
6458 //bar = vacopy a
6459 //store bar -> foo
6460 //tmp = vaarg foo, t
6461 //b = load foo
6462 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vanext.fix");
6463 CurBB->getInstList().push_back(foo);
Chris Lattnercf786592007-12-29 20:47:37 +00006464 CallInst* bar = new CallInst(NF, (yyvsp[(2) - (4)].ValueVal).V);
Reid Spencer950bf602007-01-26 08:19:09 +00006465 CurBB->getInstList().push_back(bar);
6466 CurBB->getInstList().push_back(new StoreInst(bar, foo));
6467 Instruction* tmp = new VAArgInst(foo, DstTy);
6468 CurBB->getInstList().push_back(tmp);
Chris Lattnercf786592007-12-29 20:47:37 +00006469 (yyval.InstVal).I = new LoadInst(foo);
6470 (yyval.InstVal).S.copy((yyvsp[(4) - (4)].TypeVal).S);
6471 delete (yyvsp[(4) - (4)].TypeVal).PAT;
6472 ;}
6473 break;
6474
6475 case 293:
6476#line 3602 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6477 {
6478 if (!ExtractElementInst::isValidOperands((yyvsp[(2) - (4)].ValueVal).V, (yyvsp[(4) - (4)].ValueVal).V))
Reid Spencer950bf602007-01-26 08:19:09 +00006479 error("Invalid extractelement operands");
Chris Lattnercf786592007-12-29 20:47:37 +00006480 (yyval.InstVal).I = new ExtractElementInst((yyvsp[(2) - (4)].ValueVal).V, (yyvsp[(4) - (4)].ValueVal).V);
6481 (yyval.InstVal).S.copy((yyvsp[(2) - (4)].ValueVal).S.get(0));
6482 ;}
6483 break;
6484
6485 case 294:
6486#line 3608 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6487 {
6488 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 +00006489 error("Invalid insertelement operands");
Chris Lattnercf786592007-12-29 20:47:37 +00006490 (yyval.InstVal).I = new InsertElementInst((yyvsp[(2) - (6)].ValueVal).V, (yyvsp[(4) - (6)].ValueVal).V, (yyvsp[(6) - (6)].ValueVal).V);
6491 (yyval.InstVal).S.copy((yyvsp[(2) - (6)].ValueVal).S);
6492 ;}
6493 break;
6494
6495 case 295:
6496#line 3614 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6497 {
6498 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 +00006499 error("Invalid shufflevector operands");
Chris Lattnercf786592007-12-29 20:47:37 +00006500 (yyval.InstVal).I = new ShuffleVectorInst((yyvsp[(2) - (6)].ValueVal).V, (yyvsp[(4) - (6)].ValueVal).V, (yyvsp[(6) - (6)].ValueVal).V);
6501 (yyval.InstVal).S.copy((yyvsp[(2) - (6)].ValueVal).S);
6502 ;}
6503 break;
6504
6505 case 296:
6506#line 3620 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6507 {
6508 const Type *Ty = (yyvsp[(2) - (2)].PHIList).P->front().first->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00006509 if (!Ty->isFirstClassType())
6510 error("PHI node operands must be of first class type");
6511 PHINode *PHI = new PHINode(Ty);
Chris Lattnercf786592007-12-29 20:47:37 +00006512 PHI->reserveOperandSpace((yyvsp[(2) - (2)].PHIList).P->size());
6513 while ((yyvsp[(2) - (2)].PHIList).P->begin() != (yyvsp[(2) - (2)].PHIList).P->end()) {
6514 if ((yyvsp[(2) - (2)].PHIList).P->front().first->getType() != Ty)
Reid Spencer950bf602007-01-26 08:19:09 +00006515 error("All elements of a PHI node must be of the same type");
Chris Lattnercf786592007-12-29 20:47:37 +00006516 PHI->addIncoming((yyvsp[(2) - (2)].PHIList).P->front().first, (yyvsp[(2) - (2)].PHIList).P->front().second);
6517 (yyvsp[(2) - (2)].PHIList).P->pop_front();
Reid Spencer950bf602007-01-26 08:19:09 +00006518 }
Chris Lattnercf786592007-12-29 20:47:37 +00006519 (yyval.InstVal).I = PHI;
6520 (yyval.InstVal).S.copy((yyvsp[(2) - (2)].PHIList).S);
6521 delete (yyvsp[(2) - (2)].PHIList).P; // Free the list...
6522 ;}
6523 break;
6524
6525 case 297:
6526#line 3636 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6527 {
Reid Spencer950bf602007-01-26 08:19:09 +00006528 // Handle the short call syntax
6529 const PointerType *PFTy;
6530 const FunctionType *FTy;
Reid Spencerbb1fd572007-03-21 17:15:50 +00006531 Signedness FTySign;
Chris Lattnercf786592007-12-29 20:47:37 +00006532 if (!(PFTy = dyn_cast<PointerType>((yyvsp[(3) - (7)].TypeVal).PAT->get())) ||
Reid Spencer950bf602007-01-26 08:19:09 +00006533 !(FTy = dyn_cast<FunctionType>(PFTy->getElementType()))) {
6534 // Pull out the types of all of the arguments...
6535 std::vector<const Type*> ParamTypes;
Chris Lattnercf786592007-12-29 20:47:37 +00006536 FTySign.makeComposite((yyvsp[(3) - (7)].TypeVal).S);
6537 if ((yyvsp[(6) - (7)].ValueList)) {
6538 for (std::vector<ValueInfo>::iterator I = (yyvsp[(6) - (7)].ValueList)->begin(), E = (yyvsp[(6) - (7)].ValueList)->end();
Reid Spencerbb1fd572007-03-21 17:15:50 +00006539 I != E; ++I) {
Reid Spencer950bf602007-01-26 08:19:09 +00006540 ParamTypes.push_back((*I).V->getType());
Reid Spencerbb1fd572007-03-21 17:15:50 +00006541 FTySign.add(I->S);
6542 }
Reid Spencer950bf602007-01-26 08:19:09 +00006543 }
6544
6545 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
6546 if (isVarArg) ParamTypes.pop_back();
6547
Chris Lattnercf786592007-12-29 20:47:37 +00006548 const Type *RetTy = (yyvsp[(3) - (7)].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006549 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
6550 error("Functions cannot return aggregate types");
6551
Duncan Sandsdc024672007-11-27 13:23:08 +00006552 FTy = FunctionType::get(RetTy, ParamTypes, isVarArg);
Christopher Lamb4374f8e2007-12-17 01:17:35 +00006553 PFTy = PointerType::getUnqual(FTy);
Chris Lattnercf786592007-12-29 20:47:37 +00006554 (yyval.InstVal).S.copy((yyvsp[(3) - (7)].TypeVal).S);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006555 } else {
Chris Lattnercf786592007-12-29 20:47:37 +00006556 FTySign = (yyvsp[(3) - (7)].TypeVal).S;
Reid Spencera3b12dd2007-04-07 16:14:01 +00006557 // Get the signedness of the result type. $3 is the pointer to the
6558 // function type so we get the 0th element to extract the function type,
6559 // and then the 0th element again to get the result type.
Chris Lattnercf786592007-12-29 20:47:37 +00006560 (yyval.InstVal).S.copy((yyvsp[(3) - (7)].TypeVal).S.get(0).get(0));
Reid Spencer950bf602007-01-26 08:19:09 +00006561 }
Chris Lattnercf786592007-12-29 20:47:37 +00006562 (yyvsp[(4) - (7)].ValIDVal).S.makeComposite(FTySign);
Reid Spencer950bf602007-01-26 08:19:09 +00006563
6564 // First upgrade any intrinsic calls.
6565 std::vector<Value*> Args;
Chris Lattnercf786592007-12-29 20:47:37 +00006566 if ((yyvsp[(6) - (7)].ValueList))
6567 for (unsigned i = 0, e = (yyvsp[(6) - (7)].ValueList)->size(); i < e; ++i)
6568 Args.push_back((*(yyvsp[(6) - (7)].ValueList))[i].V);
6569 Instruction *Inst = upgradeIntrinsicCall(FTy->getReturnType(), (yyvsp[(4) - (7)].ValIDVal), Args);
Reid Spencer950bf602007-01-26 08:19:09 +00006570
6571 // If we got an upgraded intrinsic
6572 if (Inst) {
Chris Lattnercf786592007-12-29 20:47:37 +00006573 (yyval.InstVal).I = Inst;
Reid Spencer950bf602007-01-26 08:19:09 +00006574 } else {
6575 // Get the function we're calling
Chris Lattnercf786592007-12-29 20:47:37 +00006576 Value *V = getVal(PFTy, (yyvsp[(4) - (7)].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00006577
6578 // Check the argument values match
Chris Lattnercf786592007-12-29 20:47:37 +00006579 if (!(yyvsp[(6) - (7)].ValueList)) { // Has no arguments?
Reid Spencer950bf602007-01-26 08:19:09 +00006580 // Make sure no arguments is a good thing!
6581 if (FTy->getNumParams() != 0)
6582 error("No arguments passed to a function that expects arguments");
6583 } else { // Has arguments?
6584 // Loop through FunctionType's arguments and ensure they are specified
6585 // correctly!
6586 //
6587 FunctionType::param_iterator I = FTy->param_begin();
6588 FunctionType::param_iterator E = FTy->param_end();
Chris Lattnercf786592007-12-29 20:47:37 +00006589 std::vector<ValueInfo>::iterator ArgI = (yyvsp[(6) - (7)].ValueList)->begin(), ArgE = (yyvsp[(6) - (7)].ValueList)->end();
Reid Spencer950bf602007-01-26 08:19:09 +00006590
6591 for (; ArgI != ArgE && I != E; ++ArgI, ++I)
6592 if ((*ArgI).V->getType() != *I)
6593 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
6594 (*I)->getDescription() + "'");
6595
6596 if (I != E || (ArgI != ArgE && !FTy->isVarArg()))
6597 error("Invalid number of parameters detected");
6598 }
6599
6600 // Create the call instruction
David Greene718fda32007-08-01 03:59:32 +00006601 CallInst *CI = new CallInst(V, Args.begin(), Args.end());
Chris Lattnercf786592007-12-29 20:47:37 +00006602 CI->setTailCall((yyvsp[(1) - (7)].BoolVal));
6603 CI->setCallingConv(upgradeCallingConv((yyvsp[(2) - (7)].UIntVal)));
Duncan Sandsdc024672007-11-27 13:23:08 +00006604
Chris Lattnercf786592007-12-29 20:47:37 +00006605 (yyval.InstVal).I = CI;
Reid Spencer950bf602007-01-26 08:19:09 +00006606 }
Duncan Sandsdc024672007-11-27 13:23:08 +00006607 // Deal with CSRetCC
Chris Lattnercf786592007-12-29 20:47:37 +00006608 if ((yyvsp[(2) - (7)].UIntVal) == OldCallingConv::CSRet) {
Duncan Sandsdc024672007-11-27 13:23:08 +00006609 ParamAttrsVector Attrs;
6610 ParamAttrsWithIndex PAWI;
6611 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
6612 Attrs.push_back(PAWI);
Chris Lattnercf786592007-12-29 20:47:37 +00006613 cast<CallInst>((yyval.InstVal).I)->setParamAttrs(ParamAttrsList::get(Attrs));
Duncan Sandsdc024672007-11-27 13:23:08 +00006614 }
Chris Lattnercf786592007-12-29 20:47:37 +00006615 delete (yyvsp[(3) - (7)].TypeVal).PAT;
6616 delete (yyvsp[(6) - (7)].ValueList);
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006617 lastCallingConv = OldCallingConv::C;
Chris Lattnercf786592007-12-29 20:47:37 +00006618 ;}
6619 break;
6620
6621 case 298:
6622#line 3728 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6623 {
6624 (yyval.InstVal) = (yyvsp[(1) - (1)].InstVal);
6625 ;}
6626 break;
6627
6628 case 299:
6629#line 3736 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6630 { (yyval.ValueList) = (yyvsp[(2) - (2)].ValueList); ;}
6631 break;
6632
6633 case 300:
6634#line 3737 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6635 { (yyval.ValueList) = new std::vector<ValueInfo>(); ;}
6636 break;
6637
6638 case 301:
6639#line 3741 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6640 { (yyval.BoolVal) = true; ;}
6641 break;
6642
6643 case 302:
6644#line 3742 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6645 { (yyval.BoolVal) = false; ;}
6646 break;
6647
6648 case 303:
6649#line 3746 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6650 {
6651 const Type *Ty = (yyvsp[(2) - (3)].TypeVal).PAT->get();
6652 (yyval.InstVal).S.makeComposite((yyvsp[(2) - (3)].TypeVal).S);
6653 (yyval.InstVal).I = new MallocInst(Ty, 0, (yyvsp[(3) - (3)].UIntVal));
6654 delete (yyvsp[(2) - (3)].TypeVal).PAT;
6655 ;}
6656 break;
6657
6658 case 304:
6659#line 3752 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6660 {
6661 const Type *Ty = (yyvsp[(2) - (6)].TypeVal).PAT->get();
6662 (yyvsp[(5) - (6)].ValIDVal).S.makeUnsigned();
6663 (yyval.InstVal).S.makeComposite((yyvsp[(2) - (6)].TypeVal).S);
6664 (yyval.InstVal).I = new MallocInst(Ty, getVal((yyvsp[(4) - (6)].PrimType).T, (yyvsp[(5) - (6)].ValIDVal)), (yyvsp[(6) - (6)].UIntVal));
6665 delete (yyvsp[(2) - (6)].TypeVal).PAT;
6666 ;}
6667 break;
6668
6669 case 305:
6670#line 3759 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6671 {
6672 const Type *Ty = (yyvsp[(2) - (3)].TypeVal).PAT->get();
6673 (yyval.InstVal).S.makeComposite((yyvsp[(2) - (3)].TypeVal).S);
6674 (yyval.InstVal).I = new AllocaInst(Ty, 0, (yyvsp[(3) - (3)].UIntVal));
6675 delete (yyvsp[(2) - (3)].TypeVal).PAT;
6676 ;}
6677 break;
6678
6679 case 306:
6680#line 3765 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6681 {
6682 const Type *Ty = (yyvsp[(2) - (6)].TypeVal).PAT->get();
6683 (yyvsp[(5) - (6)].ValIDVal).S.makeUnsigned();
6684 (yyval.InstVal).S.makeComposite((yyvsp[(4) - (6)].PrimType).S);
6685 (yyval.InstVal).I = new AllocaInst(Ty, getVal((yyvsp[(4) - (6)].PrimType).T, (yyvsp[(5) - (6)].ValIDVal)), (yyvsp[(6) - (6)].UIntVal));
6686 delete (yyvsp[(2) - (6)].TypeVal).PAT;
6687 ;}
6688 break;
6689
6690 case 307:
6691#line 3772 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6692 {
6693 const Type *PTy = (yyvsp[(2) - (2)].ValueVal).V->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00006694 if (!isa<PointerType>(PTy))
6695 error("Trying to free nonpointer type '" + PTy->getDescription() + "'");
Chris Lattnercf786592007-12-29 20:47:37 +00006696 (yyval.InstVal).I = new FreeInst((yyvsp[(2) - (2)].ValueVal).V);
6697 (yyval.InstVal).S.makeSignless();
6698 ;}
6699 break;
6700
6701 case 308:
6702#line 3779 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6703 {
6704 const Type* Ty = (yyvsp[(3) - (4)].TypeVal).PAT->get();
6705 (yyvsp[(4) - (4)].ValIDVal).S.copy((yyvsp[(3) - (4)].TypeVal).S);
Reid Spencer950bf602007-01-26 08:19:09 +00006706 if (!isa<PointerType>(Ty))
6707 error("Can't load from nonpointer type: " + Ty->getDescription());
6708 if (!cast<PointerType>(Ty)->getElementType()->isFirstClassType())
6709 error("Can't load from pointer of non-first-class type: " +
6710 Ty->getDescription());
Chris Lattnercf786592007-12-29 20:47:37 +00006711 Value* tmpVal = getVal(Ty, (yyvsp[(4) - (4)].ValIDVal));
6712 (yyval.InstVal).I = new LoadInst(tmpVal, "", (yyvsp[(1) - (4)].BoolVal));
6713 (yyval.InstVal).S.copy((yyvsp[(3) - (4)].TypeVal).S.get(0));
6714 delete (yyvsp[(3) - (4)].TypeVal).PAT;
6715 ;}
6716 break;
6717
6718 case 309:
6719#line 3792 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6720 {
6721 (yyvsp[(6) - (6)].ValIDVal).S.copy((yyvsp[(5) - (6)].TypeVal).S);
6722 const PointerType *PTy = dyn_cast<PointerType>((yyvsp[(5) - (6)].TypeVal).PAT->get());
Reid Spencered96d1e2007-02-08 09:08:52 +00006723 if (!PTy)
6724 error("Can't store to a nonpointer type: " +
Chris Lattnercf786592007-12-29 20:47:37 +00006725 (yyvsp[(5) - (6)].TypeVal).PAT->get()->getDescription());
Reid Spencered96d1e2007-02-08 09:08:52 +00006726 const Type *ElTy = PTy->getElementType();
Chris Lattnercf786592007-12-29 20:47:37 +00006727 Value *StoreVal = (yyvsp[(3) - (6)].ValueVal).V;
6728 Value* tmpVal = getVal(PTy, (yyvsp[(6) - (6)].ValIDVal));
6729 if (ElTy != (yyvsp[(3) - (6)].ValueVal).V->getType()) {
Christopher Lamb4374f8e2007-12-17 01:17:35 +00006730 PTy = PointerType::getUnqual(StoreVal->getType());
Duncan Sandsdc024672007-11-27 13:23:08 +00006731 if (Constant *C = dyn_cast<Constant>(tmpVal))
6732 tmpVal = ConstantExpr::getBitCast(C, PTy);
6733 else
6734 tmpVal = new BitCastInst(tmpVal, PTy, "upgrd.cast", CurBB);
Reid Spencered96d1e2007-02-08 09:08:52 +00006735 }
Chris Lattnercf786592007-12-29 20:47:37 +00006736 (yyval.InstVal).I = new StoreInst(StoreVal, tmpVal, (yyvsp[(1) - (6)].BoolVal));
6737 (yyval.InstVal).S.makeSignless();
6738 delete (yyvsp[(5) - (6)].TypeVal).PAT;
6739 ;}
6740 break;
6741
6742 case 310:
6743#line 3812 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
6744 {
6745 (yyvsp[(3) - (4)].ValIDVal).S.copy((yyvsp[(2) - (4)].TypeVal).S);
6746 const Type* Ty = (yyvsp[(2) - (4)].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006747 if (!isa<PointerType>(Ty))
6748 error("getelementptr insn requires pointer operand");
6749
6750 std::vector<Value*> VIndices;
Chris Lattnercf786592007-12-29 20:47:37 +00006751 upgradeGEPInstIndices(Ty, (yyvsp[(4) - (4)].ValueList), VIndices);
Reid Spencer950bf602007-01-26 08:19:09 +00006752
Chris Lattnercf786592007-12-29 20:47:37 +00006753 Value* tmpVal = getVal(Ty, (yyvsp[(3) - (4)].ValIDVal));
6754 (yyval.InstVal).I = new GetElementPtrInst(tmpVal, VIndices.begin(), VIndices.end());
6755 ValueInfo VI; VI.V = tmpVal; VI.S.copy((yyvsp[(2) - (4)].TypeVal).S);
6756 (yyval.InstVal).S.copy(getElementSign(VI, VIndices));
6757 delete (yyvsp[(2) - (4)].TypeVal).PAT;
6758 delete (yyvsp[(4) - (4)].ValueList);
6759 ;}
6760 break;
David Greene5fd22a82007-09-04 18:46:50 +00006761
Chris Lattnercf786592007-12-29 20:47:37 +00006762
6763/* Line 1267 of yacc.c. */
6764#line 6765 "UpgradeParser.tab.c"
6765 default: break;
Dale Johannesencdd509a2007-09-07 21:07:57 +00006766 }
Chris Lattnercf786592007-12-29 20:47:37 +00006767 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
6768
6769 YYPOPSTACK (yylen);
6770 yylen = 0;
6771 YY_STACK_PRINT (yyss, yyssp);
Reid Spencere7c3c602006-11-30 06:36:44 +00006772
6773 *++yyvsp = yyval;
6774
6775
Chris Lattnercf786592007-12-29 20:47:37 +00006776 /* Now `shift' the result of the reduction. Determine what state
6777 that goes to, based on the state we popped back to and the rule
6778 number reduced by. */
Reid Spencere7c3c602006-11-30 06:36:44 +00006779
6780 yyn = yyr1[yyn];
6781
Chris Lattnercf786592007-12-29 20:47:37 +00006782 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
6783 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
Reid Spencere7c3c602006-11-30 06:36:44 +00006784 yystate = yytable[yystate];
6785 else
Chris Lattnercf786592007-12-29 20:47:37 +00006786 yystate = yydefgoto[yyn - YYNTOKENS];
Reid Spencere7c3c602006-11-30 06:36:44 +00006787
6788 goto yynewstate;
6789
6790
Chris Lattnercf786592007-12-29 20:47:37 +00006791/*------------------------------------.
6792| yyerrlab -- here on detecting error |
6793`------------------------------------*/
6794yyerrlab:
6795 /* If not already recovering from an error, report this error. */
6796 if (!yyerrstatus)
Reid Spencere7c3c602006-11-30 06:36:44 +00006797 {
6798 ++yynerrs;
Chris Lattnercf786592007-12-29 20:47:37 +00006799#if ! YYERROR_VERBOSE
6800 yyerror (YY_("syntax error"));
6801#else
6802 {
6803 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
6804 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
6805 {
6806 YYSIZE_T yyalloc = 2 * yysize;
6807 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
6808 yyalloc = YYSTACK_ALLOC_MAXIMUM;
6809 if (yymsg != yymsgbuf)
6810 YYSTACK_FREE (yymsg);
6811 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
6812 if (yymsg)
6813 yymsg_alloc = yyalloc;
6814 else
6815 {
6816 yymsg = yymsgbuf;
6817 yymsg_alloc = sizeof yymsgbuf;
6818 }
6819 }
Dale Johannesencdd509a2007-09-07 21:07:57 +00006820
Chris Lattnercf786592007-12-29 20:47:37 +00006821 if (0 < yysize && yysize <= yymsg_alloc)
6822 {
6823 (void) yysyntax_error (yymsg, yystate, yychar);
6824 yyerror (yymsg);
6825 }
6826 else
6827 {
6828 yyerror (YY_("syntax error"));
6829 if (yysize != 0)
6830 goto yyexhaustedlab;
6831 }
6832 }
6833#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00006834 }
Reid Spencer950bf602007-01-26 08:19:09 +00006835
Chris Lattnercf786592007-12-29 20:47:37 +00006836
Reid Spencer950bf602007-01-26 08:19:09 +00006837
6838 if (yyerrstatus == 3)
6839 {
Chris Lattnercf786592007-12-29 20:47:37 +00006840 /* If just tried and failed to reuse look-ahead token after an
6841 error, discard it. */
Reid Spencer950bf602007-01-26 08:19:09 +00006842
Chris Lattnercf786592007-12-29 20:47:37 +00006843 if (yychar <= YYEOF)
6844 {
6845 /* Return failure if at end of input. */
6846 if (yychar == YYEOF)
6847 YYABORT;
6848 }
6849 else
6850 {
6851 yydestruct ("Error: discarding",
6852 yytoken, &yylval);
6853 yychar = YYEMPTY;
6854 }
6855 }
6856
6857 /* Else will try to reuse look-ahead token after shifting the error
6858 token. */
6859 goto yyerrlab1;
6860
6861
6862/*---------------------------------------------------.
6863| yyerrorlab -- error raised explicitly by YYERROR. |
6864`---------------------------------------------------*/
6865yyerrorlab:
6866
6867 /* Pacify compilers like GCC when the user code never invokes
6868 YYERROR and the label yyerrorlab therefore never appears in user
6869 code. */
6870 if (/*CONSTCOND*/ 0)
6871 goto yyerrorlab;
6872
6873 /* Do not reclaim the symbols of the rule which action triggered
6874 this YYERROR. */
6875 YYPOPSTACK (yylen);
6876 yylen = 0;
6877 YY_STACK_PRINT (yyss, yyssp);
6878 yystate = *yyssp;
6879 goto yyerrlab1;
6880
6881
6882/*-------------------------------------------------------------.
6883| yyerrlab1 -- common code for both syntax error and YYERROR. |
6884`-------------------------------------------------------------*/
6885yyerrlab1:
6886 yyerrstatus = 3; /* Each real token shifted decrements this. */
6887
6888 for (;;)
6889 {
6890 yyn = yypact[yystate];
6891 if (yyn != YYPACT_NINF)
6892 {
6893 yyn += YYTERROR;
6894 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
6895 {
6896 yyn = yytable[yyn];
6897 if (0 < yyn)
6898 break;
6899 }
6900 }
6901
6902 /* Pop the current state because it cannot handle the error token. */
6903 if (yyssp == yyss)
Reid Spencere7c3c602006-11-30 06:36:44 +00006904 YYABORT;
6905
Dale Johannesencdd509a2007-09-07 21:07:57 +00006906
Chris Lattnercf786592007-12-29 20:47:37 +00006907 yydestruct ("Error: popping",
6908 yystos[yystate], yyvsp);
6909 YYPOPSTACK (1);
6910 yystate = *yyssp;
6911 YY_STACK_PRINT (yyss, yyssp);
Reid Spencere7c3c602006-11-30 06:36:44 +00006912 }
6913
6914 if (yyn == YYFINAL)
6915 YYACCEPT;
6916
6917 *++yyvsp = yylval;
Chris Lattnercf786592007-12-29 20:47:37 +00006918
6919
6920 /* Shift the error token. */
6921 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006922
Reid Spencere7c3c602006-11-30 06:36:44 +00006923 yystate = yyn;
6924 goto yynewstate;
6925
Christopher Lamb4374f8e2007-12-17 01:17:35 +00006926
Chris Lattnercf786592007-12-29 20:47:37 +00006927/*-------------------------------------.
6928| yyacceptlab -- YYACCEPT comes here. |
6929`-------------------------------------*/
6930yyacceptlab:
6931 yyresult = 0;
6932 goto yyreturn;
6933
6934/*-----------------------------------.
6935| yyabortlab -- YYABORT comes here. |
6936`-----------------------------------*/
6937yyabortlab:
6938 yyresult = 1;
6939 goto yyreturn;
6940
6941#ifndef yyoverflow
6942/*-------------------------------------------------.
6943| yyexhaustedlab -- memory exhaustion comes here. |
6944`-------------------------------------------------*/
6945yyexhaustedlab:
6946 yyerror (YY_("memory exhausted"));
6947 yyresult = 2;
6948 /* Fall through. */
Duncan Sandsdc024672007-11-27 13:23:08 +00006949#endif
Chris Lattnercf786592007-12-29 20:47:37 +00006950
6951yyreturn:
6952 if (yychar != YYEOF && yychar != YYEMPTY)
6953 yydestruct ("Cleanup: discarding lookahead",
6954 yytoken, &yylval);
6955 /* Do not reclaim the symbols of the rule which action triggered
6956 this YYABORT or YYACCEPT. */
6957 YYPOPSTACK (yylen);
6958 YY_STACK_PRINT (yyss, yyssp);
6959 while (yyssp != yyss)
6960 {
6961 yydestruct ("Cleanup: popping",
6962 yystos[*yyssp], yyvsp);
6963 YYPOPSTACK (1);
Christopher Lamb4374f8e2007-12-17 01:17:35 +00006964 }
Chris Lattnercf786592007-12-29 20:47:37 +00006965#ifndef yyoverflow
6966 if (yyss != yyssa)
6967 YYSTACK_FREE (yyss);
6968#endif
6969#if YYERROR_VERBOSE
6970 if (yymsg != yymsgbuf)
6971 YYSTACK_FREE (yymsg);
6972#endif
6973 /* Make sure YYID is used. */
6974 return YYID (yyresult);
Reid Spencere7c3c602006-11-30 06:36:44 +00006975}
Chris Lattnercf786592007-12-29 20:47:37 +00006976
6977
6978#line 3830 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencere7c3c602006-11-30 06:36:44 +00006979
6980
6981int yyerror(const char *ErrorMsg) {
6982 std::string where
6983 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
Reid Spencered96d1e2007-02-08 09:08:52 +00006984 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
Reid Spencer950bf602007-01-26 08:19:09 +00006985 std::string errMsg = where + "error: " + std::string(ErrorMsg);
6986 if (yychar != YYEMPTY && yychar != 0)
6987 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
6988 "'.";
Reid Spencer71d2ec92006-12-31 06:02:26 +00006989 std::cerr << "llvm-upgrade: " << errMsg << '\n';
Reid Spencer950bf602007-01-26 08:19:09 +00006990 std::cout << "llvm-upgrade: parse failed.\n";
Reid Spencere7c3c602006-11-30 06:36:44 +00006991 exit(1);
6992}
Reid Spencer319a7302007-01-05 17:20:02 +00006993
Reid Spencer30d0c582007-01-15 00:26:18 +00006994void warning(const std::string& ErrorMsg) {
Reid Spencer319a7302007-01-05 17:20:02 +00006995 std::string where
6996 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
Reid Spencered96d1e2007-02-08 09:08:52 +00006997 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
Reid Spencer950bf602007-01-26 08:19:09 +00006998 std::string errMsg = where + "warning: " + std::string(ErrorMsg);
6999 if (yychar != YYEMPTY && yychar != 0)
7000 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
7001 "'.";
Reid Spencer319a7302007-01-05 17:20:02 +00007002 std::cerr << "llvm-upgrade: " << errMsg << '\n';
7003}
7004
Reid Spencer950bf602007-01-26 08:19:09 +00007005void error(const std::string& ErrorMsg, int LineNo) {
7006 if (LineNo == -1) LineNo = Upgradelineno;
7007 Upgradelineno = LineNo;
7008 yyerror(ErrorMsg.c_str());
7009}
7010
Chris Lattnercf786592007-12-29 20:47:37 +00007011