blob: 577d94daef24337e10ab756afe2acb16079deedb [file] [log] [blame]
Reid Spencer3fae7ba2007-03-14 23:13:06 +00001/* A Bison parser, made by GNU Bison 2.1. */
Reid Spencere7c3c602006-11-30 06:36:44 +00002
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003/* Skeleton parser for Yacc-like parsing with Bison,
4 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
Reid Spencere7c3c602006-11-30 06:36:44 +00005
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
Reid Spencere7c3c602006-11-30 06:36:44 +000010
Reid Spencer3fae7ba2007-03-14 23:13:06 +000011 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA. */
20
21/* As a special exception, when this file is copied by Bison into a
22 Bison output file, you may use that output file without restriction.
23 This special exception was added by the Free Software Foundation
24 in version 1.24 of Bison. */
25
26/* Written by Richard Stallman by simplifying the original so called
27 ``semantic'' parser. */
28
29/* All symbols defined below should begin with yy or YY, to avoid
30 infringing on user name space. This should be done even for local
31 variables, as they might otherwise be expanded by user macros.
32 There are some unavoidable exceptions within include files to
33 define necessary library symbols; they are noted "INFRINGES ON
34 USER NAME SPACE" below. */
35
36/* Identify Bison output. */
37#define YYBISON 1
38
39/* Bison version. */
40#define YYBISON_VERSION "2.1"
41
42/* Skeleton name. */
43#define YYSKELETON_NAME "yacc.c"
44
45/* Pure parsers. */
46#define YYPURE 0
47
48/* Using locations. */
49#define YYLSP_NEEDED 0
50
51/* Substitute the variable and function names. */
Reid Spencere7c3c602006-11-30 06:36:44 +000052#define yyparse Upgradeparse
Reid Spencer3fae7ba2007-03-14 23:13:06 +000053#define yylex Upgradelex
Reid Spencere7c3c602006-11-30 06:36:44 +000054#define yyerror Upgradeerror
Reid Spencer3fae7ba2007-03-14 23:13:06 +000055#define yylval Upgradelval
56#define yychar Upgradechar
Reid Spencere7c3c602006-11-30 06:36:44 +000057#define yydebug Upgradedebug
58#define yynerrs Upgradenerrs
59
Reid Spencer3fae7ba2007-03-14 23:13:06 +000060
61/* Tokens. */
62#ifndef YYTOKENTYPE
63# define YYTOKENTYPE
64 /* Put the tokens into the symbol table, so that GDB and other debuggers
65 know about them. */
66 enum yytokentype {
67 ESINT64VAL = 258,
68 EUINT64VAL = 259,
69 SINTVAL = 260,
70 UINTVAL = 261,
71 FPVAL = 262,
72 VOID = 263,
73 BOOL = 264,
74 SBYTE = 265,
75 UBYTE = 266,
76 SHORT = 267,
77 USHORT = 268,
78 INT = 269,
79 UINT = 270,
80 LONG = 271,
81 ULONG = 272,
82 FLOAT = 273,
83 DOUBLE = 274,
84 TYPE = 275,
85 LABEL = 276,
86 VAR_ID = 277,
87 LABELSTR = 278,
88 STRINGCONSTANT = 279,
89 IMPLEMENTATION = 280,
90 ZEROINITIALIZER = 281,
91 TRUETOK = 282,
92 FALSETOK = 283,
93 BEGINTOK = 284,
94 ENDTOK = 285,
95 DECLARE = 286,
96 GLOBAL = 287,
97 CONSTANT = 288,
98 SECTION = 289,
99 VOLATILE = 290,
100 TO = 291,
101 DOTDOTDOT = 292,
102 NULL_TOK = 293,
103 UNDEF = 294,
104 CONST = 295,
105 INTERNAL = 296,
106 LINKONCE = 297,
107 WEAK = 298,
108 APPENDING = 299,
109 DLLIMPORT = 300,
110 DLLEXPORT = 301,
111 EXTERN_WEAK = 302,
112 OPAQUE = 303,
113 NOT = 304,
114 EXTERNAL = 305,
115 TARGET = 306,
116 TRIPLE = 307,
117 ENDIAN = 308,
118 POINTERSIZE = 309,
119 LITTLE = 310,
120 BIG = 311,
121 ALIGN = 312,
122 DEPLIBS = 313,
123 CALL = 314,
124 TAIL = 315,
125 ASM_TOK = 316,
126 MODULE = 317,
127 SIDEEFFECT = 318,
128 CC_TOK = 319,
129 CCC_TOK = 320,
130 CSRETCC_TOK = 321,
131 FASTCC_TOK = 322,
132 COLDCC_TOK = 323,
133 X86_STDCALLCC_TOK = 324,
134 X86_FASTCALLCC_TOK = 325,
135 DATALAYOUT = 326,
136 RET = 327,
137 BR = 328,
138 SWITCH = 329,
139 INVOKE = 330,
140 UNREACHABLE = 331,
141 UNWIND = 332,
142 EXCEPT = 333,
143 ADD = 334,
144 SUB = 335,
145 MUL = 336,
146 DIV = 337,
147 UDIV = 338,
148 SDIV = 339,
149 FDIV = 340,
150 REM = 341,
151 UREM = 342,
152 SREM = 343,
153 FREM = 344,
154 AND = 345,
155 OR = 346,
156 XOR = 347,
157 SHL = 348,
158 SHR = 349,
159 ASHR = 350,
160 LSHR = 351,
161 SETLE = 352,
162 SETGE = 353,
163 SETLT = 354,
164 SETGT = 355,
165 SETEQ = 356,
166 SETNE = 357,
167 ICMP = 358,
168 FCMP = 359,
169 MALLOC = 360,
170 ALLOCA = 361,
171 FREE = 362,
172 LOAD = 363,
173 STORE = 364,
174 GETELEMENTPTR = 365,
175 PHI_TOK = 366,
176 SELECT = 367,
177 VAARG = 368,
178 EXTRACTELEMENT = 369,
179 INSERTELEMENT = 370,
180 SHUFFLEVECTOR = 371,
181 VAARG_old = 372,
182 VANEXT_old = 373,
183 EQ = 374,
184 NE = 375,
185 SLT = 376,
186 SGT = 377,
187 SLE = 378,
188 SGE = 379,
189 ULT = 380,
190 UGT = 381,
191 ULE = 382,
192 UGE = 383,
193 OEQ = 384,
194 ONE = 385,
195 OLT = 386,
196 OGT = 387,
197 OLE = 388,
198 OGE = 389,
199 ORD = 390,
200 UNO = 391,
201 UEQ = 392,
202 UNE = 393,
203 CAST = 394,
204 TRUNC = 395,
205 ZEXT = 396,
206 SEXT = 397,
207 FPTRUNC = 398,
208 FPEXT = 399,
209 FPTOUI = 400,
210 FPTOSI = 401,
211 UITOFP = 402,
212 SITOFP = 403,
213 PTRTOINT = 404,
214 INTTOPTR = 405,
215 BITCAST = 406
216 };
217#endif
218/* Tokens. */
219#define ESINT64VAL 258
220#define EUINT64VAL 259
221#define SINTVAL 260
222#define UINTVAL 261
223#define FPVAL 262
224#define VOID 263
225#define BOOL 264
226#define SBYTE 265
227#define UBYTE 266
228#define SHORT 267
229#define USHORT 268
230#define INT 269
231#define UINT 270
232#define LONG 271
233#define ULONG 272
234#define FLOAT 273
235#define DOUBLE 274
236#define TYPE 275
237#define LABEL 276
238#define VAR_ID 277
239#define LABELSTR 278
240#define STRINGCONSTANT 279
241#define IMPLEMENTATION 280
242#define ZEROINITIALIZER 281
243#define TRUETOK 282
244#define FALSETOK 283
245#define BEGINTOK 284
246#define ENDTOK 285
247#define DECLARE 286
248#define GLOBAL 287
249#define CONSTANT 288
250#define SECTION 289
251#define VOLATILE 290
252#define TO 291
253#define DOTDOTDOT 292
254#define NULL_TOK 293
255#define UNDEF 294
256#define CONST 295
257#define INTERNAL 296
258#define LINKONCE 297
259#define WEAK 298
260#define APPENDING 299
261#define DLLIMPORT 300
262#define DLLEXPORT 301
263#define EXTERN_WEAK 302
264#define OPAQUE 303
265#define NOT 304
266#define EXTERNAL 305
267#define TARGET 306
268#define TRIPLE 307
269#define ENDIAN 308
270#define POINTERSIZE 309
271#define LITTLE 310
272#define BIG 311
273#define ALIGN 312
274#define DEPLIBS 313
275#define CALL 314
276#define TAIL 315
277#define ASM_TOK 316
278#define MODULE 317
279#define SIDEEFFECT 318
280#define CC_TOK 319
281#define CCC_TOK 320
282#define CSRETCC_TOK 321
283#define FASTCC_TOK 322
284#define COLDCC_TOK 323
285#define X86_STDCALLCC_TOK 324
286#define X86_FASTCALLCC_TOK 325
287#define DATALAYOUT 326
288#define RET 327
289#define BR 328
290#define SWITCH 329
291#define INVOKE 330
292#define UNREACHABLE 331
293#define UNWIND 332
294#define EXCEPT 333
295#define ADD 334
296#define SUB 335
297#define MUL 336
298#define DIV 337
299#define UDIV 338
300#define SDIV 339
301#define FDIV 340
302#define REM 341
303#define UREM 342
304#define SREM 343
305#define FREM 344
306#define AND 345
307#define OR 346
308#define XOR 347
309#define SHL 348
310#define SHR 349
311#define ASHR 350
312#define LSHR 351
313#define SETLE 352
314#define SETGE 353
315#define SETLT 354
316#define SETGT 355
317#define SETEQ 356
318#define SETNE 357
319#define ICMP 358
320#define FCMP 359
321#define MALLOC 360
322#define ALLOCA 361
323#define FREE 362
324#define LOAD 363
325#define STORE 364
326#define GETELEMENTPTR 365
327#define PHI_TOK 366
328#define SELECT 367
329#define VAARG 368
330#define EXTRACTELEMENT 369
331#define INSERTELEMENT 370
332#define SHUFFLEVECTOR 371
333#define VAARG_old 372
334#define VANEXT_old 373
335#define EQ 374
336#define NE 375
337#define SLT 376
338#define SGT 377
339#define SLE 378
340#define SGE 379
341#define ULT 380
342#define UGT 381
343#define ULE 382
344#define UGE 383
345#define OEQ 384
346#define ONE 385
347#define OLT 386
348#define OGT 387
349#define OLE 388
350#define OGE 389
351#define ORD 390
352#define UNO 391
353#define UEQ 392
354#define UNE 393
355#define CAST 394
356#define TRUNC 395
357#define ZEXT 396
358#define SEXT 397
359#define FPTRUNC 398
360#define FPEXT 399
361#define FPTOUI 400
362#define FPTOSI 401
363#define UITOFP 402
364#define SITOFP 403
365#define PTRTOINT 404
366#define INTTOPTR 405
367#define BITCAST 406
368
369
370
371
372/* Copy the first part of user declarations. */
Reid Spencer7eea8ff2007-05-18 05:48:07 +0000373#line 14 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer319a7302007-01-05 17:20:02 +0000374
375#include "UpgradeInternals.h"
Reid Spencer950bf602007-01-26 08:19:09 +0000376#include "llvm/CallingConv.h"
377#include "llvm/InlineAsm.h"
378#include "llvm/Instructions.h"
379#include "llvm/Module.h"
Reid Spencer7b5d4662007-04-09 06:16:21 +0000380#include "llvm/ParameterAttributes.h"
Reid Spenceref9b9a72007-02-05 20:47:22 +0000381#include "llvm/ValueSymbolTable.h"
Reid Spencer950bf602007-01-26 08:19:09 +0000382#include "llvm/Support/GetElementPtrTypeIterator.h"
383#include "llvm/ADT/STLExtras.h"
384#include "llvm/Support/MathExtras.h"
Reid Spencere7c3c602006-11-30 06:36:44 +0000385#include <algorithm>
Reid Spencere7c3c602006-11-30 06:36:44 +0000386#include <iostream>
Chris Lattner8adde282007-02-11 21:40:10 +0000387#include <map>
Reid Spencer950bf602007-01-26 08:19:09 +0000388#include <list>
389#include <utility>
390
391// DEBUG_UPREFS - Define this symbol if you want to enable debugging output
392// relating to upreferences in the input stream.
393//
394//#define DEBUG_UPREFS 1
395#ifdef DEBUG_UPREFS
396#define UR_OUT(X) std::cerr << X
397#else
398#define UR_OUT(X)
399#endif
Reid Spencere7c3c602006-11-30 06:36:44 +0000400
Reid Spencere77e35e2006-12-01 20:26:20 +0000401#define YYERROR_VERBOSE 1
Reid Spencer96839be2006-11-30 16:50:26 +0000402#define YYINCLUDED_STDLIB_H
Reid Spencere77e35e2006-12-01 20:26:20 +0000403#define YYDEBUG 1
Reid Spencere7c3c602006-11-30 06:36:44 +0000404
Reid Spencer950bf602007-01-26 08:19:09 +0000405int yylex();
Reid Spencere7c3c602006-11-30 06:36:44 +0000406int yyparse();
407
Reid Spencer950bf602007-01-26 08:19:09 +0000408int yyerror(const char*);
409static void warning(const std::string& WarningMsg);
410
411namespace llvm {
412
Reid Spencer950bf602007-01-26 08:19:09 +0000413std::istream* LexInput;
Reid Spencere7c3c602006-11-30 06:36:44 +0000414static std::string CurFilename;
Reid Spencer96839be2006-11-30 16:50:26 +0000415
Reid Spencer71d2ec92006-12-31 06:02:26 +0000416// This bool controls whether attributes are ever added to function declarations
417// definitions and calls.
418static bool AddAttributes = false;
419
Reid Spencer950bf602007-01-26 08:19:09 +0000420static Module *ParserResult;
421static bool ObsoleteVarArgs;
422static bool NewVarArgs;
423static BasicBlock *CurBB;
424static GlobalVariable *CurGV;
Reid Spencer7eea8ff2007-05-18 05:48:07 +0000425static unsigned lastCallingConv;
Reid Spencera50d5962006-12-02 04:11:07 +0000426
Reid Spencer950bf602007-01-26 08:19:09 +0000427// This contains info used when building the body of a function. It is
428// destroyed when the function is completed.
429//
430typedef std::vector<Value *> ValueList; // Numbered defs
431
Reid Spencerbb1fd572007-03-21 17:15:50 +0000432typedef std::pair<std::string,TypeInfo> RenameMapKey;
Reid Spencer950bf602007-01-26 08:19:09 +0000433typedef std::map<RenameMapKey,std::string> RenameMapType;
434
435static void
436ResolveDefinitions(std::map<const Type *,ValueList> &LateResolvers,
437 std::map<const Type *,ValueList> *FutureLateResolvers = 0);
438
439static struct PerModuleInfo {
440 Module *CurrentModule;
441 std::map<const Type *, ValueList> Values; // Module level numbered definitions
442 std::map<const Type *,ValueList> LateResolveValues;
Reid Spencerbb1fd572007-03-21 17:15:50 +0000443 std::vector<PATypeHolder> Types;
444 std::vector<Signedness> TypeSigns;
445 std::map<std::string,Signedness> NamedTypeSigns;
446 std::map<std::string,Signedness> NamedValueSigns;
Reid Spencer950bf602007-01-26 08:19:09 +0000447 std::map<ValID, PATypeHolder> LateResolveTypes;
448 static Module::Endianness Endian;
449 static Module::PointerSize PointerSize;
450 RenameMapType RenameMap;
451
452 /// PlaceHolderInfo - When temporary placeholder objects are created, remember
453 /// how they were referenced and on which line of the input they came from so
454 /// that we can resolve them later and print error messages as appropriate.
455 std::map<Value*, std::pair<ValID, int> > PlaceHolderInfo;
456
457 // GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
458 // references to global values. Global values may be referenced before they
459 // are defined, and if so, the temporary object that they represent is held
460 // here. This is used for forward references of GlobalValues.
461 //
462 typedef std::map<std::pair<const PointerType *, ValID>, GlobalValue*>
463 GlobalRefsType;
464 GlobalRefsType GlobalRefs;
465
466 void ModuleDone() {
467 // If we could not resolve some functions at function compilation time
468 // (calls to functions before they are defined), resolve them now... Types
469 // are resolved when the constant pool has been completely parsed.
470 //
471 ResolveDefinitions(LateResolveValues);
472
473 // Check to make sure that all global value forward references have been
474 // resolved!
475 //
476 if (!GlobalRefs.empty()) {
477 std::string UndefinedReferences = "Unresolved global references exist:\n";
478
479 for (GlobalRefsType::iterator I = GlobalRefs.begin(), E =GlobalRefs.end();
480 I != E; ++I) {
481 UndefinedReferences += " " + I->first.first->getDescription() + " " +
482 I->first.second.getName() + "\n";
483 }
484 error(UndefinedReferences);
485 return;
486 }
487
488 if (CurrentModule->getDataLayout().empty()) {
489 std::string dataLayout;
490 if (Endian != Module::AnyEndianness)
491 dataLayout.append(Endian == Module::BigEndian ? "E" : "e");
492 if (PointerSize != Module::AnyPointerSize) {
493 if (!dataLayout.empty())
494 dataLayout += "-";
495 dataLayout.append(PointerSize == Module::Pointer64 ?
496 "p:64:64" : "p:32:32");
497 }
498 CurrentModule->setDataLayout(dataLayout);
499 }
500
501 Values.clear(); // Clear out function local definitions
502 Types.clear();
Reid Spencerbb1fd572007-03-21 17:15:50 +0000503 TypeSigns.clear();
504 NamedTypeSigns.clear();
505 NamedValueSigns.clear();
Reid Spencer950bf602007-01-26 08:19:09 +0000506 CurrentModule = 0;
507 }
508
509 // GetForwardRefForGlobal - Check to see if there is a forward reference
510 // for this global. If so, remove it from the GlobalRefs map and return it.
511 // If not, just return null.
512 GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ValID ID) {
513 // Check to see if there is a forward reference to this global variable...
514 // if there is, eliminate it and patch the reference to use the new def'n.
515 GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PTy, ID));
516 GlobalValue *Ret = 0;
517 if (I != GlobalRefs.end()) {
518 Ret = I->second;
519 GlobalRefs.erase(I);
520 }
521 return Ret;
522 }
523 void setEndianness(Module::Endianness E) { Endian = E; }
524 void setPointerSize(Module::PointerSize sz) { PointerSize = sz; }
525} CurModule;
526
527Module::Endianness PerModuleInfo::Endian = Module::AnyEndianness;
528Module::PointerSize PerModuleInfo::PointerSize = Module::AnyPointerSize;
529
530static struct PerFunctionInfo {
531 Function *CurrentFunction; // Pointer to current function being created
532
533 std::map<const Type*, ValueList> Values; // Keep track of #'d definitions
534 std::map<const Type*, ValueList> LateResolveValues;
535 bool isDeclare; // Is this function a forward declararation?
536 GlobalValue::LinkageTypes Linkage;// Linkage for forward declaration.
537
538 /// BBForwardRefs - When we see forward references to basic blocks, keep
539 /// track of them here.
540 std::map<BasicBlock*, std::pair<ValID, int> > BBForwardRefs;
541 std::vector<BasicBlock*> NumberedBlocks;
542 RenameMapType RenameMap;
Reid Spencer950bf602007-01-26 08:19:09 +0000543 unsigned NextBBNum;
544
545 inline PerFunctionInfo() {
546 CurrentFunction = 0;
547 isDeclare = false;
548 Linkage = GlobalValue::ExternalLinkage;
549 }
550
551 inline void FunctionStart(Function *M) {
552 CurrentFunction = M;
553 NextBBNum = 0;
554 }
555
556 void FunctionDone() {
557 NumberedBlocks.clear();
558
559 // Any forward referenced blocks left?
560 if (!BBForwardRefs.empty()) {
561 error("Undefined reference to label " +
562 BBForwardRefs.begin()->first->getName());
563 return;
564 }
565
566 // Resolve all forward references now.
567 ResolveDefinitions(LateResolveValues, &CurModule.LateResolveValues);
568
569 Values.clear(); // Clear out function local definitions
570 RenameMap.clear();
Reid Spencer950bf602007-01-26 08:19:09 +0000571 CurrentFunction = 0;
572 isDeclare = false;
573 Linkage = GlobalValue::ExternalLinkage;
574 }
575} CurFun; // Info for the current function...
576
577static bool inFunctionScope() { return CurFun.CurrentFunction != 0; }
578
Reid Spencerbb1fd572007-03-21 17:15:50 +0000579/// This function is just a utility to make a Key value for the rename map.
580/// The Key is a combination of the name, type, Signedness of the original
581/// value (global/function). This just constructs the key and ensures that
582/// named Signedness values are resolved to the actual Signedness.
583/// @brief Make a key for the RenameMaps
584static RenameMapKey makeRenameMapKey(const std::string &Name, const Type* Ty,
585 const Signedness &Sign) {
586 TypeInfo TI;
587 TI.T = Ty;
588 if (Sign.isNamed())
589 // Don't allow Named Signedness nodes because they won't match. The actual
590 // Signedness must be looked up in the NamedTypeSigns map.
591 TI.S.copy(CurModule.NamedTypeSigns[Sign.getName()]);
592 else
593 TI.S.copy(Sign);
594 return std::make_pair(Name, TI);
595}
596
Reid Spencer950bf602007-01-26 08:19:09 +0000597
598//===----------------------------------------------------------------------===//
599// Code to handle definitions of all the types
600//===----------------------------------------------------------------------===//
601
602static int InsertValue(Value *V,
603 std::map<const Type*,ValueList> &ValueTab = CurFun.Values) {
604 if (V->hasName()) return -1; // Is this a numbered definition?
605
606 // Yes, insert the value into the value table...
607 ValueList &List = ValueTab[V->getType()];
608 List.push_back(V);
609 return List.size()-1;
610}
611
Reid Spencerd7c4f8c2007-01-26 19:59:25 +0000612static const Type *getType(const ValID &D, bool DoNotImprovise = false) {
Reid Spencer950bf602007-01-26 08:19:09 +0000613 switch (D.Type) {
614 case ValID::NumberVal: // Is it a numbered definition?
615 // Module constants occupy the lowest numbered slots...
616 if ((unsigned)D.Num < CurModule.Types.size()) {
617 return CurModule.Types[(unsigned)D.Num];
618 }
619 break;
620 case ValID::NameVal: // Is it a named definition?
621 if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) {
Reid Spencer950bf602007-01-26 08:19:09 +0000622 return N;
623 }
624 break;
625 default:
626 error("Internal parser error: Invalid symbol type reference");
627 return 0;
628 }
629
630 // If we reached here, we referenced either a symbol that we don't know about
631 // or an id number that hasn't been read yet. We may be referencing something
632 // forward, so just create an entry to be resolved later and get to it...
633 //
634 if (DoNotImprovise) return 0; // Do we just want a null to be returned?
635
Reid Spencer950bf602007-01-26 08:19:09 +0000636 if (inFunctionScope()) {
637 if (D.Type == ValID::NameVal) {
638 error("Reference to an undefined type: '" + D.getName() + "'");
639 return 0;
640 } else {
641 error("Reference to an undefined type: #" + itostr(D.Num));
642 return 0;
643 }
644 }
645
646 std::map<ValID, PATypeHolder>::iterator I =CurModule.LateResolveTypes.find(D);
647 if (I != CurModule.LateResolveTypes.end())
648 return I->second;
649
650 Type *Typ = OpaqueType::get();
651 CurModule.LateResolveTypes.insert(std::make_pair(D, Typ));
652 return Typ;
Reid Spencerbb1fd572007-03-21 17:15:50 +0000653}
654
655/// This is like the getType method except that instead of looking up the type
656/// for a given ID, it looks up that type's sign.
657/// @brief Get the signedness of a referenced type
658static Signedness getTypeSign(const ValID &D) {
659 switch (D.Type) {
660 case ValID::NumberVal: // Is it a numbered definition?
661 // Module constants occupy the lowest numbered slots...
662 if ((unsigned)D.Num < CurModule.TypeSigns.size()) {
663 return CurModule.TypeSigns[(unsigned)D.Num];
664 }
665 break;
666 case ValID::NameVal: { // Is it a named definition?
667 std::map<std::string,Signedness>::const_iterator I =
668 CurModule.NamedTypeSigns.find(D.Name);
669 if (I != CurModule.NamedTypeSigns.end())
670 return I->second;
671 // Perhaps its a named forward .. just cache the name
672 Signedness S;
673 S.makeNamed(D.Name);
674 return S;
675 }
676 default:
677 break;
678 }
679 // If we don't find it, its signless
680 Signedness S;
681 S.makeSignless();
682 return S;
683}
684
685/// This function is analagous to getElementType in LLVM. It provides the same
686/// function except that it looks up the Signedness instead of the type. This is
687/// used when processing GEP instructions that need to extract the type of an
688/// indexed struct/array/ptr member.
689/// @brief Look up an element's sign.
690static Signedness getElementSign(const ValueInfo& VI,
691 const std::vector<Value*> &Indices) {
692 const Type *Ptr = VI.V->getType();
693 assert(isa<PointerType>(Ptr) && "Need pointer type");
694
695 unsigned CurIdx = 0;
696 Signedness S(VI.S);
697 while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) {
698 if (CurIdx == Indices.size())
699 break;
700
701 Value *Index = Indices[CurIdx++];
702 assert(!isa<PointerType>(CT) || CurIdx == 1 && "Invalid type");
703 Ptr = CT->getTypeAtIndex(Index);
704 if (const Type* Ty = Ptr->getForwardedType())
705 Ptr = Ty;
706 assert(S.isComposite() && "Bad Signedness type");
707 if (isa<StructType>(CT)) {
708 S = S.get(cast<ConstantInt>(Index)->getZExtValue());
709 } else {
710 S = S.get(0UL);
711 }
712 if (S.isNamed())
713 S = CurModule.NamedTypeSigns[S.getName()];
714 }
715 Signedness Result;
716 Result.makeComposite(S);
717 return Result;
718}
719
720/// This function just translates a ConstantInfo into a ValueInfo and calls
721/// getElementSign(ValueInfo,...). Its just a convenience.
722/// @brief ConstantInfo version of getElementSign.
723static Signedness getElementSign(const ConstInfo& CI,
724 const std::vector<Constant*> &Indices) {
725 ValueInfo VI;
726 VI.V = CI.C;
727 VI.S.copy(CI.S);
728 std::vector<Value*> Idx;
729 for (unsigned i = 0; i < Indices.size(); ++i)
730 Idx.push_back(Indices[i]);
731 Signedness result = getElementSign(VI, Idx);
732 VI.destroy();
733 return result;
734}
Reid Spencer950bf602007-01-26 08:19:09 +0000735
Reid Spencered96d1e2007-02-08 09:08:52 +0000736/// This function determines if two function types differ only in their use of
737/// the sret parameter attribute in the first argument. If they are identical
738/// in all other respects, it returns true. Otherwise, it returns false.
Reid Spencerbb1fd572007-03-21 17:15:50 +0000739static bool FuncTysDifferOnlyBySRet(const FunctionType *F1,
740 const FunctionType *F2) {
Reid Spencered96d1e2007-02-08 09:08:52 +0000741 if (F1->getReturnType() != F2->getReturnType() ||
Reid Spencer7b5d4662007-04-09 06:16:21 +0000742 F1->getNumParams() != F2->getNumParams())
Reid Spencered96d1e2007-02-08 09:08:52 +0000743 return false;
Reid Spencer7eea8ff2007-05-18 05:48:07 +0000744 const ParamAttrsList *PAL1 = F1->getParamAttrs();
745 const ParamAttrsList *PAL2 = F2->getParamAttrs();
746 if (PAL1 && !PAL2 || PAL2 && !PAL1)
747 return false;
748 if (PAL1 && PAL2 && ((PAL1->size() != PAL2->size()) ||
749 (PAL1->getParamAttrs(0) != PAL2->getParamAttrs(0))))
Reid Spencer7b5d4662007-04-09 06:16:21 +0000750 return false;
Reid Spencer18da0722007-04-11 02:44:20 +0000751 unsigned SRetMask = ~unsigned(ParamAttr::StructRet);
Reid Spencered96d1e2007-02-08 09:08:52 +0000752 for (unsigned i = 0; i < F1->getNumParams(); ++i) {
Reid Spencer7eea8ff2007-05-18 05:48:07 +0000753 if (F1->getParamType(i) != F2->getParamType(i) || (PAL1 && PAL2 &&
754 (unsigned(PAL1->getParamAttrs(i+1)) & SRetMask !=
755 unsigned(PAL2->getParamAttrs(i+1)) & SRetMask)))
Reid Spencered96d1e2007-02-08 09:08:52 +0000756 return false;
757 }
758 return true;
759}
760
Reid Spencerbb1fd572007-03-21 17:15:50 +0000761/// This function determines if the type of V and Ty differ only by the SRet
762/// parameter attribute. This is a more generalized case of
763/// FuncTysDIfferOnlyBySRet since it doesn't require FunctionType arguments.
764static bool TypesDifferOnlyBySRet(Value *V, const Type* Ty) {
765 if (V->getType() == Ty)
766 return true;
767 const PointerType *PF1 = dyn_cast<PointerType>(Ty);
768 const PointerType *PF2 = dyn_cast<PointerType>(V->getType());
769 if (PF1 && PF2) {
770 const FunctionType* FT1 = dyn_cast<FunctionType>(PF1->getElementType());
771 const FunctionType* FT2 = dyn_cast<FunctionType>(PF2->getElementType());
772 if (FT1 && FT2)
773 return FuncTysDifferOnlyBySRet(FT1, FT2);
774 }
775 return false;
776}
777
Reid Spencered96d1e2007-02-08 09:08:52 +0000778// The upgrade of csretcc to sret param attribute may have caused a function
779// to not be found because the param attribute changed the type of the called
780// function. This helper function, used in getExistingValue, detects that
Reid Spencerbb1fd572007-03-21 17:15:50 +0000781// situation and bitcasts the function to the correct type.
Reid Spencered96d1e2007-02-08 09:08:52 +0000782static Value* handleSRetFuncTypeMerge(Value *V, const Type* Ty) {
783 // Handle degenerate cases
784 if (!V)
785 return 0;
786 if (V->getType() == Ty)
787 return V;
788
Reid Spencered96d1e2007-02-08 09:08:52 +0000789 const PointerType *PF1 = dyn_cast<PointerType>(Ty);
790 const PointerType *PF2 = dyn_cast<PointerType>(V->getType());
791 if (PF1 && PF2) {
Reid Spencerbb1fd572007-03-21 17:15:50 +0000792 const FunctionType *FT1 = dyn_cast<FunctionType>(PF1->getElementType());
793 const FunctionType *FT2 = dyn_cast<FunctionType>(PF2->getElementType());
Reid Spencer7b5d4662007-04-09 06:16:21 +0000794 if (FT1 && FT2 && FuncTysDifferOnlyBySRet(FT1, FT2)) {
795 const ParamAttrsList *PAL2 = FT2->getParamAttrs();
Reid Spencer18da0722007-04-11 02:44:20 +0000796 if (PAL2 && PAL2->paramHasAttr(1, ParamAttr::StructRet))
Reid Spencerbb1fd572007-03-21 17:15:50 +0000797 return V;
Reid Spencered96d1e2007-02-08 09:08:52 +0000798 else if (Constant *C = dyn_cast<Constant>(V))
Reid Spencerbb1fd572007-03-21 17:15:50 +0000799 return ConstantExpr::getBitCast(C, PF1);
Reid Spencered96d1e2007-02-08 09:08:52 +0000800 else
Reid Spencerbb1fd572007-03-21 17:15:50 +0000801 return new BitCastInst(V, PF1, "upgrd.cast", CurBB);
Reid Spencer7b5d4662007-04-09 06:16:21 +0000802 }
Reid Spencerbb1fd572007-03-21 17:15:50 +0000803
Reid Spencered96d1e2007-02-08 09:08:52 +0000804 }
Reid Spencerbb1fd572007-03-21 17:15:50 +0000805 return 0;
Reid Spencered96d1e2007-02-08 09:08:52 +0000806}
807
Reid Spencer950bf602007-01-26 08:19:09 +0000808// getExistingValue - Look up the value specified by the provided type and
809// the provided ValID. If the value exists and has already been defined, return
810// it. Otherwise return null.
811//
812static Value *getExistingValue(const Type *Ty, const ValID &D) {
813 if (isa<FunctionType>(Ty)) {
814 error("Functions are not values and must be referenced as pointers");
815 }
816
817 switch (D.Type) {
818 case ValID::NumberVal: { // Is it a numbered definition?
819 unsigned Num = (unsigned)D.Num;
820
821 // Module constants occupy the lowest numbered slots...
822 std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
823 if (VI != CurModule.Values.end()) {
824 if (Num < VI->second.size())
825 return VI->second[Num];
826 Num -= VI->second.size();
827 }
828
829 // Make sure that our type is within bounds
830 VI = CurFun.Values.find(Ty);
831 if (VI == CurFun.Values.end()) return 0;
832
833 // Check that the number is within bounds...
834 if (VI->second.size() <= Num) return 0;
835
836 return VI->second[Num];
837 }
838
839 case ValID::NameVal: { // Is it a named definition?
840 // Get the name out of the ID
Reid Spencerbb1fd572007-03-21 17:15:50 +0000841 RenameMapKey Key = makeRenameMapKey(D.Name, Ty, D.S);
842 Value *V = 0;
Reid Spencer950bf602007-01-26 08:19:09 +0000843 if (inFunctionScope()) {
844 // See if the name was renamed
845 RenameMapType::const_iterator I = CurFun.RenameMap.find(Key);
846 std::string LookupName;
847 if (I != CurFun.RenameMap.end())
848 LookupName = I->second;
849 else
Reid Spencerbb1fd572007-03-21 17:15:50 +0000850 LookupName = D.Name;
Reid Spenceref9b9a72007-02-05 20:47:22 +0000851 ValueSymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable();
852 V = SymTab.lookup(LookupName);
Reid Spencerbb1fd572007-03-21 17:15:50 +0000853 if (V && V->getType() != Ty)
854 V = handleSRetFuncTypeMerge(V, Ty);
855 assert((!V || TypesDifferOnlyBySRet(V, Ty)) && "Found wrong type");
Reid Spencer950bf602007-01-26 08:19:09 +0000856 }
857 if (!V) {
858 RenameMapType::const_iterator I = CurModule.RenameMap.find(Key);
859 std::string LookupName;
860 if (I != CurModule.RenameMap.end())
861 LookupName = I->second;
862 else
Reid Spencerbb1fd572007-03-21 17:15:50 +0000863 LookupName = D.Name;
Reid Spenceref9b9a72007-02-05 20:47:22 +0000864 V = CurModule.CurrentModule->getValueSymbolTable().lookup(LookupName);
Reid Spencerbb1fd572007-03-21 17:15:50 +0000865 if (V && V->getType() != Ty)
866 V = handleSRetFuncTypeMerge(V, Ty);
867 assert((!V || TypesDifferOnlyBySRet(V, Ty)) && "Found wrong type");
Reid Spencer950bf602007-01-26 08:19:09 +0000868 }
Reid Spenceref9b9a72007-02-05 20:47:22 +0000869 if (!V)
Reid Spencer950bf602007-01-26 08:19:09 +0000870 return 0;
871
872 D.destroy(); // Free old strdup'd memory...
873 return V;
874 }
875
876 // Check to make sure that "Ty" is an integral type, and that our
877 // value will fit into the specified type...
878 case ValID::ConstSIntVal: // Is it a constant pool reference??
879 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
880 error("Signed integral constant '" + itostr(D.ConstPool64) +
881 "' is invalid for type '" + Ty->getDescription() + "'");
882 }
883 return ConstantInt::get(Ty, D.ConstPool64);
884
885 case ValID::ConstUIntVal: // Is it an unsigned const pool reference?
886 if (!ConstantInt::isValueValidForType(Ty, D.UConstPool64)) {
887 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64))
888 error("Integral constant '" + utostr(D.UConstPool64) +
889 "' is invalid or out of range");
890 else // This is really a signed reference. Transmogrify.
891 return ConstantInt::get(Ty, D.ConstPool64);
892 } else
893 return ConstantInt::get(Ty, D.UConstPool64);
894
895 case ValID::ConstFPVal: // Is it a floating point const pool reference?
896 if (!ConstantFP::isValueValidForType(Ty, D.ConstPoolFP))
897 error("FP constant invalid for type");
898 return ConstantFP::get(Ty, D.ConstPoolFP);
899
900 case ValID::ConstNullVal: // Is it a null value?
901 if (!isa<PointerType>(Ty))
902 error("Cannot create a a non pointer null");
903 return ConstantPointerNull::get(cast<PointerType>(Ty));
904
905 case ValID::ConstUndefVal: // Is it an undef value?
906 return UndefValue::get(Ty);
907
908 case ValID::ConstZeroVal: // Is it a zero value?
909 return Constant::getNullValue(Ty);
910
911 case ValID::ConstantVal: // Fully resolved constant?
912 if (D.ConstantValue->getType() != Ty)
913 error("Constant expression type different from required type");
914 return D.ConstantValue;
915
916 case ValID::InlineAsmVal: { // Inline asm expression
917 const PointerType *PTy = dyn_cast<PointerType>(Ty);
918 const FunctionType *FTy =
919 PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
920 if (!FTy || !InlineAsm::Verify(FTy, D.IAD->Constraints))
921 error("Invalid type for asm constraint string");
922 InlineAsm *IA = InlineAsm::get(FTy, D.IAD->AsmString, D.IAD->Constraints,
923 D.IAD->HasSideEffects);
924 D.destroy(); // Free InlineAsmDescriptor.
925 return IA;
926 }
927 default:
928 assert(0 && "Unhandled case");
929 return 0;
930 } // End of switch
931
932 assert(0 && "Unhandled case");
933 return 0;
934}
935
936// getVal - This function is identical to getExistingValue, except that if a
937// value is not already defined, it "improvises" by creating a placeholder var
938// that looks and acts just like the requested variable. When the value is
939// defined later, all uses of the placeholder variable are replaced with the
940// real thing.
941//
942static Value *getVal(const Type *Ty, const ValID &ID) {
943 if (Ty == Type::LabelTy)
944 error("Cannot use a basic block here");
945
946 // See if the value has already been defined.
947 Value *V = getExistingValue(Ty, ID);
948 if (V) return V;
949
950 if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty))
951 error("Invalid use of a composite type");
952
953 // If we reached here, we referenced either a symbol that we don't know about
954 // or an id number that hasn't been read yet. We may be referencing something
955 // forward, so just create an entry to be resolved later and get to it...
Reid Spencer950bf602007-01-26 08:19:09 +0000956 V = new Argument(Ty);
957
958 // Remember where this forward reference came from. FIXME, shouldn't we try
959 // to recycle these things??
960 CurModule.PlaceHolderInfo.insert(
Reid Spenceref9b9a72007-02-05 20:47:22 +0000961 std::make_pair(V, std::make_pair(ID, Upgradelineno)));
Reid Spencer950bf602007-01-26 08:19:09 +0000962
963 if (inFunctionScope())
964 InsertValue(V, CurFun.LateResolveValues);
965 else
966 InsertValue(V, CurModule.LateResolveValues);
967 return V;
968}
969
Reid Spencered96d1e2007-02-08 09:08:52 +0000970/// @brief This just makes any name given to it unique, up to MAX_UINT times.
971static std::string makeNameUnique(const std::string& Name) {
972 static unsigned UniqueNameCounter = 1;
973 std::string Result(Name);
974 Result += ".upgrd." + llvm::utostr(UniqueNameCounter++);
975 return Result;
976}
977
Reid Spencer950bf602007-01-26 08:19:09 +0000978/// getBBVal - This is used for two purposes:
979/// * If isDefinition is true, a new basic block with the specified ID is being
980/// defined.
981/// * If isDefinition is true, this is a reference to a basic block, which may
982/// or may not be a forward reference.
983///
984static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
985 assert(inFunctionScope() && "Can't get basic block at global scope");
986
987 std::string Name;
988 BasicBlock *BB = 0;
989 switch (ID.Type) {
990 default:
991 error("Illegal label reference " + ID.getName());
992 break;
993 case ValID::NumberVal: // Is it a numbered definition?
994 if (unsigned(ID.Num) >= CurFun.NumberedBlocks.size())
995 CurFun.NumberedBlocks.resize(ID.Num+1);
996 BB = CurFun.NumberedBlocks[ID.Num];
997 break;
998 case ValID::NameVal: // Is it a named definition?
999 Name = ID.Name;
Reid Spencerbb1fd572007-03-21 17:15:50 +00001000 if (Value *N = CurFun.CurrentFunction->getValueSymbolTable().lookup(Name)) {
Reid Spencered96d1e2007-02-08 09:08:52 +00001001 if (N->getType() != Type::LabelTy) {
1002 // Register names didn't use to conflict with basic block names
1003 // because of type planes. Now they all have to be unique. So, we just
1004 // rename the register and treat this name as if no basic block
1005 // had been found.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001006 RenameMapKey Key = makeRenameMapKey(ID.Name, N->getType(), ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00001007 N->setName(makeNameUnique(N->getName()));
1008 CurModule.RenameMap[Key] = N->getName();
1009 BB = 0;
1010 } else {
1011 BB = cast<BasicBlock>(N);
1012 }
Reid Spencer950bf602007-01-26 08:19:09 +00001013 }
1014 break;
1015 }
1016
1017 // See if the block has already been defined.
1018 if (BB) {
1019 // If this is the definition of the block, make sure the existing value was
1020 // just a forward reference. If it was a forward reference, there will be
1021 // an entry for it in the PlaceHolderInfo map.
1022 if (isDefinition && !CurFun.BBForwardRefs.erase(BB))
1023 // The existing value was a definition, not a forward reference.
1024 error("Redefinition of label " + ID.getName());
1025
1026 ID.destroy(); // Free strdup'd memory.
1027 return BB;
1028 }
1029
1030 // Otherwise this block has not been seen before.
1031 BB = new BasicBlock("", CurFun.CurrentFunction);
1032 if (ID.Type == ValID::NameVal) {
1033 BB->setName(ID.Name);
1034 } else {
1035 CurFun.NumberedBlocks[ID.Num] = BB;
1036 }
1037
1038 // If this is not a definition, keep track of it so we can use it as a forward
1039 // reference.
1040 if (!isDefinition) {
1041 // Remember where this forward reference came from.
1042 CurFun.BBForwardRefs[BB] = std::make_pair(ID, Upgradelineno);
1043 } else {
1044 // The forward declaration could have been inserted anywhere in the
1045 // function: insert it into the correct place now.
1046 CurFun.CurrentFunction->getBasicBlockList().remove(BB);
1047 CurFun.CurrentFunction->getBasicBlockList().push_back(BB);
1048 }
1049 ID.destroy();
1050 return BB;
1051}
1052
1053
1054//===----------------------------------------------------------------------===//
1055// Code to handle forward references in instructions
1056//===----------------------------------------------------------------------===//
1057//
1058// This code handles the late binding needed with statements that reference
1059// values not defined yet... for example, a forward branch, or the PHI node for
1060// a loop body.
1061//
1062// This keeps a table (CurFun.LateResolveValues) of all such forward references
1063// and back patchs after we are done.
1064//
1065
1066// ResolveDefinitions - If we could not resolve some defs at parsing
1067// time (forward branches, phi functions for loops, etc...) resolve the
1068// defs now...
1069//
1070static void
1071ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
1072 std::map<const Type*,ValueList> *FutureLateResolvers) {
Reid Spencered96d1e2007-02-08 09:08:52 +00001073
Reid Spencer950bf602007-01-26 08:19:09 +00001074 // Loop over LateResolveDefs fixing up stuff that couldn't be resolved
1075 for (std::map<const Type*,ValueList>::iterator LRI = LateResolvers.begin(),
1076 E = LateResolvers.end(); LRI != E; ++LRI) {
Reid Spencered96d1e2007-02-08 09:08:52 +00001077 const Type* Ty = LRI->first;
Reid Spencer950bf602007-01-26 08:19:09 +00001078 ValueList &List = LRI->second;
1079 while (!List.empty()) {
1080 Value *V = List.back();
1081 List.pop_back();
1082
1083 std::map<Value*, std::pair<ValID, int> >::iterator PHI =
1084 CurModule.PlaceHolderInfo.find(V);
1085 assert(PHI != CurModule.PlaceHolderInfo.end() && "Placeholder error");
1086
1087 ValID &DID = PHI->second.first;
1088
Reid Spencered96d1e2007-02-08 09:08:52 +00001089 Value *TheRealValue = getExistingValue(Ty, DID);
Reid Spencer950bf602007-01-26 08:19:09 +00001090 if (TheRealValue) {
1091 V->replaceAllUsesWith(TheRealValue);
1092 delete V;
1093 CurModule.PlaceHolderInfo.erase(PHI);
1094 } else if (FutureLateResolvers) {
1095 // Functions have their unresolved items forwarded to the module late
1096 // resolver table
1097 InsertValue(V, *FutureLateResolvers);
1098 } else {
1099 if (DID.Type == ValID::NameVal) {
Reid Spencered96d1e2007-02-08 09:08:52 +00001100 error("Reference to an invalid definition: '" + DID.getName() +
1101 "' of type '" + V->getType()->getDescription() + "'",
1102 PHI->second.second);
Reid Spencer7de2e012007-01-29 19:08:46 +00001103 return;
Reid Spencer950bf602007-01-26 08:19:09 +00001104 } else {
1105 error("Reference to an invalid definition: #" +
1106 itostr(DID.Num) + " of type '" +
1107 V->getType()->getDescription() + "'", PHI->second.second);
1108 return;
1109 }
1110 }
1111 }
1112 }
1113
1114 LateResolvers.clear();
1115}
1116
Reid Spencerbb1fd572007-03-21 17:15:50 +00001117/// This function is used for type resolution and upref handling. When a type
1118/// becomes concrete, this function is called to adjust the signedness for the
1119/// concrete type.
1120static void ResolveTypeSign(const Type* oldTy, const Signedness &Sign) {
1121 std::string TyName = CurModule.CurrentModule->getTypeName(oldTy);
1122 if (!TyName.empty())
1123 CurModule.NamedTypeSigns[TyName] = Sign;
1124}
1125
1126/// ResolveTypeTo - A brand new type was just declared. This means that (if
1127/// name is not null) things referencing Name can be resolved. Otherwise,
1128/// things refering to the number can be resolved. Do this now.
1129static void ResolveTypeTo(char *Name, const Type *ToTy, const Signedness& Sign){
Reid Spencer950bf602007-01-26 08:19:09 +00001130 ValID D;
Reid Spencerbb1fd572007-03-21 17:15:50 +00001131 if (Name)
1132 D = ValID::create(Name);
1133 else
1134 D = ValID::create((int)CurModule.Types.size());
1135 D.S.copy(Sign);
1136
Reid Spencerbaba98a2007-04-11 12:10:58 +00001137 if (Name)
1138 CurModule.NamedTypeSigns[Name] = Sign;
Reid Spencer950bf602007-01-26 08:19:09 +00001139
1140 std::map<ValID, PATypeHolder>::iterator I =
1141 CurModule.LateResolveTypes.find(D);
1142 if (I != CurModule.LateResolveTypes.end()) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00001143 const Type *OldTy = I->second.get();
1144 ((DerivedType*)OldTy)->refineAbstractTypeTo(ToTy);
Reid Spencer950bf602007-01-26 08:19:09 +00001145 CurModule.LateResolveTypes.erase(I);
1146 }
1147}
1148
Anton Korobeynikovce13b852007-01-28 15:25:24 +00001149/// This is the implementation portion of TypeHasInteger. It traverses the
1150/// type given, avoiding recursive types, and returns true as soon as it finds
1151/// an integer type. If no integer type is found, it returns false.
1152static bool TypeHasIntegerI(const Type *Ty, std::vector<const Type*> Stack) {
1153 // Handle some easy cases
1154 if (Ty->isPrimitiveType() || (Ty->getTypeID() == Type::OpaqueTyID))
1155 return false;
1156 if (Ty->isInteger())
1157 return true;
1158 if (const SequentialType *STy = dyn_cast<SequentialType>(Ty))
1159 return STy->getElementType()->isInteger();
1160
1161 // Avoid type structure recursion
1162 for (std::vector<const Type*>::iterator I = Stack.begin(), E = Stack.end();
1163 I != E; ++I)
1164 if (Ty == *I)
1165 return false;
1166
1167 // Push us on the type stack
1168 Stack.push_back(Ty);
1169
1170 if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
1171 if (TypeHasIntegerI(FTy->getReturnType(), Stack))
1172 return true;
1173 FunctionType::param_iterator I = FTy->param_begin();
1174 FunctionType::param_iterator E = FTy->param_end();
1175 for (; I != E; ++I)
1176 if (TypeHasIntegerI(*I, Stack))
1177 return true;
1178 return false;
1179 } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
1180 StructType::element_iterator I = STy->element_begin();
1181 StructType::element_iterator E = STy->element_end();
1182 for (; I != E; ++I) {
1183 if (TypeHasIntegerI(*I, Stack))
1184 return true;
1185 }
1186 return false;
1187 }
1188 // There shouldn't be anything else, but its definitely not integer
1189 assert(0 && "What type is this?");
1190 return false;
1191}
1192
1193/// This is the interface to TypeHasIntegerI. It just provides the type stack,
1194/// to avoid recursion, and then calls TypeHasIntegerI.
1195static inline bool TypeHasInteger(const Type *Ty) {
1196 std::vector<const Type*> TyStack;
1197 return TypeHasIntegerI(Ty, TyStack);
1198}
1199
Reid Spencer950bf602007-01-26 08:19:09 +00001200// setValueName - Set the specified value to the name given. The name may be
1201// null potentially, in which case this is a noop. The string passed in is
1202// assumed to be a malloc'd string buffer, and is free'd by this function.
1203//
Reid Spencerbb1fd572007-03-21 17:15:50 +00001204static void setValueName(const ValueInfo &V, char *NameStr) {
Reid Spencer950bf602007-01-26 08:19:09 +00001205 if (NameStr) {
1206 std::string Name(NameStr); // Copy string
1207 free(NameStr); // Free old string
1208
Reid Spencerbb1fd572007-03-21 17:15:50 +00001209 if (V.V->getType() == Type::VoidTy) {
Reid Spencer950bf602007-01-26 08:19:09 +00001210 error("Can't assign name '" + Name + "' to value with void type");
1211 return;
1212 }
1213
Reid Spencer950bf602007-01-26 08:19:09 +00001214 assert(inFunctionScope() && "Must be in function scope");
1215
1216 // Search the function's symbol table for an existing value of this name
Reid Spenceref9b9a72007-02-05 20:47:22 +00001217 ValueSymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
1218 Value* Existing = ST.lookup(Name);
Reid Spencer950bf602007-01-26 08:19:09 +00001219 if (Existing) {
Anton Korobeynikovce13b852007-01-28 15:25:24 +00001220 // An existing value of the same name was found. This might have happened
1221 // because of the integer type planes collapsing in LLVM 2.0.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001222 if (Existing->getType() == V.V->getType() &&
Anton Korobeynikovce13b852007-01-28 15:25:24 +00001223 !TypeHasInteger(Existing->getType())) {
1224 // If the type does not contain any integers in them then this can't be
1225 // a type plane collapsing issue. It truly is a redefinition and we
1226 // should error out as the assembly is invalid.
1227 error("Redefinition of value named '" + Name + "' of type '" +
Reid Spencerbb1fd572007-03-21 17:15:50 +00001228 V.V->getType()->getDescription() + "'");
Anton Korobeynikovce13b852007-01-28 15:25:24 +00001229 return;
Reid Spencer950bf602007-01-26 08:19:09 +00001230 }
1231 // In LLVM 2.0 we don't allow names to be re-used for any values in a
1232 // function, regardless of Type. Previously re-use of names was okay as
1233 // long as they were distinct types. With type planes collapsing because
1234 // of the signedness change and because of PR411, this can no longer be
1235 // supported. We must search the entire symbol table for a conflicting
1236 // name and make the name unique. No warning is needed as this can't
1237 // cause a problem.
1238 std::string NewName = makeNameUnique(Name);
1239 // We're changing the name but it will probably be used by other
1240 // instructions as operands later on. Consequently we have to retain
1241 // a mapping of the renaming that we're doing.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001242 RenameMapKey Key = makeRenameMapKey(Name, V.V->getType(), V.S);
Reid Spencer950bf602007-01-26 08:19:09 +00001243 CurFun.RenameMap[Key] = NewName;
1244 Name = NewName;
1245 }
1246
1247 // Set the name.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001248 V.V->setName(Name);
Reid Spencer950bf602007-01-26 08:19:09 +00001249 }
1250}
1251
1252/// ParseGlobalVariable - Handle parsing of a global. If Initializer is null,
1253/// this is a declaration, otherwise it is a definition.
1254static GlobalVariable *
1255ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
1256 bool isConstantGlobal, const Type *Ty,
Reid Spencerbb1fd572007-03-21 17:15:50 +00001257 Constant *Initializer,
1258 const Signedness &Sign) {
Reid Spencer950bf602007-01-26 08:19:09 +00001259 if (isa<FunctionType>(Ty))
1260 error("Cannot declare global vars of function type");
1261
1262 const PointerType *PTy = PointerType::get(Ty);
1263
1264 std::string Name;
1265 if (NameStr) {
1266 Name = NameStr; // Copy string
1267 free(NameStr); // Free old string
1268 }
1269
1270 // See if this global value was forward referenced. If so, recycle the
1271 // object.
1272 ValID ID;
1273 if (!Name.empty()) {
Reid Spencer5eb77c72007-03-15 03:26:42 +00001274 ID = ValID::create((char*)Name.c_str());
Reid Spencer950bf602007-01-26 08:19:09 +00001275 } else {
Reid Spencer5eb77c72007-03-15 03:26:42 +00001276 ID = ValID::create((int)CurModule.Values[PTy].size());
Reid Spencer950bf602007-01-26 08:19:09 +00001277 }
Reid Spencerbb1fd572007-03-21 17:15:50 +00001278 ID.S.makeComposite(Sign);
Reid Spencer950bf602007-01-26 08:19:09 +00001279
1280 if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) {
1281 // Move the global to the end of the list, from whereever it was
1282 // previously inserted.
1283 GlobalVariable *GV = cast<GlobalVariable>(FWGV);
1284 CurModule.CurrentModule->getGlobalList().remove(GV);
1285 CurModule.CurrentModule->getGlobalList().push_back(GV);
1286 GV->setInitializer(Initializer);
1287 GV->setLinkage(Linkage);
1288 GV->setConstant(isConstantGlobal);
1289 InsertValue(GV, CurModule.Values);
1290 return GV;
1291 }
1292
1293 // If this global has a name, check to see if there is already a definition
1294 // of this global in the module and emit warnings if there are conflicts.
1295 if (!Name.empty()) {
1296 // The global has a name. See if there's an existing one of the same name.
Reid Spencere59f4932007-04-16 03:05:01 +00001297 if (CurModule.CurrentModule->getNamedGlobal(Name) ||
1298 CurModule.CurrentModule->getFunction(Name)) {
1299 // We found an existing global of the same name. This isn't allowed
Reid Spencer950bf602007-01-26 08:19:09 +00001300 // in LLVM 2.0. Consequently, we must alter the name of the global so it
1301 // can at least compile. This can happen because of type planes
1302 // There is alread a global of the same name which means there is a
1303 // conflict. Let's see what we can do about it.
1304 std::string NewName(makeNameUnique(Name));
Reid Spencerbb1fd572007-03-21 17:15:50 +00001305 if (Linkage != GlobalValue::InternalLinkage) {
Reid Spencer950bf602007-01-26 08:19:09 +00001306 // The linkage of this gval is external so we can't reliably rename
1307 // it because it could potentially create a linking problem.
1308 // However, we can't leave the name conflict in the output either or
1309 // it won't assemble with LLVM 2.0. So, all we can do is rename
1310 // this one to something unique and emit a warning about the problem.
1311 warning("Renaming global variable '" + Name + "' to '" + NewName +
1312 "' may cause linkage errors");
1313 }
1314
1315 // Put the renaming in the global rename map
Reid Spencerbb1fd572007-03-21 17:15:50 +00001316 RenameMapKey Key = makeRenameMapKey(Name, PointerType::get(Ty), ID.S);
Reid Spencer950bf602007-01-26 08:19:09 +00001317 CurModule.RenameMap[Key] = NewName;
1318
1319 // Rename it
1320 Name = NewName;
1321 }
1322 }
1323
1324 // Otherwise there is no existing GV to use, create one now.
1325 GlobalVariable *GV =
1326 new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name,
1327 CurModule.CurrentModule);
1328 InsertValue(GV, CurModule.Values);
Reid Spencerbb1fd572007-03-21 17:15:50 +00001329 // Remember the sign of this global.
1330 CurModule.NamedValueSigns[Name] = ID.S;
Reid Spencer950bf602007-01-26 08:19:09 +00001331 return GV;
1332}
1333
1334// setTypeName - Set the specified type to the name given. The name may be
1335// null potentially, in which case this is a noop. The string passed in is
1336// assumed to be a malloc'd string buffer, and is freed by this function.
1337//
1338// This function returns true if the type has already been defined, but is
1339// allowed to be redefined in the specified context. If the name is a new name
1340// for the type plane, it is inserted and false is returned.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001341static bool setTypeName(const PATypeInfo& TI, char *NameStr) {
Reid Spencer950bf602007-01-26 08:19:09 +00001342 assert(!inFunctionScope() && "Can't give types function-local names");
1343 if (NameStr == 0) return false;
1344
1345 std::string Name(NameStr); // Copy string
1346 free(NameStr); // Free old string
1347
Reid Spencerbb1fd572007-03-21 17:15:50 +00001348 const Type* Ty = TI.PAT->get();
1349
Reid Spencer950bf602007-01-26 08:19:09 +00001350 // We don't allow assigning names to void type
Reid Spencerbb1fd572007-03-21 17:15:50 +00001351 if (Ty == Type::VoidTy) {
Reid Spencer950bf602007-01-26 08:19:09 +00001352 error("Can't assign name '" + Name + "' to the void type");
1353 return false;
1354 }
1355
1356 // Set the type name, checking for conflicts as we do so.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001357 bool AlreadyExists = CurModule.CurrentModule->addTypeName(Name, Ty);
1358
1359 // Save the sign information for later use
1360 CurModule.NamedTypeSigns[Name] = TI.S;
Reid Spencer950bf602007-01-26 08:19:09 +00001361
1362 if (AlreadyExists) { // Inserting a name that is already defined???
1363 const Type *Existing = CurModule.CurrentModule->getTypeByName(Name);
1364 assert(Existing && "Conflict but no matching type?");
1365
1366 // There is only one case where this is allowed: when we are refining an
1367 // opaque type. In this case, Existing will be an opaque type.
1368 if (const OpaqueType *OpTy = dyn_cast<OpaqueType>(Existing)) {
1369 // We ARE replacing an opaque type!
Reid Spencerbb1fd572007-03-21 17:15:50 +00001370 const_cast<OpaqueType*>(OpTy)->refineAbstractTypeTo(Ty);
Reid Spencer950bf602007-01-26 08:19:09 +00001371 return true;
1372 }
1373
1374 // Otherwise, this is an attempt to redefine a type. That's okay if
1375 // the redefinition is identical to the original. This will be so if
1376 // Existing and T point to the same Type object. In this one case we
1377 // allow the equivalent redefinition.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001378 if (Existing == Ty) return true; // Yes, it's equal.
Reid Spencer950bf602007-01-26 08:19:09 +00001379
1380 // Any other kind of (non-equivalent) redefinition is an error.
1381 error("Redefinition of type named '" + Name + "' in the '" +
Reid Spencerbb1fd572007-03-21 17:15:50 +00001382 Ty->getDescription() + "' type plane");
Reid Spencer950bf602007-01-26 08:19:09 +00001383 }
1384
1385 return false;
1386}
1387
1388//===----------------------------------------------------------------------===//
1389// Code for handling upreferences in type names...
1390//
1391
1392// TypeContains - Returns true if Ty directly contains E in it.
1393//
1394static bool TypeContains(const Type *Ty, const Type *E) {
1395 return std::find(Ty->subtype_begin(), Ty->subtype_end(),
1396 E) != Ty->subtype_end();
1397}
1398
1399namespace {
1400 struct UpRefRecord {
1401 // NestingLevel - The number of nesting levels that need to be popped before
1402 // this type is resolved.
1403 unsigned NestingLevel;
1404
1405 // LastContainedTy - This is the type at the current binding level for the
1406 // type. Every time we reduce the nesting level, this gets updated.
1407 const Type *LastContainedTy;
1408
1409 // UpRefTy - This is the actual opaque type that the upreference is
1410 // represented with.
1411 OpaqueType *UpRefTy;
1412
1413 UpRefRecord(unsigned NL, OpaqueType *URTy)
Reid Spencerbb1fd572007-03-21 17:15:50 +00001414 : NestingLevel(NL), LastContainedTy(URTy), UpRefTy(URTy) { }
Reid Spencer950bf602007-01-26 08:19:09 +00001415 };
1416}
1417
1418// UpRefs - A list of the outstanding upreferences that need to be resolved.
1419static std::vector<UpRefRecord> UpRefs;
1420
1421/// HandleUpRefs - Every time we finish a new layer of types, this function is
1422/// called. It loops through the UpRefs vector, which is a list of the
1423/// currently active types. For each type, if the up reference is contained in
1424/// the newly completed type, we decrement the level count. When the level
1425/// count reaches zero, the upreferenced type is the type that is passed in:
1426/// thus we can complete the cycle.
1427///
Reid Spencerbb1fd572007-03-21 17:15:50 +00001428static PATypeHolder HandleUpRefs(const Type *ty, const Signedness& Sign) {
Reid Spencer950bf602007-01-26 08:19:09 +00001429 // If Ty isn't abstract, or if there are no up-references in it, then there is
1430 // nothing to resolve here.
1431 if (!ty->isAbstract() || UpRefs.empty()) return ty;
1432
1433 PATypeHolder Ty(ty);
1434 UR_OUT("Type '" << Ty->getDescription() <<
1435 "' newly formed. Resolving upreferences.\n" <<
1436 UpRefs.size() << " upreferences active!\n");
1437
1438 // If we find any resolvable upreferences (i.e., those whose NestingLevel goes
1439 // to zero), we resolve them all together before we resolve them to Ty. At
1440 // the end of the loop, if there is anything to resolve to Ty, it will be in
1441 // this variable.
1442 OpaqueType *TypeToResolve = 0;
1443
Reid Spencerbb1fd572007-03-21 17:15:50 +00001444 unsigned i = 0;
1445 for (; i != UpRefs.size(); ++i) {
Reid Spencer950bf602007-01-26 08:19:09 +00001446 UR_OUT(" UR#" << i << " - TypeContains(" << Ty->getDescription() << ", "
Reid Spencerbb1fd572007-03-21 17:15:50 +00001447 << UpRefs[i].UpRefTy->getDescription() << ") = "
1448 << (TypeContains(Ty, UpRefs[i].UpRefTy) ? "true" : "false") << "\n");
Reid Spencer950bf602007-01-26 08:19:09 +00001449 if (TypeContains(Ty, UpRefs[i].LastContainedTy)) {
1450 // Decrement level of upreference
1451 unsigned Level = --UpRefs[i].NestingLevel;
1452 UpRefs[i].LastContainedTy = Ty;
1453 UR_OUT(" Uplevel Ref Level = " << Level << "\n");
1454 if (Level == 0) { // Upreference should be resolved!
1455 if (!TypeToResolve) {
1456 TypeToResolve = UpRefs[i].UpRefTy;
1457 } else {
1458 UR_OUT(" * Resolving upreference for "
Reid Spencerbb1fd572007-03-21 17:15:50 +00001459 << UpRefs[i].UpRefTy->getDescription() << "\n";
1460 std::string OldName = UpRefs[i].UpRefTy->getDescription());
1461 ResolveTypeSign(UpRefs[i].UpRefTy, Sign);
Reid Spencer950bf602007-01-26 08:19:09 +00001462 UpRefs[i].UpRefTy->refineAbstractTypeTo(TypeToResolve);
1463 UR_OUT(" * Type '" << OldName << "' refined upreference to: "
1464 << (const void*)Ty << ", " << Ty->getDescription() << "\n");
1465 }
1466 UpRefs.erase(UpRefs.begin()+i); // Remove from upreference list...
1467 --i; // Do not skip the next element...
1468 }
1469 }
1470 }
1471
1472 if (TypeToResolve) {
1473 UR_OUT(" * Resolving upreference for "
Reid Spencerbb1fd572007-03-21 17:15:50 +00001474 << UpRefs[i].UpRefTy->getDescription() << "\n";
Reid Spencer950bf602007-01-26 08:19:09 +00001475 std::string OldName = TypeToResolve->getDescription());
Reid Spencerbb1fd572007-03-21 17:15:50 +00001476 ResolveTypeSign(TypeToResolve, Sign);
Reid Spencer950bf602007-01-26 08:19:09 +00001477 TypeToResolve->refineAbstractTypeTo(Ty);
1478 }
1479
1480 return Ty;
1481}
1482
Reid Spencerbb1fd572007-03-21 17:15:50 +00001483bool Signedness::operator<(const Signedness &that) const {
1484 if (isNamed()) {
1485 if (that.isNamed())
1486 return *(this->name) < *(that.name);
1487 else
1488 return CurModule.NamedTypeSigns[*name] < that;
1489 } else if (that.isNamed()) {
1490 return *this < CurModule.NamedTypeSigns[*that.name];
1491 }
1492
1493 if (isComposite() && that.isComposite()) {
1494 if (sv->size() == that.sv->size()) {
1495 SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1496 SignVector::const_iterator thatI = that.sv->begin(),
1497 thatE = that.sv->end();
1498 for (; thisI != thisE; ++thisI, ++thatI) {
1499 if (*thisI < *thatI)
1500 return true;
1501 else if (!(*thisI == *thatI))
1502 return false;
1503 }
1504 return false;
1505 }
1506 return sv->size() < that.sv->size();
1507 }
1508 return kind < that.kind;
1509}
1510
1511bool Signedness::operator==(const Signedness &that) const {
1512 if (isNamed())
1513 if (that.isNamed())
1514 return *(this->name) == *(that.name);
1515 else
1516 return CurModule.NamedTypeSigns[*(this->name)] == that;
1517 else if (that.isNamed())
1518 return *this == CurModule.NamedTypeSigns[*(that.name)];
1519 if (isComposite() && that.isComposite()) {
1520 if (sv->size() == that.sv->size()) {
1521 SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1522 SignVector::const_iterator thatI = that.sv->begin(),
1523 thatE = that.sv->end();
1524 for (; thisI != thisE; ++thisI, ++thatI) {
1525 if (!(*thisI == *thatI))
1526 return false;
1527 }
1528 return true;
1529 }
1530 return false;
1531 }
1532 return kind == that.kind;
1533}
1534
1535void Signedness::copy(const Signedness &that) {
1536 if (that.isNamed()) {
1537 kind = Named;
1538 name = new std::string(*that.name);
1539 } else if (that.isComposite()) {
1540 kind = Composite;
1541 sv = new SignVector();
1542 *sv = *that.sv;
1543 } else {
1544 kind = that.kind;
1545 sv = 0;
1546 }
1547}
1548
1549void Signedness::destroy() {
1550 if (isNamed()) {
1551 delete name;
1552 } else if (isComposite()) {
1553 delete sv;
1554 }
1555}
1556
Evan Cheng2b484202007-03-22 07:43:51 +00001557#ifndef NDEBUG
Reid Spencerbb1fd572007-03-21 17:15:50 +00001558void Signedness::dump() const {
1559 if (isComposite()) {
1560 if (sv->size() == 1) {
1561 (*sv)[0].dump();
1562 std::cerr << "*";
1563 } else {
1564 std::cerr << "{ " ;
1565 for (unsigned i = 0; i < sv->size(); ++i) {
1566 if (i != 0)
1567 std::cerr << ", ";
1568 (*sv)[i].dump();
1569 }
1570 std::cerr << "} " ;
1571 }
1572 } else if (isNamed()) {
1573 std::cerr << *name;
1574 } else if (isSigned()) {
1575 std::cerr << "S";
1576 } else if (isUnsigned()) {
1577 std::cerr << "U";
1578 } else
1579 std::cerr << ".";
1580}
Evan Cheng2b484202007-03-22 07:43:51 +00001581#endif
Reid Spencerbb1fd572007-03-21 17:15:50 +00001582
Reid Spencer950bf602007-01-26 08:19:09 +00001583static inline Instruction::TermOps
1584getTermOp(TermOps op) {
1585 switch (op) {
1586 default : assert(0 && "Invalid OldTermOp");
1587 case RetOp : return Instruction::Ret;
1588 case BrOp : return Instruction::Br;
1589 case SwitchOp : return Instruction::Switch;
1590 case InvokeOp : return Instruction::Invoke;
1591 case UnwindOp : return Instruction::Unwind;
1592 case UnreachableOp: return Instruction::Unreachable;
1593 }
1594}
1595
1596static inline Instruction::BinaryOps
Reid Spencerbb1fd572007-03-21 17:15:50 +00001597getBinaryOp(BinaryOps op, const Type *Ty, const Signedness& Sign) {
Reid Spencer950bf602007-01-26 08:19:09 +00001598 switch (op) {
1599 default : assert(0 && "Invalid OldBinaryOps");
1600 case SetEQ :
1601 case SetNE :
1602 case SetLE :
1603 case SetGE :
1604 case SetLT :
1605 case SetGT : assert(0 && "Should use getCompareOp");
1606 case AddOp : return Instruction::Add;
1607 case SubOp : return Instruction::Sub;
1608 case MulOp : return Instruction::Mul;
1609 case DivOp : {
1610 // This is an obsolete instruction so we must upgrade it based on the
1611 // types of its operands.
1612 bool isFP = Ty->isFloatingPoint();
Reid Spencer9d6565a2007-02-15 02:26:10 +00001613 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
Chris Lattner4227bdb2007-02-19 07:34:02 +00001614 // If its a vector type we want to use the element type
Reid Spencer950bf602007-01-26 08:19:09 +00001615 isFP = PTy->getElementType()->isFloatingPoint();
1616 if (isFP)
1617 return Instruction::FDiv;
Reid Spencerbb1fd572007-03-21 17:15:50 +00001618 else if (Sign.isSigned())
Reid Spencer950bf602007-01-26 08:19:09 +00001619 return Instruction::SDiv;
1620 return Instruction::UDiv;
1621 }
1622 case UDivOp : return Instruction::UDiv;
1623 case SDivOp : return Instruction::SDiv;
1624 case FDivOp : return Instruction::FDiv;
1625 case RemOp : {
1626 // This is an obsolete instruction so we must upgrade it based on the
1627 // types of its operands.
1628 bool isFP = Ty->isFloatingPoint();
Reid Spencer9d6565a2007-02-15 02:26:10 +00001629 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
Chris Lattner4227bdb2007-02-19 07:34:02 +00001630 // If its a vector type we want to use the element type
Reid Spencer950bf602007-01-26 08:19:09 +00001631 isFP = PTy->getElementType()->isFloatingPoint();
1632 // Select correct opcode
1633 if (isFP)
1634 return Instruction::FRem;
Reid Spencerbb1fd572007-03-21 17:15:50 +00001635 else if (Sign.isSigned())
Reid Spencer950bf602007-01-26 08:19:09 +00001636 return Instruction::SRem;
1637 return Instruction::URem;
1638 }
1639 case URemOp : return Instruction::URem;
1640 case SRemOp : return Instruction::SRem;
1641 case FRemOp : return Instruction::FRem;
Reid Spencer832254e2007-02-02 02:16:23 +00001642 case LShrOp : return Instruction::LShr;
1643 case AShrOp : return Instruction::AShr;
1644 case ShlOp : return Instruction::Shl;
1645 case ShrOp :
Reid Spencerbb1fd572007-03-21 17:15:50 +00001646 if (Sign.isSigned())
Reid Spencer832254e2007-02-02 02:16:23 +00001647 return Instruction::AShr;
1648 return Instruction::LShr;
Reid Spencer950bf602007-01-26 08:19:09 +00001649 case AndOp : return Instruction::And;
1650 case OrOp : return Instruction::Or;
1651 case XorOp : return Instruction::Xor;
1652 }
1653}
1654
1655static inline Instruction::OtherOps
1656getCompareOp(BinaryOps op, unsigned short &predicate, const Type* &Ty,
Reid Spencerbb1fd572007-03-21 17:15:50 +00001657 const Signedness &Sign) {
1658 bool isSigned = Sign.isSigned();
Reid Spencer950bf602007-01-26 08:19:09 +00001659 bool isFP = Ty->isFloatingPoint();
1660 switch (op) {
1661 default : assert(0 && "Invalid OldSetCC");
1662 case SetEQ :
1663 if (isFP) {
1664 predicate = FCmpInst::FCMP_OEQ;
1665 return Instruction::FCmp;
1666 } else {
1667 predicate = ICmpInst::ICMP_EQ;
1668 return Instruction::ICmp;
1669 }
1670 case SetNE :
1671 if (isFP) {
1672 predicate = FCmpInst::FCMP_UNE;
1673 return Instruction::FCmp;
1674 } else {
1675 predicate = ICmpInst::ICMP_NE;
1676 return Instruction::ICmp;
1677 }
1678 case SetLE :
1679 if (isFP) {
1680 predicate = FCmpInst::FCMP_OLE;
1681 return Instruction::FCmp;
1682 } else {
1683 if (isSigned)
1684 predicate = ICmpInst::ICMP_SLE;
1685 else
1686 predicate = ICmpInst::ICMP_ULE;
1687 return Instruction::ICmp;
1688 }
1689 case SetGE :
1690 if (isFP) {
1691 predicate = FCmpInst::FCMP_OGE;
1692 return Instruction::FCmp;
1693 } else {
1694 if (isSigned)
1695 predicate = ICmpInst::ICMP_SGE;
1696 else
1697 predicate = ICmpInst::ICMP_UGE;
1698 return Instruction::ICmp;
1699 }
1700 case SetLT :
1701 if (isFP) {
1702 predicate = FCmpInst::FCMP_OLT;
1703 return Instruction::FCmp;
1704 } else {
1705 if (isSigned)
1706 predicate = ICmpInst::ICMP_SLT;
1707 else
1708 predicate = ICmpInst::ICMP_ULT;
1709 return Instruction::ICmp;
1710 }
1711 case SetGT :
1712 if (isFP) {
1713 predicate = FCmpInst::FCMP_OGT;
1714 return Instruction::FCmp;
1715 } else {
1716 if (isSigned)
1717 predicate = ICmpInst::ICMP_SGT;
1718 else
1719 predicate = ICmpInst::ICMP_UGT;
1720 return Instruction::ICmp;
1721 }
1722 }
1723}
1724
1725static inline Instruction::MemoryOps getMemoryOp(MemoryOps op) {
1726 switch (op) {
1727 default : assert(0 && "Invalid OldMemoryOps");
1728 case MallocOp : return Instruction::Malloc;
1729 case FreeOp : return Instruction::Free;
1730 case AllocaOp : return Instruction::Alloca;
1731 case LoadOp : return Instruction::Load;
1732 case StoreOp : return Instruction::Store;
1733 case GetElementPtrOp : return Instruction::GetElementPtr;
1734 }
1735}
1736
1737static inline Instruction::OtherOps
Reid Spencerbb1fd572007-03-21 17:15:50 +00001738getOtherOp(OtherOps op, const Signedness &Sign) {
Reid Spencer950bf602007-01-26 08:19:09 +00001739 switch (op) {
1740 default : assert(0 && "Invalid OldOtherOps");
1741 case PHIOp : return Instruction::PHI;
1742 case CallOp : return Instruction::Call;
Reid Spencer950bf602007-01-26 08:19:09 +00001743 case SelectOp : return Instruction::Select;
1744 case UserOp1 : return Instruction::UserOp1;
1745 case UserOp2 : return Instruction::UserOp2;
1746 case VAArg : return Instruction::VAArg;
1747 case ExtractElementOp : return Instruction::ExtractElement;
1748 case InsertElementOp : return Instruction::InsertElement;
1749 case ShuffleVectorOp : return Instruction::ShuffleVector;
1750 case ICmpOp : return Instruction::ICmp;
1751 case FCmpOp : return Instruction::FCmp;
Reid Spencer950bf602007-01-26 08:19:09 +00001752 };
1753}
1754
1755static inline Value*
Reid Spencerbb1fd572007-03-21 17:15:50 +00001756getCast(CastOps op, Value *Src, const Signedness &SrcSign, const Type *DstTy,
1757 const Signedness &DstSign, bool ForceInstruction = false) {
Reid Spencer950bf602007-01-26 08:19:09 +00001758 Instruction::CastOps Opcode;
1759 const Type* SrcTy = Src->getType();
1760 if (op == CastOp) {
1761 if (SrcTy->isFloatingPoint() && isa<PointerType>(DstTy)) {
1762 // fp -> ptr cast is no longer supported but we must upgrade this
1763 // by doing a double cast: fp -> int -> ptr
1764 SrcTy = Type::Int64Ty;
1765 Opcode = Instruction::IntToPtr;
1766 if (isa<Constant>(Src)) {
1767 Src = ConstantExpr::getCast(Instruction::FPToUI,
1768 cast<Constant>(Src), SrcTy);
1769 } else {
1770 std::string NewName(makeNameUnique(Src->getName()));
1771 Src = new FPToUIInst(Src, SrcTy, NewName, CurBB);
1772 }
1773 } else if (isa<IntegerType>(DstTy) &&
1774 cast<IntegerType>(DstTy)->getBitWidth() == 1) {
1775 // cast type %x to bool was previously defined as setne type %x, null
1776 // The cast semantic is now to truncate, not compare so we must retain
1777 // the original intent by replacing the cast with a setne
1778 Constant* Null = Constant::getNullValue(SrcTy);
1779 Instruction::OtherOps Opcode = Instruction::ICmp;
1780 unsigned short predicate = ICmpInst::ICMP_NE;
1781 if (SrcTy->isFloatingPoint()) {
1782 Opcode = Instruction::FCmp;
1783 predicate = FCmpInst::FCMP_ONE;
1784 } else if (!SrcTy->isInteger() && !isa<PointerType>(SrcTy)) {
1785 error("Invalid cast to bool");
1786 }
1787 if (isa<Constant>(Src) && !ForceInstruction)
1788 return ConstantExpr::getCompare(predicate, cast<Constant>(Src), Null);
1789 else
1790 return CmpInst::create(Opcode, predicate, Src, Null);
1791 }
1792 // Determine the opcode to use by calling CastInst::getCastOpcode
1793 Opcode =
Reid Spencerbb1fd572007-03-21 17:15:50 +00001794 CastInst::getCastOpcode(Src, SrcSign.isSigned(), DstTy,
1795 DstSign.isSigned());
Reid Spencer950bf602007-01-26 08:19:09 +00001796
1797 } else switch (op) {
1798 default: assert(0 && "Invalid cast token");
1799 case TruncOp: Opcode = Instruction::Trunc; break;
1800 case ZExtOp: Opcode = Instruction::ZExt; break;
1801 case SExtOp: Opcode = Instruction::SExt; break;
1802 case FPTruncOp: Opcode = Instruction::FPTrunc; break;
1803 case FPExtOp: Opcode = Instruction::FPExt; break;
1804 case FPToUIOp: Opcode = Instruction::FPToUI; break;
1805 case FPToSIOp: Opcode = Instruction::FPToSI; break;
1806 case UIToFPOp: Opcode = Instruction::UIToFP; break;
1807 case SIToFPOp: Opcode = Instruction::SIToFP; break;
1808 case PtrToIntOp: Opcode = Instruction::PtrToInt; break;
1809 case IntToPtrOp: Opcode = Instruction::IntToPtr; break;
1810 case BitCastOp: Opcode = Instruction::BitCast; break;
1811 }
1812
1813 if (isa<Constant>(Src) && !ForceInstruction)
1814 return ConstantExpr::getCast(Opcode, cast<Constant>(Src), DstTy);
1815 return CastInst::create(Opcode, Src, DstTy);
1816}
1817
1818static Instruction *
1819upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
1820 std::vector<Value*>& Args) {
1821
1822 std::string Name = ID.Type == ValID::NameVal ? ID.Name : "";
Reid Spencer7eea8ff2007-05-18 05:48:07 +00001823 if (Name.length() <= 5 || Name[0] != 'l' || Name[1] != 'l' ||
1824 Name[2] != 'v' || Name[3] != 'm' || Name[4] != '.')
1825 return 0;
1826
Reid Spencer41b213e2007-04-02 01:14:00 +00001827 switch (Name[5]) {
1828 case 'i':
1829 if (Name == "llvm.isunordered.f32" || Name == "llvm.isunordered.f64") {
1830 if (Args.size() != 2)
1831 error("Invalid prototype for " + Name);
1832 return new FCmpInst(FCmpInst::FCMP_UNO, Args[0], Args[1]);
1833 }
1834 break;
1835 case 'b':
1836 if (Name.length() == 14 && !memcmp(&Name[5], "bswap.i", 7)) {
1837 const Type* ArgTy = Args[0]->getType();
1838 Name += ".i" + utostr(cast<IntegerType>(ArgTy)->getBitWidth());
1839 Function *F = cast<Function>(
1840 CurModule.CurrentModule->getOrInsertFunction(Name, RetTy, ArgTy,
1841 (void*)0));
1842 return new CallInst(F, Args[0]);
1843 }
1844 break;
Reid Spencer8166a6c2007-04-02 02:08:35 +00001845 case 'c':
1846 if ((Name.length() <= 14 && !memcmp(&Name[5], "ctpop.i", 7)) ||
1847 (Name.length() <= 13 && !memcmp(&Name[5], "ctlz.i", 6)) ||
1848 (Name.length() <= 13 && !memcmp(&Name[5], "cttz.i", 6))) {
1849 // These intrinsics changed their result type.
1850 const Type* ArgTy = Args[0]->getType();
1851 Function *OldF = CurModule.CurrentModule->getFunction(Name);
1852 if (OldF)
1853 OldF->setName("upgrd.rm." + Name);
1854
1855 Function *NewF = cast<Function>(
1856 CurModule.CurrentModule->getOrInsertFunction(Name, Type::Int32Ty,
1857 ArgTy, (void*)0));
1858
1859 Instruction *Call = new CallInst(NewF, Args[0], "", CurBB);
1860 return CastInst::createIntegerCast(Call, RetTy, false);
1861 }
1862 break;
1863
Reid Spencer41b213e2007-04-02 01:14:00 +00001864 case 'v' : {
1865 const Type* PtrTy = PointerType::get(Type::Int8Ty);
1866 std::vector<const Type*> Params;
1867 if (Name == "llvm.va_start" || Name == "llvm.va_end") {
1868 if (Args.size() != 1)
1869 error("Invalid prototype for " + Name + " prototype");
1870 Params.push_back(PtrTy);
1871 const FunctionType *FTy =
1872 FunctionType::get(Type::VoidTy, Params, false);
1873 const PointerType *PFTy = PointerType::get(FTy);
1874 Value* Func = getVal(PFTy, ID);
1875 Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
1876 return new CallInst(Func, &Args[0], Args.size());
1877 } else if (Name == "llvm.va_copy") {
1878 if (Args.size() != 2)
1879 error("Invalid prototype for " + Name + " prototype");
1880 Params.push_back(PtrTy);
1881 Params.push_back(PtrTy);
1882 const FunctionType *FTy =
1883 FunctionType::get(Type::VoidTy, Params, false);
1884 const PointerType *PFTy = PointerType::get(FTy);
1885 Value* Func = getVal(PFTy, ID);
1886 std::string InstName0(makeNameUnique("va0"));
1887 std::string InstName1(makeNameUnique("va1"));
1888 Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
1889 Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
1890 return new CallInst(Func, &Args[0], Args.size());
1891 }
Reid Spencer950bf602007-01-26 08:19:09 +00001892 }
1893 }
1894 return 0;
1895}
1896
Reid Spencerff0e4482007-04-16 00:40:57 +00001897const Type* upgradeGEPCEIndices(const Type* PTy,
1898 std::vector<ValueInfo> *Indices,
1899 std::vector<Constant*> &Result) {
1900 const Type *Ty = PTy;
1901 Result.clear();
1902 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1903 Constant *Index = cast<Constant>((*Indices)[i].V);
1904
1905 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1906 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1907 // struct indices to i32 struct indices with ZExt for compatibility.
1908 if (CI->getBitWidth() < 32)
1909 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1910 }
1911
1912 if (isa<SequentialType>(Ty)) {
1913 // Make sure that unsigned SequentialType indices are zext'd to
1914 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1915 // all indices for SequentialType elements. We must retain the same
1916 // semantic (zext) for unsigned types.
1917 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
1918 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
1919 Index = ConstantExpr::getCast(Instruction::ZExt, Index,Type::Int64Ty);
1920 }
1921 }
1922 }
1923 Result.push_back(Index);
1924 Ty = GetElementPtrInst::getIndexedType(PTy, (Value**)&Result[0],
1925 Result.size(),true);
1926 if (!Ty)
1927 error("Index list invalid for constant getelementptr");
1928 }
1929 return Ty;
1930}
1931
1932const Type* upgradeGEPInstIndices(const Type* PTy,
1933 std::vector<ValueInfo> *Indices,
1934 std::vector<Value*> &Result) {
1935 const Type *Ty = PTy;
1936 Result.clear();
1937 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1938 Value *Index = (*Indices)[i].V;
1939
1940 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1941 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1942 // struct indices to i32 struct indices with ZExt for compatibility.
1943 if (CI->getBitWidth() < 32)
1944 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1945 }
1946
1947
1948 if (isa<StructType>(Ty)) { // Only change struct indices
1949 if (!isa<Constant>(Index)) {
1950 error("Invalid non-constant structure index");
1951 return 0;
1952 }
Reid Spencer950bf602007-01-26 08:19:09 +00001953 } else {
1954 // Make sure that unsigned SequentialType indices are zext'd to
1955 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1956 // all indices for SequentialType elements. We must retain the same
1957 // semantic (zext) for unsigned types.
Reid Spencerff0e4482007-04-16 00:40:57 +00001958 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00001959 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
Reid Spencerff0e4482007-04-16 00:40:57 +00001960 if (isa<Constant>(Index))
Reid Spencer950bf602007-01-26 08:19:09 +00001961 Index = ConstantExpr::getCast(Instruction::ZExt,
1962 cast<Constant>(Index), Type::Int64Ty);
1963 else
1964 Index = CastInst::create(Instruction::ZExt, Index, Type::Int64Ty,
Reid Spencer832254e2007-02-02 02:16:23 +00001965 makeNameUnique("gep"), CurBB);
Reid Spencer38f682b2007-01-26 20:31:18 +00001966 }
Reid Spencerff0e4482007-04-16 00:40:57 +00001967 }
Reid Spencer950bf602007-01-26 08:19:09 +00001968 }
Reid Spencerff0e4482007-04-16 00:40:57 +00001969 Result.push_back(Index);
1970 Ty = GetElementPtrInst::getIndexedType(PTy, &Result[0], Result.size(),true);
1971 if (!Ty)
Reid Spencer950bf602007-01-26 08:19:09 +00001972 error("Index list invalid for constant getelementptr");
Reid Spencerff0e4482007-04-16 00:40:57 +00001973 }
1974 return Ty;
Reid Spencer950bf602007-01-26 08:19:09 +00001975}
1976
Reid Spencerb7046c72007-01-29 05:41:34 +00001977unsigned upgradeCallingConv(unsigned CC) {
1978 switch (CC) {
1979 case OldCallingConv::C : return CallingConv::C;
1980 case OldCallingConv::CSRet : return CallingConv::C;
1981 case OldCallingConv::Fast : return CallingConv::Fast;
1982 case OldCallingConv::Cold : return CallingConv::Cold;
1983 case OldCallingConv::X86_StdCall : return CallingConv::X86_StdCall;
1984 case OldCallingConv::X86_FastCall: return CallingConv::X86_FastCall;
1985 default:
1986 return CC;
1987 }
1988}
1989
Reid Spencer950bf602007-01-26 08:19:09 +00001990Module* UpgradeAssembly(const std::string &infile, std::istream& in,
1991 bool debug, bool addAttrs)
Reid Spencere7c3c602006-11-30 06:36:44 +00001992{
1993 Upgradelineno = 1;
1994 CurFilename = infile;
Reid Spencer96839be2006-11-30 16:50:26 +00001995 LexInput = &in;
Reid Spencere77e35e2006-12-01 20:26:20 +00001996 yydebug = debug;
Reid Spencer71d2ec92006-12-31 06:02:26 +00001997 AddAttributes = addAttrs;
Reid Spencer950bf602007-01-26 08:19:09 +00001998 ObsoleteVarArgs = false;
1999 NewVarArgs = false;
Reid Spencere7c3c602006-11-30 06:36:44 +00002000
Reid Spencer950bf602007-01-26 08:19:09 +00002001 CurModule.CurrentModule = new Module(CurFilename);
2002
2003 // Check to make sure the parser succeeded
Reid Spencere7c3c602006-11-30 06:36:44 +00002004 if (yyparse()) {
Reid Spencer950bf602007-01-26 08:19:09 +00002005 if (ParserResult)
2006 delete ParserResult;
Reid Spencer30d0c582007-01-15 00:26:18 +00002007 std::cerr << "llvm-upgrade: parse failed.\n";
Reid Spencer30d0c582007-01-15 00:26:18 +00002008 return 0;
2009 }
2010
Reid Spencer950bf602007-01-26 08:19:09 +00002011 // Check to make sure that parsing produced a result
2012 if (!ParserResult) {
2013 std::cerr << "llvm-upgrade: no parse result.\n";
2014 return 0;
Reid Spencer30d0c582007-01-15 00:26:18 +00002015 }
2016
Reid Spencer950bf602007-01-26 08:19:09 +00002017 // Reset ParserResult variable while saving its value for the result.
2018 Module *Result = ParserResult;
2019 ParserResult = 0;
Reid Spencer30d0c582007-01-15 00:26:18 +00002020
Reid Spencer950bf602007-01-26 08:19:09 +00002021 //Not all functions use vaarg, so make a second check for ObsoleteVarArgs
Reid Spencer30d0c582007-01-15 00:26:18 +00002022 {
Reid Spencer950bf602007-01-26 08:19:09 +00002023 Function* F;
Reid Spencer688b0492007-02-05 21:19:13 +00002024 if ((F = Result->getFunction("llvm.va_start"))
Reid Spencer950bf602007-01-26 08:19:09 +00002025 && F->getFunctionType()->getNumParams() == 0)
2026 ObsoleteVarArgs = true;
Reid Spencer688b0492007-02-05 21:19:13 +00002027 if((F = Result->getFunction("llvm.va_copy"))
Reid Spencer950bf602007-01-26 08:19:09 +00002028 && F->getFunctionType()->getNumParams() == 1)
2029 ObsoleteVarArgs = true;
Reid Spencer280d8012006-12-01 23:40:53 +00002030 }
Reid Spencer319a7302007-01-05 17:20:02 +00002031
Reid Spencer950bf602007-01-26 08:19:09 +00002032 if (ObsoleteVarArgs && NewVarArgs) {
2033 error("This file is corrupt: it uses both new and old style varargs");
2034 return 0;
Reid Spencer319a7302007-01-05 17:20:02 +00002035 }
Reid Spencer319a7302007-01-05 17:20:02 +00002036
Reid Spencer950bf602007-01-26 08:19:09 +00002037 if(ObsoleteVarArgs) {
Reid Spencer688b0492007-02-05 21:19:13 +00002038 if(Function* F = Result->getFunction("llvm.va_start")) {
Reid Spencer950bf602007-01-26 08:19:09 +00002039 if (F->arg_size() != 0) {
2040 error("Obsolete va_start takes 0 argument");
Reid Spencer319a7302007-01-05 17:20:02 +00002041 return 0;
2042 }
Reid Spencer950bf602007-01-26 08:19:09 +00002043
2044 //foo = va_start()
2045 // ->
2046 //bar = alloca typeof(foo)
2047 //va_start(bar)
2048 //foo = load bar
Reid Spencer319a7302007-01-05 17:20:02 +00002049
Reid Spencer950bf602007-01-26 08:19:09 +00002050 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2051 const Type* ArgTy = F->getFunctionType()->getReturnType();
2052 const Type* ArgTyPtr = PointerType::get(ArgTy);
2053 Function* NF = cast<Function>(Result->getOrInsertFunction(
2054 "llvm.va_start", RetTy, ArgTyPtr, (Type *)0));
2055
2056 while (!F->use_empty()) {
2057 CallInst* CI = cast<CallInst>(F->use_back());
2058 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vastart.fix.1", CI);
2059 new CallInst(NF, bar, "", CI);
2060 Value* foo = new LoadInst(bar, "vastart.fix.2", CI);
2061 CI->replaceAllUsesWith(foo);
2062 CI->getParent()->getInstList().erase(CI);
Reid Spencerf8383de2007-01-06 06:04:32 +00002063 }
Reid Spencer950bf602007-01-26 08:19:09 +00002064 Result->getFunctionList().erase(F);
Reid Spencerf8383de2007-01-06 06:04:32 +00002065 }
Reid Spencer950bf602007-01-26 08:19:09 +00002066
Reid Spencer688b0492007-02-05 21:19:13 +00002067 if(Function* F = Result->getFunction("llvm.va_end")) {
Reid Spencer950bf602007-01-26 08:19:09 +00002068 if(F->arg_size() != 1) {
2069 error("Obsolete va_end takes 1 argument");
2070 return 0;
Reid Spencerf8383de2007-01-06 06:04:32 +00002071 }
Reid Spencerf8383de2007-01-06 06:04:32 +00002072
Reid Spencer950bf602007-01-26 08:19:09 +00002073 //vaend foo
2074 // ->
2075 //bar = alloca 1 of typeof(foo)
2076 //vaend bar
2077 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2078 const Type* ArgTy = F->getFunctionType()->getParamType(0);
2079 const Type* ArgTyPtr = PointerType::get(ArgTy);
2080 Function* NF = cast<Function>(Result->getOrInsertFunction(
2081 "llvm.va_end", RetTy, ArgTyPtr, (Type *)0));
Reid Spencerf8383de2007-01-06 06:04:32 +00002082
Reid Spencer950bf602007-01-26 08:19:09 +00002083 while (!F->use_empty()) {
2084 CallInst* CI = cast<CallInst>(F->use_back());
2085 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vaend.fix.1", CI);
2086 new StoreInst(CI->getOperand(1), bar, CI);
2087 new CallInst(NF, bar, "", CI);
2088 CI->getParent()->getInstList().erase(CI);
Reid Spencere77e35e2006-12-01 20:26:20 +00002089 }
Reid Spencer950bf602007-01-26 08:19:09 +00002090 Result->getFunctionList().erase(F);
Reid Spencere77e35e2006-12-01 20:26:20 +00002091 }
Reid Spencer950bf602007-01-26 08:19:09 +00002092
Reid Spencer688b0492007-02-05 21:19:13 +00002093 if(Function* F = Result->getFunction("llvm.va_copy")) {
Reid Spencer950bf602007-01-26 08:19:09 +00002094 if(F->arg_size() != 1) {
2095 error("Obsolete va_copy takes 1 argument");
2096 return 0;
Reid Spencere77e35e2006-12-01 20:26:20 +00002097 }
Reid Spencer950bf602007-01-26 08:19:09 +00002098 //foo = vacopy(bar)
2099 // ->
2100 //a = alloca 1 of typeof(foo)
2101 //b = alloca 1 of typeof(foo)
2102 //store bar -> b
2103 //vacopy(a, b)
2104 //foo = load a
2105
2106 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2107 const Type* ArgTy = F->getFunctionType()->getReturnType();
2108 const Type* ArgTyPtr = PointerType::get(ArgTy);
2109 Function* NF = cast<Function>(Result->getOrInsertFunction(
2110 "llvm.va_copy", RetTy, ArgTyPtr, ArgTyPtr, (Type *)0));
Reid Spencere77e35e2006-12-01 20:26:20 +00002111
Reid Spencer950bf602007-01-26 08:19:09 +00002112 while (!F->use_empty()) {
2113 CallInst* CI = cast<CallInst>(F->use_back());
2114 AllocaInst* a = new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI);
2115 AllocaInst* b = new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI);
2116 new StoreInst(CI->getOperand(1), b, CI);
2117 new CallInst(NF, a, b, "", CI);
2118 Value* foo = new LoadInst(a, "vacopy.fix.3", CI);
2119 CI->replaceAllUsesWith(foo);
2120 CI->getParent()->getInstList().erase(CI);
2121 }
2122 Result->getFunctionList().erase(F);
Reid Spencer319a7302007-01-05 17:20:02 +00002123 }
2124 }
2125
Reid Spencer52402b02007-01-02 05:45:11 +00002126 return Result;
2127}
2128
Reid Spencer950bf602007-01-26 08:19:09 +00002129} // end llvm namespace
Reid Spencer319a7302007-01-05 17:20:02 +00002130
Reid Spencer950bf602007-01-26 08:19:09 +00002131using namespace llvm;
Reid Spencer30d0c582007-01-15 00:26:18 +00002132
2133
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002134
2135/* Enabling traces. */
2136#ifndef YYDEBUG
2137# define YYDEBUG 0
2138#endif
2139
2140/* Enabling verbose error messages. */
2141#ifdef YYERROR_VERBOSE
2142# undef YYERROR_VERBOSE
2143# define YYERROR_VERBOSE 1
2144#else
2145# define YYERROR_VERBOSE 0
2146#endif
2147
2148/* Enabling the token table. */
2149#ifndef YYTOKEN_TABLE
2150# define YYTOKEN_TABLE 0
2151#endif
2152
2153#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
Reid Spencer7eea8ff2007-05-18 05:48:07 +00002154#line 1775 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002155typedef union YYSTYPE {
Reid Spencer950bf602007-01-26 08:19:09 +00002156 llvm::Module *ModuleVal;
2157 llvm::Function *FunctionVal;
2158 std::pair<llvm::PATypeInfo, char*> *ArgVal;
2159 llvm::BasicBlock *BasicBlockVal;
Reid Spencerbb1fd572007-03-21 17:15:50 +00002160 llvm::TermInstInfo TermInstVal;
Reid Spencer950bf602007-01-26 08:19:09 +00002161 llvm::InstrInfo InstVal;
2162 llvm::ConstInfo ConstVal;
2163 llvm::ValueInfo ValueVal;
2164 llvm::PATypeInfo TypeVal;
2165 llvm::TypeInfo PrimType;
2166 llvm::PHIListInfo PHIList;
2167 std::list<llvm::PATypeInfo> *TypeList;
2168 std::vector<llvm::ValueInfo> *ValueList;
2169 std::vector<llvm::ConstInfo> *ConstVector;
2170
2171
2172 std::vector<std::pair<llvm::PATypeInfo,char*> > *ArgList;
2173 // Represent the RHS of PHI node
2174 std::vector<std::pair<llvm::Constant*, llvm::BasicBlock*> > *JumpTable;
2175
2176 llvm::GlobalValue::LinkageTypes Linkage;
2177 int64_t SInt64Val;
2178 uint64_t UInt64Val;
2179 int SIntVal;
2180 unsigned UIntVal;
2181 double FPVal;
2182 bool BoolVal;
2183
2184 char *StrVal; // This memory is strdup'd!
2185 llvm::ValID ValIDVal; // strdup'd memory maybe!
2186
2187 llvm::BinaryOps BinaryOpVal;
2188 llvm::TermOps TermOpVal;
2189 llvm::MemoryOps MemOpVal;
2190 llvm::OtherOps OtherOpVal;
2191 llvm::CastOps CastOpVal;
2192 llvm::ICmpInst::Predicate IPred;
2193 llvm::FCmpInst::Predicate FPred;
2194 llvm::Module::Endianness Endianness;
Chris Lattnercf3d0612007-02-13 06:04:17 +00002195} YYSTYPE;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002196/* Line 196 of yacc.c. */
Reid Spencer7eea8ff2007-05-18 05:48:07 +00002197#line 2198 "UpgradeParser.tab.c"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002198# define yystype YYSTYPE /* obsolescent; will be withdrawn */
2199# define YYSTYPE_IS_DECLARED 1
2200# define YYSTYPE_IS_TRIVIAL 1
Reid Spencere7c3c602006-11-30 06:36:44 +00002201#endif
2202
Reid Spencer950bf602007-01-26 08:19:09 +00002203
Reid Spencere7c3c602006-11-30 06:36:44 +00002204
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002205/* Copy the second part of user declarations. */
Reid Spencere7c3c602006-11-30 06:36:44 +00002206
2207
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002208/* Line 219 of yacc.c. */
Reid Spencer7eea8ff2007-05-18 05:48:07 +00002209#line 2210 "UpgradeParser.tab.c"
Reid Spencer950bf602007-01-26 08:19:09 +00002210
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002211#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
2212# define YYSIZE_T __SIZE_TYPE__
2213#endif
2214#if ! defined (YYSIZE_T) && defined (size_t)
2215# define YYSIZE_T size_t
2216#endif
2217#if ! defined (YYSIZE_T) && (defined (__STDC__) || defined (__cplusplus))
2218# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
2219# define YYSIZE_T size_t
2220#endif
2221#if ! defined (YYSIZE_T)
2222# define YYSIZE_T unsigned int
2223#endif
Chris Lattnercf3d0612007-02-13 06:04:17 +00002224
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002225#ifndef YY_
2226# if YYENABLE_NLS
2227# if ENABLE_NLS
2228# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
2229# define YY_(msgid) dgettext ("bison-runtime", msgid)
2230# endif
2231# endif
2232# ifndef YY_
2233# define YY_(msgid) msgid
2234# endif
2235#endif
2236
2237#if ! defined (yyoverflow) || YYERROR_VERBOSE
2238
2239/* The parser invokes alloca or malloc; define the necessary symbols. */
2240
2241# ifdef YYSTACK_USE_ALLOCA
2242# if YYSTACK_USE_ALLOCA
2243# ifdef __GNUC__
2244# define YYSTACK_ALLOC __builtin_alloca
2245# else
2246# define YYSTACK_ALLOC alloca
2247# if defined (__STDC__) || defined (__cplusplus)
2248# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
2249# define YYINCLUDED_STDLIB_H
2250# endif
2251# endif
2252# endif
2253# endif
2254
2255# ifdef YYSTACK_ALLOC
2256 /* Pacify GCC's `empty if-body' warning. */
2257# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
2258# ifndef YYSTACK_ALLOC_MAXIMUM
2259 /* The OS might guarantee only one guard page at the bottom of the stack,
2260 and a page size can be as small as 4096 bytes. So we cannot safely
2261 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
2262 to allow for a few compiler-allocated temporary stack slots. */
2263# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2005 */
2264# endif
2265# else
2266# define YYSTACK_ALLOC YYMALLOC
2267# define YYSTACK_FREE YYFREE
2268# ifndef YYSTACK_ALLOC_MAXIMUM
2269# define YYSTACK_ALLOC_MAXIMUM ((YYSIZE_T) -1)
2270# endif
2271# ifdef __cplusplus
2272extern "C" {
2273# endif
2274# ifndef YYMALLOC
2275# define YYMALLOC malloc
2276# if (! defined (malloc) && ! defined (YYINCLUDED_STDLIB_H) \
2277 && (defined (__STDC__) || defined (__cplusplus)))
2278void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
2279# endif
2280# endif
2281# ifndef YYFREE
2282# define YYFREE free
2283# if (! defined (free) && ! defined (YYINCLUDED_STDLIB_H) \
2284 && (defined (__STDC__) || defined (__cplusplus)))
2285void free (void *); /* INFRINGES ON USER NAME SPACE */
2286# endif
2287# endif
2288# ifdef __cplusplus
2289}
2290# endif
2291# endif
2292#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
2293
2294
2295#if (! defined (yyoverflow) \
2296 && (! defined (__cplusplus) \
2297 || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
2298
2299/* A type that is properly aligned for any stack member. */
2300union yyalloc
2301{
2302 short int yyss;
2303 YYSTYPE yyvs;
2304 };
2305
2306/* The size of the maximum gap between one aligned stack and the next. */
2307# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
2308
2309/* The size of an array large to enough to hold all stacks, each with
2310 N elements. */
2311# define YYSTACK_BYTES(N) \
2312 ((N) * (sizeof (short int) + sizeof (YYSTYPE)) \
2313 + YYSTACK_GAP_MAXIMUM)
2314
2315/* Copy COUNT objects from FROM to TO. The source and destination do
2316 not overlap. */
2317# ifndef YYCOPY
2318# if defined (__GNUC__) && 1 < __GNUC__
2319# define YYCOPY(To, From, Count) \
2320 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
2321# else
2322# define YYCOPY(To, From, Count) \
2323 do \
2324 { \
2325 YYSIZE_T yyi; \
2326 for (yyi = 0; yyi < (Count); yyi++) \
2327 (To)[yyi] = (From)[yyi]; \
2328 } \
2329 while (0)
2330# endif
2331# endif
2332
2333/* Relocate STACK from its old location to the new one. The
2334 local variables YYSIZE and YYSTACKSIZE give the old and new number of
2335 elements in the stack, and YYPTR gives the new location of the
2336 stack. Advance YYPTR to a properly aligned location for the next
2337 stack. */
2338# define YYSTACK_RELOCATE(Stack) \
2339 do \
2340 { \
2341 YYSIZE_T yynewbytes; \
2342 YYCOPY (&yyptr->Stack, Stack, yysize); \
2343 Stack = &yyptr->Stack; \
2344 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
2345 yyptr += yynewbytes / sizeof (*yyptr); \
2346 } \
2347 while (0)
Chris Lattnercf3d0612007-02-13 06:04:17 +00002348
Reid Spencere7c3c602006-11-30 06:36:44 +00002349#endif
2350
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002351#if defined (__STDC__) || defined (__cplusplus)
2352 typedef signed char yysigned_char;
Reid Spencerb7046c72007-01-29 05:41:34 +00002353#else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002354 typedef short int yysigned_char;
Reid Spencerb7046c72007-01-29 05:41:34 +00002355#endif
2356
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002357/* YYFINAL -- State number of the termination state. */
2358#define YYFINAL 4
2359/* YYLAST -- Last index in YYTABLE. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002360#define YYLAST 1630
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002361
2362/* YYNTOKENS -- Number of terminals. */
2363#define YYNTOKENS 166
2364/* YYNNTS -- Number of nonterminals. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002365#define YYNNTS 81
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002366/* YYNRULES -- Number of rules. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002367#define YYNRULES 310
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002368/* YYNRULES -- Number of states. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002369#define YYNSTATES 606
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002370
2371/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
2372#define YYUNDEFTOK 2
2373#define YYMAXUTOK 406
2374
2375#define YYTRANSLATE(YYX) \
2376 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
2377
2378/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
2379static const unsigned char yytranslate[] =
2380{
2381 0, 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 155, 156, 164, 2, 153, 2, 2, 2, 2, 2,
2386 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2387 160, 152, 161, 2, 2, 2, 2, 2, 2, 2,
2388 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2389 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2390 2, 157, 154, 159, 2, 2, 2, 2, 2, 165,
2391 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2392 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2393 158, 2, 2, 162, 2, 163, 2, 2, 2, 2,
2394 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2395 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2396 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2397 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2398 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2399 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2400 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2401 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2402 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2403 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2404 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2405 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2406 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
2407 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
2408 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
2409 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
2410 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
2411 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
2412 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
2413 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
2414 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
2415 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
2416 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
2417 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
2418 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
2419 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
2420 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
2421 145, 146, 147, 148, 149, 150, 151
2422};
2423
2424#if YYDEBUG
2425/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
2426 YYRHS. */
2427static const unsigned short int yyprhs[] =
2428{
2429 0, 0, 3, 5, 7, 9, 11, 13, 15, 17,
2430 19, 21, 23, 25, 27, 29, 31, 33, 35, 37,
2431 39, 41, 43, 45, 47, 49, 51, 53, 55, 57,
2432 59, 61, 63, 65, 67, 69, 71, 73, 75, 77,
2433 79, 81, 83, 85, 87, 89, 91, 93, 95, 97,
2434 99, 101, 103, 105, 107, 109, 111, 113, 115, 117,
2435 119, 121, 123, 125, 127, 129, 131, 133, 135, 137,
2436 139, 141, 143, 145, 147, 149, 151, 153, 155, 157,
2437 159, 161, 164, 165, 167, 169, 171, 173, 175, 177,
2438 179, 180, 181, 183, 185, 187, 189, 191, 193, 196,
2439 197, 200, 201, 205, 208, 209, 211, 212, 216, 218,
2440 221, 223, 225, 227, 229, 231, 233, 235, 237, 239,
2441 241, 243, 245, 247, 249, 251, 253, 255, 257, 259,
2442 261, 264, 269, 275, 281, 285, 288, 294, 299, 302,
2443 304, 308, 310, 314, 316, 317, 322, 326, 330, 335,
2444 340, 344, 351, 357, 360, 363, 366, 369, 372, 375,
2445 378, 381, 384, 387, 394, 400, 409, 416, 423, 430,
2446 438, 446, 453, 460, 469, 478, 482, 484, 486, 488,
2447 490, 493, 496, 501, 504, 506, 511, 514, 519, 520,
2448 528, 529, 537, 538, 546, 547, 555, 559, 564, 565,
2449 567, 569, 571, 575, 579, 583, 587, 591, 595, 597,
2450 598, 600, 602, 604, 605, 608, 612, 614, 616, 620,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002451 622, 623, 632, 634, 636, 637, 642, 644, 646, 649,
2452 650, 652, 654, 655, 656, 662, 663, 665, 667, 669,
2453 671, 673, 675, 677, 679, 681, 685, 687, 693, 695,
2454 697, 699, 701, 704, 707, 710, 714, 717, 718, 720,
2455 722, 724, 727, 730, 734, 744, 754, 763, 777, 779,
2456 781, 788, 794, 797, 804, 812, 814, 818, 820, 821,
2457 824, 826, 832, 838, 844, 851, 858, 861, 866, 871,
2458 878, 883, 888, 893, 898, 905, 912, 915, 923, 925,
2459 928, 929, 931, 932, 936, 943, 947, 954, 957, 962,
2460 969
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002461};
2462
2463/* YYRHS -- A `-1'-separated list of the rules' RHS. */
2464static const short int yyrhs[] =
2465{
2466 200, 0, -1, 5, -1, 6, -1, 3, -1, 4,
2467 -1, 79, -1, 80, -1, 81, -1, 82, -1, 83,
2468 -1, 84, -1, 85, -1, 86, -1, 87, -1, 88,
2469 -1, 89, -1, 90, -1, 91, -1, 92, -1, 97,
2470 -1, 98, -1, 99, -1, 100, -1, 101, -1, 102,
2471 -1, 119, -1, 120, -1, 121, -1, 122, -1, 123,
2472 -1, 124, -1, 125, -1, 126, -1, 127, -1, 128,
2473 -1, 129, -1, 130, -1, 131, -1, 132, -1, 133,
2474 -1, 134, -1, 135, -1, 136, -1, 137, -1, 138,
2475 -1, 125, -1, 126, -1, 127, -1, 128, -1, 27,
2476 -1, 28, -1, 93, -1, 94, -1, 95, -1, 96,
2477 -1, 140, -1, 141, -1, 142, -1, 143, -1, 144,
2478 -1, 145, -1, 146, -1, 147, -1, 148, -1, 149,
2479 -1, 150, -1, 151, -1, 139, -1, 16, -1, 14,
2480 -1, 12, -1, 10, -1, 17, -1, 15, -1, 13,
2481 -1, 11, -1, 176, -1, 177, -1, 18, -1, 19,
2482 -1, 212, 152, -1, -1, 41, -1, 42, -1, 43,
2483 -1, 44, -1, 45, -1, 46, -1, 47, -1, -1,
2484 -1, 65, -1, 66, -1, 67, -1, 68, -1, 69,
2485 -1, 70, -1, 64, 4, -1, -1, 57, 4, -1,
2486 -1, 153, 57, 4, -1, 34, 24, -1, -1, 185,
2487 -1, -1, 153, 188, 187, -1, 185, -1, 57, 4,
2488 -1, 191, -1, 8, -1, 193, -1, 8, -1, 193,
2489 -1, 9, -1, 10, -1, 11, -1, 12, -1, 13,
2490 -1, 14, -1, 15, -1, 16, -1, 17, -1, 18,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002491 -1, 19, -1, 21, -1, 192, -1, 48, -1, 229,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002492 -1, 154, 4, -1, 190, 155, 195, 156, -1, 157,
2493 4, 158, 193, 159, -1, 160, 4, 158, 193, 161,
2494 -1, 162, 194, 163, -1, 162, 163, -1, 160, 162,
2495 194, 163, 161, -1, 160, 162, 163, 161, -1, 193,
2496 164, -1, 193, -1, 194, 153, 193, -1, 194, -1,
2497 194, 153, 37, -1, 37, -1, -1, 191, 157, 198,
2498 159, -1, 191, 157, 159, -1, 191, 165, 24, -1,
2499 191, 160, 198, 161, -1, 191, 162, 198, 163, -1,
2500 191, 162, 163, -1, 191, 160, 162, 198, 163, 161,
2501 -1, 191, 160, 162, 163, 161, -1, 191, 38, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002502 191, 39, -1, 191, 229, -1, 191, 197, -1, 191,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002503 26, -1, 176, 168, -1, 177, 4, -1, 9, 27,
2504 -1, 9, 28, -1, 179, 7, -1, 175, 155, 196,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002505 36, 191, 156, -1, 110, 155, 196, 244, 156, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002506 112, 155, 196, 153, 196, 153, 196, 156, -1, 169,
2507 155, 196, 153, 196, 156, -1, 170, 155, 196, 153,
2508 196, 156, -1, 171, 155, 196, 153, 196, 156, -1,
2509 103, 172, 155, 196, 153, 196, 156, -1, 104, 173,
2510 155, 196, 153, 196, 156, -1, 174, 155, 196, 153,
2511 196, 156, -1, 114, 155, 196, 153, 196, 156, -1,
2512 115, 155, 196, 153, 196, 153, 196, 156, -1, 116,
2513 155, 196, 153, 196, 153, 196, 156, -1, 198, 153,
2514 196, -1, 196, -1, 32, -1, 33, -1, 201, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002515 201, 222, -1, 201, 224, -1, 201, 62, 61, 207,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002516 -1, 201, 25, -1, 202, -1, 202, 180, 20, 189,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002517 -1, 202, 224, -1, 202, 62, 61, 207, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002518 202, 180, 181, 199, 196, 203, 187, -1, -1, 202,
2519 180, 50, 199, 191, 204, 187, -1, -1, 202, 180,
2520 45, 199, 191, 205, 187, -1, -1, 202, 180, 47,
2521 199, 191, 206, 187, -1, 202, 51, 209, -1, 202,
2522 58, 152, 210, -1, -1, 24, -1, 56, -1, 55,
2523 -1, 53, 152, 208, -1, 54, 152, 4, -1, 52,
2524 152, 24, -1, 71, 152, 24, -1, 157, 211, 159,
2525 -1, 211, 153, 24, -1, 24, -1, -1, 22, -1,
2526 24, -1, 212, -1, -1, 191, 213, -1, 215, 153,
2527 214, -1, 214, -1, 215, -1, 215, 153, 37, -1,
2528 37, -1, -1, 182, 189, 212, 155, 216, 156, 186,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002529 183, -1, 29, -1, 162, -1, -1, 181, 220, 217,
2530 218, -1, 30, -1, 163, -1, 232, 221, -1, -1,
2531 45, -1, 47, -1, -1, -1, 31, 225, 223, 226,
2532 217, -1, -1, 63, -1, 3, -1, 4, -1, 7,
2533 -1, 27, -1, 28, -1, 38, -1, 39, -1, 26,
2534 -1, 160, 198, 161, -1, 197, -1, 61, 227, 24,
2535 153, 24, -1, 167, -1, 212, -1, 229, -1, 228,
2536 -1, 191, 230, -1, 232, 233, -1, 219, 233, -1,
2537 234, 180, 236, -1, 234, 238, -1, -1, 23, -1,
2538 77, -1, 78, -1, 72, 231, -1, 72, 8, -1,
2539 73, 21, 230, -1, 73, 9, 230, 153, 21, 230,
2540 153, 21, 230, -1, 74, 178, 230, 153, 21, 230,
2541 157, 237, 159, -1, 74, 178, 230, 153, 21, 230,
2542 157, 159, -1, 75, 182, 189, 230, 155, 241, 156,
2543 36, 21, 230, 235, 21, 230, -1, 235, -1, 76,
2544 -1, 237, 178, 228, 153, 21, 230, -1, 178, 228,
2545 153, 21, 230, -1, 180, 243, -1, 191, 157, 230,
2546 153, 230, 159, -1, 239, 153, 157, 230, 153, 230,
2547 159, -1, 231, -1, 240, 153, 231, -1, 240, -1,
2548 -1, 60, 59, -1, 59, -1, 169, 191, 230, 153,
2549 230, -1, 170, 191, 230, 153, 230, -1, 171, 191,
2550 230, 153, 230, -1, 103, 172, 191, 230, 153, 230,
2551 -1, 104, 173, 191, 230, 153, 230, -1, 49, 231,
2552 -1, 174, 231, 153, 231, -1, 175, 231, 36, 191,
2553 -1, 112, 231, 153, 231, 153, 231, -1, 113, 231,
2554 153, 191, -1, 117, 231, 153, 191, -1, 118, 231,
2555 153, 191, -1, 114, 231, 153, 231, -1, 115, 231,
2556 153, 231, 153, 231, -1, 116, 231, 153, 231, 153,
2557 231, -1, 111, 239, -1, 242, 182, 189, 230, 155,
2558 241, 156, -1, 246, -1, 153, 240, -1, -1, 35,
2559 -1, -1, 105, 191, 184, -1, 105, 191, 153, 15,
2560 230, 184, -1, 106, 191, 184, -1, 106, 191, 153,
2561 15, 230, 184, -1, 107, 231, -1, 245, 108, 191,
2562 230, -1, 245, 109, 231, 153, 191, 230, -1, 110,
2563 191, 230, 244, -1
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002564};
2565
2566/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
2567static const unsigned short int yyrline[] =
2568{
Reid Spencer7eea8ff2007-05-18 05:48:07 +00002569 0, 1915, 1915, 1916, 1924, 1925, 1935, 1935, 1935, 1935,
2570 1935, 1935, 1935, 1935, 1935, 1935, 1935, 1939, 1939, 1939,
2571 1943, 1943, 1943, 1943, 1943, 1943, 1947, 1947, 1948, 1948,
2572 1949, 1949, 1950, 1950, 1951, 1951, 1955, 1955, 1956, 1956,
2573 1957, 1957, 1958, 1958, 1959, 1959, 1960, 1960, 1961, 1961,
2574 1962, 1963, 1966, 1966, 1966, 1966, 1970, 1970, 1970, 1970,
2575 1970, 1970, 1970, 1971, 1971, 1971, 1971, 1971, 1971, 1977,
2576 1977, 1977, 1977, 1981, 1981, 1981, 1981, 1985, 1985, 1989,
2577 1989, 1994, 1997, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
2578 2009, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2030,
2579 2031, 2039, 2040, 2048, 2057, 2058, 2065, 2066, 2070, 2074,
2580 2090, 2091, 2098, 2099, 2106, 2114, 2114, 2114, 2114, 2114,
2581 2114, 2114, 2115, 2115, 2115, 2115, 2115, 2120, 2124, 2128,
2582 2133, 2142, 2169, 2175, 2188, 2199, 2203, 2216, 2220, 2234,
2583 2238, 2245, 2246, 2252, 2259, 2271, 2301, 2314, 2337, 2365,
2584 2387, 2398, 2420, 2431, 2440, 2445, 2504, 2511, 2519, 2526,
2585 2533, 2537, 2541, 2550, 2565, 2577, 2586, 2614, 2627, 2636,
2586 2642, 2648, 2659, 2665, 2671, 2682, 2683, 2692, 2693, 2705,
2587 2714, 2715, 2716, 2717, 2718, 2734, 2754, 2756, 2758, 2758,
2588 2765, 2765, 2773, 2773, 2781, 2781, 2790, 2792, 2794, 2799,
2589 2813, 2814, 2818, 2821, 2829, 2833, 2840, 2844, 2848, 2852,
2590 2860, 2860, 2864, 2865, 2869, 2877, 2882, 2890, 2891, 2898,
2591 2905, 2909, 3099, 3099, 3103, 3103, 3113, 3113, 3117, 3122,
2592 3123, 3124, 3128, 3129, 3128, 3141, 3142, 3147, 3148, 3149,
2593 3150, 3154, 3158, 3159, 3160, 3161, 3182, 3186, 3200, 3201,
2594 3206, 3206, 3214, 3224, 3227, 3236, 3247, 3252, 3261, 3272,
2595 3272, 3275, 3279, 3283, 3288, 3298, 3316, 3325, 3398, 3402,
2596 3409, 3421, 3436, 3466, 3476, 3486, 3490, 3497, 3498, 3502,
2597 3505, 3511, 3530, 3548, 3564, 3578, 3592, 3603, 3621, 3630,
2598 3639, 3646, 3667, 3691, 3697, 3703, 3709, 3725, 3818, 3826,
2599 3827, 3831, 3832, 3836, 3842, 3849, 3855, 3862, 3869, 3882,
2600 3908
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002601};
2602#endif
2603
2604#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
2605/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
2606 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
2607static const char *const yytname[] =
2608{
2609 "$end", "error", "$undefined", "ESINT64VAL", "EUINT64VAL", "SINTVAL",
2610 "UINTVAL", "FPVAL", "VOID", "BOOL", "SBYTE", "UBYTE", "SHORT", "USHORT",
2611 "INT", "UINT", "LONG", "ULONG", "FLOAT", "DOUBLE", "TYPE", "LABEL",
2612 "VAR_ID", "LABELSTR", "STRINGCONSTANT", "IMPLEMENTATION",
2613 "ZEROINITIALIZER", "TRUETOK", "FALSETOK", "BEGINTOK", "ENDTOK",
2614 "DECLARE", "GLOBAL", "CONSTANT", "SECTION", "VOLATILE", "TO",
2615 "DOTDOTDOT", "NULL_TOK", "UNDEF", "CONST", "INTERNAL", "LINKONCE",
2616 "WEAK", "APPENDING", "DLLIMPORT", "DLLEXPORT", "EXTERN_WEAK", "OPAQUE",
2617 "NOT", "EXTERNAL", "TARGET", "TRIPLE", "ENDIAN", "POINTERSIZE", "LITTLE",
2618 "BIG", "ALIGN", "DEPLIBS", "CALL", "TAIL", "ASM_TOK", "MODULE",
2619 "SIDEEFFECT", "CC_TOK", "CCC_TOK", "CSRETCC_TOK", "FASTCC_TOK",
2620 "COLDCC_TOK", "X86_STDCALLCC_TOK", "X86_FASTCALLCC_TOK", "DATALAYOUT",
2621 "RET", "BR", "SWITCH", "INVOKE", "UNREACHABLE", "UNWIND", "EXCEPT",
2622 "ADD", "SUB", "MUL", "DIV", "UDIV", "SDIV", "FDIV", "REM", "UREM",
2623 "SREM", "FREM", "AND", "OR", "XOR", "SHL", "SHR", "ASHR", "LSHR",
2624 "SETLE", "SETGE", "SETLT", "SETGT", "SETEQ", "SETNE", "ICMP", "FCMP",
2625 "MALLOC", "ALLOCA", "FREE", "LOAD", "STORE", "GETELEMENTPTR", "PHI_TOK",
2626 "SELECT", "VAARG", "EXTRACTELEMENT", "INSERTELEMENT", "SHUFFLEVECTOR",
2627 "VAARG_old", "VANEXT_old", "EQ", "NE", "SLT", "SGT", "SLE", "SGE", "ULT",
2628 "UGT", "ULE", "UGE", "OEQ", "ONE", "OLT", "OGT", "OLE", "OGE", "ORD",
2629 "UNO", "UEQ", "UNE", "CAST", "TRUNC", "ZEXT", "SEXT", "FPTRUNC", "FPEXT",
2630 "FPTOUI", "FPTOSI", "UITOFP", "SITOFP", "PTRTOINT", "INTTOPTR",
2631 "BITCAST", "'='", "','", "'\\\\'", "'('", "')'", "'['", "'x'", "']'",
2632 "'<'", "'>'", "'{'", "'}'", "'*'", "'c'", "$accept", "INTVAL",
2633 "EINT64VAL", "ArithmeticOps", "LogicalOps", "SetCondOps", "IPredicates",
2634 "FPredicates", "ShiftOps", "CastOps", "SIntType", "UIntType", "IntType",
2635 "FPType", "OptAssign", "OptLinkage", "OptCallingConv", "OptAlign",
2636 "OptCAlign", "SectionString", "OptSection", "GlobalVarAttributes",
2637 "GlobalVarAttribute", "TypesV", "UpRTypesV", "Types", "PrimType",
2638 "UpRTypes", "TypeListI", "ArgTypeListI", "ConstVal", "ConstExpr",
2639 "ConstVector", "GlobalType", "Module", "FunctionList", "ConstPool", "@1",
2640 "@2", "@3", "@4", "AsmBlock", "BigOrLittle", "TargetDefinition",
2641 "LibrariesDefinition", "LibList", "Name", "OptName", "ArgVal",
2642 "ArgListH", "ArgList", "FunctionHeaderH", "BEGIN", "FunctionHeader",
Reid Spencerd2920cd2007-03-21 17:27:53 +00002643 "@5", "END", "Function", "FnDeclareLinkage", "FunctionProto", "@6", "@7",
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002644 "OptSideEffect", "ConstValueRef", "SymbolicValueRef", "ValueRef",
2645 "ResolvedVal", "BasicBlockList", "BasicBlock", "InstructionList",
2646 "Unwind", "BBTerminatorInst", "JumpTable", "Inst", "PHIList",
2647 "ValueRefList", "ValueRefListE", "OptTailCall", "InstVal", "IndexList",
2648 "OptVolatile", "MemoryInst", 0
2649};
2650#endif
2651
2652# ifdef YYPRINT
2653/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
2654 token YYLEX-NUM. */
2655static const unsigned short int yytoknum[] =
2656{
2657 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
2658 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
2659 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
2660 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
2661 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
2662 305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
2663 315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
2664 325, 326, 327, 328, 329, 330, 331, 332, 333, 334,
2665 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
2666 345, 346, 347, 348, 349, 350, 351, 352, 353, 354,
2667 355, 356, 357, 358, 359, 360, 361, 362, 363, 364,
2668 365, 366, 367, 368, 369, 370, 371, 372, 373, 374,
2669 375, 376, 377, 378, 379, 380, 381, 382, 383, 384,
2670 385, 386, 387, 388, 389, 390, 391, 392, 393, 394,
2671 395, 396, 397, 398, 399, 400, 401, 402, 403, 404,
2672 405, 406, 61, 44, 92, 40, 41, 91, 120, 93,
2673 60, 62, 123, 125, 42, 99
2674};
2675# endif
2676
2677/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
2678static const unsigned char yyr1[] =
2679{
2680 0, 166, 167, 167, 168, 168, 169, 169, 169, 169,
2681 169, 169, 169, 169, 169, 169, 169, 170, 170, 170,
2682 171, 171, 171, 171, 171, 171, 172, 172, 172, 172,
2683 172, 172, 172, 172, 172, 172, 173, 173, 173, 173,
2684 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
2685 173, 173, 174, 174, 174, 174, 175, 175, 175, 175,
2686 175, 175, 175, 175, 175, 175, 175, 175, 175, 176,
2687 176, 176, 176, 177, 177, 177, 177, 178, 178, 179,
2688 179, 180, 180, 181, 181, 181, 181, 181, 181, 181,
2689 181, 182, 182, 182, 182, 182, 182, 182, 182, 183,
2690 183, 184, 184, 185, 186, 186, 187, 187, 188, 188,
2691 189, 189, 190, 190, 191, 192, 192, 192, 192, 192,
2692 192, 192, 192, 192, 192, 192, 192, 193, 193, 193,
2693 193, 193, 193, 193, 193, 193, 193, 193, 193, 194,
2694 194, 195, 195, 195, 195, 196, 196, 196, 196, 196,
2695 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
2696 196, 196, 196, 197, 197, 197, 197, 197, 197, 197,
2697 197, 197, 197, 197, 197, 198, 198, 199, 199, 200,
2698 201, 201, 201, 201, 201, 202, 202, 202, 203, 202,
2699 204, 202, 205, 202, 206, 202, 202, 202, 202, 207,
2700 208, 208, 209, 209, 209, 209, 210, 211, 211, 211,
2701 212, 212, 213, 213, 214, 215, 215, 216, 216, 216,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002702 216, 217, 218, 218, 220, 219, 221, 221, 222, 223,
2703 223, 223, 225, 226, 224, 227, 227, 228, 228, 228,
2704 228, 228, 228, 228, 228, 228, 228, 228, 229, 229,
2705 230, 230, 231, 232, 232, 233, 234, 234, 234, 235,
2706 235, 236, 236, 236, 236, 236, 236, 236, 236, 236,
2707 237, 237, 238, 239, 239, 240, 240, 241, 241, 242,
2708 242, 243, 243, 243, 243, 243, 243, 243, 243, 243,
2709 243, 243, 243, 243, 243, 243, 243, 243, 243, 244,
2710 244, 245, 245, 246, 246, 246, 246, 246, 246, 246,
2711 246
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002712};
2713
2714/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
2715static const unsigned char yyr2[] =
2716{
2717 0, 2, 1, 1, 1, 1, 1, 1, 1, 1,
2718 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2719 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2720 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2721 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2722 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2723 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2724 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2725 1, 2, 0, 1, 1, 1, 1, 1, 1, 1,
2726 0, 0, 1, 1, 1, 1, 1, 1, 2, 0,
2727 2, 0, 3, 2, 0, 1, 0, 3, 1, 2,
2728 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2729 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2730 2, 4, 5, 5, 3, 2, 5, 4, 2, 1,
2731 3, 1, 3, 1, 0, 4, 3, 3, 4, 4,
2732 3, 6, 5, 2, 2, 2, 2, 2, 2, 2,
2733 2, 2, 2, 6, 5, 8, 6, 6, 6, 7,
2734 7, 6, 6, 8, 8, 3, 1, 1, 1, 1,
2735 2, 2, 4, 2, 1, 4, 2, 4, 0, 7,
2736 0, 7, 0, 7, 0, 7, 3, 4, 0, 1,
2737 1, 1, 3, 3, 3, 3, 3, 3, 1, 0,
2738 1, 1, 1, 0, 2, 3, 1, 1, 3, 1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002739 0, 8, 1, 1, 0, 4, 1, 1, 2, 0,
2740 1, 1, 0, 0, 5, 0, 1, 1, 1, 1,
2741 1, 1, 1, 1, 1, 3, 1, 5, 1, 1,
2742 1, 1, 2, 2, 2, 3, 2, 0, 1, 1,
2743 1, 2, 2, 3, 9, 9, 8, 13, 1, 1,
2744 6, 5, 2, 6, 7, 1, 3, 1, 0, 2,
2745 1, 5, 5, 5, 6, 6, 2, 4, 4, 6,
2746 4, 4, 4, 4, 6, 6, 2, 7, 1, 2,
2747 0, 1, 0, 3, 6, 3, 6, 2, 4, 6,
2748 4
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002749};
2750
2751/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
2752 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
2753 means the default is an error. */
2754static const unsigned short int yydefact[] =
2755{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002756 198, 0, 90, 184, 1, 183, 232, 83, 84, 85,
2757 86, 87, 88, 89, 0, 224, 257, 180, 181, 257,
2758 210, 211, 0, 0, 0, 90, 0, 186, 229, 0,
2759 91, 258, 254, 82, 226, 227, 228, 253, 0, 0,
2760 0, 0, 196, 0, 0, 0, 0, 0, 0, 0,
2761 81, 230, 231, 233, 199, 182, 0, 92, 93, 94,
2762 95, 96, 97, 0, 0, 302, 256, 0, 0, 0,
2763 0, 209, 197, 187, 2, 3, 111, 115, 116, 117,
2764 118, 119, 120, 121, 122, 123, 124, 125, 126, 128,
2765 0, 0, 0, 0, 248, 185, 0, 110, 127, 114,
2766 249, 129, 177, 178, 0, 0, 0, 0, 91, 98,
2767 0, 222, 223, 225, 301, 0, 280, 0, 0, 0,
2768 0, 91, 269, 259, 260, 6, 7, 8, 9, 10,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002769 11, 12, 13, 14, 15, 16, 17, 18, 19, 52,
2770 53, 54, 55, 20, 21, 22, 23, 24, 25, 0,
2771 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2772 0, 0, 0, 68, 56, 57, 58, 59, 60, 61,
2773 62, 63, 64, 65, 66, 67, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002774 0, 268, 255, 91, 272, 0, 298, 204, 201, 200,
2775 202, 203, 205, 208, 0, 130, 0, 0, 0, 113,
2776 135, 139, 0, 144, 138, 192, 194, 190, 115, 116,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002777 117, 118, 119, 120, 121, 122, 123, 124, 125, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002778 0, 0, 0, 188, 234, 0, 0, 286, 279, 262,
2779 261, 0, 0, 72, 76, 71, 75, 70, 74, 69,
2780 73, 77, 78, 0, 0, 26, 27, 28, 29, 30,
2781 31, 32, 33, 34, 35, 0, 50, 51, 46, 47,
2782 48, 49, 36, 37, 38, 39, 40, 41, 42, 43,
2783 44, 45, 0, 101, 101, 307, 0, 0, 296, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002784 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002785 0, 0, 0, 0, 0, 206, 0, 0, 0, 0,
2786 0, 134, 143, 141, 0, 106, 106, 106, 160, 161,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002787 4, 5, 158, 159, 162, 157, 153, 154, 0, 0,
2788 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002789 0, 0, 0, 0, 156, 155, 106, 220, 237, 238,
2790 239, 244, 240, 241, 242, 243, 235, 0, 246, 251,
2791 250, 252, 0, 263, 0, 0, 0, 0, 0, 303,
2792 0, 305, 300, 0, 0, 0, 0, 0, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002793 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002794 207, 112, 112, 137, 0, 140, 0, 131, 0, 193,
2795 195, 191, 0, 0, 0, 0, 0, 0, 0, 146,
2796 176, 0, 0, 0, 150, 0, 147, 0, 0, 0,
2797 0, 0, 189, 219, 213, 216, 217, 0, 236, 0,
2798 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2799 310, 0, 0, 0, 290, 293, 0, 0, 291, 292,
2800 0, 0, 0, 287, 288, 0, 308, 0, 132, 133,
2801 136, 142, 0, 0, 108, 106, 0, 0, 300, 0,
2802 0, 0, 0, 0, 145, 135, 114, 0, 148, 149,
2803 0, 0, 0, 0, 0, 212, 214, 0, 104, 0,
2804 245, 0, 0, 278, 0, 0, 101, 102, 101, 275,
2805 299, 0, 0, 0, 0, 0, 281, 282, 283, 278,
2806 0, 103, 109, 107, 0, 0, 0, 0, 0, 0,
2807 0, 175, 152, 0, 0, 0, 0, 0, 0, 218,
2808 215, 105, 99, 0, 0, 0, 277, 0, 284, 285,
2809 0, 304, 306, 0, 0, 0, 289, 294, 295, 0,
2810 309, 0, 0, 164, 0, 0, 0, 0, 151, 0,
2811 0, 0, 0, 0, 0, 221, 247, 0, 0, 0,
2812 276, 273, 0, 297, 0, 0, 0, 172, 0, 0,
2813 166, 167, 168, 171, 163, 100, 0, 266, 0, 0,
2814 0, 274, 169, 170, 0, 0, 0, 264, 0, 265,
2815 0, 0, 165, 173, 174, 0, 0, 0, 0, 0,
2816 0, 271, 0, 0, 270, 267
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002817};
2818
2819/* YYDEFGOTO[NTERM-NUM]. */
2820static const short int yydefgoto[] =
2821{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002822 -1, 94, 312, 329, 330, 331, 255, 272, 332, 333,
2823 219, 220, 243, 221, 25, 15, 63, 555, 359, 454,
2824 522, 389, 455, 95, 96, 222, 98, 99, 202, 304,
2825 400, 348, 401, 104, 1, 2, 3, 336, 307, 305,
2826 306, 55, 190, 42, 72, 194, 100, 476, 415, 416,
2827 417, 64, 113, 16, 30, 36, 17, 53, 18, 28,
2828 108, 419, 349, 101, 351, 489, 19, 32, 33, 181,
2829 182, 579, 66, 278, 526, 527, 183, 184, 430, 185,
2830 186
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002831};
2832
2833/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
2834 STATE-NUM. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002835#define YYPACT_NINF -542
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002836static const short int yypact[] =
2837{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002838 -542, 13, 162, 567, -542, -542, -542, -542, -542, -542,
2839 -542, -542, -542, -542, 83, -542, 19, -542, -542, -14,
2840 -542, -542, 50, -87, 87, 233, 27, -542, 123, 141,
2841 175, -542, -542, 98, -542, -542, -542, -542, 33, 40,
2842 66, 68, -542, 14, 141, 1265, 156, 156, 156, 156,
2843 -542, -542, -542, -542, -542, -542, 221, -542, -542, -542,
2844 -542, -542, -542, 1265, -19, 1479, -542, 204, 135, 226,
2845 227, 235, -542, -542, -542, -542, 81, -542, -542, -542,
2846 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2847 256, 257, 4, 15, -542, -542, 108, -542, -542, 12,
2848 -542, -542, -542, -542, 1306, 1306, 1306, 1326, 175, -542,
2849 98, -542, -542, -542, -542, 1306, -542, 205, 1367, 116,
2850 479, 175, -542, -542, -542, -542, -542, -542, -542, -542,
2851 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2852 -542, -542, -542, -542, -542, -542, -542, -542, -542, 355,
2853 429, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306,
2854 1306, 1306, 1306, -542, -542, -542, -542, -542, -542, -542,
2855 -542, -542, -542, -542, -542, -542, 1306, 1306, 1306, 1306,
2856 1306, -542, -542, 175, -542, 86, -542, -542, -542, -542,
2857 -542, -542, -542, -542, -13, -542, 110, 111, 75, -542,
2858 -542, 12, -81, 1046, -542, -542, -542, -542, 174, 208,
2859 266, 210, 267, 212, 268, 230, 277, 275, 278, 246,
2860 280, 279, 566, -542, -542, 136, 766, -542, -542, 81,
2861 -542, 766, 766, -542, -542, -542, -542, -542, -542, -542,
2862 -542, -542, -542, 766, 1265, -542, -542, -542, -542, -542,
2863 -542, -542, -542, -542, -542, 1306, -542, -542, -542, -542,
2864 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2865 -542, -542, 1306, 137, 145, -542, 766, 132, 146, 147,
2866 148, 149, 151, 152, 158, 160, 766, 766, 766, 161,
2867 281, 1265, 1306, 1306, 291, -542, 1306, 1306, 155, -27,
2868 1306, -542, -542, 165, 163, 176, 176, 176, -542, -542,
2869 -542, -542, -542, -542, -542, -542, -542, -542, 355, 429,
2870 172, 177, 178, 179, 182, 1087, 1387, 529, 311, 184,
2871 185, 186, 188, 189, -542, -542, 176, 1107, -542, -542,
2872 -542, -542, -542, -542, -542, -542, 282, 1326, -542, -542,
2873 -542, -542, 193, -542, 194, 766, 766, 766, 7, -542,
2874 20, -542, 195, 766, 192, 1306, 1306, 1306, 1306, 1306,
2875 1306, 1306, 200, 201, 206, 1306, 1306, 766, 766, 207,
2876 -542, -59, -149, -542, 196, 12, 1148, -542, 44, -542,
2877 -542, -542, 203, 211, 1326, 1326, 1326, 1326, 1326, -542,
2878 -542, -8, 741, -82, -542, 10, -542, 1326, 1326, 1326,
2879 1326, 1326, -542, -542, 98, -542, 214, 209, -542, 337,
2880 -34, 342, 348, 215, 218, 219, 766, 371, 766, 1306,
2881 -542, 223, 766, 224, -542, -542, 225, 234, -542, -542,
2882 766, 766, 766, -542, -542, 228, -542, 1306, -542, -542,
2883 -542, -542, 362, 375, -542, 176, 1326, 1326, 195, 236,
2884 237, 240, 243, 1326, -542, 238, -25, 11, -542, -542,
2885 244, 245, 247, 250, 352, -542, -542, 1205, 370, 252,
2886 -542, 766, 766, 1306, 766, 766, 258, -542, 258, -542,
2887 259, 766, 264, 1306, 1306, 1306, -542, -542, -542, 1306,
2888 766, -542, -542, -542, 270, 271, 263, 1326, 1326, 1326,
2889 1326, -542, -542, 260, 1326, 1326, 1326, 1326, 1306, -542,
2890 -542, -542, 368, 402, 274, 276, 259, 287, -542, -542,
2891 374, -542, -542, 1306, 285, 766, -542, -542, -542, 290,
2892 -542, 1326, 1326, -542, 283, 295, 284, 294, -542, 296,
2893 297, 299, 302, 303, 430, -542, -542, 414, 41, 425,
2894 -542, -542, 305, -542, 306, 310, 1326, -542, 1326, 1326,
2895 -542, -542, -542, -542, -542, -542, 766, -542, 893, 144,
2896 448, -542, -542, -542, 314, 315, 316, -542, 331, -542,
2897 893, 766, -542, -542, -542, 464, 334, 180, 766, 481,
2898 482, -542, 766, 766, -542, -542
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002899};
2900
2901/* YYPGOTO[NTERM-NUM]. */
2902static const short int yypgoto[] =
2903{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002904 -542, -542, -542, 435, 439, 441, 191, 197, 442, 445,
2905 -119, -116, -541, -542, 478, 489, -107, -542, -267, 37,
2906 -542, -238, -542, -60, -542, -45, -542, -74, -51, -542,
2907 -101, 300, -252, 134, -542, -542, -542, -542, -542, -542,
2908 -542, 473, -542, -542, -542, -542, 8, -542, 46, -542,
2909 -542, 410, -542, -542, -542, -542, -542, -542, 518, -542,
2910 -542, -542, -528, 142, -90, -113, -542, 505, -542, -72,
2911 -542, -542, -542, -542, 97, 28, -542, -542, 70, -542,
2912 -542
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002913};
2914
2915/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
2916 positive, shift that token. If negative, reduce the rule which
2917 number is the opposite. If zero, do what YYDEFACT says.
2918 If YYTABLE_NINF, syntax error. */
2919#define YYTABLE_NINF -180
2920static const short int yytable[] =
2921{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002922 97, 241, 227, 110, 242, 230, 223, 361, 197, 31,
2923 111, 26, 449, 4, 244, 204, 34, 578, 97, 201,
2924 74, 75, 426, 199, 77, 78, 79, 80, 81, 82,
2925 83, 84, 85, 86, 87, 428, 88, 20, 590, 21,
2926 275, 26, 31, 279, 280, 281, 282, 283, 284, 285,
2927 588, 233, 234, 235, 236, 237, 238, 239, 240, 205,
2928 206, 207, 596, 89, 427, 43, 289, 290, 390, 391,
2929 226, 463, 300, 226, 403, 405, 291, 427, 452, 468,
2930 74, 75, 301, 199, 77, 78, 79, 80, 81, 82,
2931 83, 84, 85, 86, 87, 420, 88, 20, 412, 21,
2932 448, 453, 38, 39, 40, 204, 273, 274, 226, 276,
2933 277, 226, 226, 226, 226, 226, 226, 226, 225, 463,
2934 20, 41, 21, 89, 201, 231, 300, 480, -139, 201,
2935 -112, 286, 287, 288, 226, 226, 384, 232, -139, 204,
2936 294, 352, 353, 112, 29, 463, 295, 299, 44, 35,
2937 467, 464, 303, 354, 233, 234, 235, 236, 237, 238,
2938 239, 240, -179, 463, 463, 54, 198, -112, 51, 90,
2939 52, 71, 91, 469, 513, 92, 204, 93, 200, 50,
2940 379, 105, 106, 107, 355, 67, 362, 5, 102, 103,
2941 188, 189, 68, 6, 292, 293, 372, 373, 374, 97,
2942 577, 308, 309, 7, 8, 9, 10, 11, 12, 13,
2943 356, -72, -72, -71, -71, -70, -70, 503, 69, 531,
2944 70, 532, 381, 382, 14, 109, 385, 357, 187, 90,
2945 191, 377, 91, -69, -69, 92, -113, 93, 298, 56,
2946 57, 58, 59, 60, 61, 62, 97, 378, 226, 310,
2947 311, 192, 433, 45, 435, 436, 437, 123, 124, 193,
2948 195, 196, 443, 203, 228, 423, 424, 425, 296, 297,
2949 -76, -75, -74, 431, 7, 8, 9, 10, 46, 12,
2950 47, -73, -79, 48, 313, -80, 314, 445, 446, 363,
2951 358, 337, 414, 458, 459, 460, 461, 462, 360, 364,
2952 365, 366, 367, 589, 368, 369, 470, 471, 472, 473,
2953 474, 370, 385, 371, 375, 380, 383, 376, 386, 387,
2954 226, 434, 226, 226, 226, 438, 439, 394, 466, 388,
2955 226, 444, 395, 396, 397, 406, 486, 398, 488, 407,
2956 408, 409, 492, 410, 411, 418, 421, 422, 429, 432,
2957 496, 497, 498, 440, 441, 504, 505, 450, 456, 442,
2958 447, 479, 511, 481, 335, 478, 457, 477, 350, 482,
2959 483, 484, 485, 350, 350, 487, 491, 493, 494, 502,
2960 536, 537, 538, 499, 226, 350, 501, 495, 518, 507,
2961 508, 524, 525, 509, 528, 529, 510, 514, 515, 512,
2962 516, 534, 500, 517, 452, 523, 544, 545, 546, 547,
2963 540, 530, 533, 549, 550, 551, 552, 535, 350, 543,
2964 560, 548, 475, 541, 542, 554, 556, 557, 350, 350,
2965 350, 427, 414, 558, 575, 576, 566, 568, 226, 241,
2966 564, 565, 242, 559, 561, 562, 563, 569, 226, 226,
2967 226, 567, 570, 571, 226, 572, 256, 257, 573, 574,
2968 241, 580, 582, 242, 581, 584, 583, 585, 586, 591,
2969 592, 593, 594, 553, 245, 246, 247, 248, 249, 250,
2970 251, 252, 253, 254, 595, 598, 587, 599, 226, 233,
2971 234, 235, 236, 237, 238, 239, 240, 350, 350, 350,
2972 176, 597, 602, 603, 177, 350, 178, 179, 601, 392,
2973 180, 65, 604, 605, 49, 521, 393, 73, 224, 350,
2974 350, 27, 334, 520, 37, 600, 490, 539, 506, 0,
2975 0, 0, 0, 0, 74, 75, 0, 199, 208, 209,
2976 210, 211, 212, 213, 214, 215, 216, 217, 218, 0,
2977 88, 20, 0, 21, 258, 259, 260, 261, 262, 263,
2978 264, 265, 266, 267, 268, 269, 270, 271, 350, 0,
2979 350, 74, 75, 0, 350, 0, 0, 89, 0, 0,
2980 0, 0, 350, 350, 350, 0, 0, -82, 20, 20,
2981 21, 21, 315, 0, 0, 0, 0, 0, 6, -82,
2982 -82, 0, 0, 0, 316, 317, 0, 0, -82, -82,
2983 -82, -82, -82, -82, -82, 0, 0, -82, 22, 0,
2984 0, 0, 0, 350, 350, 23, 350, 350, 0, 24,
2985 0, 0, 0, 350, 0, 0, 0, 0, 0, 0,
2986 0, 0, 350, 0, 0, 125, 126, 127, 128, 129,
2987 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
2988 140, 141, 142, 143, 144, 145, 146, 147, 148, 318,
2989 319, 0, 0, 0, 0, 0, 320, 350, 321, 0,
2990 322, 323, 324, 90, 0, 0, 91, 0, 0, 92,
2991 0, 93, 404, 0, 0, 0, 0, 0, 0, 0,
2992 0, 0, 0, 0, 0, 163, 164, 165, 166, 167,
2993 168, 169, 170, 171, 172, 173, 174, 175, 350, 0,
2994 0, 0, 0, 325, 0, 0, 326, 0, 327, 0,
2995 0, 328, 0, 350, 0, 0, 0, 0, 0, 0,
2996 350, 0, 0, 0, 350, 350, 74, 75, 0, 199,
2997 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
2998 218, 0, 88, 20, 0, 21, 0, 0, 0, 338,
2999 339, 74, 75, 340, 0, 0, 0, 0, 0, 0,
3000 0, 0, 0, 0, 0, 0, 0, 0, 20, 89,
3001 21, 0, 341, 342, 343, 0, 0, 0, 0, 0,
3002 0, 0, 0, 0, 344, 345, 0, 0, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003003 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003004 0, 0, 0, 0, 0, 0, 0, 346, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003005 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003006 0, 0, 0, 0, 0, 125, 126, 127, 128, 129,
3007 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
3008 140, 141, 142, 143, 144, 145, 146, 147, 148, 318,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003009 319, 0, 0, 0, 0, 0, 320, 0, 321, 0,
3010 322, 323, 324, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003011 0, 0, 0, 0, 0, 90, 338, 339, 91, 0,
3012 340, 92, 0, 93, 465, 163, 164, 165, 166, 167,
3013 168, 169, 170, 171, 172, 173, 174, 175, 0, 341,
3014 342, 343, 0, 0, 0, 0, 347, 0, 0, 0,
3015 0, 344, 345, 0, 0, 0, 0, 0, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003016 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003017 0, 0, 0, 0, 346, 0, 0, 0, 0, 0,
3018 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3019 0, 0, 125, 126, 127, 128, 129, 130, 131, 132,
3020 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
3021 143, 144, 145, 146, 147, 148, 318, 319, 0, 0,
3022 0, 0, 0, 320, 0, 321, 0, 322, 323, 324,
3023 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3024 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3025 0, 0, 163, 164, 165, 166, 167, 168, 169, 170,
3026 171, 172, 173, 174, 175, 0, 0, 0, 0, 0,
3027 0, 74, 75, 347, 199, 77, 78, 79, 80, 81,
3028 82, 83, 84, 85, 86, 87, 0, 88, 20, 0,
3029 21, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3030 0, 0, 0, 302, 0, 0, 0, 0, 0, 0,
3031 0, 0, 74, 75, 89, 199, 208, 209, 210, 211,
3032 212, 213, 214, 215, 216, 217, 218, 0, 88, 20,
3033 0, 21, 74, 75, 0, 199, 77, 78, 79, 80,
3034 81, 82, 83, 84, 85, 86, 87, 0, 88, 20,
3035 0, 21, 0, 0, 0, 89, 0, 0, 0, 0,
3036 0, 0, 0, 0, 413, 0, 0, 0, 0, 0,
3037 0, 0, 0, 74, 75, 89, 199, 77, 78, 79,
3038 80, 81, 82, 83, 84, 85, 86, 87, 0, 88,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003039 20, 0, 21, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003040 0, 0, 0, 0, 0, 451, 0, 0, 0, 0,
3041 0, 0, 0, 0, 0, 0, 89, 0, 0, 0,
3042 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
3043 74, 75, 0, 199, 77, 78, 79, 80, 81, 82,
3044 83, 84, 85, 86, 87, 0, 88, 20, 0, 21,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003045 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003046 0, 90, 519, 0, 91, 0, 399, 92, 0, 93,
3047 0, 0, 0, 89, 0, 0, 0, 0, 0, 0,
3048 0, 90, 0, 0, 91, 0, 0, 92, 0, 93,
3049 74, 75, 0, 76, 77, 78, 79, 80, 81, 82,
3050 83, 84, 85, 86, 87, 0, 88, 20, 0, 21,
3051 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3052 0, 0, 90, 0, 0, 91, 0, 0, 92, 0,
3053 93, 74, 75, 89, 199, 77, 78, 79, 80, 81,
3054 82, 83, 84, 85, 86, 87, 0, 88, 20, 0,
3055 21, 74, 75, 0, 199, 208, 209, 210, 211, 212,
3056 213, 214, 215, 216, 217, 218, 0, 88, 20, 0,
3057 21, 0, 0, 0, 89, 0, 0, 0, 0, 90,
3058 0, 0, 91, 0, 0, 92, 0, 93, 0, 0,
3059 0, 0, 74, 75, 89, 229, 77, 78, 79, 80,
3060 81, 82, 83, 84, 85, 86, 87, 0, 88, 20,
3061 0, 21, 74, 75, 0, 199, 208, 209, 210, 211,
3062 212, 213, 214, 215, 216, 217, 218, 0, 88, 20,
3063 0, 21, 0, 0, 0, 89, 0, 0, 0, 90,
3064 0, 0, 91, 0, 0, 92, 0, 93, 0, 0,
3065 0, 0, 0, 0, 0, 89, 0, 0, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003066 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3067 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003068 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003069 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003070 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003071 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3072 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003073 0, 0, 0, 0, 114, 0, 0, 0, 0, 0,
3074 0, 90, 0, 0, 91, 0, 0, 92, 115, 93,
3075 0, 0, 0, 0, 0, 0, 0, 0, 116, 117,
3076 0, 90, 0, 0, 91, 0, 0, 92, 0, 402,
3077 0, 118, 119, 120, 121, 122, 123, 124, 125, 126,
3078 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
3079 137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
3080 147, 148, 149, 150, 151, 152, 153, 0, 0, 154,
3081 155, 156, 157, 158, 159, 160, 161, 162, 0, 0,
3082 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3083 0, 0, 0, 0, 0, 0, 0, 0, 163, 164,
3084 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
3085 175
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003086};
3087
3088static const short int yycheck[] =
3089{
Reid Spencerd2920cd2007-03-21 17:27:53 +00003090 45, 120, 115, 63, 120, 118, 107, 274, 4, 23,
3091 29, 3, 161, 0, 121, 164, 30, 558, 63, 93,
3092 5, 6, 15, 8, 9, 10, 11, 12, 13, 14,
3093 15, 16, 17, 18, 19, 15, 21, 22, 579, 24,
3094 153, 33, 23, 156, 157, 158, 159, 160, 161, 162,
3095 578, 10, 11, 12, 13, 14, 15, 16, 17, 104,
3096 105, 106, 590, 48, 57, 152, 179, 180, 306, 307,
3097 115, 153, 153, 118, 326, 327, 183, 57, 34, 161,
3098 5, 6, 163, 8, 9, 10, 11, 12, 13, 14,
3099 15, 16, 17, 18, 19, 347, 21, 22, 336, 24,
3100 159, 57, 52, 53, 54, 164, 151, 152, 153, 154,
3101 155, 156, 157, 158, 159, 160, 161, 162, 110, 153,
3102 22, 71, 24, 48, 198, 9, 153, 161, 153, 203,
3103 155, 176, 177, 178, 179, 180, 163, 21, 163, 164,
3104 153, 231, 232, 162, 61, 153, 159, 198, 61, 163,
3105 402, 159, 203, 243, 10, 11, 12, 13, 14, 15,
3106 16, 17, 0, 153, 153, 24, 162, 155, 45, 154,
3107 47, 157, 157, 163, 163, 160, 164, 162, 163, 152,
3108 293, 47, 48, 49, 244, 152, 276, 25, 32, 33,
3109 55, 56, 152, 31, 108, 109, 286, 287, 288, 244,
3110 159, 27, 28, 41, 42, 43, 44, 45, 46, 47,
3111 255, 3, 4, 3, 4, 3, 4, 455, 152, 486,
3112 152, 488, 296, 297, 62, 4, 300, 272, 24, 154,
3113 4, 291, 157, 3, 4, 160, 155, 162, 163, 64,
3114 65, 66, 67, 68, 69, 70, 291, 292, 293, 3,
3115 4, 24, 365, 20, 367, 368, 369, 77, 78, 24,
3116 4, 4, 375, 155, 59, 355, 356, 357, 158, 158,
3117 4, 4, 4, 363, 41, 42, 43, 44, 45, 46,
3118 47, 4, 7, 50, 4, 7, 7, 377, 378, 157,
3119 153, 155, 337, 394, 395, 396, 397, 398, 153, 153,
3120 153, 153, 153, 159, 153, 153, 407, 408, 409, 410,
3121 411, 153, 386, 153, 153, 24, 161, 36, 153, 156,
3122 365, 366, 367, 368, 369, 370, 371, 155, 402, 153,
3123 375, 376, 155, 155, 155, 24, 426, 155, 428, 155,
3124 155, 155, 432, 155, 155, 63, 153, 153, 153, 157,
3125 440, 441, 442, 153, 153, 456, 457, 161, 155, 153,
3126 153, 24, 463, 21, 222, 156, 155, 153, 226, 21,
3127 155, 153, 153, 231, 232, 4, 153, 153, 153, 4,
3128 493, 494, 495, 155, 429, 243, 24, 153, 36, 153,
3129 153, 481, 482, 153, 484, 485, 153, 153, 153, 161,
3130 153, 491, 447, 153, 34, 153, 507, 508, 509, 510,
3131 500, 153, 153, 514, 515, 516, 517, 153, 276, 156,
3132 533, 161, 414, 153, 153, 57, 24, 153, 286, 287,
3133 288, 57, 477, 157, 4, 21, 153, 153, 483, 558,
3134 541, 542, 558, 156, 159, 535, 156, 153, 493, 494,
3135 495, 156, 156, 156, 499, 156, 27, 28, 156, 156,
3136 579, 36, 156, 579, 159, 566, 156, 568, 569, 21,
3137 156, 156, 156, 518, 119, 120, 121, 122, 123, 124,
3138 125, 126, 127, 128, 153, 21, 576, 153, 533, 10,
3139 11, 12, 13, 14, 15, 16, 17, 355, 356, 357,
3140 65, 591, 21, 21, 65, 363, 65, 65, 598, 318,
3141 65, 33, 602, 603, 25, 478, 319, 44, 108, 377,
3142 378, 3, 222, 477, 19, 597, 429, 499, 458, -1,
3143 -1, -1, -1, -1, 5, 6, -1, 8, 9, 10,
3144 11, 12, 13, 14, 15, 16, 17, 18, 19, -1,
3145 21, 22, -1, 24, 125, 126, 127, 128, 129, 130,
3146 131, 132, 133, 134, 135, 136, 137, 138, 426, -1,
3147 428, 5, 6, -1, 432, -1, -1, 48, -1, -1,
3148 -1, -1, 440, 441, 442, -1, -1, 20, 22, 22,
3149 24, 24, 26, -1, -1, -1, -1, -1, 31, 32,
3150 33, -1, -1, -1, 38, 39, -1, -1, 41, 42,
3151 43, 44, 45, 46, 47, -1, -1, 50, 51, -1,
3152 -1, -1, -1, 481, 482, 58, 484, 485, -1, 62,
3153 -1, -1, -1, 491, -1, -1, -1, -1, -1, -1,
3154 -1, -1, 500, -1, -1, 79, 80, 81, 82, 83,
3155 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3156 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3157 104, -1, -1, -1, -1, -1, 110, 535, 112, -1,
3158 114, 115, 116, 154, -1, -1, 157, -1, -1, 160,
3159 -1, 162, 163, -1, -1, -1, -1, -1, -1, -1,
3160 -1, -1, -1, -1, -1, 139, 140, 141, 142, 143,
3161 144, 145, 146, 147, 148, 149, 150, 151, 576, -1,
3162 -1, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3163 -1, 165, -1, 591, -1, -1, -1, -1, -1, -1,
3164 598, -1, -1, -1, 602, 603, 5, 6, -1, 8,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003165 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003166 19, -1, 21, 22, -1, 24, -1, -1, -1, 3,
3167 4, 5, 6, 7, -1, -1, -1, -1, -1, -1,
3168 -1, -1, -1, -1, -1, -1, -1, -1, 22, 48,
3169 24, -1, 26, 27, 28, -1, -1, -1, -1, -1,
3170 -1, -1, -1, -1, 38, 39, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003171 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3172 -1, -1, -1, -1, -1, -1, -1, 61, -1, -1,
3173 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3174 -1, -1, -1, -1, -1, 79, 80, 81, 82, 83,
3175 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3176 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3177 104, -1, -1, -1, -1, -1, 110, -1, 112, -1,
3178 114, 115, 116, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003179 -1, -1, -1, -1, -1, 154, 3, 4, 157, -1,
3180 7, 160, -1, 162, 163, 139, 140, 141, 142, 143,
3181 144, 145, 146, 147, 148, 149, 150, 151, -1, 26,
3182 27, 28, -1, -1, -1, -1, 160, -1, -1, -1,
3183 -1, 38, 39, -1, -1, -1, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003184 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003185 -1, -1, -1, -1, 61, -1, -1, -1, -1, -1,
3186 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3187 -1, -1, 79, 80, 81, 82, 83, 84, 85, 86,
3188 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
3189 97, 98, 99, 100, 101, 102, 103, 104, -1, -1,
3190 -1, -1, -1, 110, -1, 112, -1, 114, 115, 116,
3191 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3192 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3193 -1, -1, 139, 140, 141, 142, 143, 144, 145, 146,
3194 147, 148, 149, 150, 151, -1, -1, -1, -1, -1,
3195 -1, 5, 6, 160, 8, 9, 10, 11, 12, 13,
3196 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3197 24, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3198 -1, -1, -1, 37, -1, -1, -1, -1, -1, -1,
3199 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003200 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003201 -1, 24, 5, 6, -1, 8, 9, 10, 11, 12,
3202 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3203 -1, 24, -1, -1, -1, 48, -1, -1, -1, -1,
3204 -1, -1, -1, -1, 37, -1, -1, -1, -1, -1,
3205 -1, -1, -1, 5, 6, 48, 8, 9, 10, 11,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003206 12, 13, 14, 15, 16, 17, 18, 19, -1, 21,
3207 22, -1, 24, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003208 -1, -1, -1, -1, -1, 37, -1, -1, -1, -1,
3209 -1, -1, -1, -1, -1, -1, 48, -1, -1, -1,
3210 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3211 5, 6, -1, 8, 9, 10, 11, 12, 13, 14,
3212 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
3213 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3214 -1, 154, 37, -1, 157, -1, 159, 160, -1, 162,
3215 -1, -1, -1, 48, -1, -1, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003216 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003217 5, 6, -1, 8, 9, 10, 11, 12, 13, 14,
3218 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003219 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003220 -1, -1, 154, -1, -1, 157, -1, -1, 160, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003221 162, 5, 6, 48, 8, 9, 10, 11, 12, 13,
3222 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3223 24, 5, 6, -1, 8, 9, 10, 11, 12, 13,
3224 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3225 24, -1, -1, -1, 48, -1, -1, -1, -1, 154,
3226 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
3227 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
3228 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3229 -1, 24, 5, 6, -1, 8, 9, 10, 11, 12,
3230 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3231 -1, 24, -1, -1, -1, 48, -1, -1, -1, 154,
3232 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
3233 -1, -1, -1, -1, -1, 48, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003234 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3235 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003236 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003237 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003238 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003239 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3240 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003241 -1, -1, -1, -1, 35, -1, -1, -1, -1, -1,
3242 -1, 154, -1, -1, 157, -1, -1, 160, 49, 162,
3243 -1, -1, -1, -1, -1, -1, -1, -1, 59, 60,
3244 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
3245 -1, 72, 73, 74, 75, 76, 77, 78, 79, 80,
3246 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
3247 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
3248 101, 102, 103, 104, 105, 106, 107, -1, -1, 110,
3249 111, 112, 113, 114, 115, 116, 117, 118, -1, -1,
3250 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3251 -1, -1, -1, -1, -1, -1, -1, -1, 139, 140,
3252 141, 142, 143, 144, 145, 146, 147, 148, 149, 150,
3253 151
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003254};
3255
3256/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
3257 symbol of state STATE-NUM. */
3258static const unsigned char yystos[] =
3259{
3260 0, 200, 201, 202, 0, 25, 31, 41, 42, 43,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003261 44, 45, 46, 47, 62, 181, 219, 222, 224, 232,
3262 22, 24, 51, 58, 62, 180, 212, 224, 225, 61,
3263 220, 23, 233, 234, 30, 163, 221, 233, 52, 53,
3264 54, 71, 209, 152, 61, 20, 45, 47, 50, 181,
3265 152, 45, 47, 223, 24, 207, 64, 65, 66, 67,
3266 68, 69, 70, 182, 217, 180, 238, 152, 152, 152,
3267 152, 157, 210, 207, 5, 6, 8, 9, 10, 11,
3268 12, 13, 14, 15, 16, 17, 18, 19, 21, 48,
3269 154, 157, 160, 162, 167, 189, 190, 191, 192, 193,
3270 212, 229, 32, 33, 199, 199, 199, 199, 226, 4,
3271 189, 29, 162, 218, 35, 49, 59, 60, 72, 73,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003272 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
3273 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3274 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3275 104, 105, 106, 107, 110, 111, 112, 113, 114, 115,
3276 116, 117, 118, 139, 140, 141, 142, 143, 144, 145,
3277 146, 147, 148, 149, 150, 151, 169, 170, 171, 174,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003278 175, 235, 236, 242, 243, 245, 246, 24, 55, 56,
3279 208, 4, 24, 24, 211, 4, 4, 4, 162, 8,
3280 163, 193, 194, 155, 164, 191, 191, 191, 9, 10,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003281 11, 12, 13, 14, 15, 16, 17, 18, 19, 176,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003282 177, 179, 191, 196, 217, 212, 191, 231, 59, 8,
3283 231, 9, 21, 10, 11, 12, 13, 14, 15, 16,
3284 17, 176, 177, 178, 182, 119, 120, 121, 122, 123,
3285 124, 125, 126, 127, 128, 172, 27, 28, 125, 126,
3286 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
3287 137, 138, 173, 191, 191, 231, 191, 191, 239, 231,
3288 231, 231, 231, 231, 231, 231, 191, 191, 191, 231,
3289 231, 182, 108, 109, 153, 159, 158, 158, 163, 194,
3290 153, 163, 37, 194, 195, 205, 206, 204, 27, 28,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003291 3, 4, 168, 4, 7, 26, 38, 39, 103, 104,
3292 110, 112, 114, 115, 116, 157, 160, 162, 165, 169,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003293 170, 171, 174, 175, 197, 229, 203, 155, 3, 4,
3294 7, 26, 27, 28, 38, 39, 61, 160, 197, 228,
3295 229, 230, 230, 230, 230, 189, 191, 191, 153, 184,
3296 153, 184, 230, 157, 153, 153, 153, 153, 153, 153,
3297 153, 153, 230, 230, 230, 153, 36, 189, 191, 231,
3298 24, 193, 193, 161, 163, 193, 153, 156, 153, 187,
3299 187, 187, 172, 173, 155, 155, 155, 155, 155, 159,
3300 196, 198, 162, 198, 163, 198, 24, 155, 155, 155,
3301 155, 155, 187, 37, 191, 214, 215, 216, 63, 227,
3302 198, 153, 153, 230, 230, 230, 15, 57, 15, 153,
3303 244, 230, 157, 231, 191, 231, 231, 231, 191, 191,
3304 153, 153, 153, 231, 191, 230, 230, 153, 159, 161,
3305 161, 37, 34, 57, 185, 188, 155, 155, 196, 196,
3306 196, 196, 196, 153, 159, 163, 193, 198, 161, 163,
3307 196, 196, 196, 196, 196, 212, 213, 153, 156, 24,
3308 161, 21, 21, 155, 153, 153, 230, 4, 230, 231,
3309 240, 153, 230, 153, 153, 153, 230, 230, 230, 155,
3310 191, 24, 4, 187, 196, 196, 244, 153, 153, 153,
3311 153, 196, 161, 163, 153, 153, 153, 153, 36, 37,
3312 214, 185, 186, 153, 230, 230, 240, 241, 230, 230,
3313 153, 184, 184, 153, 230, 153, 231, 231, 231, 241,
3314 230, 153, 153, 156, 196, 196, 196, 196, 161, 196,
3315 196, 196, 196, 191, 57, 183, 24, 153, 157, 156,
3316 231, 159, 230, 156, 196, 196, 153, 156, 153, 153,
3317 156, 156, 156, 156, 156, 4, 21, 159, 178, 237,
3318 36, 159, 156, 156, 196, 196, 196, 230, 228, 159,
3319 178, 21, 156, 156, 156, 153, 228, 230, 21, 153,
3320 235, 230, 21, 21, 230, 230
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003321};
Reid Spencere7c3c602006-11-30 06:36:44 +00003322
3323#define yyerrok (yyerrstatus = 0)
3324#define yyclearin (yychar = YYEMPTY)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003325#define YYEMPTY (-2)
Reid Spencere7c3c602006-11-30 06:36:44 +00003326#define YYEOF 0
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003327
Reid Spencere7c3c602006-11-30 06:36:44 +00003328#define YYACCEPT goto yyacceptlab
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003329#define YYABORT goto yyabortlab
3330#define YYERROR goto yyerrorlab
3331
3332
3333/* Like YYERROR except do call yyerror. This remains here temporarily
3334 to ease the transition to the new meaning of YYERROR, for GCC.
Reid Spencere7c3c602006-11-30 06:36:44 +00003335 Once GCC version 2 has supplanted version 1, this can go. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003336
Reid Spencere7c3c602006-11-30 06:36:44 +00003337#define YYFAIL goto yyerrlab
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003338
Reid Spencere7c3c602006-11-30 06:36:44 +00003339#define YYRECOVERING() (!!yyerrstatus)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003340
3341#define YYBACKUP(Token, Value) \
Reid Spencere7c3c602006-11-30 06:36:44 +00003342do \
3343 if (yychar == YYEMPTY && yylen == 1) \
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003344 { \
3345 yychar = (Token); \
3346 yylval = (Value); \
3347 yytoken = YYTRANSLATE (yychar); \
Chris Lattnercf3d0612007-02-13 06:04:17 +00003348 YYPOPSTACK; \
Reid Spencere7c3c602006-11-30 06:36:44 +00003349 goto yybackup; \
3350 } \
3351 else \
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003352 { \
3353 yyerror (YY_("syntax error: cannot back up")); \
3354 YYERROR; \
3355 } \
Chris Lattnercf3d0612007-02-13 06:04:17 +00003356while (0)
Reid Spencere7c3c602006-11-30 06:36:44 +00003357
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003358
Reid Spencere7c3c602006-11-30 06:36:44 +00003359#define YYTERROR 1
3360#define YYERRCODE 256
3361
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003362
3363/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
3364 If N is 0, then set CURRENT to the empty location which ends
3365 the previous symbol: RHS[0] (always defined). */
3366
3367#define YYRHSLOC(Rhs, K) ((Rhs)[K])
3368#ifndef YYLLOC_DEFAULT
3369# define YYLLOC_DEFAULT(Current, Rhs, N) \
3370 do \
3371 if (N) \
3372 { \
3373 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
3374 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
3375 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
3376 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
3377 } \
3378 else \
3379 { \
3380 (Current).first_line = (Current).last_line = \
3381 YYRHSLOC (Rhs, 0).last_line; \
3382 (Current).first_column = (Current).last_column = \
3383 YYRHSLOC (Rhs, 0).last_column; \
3384 } \
3385 while (0)
Reid Spencere7c3c602006-11-30 06:36:44 +00003386#endif
3387
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003388
3389/* YY_LOCATION_PRINT -- Print the location on the stream.
3390 This macro was not mandated originally: define only if we know
3391 we won't break user code: when these are the locations we know. */
3392
3393#ifndef YY_LOCATION_PRINT
3394# if YYLTYPE_IS_TRIVIAL
3395# define YY_LOCATION_PRINT(File, Loc) \
3396 fprintf (File, "%d.%d-%d.%d", \
3397 (Loc).first_line, (Loc).first_column, \
3398 (Loc).last_line, (Loc).last_column)
3399# else
3400# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
3401# endif
3402#endif
3403
3404
3405/* YYLEX -- calling `yylex' with the right arguments. */
3406
Reid Spencer950bf602007-01-26 08:19:09 +00003407#ifdef YYLEX_PARAM
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003408# define YYLEX yylex (YYLEX_PARAM)
Reid Spencer950bf602007-01-26 08:19:09 +00003409#else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003410# define YYLEX yylex ()
Chris Lattner4227bdb2007-02-19 07:34:02 +00003411#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003412
3413/* Enable debugging if requested. */
3414#if YYDEBUG
3415
3416# ifndef YYFPRINTF
3417# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
3418# define YYFPRINTF fprintf
3419# endif
3420
3421# define YYDPRINTF(Args) \
3422do { \
3423 if (yydebug) \
3424 YYFPRINTF Args; \
3425} while (0)
3426
3427# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
3428do { \
3429 if (yydebug) \
3430 { \
3431 YYFPRINTF (stderr, "%s ", Title); \
3432 yysymprint (stderr, \
3433 Type, Value); \
3434 YYFPRINTF (stderr, "\n"); \
3435 } \
3436} while (0)
3437
3438/*------------------------------------------------------------------.
3439| yy_stack_print -- Print the state stack from its BOTTOM up to its |
3440| TOP (included). |
3441`------------------------------------------------------------------*/
3442
3443#if defined (__STDC__) || defined (__cplusplus)
3444static void
3445yy_stack_print (short int *bottom, short int *top)
Chris Lattner4227bdb2007-02-19 07:34:02 +00003446#else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003447static void
3448yy_stack_print (bottom, top)
3449 short int *bottom;
3450 short int *top;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003451#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003452{
3453 YYFPRINTF (stderr, "Stack now");
3454 for (/* Nothing. */; bottom <= top; ++bottom)
3455 YYFPRINTF (stderr, " %d", *bottom);
3456 YYFPRINTF (stderr, "\n");
3457}
3458
3459# define YY_STACK_PRINT(Bottom, Top) \
3460do { \
3461 if (yydebug) \
3462 yy_stack_print ((Bottom), (Top)); \
3463} while (0)
3464
3465
3466/*------------------------------------------------.
3467| Report that the YYRULE is going to be reduced. |
3468`------------------------------------------------*/
3469
3470#if defined (__STDC__) || defined (__cplusplus)
3471static void
3472yy_reduce_print (int yyrule)
3473#else
3474static void
3475yy_reduce_print (yyrule)
3476 int yyrule;
Chris Lattnercf3d0612007-02-13 06:04:17 +00003477#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003478{
3479 int yyi;
3480 unsigned long int yylno = yyrline[yyrule];
3481 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu), ",
3482 yyrule - 1, yylno);
3483 /* Print the symbols being reduced, and their result. */
3484 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
3485 YYFPRINTF (stderr, "%s ", yytname[yyrhs[yyi]]);
3486 YYFPRINTF (stderr, "-> %s\n", yytname[yyr1[yyrule]]);
3487}
Reid Spencer9d6565a2007-02-15 02:26:10 +00003488
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003489# define YY_REDUCE_PRINT(Rule) \
3490do { \
3491 if (yydebug) \
3492 yy_reduce_print (Rule); \
3493} while (0)
Reid Spencer9d6565a2007-02-15 02:26:10 +00003494
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003495/* Nonzero means print parse trace. It is left uninitialized so that
3496 multiple parsers can coexist. */
3497int yydebug;
3498#else /* !YYDEBUG */
3499# define YYDPRINTF(Args)
3500# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
3501# define YY_STACK_PRINT(Bottom, Top)
3502# define YY_REDUCE_PRINT(Rule)
3503#endif /* !YYDEBUG */
Reid Spencer9d6565a2007-02-15 02:26:10 +00003504
Reid Spencer9d6565a2007-02-15 02:26:10 +00003505
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003506/* YYINITDEPTH -- initial size of the parser's stacks. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003507#ifndef YYINITDEPTH
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003508# define YYINITDEPTH 200
Reid Spencere7c3c602006-11-30 06:36:44 +00003509#endif
3510
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003511/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
3512 if the built-in stack extension method is used).
Reid Spencere7c3c602006-11-30 06:36:44 +00003513
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003514 Do not make this value too large; the results are undefined if
3515 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
3516 evaluated with infinite-precision integer arithmetic. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003517
3518#ifndef YYMAXDEPTH
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003519# define YYMAXDEPTH 10000
Reid Spencere7c3c602006-11-30 06:36:44 +00003520#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003521
Reid Spencere7c3c602006-11-30 06:36:44 +00003522
3523
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003524#if YYERROR_VERBOSE
Reid Spencere7c3c602006-11-30 06:36:44 +00003525
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003526# ifndef yystrlen
3527# if defined (__GLIBC__) && defined (_STRING_H)
3528# define yystrlen strlen
3529# else
3530/* Return the length of YYSTR. */
3531static YYSIZE_T
3532# if defined (__STDC__) || defined (__cplusplus)
3533yystrlen (const char *yystr)
3534# else
3535yystrlen (yystr)
3536 const char *yystr;
3537# endif
Chris Lattner4227bdb2007-02-19 07:34:02 +00003538{
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003539 const char *yys = yystr;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003540
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003541 while (*yys++ != '\0')
3542 continue;
3543
3544 return yys - yystr - 1;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003545}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003546# endif
3547# endif
Chris Lattner4227bdb2007-02-19 07:34:02 +00003548
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003549# ifndef yystpcpy
3550# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
3551# define yystpcpy stpcpy
3552# else
3553/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
3554 YYDEST. */
3555static char *
3556# if defined (__STDC__) || defined (__cplusplus)
3557yystpcpy (char *yydest, const char *yysrc)
3558# else
3559yystpcpy (yydest, yysrc)
3560 char *yydest;
3561 const char *yysrc;
3562# endif
Chris Lattner4227bdb2007-02-19 07:34:02 +00003563{
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003564 char *yyd = yydest;
3565 const char *yys = yysrc;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003566
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003567 while ((*yyd++ = *yys++) != '\0')
3568 continue;
3569
3570 return yyd - 1;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003571}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003572# endif
3573# endif
Chris Lattner4227bdb2007-02-19 07:34:02 +00003574
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003575# ifndef yytnamerr
3576/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
3577 quotes and backslashes, so that it's suitable for yyerror. The
3578 heuristic is that double-quoting is unnecessary unless the string
3579 contains an apostrophe, a comma, or backslash (other than
3580 backslash-backslash). YYSTR is taken from yytname. If YYRES is
3581 null, do not copy; instead, return the length of what the result
3582 would have been. */
3583static YYSIZE_T
3584yytnamerr (char *yyres, const char *yystr)
3585{
3586 if (*yystr == '"')
3587 {
3588 size_t yyn = 0;
3589 char const *yyp = yystr;
3590
3591 for (;;)
3592 switch (*++yyp)
3593 {
3594 case '\'':
3595 case ',':
3596 goto do_not_strip_quotes;
3597
3598 case '\\':
3599 if (*++yyp != '\\')
3600 goto do_not_strip_quotes;
3601 /* Fall through. */
3602 default:
3603 if (yyres)
3604 yyres[yyn] = *yyp;
3605 yyn++;
3606 break;
3607
3608 case '"':
3609 if (yyres)
3610 yyres[yyn] = '\0';
3611 return yyn;
3612 }
3613 do_not_strip_quotes: ;
3614 }
3615
3616 if (! yyres)
3617 return yystrlen (yystr);
3618
3619 return yystpcpy (yyres, yystr) - yyres;
3620}
3621# endif
3622
3623#endif /* YYERROR_VERBOSE */
3624
Reid Spencer9d6565a2007-02-15 02:26:10 +00003625
3626
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003627#if YYDEBUG
3628/*--------------------------------.
3629| Print this symbol on YYOUTPUT. |
3630`--------------------------------*/
Reid Spencer9d6565a2007-02-15 02:26:10 +00003631
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003632#if defined (__STDC__) || defined (__cplusplus)
3633static void
3634yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
Chris Lattner4227bdb2007-02-19 07:34:02 +00003635#else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003636static void
3637yysymprint (yyoutput, yytype, yyvaluep)
3638 FILE *yyoutput;
3639 int yytype;
3640 YYSTYPE *yyvaluep;
3641#endif
3642{
3643 /* Pacify ``unused variable'' warnings. */
3644 (void) yyvaluep;
3645
3646 if (yytype < YYNTOKENS)
3647 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
3648 else
3649 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
3650
3651
3652# ifdef YYPRINT
3653 if (yytype < YYNTOKENS)
3654 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
3655# endif
3656 switch (yytype)
3657 {
3658 default:
3659 break;
3660 }
3661 YYFPRINTF (yyoutput, ")");
3662}
3663
3664#endif /* ! YYDEBUG */
3665/*-----------------------------------------------.
3666| Release the memory associated to this symbol. |
3667`-----------------------------------------------*/
3668
3669#if defined (__STDC__) || defined (__cplusplus)
3670static void
3671yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
3672#else
3673static void
3674yydestruct (yymsg, yytype, yyvaluep)
3675 const char *yymsg;
3676 int yytype;
3677 YYSTYPE *yyvaluep;
3678#endif
3679{
3680 /* Pacify ``unused variable'' warnings. */
3681 (void) yyvaluep;
3682
3683 if (!yymsg)
3684 yymsg = "Deleting";
3685 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
3686
3687 switch (yytype)
3688 {
3689
3690 default:
3691 break;
3692 }
3693}
3694
3695
3696/* Prevent warnings from -Wmissing-prototypes. */
3697
3698#ifdef YYPARSE_PARAM
3699# if defined (__STDC__) || defined (__cplusplus)
3700int yyparse (void *YYPARSE_PARAM);
3701# else
3702int yyparse ();
3703# endif
3704#else /* ! YYPARSE_PARAM */
3705#if defined (__STDC__) || defined (__cplusplus)
Reid Spencere7c3c602006-11-30 06:36:44 +00003706int yyparse (void);
Chris Lattner4227bdb2007-02-19 07:34:02 +00003707#else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003708int yyparse ();
3709#endif
3710#endif /* ! YYPARSE_PARAM */
3711
3712
3713
3714/* The look-ahead symbol. */
3715int yychar;
3716
3717/* The semantic value of the look-ahead symbol. */
3718YYSTYPE yylval;
3719
3720/* Number of syntax errors so far. */
3721int yynerrs;
3722
3723
3724
3725/*----------.
3726| yyparse. |
3727`----------*/
3728
3729#ifdef YYPARSE_PARAM
3730# if defined (__STDC__) || defined (__cplusplus)
3731int yyparse (void *YYPARSE_PARAM)
3732# else
3733int yyparse (YYPARSE_PARAM)
3734 void *YYPARSE_PARAM;
3735# endif
3736#else /* ! YYPARSE_PARAM */
3737#if defined (__STDC__) || defined (__cplusplus)
3738int
3739yyparse (void)
3740#else
3741int
3742yyparse ()
3743
3744#endif
3745#endif
3746{
3747
3748 int yystate;
3749 int yyn;
3750 int yyresult;
3751 /* Number of tokens to shift before error messages enabled. */
3752 int yyerrstatus;
3753 /* Look-ahead token as an internal (translated) token number. */
3754 int yytoken = 0;
3755
3756 /* Three stacks and their tools:
3757 `yyss': related to states,
3758 `yyvs': related to semantic values,
3759 `yyls': related to locations.
3760
3761 Refer to the stacks thru separate pointers, to allow yyoverflow
3762 to reallocate them elsewhere. */
3763
3764 /* The state stack. */
3765 short int yyssa[YYINITDEPTH];
3766 short int *yyss = yyssa;
3767 short int *yyssp;
3768
3769 /* The semantic value stack. */
3770 YYSTYPE yyvsa[YYINITDEPTH];
3771 YYSTYPE *yyvs = yyvsa;
3772 YYSTYPE *yyvsp;
3773
3774
3775
Chris Lattnercf3d0612007-02-13 06:04:17 +00003776#define YYPOPSTACK (yyvsp--, yyssp--)
Reid Spencere7c3c602006-11-30 06:36:44 +00003777
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003778 YYSIZE_T yystacksize = YYINITDEPTH;
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003779
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003780 /* The variables used to return semantic value and location from the
3781 action routines. */
3782 YYSTYPE yyval;
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003783
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003784
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003785 /* When reducing, the number of symbols on the RHS of the reduced
3786 rule. */
Chris Lattnercf3d0612007-02-13 06:04:17 +00003787 int yylen;
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003788
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003789 YYDPRINTF ((stderr, "Starting parse\n"));
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003790
Reid Spencere7c3c602006-11-30 06:36:44 +00003791 yystate = 0;
3792 yyerrstatus = 0;
3793 yynerrs = 0;
3794 yychar = YYEMPTY; /* Cause a token to be read. */
3795
3796 /* Initialize stack pointers.
3797 Waste one element of value and location stack
3798 so that they stay on the same level as the state stack.
3799 The wasted elements are never initialized. */
3800
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003801 yyssp = yyss;
Reid Spencere7c3c602006-11-30 06:36:44 +00003802 yyvsp = yyvs;
3803
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003804 goto yysetstate;
Reid Spencere7c3c602006-11-30 06:36:44 +00003805
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003806/*------------------------------------------------------------.
3807| yynewstate -- Push a new state, which is found in yystate. |
3808`------------------------------------------------------------*/
3809 yynewstate:
3810 /* In all cases, when you get here, the value and location stacks
3811 have just been pushed. so pushing a state here evens the stacks.
3812 */
3813 yyssp++;
Reid Spencere7c3c602006-11-30 06:36:44 +00003814
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003815 yysetstate:
3816 *yyssp = yystate;
3817
3818 if (yyss + yystacksize - 1 <= yyssp)
Reid Spencere7c3c602006-11-30 06:36:44 +00003819 {
3820 /* Get the current used size of the three stacks, in elements. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003821 YYSIZE_T yysize = yyssp - yyss + 1;
Reid Spencere7c3c602006-11-30 06:36:44 +00003822
3823#ifdef yyoverflow
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003824 {
3825 /* Give user a chance to reallocate the stack. Use copies of
3826 these so that the &'s don't force the real ones into
3827 memory. */
3828 YYSTYPE *yyvs1 = yyvs;
3829 short int *yyss1 = yyss;
Reid Spencere7c3c602006-11-30 06:36:44 +00003830
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003831
3832 /* Each stack pointer address is followed by the size of the
3833 data in use in that stack, in bytes. This used to be a
3834 conditional around just the two extra args, but that might
3835 be undefined if yyoverflow is a macro. */
3836 yyoverflow (YY_("memory exhausted"),
3837 &yyss1, yysize * sizeof (*yyssp),
3838 &yyvs1, yysize * sizeof (*yyvsp),
3839
3840 &yystacksize);
3841
3842 yyss = yyss1;
3843 yyvs = yyvs1;
3844 }
Reid Spencere7c3c602006-11-30 06:36:44 +00003845#else /* no yyoverflow */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003846# ifndef YYSTACK_RELOCATE
3847 goto yyexhaustedlab;
3848# else
Reid Spencere7c3c602006-11-30 06:36:44 +00003849 /* Extend the stack our own way. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003850 if (YYMAXDEPTH <= yystacksize)
3851 goto yyexhaustedlab;
Reid Spencere7c3c602006-11-30 06:36:44 +00003852 yystacksize *= 2;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003853 if (YYMAXDEPTH < yystacksize)
Reid Spencere7c3c602006-11-30 06:36:44 +00003854 yystacksize = YYMAXDEPTH;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003855
3856 {
3857 short int *yyss1 = yyss;
3858 union yyalloc *yyptr =
3859 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
3860 if (! yyptr)
3861 goto yyexhaustedlab;
3862 YYSTACK_RELOCATE (yyss);
3863 YYSTACK_RELOCATE (yyvs);
3864
3865# undef YYSTACK_RELOCATE
3866 if (yyss1 != yyssa)
3867 YYSTACK_FREE (yyss1);
3868 }
3869# endif
Reid Spencere7c3c602006-11-30 06:36:44 +00003870#endif /* no yyoverflow */
3871
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003872 yyssp = yyss + yysize - 1;
3873 yyvsp = yyvs + yysize - 1;
Reid Spencere7c3c602006-11-30 06:36:44 +00003874
3875
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003876 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
3877 (unsigned long int) yystacksize));
3878
3879 if (yyss + yystacksize - 1 <= yyssp)
Reid Spencere7c3c602006-11-30 06:36:44 +00003880 YYABORT;
3881 }
3882
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003883 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
Reid Spencere7c3c602006-11-30 06:36:44 +00003884
3885 goto yybackup;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003886
3887/*-----------.
3888| yybackup. |
3889`-----------*/
3890yybackup:
Reid Spencere7c3c602006-11-30 06:36:44 +00003891
Chris Lattnercf3d0612007-02-13 06:04:17 +00003892/* Do appropriate processing given the current state. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003893/* Read a look-ahead token if we need one and don't already have one. */
Chris Lattnercf3d0612007-02-13 06:04:17 +00003894/* yyresume: */
Reid Spencere7c3c602006-11-30 06:36:44 +00003895
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003896 /* First try to decide what to do without reference to look-ahead token. */
Reid Spencerb7046c72007-01-29 05:41:34 +00003897
Reid Spencere7c3c602006-11-30 06:36:44 +00003898 yyn = yypact[yystate];
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003899 if (yyn == YYPACT_NINF)
Reid Spencere7c3c602006-11-30 06:36:44 +00003900 goto yydefault;
3901
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003902 /* Not known => get a look-ahead token if don't already have one. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003903
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003904 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003905 if (yychar == YYEMPTY)
3906 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003907 YYDPRINTF ((stderr, "Reading a token: "));
Reid Spencere7c3c602006-11-30 06:36:44 +00003908 yychar = YYLEX;
3909 }
3910
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003911 if (yychar <= YYEOF)
Reid Spencere7c3c602006-11-30 06:36:44 +00003912 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003913 yychar = yytoken = YYEOF;
3914 YYDPRINTF ((stderr, "Now at end of input.\n"));
Reid Spencere7c3c602006-11-30 06:36:44 +00003915 }
3916 else
3917 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003918 yytoken = YYTRANSLATE (yychar);
3919 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
Reid Spencere7c3c602006-11-30 06:36:44 +00003920 }
3921
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003922 /* If the proper action on seeing token YYTOKEN is to reduce or to
3923 detect an error, take that action. */
3924 yyn += yytoken;
3925 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
Reid Spencere7c3c602006-11-30 06:36:44 +00003926 goto yydefault;
3927 yyn = yytable[yyn];
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003928 if (yyn <= 0)
Reid Spencere7c3c602006-11-30 06:36:44 +00003929 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003930 if (yyn == 0 || yyn == YYTABLE_NINF)
Reid Spencere7c3c602006-11-30 06:36:44 +00003931 goto yyerrlab;
3932 yyn = -yyn;
3933 goto yyreduce;
3934 }
3935
3936 if (yyn == YYFINAL)
3937 YYACCEPT;
3938
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003939 /* Shift the look-ahead token. */
3940 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
Reid Spencerb7046c72007-01-29 05:41:34 +00003941
Chris Lattnercf3d0612007-02-13 06:04:17 +00003942 /* Discard the token being shifted unless it is eof. */
Reid Spencerb7046c72007-01-29 05:41:34 +00003943 if (yychar != YYEOF)
3944 yychar = YYEMPTY;
3945
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003946 *++yyvsp = yylval;
3947
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003948
3949 /* Count tokens shifted since error; after three, turn off error
3950 status. */
3951 if (yyerrstatus)
3952 yyerrstatus--;
Chris Lattnercf3d0612007-02-13 06:04:17 +00003953
3954 yystate = yyn;
Reid Spencere7c3c602006-11-30 06:36:44 +00003955 goto yynewstate;
3956
Chris Lattner4227bdb2007-02-19 07:34:02 +00003957
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003958/*-----------------------------------------------------------.
3959| yydefault -- do the default action for the current state. |
3960`-----------------------------------------------------------*/
3961yydefault:
Reid Spencere7c3c602006-11-30 06:36:44 +00003962 yyn = yydefact[yystate];
3963 if (yyn == 0)
3964 goto yyerrlab;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003965 goto yyreduce;
Reid Spencere7c3c602006-11-30 06:36:44 +00003966
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003967
3968/*-----------------------------.
3969| yyreduce -- Do a reduction. |
3970`-----------------------------*/
Reid Spencere7c3c602006-11-30 06:36:44 +00003971yyreduce:
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003972 /* yyn is the number of a rule to reduce with. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003973 yylen = yyr2[yyn];
3974
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003975 /* If YYLEN is nonzero, implement the default value of the action:
3976 `$$ = $1'.
3977
3978 Otherwise, the following line sets YYVAL to garbage.
3979 This behavior is undocumented and Bison
3980 users should not rely upon it. Assigning to YYVAL
3981 unconditionally makes the parser a bit smaller, and it avoids a
3982 GCC warning that YYVAL may be used uninitialized. */
3983 yyval = yyvsp[1-yylen];
3984
3985
3986 YY_REDUCE_PRINT (yyn);
3987 switch (yyn)
Reid Spencere7c3c602006-11-30 06:36:44 +00003988 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003989 case 3:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00003990#line 1916 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003991 {
3992 if ((yyvsp[0].UIntVal) > (uint32_t)INT32_MAX) // Outside of my range!
Reid Spencer950bf602007-01-26 08:19:09 +00003993 error("Value too large for type");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003994 (yyval.SIntVal) = (int32_t)(yyvsp[0].UIntVal);
3995 ;}
3996 break;
3997
3998 case 5:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00003999#line 1925 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004000 {
4001 if ((yyvsp[0].UInt64Val) > (uint64_t)INT64_MAX) // Outside of my range!
Reid Spencer950bf602007-01-26 08:19:09 +00004002 error("Value too large for type");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004003 (yyval.SInt64Val) = (int64_t)(yyvsp[0].UInt64Val);
4004 ;}
4005 break;
4006
4007 case 26:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004008#line 1947 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004009 { (yyval.IPred) = ICmpInst::ICMP_EQ; ;}
4010 break;
4011
4012 case 27:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004013#line 1947 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004014 { (yyval.IPred) = ICmpInst::ICMP_NE; ;}
4015 break;
4016
4017 case 28:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004018#line 1948 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004019 { (yyval.IPred) = ICmpInst::ICMP_SLT; ;}
4020 break;
4021
4022 case 29:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004023#line 1948 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004024 { (yyval.IPred) = ICmpInst::ICMP_SGT; ;}
4025 break;
4026
4027 case 30:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004028#line 1949 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004029 { (yyval.IPred) = ICmpInst::ICMP_SLE; ;}
4030 break;
4031
4032 case 31:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004033#line 1949 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004034 { (yyval.IPred) = ICmpInst::ICMP_SGE; ;}
4035 break;
4036
4037 case 32:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004038#line 1950 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004039 { (yyval.IPred) = ICmpInst::ICMP_ULT; ;}
4040 break;
4041
4042 case 33:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004043#line 1950 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004044 { (yyval.IPred) = ICmpInst::ICMP_UGT; ;}
4045 break;
4046
4047 case 34:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004048#line 1951 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004049 { (yyval.IPred) = ICmpInst::ICMP_ULE; ;}
4050 break;
4051
4052 case 35:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004053#line 1951 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004054 { (yyval.IPred) = ICmpInst::ICMP_UGE; ;}
4055 break;
4056
4057 case 36:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004058#line 1955 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004059 { (yyval.FPred) = FCmpInst::FCMP_OEQ; ;}
4060 break;
4061
4062 case 37:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004063#line 1955 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004064 { (yyval.FPred) = FCmpInst::FCMP_ONE; ;}
4065 break;
4066
4067 case 38:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004068#line 1956 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004069 { (yyval.FPred) = FCmpInst::FCMP_OLT; ;}
4070 break;
4071
4072 case 39:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004073#line 1956 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004074 { (yyval.FPred) = FCmpInst::FCMP_OGT; ;}
4075 break;
4076
4077 case 40:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004078#line 1957 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004079 { (yyval.FPred) = FCmpInst::FCMP_OLE; ;}
4080 break;
4081
4082 case 41:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004083#line 1957 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004084 { (yyval.FPred) = FCmpInst::FCMP_OGE; ;}
4085 break;
4086
4087 case 42:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004088#line 1958 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004089 { (yyval.FPred) = FCmpInst::FCMP_ORD; ;}
4090 break;
4091
4092 case 43:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004093#line 1958 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004094 { (yyval.FPred) = FCmpInst::FCMP_UNO; ;}
4095 break;
4096
4097 case 44:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004098#line 1959 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004099 { (yyval.FPred) = FCmpInst::FCMP_UEQ; ;}
4100 break;
4101
4102 case 45:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004103#line 1959 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004104 { (yyval.FPred) = FCmpInst::FCMP_UNE; ;}
4105 break;
4106
4107 case 46:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004108#line 1960 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004109 { (yyval.FPred) = FCmpInst::FCMP_ULT; ;}
4110 break;
4111
4112 case 47:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004113#line 1960 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004114 { (yyval.FPred) = FCmpInst::FCMP_UGT; ;}
4115 break;
4116
4117 case 48:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004118#line 1961 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004119 { (yyval.FPred) = FCmpInst::FCMP_ULE; ;}
4120 break;
4121
4122 case 49:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004123#line 1961 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004124 { (yyval.FPred) = FCmpInst::FCMP_UGE; ;}
4125 break;
4126
4127 case 50:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004128#line 1962 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004129 { (yyval.FPred) = FCmpInst::FCMP_TRUE; ;}
4130 break;
4131
4132 case 51:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004133#line 1963 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004134 { (yyval.FPred) = FCmpInst::FCMP_FALSE; ;}
4135 break;
4136
4137 case 81:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004138#line 1994 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004139 {
4140 (yyval.StrVal) = (yyvsp[-1].StrVal);
4141 ;}
4142 break;
4143
4144 case 82:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004145#line 1997 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004146 {
4147 (yyval.StrVal) = 0;
4148 ;}
4149 break;
4150
4151 case 83:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004152#line 2002 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004153 { (yyval.Linkage) = GlobalValue::InternalLinkage; ;}
4154 break;
4155
4156 case 84:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004157#line 2003 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004158 { (yyval.Linkage) = GlobalValue::LinkOnceLinkage; ;}
4159 break;
4160
4161 case 85:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004162#line 2004 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004163 { (yyval.Linkage) = GlobalValue::WeakLinkage; ;}
4164 break;
4165
4166 case 86:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004167#line 2005 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004168 { (yyval.Linkage) = GlobalValue::AppendingLinkage; ;}
4169 break;
4170
4171 case 87:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004172#line 2006 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004173 { (yyval.Linkage) = GlobalValue::DLLImportLinkage; ;}
4174 break;
4175
4176 case 88:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004177#line 2007 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004178 { (yyval.Linkage) = GlobalValue::DLLExportLinkage; ;}
4179 break;
4180
4181 case 89:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004182#line 2008 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004183 { (yyval.Linkage) = GlobalValue::ExternalWeakLinkage; ;}
4184 break;
4185
4186 case 90:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004187#line 2009 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004188 { (yyval.Linkage) = GlobalValue::ExternalLinkage; ;}
4189 break;
4190
4191 case 91:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004192#line 2013 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
4193 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::C; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004194 break;
4195
Reid Spencere59f4932007-04-16 03:05:01 +00004196 case 92:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004197#line 2014 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
4198 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::C; ;}
Reid Spencere59f4932007-04-16 03:05:01 +00004199 break;
4200
4201 case 93:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004202#line 2015 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
4203 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::CSRet; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004204 break;
4205
4206 case 94:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004207#line 2016 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
4208 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::Fast; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004209 break;
4210
4211 case 95:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004212#line 2017 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
4213 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::Cold; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004214 break;
4215
4216 case 96:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004217#line 2018 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
4218 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::X86_StdCall; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004219 break;
4220
4221 case 97:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004222#line 2019 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
4223 { (yyval.UIntVal) = lastCallingConv = OldCallingConv::X86_FastCall; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004224 break;
4225
4226 case 98:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004227#line 2020 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004228 {
4229 if ((unsigned)(yyvsp[0].UInt64Val) != (yyvsp[0].UInt64Val))
Reid Spencer950bf602007-01-26 08:19:09 +00004230 error("Calling conv too large");
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004231 (yyval.UIntVal) = lastCallingConv = (yyvsp[0].UInt64Val);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004232 ;}
4233 break;
4234
4235 case 99:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004236#line 2030 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004237 { (yyval.UIntVal) = 0; ;}
4238 break;
4239
4240 case 100:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004241#line 2031 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004242 {
4243 (yyval.UIntVal) = (yyvsp[0].UInt64Val);
4244 if ((yyval.UIntVal) != 0 && !isPowerOf2_32((yyval.UIntVal)))
Reid Spencer950bf602007-01-26 08:19:09 +00004245 error("Alignment must be a power of two");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004246 ;}
4247 break;
4248
4249 case 101:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004250#line 2039 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004251 { (yyval.UIntVal) = 0; ;}
4252 break;
4253
4254 case 102:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004255#line 2040 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004256 {
4257 (yyval.UIntVal) = (yyvsp[0].UInt64Val);
4258 if ((yyval.UIntVal) != 0 && !isPowerOf2_32((yyval.UIntVal)))
Reid Spencer950bf602007-01-26 08:19:09 +00004259 error("Alignment must be a power of two");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004260 ;}
4261 break;
4262
4263 case 103:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004264#line 2048 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004265 {
4266 for (unsigned i = 0, e = strlen((yyvsp[0].StrVal)); i != e; ++i)
4267 if ((yyvsp[0].StrVal)[i] == '"' || (yyvsp[0].StrVal)[i] == '\\')
Reid Spencer950bf602007-01-26 08:19:09 +00004268 error("Invalid character in section name");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004269 (yyval.StrVal) = (yyvsp[0].StrVal);
4270 ;}
4271 break;
4272
4273 case 104:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004274#line 2057 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004275 { (yyval.StrVal) = 0; ;}
4276 break;
4277
4278 case 105:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004279#line 2058 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004280 { (yyval.StrVal) = (yyvsp[0].StrVal); ;}
4281 break;
4282
4283 case 106:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004284#line 2065 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004285 {;}
4286 break;
4287
Reid Spencere59f4932007-04-16 03:05:01 +00004288 case 107:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004289#line 2066 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencere59f4932007-04-16 03:05:01 +00004290 {;}
4291 break;
4292
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004293 case 108:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004294#line 2070 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004295 {
4296 CurGV->setSection((yyvsp[0].StrVal));
4297 free((yyvsp[0].StrVal));
4298 ;}
4299 break;
4300
4301 case 109:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004302#line 2074 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004303 {
4304 if ((yyvsp[0].UInt64Val) != 0 && !isPowerOf2_32((yyvsp[0].UInt64Val)))
Reid Spencer950bf602007-01-26 08:19:09 +00004305 error("Alignment must be a power of two");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004306 CurGV->setAlignment((yyvsp[0].UInt64Val));
Reid Spencer950bf602007-01-26 08:19:09 +00004307
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004308 ;}
4309 break;
4310
4311 case 111:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004312#line 2091 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004313 {
4314 (yyval.TypeVal).PAT = new PATypeHolder((yyvsp[0].PrimType).T);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004315 (yyval.TypeVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004316 ;}
4317 break;
4318
4319 case 113:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004320#line 2099 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004321 {
4322 (yyval.TypeVal).PAT = new PATypeHolder((yyvsp[0].PrimType).T);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004323 (yyval.TypeVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004324 ;}
4325 break;
4326
4327 case 114:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004328#line 2106 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004329 {
Reid Spencer950bf602007-01-26 08:19:09 +00004330 if (!UpRefs.empty())
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004331 error("Invalid upreference in type: " + (*(yyvsp[0].TypeVal).PAT)->getDescription());
4332 (yyval.TypeVal) = (yyvsp[0].TypeVal);
4333 ;}
4334 break;
4335
4336 case 127:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004337#line 2120 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004338 {
4339 (yyval.TypeVal).PAT = new PATypeHolder((yyvsp[0].PrimType).T);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004340 (yyval.TypeVal).S.copy((yyvsp[0].PrimType).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004341 ;}
4342 break;
4343
4344 case 128:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004345#line 2124 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004346 {
4347 (yyval.TypeVal).PAT = new PATypeHolder(OpaqueType::get());
Reid Spencerbb1fd572007-03-21 17:15:50 +00004348 (yyval.TypeVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004349 ;}
4350 break;
4351
4352 case 129:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004353#line 2128 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004354 { // Named types are also simple types...
Reid Spencerbb1fd572007-03-21 17:15:50 +00004355 (yyval.TypeVal).S.copy(getTypeSign((yyvsp[0].ValIDVal)));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004356 const Type* tmp = getType((yyvsp[0].ValIDVal));
4357 (yyval.TypeVal).PAT = new PATypeHolder(tmp);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004358 ;}
4359 break;
4360
4361 case 130:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004362#line 2133 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004363 { // Type UpReference
4364 if ((yyvsp[0].UInt64Val) > (uint64_t)~0U)
Reid Spencer950bf602007-01-26 08:19:09 +00004365 error("Value out of range");
4366 OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004367 UpRefs.push_back(UpRefRecord((unsigned)(yyvsp[0].UInt64Val), OT)); // Add to vector...
4368 (yyval.TypeVal).PAT = new PATypeHolder(OT);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004369 (yyval.TypeVal).S.makeSignless();
Reid Spencer950bf602007-01-26 08:19:09 +00004370 UR_OUT("New Upreference!\n");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004371 ;}
4372 break;
4373
4374 case 131:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004375#line 2142 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004376 { // Function derived type?
Reid Spencerbb1fd572007-03-21 17:15:50 +00004377 (yyval.TypeVal).S.makeComposite((yyvsp[-3].TypeVal).S);
Reid Spencer950bf602007-01-26 08:19:09 +00004378 std::vector<const Type*> Params;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004379 for (std::list<llvm::PATypeInfo>::iterator I = (yyvsp[-1].TypeList)->begin(),
4380 E = (yyvsp[-1].TypeList)->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004381 Params.push_back(I->PAT->get());
Reid Spencerbb1fd572007-03-21 17:15:50 +00004382 (yyval.TypeVal).S.add(I->S);
Reid Spencer52402b02007-01-02 05:45:11 +00004383 }
Reid Spencer950bf602007-01-26 08:19:09 +00004384 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
4385 if (isVarArg) Params.pop_back();
4386
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004387 ParamAttrsList *PAL = 0;
4388 if (lastCallingConv == OldCallingConv::CSRet) {
4389 ParamAttrsVector Attrs;
4390 ParamAttrsWithIndex PAWI;
4391 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
4392 Attrs.push_back(PAWI);
4393 PAL = ParamAttrsList::get(Attrs);
4394 }
4395
Reid Spencer7b5d4662007-04-09 06:16:21 +00004396 const FunctionType *FTy =
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004397 FunctionType::get((yyvsp[-3].TypeVal).PAT->get(), Params, isVarArg, PAL);
Reid Spencer7b5d4662007-04-09 06:16:21 +00004398
4399 (yyval.TypeVal).PAT = new PATypeHolder( HandleUpRefs(FTy, (yyval.TypeVal).S) );
Reid Spencerbb1fd572007-03-21 17:15:50 +00004400 delete (yyvsp[-3].TypeVal).PAT; // Delete the return type handle
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004401 delete (yyvsp[-1].TypeList); // Delete the argument list
4402 ;}
4403 break;
4404
4405 case 132:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004406#line 2169 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004407 { // Sized array type?
Reid Spencerbb1fd572007-03-21 17:15:50 +00004408 (yyval.TypeVal).S.makeComposite((yyvsp[-1].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004409 (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(ArrayType::get((yyvsp[-1].TypeVal).PAT->get(),
Reid Spencerbb1fd572007-03-21 17:15:50 +00004410 (unsigned)(yyvsp[-3].UInt64Val)), (yyval.TypeVal).S));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004411 delete (yyvsp[-1].TypeVal).PAT;
4412 ;}
4413 break;
4414
4415 case 133:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004416#line 2175 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004417 { // Vector type?
Reid Spencerbb1fd572007-03-21 17:15:50 +00004418 const llvm::Type* ElemTy = (yyvsp[-1].TypeVal).PAT->get();
4419 if ((unsigned)(yyvsp[-3].UInt64Val) != (yyvsp[-3].UInt64Val))
4420 error("Unsigned result not equal to signed result");
4421 if (!(ElemTy->isInteger() || ElemTy->isFloatingPoint()))
4422 error("Elements of a VectorType must be integer or floating point");
4423 if (!isPowerOf2_32((yyvsp[-3].UInt64Val)))
4424 error("VectorType length should be a power of 2");
4425 (yyval.TypeVal).S.makeComposite((yyvsp[-1].TypeVal).S);
4426 (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(VectorType::get(ElemTy,
4427 (unsigned)(yyvsp[-3].UInt64Val)), (yyval.TypeVal).S));
4428 delete (yyvsp[-1].TypeVal).PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004429 ;}
4430 break;
4431
4432 case 134:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004433#line 2188 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004434 { // Structure type?
Reid Spencer950bf602007-01-26 08:19:09 +00004435 std::vector<const Type*> Elements;
Reid Spencerbb1fd572007-03-21 17:15:50 +00004436 (yyval.TypeVal).S.makeComposite();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004437 for (std::list<llvm::PATypeInfo>::iterator I = (yyvsp[-1].TypeList)->begin(),
Reid Spencerbb1fd572007-03-21 17:15:50 +00004438 E = (yyvsp[-1].TypeList)->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004439 Elements.push_back(I->PAT->get());
Reid Spencerbb1fd572007-03-21 17:15:50 +00004440 (yyval.TypeVal).S.add(I->S);
4441 }
4442 (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements), (yyval.TypeVal).S));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004443 delete (yyvsp[-1].TypeList);
4444 ;}
4445 break;
4446
4447 case 135:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004448#line 2199 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004449 { // Empty structure type?
4450 (yyval.TypeVal).PAT = new PATypeHolder(StructType::get(std::vector<const Type*>()));
Reid Spencerbb1fd572007-03-21 17:15:50 +00004451 (yyval.TypeVal).S.makeComposite();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004452 ;}
4453 break;
4454
4455 case 136:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004456#line 2203 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004457 { // Packed Structure type?
Reid Spencerbb1fd572007-03-21 17:15:50 +00004458 (yyval.TypeVal).S.makeComposite();
Reid Spencer950bf602007-01-26 08:19:09 +00004459 std::vector<const Type*> Elements;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004460 for (std::list<llvm::PATypeInfo>::iterator I = (yyvsp[-2].TypeList)->begin(),
4461 E = (yyvsp[-2].TypeList)->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004462 Elements.push_back(I->PAT->get());
Reid Spencerbb1fd572007-03-21 17:15:50 +00004463 (yyval.TypeVal).S.add(I->S);
Reid Spencered96d1e2007-02-08 09:08:52 +00004464 delete I->PAT;
Reid Spencer52402b02007-01-02 05:45:11 +00004465 }
Reid Spencerbb1fd572007-03-21 17:15:50 +00004466 (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements, true),
4467 (yyval.TypeVal).S));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004468 delete (yyvsp[-2].TypeList);
4469 ;}
4470 break;
4471
4472 case 137:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004473#line 2216 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004474 { // Empty packed structure type?
4475 (yyval.TypeVal).PAT = new PATypeHolder(StructType::get(std::vector<const Type*>(),true));
Reid Spencerbb1fd572007-03-21 17:15:50 +00004476 (yyval.TypeVal).S.makeComposite();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004477 ;}
4478 break;
4479
4480 case 138:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004481#line 2220 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004482 { // Pointer type?
4483 if ((yyvsp[-1].TypeVal).PAT->get() == Type::LabelTy)
Reid Spencer950bf602007-01-26 08:19:09 +00004484 error("Cannot form a pointer to a basic block");
Reid Spencerbb1fd572007-03-21 17:15:50 +00004485 (yyval.TypeVal).S.makeComposite((yyvsp[-1].TypeVal).S);
4486 (yyval.TypeVal).PAT = new PATypeHolder(HandleUpRefs(PointerType::get((yyvsp[-1].TypeVal).PAT->get()),
4487 (yyval.TypeVal).S));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004488 delete (yyvsp[-1].TypeVal).PAT;
4489 ;}
4490 break;
4491
4492 case 139:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004493#line 2234 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004494 {
4495 (yyval.TypeList) = new std::list<PATypeInfo>();
4496 (yyval.TypeList)->push_back((yyvsp[0].TypeVal));
4497 ;}
4498 break;
4499
4500 case 140:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004501#line 2238 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004502 {
4503 ((yyval.TypeList)=(yyvsp[-2].TypeList))->push_back((yyvsp[0].TypeVal));
4504 ;}
4505 break;
4506
4507 case 142:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004508#line 2246 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004509 {
Reid Spencer950bf602007-01-26 08:19:09 +00004510 PATypeInfo VoidTI;
Reid Spencered96d1e2007-02-08 09:08:52 +00004511 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004512 VoidTI.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004513 ((yyval.TypeList)=(yyvsp[-2].TypeList))->push_back(VoidTI);
4514 ;}
4515 break;
4516
4517 case 143:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004518#line 2252 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004519 {
4520 (yyval.TypeList) = new std::list<PATypeInfo>();
Reid Spencer950bf602007-01-26 08:19:09 +00004521 PATypeInfo VoidTI;
Reid Spencered96d1e2007-02-08 09:08:52 +00004522 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004523 VoidTI.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004524 (yyval.TypeList)->push_back(VoidTI);
4525 ;}
4526 break;
4527
4528 case 144:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004529#line 2259 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004530 {
4531 (yyval.TypeList) = new std::list<PATypeInfo>();
4532 ;}
4533 break;
4534
4535 case 145:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004536#line 2271 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004537 { // Nonempty unsized arr
4538 const ArrayType *ATy = dyn_cast<ArrayType>((yyvsp[-3].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004539 if (ATy == 0)
4540 error("Cannot make array constant with type: '" +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004541 (yyvsp[-3].TypeVal).PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004542 const Type *ETy = ATy->getElementType();
4543 int NumElements = ATy->getNumElements();
4544
4545 // Verify that we have the correct size...
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004546 if (NumElements != -1 && NumElements != (int)(yyvsp[-1].ConstVector)->size())
Reid Spencer950bf602007-01-26 08:19:09 +00004547 error("Type mismatch: constant sized array initialized with " +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004548 utostr((yyvsp[-1].ConstVector)->size()) + " arguments, but has size of " +
Reid Spencer950bf602007-01-26 08:19:09 +00004549 itostr(NumElements) + "");
4550
4551 // Verify all elements are correct type!
4552 std::vector<Constant*> Elems;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004553 for (unsigned i = 0; i < (yyvsp[-1].ConstVector)->size(); i++) {
4554 Constant *C = (*(yyvsp[-1].ConstVector))[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004555 const Type* ValTy = C->getType();
4556 if (ETy != ValTy)
4557 error("Element #" + utostr(i) + " is not of type '" +
4558 ETy->getDescription() +"' as required!\nIt is of type '"+
4559 ValTy->getDescription() + "'");
4560 Elems.push_back(C);
4561 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004562 (yyval.ConstVal).C = ConstantArray::get(ATy, Elems);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004563 (yyval.ConstVal).S.copy((yyvsp[-3].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004564 delete (yyvsp[-3].TypeVal).PAT;
4565 delete (yyvsp[-1].ConstVector);
4566 ;}
4567 break;
4568
4569 case 146:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004570#line 2301 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004571 {
4572 const ArrayType *ATy = dyn_cast<ArrayType>((yyvsp[-2].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004573 if (ATy == 0)
4574 error("Cannot make array constant with type: '" +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004575 (yyvsp[-2].TypeVal).PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004576 int NumElements = ATy->getNumElements();
4577 if (NumElements != -1 && NumElements != 0)
4578 error("Type mismatch: constant sized array initialized with 0"
4579 " arguments, but has size of " + itostr(NumElements) +"");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004580 (yyval.ConstVal).C = ConstantArray::get(ATy, std::vector<Constant*>());
Reid Spencerbb1fd572007-03-21 17:15:50 +00004581 (yyval.ConstVal).S.copy((yyvsp[-2].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004582 delete (yyvsp[-2].TypeVal).PAT;
4583 ;}
4584 break;
4585
4586 case 147:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004587#line 2314 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004588 {
4589 const ArrayType *ATy = dyn_cast<ArrayType>((yyvsp[-2].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004590 if (ATy == 0)
4591 error("Cannot make array constant with type: '" +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004592 (yyvsp[-2].TypeVal).PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004593 int NumElements = ATy->getNumElements();
4594 const Type *ETy = dyn_cast<IntegerType>(ATy->getElementType());
4595 if (!ETy || cast<IntegerType>(ETy)->getBitWidth() != 8)
4596 error("String arrays require type i8, not '" + ETy->getDescription() +
4597 "'");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004598 char *EndStr = UnEscapeLexed((yyvsp[0].StrVal), true);
4599 if (NumElements != -1 && NumElements != (EndStr-(yyvsp[0].StrVal)))
Reid Spencer950bf602007-01-26 08:19:09 +00004600 error("Can't build string constant of size " +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004601 itostr((int)(EndStr-(yyvsp[0].StrVal))) + " when array has size " +
Reid Spencer950bf602007-01-26 08:19:09 +00004602 itostr(NumElements) + "");
4603 std::vector<Constant*> Vals;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004604 for (char *C = (char *)(yyvsp[0].StrVal); C != (char *)EndStr; ++C)
Reid Spencer950bf602007-01-26 08:19:09 +00004605 Vals.push_back(ConstantInt::get(ETy, *C));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004606 free((yyvsp[0].StrVal));
4607 (yyval.ConstVal).C = ConstantArray::get(ATy, Vals);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004608 (yyval.ConstVal).S.copy((yyvsp[-2].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004609 delete (yyvsp[-2].TypeVal).PAT;
4610 ;}
4611 break;
4612
4613 case 148:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004614#line 2337 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004615 { // Nonempty unsized arr
4616 const VectorType *PTy = dyn_cast<VectorType>((yyvsp[-3].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004617 if (PTy == 0)
4618 error("Cannot make packed constant with type: '" +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004619 (yyvsp[-3].TypeVal).PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004620 const Type *ETy = PTy->getElementType();
4621 int NumElements = PTy->getNumElements();
4622 // Verify that we have the correct size...
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004623 if (NumElements != -1 && NumElements != (int)(yyvsp[-1].ConstVector)->size())
Reid Spencer950bf602007-01-26 08:19:09 +00004624 error("Type mismatch: constant sized packed initialized with " +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004625 utostr((yyvsp[-1].ConstVector)->size()) + " arguments, but has size of " +
Reid Spencer950bf602007-01-26 08:19:09 +00004626 itostr(NumElements) + "");
4627 // Verify all elements are correct type!
4628 std::vector<Constant*> Elems;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004629 for (unsigned i = 0; i < (yyvsp[-1].ConstVector)->size(); i++) {
4630 Constant *C = (*(yyvsp[-1].ConstVector))[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004631 const Type* ValTy = C->getType();
4632 if (ETy != ValTy)
4633 error("Element #" + utostr(i) + " is not of type '" +
4634 ETy->getDescription() +"' as required!\nIt is of type '"+
4635 ValTy->getDescription() + "'");
4636 Elems.push_back(C);
4637 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004638 (yyval.ConstVal).C = ConstantVector::get(PTy, Elems);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004639 (yyval.ConstVal).S.copy((yyvsp[-3].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004640 delete (yyvsp[-3].TypeVal).PAT;
4641 delete (yyvsp[-1].ConstVector);
4642 ;}
4643 break;
4644
4645 case 149:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004646#line 2365 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004647 {
4648 const StructType *STy = dyn_cast<StructType>((yyvsp[-3].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004649 if (STy == 0)
4650 error("Cannot make struct constant with type: '" +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004651 (yyvsp[-3].TypeVal).PAT->get()->getDescription() + "'");
4652 if ((yyvsp[-1].ConstVector)->size() != STy->getNumContainedTypes())
Reid Spencer950bf602007-01-26 08:19:09 +00004653 error("Illegal number of initializers for structure type");
4654
4655 // Check to ensure that constants are compatible with the type initializer!
4656 std::vector<Constant*> Fields;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004657 for (unsigned i = 0, e = (yyvsp[-1].ConstVector)->size(); i != e; ++i) {
4658 Constant *C = (*(yyvsp[-1].ConstVector))[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004659 if (C->getType() != STy->getElementType(i))
4660 error("Expected type '" + STy->getElementType(i)->getDescription() +
4661 "' for element #" + utostr(i) + " of structure initializer");
4662 Fields.push_back(C);
4663 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004664 (yyval.ConstVal).C = ConstantStruct::get(STy, Fields);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004665 (yyval.ConstVal).S.copy((yyvsp[-3].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004666 delete (yyvsp[-3].TypeVal).PAT;
4667 delete (yyvsp[-1].ConstVector);
4668 ;}
4669 break;
4670
4671 case 150:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004672#line 2387 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004673 {
4674 const StructType *STy = dyn_cast<StructType>((yyvsp[-2].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004675 if (STy == 0)
4676 error("Cannot make struct constant with type: '" +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004677 (yyvsp[-2].TypeVal).PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004678 if (STy->getNumContainedTypes() != 0)
4679 error("Illegal number of initializers for structure type");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004680 (yyval.ConstVal).C = ConstantStruct::get(STy, std::vector<Constant*>());
Reid Spencerbb1fd572007-03-21 17:15:50 +00004681 (yyval.ConstVal).S.copy((yyvsp[-2].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004682 delete (yyvsp[-2].TypeVal).PAT;
4683 ;}
4684 break;
4685
4686 case 151:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004687#line 2398 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004688 {
4689 const StructType *STy = dyn_cast<StructType>((yyvsp[-5].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004690 if (STy == 0)
4691 error("Cannot make packed struct constant with type: '" +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004692 (yyvsp[-5].TypeVal).PAT->get()->getDescription() + "'");
4693 if ((yyvsp[-2].ConstVector)->size() != STy->getNumContainedTypes())
Reid Spencer950bf602007-01-26 08:19:09 +00004694 error("Illegal number of initializers for packed structure type");
4695
4696 // Check to ensure that constants are compatible with the type initializer!
4697 std::vector<Constant*> Fields;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004698 for (unsigned i = 0, e = (yyvsp[-2].ConstVector)->size(); i != e; ++i) {
4699 Constant *C = (*(yyvsp[-2].ConstVector))[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004700 if (C->getType() != STy->getElementType(i))
4701 error("Expected type '" + STy->getElementType(i)->getDescription() +
4702 "' for element #" + utostr(i) + " of packed struct initializer");
4703 Fields.push_back(C);
4704 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004705 (yyval.ConstVal).C = ConstantStruct::get(STy, Fields);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004706 (yyval.ConstVal).S.copy((yyvsp[-5].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004707 delete (yyvsp[-5].TypeVal).PAT;
4708 delete (yyvsp[-2].ConstVector);
4709 ;}
4710 break;
4711
4712 case 152:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004713#line 2420 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004714 {
4715 const StructType *STy = dyn_cast<StructType>((yyvsp[-4].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004716 if (STy == 0)
4717 error("Cannot make packed struct constant with type: '" +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004718 (yyvsp[-4].TypeVal).PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004719 if (STy->getNumContainedTypes() != 0)
4720 error("Illegal number of initializers for packed structure type");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004721 (yyval.ConstVal).C = ConstantStruct::get(STy, std::vector<Constant*>());
Reid Spencerbb1fd572007-03-21 17:15:50 +00004722 (yyval.ConstVal).S.copy((yyvsp[-4].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004723 delete (yyvsp[-4].TypeVal).PAT;
4724 ;}
4725 break;
4726
4727 case 153:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004728#line 2431 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004729 {
4730 const PointerType *PTy = dyn_cast<PointerType>((yyvsp[-1].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004731 if (PTy == 0)
4732 error("Cannot make null pointer constant with type: '" +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004733 (yyvsp[-1].TypeVal).PAT->get()->getDescription() + "'");
4734 (yyval.ConstVal).C = ConstantPointerNull::get(PTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004735 (yyval.ConstVal).S.copy((yyvsp[-1].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004736 delete (yyvsp[-1].TypeVal).PAT;
4737 ;}
4738 break;
4739
4740 case 154:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004741#line 2440 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004742 {
4743 (yyval.ConstVal).C = UndefValue::get((yyvsp[-1].TypeVal).PAT->get());
Reid Spencerbb1fd572007-03-21 17:15:50 +00004744 (yyval.ConstVal).S.copy((yyvsp[-1].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004745 delete (yyvsp[-1].TypeVal).PAT;
4746 ;}
4747 break;
4748
4749 case 155:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004750#line 2445 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004751 {
4752 const PointerType *Ty = dyn_cast<PointerType>((yyvsp[-1].TypeVal).PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004753 if (Ty == 0)
4754 error("Global const reference must be a pointer type, not" +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004755 (yyvsp[-1].TypeVal).PAT->get()->getDescription());
Reid Spencer950bf602007-01-26 08:19:09 +00004756
4757 // ConstExprs can exist in the body of a function, thus creating
4758 // GlobalValues whenever they refer to a variable. Because we are in
4759 // the context of a function, getExistingValue will search the functions
4760 // symbol table instead of the module symbol table for the global symbol,
4761 // which throws things all off. To get around this, we just tell
4762 // getExistingValue that we are at global scope here.
4763 //
4764 Function *SavedCurFn = CurFun.CurrentFunction;
4765 CurFun.CurrentFunction = 0;
Reid Spencerbb1fd572007-03-21 17:15:50 +00004766 (yyvsp[0].ValIDVal).S.copy((yyvsp[-1].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004767 Value *V = getExistingValue(Ty, (yyvsp[0].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00004768 CurFun.CurrentFunction = SavedCurFn;
4769
4770 // If this is an initializer for a constant pointer, which is referencing a
4771 // (currently) undefined variable, create a stub now that shall be replaced
4772 // in the future with the right type of variable.
4773 //
4774 if (V == 0) {
4775 assert(isa<PointerType>(Ty) && "Globals may only be used as pointers");
4776 const PointerType *PT = cast<PointerType>(Ty);
4777
4778 // First check to see if the forward references value is already created!
4779 PerModuleInfo::GlobalRefsType::iterator I =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004780 CurModule.GlobalRefs.find(std::make_pair(PT, (yyvsp[0].ValIDVal)));
Reid Spencer950bf602007-01-26 08:19:09 +00004781
4782 if (I != CurModule.GlobalRefs.end()) {
4783 V = I->second; // Placeholder already exists, use it...
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004784 (yyvsp[0].ValIDVal).destroy();
Reid Spencer950bf602007-01-26 08:19:09 +00004785 } else {
4786 std::string Name;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004787 if ((yyvsp[0].ValIDVal).Type == ValID::NameVal) Name = (yyvsp[0].ValIDVal).Name;
Reid Spencer950bf602007-01-26 08:19:09 +00004788
4789 // Create the forward referenced global.
4790 GlobalValue *GV;
4791 if (const FunctionType *FTy =
4792 dyn_cast<FunctionType>(PT->getElementType())) {
4793 GV = new Function(FTy, GlobalValue::ExternalLinkage, Name,
4794 CurModule.CurrentModule);
4795 } else {
4796 GV = new GlobalVariable(PT->getElementType(), false,
4797 GlobalValue::ExternalLinkage, 0,
4798 Name, CurModule.CurrentModule);
4799 }
4800
4801 // Keep track of the fact that we have a forward ref to recycle it
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004802 CurModule.GlobalRefs.insert(std::make_pair(std::make_pair(PT, (yyvsp[0].ValIDVal)), GV));
Reid Spencer950bf602007-01-26 08:19:09 +00004803 V = GV;
4804 }
4805 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004806 (yyval.ConstVal).C = cast<GlobalValue>(V);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004807 (yyval.ConstVal).S.copy((yyvsp[-1].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004808 delete (yyvsp[-1].TypeVal).PAT; // Free the type handle
4809 ;}
4810 break;
4811
4812 case 156:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004813#line 2504 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004814 {
4815 if ((yyvsp[-1].TypeVal).PAT->get() != (yyvsp[0].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004816 error("Mismatched types for constant expression");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004817 (yyval.ConstVal) = (yyvsp[0].ConstVal);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004818 (yyval.ConstVal).S.copy((yyvsp[-1].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004819 delete (yyvsp[-1].TypeVal).PAT;
4820 ;}
4821 break;
4822
4823 case 157:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004824#line 2511 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004825 {
4826 const Type *Ty = (yyvsp[-1].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00004827 if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
4828 error("Cannot create a null initialized value of this type");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004829 (yyval.ConstVal).C = Constant::getNullValue(Ty);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004830 (yyval.ConstVal).S.copy((yyvsp[-1].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004831 delete (yyvsp[-1].TypeVal).PAT;
4832 ;}
4833 break;
4834
4835 case 158:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004836#line 2519 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004837 { // integral constants
4838 const Type *Ty = (yyvsp[-1].PrimType).T;
4839 if (!ConstantInt::isValueValidForType(Ty, (yyvsp[0].SInt64Val)))
Reid Spencer950bf602007-01-26 08:19:09 +00004840 error("Constant value doesn't fit in type");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004841 (yyval.ConstVal).C = ConstantInt::get(Ty, (yyvsp[0].SInt64Val));
Reid Spencerbb1fd572007-03-21 17:15:50 +00004842 (yyval.ConstVal).S.makeSigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004843 ;}
4844 break;
4845
4846 case 159:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004847#line 2526 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004848 { // integral constants
4849 const Type *Ty = (yyvsp[-1].PrimType).T;
4850 if (!ConstantInt::isValueValidForType(Ty, (yyvsp[0].UInt64Val)))
Reid Spencer950bf602007-01-26 08:19:09 +00004851 error("Constant value doesn't fit in type");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004852 (yyval.ConstVal).C = ConstantInt::get(Ty, (yyvsp[0].UInt64Val));
Reid Spencerbb1fd572007-03-21 17:15:50 +00004853 (yyval.ConstVal).S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004854 ;}
4855 break;
4856
4857 case 160:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004858#line 2533 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004859 { // Boolean constants
4860 (yyval.ConstVal).C = ConstantInt::get(Type::Int1Ty, true);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004861 (yyval.ConstVal).S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004862 ;}
4863 break;
4864
4865 case 161:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004866#line 2537 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004867 { // Boolean constants
4868 (yyval.ConstVal).C = ConstantInt::get(Type::Int1Ty, false);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004869 (yyval.ConstVal).S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004870 ;}
4871 break;
4872
4873 case 162:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004874#line 2541 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004875 { // Float & Double constants
4876 if (!ConstantFP::isValueValidForType((yyvsp[-1].PrimType).T, (yyvsp[0].FPVal)))
Reid Spencer950bf602007-01-26 08:19:09 +00004877 error("Floating point constant invalid for type");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004878 (yyval.ConstVal).C = ConstantFP::get((yyvsp[-1].PrimType).T, (yyvsp[0].FPVal));
Reid Spencerbb1fd572007-03-21 17:15:50 +00004879 (yyval.ConstVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004880 ;}
4881 break;
4882
4883 case 163:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004884#line 2550 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004885 {
4886 const Type* SrcTy = (yyvsp[-3].ConstVal).C->getType();
4887 const Type* DstTy = (yyvsp[-1].TypeVal).PAT->get();
Reid Spencerbb1fd572007-03-21 17:15:50 +00004888 Signedness SrcSign((yyvsp[-3].ConstVal).S);
4889 Signedness DstSign((yyvsp[-1].TypeVal).S);
Reid Spencer950bf602007-01-26 08:19:09 +00004890 if (!SrcTy->isFirstClassType())
4891 error("cast constant expression from a non-primitive type: '" +
4892 SrcTy->getDescription() + "'");
4893 if (!DstTy->isFirstClassType())
4894 error("cast constant expression to a non-primitive type: '" +
4895 DstTy->getDescription() + "'");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004896 (yyval.ConstVal).C = cast<Constant>(getCast((yyvsp[-5].CastOpVal), (yyvsp[-3].ConstVal).C, SrcSign, DstTy, DstSign));
Reid Spencerbb1fd572007-03-21 17:15:50 +00004897 (yyval.ConstVal).S.copy(DstSign);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004898 delete (yyvsp[-1].TypeVal).PAT;
4899 ;}
4900 break;
4901
4902 case 164:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004903#line 2565 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004904 {
4905 const Type *Ty = (yyvsp[-2].ConstVal).C->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00004906 if (!isa<PointerType>(Ty))
4907 error("GetElementPtr requires a pointer operand");
4908
Reid Spencer950bf602007-01-26 08:19:09 +00004909 std::vector<Constant*> CIndices;
Reid Spencerff0e4482007-04-16 00:40:57 +00004910 upgradeGEPCEIndices((yyvsp[-2].ConstVal).C->getType(), (yyvsp[-1].ValueList), CIndices);
Reid Spencer950bf602007-01-26 08:19:09 +00004911
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004912 delete (yyvsp[-1].ValueList);
4913 (yyval.ConstVal).C = ConstantExpr::getGetElementPtr((yyvsp[-2].ConstVal).C, &CIndices[0], CIndices.size());
Reid Spencerbb1fd572007-03-21 17:15:50 +00004914 (yyval.ConstVal).S.copy(getElementSign((yyvsp[-2].ConstVal), CIndices));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004915 ;}
4916 break;
4917
4918 case 165:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004919#line 2577 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004920 {
4921 if (!(yyvsp[-5].ConstVal).C->getType()->isInteger() ||
4922 cast<IntegerType>((yyvsp[-5].ConstVal).C->getType())->getBitWidth() != 1)
Reid Spencer950bf602007-01-26 08:19:09 +00004923 error("Select condition must be bool type");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004924 if ((yyvsp[-3].ConstVal).C->getType() != (yyvsp[-1].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004925 error("Select operand types must match");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004926 (yyval.ConstVal).C = ConstantExpr::getSelect((yyvsp[-5].ConstVal).C, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004927 (yyval.ConstVal).S.copy((yyvsp[-3].ConstVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004928 ;}
4929 break;
4930
4931 case 166:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004932#line 2586 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004933 {
4934 const Type *Ty = (yyvsp[-3].ConstVal).C->getType();
4935 if (Ty != (yyvsp[-1].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004936 error("Binary operator types must match");
4937 // First, make sure we're dealing with the right opcode by upgrading from
4938 // obsolete versions.
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004939 Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[-5].BinaryOpVal), Ty, (yyvsp[-3].ConstVal).S);
Reid Spencer950bf602007-01-26 08:19:09 +00004940
4941 // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs.
4942 // To retain backward compatibility with these early compilers, we emit a
4943 // cast to the appropriate integer type automatically if we are in the
4944 // broken case. See PR424 for more information.
4945 if (!isa<PointerType>(Ty)) {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004946 (yyval.ConstVal).C = ConstantExpr::get(Opcode, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
Reid Spencer950bf602007-01-26 08:19:09 +00004947 } else {
4948 const Type *IntPtrTy = 0;
4949 switch (CurModule.CurrentModule->getPointerSize()) {
4950 case Module::Pointer32: IntPtrTy = Type::Int32Ty; break;
4951 case Module::Pointer64: IntPtrTy = Type::Int64Ty; break;
4952 default: error("invalid pointer binary constant expr");
4953 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004954 (yyval.ConstVal).C = ConstantExpr::get(Opcode,
4955 ConstantExpr::getCast(Instruction::PtrToInt, (yyvsp[-3].ConstVal).C, IntPtrTy),
4956 ConstantExpr::getCast(Instruction::PtrToInt, (yyvsp[-1].ConstVal).C, IntPtrTy));
4957 (yyval.ConstVal).C = ConstantExpr::getCast(Instruction::IntToPtr, (yyval.ConstVal).C, Ty);
Reid Spencer950bf602007-01-26 08:19:09 +00004958 }
Reid Spencerbb1fd572007-03-21 17:15:50 +00004959 (yyval.ConstVal).S.copy((yyvsp[-3].ConstVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004960 ;}
4961 break;
4962
4963 case 167:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004964#line 2614 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004965 {
4966 const Type* Ty = (yyvsp[-3].ConstVal).C->getType();
4967 if (Ty != (yyvsp[-1].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004968 error("Logical operator types must match");
4969 if (!Ty->isInteger()) {
Reid Spencer9d6565a2007-02-15 02:26:10 +00004970 if (!isa<VectorType>(Ty) ||
4971 !cast<VectorType>(Ty)->getElementType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00004972 error("Logical operator requires integer operands");
4973 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004974 Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[-5].BinaryOpVal), Ty, (yyvsp[-3].ConstVal).S);
4975 (yyval.ConstVal).C = ConstantExpr::get(Opcode, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004976 (yyval.ConstVal).S.copy((yyvsp[-3].ConstVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004977 ;}
4978 break;
4979
4980 case 168:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004981#line 2627 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004982 {
4983 const Type* Ty = (yyvsp[-3].ConstVal).C->getType();
4984 if (Ty != (yyvsp[-1].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004985 error("setcc operand types must match");
4986 unsigned short pred;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004987 Instruction::OtherOps Opcode = getCompareOp((yyvsp[-5].BinaryOpVal), pred, Ty, (yyvsp[-3].ConstVal).S);
4988 (yyval.ConstVal).C = ConstantExpr::getCompare(Opcode, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004989 (yyval.ConstVal).S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004990 ;}
4991 break;
4992
4993 case 169:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004994#line 2636 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004995 {
4996 if ((yyvsp[-3].ConstVal).C->getType() != (yyvsp[-1].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004997 error("icmp operand types must match");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004998 (yyval.ConstVal).C = ConstantExpr::getCompare((yyvsp[-5].IPred), (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004999 (yyval.ConstVal).S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005000 ;}
5001 break;
5002
5003 case 170:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005004#line 2642 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005005 {
5006 if ((yyvsp[-3].ConstVal).C->getType() != (yyvsp[-1].ConstVal).C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00005007 error("fcmp operand types must match");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005008 (yyval.ConstVal).C = ConstantExpr::getCompare((yyvsp[-5].FPred), (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005009 (yyval.ConstVal).S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005010 ;}
5011 break;
5012
5013 case 171:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005014#line 2648 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005015 {
5016 if (!(yyvsp[-1].ConstVal).C->getType()->isInteger() ||
5017 cast<IntegerType>((yyvsp[-1].ConstVal).C->getType())->getBitWidth() != 8)
Reid Spencer950bf602007-01-26 08:19:09 +00005018 error("Shift count for shift constant must be unsigned byte");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005019 const Type* Ty = (yyvsp[-3].ConstVal).C->getType();
5020 if (!(yyvsp[-3].ConstVal).C->getType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00005021 error("Shift constant expression requires integer operand");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005022 Constant *ShiftAmt = ConstantExpr::getZExt((yyvsp[-1].ConstVal).C, Ty);
5023 (yyval.ConstVal).C = ConstantExpr::get(getBinaryOp((yyvsp[-5].BinaryOpVal), Ty, (yyvsp[-3].ConstVal).S), (yyvsp[-3].ConstVal).C, ShiftAmt);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005024 (yyval.ConstVal).S.copy((yyvsp[-3].ConstVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005025 ;}
5026 break;
5027
5028 case 172:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005029#line 2659 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005030 {
5031 if (!ExtractElementInst::isValidOperands((yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C))
Reid Spencer950bf602007-01-26 08:19:09 +00005032 error("Invalid extractelement operands");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005033 (yyval.ConstVal).C = ConstantExpr::getExtractElement((yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005034 (yyval.ConstVal).S.copy((yyvsp[-3].ConstVal).S.get(0));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005035 ;}
5036 break;
5037
5038 case 173:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005039#line 2665 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005040 {
5041 if (!InsertElementInst::isValidOperands((yyvsp[-5].ConstVal).C, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C))
Reid Spencer950bf602007-01-26 08:19:09 +00005042 error("Invalid insertelement operands");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005043 (yyval.ConstVal).C = ConstantExpr::getInsertElement((yyvsp[-5].ConstVal).C, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005044 (yyval.ConstVal).S.copy((yyvsp[-5].ConstVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005045 ;}
5046 break;
5047
5048 case 174:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005049#line 2671 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005050 {
5051 if (!ShuffleVectorInst::isValidOperands((yyvsp[-5].ConstVal).C, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C))
Reid Spencer950bf602007-01-26 08:19:09 +00005052 error("Invalid shufflevector operands");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005053 (yyval.ConstVal).C = ConstantExpr::getShuffleVector((yyvsp[-5].ConstVal).C, (yyvsp[-3].ConstVal).C, (yyvsp[-1].ConstVal).C);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005054 (yyval.ConstVal).S.copy((yyvsp[-5].ConstVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005055 ;}
5056 break;
5057
5058 case 175:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005059#line 2682 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005060 { ((yyval.ConstVector) = (yyvsp[-2].ConstVector))->push_back((yyvsp[0].ConstVal)); ;}
5061 break;
5062
5063 case 176:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005064#line 2683 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005065 {
5066 (yyval.ConstVector) = new std::vector<ConstInfo>();
5067 (yyval.ConstVector)->push_back((yyvsp[0].ConstVal));
5068 ;}
5069 break;
5070
5071 case 177:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005072#line 2692 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005073 { (yyval.BoolVal) = false; ;}
5074 break;
5075
5076 case 178:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005077#line 2693 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005078 { (yyval.BoolVal) = true; ;}
5079 break;
5080
5081 case 179:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005082#line 2705 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005083 {
5084 (yyval.ModuleVal) = ParserResult = (yyvsp[0].ModuleVal);
Reid Spencer950bf602007-01-26 08:19:09 +00005085 CurModule.ModuleDone();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005086 ;}
5087 break;
5088
5089 case 180:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005090#line 2714 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005091 { (yyval.ModuleVal) = (yyvsp[-1].ModuleVal); CurFun.FunctionDone(); ;}
5092 break;
5093
5094 case 181:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005095#line 2715 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005096 { (yyval.ModuleVal) = (yyvsp[-1].ModuleVal); ;}
5097 break;
5098
5099 case 182:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005100#line 2716 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005101 { (yyval.ModuleVal) = (yyvsp[-3].ModuleVal); ;}
5102 break;
5103
5104 case 183:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005105#line 2717 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005106 { (yyval.ModuleVal) = (yyvsp[-1].ModuleVal); ;}
5107 break;
5108
5109 case 184:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005110#line 2718 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005111 {
5112 (yyval.ModuleVal) = CurModule.CurrentModule;
Reid Spencer950bf602007-01-26 08:19:09 +00005113 // Emit an error if there are any unresolved types left.
5114 if (!CurModule.LateResolveTypes.empty()) {
5115 const ValID &DID = CurModule.LateResolveTypes.begin()->first;
5116 if (DID.Type == ValID::NameVal) {
5117 error("Reference to an undefined type: '"+DID.getName() + "'");
5118 } else {
5119 error("Reference to an undefined type: #" + itostr(DID.Num));
5120 }
5121 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005122 ;}
5123 break;
5124
5125 case 185:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005126#line 2734 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005127 {
Reid Spencer950bf602007-01-26 08:19:09 +00005128 // Eagerly resolve types. This is not an optimization, this is a
5129 // requirement that is due to the fact that we could have this:
5130 //
5131 // %list = type { %list * }
5132 // %list = type { %list * } ; repeated type decl
5133 //
5134 // If types are not resolved eagerly, then the two types will not be
5135 // determined to be the same type!
5136 //
Reid Spencerbb1fd572007-03-21 17:15:50 +00005137 ResolveTypeTo((yyvsp[-2].StrVal), (yyvsp[0].TypeVal).PAT->get(), (yyvsp[0].TypeVal).S);
Reid Spencer950bf602007-01-26 08:19:09 +00005138
Reid Spencerbb1fd572007-03-21 17:15:50 +00005139 if (!setTypeName((yyvsp[0].TypeVal), (yyvsp[-2].StrVal)) && !(yyvsp[-2].StrVal)) {
5140 // If this is a numbered type that is not a redefinition, add it to the
5141 // slot table.
5142 CurModule.Types.push_back((yyvsp[0].TypeVal).PAT->get());
5143 CurModule.TypeSigns.push_back((yyvsp[0].TypeVal).S);
Reid Spencera50d5962006-12-02 04:11:07 +00005144 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005145 delete (yyvsp[0].TypeVal).PAT;
5146 ;}
5147 break;
5148
5149 case 186:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005150#line 2754 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005151 { // Function prototypes can be in const pool
5152 ;}
5153 break;
5154
5155 case 187:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005156#line 2756 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005157 { // Asm blocks can be in the const pool
5158 ;}
5159 break;
5160
5161 case 188:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005162#line 2758 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005163 {
5164 if ((yyvsp[0].ConstVal).C == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00005165 error("Global value initializer is not a constant");
Reid Spencerbb1fd572007-03-21 17:15:50 +00005166 CurGV = ParseGlobalVariable((yyvsp[-3].StrVal), (yyvsp[-2].Linkage), (yyvsp[-1].BoolVal), (yyvsp[0].ConstVal).C->getType(), (yyvsp[0].ConstVal).C, (yyvsp[0].ConstVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005167 ;}
5168 break;
5169
5170 case 189:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005171#line 2762 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005172 {
Reid Spencer950bf602007-01-26 08:19:09 +00005173 CurGV = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005174 ;}
5175 break;
5176
5177 case 190:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005178#line 2765 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005179 {
5180 const Type *Ty = (yyvsp[0].TypeVal).PAT->get();
Reid Spencerbb1fd572007-03-21 17:15:50 +00005181 CurGV = ParseGlobalVariable((yyvsp[-3].StrVal), GlobalValue::ExternalLinkage, (yyvsp[-1].BoolVal), Ty, 0,
5182 (yyvsp[0].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005183 delete (yyvsp[0].TypeVal).PAT;
5184 ;}
5185 break;
5186
5187 case 191:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005188#line 2770 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005189 {
Reid Spencer950bf602007-01-26 08:19:09 +00005190 CurGV = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005191 ;}
5192 break;
5193
5194 case 192:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005195#line 2773 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005196 {
5197 const Type *Ty = (yyvsp[0].TypeVal).PAT->get();
Reid Spencerbb1fd572007-03-21 17:15:50 +00005198 CurGV = ParseGlobalVariable((yyvsp[-3].StrVal), GlobalValue::DLLImportLinkage, (yyvsp[-1].BoolVal), Ty, 0,
5199 (yyvsp[0].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005200 delete (yyvsp[0].TypeVal).PAT;
5201 ;}
5202 break;
5203
5204 case 193:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005205#line 2778 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005206 {
Reid Spencer950bf602007-01-26 08:19:09 +00005207 CurGV = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005208 ;}
5209 break;
5210
5211 case 194:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005212#line 2781 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005213 {
5214 const Type *Ty = (yyvsp[0].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005215 CurGV =
Reid Spencerbb1fd572007-03-21 17:15:50 +00005216 ParseGlobalVariable((yyvsp[-3].StrVal), GlobalValue::ExternalWeakLinkage, (yyvsp[-1].BoolVal), Ty, 0,
5217 (yyvsp[0].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005218 delete (yyvsp[0].TypeVal).PAT;
5219 ;}
5220 break;
5221
5222 case 195:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005223#line 2787 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005224 {
Reid Spencer950bf602007-01-26 08:19:09 +00005225 CurGV = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005226 ;}
5227 break;
5228
5229 case 196:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005230#line 2790 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005231 {
5232 ;}
5233 break;
5234
5235 case 197:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005236#line 2792 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005237 {
5238 ;}
5239 break;
5240
5241 case 198:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005242#line 2794 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005243 {
5244 ;}
5245 break;
5246
5247 case 199:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005248#line 2799 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005249 {
Reid Spencer950bf602007-01-26 08:19:09 +00005250 const std::string &AsmSoFar = CurModule.CurrentModule->getModuleInlineAsm();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005251 char *EndStr = UnEscapeLexed((yyvsp[0].StrVal), true);
5252 std::string NewAsm((yyvsp[0].StrVal), EndStr);
5253 free((yyvsp[0].StrVal));
Reid Spencer950bf602007-01-26 08:19:09 +00005254
5255 if (AsmSoFar.empty())
5256 CurModule.CurrentModule->setModuleInlineAsm(NewAsm);
5257 else
5258 CurModule.CurrentModule->setModuleInlineAsm(AsmSoFar+"\n"+NewAsm);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005259 ;}
5260 break;
5261
5262 case 200:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005263#line 2813 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005264 { (yyval.Endianness) = Module::BigEndian; ;}
5265 break;
5266
5267 case 201:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005268#line 2814 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005269 { (yyval.Endianness) = Module::LittleEndian; ;}
5270 break;
5271
5272 case 202:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005273#line 2818 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005274 {
5275 CurModule.setEndianness((yyvsp[0].Endianness));
5276 ;}
5277 break;
5278
5279 case 203:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005280#line 2821 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005281 {
5282 if ((yyvsp[0].UInt64Val) == 32)
Reid Spencer950bf602007-01-26 08:19:09 +00005283 CurModule.setPointerSize(Module::Pointer32);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005284 else if ((yyvsp[0].UInt64Val) == 64)
Reid Spencer950bf602007-01-26 08:19:09 +00005285 CurModule.setPointerSize(Module::Pointer64);
5286 else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005287 error("Invalid pointer size: '" + utostr((yyvsp[0].UInt64Val)) + "'");
5288 ;}
5289 break;
Reid Spencer9d6565a2007-02-15 02:26:10 +00005290
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005291 case 204:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005292#line 2829 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005293 {
5294 CurModule.CurrentModule->setTargetTriple((yyvsp[0].StrVal));
5295 free((yyvsp[0].StrVal));
5296 ;}
5297 break;
5298
5299 case 205:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005300#line 2833 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005301 {
5302 CurModule.CurrentModule->setDataLayout((yyvsp[0].StrVal));
5303 free((yyvsp[0].StrVal));
5304 ;}
5305 break;
5306
5307 case 207:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005308#line 2844 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005309 {
5310 CurModule.CurrentModule->addLibrary((yyvsp[0].StrVal));
5311 free((yyvsp[0].StrVal));
5312 ;}
5313 break;
5314
5315 case 208:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005316#line 2848 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005317 {
5318 CurModule.CurrentModule->addLibrary((yyvsp[0].StrVal));
5319 free((yyvsp[0].StrVal));
5320 ;}
5321 break;
5322
5323 case 209:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005324#line 2852 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005325 { ;}
5326 break;
5327
5328 case 213:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005329#line 2865 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005330 { (yyval.StrVal) = 0; ;}
5331 break;
5332
5333 case 214:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005334#line 2869 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005335 {
5336 if ((yyvsp[-1].TypeVal).PAT->get() == Type::VoidTy)
5337 error("void typed arguments are invalid");
5338 (yyval.ArgVal) = new std::pair<PATypeInfo, char*>((yyvsp[-1].TypeVal), (yyvsp[0].StrVal));
5339 ;}
5340 break;
5341
5342 case 215:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005343#line 2877 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005344 {
5345 (yyval.ArgList) = (yyvsp[-2].ArgList);
5346 (yyval.ArgList)->push_back(*(yyvsp[0].ArgVal));
5347 delete (yyvsp[0].ArgVal);
5348 ;}
5349 break;
5350
5351 case 216:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005352#line 2882 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005353 {
5354 (yyval.ArgList) = new std::vector<std::pair<PATypeInfo,char*> >();
5355 (yyval.ArgList)->push_back(*(yyvsp[0].ArgVal));
5356 delete (yyvsp[0].ArgVal);
5357 ;}
5358 break;
5359
5360 case 217:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005361#line 2890 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005362 { (yyval.ArgList) = (yyvsp[0].ArgList); ;}
5363 break;
5364
5365 case 218:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005366#line 2891 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005367 {
5368 (yyval.ArgList) = (yyvsp[-2].ArgList);
5369 PATypeInfo VoidTI;
5370 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005371 VoidTI.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005372 (yyval.ArgList)->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
5373 ;}
5374 break;
5375
5376 case 219:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005377#line 2898 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005378 {
5379 (yyval.ArgList) = new std::vector<std::pair<PATypeInfo,char*> >();
5380 PATypeInfo VoidTI;
5381 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005382 VoidTI.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005383 (yyval.ArgList)->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
5384 ;}
5385 break;
5386
5387 case 220:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005388#line 2905 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005389 { (yyval.ArgList) = 0; ;}
5390 break;
5391
5392 case 221:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005393#line 2909 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005394 {
5395 UnEscapeLexed((yyvsp[-5].StrVal));
5396 std::string FunctionName((yyvsp[-5].StrVal));
5397 free((yyvsp[-5].StrVal)); // Free strdup'd memory!
5398
5399 const Type* RetTy = (yyvsp[-6].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005400
5401 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
5402 error("LLVM functions cannot return aggregate types");
5403
Reid Spencerbb1fd572007-03-21 17:15:50 +00005404 Signedness FTySign;
5405 FTySign.makeComposite((yyvsp[-6].TypeVal).S);
Reid Spenceref9b9a72007-02-05 20:47:22 +00005406 std::vector<const Type*> ParamTyList;
Reid Spencer950bf602007-01-26 08:19:09 +00005407
5408 // In LLVM 2.0 the signatures of three varargs intrinsics changed to take
5409 // i8*. We check here for those names and override the parameter list
5410 // types to ensure the prototype is correct.
5411 if (FunctionName == "llvm.va_start" || FunctionName == "llvm.va_end") {
Reid Spenceref9b9a72007-02-05 20:47:22 +00005412 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
Reid Spencer950bf602007-01-26 08:19:09 +00005413 } else if (FunctionName == "llvm.va_copy") {
Reid Spenceref9b9a72007-02-05 20:47:22 +00005414 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
5415 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005416 } else if ((yyvsp[-3].ArgList)) { // If there are arguments...
Reid Spencer950bf602007-01-26 08:19:09 +00005417 for (std::vector<std::pair<PATypeInfo,char*> >::iterator
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005418 I = (yyvsp[-3].ArgList)->begin(), E = (yyvsp[-3].ArgList)->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00005419 const Type *Ty = I->first.PAT->get();
Reid Spenceref9b9a72007-02-05 20:47:22 +00005420 ParamTyList.push_back(Ty);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005421 FTySign.add(I->first.S);
Reid Spencer950bf602007-01-26 08:19:09 +00005422 }
5423 }
5424
Reid Spenceref9b9a72007-02-05 20:47:22 +00005425 bool isVarArg = ParamTyList.size() && ParamTyList.back() == Type::VoidTy;
5426 if (isVarArg)
5427 ParamTyList.pop_back();
Reid Spencer950bf602007-01-26 08:19:09 +00005428
Reid Spencerb7046c72007-01-29 05:41:34 +00005429 // Convert the CSRet calling convention into the corresponding parameter
5430 // attribute.
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005431 ParamAttrsList *PAL = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005432 if ((yyvsp[-7].UIntVal) == OldCallingConv::CSRet) {
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005433 ParamAttrsVector Attrs;
5434 ParamAttrsWithIndex PAWI;
5435 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
5436 Attrs.push_back(PAWI);
5437 PAL = ParamAttrsList::get(Attrs);
Reid Spencerb7046c72007-01-29 05:41:34 +00005438 }
5439
Reid Spencer7b5d4662007-04-09 06:16:21 +00005440 const FunctionType *FT =
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005441 FunctionType::get(RetTy, ParamTyList, isVarArg, PAL);
Reid Spencer950bf602007-01-26 08:19:09 +00005442 const PointerType *PFT = PointerType::get(FT);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005443 delete (yyvsp[-6].TypeVal).PAT;
Reid Spencer950bf602007-01-26 08:19:09 +00005444
5445 ValID ID;
5446 if (!FunctionName.empty()) {
Reid Spencer5eb77c72007-03-15 03:26:42 +00005447 ID = ValID::create((char*)FunctionName.c_str());
Reid Spencer950bf602007-01-26 08:19:09 +00005448 } else {
Reid Spencer5eb77c72007-03-15 03:26:42 +00005449 ID = ValID::create((int)CurModule.Values[PFT].size());
Reid Spencer950bf602007-01-26 08:19:09 +00005450 }
Reid Spencerbb1fd572007-03-21 17:15:50 +00005451 ID.S.makeComposite(FTySign);
Reid Spencer950bf602007-01-26 08:19:09 +00005452
5453 Function *Fn = 0;
Reid Spencered96d1e2007-02-08 09:08:52 +00005454 Module* M = CurModule.CurrentModule;
5455
Reid Spencer950bf602007-01-26 08:19:09 +00005456 // See if this function was forward referenced. If so, recycle the object.
5457 if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, ID)) {
5458 // Move the function to the end of the list, from whereever it was
5459 // previously inserted.
5460 Fn = cast<Function>(FWRef);
Reid Spencered96d1e2007-02-08 09:08:52 +00005461 M->getFunctionList().remove(Fn);
5462 M->getFunctionList().push_back(Fn);
5463 } else if (!FunctionName.empty()) {
5464 GlobalValue *Conflict = M->getFunction(FunctionName);
5465 if (!Conflict)
5466 Conflict = M->getNamedGlobal(FunctionName);
5467 if (Conflict && PFT == Conflict->getType()) {
5468 if (!CurFun.isDeclare && !Conflict->isDeclaration()) {
5469 // We have two function definitions that conflict, same type, same
5470 // name. We should really check to make sure that this is the result
5471 // of integer type planes collapsing and generate an error if it is
5472 // not, but we'll just rename on the assumption that it is. However,
5473 // let's do it intelligently and rename the internal linkage one
5474 // if there is one.
5475 std::string NewName(makeNameUnique(FunctionName));
5476 if (Conflict->hasInternalLinkage()) {
5477 Conflict->setName(NewName);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005478 RenameMapKey Key =
5479 makeRenameMapKey(FunctionName, Conflict->getType(), ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00005480 CurModule.RenameMap[Key] = NewName;
5481 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5482 InsertValue(Fn, CurModule.Values);
5483 } else {
5484 Fn = new Function(FT, CurFun.Linkage, NewName, M);
5485 InsertValue(Fn, CurModule.Values);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005486 RenameMapKey Key =
5487 makeRenameMapKey(FunctionName, PFT, ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00005488 CurModule.RenameMap[Key] = NewName;
5489 }
5490 } else {
5491 // If they are not both definitions, then just use the function we
5492 // found since the types are the same.
5493 Fn = cast<Function>(Conflict);
Reid Spenceref9b9a72007-02-05 20:47:22 +00005494
Reid Spencered96d1e2007-02-08 09:08:52 +00005495 // Make sure to strip off any argument names so we can't get
5496 // conflicts.
5497 if (Fn->isDeclaration())
5498 for (Function::arg_iterator AI = Fn->arg_begin(),
5499 AE = Fn->arg_end(); AI != AE; ++AI)
5500 AI->setName("");
5501 }
5502 } else if (Conflict) {
Reid Spencere59f4932007-04-16 03:05:01 +00005503 // We have two globals with the same name and different types.
Reid Spencered96d1e2007-02-08 09:08:52 +00005504 // Previously, this was permitted because the symbol table had
5505 // "type planes" and names only needed to be distinct within a
5506 // type plane. After PR411 was fixed, this is no loner the case.
5507 // To resolve this we must rename one of the two.
5508 if (Conflict->hasInternalLinkage()) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00005509 // We can safely rename the Conflict.
5510 RenameMapKey Key =
5511 makeRenameMapKey(Conflict->getName(), Conflict->getType(),
5512 CurModule.NamedValueSigns[Conflict->getName()]);
Reid Spencered96d1e2007-02-08 09:08:52 +00005513 Conflict->setName(makeNameUnique(Conflict->getName()));
Reid Spencered96d1e2007-02-08 09:08:52 +00005514 CurModule.RenameMap[Key] = Conflict->getName();
5515 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5516 InsertValue(Fn, CurModule.Values);
Reid Spencerd2920cd2007-03-21 17:27:53 +00005517 } else {
Reid Spencered96d1e2007-02-08 09:08:52 +00005518 // We can't quietly rename either of these things, but we must
Reid Spencerd2920cd2007-03-21 17:27:53 +00005519 // rename one of them. Only if the function's linkage is internal can
5520 // we forgo a warning message about the renamed function.
Reid Spencered96d1e2007-02-08 09:08:52 +00005521 std::string NewName = makeNameUnique(FunctionName);
Reid Spencerd2920cd2007-03-21 17:27:53 +00005522 if (CurFun.Linkage != GlobalValue::InternalLinkage) {
5523 warning("Renaming function '" + FunctionName + "' as '" + NewName +
5524 "' may cause linkage errors");
5525 }
5526 // Elect to rename the thing we're now defining.
Reid Spencered96d1e2007-02-08 09:08:52 +00005527 Fn = new Function(FT, CurFun.Linkage, NewName, M);
5528 InsertValue(Fn, CurModule.Values);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005529 RenameMapKey Key = makeRenameMapKey(FunctionName, PFT, ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00005530 CurModule.RenameMap[Key] = NewName;
Reid Spencerd2920cd2007-03-21 17:27:53 +00005531 }
Reid Spenceref9b9a72007-02-05 20:47:22 +00005532 } else {
Reid Spencered96d1e2007-02-08 09:08:52 +00005533 // There's no conflict, just define the function
5534 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5535 InsertValue(Fn, CurModule.Values);
Reid Spenceref9b9a72007-02-05 20:47:22 +00005536 }
Reid Spencere59f4932007-04-16 03:05:01 +00005537 } else {
5538 // There's no conflict, just define the function
5539 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5540 InsertValue(Fn, CurModule.Values);
Reid Spencer950bf602007-01-26 08:19:09 +00005541 }
5542
Reid Spencere59f4932007-04-16 03:05:01 +00005543
Reid Spencer950bf602007-01-26 08:19:09 +00005544 CurFun.FunctionStart(Fn);
5545
5546 if (CurFun.isDeclare) {
5547 // If we have declaration, always overwrite linkage. This will allow us
5548 // to correctly handle cases, when pointer to function is passed as
5549 // argument to another function.
5550 Fn->setLinkage(CurFun.Linkage);
5551 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005552 Fn->setCallingConv(upgradeCallingConv((yyvsp[-7].UIntVal)));
5553 Fn->setAlignment((yyvsp[0].UIntVal));
5554 if ((yyvsp[-1].StrVal)) {
5555 Fn->setSection((yyvsp[-1].StrVal));
5556 free((yyvsp[-1].StrVal));
Reid Spencer950bf602007-01-26 08:19:09 +00005557 }
5558
5559 // Add all of the arguments we parsed to the function...
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005560 if ((yyvsp[-3].ArgList)) { // Is null if empty...
Reid Spencer950bf602007-01-26 08:19:09 +00005561 if (isVarArg) { // Nuke the last entry
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005562 assert((yyvsp[-3].ArgList)->back().first.PAT->get() == Type::VoidTy &&
5563 (yyvsp[-3].ArgList)->back().second == 0 && "Not a varargs marker");
5564 delete (yyvsp[-3].ArgList)->back().first.PAT;
5565 (yyvsp[-3].ArgList)->pop_back(); // Delete the last entry
Reid Spencer950bf602007-01-26 08:19:09 +00005566 }
5567 Function::arg_iterator ArgIt = Fn->arg_begin();
Reid Spenceref9b9a72007-02-05 20:47:22 +00005568 Function::arg_iterator ArgEnd = Fn->arg_end();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005569 std::vector<std::pair<PATypeInfo,char*> >::iterator I = (yyvsp[-3].ArgList)->begin();
5570 std::vector<std::pair<PATypeInfo,char*> >::iterator E = (yyvsp[-3].ArgList)->end();
Reid Spenceref9b9a72007-02-05 20:47:22 +00005571 for ( ; I != E && ArgIt != ArgEnd; ++I, ++ArgIt) {
Reid Spencered96d1e2007-02-08 09:08:52 +00005572 delete I->first.PAT; // Delete the typeholder...
Reid Spencerbb1fd572007-03-21 17:15:50 +00005573 ValueInfo VI; VI.V = ArgIt; VI.S.copy(I->first.S);
5574 setValueName(VI, I->second); // Insert arg into symtab...
Reid Spencer950bf602007-01-26 08:19:09 +00005575 InsertValue(ArgIt);
5576 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005577 delete (yyvsp[-3].ArgList); // We're now done with the argument list
Reid Spencer950bf602007-01-26 08:19:09 +00005578 }
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005579 lastCallingConv = OldCallingConv::C;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005580 ;}
5581 break;
5582
5583 case 224:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005584#line 3103 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencerd2920cd2007-03-21 17:27:53 +00005585 { CurFun.Linkage = (yyvsp[0].Linkage); ;}
5586 break;
5587
5588 case 225:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005589#line 3103 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005590 {
5591 (yyval.FunctionVal) = CurFun.CurrentFunction;
Reid Spencer950bf602007-01-26 08:19:09 +00005592
5593 // Make sure that we keep track of the linkage type even if there was a
5594 // previous "declare".
Reid Spencerd2920cd2007-03-21 17:27:53 +00005595 (yyval.FunctionVal)->setLinkage((yyvsp[-3].Linkage));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005596 ;}
5597 break;
5598
Reid Spencerd2920cd2007-03-21 17:27:53 +00005599 case 228:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005600#line 3117 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005601 {
5602 (yyval.FunctionVal) = (yyvsp[-1].FunctionVal);
5603 ;}
5604 break;
5605
Reid Spencerd2920cd2007-03-21 17:27:53 +00005606 case 229:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005607#line 3122 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005608 { (yyval.Linkage) = GlobalValue::ExternalLinkage; ;}
5609 break;
5610
Reid Spencerd2920cd2007-03-21 17:27:53 +00005611 case 230:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005612#line 3123 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005613 { (yyval.Linkage) = GlobalValue::DLLImportLinkage; ;}
5614 break;
5615
Reid Spencerd2920cd2007-03-21 17:27:53 +00005616 case 231:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005617#line 3124 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005618 { (yyval.Linkage) = GlobalValue::ExternalWeakLinkage; ;}
5619 break;
5620
Reid Spencerd2920cd2007-03-21 17:27:53 +00005621 case 232:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005622#line 3128 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005623 { CurFun.isDeclare = true; ;}
5624 break;
5625
Reid Spencerd2920cd2007-03-21 17:27:53 +00005626 case 233:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005627#line 3129 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005628 { CurFun.Linkage = (yyvsp[0].Linkage); ;}
5629 break;
5630
Reid Spencerd2920cd2007-03-21 17:27:53 +00005631 case 234:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005632#line 3129 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005633 {
5634 (yyval.FunctionVal) = CurFun.CurrentFunction;
Reid Spencer950bf602007-01-26 08:19:09 +00005635 CurFun.FunctionDone();
5636
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005637 ;}
5638 break;
5639
Reid Spencerd2920cd2007-03-21 17:27:53 +00005640 case 235:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005641#line 3141 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005642 { (yyval.BoolVal) = false; ;}
5643 break;
5644
Reid Spencerd2920cd2007-03-21 17:27:53 +00005645 case 236:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005646#line 3142 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005647 { (yyval.BoolVal) = true; ;}
5648 break;
5649
Reid Spencerd2920cd2007-03-21 17:27:53 +00005650 case 237:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005651#line 3147 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencerbb1fd572007-03-21 17:15:50 +00005652 { (yyval.ValIDVal) = ValID::create((yyvsp[0].SInt64Val)); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005653 break;
5654
Reid Spencerd2920cd2007-03-21 17:27:53 +00005655 case 238:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005656#line 3148 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005657 { (yyval.ValIDVal) = ValID::create((yyvsp[0].UInt64Val)); ;}
5658 break;
5659
Reid Spencerd2920cd2007-03-21 17:27:53 +00005660 case 239:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005661#line 3149 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005662 { (yyval.ValIDVal) = ValID::create((yyvsp[0].FPVal)); ;}
5663 break;
5664
Reid Spencerd2920cd2007-03-21 17:27:53 +00005665 case 240:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005666#line 3150 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencerbb1fd572007-03-21 17:15:50 +00005667 {
5668 (yyval.ValIDVal) = ValID::create(ConstantInt::get(Type::Int1Ty, true));
5669 (yyval.ValIDVal).S.makeUnsigned();
5670 ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005671 break;
5672
Reid Spencerd2920cd2007-03-21 17:27:53 +00005673 case 241:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005674#line 3154 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencerbb1fd572007-03-21 17:15:50 +00005675 {
5676 (yyval.ValIDVal) = ValID::create(ConstantInt::get(Type::Int1Ty, false));
5677 (yyval.ValIDVal).S.makeUnsigned();
5678 ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005679 break;
5680
Reid Spencerd2920cd2007-03-21 17:27:53 +00005681 case 242:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005682#line 3158 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005683 { (yyval.ValIDVal) = ValID::createNull(); ;}
5684 break;
5685
Reid Spencerd2920cd2007-03-21 17:27:53 +00005686 case 243:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005687#line 3159 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005688 { (yyval.ValIDVal) = ValID::createUndef(); ;}
5689 break;
5690
Reid Spencerd2920cd2007-03-21 17:27:53 +00005691 case 244:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005692#line 3160 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005693 { (yyval.ValIDVal) = ValID::createZeroInit(); ;}
5694 break;
5695
Reid Spencerd2920cd2007-03-21 17:27:53 +00005696 case 245:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005697#line 3161 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005698 { // Nonempty unsized packed vector
5699 const Type *ETy = (*(yyvsp[-1].ConstVector))[0].C->getType();
5700 int NumElements = (yyvsp[-1].ConstVector)->size();
Reid Spencer9d6565a2007-02-15 02:26:10 +00005701 VectorType* pt = VectorType::get(ETy, NumElements);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005702 (yyval.ValIDVal).S.makeComposite((*(yyvsp[-1].ConstVector))[0].S);
5703 PATypeHolder* PTy = new PATypeHolder(HandleUpRefs(pt, (yyval.ValIDVal).S));
Reid Spencer950bf602007-01-26 08:19:09 +00005704
5705 // Verify all elements are correct type!
5706 std::vector<Constant*> Elems;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005707 for (unsigned i = 0; i < (yyvsp[-1].ConstVector)->size(); i++) {
5708 Constant *C = (*(yyvsp[-1].ConstVector))[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00005709 const Type *CTy = C->getType();
5710 if (ETy != CTy)
5711 error("Element #" + utostr(i) + " is not of type '" +
5712 ETy->getDescription() +"' as required!\nIt is of type '" +
5713 CTy->getDescription() + "'");
5714 Elems.push_back(C);
Reid Spencere77e35e2006-12-01 20:26:20 +00005715 }
Reid Spencer5eb77c72007-03-15 03:26:42 +00005716 (yyval.ValIDVal) = ValID::create(ConstantVector::get(pt, Elems));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005717 delete PTy; delete (yyvsp[-1].ConstVector);
5718 ;}
5719 break;
5720
Reid Spencerd2920cd2007-03-21 17:27:53 +00005721 case 246:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005722#line 3182 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005723 {
Reid Spencer5eb77c72007-03-15 03:26:42 +00005724 (yyval.ValIDVal) = ValID::create((yyvsp[0].ConstVal).C);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005725 (yyval.ValIDVal).S.copy((yyvsp[0].ConstVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005726 ;}
5727 break;
5728
Reid Spencerd2920cd2007-03-21 17:27:53 +00005729 case 247:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005730#line 3186 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005731 {
5732 char *End = UnEscapeLexed((yyvsp[-2].StrVal), true);
5733 std::string AsmStr = std::string((yyvsp[-2].StrVal), End);
5734 End = UnEscapeLexed((yyvsp[0].StrVal), true);
5735 std::string Constraints = std::string((yyvsp[0].StrVal), End);
5736 (yyval.ValIDVal) = ValID::createInlineAsm(AsmStr, Constraints, (yyvsp[-3].BoolVal));
5737 free((yyvsp[-2].StrVal));
5738 free((yyvsp[0].StrVal));
5739 ;}
5740 break;
5741
Reid Spencerd2920cd2007-03-21 17:27:53 +00005742 case 248:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005743#line 3200 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencerbb1fd572007-03-21 17:15:50 +00005744 { (yyval.ValIDVal) = ValID::create((yyvsp[0].SIntVal)); (yyval.ValIDVal).S.makeSignless(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005745 break;
5746
Reid Spencerd2920cd2007-03-21 17:27:53 +00005747 case 249:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005748#line 3201 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencerbb1fd572007-03-21 17:15:50 +00005749 { (yyval.ValIDVal) = ValID::create((yyvsp[0].StrVal)); (yyval.ValIDVal).S.makeSignless(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005750 break;
5751
Reid Spencerd2920cd2007-03-21 17:27:53 +00005752 case 252:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005753#line 3214 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005754 {
5755 const Type *Ty = (yyvsp[-1].TypeVal).PAT->get();
Reid Spencerbb1fd572007-03-21 17:15:50 +00005756 (yyvsp[0].ValIDVal).S.copy((yyvsp[-1].TypeVal).S);
Reid Spencer5eb77c72007-03-15 03:26:42 +00005757 (yyval.ValueVal).V = getVal(Ty, (yyvsp[0].ValIDVal));
Reid Spencerbb1fd572007-03-21 17:15:50 +00005758 (yyval.ValueVal).S.copy((yyvsp[-1].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005759 delete (yyvsp[-1].TypeVal).PAT;
5760 ;}
5761 break;
5762
Reid Spencerd2920cd2007-03-21 17:27:53 +00005763 case 253:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005764#line 3224 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005765 {
5766 (yyval.FunctionVal) = (yyvsp[-1].FunctionVal);
5767 ;}
5768 break;
5769
Reid Spencerd2920cd2007-03-21 17:27:53 +00005770 case 254:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005771#line 3227 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005772 { // Do not allow functions with 0 basic blocks
5773 (yyval.FunctionVal) = (yyvsp[-1].FunctionVal);
5774 ;}
5775 break;
5776
Reid Spencerd2920cd2007-03-21 17:27:53 +00005777 case 255:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005778#line 3236 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005779 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00005780 ValueInfo VI; VI.V = (yyvsp[0].TermInstVal).TI; VI.S.copy((yyvsp[0].TermInstVal).S);
5781 setValueName(VI, (yyvsp[-1].StrVal));
5782 InsertValue((yyvsp[0].TermInstVal).TI);
5783 (yyvsp[-2].BasicBlockVal)->getInstList().push_back((yyvsp[0].TermInstVal).TI);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005784 InsertValue((yyvsp[-2].BasicBlockVal));
5785 (yyval.BasicBlockVal) = (yyvsp[-2].BasicBlockVal);
5786 ;}
5787 break;
5788
Reid Spencerd2920cd2007-03-21 17:27:53 +00005789 case 256:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005790#line 3247 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005791 {
5792 if ((yyvsp[0].InstVal).I)
5793 (yyvsp[-1].BasicBlockVal)->getInstList().push_back((yyvsp[0].InstVal).I);
5794 (yyval.BasicBlockVal) = (yyvsp[-1].BasicBlockVal);
5795 ;}
5796 break;
5797
Reid Spencerd2920cd2007-03-21 17:27:53 +00005798 case 257:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005799#line 3252 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005800 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00005801 (yyval.BasicBlockVal) = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++),true);
Reid Spencer950bf602007-01-26 08:19:09 +00005802 // Make sure to move the basic block to the correct location in the
5803 // function, instead of leaving it inserted wherever it was first
5804 // referenced.
5805 Function::BasicBlockListType &BBL =
5806 CurFun.CurrentFunction->getBasicBlockList();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005807 BBL.splice(BBL.end(), BBL, (yyval.BasicBlockVal));
5808 ;}
5809 break;
5810
Reid Spencerd2920cd2007-03-21 17:27:53 +00005811 case 258:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005812#line 3261 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005813 {
Reid Spencer5eb77c72007-03-15 03:26:42 +00005814 (yyval.BasicBlockVal) = CurBB = getBBVal(ValID::create((yyvsp[0].StrVal)), true);
Reid Spencer950bf602007-01-26 08:19:09 +00005815 // Make sure to move the basic block to the correct location in the
5816 // function, instead of leaving it inserted wherever it was first
5817 // referenced.
5818 Function::BasicBlockListType &BBL =
5819 CurFun.CurrentFunction->getBasicBlockList();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005820 BBL.splice(BBL.end(), BBL, (yyval.BasicBlockVal));
5821 ;}
5822 break;
5823
Reid Spencerd2920cd2007-03-21 17:27:53 +00005824 case 261:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005825#line 3275 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005826 { // Return with a result...
Reid Spencerbb1fd572007-03-21 17:15:50 +00005827 (yyval.TermInstVal).TI = new ReturnInst((yyvsp[0].ValueVal).V);
5828 (yyval.TermInstVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005829 ;}
5830 break;
5831
Reid Spencerd2920cd2007-03-21 17:27:53 +00005832 case 262:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005833#line 3279 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005834 { // Return with no result...
Reid Spencerbb1fd572007-03-21 17:15:50 +00005835 (yyval.TermInstVal).TI = new ReturnInst();
5836 (yyval.TermInstVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005837 ;}
5838 break;
5839
Reid Spencerd2920cd2007-03-21 17:27:53 +00005840 case 263:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005841#line 3283 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005842 { // Unconditional Branch...
5843 BasicBlock* tmpBB = getBBVal((yyvsp[0].ValIDVal));
Reid Spencerbb1fd572007-03-21 17:15:50 +00005844 (yyval.TermInstVal).TI = new BranchInst(tmpBB);
5845 (yyval.TermInstVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005846 ;}
5847 break;
5848
Reid Spencerd2920cd2007-03-21 17:27:53 +00005849 case 264:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005850#line 3288 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005851 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00005852 (yyvsp[-3].ValIDVal).S.makeSignless();
5853 (yyvsp[0].ValIDVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005854 BasicBlock* tmpBBA = getBBVal((yyvsp[-3].ValIDVal));
5855 BasicBlock* tmpBBB = getBBVal((yyvsp[0].ValIDVal));
Reid Spencerbb1fd572007-03-21 17:15:50 +00005856 (yyvsp[-6].ValIDVal).S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005857 Value* tmpVal = getVal(Type::Int1Ty, (yyvsp[-6].ValIDVal));
Reid Spencerbb1fd572007-03-21 17:15:50 +00005858 (yyval.TermInstVal).TI = new BranchInst(tmpBBA, tmpBBB, tmpVal);
5859 (yyval.TermInstVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005860 ;}
5861 break;
5862
Reid Spencerd2920cd2007-03-21 17:27:53 +00005863 case 265:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005864#line 3298 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005865 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00005866 (yyvsp[-6].ValIDVal).S.copy((yyvsp[-7].PrimType).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005867 Value* tmpVal = getVal((yyvsp[-7].PrimType).T, (yyvsp[-6].ValIDVal));
Reid Spencerbb1fd572007-03-21 17:15:50 +00005868 (yyvsp[-3].ValIDVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005869 BasicBlock* tmpBB = getBBVal((yyvsp[-3].ValIDVal));
5870 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, (yyvsp[-1].JumpTable)->size());
Reid Spencerbb1fd572007-03-21 17:15:50 +00005871 (yyval.TermInstVal).TI = S;
5872 (yyval.TermInstVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005873 std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = (yyvsp[-1].JumpTable)->begin(),
5874 E = (yyvsp[-1].JumpTable)->end();
Reid Spencer950bf602007-01-26 08:19:09 +00005875 for (; I != E; ++I) {
5876 if (ConstantInt *CI = dyn_cast<ConstantInt>(I->first))
5877 S->addCase(CI, I->second);
5878 else
5879 error("Switch case is constant, but not a simple integer");
5880 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005881 delete (yyvsp[-1].JumpTable);
5882 ;}
5883 break;
5884
Reid Spencerd2920cd2007-03-21 17:27:53 +00005885 case 266:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005886#line 3316 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005887 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00005888 (yyvsp[-5].ValIDVal).S.copy((yyvsp[-6].PrimType).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005889 Value* tmpVal = getVal((yyvsp[-6].PrimType).T, (yyvsp[-5].ValIDVal));
Reid Spencerbb1fd572007-03-21 17:15:50 +00005890 (yyvsp[-2].ValIDVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005891 BasicBlock* tmpBB = getBBVal((yyvsp[-2].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00005892 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005893 (yyval.TermInstVal).TI = S;
5894 (yyval.TermInstVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005895 ;}
5896 break;
5897
Reid Spencerd2920cd2007-03-21 17:27:53 +00005898 case 267:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005899#line 3326 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005900 {
Reid Spencer950bf602007-01-26 08:19:09 +00005901 const PointerType *PFTy;
5902 const FunctionType *Ty;
Reid Spencerbb1fd572007-03-21 17:15:50 +00005903 Signedness FTySign;
Reid Spencer950bf602007-01-26 08:19:09 +00005904
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005905 if (!(PFTy = dyn_cast<PointerType>((yyvsp[-10].TypeVal).PAT->get())) ||
Reid Spencer950bf602007-01-26 08:19:09 +00005906 !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
5907 // Pull out the types of all of the arguments...
5908 std::vector<const Type*> ParamTypes;
Reid Spencerbb1fd572007-03-21 17:15:50 +00005909 FTySign.makeComposite((yyvsp[-10].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005910 if ((yyvsp[-7].ValueList)) {
5911 for (std::vector<ValueInfo>::iterator I = (yyvsp[-7].ValueList)->begin(), E = (yyvsp[-7].ValueList)->end();
Reid Spencerbb1fd572007-03-21 17:15:50 +00005912 I != E; ++I) {
Reid Spencer950bf602007-01-26 08:19:09 +00005913 ParamTypes.push_back((*I).V->getType());
Reid Spencerbb1fd572007-03-21 17:15:50 +00005914 FTySign.add(I->S);
5915 }
Reid Spencer950bf602007-01-26 08:19:09 +00005916 }
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005917 ParamAttrsList *PAL = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005918 if ((yyvsp[-11].UIntVal) == OldCallingConv::CSRet) {
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005919 ParamAttrsVector Attrs;
5920 ParamAttrsWithIndex PAWI;
5921 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
5922 Attrs.push_back(PAWI);
5923 PAL = ParamAttrsList::get(Attrs);
Reid Spencerb7046c72007-01-29 05:41:34 +00005924 }
Reid Spencer950bf602007-01-26 08:19:09 +00005925 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
5926 if (isVarArg) ParamTypes.pop_back();
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005927 Ty = FunctionType::get((yyvsp[-10].TypeVal).PAT->get(), ParamTypes, isVarArg, PAL);
Reid Spencer950bf602007-01-26 08:19:09 +00005928 PFTy = PointerType::get(Ty);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005929 (yyval.TermInstVal).S.copy((yyvsp[-10].TypeVal).S);
5930 } else {
5931 FTySign = (yyvsp[-10].TypeVal).S;
Reid Spencera3b12dd2007-04-07 16:14:01 +00005932 // Get the signedness of the result type. $3 is the pointer to the
5933 // function type so we get the 0th element to extract the function type,
5934 // and then the 0th element again to get the result type.
5935 (yyval.TermInstVal).S.copy((yyvsp[-10].TypeVal).S.get(0).get(0));
Reid Spencer950bf602007-01-26 08:19:09 +00005936 }
Reid Spencer7b5d4662007-04-09 06:16:21 +00005937
Reid Spencerbb1fd572007-03-21 17:15:50 +00005938 (yyvsp[-9].ValIDVal).S.makeComposite(FTySign);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005939 Value *V = getVal(PFTy, (yyvsp[-9].ValIDVal)); // Get the function we're calling...
5940 BasicBlock *Normal = getBBVal((yyvsp[-3].ValIDVal));
5941 BasicBlock *Except = getBBVal((yyvsp[0].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00005942
5943 // Create the call node...
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005944 if (!(yyvsp[-7].ValueList)) { // Has no arguments?
Reid Spencerbb1fd572007-03-21 17:15:50 +00005945 (yyval.TermInstVal).TI = new InvokeInst(V, Normal, Except, 0, 0);
Reid Spencer950bf602007-01-26 08:19:09 +00005946 } else { // Has arguments?
5947 // Loop through FunctionType's arguments and ensure they are specified
5948 // correctly!
5949 //
5950 FunctionType::param_iterator I = Ty->param_begin();
5951 FunctionType::param_iterator E = Ty->param_end();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005952 std::vector<ValueInfo>::iterator ArgI = (yyvsp[-7].ValueList)->begin(), ArgE = (yyvsp[-7].ValueList)->end();
Reid Spencer950bf602007-01-26 08:19:09 +00005953
5954 std::vector<Value*> Args;
5955 for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
5956 if ((*ArgI).V->getType() != *I)
5957 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
5958 (*I)->getDescription() + "'");
5959 Args.push_back((*ArgI).V);
5960 }
5961
5962 if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
5963 error("Invalid number of parameters detected");
5964
Reid Spencerbb1fd572007-03-21 17:15:50 +00005965 (yyval.TermInstVal).TI = new InvokeInst(V, Normal, Except, &Args[0], Args.size());
Reid Spencer950bf602007-01-26 08:19:09 +00005966 }
Reid Spencerbb1fd572007-03-21 17:15:50 +00005967 cast<InvokeInst>((yyval.TermInstVal).TI)->setCallingConv(upgradeCallingConv((yyvsp[-11].UIntVal)));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005968 delete (yyvsp[-10].TypeVal).PAT;
5969 delete (yyvsp[-7].ValueList);
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005970 lastCallingConv = OldCallingConv::C;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005971 ;}
5972 break;
5973
Reid Spencerd2920cd2007-03-21 17:27:53 +00005974 case 268:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005975#line 3398 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005976 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00005977 (yyval.TermInstVal).TI = new UnwindInst();
5978 (yyval.TermInstVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005979 ;}
5980 break;
5981
Reid Spencerd2920cd2007-03-21 17:27:53 +00005982 case 269:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005983#line 3402 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005984 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00005985 (yyval.TermInstVal).TI = new UnreachableInst();
5986 (yyval.TermInstVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005987 ;}
5988 break;
5989
Reid Spencerd2920cd2007-03-21 17:27:53 +00005990 case 270:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005991#line 3409 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005992 {
5993 (yyval.JumpTable) = (yyvsp[-5].JumpTable);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005994 (yyvsp[-3].ValIDVal).S.copy((yyvsp[-4].PrimType).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005995 Constant *V = cast<Constant>(getExistingValue((yyvsp[-4].PrimType).T, (yyvsp[-3].ValIDVal)));
Reid Spencer950bf602007-01-26 08:19:09 +00005996
5997 if (V == 0)
5998 error("May only switch on a constant pool value");
5999
Reid Spencerbb1fd572007-03-21 17:15:50 +00006000 (yyvsp[0].ValIDVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006001 BasicBlock* tmpBB = getBBVal((yyvsp[0].ValIDVal));
6002 (yyval.JumpTable)->push_back(std::make_pair(V, tmpBB));
6003 ;}
6004 break;
6005
Reid Spencerd2920cd2007-03-21 17:27:53 +00006006 case 271:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006007#line 3421 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006008 {
6009 (yyval.JumpTable) = new std::vector<std::pair<Constant*, BasicBlock*> >();
Reid Spencerbb1fd572007-03-21 17:15:50 +00006010 (yyvsp[-3].ValIDVal).S.copy((yyvsp[-4].PrimType).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006011 Constant *V = cast<Constant>(getExistingValue((yyvsp[-4].PrimType).T, (yyvsp[-3].ValIDVal)));
Reid Spencer950bf602007-01-26 08:19:09 +00006012
6013 if (V == 0)
6014 error("May only switch on a constant pool value");
6015
Reid Spencerbb1fd572007-03-21 17:15:50 +00006016 (yyvsp[0].ValIDVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006017 BasicBlock* tmpBB = getBBVal((yyvsp[0].ValIDVal));
6018 (yyval.JumpTable)->push_back(std::make_pair(V, tmpBB));
6019 ;}
6020 break;
6021
Reid Spencerd2920cd2007-03-21 17:27:53 +00006022 case 272:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006023#line 3436 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006024 {
Reid Spencer950bf602007-01-26 08:19:09 +00006025 bool omit = false;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006026 if ((yyvsp[-1].StrVal))
6027 if (BitCastInst *BCI = dyn_cast<BitCastInst>((yyvsp[0].InstVal).I))
Reid Spencer950bf602007-01-26 08:19:09 +00006028 if (BCI->getSrcTy() == BCI->getDestTy() &&
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006029 BCI->getOperand(0)->getName() == (yyvsp[-1].StrVal))
Reid Spencer950bf602007-01-26 08:19:09 +00006030 // This is a useless bit cast causing a name redefinition. It is
6031 // a bit cast from a type to the same type of an operand with the
6032 // same name as the name we would give this instruction. Since this
6033 // instruction results in no code generation, it is safe to omit
6034 // the instruction. This situation can occur because of collapsed
6035 // type planes. For example:
6036 // %X = add int %Y, %Z
6037 // %X = cast int %Y to uint
6038 // After upgrade, this looks like:
6039 // %X = add i32 %Y, %Z
6040 // %X = bitcast i32 to i32
6041 // The bitcast is clearly useless so we omit it.
6042 omit = true;
6043 if (omit) {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006044 (yyval.InstVal).I = 0;
Reid Spencerbb1fd572007-03-21 17:15:50 +00006045 (yyval.InstVal).S.makeSignless();
Reid Spencer950bf602007-01-26 08:19:09 +00006046 } else {
Reid Spencerbb1fd572007-03-21 17:15:50 +00006047 ValueInfo VI; VI.V = (yyvsp[0].InstVal).I; VI.S.copy((yyvsp[0].InstVal).S);
6048 setValueName(VI, (yyvsp[-1].StrVal));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006049 InsertValue((yyvsp[0].InstVal).I);
6050 (yyval.InstVal) = (yyvsp[0].InstVal);
Reid Spencer950bf602007-01-26 08:19:09 +00006051 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006052 ;}
6053 break;
6054
Reid Spencerd2920cd2007-03-21 17:27:53 +00006055 case 273:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006056#line 3466 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006057 { // Used for PHI nodes
6058 (yyval.PHIList).P = new std::list<std::pair<Value*, BasicBlock*> >();
Reid Spencerbb1fd572007-03-21 17:15:50 +00006059 (yyval.PHIList).S.copy((yyvsp[-5].TypeVal).S);
6060 (yyvsp[-3].ValIDVal).S.copy((yyvsp[-5].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006061 Value* tmpVal = getVal((yyvsp[-5].TypeVal).PAT->get(), (yyvsp[-3].ValIDVal));
Reid Spencerbb1fd572007-03-21 17:15:50 +00006062 (yyvsp[-1].ValIDVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006063 BasicBlock* tmpBB = getBBVal((yyvsp[-1].ValIDVal));
6064 (yyval.PHIList).P->push_back(std::make_pair(tmpVal, tmpBB));
6065 delete (yyvsp[-5].TypeVal).PAT;
6066 ;}
6067 break;
6068
Reid Spencerd2920cd2007-03-21 17:27:53 +00006069 case 274:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006070#line 3476 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006071 {
6072 (yyval.PHIList) = (yyvsp[-6].PHIList);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006073 (yyvsp[-3].ValIDVal).S.copy((yyvsp[-6].PHIList).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006074 Value* tmpVal = getVal((yyvsp[-6].PHIList).P->front().first->getType(), (yyvsp[-3].ValIDVal));
Reid Spencerbb1fd572007-03-21 17:15:50 +00006075 (yyvsp[-1].ValIDVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006076 BasicBlock* tmpBB = getBBVal((yyvsp[-1].ValIDVal));
6077 (yyvsp[-6].PHIList).P->push_back(std::make_pair(tmpVal, tmpBB));
6078 ;}
6079 break;
6080
Reid Spencerd2920cd2007-03-21 17:27:53 +00006081 case 275:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006082#line 3486 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006083 { // Used for call statements, and memory insts...
6084 (yyval.ValueList) = new std::vector<ValueInfo>();
6085 (yyval.ValueList)->push_back((yyvsp[0].ValueVal));
6086 ;}
6087 break;
6088
Reid Spencerd2920cd2007-03-21 17:27:53 +00006089 case 276:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006090#line 3490 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006091 {
6092 (yyval.ValueList) = (yyvsp[-2].ValueList);
6093 (yyvsp[-2].ValueList)->push_back((yyvsp[0].ValueVal));
6094 ;}
6095 break;
6096
Reid Spencerd2920cd2007-03-21 17:27:53 +00006097 case 278:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006098#line 3498 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006099 { (yyval.ValueList) = 0; ;}
6100 break;
6101
Reid Spencerd2920cd2007-03-21 17:27:53 +00006102 case 279:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006103#line 3502 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006104 {
6105 (yyval.BoolVal) = true;
6106 ;}
6107 break;
6108
Reid Spencerd2920cd2007-03-21 17:27:53 +00006109 case 280:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006110#line 3505 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006111 {
6112 (yyval.BoolVal) = false;
6113 ;}
6114 break;
6115
Reid Spencerd2920cd2007-03-21 17:27:53 +00006116 case 281:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006117#line 3511 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006118 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00006119 (yyvsp[-2].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6120 (yyvsp[0].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006121 const Type* Ty = (yyvsp[-3].TypeVal).PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006122 if (!Ty->isInteger() && !Ty->isFloatingPoint() && !isa<VectorType>(Ty))
Reid Spencer950bf602007-01-26 08:19:09 +00006123 error("Arithmetic operator requires integer, FP, or packed operands");
Reid Spencer9d6565a2007-02-15 02:26:10 +00006124 if (isa<VectorType>(Ty) &&
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006125 ((yyvsp[-4].BinaryOpVal) == URemOp || (yyvsp[-4].BinaryOpVal) == SRemOp || (yyvsp[-4].BinaryOpVal) == FRemOp || (yyvsp[-4].BinaryOpVal) == RemOp))
Chris Lattner4227bdb2007-02-19 07:34:02 +00006126 error("Remainder not supported on vector types");
Reid Spencer950bf602007-01-26 08:19:09 +00006127 // Upgrade the opcode from obsolete versions before we do anything with it.
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006128 Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[-4].BinaryOpVal), Ty, (yyvsp[-3].TypeVal).S);
6129 Value* val1 = getVal(Ty, (yyvsp[-2].ValIDVal));
6130 Value* val2 = getVal(Ty, (yyvsp[0].ValIDVal));
6131 (yyval.InstVal).I = BinaryOperator::create(Opcode, val1, val2);
6132 if ((yyval.InstVal).I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006133 error("binary operator returned null");
Reid Spencerbb1fd572007-03-21 17:15:50 +00006134 (yyval.InstVal).S.copy((yyvsp[-3].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006135 delete (yyvsp[-3].TypeVal).PAT;
6136 ;}
6137 break;
6138
Reid Spencerd2920cd2007-03-21 17:27:53 +00006139 case 282:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006140#line 3530 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006141 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00006142 (yyvsp[-2].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6143 (yyvsp[0].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006144 const Type *Ty = (yyvsp[-3].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006145 if (!Ty->isInteger()) {
Reid Spencer9d6565a2007-02-15 02:26:10 +00006146 if (!isa<VectorType>(Ty) ||
6147 !cast<VectorType>(Ty)->getElementType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00006148 error("Logical operator requires integral operands");
6149 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006150 Instruction::BinaryOps Opcode = getBinaryOp((yyvsp[-4].BinaryOpVal), Ty, (yyvsp[-3].TypeVal).S);
6151 Value* tmpVal1 = getVal(Ty, (yyvsp[-2].ValIDVal));
6152 Value* tmpVal2 = getVal(Ty, (yyvsp[0].ValIDVal));
6153 (yyval.InstVal).I = BinaryOperator::create(Opcode, tmpVal1, tmpVal2);
6154 if ((yyval.InstVal).I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006155 error("binary operator returned null");
Reid Spencerbb1fd572007-03-21 17:15:50 +00006156 (yyval.InstVal).S.copy((yyvsp[-3].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006157 delete (yyvsp[-3].TypeVal).PAT;
6158 ;}
6159 break;
6160
Reid Spencerd2920cd2007-03-21 17:27:53 +00006161 case 283:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006162#line 3548 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006163 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00006164 (yyvsp[-2].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6165 (yyvsp[0].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006166 const Type* Ty = (yyvsp[-3].TypeVal).PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006167 if(isa<VectorType>(Ty))
6168 error("VectorTypes currently not supported in setcc instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00006169 unsigned short pred;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006170 Instruction::OtherOps Opcode = getCompareOp((yyvsp[-4].BinaryOpVal), pred, Ty, (yyvsp[-3].TypeVal).S);
6171 Value* tmpVal1 = getVal(Ty, (yyvsp[-2].ValIDVal));
6172 Value* tmpVal2 = getVal(Ty, (yyvsp[0].ValIDVal));
6173 (yyval.InstVal).I = CmpInst::create(Opcode, pred, tmpVal1, tmpVal2);
6174 if ((yyval.InstVal).I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006175 error("binary operator returned null");
Reid Spencerbb1fd572007-03-21 17:15:50 +00006176 (yyval.InstVal).S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006177 delete (yyvsp[-3].TypeVal).PAT;
6178 ;}
6179 break;
6180
Reid Spencerd2920cd2007-03-21 17:27:53 +00006181 case 284:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006182#line 3564 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006183 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00006184 (yyvsp[-2].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6185 (yyvsp[0].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006186 const Type *Ty = (yyvsp[-3].TypeVal).PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006187 if (isa<VectorType>(Ty))
6188 error("VectorTypes currently not supported in icmp instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00006189 else if (!Ty->isInteger() && !isa<PointerType>(Ty))
6190 error("icmp requires integer or pointer typed operands");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006191 Value* tmpVal1 = getVal(Ty, (yyvsp[-2].ValIDVal));
6192 Value* tmpVal2 = getVal(Ty, (yyvsp[0].ValIDVal));
6193 (yyval.InstVal).I = new ICmpInst((yyvsp[-4].IPred), tmpVal1, tmpVal2);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006194 (yyval.InstVal).S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006195 delete (yyvsp[-3].TypeVal).PAT;
6196 ;}
6197 break;
6198
Reid Spencerd2920cd2007-03-21 17:27:53 +00006199 case 285:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006200#line 3578 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006201 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00006202 (yyvsp[-2].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
6203 (yyvsp[0].ValIDVal).S.copy((yyvsp[-3].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006204 const Type *Ty = (yyvsp[-3].TypeVal).PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006205 if (isa<VectorType>(Ty))
6206 error("VectorTypes currently not supported in fcmp instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00006207 else if (!Ty->isFloatingPoint())
6208 error("fcmp instruction requires floating point operands");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006209 Value* tmpVal1 = getVal(Ty, (yyvsp[-2].ValIDVal));
6210 Value* tmpVal2 = getVal(Ty, (yyvsp[0].ValIDVal));
6211 (yyval.InstVal).I = new FCmpInst((yyvsp[-4].FPred), tmpVal1, tmpVal2);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006212 (yyval.InstVal).S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006213 delete (yyvsp[-3].TypeVal).PAT;
6214 ;}
6215 break;
6216
Reid Spencerd2920cd2007-03-21 17:27:53 +00006217 case 286:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006218#line 3592 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006219 {
Reid Spencer950bf602007-01-26 08:19:09 +00006220 warning("Use of obsolete 'not' instruction: Replacing with 'xor");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006221 const Type *Ty = (yyvsp[0].ValueVal).V->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00006222 Value *Ones = ConstantInt::getAllOnesValue(Ty);
6223 if (Ones == 0)
6224 error("Expected integral type for not instruction");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006225 (yyval.InstVal).I = BinaryOperator::create(Instruction::Xor, (yyvsp[0].ValueVal).V, Ones);
6226 if ((yyval.InstVal).I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006227 error("Could not create a xor instruction");
Reid Spencerbb1fd572007-03-21 17:15:50 +00006228 (yyval.InstVal).S.copy((yyvsp[0].ValueVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006229 ;}
6230 break;
6231
Reid Spencerd2920cd2007-03-21 17:27:53 +00006232 case 287:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006233#line 3603 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006234 {
6235 if (!(yyvsp[0].ValueVal).V->getType()->isInteger() ||
6236 cast<IntegerType>((yyvsp[0].ValueVal).V->getType())->getBitWidth() != 8)
Reid Spencer950bf602007-01-26 08:19:09 +00006237 error("Shift amount must be int8");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006238 const Type* Ty = (yyvsp[-2].ValueVal).V->getType();
Reid Spencer832254e2007-02-02 02:16:23 +00006239 if (!Ty->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00006240 error("Shift constant expression requires integer operand");
Reid Spencer832254e2007-02-02 02:16:23 +00006241 Value* ShiftAmt = 0;
6242 if (cast<IntegerType>(Ty)->getBitWidth() > Type::Int8Ty->getBitWidth())
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006243 if (Constant *C = dyn_cast<Constant>((yyvsp[0].ValueVal).V))
Reid Spencer832254e2007-02-02 02:16:23 +00006244 ShiftAmt = ConstantExpr::getZExt(C, Ty);
6245 else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006246 ShiftAmt = new ZExtInst((yyvsp[0].ValueVal).V, Ty, makeNameUnique("shift"), CurBB);
Reid Spencer832254e2007-02-02 02:16:23 +00006247 else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006248 ShiftAmt = (yyvsp[0].ValueVal).V;
6249 (yyval.InstVal).I = BinaryOperator::create(getBinaryOp((yyvsp[-3].BinaryOpVal), Ty, (yyvsp[-2].ValueVal).S), (yyvsp[-2].ValueVal).V, ShiftAmt);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006250 (yyval.InstVal).S.copy((yyvsp[-2].ValueVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006251 ;}
6252 break;
6253
Reid Spencerd2920cd2007-03-21 17:27:53 +00006254 case 288:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006255#line 3621 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006256 {
6257 const Type *DstTy = (yyvsp[0].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006258 if (!DstTy->isFirstClassType())
6259 error("cast instruction to a non-primitive type: '" +
6260 DstTy->getDescription() + "'");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006261 (yyval.InstVal).I = cast<Instruction>(getCast((yyvsp[-3].CastOpVal), (yyvsp[-2].ValueVal).V, (yyvsp[-2].ValueVal).S, DstTy, (yyvsp[0].TypeVal).S, true));
Reid Spencerbb1fd572007-03-21 17:15:50 +00006262 (yyval.InstVal).S.copy((yyvsp[0].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006263 delete (yyvsp[0].TypeVal).PAT;
6264 ;}
6265 break;
6266
Reid Spencerd2920cd2007-03-21 17:27:53 +00006267 case 289:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006268#line 3630 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006269 {
6270 if (!(yyvsp[-4].ValueVal).V->getType()->isInteger() ||
6271 cast<IntegerType>((yyvsp[-4].ValueVal).V->getType())->getBitWidth() != 1)
Reid Spencer950bf602007-01-26 08:19:09 +00006272 error("select condition must be bool");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006273 if ((yyvsp[-2].ValueVal).V->getType() != (yyvsp[0].ValueVal).V->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00006274 error("select value types should match");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006275 (yyval.InstVal).I = new SelectInst((yyvsp[-4].ValueVal).V, (yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006276 (yyval.InstVal).S.copy((yyvsp[-2].ValueVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006277 ;}
6278 break;
6279
Reid Spencerd2920cd2007-03-21 17:27:53 +00006280 case 290:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006281#line 3639 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006282 {
6283 const Type *Ty = (yyvsp[0].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006284 NewVarArgs = true;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006285 (yyval.InstVal).I = new VAArgInst((yyvsp[-2].ValueVal).V, Ty);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006286 (yyval.InstVal).S.copy((yyvsp[0].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006287 delete (yyvsp[0].TypeVal).PAT;
6288 ;}
6289 break;
6290
Reid Spencerd2920cd2007-03-21 17:27:53 +00006291 case 291:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006292#line 3646 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006293 {
6294 const Type* ArgTy = (yyvsp[-2].ValueVal).V->getType();
6295 const Type* DstTy = (yyvsp[0].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006296 ObsoleteVarArgs = true;
6297 Function* NF = cast<Function>(CurModule.CurrentModule->
6298 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
6299
6300 //b = vaarg a, t ->
6301 //foo = alloca 1 of t
6302 //bar = vacopy a
6303 //store bar -> foo
6304 //b = vaarg foo, t
6305 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vaarg.fix");
6306 CurBB->getInstList().push_back(foo);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006307 CallInst* bar = new CallInst(NF, (yyvsp[-2].ValueVal).V);
Reid Spencer950bf602007-01-26 08:19:09 +00006308 CurBB->getInstList().push_back(bar);
6309 CurBB->getInstList().push_back(new StoreInst(bar, foo));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006310 (yyval.InstVal).I = new VAArgInst(foo, DstTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006311 (yyval.InstVal).S.copy((yyvsp[0].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006312 delete (yyvsp[0].TypeVal).PAT;
6313 ;}
6314 break;
6315
Reid Spencerd2920cd2007-03-21 17:27:53 +00006316 case 292:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006317#line 3667 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006318 {
6319 const Type* ArgTy = (yyvsp[-2].ValueVal).V->getType();
6320 const Type* DstTy = (yyvsp[0].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006321 ObsoleteVarArgs = true;
6322 Function* NF = cast<Function>(CurModule.CurrentModule->
6323 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
6324
6325 //b = vanext a, t ->
6326 //foo = alloca 1 of t
6327 //bar = vacopy a
6328 //store bar -> foo
6329 //tmp = vaarg foo, t
6330 //b = load foo
6331 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vanext.fix");
6332 CurBB->getInstList().push_back(foo);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006333 CallInst* bar = new CallInst(NF, (yyvsp[-2].ValueVal).V);
Reid Spencer950bf602007-01-26 08:19:09 +00006334 CurBB->getInstList().push_back(bar);
6335 CurBB->getInstList().push_back(new StoreInst(bar, foo));
6336 Instruction* tmp = new VAArgInst(foo, DstTy);
6337 CurBB->getInstList().push_back(tmp);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006338 (yyval.InstVal).I = new LoadInst(foo);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006339 (yyval.InstVal).S.copy((yyvsp[0].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006340 delete (yyvsp[0].TypeVal).PAT;
6341 ;}
6342 break;
6343
Reid Spencerd2920cd2007-03-21 17:27:53 +00006344 case 293:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006345#line 3691 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006346 {
6347 if (!ExtractElementInst::isValidOperands((yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V))
Reid Spencer950bf602007-01-26 08:19:09 +00006348 error("Invalid extractelement operands");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006349 (yyval.InstVal).I = new ExtractElementInst((yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006350 (yyval.InstVal).S.copy((yyvsp[-2].ValueVal).S.get(0));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006351 ;}
6352 break;
6353
Reid Spencerd2920cd2007-03-21 17:27:53 +00006354 case 294:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006355#line 3697 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006356 {
6357 if (!InsertElementInst::isValidOperands((yyvsp[-4].ValueVal).V, (yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V))
Reid Spencer950bf602007-01-26 08:19:09 +00006358 error("Invalid insertelement operands");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006359 (yyval.InstVal).I = new InsertElementInst((yyvsp[-4].ValueVal).V, (yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006360 (yyval.InstVal).S.copy((yyvsp[-4].ValueVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006361 ;}
6362 break;
6363
Reid Spencerd2920cd2007-03-21 17:27:53 +00006364 case 295:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006365#line 3703 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006366 {
6367 if (!ShuffleVectorInst::isValidOperands((yyvsp[-4].ValueVal).V, (yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V))
Reid Spencer950bf602007-01-26 08:19:09 +00006368 error("Invalid shufflevector operands");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006369 (yyval.InstVal).I = new ShuffleVectorInst((yyvsp[-4].ValueVal).V, (yyvsp[-2].ValueVal).V, (yyvsp[0].ValueVal).V);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006370 (yyval.InstVal).S.copy((yyvsp[-4].ValueVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006371 ;}
6372 break;
6373
Reid Spencerd2920cd2007-03-21 17:27:53 +00006374 case 296:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006375#line 3709 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006376 {
6377 const Type *Ty = (yyvsp[0].PHIList).P->front().first->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00006378 if (!Ty->isFirstClassType())
6379 error("PHI node operands must be of first class type");
6380 PHINode *PHI = new PHINode(Ty);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006381 PHI->reserveOperandSpace((yyvsp[0].PHIList).P->size());
6382 while ((yyvsp[0].PHIList).P->begin() != (yyvsp[0].PHIList).P->end()) {
6383 if ((yyvsp[0].PHIList).P->front().first->getType() != Ty)
Reid Spencer950bf602007-01-26 08:19:09 +00006384 error("All elements of a PHI node must be of the same type");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006385 PHI->addIncoming((yyvsp[0].PHIList).P->front().first, (yyvsp[0].PHIList).P->front().second);
6386 (yyvsp[0].PHIList).P->pop_front();
Reid Spencer950bf602007-01-26 08:19:09 +00006387 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006388 (yyval.InstVal).I = PHI;
Reid Spencerbb1fd572007-03-21 17:15:50 +00006389 (yyval.InstVal).S.copy((yyvsp[0].PHIList).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006390 delete (yyvsp[0].PHIList).P; // Free the list...
6391 ;}
6392 break;
Reid Spencer950bf602007-01-26 08:19:09 +00006393
Reid Spencerd2920cd2007-03-21 17:27:53 +00006394 case 297:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006395#line 3725 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006396 {
Reid Spencer950bf602007-01-26 08:19:09 +00006397 // Handle the short call syntax
6398 const PointerType *PFTy;
6399 const FunctionType *FTy;
Reid Spencerbb1fd572007-03-21 17:15:50 +00006400 Signedness FTySign;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006401 if (!(PFTy = dyn_cast<PointerType>((yyvsp[-4].TypeVal).PAT->get())) ||
Reid Spencer950bf602007-01-26 08:19:09 +00006402 !(FTy = dyn_cast<FunctionType>(PFTy->getElementType()))) {
6403 // Pull out the types of all of the arguments...
6404 std::vector<const Type*> ParamTypes;
Reid Spencerbb1fd572007-03-21 17:15:50 +00006405 FTySign.makeComposite((yyvsp[-4].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006406 if ((yyvsp[-1].ValueList)) {
6407 for (std::vector<ValueInfo>::iterator I = (yyvsp[-1].ValueList)->begin(), E = (yyvsp[-1].ValueList)->end();
Reid Spencerbb1fd572007-03-21 17:15:50 +00006408 I != E; ++I) {
Reid Spencer950bf602007-01-26 08:19:09 +00006409 ParamTypes.push_back((*I).V->getType());
Reid Spencerbb1fd572007-03-21 17:15:50 +00006410 FTySign.add(I->S);
6411 }
Reid Spencer950bf602007-01-26 08:19:09 +00006412 }
6413
6414 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
6415 if (isVarArg) ParamTypes.pop_back();
6416
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006417 const Type *RetTy = (yyvsp[-4].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006418 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
6419 error("Functions cannot return aggregate types");
6420
Reid Spencer7b5d4662007-04-09 06:16:21 +00006421 // Deal with CSRetCC
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006422 ParamAttrsList *PAL = 0;
Reid Spencer7b5d4662007-04-09 06:16:21 +00006423 if ((yyvsp[-5].UIntVal) == OldCallingConv::CSRet) {
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006424 ParamAttrsVector Attrs;
6425 ParamAttrsWithIndex PAWI;
6426 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
6427 Attrs.push_back(PAWI);
6428 PAL = ParamAttrsList::get(Attrs);
Reid Spencer7b5d4662007-04-09 06:16:21 +00006429 }
6430
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006431 FTy = FunctionType::get(RetTy, ParamTypes, isVarArg, PAL);
Reid Spencer950bf602007-01-26 08:19:09 +00006432 PFTy = PointerType::get(FTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006433 (yyval.InstVal).S.copy((yyvsp[-4].TypeVal).S);
6434 } else {
6435 FTySign = (yyvsp[-4].TypeVal).S;
Reid Spencera3b12dd2007-04-07 16:14:01 +00006436 // Get the signedness of the result type. $3 is the pointer to the
6437 // function type so we get the 0th element to extract the function type,
6438 // and then the 0th element again to get the result type.
6439 (yyval.InstVal).S.copy((yyvsp[-4].TypeVal).S.get(0).get(0));
Reid Spencer950bf602007-01-26 08:19:09 +00006440 }
Reid Spencerbb1fd572007-03-21 17:15:50 +00006441 (yyvsp[-3].ValIDVal).S.makeComposite(FTySign);
Reid Spencer950bf602007-01-26 08:19:09 +00006442
6443 // First upgrade any intrinsic calls.
6444 std::vector<Value*> Args;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006445 if ((yyvsp[-1].ValueList))
6446 for (unsigned i = 0, e = (yyvsp[-1].ValueList)->size(); i < e; ++i)
6447 Args.push_back((*(yyvsp[-1].ValueList))[i].V);
Reid Spencer41b213e2007-04-02 01:14:00 +00006448 Instruction *Inst = upgradeIntrinsicCall(FTy->getReturnType(), (yyvsp[-3].ValIDVal), Args);
Reid Spencer950bf602007-01-26 08:19:09 +00006449
6450 // If we got an upgraded intrinsic
6451 if (Inst) {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006452 (yyval.InstVal).I = Inst;
Reid Spencer950bf602007-01-26 08:19:09 +00006453 } else {
6454 // Get the function we're calling
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006455 Value *V = getVal(PFTy, (yyvsp[-3].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00006456
6457 // Check the argument values match
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006458 if (!(yyvsp[-1].ValueList)) { // Has no arguments?
Reid Spencer950bf602007-01-26 08:19:09 +00006459 // Make sure no arguments is a good thing!
6460 if (FTy->getNumParams() != 0)
6461 error("No arguments passed to a function that expects arguments");
6462 } else { // Has arguments?
6463 // Loop through FunctionType's arguments and ensure they are specified
6464 // correctly!
6465 //
6466 FunctionType::param_iterator I = FTy->param_begin();
6467 FunctionType::param_iterator E = FTy->param_end();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006468 std::vector<ValueInfo>::iterator ArgI = (yyvsp[-1].ValueList)->begin(), ArgE = (yyvsp[-1].ValueList)->end();
Reid Spencer950bf602007-01-26 08:19:09 +00006469
6470 for (; ArgI != ArgE && I != E; ++ArgI, ++I)
6471 if ((*ArgI).V->getType() != *I)
6472 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
6473 (*I)->getDescription() + "'");
6474
6475 if (I != E || (ArgI != ArgE && !FTy->isVarArg()))
6476 error("Invalid number of parameters detected");
6477 }
6478
6479 // Create the call instruction
Chris Lattnercf3d0612007-02-13 06:04:17 +00006480 CallInst *CI = new CallInst(V, &Args[0], Args.size());
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006481 CI->setTailCall((yyvsp[-6].BoolVal));
6482 CI->setCallingConv(upgradeCallingConv((yyvsp[-5].UIntVal)));
6483 (yyval.InstVal).I = CI;
Reid Spencer950bf602007-01-26 08:19:09 +00006484 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006485 delete (yyvsp[-4].TypeVal).PAT;
6486 delete (yyvsp[-1].ValueList);
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006487 lastCallingConv = OldCallingConv::C;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006488 ;}
6489 break;
6490
Reid Spencerd2920cd2007-03-21 17:27:53 +00006491 case 298:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006492#line 3818 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006493 {
6494 (yyval.InstVal) = (yyvsp[0].InstVal);
6495 ;}
6496 break;
6497
Reid Spencerd2920cd2007-03-21 17:27:53 +00006498 case 299:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006499#line 3826 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006500 { (yyval.ValueList) = (yyvsp[0].ValueList); ;}
6501 break;
6502
Reid Spencerd2920cd2007-03-21 17:27:53 +00006503 case 300:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006504#line 3827 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006505 { (yyval.ValueList) = new std::vector<ValueInfo>(); ;}
6506 break;
6507
Reid Spencerd2920cd2007-03-21 17:27:53 +00006508 case 301:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006509#line 3831 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006510 { (yyval.BoolVal) = true; ;}
6511 break;
6512
Reid Spencerd2920cd2007-03-21 17:27:53 +00006513 case 302:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006514#line 3832 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006515 { (yyval.BoolVal) = false; ;}
6516 break;
6517
Reid Spencerd2920cd2007-03-21 17:27:53 +00006518 case 303:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006519#line 3836 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006520 {
6521 const Type *Ty = (yyvsp[-1].TypeVal).PAT->get();
Reid Spencerbb1fd572007-03-21 17:15:50 +00006522 (yyval.InstVal).S.makeComposite((yyvsp[-1].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006523 (yyval.InstVal).I = new MallocInst(Ty, 0, (yyvsp[0].UIntVal));
6524 delete (yyvsp[-1].TypeVal).PAT;
6525 ;}
6526 break;
6527
Reid Spencerd2920cd2007-03-21 17:27:53 +00006528 case 304:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006529#line 3842 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006530 {
6531 const Type *Ty = (yyvsp[-4].TypeVal).PAT->get();
Reid Spencerbb1fd572007-03-21 17:15:50 +00006532 (yyvsp[-1].ValIDVal).S.makeUnsigned();
6533 (yyval.InstVal).S.makeComposite((yyvsp[-4].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006534 (yyval.InstVal).I = new MallocInst(Ty, getVal((yyvsp[-2].PrimType).T, (yyvsp[-1].ValIDVal)), (yyvsp[0].UIntVal));
6535 delete (yyvsp[-4].TypeVal).PAT;
6536 ;}
6537 break;
6538
Reid Spencerd2920cd2007-03-21 17:27:53 +00006539 case 305:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006540#line 3849 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006541 {
6542 const Type *Ty = (yyvsp[-1].TypeVal).PAT->get();
Reid Spencerbb1fd572007-03-21 17:15:50 +00006543 (yyval.InstVal).S.makeComposite((yyvsp[-1].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006544 (yyval.InstVal).I = new AllocaInst(Ty, 0, (yyvsp[0].UIntVal));
6545 delete (yyvsp[-1].TypeVal).PAT;
6546 ;}
6547 break;
6548
Reid Spencerd2920cd2007-03-21 17:27:53 +00006549 case 306:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006550#line 3855 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006551 {
6552 const Type *Ty = (yyvsp[-4].TypeVal).PAT->get();
Reid Spencerbb1fd572007-03-21 17:15:50 +00006553 (yyvsp[-1].ValIDVal).S.makeUnsigned();
6554 (yyval.InstVal).S.makeComposite((yyvsp[-2].PrimType).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006555 (yyval.InstVal).I = new AllocaInst(Ty, getVal((yyvsp[-2].PrimType).T, (yyvsp[-1].ValIDVal)), (yyvsp[0].UIntVal));
6556 delete (yyvsp[-4].TypeVal).PAT;
6557 ;}
6558 break;
6559
Reid Spencerd2920cd2007-03-21 17:27:53 +00006560 case 307:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006561#line 3862 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006562 {
6563 const Type *PTy = (yyvsp[0].ValueVal).V->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00006564 if (!isa<PointerType>(PTy))
6565 error("Trying to free nonpointer type '" + PTy->getDescription() + "'");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006566 (yyval.InstVal).I = new FreeInst((yyvsp[0].ValueVal).V);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006567 (yyval.InstVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006568 ;}
6569 break;
6570
Reid Spencerd2920cd2007-03-21 17:27:53 +00006571 case 308:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006572#line 3869 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006573 {
6574 const Type* Ty = (yyvsp[-1].TypeVal).PAT->get();
Reid Spencerbb1fd572007-03-21 17:15:50 +00006575 (yyvsp[0].ValIDVal).S.copy((yyvsp[-1].TypeVal).S);
Reid Spencer950bf602007-01-26 08:19:09 +00006576 if (!isa<PointerType>(Ty))
6577 error("Can't load from nonpointer type: " + Ty->getDescription());
6578 if (!cast<PointerType>(Ty)->getElementType()->isFirstClassType())
6579 error("Can't load from pointer of non-first-class type: " +
6580 Ty->getDescription());
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006581 Value* tmpVal = getVal(Ty, (yyvsp[0].ValIDVal));
6582 (yyval.InstVal).I = new LoadInst(tmpVal, "", (yyvsp[-3].BoolVal));
Reid Spencerbb1fd572007-03-21 17:15:50 +00006583 (yyval.InstVal).S.copy((yyvsp[-1].TypeVal).S.get(0));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006584 delete (yyvsp[-1].TypeVal).PAT;
6585 ;}
6586 break;
6587
Reid Spencerd2920cd2007-03-21 17:27:53 +00006588 case 309:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006589#line 3882 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006590 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00006591 (yyvsp[0].ValIDVal).S.copy((yyvsp[-1].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006592 const PointerType *PTy = dyn_cast<PointerType>((yyvsp[-1].TypeVal).PAT->get());
Reid Spencered96d1e2007-02-08 09:08:52 +00006593 if (!PTy)
6594 error("Can't store to a nonpointer type: " +
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006595 (yyvsp[-1].TypeVal).PAT->get()->getDescription());
Reid Spencered96d1e2007-02-08 09:08:52 +00006596 const Type *ElTy = PTy->getElementType();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006597 Value *StoreVal = (yyvsp[-3].ValueVal).V;
6598 Value* tmpVal = getVal(PTy, (yyvsp[0].ValIDVal));
6599 if (ElTy != (yyvsp[-3].ValueVal).V->getType()) {
6600 StoreVal = handleSRetFuncTypeMerge((yyvsp[-3].ValueVal).V, ElTy);
Reid Spencered96d1e2007-02-08 09:08:52 +00006601 if (!StoreVal)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006602 error("Can't store '" + (yyvsp[-3].ValueVal).V->getType()->getDescription() +
Reid Spencered96d1e2007-02-08 09:08:52 +00006603 "' into space of type '" + ElTy->getDescription() + "'");
6604 else {
6605 PTy = PointerType::get(StoreVal->getType());
6606 if (Constant *C = dyn_cast<Constant>(tmpVal))
6607 tmpVal = ConstantExpr::getBitCast(C, PTy);
6608 else
6609 tmpVal = new BitCastInst(tmpVal, PTy, "upgrd.cast", CurBB);
6610 }
6611 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006612 (yyval.InstVal).I = new StoreInst(StoreVal, tmpVal, (yyvsp[-5].BoolVal));
Reid Spencerbb1fd572007-03-21 17:15:50 +00006613 (yyval.InstVal).S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006614 delete (yyvsp[-1].TypeVal).PAT;
6615 ;}
6616 break;
6617
Reid Spencerd2920cd2007-03-21 17:27:53 +00006618 case 310:
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006619#line 3908 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006620 {
Reid Spencerbb1fd572007-03-21 17:15:50 +00006621 (yyvsp[-1].ValIDVal).S.copy((yyvsp[-2].TypeVal).S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006622 const Type* Ty = (yyvsp[-2].TypeVal).PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006623 if (!isa<PointerType>(Ty))
6624 error("getelementptr insn requires pointer operand");
6625
6626 std::vector<Value*> VIndices;
Reid Spencerff0e4482007-04-16 00:40:57 +00006627 upgradeGEPInstIndices(Ty, (yyvsp[0].ValueList), VIndices);
Reid Spencer950bf602007-01-26 08:19:09 +00006628
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006629 Value* tmpVal = getVal(Ty, (yyvsp[-1].ValIDVal));
6630 (yyval.InstVal).I = new GetElementPtrInst(tmpVal, &VIndices[0], VIndices.size());
Reid Spencerbb1fd572007-03-21 17:15:50 +00006631 ValueInfo VI; VI.V = tmpVal; VI.S.copy((yyvsp[-2].TypeVal).S);
6632 (yyval.InstVal).S.copy(getElementSign(VI, VIndices));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006633 delete (yyvsp[-2].TypeVal).PAT;
6634 delete (yyvsp[0].ValueList);
6635 ;}
6636 break;
6637
6638
6639 default: break;
6640 }
6641
6642/* Line 1126 of yacc.c. */
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006643#line 6644 "UpgradeParser.tab.c"
Chris Lattnercf3d0612007-02-13 06:04:17 +00006644
6645 yyvsp -= yylen;
6646 yyssp -= yylen;
Reid Spencerb7046c72007-01-29 05:41:34 +00006647
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006648
6649 YY_STACK_PRINT (yyss, yyssp);
Reid Spencere7c3c602006-11-30 06:36:44 +00006650
6651 *++yyvsp = yyval;
6652
6653
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006654 /* Now `shift' the result of the reduction. Determine what state
6655 that goes to, based on the state we popped back to and the rule
6656 number reduced by. */
Reid Spencere7c3c602006-11-30 06:36:44 +00006657
6658 yyn = yyr1[yyn];
6659
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006660 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
6661 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
Reid Spencere7c3c602006-11-30 06:36:44 +00006662 yystate = yytable[yystate];
6663 else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006664 yystate = yydefgoto[yyn - YYNTOKENS];
Reid Spencere7c3c602006-11-30 06:36:44 +00006665
6666 goto yynewstate;
6667
6668
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006669/*------------------------------------.
6670| yyerrlab -- here on detecting error |
6671`------------------------------------*/
6672yyerrlab:
6673 /* If not already recovering from an error, report this error. */
6674 if (!yyerrstatus)
Reid Spencere7c3c602006-11-30 06:36:44 +00006675 {
6676 ++yynerrs;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006677#if YYERROR_VERBOSE
Chris Lattnercf3d0612007-02-13 06:04:17 +00006678 yyn = yypact[yystate];
6679
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006680 if (YYPACT_NINF < yyn && yyn < YYLAST)
Chris Lattnercf3d0612007-02-13 06:04:17 +00006681 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006682 int yytype = YYTRANSLATE (yychar);
6683 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
6684 YYSIZE_T yysize = yysize0;
6685 YYSIZE_T yysize1;
6686 int yysize_overflow = 0;
6687 char *yymsg = 0;
6688# define YYERROR_VERBOSE_ARGS_MAXIMUM 5
6689 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
6690 int yyx;
Chris Lattnercf3d0612007-02-13 06:04:17 +00006691
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006692#if 0
6693 /* This is so xgettext sees the translatable formats that are
6694 constructed on the fly. */
6695 YY_("syntax error, unexpected %s");
6696 YY_("syntax error, unexpected %s, expecting %s");
6697 YY_("syntax error, unexpected %s, expecting %s or %s");
6698 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
6699 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
6700#endif
6701 char *yyfmt;
6702 char const *yyf;
6703 static char const yyunexpected[] = "syntax error, unexpected %s";
6704 static char const yyexpecting[] = ", expecting %s";
6705 static char const yyor[] = " or %s";
6706 char yyformat[sizeof yyunexpected
6707 + sizeof yyexpecting - 1
6708 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
6709 * (sizeof yyor - 1))];
6710 char const *yyprefix = yyexpecting;
6711
6712 /* Start YYX at -YYN if negative to avoid negative indexes in
6713 YYCHECK. */
6714 int yyxbegin = yyn < 0 ? -yyn : 0;
6715
6716 /* Stay within bounds of both yycheck and yytname. */
6717 int yychecklim = YYLAST - yyn;
6718 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
6719 int yycount = 1;
6720
6721 yyarg[0] = yytname[yytype];
6722 yyfmt = yystpcpy (yyformat, yyunexpected);
6723
6724 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
6725 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
6726 {
6727 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
6728 {
6729 yycount = 1;
6730 yysize = yysize0;
6731 yyformat[sizeof yyunexpected - 1] = '\0';
6732 break;
6733 }
6734 yyarg[yycount++] = yytname[yyx];
6735 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
6736 yysize_overflow |= yysize1 < yysize;
6737 yysize = yysize1;
6738 yyfmt = yystpcpy (yyfmt, yyprefix);
6739 yyprefix = yyor;
6740 }
6741
6742 yyf = YY_(yyformat);
6743 yysize1 = yysize + yystrlen (yyf);
6744 yysize_overflow |= yysize1 < yysize;
6745 yysize = yysize1;
6746
6747 if (!yysize_overflow && yysize <= YYSTACK_ALLOC_MAXIMUM)
6748 yymsg = (char *) YYSTACK_ALLOC (yysize);
6749 if (yymsg)
Chris Lattnercf3d0612007-02-13 06:04:17 +00006750 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006751 /* Avoid sprintf, as that infringes on the user's name space.
6752 Don't have undefined behavior even if the translation
6753 produced a string with the wrong number of "%s"s. */
6754 char *yyp = yymsg;
6755 int yyi = 0;
6756 while ((*yyp = *yyf))
Chris Lattnercf3d0612007-02-13 06:04:17 +00006757 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006758 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
6759 {
6760 yyp += yytnamerr (yyp, yyarg[yyi++]);
6761 yyf += 2;
6762 }
6763 else
6764 {
6765 yyp++;
6766 yyf++;
6767 }
Chris Lattnercf3d0612007-02-13 06:04:17 +00006768 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006769 yyerror (yymsg);
6770 YYSTACK_FREE (yymsg);
Chris Lattnercf3d0612007-02-13 06:04:17 +00006771 }
6772 else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006773 {
6774 yyerror (YY_("syntax error"));
6775 goto yyexhaustedlab;
6776 }
Chris Lattnercf3d0612007-02-13 06:04:17 +00006777 }
6778 else
6779#endif /* YYERROR_VERBOSE */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006780 yyerror (YY_("syntax error"));
Reid Spencere7c3c602006-11-30 06:36:44 +00006781 }
Reid Spencer950bf602007-01-26 08:19:09 +00006782
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006783
Reid Spencer950bf602007-01-26 08:19:09 +00006784
6785 if (yyerrstatus == 3)
6786 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006787 /* If just tried and failed to reuse look-ahead token after an
6788 error, discard it. */
Reid Spencer950bf602007-01-26 08:19:09 +00006789
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006790 if (yychar <= YYEOF)
6791 {
6792 /* Return failure if at end of input. */
6793 if (yychar == YYEOF)
6794 YYABORT;
6795 }
6796 else
6797 {
6798 yydestruct ("Error: discarding", yytoken, &yylval);
6799 yychar = YYEMPTY;
6800 }
6801 }
6802
6803 /* Else will try to reuse look-ahead token after shifting the error
6804 token. */
6805 goto yyerrlab1;
6806
6807
6808/*---------------------------------------------------.
6809| yyerrorlab -- error raised explicitly by YYERROR. |
6810`---------------------------------------------------*/
6811yyerrorlab:
6812
6813 /* Pacify compilers like GCC when the user code never invokes
6814 YYERROR and the label yyerrorlab therefore never appears in user
6815 code. */
6816 if (0)
6817 goto yyerrorlab;
6818
6819yyvsp -= yylen;
6820 yyssp -= yylen;
6821 yystate = *yyssp;
6822 goto yyerrlab1;
6823
6824
6825/*-------------------------------------------------------------.
6826| yyerrlab1 -- common code for both syntax error and YYERROR. |
6827`-------------------------------------------------------------*/
6828yyerrlab1:
6829 yyerrstatus = 3; /* Each real token shifted decrements this. */
6830
6831 for (;;)
6832 {
6833 yyn = yypact[yystate];
6834 if (yyn != YYPACT_NINF)
6835 {
6836 yyn += YYTERROR;
6837 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
6838 {
6839 yyn = yytable[yyn];
6840 if (0 < yyn)
6841 break;
6842 }
6843 }
6844
6845 /* Pop the current state because it cannot handle the error token. */
6846 if (yyssp == yyss)
Reid Spencere7c3c602006-11-30 06:36:44 +00006847 YYABORT;
6848
6849
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006850 yydestruct ("Error: popping", yystos[yystate], yyvsp);
6851 YYPOPSTACK;
6852 yystate = *yyssp;
6853 YY_STACK_PRINT (yyss, yyssp);
Reid Spencere7c3c602006-11-30 06:36:44 +00006854 }
6855
6856 if (yyn == YYFINAL)
6857 YYACCEPT;
6858
6859 *++yyvsp = yylval;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006860
6861
6862 /* Shift the error token. */
6863 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
Reid Spencer950bf602007-01-26 08:19:09 +00006864
Reid Spencere7c3c602006-11-30 06:36:44 +00006865 yystate = yyn;
6866 goto yynewstate;
6867
Chris Lattner4227bdb2007-02-19 07:34:02 +00006868
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006869/*-------------------------------------.
6870| yyacceptlab -- YYACCEPT comes here. |
6871`-------------------------------------*/
6872yyacceptlab:
6873 yyresult = 0;
6874 goto yyreturn;
6875
6876/*-----------------------------------.
6877| yyabortlab -- YYABORT comes here. |
6878`-----------------------------------*/
6879yyabortlab:
6880 yyresult = 1;
6881 goto yyreturn;
6882
6883#ifndef yyoverflow
6884/*-------------------------------------------------.
6885| yyexhaustedlab -- memory exhaustion comes here. |
6886`-------------------------------------------------*/
6887yyexhaustedlab:
6888 yyerror (YY_("memory exhausted"));
6889 yyresult = 2;
6890 /* Fall through. */
Chris Lattner4227bdb2007-02-19 07:34:02 +00006891#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006892
6893yyreturn:
6894 if (yychar != YYEOF && yychar != YYEMPTY)
6895 yydestruct ("Cleanup: discarding lookahead",
6896 yytoken, &yylval);
6897 while (yyssp != yyss)
6898 {
6899 yydestruct ("Cleanup: popping",
6900 yystos[*yyssp], yyvsp);
6901 YYPOPSTACK;
Chris Lattner4227bdb2007-02-19 07:34:02 +00006902 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006903#ifndef yyoverflow
6904 if (yyss != yyssa)
6905 YYSTACK_FREE (yyss);
6906#endif
6907 return yyresult;
Reid Spencere7c3c602006-11-30 06:36:44 +00006908}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006909
6910
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006911#line 3926 "/proj/llvm/llvm-4/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencere7c3c602006-11-30 06:36:44 +00006912
6913
6914int yyerror(const char *ErrorMsg) {
6915 std::string where
6916 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
Reid Spencered96d1e2007-02-08 09:08:52 +00006917 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
Reid Spencer950bf602007-01-26 08:19:09 +00006918 std::string errMsg = where + "error: " + std::string(ErrorMsg);
6919 if (yychar != YYEMPTY && yychar != 0)
6920 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
6921 "'.";
Reid Spencer71d2ec92006-12-31 06:02:26 +00006922 std::cerr << "llvm-upgrade: " << errMsg << '\n';
Reid Spencer950bf602007-01-26 08:19:09 +00006923 std::cout << "llvm-upgrade: parse failed.\n";
Reid Spencere7c3c602006-11-30 06:36:44 +00006924 exit(1);
6925}
Reid Spencer319a7302007-01-05 17:20:02 +00006926
Reid Spencer30d0c582007-01-15 00:26:18 +00006927void warning(const std::string& ErrorMsg) {
Reid Spencer319a7302007-01-05 17:20:02 +00006928 std::string where
6929 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
Reid Spencered96d1e2007-02-08 09:08:52 +00006930 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
Reid Spencer950bf602007-01-26 08:19:09 +00006931 std::string errMsg = where + "warning: " + std::string(ErrorMsg);
6932 if (yychar != YYEMPTY && yychar != 0)
6933 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
6934 "'.";
Reid Spencer319a7302007-01-05 17:20:02 +00006935 std::cerr << "llvm-upgrade: " << errMsg << '\n';
6936}
6937
Reid Spencer950bf602007-01-26 08:19:09 +00006938void error(const std::string& ErrorMsg, int LineNo) {
6939 if (LineNo == -1) LineNo = Upgradelineno;
6940 Upgradelineno = LineNo;
6941 yyerror(ErrorMsg.c_str());
6942}
6943
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006944