blob: c7935bcc21b498ea2cc9e12ed35f9f90603a9669 [file] [log] [blame]
David Greene718fda32007-08-01 03:59:32 +00001/* A Bison parser, made by GNU Bison 1.875c. */
Reid Spencere7c3c602006-11-30 06:36:44 +00002
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003/* Skeleton parser for Yacc-like parsing with Bison,
David Greene718fda32007-08-01 03:59:32 +00004 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 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
David Greene718fda32007-08-01 03:59:32 +000018 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +000020
21/* As a special exception, when this file is copied by Bison into a
22 Bison output file, you may use that output file without restriction.
23 This special exception was added by the Free Software Foundation
24 in version 1.24 of Bison. */
25
26/* Written by Richard Stallman by simplifying the original so called
27 ``semantic'' parser. */
28
29/* All symbols defined below should begin with yy or YY, to avoid
30 infringing on user name space. This should be done even for local
31 variables, as they might otherwise be expanded by user macros.
32 There are some unavoidable exceptions within include files to
33 define necessary library symbols; they are noted "INFRINGES ON
34 USER NAME SPACE" below. */
35
36/* Identify Bison output. */
37#define YYBISON 1
38
Reid Spencer3fae7ba2007-03-14 23:13:06 +000039/* Skeleton name. */
40#define YYSKELETON_NAME "yacc.c"
41
42/* Pure parsers. */
43#define YYPURE 0
44
45/* Using locations. */
46#define YYLSP_NEEDED 0
47
David Greene718fda32007-08-01 03:59:32 +000048/* If NAME_PREFIX is specified substitute the variables and functions
49 names. */
Reid Spencere7c3c602006-11-30 06:36:44 +000050#define yyparse Upgradeparse
Reid Spencer3fae7ba2007-03-14 23:13:06 +000051#define yylex Upgradelex
Reid Spencere7c3c602006-11-30 06:36:44 +000052#define yyerror Upgradeerror
Reid Spencer3fae7ba2007-03-14 23:13:06 +000053#define yylval Upgradelval
54#define yychar Upgradechar
Reid Spencere7c3c602006-11-30 06:36:44 +000055#define yydebug Upgradedebug
56#define yynerrs Upgradenerrs
57
Reid Spencer3fae7ba2007-03-14 23:13:06 +000058
59/* Tokens. */
60#ifndef YYTOKENTYPE
61# define YYTOKENTYPE
62 /* Put the tokens into the symbol table, so that GDB and other debuggers
63 know about them. */
64 enum yytokentype {
65 ESINT64VAL = 258,
66 EUINT64VAL = 259,
67 SINTVAL = 260,
68 UINTVAL = 261,
69 FPVAL = 262,
70 VOID = 263,
71 BOOL = 264,
72 SBYTE = 265,
73 UBYTE = 266,
74 SHORT = 267,
75 USHORT = 268,
76 INT = 269,
77 UINT = 270,
78 LONG = 271,
79 ULONG = 272,
80 FLOAT = 273,
81 DOUBLE = 274,
82 TYPE = 275,
83 LABEL = 276,
84 VAR_ID = 277,
85 LABELSTR = 278,
86 STRINGCONSTANT = 279,
87 IMPLEMENTATION = 280,
88 ZEROINITIALIZER = 281,
89 TRUETOK = 282,
90 FALSETOK = 283,
91 BEGINTOK = 284,
92 ENDTOK = 285,
93 DECLARE = 286,
94 GLOBAL = 287,
95 CONSTANT = 288,
96 SECTION = 289,
97 VOLATILE = 290,
98 TO = 291,
99 DOTDOTDOT = 292,
100 NULL_TOK = 293,
101 UNDEF = 294,
102 CONST = 295,
103 INTERNAL = 296,
104 LINKONCE = 297,
105 WEAK = 298,
106 APPENDING = 299,
107 DLLIMPORT = 300,
108 DLLEXPORT = 301,
109 EXTERN_WEAK = 302,
110 OPAQUE = 303,
111 NOT = 304,
112 EXTERNAL = 305,
113 TARGET = 306,
114 TRIPLE = 307,
115 ENDIAN = 308,
116 POINTERSIZE = 309,
117 LITTLE = 310,
118 BIG = 311,
119 ALIGN = 312,
120 DEPLIBS = 313,
121 CALL = 314,
122 TAIL = 315,
123 ASM_TOK = 316,
124 MODULE = 317,
125 SIDEEFFECT = 318,
126 CC_TOK = 319,
127 CCC_TOK = 320,
128 CSRETCC_TOK = 321,
129 FASTCC_TOK = 322,
130 COLDCC_TOK = 323,
131 X86_STDCALLCC_TOK = 324,
132 X86_FASTCALLCC_TOK = 325,
133 DATALAYOUT = 326,
134 RET = 327,
135 BR = 328,
136 SWITCH = 329,
137 INVOKE = 330,
138 UNREACHABLE = 331,
139 UNWIND = 332,
140 EXCEPT = 333,
141 ADD = 334,
142 SUB = 335,
143 MUL = 336,
144 DIV = 337,
145 UDIV = 338,
146 SDIV = 339,
147 FDIV = 340,
148 REM = 341,
149 UREM = 342,
150 SREM = 343,
151 FREM = 344,
152 AND = 345,
153 OR = 346,
154 XOR = 347,
155 SHL = 348,
156 SHR = 349,
157 ASHR = 350,
158 LSHR = 351,
159 SETLE = 352,
160 SETGE = 353,
161 SETLT = 354,
162 SETGT = 355,
163 SETEQ = 356,
164 SETNE = 357,
165 ICMP = 358,
166 FCMP = 359,
167 MALLOC = 360,
168 ALLOCA = 361,
169 FREE = 362,
170 LOAD = 363,
171 STORE = 364,
172 GETELEMENTPTR = 365,
173 PHI_TOK = 366,
174 SELECT = 367,
175 VAARG = 368,
176 EXTRACTELEMENT = 369,
177 INSERTELEMENT = 370,
178 SHUFFLEVECTOR = 371,
179 VAARG_old = 372,
180 VANEXT_old = 373,
181 EQ = 374,
182 NE = 375,
183 SLT = 376,
184 SGT = 377,
185 SLE = 378,
186 SGE = 379,
187 ULT = 380,
188 UGT = 381,
189 ULE = 382,
190 UGE = 383,
191 OEQ = 384,
192 ONE = 385,
193 OLT = 386,
194 OGT = 387,
195 OLE = 388,
196 OGE = 389,
197 ORD = 390,
198 UNO = 391,
199 UEQ = 392,
200 UNE = 393,
201 CAST = 394,
202 TRUNC = 395,
203 ZEXT = 396,
204 SEXT = 397,
205 FPTRUNC = 398,
206 FPEXT = 399,
207 FPTOUI = 400,
208 FPTOSI = 401,
209 UITOFP = 402,
210 SITOFP = 403,
211 PTRTOINT = 404,
212 INTTOPTR = 405,
213 BITCAST = 406
214 };
215#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +0000216#define ESINT64VAL 258
217#define EUINT64VAL 259
218#define SINTVAL 260
219#define UINTVAL 261
220#define FPVAL 262
221#define VOID 263
222#define BOOL 264
223#define SBYTE 265
224#define UBYTE 266
225#define SHORT 267
226#define USHORT 268
227#define INT 269
228#define UINT 270
229#define LONG 271
230#define ULONG 272
231#define FLOAT 273
232#define DOUBLE 274
233#define TYPE 275
234#define LABEL 276
235#define VAR_ID 277
236#define LABELSTR 278
237#define STRINGCONSTANT 279
238#define IMPLEMENTATION 280
239#define ZEROINITIALIZER 281
240#define TRUETOK 282
241#define FALSETOK 283
242#define BEGINTOK 284
243#define ENDTOK 285
244#define DECLARE 286
245#define GLOBAL 287
246#define CONSTANT 288
247#define SECTION 289
248#define VOLATILE 290
249#define TO 291
250#define DOTDOTDOT 292
251#define NULL_TOK 293
252#define UNDEF 294
253#define CONST 295
254#define INTERNAL 296
255#define LINKONCE 297
256#define WEAK 298
257#define APPENDING 299
258#define DLLIMPORT 300
259#define DLLEXPORT 301
260#define EXTERN_WEAK 302
261#define OPAQUE 303
262#define NOT 304
263#define EXTERNAL 305
264#define TARGET 306
265#define TRIPLE 307
266#define ENDIAN 308
267#define POINTERSIZE 309
268#define LITTLE 310
269#define BIG 311
270#define ALIGN 312
271#define DEPLIBS 313
272#define CALL 314
273#define TAIL 315
274#define ASM_TOK 316
275#define MODULE 317
276#define SIDEEFFECT 318
277#define CC_TOK 319
278#define CCC_TOK 320
279#define CSRETCC_TOK 321
280#define FASTCC_TOK 322
281#define COLDCC_TOK 323
282#define X86_STDCALLCC_TOK 324
283#define X86_FASTCALLCC_TOK 325
284#define DATALAYOUT 326
285#define RET 327
286#define BR 328
287#define SWITCH 329
288#define INVOKE 330
289#define UNREACHABLE 331
290#define UNWIND 332
291#define EXCEPT 333
292#define ADD 334
293#define SUB 335
294#define MUL 336
295#define DIV 337
296#define UDIV 338
297#define SDIV 339
298#define FDIV 340
299#define REM 341
300#define UREM 342
301#define SREM 343
302#define FREM 344
303#define AND 345
304#define OR 346
305#define XOR 347
306#define SHL 348
307#define SHR 349
308#define ASHR 350
309#define LSHR 351
310#define SETLE 352
311#define SETGE 353
312#define SETLT 354
313#define SETGT 355
314#define SETEQ 356
315#define SETNE 357
316#define ICMP 358
317#define FCMP 359
318#define MALLOC 360
319#define ALLOCA 361
320#define FREE 362
321#define LOAD 363
322#define STORE 364
323#define GETELEMENTPTR 365
324#define PHI_TOK 366
325#define SELECT 367
326#define VAARG 368
327#define EXTRACTELEMENT 369
328#define INSERTELEMENT 370
329#define SHUFFLEVECTOR 371
330#define VAARG_old 372
331#define VANEXT_old 373
332#define EQ 374
333#define NE 375
334#define SLT 376
335#define SGT 377
336#define SLE 378
337#define SGE 379
338#define ULT 380
339#define UGT 381
340#define ULE 382
341#define UGE 383
342#define OEQ 384
343#define ONE 385
344#define OLT 386
345#define OGT 387
346#define OLE 388
347#define OGE 389
348#define ORD 390
349#define UNO 391
350#define UEQ 392
351#define UNE 393
352#define CAST 394
353#define TRUNC 395
354#define ZEXT 396
355#define SEXT 397
356#define FPTRUNC 398
357#define FPEXT 399
358#define FPTOUI 400
359#define FPTOSI 401
360#define UITOFP 402
361#define SITOFP 403
362#define PTRTOINT 404
363#define INTTOPTR 405
364#define BITCAST 406
365
366
367
368
369/* Copy the first part of user declarations. */
David Greene718fda32007-08-01 03:59:32 +0000370#line 14 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer319a7302007-01-05 17:20:02 +0000371
372#include "UpgradeInternals.h"
Reid Spencer950bf602007-01-26 08:19:09 +0000373#include "llvm/CallingConv.h"
374#include "llvm/InlineAsm.h"
375#include "llvm/Instructions.h"
376#include "llvm/Module.h"
Reid Spencer7b5d4662007-04-09 06:16:21 +0000377#include "llvm/ParameterAttributes.h"
Reid Spenceref9b9a72007-02-05 20:47:22 +0000378#include "llvm/ValueSymbolTable.h"
Reid Spencer950bf602007-01-26 08:19:09 +0000379#include "llvm/Support/GetElementPtrTypeIterator.h"
380#include "llvm/ADT/STLExtras.h"
381#include "llvm/Support/MathExtras.h"
Reid Spencere7c3c602006-11-30 06:36:44 +0000382#include <algorithm>
Reid Spencere7c3c602006-11-30 06:36:44 +0000383#include <iostream>
Chris Lattner8adde282007-02-11 21:40:10 +0000384#include <map>
Reid Spencer950bf602007-01-26 08:19:09 +0000385#include <list>
386#include <utility>
387
388// DEBUG_UPREFS - Define this symbol if you want to enable debugging output
389// relating to upreferences in the input stream.
390//
391//#define DEBUG_UPREFS 1
392#ifdef DEBUG_UPREFS
393#define UR_OUT(X) std::cerr << X
394#else
395#define UR_OUT(X)
396#endif
Reid Spencere7c3c602006-11-30 06:36:44 +0000397
Reid Spencere77e35e2006-12-01 20:26:20 +0000398#define YYERROR_VERBOSE 1
Reid Spencer96839be2006-11-30 16:50:26 +0000399#define YYINCLUDED_STDLIB_H
Reid Spencere77e35e2006-12-01 20:26:20 +0000400#define YYDEBUG 1
Reid Spencere7c3c602006-11-30 06:36:44 +0000401
Reid Spencer950bf602007-01-26 08:19:09 +0000402int yylex();
Reid Spencere7c3c602006-11-30 06:36:44 +0000403int yyparse();
404
Reid Spencer950bf602007-01-26 08:19:09 +0000405int yyerror(const char*);
406static void warning(const std::string& WarningMsg);
407
408namespace llvm {
409
Reid Spencer950bf602007-01-26 08:19:09 +0000410std::istream* LexInput;
Reid Spencere7c3c602006-11-30 06:36:44 +0000411static std::string CurFilename;
Reid Spencer96839be2006-11-30 16:50:26 +0000412
Reid Spencer71d2ec92006-12-31 06:02:26 +0000413// This bool controls whether attributes are ever added to function declarations
414// definitions and calls.
415static bool AddAttributes = false;
416
Reid Spencer950bf602007-01-26 08:19:09 +0000417static Module *ParserResult;
418static bool ObsoleteVarArgs;
419static bool NewVarArgs;
420static BasicBlock *CurBB;
421static GlobalVariable *CurGV;
Reid Spencer7eea8ff2007-05-18 05:48:07 +0000422static unsigned lastCallingConv;
Reid Spencera50d5962006-12-02 04:11:07 +0000423
Reid Spencer950bf602007-01-26 08:19:09 +0000424// This contains info used when building the body of a function. It is
425// destroyed when the function is completed.
426//
427typedef std::vector<Value *> ValueList; // Numbered defs
428
Reid Spencerbb1fd572007-03-21 17:15:50 +0000429typedef std::pair<std::string,TypeInfo> RenameMapKey;
Reid Spencer950bf602007-01-26 08:19:09 +0000430typedef std::map<RenameMapKey,std::string> RenameMapType;
431
432static void
433ResolveDefinitions(std::map<const Type *,ValueList> &LateResolvers,
434 std::map<const Type *,ValueList> *FutureLateResolvers = 0);
435
436static struct PerModuleInfo {
437 Module *CurrentModule;
438 std::map<const Type *, ValueList> Values; // Module level numbered definitions
439 std::map<const Type *,ValueList> LateResolveValues;
Reid Spencerbb1fd572007-03-21 17:15:50 +0000440 std::vector<PATypeHolder> Types;
441 std::vector<Signedness> TypeSigns;
442 std::map<std::string,Signedness> NamedTypeSigns;
443 std::map<std::string,Signedness> NamedValueSigns;
Reid Spencer950bf602007-01-26 08:19:09 +0000444 std::map<ValID, PATypeHolder> LateResolveTypes;
445 static Module::Endianness Endian;
446 static Module::PointerSize PointerSize;
447 RenameMapType RenameMap;
448
449 /// PlaceHolderInfo - When temporary placeholder objects are created, remember
450 /// how they were referenced and on which line of the input they came from so
451 /// that we can resolve them later and print error messages as appropriate.
452 std::map<Value*, std::pair<ValID, int> > PlaceHolderInfo;
453
454 // GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
455 // references to global values. Global values may be referenced before they
456 // are defined, and if so, the temporary object that they represent is held
457 // here. This is used for forward references of GlobalValues.
458 //
459 typedef std::map<std::pair<const PointerType *, ValID>, GlobalValue*>
460 GlobalRefsType;
461 GlobalRefsType GlobalRefs;
462
463 void ModuleDone() {
464 // If we could not resolve some functions at function compilation time
465 // (calls to functions before they are defined), resolve them now... Types
466 // are resolved when the constant pool has been completely parsed.
467 //
468 ResolveDefinitions(LateResolveValues);
469
470 // Check to make sure that all global value forward references have been
471 // resolved!
472 //
473 if (!GlobalRefs.empty()) {
474 std::string UndefinedReferences = "Unresolved global references exist:\n";
475
476 for (GlobalRefsType::iterator I = GlobalRefs.begin(), E =GlobalRefs.end();
477 I != E; ++I) {
478 UndefinedReferences += " " + I->first.first->getDescription() + " " +
479 I->first.second.getName() + "\n";
480 }
481 error(UndefinedReferences);
482 return;
483 }
484
485 if (CurrentModule->getDataLayout().empty()) {
486 std::string dataLayout;
487 if (Endian != Module::AnyEndianness)
488 dataLayout.append(Endian == Module::BigEndian ? "E" : "e");
489 if (PointerSize != Module::AnyPointerSize) {
490 if (!dataLayout.empty())
491 dataLayout += "-";
492 dataLayout.append(PointerSize == Module::Pointer64 ?
493 "p:64:64" : "p:32:32");
494 }
495 CurrentModule->setDataLayout(dataLayout);
496 }
497
498 Values.clear(); // Clear out function local definitions
499 Types.clear();
Reid Spencerbb1fd572007-03-21 17:15:50 +0000500 TypeSigns.clear();
501 NamedTypeSigns.clear();
502 NamedValueSigns.clear();
Reid Spencer950bf602007-01-26 08:19:09 +0000503 CurrentModule = 0;
504 }
505
506 // GetForwardRefForGlobal - Check to see if there is a forward reference
507 // for this global. If so, remove it from the GlobalRefs map and return it.
508 // If not, just return null.
509 GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ValID ID) {
510 // Check to see if there is a forward reference to this global variable...
511 // if there is, eliminate it and patch the reference to use the new def'n.
512 GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PTy, ID));
513 GlobalValue *Ret = 0;
514 if (I != GlobalRefs.end()) {
515 Ret = I->second;
516 GlobalRefs.erase(I);
517 }
518 return Ret;
519 }
520 void setEndianness(Module::Endianness E) { Endian = E; }
521 void setPointerSize(Module::PointerSize sz) { PointerSize = sz; }
522} CurModule;
523
524Module::Endianness PerModuleInfo::Endian = Module::AnyEndianness;
525Module::PointerSize PerModuleInfo::PointerSize = Module::AnyPointerSize;
526
527static struct PerFunctionInfo {
528 Function *CurrentFunction; // Pointer to current function being created
529
530 std::map<const Type*, ValueList> Values; // Keep track of #'d definitions
531 std::map<const Type*, ValueList> LateResolveValues;
532 bool isDeclare; // Is this function a forward declararation?
533 GlobalValue::LinkageTypes Linkage;// Linkage for forward declaration.
534
535 /// BBForwardRefs - When we see forward references to basic blocks, keep
536 /// track of them here.
537 std::map<BasicBlock*, std::pair<ValID, int> > BBForwardRefs;
538 std::vector<BasicBlock*> NumberedBlocks;
539 RenameMapType RenameMap;
Reid Spencer950bf602007-01-26 08:19:09 +0000540 unsigned NextBBNum;
541
542 inline PerFunctionInfo() {
543 CurrentFunction = 0;
544 isDeclare = false;
545 Linkage = GlobalValue::ExternalLinkage;
546 }
547
548 inline void FunctionStart(Function *M) {
549 CurrentFunction = M;
550 NextBBNum = 0;
551 }
552
553 void FunctionDone() {
554 NumberedBlocks.clear();
555
556 // Any forward referenced blocks left?
557 if (!BBForwardRefs.empty()) {
558 error("Undefined reference to label " +
559 BBForwardRefs.begin()->first->getName());
560 return;
561 }
562
563 // Resolve all forward references now.
564 ResolveDefinitions(LateResolveValues, &CurModule.LateResolveValues);
565
566 Values.clear(); // Clear out function local definitions
567 RenameMap.clear();
Reid Spencer950bf602007-01-26 08:19:09 +0000568 CurrentFunction = 0;
569 isDeclare = false;
570 Linkage = GlobalValue::ExternalLinkage;
571 }
572} CurFun; // Info for the current function...
573
574static bool inFunctionScope() { return CurFun.CurrentFunction != 0; }
575
Reid Spencerbb1fd572007-03-21 17:15:50 +0000576/// This function is just a utility to make a Key value for the rename map.
577/// The Key is a combination of the name, type, Signedness of the original
578/// value (global/function). This just constructs the key and ensures that
579/// named Signedness values are resolved to the actual Signedness.
580/// @brief Make a key for the RenameMaps
581static RenameMapKey makeRenameMapKey(const std::string &Name, const Type* Ty,
582 const Signedness &Sign) {
583 TypeInfo TI;
584 TI.T = Ty;
585 if (Sign.isNamed())
586 // Don't allow Named Signedness nodes because they won't match. The actual
587 // Signedness must be looked up in the NamedTypeSigns map.
588 TI.S.copy(CurModule.NamedTypeSigns[Sign.getName()]);
589 else
590 TI.S.copy(Sign);
591 return std::make_pair(Name, TI);
592}
593
Reid Spencer950bf602007-01-26 08:19:09 +0000594
595//===----------------------------------------------------------------------===//
596// Code to handle definitions of all the types
597//===----------------------------------------------------------------------===//
598
599static int InsertValue(Value *V,
600 std::map<const Type*,ValueList> &ValueTab = CurFun.Values) {
601 if (V->hasName()) return -1; // Is this a numbered definition?
602
603 // Yes, insert the value into the value table...
604 ValueList &List = ValueTab[V->getType()];
605 List.push_back(V);
606 return List.size()-1;
607}
608
Reid Spencerd7c4f8c2007-01-26 19:59:25 +0000609static const Type *getType(const ValID &D, bool DoNotImprovise = false) {
Reid Spencer950bf602007-01-26 08:19:09 +0000610 switch (D.Type) {
611 case ValID::NumberVal: // Is it a numbered definition?
612 // Module constants occupy the lowest numbered slots...
613 if ((unsigned)D.Num < CurModule.Types.size()) {
614 return CurModule.Types[(unsigned)D.Num];
615 }
616 break;
617 case ValID::NameVal: // Is it a named definition?
618 if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) {
Reid Spencer950bf602007-01-26 08:19:09 +0000619 return N;
620 }
621 break;
622 default:
623 error("Internal parser error: Invalid symbol type reference");
624 return 0;
625 }
626
627 // If we reached here, we referenced either a symbol that we don't know about
628 // or an id number that hasn't been read yet. We may be referencing something
629 // forward, so just create an entry to be resolved later and get to it...
630 //
631 if (DoNotImprovise) return 0; // Do we just want a null to be returned?
632
Reid Spencer950bf602007-01-26 08:19:09 +0000633 if (inFunctionScope()) {
634 if (D.Type == ValID::NameVal) {
635 error("Reference to an undefined type: '" + D.getName() + "'");
636 return 0;
637 } else {
638 error("Reference to an undefined type: #" + itostr(D.Num));
639 return 0;
640 }
641 }
642
643 std::map<ValID, PATypeHolder>::iterator I =CurModule.LateResolveTypes.find(D);
644 if (I != CurModule.LateResolveTypes.end())
645 return I->second;
646
647 Type *Typ = OpaqueType::get();
648 CurModule.LateResolveTypes.insert(std::make_pair(D, Typ));
649 return Typ;
Reid Spencerbb1fd572007-03-21 17:15:50 +0000650}
651
652/// This is like the getType method except that instead of looking up the type
653/// for a given ID, it looks up that type's sign.
654/// @brief Get the signedness of a referenced type
655static Signedness getTypeSign(const ValID &D) {
656 switch (D.Type) {
657 case ValID::NumberVal: // Is it a numbered definition?
658 // Module constants occupy the lowest numbered slots...
659 if ((unsigned)D.Num < CurModule.TypeSigns.size()) {
660 return CurModule.TypeSigns[(unsigned)D.Num];
661 }
662 break;
663 case ValID::NameVal: { // Is it a named definition?
664 std::map<std::string,Signedness>::const_iterator I =
665 CurModule.NamedTypeSigns.find(D.Name);
666 if (I != CurModule.NamedTypeSigns.end())
667 return I->second;
668 // Perhaps its a named forward .. just cache the name
669 Signedness S;
670 S.makeNamed(D.Name);
671 return S;
672 }
673 default:
674 break;
675 }
676 // If we don't find it, its signless
677 Signedness S;
678 S.makeSignless();
679 return S;
680}
681
682/// This function is analagous to getElementType in LLVM. It provides the same
683/// function except that it looks up the Signedness instead of the type. This is
684/// used when processing GEP instructions that need to extract the type of an
685/// indexed struct/array/ptr member.
686/// @brief Look up an element's sign.
687static Signedness getElementSign(const ValueInfo& VI,
688 const std::vector<Value*> &Indices) {
689 const Type *Ptr = VI.V->getType();
690 assert(isa<PointerType>(Ptr) && "Need pointer type");
691
692 unsigned CurIdx = 0;
693 Signedness S(VI.S);
694 while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) {
695 if (CurIdx == Indices.size())
696 break;
697
698 Value *Index = Indices[CurIdx++];
699 assert(!isa<PointerType>(CT) || CurIdx == 1 && "Invalid type");
700 Ptr = CT->getTypeAtIndex(Index);
701 if (const Type* Ty = Ptr->getForwardedType())
702 Ptr = Ty;
703 assert(S.isComposite() && "Bad Signedness type");
704 if (isa<StructType>(CT)) {
705 S = S.get(cast<ConstantInt>(Index)->getZExtValue());
706 } else {
707 S = S.get(0UL);
708 }
709 if (S.isNamed())
710 S = CurModule.NamedTypeSigns[S.getName()];
711 }
712 Signedness Result;
713 Result.makeComposite(S);
714 return Result;
715}
716
717/// This function just translates a ConstantInfo into a ValueInfo and calls
718/// getElementSign(ValueInfo,...). Its just a convenience.
719/// @brief ConstantInfo version of getElementSign.
720static Signedness getElementSign(const ConstInfo& CI,
721 const std::vector<Constant*> &Indices) {
722 ValueInfo VI;
723 VI.V = CI.C;
724 VI.S.copy(CI.S);
725 std::vector<Value*> Idx;
726 for (unsigned i = 0; i < Indices.size(); ++i)
727 Idx.push_back(Indices[i]);
728 Signedness result = getElementSign(VI, Idx);
729 VI.destroy();
730 return result;
731}
Reid Spencer950bf602007-01-26 08:19:09 +0000732
Reid Spencered96d1e2007-02-08 09:08:52 +0000733/// This function determines if two function types differ only in their use of
734/// the sret parameter attribute in the first argument. If they are identical
735/// in all other respects, it returns true. Otherwise, it returns false.
Reid Spencerbb1fd572007-03-21 17:15:50 +0000736static bool FuncTysDifferOnlyBySRet(const FunctionType *F1,
737 const FunctionType *F2) {
Reid Spencered96d1e2007-02-08 09:08:52 +0000738 if (F1->getReturnType() != F2->getReturnType() ||
Reid Spencer7b5d4662007-04-09 06:16:21 +0000739 F1->getNumParams() != F2->getNumParams())
Reid Spencered96d1e2007-02-08 09:08:52 +0000740 return false;
Reid Spencer7eea8ff2007-05-18 05:48:07 +0000741 const ParamAttrsList *PAL1 = F1->getParamAttrs();
742 const ParamAttrsList *PAL2 = F2->getParamAttrs();
743 if (PAL1 && !PAL2 || PAL2 && !PAL1)
744 return false;
745 if (PAL1 && PAL2 && ((PAL1->size() != PAL2->size()) ||
746 (PAL1->getParamAttrs(0) != PAL2->getParamAttrs(0))))
Reid Spencer7b5d4662007-04-09 06:16:21 +0000747 return false;
Reid Spencer18da0722007-04-11 02:44:20 +0000748 unsigned SRetMask = ~unsigned(ParamAttr::StructRet);
Reid Spencered96d1e2007-02-08 09:08:52 +0000749 for (unsigned i = 0; i < F1->getNumParams(); ++i) {
Reid Spencer7eea8ff2007-05-18 05:48:07 +0000750 if (F1->getParamType(i) != F2->getParamType(i) || (PAL1 && PAL2 &&
751 (unsigned(PAL1->getParamAttrs(i+1)) & SRetMask !=
752 unsigned(PAL2->getParamAttrs(i+1)) & SRetMask)))
Reid Spencered96d1e2007-02-08 09:08:52 +0000753 return false;
754 }
755 return true;
756}
757
Reid Spencerbb1fd572007-03-21 17:15:50 +0000758/// This function determines if the type of V and Ty differ only by the SRet
759/// parameter attribute. This is a more generalized case of
760/// FuncTysDIfferOnlyBySRet since it doesn't require FunctionType arguments.
761static bool TypesDifferOnlyBySRet(Value *V, const Type* Ty) {
762 if (V->getType() == Ty)
763 return true;
764 const PointerType *PF1 = dyn_cast<PointerType>(Ty);
765 const PointerType *PF2 = dyn_cast<PointerType>(V->getType());
766 if (PF1 && PF2) {
767 const FunctionType* FT1 = dyn_cast<FunctionType>(PF1->getElementType());
768 const FunctionType* FT2 = dyn_cast<FunctionType>(PF2->getElementType());
769 if (FT1 && FT2)
770 return FuncTysDifferOnlyBySRet(FT1, FT2);
771 }
772 return false;
773}
774
Reid Spencered96d1e2007-02-08 09:08:52 +0000775// The upgrade of csretcc to sret param attribute may have caused a function
776// to not be found because the param attribute changed the type of the called
777// function. This helper function, used in getExistingValue, detects that
Reid Spencerbb1fd572007-03-21 17:15:50 +0000778// situation and bitcasts the function to the correct type.
Reid Spencered96d1e2007-02-08 09:08:52 +0000779static Value* handleSRetFuncTypeMerge(Value *V, const Type* Ty) {
780 // Handle degenerate cases
781 if (!V)
782 return 0;
783 if (V->getType() == Ty)
784 return V;
785
Reid Spencered96d1e2007-02-08 09:08:52 +0000786 const PointerType *PF1 = dyn_cast<PointerType>(Ty);
787 const PointerType *PF2 = dyn_cast<PointerType>(V->getType());
788 if (PF1 && PF2) {
Reid Spencerbb1fd572007-03-21 17:15:50 +0000789 const FunctionType *FT1 = dyn_cast<FunctionType>(PF1->getElementType());
790 const FunctionType *FT2 = dyn_cast<FunctionType>(PF2->getElementType());
Reid Spencer7b5d4662007-04-09 06:16:21 +0000791 if (FT1 && FT2 && FuncTysDifferOnlyBySRet(FT1, FT2)) {
792 const ParamAttrsList *PAL2 = FT2->getParamAttrs();
Reid Spencer18da0722007-04-11 02:44:20 +0000793 if (PAL2 && PAL2->paramHasAttr(1, ParamAttr::StructRet))
Reid Spencerbb1fd572007-03-21 17:15:50 +0000794 return V;
Reid Spencered96d1e2007-02-08 09:08:52 +0000795 else if (Constant *C = dyn_cast<Constant>(V))
Reid Spencerbb1fd572007-03-21 17:15:50 +0000796 return ConstantExpr::getBitCast(C, PF1);
Reid Spencered96d1e2007-02-08 09:08:52 +0000797 else
Reid Spencerbb1fd572007-03-21 17:15:50 +0000798 return new BitCastInst(V, PF1, "upgrd.cast", CurBB);
Reid Spencer7b5d4662007-04-09 06:16:21 +0000799 }
Reid Spencerbb1fd572007-03-21 17:15:50 +0000800
Reid Spencered96d1e2007-02-08 09:08:52 +0000801 }
Reid Spencerbb1fd572007-03-21 17:15:50 +0000802 return 0;
Reid Spencered96d1e2007-02-08 09:08:52 +0000803}
804
Reid Spencer950bf602007-01-26 08:19:09 +0000805// getExistingValue - Look up the value specified by the provided type and
806// the provided ValID. If the value exists and has already been defined, return
807// it. Otherwise return null.
808//
809static Value *getExistingValue(const Type *Ty, const ValID &D) {
810 if (isa<FunctionType>(Ty)) {
811 error("Functions are not values and must be referenced as pointers");
812 }
813
814 switch (D.Type) {
815 case ValID::NumberVal: { // Is it a numbered definition?
816 unsigned Num = (unsigned)D.Num;
817
818 // Module constants occupy the lowest numbered slots...
819 std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
820 if (VI != CurModule.Values.end()) {
821 if (Num < VI->second.size())
822 return VI->second[Num];
823 Num -= VI->second.size();
824 }
825
826 // Make sure that our type is within bounds
827 VI = CurFun.Values.find(Ty);
828 if (VI == CurFun.Values.end()) return 0;
829
830 // Check that the number is within bounds...
831 if (VI->second.size() <= Num) return 0;
832
833 return VI->second[Num];
834 }
835
836 case ValID::NameVal: { // Is it a named definition?
837 // Get the name out of the ID
Reid Spencerbb1fd572007-03-21 17:15:50 +0000838 RenameMapKey Key = makeRenameMapKey(D.Name, Ty, D.S);
839 Value *V = 0;
Reid Spencer950bf602007-01-26 08:19:09 +0000840 if (inFunctionScope()) {
841 // See if the name was renamed
842 RenameMapType::const_iterator I = CurFun.RenameMap.find(Key);
843 std::string LookupName;
844 if (I != CurFun.RenameMap.end())
845 LookupName = I->second;
846 else
Reid Spencerbb1fd572007-03-21 17:15:50 +0000847 LookupName = D.Name;
Reid Spenceref9b9a72007-02-05 20:47:22 +0000848 ValueSymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable();
849 V = SymTab.lookup(LookupName);
Reid Spencerbb1fd572007-03-21 17:15:50 +0000850 if (V && V->getType() != Ty)
851 V = handleSRetFuncTypeMerge(V, Ty);
852 assert((!V || TypesDifferOnlyBySRet(V, Ty)) && "Found wrong type");
Reid Spencer950bf602007-01-26 08:19:09 +0000853 }
854 if (!V) {
855 RenameMapType::const_iterator I = CurModule.RenameMap.find(Key);
856 std::string LookupName;
857 if (I != CurModule.RenameMap.end())
858 LookupName = I->second;
859 else
Reid Spencerbb1fd572007-03-21 17:15:50 +0000860 LookupName = D.Name;
Reid Spenceref9b9a72007-02-05 20:47:22 +0000861 V = CurModule.CurrentModule->getValueSymbolTable().lookup(LookupName);
Reid Spencerbb1fd572007-03-21 17:15:50 +0000862 if (V && V->getType() != Ty)
863 V = handleSRetFuncTypeMerge(V, Ty);
864 assert((!V || TypesDifferOnlyBySRet(V, Ty)) && "Found wrong type");
Reid Spencer950bf602007-01-26 08:19:09 +0000865 }
Reid Spenceref9b9a72007-02-05 20:47:22 +0000866 if (!V)
Reid Spencer950bf602007-01-26 08:19:09 +0000867 return 0;
868
869 D.destroy(); // Free old strdup'd memory...
870 return V;
871 }
872
873 // Check to make sure that "Ty" is an integral type, and that our
874 // value will fit into the specified type...
875 case ValID::ConstSIntVal: // Is it a constant pool reference??
876 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
877 error("Signed integral constant '" + itostr(D.ConstPool64) +
878 "' is invalid for type '" + Ty->getDescription() + "'");
879 }
880 return ConstantInt::get(Ty, D.ConstPool64);
881
882 case ValID::ConstUIntVal: // Is it an unsigned const pool reference?
883 if (!ConstantInt::isValueValidForType(Ty, D.UConstPool64)) {
884 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64))
885 error("Integral constant '" + utostr(D.UConstPool64) +
886 "' is invalid or out of range");
887 else // This is really a signed reference. Transmogrify.
888 return ConstantInt::get(Ty, D.ConstPool64);
889 } else
890 return ConstantInt::get(Ty, D.UConstPool64);
891
892 case ValID::ConstFPVal: // Is it a floating point const pool reference?
893 if (!ConstantFP::isValueValidForType(Ty, D.ConstPoolFP))
894 error("FP constant invalid for type");
895 return ConstantFP::get(Ty, D.ConstPoolFP);
896
897 case ValID::ConstNullVal: // Is it a null value?
898 if (!isa<PointerType>(Ty))
899 error("Cannot create a a non pointer null");
900 return ConstantPointerNull::get(cast<PointerType>(Ty));
901
902 case ValID::ConstUndefVal: // Is it an undef value?
903 return UndefValue::get(Ty);
904
905 case ValID::ConstZeroVal: // Is it a zero value?
906 return Constant::getNullValue(Ty);
907
908 case ValID::ConstantVal: // Fully resolved constant?
909 if (D.ConstantValue->getType() != Ty)
910 error("Constant expression type different from required type");
911 return D.ConstantValue;
912
913 case ValID::InlineAsmVal: { // Inline asm expression
914 const PointerType *PTy = dyn_cast<PointerType>(Ty);
915 const FunctionType *FTy =
916 PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
917 if (!FTy || !InlineAsm::Verify(FTy, D.IAD->Constraints))
918 error("Invalid type for asm constraint string");
919 InlineAsm *IA = InlineAsm::get(FTy, D.IAD->AsmString, D.IAD->Constraints,
920 D.IAD->HasSideEffects);
921 D.destroy(); // Free InlineAsmDescriptor.
922 return IA;
923 }
924 default:
925 assert(0 && "Unhandled case");
926 return 0;
927 } // End of switch
928
929 assert(0 && "Unhandled case");
930 return 0;
931}
932
933// getVal - This function is identical to getExistingValue, except that if a
934// value is not already defined, it "improvises" by creating a placeholder var
935// that looks and acts just like the requested variable. When the value is
936// defined later, all uses of the placeholder variable are replaced with the
937// real thing.
938//
939static Value *getVal(const Type *Ty, const ValID &ID) {
940 if (Ty == Type::LabelTy)
941 error("Cannot use a basic block here");
942
943 // See if the value has already been defined.
944 Value *V = getExistingValue(Ty, ID);
945 if (V) return V;
946
947 if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty))
948 error("Invalid use of a composite type");
949
950 // If we reached here, we referenced either a symbol that we don't know about
951 // or an id number that hasn't been read yet. We may be referencing something
952 // forward, so just create an entry to be resolved later and get to it...
Reid Spencer950bf602007-01-26 08:19:09 +0000953 V = new Argument(Ty);
954
955 // Remember where this forward reference came from. FIXME, shouldn't we try
956 // to recycle these things??
957 CurModule.PlaceHolderInfo.insert(
Reid Spenceref9b9a72007-02-05 20:47:22 +0000958 std::make_pair(V, std::make_pair(ID, Upgradelineno)));
Reid Spencer950bf602007-01-26 08:19:09 +0000959
960 if (inFunctionScope())
961 InsertValue(V, CurFun.LateResolveValues);
962 else
963 InsertValue(V, CurModule.LateResolveValues);
964 return V;
965}
966
Reid Spencered96d1e2007-02-08 09:08:52 +0000967/// @brief This just makes any name given to it unique, up to MAX_UINT times.
968static std::string makeNameUnique(const std::string& Name) {
969 static unsigned UniqueNameCounter = 1;
970 std::string Result(Name);
971 Result += ".upgrd." + llvm::utostr(UniqueNameCounter++);
972 return Result;
973}
974
Reid Spencer950bf602007-01-26 08:19:09 +0000975/// getBBVal - This is used for two purposes:
976/// * If isDefinition is true, a new basic block with the specified ID is being
977/// defined.
978/// * If isDefinition is true, this is a reference to a basic block, which may
979/// or may not be a forward reference.
980///
981static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
982 assert(inFunctionScope() && "Can't get basic block at global scope");
983
984 std::string Name;
985 BasicBlock *BB = 0;
986 switch (ID.Type) {
987 default:
988 error("Illegal label reference " + ID.getName());
989 break;
990 case ValID::NumberVal: // Is it a numbered definition?
991 if (unsigned(ID.Num) >= CurFun.NumberedBlocks.size())
992 CurFun.NumberedBlocks.resize(ID.Num+1);
993 BB = CurFun.NumberedBlocks[ID.Num];
994 break;
995 case ValID::NameVal: // Is it a named definition?
996 Name = ID.Name;
Reid Spencerbb1fd572007-03-21 17:15:50 +0000997 if (Value *N = CurFun.CurrentFunction->getValueSymbolTable().lookup(Name)) {
Reid Spencered96d1e2007-02-08 09:08:52 +0000998 if (N->getType() != Type::LabelTy) {
999 // Register names didn't use to conflict with basic block names
1000 // because of type planes. Now they all have to be unique. So, we just
1001 // rename the register and treat this name as if no basic block
1002 // had been found.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001003 RenameMapKey Key = makeRenameMapKey(ID.Name, N->getType(), ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00001004 N->setName(makeNameUnique(N->getName()));
1005 CurModule.RenameMap[Key] = N->getName();
1006 BB = 0;
1007 } else {
1008 BB = cast<BasicBlock>(N);
1009 }
Reid Spencer950bf602007-01-26 08:19:09 +00001010 }
1011 break;
1012 }
1013
1014 // See if the block has already been defined.
1015 if (BB) {
1016 // If this is the definition of the block, make sure the existing value was
1017 // just a forward reference. If it was a forward reference, there will be
1018 // an entry for it in the PlaceHolderInfo map.
1019 if (isDefinition && !CurFun.BBForwardRefs.erase(BB))
1020 // The existing value was a definition, not a forward reference.
1021 error("Redefinition of label " + ID.getName());
1022
1023 ID.destroy(); // Free strdup'd memory.
1024 return BB;
1025 }
1026
1027 // Otherwise this block has not been seen before.
1028 BB = new BasicBlock("", CurFun.CurrentFunction);
1029 if (ID.Type == ValID::NameVal) {
1030 BB->setName(ID.Name);
1031 } else {
1032 CurFun.NumberedBlocks[ID.Num] = BB;
1033 }
1034
1035 // If this is not a definition, keep track of it so we can use it as a forward
1036 // reference.
1037 if (!isDefinition) {
1038 // Remember where this forward reference came from.
1039 CurFun.BBForwardRefs[BB] = std::make_pair(ID, Upgradelineno);
1040 } else {
1041 // The forward declaration could have been inserted anywhere in the
1042 // function: insert it into the correct place now.
1043 CurFun.CurrentFunction->getBasicBlockList().remove(BB);
1044 CurFun.CurrentFunction->getBasicBlockList().push_back(BB);
1045 }
1046 ID.destroy();
1047 return BB;
1048}
1049
1050
1051//===----------------------------------------------------------------------===//
1052// Code to handle forward references in instructions
1053//===----------------------------------------------------------------------===//
1054//
1055// This code handles the late binding needed with statements that reference
1056// values not defined yet... for example, a forward branch, or the PHI node for
1057// a loop body.
1058//
1059// This keeps a table (CurFun.LateResolveValues) of all such forward references
1060// and back patchs after we are done.
1061//
1062
1063// ResolveDefinitions - If we could not resolve some defs at parsing
1064// time (forward branches, phi functions for loops, etc...) resolve the
1065// defs now...
1066//
1067static void
1068ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
1069 std::map<const Type*,ValueList> *FutureLateResolvers) {
Reid Spencered96d1e2007-02-08 09:08:52 +00001070
Reid Spencer950bf602007-01-26 08:19:09 +00001071 // Loop over LateResolveDefs fixing up stuff that couldn't be resolved
1072 for (std::map<const Type*,ValueList>::iterator LRI = LateResolvers.begin(),
1073 E = LateResolvers.end(); LRI != E; ++LRI) {
Reid Spencered96d1e2007-02-08 09:08:52 +00001074 const Type* Ty = LRI->first;
Reid Spencer950bf602007-01-26 08:19:09 +00001075 ValueList &List = LRI->second;
1076 while (!List.empty()) {
1077 Value *V = List.back();
1078 List.pop_back();
1079
1080 std::map<Value*, std::pair<ValID, int> >::iterator PHI =
1081 CurModule.PlaceHolderInfo.find(V);
1082 assert(PHI != CurModule.PlaceHolderInfo.end() && "Placeholder error");
1083
1084 ValID &DID = PHI->second.first;
1085
Reid Spencered96d1e2007-02-08 09:08:52 +00001086 Value *TheRealValue = getExistingValue(Ty, DID);
Reid Spencer950bf602007-01-26 08:19:09 +00001087 if (TheRealValue) {
1088 V->replaceAllUsesWith(TheRealValue);
1089 delete V;
1090 CurModule.PlaceHolderInfo.erase(PHI);
1091 } else if (FutureLateResolvers) {
1092 // Functions have their unresolved items forwarded to the module late
1093 // resolver table
1094 InsertValue(V, *FutureLateResolvers);
1095 } else {
1096 if (DID.Type == ValID::NameVal) {
Reid Spencered96d1e2007-02-08 09:08:52 +00001097 error("Reference to an invalid definition: '" + DID.getName() +
1098 "' of type '" + V->getType()->getDescription() + "'",
1099 PHI->second.second);
Reid Spencer7de2e012007-01-29 19:08:46 +00001100 return;
Reid Spencer950bf602007-01-26 08:19:09 +00001101 } else {
1102 error("Reference to an invalid definition: #" +
1103 itostr(DID.Num) + " of type '" +
1104 V->getType()->getDescription() + "'", PHI->second.second);
1105 return;
1106 }
1107 }
1108 }
1109 }
1110
1111 LateResolvers.clear();
1112}
1113
Reid Spencerbb1fd572007-03-21 17:15:50 +00001114/// This function is used for type resolution and upref handling. When a type
1115/// becomes concrete, this function is called to adjust the signedness for the
1116/// concrete type.
1117static void ResolveTypeSign(const Type* oldTy, const Signedness &Sign) {
1118 std::string TyName = CurModule.CurrentModule->getTypeName(oldTy);
1119 if (!TyName.empty())
1120 CurModule.NamedTypeSigns[TyName] = Sign;
1121}
1122
1123/// ResolveTypeTo - A brand new type was just declared. This means that (if
1124/// name is not null) things referencing Name can be resolved. Otherwise,
1125/// things refering to the number can be resolved. Do this now.
1126static void ResolveTypeTo(char *Name, const Type *ToTy, const Signedness& Sign){
Reid Spencer950bf602007-01-26 08:19:09 +00001127 ValID D;
Reid Spencerbb1fd572007-03-21 17:15:50 +00001128 if (Name)
1129 D = ValID::create(Name);
1130 else
1131 D = ValID::create((int)CurModule.Types.size());
1132 D.S.copy(Sign);
1133
Reid Spencerbaba98a2007-04-11 12:10:58 +00001134 if (Name)
1135 CurModule.NamedTypeSigns[Name] = Sign;
Reid Spencer950bf602007-01-26 08:19:09 +00001136
1137 std::map<ValID, PATypeHolder>::iterator I =
1138 CurModule.LateResolveTypes.find(D);
1139 if (I != CurModule.LateResolveTypes.end()) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00001140 const Type *OldTy = I->second.get();
1141 ((DerivedType*)OldTy)->refineAbstractTypeTo(ToTy);
Reid Spencer950bf602007-01-26 08:19:09 +00001142 CurModule.LateResolveTypes.erase(I);
1143 }
1144}
1145
Anton Korobeynikovce13b852007-01-28 15:25:24 +00001146/// This is the implementation portion of TypeHasInteger. It traverses the
1147/// type given, avoiding recursive types, and returns true as soon as it finds
1148/// an integer type. If no integer type is found, it returns false.
1149static bool TypeHasIntegerI(const Type *Ty, std::vector<const Type*> Stack) {
1150 // Handle some easy cases
1151 if (Ty->isPrimitiveType() || (Ty->getTypeID() == Type::OpaqueTyID))
1152 return false;
1153 if (Ty->isInteger())
1154 return true;
1155 if (const SequentialType *STy = dyn_cast<SequentialType>(Ty))
1156 return STy->getElementType()->isInteger();
1157
1158 // Avoid type structure recursion
1159 for (std::vector<const Type*>::iterator I = Stack.begin(), E = Stack.end();
1160 I != E; ++I)
1161 if (Ty == *I)
1162 return false;
1163
1164 // Push us on the type stack
1165 Stack.push_back(Ty);
1166
1167 if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
1168 if (TypeHasIntegerI(FTy->getReturnType(), Stack))
1169 return true;
1170 FunctionType::param_iterator I = FTy->param_begin();
1171 FunctionType::param_iterator E = FTy->param_end();
1172 for (; I != E; ++I)
1173 if (TypeHasIntegerI(*I, Stack))
1174 return true;
1175 return false;
1176 } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
1177 StructType::element_iterator I = STy->element_begin();
1178 StructType::element_iterator E = STy->element_end();
1179 for (; I != E; ++I) {
1180 if (TypeHasIntegerI(*I, Stack))
1181 return true;
1182 }
1183 return false;
1184 }
1185 // There shouldn't be anything else, but its definitely not integer
1186 assert(0 && "What type is this?");
1187 return false;
1188}
1189
1190/// This is the interface to TypeHasIntegerI. It just provides the type stack,
1191/// to avoid recursion, and then calls TypeHasIntegerI.
1192static inline bool TypeHasInteger(const Type *Ty) {
1193 std::vector<const Type*> TyStack;
1194 return TypeHasIntegerI(Ty, TyStack);
1195}
1196
Reid Spencer950bf602007-01-26 08:19:09 +00001197// setValueName - Set the specified value to the name given. The name may be
1198// null potentially, in which case this is a noop. The string passed in is
1199// assumed to be a malloc'd string buffer, and is free'd by this function.
1200//
Reid Spencerbb1fd572007-03-21 17:15:50 +00001201static void setValueName(const ValueInfo &V, char *NameStr) {
Reid Spencer950bf602007-01-26 08:19:09 +00001202 if (NameStr) {
1203 std::string Name(NameStr); // Copy string
1204 free(NameStr); // Free old string
1205
Reid Spencerbb1fd572007-03-21 17:15:50 +00001206 if (V.V->getType() == Type::VoidTy) {
Reid Spencer950bf602007-01-26 08:19:09 +00001207 error("Can't assign name '" + Name + "' to value with void type");
1208 return;
1209 }
1210
Reid Spencer950bf602007-01-26 08:19:09 +00001211 assert(inFunctionScope() && "Must be in function scope");
1212
1213 // Search the function's symbol table for an existing value of this name
Reid Spenceref9b9a72007-02-05 20:47:22 +00001214 ValueSymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
1215 Value* Existing = ST.lookup(Name);
Reid Spencer950bf602007-01-26 08:19:09 +00001216 if (Existing) {
Anton Korobeynikovce13b852007-01-28 15:25:24 +00001217 // An existing value of the same name was found. This might have happened
1218 // because of the integer type planes collapsing in LLVM 2.0.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001219 if (Existing->getType() == V.V->getType() &&
Anton Korobeynikovce13b852007-01-28 15:25:24 +00001220 !TypeHasInteger(Existing->getType())) {
1221 // If the type does not contain any integers in them then this can't be
1222 // a type plane collapsing issue. It truly is a redefinition and we
1223 // should error out as the assembly is invalid.
1224 error("Redefinition of value named '" + Name + "' of type '" +
Reid Spencerbb1fd572007-03-21 17:15:50 +00001225 V.V->getType()->getDescription() + "'");
Anton Korobeynikovce13b852007-01-28 15:25:24 +00001226 return;
Reid Spencer950bf602007-01-26 08:19:09 +00001227 }
1228 // In LLVM 2.0 we don't allow names to be re-used for any values in a
1229 // function, regardless of Type. Previously re-use of names was okay as
1230 // long as they were distinct types. With type planes collapsing because
1231 // of the signedness change and because of PR411, this can no longer be
1232 // supported. We must search the entire symbol table for a conflicting
1233 // name and make the name unique. No warning is needed as this can't
1234 // cause a problem.
1235 std::string NewName = makeNameUnique(Name);
1236 // We're changing the name but it will probably be used by other
1237 // instructions as operands later on. Consequently we have to retain
1238 // a mapping of the renaming that we're doing.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001239 RenameMapKey Key = makeRenameMapKey(Name, V.V->getType(), V.S);
Reid Spencer950bf602007-01-26 08:19:09 +00001240 CurFun.RenameMap[Key] = NewName;
1241 Name = NewName;
1242 }
1243
1244 // Set the name.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001245 V.V->setName(Name);
Reid Spencer950bf602007-01-26 08:19:09 +00001246 }
1247}
1248
1249/// ParseGlobalVariable - Handle parsing of a global. If Initializer is null,
1250/// this is a declaration, otherwise it is a definition.
1251static GlobalVariable *
1252ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
1253 bool isConstantGlobal, const Type *Ty,
Reid Spencerbb1fd572007-03-21 17:15:50 +00001254 Constant *Initializer,
1255 const Signedness &Sign) {
Reid Spencer950bf602007-01-26 08:19:09 +00001256 if (isa<FunctionType>(Ty))
1257 error("Cannot declare global vars of function type");
1258
1259 const PointerType *PTy = PointerType::get(Ty);
1260
1261 std::string Name;
1262 if (NameStr) {
1263 Name = NameStr; // Copy string
1264 free(NameStr); // Free old string
1265 }
1266
1267 // See if this global value was forward referenced. If so, recycle the
1268 // object.
1269 ValID ID;
1270 if (!Name.empty()) {
Reid Spencer5eb77c72007-03-15 03:26:42 +00001271 ID = ValID::create((char*)Name.c_str());
Reid Spencer950bf602007-01-26 08:19:09 +00001272 } else {
Reid Spencer5eb77c72007-03-15 03:26:42 +00001273 ID = ValID::create((int)CurModule.Values[PTy].size());
Reid Spencer950bf602007-01-26 08:19:09 +00001274 }
Reid Spencerbb1fd572007-03-21 17:15:50 +00001275 ID.S.makeComposite(Sign);
Reid Spencer950bf602007-01-26 08:19:09 +00001276
1277 if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) {
1278 // Move the global to the end of the list, from whereever it was
1279 // previously inserted.
1280 GlobalVariable *GV = cast<GlobalVariable>(FWGV);
1281 CurModule.CurrentModule->getGlobalList().remove(GV);
1282 CurModule.CurrentModule->getGlobalList().push_back(GV);
1283 GV->setInitializer(Initializer);
1284 GV->setLinkage(Linkage);
1285 GV->setConstant(isConstantGlobal);
1286 InsertValue(GV, CurModule.Values);
1287 return GV;
1288 }
1289
1290 // If this global has a name, check to see if there is already a definition
1291 // of this global in the module and emit warnings if there are conflicts.
1292 if (!Name.empty()) {
1293 // The global has a name. See if there's an existing one of the same name.
Reid Spencere59f4932007-04-16 03:05:01 +00001294 if (CurModule.CurrentModule->getNamedGlobal(Name) ||
1295 CurModule.CurrentModule->getFunction(Name)) {
1296 // We found an existing global of the same name. This isn't allowed
Reid Spencer950bf602007-01-26 08:19:09 +00001297 // in LLVM 2.0. Consequently, we must alter the name of the global so it
1298 // can at least compile. This can happen because of type planes
1299 // There is alread a global of the same name which means there is a
1300 // conflict. Let's see what we can do about it.
1301 std::string NewName(makeNameUnique(Name));
Reid Spencerbb1fd572007-03-21 17:15:50 +00001302 if (Linkage != GlobalValue::InternalLinkage) {
Reid Spencer950bf602007-01-26 08:19:09 +00001303 // The linkage of this gval is external so we can't reliably rename
1304 // it because it could potentially create a linking problem.
1305 // However, we can't leave the name conflict in the output either or
1306 // it won't assemble with LLVM 2.0. So, all we can do is rename
1307 // this one to something unique and emit a warning about the problem.
1308 warning("Renaming global variable '" + Name + "' to '" + NewName +
1309 "' may cause linkage errors");
1310 }
1311
1312 // Put the renaming in the global rename map
Reid Spencerbb1fd572007-03-21 17:15:50 +00001313 RenameMapKey Key = makeRenameMapKey(Name, PointerType::get(Ty), ID.S);
Reid Spencer950bf602007-01-26 08:19:09 +00001314 CurModule.RenameMap[Key] = NewName;
1315
1316 // Rename it
1317 Name = NewName;
1318 }
1319 }
1320
1321 // Otherwise there is no existing GV to use, create one now.
1322 GlobalVariable *GV =
1323 new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name,
1324 CurModule.CurrentModule);
1325 InsertValue(GV, CurModule.Values);
Reid Spencerbb1fd572007-03-21 17:15:50 +00001326 // Remember the sign of this global.
1327 CurModule.NamedValueSigns[Name] = ID.S;
Reid Spencer950bf602007-01-26 08:19:09 +00001328 return GV;
1329}
1330
1331// setTypeName - Set the specified type to the name given. The name may be
1332// null potentially, in which case this is a noop. The string passed in is
1333// assumed to be a malloc'd string buffer, and is freed by this function.
1334//
1335// This function returns true if the type has already been defined, but is
1336// allowed to be redefined in the specified context. If the name is a new name
1337// for the type plane, it is inserted and false is returned.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001338static bool setTypeName(const PATypeInfo& TI, char *NameStr) {
Reid Spencer950bf602007-01-26 08:19:09 +00001339 assert(!inFunctionScope() && "Can't give types function-local names");
1340 if (NameStr == 0) return false;
1341
1342 std::string Name(NameStr); // Copy string
1343 free(NameStr); // Free old string
1344
Reid Spencerbb1fd572007-03-21 17:15:50 +00001345 const Type* Ty = TI.PAT->get();
1346
Reid Spencer950bf602007-01-26 08:19:09 +00001347 // We don't allow assigning names to void type
Reid Spencerbb1fd572007-03-21 17:15:50 +00001348 if (Ty == Type::VoidTy) {
Reid Spencer950bf602007-01-26 08:19:09 +00001349 error("Can't assign name '" + Name + "' to the void type");
1350 return false;
1351 }
1352
1353 // Set the type name, checking for conflicts as we do so.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001354 bool AlreadyExists = CurModule.CurrentModule->addTypeName(Name, Ty);
1355
1356 // Save the sign information for later use
1357 CurModule.NamedTypeSigns[Name] = TI.S;
Reid Spencer950bf602007-01-26 08:19:09 +00001358
1359 if (AlreadyExists) { // Inserting a name that is already defined???
1360 const Type *Existing = CurModule.CurrentModule->getTypeByName(Name);
1361 assert(Existing && "Conflict but no matching type?");
1362
1363 // There is only one case where this is allowed: when we are refining an
1364 // opaque type. In this case, Existing will be an opaque type.
1365 if (const OpaqueType *OpTy = dyn_cast<OpaqueType>(Existing)) {
1366 // We ARE replacing an opaque type!
Reid Spencerbb1fd572007-03-21 17:15:50 +00001367 const_cast<OpaqueType*>(OpTy)->refineAbstractTypeTo(Ty);
Reid Spencer950bf602007-01-26 08:19:09 +00001368 return true;
1369 }
1370
1371 // Otherwise, this is an attempt to redefine a type. That's okay if
1372 // the redefinition is identical to the original. This will be so if
1373 // Existing and T point to the same Type object. In this one case we
1374 // allow the equivalent redefinition.
Reid Spencerbb1fd572007-03-21 17:15:50 +00001375 if (Existing == Ty) return true; // Yes, it's equal.
Reid Spencer950bf602007-01-26 08:19:09 +00001376
1377 // Any other kind of (non-equivalent) redefinition is an error.
1378 error("Redefinition of type named '" + Name + "' in the '" +
Reid Spencerbb1fd572007-03-21 17:15:50 +00001379 Ty->getDescription() + "' type plane");
Reid Spencer950bf602007-01-26 08:19:09 +00001380 }
1381
1382 return false;
1383}
1384
1385//===----------------------------------------------------------------------===//
1386// Code for handling upreferences in type names...
1387//
1388
1389// TypeContains - Returns true if Ty directly contains E in it.
1390//
1391static bool TypeContains(const Type *Ty, const Type *E) {
1392 return std::find(Ty->subtype_begin(), Ty->subtype_end(),
1393 E) != Ty->subtype_end();
1394}
1395
1396namespace {
1397 struct UpRefRecord {
1398 // NestingLevel - The number of nesting levels that need to be popped before
1399 // this type is resolved.
1400 unsigned NestingLevel;
1401
1402 // LastContainedTy - This is the type at the current binding level for the
1403 // type. Every time we reduce the nesting level, this gets updated.
1404 const Type *LastContainedTy;
1405
1406 // UpRefTy - This is the actual opaque type that the upreference is
1407 // represented with.
1408 OpaqueType *UpRefTy;
1409
1410 UpRefRecord(unsigned NL, OpaqueType *URTy)
Reid Spencerbb1fd572007-03-21 17:15:50 +00001411 : NestingLevel(NL), LastContainedTy(URTy), UpRefTy(URTy) { }
Reid Spencer950bf602007-01-26 08:19:09 +00001412 };
1413}
1414
1415// UpRefs - A list of the outstanding upreferences that need to be resolved.
1416static std::vector<UpRefRecord> UpRefs;
1417
1418/// HandleUpRefs - Every time we finish a new layer of types, this function is
1419/// called. It loops through the UpRefs vector, which is a list of the
1420/// currently active types. For each type, if the up reference is contained in
1421/// the newly completed type, we decrement the level count. When the level
1422/// count reaches zero, the upreferenced type is the type that is passed in:
1423/// thus we can complete the cycle.
1424///
Reid Spencerbb1fd572007-03-21 17:15:50 +00001425static PATypeHolder HandleUpRefs(const Type *ty, const Signedness& Sign) {
Reid Spencer950bf602007-01-26 08:19:09 +00001426 // If Ty isn't abstract, or if there are no up-references in it, then there is
1427 // nothing to resolve here.
1428 if (!ty->isAbstract() || UpRefs.empty()) return ty;
1429
1430 PATypeHolder Ty(ty);
1431 UR_OUT("Type '" << Ty->getDescription() <<
1432 "' newly formed. Resolving upreferences.\n" <<
1433 UpRefs.size() << " upreferences active!\n");
1434
1435 // If we find any resolvable upreferences (i.e., those whose NestingLevel goes
1436 // to zero), we resolve them all together before we resolve them to Ty. At
1437 // the end of the loop, if there is anything to resolve to Ty, it will be in
1438 // this variable.
1439 OpaqueType *TypeToResolve = 0;
1440
Reid Spencerbb1fd572007-03-21 17:15:50 +00001441 unsigned i = 0;
1442 for (; i != UpRefs.size(); ++i) {
Reid Spencer950bf602007-01-26 08:19:09 +00001443 UR_OUT(" UR#" << i << " - TypeContains(" << Ty->getDescription() << ", "
Reid Spencerbb1fd572007-03-21 17:15:50 +00001444 << UpRefs[i].UpRefTy->getDescription() << ") = "
1445 << (TypeContains(Ty, UpRefs[i].UpRefTy) ? "true" : "false") << "\n");
Reid Spencer950bf602007-01-26 08:19:09 +00001446 if (TypeContains(Ty, UpRefs[i].LastContainedTy)) {
1447 // Decrement level of upreference
1448 unsigned Level = --UpRefs[i].NestingLevel;
1449 UpRefs[i].LastContainedTy = Ty;
1450 UR_OUT(" Uplevel Ref Level = " << Level << "\n");
1451 if (Level == 0) { // Upreference should be resolved!
1452 if (!TypeToResolve) {
1453 TypeToResolve = UpRefs[i].UpRefTy;
1454 } else {
1455 UR_OUT(" * Resolving upreference for "
Reid Spencerbb1fd572007-03-21 17:15:50 +00001456 << UpRefs[i].UpRefTy->getDescription() << "\n";
1457 std::string OldName = UpRefs[i].UpRefTy->getDescription());
1458 ResolveTypeSign(UpRefs[i].UpRefTy, Sign);
Reid Spencer950bf602007-01-26 08:19:09 +00001459 UpRefs[i].UpRefTy->refineAbstractTypeTo(TypeToResolve);
1460 UR_OUT(" * Type '" << OldName << "' refined upreference to: "
1461 << (const void*)Ty << ", " << Ty->getDescription() << "\n");
1462 }
1463 UpRefs.erase(UpRefs.begin()+i); // Remove from upreference list...
1464 --i; // Do not skip the next element...
1465 }
1466 }
1467 }
1468
1469 if (TypeToResolve) {
1470 UR_OUT(" * Resolving upreference for "
Reid Spencerbb1fd572007-03-21 17:15:50 +00001471 << UpRefs[i].UpRefTy->getDescription() << "\n";
Reid Spencer950bf602007-01-26 08:19:09 +00001472 std::string OldName = TypeToResolve->getDescription());
Reid Spencerbb1fd572007-03-21 17:15:50 +00001473 ResolveTypeSign(TypeToResolve, Sign);
Reid Spencer950bf602007-01-26 08:19:09 +00001474 TypeToResolve->refineAbstractTypeTo(Ty);
1475 }
1476
1477 return Ty;
1478}
1479
Reid Spencerbb1fd572007-03-21 17:15:50 +00001480bool Signedness::operator<(const Signedness &that) const {
1481 if (isNamed()) {
1482 if (that.isNamed())
1483 return *(this->name) < *(that.name);
1484 else
1485 return CurModule.NamedTypeSigns[*name] < that;
1486 } else if (that.isNamed()) {
1487 return *this < CurModule.NamedTypeSigns[*that.name];
1488 }
1489
1490 if (isComposite() && that.isComposite()) {
1491 if (sv->size() == that.sv->size()) {
1492 SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1493 SignVector::const_iterator thatI = that.sv->begin(),
1494 thatE = that.sv->end();
1495 for (; thisI != thisE; ++thisI, ++thatI) {
1496 if (*thisI < *thatI)
1497 return true;
1498 else if (!(*thisI == *thatI))
1499 return false;
1500 }
1501 return false;
1502 }
1503 return sv->size() < that.sv->size();
1504 }
1505 return kind < that.kind;
1506}
1507
1508bool Signedness::operator==(const Signedness &that) const {
1509 if (isNamed())
1510 if (that.isNamed())
1511 return *(this->name) == *(that.name);
1512 else
1513 return CurModule.NamedTypeSigns[*(this->name)] == that;
1514 else if (that.isNamed())
1515 return *this == CurModule.NamedTypeSigns[*(that.name)];
1516 if (isComposite() && that.isComposite()) {
1517 if (sv->size() == that.sv->size()) {
1518 SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1519 SignVector::const_iterator thatI = that.sv->begin(),
1520 thatE = that.sv->end();
1521 for (; thisI != thisE; ++thisI, ++thatI) {
1522 if (!(*thisI == *thatI))
1523 return false;
1524 }
1525 return true;
1526 }
1527 return false;
1528 }
1529 return kind == that.kind;
1530}
1531
1532void Signedness::copy(const Signedness &that) {
1533 if (that.isNamed()) {
1534 kind = Named;
1535 name = new std::string(*that.name);
1536 } else if (that.isComposite()) {
1537 kind = Composite;
1538 sv = new SignVector();
1539 *sv = *that.sv;
1540 } else {
1541 kind = that.kind;
1542 sv = 0;
1543 }
1544}
1545
1546void Signedness::destroy() {
1547 if (isNamed()) {
1548 delete name;
1549 } else if (isComposite()) {
1550 delete sv;
1551 }
1552}
1553
Evan Cheng2b484202007-03-22 07:43:51 +00001554#ifndef NDEBUG
Reid Spencerbb1fd572007-03-21 17:15:50 +00001555void Signedness::dump() const {
1556 if (isComposite()) {
1557 if (sv->size() == 1) {
1558 (*sv)[0].dump();
1559 std::cerr << "*";
1560 } else {
1561 std::cerr << "{ " ;
1562 for (unsigned i = 0; i < sv->size(); ++i) {
1563 if (i != 0)
1564 std::cerr << ", ";
1565 (*sv)[i].dump();
1566 }
1567 std::cerr << "} " ;
1568 }
1569 } else if (isNamed()) {
1570 std::cerr << *name;
1571 } else if (isSigned()) {
1572 std::cerr << "S";
1573 } else if (isUnsigned()) {
1574 std::cerr << "U";
1575 } else
1576 std::cerr << ".";
1577}
Evan Cheng2b484202007-03-22 07:43:51 +00001578#endif
Reid Spencerbb1fd572007-03-21 17:15:50 +00001579
Reid Spencer950bf602007-01-26 08:19:09 +00001580static inline Instruction::TermOps
1581getTermOp(TermOps op) {
1582 switch (op) {
1583 default : assert(0 && "Invalid OldTermOp");
1584 case RetOp : return Instruction::Ret;
1585 case BrOp : return Instruction::Br;
1586 case SwitchOp : return Instruction::Switch;
1587 case InvokeOp : return Instruction::Invoke;
1588 case UnwindOp : return Instruction::Unwind;
1589 case UnreachableOp: return Instruction::Unreachable;
1590 }
1591}
1592
1593static inline Instruction::BinaryOps
Reid Spencerbb1fd572007-03-21 17:15:50 +00001594getBinaryOp(BinaryOps op, const Type *Ty, const Signedness& Sign) {
Reid Spencer950bf602007-01-26 08:19:09 +00001595 switch (op) {
1596 default : assert(0 && "Invalid OldBinaryOps");
1597 case SetEQ :
1598 case SetNE :
1599 case SetLE :
1600 case SetGE :
1601 case SetLT :
1602 case SetGT : assert(0 && "Should use getCompareOp");
1603 case AddOp : return Instruction::Add;
1604 case SubOp : return Instruction::Sub;
1605 case MulOp : return Instruction::Mul;
1606 case DivOp : {
1607 // This is an obsolete instruction so we must upgrade it based on the
1608 // types of its operands.
1609 bool isFP = Ty->isFloatingPoint();
Reid Spencer9d6565a2007-02-15 02:26:10 +00001610 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
Chris Lattner4227bdb2007-02-19 07:34:02 +00001611 // If its a vector type we want to use the element type
Reid Spencer950bf602007-01-26 08:19:09 +00001612 isFP = PTy->getElementType()->isFloatingPoint();
1613 if (isFP)
1614 return Instruction::FDiv;
Reid Spencerbb1fd572007-03-21 17:15:50 +00001615 else if (Sign.isSigned())
Reid Spencer950bf602007-01-26 08:19:09 +00001616 return Instruction::SDiv;
1617 return Instruction::UDiv;
1618 }
1619 case UDivOp : return Instruction::UDiv;
1620 case SDivOp : return Instruction::SDiv;
1621 case FDivOp : return Instruction::FDiv;
1622 case RemOp : {
1623 // This is an obsolete instruction so we must upgrade it based on the
1624 // types of its operands.
1625 bool isFP = Ty->isFloatingPoint();
Reid Spencer9d6565a2007-02-15 02:26:10 +00001626 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
Chris Lattner4227bdb2007-02-19 07:34:02 +00001627 // If its a vector type we want to use the element type
Reid Spencer950bf602007-01-26 08:19:09 +00001628 isFP = PTy->getElementType()->isFloatingPoint();
1629 // Select correct opcode
1630 if (isFP)
1631 return Instruction::FRem;
Reid Spencerbb1fd572007-03-21 17:15:50 +00001632 else if (Sign.isSigned())
Reid Spencer950bf602007-01-26 08:19:09 +00001633 return Instruction::SRem;
1634 return Instruction::URem;
1635 }
1636 case URemOp : return Instruction::URem;
1637 case SRemOp : return Instruction::SRem;
1638 case FRemOp : return Instruction::FRem;
Reid Spencer832254e2007-02-02 02:16:23 +00001639 case LShrOp : return Instruction::LShr;
1640 case AShrOp : return Instruction::AShr;
1641 case ShlOp : return Instruction::Shl;
1642 case ShrOp :
Reid Spencerbb1fd572007-03-21 17:15:50 +00001643 if (Sign.isSigned())
Reid Spencer832254e2007-02-02 02:16:23 +00001644 return Instruction::AShr;
1645 return Instruction::LShr;
Reid Spencer950bf602007-01-26 08:19:09 +00001646 case AndOp : return Instruction::And;
1647 case OrOp : return Instruction::Or;
1648 case XorOp : return Instruction::Xor;
1649 }
1650}
1651
1652static inline Instruction::OtherOps
1653getCompareOp(BinaryOps op, unsigned short &predicate, const Type* &Ty,
Reid Spencerbb1fd572007-03-21 17:15:50 +00001654 const Signedness &Sign) {
1655 bool isSigned = Sign.isSigned();
Reid Spencer950bf602007-01-26 08:19:09 +00001656 bool isFP = Ty->isFloatingPoint();
1657 switch (op) {
1658 default : assert(0 && "Invalid OldSetCC");
1659 case SetEQ :
1660 if (isFP) {
1661 predicate = FCmpInst::FCMP_OEQ;
1662 return Instruction::FCmp;
1663 } else {
1664 predicate = ICmpInst::ICMP_EQ;
1665 return Instruction::ICmp;
1666 }
1667 case SetNE :
1668 if (isFP) {
1669 predicate = FCmpInst::FCMP_UNE;
1670 return Instruction::FCmp;
1671 } else {
1672 predicate = ICmpInst::ICMP_NE;
1673 return Instruction::ICmp;
1674 }
1675 case SetLE :
1676 if (isFP) {
1677 predicate = FCmpInst::FCMP_OLE;
1678 return Instruction::FCmp;
1679 } else {
1680 if (isSigned)
1681 predicate = ICmpInst::ICMP_SLE;
1682 else
1683 predicate = ICmpInst::ICMP_ULE;
1684 return Instruction::ICmp;
1685 }
1686 case SetGE :
1687 if (isFP) {
1688 predicate = FCmpInst::FCMP_OGE;
1689 return Instruction::FCmp;
1690 } else {
1691 if (isSigned)
1692 predicate = ICmpInst::ICMP_SGE;
1693 else
1694 predicate = ICmpInst::ICMP_UGE;
1695 return Instruction::ICmp;
1696 }
1697 case SetLT :
1698 if (isFP) {
1699 predicate = FCmpInst::FCMP_OLT;
1700 return Instruction::FCmp;
1701 } else {
1702 if (isSigned)
1703 predicate = ICmpInst::ICMP_SLT;
1704 else
1705 predicate = ICmpInst::ICMP_ULT;
1706 return Instruction::ICmp;
1707 }
1708 case SetGT :
1709 if (isFP) {
1710 predicate = FCmpInst::FCMP_OGT;
1711 return Instruction::FCmp;
1712 } else {
1713 if (isSigned)
1714 predicate = ICmpInst::ICMP_SGT;
1715 else
1716 predicate = ICmpInst::ICMP_UGT;
1717 return Instruction::ICmp;
1718 }
1719 }
1720}
1721
1722static inline Instruction::MemoryOps getMemoryOp(MemoryOps op) {
1723 switch (op) {
1724 default : assert(0 && "Invalid OldMemoryOps");
1725 case MallocOp : return Instruction::Malloc;
1726 case FreeOp : return Instruction::Free;
1727 case AllocaOp : return Instruction::Alloca;
1728 case LoadOp : return Instruction::Load;
1729 case StoreOp : return Instruction::Store;
1730 case GetElementPtrOp : return Instruction::GetElementPtr;
1731 }
1732}
1733
1734static inline Instruction::OtherOps
Reid Spencerbb1fd572007-03-21 17:15:50 +00001735getOtherOp(OtherOps op, const Signedness &Sign) {
Reid Spencer950bf602007-01-26 08:19:09 +00001736 switch (op) {
1737 default : assert(0 && "Invalid OldOtherOps");
1738 case PHIOp : return Instruction::PHI;
1739 case CallOp : return Instruction::Call;
Reid Spencer950bf602007-01-26 08:19:09 +00001740 case SelectOp : return Instruction::Select;
1741 case UserOp1 : return Instruction::UserOp1;
1742 case UserOp2 : return Instruction::UserOp2;
1743 case VAArg : return Instruction::VAArg;
1744 case ExtractElementOp : return Instruction::ExtractElement;
1745 case InsertElementOp : return Instruction::InsertElement;
1746 case ShuffleVectorOp : return Instruction::ShuffleVector;
1747 case ICmpOp : return Instruction::ICmp;
1748 case FCmpOp : return Instruction::FCmp;
Reid Spencer950bf602007-01-26 08:19:09 +00001749 };
1750}
1751
1752static inline Value*
Reid Spencerbb1fd572007-03-21 17:15:50 +00001753getCast(CastOps op, Value *Src, const Signedness &SrcSign, const Type *DstTy,
1754 const Signedness &DstSign, bool ForceInstruction = false) {
Reid Spencer950bf602007-01-26 08:19:09 +00001755 Instruction::CastOps Opcode;
1756 const Type* SrcTy = Src->getType();
1757 if (op == CastOp) {
1758 if (SrcTy->isFloatingPoint() && isa<PointerType>(DstTy)) {
1759 // fp -> ptr cast is no longer supported but we must upgrade this
1760 // by doing a double cast: fp -> int -> ptr
1761 SrcTy = Type::Int64Ty;
1762 Opcode = Instruction::IntToPtr;
1763 if (isa<Constant>(Src)) {
1764 Src = ConstantExpr::getCast(Instruction::FPToUI,
1765 cast<Constant>(Src), SrcTy);
1766 } else {
1767 std::string NewName(makeNameUnique(Src->getName()));
1768 Src = new FPToUIInst(Src, SrcTy, NewName, CurBB);
1769 }
1770 } else if (isa<IntegerType>(DstTy) &&
1771 cast<IntegerType>(DstTy)->getBitWidth() == 1) {
1772 // cast type %x to bool was previously defined as setne type %x, null
1773 // The cast semantic is now to truncate, not compare so we must retain
1774 // the original intent by replacing the cast with a setne
1775 Constant* Null = Constant::getNullValue(SrcTy);
1776 Instruction::OtherOps Opcode = Instruction::ICmp;
1777 unsigned short predicate = ICmpInst::ICMP_NE;
1778 if (SrcTy->isFloatingPoint()) {
1779 Opcode = Instruction::FCmp;
1780 predicate = FCmpInst::FCMP_ONE;
1781 } else if (!SrcTy->isInteger() && !isa<PointerType>(SrcTy)) {
1782 error("Invalid cast to bool");
1783 }
1784 if (isa<Constant>(Src) && !ForceInstruction)
1785 return ConstantExpr::getCompare(predicate, cast<Constant>(Src), Null);
1786 else
1787 return CmpInst::create(Opcode, predicate, Src, Null);
1788 }
1789 // Determine the opcode to use by calling CastInst::getCastOpcode
1790 Opcode =
Reid Spencerbb1fd572007-03-21 17:15:50 +00001791 CastInst::getCastOpcode(Src, SrcSign.isSigned(), DstTy,
1792 DstSign.isSigned());
Reid Spencer950bf602007-01-26 08:19:09 +00001793
1794 } else switch (op) {
1795 default: assert(0 && "Invalid cast token");
1796 case TruncOp: Opcode = Instruction::Trunc; break;
1797 case ZExtOp: Opcode = Instruction::ZExt; break;
1798 case SExtOp: Opcode = Instruction::SExt; break;
1799 case FPTruncOp: Opcode = Instruction::FPTrunc; break;
1800 case FPExtOp: Opcode = Instruction::FPExt; break;
1801 case FPToUIOp: Opcode = Instruction::FPToUI; break;
1802 case FPToSIOp: Opcode = Instruction::FPToSI; break;
1803 case UIToFPOp: Opcode = Instruction::UIToFP; break;
1804 case SIToFPOp: Opcode = Instruction::SIToFP; break;
1805 case PtrToIntOp: Opcode = Instruction::PtrToInt; break;
1806 case IntToPtrOp: Opcode = Instruction::IntToPtr; break;
1807 case BitCastOp: Opcode = Instruction::BitCast; break;
1808 }
1809
1810 if (isa<Constant>(Src) && !ForceInstruction)
1811 return ConstantExpr::getCast(Opcode, cast<Constant>(Src), DstTy);
1812 return CastInst::create(Opcode, Src, DstTy);
1813}
1814
1815static Instruction *
1816upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
1817 std::vector<Value*>& Args) {
1818
1819 std::string Name = ID.Type == ValID::NameVal ? ID.Name : "";
Reid Spencer7eea8ff2007-05-18 05:48:07 +00001820 if (Name.length() <= 5 || Name[0] != 'l' || Name[1] != 'l' ||
1821 Name[2] != 'v' || Name[3] != 'm' || Name[4] != '.')
1822 return 0;
1823
Reid Spencer41b213e2007-04-02 01:14:00 +00001824 switch (Name[5]) {
1825 case 'i':
1826 if (Name == "llvm.isunordered.f32" || Name == "llvm.isunordered.f64") {
1827 if (Args.size() != 2)
1828 error("Invalid prototype for " + Name);
1829 return new FCmpInst(FCmpInst::FCMP_UNO, Args[0], Args[1]);
1830 }
1831 break;
1832 case 'b':
1833 if (Name.length() == 14 && !memcmp(&Name[5], "bswap.i", 7)) {
1834 const Type* ArgTy = Args[0]->getType();
1835 Name += ".i" + utostr(cast<IntegerType>(ArgTy)->getBitWidth());
1836 Function *F = cast<Function>(
1837 CurModule.CurrentModule->getOrInsertFunction(Name, RetTy, ArgTy,
1838 (void*)0));
1839 return new CallInst(F, Args[0]);
1840 }
1841 break;
Reid Spencer8166a6c2007-04-02 02:08:35 +00001842 case 'c':
1843 if ((Name.length() <= 14 && !memcmp(&Name[5], "ctpop.i", 7)) ||
1844 (Name.length() <= 13 && !memcmp(&Name[5], "ctlz.i", 6)) ||
1845 (Name.length() <= 13 && !memcmp(&Name[5], "cttz.i", 6))) {
1846 // These intrinsics changed their result type.
1847 const Type* ArgTy = Args[0]->getType();
1848 Function *OldF = CurModule.CurrentModule->getFunction(Name);
1849 if (OldF)
1850 OldF->setName("upgrd.rm." + Name);
1851
1852 Function *NewF = cast<Function>(
1853 CurModule.CurrentModule->getOrInsertFunction(Name, Type::Int32Ty,
1854 ArgTy, (void*)0));
1855
1856 Instruction *Call = new CallInst(NewF, Args[0], "", CurBB);
1857 return CastInst::createIntegerCast(Call, RetTy, false);
1858 }
1859 break;
1860
Reid Spencer41b213e2007-04-02 01:14:00 +00001861 case 'v' : {
1862 const Type* PtrTy = PointerType::get(Type::Int8Ty);
1863 std::vector<const Type*> Params;
1864 if (Name == "llvm.va_start" || Name == "llvm.va_end") {
1865 if (Args.size() != 1)
1866 error("Invalid prototype for " + Name + " prototype");
1867 Params.push_back(PtrTy);
1868 const FunctionType *FTy =
1869 FunctionType::get(Type::VoidTy, Params, false);
1870 const PointerType *PFTy = PointerType::get(FTy);
1871 Value* Func = getVal(PFTy, ID);
1872 Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
David Greene718fda32007-08-01 03:59:32 +00001873 return new CallInst(Func, Args.begin(), Args.end());
Reid Spencer41b213e2007-04-02 01:14:00 +00001874 } else if (Name == "llvm.va_copy") {
1875 if (Args.size() != 2)
1876 error("Invalid prototype for " + Name + " prototype");
1877 Params.push_back(PtrTy);
1878 Params.push_back(PtrTy);
1879 const FunctionType *FTy =
1880 FunctionType::get(Type::VoidTy, Params, false);
1881 const PointerType *PFTy = PointerType::get(FTy);
1882 Value* Func = getVal(PFTy, ID);
1883 std::string InstName0(makeNameUnique("va0"));
1884 std::string InstName1(makeNameUnique("va1"));
1885 Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
1886 Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
David Greene718fda32007-08-01 03:59:32 +00001887 return new CallInst(Func, Args.begin(), Args.end());
Reid Spencer41b213e2007-04-02 01:14:00 +00001888 }
Reid Spencer950bf602007-01-26 08:19:09 +00001889 }
1890 }
1891 return 0;
1892}
1893
Reid Spencerff0e4482007-04-16 00:40:57 +00001894const Type* upgradeGEPCEIndices(const Type* PTy,
1895 std::vector<ValueInfo> *Indices,
1896 std::vector<Constant*> &Result) {
1897 const Type *Ty = PTy;
1898 Result.clear();
1899 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1900 Constant *Index = cast<Constant>((*Indices)[i].V);
1901
1902 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1903 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1904 // struct indices to i32 struct indices with ZExt for compatibility.
1905 if (CI->getBitWidth() < 32)
1906 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1907 }
1908
1909 if (isa<SequentialType>(Ty)) {
1910 // Make sure that unsigned SequentialType indices are zext'd to
1911 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1912 // all indices for SequentialType elements. We must retain the same
1913 // semantic (zext) for unsigned types.
1914 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
1915 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
1916 Index = ConstantExpr::getCast(Instruction::ZExt, Index,Type::Int64Ty);
1917 }
1918 }
1919 }
1920 Result.push_back(Index);
1921 Ty = GetElementPtrInst::getIndexedType(PTy, (Value**)&Result[0],
1922 Result.size(),true);
1923 if (!Ty)
1924 error("Index list invalid for constant getelementptr");
1925 }
1926 return Ty;
1927}
1928
1929const Type* upgradeGEPInstIndices(const Type* PTy,
1930 std::vector<ValueInfo> *Indices,
1931 std::vector<Value*> &Result) {
1932 const Type *Ty = PTy;
1933 Result.clear();
1934 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1935 Value *Index = (*Indices)[i].V;
1936
1937 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1938 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1939 // struct indices to i32 struct indices with ZExt for compatibility.
1940 if (CI->getBitWidth() < 32)
1941 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1942 }
1943
1944
1945 if (isa<StructType>(Ty)) { // Only change struct indices
1946 if (!isa<Constant>(Index)) {
1947 error("Invalid non-constant structure index");
1948 return 0;
1949 }
Reid Spencer950bf602007-01-26 08:19:09 +00001950 } else {
1951 // Make sure that unsigned SequentialType indices are zext'd to
1952 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1953 // all indices for SequentialType elements. We must retain the same
1954 // semantic (zext) for unsigned types.
Reid Spencerff0e4482007-04-16 00:40:57 +00001955 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00001956 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
Reid Spencerff0e4482007-04-16 00:40:57 +00001957 if (isa<Constant>(Index))
Reid Spencer950bf602007-01-26 08:19:09 +00001958 Index = ConstantExpr::getCast(Instruction::ZExt,
1959 cast<Constant>(Index), Type::Int64Ty);
1960 else
1961 Index = CastInst::create(Instruction::ZExt, Index, Type::Int64Ty,
Reid Spencer832254e2007-02-02 02:16:23 +00001962 makeNameUnique("gep"), CurBB);
Reid Spencer38f682b2007-01-26 20:31:18 +00001963 }
Reid Spencerff0e4482007-04-16 00:40:57 +00001964 }
Reid Spencer950bf602007-01-26 08:19:09 +00001965 }
Reid Spencerff0e4482007-04-16 00:40:57 +00001966 Result.push_back(Index);
1967 Ty = GetElementPtrInst::getIndexedType(PTy, &Result[0], Result.size(),true);
1968 if (!Ty)
Reid Spencer950bf602007-01-26 08:19:09 +00001969 error("Index list invalid for constant getelementptr");
Reid Spencerff0e4482007-04-16 00:40:57 +00001970 }
1971 return Ty;
Reid Spencer950bf602007-01-26 08:19:09 +00001972}
1973
Reid Spencerb7046c72007-01-29 05:41:34 +00001974unsigned upgradeCallingConv(unsigned CC) {
1975 switch (CC) {
1976 case OldCallingConv::C : return CallingConv::C;
1977 case OldCallingConv::CSRet : return CallingConv::C;
1978 case OldCallingConv::Fast : return CallingConv::Fast;
1979 case OldCallingConv::Cold : return CallingConv::Cold;
1980 case OldCallingConv::X86_StdCall : return CallingConv::X86_StdCall;
1981 case OldCallingConv::X86_FastCall: return CallingConv::X86_FastCall;
1982 default:
1983 return CC;
1984 }
1985}
1986
Reid Spencer950bf602007-01-26 08:19:09 +00001987Module* UpgradeAssembly(const std::string &infile, std::istream& in,
1988 bool debug, bool addAttrs)
Reid Spencere7c3c602006-11-30 06:36:44 +00001989{
1990 Upgradelineno = 1;
1991 CurFilename = infile;
Reid Spencer96839be2006-11-30 16:50:26 +00001992 LexInput = &in;
Reid Spencere77e35e2006-12-01 20:26:20 +00001993 yydebug = debug;
Reid Spencer71d2ec92006-12-31 06:02:26 +00001994 AddAttributes = addAttrs;
Reid Spencer950bf602007-01-26 08:19:09 +00001995 ObsoleteVarArgs = false;
1996 NewVarArgs = false;
Reid Spencere7c3c602006-11-30 06:36:44 +00001997
Reid Spencer950bf602007-01-26 08:19:09 +00001998 CurModule.CurrentModule = new Module(CurFilename);
1999
2000 // Check to make sure the parser succeeded
Reid Spencere7c3c602006-11-30 06:36:44 +00002001 if (yyparse()) {
Reid Spencer950bf602007-01-26 08:19:09 +00002002 if (ParserResult)
2003 delete ParserResult;
Reid Spencer30d0c582007-01-15 00:26:18 +00002004 std::cerr << "llvm-upgrade: parse failed.\n";
Reid Spencer30d0c582007-01-15 00:26:18 +00002005 return 0;
2006 }
2007
Reid Spencer950bf602007-01-26 08:19:09 +00002008 // Check to make sure that parsing produced a result
2009 if (!ParserResult) {
2010 std::cerr << "llvm-upgrade: no parse result.\n";
2011 return 0;
Reid Spencer30d0c582007-01-15 00:26:18 +00002012 }
2013
Reid Spencer950bf602007-01-26 08:19:09 +00002014 // Reset ParserResult variable while saving its value for the result.
2015 Module *Result = ParserResult;
2016 ParserResult = 0;
Reid Spencer30d0c582007-01-15 00:26:18 +00002017
Reid Spencer950bf602007-01-26 08:19:09 +00002018 //Not all functions use vaarg, so make a second check for ObsoleteVarArgs
Reid Spencer30d0c582007-01-15 00:26:18 +00002019 {
Reid Spencer950bf602007-01-26 08:19:09 +00002020 Function* F;
Reid Spencer688b0492007-02-05 21:19:13 +00002021 if ((F = Result->getFunction("llvm.va_start"))
Reid Spencer950bf602007-01-26 08:19:09 +00002022 && F->getFunctionType()->getNumParams() == 0)
2023 ObsoleteVarArgs = true;
Reid Spencer688b0492007-02-05 21:19:13 +00002024 if((F = Result->getFunction("llvm.va_copy"))
Reid Spencer950bf602007-01-26 08:19:09 +00002025 && F->getFunctionType()->getNumParams() == 1)
2026 ObsoleteVarArgs = true;
Reid Spencer280d8012006-12-01 23:40:53 +00002027 }
Reid Spencer319a7302007-01-05 17:20:02 +00002028
Reid Spencer950bf602007-01-26 08:19:09 +00002029 if (ObsoleteVarArgs && NewVarArgs) {
2030 error("This file is corrupt: it uses both new and old style varargs");
2031 return 0;
Reid Spencer319a7302007-01-05 17:20:02 +00002032 }
Reid Spencer319a7302007-01-05 17:20:02 +00002033
Reid Spencer950bf602007-01-26 08:19:09 +00002034 if(ObsoleteVarArgs) {
Reid Spencer688b0492007-02-05 21:19:13 +00002035 if(Function* F = Result->getFunction("llvm.va_start")) {
Reid Spencer950bf602007-01-26 08:19:09 +00002036 if (F->arg_size() != 0) {
2037 error("Obsolete va_start takes 0 argument");
Reid Spencer319a7302007-01-05 17:20:02 +00002038 return 0;
2039 }
Reid Spencer950bf602007-01-26 08:19:09 +00002040
2041 //foo = va_start()
2042 // ->
2043 //bar = alloca typeof(foo)
2044 //va_start(bar)
2045 //foo = load bar
Reid Spencer319a7302007-01-05 17:20:02 +00002046
Reid Spencer950bf602007-01-26 08:19:09 +00002047 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2048 const Type* ArgTy = F->getFunctionType()->getReturnType();
2049 const Type* ArgTyPtr = PointerType::get(ArgTy);
2050 Function* NF = cast<Function>(Result->getOrInsertFunction(
2051 "llvm.va_start", RetTy, ArgTyPtr, (Type *)0));
2052
2053 while (!F->use_empty()) {
2054 CallInst* CI = cast<CallInst>(F->use_back());
2055 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vastart.fix.1", CI);
2056 new CallInst(NF, bar, "", CI);
2057 Value* foo = new LoadInst(bar, "vastart.fix.2", CI);
2058 CI->replaceAllUsesWith(foo);
2059 CI->getParent()->getInstList().erase(CI);
Reid Spencerf8383de2007-01-06 06:04:32 +00002060 }
Reid Spencer950bf602007-01-26 08:19:09 +00002061 Result->getFunctionList().erase(F);
Reid Spencerf8383de2007-01-06 06:04:32 +00002062 }
Reid Spencer950bf602007-01-26 08:19:09 +00002063
Reid Spencer688b0492007-02-05 21:19:13 +00002064 if(Function* F = Result->getFunction("llvm.va_end")) {
Reid Spencer950bf602007-01-26 08:19:09 +00002065 if(F->arg_size() != 1) {
2066 error("Obsolete va_end takes 1 argument");
2067 return 0;
Reid Spencerf8383de2007-01-06 06:04:32 +00002068 }
Reid Spencerf8383de2007-01-06 06:04:32 +00002069
Reid Spencer950bf602007-01-26 08:19:09 +00002070 //vaend foo
2071 // ->
2072 //bar = alloca 1 of typeof(foo)
2073 //vaend bar
2074 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2075 const Type* ArgTy = F->getFunctionType()->getParamType(0);
2076 const Type* ArgTyPtr = PointerType::get(ArgTy);
2077 Function* NF = cast<Function>(Result->getOrInsertFunction(
2078 "llvm.va_end", RetTy, ArgTyPtr, (Type *)0));
Reid Spencerf8383de2007-01-06 06:04:32 +00002079
Reid Spencer950bf602007-01-26 08:19:09 +00002080 while (!F->use_empty()) {
2081 CallInst* CI = cast<CallInst>(F->use_back());
2082 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vaend.fix.1", CI);
2083 new StoreInst(CI->getOperand(1), bar, CI);
2084 new CallInst(NF, bar, "", CI);
2085 CI->getParent()->getInstList().erase(CI);
Reid Spencere77e35e2006-12-01 20:26:20 +00002086 }
Reid Spencer950bf602007-01-26 08:19:09 +00002087 Result->getFunctionList().erase(F);
Reid Spencere77e35e2006-12-01 20:26:20 +00002088 }
Reid Spencer950bf602007-01-26 08:19:09 +00002089
Reid Spencer688b0492007-02-05 21:19:13 +00002090 if(Function* F = Result->getFunction("llvm.va_copy")) {
Reid Spencer950bf602007-01-26 08:19:09 +00002091 if(F->arg_size() != 1) {
2092 error("Obsolete va_copy takes 1 argument");
2093 return 0;
Reid Spencere77e35e2006-12-01 20:26:20 +00002094 }
Reid Spencer950bf602007-01-26 08:19:09 +00002095 //foo = vacopy(bar)
2096 // ->
2097 //a = alloca 1 of typeof(foo)
2098 //b = alloca 1 of typeof(foo)
2099 //store bar -> b
2100 //vacopy(a, b)
2101 //foo = load a
2102
2103 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2104 const Type* ArgTy = F->getFunctionType()->getReturnType();
2105 const Type* ArgTyPtr = PointerType::get(ArgTy);
2106 Function* NF = cast<Function>(Result->getOrInsertFunction(
2107 "llvm.va_copy", RetTy, ArgTyPtr, ArgTyPtr, (Type *)0));
Reid Spencere77e35e2006-12-01 20:26:20 +00002108
Reid Spencer950bf602007-01-26 08:19:09 +00002109 while (!F->use_empty()) {
2110 CallInst* CI = cast<CallInst>(F->use_back());
David Greene718fda32007-08-01 03:59:32 +00002111 SmallVector<Value *, 2> Args;
2112 Args.push_back(new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI));
2113 Args.push_back(new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI));
2114 new StoreInst(CI->getOperand(1), Args[1], CI);
2115 new CallInst(NF, Args.begin(), Args.end(), "", CI);
2116 Value* foo = new LoadInst(Args[0], "vacopy.fix.3", CI);
Reid Spencer950bf602007-01-26 08:19:09 +00002117 CI->replaceAllUsesWith(foo);
2118 CI->getParent()->getInstList().erase(CI);
2119 }
2120 Result->getFunctionList().erase(F);
Reid Spencer319a7302007-01-05 17:20:02 +00002121 }
2122 }
2123
Reid Spencer52402b02007-01-02 05:45:11 +00002124 return Result;
2125}
2126
Reid Spencer950bf602007-01-26 08:19:09 +00002127} // end llvm namespace
Reid Spencer319a7302007-01-05 17:20:02 +00002128
Reid Spencer950bf602007-01-26 08:19:09 +00002129using namespace llvm;
Reid Spencer30d0c582007-01-15 00:26:18 +00002130
2131
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002132
2133/* Enabling traces. */
2134#ifndef YYDEBUG
2135# define YYDEBUG 0
2136#endif
2137
2138/* Enabling verbose error messages. */
2139#ifdef YYERROR_VERBOSE
2140# undef YYERROR_VERBOSE
2141# define YYERROR_VERBOSE 1
2142#else
2143# define YYERROR_VERBOSE 0
2144#endif
2145
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002146#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
David Greene718fda32007-08-01 03:59:32 +00002147#line 1776 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002148typedef union YYSTYPE {
Reid Spencer950bf602007-01-26 08:19:09 +00002149 llvm::Module *ModuleVal;
2150 llvm::Function *FunctionVal;
2151 std::pair<llvm::PATypeInfo, char*> *ArgVal;
2152 llvm::BasicBlock *BasicBlockVal;
Reid Spencerbb1fd572007-03-21 17:15:50 +00002153 llvm::TermInstInfo TermInstVal;
Reid Spencer950bf602007-01-26 08:19:09 +00002154 llvm::InstrInfo InstVal;
2155 llvm::ConstInfo ConstVal;
2156 llvm::ValueInfo ValueVal;
2157 llvm::PATypeInfo TypeVal;
2158 llvm::TypeInfo PrimType;
2159 llvm::PHIListInfo PHIList;
2160 std::list<llvm::PATypeInfo> *TypeList;
2161 std::vector<llvm::ValueInfo> *ValueList;
2162 std::vector<llvm::ConstInfo> *ConstVector;
2163
2164
2165 std::vector<std::pair<llvm::PATypeInfo,char*> > *ArgList;
2166 // Represent the RHS of PHI node
2167 std::vector<std::pair<llvm::Constant*, llvm::BasicBlock*> > *JumpTable;
2168
2169 llvm::GlobalValue::LinkageTypes Linkage;
2170 int64_t SInt64Val;
2171 uint64_t UInt64Val;
2172 int SIntVal;
2173 unsigned UIntVal;
2174 double FPVal;
2175 bool BoolVal;
2176
2177 char *StrVal; // This memory is strdup'd!
2178 llvm::ValID ValIDVal; // strdup'd memory maybe!
2179
2180 llvm::BinaryOps BinaryOpVal;
2181 llvm::TermOps TermOpVal;
2182 llvm::MemoryOps MemOpVal;
2183 llvm::OtherOps OtherOpVal;
2184 llvm::CastOps CastOpVal;
2185 llvm::ICmpInst::Predicate IPred;
2186 llvm::FCmpInst::Predicate FPred;
2187 llvm::Module::Endianness Endianness;
Chris Lattnercf3d0612007-02-13 06:04:17 +00002188} YYSTYPE;
David Greene718fda32007-08-01 03:59:32 +00002189/* Line 191 of yacc.c. */
2190#line 2191 "UpgradeParser.tab.c"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002191# define yystype YYSTYPE /* obsolescent; will be withdrawn */
2192# define YYSTYPE_IS_DECLARED 1
2193# define YYSTYPE_IS_TRIVIAL 1
Reid Spencere7c3c602006-11-30 06:36:44 +00002194#endif
2195
Reid Spencer950bf602007-01-26 08:19:09 +00002196
Reid Spencere7c3c602006-11-30 06:36:44 +00002197
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002198/* Copy the second part of user declarations. */
Reid Spencere7c3c602006-11-30 06:36:44 +00002199
2200
David Greene718fda32007-08-01 03:59:32 +00002201/* Line 214 of yacc.c. */
2202#line 2203 "UpgradeParser.tab.c"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002203
2204#if ! defined (yyoverflow) || YYERROR_VERBOSE
2205
2206/* The parser invokes alloca or malloc; define the necessary symbols. */
2207
2208# ifdef YYSTACK_USE_ALLOCA
2209# if YYSTACK_USE_ALLOCA
David Greene718fda32007-08-01 03:59:32 +00002210# define YYSTACK_ALLOC alloca
2211# endif
2212# else
2213# if defined (alloca) || defined (_ALLOCA_H)
2214# define YYSTACK_ALLOC alloca
2215# else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002216# ifdef __GNUC__
2217# define YYSTACK_ALLOC __builtin_alloca
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002218# endif
2219# endif
2220# endif
2221
2222# ifdef YYSTACK_ALLOC
2223 /* Pacify GCC's `empty if-body' warning. */
2224# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002225# else
David Greene718fda32007-08-01 03:59:32 +00002226# if defined (__STDC__) || defined (__cplusplus)
2227# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
2228# define YYSIZE_T size_t
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002229# endif
David Greene718fda32007-08-01 03:59:32 +00002230# define YYSTACK_ALLOC malloc
2231# define YYSTACK_FREE free
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002232# endif
2233#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
2234
2235
2236#if (! defined (yyoverflow) \
2237 && (! defined (__cplusplus) \
2238 || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
2239
2240/* A type that is properly aligned for any stack member. */
2241union yyalloc
2242{
David Greene718fda32007-08-01 03:59:32 +00002243 short yyss;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002244 YYSTYPE yyvs;
2245 };
2246
2247/* The size of the maximum gap between one aligned stack and the next. */
2248# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
2249
2250/* The size of an array large to enough to hold all stacks, each with
2251 N elements. */
2252# define YYSTACK_BYTES(N) \
David Greene718fda32007-08-01 03:59:32 +00002253 ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002254 + YYSTACK_GAP_MAXIMUM)
2255
2256/* Copy COUNT objects from FROM to TO. The source and destination do
2257 not overlap. */
2258# ifndef YYCOPY
2259# if defined (__GNUC__) && 1 < __GNUC__
2260# define YYCOPY(To, From, Count) \
2261 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
2262# else
2263# define YYCOPY(To, From, Count) \
2264 do \
2265 { \
David Greene718fda32007-08-01 03:59:32 +00002266 register YYSIZE_T yyi; \
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002267 for (yyi = 0; yyi < (Count); yyi++) \
2268 (To)[yyi] = (From)[yyi]; \
2269 } \
2270 while (0)
2271# endif
2272# endif
2273
2274/* Relocate STACK from its old location to the new one. The
2275 local variables YYSIZE and YYSTACKSIZE give the old and new number of
2276 elements in the stack, and YYPTR gives the new location of the
2277 stack. Advance YYPTR to a properly aligned location for the next
2278 stack. */
2279# define YYSTACK_RELOCATE(Stack) \
2280 do \
2281 { \
2282 YYSIZE_T yynewbytes; \
2283 YYCOPY (&yyptr->Stack, Stack, yysize); \
2284 Stack = &yyptr->Stack; \
2285 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
2286 yyptr += yynewbytes / sizeof (*yyptr); \
2287 } \
2288 while (0)
Chris Lattnercf3d0612007-02-13 06:04:17 +00002289
Reid Spencere7c3c602006-11-30 06:36:44 +00002290#endif
2291
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002292#if defined (__STDC__) || defined (__cplusplus)
2293 typedef signed char yysigned_char;
Reid Spencerb7046c72007-01-29 05:41:34 +00002294#else
David Greene718fda32007-08-01 03:59:32 +00002295 typedef short yysigned_char;
Reid Spencerb7046c72007-01-29 05:41:34 +00002296#endif
2297
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002298/* YYFINAL -- State number of the termination state. */
2299#define YYFINAL 4
2300/* YYLAST -- Last index in YYTABLE. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002301#define YYLAST 1630
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002302
2303/* YYNTOKENS -- Number of terminals. */
2304#define YYNTOKENS 166
2305/* YYNNTS -- Number of nonterminals. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002306#define YYNNTS 81
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002307/* YYNRULES -- Number of rules. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002308#define YYNRULES 310
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002309/* YYNRULES -- Number of states. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002310#define YYNSTATES 606
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002311
2312/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
2313#define YYUNDEFTOK 2
2314#define YYMAXUTOK 406
2315
David Greene718fda32007-08-01 03:59:32 +00002316#define YYTRANSLATE(YYX) \
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002317 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
2318
2319/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
2320static const unsigned char yytranslate[] =
2321{
2322 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2323 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2324 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2325 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2326 155, 156, 164, 2, 153, 2, 2, 2, 2, 2,
2327 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2328 160, 152, 161, 2, 2, 2, 2, 2, 2, 2,
2329 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2330 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2331 2, 157, 154, 159, 2, 2, 2, 2, 2, 165,
2332 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2333 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2334 158, 2, 2, 162, 2, 163, 2, 2, 2, 2,
2335 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2336 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2337 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2338 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2339 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2340 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2341 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2342 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2343 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2344 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2345 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2346 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2347 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
2348 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
2349 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
2350 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
2351 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
2352 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
2353 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
2354 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
2355 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
2356 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
2357 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
2358 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
2359 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
2360 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
2361 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
2362 145, 146, 147, 148, 149, 150, 151
2363};
2364
2365#if YYDEBUG
2366/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
2367 YYRHS. */
David Greene718fda32007-08-01 03:59:32 +00002368static const unsigned short yyprhs[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002369{
2370 0, 0, 3, 5, 7, 9, 11, 13, 15, 17,
2371 19, 21, 23, 25, 27, 29, 31, 33, 35, 37,
2372 39, 41, 43, 45, 47, 49, 51, 53, 55, 57,
2373 59, 61, 63, 65, 67, 69, 71, 73, 75, 77,
2374 79, 81, 83, 85, 87, 89, 91, 93, 95, 97,
2375 99, 101, 103, 105, 107, 109, 111, 113, 115, 117,
2376 119, 121, 123, 125, 127, 129, 131, 133, 135, 137,
2377 139, 141, 143, 145, 147, 149, 151, 153, 155, 157,
2378 159, 161, 164, 165, 167, 169, 171, 173, 175, 177,
2379 179, 180, 181, 183, 185, 187, 189, 191, 193, 196,
2380 197, 200, 201, 205, 208, 209, 211, 212, 216, 218,
2381 221, 223, 225, 227, 229, 231, 233, 235, 237, 239,
2382 241, 243, 245, 247, 249, 251, 253, 255, 257, 259,
2383 261, 264, 269, 275, 281, 285, 288, 294, 299, 302,
2384 304, 308, 310, 314, 316, 317, 322, 326, 330, 335,
2385 340, 344, 351, 357, 360, 363, 366, 369, 372, 375,
2386 378, 381, 384, 387, 394, 400, 409, 416, 423, 430,
2387 438, 446, 453, 460, 469, 478, 482, 484, 486, 488,
2388 490, 493, 496, 501, 504, 506, 511, 514, 519, 520,
2389 528, 529, 537, 538, 546, 547, 555, 559, 564, 565,
2390 567, 569, 571, 575, 579, 583, 587, 591, 595, 597,
2391 598, 600, 602, 604, 605, 608, 612, 614, 616, 620,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002392 622, 623, 632, 634, 636, 637, 642, 644, 646, 649,
2393 650, 652, 654, 655, 656, 662, 663, 665, 667, 669,
2394 671, 673, 675, 677, 679, 681, 685, 687, 693, 695,
2395 697, 699, 701, 704, 707, 710, 714, 717, 718, 720,
2396 722, 724, 727, 730, 734, 744, 754, 763, 777, 779,
2397 781, 788, 794, 797, 804, 812, 814, 818, 820, 821,
2398 824, 826, 832, 838, 844, 851, 858, 861, 866, 871,
2399 878, 883, 888, 893, 898, 905, 912, 915, 923, 925,
2400 928, 929, 931, 932, 936, 943, 947, 954, 957, 962,
2401 969
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002402};
2403
2404/* YYRHS -- A `-1'-separated list of the rules' RHS. */
David Greene718fda32007-08-01 03:59:32 +00002405static const short yyrhs[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002406{
2407 200, 0, -1, 5, -1, 6, -1, 3, -1, 4,
2408 -1, 79, -1, 80, -1, 81, -1, 82, -1, 83,
2409 -1, 84, -1, 85, -1, 86, -1, 87, -1, 88,
2410 -1, 89, -1, 90, -1, 91, -1, 92, -1, 97,
2411 -1, 98, -1, 99, -1, 100, -1, 101, -1, 102,
2412 -1, 119, -1, 120, -1, 121, -1, 122, -1, 123,
2413 -1, 124, -1, 125, -1, 126, -1, 127, -1, 128,
2414 -1, 129, -1, 130, -1, 131, -1, 132, -1, 133,
2415 -1, 134, -1, 135, -1, 136, -1, 137, -1, 138,
2416 -1, 125, -1, 126, -1, 127, -1, 128, -1, 27,
2417 -1, 28, -1, 93, -1, 94, -1, 95, -1, 96,
2418 -1, 140, -1, 141, -1, 142, -1, 143, -1, 144,
2419 -1, 145, -1, 146, -1, 147, -1, 148, -1, 149,
2420 -1, 150, -1, 151, -1, 139, -1, 16, -1, 14,
2421 -1, 12, -1, 10, -1, 17, -1, 15, -1, 13,
2422 -1, 11, -1, 176, -1, 177, -1, 18, -1, 19,
2423 -1, 212, 152, -1, -1, 41, -1, 42, -1, 43,
2424 -1, 44, -1, 45, -1, 46, -1, 47, -1, -1,
2425 -1, 65, -1, 66, -1, 67, -1, 68, -1, 69,
2426 -1, 70, -1, 64, 4, -1, -1, 57, 4, -1,
2427 -1, 153, 57, 4, -1, 34, 24, -1, -1, 185,
2428 -1, -1, 153, 188, 187, -1, 185, -1, 57, 4,
2429 -1, 191, -1, 8, -1, 193, -1, 8, -1, 193,
2430 -1, 9, -1, 10, -1, 11, -1, 12, -1, 13,
2431 -1, 14, -1, 15, -1, 16, -1, 17, -1, 18,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002432 -1, 19, -1, 21, -1, 192, -1, 48, -1, 229,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002433 -1, 154, 4, -1, 190, 155, 195, 156, -1, 157,
2434 4, 158, 193, 159, -1, 160, 4, 158, 193, 161,
2435 -1, 162, 194, 163, -1, 162, 163, -1, 160, 162,
2436 194, 163, 161, -1, 160, 162, 163, 161, -1, 193,
2437 164, -1, 193, -1, 194, 153, 193, -1, 194, -1,
2438 194, 153, 37, -1, 37, -1, -1, 191, 157, 198,
2439 159, -1, 191, 157, 159, -1, 191, 165, 24, -1,
2440 191, 160, 198, 161, -1, 191, 162, 198, 163, -1,
2441 191, 162, 163, -1, 191, 160, 162, 198, 163, 161,
2442 -1, 191, 160, 162, 163, 161, -1, 191, 38, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002443 191, 39, -1, 191, 229, -1, 191, 197, -1, 191,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002444 26, -1, 176, 168, -1, 177, 4, -1, 9, 27,
2445 -1, 9, 28, -1, 179, 7, -1, 175, 155, 196,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002446 36, 191, 156, -1, 110, 155, 196, 244, 156, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002447 112, 155, 196, 153, 196, 153, 196, 156, -1, 169,
2448 155, 196, 153, 196, 156, -1, 170, 155, 196, 153,
2449 196, 156, -1, 171, 155, 196, 153, 196, 156, -1,
2450 103, 172, 155, 196, 153, 196, 156, -1, 104, 173,
2451 155, 196, 153, 196, 156, -1, 174, 155, 196, 153,
2452 196, 156, -1, 114, 155, 196, 153, 196, 156, -1,
2453 115, 155, 196, 153, 196, 153, 196, 156, -1, 116,
2454 155, 196, 153, 196, 153, 196, 156, -1, 198, 153,
2455 196, -1, 196, -1, 32, -1, 33, -1, 201, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002456 201, 222, -1, 201, 224, -1, 201, 62, 61, 207,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002457 -1, 201, 25, -1, 202, -1, 202, 180, 20, 189,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002458 -1, 202, 224, -1, 202, 62, 61, 207, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002459 202, 180, 181, 199, 196, 203, 187, -1, -1, 202,
2460 180, 50, 199, 191, 204, 187, -1, -1, 202, 180,
2461 45, 199, 191, 205, 187, -1, -1, 202, 180, 47,
2462 199, 191, 206, 187, -1, 202, 51, 209, -1, 202,
2463 58, 152, 210, -1, -1, 24, -1, 56, -1, 55,
2464 -1, 53, 152, 208, -1, 54, 152, 4, -1, 52,
2465 152, 24, -1, 71, 152, 24, -1, 157, 211, 159,
2466 -1, 211, 153, 24, -1, 24, -1, -1, 22, -1,
2467 24, -1, 212, -1, -1, 191, 213, -1, 215, 153,
2468 214, -1, 214, -1, 215, -1, 215, 153, 37, -1,
2469 37, -1, -1, 182, 189, 212, 155, 216, 156, 186,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002470 183, -1, 29, -1, 162, -1, -1, 181, 220, 217,
2471 218, -1, 30, -1, 163, -1, 232, 221, -1, -1,
2472 45, -1, 47, -1, -1, -1, 31, 225, 223, 226,
2473 217, -1, -1, 63, -1, 3, -1, 4, -1, 7,
2474 -1, 27, -1, 28, -1, 38, -1, 39, -1, 26,
2475 -1, 160, 198, 161, -1, 197, -1, 61, 227, 24,
2476 153, 24, -1, 167, -1, 212, -1, 229, -1, 228,
2477 -1, 191, 230, -1, 232, 233, -1, 219, 233, -1,
2478 234, 180, 236, -1, 234, 238, -1, -1, 23, -1,
2479 77, -1, 78, -1, 72, 231, -1, 72, 8, -1,
2480 73, 21, 230, -1, 73, 9, 230, 153, 21, 230,
2481 153, 21, 230, -1, 74, 178, 230, 153, 21, 230,
2482 157, 237, 159, -1, 74, 178, 230, 153, 21, 230,
2483 157, 159, -1, 75, 182, 189, 230, 155, 241, 156,
2484 36, 21, 230, 235, 21, 230, -1, 235, -1, 76,
2485 -1, 237, 178, 228, 153, 21, 230, -1, 178, 228,
2486 153, 21, 230, -1, 180, 243, -1, 191, 157, 230,
2487 153, 230, 159, -1, 239, 153, 157, 230, 153, 230,
2488 159, -1, 231, -1, 240, 153, 231, -1, 240, -1,
2489 -1, 60, 59, -1, 59, -1, 169, 191, 230, 153,
2490 230, -1, 170, 191, 230, 153, 230, -1, 171, 191,
2491 230, 153, 230, -1, 103, 172, 191, 230, 153, 230,
2492 -1, 104, 173, 191, 230, 153, 230, -1, 49, 231,
2493 -1, 174, 231, 153, 231, -1, 175, 231, 36, 191,
2494 -1, 112, 231, 153, 231, 153, 231, -1, 113, 231,
2495 153, 191, -1, 117, 231, 153, 191, -1, 118, 231,
2496 153, 191, -1, 114, 231, 153, 231, -1, 115, 231,
2497 153, 231, 153, 231, -1, 116, 231, 153, 231, 153,
2498 231, -1, 111, 239, -1, 242, 182, 189, 230, 155,
2499 241, 156, -1, 246, -1, 153, 240, -1, -1, 35,
2500 -1, -1, 105, 191, 184, -1, 105, 191, 153, 15,
2501 230, 184, -1, 106, 191, 184, -1, 106, 191, 153,
2502 15, 230, 184, -1, 107, 231, -1, 245, 108, 191,
2503 230, -1, 245, 109, 231, 153, 191, 230, -1, 110,
2504 191, 230, 244, -1
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002505};
2506
2507/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
David Greene718fda32007-08-01 03:59:32 +00002508static const unsigned short yyrline[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002509{
David Greene718fda32007-08-01 03:59:32 +00002510 0, 1916, 1916, 1917, 1925, 1926, 1936, 1936, 1936, 1936,
2511 1936, 1936, 1936, 1936, 1936, 1936, 1936, 1940, 1940, 1940,
2512 1944, 1944, 1944, 1944, 1944, 1944, 1948, 1948, 1949, 1949,
2513 1950, 1950, 1951, 1951, 1952, 1952, 1956, 1956, 1957, 1957,
2514 1958, 1958, 1959, 1959, 1960, 1960, 1961, 1961, 1962, 1962,
2515 1963, 1964, 1967, 1967, 1967, 1967, 1971, 1971, 1971, 1971,
2516 1971, 1971, 1971, 1972, 1972, 1972, 1972, 1972, 1972, 1978,
2517 1978, 1978, 1978, 1982, 1982, 1982, 1982, 1986, 1986, 1990,
2518 1990, 1995, 1998, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
2519 2010, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2031,
2520 2032, 2040, 2041, 2049, 2058, 2059, 2066, 2067, 2071, 2075,
2521 2091, 2092, 2099, 2100, 2107, 2115, 2115, 2115, 2115, 2115,
2522 2115, 2115, 2116, 2116, 2116, 2116, 2116, 2121, 2125, 2129,
2523 2134, 2143, 2170, 2176, 2189, 2200, 2204, 2217, 2221, 2235,
2524 2239, 2246, 2247, 2253, 2260, 2272, 2302, 2315, 2338, 2366,
2525 2388, 2399, 2421, 2432, 2441, 2446, 2505, 2512, 2520, 2527,
2526 2534, 2538, 2542, 2551, 2566, 2578, 2587, 2615, 2628, 2637,
2527 2643, 2649, 2660, 2666, 2672, 2683, 2684, 2693, 2694, 2706,
2528 2715, 2716, 2717, 2718, 2719, 2735, 2755, 2757, 2759, 2759,
2529 2766, 2766, 2774, 2774, 2782, 2782, 2791, 2793, 2795, 2800,
2530 2814, 2815, 2819, 2822, 2830, 2834, 2841, 2845, 2849, 2853,
2531 2861, 2861, 2865, 2866, 2870, 2878, 2883, 2891, 2892, 2899,
2532 2906, 2910, 3100, 3100, 3104, 3104, 3114, 3114, 3118, 3123,
2533 3124, 3125, 3129, 3130, 3129, 3142, 3143, 3148, 3149, 3150,
2534 3151, 3155, 3159, 3160, 3161, 3162, 3183, 3187, 3201, 3202,
2535 3207, 3207, 3215, 3225, 3228, 3237, 3248, 3253, 3262, 3273,
2536 3273, 3276, 3280, 3284, 3289, 3299, 3317, 3326, 3399, 3403,
2537 3410, 3422, 3437, 3467, 3477, 3487, 3491, 3498, 3499, 3503,
2538 3506, 3512, 3531, 3549, 3565, 3579, 3593, 3604, 3622, 3631,
2539 3640, 3647, 3668, 3692, 3698, 3704, 3710, 3726, 3819, 3827,
2540 3828, 3832, 3833, 3837, 3843, 3850, 3856, 3863, 3870, 3883,
2541 3909
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002542};
2543#endif
2544
David Greene718fda32007-08-01 03:59:32 +00002545#if YYDEBUG || YYERROR_VERBOSE
2546/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002547 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
2548static const char *const yytname[] =
2549{
2550 "$end", "error", "$undefined", "ESINT64VAL", "EUINT64VAL", "SINTVAL",
2551 "UINTVAL", "FPVAL", "VOID", "BOOL", "SBYTE", "UBYTE", "SHORT", "USHORT",
2552 "INT", "UINT", "LONG", "ULONG", "FLOAT", "DOUBLE", "TYPE", "LABEL",
2553 "VAR_ID", "LABELSTR", "STRINGCONSTANT", "IMPLEMENTATION",
2554 "ZEROINITIALIZER", "TRUETOK", "FALSETOK", "BEGINTOK", "ENDTOK",
2555 "DECLARE", "GLOBAL", "CONSTANT", "SECTION", "VOLATILE", "TO",
2556 "DOTDOTDOT", "NULL_TOK", "UNDEF", "CONST", "INTERNAL", "LINKONCE",
2557 "WEAK", "APPENDING", "DLLIMPORT", "DLLEXPORT", "EXTERN_WEAK", "OPAQUE",
2558 "NOT", "EXTERNAL", "TARGET", "TRIPLE", "ENDIAN", "POINTERSIZE", "LITTLE",
2559 "BIG", "ALIGN", "DEPLIBS", "CALL", "TAIL", "ASM_TOK", "MODULE",
2560 "SIDEEFFECT", "CC_TOK", "CCC_TOK", "CSRETCC_TOK", "FASTCC_TOK",
2561 "COLDCC_TOK", "X86_STDCALLCC_TOK", "X86_FASTCALLCC_TOK", "DATALAYOUT",
2562 "RET", "BR", "SWITCH", "INVOKE", "UNREACHABLE", "UNWIND", "EXCEPT",
2563 "ADD", "SUB", "MUL", "DIV", "UDIV", "SDIV", "FDIV", "REM", "UREM",
2564 "SREM", "FREM", "AND", "OR", "XOR", "SHL", "SHR", "ASHR", "LSHR",
2565 "SETLE", "SETGE", "SETLT", "SETGT", "SETEQ", "SETNE", "ICMP", "FCMP",
2566 "MALLOC", "ALLOCA", "FREE", "LOAD", "STORE", "GETELEMENTPTR", "PHI_TOK",
2567 "SELECT", "VAARG", "EXTRACTELEMENT", "INSERTELEMENT", "SHUFFLEVECTOR",
2568 "VAARG_old", "VANEXT_old", "EQ", "NE", "SLT", "SGT", "SLE", "SGE", "ULT",
2569 "UGT", "ULE", "UGE", "OEQ", "ONE", "OLT", "OGT", "OLE", "OGE", "ORD",
2570 "UNO", "UEQ", "UNE", "CAST", "TRUNC", "ZEXT", "SEXT", "FPTRUNC", "FPEXT",
2571 "FPTOUI", "FPTOSI", "UITOFP", "SITOFP", "PTRTOINT", "INTTOPTR",
2572 "BITCAST", "'='", "','", "'\\\\'", "'('", "')'", "'['", "'x'", "']'",
2573 "'<'", "'>'", "'{'", "'}'", "'*'", "'c'", "$accept", "INTVAL",
2574 "EINT64VAL", "ArithmeticOps", "LogicalOps", "SetCondOps", "IPredicates",
2575 "FPredicates", "ShiftOps", "CastOps", "SIntType", "UIntType", "IntType",
2576 "FPType", "OptAssign", "OptLinkage", "OptCallingConv", "OptAlign",
2577 "OptCAlign", "SectionString", "OptSection", "GlobalVarAttributes",
2578 "GlobalVarAttribute", "TypesV", "UpRTypesV", "Types", "PrimType",
2579 "UpRTypes", "TypeListI", "ArgTypeListI", "ConstVal", "ConstExpr",
2580 "ConstVector", "GlobalType", "Module", "FunctionList", "ConstPool", "@1",
2581 "@2", "@3", "@4", "AsmBlock", "BigOrLittle", "TargetDefinition",
2582 "LibrariesDefinition", "LibList", "Name", "OptName", "ArgVal",
2583 "ArgListH", "ArgList", "FunctionHeaderH", "BEGIN", "FunctionHeader",
Reid Spencerd2920cd2007-03-21 17:27:53 +00002584 "@5", "END", "Function", "FnDeclareLinkage", "FunctionProto", "@6", "@7",
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002585 "OptSideEffect", "ConstValueRef", "SymbolicValueRef", "ValueRef",
2586 "ResolvedVal", "BasicBlockList", "BasicBlock", "InstructionList",
2587 "Unwind", "BBTerminatorInst", "JumpTable", "Inst", "PHIList",
2588 "ValueRefList", "ValueRefListE", "OptTailCall", "InstVal", "IndexList",
2589 "OptVolatile", "MemoryInst", 0
2590};
2591#endif
2592
2593# ifdef YYPRINT
2594/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
2595 token YYLEX-NUM. */
David Greene718fda32007-08-01 03:59:32 +00002596static const unsigned short yytoknum[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002597{
2598 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
2599 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
2600 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
2601 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
2602 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
2603 305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
2604 315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
2605 325, 326, 327, 328, 329, 330, 331, 332, 333, 334,
2606 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
2607 345, 346, 347, 348, 349, 350, 351, 352, 353, 354,
2608 355, 356, 357, 358, 359, 360, 361, 362, 363, 364,
2609 365, 366, 367, 368, 369, 370, 371, 372, 373, 374,
2610 375, 376, 377, 378, 379, 380, 381, 382, 383, 384,
2611 385, 386, 387, 388, 389, 390, 391, 392, 393, 394,
2612 395, 396, 397, 398, 399, 400, 401, 402, 403, 404,
2613 405, 406, 61, 44, 92, 40, 41, 91, 120, 93,
2614 60, 62, 123, 125, 42, 99
2615};
2616# endif
2617
2618/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
2619static const unsigned char yyr1[] =
2620{
2621 0, 166, 167, 167, 168, 168, 169, 169, 169, 169,
2622 169, 169, 169, 169, 169, 169, 169, 170, 170, 170,
2623 171, 171, 171, 171, 171, 171, 172, 172, 172, 172,
2624 172, 172, 172, 172, 172, 172, 173, 173, 173, 173,
2625 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
2626 173, 173, 174, 174, 174, 174, 175, 175, 175, 175,
2627 175, 175, 175, 175, 175, 175, 175, 175, 175, 176,
2628 176, 176, 176, 177, 177, 177, 177, 178, 178, 179,
2629 179, 180, 180, 181, 181, 181, 181, 181, 181, 181,
2630 181, 182, 182, 182, 182, 182, 182, 182, 182, 183,
2631 183, 184, 184, 185, 186, 186, 187, 187, 188, 188,
2632 189, 189, 190, 190, 191, 192, 192, 192, 192, 192,
2633 192, 192, 192, 192, 192, 192, 192, 193, 193, 193,
2634 193, 193, 193, 193, 193, 193, 193, 193, 193, 194,
2635 194, 195, 195, 195, 195, 196, 196, 196, 196, 196,
2636 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
2637 196, 196, 196, 197, 197, 197, 197, 197, 197, 197,
2638 197, 197, 197, 197, 197, 198, 198, 199, 199, 200,
2639 201, 201, 201, 201, 201, 202, 202, 202, 203, 202,
2640 204, 202, 205, 202, 206, 202, 202, 202, 202, 207,
2641 208, 208, 209, 209, 209, 209, 210, 211, 211, 211,
2642 212, 212, 213, 213, 214, 215, 215, 216, 216, 216,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002643 216, 217, 218, 218, 220, 219, 221, 221, 222, 223,
2644 223, 223, 225, 226, 224, 227, 227, 228, 228, 228,
2645 228, 228, 228, 228, 228, 228, 228, 228, 229, 229,
2646 230, 230, 231, 232, 232, 233, 234, 234, 234, 235,
2647 235, 236, 236, 236, 236, 236, 236, 236, 236, 236,
2648 237, 237, 238, 239, 239, 240, 240, 241, 241, 242,
2649 242, 243, 243, 243, 243, 243, 243, 243, 243, 243,
2650 243, 243, 243, 243, 243, 243, 243, 243, 243, 244,
2651 244, 245, 245, 246, 246, 246, 246, 246, 246, 246,
2652 246
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002653};
2654
2655/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
2656static const unsigned char yyr2[] =
2657{
2658 0, 2, 1, 1, 1, 1, 1, 1, 1, 1,
2659 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2660 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2661 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2662 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2663 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2664 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2665 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2666 1, 2, 0, 1, 1, 1, 1, 1, 1, 1,
2667 0, 0, 1, 1, 1, 1, 1, 1, 2, 0,
2668 2, 0, 3, 2, 0, 1, 0, 3, 1, 2,
2669 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2670 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2671 2, 4, 5, 5, 3, 2, 5, 4, 2, 1,
2672 3, 1, 3, 1, 0, 4, 3, 3, 4, 4,
2673 3, 6, 5, 2, 2, 2, 2, 2, 2, 2,
2674 2, 2, 2, 6, 5, 8, 6, 6, 6, 7,
2675 7, 6, 6, 8, 8, 3, 1, 1, 1, 1,
2676 2, 2, 4, 2, 1, 4, 2, 4, 0, 7,
2677 0, 7, 0, 7, 0, 7, 3, 4, 0, 1,
2678 1, 1, 3, 3, 3, 3, 3, 3, 1, 0,
2679 1, 1, 1, 0, 2, 3, 1, 1, 3, 1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002680 0, 8, 1, 1, 0, 4, 1, 1, 2, 0,
2681 1, 1, 0, 0, 5, 0, 1, 1, 1, 1,
2682 1, 1, 1, 1, 1, 3, 1, 5, 1, 1,
2683 1, 1, 2, 2, 2, 3, 2, 0, 1, 1,
2684 1, 2, 2, 3, 9, 9, 8, 13, 1, 1,
2685 6, 5, 2, 6, 7, 1, 3, 1, 0, 2,
2686 1, 5, 5, 5, 6, 6, 2, 4, 4, 6,
2687 4, 4, 4, 4, 6, 6, 2, 7, 1, 2,
2688 0, 1, 0, 3, 6, 3, 6, 2, 4, 6,
2689 4
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002690};
2691
2692/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
2693 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
2694 means the default is an error. */
David Greene718fda32007-08-01 03:59:32 +00002695static const unsigned short yydefact[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002696{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002697 198, 0, 90, 184, 1, 183, 232, 83, 84, 85,
2698 86, 87, 88, 89, 0, 224, 257, 180, 181, 257,
2699 210, 211, 0, 0, 0, 90, 0, 186, 229, 0,
2700 91, 258, 254, 82, 226, 227, 228, 253, 0, 0,
2701 0, 0, 196, 0, 0, 0, 0, 0, 0, 0,
2702 81, 230, 231, 233, 199, 182, 0, 92, 93, 94,
2703 95, 96, 97, 0, 0, 302, 256, 0, 0, 0,
2704 0, 209, 197, 187, 2, 3, 111, 115, 116, 117,
2705 118, 119, 120, 121, 122, 123, 124, 125, 126, 128,
2706 0, 0, 0, 0, 248, 185, 0, 110, 127, 114,
2707 249, 129, 177, 178, 0, 0, 0, 0, 91, 98,
2708 0, 222, 223, 225, 301, 0, 280, 0, 0, 0,
2709 0, 91, 269, 259, 260, 6, 7, 8, 9, 10,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002710 11, 12, 13, 14, 15, 16, 17, 18, 19, 52,
2711 53, 54, 55, 20, 21, 22, 23, 24, 25, 0,
2712 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2713 0, 0, 0, 68, 56, 57, 58, 59, 60, 61,
2714 62, 63, 64, 65, 66, 67, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002715 0, 268, 255, 91, 272, 0, 298, 204, 201, 200,
2716 202, 203, 205, 208, 0, 130, 0, 0, 0, 113,
2717 135, 139, 0, 144, 138, 192, 194, 190, 115, 116,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002718 117, 118, 119, 120, 121, 122, 123, 124, 125, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002719 0, 0, 0, 188, 234, 0, 0, 286, 279, 262,
2720 261, 0, 0, 72, 76, 71, 75, 70, 74, 69,
2721 73, 77, 78, 0, 0, 26, 27, 28, 29, 30,
2722 31, 32, 33, 34, 35, 0, 50, 51, 46, 47,
2723 48, 49, 36, 37, 38, 39, 40, 41, 42, 43,
2724 44, 45, 0, 101, 101, 307, 0, 0, 296, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002725 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002726 0, 0, 0, 0, 0, 206, 0, 0, 0, 0,
2727 0, 134, 143, 141, 0, 106, 106, 106, 160, 161,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002728 4, 5, 158, 159, 162, 157, 153, 154, 0, 0,
2729 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002730 0, 0, 0, 0, 156, 155, 106, 220, 237, 238,
2731 239, 244, 240, 241, 242, 243, 235, 0, 246, 251,
2732 250, 252, 0, 263, 0, 0, 0, 0, 0, 303,
2733 0, 305, 300, 0, 0, 0, 0, 0, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002734 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002735 207, 112, 112, 137, 0, 140, 0, 131, 0, 193,
2736 195, 191, 0, 0, 0, 0, 0, 0, 0, 146,
2737 176, 0, 0, 0, 150, 0, 147, 0, 0, 0,
2738 0, 0, 189, 219, 213, 216, 217, 0, 236, 0,
2739 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2740 310, 0, 0, 0, 290, 293, 0, 0, 291, 292,
2741 0, 0, 0, 287, 288, 0, 308, 0, 132, 133,
2742 136, 142, 0, 0, 108, 106, 0, 0, 300, 0,
2743 0, 0, 0, 0, 145, 135, 114, 0, 148, 149,
2744 0, 0, 0, 0, 0, 212, 214, 0, 104, 0,
2745 245, 0, 0, 278, 0, 0, 101, 102, 101, 275,
2746 299, 0, 0, 0, 0, 0, 281, 282, 283, 278,
2747 0, 103, 109, 107, 0, 0, 0, 0, 0, 0,
2748 0, 175, 152, 0, 0, 0, 0, 0, 0, 218,
2749 215, 105, 99, 0, 0, 0, 277, 0, 284, 285,
2750 0, 304, 306, 0, 0, 0, 289, 294, 295, 0,
2751 309, 0, 0, 164, 0, 0, 0, 0, 151, 0,
2752 0, 0, 0, 0, 0, 221, 247, 0, 0, 0,
2753 276, 273, 0, 297, 0, 0, 0, 172, 0, 0,
2754 166, 167, 168, 171, 163, 100, 0, 266, 0, 0,
2755 0, 274, 169, 170, 0, 0, 0, 264, 0, 265,
2756 0, 0, 165, 173, 174, 0, 0, 0, 0, 0,
2757 0, 271, 0, 0, 270, 267
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002758};
2759
2760/* YYDEFGOTO[NTERM-NUM]. */
David Greene718fda32007-08-01 03:59:32 +00002761static const short yydefgoto[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002762{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002763 -1, 94, 312, 329, 330, 331, 255, 272, 332, 333,
2764 219, 220, 243, 221, 25, 15, 63, 555, 359, 454,
2765 522, 389, 455, 95, 96, 222, 98, 99, 202, 304,
2766 400, 348, 401, 104, 1, 2, 3, 336, 307, 305,
2767 306, 55, 190, 42, 72, 194, 100, 476, 415, 416,
2768 417, 64, 113, 16, 30, 36, 17, 53, 18, 28,
2769 108, 419, 349, 101, 351, 489, 19, 32, 33, 181,
2770 182, 579, 66, 278, 526, 527, 183, 184, 430, 185,
2771 186
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002772};
2773
2774/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
2775 STATE-NUM. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002776#define YYPACT_NINF -542
David Greene718fda32007-08-01 03:59:32 +00002777static const short yypact[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002778{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002779 -542, 13, 162, 567, -542, -542, -542, -542, -542, -542,
2780 -542, -542, -542, -542, 83, -542, 19, -542, -542, -14,
2781 -542, -542, 50, -87, 87, 233, 27, -542, 123, 141,
2782 175, -542, -542, 98, -542, -542, -542, -542, 33, 40,
2783 66, 68, -542, 14, 141, 1265, 156, 156, 156, 156,
2784 -542, -542, -542, -542, -542, -542, 221, -542, -542, -542,
2785 -542, -542, -542, 1265, -19, 1479, -542, 204, 135, 226,
2786 227, 235, -542, -542, -542, -542, 81, -542, -542, -542,
2787 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2788 256, 257, 4, 15, -542, -542, 108, -542, -542, 12,
2789 -542, -542, -542, -542, 1306, 1306, 1306, 1326, 175, -542,
2790 98, -542, -542, -542, -542, 1306, -542, 205, 1367, 116,
2791 479, 175, -542, -542, -542, -542, -542, -542, -542, -542,
2792 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2793 -542, -542, -542, -542, -542, -542, -542, -542, -542, 355,
2794 429, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306,
2795 1306, 1306, 1306, -542, -542, -542, -542, -542, -542, -542,
2796 -542, -542, -542, -542, -542, -542, 1306, 1306, 1306, 1306,
2797 1306, -542, -542, 175, -542, 86, -542, -542, -542, -542,
2798 -542, -542, -542, -542, -13, -542, 110, 111, 75, -542,
2799 -542, 12, -81, 1046, -542, -542, -542, -542, 174, 208,
2800 266, 210, 267, 212, 268, 230, 277, 275, 278, 246,
2801 280, 279, 566, -542, -542, 136, 766, -542, -542, 81,
2802 -542, 766, 766, -542, -542, -542, -542, -542, -542, -542,
2803 -542, -542, -542, 766, 1265, -542, -542, -542, -542, -542,
2804 -542, -542, -542, -542, -542, 1306, -542, -542, -542, -542,
2805 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2806 -542, -542, 1306, 137, 145, -542, 766, 132, 146, 147,
2807 148, 149, 151, 152, 158, 160, 766, 766, 766, 161,
2808 281, 1265, 1306, 1306, 291, -542, 1306, 1306, 155, -27,
2809 1306, -542, -542, 165, 163, 176, 176, 176, -542, -542,
2810 -542, -542, -542, -542, -542, -542, -542, -542, 355, 429,
2811 172, 177, 178, 179, 182, 1087, 1387, 529, 311, 184,
2812 185, 186, 188, 189, -542, -542, 176, 1107, -542, -542,
2813 -542, -542, -542, -542, -542, -542, 282, 1326, -542, -542,
2814 -542, -542, 193, -542, 194, 766, 766, 766, 7, -542,
2815 20, -542, 195, 766, 192, 1306, 1306, 1306, 1306, 1306,
2816 1306, 1306, 200, 201, 206, 1306, 1306, 766, 766, 207,
2817 -542, -59, -149, -542, 196, 12, 1148, -542, 44, -542,
2818 -542, -542, 203, 211, 1326, 1326, 1326, 1326, 1326, -542,
2819 -542, -8, 741, -82, -542, 10, -542, 1326, 1326, 1326,
2820 1326, 1326, -542, -542, 98, -542, 214, 209, -542, 337,
2821 -34, 342, 348, 215, 218, 219, 766, 371, 766, 1306,
2822 -542, 223, 766, 224, -542, -542, 225, 234, -542, -542,
2823 766, 766, 766, -542, -542, 228, -542, 1306, -542, -542,
2824 -542, -542, 362, 375, -542, 176, 1326, 1326, 195, 236,
2825 237, 240, 243, 1326, -542, 238, -25, 11, -542, -542,
2826 244, 245, 247, 250, 352, -542, -542, 1205, 370, 252,
2827 -542, 766, 766, 1306, 766, 766, 258, -542, 258, -542,
2828 259, 766, 264, 1306, 1306, 1306, -542, -542, -542, 1306,
2829 766, -542, -542, -542, 270, 271, 263, 1326, 1326, 1326,
2830 1326, -542, -542, 260, 1326, 1326, 1326, 1326, 1306, -542,
2831 -542, -542, 368, 402, 274, 276, 259, 287, -542, -542,
2832 374, -542, -542, 1306, 285, 766, -542, -542, -542, 290,
2833 -542, 1326, 1326, -542, 283, 295, 284, 294, -542, 296,
2834 297, 299, 302, 303, 430, -542, -542, 414, 41, 425,
2835 -542, -542, 305, -542, 306, 310, 1326, -542, 1326, 1326,
2836 -542, -542, -542, -542, -542, -542, 766, -542, 893, 144,
2837 448, -542, -542, -542, 314, 315, 316, -542, 331, -542,
2838 893, 766, -542, -542, -542, 464, 334, 180, 766, 481,
2839 482, -542, 766, 766, -542, -542
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002840};
2841
2842/* YYPGOTO[NTERM-NUM]. */
David Greene718fda32007-08-01 03:59:32 +00002843static const short yypgoto[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002844{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002845 -542, -542, -542, 435, 439, 441, 191, 197, 442, 445,
2846 -119, -116, -541, -542, 478, 489, -107, -542, -267, 37,
2847 -542, -238, -542, -60, -542, -45, -542, -74, -51, -542,
2848 -101, 300, -252, 134, -542, -542, -542, -542, -542, -542,
2849 -542, 473, -542, -542, -542, -542, 8, -542, 46, -542,
2850 -542, 410, -542, -542, -542, -542, -542, -542, 518, -542,
2851 -542, -542, -528, 142, -90, -113, -542, 505, -542, -72,
2852 -542, -542, -542, -542, 97, 28, -542, -542, 70, -542,
2853 -542
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002854};
2855
2856/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
2857 positive, shift that token. If negative, reduce the rule which
2858 number is the opposite. If zero, do what YYDEFACT says.
2859 If YYTABLE_NINF, syntax error. */
2860#define YYTABLE_NINF -180
David Greene718fda32007-08-01 03:59:32 +00002861static const short yytable[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002862{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002863 97, 241, 227, 110, 242, 230, 223, 361, 197, 31,
2864 111, 26, 449, 4, 244, 204, 34, 578, 97, 201,
2865 74, 75, 426, 199, 77, 78, 79, 80, 81, 82,
2866 83, 84, 85, 86, 87, 428, 88, 20, 590, 21,
2867 275, 26, 31, 279, 280, 281, 282, 283, 284, 285,
2868 588, 233, 234, 235, 236, 237, 238, 239, 240, 205,
2869 206, 207, 596, 89, 427, 43, 289, 290, 390, 391,
2870 226, 463, 300, 226, 403, 405, 291, 427, 452, 468,
2871 74, 75, 301, 199, 77, 78, 79, 80, 81, 82,
2872 83, 84, 85, 86, 87, 420, 88, 20, 412, 21,
2873 448, 453, 38, 39, 40, 204, 273, 274, 226, 276,
2874 277, 226, 226, 226, 226, 226, 226, 226, 225, 463,
2875 20, 41, 21, 89, 201, 231, 300, 480, -139, 201,
2876 -112, 286, 287, 288, 226, 226, 384, 232, -139, 204,
2877 294, 352, 353, 112, 29, 463, 295, 299, 44, 35,
2878 467, 464, 303, 354, 233, 234, 235, 236, 237, 238,
2879 239, 240, -179, 463, 463, 54, 198, -112, 51, 90,
2880 52, 71, 91, 469, 513, 92, 204, 93, 200, 50,
2881 379, 105, 106, 107, 355, 67, 362, 5, 102, 103,
2882 188, 189, 68, 6, 292, 293, 372, 373, 374, 97,
2883 577, 308, 309, 7, 8, 9, 10, 11, 12, 13,
2884 356, -72, -72, -71, -71, -70, -70, 503, 69, 531,
2885 70, 532, 381, 382, 14, 109, 385, 357, 187, 90,
2886 191, 377, 91, -69, -69, 92, -113, 93, 298, 56,
2887 57, 58, 59, 60, 61, 62, 97, 378, 226, 310,
2888 311, 192, 433, 45, 435, 436, 437, 123, 124, 193,
2889 195, 196, 443, 203, 228, 423, 424, 425, 296, 297,
2890 -76, -75, -74, 431, 7, 8, 9, 10, 46, 12,
2891 47, -73, -79, 48, 313, -80, 314, 445, 446, 363,
2892 358, 337, 414, 458, 459, 460, 461, 462, 360, 364,
2893 365, 366, 367, 589, 368, 369, 470, 471, 472, 473,
2894 474, 370, 385, 371, 375, 380, 383, 376, 386, 387,
2895 226, 434, 226, 226, 226, 438, 439, 394, 466, 388,
2896 226, 444, 395, 396, 397, 406, 486, 398, 488, 407,
2897 408, 409, 492, 410, 411, 418, 421, 422, 429, 432,
2898 496, 497, 498, 440, 441, 504, 505, 450, 456, 442,
2899 447, 479, 511, 481, 335, 478, 457, 477, 350, 482,
2900 483, 484, 485, 350, 350, 487, 491, 493, 494, 502,
2901 536, 537, 538, 499, 226, 350, 501, 495, 518, 507,
2902 508, 524, 525, 509, 528, 529, 510, 514, 515, 512,
2903 516, 534, 500, 517, 452, 523, 544, 545, 546, 547,
2904 540, 530, 533, 549, 550, 551, 552, 535, 350, 543,
2905 560, 548, 475, 541, 542, 554, 556, 557, 350, 350,
2906 350, 427, 414, 558, 575, 576, 566, 568, 226, 241,
2907 564, 565, 242, 559, 561, 562, 563, 569, 226, 226,
2908 226, 567, 570, 571, 226, 572, 256, 257, 573, 574,
2909 241, 580, 582, 242, 581, 584, 583, 585, 586, 591,
2910 592, 593, 594, 553, 245, 246, 247, 248, 249, 250,
2911 251, 252, 253, 254, 595, 598, 587, 599, 226, 233,
2912 234, 235, 236, 237, 238, 239, 240, 350, 350, 350,
2913 176, 597, 602, 603, 177, 350, 178, 179, 601, 392,
2914 180, 65, 604, 605, 49, 521, 393, 73, 224, 350,
2915 350, 27, 334, 520, 37, 600, 490, 539, 506, 0,
2916 0, 0, 0, 0, 74, 75, 0, 199, 208, 209,
2917 210, 211, 212, 213, 214, 215, 216, 217, 218, 0,
2918 88, 20, 0, 21, 258, 259, 260, 261, 262, 263,
2919 264, 265, 266, 267, 268, 269, 270, 271, 350, 0,
2920 350, 74, 75, 0, 350, 0, 0, 89, 0, 0,
2921 0, 0, 350, 350, 350, 0, 0, -82, 20, 20,
2922 21, 21, 315, 0, 0, 0, 0, 0, 6, -82,
2923 -82, 0, 0, 0, 316, 317, 0, 0, -82, -82,
2924 -82, -82, -82, -82, -82, 0, 0, -82, 22, 0,
2925 0, 0, 0, 350, 350, 23, 350, 350, 0, 24,
2926 0, 0, 0, 350, 0, 0, 0, 0, 0, 0,
2927 0, 0, 350, 0, 0, 125, 126, 127, 128, 129,
2928 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
2929 140, 141, 142, 143, 144, 145, 146, 147, 148, 318,
2930 319, 0, 0, 0, 0, 0, 320, 350, 321, 0,
2931 322, 323, 324, 90, 0, 0, 91, 0, 0, 92,
2932 0, 93, 404, 0, 0, 0, 0, 0, 0, 0,
2933 0, 0, 0, 0, 0, 163, 164, 165, 166, 167,
2934 168, 169, 170, 171, 172, 173, 174, 175, 350, 0,
2935 0, 0, 0, 325, 0, 0, 326, 0, 327, 0,
2936 0, 328, 0, 350, 0, 0, 0, 0, 0, 0,
2937 350, 0, 0, 0, 350, 350, 74, 75, 0, 199,
2938 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
2939 218, 0, 88, 20, 0, 21, 0, 0, 0, 338,
2940 339, 74, 75, 340, 0, 0, 0, 0, 0, 0,
2941 0, 0, 0, 0, 0, 0, 0, 0, 20, 89,
2942 21, 0, 341, 342, 343, 0, 0, 0, 0, 0,
2943 0, 0, 0, 0, 344, 345, 0, 0, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002944 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002945 0, 0, 0, 0, 0, 0, 0, 346, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002946 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002947 0, 0, 0, 0, 0, 125, 126, 127, 128, 129,
2948 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
2949 140, 141, 142, 143, 144, 145, 146, 147, 148, 318,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002950 319, 0, 0, 0, 0, 0, 320, 0, 321, 0,
2951 322, 323, 324, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002952 0, 0, 0, 0, 0, 90, 338, 339, 91, 0,
2953 340, 92, 0, 93, 465, 163, 164, 165, 166, 167,
2954 168, 169, 170, 171, 172, 173, 174, 175, 0, 341,
2955 342, 343, 0, 0, 0, 0, 347, 0, 0, 0,
2956 0, 344, 345, 0, 0, 0, 0, 0, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002957 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002958 0, 0, 0, 0, 346, 0, 0, 0, 0, 0,
2959 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2960 0, 0, 125, 126, 127, 128, 129, 130, 131, 132,
2961 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
2962 143, 144, 145, 146, 147, 148, 318, 319, 0, 0,
2963 0, 0, 0, 320, 0, 321, 0, 322, 323, 324,
2964 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2965 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2966 0, 0, 163, 164, 165, 166, 167, 168, 169, 170,
2967 171, 172, 173, 174, 175, 0, 0, 0, 0, 0,
2968 0, 74, 75, 347, 199, 77, 78, 79, 80, 81,
2969 82, 83, 84, 85, 86, 87, 0, 88, 20, 0,
2970 21, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2971 0, 0, 0, 302, 0, 0, 0, 0, 0, 0,
2972 0, 0, 74, 75, 89, 199, 208, 209, 210, 211,
2973 212, 213, 214, 215, 216, 217, 218, 0, 88, 20,
2974 0, 21, 74, 75, 0, 199, 77, 78, 79, 80,
2975 81, 82, 83, 84, 85, 86, 87, 0, 88, 20,
2976 0, 21, 0, 0, 0, 89, 0, 0, 0, 0,
2977 0, 0, 0, 0, 413, 0, 0, 0, 0, 0,
2978 0, 0, 0, 74, 75, 89, 199, 77, 78, 79,
2979 80, 81, 82, 83, 84, 85, 86, 87, 0, 88,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002980 20, 0, 21, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002981 0, 0, 0, 0, 0, 451, 0, 0, 0, 0,
2982 0, 0, 0, 0, 0, 0, 89, 0, 0, 0,
2983 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
2984 74, 75, 0, 199, 77, 78, 79, 80, 81, 82,
2985 83, 84, 85, 86, 87, 0, 88, 20, 0, 21,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002986 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002987 0, 90, 519, 0, 91, 0, 399, 92, 0, 93,
2988 0, 0, 0, 89, 0, 0, 0, 0, 0, 0,
2989 0, 90, 0, 0, 91, 0, 0, 92, 0, 93,
2990 74, 75, 0, 76, 77, 78, 79, 80, 81, 82,
2991 83, 84, 85, 86, 87, 0, 88, 20, 0, 21,
2992 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2993 0, 0, 90, 0, 0, 91, 0, 0, 92, 0,
2994 93, 74, 75, 89, 199, 77, 78, 79, 80, 81,
2995 82, 83, 84, 85, 86, 87, 0, 88, 20, 0,
2996 21, 74, 75, 0, 199, 208, 209, 210, 211, 212,
2997 213, 214, 215, 216, 217, 218, 0, 88, 20, 0,
2998 21, 0, 0, 0, 89, 0, 0, 0, 0, 90,
2999 0, 0, 91, 0, 0, 92, 0, 93, 0, 0,
3000 0, 0, 74, 75, 89, 229, 77, 78, 79, 80,
3001 81, 82, 83, 84, 85, 86, 87, 0, 88, 20,
3002 0, 21, 74, 75, 0, 199, 208, 209, 210, 211,
3003 212, 213, 214, 215, 216, 217, 218, 0, 88, 20,
3004 0, 21, 0, 0, 0, 89, 0, 0, 0, 90,
3005 0, 0, 91, 0, 0, 92, 0, 93, 0, 0,
3006 0, 0, 0, 0, 0, 89, 0, 0, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003007 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3008 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003009 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003010 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003011 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003012 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3013 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003014 0, 0, 0, 0, 114, 0, 0, 0, 0, 0,
3015 0, 90, 0, 0, 91, 0, 0, 92, 115, 93,
3016 0, 0, 0, 0, 0, 0, 0, 0, 116, 117,
3017 0, 90, 0, 0, 91, 0, 0, 92, 0, 402,
3018 0, 118, 119, 120, 121, 122, 123, 124, 125, 126,
3019 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
3020 137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
3021 147, 148, 149, 150, 151, 152, 153, 0, 0, 154,
3022 155, 156, 157, 158, 159, 160, 161, 162, 0, 0,
3023 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
3024 0, 0, 0, 0, 0, 0, 0, 0, 163, 164,
3025 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
3026 175
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003027};
3028
David Greene718fda32007-08-01 03:59:32 +00003029static const short yycheck[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003030{
Reid Spencerd2920cd2007-03-21 17:27:53 +00003031 45, 120, 115, 63, 120, 118, 107, 274, 4, 23,
3032 29, 3, 161, 0, 121, 164, 30, 558, 63, 93,
3033 5, 6, 15, 8, 9, 10, 11, 12, 13, 14,
3034 15, 16, 17, 18, 19, 15, 21, 22, 579, 24,
3035 153, 33, 23, 156, 157, 158, 159, 160, 161, 162,
3036 578, 10, 11, 12, 13, 14, 15, 16, 17, 104,
3037 105, 106, 590, 48, 57, 152, 179, 180, 306, 307,
3038 115, 153, 153, 118, 326, 327, 183, 57, 34, 161,
3039 5, 6, 163, 8, 9, 10, 11, 12, 13, 14,
3040 15, 16, 17, 18, 19, 347, 21, 22, 336, 24,
3041 159, 57, 52, 53, 54, 164, 151, 152, 153, 154,
3042 155, 156, 157, 158, 159, 160, 161, 162, 110, 153,
3043 22, 71, 24, 48, 198, 9, 153, 161, 153, 203,
3044 155, 176, 177, 178, 179, 180, 163, 21, 163, 164,
3045 153, 231, 232, 162, 61, 153, 159, 198, 61, 163,
3046 402, 159, 203, 243, 10, 11, 12, 13, 14, 15,
3047 16, 17, 0, 153, 153, 24, 162, 155, 45, 154,
3048 47, 157, 157, 163, 163, 160, 164, 162, 163, 152,
3049 293, 47, 48, 49, 244, 152, 276, 25, 32, 33,
3050 55, 56, 152, 31, 108, 109, 286, 287, 288, 244,
3051 159, 27, 28, 41, 42, 43, 44, 45, 46, 47,
3052 255, 3, 4, 3, 4, 3, 4, 455, 152, 486,
3053 152, 488, 296, 297, 62, 4, 300, 272, 24, 154,
3054 4, 291, 157, 3, 4, 160, 155, 162, 163, 64,
3055 65, 66, 67, 68, 69, 70, 291, 292, 293, 3,
3056 4, 24, 365, 20, 367, 368, 369, 77, 78, 24,
3057 4, 4, 375, 155, 59, 355, 356, 357, 158, 158,
3058 4, 4, 4, 363, 41, 42, 43, 44, 45, 46,
3059 47, 4, 7, 50, 4, 7, 7, 377, 378, 157,
3060 153, 155, 337, 394, 395, 396, 397, 398, 153, 153,
3061 153, 153, 153, 159, 153, 153, 407, 408, 409, 410,
3062 411, 153, 386, 153, 153, 24, 161, 36, 153, 156,
3063 365, 366, 367, 368, 369, 370, 371, 155, 402, 153,
3064 375, 376, 155, 155, 155, 24, 426, 155, 428, 155,
3065 155, 155, 432, 155, 155, 63, 153, 153, 153, 157,
3066 440, 441, 442, 153, 153, 456, 457, 161, 155, 153,
3067 153, 24, 463, 21, 222, 156, 155, 153, 226, 21,
3068 155, 153, 153, 231, 232, 4, 153, 153, 153, 4,
3069 493, 494, 495, 155, 429, 243, 24, 153, 36, 153,
3070 153, 481, 482, 153, 484, 485, 153, 153, 153, 161,
3071 153, 491, 447, 153, 34, 153, 507, 508, 509, 510,
3072 500, 153, 153, 514, 515, 516, 517, 153, 276, 156,
3073 533, 161, 414, 153, 153, 57, 24, 153, 286, 287,
3074 288, 57, 477, 157, 4, 21, 153, 153, 483, 558,
3075 541, 542, 558, 156, 159, 535, 156, 153, 493, 494,
3076 495, 156, 156, 156, 499, 156, 27, 28, 156, 156,
3077 579, 36, 156, 579, 159, 566, 156, 568, 569, 21,
3078 156, 156, 156, 518, 119, 120, 121, 122, 123, 124,
3079 125, 126, 127, 128, 153, 21, 576, 153, 533, 10,
3080 11, 12, 13, 14, 15, 16, 17, 355, 356, 357,
3081 65, 591, 21, 21, 65, 363, 65, 65, 598, 318,
3082 65, 33, 602, 603, 25, 478, 319, 44, 108, 377,
3083 378, 3, 222, 477, 19, 597, 429, 499, 458, -1,
3084 -1, -1, -1, -1, 5, 6, -1, 8, 9, 10,
3085 11, 12, 13, 14, 15, 16, 17, 18, 19, -1,
3086 21, 22, -1, 24, 125, 126, 127, 128, 129, 130,
3087 131, 132, 133, 134, 135, 136, 137, 138, 426, -1,
3088 428, 5, 6, -1, 432, -1, -1, 48, -1, -1,
3089 -1, -1, 440, 441, 442, -1, -1, 20, 22, 22,
3090 24, 24, 26, -1, -1, -1, -1, -1, 31, 32,
3091 33, -1, -1, -1, 38, 39, -1, -1, 41, 42,
3092 43, 44, 45, 46, 47, -1, -1, 50, 51, -1,
3093 -1, -1, -1, 481, 482, 58, 484, 485, -1, 62,
3094 -1, -1, -1, 491, -1, -1, -1, -1, -1, -1,
3095 -1, -1, 500, -1, -1, 79, 80, 81, 82, 83,
3096 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3097 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3098 104, -1, -1, -1, -1, -1, 110, 535, 112, -1,
3099 114, 115, 116, 154, -1, -1, 157, -1, -1, 160,
3100 -1, 162, 163, -1, -1, -1, -1, -1, -1, -1,
3101 -1, -1, -1, -1, -1, 139, 140, 141, 142, 143,
3102 144, 145, 146, 147, 148, 149, 150, 151, 576, -1,
3103 -1, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3104 -1, 165, -1, 591, -1, -1, -1, -1, -1, -1,
3105 598, -1, -1, -1, 602, 603, 5, 6, -1, 8,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003106 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003107 19, -1, 21, 22, -1, 24, -1, -1, -1, 3,
3108 4, 5, 6, 7, -1, -1, -1, -1, -1, -1,
3109 -1, -1, -1, -1, -1, -1, -1, -1, 22, 48,
3110 24, -1, 26, 27, 28, -1, -1, -1, -1, -1,
3111 -1, -1, -1, -1, 38, 39, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003112 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3113 -1, -1, -1, -1, -1, -1, -1, 61, -1, -1,
3114 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3115 -1, -1, -1, -1, -1, 79, 80, 81, 82, 83,
3116 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3117 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3118 104, -1, -1, -1, -1, -1, 110, -1, 112, -1,
3119 114, 115, 116, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003120 -1, -1, -1, -1, -1, 154, 3, 4, 157, -1,
3121 7, 160, -1, 162, 163, 139, 140, 141, 142, 143,
3122 144, 145, 146, 147, 148, 149, 150, 151, -1, 26,
3123 27, 28, -1, -1, -1, -1, 160, -1, -1, -1,
3124 -1, 38, 39, -1, -1, -1, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003125 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003126 -1, -1, -1, -1, 61, -1, -1, -1, -1, -1,
3127 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3128 -1, -1, 79, 80, 81, 82, 83, 84, 85, 86,
3129 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
3130 97, 98, 99, 100, 101, 102, 103, 104, -1, -1,
3131 -1, -1, -1, 110, -1, 112, -1, 114, 115, 116,
3132 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3133 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3134 -1, -1, 139, 140, 141, 142, 143, 144, 145, 146,
3135 147, 148, 149, 150, 151, -1, -1, -1, -1, -1,
3136 -1, 5, 6, 160, 8, 9, 10, 11, 12, 13,
3137 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3138 24, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3139 -1, -1, -1, 37, -1, -1, -1, -1, -1, -1,
3140 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003141 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003142 -1, 24, 5, 6, -1, 8, 9, 10, 11, 12,
3143 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3144 -1, 24, -1, -1, -1, 48, -1, -1, -1, -1,
3145 -1, -1, -1, -1, 37, -1, -1, -1, -1, -1,
3146 -1, -1, -1, 5, 6, 48, 8, 9, 10, 11,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003147 12, 13, 14, 15, 16, 17, 18, 19, -1, 21,
3148 22, -1, 24, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003149 -1, -1, -1, -1, -1, 37, -1, -1, -1, -1,
3150 -1, -1, -1, -1, -1, -1, 48, -1, -1, -1,
3151 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3152 5, 6, -1, 8, 9, 10, 11, 12, 13, 14,
3153 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
3154 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3155 -1, 154, 37, -1, 157, -1, 159, 160, -1, 162,
3156 -1, -1, -1, 48, -1, -1, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003157 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003158 5, 6, -1, 8, 9, 10, 11, 12, 13, 14,
3159 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003160 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003161 -1, -1, 154, -1, -1, 157, -1, -1, 160, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003162 162, 5, 6, 48, 8, 9, 10, 11, 12, 13,
3163 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3164 24, 5, 6, -1, 8, 9, 10, 11, 12, 13,
3165 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3166 24, -1, -1, -1, 48, -1, -1, -1, -1, 154,
3167 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
3168 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
3169 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3170 -1, 24, 5, 6, -1, 8, 9, 10, 11, 12,
3171 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3172 -1, 24, -1, -1, -1, 48, -1, -1, -1, 154,
3173 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
3174 -1, -1, -1, -1, -1, 48, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003175 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3176 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003177 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003178 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003179 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003180 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3181 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003182 -1, -1, -1, -1, 35, -1, -1, -1, -1, -1,
3183 -1, 154, -1, -1, 157, -1, -1, 160, 49, 162,
3184 -1, -1, -1, -1, -1, -1, -1, -1, 59, 60,
3185 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
3186 -1, 72, 73, 74, 75, 76, 77, 78, 79, 80,
3187 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
3188 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
3189 101, 102, 103, 104, 105, 106, 107, -1, -1, 110,
3190 111, 112, 113, 114, 115, 116, 117, 118, -1, -1,
3191 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3192 -1, -1, -1, -1, -1, -1, -1, -1, 139, 140,
3193 141, 142, 143, 144, 145, 146, 147, 148, 149, 150,
3194 151
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003195};
3196
3197/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
3198 symbol of state STATE-NUM. */
3199static const unsigned char yystos[] =
3200{
3201 0, 200, 201, 202, 0, 25, 31, 41, 42, 43,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003202 44, 45, 46, 47, 62, 181, 219, 222, 224, 232,
3203 22, 24, 51, 58, 62, 180, 212, 224, 225, 61,
3204 220, 23, 233, 234, 30, 163, 221, 233, 52, 53,
3205 54, 71, 209, 152, 61, 20, 45, 47, 50, 181,
3206 152, 45, 47, 223, 24, 207, 64, 65, 66, 67,
3207 68, 69, 70, 182, 217, 180, 238, 152, 152, 152,
3208 152, 157, 210, 207, 5, 6, 8, 9, 10, 11,
3209 12, 13, 14, 15, 16, 17, 18, 19, 21, 48,
3210 154, 157, 160, 162, 167, 189, 190, 191, 192, 193,
3211 212, 229, 32, 33, 199, 199, 199, 199, 226, 4,
3212 189, 29, 162, 218, 35, 49, 59, 60, 72, 73,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003213 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
3214 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3215 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3216 104, 105, 106, 107, 110, 111, 112, 113, 114, 115,
3217 116, 117, 118, 139, 140, 141, 142, 143, 144, 145,
3218 146, 147, 148, 149, 150, 151, 169, 170, 171, 174,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003219 175, 235, 236, 242, 243, 245, 246, 24, 55, 56,
3220 208, 4, 24, 24, 211, 4, 4, 4, 162, 8,
3221 163, 193, 194, 155, 164, 191, 191, 191, 9, 10,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003222 11, 12, 13, 14, 15, 16, 17, 18, 19, 176,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003223 177, 179, 191, 196, 217, 212, 191, 231, 59, 8,
3224 231, 9, 21, 10, 11, 12, 13, 14, 15, 16,
3225 17, 176, 177, 178, 182, 119, 120, 121, 122, 123,
3226 124, 125, 126, 127, 128, 172, 27, 28, 125, 126,
3227 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
3228 137, 138, 173, 191, 191, 231, 191, 191, 239, 231,
3229 231, 231, 231, 231, 231, 231, 191, 191, 191, 231,
3230 231, 182, 108, 109, 153, 159, 158, 158, 163, 194,
3231 153, 163, 37, 194, 195, 205, 206, 204, 27, 28,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003232 3, 4, 168, 4, 7, 26, 38, 39, 103, 104,
3233 110, 112, 114, 115, 116, 157, 160, 162, 165, 169,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003234 170, 171, 174, 175, 197, 229, 203, 155, 3, 4,
3235 7, 26, 27, 28, 38, 39, 61, 160, 197, 228,
3236 229, 230, 230, 230, 230, 189, 191, 191, 153, 184,
3237 153, 184, 230, 157, 153, 153, 153, 153, 153, 153,
3238 153, 153, 230, 230, 230, 153, 36, 189, 191, 231,
3239 24, 193, 193, 161, 163, 193, 153, 156, 153, 187,
3240 187, 187, 172, 173, 155, 155, 155, 155, 155, 159,
3241 196, 198, 162, 198, 163, 198, 24, 155, 155, 155,
3242 155, 155, 187, 37, 191, 214, 215, 216, 63, 227,
3243 198, 153, 153, 230, 230, 230, 15, 57, 15, 153,
3244 244, 230, 157, 231, 191, 231, 231, 231, 191, 191,
3245 153, 153, 153, 231, 191, 230, 230, 153, 159, 161,
3246 161, 37, 34, 57, 185, 188, 155, 155, 196, 196,
3247 196, 196, 196, 153, 159, 163, 193, 198, 161, 163,
3248 196, 196, 196, 196, 196, 212, 213, 153, 156, 24,
3249 161, 21, 21, 155, 153, 153, 230, 4, 230, 231,
3250 240, 153, 230, 153, 153, 153, 230, 230, 230, 155,
3251 191, 24, 4, 187, 196, 196, 244, 153, 153, 153,
3252 153, 196, 161, 163, 153, 153, 153, 153, 36, 37,
3253 214, 185, 186, 153, 230, 230, 240, 241, 230, 230,
3254 153, 184, 184, 153, 230, 153, 231, 231, 231, 241,
3255 230, 153, 153, 156, 196, 196, 196, 196, 161, 196,
3256 196, 196, 196, 191, 57, 183, 24, 153, 157, 156,
3257 231, 159, 230, 156, 196, 196, 153, 156, 153, 153,
3258 156, 156, 156, 156, 156, 4, 21, 159, 178, 237,
3259 36, 159, 156, 156, 196, 196, 196, 230, 228, 159,
3260 178, 21, 156, 156, 156, 153, 228, 230, 21, 153,
3261 235, 230, 21, 21, 230, 230
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003262};
Reid Spencere7c3c602006-11-30 06:36:44 +00003263
David Greene718fda32007-08-01 03:59:32 +00003264#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
3265# define YYSIZE_T __SIZE_TYPE__
3266#endif
3267#if ! defined (YYSIZE_T) && defined (size_t)
3268# define YYSIZE_T size_t
3269#endif
3270#if ! defined (YYSIZE_T)
3271# if defined (__STDC__) || defined (__cplusplus)
3272# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
3273# define YYSIZE_T size_t
3274# endif
3275#endif
3276#if ! defined (YYSIZE_T)
3277# define YYSIZE_T unsigned int
3278#endif
3279
Reid Spencere7c3c602006-11-30 06:36:44 +00003280#define yyerrok (yyerrstatus = 0)
3281#define yyclearin (yychar = YYEMPTY)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003282#define YYEMPTY (-2)
Reid Spencere7c3c602006-11-30 06:36:44 +00003283#define YYEOF 0
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003284
Reid Spencere7c3c602006-11-30 06:36:44 +00003285#define YYACCEPT goto yyacceptlab
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003286#define YYABORT goto yyabortlab
3287#define YYERROR goto yyerrorlab
3288
3289
3290/* Like YYERROR except do call yyerror. This remains here temporarily
3291 to ease the transition to the new meaning of YYERROR, for GCC.
Reid Spencere7c3c602006-11-30 06:36:44 +00003292 Once GCC version 2 has supplanted version 1, this can go. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003293
Reid Spencere7c3c602006-11-30 06:36:44 +00003294#define YYFAIL goto yyerrlab
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003295
Reid Spencere7c3c602006-11-30 06:36:44 +00003296#define YYRECOVERING() (!!yyerrstatus)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003297
3298#define YYBACKUP(Token, Value) \
Reid Spencere7c3c602006-11-30 06:36:44 +00003299do \
3300 if (yychar == YYEMPTY && yylen == 1) \
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003301 { \
3302 yychar = (Token); \
3303 yylval = (Value); \
3304 yytoken = YYTRANSLATE (yychar); \
Chris Lattnercf3d0612007-02-13 06:04:17 +00003305 YYPOPSTACK; \
Reid Spencere7c3c602006-11-30 06:36:44 +00003306 goto yybackup; \
3307 } \
3308 else \
David Greene718fda32007-08-01 03:59:32 +00003309 { \
3310 yyerror ("syntax error: cannot back up");\
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003311 YYERROR; \
3312 } \
Chris Lattnercf3d0612007-02-13 06:04:17 +00003313while (0)
Reid Spencere7c3c602006-11-30 06:36:44 +00003314
Reid Spencere7c3c602006-11-30 06:36:44 +00003315#define YYTERROR 1
3316#define YYERRCODE 256
3317
David Greene718fda32007-08-01 03:59:32 +00003318/* YYLLOC_DEFAULT -- Compute the default location (before the actions
3319 are run). */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003320
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003321#ifndef YYLLOC_DEFAULT
David Greene718fda32007-08-01 03:59:32 +00003322# define YYLLOC_DEFAULT(Current, Rhs, N) \
3323 ((Current).first_line = (Rhs)[1].first_line, \
3324 (Current).first_column = (Rhs)[1].first_column, \
3325 (Current).last_line = (Rhs)[N].last_line, \
3326 (Current).last_column = (Rhs)[N].last_column)
Reid Spencere7c3c602006-11-30 06:36:44 +00003327#endif
3328
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003329/* YYLEX -- calling `yylex' with the right arguments. */
3330
Reid Spencer950bf602007-01-26 08:19:09 +00003331#ifdef YYLEX_PARAM
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003332# define YYLEX yylex (YYLEX_PARAM)
Reid Spencer950bf602007-01-26 08:19:09 +00003333#else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003334# define YYLEX yylex ()
Chris Lattner4227bdb2007-02-19 07:34:02 +00003335#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003336
3337/* Enable debugging if requested. */
3338#if YYDEBUG
3339
3340# ifndef YYFPRINTF
3341# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
3342# define YYFPRINTF fprintf
3343# endif
3344
3345# define YYDPRINTF(Args) \
3346do { \
3347 if (yydebug) \
3348 YYFPRINTF Args; \
3349} while (0)
3350
David Greene718fda32007-08-01 03:59:32 +00003351# define YYDSYMPRINT(Args) \
3352do { \
3353 if (yydebug) \
3354 yysymprint Args; \
3355} while (0)
3356
3357# define YYDSYMPRINTF(Title, Token, Value, Location) \
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003358do { \
3359 if (yydebug) \
3360 { \
3361 YYFPRINTF (stderr, "%s ", Title); \
David Greene718fda32007-08-01 03:59:32 +00003362 yysymprint (stderr, \
3363 Token, Value); \
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003364 YYFPRINTF (stderr, "\n"); \
3365 } \
3366} while (0)
3367
3368/*------------------------------------------------------------------.
3369| yy_stack_print -- Print the state stack from its BOTTOM up to its |
3370| TOP (included). |
3371`------------------------------------------------------------------*/
3372
3373#if defined (__STDC__) || defined (__cplusplus)
3374static void
David Greene718fda32007-08-01 03:59:32 +00003375yy_stack_print (short *bottom, short *top)
Chris Lattner4227bdb2007-02-19 07:34:02 +00003376#else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003377static void
3378yy_stack_print (bottom, top)
David Greene718fda32007-08-01 03:59:32 +00003379 short *bottom;
3380 short *top;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003381#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003382{
3383 YYFPRINTF (stderr, "Stack now");
3384 for (/* Nothing. */; bottom <= top; ++bottom)
3385 YYFPRINTF (stderr, " %d", *bottom);
3386 YYFPRINTF (stderr, "\n");
3387}
3388
3389# define YY_STACK_PRINT(Bottom, Top) \
3390do { \
3391 if (yydebug) \
3392 yy_stack_print ((Bottom), (Top)); \
3393} while (0)
3394
3395
3396/*------------------------------------------------.
3397| Report that the YYRULE is going to be reduced. |
3398`------------------------------------------------*/
3399
3400#if defined (__STDC__) || defined (__cplusplus)
3401static void
3402yy_reduce_print (int yyrule)
3403#else
3404static void
3405yy_reduce_print (yyrule)
3406 int yyrule;
Chris Lattnercf3d0612007-02-13 06:04:17 +00003407#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003408{
3409 int yyi;
David Greene718fda32007-08-01 03:59:32 +00003410 unsigned int yylno = yyrline[yyrule];
3411 YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003412 yyrule - 1, yylno);
3413 /* Print the symbols being reduced, and their result. */
3414 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
David Greene718fda32007-08-01 03:59:32 +00003415 YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
3416 YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003417}
Reid Spencer9d6565a2007-02-15 02:26:10 +00003418
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003419# define YY_REDUCE_PRINT(Rule) \
3420do { \
3421 if (yydebug) \
3422 yy_reduce_print (Rule); \
3423} while (0)
Reid Spencer9d6565a2007-02-15 02:26:10 +00003424
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003425/* Nonzero means print parse trace. It is left uninitialized so that
3426 multiple parsers can coexist. */
3427int yydebug;
3428#else /* !YYDEBUG */
3429# define YYDPRINTF(Args)
David Greene718fda32007-08-01 03:59:32 +00003430# define YYDSYMPRINT(Args)
3431# define YYDSYMPRINTF(Title, Token, Value, Location)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003432# define YY_STACK_PRINT(Bottom, Top)
3433# define YY_REDUCE_PRINT(Rule)
3434#endif /* !YYDEBUG */
Reid Spencer9d6565a2007-02-15 02:26:10 +00003435
Reid Spencer9d6565a2007-02-15 02:26:10 +00003436
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003437/* YYINITDEPTH -- initial size of the parser's stacks. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003438#ifndef YYINITDEPTH
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003439# define YYINITDEPTH 200
Reid Spencere7c3c602006-11-30 06:36:44 +00003440#endif
3441
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003442/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
3443 if the built-in stack extension method is used).
Reid Spencere7c3c602006-11-30 06:36:44 +00003444
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003445 Do not make this value too large; the results are undefined if
David Greene718fda32007-08-01 03:59:32 +00003446 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003447 evaluated with infinite-precision integer arithmetic. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003448
David Greene718fda32007-08-01 03:59:32 +00003449#if defined (YYMAXDEPTH) && YYMAXDEPTH == 0
3450# undef YYMAXDEPTH
3451#endif
3452
Reid Spencere7c3c602006-11-30 06:36:44 +00003453#ifndef YYMAXDEPTH
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003454# define YYMAXDEPTH 10000
Reid Spencere7c3c602006-11-30 06:36:44 +00003455#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003456
Reid Spencere7c3c602006-11-30 06:36:44 +00003457
3458
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003459#if YYERROR_VERBOSE
Reid Spencere7c3c602006-11-30 06:36:44 +00003460
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003461# ifndef yystrlen
3462# if defined (__GLIBC__) && defined (_STRING_H)
3463# define yystrlen strlen
3464# else
3465/* Return the length of YYSTR. */
3466static YYSIZE_T
3467# if defined (__STDC__) || defined (__cplusplus)
3468yystrlen (const char *yystr)
3469# else
3470yystrlen (yystr)
3471 const char *yystr;
3472# endif
Chris Lattner4227bdb2007-02-19 07:34:02 +00003473{
David Greene718fda32007-08-01 03:59:32 +00003474 register const char *yys = yystr;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003475
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003476 while (*yys++ != '\0')
3477 continue;
3478
3479 return yys - yystr - 1;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003480}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003481# endif
3482# endif
Chris Lattner4227bdb2007-02-19 07:34:02 +00003483
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003484# ifndef yystpcpy
3485# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
3486# define yystpcpy stpcpy
3487# else
3488/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
3489 YYDEST. */
3490static char *
3491# if defined (__STDC__) || defined (__cplusplus)
3492yystpcpy (char *yydest, const char *yysrc)
3493# else
3494yystpcpy (yydest, yysrc)
3495 char *yydest;
3496 const char *yysrc;
3497# endif
Chris Lattner4227bdb2007-02-19 07:34:02 +00003498{
David Greene718fda32007-08-01 03:59:32 +00003499 register char *yyd = yydest;
3500 register const char *yys = yysrc;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003501
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003502 while ((*yyd++ = *yys++) != '\0')
3503 continue;
3504
3505 return yyd - 1;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003506}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003507# endif
3508# endif
Chris Lattner4227bdb2007-02-19 07:34:02 +00003509
David Greene718fda32007-08-01 03:59:32 +00003510#endif /* !YYERROR_VERBOSE */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003511
Reid Spencer9d6565a2007-02-15 02:26:10 +00003512
3513
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003514#if YYDEBUG
3515/*--------------------------------.
3516| Print this symbol on YYOUTPUT. |
3517`--------------------------------*/
Reid Spencer9d6565a2007-02-15 02:26:10 +00003518
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003519#if defined (__STDC__) || defined (__cplusplus)
3520static void
3521yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
Chris Lattner4227bdb2007-02-19 07:34:02 +00003522#else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003523static void
3524yysymprint (yyoutput, yytype, yyvaluep)
3525 FILE *yyoutput;
3526 int yytype;
3527 YYSTYPE *yyvaluep;
3528#endif
3529{
3530 /* Pacify ``unused variable'' warnings. */
3531 (void) yyvaluep;
3532
3533 if (yytype < YYNTOKENS)
David Greene718fda32007-08-01 03:59:32 +00003534 {
3535 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
3536# ifdef YYPRINT
3537 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
3538# endif
3539 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003540 else
3541 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
3542
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003543 switch (yytype)
3544 {
3545 default:
3546 break;
3547 }
3548 YYFPRINTF (yyoutput, ")");
3549}
3550
3551#endif /* ! YYDEBUG */
3552/*-----------------------------------------------.
3553| Release the memory associated to this symbol. |
3554`-----------------------------------------------*/
3555
3556#if defined (__STDC__) || defined (__cplusplus)
3557static void
David Greene718fda32007-08-01 03:59:32 +00003558yydestruct (int yytype, YYSTYPE *yyvaluep)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003559#else
3560static void
David Greene718fda32007-08-01 03:59:32 +00003561yydestruct (yytype, yyvaluep)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003562 int yytype;
3563 YYSTYPE *yyvaluep;
3564#endif
3565{
3566 /* Pacify ``unused variable'' warnings. */
3567 (void) yyvaluep;
3568
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003569 switch (yytype)
3570 {
3571
3572 default:
3573 break;
3574 }
3575}
3576
3577
3578/* Prevent warnings from -Wmissing-prototypes. */
3579
3580#ifdef YYPARSE_PARAM
3581# if defined (__STDC__) || defined (__cplusplus)
3582int yyparse (void *YYPARSE_PARAM);
3583# else
3584int yyparse ();
3585# endif
3586#else /* ! YYPARSE_PARAM */
3587#if defined (__STDC__) || defined (__cplusplus)
Reid Spencere7c3c602006-11-30 06:36:44 +00003588int yyparse (void);
Chris Lattner4227bdb2007-02-19 07:34:02 +00003589#else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003590int yyparse ();
3591#endif
3592#endif /* ! YYPARSE_PARAM */
3593
3594
3595
David Greene718fda32007-08-01 03:59:32 +00003596/* The lookahead symbol. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003597int yychar;
3598
David Greene718fda32007-08-01 03:59:32 +00003599/* The semantic value of the lookahead symbol. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003600YYSTYPE yylval;
3601
3602/* Number of syntax errors so far. */
3603int yynerrs;
3604
3605
3606
3607/*----------.
3608| yyparse. |
3609`----------*/
3610
3611#ifdef YYPARSE_PARAM
3612# if defined (__STDC__) || defined (__cplusplus)
3613int yyparse (void *YYPARSE_PARAM)
3614# else
3615int yyparse (YYPARSE_PARAM)
3616 void *YYPARSE_PARAM;
3617# endif
3618#else /* ! YYPARSE_PARAM */
3619#if defined (__STDC__) || defined (__cplusplus)
3620int
3621yyparse (void)
3622#else
3623int
3624yyparse ()
3625
3626#endif
3627#endif
3628{
3629
David Greene718fda32007-08-01 03:59:32 +00003630 register int yystate;
3631 register int yyn;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003632 int yyresult;
3633 /* Number of tokens to shift before error messages enabled. */
3634 int yyerrstatus;
David Greene718fda32007-08-01 03:59:32 +00003635 /* Lookahead token as an internal (translated) token number. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003636 int yytoken = 0;
3637
3638 /* Three stacks and their tools:
3639 `yyss': related to states,
3640 `yyvs': related to semantic values,
3641 `yyls': related to locations.
3642
3643 Refer to the stacks thru separate pointers, to allow yyoverflow
3644 to reallocate them elsewhere. */
3645
3646 /* The state stack. */
David Greene718fda32007-08-01 03:59:32 +00003647 short yyssa[YYINITDEPTH];
3648 short *yyss = yyssa;
3649 register short *yyssp;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003650
3651 /* The semantic value stack. */
3652 YYSTYPE yyvsa[YYINITDEPTH];
3653 YYSTYPE *yyvs = yyvsa;
David Greene718fda32007-08-01 03:59:32 +00003654 register YYSTYPE *yyvsp;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003655
3656
3657
Chris Lattnercf3d0612007-02-13 06:04:17 +00003658#define YYPOPSTACK (yyvsp--, yyssp--)
Reid Spencere7c3c602006-11-30 06:36:44 +00003659
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003660 YYSIZE_T yystacksize = YYINITDEPTH;
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003661
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003662 /* The variables used to return semantic value and location from the
3663 action routines. */
3664 YYSTYPE yyval;
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003665
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003666
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003667 /* When reducing, the number of symbols on the RHS of the reduced
3668 rule. */
Chris Lattnercf3d0612007-02-13 06:04:17 +00003669 int yylen;
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003670
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003671 YYDPRINTF ((stderr, "Starting parse\n"));
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003672
Reid Spencere7c3c602006-11-30 06:36:44 +00003673 yystate = 0;
3674 yyerrstatus = 0;
3675 yynerrs = 0;
3676 yychar = YYEMPTY; /* Cause a token to be read. */
3677
3678 /* Initialize stack pointers.
3679 Waste one element of value and location stack
3680 so that they stay on the same level as the state stack.
3681 The wasted elements are never initialized. */
3682
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003683 yyssp = yyss;
Reid Spencere7c3c602006-11-30 06:36:44 +00003684 yyvsp = yyvs;
3685
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003686 goto yysetstate;
Reid Spencere7c3c602006-11-30 06:36:44 +00003687
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003688/*------------------------------------------------------------.
3689| yynewstate -- Push a new state, which is found in yystate. |
3690`------------------------------------------------------------*/
3691 yynewstate:
3692 /* In all cases, when you get here, the value and location stacks
3693 have just been pushed. so pushing a state here evens the stacks.
3694 */
3695 yyssp++;
Reid Spencere7c3c602006-11-30 06:36:44 +00003696
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003697 yysetstate:
3698 *yyssp = yystate;
3699
3700 if (yyss + yystacksize - 1 <= yyssp)
Reid Spencere7c3c602006-11-30 06:36:44 +00003701 {
3702 /* Get the current used size of the three stacks, in elements. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003703 YYSIZE_T yysize = yyssp - yyss + 1;
Reid Spencere7c3c602006-11-30 06:36:44 +00003704
3705#ifdef yyoverflow
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003706 {
3707 /* Give user a chance to reallocate the stack. Use copies of
3708 these so that the &'s don't force the real ones into
3709 memory. */
3710 YYSTYPE *yyvs1 = yyvs;
David Greene718fda32007-08-01 03:59:32 +00003711 short *yyss1 = yyss;
Reid Spencere7c3c602006-11-30 06:36:44 +00003712
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003713
3714 /* Each stack pointer address is followed by the size of the
3715 data in use in that stack, in bytes. This used to be a
3716 conditional around just the two extra args, but that might
3717 be undefined if yyoverflow is a macro. */
David Greene718fda32007-08-01 03:59:32 +00003718 yyoverflow ("parser stack overflow",
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003719 &yyss1, yysize * sizeof (*yyssp),
3720 &yyvs1, yysize * sizeof (*yyvsp),
3721
3722 &yystacksize);
3723
3724 yyss = yyss1;
3725 yyvs = yyvs1;
3726 }
Reid Spencere7c3c602006-11-30 06:36:44 +00003727#else /* no yyoverflow */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003728# ifndef YYSTACK_RELOCATE
David Greene718fda32007-08-01 03:59:32 +00003729 goto yyoverflowlab;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003730# else
Reid Spencere7c3c602006-11-30 06:36:44 +00003731 /* Extend the stack our own way. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003732 if (YYMAXDEPTH <= yystacksize)
David Greene718fda32007-08-01 03:59:32 +00003733 goto yyoverflowlab;
Reid Spencere7c3c602006-11-30 06:36:44 +00003734 yystacksize *= 2;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003735 if (YYMAXDEPTH < yystacksize)
Reid Spencere7c3c602006-11-30 06:36:44 +00003736 yystacksize = YYMAXDEPTH;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003737
3738 {
David Greene718fda32007-08-01 03:59:32 +00003739 short *yyss1 = yyss;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003740 union yyalloc *yyptr =
3741 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
3742 if (! yyptr)
David Greene718fda32007-08-01 03:59:32 +00003743 goto yyoverflowlab;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003744 YYSTACK_RELOCATE (yyss);
3745 YYSTACK_RELOCATE (yyvs);
3746
3747# undef YYSTACK_RELOCATE
3748 if (yyss1 != yyssa)
3749 YYSTACK_FREE (yyss1);
3750 }
3751# endif
Reid Spencere7c3c602006-11-30 06:36:44 +00003752#endif /* no yyoverflow */
3753
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003754 yyssp = yyss + yysize - 1;
3755 yyvsp = yyvs + yysize - 1;
Reid Spencere7c3c602006-11-30 06:36:44 +00003756
3757
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003758 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
3759 (unsigned long int) yystacksize));
3760
3761 if (yyss + yystacksize - 1 <= yyssp)
Reid Spencere7c3c602006-11-30 06:36:44 +00003762 YYABORT;
3763 }
3764
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003765 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
Reid Spencere7c3c602006-11-30 06:36:44 +00003766
3767 goto yybackup;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003768
3769/*-----------.
3770| yybackup. |
3771`-----------*/
3772yybackup:
Reid Spencere7c3c602006-11-30 06:36:44 +00003773
Chris Lattnercf3d0612007-02-13 06:04:17 +00003774/* Do appropriate processing given the current state. */
David Greene718fda32007-08-01 03:59:32 +00003775/* Read a lookahead token if we need one and don't already have one. */
Chris Lattnercf3d0612007-02-13 06:04:17 +00003776/* yyresume: */
Reid Spencere7c3c602006-11-30 06:36:44 +00003777
David Greene718fda32007-08-01 03:59:32 +00003778 /* First try to decide what to do without reference to lookahead token. */
Reid Spencerb7046c72007-01-29 05:41:34 +00003779
Reid Spencere7c3c602006-11-30 06:36:44 +00003780 yyn = yypact[yystate];
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003781 if (yyn == YYPACT_NINF)
Reid Spencere7c3c602006-11-30 06:36:44 +00003782 goto yydefault;
3783
David Greene718fda32007-08-01 03:59:32 +00003784 /* Not known => get a lookahead token if don't already have one. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003785
David Greene718fda32007-08-01 03:59:32 +00003786 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003787 if (yychar == YYEMPTY)
3788 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003789 YYDPRINTF ((stderr, "Reading a token: "));
Reid Spencere7c3c602006-11-30 06:36:44 +00003790 yychar = YYLEX;
3791 }
3792
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003793 if (yychar <= YYEOF)
Reid Spencere7c3c602006-11-30 06:36:44 +00003794 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003795 yychar = yytoken = YYEOF;
3796 YYDPRINTF ((stderr, "Now at end of input.\n"));
Reid Spencere7c3c602006-11-30 06:36:44 +00003797 }
3798 else
3799 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003800 yytoken = YYTRANSLATE (yychar);
David Greene718fda32007-08-01 03:59:32 +00003801 YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
Reid Spencere7c3c602006-11-30 06:36:44 +00003802 }
3803
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003804 /* If the proper action on seeing token YYTOKEN is to reduce or to
3805 detect an error, take that action. */
3806 yyn += yytoken;
3807 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
Reid Spencere7c3c602006-11-30 06:36:44 +00003808 goto yydefault;
3809 yyn = yytable[yyn];
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003810 if (yyn <= 0)
Reid Spencere7c3c602006-11-30 06:36:44 +00003811 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003812 if (yyn == 0 || yyn == YYTABLE_NINF)
Reid Spencere7c3c602006-11-30 06:36:44 +00003813 goto yyerrlab;
3814 yyn = -yyn;
3815 goto yyreduce;
3816 }
3817
3818 if (yyn == YYFINAL)
3819 YYACCEPT;
3820
David Greene718fda32007-08-01 03:59:32 +00003821 /* Shift the lookahead token. */
3822 YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
Reid Spencerb7046c72007-01-29 05:41:34 +00003823
Chris Lattnercf3d0612007-02-13 06:04:17 +00003824 /* Discard the token being shifted unless it is eof. */
Reid Spencerb7046c72007-01-29 05:41:34 +00003825 if (yychar != YYEOF)
3826 yychar = YYEMPTY;
3827
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003828 *++yyvsp = yylval;
3829
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003830
3831 /* Count tokens shifted since error; after three, turn off error
3832 status. */
3833 if (yyerrstatus)
3834 yyerrstatus--;
Chris Lattnercf3d0612007-02-13 06:04:17 +00003835
3836 yystate = yyn;
Reid Spencere7c3c602006-11-30 06:36:44 +00003837 goto yynewstate;
3838
Chris Lattner4227bdb2007-02-19 07:34:02 +00003839
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003840/*-----------------------------------------------------------.
3841| yydefault -- do the default action for the current state. |
3842`-----------------------------------------------------------*/
3843yydefault:
Reid Spencere7c3c602006-11-30 06:36:44 +00003844 yyn = yydefact[yystate];
3845 if (yyn == 0)
3846 goto yyerrlab;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003847 goto yyreduce;
Reid Spencere7c3c602006-11-30 06:36:44 +00003848
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003849
3850/*-----------------------------.
3851| yyreduce -- Do a reduction. |
3852`-----------------------------*/
Reid Spencere7c3c602006-11-30 06:36:44 +00003853yyreduce:
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003854 /* yyn is the number of a rule to reduce with. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003855 yylen = yyr2[yyn];
3856
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003857 /* If YYLEN is nonzero, implement the default value of the action:
3858 `$$ = $1'.
3859
3860 Otherwise, the following line sets YYVAL to garbage.
3861 This behavior is undocumented and Bison
3862 users should not rely upon it. Assigning to YYVAL
3863 unconditionally makes the parser a bit smaller, and it avoids a
3864 GCC warning that YYVAL may be used uninitialized. */
3865 yyval = yyvsp[1-yylen];
3866
3867
3868 YY_REDUCE_PRINT (yyn);
3869 switch (yyn)
Reid Spencere7c3c602006-11-30 06:36:44 +00003870 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003871 case 3:
David Greene718fda32007-08-01 03:59:32 +00003872#line 1917 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003873 {
David Greene718fda32007-08-01 03:59:32 +00003874 if (yyvsp[0].UIntVal > (uint32_t)INT32_MAX) // Outside of my range!
Reid Spencer950bf602007-01-26 08:19:09 +00003875 error("Value too large for type");
David Greene718fda32007-08-01 03:59:32 +00003876 yyval.SIntVal = (int32_t)yyvsp[0].UIntVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003877 ;}
3878 break;
3879
3880 case 5:
David Greene718fda32007-08-01 03:59:32 +00003881#line 1926 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003882 {
David Greene718fda32007-08-01 03:59:32 +00003883 if (yyvsp[0].UInt64Val > (uint64_t)INT64_MAX) // Outside of my range!
Reid Spencer950bf602007-01-26 08:19:09 +00003884 error("Value too large for type");
David Greene718fda32007-08-01 03:59:32 +00003885 yyval.SInt64Val = (int64_t)yyvsp[0].UInt64Val;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003886 ;}
3887 break;
3888
3889 case 26:
David Greene718fda32007-08-01 03:59:32 +00003890#line 1948 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3891 { yyval.IPred = ICmpInst::ICMP_EQ; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003892 break;
3893
3894 case 27:
David Greene718fda32007-08-01 03:59:32 +00003895#line 1948 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3896 { yyval.IPred = ICmpInst::ICMP_NE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003897 break;
3898
3899 case 28:
David Greene718fda32007-08-01 03:59:32 +00003900#line 1949 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3901 { yyval.IPred = ICmpInst::ICMP_SLT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003902 break;
3903
3904 case 29:
David Greene718fda32007-08-01 03:59:32 +00003905#line 1949 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3906 { yyval.IPred = ICmpInst::ICMP_SGT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003907 break;
3908
3909 case 30:
David Greene718fda32007-08-01 03:59:32 +00003910#line 1950 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3911 { yyval.IPred = ICmpInst::ICMP_SLE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003912 break;
3913
3914 case 31:
David Greene718fda32007-08-01 03:59:32 +00003915#line 1950 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3916 { yyval.IPred = ICmpInst::ICMP_SGE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003917 break;
3918
3919 case 32:
David Greene718fda32007-08-01 03:59:32 +00003920#line 1951 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3921 { yyval.IPred = ICmpInst::ICMP_ULT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003922 break;
3923
3924 case 33:
David Greene718fda32007-08-01 03:59:32 +00003925#line 1951 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3926 { yyval.IPred = ICmpInst::ICMP_UGT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003927 break;
3928
3929 case 34:
David Greene718fda32007-08-01 03:59:32 +00003930#line 1952 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3931 { yyval.IPred = ICmpInst::ICMP_ULE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003932 break;
3933
3934 case 35:
David Greene718fda32007-08-01 03:59:32 +00003935#line 1952 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3936 { yyval.IPred = ICmpInst::ICMP_UGE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003937 break;
3938
3939 case 36:
David Greene718fda32007-08-01 03:59:32 +00003940#line 1956 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3941 { yyval.FPred = FCmpInst::FCMP_OEQ; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003942 break;
3943
3944 case 37:
David Greene718fda32007-08-01 03:59:32 +00003945#line 1956 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3946 { yyval.FPred = FCmpInst::FCMP_ONE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003947 break;
3948
3949 case 38:
David Greene718fda32007-08-01 03:59:32 +00003950#line 1957 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3951 { yyval.FPred = FCmpInst::FCMP_OLT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003952 break;
3953
3954 case 39:
David Greene718fda32007-08-01 03:59:32 +00003955#line 1957 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3956 { yyval.FPred = FCmpInst::FCMP_OGT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003957 break;
3958
3959 case 40:
David Greene718fda32007-08-01 03:59:32 +00003960#line 1958 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3961 { yyval.FPred = FCmpInst::FCMP_OLE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003962 break;
3963
3964 case 41:
David Greene718fda32007-08-01 03:59:32 +00003965#line 1958 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3966 { yyval.FPred = FCmpInst::FCMP_OGE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003967 break;
3968
3969 case 42:
David Greene718fda32007-08-01 03:59:32 +00003970#line 1959 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3971 { yyval.FPred = FCmpInst::FCMP_ORD; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003972 break;
3973
3974 case 43:
David Greene718fda32007-08-01 03:59:32 +00003975#line 1959 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3976 { yyval.FPred = FCmpInst::FCMP_UNO; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003977 break;
3978
3979 case 44:
David Greene718fda32007-08-01 03:59:32 +00003980#line 1960 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3981 { yyval.FPred = FCmpInst::FCMP_UEQ; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003982 break;
3983
3984 case 45:
David Greene718fda32007-08-01 03:59:32 +00003985#line 1960 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3986 { yyval.FPred = FCmpInst::FCMP_UNE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003987 break;
3988
3989 case 46:
David Greene718fda32007-08-01 03:59:32 +00003990#line 1961 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3991 { yyval.FPred = FCmpInst::FCMP_ULT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003992 break;
3993
3994 case 47:
David Greene718fda32007-08-01 03:59:32 +00003995#line 1961 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3996 { yyval.FPred = FCmpInst::FCMP_UGT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003997 break;
3998
3999 case 48:
David Greene718fda32007-08-01 03:59:32 +00004000#line 1962 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4001 { yyval.FPred = FCmpInst::FCMP_ULE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004002 break;
4003
4004 case 49:
David Greene718fda32007-08-01 03:59:32 +00004005#line 1962 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4006 { yyval.FPred = FCmpInst::FCMP_UGE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004007 break;
4008
4009 case 50:
David Greene718fda32007-08-01 03:59:32 +00004010#line 1963 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4011 { yyval.FPred = FCmpInst::FCMP_TRUE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004012 break;
4013
4014 case 51:
David Greene718fda32007-08-01 03:59:32 +00004015#line 1964 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4016 { yyval.FPred = FCmpInst::FCMP_FALSE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004017 break;
4018
4019 case 81:
David Greene718fda32007-08-01 03:59:32 +00004020#line 1995 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004021 {
David Greene718fda32007-08-01 03:59:32 +00004022 yyval.StrVal = yyvsp[-1].StrVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004023 ;}
4024 break;
4025
4026 case 82:
David Greene718fda32007-08-01 03:59:32 +00004027#line 1998 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004028 {
David Greene718fda32007-08-01 03:59:32 +00004029 yyval.StrVal = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004030 ;}
4031 break;
4032
4033 case 83:
David Greene718fda32007-08-01 03:59:32 +00004034#line 2003 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4035 { yyval.Linkage = GlobalValue::InternalLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004036 break;
4037
4038 case 84:
David Greene718fda32007-08-01 03:59:32 +00004039#line 2004 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4040 { yyval.Linkage = GlobalValue::LinkOnceLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004041 break;
4042
4043 case 85:
David Greene718fda32007-08-01 03:59:32 +00004044#line 2005 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4045 { yyval.Linkage = GlobalValue::WeakLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004046 break;
4047
4048 case 86:
David Greene718fda32007-08-01 03:59:32 +00004049#line 2006 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4050 { yyval.Linkage = GlobalValue::AppendingLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004051 break;
4052
4053 case 87:
David Greene718fda32007-08-01 03:59:32 +00004054#line 2007 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4055 { yyval.Linkage = GlobalValue::DLLImportLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004056 break;
4057
4058 case 88:
David Greene718fda32007-08-01 03:59:32 +00004059#line 2008 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4060 { yyval.Linkage = GlobalValue::DLLExportLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004061 break;
4062
4063 case 89:
David Greene718fda32007-08-01 03:59:32 +00004064#line 2009 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4065 { yyval.Linkage = GlobalValue::ExternalWeakLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004066 break;
4067
4068 case 90:
David Greene718fda32007-08-01 03:59:32 +00004069#line 2010 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4070 { yyval.Linkage = GlobalValue::ExternalLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004071 break;
4072
4073 case 91:
David Greene718fda32007-08-01 03:59:32 +00004074#line 2014 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4075 { yyval.UIntVal = lastCallingConv = OldCallingConv::C; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004076 break;
4077
Reid Spencere59f4932007-04-16 03:05:01 +00004078 case 92:
David Greene718fda32007-08-01 03:59:32 +00004079#line 2015 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4080 { yyval.UIntVal = lastCallingConv = OldCallingConv::C; ;}
Reid Spencere59f4932007-04-16 03:05:01 +00004081 break;
4082
4083 case 93:
David Greene718fda32007-08-01 03:59:32 +00004084#line 2016 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4085 { yyval.UIntVal = lastCallingConv = OldCallingConv::CSRet; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004086 break;
4087
4088 case 94:
David Greene718fda32007-08-01 03:59:32 +00004089#line 2017 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4090 { yyval.UIntVal = lastCallingConv = OldCallingConv::Fast; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004091 break;
4092
4093 case 95:
David Greene718fda32007-08-01 03:59:32 +00004094#line 2018 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4095 { yyval.UIntVal = lastCallingConv = OldCallingConv::Cold; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004096 break;
4097
4098 case 96:
David Greene718fda32007-08-01 03:59:32 +00004099#line 2019 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4100 { yyval.UIntVal = lastCallingConv = OldCallingConv::X86_StdCall; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004101 break;
4102
4103 case 97:
David Greene718fda32007-08-01 03:59:32 +00004104#line 2020 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4105 { yyval.UIntVal = lastCallingConv = OldCallingConv::X86_FastCall; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004106 break;
4107
4108 case 98:
David Greene718fda32007-08-01 03:59:32 +00004109#line 2021 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004110 {
David Greene718fda32007-08-01 03:59:32 +00004111 if ((unsigned)yyvsp[0].UInt64Val != yyvsp[0].UInt64Val)
Reid Spencer950bf602007-01-26 08:19:09 +00004112 error("Calling conv too large");
David Greene718fda32007-08-01 03:59:32 +00004113 yyval.UIntVal = lastCallingConv = yyvsp[0].UInt64Val;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004114 ;}
4115 break;
4116
4117 case 99:
David Greene718fda32007-08-01 03:59:32 +00004118#line 2031 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4119 { yyval.UIntVal = 0; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004120 break;
4121
4122 case 100:
David Greene718fda32007-08-01 03:59:32 +00004123#line 2032 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004124 {
David Greene718fda32007-08-01 03:59:32 +00004125 yyval.UIntVal = yyvsp[0].UInt64Val;
4126 if (yyval.UIntVal != 0 && !isPowerOf2_32(yyval.UIntVal))
Reid Spencer950bf602007-01-26 08:19:09 +00004127 error("Alignment must be a power of two");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004128 ;}
4129 break;
4130
4131 case 101:
David Greene718fda32007-08-01 03:59:32 +00004132#line 2040 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4133 { yyval.UIntVal = 0; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004134 break;
4135
4136 case 102:
David Greene718fda32007-08-01 03:59:32 +00004137#line 2041 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004138 {
David Greene718fda32007-08-01 03:59:32 +00004139 yyval.UIntVal = yyvsp[0].UInt64Val;
4140 if (yyval.UIntVal != 0 && !isPowerOf2_32(yyval.UIntVal))
Reid Spencer950bf602007-01-26 08:19:09 +00004141 error("Alignment must be a power of two");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004142 ;}
4143 break;
4144
4145 case 103:
David Greene718fda32007-08-01 03:59:32 +00004146#line 2049 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004147 {
David Greene718fda32007-08-01 03:59:32 +00004148 for (unsigned i = 0, e = strlen(yyvsp[0].StrVal); i != e; ++i)
4149 if (yyvsp[0].StrVal[i] == '"' || yyvsp[0].StrVal[i] == '\\')
Reid Spencer950bf602007-01-26 08:19:09 +00004150 error("Invalid character in section name");
David Greene718fda32007-08-01 03:59:32 +00004151 yyval.StrVal = yyvsp[0].StrVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004152 ;}
4153 break;
4154
4155 case 104:
David Greene718fda32007-08-01 03:59:32 +00004156#line 2058 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4157 { yyval.StrVal = 0; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004158 break;
4159
4160 case 105:
David Greene718fda32007-08-01 03:59:32 +00004161#line 2059 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4162 { yyval.StrVal = yyvsp[0].StrVal; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004163 break;
4164
4165 case 106:
David Greene718fda32007-08-01 03:59:32 +00004166#line 2066 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004167 {;}
4168 break;
4169
Reid Spencere59f4932007-04-16 03:05:01 +00004170 case 107:
David Greene718fda32007-08-01 03:59:32 +00004171#line 2067 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencere59f4932007-04-16 03:05:01 +00004172 {;}
4173 break;
4174
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004175 case 108:
David Greene718fda32007-08-01 03:59:32 +00004176#line 2071 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004177 {
David Greene718fda32007-08-01 03:59:32 +00004178 CurGV->setSection(yyvsp[0].StrVal);
4179 free(yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004180 ;}
4181 break;
4182
4183 case 109:
David Greene718fda32007-08-01 03:59:32 +00004184#line 2075 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004185 {
David Greene718fda32007-08-01 03:59:32 +00004186 if (yyvsp[0].UInt64Val != 0 && !isPowerOf2_32(yyvsp[0].UInt64Val))
Reid Spencer950bf602007-01-26 08:19:09 +00004187 error("Alignment must be a power of two");
David Greene718fda32007-08-01 03:59:32 +00004188 CurGV->setAlignment(yyvsp[0].UInt64Val);
Reid Spencer950bf602007-01-26 08:19:09 +00004189
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004190 ;}
4191 break;
4192
4193 case 111:
David Greene718fda32007-08-01 03:59:32 +00004194#line 2092 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004195 {
David Greene718fda32007-08-01 03:59:32 +00004196 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
4197 yyval.TypeVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004198 ;}
4199 break;
4200
4201 case 113:
David Greene718fda32007-08-01 03:59:32 +00004202#line 2100 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004203 {
David Greene718fda32007-08-01 03:59:32 +00004204 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
4205 yyval.TypeVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004206 ;}
4207 break;
4208
4209 case 114:
David Greene718fda32007-08-01 03:59:32 +00004210#line 2107 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004211 {
Reid Spencer950bf602007-01-26 08:19:09 +00004212 if (!UpRefs.empty())
David Greene718fda32007-08-01 03:59:32 +00004213 error("Invalid upreference in type: " + (*yyvsp[0].TypeVal.PAT)->getDescription());
4214 yyval.TypeVal = yyvsp[0].TypeVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004215 ;}
4216 break;
4217
4218 case 127:
David Greene718fda32007-08-01 03:59:32 +00004219#line 2121 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004220 {
David Greene718fda32007-08-01 03:59:32 +00004221 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
4222 yyval.TypeVal.S.copy(yyvsp[0].PrimType.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004223 ;}
4224 break;
4225
4226 case 128:
David Greene718fda32007-08-01 03:59:32 +00004227#line 2125 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004228 {
David Greene718fda32007-08-01 03:59:32 +00004229 yyval.TypeVal.PAT = new PATypeHolder(OpaqueType::get());
4230 yyval.TypeVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004231 ;}
4232 break;
4233
4234 case 129:
David Greene718fda32007-08-01 03:59:32 +00004235#line 2129 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004236 { // Named types are also simple types...
David Greene718fda32007-08-01 03:59:32 +00004237 yyval.TypeVal.S.copy(getTypeSign(yyvsp[0].ValIDVal));
4238 const Type* tmp = getType(yyvsp[0].ValIDVal);
4239 yyval.TypeVal.PAT = new PATypeHolder(tmp);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004240 ;}
4241 break;
4242
4243 case 130:
David Greene718fda32007-08-01 03:59:32 +00004244#line 2134 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004245 { // Type UpReference
David Greene718fda32007-08-01 03:59:32 +00004246 if (yyvsp[0].UInt64Val > (uint64_t)~0U)
Reid Spencer950bf602007-01-26 08:19:09 +00004247 error("Value out of range");
4248 OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder
David Greene718fda32007-08-01 03:59:32 +00004249 UpRefs.push_back(UpRefRecord((unsigned)yyvsp[0].UInt64Val, OT)); // Add to vector...
4250 yyval.TypeVal.PAT = new PATypeHolder(OT);
4251 yyval.TypeVal.S.makeSignless();
Reid Spencer950bf602007-01-26 08:19:09 +00004252 UR_OUT("New Upreference!\n");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004253 ;}
4254 break;
4255
4256 case 131:
David Greene718fda32007-08-01 03:59:32 +00004257#line 2143 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004258 { // Function derived type?
David Greene718fda32007-08-01 03:59:32 +00004259 yyval.TypeVal.S.makeComposite(yyvsp[-3].TypeVal.S);
Reid Spencer950bf602007-01-26 08:19:09 +00004260 std::vector<const Type*> Params;
David Greene718fda32007-08-01 03:59:32 +00004261 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-1].TypeList->begin(),
4262 E = yyvsp[-1].TypeList->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004263 Params.push_back(I->PAT->get());
David Greene718fda32007-08-01 03:59:32 +00004264 yyval.TypeVal.S.add(I->S);
Reid Spencer52402b02007-01-02 05:45:11 +00004265 }
Reid Spencer950bf602007-01-26 08:19:09 +00004266 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
4267 if (isVarArg) Params.pop_back();
4268
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004269 ParamAttrsList *PAL = 0;
4270 if (lastCallingConv == OldCallingConv::CSRet) {
4271 ParamAttrsVector Attrs;
4272 ParamAttrsWithIndex PAWI;
4273 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
4274 Attrs.push_back(PAWI);
4275 PAL = ParamAttrsList::get(Attrs);
4276 }
4277
Reid Spencer7b5d4662007-04-09 06:16:21 +00004278 const FunctionType *FTy =
David Greene718fda32007-08-01 03:59:32 +00004279 FunctionType::get(yyvsp[-3].TypeVal.PAT->get(), Params, isVarArg, PAL);
Reid Spencer7b5d4662007-04-09 06:16:21 +00004280
David Greene718fda32007-08-01 03:59:32 +00004281 yyval.TypeVal.PAT = new PATypeHolder( HandleUpRefs(FTy, yyval.TypeVal.S) );
4282 delete yyvsp[-3].TypeVal.PAT; // Delete the return type handle
4283 delete yyvsp[-1].TypeList; // Delete the argument list
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004284 ;}
4285 break;
4286
4287 case 132:
David Greene718fda32007-08-01 03:59:32 +00004288#line 2170 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004289 { // Sized array type?
David Greene718fda32007-08-01 03:59:32 +00004290 yyval.TypeVal.S.makeComposite(yyvsp[-1].TypeVal.S);
4291 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(ArrayType::get(yyvsp[-1].TypeVal.PAT->get(),
4292 (unsigned)yyvsp[-3].UInt64Val), yyval.TypeVal.S));
4293 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004294 ;}
4295 break;
4296
4297 case 133:
David Greene718fda32007-08-01 03:59:32 +00004298#line 2176 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004299 { // Vector type?
David Greene718fda32007-08-01 03:59:32 +00004300 const llvm::Type* ElemTy = yyvsp[-1].TypeVal.PAT->get();
4301 if ((unsigned)yyvsp[-3].UInt64Val != yyvsp[-3].UInt64Val)
Reid Spencerbb1fd572007-03-21 17:15:50 +00004302 error("Unsigned result not equal to signed result");
4303 if (!(ElemTy->isInteger() || ElemTy->isFloatingPoint()))
4304 error("Elements of a VectorType must be integer or floating point");
David Greene718fda32007-08-01 03:59:32 +00004305 if (!isPowerOf2_32(yyvsp[-3].UInt64Val))
Reid Spencerbb1fd572007-03-21 17:15:50 +00004306 error("VectorType length should be a power of 2");
David Greene718fda32007-08-01 03:59:32 +00004307 yyval.TypeVal.S.makeComposite(yyvsp[-1].TypeVal.S);
4308 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(VectorType::get(ElemTy,
4309 (unsigned)yyvsp[-3].UInt64Val), yyval.TypeVal.S));
4310 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004311 ;}
4312 break;
4313
4314 case 134:
David Greene718fda32007-08-01 03:59:32 +00004315#line 2189 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004316 { // Structure type?
Reid Spencer950bf602007-01-26 08:19:09 +00004317 std::vector<const Type*> Elements;
David Greene718fda32007-08-01 03:59:32 +00004318 yyval.TypeVal.S.makeComposite();
4319 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-1].TypeList->begin(),
4320 E = yyvsp[-1].TypeList->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004321 Elements.push_back(I->PAT->get());
David Greene718fda32007-08-01 03:59:32 +00004322 yyval.TypeVal.S.add(I->S);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004323 }
David Greene718fda32007-08-01 03:59:32 +00004324 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements), yyval.TypeVal.S));
4325 delete yyvsp[-1].TypeList;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004326 ;}
4327 break;
4328
4329 case 135:
David Greene718fda32007-08-01 03:59:32 +00004330#line 2200 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004331 { // Empty structure type?
David Greene718fda32007-08-01 03:59:32 +00004332 yyval.TypeVal.PAT = new PATypeHolder(StructType::get(std::vector<const Type*>()));
4333 yyval.TypeVal.S.makeComposite();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004334 ;}
4335 break;
4336
4337 case 136:
David Greene718fda32007-08-01 03:59:32 +00004338#line 2204 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004339 { // Packed Structure type?
David Greene718fda32007-08-01 03:59:32 +00004340 yyval.TypeVal.S.makeComposite();
Reid Spencer950bf602007-01-26 08:19:09 +00004341 std::vector<const Type*> Elements;
David Greene718fda32007-08-01 03:59:32 +00004342 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-2].TypeList->begin(),
4343 E = yyvsp[-2].TypeList->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004344 Elements.push_back(I->PAT->get());
David Greene718fda32007-08-01 03:59:32 +00004345 yyval.TypeVal.S.add(I->S);
Reid Spencered96d1e2007-02-08 09:08:52 +00004346 delete I->PAT;
Reid Spencer52402b02007-01-02 05:45:11 +00004347 }
David Greene718fda32007-08-01 03:59:32 +00004348 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements, true),
4349 yyval.TypeVal.S));
4350 delete yyvsp[-2].TypeList;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004351 ;}
4352 break;
4353
4354 case 137:
David Greene718fda32007-08-01 03:59:32 +00004355#line 2217 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004356 { // Empty packed structure type?
David Greene718fda32007-08-01 03:59:32 +00004357 yyval.TypeVal.PAT = new PATypeHolder(StructType::get(std::vector<const Type*>(),true));
4358 yyval.TypeVal.S.makeComposite();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004359 ;}
4360 break;
4361
4362 case 138:
David Greene718fda32007-08-01 03:59:32 +00004363#line 2221 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004364 { // Pointer type?
David Greene718fda32007-08-01 03:59:32 +00004365 if (yyvsp[-1].TypeVal.PAT->get() == Type::LabelTy)
Reid Spencer950bf602007-01-26 08:19:09 +00004366 error("Cannot form a pointer to a basic block");
David Greene718fda32007-08-01 03:59:32 +00004367 yyval.TypeVal.S.makeComposite(yyvsp[-1].TypeVal.S);
4368 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(PointerType::get(yyvsp[-1].TypeVal.PAT->get()),
4369 yyval.TypeVal.S));
4370 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004371 ;}
4372 break;
4373
4374 case 139:
David Greene718fda32007-08-01 03:59:32 +00004375#line 2235 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004376 {
David Greene718fda32007-08-01 03:59:32 +00004377 yyval.TypeList = new std::list<PATypeInfo>();
4378 yyval.TypeList->push_back(yyvsp[0].TypeVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004379 ;}
4380 break;
4381
4382 case 140:
David Greene718fda32007-08-01 03:59:32 +00004383#line 2239 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004384 {
David Greene718fda32007-08-01 03:59:32 +00004385 (yyval.TypeList=yyvsp[-2].TypeList)->push_back(yyvsp[0].TypeVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004386 ;}
4387 break;
4388
4389 case 142:
David Greene718fda32007-08-01 03:59:32 +00004390#line 2247 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004391 {
Reid Spencer950bf602007-01-26 08:19:09 +00004392 PATypeInfo VoidTI;
Reid Spencered96d1e2007-02-08 09:08:52 +00004393 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004394 VoidTI.S.makeSignless();
David Greene718fda32007-08-01 03:59:32 +00004395 (yyval.TypeList=yyvsp[-2].TypeList)->push_back(VoidTI);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004396 ;}
4397 break;
4398
4399 case 143:
David Greene718fda32007-08-01 03:59:32 +00004400#line 2253 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004401 {
David Greene718fda32007-08-01 03:59:32 +00004402 yyval.TypeList = new std::list<PATypeInfo>();
Reid Spencer950bf602007-01-26 08:19:09 +00004403 PATypeInfo VoidTI;
Reid Spencered96d1e2007-02-08 09:08:52 +00004404 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004405 VoidTI.S.makeSignless();
David Greene718fda32007-08-01 03:59:32 +00004406 yyval.TypeList->push_back(VoidTI);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004407 ;}
4408 break;
4409
4410 case 144:
David Greene718fda32007-08-01 03:59:32 +00004411#line 2260 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004412 {
David Greene718fda32007-08-01 03:59:32 +00004413 yyval.TypeList = new std::list<PATypeInfo>();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004414 ;}
4415 break;
4416
4417 case 145:
David Greene718fda32007-08-01 03:59:32 +00004418#line 2272 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004419 { // Nonempty unsized arr
David Greene718fda32007-08-01 03:59:32 +00004420 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-3].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004421 if (ATy == 0)
4422 error("Cannot make array constant with type: '" +
David Greene718fda32007-08-01 03:59:32 +00004423 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004424 const Type *ETy = ATy->getElementType();
4425 int NumElements = ATy->getNumElements();
4426
4427 // Verify that we have the correct size...
David Greene718fda32007-08-01 03:59:32 +00004428 if (NumElements != -1 && NumElements != (int)yyvsp[-1].ConstVector->size())
Reid Spencer950bf602007-01-26 08:19:09 +00004429 error("Type mismatch: constant sized array initialized with " +
David Greene718fda32007-08-01 03:59:32 +00004430 utostr(yyvsp[-1].ConstVector->size()) + " arguments, but has size of " +
Reid Spencer950bf602007-01-26 08:19:09 +00004431 itostr(NumElements) + "");
4432
4433 // Verify all elements are correct type!
4434 std::vector<Constant*> Elems;
David Greene718fda32007-08-01 03:59:32 +00004435 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
4436 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004437 const Type* ValTy = C->getType();
4438 if (ETy != ValTy)
4439 error("Element #" + utostr(i) + " is not of type '" +
4440 ETy->getDescription() +"' as required!\nIt is of type '"+
4441 ValTy->getDescription() + "'");
4442 Elems.push_back(C);
4443 }
David Greene718fda32007-08-01 03:59:32 +00004444 yyval.ConstVal.C = ConstantArray::get(ATy, Elems);
4445 yyval.ConstVal.S.copy(yyvsp[-3].TypeVal.S);
4446 delete yyvsp[-3].TypeVal.PAT;
4447 delete yyvsp[-1].ConstVector;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004448 ;}
4449 break;
4450
4451 case 146:
David Greene718fda32007-08-01 03:59:32 +00004452#line 2302 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004453 {
David Greene718fda32007-08-01 03:59:32 +00004454 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-2].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004455 if (ATy == 0)
4456 error("Cannot make array constant with type: '" +
David Greene718fda32007-08-01 03:59:32 +00004457 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004458 int NumElements = ATy->getNumElements();
4459 if (NumElements != -1 && NumElements != 0)
4460 error("Type mismatch: constant sized array initialized with 0"
4461 " arguments, but has size of " + itostr(NumElements) +"");
David Greene718fda32007-08-01 03:59:32 +00004462 yyval.ConstVal.C = ConstantArray::get(ATy, std::vector<Constant*>());
4463 yyval.ConstVal.S.copy(yyvsp[-2].TypeVal.S);
4464 delete yyvsp[-2].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004465 ;}
4466 break;
4467
4468 case 147:
David Greene718fda32007-08-01 03:59:32 +00004469#line 2315 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004470 {
David Greene718fda32007-08-01 03:59:32 +00004471 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-2].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004472 if (ATy == 0)
4473 error("Cannot make array constant with type: '" +
David Greene718fda32007-08-01 03:59:32 +00004474 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004475 int NumElements = ATy->getNumElements();
4476 const Type *ETy = dyn_cast<IntegerType>(ATy->getElementType());
4477 if (!ETy || cast<IntegerType>(ETy)->getBitWidth() != 8)
4478 error("String arrays require type i8, not '" + ETy->getDescription() +
4479 "'");
David Greene718fda32007-08-01 03:59:32 +00004480 char *EndStr = UnEscapeLexed(yyvsp[0].StrVal, true);
4481 if (NumElements != -1 && NumElements != (EndStr-yyvsp[0].StrVal))
Reid Spencer950bf602007-01-26 08:19:09 +00004482 error("Can't build string constant of size " +
David Greene718fda32007-08-01 03:59:32 +00004483 itostr((int)(EndStr-yyvsp[0].StrVal)) + " when array has size " +
Reid Spencer950bf602007-01-26 08:19:09 +00004484 itostr(NumElements) + "");
4485 std::vector<Constant*> Vals;
David Greene718fda32007-08-01 03:59:32 +00004486 for (char *C = (char *)yyvsp[0].StrVal; C != (char *)EndStr; ++C)
Reid Spencer950bf602007-01-26 08:19:09 +00004487 Vals.push_back(ConstantInt::get(ETy, *C));
David Greene718fda32007-08-01 03:59:32 +00004488 free(yyvsp[0].StrVal);
4489 yyval.ConstVal.C = ConstantArray::get(ATy, Vals);
4490 yyval.ConstVal.S.copy(yyvsp[-2].TypeVal.S);
4491 delete yyvsp[-2].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004492 ;}
4493 break;
4494
4495 case 148:
David Greene718fda32007-08-01 03:59:32 +00004496#line 2338 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004497 { // Nonempty unsized arr
David Greene718fda32007-08-01 03:59:32 +00004498 const VectorType *PTy = dyn_cast<VectorType>(yyvsp[-3].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004499 if (PTy == 0)
4500 error("Cannot make packed constant with type: '" +
David Greene718fda32007-08-01 03:59:32 +00004501 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004502 const Type *ETy = PTy->getElementType();
4503 int NumElements = PTy->getNumElements();
4504 // Verify that we have the correct size...
David Greene718fda32007-08-01 03:59:32 +00004505 if (NumElements != -1 && NumElements != (int)yyvsp[-1].ConstVector->size())
Reid Spencer950bf602007-01-26 08:19:09 +00004506 error("Type mismatch: constant sized packed initialized with " +
David Greene718fda32007-08-01 03:59:32 +00004507 utostr(yyvsp[-1].ConstVector->size()) + " arguments, but has size of " +
Reid Spencer950bf602007-01-26 08:19:09 +00004508 itostr(NumElements) + "");
4509 // Verify all elements are correct type!
4510 std::vector<Constant*> Elems;
David Greene718fda32007-08-01 03:59:32 +00004511 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
4512 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004513 const Type* ValTy = C->getType();
4514 if (ETy != ValTy)
4515 error("Element #" + utostr(i) + " is not of type '" +
4516 ETy->getDescription() +"' as required!\nIt is of type '"+
4517 ValTy->getDescription() + "'");
4518 Elems.push_back(C);
4519 }
David Greene718fda32007-08-01 03:59:32 +00004520 yyval.ConstVal.C = ConstantVector::get(PTy, Elems);
4521 yyval.ConstVal.S.copy(yyvsp[-3].TypeVal.S);
4522 delete yyvsp[-3].TypeVal.PAT;
4523 delete yyvsp[-1].ConstVector;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004524 ;}
4525 break;
4526
4527 case 149:
David Greene718fda32007-08-01 03:59:32 +00004528#line 2366 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004529 {
David Greene718fda32007-08-01 03:59:32 +00004530 const StructType *STy = dyn_cast<StructType>(yyvsp[-3].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004531 if (STy == 0)
4532 error("Cannot make struct constant with type: '" +
David Greene718fda32007-08-01 03:59:32 +00004533 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
4534 if (yyvsp[-1].ConstVector->size() != STy->getNumContainedTypes())
Reid Spencer950bf602007-01-26 08:19:09 +00004535 error("Illegal number of initializers for structure type");
4536
4537 // Check to ensure that constants are compatible with the type initializer!
4538 std::vector<Constant*> Fields;
David Greene718fda32007-08-01 03:59:32 +00004539 for (unsigned i = 0, e = yyvsp[-1].ConstVector->size(); i != e; ++i) {
4540 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004541 if (C->getType() != STy->getElementType(i))
4542 error("Expected type '" + STy->getElementType(i)->getDescription() +
4543 "' for element #" + utostr(i) + " of structure initializer");
4544 Fields.push_back(C);
4545 }
David Greene718fda32007-08-01 03:59:32 +00004546 yyval.ConstVal.C = ConstantStruct::get(STy, Fields);
4547 yyval.ConstVal.S.copy(yyvsp[-3].TypeVal.S);
4548 delete yyvsp[-3].TypeVal.PAT;
4549 delete yyvsp[-1].ConstVector;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004550 ;}
4551 break;
4552
4553 case 150:
David Greene718fda32007-08-01 03:59:32 +00004554#line 2388 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004555 {
David Greene718fda32007-08-01 03:59:32 +00004556 const StructType *STy = dyn_cast<StructType>(yyvsp[-2].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004557 if (STy == 0)
4558 error("Cannot make struct constant with type: '" +
David Greene718fda32007-08-01 03:59:32 +00004559 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004560 if (STy->getNumContainedTypes() != 0)
4561 error("Illegal number of initializers for structure type");
David Greene718fda32007-08-01 03:59:32 +00004562 yyval.ConstVal.C = ConstantStruct::get(STy, std::vector<Constant*>());
4563 yyval.ConstVal.S.copy(yyvsp[-2].TypeVal.S);
4564 delete yyvsp[-2].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004565 ;}
4566 break;
4567
4568 case 151:
David Greene718fda32007-08-01 03:59:32 +00004569#line 2399 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004570 {
David Greene718fda32007-08-01 03:59:32 +00004571 const StructType *STy = dyn_cast<StructType>(yyvsp[-5].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004572 if (STy == 0)
4573 error("Cannot make packed struct constant with type: '" +
David Greene718fda32007-08-01 03:59:32 +00004574 yyvsp[-5].TypeVal.PAT->get()->getDescription() + "'");
4575 if (yyvsp[-2].ConstVector->size() != STy->getNumContainedTypes())
Reid Spencer950bf602007-01-26 08:19:09 +00004576 error("Illegal number of initializers for packed structure type");
4577
4578 // Check to ensure that constants are compatible with the type initializer!
4579 std::vector<Constant*> Fields;
David Greene718fda32007-08-01 03:59:32 +00004580 for (unsigned i = 0, e = yyvsp[-2].ConstVector->size(); i != e; ++i) {
4581 Constant *C = (*yyvsp[-2].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004582 if (C->getType() != STy->getElementType(i))
4583 error("Expected type '" + STy->getElementType(i)->getDescription() +
4584 "' for element #" + utostr(i) + " of packed struct initializer");
4585 Fields.push_back(C);
4586 }
David Greene718fda32007-08-01 03:59:32 +00004587 yyval.ConstVal.C = ConstantStruct::get(STy, Fields);
4588 yyval.ConstVal.S.copy(yyvsp[-5].TypeVal.S);
4589 delete yyvsp[-5].TypeVal.PAT;
4590 delete yyvsp[-2].ConstVector;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004591 ;}
4592 break;
4593
4594 case 152:
David Greene718fda32007-08-01 03:59:32 +00004595#line 2421 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004596 {
David Greene718fda32007-08-01 03:59:32 +00004597 const StructType *STy = dyn_cast<StructType>(yyvsp[-4].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004598 if (STy == 0)
4599 error("Cannot make packed struct constant with type: '" +
David Greene718fda32007-08-01 03:59:32 +00004600 yyvsp[-4].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004601 if (STy->getNumContainedTypes() != 0)
4602 error("Illegal number of initializers for packed structure type");
David Greene718fda32007-08-01 03:59:32 +00004603 yyval.ConstVal.C = ConstantStruct::get(STy, std::vector<Constant*>());
4604 yyval.ConstVal.S.copy(yyvsp[-4].TypeVal.S);
4605 delete yyvsp[-4].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004606 ;}
4607 break;
4608
4609 case 153:
David Greene718fda32007-08-01 03:59:32 +00004610#line 2432 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004611 {
David Greene718fda32007-08-01 03:59:32 +00004612 const PointerType *PTy = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004613 if (PTy == 0)
4614 error("Cannot make null pointer constant with type: '" +
David Greene718fda32007-08-01 03:59:32 +00004615 yyvsp[-1].TypeVal.PAT->get()->getDescription() + "'");
4616 yyval.ConstVal.C = ConstantPointerNull::get(PTy);
4617 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4618 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004619 ;}
4620 break;
4621
4622 case 154:
David Greene718fda32007-08-01 03:59:32 +00004623#line 2441 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004624 {
David Greene718fda32007-08-01 03:59:32 +00004625 yyval.ConstVal.C = UndefValue::get(yyvsp[-1].TypeVal.PAT->get());
4626 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4627 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004628 ;}
4629 break;
4630
4631 case 155:
David Greene718fda32007-08-01 03:59:32 +00004632#line 2446 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004633 {
David Greene718fda32007-08-01 03:59:32 +00004634 const PointerType *Ty = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004635 if (Ty == 0)
4636 error("Global const reference must be a pointer type, not" +
David Greene718fda32007-08-01 03:59:32 +00004637 yyvsp[-1].TypeVal.PAT->get()->getDescription());
Reid Spencer950bf602007-01-26 08:19:09 +00004638
4639 // ConstExprs can exist in the body of a function, thus creating
4640 // GlobalValues whenever they refer to a variable. Because we are in
4641 // the context of a function, getExistingValue will search the functions
4642 // symbol table instead of the module symbol table for the global symbol,
4643 // which throws things all off. To get around this, we just tell
4644 // getExistingValue that we are at global scope here.
4645 //
4646 Function *SavedCurFn = CurFun.CurrentFunction;
4647 CurFun.CurrentFunction = 0;
David Greene718fda32007-08-01 03:59:32 +00004648 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
4649 Value *V = getExistingValue(Ty, yyvsp[0].ValIDVal);
Reid Spencer950bf602007-01-26 08:19:09 +00004650 CurFun.CurrentFunction = SavedCurFn;
4651
4652 // If this is an initializer for a constant pointer, which is referencing a
4653 // (currently) undefined variable, create a stub now that shall be replaced
4654 // in the future with the right type of variable.
4655 //
4656 if (V == 0) {
4657 assert(isa<PointerType>(Ty) && "Globals may only be used as pointers");
4658 const PointerType *PT = cast<PointerType>(Ty);
4659
4660 // First check to see if the forward references value is already created!
4661 PerModuleInfo::GlobalRefsType::iterator I =
David Greene718fda32007-08-01 03:59:32 +00004662 CurModule.GlobalRefs.find(std::make_pair(PT, yyvsp[0].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00004663
4664 if (I != CurModule.GlobalRefs.end()) {
4665 V = I->second; // Placeholder already exists, use it...
David Greene718fda32007-08-01 03:59:32 +00004666 yyvsp[0].ValIDVal.destroy();
Reid Spencer950bf602007-01-26 08:19:09 +00004667 } else {
4668 std::string Name;
David Greene718fda32007-08-01 03:59:32 +00004669 if (yyvsp[0].ValIDVal.Type == ValID::NameVal) Name = yyvsp[0].ValIDVal.Name;
Reid Spencer950bf602007-01-26 08:19:09 +00004670
4671 // Create the forward referenced global.
4672 GlobalValue *GV;
4673 if (const FunctionType *FTy =
4674 dyn_cast<FunctionType>(PT->getElementType())) {
4675 GV = new Function(FTy, GlobalValue::ExternalLinkage, Name,
4676 CurModule.CurrentModule);
4677 } else {
4678 GV = new GlobalVariable(PT->getElementType(), false,
4679 GlobalValue::ExternalLinkage, 0,
4680 Name, CurModule.CurrentModule);
4681 }
4682
4683 // Keep track of the fact that we have a forward ref to recycle it
David Greene718fda32007-08-01 03:59:32 +00004684 CurModule.GlobalRefs.insert(std::make_pair(std::make_pair(PT, yyvsp[0].ValIDVal), GV));
Reid Spencer950bf602007-01-26 08:19:09 +00004685 V = GV;
4686 }
4687 }
David Greene718fda32007-08-01 03:59:32 +00004688 yyval.ConstVal.C = cast<GlobalValue>(V);
4689 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4690 delete yyvsp[-1].TypeVal.PAT; // Free the type handle
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004691 ;}
4692 break;
4693
4694 case 156:
David Greene718fda32007-08-01 03:59:32 +00004695#line 2505 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004696 {
David Greene718fda32007-08-01 03:59:32 +00004697 if (yyvsp[-1].TypeVal.PAT->get() != yyvsp[0].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004698 error("Mismatched types for constant expression");
David Greene718fda32007-08-01 03:59:32 +00004699 yyval.ConstVal = yyvsp[0].ConstVal;
4700 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4701 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004702 ;}
4703 break;
4704
4705 case 157:
David Greene718fda32007-08-01 03:59:32 +00004706#line 2512 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004707 {
David Greene718fda32007-08-01 03:59:32 +00004708 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00004709 if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
4710 error("Cannot create a null initialized value of this type");
David Greene718fda32007-08-01 03:59:32 +00004711 yyval.ConstVal.C = Constant::getNullValue(Ty);
4712 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4713 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004714 ;}
4715 break;
4716
4717 case 158:
David Greene718fda32007-08-01 03:59:32 +00004718#line 2520 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004719 { // integral constants
David Greene718fda32007-08-01 03:59:32 +00004720 const Type *Ty = yyvsp[-1].PrimType.T;
4721 if (!ConstantInt::isValueValidForType(Ty, yyvsp[0].SInt64Val))
Reid Spencer950bf602007-01-26 08:19:09 +00004722 error("Constant value doesn't fit in type");
David Greene718fda32007-08-01 03:59:32 +00004723 yyval.ConstVal.C = ConstantInt::get(Ty, yyvsp[0].SInt64Val);
4724 yyval.ConstVal.S.makeSigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004725 ;}
4726 break;
4727
4728 case 159:
David Greene718fda32007-08-01 03:59:32 +00004729#line 2527 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004730 { // integral constants
David Greene718fda32007-08-01 03:59:32 +00004731 const Type *Ty = yyvsp[-1].PrimType.T;
4732 if (!ConstantInt::isValueValidForType(Ty, yyvsp[0].UInt64Val))
Reid Spencer950bf602007-01-26 08:19:09 +00004733 error("Constant value doesn't fit in type");
David Greene718fda32007-08-01 03:59:32 +00004734 yyval.ConstVal.C = ConstantInt::get(Ty, yyvsp[0].UInt64Val);
4735 yyval.ConstVal.S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004736 ;}
4737 break;
4738
4739 case 160:
David Greene718fda32007-08-01 03:59:32 +00004740#line 2534 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004741 { // Boolean constants
David Greene718fda32007-08-01 03:59:32 +00004742 yyval.ConstVal.C = ConstantInt::get(Type::Int1Ty, true);
4743 yyval.ConstVal.S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004744 ;}
4745 break;
4746
4747 case 161:
David Greene718fda32007-08-01 03:59:32 +00004748#line 2538 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004749 { // Boolean constants
David Greene718fda32007-08-01 03:59:32 +00004750 yyval.ConstVal.C = ConstantInt::get(Type::Int1Ty, false);
4751 yyval.ConstVal.S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004752 ;}
4753 break;
4754
4755 case 162:
David Greene718fda32007-08-01 03:59:32 +00004756#line 2542 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004757 { // Float & Double constants
David Greene718fda32007-08-01 03:59:32 +00004758 if (!ConstantFP::isValueValidForType(yyvsp[-1].PrimType.T, yyvsp[0].FPVal))
Reid Spencer950bf602007-01-26 08:19:09 +00004759 error("Floating point constant invalid for type");
David Greene718fda32007-08-01 03:59:32 +00004760 yyval.ConstVal.C = ConstantFP::get(yyvsp[-1].PrimType.T, yyvsp[0].FPVal);
4761 yyval.ConstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004762 ;}
4763 break;
4764
4765 case 163:
David Greene718fda32007-08-01 03:59:32 +00004766#line 2551 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004767 {
David Greene718fda32007-08-01 03:59:32 +00004768 const Type* SrcTy = yyvsp[-3].ConstVal.C->getType();
4769 const Type* DstTy = yyvsp[-1].TypeVal.PAT->get();
4770 Signedness SrcSign(yyvsp[-3].ConstVal.S);
4771 Signedness DstSign(yyvsp[-1].TypeVal.S);
Reid Spencer950bf602007-01-26 08:19:09 +00004772 if (!SrcTy->isFirstClassType())
4773 error("cast constant expression from a non-primitive type: '" +
4774 SrcTy->getDescription() + "'");
4775 if (!DstTy->isFirstClassType())
4776 error("cast constant expression to a non-primitive type: '" +
4777 DstTy->getDescription() + "'");
David Greene718fda32007-08-01 03:59:32 +00004778 yyval.ConstVal.C = cast<Constant>(getCast(yyvsp[-5].CastOpVal, yyvsp[-3].ConstVal.C, SrcSign, DstTy, DstSign));
4779 yyval.ConstVal.S.copy(DstSign);
4780 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004781 ;}
4782 break;
4783
4784 case 164:
David Greene718fda32007-08-01 03:59:32 +00004785#line 2566 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004786 {
David Greene718fda32007-08-01 03:59:32 +00004787 const Type *Ty = yyvsp[-2].ConstVal.C->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00004788 if (!isa<PointerType>(Ty))
4789 error("GetElementPtr requires a pointer operand");
4790
Reid Spencer950bf602007-01-26 08:19:09 +00004791 std::vector<Constant*> CIndices;
David Greene718fda32007-08-01 03:59:32 +00004792 upgradeGEPCEIndices(yyvsp[-2].ConstVal.C->getType(), yyvsp[-1].ValueList, CIndices);
Reid Spencer950bf602007-01-26 08:19:09 +00004793
David Greene718fda32007-08-01 03:59:32 +00004794 delete yyvsp[-1].ValueList;
4795 yyval.ConstVal.C = ConstantExpr::getGetElementPtr(yyvsp[-2].ConstVal.C, &CIndices[0], CIndices.size());
4796 yyval.ConstVal.S.copy(getElementSign(yyvsp[-2].ConstVal, CIndices));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004797 ;}
4798 break;
4799
4800 case 165:
David Greene718fda32007-08-01 03:59:32 +00004801#line 2578 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004802 {
David Greene718fda32007-08-01 03:59:32 +00004803 if (!yyvsp[-5].ConstVal.C->getType()->isInteger() ||
4804 cast<IntegerType>(yyvsp[-5].ConstVal.C->getType())->getBitWidth() != 1)
Reid Spencer950bf602007-01-26 08:19:09 +00004805 error("Select condition must be bool type");
David Greene718fda32007-08-01 03:59:32 +00004806 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004807 error("Select operand types must match");
David Greene718fda32007-08-01 03:59:32 +00004808 yyval.ConstVal.C = ConstantExpr::getSelect(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4809 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004810 ;}
4811 break;
4812
4813 case 166:
David Greene718fda32007-08-01 03:59:32 +00004814#line 2587 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004815 {
David Greene718fda32007-08-01 03:59:32 +00004816 const Type *Ty = yyvsp[-3].ConstVal.C->getType();
4817 if (Ty != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004818 error("Binary operator types must match");
4819 // First, make sure we're dealing with the right opcode by upgrading from
4820 // obsolete versions.
David Greene718fda32007-08-01 03:59:32 +00004821 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S);
Reid Spencer950bf602007-01-26 08:19:09 +00004822
4823 // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs.
4824 // To retain backward compatibility with these early compilers, we emit a
4825 // cast to the appropriate integer type automatically if we are in the
4826 // broken case. See PR424 for more information.
4827 if (!isa<PointerType>(Ty)) {
David Greene718fda32007-08-01 03:59:32 +00004828 yyval.ConstVal.C = ConstantExpr::get(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
Reid Spencer950bf602007-01-26 08:19:09 +00004829 } else {
4830 const Type *IntPtrTy = 0;
4831 switch (CurModule.CurrentModule->getPointerSize()) {
4832 case Module::Pointer32: IntPtrTy = Type::Int32Ty; break;
4833 case Module::Pointer64: IntPtrTy = Type::Int64Ty; break;
4834 default: error("invalid pointer binary constant expr");
4835 }
David Greene718fda32007-08-01 03:59:32 +00004836 yyval.ConstVal.C = ConstantExpr::get(Opcode,
4837 ConstantExpr::getCast(Instruction::PtrToInt, yyvsp[-3].ConstVal.C, IntPtrTy),
4838 ConstantExpr::getCast(Instruction::PtrToInt, yyvsp[-1].ConstVal.C, IntPtrTy));
4839 yyval.ConstVal.C = ConstantExpr::getCast(Instruction::IntToPtr, yyval.ConstVal.C, Ty);
Reid Spencer950bf602007-01-26 08:19:09 +00004840 }
David Greene718fda32007-08-01 03:59:32 +00004841 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004842 ;}
4843 break;
4844
4845 case 167:
David Greene718fda32007-08-01 03:59:32 +00004846#line 2615 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004847 {
David Greene718fda32007-08-01 03:59:32 +00004848 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
4849 if (Ty != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004850 error("Logical operator types must match");
4851 if (!Ty->isInteger()) {
Reid Spencer9d6565a2007-02-15 02:26:10 +00004852 if (!isa<VectorType>(Ty) ||
4853 !cast<VectorType>(Ty)->getElementType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00004854 error("Logical operator requires integer operands");
4855 }
David Greene718fda32007-08-01 03:59:32 +00004856 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S);
4857 yyval.ConstVal.C = ConstantExpr::get(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4858 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004859 ;}
4860 break;
4861
4862 case 168:
David Greene718fda32007-08-01 03:59:32 +00004863#line 2628 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004864 {
David Greene718fda32007-08-01 03:59:32 +00004865 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
4866 if (Ty != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004867 error("setcc operand types must match");
4868 unsigned short pred;
David Greene718fda32007-08-01 03:59:32 +00004869 Instruction::OtherOps Opcode = getCompareOp(yyvsp[-5].BinaryOpVal, pred, Ty, yyvsp[-3].ConstVal.S);
4870 yyval.ConstVal.C = ConstantExpr::getCompare(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4871 yyval.ConstVal.S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004872 ;}
4873 break;
4874
4875 case 169:
David Greene718fda32007-08-01 03:59:32 +00004876#line 2637 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004877 {
David Greene718fda32007-08-01 03:59:32 +00004878 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004879 error("icmp operand types must match");
David Greene718fda32007-08-01 03:59:32 +00004880 yyval.ConstVal.C = ConstantExpr::getCompare(yyvsp[-5].IPred, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4881 yyval.ConstVal.S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004882 ;}
4883 break;
4884
4885 case 170:
David Greene718fda32007-08-01 03:59:32 +00004886#line 2643 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004887 {
David Greene718fda32007-08-01 03:59:32 +00004888 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004889 error("fcmp operand types must match");
David Greene718fda32007-08-01 03:59:32 +00004890 yyval.ConstVal.C = ConstantExpr::getCompare(yyvsp[-5].FPred, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4891 yyval.ConstVal.S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004892 ;}
4893 break;
4894
4895 case 171:
David Greene718fda32007-08-01 03:59:32 +00004896#line 2649 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004897 {
David Greene718fda32007-08-01 03:59:32 +00004898 if (!yyvsp[-1].ConstVal.C->getType()->isInteger() ||
4899 cast<IntegerType>(yyvsp[-1].ConstVal.C->getType())->getBitWidth() != 8)
Reid Spencer950bf602007-01-26 08:19:09 +00004900 error("Shift count for shift constant must be unsigned byte");
David Greene718fda32007-08-01 03:59:32 +00004901 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
4902 if (!yyvsp[-3].ConstVal.C->getType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00004903 error("Shift constant expression requires integer operand");
David Greene718fda32007-08-01 03:59:32 +00004904 Constant *ShiftAmt = ConstantExpr::getZExt(yyvsp[-1].ConstVal.C, Ty);
4905 yyval.ConstVal.C = ConstantExpr::get(getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S), yyvsp[-3].ConstVal.C, ShiftAmt);
4906 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004907 ;}
4908 break;
4909
4910 case 172:
David Greene718fda32007-08-01 03:59:32 +00004911#line 2660 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004912 {
David Greene718fda32007-08-01 03:59:32 +00004913 if (!ExtractElementInst::isValidOperands(yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Reid Spencer950bf602007-01-26 08:19:09 +00004914 error("Invalid extractelement operands");
David Greene718fda32007-08-01 03:59:32 +00004915 yyval.ConstVal.C = ConstantExpr::getExtractElement(yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4916 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S.get(0));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004917 ;}
4918 break;
4919
4920 case 173:
David Greene718fda32007-08-01 03:59:32 +00004921#line 2666 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004922 {
David Greene718fda32007-08-01 03:59:32 +00004923 if (!InsertElementInst::isValidOperands(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Reid Spencer950bf602007-01-26 08:19:09 +00004924 error("Invalid insertelement operands");
David Greene718fda32007-08-01 03:59:32 +00004925 yyval.ConstVal.C = ConstantExpr::getInsertElement(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4926 yyval.ConstVal.S.copy(yyvsp[-5].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004927 ;}
4928 break;
4929
4930 case 174:
David Greene718fda32007-08-01 03:59:32 +00004931#line 2672 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004932 {
David Greene718fda32007-08-01 03:59:32 +00004933 if (!ShuffleVectorInst::isValidOperands(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Reid Spencer950bf602007-01-26 08:19:09 +00004934 error("Invalid shufflevector operands");
David Greene718fda32007-08-01 03:59:32 +00004935 yyval.ConstVal.C = ConstantExpr::getShuffleVector(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4936 yyval.ConstVal.S.copy(yyvsp[-5].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004937 ;}
4938 break;
4939
4940 case 175:
David Greene718fda32007-08-01 03:59:32 +00004941#line 2683 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4942 { (yyval.ConstVector = yyvsp[-2].ConstVector)->push_back(yyvsp[0].ConstVal); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004943 break;
4944
4945 case 176:
David Greene718fda32007-08-01 03:59:32 +00004946#line 2684 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004947 {
David Greene718fda32007-08-01 03:59:32 +00004948 yyval.ConstVector = new std::vector<ConstInfo>();
4949 yyval.ConstVector->push_back(yyvsp[0].ConstVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004950 ;}
4951 break;
4952
4953 case 177:
David Greene718fda32007-08-01 03:59:32 +00004954#line 2693 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4955 { yyval.BoolVal = false; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004956 break;
4957
4958 case 178:
David Greene718fda32007-08-01 03:59:32 +00004959#line 2694 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4960 { yyval.BoolVal = true; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004961 break;
4962
4963 case 179:
David Greene718fda32007-08-01 03:59:32 +00004964#line 2706 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004965 {
David Greene718fda32007-08-01 03:59:32 +00004966 yyval.ModuleVal = ParserResult = yyvsp[0].ModuleVal;
Reid Spencer950bf602007-01-26 08:19:09 +00004967 CurModule.ModuleDone();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004968 ;}
4969 break;
4970
4971 case 180:
David Greene718fda32007-08-01 03:59:32 +00004972#line 2715 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4973 { yyval.ModuleVal = yyvsp[-1].ModuleVal; CurFun.FunctionDone(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004974 break;
4975
4976 case 181:
David Greene718fda32007-08-01 03:59:32 +00004977#line 2716 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4978 { yyval.ModuleVal = yyvsp[-1].ModuleVal; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004979 break;
4980
4981 case 182:
David Greene718fda32007-08-01 03:59:32 +00004982#line 2717 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4983 { yyval.ModuleVal = yyvsp[-3].ModuleVal; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004984 break;
4985
4986 case 183:
David Greene718fda32007-08-01 03:59:32 +00004987#line 2718 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4988 { yyval.ModuleVal = yyvsp[-1].ModuleVal; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004989 break;
4990
4991 case 184:
David Greene718fda32007-08-01 03:59:32 +00004992#line 2719 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004993 {
David Greene718fda32007-08-01 03:59:32 +00004994 yyval.ModuleVal = CurModule.CurrentModule;
Reid Spencer950bf602007-01-26 08:19:09 +00004995 // Emit an error if there are any unresolved types left.
4996 if (!CurModule.LateResolveTypes.empty()) {
4997 const ValID &DID = CurModule.LateResolveTypes.begin()->first;
4998 if (DID.Type == ValID::NameVal) {
4999 error("Reference to an undefined type: '"+DID.getName() + "'");
5000 } else {
5001 error("Reference to an undefined type: #" + itostr(DID.Num));
5002 }
5003 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005004 ;}
5005 break;
5006
5007 case 185:
David Greene718fda32007-08-01 03:59:32 +00005008#line 2735 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005009 {
Reid Spencer950bf602007-01-26 08:19:09 +00005010 // Eagerly resolve types. This is not an optimization, this is a
5011 // requirement that is due to the fact that we could have this:
5012 //
5013 // %list = type { %list * }
5014 // %list = type { %list * } ; repeated type decl
5015 //
5016 // If types are not resolved eagerly, then the two types will not be
5017 // determined to be the same type!
5018 //
David Greene718fda32007-08-01 03:59:32 +00005019 ResolveTypeTo(yyvsp[-2].StrVal, yyvsp[0].TypeVal.PAT->get(), yyvsp[0].TypeVal.S);
Reid Spencer950bf602007-01-26 08:19:09 +00005020
David Greene718fda32007-08-01 03:59:32 +00005021 if (!setTypeName(yyvsp[0].TypeVal, yyvsp[-2].StrVal) && !yyvsp[-2].StrVal) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00005022 // If this is a numbered type that is not a redefinition, add it to the
5023 // slot table.
David Greene718fda32007-08-01 03:59:32 +00005024 CurModule.Types.push_back(yyvsp[0].TypeVal.PAT->get());
5025 CurModule.TypeSigns.push_back(yyvsp[0].TypeVal.S);
Reid Spencera50d5962006-12-02 04:11:07 +00005026 }
David Greene718fda32007-08-01 03:59:32 +00005027 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005028 ;}
5029 break;
5030
5031 case 186:
David Greene718fda32007-08-01 03:59:32 +00005032#line 2755 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005033 { // Function prototypes can be in const pool
5034 ;}
5035 break;
5036
5037 case 187:
David Greene718fda32007-08-01 03:59:32 +00005038#line 2757 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005039 { // Asm blocks can be in the const pool
5040 ;}
5041 break;
5042
5043 case 188:
David Greene718fda32007-08-01 03:59:32 +00005044#line 2759 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005045 {
David Greene718fda32007-08-01 03:59:32 +00005046 if (yyvsp[0].ConstVal.C == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00005047 error("Global value initializer is not a constant");
David Greene718fda32007-08-01 03:59:32 +00005048 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, yyvsp[-2].Linkage, yyvsp[-1].BoolVal, yyvsp[0].ConstVal.C->getType(), yyvsp[0].ConstVal.C, yyvsp[0].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005049 ;}
5050 break;
5051
5052 case 189:
David Greene718fda32007-08-01 03:59:32 +00005053#line 2763 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005054 {
Reid Spencer950bf602007-01-26 08:19:09 +00005055 CurGV = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005056 ;}
5057 break;
5058
5059 case 190:
David Greene718fda32007-08-01 03:59:32 +00005060#line 2766 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005061 {
David Greene718fda32007-08-01 03:59:32 +00005062 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
5063 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::ExternalLinkage, yyvsp[-1].BoolVal, Ty, 0,
5064 yyvsp[0].TypeVal.S);
5065 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005066 ;}
5067 break;
5068
5069 case 191:
David Greene718fda32007-08-01 03:59:32 +00005070#line 2771 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005071 {
Reid Spencer950bf602007-01-26 08:19:09 +00005072 CurGV = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005073 ;}
5074 break;
5075
5076 case 192:
David Greene718fda32007-08-01 03:59:32 +00005077#line 2774 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005078 {
David Greene718fda32007-08-01 03:59:32 +00005079 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
5080 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::DLLImportLinkage, yyvsp[-1].BoolVal, Ty, 0,
5081 yyvsp[0].TypeVal.S);
5082 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005083 ;}
5084 break;
5085
5086 case 193:
David Greene718fda32007-08-01 03:59:32 +00005087#line 2779 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005088 {
Reid Spencer950bf602007-01-26 08:19:09 +00005089 CurGV = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005090 ;}
5091 break;
5092
5093 case 194:
David Greene718fda32007-08-01 03:59:32 +00005094#line 2782 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005095 {
David Greene718fda32007-08-01 03:59:32 +00005096 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005097 CurGV =
David Greene718fda32007-08-01 03:59:32 +00005098 ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::ExternalWeakLinkage, yyvsp[-1].BoolVal, Ty, 0,
5099 yyvsp[0].TypeVal.S);
5100 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005101 ;}
5102 break;
5103
5104 case 195:
David Greene718fda32007-08-01 03:59:32 +00005105#line 2788 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005106 {
Reid Spencer950bf602007-01-26 08:19:09 +00005107 CurGV = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005108 ;}
5109 break;
5110
5111 case 196:
David Greene718fda32007-08-01 03:59:32 +00005112#line 2791 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005113 {
5114 ;}
5115 break;
5116
5117 case 197:
David Greene718fda32007-08-01 03:59:32 +00005118#line 2793 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005119 {
5120 ;}
5121 break;
5122
5123 case 198:
David Greene718fda32007-08-01 03:59:32 +00005124#line 2795 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005125 {
5126 ;}
5127 break;
5128
5129 case 199:
David Greene718fda32007-08-01 03:59:32 +00005130#line 2800 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005131 {
Reid Spencer950bf602007-01-26 08:19:09 +00005132 const std::string &AsmSoFar = CurModule.CurrentModule->getModuleInlineAsm();
David Greene718fda32007-08-01 03:59:32 +00005133 char *EndStr = UnEscapeLexed(yyvsp[0].StrVal, true);
5134 std::string NewAsm(yyvsp[0].StrVal, EndStr);
5135 free(yyvsp[0].StrVal);
Reid Spencer950bf602007-01-26 08:19:09 +00005136
5137 if (AsmSoFar.empty())
5138 CurModule.CurrentModule->setModuleInlineAsm(NewAsm);
5139 else
5140 CurModule.CurrentModule->setModuleInlineAsm(AsmSoFar+"\n"+NewAsm);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005141 ;}
5142 break;
5143
5144 case 200:
David Greene718fda32007-08-01 03:59:32 +00005145#line 2814 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5146 { yyval.Endianness = Module::BigEndian; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005147 break;
5148
5149 case 201:
David Greene718fda32007-08-01 03:59:32 +00005150#line 2815 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5151 { yyval.Endianness = Module::LittleEndian; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005152 break;
5153
5154 case 202:
David Greene718fda32007-08-01 03:59:32 +00005155#line 2819 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005156 {
David Greene718fda32007-08-01 03:59:32 +00005157 CurModule.setEndianness(yyvsp[0].Endianness);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005158 ;}
5159 break;
5160
5161 case 203:
David Greene718fda32007-08-01 03:59:32 +00005162#line 2822 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005163 {
David Greene718fda32007-08-01 03:59:32 +00005164 if (yyvsp[0].UInt64Val == 32)
Reid Spencer950bf602007-01-26 08:19:09 +00005165 CurModule.setPointerSize(Module::Pointer32);
David Greene718fda32007-08-01 03:59:32 +00005166 else if (yyvsp[0].UInt64Val == 64)
Reid Spencer950bf602007-01-26 08:19:09 +00005167 CurModule.setPointerSize(Module::Pointer64);
5168 else
David Greene718fda32007-08-01 03:59:32 +00005169 error("Invalid pointer size: '" + utostr(yyvsp[0].UInt64Val) + "'");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005170 ;}
5171 break;
Reid Spencer9d6565a2007-02-15 02:26:10 +00005172
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005173 case 204:
David Greene718fda32007-08-01 03:59:32 +00005174#line 2830 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005175 {
David Greene718fda32007-08-01 03:59:32 +00005176 CurModule.CurrentModule->setTargetTriple(yyvsp[0].StrVal);
5177 free(yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005178 ;}
5179 break;
5180
5181 case 205:
David Greene718fda32007-08-01 03:59:32 +00005182#line 2834 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005183 {
David Greene718fda32007-08-01 03:59:32 +00005184 CurModule.CurrentModule->setDataLayout(yyvsp[0].StrVal);
5185 free(yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005186 ;}
5187 break;
5188
5189 case 207:
David Greene718fda32007-08-01 03:59:32 +00005190#line 2845 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005191 {
David Greene718fda32007-08-01 03:59:32 +00005192 CurModule.CurrentModule->addLibrary(yyvsp[0].StrVal);
5193 free(yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005194 ;}
5195 break;
5196
5197 case 208:
David Greene718fda32007-08-01 03:59:32 +00005198#line 2849 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005199 {
David Greene718fda32007-08-01 03:59:32 +00005200 CurModule.CurrentModule->addLibrary(yyvsp[0].StrVal);
5201 free(yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005202 ;}
5203 break;
5204
5205 case 209:
David Greene718fda32007-08-01 03:59:32 +00005206#line 2853 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005207 { ;}
5208 break;
5209
5210 case 213:
David Greene718fda32007-08-01 03:59:32 +00005211#line 2866 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5212 { yyval.StrVal = 0; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005213 break;
5214
5215 case 214:
David Greene718fda32007-08-01 03:59:32 +00005216#line 2870 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005217 {
David Greene718fda32007-08-01 03:59:32 +00005218 if (yyvsp[-1].TypeVal.PAT->get() == Type::VoidTy)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005219 error("void typed arguments are invalid");
David Greene718fda32007-08-01 03:59:32 +00005220 yyval.ArgVal = new std::pair<PATypeInfo, char*>(yyvsp[-1].TypeVal, yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005221 ;}
5222 break;
5223
5224 case 215:
David Greene718fda32007-08-01 03:59:32 +00005225#line 2878 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005226 {
David Greene718fda32007-08-01 03:59:32 +00005227 yyval.ArgList = yyvsp[-2].ArgList;
5228 yyval.ArgList->push_back(*yyvsp[0].ArgVal);
5229 delete yyvsp[0].ArgVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005230 ;}
5231 break;
5232
5233 case 216:
David Greene718fda32007-08-01 03:59:32 +00005234#line 2883 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005235 {
David Greene718fda32007-08-01 03:59:32 +00005236 yyval.ArgList = new std::vector<std::pair<PATypeInfo,char*> >();
5237 yyval.ArgList->push_back(*yyvsp[0].ArgVal);
5238 delete yyvsp[0].ArgVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005239 ;}
5240 break;
5241
5242 case 217:
David Greene718fda32007-08-01 03:59:32 +00005243#line 2891 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5244 { yyval.ArgList = yyvsp[0].ArgList; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005245 break;
5246
5247 case 218:
David Greene718fda32007-08-01 03:59:32 +00005248#line 2892 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005249 {
David Greene718fda32007-08-01 03:59:32 +00005250 yyval.ArgList = yyvsp[-2].ArgList;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005251 PATypeInfo VoidTI;
5252 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005253 VoidTI.S.makeSignless();
David Greene718fda32007-08-01 03:59:32 +00005254 yyval.ArgList->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005255 ;}
5256 break;
5257
5258 case 219:
David Greene718fda32007-08-01 03:59:32 +00005259#line 2899 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005260 {
David Greene718fda32007-08-01 03:59:32 +00005261 yyval.ArgList = new std::vector<std::pair<PATypeInfo,char*> >();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005262 PATypeInfo VoidTI;
5263 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005264 VoidTI.S.makeSignless();
David Greene718fda32007-08-01 03:59:32 +00005265 yyval.ArgList->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005266 ;}
5267 break;
5268
5269 case 220:
David Greene718fda32007-08-01 03:59:32 +00005270#line 2906 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5271 { yyval.ArgList = 0; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005272 break;
5273
5274 case 221:
David Greene718fda32007-08-01 03:59:32 +00005275#line 2910 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005276 {
David Greene718fda32007-08-01 03:59:32 +00005277 UnEscapeLexed(yyvsp[-5].StrVal);
5278 std::string FunctionName(yyvsp[-5].StrVal);
5279 free(yyvsp[-5].StrVal); // Free strdup'd memory!
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005280
David Greene718fda32007-08-01 03:59:32 +00005281 const Type* RetTy = yyvsp[-6].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005282
5283 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
5284 error("LLVM functions cannot return aggregate types");
5285
Reid Spencerbb1fd572007-03-21 17:15:50 +00005286 Signedness FTySign;
David Greene718fda32007-08-01 03:59:32 +00005287 FTySign.makeComposite(yyvsp[-6].TypeVal.S);
Reid Spenceref9b9a72007-02-05 20:47:22 +00005288 std::vector<const Type*> ParamTyList;
Reid Spencer950bf602007-01-26 08:19:09 +00005289
5290 // In LLVM 2.0 the signatures of three varargs intrinsics changed to take
5291 // i8*. We check here for those names and override the parameter list
5292 // types to ensure the prototype is correct.
5293 if (FunctionName == "llvm.va_start" || FunctionName == "llvm.va_end") {
Reid Spenceref9b9a72007-02-05 20:47:22 +00005294 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
Reid Spencer950bf602007-01-26 08:19:09 +00005295 } else if (FunctionName == "llvm.va_copy") {
Reid Spenceref9b9a72007-02-05 20:47:22 +00005296 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
5297 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
David Greene718fda32007-08-01 03:59:32 +00005298 } else if (yyvsp[-3].ArgList) { // If there are arguments...
Reid Spencer950bf602007-01-26 08:19:09 +00005299 for (std::vector<std::pair<PATypeInfo,char*> >::iterator
David Greene718fda32007-08-01 03:59:32 +00005300 I = yyvsp[-3].ArgList->begin(), E = yyvsp[-3].ArgList->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00005301 const Type *Ty = I->first.PAT->get();
Reid Spenceref9b9a72007-02-05 20:47:22 +00005302 ParamTyList.push_back(Ty);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005303 FTySign.add(I->first.S);
Reid Spencer950bf602007-01-26 08:19:09 +00005304 }
5305 }
5306
Reid Spenceref9b9a72007-02-05 20:47:22 +00005307 bool isVarArg = ParamTyList.size() && ParamTyList.back() == Type::VoidTy;
5308 if (isVarArg)
5309 ParamTyList.pop_back();
Reid Spencer950bf602007-01-26 08:19:09 +00005310
Reid Spencerb7046c72007-01-29 05:41:34 +00005311 // Convert the CSRet calling convention into the corresponding parameter
5312 // attribute.
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005313 ParamAttrsList *PAL = 0;
David Greene718fda32007-08-01 03:59:32 +00005314 if (yyvsp[-7].UIntVal == OldCallingConv::CSRet) {
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005315 ParamAttrsVector Attrs;
5316 ParamAttrsWithIndex PAWI;
5317 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
5318 Attrs.push_back(PAWI);
5319 PAL = ParamAttrsList::get(Attrs);
Reid Spencerb7046c72007-01-29 05:41:34 +00005320 }
5321
Reid Spencer7b5d4662007-04-09 06:16:21 +00005322 const FunctionType *FT =
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005323 FunctionType::get(RetTy, ParamTyList, isVarArg, PAL);
Reid Spencer950bf602007-01-26 08:19:09 +00005324 const PointerType *PFT = PointerType::get(FT);
David Greene718fda32007-08-01 03:59:32 +00005325 delete yyvsp[-6].TypeVal.PAT;
Reid Spencer950bf602007-01-26 08:19:09 +00005326
5327 ValID ID;
5328 if (!FunctionName.empty()) {
Reid Spencer5eb77c72007-03-15 03:26:42 +00005329 ID = ValID::create((char*)FunctionName.c_str());
Reid Spencer950bf602007-01-26 08:19:09 +00005330 } else {
Reid Spencer5eb77c72007-03-15 03:26:42 +00005331 ID = ValID::create((int)CurModule.Values[PFT].size());
Reid Spencer950bf602007-01-26 08:19:09 +00005332 }
Reid Spencerbb1fd572007-03-21 17:15:50 +00005333 ID.S.makeComposite(FTySign);
Reid Spencer950bf602007-01-26 08:19:09 +00005334
5335 Function *Fn = 0;
Reid Spencered96d1e2007-02-08 09:08:52 +00005336 Module* M = CurModule.CurrentModule;
5337
Reid Spencer950bf602007-01-26 08:19:09 +00005338 // See if this function was forward referenced. If so, recycle the object.
5339 if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, ID)) {
5340 // Move the function to the end of the list, from whereever it was
5341 // previously inserted.
5342 Fn = cast<Function>(FWRef);
Reid Spencered96d1e2007-02-08 09:08:52 +00005343 M->getFunctionList().remove(Fn);
5344 M->getFunctionList().push_back(Fn);
5345 } else if (!FunctionName.empty()) {
5346 GlobalValue *Conflict = M->getFunction(FunctionName);
5347 if (!Conflict)
5348 Conflict = M->getNamedGlobal(FunctionName);
5349 if (Conflict && PFT == Conflict->getType()) {
5350 if (!CurFun.isDeclare && !Conflict->isDeclaration()) {
5351 // We have two function definitions that conflict, same type, same
5352 // name. We should really check to make sure that this is the result
5353 // of integer type planes collapsing and generate an error if it is
5354 // not, but we'll just rename on the assumption that it is. However,
5355 // let's do it intelligently and rename the internal linkage one
5356 // if there is one.
5357 std::string NewName(makeNameUnique(FunctionName));
5358 if (Conflict->hasInternalLinkage()) {
5359 Conflict->setName(NewName);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005360 RenameMapKey Key =
5361 makeRenameMapKey(FunctionName, Conflict->getType(), ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00005362 CurModule.RenameMap[Key] = NewName;
5363 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5364 InsertValue(Fn, CurModule.Values);
5365 } else {
5366 Fn = new Function(FT, CurFun.Linkage, NewName, M);
5367 InsertValue(Fn, CurModule.Values);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005368 RenameMapKey Key =
5369 makeRenameMapKey(FunctionName, PFT, ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00005370 CurModule.RenameMap[Key] = NewName;
5371 }
5372 } else {
5373 // If they are not both definitions, then just use the function we
5374 // found since the types are the same.
5375 Fn = cast<Function>(Conflict);
Reid Spenceref9b9a72007-02-05 20:47:22 +00005376
Reid Spencered96d1e2007-02-08 09:08:52 +00005377 // Make sure to strip off any argument names so we can't get
5378 // conflicts.
5379 if (Fn->isDeclaration())
5380 for (Function::arg_iterator AI = Fn->arg_begin(),
5381 AE = Fn->arg_end(); AI != AE; ++AI)
5382 AI->setName("");
5383 }
5384 } else if (Conflict) {
Reid Spencere59f4932007-04-16 03:05:01 +00005385 // We have two globals with the same name and different types.
Reid Spencered96d1e2007-02-08 09:08:52 +00005386 // Previously, this was permitted because the symbol table had
5387 // "type planes" and names only needed to be distinct within a
5388 // type plane. After PR411 was fixed, this is no loner the case.
5389 // To resolve this we must rename one of the two.
5390 if (Conflict->hasInternalLinkage()) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00005391 // We can safely rename the Conflict.
5392 RenameMapKey Key =
5393 makeRenameMapKey(Conflict->getName(), Conflict->getType(),
5394 CurModule.NamedValueSigns[Conflict->getName()]);
Reid Spencered96d1e2007-02-08 09:08:52 +00005395 Conflict->setName(makeNameUnique(Conflict->getName()));
Reid Spencered96d1e2007-02-08 09:08:52 +00005396 CurModule.RenameMap[Key] = Conflict->getName();
5397 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5398 InsertValue(Fn, CurModule.Values);
Reid Spencerd2920cd2007-03-21 17:27:53 +00005399 } else {
Reid Spencered96d1e2007-02-08 09:08:52 +00005400 // We can't quietly rename either of these things, but we must
Reid Spencerd2920cd2007-03-21 17:27:53 +00005401 // rename one of them. Only if the function's linkage is internal can
5402 // we forgo a warning message about the renamed function.
Reid Spencered96d1e2007-02-08 09:08:52 +00005403 std::string NewName = makeNameUnique(FunctionName);
Reid Spencerd2920cd2007-03-21 17:27:53 +00005404 if (CurFun.Linkage != GlobalValue::InternalLinkage) {
5405 warning("Renaming function '" + FunctionName + "' as '" + NewName +
5406 "' may cause linkage errors");
5407 }
5408 // Elect to rename the thing we're now defining.
Reid Spencered96d1e2007-02-08 09:08:52 +00005409 Fn = new Function(FT, CurFun.Linkage, NewName, M);
5410 InsertValue(Fn, CurModule.Values);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005411 RenameMapKey Key = makeRenameMapKey(FunctionName, PFT, ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00005412 CurModule.RenameMap[Key] = NewName;
Reid Spencerd2920cd2007-03-21 17:27:53 +00005413 }
Reid Spenceref9b9a72007-02-05 20:47:22 +00005414 } else {
Reid Spencered96d1e2007-02-08 09:08:52 +00005415 // There's no conflict, just define the function
5416 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5417 InsertValue(Fn, CurModule.Values);
Reid Spenceref9b9a72007-02-05 20:47:22 +00005418 }
Reid Spencere59f4932007-04-16 03:05:01 +00005419 } else {
5420 // There's no conflict, just define the function
5421 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5422 InsertValue(Fn, CurModule.Values);
Reid Spencer950bf602007-01-26 08:19:09 +00005423 }
5424
Reid Spencere59f4932007-04-16 03:05:01 +00005425
Reid Spencer950bf602007-01-26 08:19:09 +00005426 CurFun.FunctionStart(Fn);
5427
5428 if (CurFun.isDeclare) {
5429 // If we have declaration, always overwrite linkage. This will allow us
5430 // to correctly handle cases, when pointer to function is passed as
5431 // argument to another function.
5432 Fn->setLinkage(CurFun.Linkage);
5433 }
David Greene718fda32007-08-01 03:59:32 +00005434 Fn->setCallingConv(upgradeCallingConv(yyvsp[-7].UIntVal));
5435 Fn->setAlignment(yyvsp[0].UIntVal);
5436 if (yyvsp[-1].StrVal) {
5437 Fn->setSection(yyvsp[-1].StrVal);
5438 free(yyvsp[-1].StrVal);
Reid Spencer950bf602007-01-26 08:19:09 +00005439 }
5440
5441 // Add all of the arguments we parsed to the function...
David Greene718fda32007-08-01 03:59:32 +00005442 if (yyvsp[-3].ArgList) { // Is null if empty...
Reid Spencer950bf602007-01-26 08:19:09 +00005443 if (isVarArg) { // Nuke the last entry
David Greene718fda32007-08-01 03:59:32 +00005444 assert(yyvsp[-3].ArgList->back().first.PAT->get() == Type::VoidTy &&
5445 yyvsp[-3].ArgList->back().second == 0 && "Not a varargs marker");
5446 delete yyvsp[-3].ArgList->back().first.PAT;
5447 yyvsp[-3].ArgList->pop_back(); // Delete the last entry
Reid Spencer950bf602007-01-26 08:19:09 +00005448 }
5449 Function::arg_iterator ArgIt = Fn->arg_begin();
Reid Spenceref9b9a72007-02-05 20:47:22 +00005450 Function::arg_iterator ArgEnd = Fn->arg_end();
David Greene718fda32007-08-01 03:59:32 +00005451 std::vector<std::pair<PATypeInfo,char*> >::iterator I = yyvsp[-3].ArgList->begin();
5452 std::vector<std::pair<PATypeInfo,char*> >::iterator E = yyvsp[-3].ArgList->end();
Reid Spenceref9b9a72007-02-05 20:47:22 +00005453 for ( ; I != E && ArgIt != ArgEnd; ++I, ++ArgIt) {
Reid Spencered96d1e2007-02-08 09:08:52 +00005454 delete I->first.PAT; // Delete the typeholder...
Reid Spencerbb1fd572007-03-21 17:15:50 +00005455 ValueInfo VI; VI.V = ArgIt; VI.S.copy(I->first.S);
5456 setValueName(VI, I->second); // Insert arg into symtab...
Reid Spencer950bf602007-01-26 08:19:09 +00005457 InsertValue(ArgIt);
5458 }
David Greene718fda32007-08-01 03:59:32 +00005459 delete yyvsp[-3].ArgList; // We're now done with the argument list
Reid Spencer950bf602007-01-26 08:19:09 +00005460 }
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005461 lastCallingConv = OldCallingConv::C;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005462 ;}
5463 break;
5464
5465 case 224:
David Greene718fda32007-08-01 03:59:32 +00005466#line 3104 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5467 { CurFun.Linkage = yyvsp[0].Linkage; ;}
Reid Spencerd2920cd2007-03-21 17:27:53 +00005468 break;
5469
5470 case 225:
David Greene718fda32007-08-01 03:59:32 +00005471#line 3104 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005472 {
David Greene718fda32007-08-01 03:59:32 +00005473 yyval.FunctionVal = CurFun.CurrentFunction;
Reid Spencer950bf602007-01-26 08:19:09 +00005474
5475 // Make sure that we keep track of the linkage type even if there was a
5476 // previous "declare".
David Greene718fda32007-08-01 03:59:32 +00005477 yyval.FunctionVal->setLinkage(yyvsp[-3].Linkage);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005478 ;}
5479 break;
5480
Reid Spencerd2920cd2007-03-21 17:27:53 +00005481 case 228:
David Greene718fda32007-08-01 03:59:32 +00005482#line 3118 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005483 {
David Greene718fda32007-08-01 03:59:32 +00005484 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005485 ;}
5486 break;
5487
Reid Spencerd2920cd2007-03-21 17:27:53 +00005488 case 229:
David Greene718fda32007-08-01 03:59:32 +00005489#line 3123 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5490 { yyval.Linkage = GlobalValue::ExternalLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005491 break;
5492
Reid Spencerd2920cd2007-03-21 17:27:53 +00005493 case 230:
David Greene718fda32007-08-01 03:59:32 +00005494#line 3124 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5495 { yyval.Linkage = GlobalValue::DLLImportLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005496 break;
5497
Reid Spencerd2920cd2007-03-21 17:27:53 +00005498 case 231:
David Greene718fda32007-08-01 03:59:32 +00005499#line 3125 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5500 { yyval.Linkage = GlobalValue::ExternalWeakLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005501 break;
5502
Reid Spencerd2920cd2007-03-21 17:27:53 +00005503 case 232:
David Greene718fda32007-08-01 03:59:32 +00005504#line 3129 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005505 { CurFun.isDeclare = true; ;}
5506 break;
5507
Reid Spencerd2920cd2007-03-21 17:27:53 +00005508 case 233:
David Greene718fda32007-08-01 03:59:32 +00005509#line 3130 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5510 { CurFun.Linkage = yyvsp[0].Linkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005511 break;
5512
Reid Spencerd2920cd2007-03-21 17:27:53 +00005513 case 234:
David Greene718fda32007-08-01 03:59:32 +00005514#line 3130 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005515 {
David Greene718fda32007-08-01 03:59:32 +00005516 yyval.FunctionVal = CurFun.CurrentFunction;
Reid Spencer950bf602007-01-26 08:19:09 +00005517 CurFun.FunctionDone();
5518
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005519 ;}
5520 break;
5521
Reid Spencerd2920cd2007-03-21 17:27:53 +00005522 case 235:
David Greene718fda32007-08-01 03:59:32 +00005523#line 3142 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5524 { yyval.BoolVal = false; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005525 break;
5526
Reid Spencerd2920cd2007-03-21 17:27:53 +00005527 case 236:
David Greene718fda32007-08-01 03:59:32 +00005528#line 3143 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5529 { yyval.BoolVal = true; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005530 break;
5531
Reid Spencerd2920cd2007-03-21 17:27:53 +00005532 case 237:
David Greene718fda32007-08-01 03:59:32 +00005533#line 3148 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5534 { yyval.ValIDVal = ValID::create(yyvsp[0].SInt64Val); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005535 break;
5536
Reid Spencerd2920cd2007-03-21 17:27:53 +00005537 case 238:
David Greene718fda32007-08-01 03:59:32 +00005538#line 3149 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5539 { yyval.ValIDVal = ValID::create(yyvsp[0].UInt64Val); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005540 break;
5541
Reid Spencerd2920cd2007-03-21 17:27:53 +00005542 case 239:
David Greene718fda32007-08-01 03:59:32 +00005543#line 3150 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5544 { yyval.ValIDVal = ValID::create(yyvsp[0].FPVal); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005545 break;
5546
Reid Spencerd2920cd2007-03-21 17:27:53 +00005547 case 240:
David Greene718fda32007-08-01 03:59:32 +00005548#line 3151 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencerbb1fd572007-03-21 17:15:50 +00005549 {
David Greene718fda32007-08-01 03:59:32 +00005550 yyval.ValIDVal = ValID::create(ConstantInt::get(Type::Int1Ty, true));
5551 yyval.ValIDVal.S.makeUnsigned();
Reid Spencerbb1fd572007-03-21 17:15:50 +00005552 ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005553 break;
5554
Reid Spencerd2920cd2007-03-21 17:27:53 +00005555 case 241:
David Greene718fda32007-08-01 03:59:32 +00005556#line 3155 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencerbb1fd572007-03-21 17:15:50 +00005557 {
David Greene718fda32007-08-01 03:59:32 +00005558 yyval.ValIDVal = ValID::create(ConstantInt::get(Type::Int1Ty, false));
5559 yyval.ValIDVal.S.makeUnsigned();
Reid Spencerbb1fd572007-03-21 17:15:50 +00005560 ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005561 break;
5562
Reid Spencerd2920cd2007-03-21 17:27:53 +00005563 case 242:
David Greene718fda32007-08-01 03:59:32 +00005564#line 3159 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5565 { yyval.ValIDVal = ValID::createNull(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005566 break;
5567
Reid Spencerd2920cd2007-03-21 17:27:53 +00005568 case 243:
David Greene718fda32007-08-01 03:59:32 +00005569#line 3160 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5570 { yyval.ValIDVal = ValID::createUndef(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005571 break;
5572
Reid Spencerd2920cd2007-03-21 17:27:53 +00005573 case 244:
David Greene718fda32007-08-01 03:59:32 +00005574#line 3161 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5575 { yyval.ValIDVal = ValID::createZeroInit(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005576 break;
5577
Reid Spencerd2920cd2007-03-21 17:27:53 +00005578 case 245:
David Greene718fda32007-08-01 03:59:32 +00005579#line 3162 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005580 { // Nonempty unsized packed vector
David Greene718fda32007-08-01 03:59:32 +00005581 const Type *ETy = (*yyvsp[-1].ConstVector)[0].C->getType();
5582 int NumElements = yyvsp[-1].ConstVector->size();
Reid Spencer9d6565a2007-02-15 02:26:10 +00005583 VectorType* pt = VectorType::get(ETy, NumElements);
David Greene718fda32007-08-01 03:59:32 +00005584 yyval.ValIDVal.S.makeComposite((*yyvsp[-1].ConstVector)[0].S);
5585 PATypeHolder* PTy = new PATypeHolder(HandleUpRefs(pt, yyval.ValIDVal.S));
Reid Spencer950bf602007-01-26 08:19:09 +00005586
5587 // Verify all elements are correct type!
5588 std::vector<Constant*> Elems;
David Greene718fda32007-08-01 03:59:32 +00005589 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
5590 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00005591 const Type *CTy = C->getType();
5592 if (ETy != CTy)
5593 error("Element #" + utostr(i) + " is not of type '" +
5594 ETy->getDescription() +"' as required!\nIt is of type '" +
5595 CTy->getDescription() + "'");
5596 Elems.push_back(C);
Reid Spencere77e35e2006-12-01 20:26:20 +00005597 }
David Greene718fda32007-08-01 03:59:32 +00005598 yyval.ValIDVal = ValID::create(ConstantVector::get(pt, Elems));
5599 delete PTy; delete yyvsp[-1].ConstVector;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005600 ;}
5601 break;
5602
Reid Spencerd2920cd2007-03-21 17:27:53 +00005603 case 246:
David Greene718fda32007-08-01 03:59:32 +00005604#line 3183 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005605 {
David Greene718fda32007-08-01 03:59:32 +00005606 yyval.ValIDVal = ValID::create(yyvsp[0].ConstVal.C);
5607 yyval.ValIDVal.S.copy(yyvsp[0].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005608 ;}
5609 break;
5610
Reid Spencerd2920cd2007-03-21 17:27:53 +00005611 case 247:
David Greene718fda32007-08-01 03:59:32 +00005612#line 3187 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005613 {
David Greene718fda32007-08-01 03:59:32 +00005614 char *End = UnEscapeLexed(yyvsp[-2].StrVal, true);
5615 std::string AsmStr = std::string(yyvsp[-2].StrVal, End);
5616 End = UnEscapeLexed(yyvsp[0].StrVal, true);
5617 std::string Constraints = std::string(yyvsp[0].StrVal, End);
5618 yyval.ValIDVal = ValID::createInlineAsm(AsmStr, Constraints, yyvsp[-3].BoolVal);
5619 free(yyvsp[-2].StrVal);
5620 free(yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005621 ;}
5622 break;
5623
Reid Spencerd2920cd2007-03-21 17:27:53 +00005624 case 248:
David Greene718fda32007-08-01 03:59:32 +00005625#line 3201 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5626 { yyval.ValIDVal = ValID::create(yyvsp[0].SIntVal); yyval.ValIDVal.S.makeSignless(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005627 break;
5628
Reid Spencerd2920cd2007-03-21 17:27:53 +00005629 case 249:
David Greene718fda32007-08-01 03:59:32 +00005630#line 3202 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5631 { yyval.ValIDVal = ValID::create(yyvsp[0].StrVal); yyval.ValIDVal.S.makeSignless(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005632 break;
5633
Reid Spencerd2920cd2007-03-21 17:27:53 +00005634 case 252:
David Greene718fda32007-08-01 03:59:32 +00005635#line 3215 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005636 {
David Greene718fda32007-08-01 03:59:32 +00005637 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
5638 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
5639 yyval.ValueVal.V = getVal(Ty, yyvsp[0].ValIDVal);
5640 yyval.ValueVal.S.copy(yyvsp[-1].TypeVal.S);
5641 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005642 ;}
5643 break;
5644
Reid Spencerd2920cd2007-03-21 17:27:53 +00005645 case 253:
David Greene718fda32007-08-01 03:59:32 +00005646#line 3225 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005647 {
David Greene718fda32007-08-01 03:59:32 +00005648 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005649 ;}
5650 break;
5651
Reid Spencerd2920cd2007-03-21 17:27:53 +00005652 case 254:
David Greene718fda32007-08-01 03:59:32 +00005653#line 3228 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005654 { // Do not allow functions with 0 basic blocks
David Greene718fda32007-08-01 03:59:32 +00005655 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005656 ;}
5657 break;
5658
Reid Spencerd2920cd2007-03-21 17:27:53 +00005659 case 255:
David Greene718fda32007-08-01 03:59:32 +00005660#line 3237 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005661 {
David Greene718fda32007-08-01 03:59:32 +00005662 ValueInfo VI; VI.V = yyvsp[0].TermInstVal.TI; VI.S.copy(yyvsp[0].TermInstVal.S);
5663 setValueName(VI, yyvsp[-1].StrVal);
5664 InsertValue(yyvsp[0].TermInstVal.TI);
5665 yyvsp[-2].BasicBlockVal->getInstList().push_back(yyvsp[0].TermInstVal.TI);
5666 InsertValue(yyvsp[-2].BasicBlockVal);
5667 yyval.BasicBlockVal = yyvsp[-2].BasicBlockVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005668 ;}
5669 break;
5670
Reid Spencerd2920cd2007-03-21 17:27:53 +00005671 case 256:
David Greene718fda32007-08-01 03:59:32 +00005672#line 3248 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005673 {
David Greene718fda32007-08-01 03:59:32 +00005674 if (yyvsp[0].InstVal.I)
5675 yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].InstVal.I);
5676 yyval.BasicBlockVal = yyvsp[-1].BasicBlockVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005677 ;}
5678 break;
5679
Reid Spencerd2920cd2007-03-21 17:27:53 +00005680 case 257:
David Greene718fda32007-08-01 03:59:32 +00005681#line 3253 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005682 {
David Greene718fda32007-08-01 03:59:32 +00005683 yyval.BasicBlockVal = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++),true);
Reid Spencer950bf602007-01-26 08:19:09 +00005684 // Make sure to move the basic block to the correct location in the
5685 // function, instead of leaving it inserted wherever it was first
5686 // referenced.
5687 Function::BasicBlockListType &BBL =
5688 CurFun.CurrentFunction->getBasicBlockList();
David Greene718fda32007-08-01 03:59:32 +00005689 BBL.splice(BBL.end(), BBL, yyval.BasicBlockVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005690 ;}
5691 break;
5692
Reid Spencerd2920cd2007-03-21 17:27:53 +00005693 case 258:
David Greene718fda32007-08-01 03:59:32 +00005694#line 3262 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005695 {
David Greene718fda32007-08-01 03:59:32 +00005696 yyval.BasicBlockVal = CurBB = getBBVal(ValID::create(yyvsp[0].StrVal), true);
Reid Spencer950bf602007-01-26 08:19:09 +00005697 // Make sure to move the basic block to the correct location in the
5698 // function, instead of leaving it inserted wherever it was first
5699 // referenced.
5700 Function::BasicBlockListType &BBL =
5701 CurFun.CurrentFunction->getBasicBlockList();
David Greene718fda32007-08-01 03:59:32 +00005702 BBL.splice(BBL.end(), BBL, yyval.BasicBlockVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005703 ;}
5704 break;
5705
Reid Spencerd2920cd2007-03-21 17:27:53 +00005706 case 261:
David Greene718fda32007-08-01 03:59:32 +00005707#line 3276 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005708 { // Return with a result...
David Greene718fda32007-08-01 03:59:32 +00005709 yyval.TermInstVal.TI = new ReturnInst(yyvsp[0].ValueVal.V);
5710 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005711 ;}
5712 break;
5713
Reid Spencerd2920cd2007-03-21 17:27:53 +00005714 case 262:
David Greene718fda32007-08-01 03:59:32 +00005715#line 3280 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005716 { // Return with no result...
David Greene718fda32007-08-01 03:59:32 +00005717 yyval.TermInstVal.TI = new ReturnInst();
5718 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005719 ;}
5720 break;
5721
Reid Spencerd2920cd2007-03-21 17:27:53 +00005722 case 263:
David Greene718fda32007-08-01 03:59:32 +00005723#line 3284 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005724 { // Unconditional Branch...
David Greene718fda32007-08-01 03:59:32 +00005725 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
5726 yyval.TermInstVal.TI = new BranchInst(tmpBB);
5727 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005728 ;}
5729 break;
5730
Reid Spencerd2920cd2007-03-21 17:27:53 +00005731 case 264:
David Greene718fda32007-08-01 03:59:32 +00005732#line 3289 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005733 {
David Greene718fda32007-08-01 03:59:32 +00005734 yyvsp[-3].ValIDVal.S.makeSignless();
5735 yyvsp[0].ValIDVal.S.makeSignless();
5736 BasicBlock* tmpBBA = getBBVal(yyvsp[-3].ValIDVal);
5737 BasicBlock* tmpBBB = getBBVal(yyvsp[0].ValIDVal);
5738 yyvsp[-6].ValIDVal.S.makeUnsigned();
5739 Value* tmpVal = getVal(Type::Int1Ty, yyvsp[-6].ValIDVal);
5740 yyval.TermInstVal.TI = new BranchInst(tmpBBA, tmpBBB, tmpVal);
5741 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005742 ;}
5743 break;
5744
Reid Spencerd2920cd2007-03-21 17:27:53 +00005745 case 265:
David Greene718fda32007-08-01 03:59:32 +00005746#line 3299 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005747 {
David Greene718fda32007-08-01 03:59:32 +00005748 yyvsp[-6].ValIDVal.S.copy(yyvsp[-7].PrimType.S);
5749 Value* tmpVal = getVal(yyvsp[-7].PrimType.T, yyvsp[-6].ValIDVal);
5750 yyvsp[-3].ValIDVal.S.makeSignless();
5751 BasicBlock* tmpBB = getBBVal(yyvsp[-3].ValIDVal);
5752 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, yyvsp[-1].JumpTable->size());
5753 yyval.TermInstVal.TI = S;
5754 yyval.TermInstVal.S.makeSignless();
5755 std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = yyvsp[-1].JumpTable->begin(),
5756 E = yyvsp[-1].JumpTable->end();
Reid Spencer950bf602007-01-26 08:19:09 +00005757 for (; I != E; ++I) {
5758 if (ConstantInt *CI = dyn_cast<ConstantInt>(I->first))
5759 S->addCase(CI, I->second);
5760 else
5761 error("Switch case is constant, but not a simple integer");
5762 }
David Greene718fda32007-08-01 03:59:32 +00005763 delete yyvsp[-1].JumpTable;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005764 ;}
5765 break;
5766
Reid Spencerd2920cd2007-03-21 17:27:53 +00005767 case 266:
David Greene718fda32007-08-01 03:59:32 +00005768#line 3317 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005769 {
David Greene718fda32007-08-01 03:59:32 +00005770 yyvsp[-5].ValIDVal.S.copy(yyvsp[-6].PrimType.S);
5771 Value* tmpVal = getVal(yyvsp[-6].PrimType.T, yyvsp[-5].ValIDVal);
5772 yyvsp[-2].ValIDVal.S.makeSignless();
5773 BasicBlock* tmpBB = getBBVal(yyvsp[-2].ValIDVal);
Reid Spencer950bf602007-01-26 08:19:09 +00005774 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0);
David Greene718fda32007-08-01 03:59:32 +00005775 yyval.TermInstVal.TI = S;
5776 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005777 ;}
5778 break;
5779
Reid Spencerd2920cd2007-03-21 17:27:53 +00005780 case 267:
David Greene718fda32007-08-01 03:59:32 +00005781#line 3327 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005782 {
Reid Spencer950bf602007-01-26 08:19:09 +00005783 const PointerType *PFTy;
5784 const FunctionType *Ty;
Reid Spencerbb1fd572007-03-21 17:15:50 +00005785 Signedness FTySign;
Reid Spencer950bf602007-01-26 08:19:09 +00005786
David Greene718fda32007-08-01 03:59:32 +00005787 if (!(PFTy = dyn_cast<PointerType>(yyvsp[-10].TypeVal.PAT->get())) ||
Reid Spencer950bf602007-01-26 08:19:09 +00005788 !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
5789 // Pull out the types of all of the arguments...
5790 std::vector<const Type*> ParamTypes;
David Greene718fda32007-08-01 03:59:32 +00005791 FTySign.makeComposite(yyvsp[-10].TypeVal.S);
5792 if (yyvsp[-7].ValueList) {
5793 for (std::vector<ValueInfo>::iterator I = yyvsp[-7].ValueList->begin(), E = yyvsp[-7].ValueList->end();
Reid Spencerbb1fd572007-03-21 17:15:50 +00005794 I != E; ++I) {
Reid Spencer950bf602007-01-26 08:19:09 +00005795 ParamTypes.push_back((*I).V->getType());
Reid Spencerbb1fd572007-03-21 17:15:50 +00005796 FTySign.add(I->S);
5797 }
Reid Spencer950bf602007-01-26 08:19:09 +00005798 }
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005799 ParamAttrsList *PAL = 0;
David Greene718fda32007-08-01 03:59:32 +00005800 if (yyvsp[-11].UIntVal == OldCallingConv::CSRet) {
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005801 ParamAttrsVector Attrs;
5802 ParamAttrsWithIndex PAWI;
5803 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
5804 Attrs.push_back(PAWI);
5805 PAL = ParamAttrsList::get(Attrs);
Reid Spencerb7046c72007-01-29 05:41:34 +00005806 }
Reid Spencer950bf602007-01-26 08:19:09 +00005807 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
5808 if (isVarArg) ParamTypes.pop_back();
David Greene718fda32007-08-01 03:59:32 +00005809 Ty = FunctionType::get(yyvsp[-10].TypeVal.PAT->get(), ParamTypes, isVarArg, PAL);
Reid Spencer950bf602007-01-26 08:19:09 +00005810 PFTy = PointerType::get(Ty);
David Greene718fda32007-08-01 03:59:32 +00005811 yyval.TermInstVal.S.copy(yyvsp[-10].TypeVal.S);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005812 } else {
David Greene718fda32007-08-01 03:59:32 +00005813 FTySign = yyvsp[-10].TypeVal.S;
Reid Spencera3b12dd2007-04-07 16:14:01 +00005814 // Get the signedness of the result type. $3 is the pointer to the
5815 // function type so we get the 0th element to extract the function type,
5816 // and then the 0th element again to get the result type.
David Greene718fda32007-08-01 03:59:32 +00005817 yyval.TermInstVal.S.copy(yyvsp[-10].TypeVal.S.get(0).get(0));
Reid Spencer950bf602007-01-26 08:19:09 +00005818 }
Reid Spencer7b5d4662007-04-09 06:16:21 +00005819
David Greene718fda32007-08-01 03:59:32 +00005820 yyvsp[-9].ValIDVal.S.makeComposite(FTySign);
5821 Value *V = getVal(PFTy, yyvsp[-9].ValIDVal); // Get the function we're calling...
5822 BasicBlock *Normal = getBBVal(yyvsp[-3].ValIDVal);
5823 BasicBlock *Except = getBBVal(yyvsp[0].ValIDVal);
Reid Spencer950bf602007-01-26 08:19:09 +00005824
5825 // Create the call node...
David Greene718fda32007-08-01 03:59:32 +00005826 if (!yyvsp[-7].ValueList) { // Has no arguments?
5827 yyval.TermInstVal.TI = new InvokeInst(V, Normal, Except, 0, 0);
Reid Spencer950bf602007-01-26 08:19:09 +00005828 } else { // Has arguments?
5829 // Loop through FunctionType's arguments and ensure they are specified
5830 // correctly!
5831 //
5832 FunctionType::param_iterator I = Ty->param_begin();
5833 FunctionType::param_iterator E = Ty->param_end();
David Greene718fda32007-08-01 03:59:32 +00005834 std::vector<ValueInfo>::iterator ArgI = yyvsp[-7].ValueList->begin(), ArgE = yyvsp[-7].ValueList->end();
Reid Spencer950bf602007-01-26 08:19:09 +00005835
5836 std::vector<Value*> Args;
5837 for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
5838 if ((*ArgI).V->getType() != *I)
5839 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
5840 (*I)->getDescription() + "'");
5841 Args.push_back((*ArgI).V);
5842 }
5843
5844 if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
5845 error("Invalid number of parameters detected");
5846
David Greene718fda32007-08-01 03:59:32 +00005847 yyval.TermInstVal.TI = new InvokeInst(V, Normal, Except, &Args[0], Args.size());
Reid Spencer950bf602007-01-26 08:19:09 +00005848 }
David Greene718fda32007-08-01 03:59:32 +00005849 cast<InvokeInst>(yyval.TermInstVal.TI)->setCallingConv(upgradeCallingConv(yyvsp[-11].UIntVal));
5850 delete yyvsp[-10].TypeVal.PAT;
5851 delete yyvsp[-7].ValueList;
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005852 lastCallingConv = OldCallingConv::C;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005853 ;}
5854 break;
5855
Reid Spencerd2920cd2007-03-21 17:27:53 +00005856 case 268:
David Greene718fda32007-08-01 03:59:32 +00005857#line 3399 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005858 {
David Greene718fda32007-08-01 03:59:32 +00005859 yyval.TermInstVal.TI = new UnwindInst();
5860 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005861 ;}
5862 break;
5863
Reid Spencerd2920cd2007-03-21 17:27:53 +00005864 case 269:
David Greene718fda32007-08-01 03:59:32 +00005865#line 3403 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005866 {
David Greene718fda32007-08-01 03:59:32 +00005867 yyval.TermInstVal.TI = new UnreachableInst();
5868 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005869 ;}
5870 break;
5871
Reid Spencerd2920cd2007-03-21 17:27:53 +00005872 case 270:
David Greene718fda32007-08-01 03:59:32 +00005873#line 3410 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005874 {
David Greene718fda32007-08-01 03:59:32 +00005875 yyval.JumpTable = yyvsp[-5].JumpTable;
5876 yyvsp[-3].ValIDVal.S.copy(yyvsp[-4].PrimType.S);
5877 Constant *V = cast<Constant>(getExistingValue(yyvsp[-4].PrimType.T, yyvsp[-3].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00005878
5879 if (V == 0)
5880 error("May only switch on a constant pool value");
5881
David Greene718fda32007-08-01 03:59:32 +00005882 yyvsp[0].ValIDVal.S.makeSignless();
5883 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
5884 yyval.JumpTable->push_back(std::make_pair(V, tmpBB));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005885 ;}
5886 break;
5887
Reid Spencerd2920cd2007-03-21 17:27:53 +00005888 case 271:
David Greene718fda32007-08-01 03:59:32 +00005889#line 3422 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005890 {
David Greene718fda32007-08-01 03:59:32 +00005891 yyval.JumpTable = new std::vector<std::pair<Constant*, BasicBlock*> >();
5892 yyvsp[-3].ValIDVal.S.copy(yyvsp[-4].PrimType.S);
5893 Constant *V = cast<Constant>(getExistingValue(yyvsp[-4].PrimType.T, yyvsp[-3].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00005894
5895 if (V == 0)
5896 error("May only switch on a constant pool value");
5897
David Greene718fda32007-08-01 03:59:32 +00005898 yyvsp[0].ValIDVal.S.makeSignless();
5899 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
5900 yyval.JumpTable->push_back(std::make_pair(V, tmpBB));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005901 ;}
5902 break;
5903
Reid Spencerd2920cd2007-03-21 17:27:53 +00005904 case 272:
David Greene718fda32007-08-01 03:59:32 +00005905#line 3437 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005906 {
Reid Spencer950bf602007-01-26 08:19:09 +00005907 bool omit = false;
David Greene718fda32007-08-01 03:59:32 +00005908 if (yyvsp[-1].StrVal)
5909 if (BitCastInst *BCI = dyn_cast<BitCastInst>(yyvsp[0].InstVal.I))
Reid Spencer950bf602007-01-26 08:19:09 +00005910 if (BCI->getSrcTy() == BCI->getDestTy() &&
David Greene718fda32007-08-01 03:59:32 +00005911 BCI->getOperand(0)->getName() == yyvsp[-1].StrVal)
Reid Spencer950bf602007-01-26 08:19:09 +00005912 // This is a useless bit cast causing a name redefinition. It is
5913 // a bit cast from a type to the same type of an operand with the
5914 // same name as the name we would give this instruction. Since this
5915 // instruction results in no code generation, it is safe to omit
5916 // the instruction. This situation can occur because of collapsed
5917 // type planes. For example:
5918 // %X = add int %Y, %Z
5919 // %X = cast int %Y to uint
5920 // After upgrade, this looks like:
5921 // %X = add i32 %Y, %Z
5922 // %X = bitcast i32 to i32
5923 // The bitcast is clearly useless so we omit it.
5924 omit = true;
5925 if (omit) {
David Greene718fda32007-08-01 03:59:32 +00005926 yyval.InstVal.I = 0;
5927 yyval.InstVal.S.makeSignless();
Reid Spencer950bf602007-01-26 08:19:09 +00005928 } else {
David Greene718fda32007-08-01 03:59:32 +00005929 ValueInfo VI; VI.V = yyvsp[0].InstVal.I; VI.S.copy(yyvsp[0].InstVal.S);
5930 setValueName(VI, yyvsp[-1].StrVal);
5931 InsertValue(yyvsp[0].InstVal.I);
5932 yyval.InstVal = yyvsp[0].InstVal;
Reid Spencer950bf602007-01-26 08:19:09 +00005933 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005934 ;}
5935 break;
5936
Reid Spencerd2920cd2007-03-21 17:27:53 +00005937 case 273:
David Greene718fda32007-08-01 03:59:32 +00005938#line 3467 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005939 { // Used for PHI nodes
David Greene718fda32007-08-01 03:59:32 +00005940 yyval.PHIList.P = new std::list<std::pair<Value*, BasicBlock*> >();
5941 yyval.PHIList.S.copy(yyvsp[-5].TypeVal.S);
5942 yyvsp[-3].ValIDVal.S.copy(yyvsp[-5].TypeVal.S);
5943 Value* tmpVal = getVal(yyvsp[-5].TypeVal.PAT->get(), yyvsp[-3].ValIDVal);
5944 yyvsp[-1].ValIDVal.S.makeSignless();
5945 BasicBlock* tmpBB = getBBVal(yyvsp[-1].ValIDVal);
5946 yyval.PHIList.P->push_back(std::make_pair(tmpVal, tmpBB));
5947 delete yyvsp[-5].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005948 ;}
5949 break;
5950
Reid Spencerd2920cd2007-03-21 17:27:53 +00005951 case 274:
David Greene718fda32007-08-01 03:59:32 +00005952#line 3477 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005953 {
David Greene718fda32007-08-01 03:59:32 +00005954 yyval.PHIList = yyvsp[-6].PHIList;
5955 yyvsp[-3].ValIDVal.S.copy(yyvsp[-6].PHIList.S);
5956 Value* tmpVal = getVal(yyvsp[-6].PHIList.P->front().first->getType(), yyvsp[-3].ValIDVal);
5957 yyvsp[-1].ValIDVal.S.makeSignless();
5958 BasicBlock* tmpBB = getBBVal(yyvsp[-1].ValIDVal);
5959 yyvsp[-6].PHIList.P->push_back(std::make_pair(tmpVal, tmpBB));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005960 ;}
5961 break;
5962
Reid Spencerd2920cd2007-03-21 17:27:53 +00005963 case 275:
David Greene718fda32007-08-01 03:59:32 +00005964#line 3487 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005965 { // Used for call statements, and memory insts...
David Greene718fda32007-08-01 03:59:32 +00005966 yyval.ValueList = new std::vector<ValueInfo>();
5967 yyval.ValueList->push_back(yyvsp[0].ValueVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005968 ;}
5969 break;
5970
Reid Spencerd2920cd2007-03-21 17:27:53 +00005971 case 276:
David Greene718fda32007-08-01 03:59:32 +00005972#line 3491 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005973 {
David Greene718fda32007-08-01 03:59:32 +00005974 yyval.ValueList = yyvsp[-2].ValueList;
5975 yyvsp[-2].ValueList->push_back(yyvsp[0].ValueVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005976 ;}
5977 break;
5978
Reid Spencerd2920cd2007-03-21 17:27:53 +00005979 case 278:
David Greene718fda32007-08-01 03:59:32 +00005980#line 3499 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5981 { yyval.ValueList = 0; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005982 break;
5983
Reid Spencerd2920cd2007-03-21 17:27:53 +00005984 case 279:
David Greene718fda32007-08-01 03:59:32 +00005985#line 3503 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005986 {
David Greene718fda32007-08-01 03:59:32 +00005987 yyval.BoolVal = true;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005988 ;}
5989 break;
5990
Reid Spencerd2920cd2007-03-21 17:27:53 +00005991 case 280:
David Greene718fda32007-08-01 03:59:32 +00005992#line 3506 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005993 {
David Greene718fda32007-08-01 03:59:32 +00005994 yyval.BoolVal = false;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005995 ;}
5996 break;
5997
Reid Spencerd2920cd2007-03-21 17:27:53 +00005998 case 281:
David Greene718fda32007-08-01 03:59:32 +00005999#line 3512 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006000 {
David Greene718fda32007-08-01 03:59:32 +00006001 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6002 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6003 const Type* Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006004 if (!Ty->isInteger() && !Ty->isFloatingPoint() && !isa<VectorType>(Ty))
Reid Spencer950bf602007-01-26 08:19:09 +00006005 error("Arithmetic operator requires integer, FP, or packed operands");
Reid Spencer9d6565a2007-02-15 02:26:10 +00006006 if (isa<VectorType>(Ty) &&
David Greene718fda32007-08-01 03:59:32 +00006007 (yyvsp[-4].BinaryOpVal == URemOp || yyvsp[-4].BinaryOpVal == SRemOp || yyvsp[-4].BinaryOpVal == FRemOp || yyvsp[-4].BinaryOpVal == RemOp))
Chris Lattner4227bdb2007-02-19 07:34:02 +00006008 error("Remainder not supported on vector types");
Reid Spencer950bf602007-01-26 08:19:09 +00006009 // Upgrade the opcode from obsolete versions before we do anything with it.
David Greene718fda32007-08-01 03:59:32 +00006010 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-4].BinaryOpVal, Ty, yyvsp[-3].TypeVal.S);
6011 Value* val1 = getVal(Ty, yyvsp[-2].ValIDVal);
6012 Value* val2 = getVal(Ty, yyvsp[0].ValIDVal);
6013 yyval.InstVal.I = BinaryOperator::create(Opcode, val1, val2);
6014 if (yyval.InstVal.I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006015 error("binary operator returned null");
David Greene718fda32007-08-01 03:59:32 +00006016 yyval.InstVal.S.copy(yyvsp[-3].TypeVal.S);
6017 delete yyvsp[-3].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006018 ;}
6019 break;
6020
Reid Spencerd2920cd2007-03-21 17:27:53 +00006021 case 282:
David Greene718fda32007-08-01 03:59:32 +00006022#line 3531 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006023 {
David Greene718fda32007-08-01 03:59:32 +00006024 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6025 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6026 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006027 if (!Ty->isInteger()) {
Reid Spencer9d6565a2007-02-15 02:26:10 +00006028 if (!isa<VectorType>(Ty) ||
6029 !cast<VectorType>(Ty)->getElementType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00006030 error("Logical operator requires integral operands");
6031 }
David Greene718fda32007-08-01 03:59:32 +00006032 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-4].BinaryOpVal, Ty, yyvsp[-3].TypeVal.S);
6033 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
6034 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
6035 yyval.InstVal.I = BinaryOperator::create(Opcode, tmpVal1, tmpVal2);
6036 if (yyval.InstVal.I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006037 error("binary operator returned null");
David Greene718fda32007-08-01 03:59:32 +00006038 yyval.InstVal.S.copy(yyvsp[-3].TypeVal.S);
6039 delete yyvsp[-3].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006040 ;}
6041 break;
6042
Reid Spencerd2920cd2007-03-21 17:27:53 +00006043 case 283:
David Greene718fda32007-08-01 03:59:32 +00006044#line 3549 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006045 {
David Greene718fda32007-08-01 03:59:32 +00006046 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6047 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6048 const Type* Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006049 if(isa<VectorType>(Ty))
6050 error("VectorTypes currently not supported in setcc instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00006051 unsigned short pred;
David Greene718fda32007-08-01 03:59:32 +00006052 Instruction::OtherOps Opcode = getCompareOp(yyvsp[-4].BinaryOpVal, pred, Ty, yyvsp[-3].TypeVal.S);
6053 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
6054 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
6055 yyval.InstVal.I = CmpInst::create(Opcode, pred, tmpVal1, tmpVal2);
6056 if (yyval.InstVal.I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006057 error("binary operator returned null");
David Greene718fda32007-08-01 03:59:32 +00006058 yyval.InstVal.S.makeUnsigned();
6059 delete yyvsp[-3].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006060 ;}
6061 break;
6062
Reid Spencerd2920cd2007-03-21 17:27:53 +00006063 case 284:
David Greene718fda32007-08-01 03:59:32 +00006064#line 3565 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006065 {
David Greene718fda32007-08-01 03:59:32 +00006066 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6067 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6068 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006069 if (isa<VectorType>(Ty))
6070 error("VectorTypes currently not supported in icmp instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00006071 else if (!Ty->isInteger() && !isa<PointerType>(Ty))
6072 error("icmp requires integer or pointer typed operands");
David Greene718fda32007-08-01 03:59:32 +00006073 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
6074 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
6075 yyval.InstVal.I = new ICmpInst(yyvsp[-4].IPred, tmpVal1, tmpVal2);
6076 yyval.InstVal.S.makeUnsigned();
6077 delete yyvsp[-3].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006078 ;}
6079 break;
6080
Reid Spencerd2920cd2007-03-21 17:27:53 +00006081 case 285:
David Greene718fda32007-08-01 03:59:32 +00006082#line 3579 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006083 {
David Greene718fda32007-08-01 03:59:32 +00006084 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6085 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6086 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006087 if (isa<VectorType>(Ty))
6088 error("VectorTypes currently not supported in fcmp instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00006089 else if (!Ty->isFloatingPoint())
6090 error("fcmp instruction requires floating point operands");
David Greene718fda32007-08-01 03:59:32 +00006091 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
6092 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
6093 yyval.InstVal.I = new FCmpInst(yyvsp[-4].FPred, tmpVal1, tmpVal2);
6094 yyval.InstVal.S.makeUnsigned();
6095 delete yyvsp[-3].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006096 ;}
6097 break;
6098
Reid Spencerd2920cd2007-03-21 17:27:53 +00006099 case 286:
David Greene718fda32007-08-01 03:59:32 +00006100#line 3593 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006101 {
Reid Spencer950bf602007-01-26 08:19:09 +00006102 warning("Use of obsolete 'not' instruction: Replacing with 'xor");
David Greene718fda32007-08-01 03:59:32 +00006103 const Type *Ty = yyvsp[0].ValueVal.V->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00006104 Value *Ones = ConstantInt::getAllOnesValue(Ty);
6105 if (Ones == 0)
6106 error("Expected integral type for not instruction");
David Greene718fda32007-08-01 03:59:32 +00006107 yyval.InstVal.I = BinaryOperator::create(Instruction::Xor, yyvsp[0].ValueVal.V, Ones);
6108 if (yyval.InstVal.I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006109 error("Could not create a xor instruction");
David Greene718fda32007-08-01 03:59:32 +00006110 yyval.InstVal.S.copy(yyvsp[0].ValueVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006111 ;}
6112 break;
6113
Reid Spencerd2920cd2007-03-21 17:27:53 +00006114 case 287:
David Greene718fda32007-08-01 03:59:32 +00006115#line 3604 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006116 {
David Greene718fda32007-08-01 03:59:32 +00006117 if (!yyvsp[0].ValueVal.V->getType()->isInteger() ||
6118 cast<IntegerType>(yyvsp[0].ValueVal.V->getType())->getBitWidth() != 8)
Reid Spencer950bf602007-01-26 08:19:09 +00006119 error("Shift amount must be int8");
David Greene718fda32007-08-01 03:59:32 +00006120 const Type* Ty = yyvsp[-2].ValueVal.V->getType();
Reid Spencer832254e2007-02-02 02:16:23 +00006121 if (!Ty->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00006122 error("Shift constant expression requires integer operand");
Reid Spencer832254e2007-02-02 02:16:23 +00006123 Value* ShiftAmt = 0;
6124 if (cast<IntegerType>(Ty)->getBitWidth() > Type::Int8Ty->getBitWidth())
David Greene718fda32007-08-01 03:59:32 +00006125 if (Constant *C = dyn_cast<Constant>(yyvsp[0].ValueVal.V))
Reid Spencer832254e2007-02-02 02:16:23 +00006126 ShiftAmt = ConstantExpr::getZExt(C, Ty);
6127 else
David Greene718fda32007-08-01 03:59:32 +00006128 ShiftAmt = new ZExtInst(yyvsp[0].ValueVal.V, Ty, makeNameUnique("shift"), CurBB);
Reid Spencer832254e2007-02-02 02:16:23 +00006129 else
David Greene718fda32007-08-01 03:59:32 +00006130 ShiftAmt = yyvsp[0].ValueVal.V;
6131 yyval.InstVal.I = BinaryOperator::create(getBinaryOp(yyvsp[-3].BinaryOpVal, Ty, yyvsp[-2].ValueVal.S), yyvsp[-2].ValueVal.V, ShiftAmt);
6132 yyval.InstVal.S.copy(yyvsp[-2].ValueVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006133 ;}
6134 break;
6135
Reid Spencerd2920cd2007-03-21 17:27:53 +00006136 case 288:
David Greene718fda32007-08-01 03:59:32 +00006137#line 3622 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006138 {
David Greene718fda32007-08-01 03:59:32 +00006139 const Type *DstTy = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006140 if (!DstTy->isFirstClassType())
6141 error("cast instruction to a non-primitive type: '" +
6142 DstTy->getDescription() + "'");
David Greene718fda32007-08-01 03:59:32 +00006143 yyval.InstVal.I = cast<Instruction>(getCast(yyvsp[-3].CastOpVal, yyvsp[-2].ValueVal.V, yyvsp[-2].ValueVal.S, DstTy, yyvsp[0].TypeVal.S, true));
6144 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
6145 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006146 ;}
6147 break;
6148
Reid Spencerd2920cd2007-03-21 17:27:53 +00006149 case 289:
David Greene718fda32007-08-01 03:59:32 +00006150#line 3631 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006151 {
David Greene718fda32007-08-01 03:59:32 +00006152 if (!yyvsp[-4].ValueVal.V->getType()->isInteger() ||
6153 cast<IntegerType>(yyvsp[-4].ValueVal.V->getType())->getBitWidth() != 1)
Reid Spencer950bf602007-01-26 08:19:09 +00006154 error("select condition must be bool");
David Greene718fda32007-08-01 03:59:32 +00006155 if (yyvsp[-2].ValueVal.V->getType() != yyvsp[0].ValueVal.V->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00006156 error("select value types should match");
David Greene718fda32007-08-01 03:59:32 +00006157 yyval.InstVal.I = new SelectInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
6158 yyval.InstVal.S.copy(yyvsp[-2].ValueVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006159 ;}
6160 break;
6161
Reid Spencerd2920cd2007-03-21 17:27:53 +00006162 case 290:
David Greene718fda32007-08-01 03:59:32 +00006163#line 3640 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006164 {
David Greene718fda32007-08-01 03:59:32 +00006165 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006166 NewVarArgs = true;
David Greene718fda32007-08-01 03:59:32 +00006167 yyval.InstVal.I = new VAArgInst(yyvsp[-2].ValueVal.V, Ty);
6168 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
6169 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006170 ;}
6171 break;
6172
Reid Spencerd2920cd2007-03-21 17:27:53 +00006173 case 291:
David Greene718fda32007-08-01 03:59:32 +00006174#line 3647 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006175 {
David Greene718fda32007-08-01 03:59:32 +00006176 const Type* ArgTy = yyvsp[-2].ValueVal.V->getType();
6177 const Type* DstTy = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006178 ObsoleteVarArgs = true;
6179 Function* NF = cast<Function>(CurModule.CurrentModule->
6180 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
6181
6182 //b = vaarg a, t ->
6183 //foo = alloca 1 of t
6184 //bar = vacopy a
6185 //store bar -> foo
6186 //b = vaarg foo, t
6187 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vaarg.fix");
6188 CurBB->getInstList().push_back(foo);
David Greene718fda32007-08-01 03:59:32 +00006189 CallInst* bar = new CallInst(NF, yyvsp[-2].ValueVal.V);
Reid Spencer950bf602007-01-26 08:19:09 +00006190 CurBB->getInstList().push_back(bar);
6191 CurBB->getInstList().push_back(new StoreInst(bar, foo));
David Greene718fda32007-08-01 03:59:32 +00006192 yyval.InstVal.I = new VAArgInst(foo, DstTy);
6193 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
6194 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006195 ;}
6196 break;
6197
Reid Spencerd2920cd2007-03-21 17:27:53 +00006198 case 292:
David Greene718fda32007-08-01 03:59:32 +00006199#line 3668 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006200 {
David Greene718fda32007-08-01 03:59:32 +00006201 const Type* ArgTy = yyvsp[-2].ValueVal.V->getType();
6202 const Type* DstTy = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006203 ObsoleteVarArgs = true;
6204 Function* NF = cast<Function>(CurModule.CurrentModule->
6205 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
6206
6207 //b = vanext a, t ->
6208 //foo = alloca 1 of t
6209 //bar = vacopy a
6210 //store bar -> foo
6211 //tmp = vaarg foo, t
6212 //b = load foo
6213 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vanext.fix");
6214 CurBB->getInstList().push_back(foo);
David Greene718fda32007-08-01 03:59:32 +00006215 CallInst* bar = new CallInst(NF, yyvsp[-2].ValueVal.V);
Reid Spencer950bf602007-01-26 08:19:09 +00006216 CurBB->getInstList().push_back(bar);
6217 CurBB->getInstList().push_back(new StoreInst(bar, foo));
6218 Instruction* tmp = new VAArgInst(foo, DstTy);
6219 CurBB->getInstList().push_back(tmp);
David Greene718fda32007-08-01 03:59:32 +00006220 yyval.InstVal.I = new LoadInst(foo);
6221 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
6222 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006223 ;}
6224 break;
6225
Reid Spencerd2920cd2007-03-21 17:27:53 +00006226 case 293:
David Greene718fda32007-08-01 03:59:32 +00006227#line 3692 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006228 {
David Greene718fda32007-08-01 03:59:32 +00006229 if (!ExtractElementInst::isValidOperands(yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Reid Spencer950bf602007-01-26 08:19:09 +00006230 error("Invalid extractelement operands");
David Greene718fda32007-08-01 03:59:32 +00006231 yyval.InstVal.I = new ExtractElementInst(yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
6232 yyval.InstVal.S.copy(yyvsp[-2].ValueVal.S.get(0));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006233 ;}
6234 break;
6235
Reid Spencerd2920cd2007-03-21 17:27:53 +00006236 case 294:
David Greene718fda32007-08-01 03:59:32 +00006237#line 3698 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006238 {
David Greene718fda32007-08-01 03:59:32 +00006239 if (!InsertElementInst::isValidOperands(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Reid Spencer950bf602007-01-26 08:19:09 +00006240 error("Invalid insertelement operands");
David Greene718fda32007-08-01 03:59:32 +00006241 yyval.InstVal.I = new InsertElementInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
6242 yyval.InstVal.S.copy(yyvsp[-4].ValueVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006243 ;}
6244 break;
6245
Reid Spencerd2920cd2007-03-21 17:27:53 +00006246 case 295:
David Greene718fda32007-08-01 03:59:32 +00006247#line 3704 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006248 {
David Greene718fda32007-08-01 03:59:32 +00006249 if (!ShuffleVectorInst::isValidOperands(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Reid Spencer950bf602007-01-26 08:19:09 +00006250 error("Invalid shufflevector operands");
David Greene718fda32007-08-01 03:59:32 +00006251 yyval.InstVal.I = new ShuffleVectorInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
6252 yyval.InstVal.S.copy(yyvsp[-4].ValueVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006253 ;}
6254 break;
6255
Reid Spencerd2920cd2007-03-21 17:27:53 +00006256 case 296:
David Greene718fda32007-08-01 03:59:32 +00006257#line 3710 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006258 {
David Greene718fda32007-08-01 03:59:32 +00006259 const Type *Ty = yyvsp[0].PHIList.P->front().first->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00006260 if (!Ty->isFirstClassType())
6261 error("PHI node operands must be of first class type");
6262 PHINode *PHI = new PHINode(Ty);
David Greene718fda32007-08-01 03:59:32 +00006263 PHI->reserveOperandSpace(yyvsp[0].PHIList.P->size());
6264 while (yyvsp[0].PHIList.P->begin() != yyvsp[0].PHIList.P->end()) {
6265 if (yyvsp[0].PHIList.P->front().first->getType() != Ty)
Reid Spencer950bf602007-01-26 08:19:09 +00006266 error("All elements of a PHI node must be of the same type");
David Greene718fda32007-08-01 03:59:32 +00006267 PHI->addIncoming(yyvsp[0].PHIList.P->front().first, yyvsp[0].PHIList.P->front().second);
6268 yyvsp[0].PHIList.P->pop_front();
Reid Spencer950bf602007-01-26 08:19:09 +00006269 }
David Greene718fda32007-08-01 03:59:32 +00006270 yyval.InstVal.I = PHI;
6271 yyval.InstVal.S.copy(yyvsp[0].PHIList.S);
6272 delete yyvsp[0].PHIList.P; // Free the list...
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006273 ;}
6274 break;
Reid Spencer950bf602007-01-26 08:19:09 +00006275
Reid Spencerd2920cd2007-03-21 17:27:53 +00006276 case 297:
David Greene718fda32007-08-01 03:59:32 +00006277#line 3726 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006278 {
Reid Spencer950bf602007-01-26 08:19:09 +00006279 // Handle the short call syntax
6280 const PointerType *PFTy;
6281 const FunctionType *FTy;
Reid Spencerbb1fd572007-03-21 17:15:50 +00006282 Signedness FTySign;
David Greene718fda32007-08-01 03:59:32 +00006283 if (!(PFTy = dyn_cast<PointerType>(yyvsp[-4].TypeVal.PAT->get())) ||
Reid Spencer950bf602007-01-26 08:19:09 +00006284 !(FTy = dyn_cast<FunctionType>(PFTy->getElementType()))) {
6285 // Pull out the types of all of the arguments...
6286 std::vector<const Type*> ParamTypes;
David Greene718fda32007-08-01 03:59:32 +00006287 FTySign.makeComposite(yyvsp[-4].TypeVal.S);
6288 if (yyvsp[-1].ValueList) {
6289 for (std::vector<ValueInfo>::iterator I = yyvsp[-1].ValueList->begin(), E = yyvsp[-1].ValueList->end();
Reid Spencerbb1fd572007-03-21 17:15:50 +00006290 I != E; ++I) {
Reid Spencer950bf602007-01-26 08:19:09 +00006291 ParamTypes.push_back((*I).V->getType());
Reid Spencerbb1fd572007-03-21 17:15:50 +00006292 FTySign.add(I->S);
6293 }
Reid Spencer950bf602007-01-26 08:19:09 +00006294 }
6295
6296 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
6297 if (isVarArg) ParamTypes.pop_back();
6298
David Greene718fda32007-08-01 03:59:32 +00006299 const Type *RetTy = yyvsp[-4].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006300 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
6301 error("Functions cannot return aggregate types");
6302
Reid Spencer7b5d4662007-04-09 06:16:21 +00006303 // Deal with CSRetCC
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006304 ParamAttrsList *PAL = 0;
David Greene718fda32007-08-01 03:59:32 +00006305 if (yyvsp[-5].UIntVal == OldCallingConv::CSRet) {
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006306 ParamAttrsVector Attrs;
6307 ParamAttrsWithIndex PAWI;
6308 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
6309 Attrs.push_back(PAWI);
6310 PAL = ParamAttrsList::get(Attrs);
Reid Spencer7b5d4662007-04-09 06:16:21 +00006311 }
6312
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006313 FTy = FunctionType::get(RetTy, ParamTypes, isVarArg, PAL);
Reid Spencer950bf602007-01-26 08:19:09 +00006314 PFTy = PointerType::get(FTy);
David Greene718fda32007-08-01 03:59:32 +00006315 yyval.InstVal.S.copy(yyvsp[-4].TypeVal.S);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006316 } else {
David Greene718fda32007-08-01 03:59:32 +00006317 FTySign = yyvsp[-4].TypeVal.S;
Reid Spencera3b12dd2007-04-07 16:14:01 +00006318 // Get the signedness of the result type. $3 is the pointer to the
6319 // function type so we get the 0th element to extract the function type,
6320 // and then the 0th element again to get the result type.
David Greene718fda32007-08-01 03:59:32 +00006321 yyval.InstVal.S.copy(yyvsp[-4].TypeVal.S.get(0).get(0));
Reid Spencer950bf602007-01-26 08:19:09 +00006322 }
David Greene718fda32007-08-01 03:59:32 +00006323 yyvsp[-3].ValIDVal.S.makeComposite(FTySign);
Reid Spencer950bf602007-01-26 08:19:09 +00006324
6325 // First upgrade any intrinsic calls.
6326 std::vector<Value*> Args;
David Greene718fda32007-08-01 03:59:32 +00006327 if (yyvsp[-1].ValueList)
6328 for (unsigned i = 0, e = yyvsp[-1].ValueList->size(); i < e; ++i)
6329 Args.push_back((*yyvsp[-1].ValueList)[i].V);
6330 Instruction *Inst = upgradeIntrinsicCall(FTy->getReturnType(), yyvsp[-3].ValIDVal, Args);
Reid Spencer950bf602007-01-26 08:19:09 +00006331
6332 // If we got an upgraded intrinsic
6333 if (Inst) {
David Greene718fda32007-08-01 03:59:32 +00006334 yyval.InstVal.I = Inst;
Reid Spencer950bf602007-01-26 08:19:09 +00006335 } else {
6336 // Get the function we're calling
David Greene718fda32007-08-01 03:59:32 +00006337 Value *V = getVal(PFTy, yyvsp[-3].ValIDVal);
Reid Spencer950bf602007-01-26 08:19:09 +00006338
6339 // Check the argument values match
David Greene718fda32007-08-01 03:59:32 +00006340 if (!yyvsp[-1].ValueList) { // Has no arguments?
Reid Spencer950bf602007-01-26 08:19:09 +00006341 // Make sure no arguments is a good thing!
6342 if (FTy->getNumParams() != 0)
6343 error("No arguments passed to a function that expects arguments");
6344 } else { // Has arguments?
6345 // Loop through FunctionType's arguments and ensure they are specified
6346 // correctly!
6347 //
6348 FunctionType::param_iterator I = FTy->param_begin();
6349 FunctionType::param_iterator E = FTy->param_end();
David Greene718fda32007-08-01 03:59:32 +00006350 std::vector<ValueInfo>::iterator ArgI = yyvsp[-1].ValueList->begin(), ArgE = yyvsp[-1].ValueList->end();
Reid Spencer950bf602007-01-26 08:19:09 +00006351
6352 for (; ArgI != ArgE && I != E; ++ArgI, ++I)
6353 if ((*ArgI).V->getType() != *I)
6354 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
6355 (*I)->getDescription() + "'");
6356
6357 if (I != E || (ArgI != ArgE && !FTy->isVarArg()))
6358 error("Invalid number of parameters detected");
6359 }
6360
6361 // Create the call instruction
David Greene718fda32007-08-01 03:59:32 +00006362 CallInst *CI = new CallInst(V, Args.begin(), Args.end());
6363 CI->setTailCall(yyvsp[-6].BoolVal);
6364 CI->setCallingConv(upgradeCallingConv(yyvsp[-5].UIntVal));
6365 yyval.InstVal.I = CI;
Reid Spencer950bf602007-01-26 08:19:09 +00006366 }
David Greene718fda32007-08-01 03:59:32 +00006367 delete yyvsp[-4].TypeVal.PAT;
6368 delete yyvsp[-1].ValueList;
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006369 lastCallingConv = OldCallingConv::C;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006370 ;}
6371 break;
6372
Reid Spencerd2920cd2007-03-21 17:27:53 +00006373 case 298:
David Greene718fda32007-08-01 03:59:32 +00006374#line 3819 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006375 {
David Greene718fda32007-08-01 03:59:32 +00006376 yyval.InstVal = yyvsp[0].InstVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006377 ;}
6378 break;
6379
Reid Spencerd2920cd2007-03-21 17:27:53 +00006380 case 299:
David Greene718fda32007-08-01 03:59:32 +00006381#line 3827 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
6382 { yyval.ValueList = yyvsp[0].ValueList; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006383 break;
6384
Reid Spencerd2920cd2007-03-21 17:27:53 +00006385 case 300:
David Greene718fda32007-08-01 03:59:32 +00006386#line 3828 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
6387 { yyval.ValueList = new std::vector<ValueInfo>(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006388 break;
6389
Reid Spencerd2920cd2007-03-21 17:27:53 +00006390 case 301:
David Greene718fda32007-08-01 03:59:32 +00006391#line 3832 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
6392 { yyval.BoolVal = true; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006393 break;
6394
Reid Spencerd2920cd2007-03-21 17:27:53 +00006395 case 302:
David Greene718fda32007-08-01 03:59:32 +00006396#line 3833 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
6397 { yyval.BoolVal = false; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006398 break;
6399
Reid Spencerd2920cd2007-03-21 17:27:53 +00006400 case 303:
David Greene718fda32007-08-01 03:59:32 +00006401#line 3837 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006402 {
David Greene718fda32007-08-01 03:59:32 +00006403 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
6404 yyval.InstVal.S.makeComposite(yyvsp[-1].TypeVal.S);
6405 yyval.InstVal.I = new MallocInst(Ty, 0, yyvsp[0].UIntVal);
6406 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006407 ;}
6408 break;
6409
Reid Spencerd2920cd2007-03-21 17:27:53 +00006410 case 304:
David Greene718fda32007-08-01 03:59:32 +00006411#line 3843 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006412 {
David Greene718fda32007-08-01 03:59:32 +00006413 const Type *Ty = yyvsp[-4].TypeVal.PAT->get();
6414 yyvsp[-1].ValIDVal.S.makeUnsigned();
6415 yyval.InstVal.S.makeComposite(yyvsp[-4].TypeVal.S);
6416 yyval.InstVal.I = new MallocInst(Ty, getVal(yyvsp[-2].PrimType.T, yyvsp[-1].ValIDVal), yyvsp[0].UIntVal);
6417 delete yyvsp[-4].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006418 ;}
6419 break;
6420
Reid Spencerd2920cd2007-03-21 17:27:53 +00006421 case 305:
David Greene718fda32007-08-01 03:59:32 +00006422#line 3850 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006423 {
David Greene718fda32007-08-01 03:59:32 +00006424 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
6425 yyval.InstVal.S.makeComposite(yyvsp[-1].TypeVal.S);
6426 yyval.InstVal.I = new AllocaInst(Ty, 0, yyvsp[0].UIntVal);
6427 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006428 ;}
6429 break;
6430
Reid Spencerd2920cd2007-03-21 17:27:53 +00006431 case 306:
David Greene718fda32007-08-01 03:59:32 +00006432#line 3856 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006433 {
David Greene718fda32007-08-01 03:59:32 +00006434 const Type *Ty = yyvsp[-4].TypeVal.PAT->get();
6435 yyvsp[-1].ValIDVal.S.makeUnsigned();
6436 yyval.InstVal.S.makeComposite(yyvsp[-2].PrimType.S);
6437 yyval.InstVal.I = new AllocaInst(Ty, getVal(yyvsp[-2].PrimType.T, yyvsp[-1].ValIDVal), yyvsp[0].UIntVal);
6438 delete yyvsp[-4].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006439 ;}
6440 break;
6441
Reid Spencerd2920cd2007-03-21 17:27:53 +00006442 case 307:
David Greene718fda32007-08-01 03:59:32 +00006443#line 3863 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006444 {
David Greene718fda32007-08-01 03:59:32 +00006445 const Type *PTy = yyvsp[0].ValueVal.V->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00006446 if (!isa<PointerType>(PTy))
6447 error("Trying to free nonpointer type '" + PTy->getDescription() + "'");
David Greene718fda32007-08-01 03:59:32 +00006448 yyval.InstVal.I = new FreeInst(yyvsp[0].ValueVal.V);
6449 yyval.InstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006450 ;}
6451 break;
6452
Reid Spencerd2920cd2007-03-21 17:27:53 +00006453 case 308:
David Greene718fda32007-08-01 03:59:32 +00006454#line 3870 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006455 {
David Greene718fda32007-08-01 03:59:32 +00006456 const Type* Ty = yyvsp[-1].TypeVal.PAT->get();
6457 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
Reid Spencer950bf602007-01-26 08:19:09 +00006458 if (!isa<PointerType>(Ty))
6459 error("Can't load from nonpointer type: " + Ty->getDescription());
6460 if (!cast<PointerType>(Ty)->getElementType()->isFirstClassType())
6461 error("Can't load from pointer of non-first-class type: " +
6462 Ty->getDescription());
David Greene718fda32007-08-01 03:59:32 +00006463 Value* tmpVal = getVal(Ty, yyvsp[0].ValIDVal);
6464 yyval.InstVal.I = new LoadInst(tmpVal, "", yyvsp[-3].BoolVal);
6465 yyval.InstVal.S.copy(yyvsp[-1].TypeVal.S.get(0));
6466 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006467 ;}
6468 break;
6469
Reid Spencerd2920cd2007-03-21 17:27:53 +00006470 case 309:
David Greene718fda32007-08-01 03:59:32 +00006471#line 3883 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006472 {
David Greene718fda32007-08-01 03:59:32 +00006473 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
6474 const PointerType *PTy = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Reid Spencered96d1e2007-02-08 09:08:52 +00006475 if (!PTy)
6476 error("Can't store to a nonpointer type: " +
David Greene718fda32007-08-01 03:59:32 +00006477 yyvsp[-1].TypeVal.PAT->get()->getDescription());
Reid Spencered96d1e2007-02-08 09:08:52 +00006478 const Type *ElTy = PTy->getElementType();
David Greene718fda32007-08-01 03:59:32 +00006479 Value *StoreVal = yyvsp[-3].ValueVal.V;
6480 Value* tmpVal = getVal(PTy, yyvsp[0].ValIDVal);
6481 if (ElTy != yyvsp[-3].ValueVal.V->getType()) {
6482 StoreVal = handleSRetFuncTypeMerge(yyvsp[-3].ValueVal.V, ElTy);
Reid Spencered96d1e2007-02-08 09:08:52 +00006483 if (!StoreVal)
David Greene718fda32007-08-01 03:59:32 +00006484 error("Can't store '" + yyvsp[-3].ValueVal.V->getType()->getDescription() +
Reid Spencered96d1e2007-02-08 09:08:52 +00006485 "' into space of type '" + ElTy->getDescription() + "'");
6486 else {
6487 PTy = PointerType::get(StoreVal->getType());
6488 if (Constant *C = dyn_cast<Constant>(tmpVal))
6489 tmpVal = ConstantExpr::getBitCast(C, PTy);
6490 else
6491 tmpVal = new BitCastInst(tmpVal, PTy, "upgrd.cast", CurBB);
6492 }
6493 }
David Greene718fda32007-08-01 03:59:32 +00006494 yyval.InstVal.I = new StoreInst(StoreVal, tmpVal, yyvsp[-5].BoolVal);
6495 yyval.InstVal.S.makeSignless();
6496 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006497 ;}
6498 break;
6499
Reid Spencerd2920cd2007-03-21 17:27:53 +00006500 case 310:
David Greene718fda32007-08-01 03:59:32 +00006501#line 3909 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006502 {
David Greene718fda32007-08-01 03:59:32 +00006503 yyvsp[-1].ValIDVal.S.copy(yyvsp[-2].TypeVal.S);
6504 const Type* Ty = yyvsp[-2].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006505 if (!isa<PointerType>(Ty))
6506 error("getelementptr insn requires pointer operand");
6507
6508 std::vector<Value*> VIndices;
David Greene718fda32007-08-01 03:59:32 +00006509 upgradeGEPInstIndices(Ty, yyvsp[0].ValueList, VIndices);
Reid Spencer950bf602007-01-26 08:19:09 +00006510
David Greene718fda32007-08-01 03:59:32 +00006511 Value* tmpVal = getVal(Ty, yyvsp[-1].ValIDVal);
6512 yyval.InstVal.I = new GetElementPtrInst(tmpVal, &VIndices[0], VIndices.size());
6513 ValueInfo VI; VI.V = tmpVal; VI.S.copy(yyvsp[-2].TypeVal.S);
6514 yyval.InstVal.S.copy(getElementSign(VI, VIndices));
6515 delete yyvsp[-2].TypeVal.PAT;
6516 delete yyvsp[0].ValueList;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006517 ;}
6518 break;
6519
6520
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006521 }
6522
David Greene718fda32007-08-01 03:59:32 +00006523/* Line 993 of yacc.c. */
6524#line 6525 "UpgradeParser.tab.c"
Chris Lattnercf3d0612007-02-13 06:04:17 +00006525
6526 yyvsp -= yylen;
6527 yyssp -= yylen;
Reid Spencerb7046c72007-01-29 05:41:34 +00006528
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006529
6530 YY_STACK_PRINT (yyss, yyssp);
Reid Spencere7c3c602006-11-30 06:36:44 +00006531
6532 *++yyvsp = yyval;
6533
6534
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006535 /* Now `shift' the result of the reduction. Determine what state
6536 that goes to, based on the state we popped back to and the rule
6537 number reduced by. */
Reid Spencere7c3c602006-11-30 06:36:44 +00006538
6539 yyn = yyr1[yyn];
6540
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006541 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
6542 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
Reid Spencere7c3c602006-11-30 06:36:44 +00006543 yystate = yytable[yystate];
6544 else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006545 yystate = yydefgoto[yyn - YYNTOKENS];
Reid Spencere7c3c602006-11-30 06:36:44 +00006546
6547 goto yynewstate;
6548
6549
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006550/*------------------------------------.
6551| yyerrlab -- here on detecting error |
6552`------------------------------------*/
6553yyerrlab:
6554 /* If not already recovering from an error, report this error. */
6555 if (!yyerrstatus)
Reid Spencere7c3c602006-11-30 06:36:44 +00006556 {
6557 ++yynerrs;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006558#if YYERROR_VERBOSE
Chris Lattnercf3d0612007-02-13 06:04:17 +00006559 yyn = yypact[yystate];
6560
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006561 if (YYPACT_NINF < yyn && yyn < YYLAST)
Chris Lattnercf3d0612007-02-13 06:04:17 +00006562 {
David Greene718fda32007-08-01 03:59:32 +00006563 YYSIZE_T yysize = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006564 int yytype = YYTRANSLATE (yychar);
David Greene718fda32007-08-01 03:59:32 +00006565 const char* yyprefix;
6566 char *yymsg;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006567 int yyx;
Chris Lattnercf3d0612007-02-13 06:04:17 +00006568
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006569 /* Start YYX at -YYN if negative to avoid negative indexes in
6570 YYCHECK. */
6571 int yyxbegin = yyn < 0 ? -yyn : 0;
6572
6573 /* Stay within bounds of both yycheck and yytname. */
6574 int yychecklim = YYLAST - yyn;
6575 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
David Greene718fda32007-08-01 03:59:32 +00006576 int yycount = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006577
David Greene718fda32007-08-01 03:59:32 +00006578 yyprefix = ", expecting ";
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006579 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
6580 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
6581 {
David Greene718fda32007-08-01 03:59:32 +00006582 yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
6583 yycount += 1;
6584 if (yycount == 5)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006585 {
David Greene718fda32007-08-01 03:59:32 +00006586 yysize = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006587 break;
6588 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006589 }
David Greene718fda32007-08-01 03:59:32 +00006590 yysize += (sizeof ("syntax error, unexpected ")
6591 + yystrlen (yytname[yytype]));
6592 yymsg = (char *) YYSTACK_ALLOC (yysize);
6593 if (yymsg != 0)
Chris Lattnercf3d0612007-02-13 06:04:17 +00006594 {
David Greene718fda32007-08-01 03:59:32 +00006595 char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
6596 yyp = yystpcpy (yyp, yytname[yytype]);
6597
6598 if (yycount < 5)
Chris Lattnercf3d0612007-02-13 06:04:17 +00006599 {
David Greene718fda32007-08-01 03:59:32 +00006600 yyprefix = ", expecting ";
6601 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
6602 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
6603 {
6604 yyp = yystpcpy (yyp, yyprefix);
6605 yyp = yystpcpy (yyp, yytname[yyx]);
6606 yyprefix = " or ";
6607 }
Chris Lattnercf3d0612007-02-13 06:04:17 +00006608 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006609 yyerror (yymsg);
6610 YYSTACK_FREE (yymsg);
Chris Lattnercf3d0612007-02-13 06:04:17 +00006611 }
6612 else
David Greene718fda32007-08-01 03:59:32 +00006613 yyerror ("syntax error; also virtual memory exhausted");
Chris Lattnercf3d0612007-02-13 06:04:17 +00006614 }
6615 else
6616#endif /* YYERROR_VERBOSE */
David Greene718fda32007-08-01 03:59:32 +00006617 yyerror ("syntax error");
Reid Spencere7c3c602006-11-30 06:36:44 +00006618 }
Reid Spencer950bf602007-01-26 08:19:09 +00006619
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006620
Reid Spencer950bf602007-01-26 08:19:09 +00006621
6622 if (yyerrstatus == 3)
6623 {
David Greene718fda32007-08-01 03:59:32 +00006624 /* If just tried and failed to reuse lookahead token after an
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006625 error, discard it. */
Reid Spencer950bf602007-01-26 08:19:09 +00006626
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006627 if (yychar <= YYEOF)
6628 {
David Greene718fda32007-08-01 03:59:32 +00006629 /* If at end of input, pop the error token,
6630 then the rest of the stack, then return failure. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006631 if (yychar == YYEOF)
David Greene718fda32007-08-01 03:59:32 +00006632 for (;;)
6633 {
6634 YYPOPSTACK;
6635 if (yyssp == yyss)
6636 YYABORT;
6637 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
6638 yydestruct (yystos[*yyssp], yyvsp);
6639 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006640 }
6641 else
6642 {
David Greene718fda32007-08-01 03:59:32 +00006643 YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
6644 yydestruct (yytoken, &yylval);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006645 yychar = YYEMPTY;
David Greene718fda32007-08-01 03:59:32 +00006646
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006647 }
6648 }
6649
David Greene718fda32007-08-01 03:59:32 +00006650 /* Else will try to reuse lookahead token after shifting the error
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006651 token. */
6652 goto yyerrlab1;
6653
6654
6655/*---------------------------------------------------.
6656| yyerrorlab -- error raised explicitly by YYERROR. |
6657`---------------------------------------------------*/
6658yyerrorlab:
6659
David Greene718fda32007-08-01 03:59:32 +00006660#ifdef __GNUC__
6661 /* Pacify GCC when the user code never invokes YYERROR and the label
6662 yyerrorlab therefore never appears in user code. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006663 if (0)
6664 goto yyerrorlab;
David Greene718fda32007-08-01 03:59:32 +00006665#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006666
David Greene718fda32007-08-01 03:59:32 +00006667 yyvsp -= yylen;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006668 yyssp -= yylen;
6669 yystate = *yyssp;
6670 goto yyerrlab1;
6671
6672
6673/*-------------------------------------------------------------.
6674| yyerrlab1 -- common code for both syntax error and YYERROR. |
6675`-------------------------------------------------------------*/
6676yyerrlab1:
6677 yyerrstatus = 3; /* Each real token shifted decrements this. */
6678
6679 for (;;)
6680 {
6681 yyn = yypact[yystate];
6682 if (yyn != YYPACT_NINF)
6683 {
6684 yyn += YYTERROR;
6685 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
6686 {
6687 yyn = yytable[yyn];
6688 if (0 < yyn)
6689 break;
6690 }
6691 }
6692
6693 /* Pop the current state because it cannot handle the error token. */
6694 if (yyssp == yyss)
Reid Spencere7c3c602006-11-30 06:36:44 +00006695 YYABORT;
6696
David Greene718fda32007-08-01 03:59:32 +00006697 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
6698 yydestruct (yystos[yystate], yyvsp);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006699 YYPOPSTACK;
6700 yystate = *yyssp;
6701 YY_STACK_PRINT (yyss, yyssp);
Reid Spencere7c3c602006-11-30 06:36:44 +00006702 }
6703
6704 if (yyn == YYFINAL)
6705 YYACCEPT;
6706
David Greene718fda32007-08-01 03:59:32 +00006707 YYDPRINTF ((stderr, "Shifting error token, "));
6708
Reid Spencere7c3c602006-11-30 06:36:44 +00006709 *++yyvsp = yylval;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006710
6711
Reid Spencere7c3c602006-11-30 06:36:44 +00006712 yystate = yyn;
6713 goto yynewstate;
6714
Chris Lattner4227bdb2007-02-19 07:34:02 +00006715
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006716/*-------------------------------------.
6717| yyacceptlab -- YYACCEPT comes here. |
6718`-------------------------------------*/
6719yyacceptlab:
6720 yyresult = 0;
6721 goto yyreturn;
6722
6723/*-----------------------------------.
6724| yyabortlab -- YYABORT comes here. |
6725`-----------------------------------*/
6726yyabortlab:
6727 yyresult = 1;
6728 goto yyreturn;
6729
6730#ifndef yyoverflow
David Greene718fda32007-08-01 03:59:32 +00006731/*----------------------------------------------.
6732| yyoverflowlab -- parser overflow comes here. |
6733`----------------------------------------------*/
6734yyoverflowlab:
6735 yyerror ("parser stack overflow");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006736 yyresult = 2;
6737 /* Fall through. */
Chris Lattner4227bdb2007-02-19 07:34:02 +00006738#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006739
6740yyreturn:
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006741#ifndef yyoverflow
6742 if (yyss != yyssa)
6743 YYSTACK_FREE (yyss);
6744#endif
6745 return yyresult;
Reid Spencere7c3c602006-11-30 06:36:44 +00006746}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006747
6748
David Greene718fda32007-08-01 03:59:32 +00006749#line 3927 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencere7c3c602006-11-30 06:36:44 +00006750
6751
6752int yyerror(const char *ErrorMsg) {
6753 std::string where
6754 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
Reid Spencered96d1e2007-02-08 09:08:52 +00006755 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
Reid Spencer950bf602007-01-26 08:19:09 +00006756 std::string errMsg = where + "error: " + std::string(ErrorMsg);
6757 if (yychar != YYEMPTY && yychar != 0)
6758 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
6759 "'.";
Reid Spencer71d2ec92006-12-31 06:02:26 +00006760 std::cerr << "llvm-upgrade: " << errMsg << '\n';
Reid Spencer950bf602007-01-26 08:19:09 +00006761 std::cout << "llvm-upgrade: parse failed.\n";
Reid Spencere7c3c602006-11-30 06:36:44 +00006762 exit(1);
6763}
Reid Spencer319a7302007-01-05 17:20:02 +00006764
Reid Spencer30d0c582007-01-15 00:26:18 +00006765void warning(const std::string& ErrorMsg) {
Reid Spencer319a7302007-01-05 17:20:02 +00006766 std::string where
6767 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
Reid Spencered96d1e2007-02-08 09:08:52 +00006768 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
Reid Spencer950bf602007-01-26 08:19:09 +00006769 std::string errMsg = where + "warning: " + std::string(ErrorMsg);
6770 if (yychar != YYEMPTY && yychar != 0)
6771 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
6772 "'.";
Reid Spencer319a7302007-01-05 17:20:02 +00006773 std::cerr << "llvm-upgrade: " << errMsg << '\n';
6774}
6775
Reid Spencer950bf602007-01-26 08:19:09 +00006776void error(const std::string& ErrorMsg, int LineNo) {
6777 if (LineNo == -1) LineNo = Upgradelineno;
6778 Upgradelineno = LineNo;
6779 yyerror(ErrorMsg.c_str());
6780}
6781
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006782