blob: c8b747e1958358411cfca67f9ddf339143c946d4 [file] [log] [blame]
David Greene5fd22a82007-09-04 18:46:50 +00001/* A Bison parser, made by GNU Bison 1.875c. */
Reid Spencere7c3c602006-11-30 06:36:44 +00002
David Greene5fd22a82007-09-04 18:46:50 +00003/* Skeleton parser for Yacc-like parsing with Bison,
4 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 Greene5fd22a82007-09-04 18:46:50 +000018 Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +000020
David Greene5fd22a82007-09-04 18:46:50 +000021/* 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. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +000025
David Greene5fd22a82007-09-04 18:46:50 +000026/* Written by Richard Stallman by simplifying the original so called
27 ``semantic'' parser. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +000028
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 Greene5fd22a82007-09-04 18:46:50 +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 Greene5fd22a82007-09-04 18:46:50 +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;
Reid Spencer8166a6c2007-04-02 02:08:35 +00001832
Reid Spencer41b213e2007-04-02 01:14:00 +00001833 case 'v' : {
1834 const Type* PtrTy = PointerType::get(Type::Int8Ty);
1835 std::vector<const Type*> Params;
1836 if (Name == "llvm.va_start" || Name == "llvm.va_end") {
1837 if (Args.size() != 1)
1838 error("Invalid prototype for " + Name + " prototype");
1839 Params.push_back(PtrTy);
1840 const FunctionType *FTy =
1841 FunctionType::get(Type::VoidTy, Params, false);
1842 const PointerType *PFTy = PointerType::get(FTy);
1843 Value* Func = getVal(PFTy, ID);
1844 Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
David Greene718fda32007-08-01 03:59:32 +00001845 return new CallInst(Func, Args.begin(), Args.end());
Reid Spencer41b213e2007-04-02 01:14:00 +00001846 } else if (Name == "llvm.va_copy") {
1847 if (Args.size() != 2)
1848 error("Invalid prototype for " + Name + " prototype");
1849 Params.push_back(PtrTy);
1850 Params.push_back(PtrTy);
1851 const FunctionType *FTy =
1852 FunctionType::get(Type::VoidTy, Params, false);
1853 const PointerType *PFTy = PointerType::get(FTy);
1854 Value* Func = getVal(PFTy, ID);
1855 std::string InstName0(makeNameUnique("va0"));
1856 std::string InstName1(makeNameUnique("va1"));
1857 Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
1858 Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
David Greene718fda32007-08-01 03:59:32 +00001859 return new CallInst(Func, Args.begin(), Args.end());
Reid Spencer41b213e2007-04-02 01:14:00 +00001860 }
Reid Spencer950bf602007-01-26 08:19:09 +00001861 }
1862 }
1863 return 0;
1864}
1865
Reid Spencerff0e4482007-04-16 00:40:57 +00001866const Type* upgradeGEPCEIndices(const Type* PTy,
1867 std::vector<ValueInfo> *Indices,
1868 std::vector<Constant*> &Result) {
1869 const Type *Ty = PTy;
1870 Result.clear();
1871 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1872 Constant *Index = cast<Constant>((*Indices)[i].V);
1873
1874 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1875 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1876 // struct indices to i32 struct indices with ZExt for compatibility.
1877 if (CI->getBitWidth() < 32)
1878 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1879 }
1880
1881 if (isa<SequentialType>(Ty)) {
1882 // Make sure that unsigned SequentialType indices are zext'd to
1883 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1884 // all indices for SequentialType elements. We must retain the same
1885 // semantic (zext) for unsigned types.
1886 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
1887 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
1888 Index = ConstantExpr::getCast(Instruction::ZExt, Index,Type::Int64Ty);
1889 }
1890 }
1891 }
1892 Result.push_back(Index);
David Greene5fd22a82007-09-04 18:46:50 +00001893 Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(),
1894 Result.end(),true);
Reid Spencerff0e4482007-04-16 00:40:57 +00001895 if (!Ty)
1896 error("Index list invalid for constant getelementptr");
1897 }
1898 return Ty;
1899}
1900
1901const Type* upgradeGEPInstIndices(const Type* PTy,
1902 std::vector<ValueInfo> *Indices,
1903 std::vector<Value*> &Result) {
1904 const Type *Ty = PTy;
1905 Result.clear();
1906 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1907 Value *Index = (*Indices)[i].V;
1908
1909 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1910 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1911 // struct indices to i32 struct indices with ZExt for compatibility.
1912 if (CI->getBitWidth() < 32)
1913 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1914 }
1915
1916
1917 if (isa<StructType>(Ty)) { // Only change struct indices
1918 if (!isa<Constant>(Index)) {
1919 error("Invalid non-constant structure index");
1920 return 0;
1921 }
Reid Spencer950bf602007-01-26 08:19:09 +00001922 } else {
1923 // Make sure that unsigned SequentialType indices are zext'd to
1924 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1925 // all indices for SequentialType elements. We must retain the same
1926 // semantic (zext) for unsigned types.
Reid Spencerff0e4482007-04-16 00:40:57 +00001927 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00001928 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
Reid Spencerff0e4482007-04-16 00:40:57 +00001929 if (isa<Constant>(Index))
Reid Spencer950bf602007-01-26 08:19:09 +00001930 Index = ConstantExpr::getCast(Instruction::ZExt,
1931 cast<Constant>(Index), Type::Int64Ty);
1932 else
1933 Index = CastInst::create(Instruction::ZExt, Index, Type::Int64Ty,
Reid Spencer832254e2007-02-02 02:16:23 +00001934 makeNameUnique("gep"), CurBB);
Reid Spencer38f682b2007-01-26 20:31:18 +00001935 }
Reid Spencerff0e4482007-04-16 00:40:57 +00001936 }
Reid Spencer950bf602007-01-26 08:19:09 +00001937 }
Reid Spencerff0e4482007-04-16 00:40:57 +00001938 Result.push_back(Index);
David Greene5fd22a82007-09-04 18:46:50 +00001939 Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(),
1940 Result.end(),true);
Reid Spencerff0e4482007-04-16 00:40:57 +00001941 if (!Ty)
Reid Spencer950bf602007-01-26 08:19:09 +00001942 error("Index list invalid for constant getelementptr");
Reid Spencerff0e4482007-04-16 00:40:57 +00001943 }
1944 return Ty;
Reid Spencer950bf602007-01-26 08:19:09 +00001945}
1946
Reid Spencerb7046c72007-01-29 05:41:34 +00001947unsigned upgradeCallingConv(unsigned CC) {
1948 switch (CC) {
1949 case OldCallingConv::C : return CallingConv::C;
1950 case OldCallingConv::CSRet : return CallingConv::C;
1951 case OldCallingConv::Fast : return CallingConv::Fast;
1952 case OldCallingConv::Cold : return CallingConv::Cold;
1953 case OldCallingConv::X86_StdCall : return CallingConv::X86_StdCall;
1954 case OldCallingConv::X86_FastCall: return CallingConv::X86_FastCall;
1955 default:
1956 return CC;
1957 }
1958}
1959
Reid Spencer950bf602007-01-26 08:19:09 +00001960Module* UpgradeAssembly(const std::string &infile, std::istream& in,
1961 bool debug, bool addAttrs)
Reid Spencere7c3c602006-11-30 06:36:44 +00001962{
1963 Upgradelineno = 1;
1964 CurFilename = infile;
Reid Spencer96839be2006-11-30 16:50:26 +00001965 LexInput = &in;
Reid Spencere77e35e2006-12-01 20:26:20 +00001966 yydebug = debug;
Reid Spencer71d2ec92006-12-31 06:02:26 +00001967 AddAttributes = addAttrs;
Reid Spencer950bf602007-01-26 08:19:09 +00001968 ObsoleteVarArgs = false;
1969 NewVarArgs = false;
Reid Spencere7c3c602006-11-30 06:36:44 +00001970
Reid Spencer950bf602007-01-26 08:19:09 +00001971 CurModule.CurrentModule = new Module(CurFilename);
1972
1973 // Check to make sure the parser succeeded
Reid Spencere7c3c602006-11-30 06:36:44 +00001974 if (yyparse()) {
Reid Spencer950bf602007-01-26 08:19:09 +00001975 if (ParserResult)
1976 delete ParserResult;
Reid Spencer30d0c582007-01-15 00:26:18 +00001977 std::cerr << "llvm-upgrade: parse failed.\n";
Reid Spencer30d0c582007-01-15 00:26:18 +00001978 return 0;
1979 }
1980
Reid Spencer950bf602007-01-26 08:19:09 +00001981 // Check to make sure that parsing produced a result
1982 if (!ParserResult) {
1983 std::cerr << "llvm-upgrade: no parse result.\n";
1984 return 0;
Reid Spencer30d0c582007-01-15 00:26:18 +00001985 }
1986
Reid Spencer950bf602007-01-26 08:19:09 +00001987 // Reset ParserResult variable while saving its value for the result.
1988 Module *Result = ParserResult;
1989 ParserResult = 0;
Reid Spencer30d0c582007-01-15 00:26:18 +00001990
Reid Spencer950bf602007-01-26 08:19:09 +00001991 //Not all functions use vaarg, so make a second check for ObsoleteVarArgs
Reid Spencer30d0c582007-01-15 00:26:18 +00001992 {
Reid Spencer950bf602007-01-26 08:19:09 +00001993 Function* F;
Reid Spencer688b0492007-02-05 21:19:13 +00001994 if ((F = Result->getFunction("llvm.va_start"))
Reid Spencer950bf602007-01-26 08:19:09 +00001995 && F->getFunctionType()->getNumParams() == 0)
1996 ObsoleteVarArgs = true;
Reid Spencer688b0492007-02-05 21:19:13 +00001997 if((F = Result->getFunction("llvm.va_copy"))
Reid Spencer950bf602007-01-26 08:19:09 +00001998 && F->getFunctionType()->getNumParams() == 1)
1999 ObsoleteVarArgs = true;
Reid Spencer280d8012006-12-01 23:40:53 +00002000 }
Reid Spencer319a7302007-01-05 17:20:02 +00002001
Reid Spencer950bf602007-01-26 08:19:09 +00002002 if (ObsoleteVarArgs && NewVarArgs) {
2003 error("This file is corrupt: it uses both new and old style varargs");
2004 return 0;
Reid Spencer319a7302007-01-05 17:20:02 +00002005 }
Reid Spencer319a7302007-01-05 17:20:02 +00002006
Reid Spencer950bf602007-01-26 08:19:09 +00002007 if(ObsoleteVarArgs) {
Reid Spencer688b0492007-02-05 21:19:13 +00002008 if(Function* F = Result->getFunction("llvm.va_start")) {
Reid Spencer950bf602007-01-26 08:19:09 +00002009 if (F->arg_size() != 0) {
2010 error("Obsolete va_start takes 0 argument");
Reid Spencer319a7302007-01-05 17:20:02 +00002011 return 0;
2012 }
Reid Spencer950bf602007-01-26 08:19:09 +00002013
2014 //foo = va_start()
2015 // ->
2016 //bar = alloca typeof(foo)
2017 //va_start(bar)
2018 //foo = load bar
Reid Spencer319a7302007-01-05 17:20:02 +00002019
Reid Spencer950bf602007-01-26 08:19:09 +00002020 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2021 const Type* ArgTy = F->getFunctionType()->getReturnType();
2022 const Type* ArgTyPtr = PointerType::get(ArgTy);
2023 Function* NF = cast<Function>(Result->getOrInsertFunction(
2024 "llvm.va_start", RetTy, ArgTyPtr, (Type *)0));
2025
2026 while (!F->use_empty()) {
2027 CallInst* CI = cast<CallInst>(F->use_back());
2028 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vastart.fix.1", CI);
2029 new CallInst(NF, bar, "", CI);
2030 Value* foo = new LoadInst(bar, "vastart.fix.2", CI);
2031 CI->replaceAllUsesWith(foo);
2032 CI->getParent()->getInstList().erase(CI);
Reid Spencerf8383de2007-01-06 06:04:32 +00002033 }
Reid Spencer950bf602007-01-26 08:19:09 +00002034 Result->getFunctionList().erase(F);
Reid Spencerf8383de2007-01-06 06:04:32 +00002035 }
Reid Spencer950bf602007-01-26 08:19:09 +00002036
Reid Spencer688b0492007-02-05 21:19:13 +00002037 if(Function* F = Result->getFunction("llvm.va_end")) {
Reid Spencer950bf602007-01-26 08:19:09 +00002038 if(F->arg_size() != 1) {
2039 error("Obsolete va_end takes 1 argument");
2040 return 0;
Reid Spencerf8383de2007-01-06 06:04:32 +00002041 }
Reid Spencerf8383de2007-01-06 06:04:32 +00002042
Reid Spencer950bf602007-01-26 08:19:09 +00002043 //vaend foo
2044 // ->
2045 //bar = alloca 1 of typeof(foo)
2046 //vaend bar
2047 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2048 const Type* ArgTy = F->getFunctionType()->getParamType(0);
2049 const Type* ArgTyPtr = PointerType::get(ArgTy);
2050 Function* NF = cast<Function>(Result->getOrInsertFunction(
2051 "llvm.va_end", RetTy, ArgTyPtr, (Type *)0));
Reid Spencerf8383de2007-01-06 06:04:32 +00002052
Reid Spencer950bf602007-01-26 08:19:09 +00002053 while (!F->use_empty()) {
2054 CallInst* CI = cast<CallInst>(F->use_back());
2055 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vaend.fix.1", CI);
2056 new StoreInst(CI->getOperand(1), bar, CI);
2057 new CallInst(NF, bar, "", CI);
2058 CI->getParent()->getInstList().erase(CI);
Reid Spencere77e35e2006-12-01 20:26:20 +00002059 }
Reid Spencer950bf602007-01-26 08:19:09 +00002060 Result->getFunctionList().erase(F);
Reid Spencere77e35e2006-12-01 20:26:20 +00002061 }
Reid Spencer950bf602007-01-26 08:19:09 +00002062
Reid Spencer688b0492007-02-05 21:19:13 +00002063 if(Function* F = Result->getFunction("llvm.va_copy")) {
Reid Spencer950bf602007-01-26 08:19:09 +00002064 if(F->arg_size() != 1) {
2065 error("Obsolete va_copy takes 1 argument");
2066 return 0;
Reid Spencere77e35e2006-12-01 20:26:20 +00002067 }
Reid Spencer950bf602007-01-26 08:19:09 +00002068 //foo = vacopy(bar)
2069 // ->
2070 //a = alloca 1 of typeof(foo)
2071 //b = alloca 1 of typeof(foo)
2072 //store bar -> b
2073 //vacopy(a, b)
2074 //foo = load a
2075
2076 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
2077 const Type* ArgTy = F->getFunctionType()->getReturnType();
2078 const Type* ArgTyPtr = PointerType::get(ArgTy);
2079 Function* NF = cast<Function>(Result->getOrInsertFunction(
2080 "llvm.va_copy", RetTy, ArgTyPtr, ArgTyPtr, (Type *)0));
Reid Spencere77e35e2006-12-01 20:26:20 +00002081
Reid Spencer950bf602007-01-26 08:19:09 +00002082 while (!F->use_empty()) {
2083 CallInst* CI = cast<CallInst>(F->use_back());
David Greene5fd22a82007-09-04 18:46:50 +00002084 Value *Args[2] = {
2085 new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI),
2086 new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI)
2087 };
David Greene718fda32007-08-01 03:59:32 +00002088 new StoreInst(CI->getOperand(1), Args[1], CI);
David Greene5fd22a82007-09-04 18:46:50 +00002089 new CallInst(NF, Args, Args + 2, "", CI);
David Greene718fda32007-08-01 03:59:32 +00002090 Value* foo = new LoadInst(Args[0], "vacopy.fix.3", CI);
Reid Spencer950bf602007-01-26 08:19:09 +00002091 CI->replaceAllUsesWith(foo);
2092 CI->getParent()->getInstList().erase(CI);
2093 }
2094 Result->getFunctionList().erase(F);
Reid Spencer319a7302007-01-05 17:20:02 +00002095 }
2096 }
2097
Reid Spencer52402b02007-01-02 05:45:11 +00002098 return Result;
2099}
2100
Reid Spencer950bf602007-01-26 08:19:09 +00002101} // end llvm namespace
Reid Spencer319a7302007-01-05 17:20:02 +00002102
Reid Spencer950bf602007-01-26 08:19:09 +00002103using namespace llvm;
Reid Spencer30d0c582007-01-15 00:26:18 +00002104
2105
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002106
2107/* Enabling traces. */
2108#ifndef YYDEBUG
2109# define YYDEBUG 0
2110#endif
2111
2112/* Enabling verbose error messages. */
2113#ifdef YYERROR_VERBOSE
2114# undef YYERROR_VERBOSE
2115# define YYERROR_VERBOSE 1
2116#else
2117# define YYERROR_VERBOSE 0
2118#endif
2119
David Greene5fd22a82007-09-04 18:46:50 +00002120#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
2121#line 1750 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
2122typedef union YYSTYPE {
Reid Spencer950bf602007-01-26 08:19:09 +00002123 llvm::Module *ModuleVal;
2124 llvm::Function *FunctionVal;
2125 std::pair<llvm::PATypeInfo, char*> *ArgVal;
2126 llvm::BasicBlock *BasicBlockVal;
Reid Spencerbb1fd572007-03-21 17:15:50 +00002127 llvm::TermInstInfo TermInstVal;
Reid Spencer950bf602007-01-26 08:19:09 +00002128 llvm::InstrInfo InstVal;
2129 llvm::ConstInfo ConstVal;
2130 llvm::ValueInfo ValueVal;
2131 llvm::PATypeInfo TypeVal;
2132 llvm::TypeInfo PrimType;
2133 llvm::PHIListInfo PHIList;
2134 std::list<llvm::PATypeInfo> *TypeList;
2135 std::vector<llvm::ValueInfo> *ValueList;
2136 std::vector<llvm::ConstInfo> *ConstVector;
2137
2138
2139 std::vector<std::pair<llvm::PATypeInfo,char*> > *ArgList;
2140 // Represent the RHS of PHI node
2141 std::vector<std::pair<llvm::Constant*, llvm::BasicBlock*> > *JumpTable;
2142
2143 llvm::GlobalValue::LinkageTypes Linkage;
2144 int64_t SInt64Val;
2145 uint64_t UInt64Val;
2146 int SIntVal;
2147 unsigned UIntVal;
2148 double FPVal;
2149 bool BoolVal;
2150
2151 char *StrVal; // This memory is strdup'd!
2152 llvm::ValID ValIDVal; // strdup'd memory maybe!
2153
2154 llvm::BinaryOps BinaryOpVal;
2155 llvm::TermOps TermOpVal;
2156 llvm::MemoryOps MemOpVal;
2157 llvm::OtherOps OtherOpVal;
2158 llvm::CastOps CastOpVal;
2159 llvm::ICmpInst::Predicate IPred;
2160 llvm::FCmpInst::Predicate FPred;
2161 llvm::Module::Endianness Endianness;
David Greene5fd22a82007-09-04 18:46:50 +00002162} YYSTYPE;
2163/* Line 191 of yacc.c. */
2164#line 2165 "UpgradeParser.tab.c"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002165# define yystype YYSTYPE /* obsolescent; will be withdrawn */
2166# define YYSTYPE_IS_DECLARED 1
2167# define YYSTYPE_IS_TRIVIAL 1
Reid Spencere7c3c602006-11-30 06:36:44 +00002168#endif
2169
Reid Spencer950bf602007-01-26 08:19:09 +00002170
Reid Spencere7c3c602006-11-30 06:36:44 +00002171
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002172/* Copy the second part of user declarations. */
Reid Spencere7c3c602006-11-30 06:36:44 +00002173
2174
David Greene5fd22a82007-09-04 18:46:50 +00002175/* Line 214 of yacc.c. */
2176#line 2177 "UpgradeParser.tab.c"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002177
David Greene5fd22a82007-09-04 18:46:50 +00002178#if ! defined (yyoverflow) || YYERROR_VERBOSE
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002179
2180/* The parser invokes alloca or malloc; define the necessary symbols. */
2181
2182# ifdef YYSTACK_USE_ALLOCA
2183# if YYSTACK_USE_ALLOCA
David Greene5fd22a82007-09-04 18:46:50 +00002184# define YYSTACK_ALLOC alloca
2185# endif
2186# else
2187# if defined (alloca) || defined (_ALLOCA_H)
2188# define YYSTACK_ALLOC alloca
2189# else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002190# ifdef __GNUC__
2191# define YYSTACK_ALLOC __builtin_alloca
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002192# endif
2193# endif
2194# endif
2195
2196# ifdef YYSTACK_ALLOC
David Greene5fd22a82007-09-04 18:46:50 +00002197 /* Pacify GCC's `empty if-body' warning. */
2198# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
Chandler Carruth02202192007-08-04 01:56:21 +00002199# else
David Greene5fd22a82007-09-04 18:46:50 +00002200# if defined (__STDC__) || defined (__cplusplus)
Chandler Carruth02202192007-08-04 01:56:21 +00002201# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
David Greene5fd22a82007-09-04 18:46:50 +00002202# define YYSIZE_T size_t
Chandler Carruth02202192007-08-04 01:56:21 +00002203# endif
David Greene5fd22a82007-09-04 18:46:50 +00002204# define YYSTACK_ALLOC malloc
2205# define YYSTACK_FREE free
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002206# endif
David Greene5fd22a82007-09-04 18:46:50 +00002207#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002208
2209
David Greene5fd22a82007-09-04 18:46:50 +00002210#if (! defined (yyoverflow) \
2211 && (! defined (__cplusplus) \
2212 || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL)))
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002213
2214/* A type that is properly aligned for any stack member. */
2215union yyalloc
2216{
David Greene5fd22a82007-09-04 18:46:50 +00002217 short yyss;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002218 YYSTYPE yyvs;
2219 };
2220
2221/* The size of the maximum gap between one aligned stack and the next. */
2222# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
2223
2224/* The size of an array large to enough to hold all stacks, each with
2225 N elements. */
2226# define YYSTACK_BYTES(N) \
David Greene5fd22a82007-09-04 18:46:50 +00002227 ((N) * (sizeof (short) + sizeof (YYSTYPE)) \
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002228 + YYSTACK_GAP_MAXIMUM)
2229
2230/* Copy COUNT objects from FROM to TO. The source and destination do
2231 not overlap. */
2232# ifndef YYCOPY
David Greene5fd22a82007-09-04 18:46:50 +00002233# if defined (__GNUC__) && 1 < __GNUC__
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002234# define YYCOPY(To, From, Count) \
2235 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
2236# else
2237# define YYCOPY(To, From, Count) \
2238 do \
2239 { \
David Greene5fd22a82007-09-04 18:46:50 +00002240 register YYSIZE_T yyi; \
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002241 for (yyi = 0; yyi < (Count); yyi++) \
2242 (To)[yyi] = (From)[yyi]; \
2243 } \
David Greene5fd22a82007-09-04 18:46:50 +00002244 while (0)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002245# endif
2246# endif
2247
2248/* Relocate STACK from its old location to the new one. The
2249 local variables YYSIZE and YYSTACKSIZE give the old and new number of
2250 elements in the stack, and YYPTR gives the new location of the
2251 stack. Advance YYPTR to a properly aligned location for the next
2252 stack. */
2253# define YYSTACK_RELOCATE(Stack) \
2254 do \
2255 { \
2256 YYSIZE_T yynewbytes; \
2257 YYCOPY (&yyptr->Stack, Stack, yysize); \
2258 Stack = &yyptr->Stack; \
2259 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
2260 yyptr += yynewbytes / sizeof (*yyptr); \
2261 } \
David Greene5fd22a82007-09-04 18:46:50 +00002262 while (0)
Chris Lattnercf3d0612007-02-13 06:04:17 +00002263
Reid Spencere7c3c602006-11-30 06:36:44 +00002264#endif
2265
David Greene5fd22a82007-09-04 18:46:50 +00002266#if defined (__STDC__) || defined (__cplusplus)
2267 typedef signed char yysigned_char;
2268#else
2269 typedef short yysigned_char;
2270#endif
2271
2272/* YYFINAL -- State number of the termination state. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002273#define YYFINAL 4
2274/* YYLAST -- Last index in YYTABLE. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002275#define YYLAST 1630
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002276
David Greene5fd22a82007-09-04 18:46:50 +00002277/* YYNTOKENS -- Number of terminals. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002278#define YYNTOKENS 166
David Greene5fd22a82007-09-04 18:46:50 +00002279/* YYNNTS -- Number of nonterminals. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002280#define YYNNTS 81
David Greene5fd22a82007-09-04 18:46:50 +00002281/* YYNRULES -- Number of rules. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002282#define YYNRULES 310
David Greene5fd22a82007-09-04 18:46:50 +00002283/* YYNRULES -- Number of states. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002284#define YYNSTATES 606
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002285
2286/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
2287#define YYUNDEFTOK 2
2288#define YYMAXUTOK 406
2289
David Greene5fd22a82007-09-04 18:46:50 +00002290#define YYTRANSLATE(YYX) \
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002291 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
2292
2293/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
David Greene5fd22a82007-09-04 18:46:50 +00002294static const unsigned char yytranslate[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002295{
2296 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2297 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2298 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2299 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2300 155, 156, 164, 2, 153, 2, 2, 2, 2, 2,
2301 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2302 160, 152, 161, 2, 2, 2, 2, 2, 2, 2,
2303 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2304 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2305 2, 157, 154, 159, 2, 2, 2, 2, 2, 165,
2306 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2307 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2308 158, 2, 2, 162, 2, 163, 2, 2, 2, 2,
2309 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2310 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2311 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2312 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2313 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2314 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2315 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2316 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2317 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2318 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2319 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2320 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2321 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
2322 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
2323 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
2324 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
2325 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
2326 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
2327 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
2328 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
2329 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
2330 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
2331 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
2332 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
2333 115, 116, 117, 118, 119, 120, 121, 122, 123, 124,
2334 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
2335 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
2336 145, 146, 147, 148, 149, 150, 151
2337};
2338
2339#if YYDEBUG
2340/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
2341 YYRHS. */
David Greene5fd22a82007-09-04 18:46:50 +00002342static const unsigned short yyprhs[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002343{
2344 0, 0, 3, 5, 7, 9, 11, 13, 15, 17,
2345 19, 21, 23, 25, 27, 29, 31, 33, 35, 37,
2346 39, 41, 43, 45, 47, 49, 51, 53, 55, 57,
2347 59, 61, 63, 65, 67, 69, 71, 73, 75, 77,
2348 79, 81, 83, 85, 87, 89, 91, 93, 95, 97,
2349 99, 101, 103, 105, 107, 109, 111, 113, 115, 117,
2350 119, 121, 123, 125, 127, 129, 131, 133, 135, 137,
2351 139, 141, 143, 145, 147, 149, 151, 153, 155, 157,
2352 159, 161, 164, 165, 167, 169, 171, 173, 175, 177,
2353 179, 180, 181, 183, 185, 187, 189, 191, 193, 196,
2354 197, 200, 201, 205, 208, 209, 211, 212, 216, 218,
2355 221, 223, 225, 227, 229, 231, 233, 235, 237, 239,
2356 241, 243, 245, 247, 249, 251, 253, 255, 257, 259,
2357 261, 264, 269, 275, 281, 285, 288, 294, 299, 302,
2358 304, 308, 310, 314, 316, 317, 322, 326, 330, 335,
2359 340, 344, 351, 357, 360, 363, 366, 369, 372, 375,
2360 378, 381, 384, 387, 394, 400, 409, 416, 423, 430,
2361 438, 446, 453, 460, 469, 478, 482, 484, 486, 488,
2362 490, 493, 496, 501, 504, 506, 511, 514, 519, 520,
2363 528, 529, 537, 538, 546, 547, 555, 559, 564, 565,
2364 567, 569, 571, 575, 579, 583, 587, 591, 595, 597,
2365 598, 600, 602, 604, 605, 608, 612, 614, 616, 620,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002366 622, 623, 632, 634, 636, 637, 642, 644, 646, 649,
2367 650, 652, 654, 655, 656, 662, 663, 665, 667, 669,
2368 671, 673, 675, 677, 679, 681, 685, 687, 693, 695,
2369 697, 699, 701, 704, 707, 710, 714, 717, 718, 720,
2370 722, 724, 727, 730, 734, 744, 754, 763, 777, 779,
2371 781, 788, 794, 797, 804, 812, 814, 818, 820, 821,
2372 824, 826, 832, 838, 844, 851, 858, 861, 866, 871,
2373 878, 883, 888, 893, 898, 905, 912, 915, 923, 925,
2374 928, 929, 931, 932, 936, 943, 947, 954, 957, 962,
2375 969
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002376};
2377
David Greene5fd22a82007-09-04 18:46:50 +00002378/* YYRHS -- A `-1'-separated list of the rules' RHS. */
2379static const short yyrhs[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002380{
2381 200, 0, -1, 5, -1, 6, -1, 3, -1, 4,
2382 -1, 79, -1, 80, -1, 81, -1, 82, -1, 83,
2383 -1, 84, -1, 85, -1, 86, -1, 87, -1, 88,
2384 -1, 89, -1, 90, -1, 91, -1, 92, -1, 97,
2385 -1, 98, -1, 99, -1, 100, -1, 101, -1, 102,
2386 -1, 119, -1, 120, -1, 121, -1, 122, -1, 123,
2387 -1, 124, -1, 125, -1, 126, -1, 127, -1, 128,
2388 -1, 129, -1, 130, -1, 131, -1, 132, -1, 133,
2389 -1, 134, -1, 135, -1, 136, -1, 137, -1, 138,
2390 -1, 125, -1, 126, -1, 127, -1, 128, -1, 27,
2391 -1, 28, -1, 93, -1, 94, -1, 95, -1, 96,
2392 -1, 140, -1, 141, -1, 142, -1, 143, -1, 144,
2393 -1, 145, -1, 146, -1, 147, -1, 148, -1, 149,
2394 -1, 150, -1, 151, -1, 139, -1, 16, -1, 14,
2395 -1, 12, -1, 10, -1, 17, -1, 15, -1, 13,
2396 -1, 11, -1, 176, -1, 177, -1, 18, -1, 19,
2397 -1, 212, 152, -1, -1, 41, -1, 42, -1, 43,
2398 -1, 44, -1, 45, -1, 46, -1, 47, -1, -1,
2399 -1, 65, -1, 66, -1, 67, -1, 68, -1, 69,
2400 -1, 70, -1, 64, 4, -1, -1, 57, 4, -1,
2401 -1, 153, 57, 4, -1, 34, 24, -1, -1, 185,
2402 -1, -1, 153, 188, 187, -1, 185, -1, 57, 4,
2403 -1, 191, -1, 8, -1, 193, -1, 8, -1, 193,
2404 -1, 9, -1, 10, -1, 11, -1, 12, -1, 13,
2405 -1, 14, -1, 15, -1, 16, -1, 17, -1, 18,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002406 -1, 19, -1, 21, -1, 192, -1, 48, -1, 229,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002407 -1, 154, 4, -1, 190, 155, 195, 156, -1, 157,
2408 4, 158, 193, 159, -1, 160, 4, 158, 193, 161,
2409 -1, 162, 194, 163, -1, 162, 163, -1, 160, 162,
2410 194, 163, 161, -1, 160, 162, 163, 161, -1, 193,
2411 164, -1, 193, -1, 194, 153, 193, -1, 194, -1,
2412 194, 153, 37, -1, 37, -1, -1, 191, 157, 198,
2413 159, -1, 191, 157, 159, -1, 191, 165, 24, -1,
2414 191, 160, 198, 161, -1, 191, 162, 198, 163, -1,
2415 191, 162, 163, -1, 191, 160, 162, 198, 163, 161,
2416 -1, 191, 160, 162, 163, 161, -1, 191, 38, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002417 191, 39, -1, 191, 229, -1, 191, 197, -1, 191,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002418 26, -1, 176, 168, -1, 177, 4, -1, 9, 27,
2419 -1, 9, 28, -1, 179, 7, -1, 175, 155, 196,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002420 36, 191, 156, -1, 110, 155, 196, 244, 156, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002421 112, 155, 196, 153, 196, 153, 196, 156, -1, 169,
2422 155, 196, 153, 196, 156, -1, 170, 155, 196, 153,
2423 196, 156, -1, 171, 155, 196, 153, 196, 156, -1,
2424 103, 172, 155, 196, 153, 196, 156, -1, 104, 173,
2425 155, 196, 153, 196, 156, -1, 174, 155, 196, 153,
2426 196, 156, -1, 114, 155, 196, 153, 196, 156, -1,
2427 115, 155, 196, 153, 196, 153, 196, 156, -1, 116,
2428 155, 196, 153, 196, 153, 196, 156, -1, 198, 153,
2429 196, -1, 196, -1, 32, -1, 33, -1, 201, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002430 201, 222, -1, 201, 224, -1, 201, 62, 61, 207,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002431 -1, 201, 25, -1, 202, -1, 202, 180, 20, 189,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002432 -1, 202, 224, -1, 202, 62, 61, 207, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002433 202, 180, 181, 199, 196, 203, 187, -1, -1, 202,
2434 180, 50, 199, 191, 204, 187, -1, -1, 202, 180,
2435 45, 199, 191, 205, 187, -1, -1, 202, 180, 47,
2436 199, 191, 206, 187, -1, 202, 51, 209, -1, 202,
2437 58, 152, 210, -1, -1, 24, -1, 56, -1, 55,
2438 -1, 53, 152, 208, -1, 54, 152, 4, -1, 52,
2439 152, 24, -1, 71, 152, 24, -1, 157, 211, 159,
2440 -1, 211, 153, 24, -1, 24, -1, -1, 22, -1,
2441 24, -1, 212, -1, -1, 191, 213, -1, 215, 153,
2442 214, -1, 214, -1, 215, -1, 215, 153, 37, -1,
2443 37, -1, -1, 182, 189, 212, 155, 216, 156, 186,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002444 183, -1, 29, -1, 162, -1, -1, 181, 220, 217,
2445 218, -1, 30, -1, 163, -1, 232, 221, -1, -1,
2446 45, -1, 47, -1, -1, -1, 31, 225, 223, 226,
2447 217, -1, -1, 63, -1, 3, -1, 4, -1, 7,
2448 -1, 27, -1, 28, -1, 38, -1, 39, -1, 26,
2449 -1, 160, 198, 161, -1, 197, -1, 61, 227, 24,
2450 153, 24, -1, 167, -1, 212, -1, 229, -1, 228,
2451 -1, 191, 230, -1, 232, 233, -1, 219, 233, -1,
2452 234, 180, 236, -1, 234, 238, -1, -1, 23, -1,
2453 77, -1, 78, -1, 72, 231, -1, 72, 8, -1,
2454 73, 21, 230, -1, 73, 9, 230, 153, 21, 230,
2455 153, 21, 230, -1, 74, 178, 230, 153, 21, 230,
2456 157, 237, 159, -1, 74, 178, 230, 153, 21, 230,
2457 157, 159, -1, 75, 182, 189, 230, 155, 241, 156,
2458 36, 21, 230, 235, 21, 230, -1, 235, -1, 76,
2459 -1, 237, 178, 228, 153, 21, 230, -1, 178, 228,
2460 153, 21, 230, -1, 180, 243, -1, 191, 157, 230,
2461 153, 230, 159, -1, 239, 153, 157, 230, 153, 230,
2462 159, -1, 231, -1, 240, 153, 231, -1, 240, -1,
2463 -1, 60, 59, -1, 59, -1, 169, 191, 230, 153,
2464 230, -1, 170, 191, 230, 153, 230, -1, 171, 191,
2465 230, 153, 230, -1, 103, 172, 191, 230, 153, 230,
2466 -1, 104, 173, 191, 230, 153, 230, -1, 49, 231,
2467 -1, 174, 231, 153, 231, -1, 175, 231, 36, 191,
2468 -1, 112, 231, 153, 231, 153, 231, -1, 113, 231,
2469 153, 191, -1, 117, 231, 153, 191, -1, 118, 231,
2470 153, 191, -1, 114, 231, 153, 231, -1, 115, 231,
2471 153, 231, 153, 231, -1, 116, 231, 153, 231, 153,
2472 231, -1, 111, 239, -1, 242, 182, 189, 230, 155,
2473 241, 156, -1, 246, -1, 153, 240, -1, -1, 35,
2474 -1, -1, 105, 191, 184, -1, 105, 191, 153, 15,
2475 230, 184, -1, 106, 191, 184, -1, 106, 191, 153,
2476 15, 230, 184, -1, 107, 231, -1, 245, 108, 191,
2477 230, -1, 245, 109, 231, 153, 191, 230, -1, 110,
2478 191, 230, 244, -1
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002479};
2480
2481/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
David Greene5fd22a82007-09-04 18:46:50 +00002482static const unsigned short yyrline[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002483{
David Greene5fd22a82007-09-04 18:46:50 +00002484 0, 1890, 1890, 1891, 1899, 1900, 1910, 1910, 1910, 1910,
2485 1910, 1910, 1910, 1910, 1910, 1910, 1910, 1914, 1914, 1914,
2486 1918, 1918, 1918, 1918, 1918, 1918, 1922, 1922, 1923, 1923,
2487 1924, 1924, 1925, 1925, 1926, 1926, 1930, 1930, 1931, 1931,
2488 1932, 1932, 1933, 1933, 1934, 1934, 1935, 1935, 1936, 1936,
2489 1937, 1938, 1941, 1941, 1941, 1941, 1945, 1945, 1945, 1945,
2490 1945, 1945, 1945, 1946, 1946, 1946, 1946, 1946, 1946, 1952,
2491 1952, 1952, 1952, 1956, 1956, 1956, 1956, 1960, 1960, 1964,
2492 1964, 1969, 1972, 1977, 1978, 1979, 1980, 1981, 1982, 1983,
2493 1984, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 2005,
2494 2006, 2014, 2015, 2023, 2032, 2033, 2040, 2041, 2045, 2049,
2495 2065, 2066, 2073, 2074, 2081, 2089, 2089, 2089, 2089, 2089,
2496 2089, 2089, 2090, 2090, 2090, 2090, 2090, 2095, 2099, 2103,
2497 2108, 2117, 2144, 2150, 2163, 2174, 2178, 2191, 2195, 2209,
2498 2213, 2220, 2221, 2227, 2234, 2246, 2276, 2289, 2312, 2340,
2499 2362, 2373, 2395, 2406, 2415, 2420, 2479, 2486, 2494, 2501,
2500 2508, 2512, 2516, 2525, 2540, 2552, 2561, 2589, 2602, 2611,
2501 2617, 2623, 2634, 2640, 2646, 2657, 2658, 2667, 2668, 2680,
2502 2689, 2690, 2691, 2692, 2693, 2709, 2729, 2731, 2733, 2733,
2503 2740, 2740, 2748, 2748, 2756, 2756, 2765, 2767, 2769, 2774,
2504 2788, 2789, 2793, 2796, 2804, 2808, 2815, 2819, 2823, 2827,
2505 2835, 2835, 2839, 2840, 2844, 2852, 2857, 2865, 2866, 2873,
2506 2880, 2884, 3074, 3074, 3078, 3078, 3088, 3088, 3092, 3097,
2507 3098, 3099, 3103, 3104, 3103, 3116, 3117, 3122, 3123, 3124,
2508 3125, 3129, 3133, 3134, 3135, 3136, 3157, 3161, 3175, 3176,
2509 3181, 3181, 3189, 3199, 3202, 3211, 3222, 3227, 3236, 3247,
2510 3247, 3250, 3254, 3258, 3263, 3273, 3291, 3300, 3374, 3378,
2511 3385, 3397, 3412, 3442, 3452, 3462, 3466, 3473, 3474, 3478,
2512 3481, 3487, 3506, 3524, 3540, 3554, 3568, 3579, 3597, 3606,
2513 3615, 3622, 3643, 3667, 3673, 3679, 3685, 3701, 3794, 3802,
2514 3803, 3807, 3808, 3812, 3818, 3825, 3831, 3838, 3845, 3858,
2515 3884
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002516};
2517#endif
2518
David Greene5fd22a82007-09-04 18:46:50 +00002519#if YYDEBUG || YYERROR_VERBOSE
2520/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
2521 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002522static const char *const yytname[] =
2523{
2524 "$end", "error", "$undefined", "ESINT64VAL", "EUINT64VAL", "SINTVAL",
2525 "UINTVAL", "FPVAL", "VOID", "BOOL", "SBYTE", "UBYTE", "SHORT", "USHORT",
2526 "INT", "UINT", "LONG", "ULONG", "FLOAT", "DOUBLE", "TYPE", "LABEL",
2527 "VAR_ID", "LABELSTR", "STRINGCONSTANT", "IMPLEMENTATION",
2528 "ZEROINITIALIZER", "TRUETOK", "FALSETOK", "BEGINTOK", "ENDTOK",
2529 "DECLARE", "GLOBAL", "CONSTANT", "SECTION", "VOLATILE", "TO",
2530 "DOTDOTDOT", "NULL_TOK", "UNDEF", "CONST", "INTERNAL", "LINKONCE",
2531 "WEAK", "APPENDING", "DLLIMPORT", "DLLEXPORT", "EXTERN_WEAK", "OPAQUE",
2532 "NOT", "EXTERNAL", "TARGET", "TRIPLE", "ENDIAN", "POINTERSIZE", "LITTLE",
2533 "BIG", "ALIGN", "DEPLIBS", "CALL", "TAIL", "ASM_TOK", "MODULE",
2534 "SIDEEFFECT", "CC_TOK", "CCC_TOK", "CSRETCC_TOK", "FASTCC_TOK",
2535 "COLDCC_TOK", "X86_STDCALLCC_TOK", "X86_FASTCALLCC_TOK", "DATALAYOUT",
2536 "RET", "BR", "SWITCH", "INVOKE", "UNREACHABLE", "UNWIND", "EXCEPT",
2537 "ADD", "SUB", "MUL", "DIV", "UDIV", "SDIV", "FDIV", "REM", "UREM",
2538 "SREM", "FREM", "AND", "OR", "XOR", "SHL", "SHR", "ASHR", "LSHR",
2539 "SETLE", "SETGE", "SETLT", "SETGT", "SETEQ", "SETNE", "ICMP", "FCMP",
2540 "MALLOC", "ALLOCA", "FREE", "LOAD", "STORE", "GETELEMENTPTR", "PHI_TOK",
2541 "SELECT", "VAARG", "EXTRACTELEMENT", "INSERTELEMENT", "SHUFFLEVECTOR",
2542 "VAARG_old", "VANEXT_old", "EQ", "NE", "SLT", "SGT", "SLE", "SGE", "ULT",
2543 "UGT", "ULE", "UGE", "OEQ", "ONE", "OLT", "OGT", "OLE", "OGE", "ORD",
2544 "UNO", "UEQ", "UNE", "CAST", "TRUNC", "ZEXT", "SEXT", "FPTRUNC", "FPEXT",
2545 "FPTOUI", "FPTOSI", "UITOFP", "SITOFP", "PTRTOINT", "INTTOPTR",
2546 "BITCAST", "'='", "','", "'\\\\'", "'('", "')'", "'['", "'x'", "']'",
2547 "'<'", "'>'", "'{'", "'}'", "'*'", "'c'", "$accept", "INTVAL",
2548 "EINT64VAL", "ArithmeticOps", "LogicalOps", "SetCondOps", "IPredicates",
2549 "FPredicates", "ShiftOps", "CastOps", "SIntType", "UIntType", "IntType",
2550 "FPType", "OptAssign", "OptLinkage", "OptCallingConv", "OptAlign",
2551 "OptCAlign", "SectionString", "OptSection", "GlobalVarAttributes",
2552 "GlobalVarAttribute", "TypesV", "UpRTypesV", "Types", "PrimType",
2553 "UpRTypes", "TypeListI", "ArgTypeListI", "ConstVal", "ConstExpr",
2554 "ConstVector", "GlobalType", "Module", "FunctionList", "ConstPool", "@1",
2555 "@2", "@3", "@4", "AsmBlock", "BigOrLittle", "TargetDefinition",
2556 "LibrariesDefinition", "LibList", "Name", "OptName", "ArgVal",
2557 "ArgListH", "ArgList", "FunctionHeaderH", "BEGIN", "FunctionHeader",
Reid Spencerd2920cd2007-03-21 17:27:53 +00002558 "@5", "END", "Function", "FnDeclareLinkage", "FunctionProto", "@6", "@7",
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002559 "OptSideEffect", "ConstValueRef", "SymbolicValueRef", "ValueRef",
2560 "ResolvedVal", "BasicBlockList", "BasicBlock", "InstructionList",
2561 "Unwind", "BBTerminatorInst", "JumpTable", "Inst", "PHIList",
2562 "ValueRefList", "ValueRefListE", "OptTailCall", "InstVal", "IndexList",
2563 "OptVolatile", "MemoryInst", 0
2564};
2565#endif
2566
2567# ifdef YYPRINT
2568/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
2569 token YYLEX-NUM. */
David Greene5fd22a82007-09-04 18:46:50 +00002570static const unsigned short yytoknum[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002571{
2572 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
2573 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
2574 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
2575 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
2576 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
2577 305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
2578 315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
2579 325, 326, 327, 328, 329, 330, 331, 332, 333, 334,
2580 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
2581 345, 346, 347, 348, 349, 350, 351, 352, 353, 354,
2582 355, 356, 357, 358, 359, 360, 361, 362, 363, 364,
2583 365, 366, 367, 368, 369, 370, 371, 372, 373, 374,
2584 375, 376, 377, 378, 379, 380, 381, 382, 383, 384,
2585 385, 386, 387, 388, 389, 390, 391, 392, 393, 394,
2586 395, 396, 397, 398, 399, 400, 401, 402, 403, 404,
2587 405, 406, 61, 44, 92, 40, 41, 91, 120, 93,
2588 60, 62, 123, 125, 42, 99
2589};
2590# endif
2591
2592/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
David Greene5fd22a82007-09-04 18:46:50 +00002593static const unsigned char yyr1[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002594{
2595 0, 166, 167, 167, 168, 168, 169, 169, 169, 169,
2596 169, 169, 169, 169, 169, 169, 169, 170, 170, 170,
2597 171, 171, 171, 171, 171, 171, 172, 172, 172, 172,
2598 172, 172, 172, 172, 172, 172, 173, 173, 173, 173,
2599 173, 173, 173, 173, 173, 173, 173, 173, 173, 173,
2600 173, 173, 174, 174, 174, 174, 175, 175, 175, 175,
2601 175, 175, 175, 175, 175, 175, 175, 175, 175, 176,
2602 176, 176, 176, 177, 177, 177, 177, 178, 178, 179,
2603 179, 180, 180, 181, 181, 181, 181, 181, 181, 181,
2604 181, 182, 182, 182, 182, 182, 182, 182, 182, 183,
2605 183, 184, 184, 185, 186, 186, 187, 187, 188, 188,
2606 189, 189, 190, 190, 191, 192, 192, 192, 192, 192,
2607 192, 192, 192, 192, 192, 192, 192, 193, 193, 193,
2608 193, 193, 193, 193, 193, 193, 193, 193, 193, 194,
2609 194, 195, 195, 195, 195, 196, 196, 196, 196, 196,
2610 196, 196, 196, 196, 196, 196, 196, 196, 196, 196,
2611 196, 196, 196, 197, 197, 197, 197, 197, 197, 197,
2612 197, 197, 197, 197, 197, 198, 198, 199, 199, 200,
2613 201, 201, 201, 201, 201, 202, 202, 202, 203, 202,
2614 204, 202, 205, 202, 206, 202, 202, 202, 202, 207,
2615 208, 208, 209, 209, 209, 209, 210, 211, 211, 211,
2616 212, 212, 213, 213, 214, 215, 215, 216, 216, 216,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002617 216, 217, 218, 218, 220, 219, 221, 221, 222, 223,
2618 223, 223, 225, 226, 224, 227, 227, 228, 228, 228,
2619 228, 228, 228, 228, 228, 228, 228, 228, 229, 229,
2620 230, 230, 231, 232, 232, 233, 234, 234, 234, 235,
2621 235, 236, 236, 236, 236, 236, 236, 236, 236, 236,
2622 237, 237, 238, 239, 239, 240, 240, 241, 241, 242,
2623 242, 243, 243, 243, 243, 243, 243, 243, 243, 243,
2624 243, 243, 243, 243, 243, 243, 243, 243, 243, 244,
2625 244, 245, 245, 246, 246, 246, 246, 246, 246, 246,
2626 246
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002627};
2628
2629/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
David Greene5fd22a82007-09-04 18:46:50 +00002630static const unsigned char yyr2[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002631{
2632 0, 2, 1, 1, 1, 1, 1, 1, 1, 1,
2633 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2634 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2635 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2636 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2637 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2638 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2639 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2640 1, 2, 0, 1, 1, 1, 1, 1, 1, 1,
2641 0, 0, 1, 1, 1, 1, 1, 1, 2, 0,
2642 2, 0, 3, 2, 0, 1, 0, 3, 1, 2,
2643 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2644 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2645 2, 4, 5, 5, 3, 2, 5, 4, 2, 1,
2646 3, 1, 3, 1, 0, 4, 3, 3, 4, 4,
2647 3, 6, 5, 2, 2, 2, 2, 2, 2, 2,
2648 2, 2, 2, 6, 5, 8, 6, 6, 6, 7,
2649 7, 6, 6, 8, 8, 3, 1, 1, 1, 1,
2650 2, 2, 4, 2, 1, 4, 2, 4, 0, 7,
2651 0, 7, 0, 7, 0, 7, 3, 4, 0, 1,
2652 1, 1, 3, 3, 3, 3, 3, 3, 1, 0,
2653 1, 1, 1, 0, 2, 3, 1, 1, 3, 1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002654 0, 8, 1, 1, 0, 4, 1, 1, 2, 0,
2655 1, 1, 0, 0, 5, 0, 1, 1, 1, 1,
2656 1, 1, 1, 1, 1, 3, 1, 5, 1, 1,
2657 1, 1, 2, 2, 2, 3, 2, 0, 1, 1,
2658 1, 2, 2, 3, 9, 9, 8, 13, 1, 1,
2659 6, 5, 2, 6, 7, 1, 3, 1, 0, 2,
2660 1, 5, 5, 5, 6, 6, 2, 4, 4, 6,
2661 4, 4, 4, 4, 6, 6, 2, 7, 1, 2,
2662 0, 1, 0, 3, 6, 3, 6, 2, 4, 6,
2663 4
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002664};
2665
2666/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
2667 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
2668 means the default is an error. */
David Greene5fd22a82007-09-04 18:46:50 +00002669static const unsigned short yydefact[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002670{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002671 198, 0, 90, 184, 1, 183, 232, 83, 84, 85,
2672 86, 87, 88, 89, 0, 224, 257, 180, 181, 257,
2673 210, 211, 0, 0, 0, 90, 0, 186, 229, 0,
2674 91, 258, 254, 82, 226, 227, 228, 253, 0, 0,
2675 0, 0, 196, 0, 0, 0, 0, 0, 0, 0,
2676 81, 230, 231, 233, 199, 182, 0, 92, 93, 94,
2677 95, 96, 97, 0, 0, 302, 256, 0, 0, 0,
2678 0, 209, 197, 187, 2, 3, 111, 115, 116, 117,
2679 118, 119, 120, 121, 122, 123, 124, 125, 126, 128,
2680 0, 0, 0, 0, 248, 185, 0, 110, 127, 114,
2681 249, 129, 177, 178, 0, 0, 0, 0, 91, 98,
2682 0, 222, 223, 225, 301, 0, 280, 0, 0, 0,
2683 0, 91, 269, 259, 260, 6, 7, 8, 9, 10,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002684 11, 12, 13, 14, 15, 16, 17, 18, 19, 52,
2685 53, 54, 55, 20, 21, 22, 23, 24, 25, 0,
2686 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2687 0, 0, 0, 68, 56, 57, 58, 59, 60, 61,
2688 62, 63, 64, 65, 66, 67, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002689 0, 268, 255, 91, 272, 0, 298, 204, 201, 200,
2690 202, 203, 205, 208, 0, 130, 0, 0, 0, 113,
2691 135, 139, 0, 144, 138, 192, 194, 190, 115, 116,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002692 117, 118, 119, 120, 121, 122, 123, 124, 125, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002693 0, 0, 0, 188, 234, 0, 0, 286, 279, 262,
2694 261, 0, 0, 72, 76, 71, 75, 70, 74, 69,
2695 73, 77, 78, 0, 0, 26, 27, 28, 29, 30,
2696 31, 32, 33, 34, 35, 0, 50, 51, 46, 47,
2697 48, 49, 36, 37, 38, 39, 40, 41, 42, 43,
2698 44, 45, 0, 101, 101, 307, 0, 0, 296, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002699 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002700 0, 0, 0, 0, 0, 206, 0, 0, 0, 0,
2701 0, 134, 143, 141, 0, 106, 106, 106, 160, 161,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002702 4, 5, 158, 159, 162, 157, 153, 154, 0, 0,
2703 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002704 0, 0, 0, 0, 156, 155, 106, 220, 237, 238,
2705 239, 244, 240, 241, 242, 243, 235, 0, 246, 251,
2706 250, 252, 0, 263, 0, 0, 0, 0, 0, 303,
2707 0, 305, 300, 0, 0, 0, 0, 0, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002708 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002709 207, 112, 112, 137, 0, 140, 0, 131, 0, 193,
2710 195, 191, 0, 0, 0, 0, 0, 0, 0, 146,
2711 176, 0, 0, 0, 150, 0, 147, 0, 0, 0,
2712 0, 0, 189, 219, 213, 216, 217, 0, 236, 0,
2713 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2714 310, 0, 0, 0, 290, 293, 0, 0, 291, 292,
2715 0, 0, 0, 287, 288, 0, 308, 0, 132, 133,
2716 136, 142, 0, 0, 108, 106, 0, 0, 300, 0,
2717 0, 0, 0, 0, 145, 135, 114, 0, 148, 149,
2718 0, 0, 0, 0, 0, 212, 214, 0, 104, 0,
2719 245, 0, 0, 278, 0, 0, 101, 102, 101, 275,
2720 299, 0, 0, 0, 0, 0, 281, 282, 283, 278,
2721 0, 103, 109, 107, 0, 0, 0, 0, 0, 0,
2722 0, 175, 152, 0, 0, 0, 0, 0, 0, 218,
2723 215, 105, 99, 0, 0, 0, 277, 0, 284, 285,
2724 0, 304, 306, 0, 0, 0, 289, 294, 295, 0,
2725 309, 0, 0, 164, 0, 0, 0, 0, 151, 0,
2726 0, 0, 0, 0, 0, 221, 247, 0, 0, 0,
2727 276, 273, 0, 297, 0, 0, 0, 172, 0, 0,
2728 166, 167, 168, 171, 163, 100, 0, 266, 0, 0,
2729 0, 274, 169, 170, 0, 0, 0, 264, 0, 265,
2730 0, 0, 165, 173, 174, 0, 0, 0, 0, 0,
2731 0, 271, 0, 0, 270, 267
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002732};
2733
David Greene5fd22a82007-09-04 18:46:50 +00002734/* YYDEFGOTO[NTERM-NUM]. */
2735static const short yydefgoto[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002736{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002737 -1, 94, 312, 329, 330, 331, 255, 272, 332, 333,
2738 219, 220, 243, 221, 25, 15, 63, 555, 359, 454,
2739 522, 389, 455, 95, 96, 222, 98, 99, 202, 304,
2740 400, 348, 401, 104, 1, 2, 3, 336, 307, 305,
2741 306, 55, 190, 42, 72, 194, 100, 476, 415, 416,
2742 417, 64, 113, 16, 30, 36, 17, 53, 18, 28,
2743 108, 419, 349, 101, 351, 489, 19, 32, 33, 181,
2744 182, 579, 66, 278, 526, 527, 183, 184, 430, 185,
2745 186
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002746};
2747
2748/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
2749 STATE-NUM. */
Reid Spencerd2920cd2007-03-21 17:27:53 +00002750#define YYPACT_NINF -542
David Greene5fd22a82007-09-04 18:46:50 +00002751static const short yypact[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002752{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002753 -542, 13, 162, 567, -542, -542, -542, -542, -542, -542,
2754 -542, -542, -542, -542, 83, -542, 19, -542, -542, -14,
2755 -542, -542, 50, -87, 87, 233, 27, -542, 123, 141,
2756 175, -542, -542, 98, -542, -542, -542, -542, 33, 40,
2757 66, 68, -542, 14, 141, 1265, 156, 156, 156, 156,
2758 -542, -542, -542, -542, -542, -542, 221, -542, -542, -542,
2759 -542, -542, -542, 1265, -19, 1479, -542, 204, 135, 226,
2760 227, 235, -542, -542, -542, -542, 81, -542, -542, -542,
2761 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2762 256, 257, 4, 15, -542, -542, 108, -542, -542, 12,
2763 -542, -542, -542, -542, 1306, 1306, 1306, 1326, 175, -542,
2764 98, -542, -542, -542, -542, 1306, -542, 205, 1367, 116,
2765 479, 175, -542, -542, -542, -542, -542, -542, -542, -542,
2766 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2767 -542, -542, -542, -542, -542, -542, -542, -542, -542, 355,
2768 429, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306,
2769 1306, 1306, 1306, -542, -542, -542, -542, -542, -542, -542,
2770 -542, -542, -542, -542, -542, -542, 1306, 1306, 1306, 1306,
2771 1306, -542, -542, 175, -542, 86, -542, -542, -542, -542,
2772 -542, -542, -542, -542, -13, -542, 110, 111, 75, -542,
2773 -542, 12, -81, 1046, -542, -542, -542, -542, 174, 208,
2774 266, 210, 267, 212, 268, 230, 277, 275, 278, 246,
2775 280, 279, 566, -542, -542, 136, 766, -542, -542, 81,
2776 -542, 766, 766, -542, -542, -542, -542, -542, -542, -542,
2777 -542, -542, -542, 766, 1265, -542, -542, -542, -542, -542,
2778 -542, -542, -542, -542, -542, 1306, -542, -542, -542, -542,
2779 -542, -542, -542, -542, -542, -542, -542, -542, -542, -542,
2780 -542, -542, 1306, 137, 145, -542, 766, 132, 146, 147,
2781 148, 149, 151, 152, 158, 160, 766, 766, 766, 161,
2782 281, 1265, 1306, 1306, 291, -542, 1306, 1306, 155, -27,
2783 1306, -542, -542, 165, 163, 176, 176, 176, -542, -542,
2784 -542, -542, -542, -542, -542, -542, -542, -542, 355, 429,
2785 172, 177, 178, 179, 182, 1087, 1387, 529, 311, 184,
2786 185, 186, 188, 189, -542, -542, 176, 1107, -542, -542,
2787 -542, -542, -542, -542, -542, -542, 282, 1326, -542, -542,
2788 -542, -542, 193, -542, 194, 766, 766, 766, 7, -542,
2789 20, -542, 195, 766, 192, 1306, 1306, 1306, 1306, 1306,
2790 1306, 1306, 200, 201, 206, 1306, 1306, 766, 766, 207,
2791 -542, -59, -149, -542, 196, 12, 1148, -542, 44, -542,
2792 -542, -542, 203, 211, 1326, 1326, 1326, 1326, 1326, -542,
2793 -542, -8, 741, -82, -542, 10, -542, 1326, 1326, 1326,
2794 1326, 1326, -542, -542, 98, -542, 214, 209, -542, 337,
2795 -34, 342, 348, 215, 218, 219, 766, 371, 766, 1306,
2796 -542, 223, 766, 224, -542, -542, 225, 234, -542, -542,
2797 766, 766, 766, -542, -542, 228, -542, 1306, -542, -542,
2798 -542, -542, 362, 375, -542, 176, 1326, 1326, 195, 236,
2799 237, 240, 243, 1326, -542, 238, -25, 11, -542, -542,
2800 244, 245, 247, 250, 352, -542, -542, 1205, 370, 252,
2801 -542, 766, 766, 1306, 766, 766, 258, -542, 258, -542,
2802 259, 766, 264, 1306, 1306, 1306, -542, -542, -542, 1306,
2803 766, -542, -542, -542, 270, 271, 263, 1326, 1326, 1326,
2804 1326, -542, -542, 260, 1326, 1326, 1326, 1326, 1306, -542,
2805 -542, -542, 368, 402, 274, 276, 259, 287, -542, -542,
2806 374, -542, -542, 1306, 285, 766, -542, -542, -542, 290,
2807 -542, 1326, 1326, -542, 283, 295, 284, 294, -542, 296,
2808 297, 299, 302, 303, 430, -542, -542, 414, 41, 425,
2809 -542, -542, 305, -542, 306, 310, 1326, -542, 1326, 1326,
2810 -542, -542, -542, -542, -542, -542, 766, -542, 893, 144,
2811 448, -542, -542, -542, 314, 315, 316, -542, 331, -542,
2812 893, 766, -542, -542, -542, 464, 334, 180, 766, 481,
2813 482, -542, 766, 766, -542, -542
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002814};
2815
2816/* YYPGOTO[NTERM-NUM]. */
David Greene5fd22a82007-09-04 18:46:50 +00002817static const short yypgoto[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002818{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002819 -542, -542, -542, 435, 439, 441, 191, 197, 442, 445,
2820 -119, -116, -541, -542, 478, 489, -107, -542, -267, 37,
2821 -542, -238, -542, -60, -542, -45, -542, -74, -51, -542,
2822 -101, 300, -252, 134, -542, -542, -542, -542, -542, -542,
2823 -542, 473, -542, -542, -542, -542, 8, -542, 46, -542,
2824 -542, 410, -542, -542, -542, -542, -542, -542, 518, -542,
2825 -542, -542, -528, 142, -90, -113, -542, 505, -542, -72,
2826 -542, -542, -542, -542, 97, 28, -542, -542, 70, -542,
2827 -542
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002828};
2829
2830/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
2831 positive, shift that token. If negative, reduce the rule which
2832 number is the opposite. If zero, do what YYDEFACT says.
2833 If YYTABLE_NINF, syntax error. */
2834#define YYTABLE_NINF -180
David Greene5fd22a82007-09-04 18:46:50 +00002835static const short yytable[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002836{
Reid Spencerd2920cd2007-03-21 17:27:53 +00002837 97, 241, 227, 110, 242, 230, 223, 361, 197, 31,
2838 111, 26, 449, 4, 244, 204, 34, 578, 97, 201,
2839 74, 75, 426, 199, 77, 78, 79, 80, 81, 82,
2840 83, 84, 85, 86, 87, 428, 88, 20, 590, 21,
2841 275, 26, 31, 279, 280, 281, 282, 283, 284, 285,
2842 588, 233, 234, 235, 236, 237, 238, 239, 240, 205,
2843 206, 207, 596, 89, 427, 43, 289, 290, 390, 391,
2844 226, 463, 300, 226, 403, 405, 291, 427, 452, 468,
2845 74, 75, 301, 199, 77, 78, 79, 80, 81, 82,
2846 83, 84, 85, 86, 87, 420, 88, 20, 412, 21,
2847 448, 453, 38, 39, 40, 204, 273, 274, 226, 276,
2848 277, 226, 226, 226, 226, 226, 226, 226, 225, 463,
2849 20, 41, 21, 89, 201, 231, 300, 480, -139, 201,
2850 -112, 286, 287, 288, 226, 226, 384, 232, -139, 204,
2851 294, 352, 353, 112, 29, 463, 295, 299, 44, 35,
2852 467, 464, 303, 354, 233, 234, 235, 236, 237, 238,
2853 239, 240, -179, 463, 463, 54, 198, -112, 51, 90,
2854 52, 71, 91, 469, 513, 92, 204, 93, 200, 50,
2855 379, 105, 106, 107, 355, 67, 362, 5, 102, 103,
2856 188, 189, 68, 6, 292, 293, 372, 373, 374, 97,
2857 577, 308, 309, 7, 8, 9, 10, 11, 12, 13,
2858 356, -72, -72, -71, -71, -70, -70, 503, 69, 531,
2859 70, 532, 381, 382, 14, 109, 385, 357, 187, 90,
2860 191, 377, 91, -69, -69, 92, -113, 93, 298, 56,
2861 57, 58, 59, 60, 61, 62, 97, 378, 226, 310,
2862 311, 192, 433, 45, 435, 436, 437, 123, 124, 193,
2863 195, 196, 443, 203, 228, 423, 424, 425, 296, 297,
2864 -76, -75, -74, 431, 7, 8, 9, 10, 46, 12,
2865 47, -73, -79, 48, 313, -80, 314, 445, 446, 363,
2866 358, 337, 414, 458, 459, 460, 461, 462, 360, 364,
2867 365, 366, 367, 589, 368, 369, 470, 471, 472, 473,
2868 474, 370, 385, 371, 375, 380, 383, 376, 386, 387,
2869 226, 434, 226, 226, 226, 438, 439, 394, 466, 388,
2870 226, 444, 395, 396, 397, 406, 486, 398, 488, 407,
2871 408, 409, 492, 410, 411, 418, 421, 422, 429, 432,
2872 496, 497, 498, 440, 441, 504, 505, 450, 456, 442,
2873 447, 479, 511, 481, 335, 478, 457, 477, 350, 482,
2874 483, 484, 485, 350, 350, 487, 491, 493, 494, 502,
2875 536, 537, 538, 499, 226, 350, 501, 495, 518, 507,
2876 508, 524, 525, 509, 528, 529, 510, 514, 515, 512,
2877 516, 534, 500, 517, 452, 523, 544, 545, 546, 547,
2878 540, 530, 533, 549, 550, 551, 552, 535, 350, 543,
2879 560, 548, 475, 541, 542, 554, 556, 557, 350, 350,
2880 350, 427, 414, 558, 575, 576, 566, 568, 226, 241,
2881 564, 565, 242, 559, 561, 562, 563, 569, 226, 226,
2882 226, 567, 570, 571, 226, 572, 256, 257, 573, 574,
2883 241, 580, 582, 242, 581, 584, 583, 585, 586, 591,
2884 592, 593, 594, 553, 245, 246, 247, 248, 249, 250,
2885 251, 252, 253, 254, 595, 598, 587, 599, 226, 233,
2886 234, 235, 236, 237, 238, 239, 240, 350, 350, 350,
2887 176, 597, 602, 603, 177, 350, 178, 179, 601, 392,
2888 180, 65, 604, 605, 49, 521, 393, 73, 224, 350,
2889 350, 27, 334, 520, 37, 600, 490, 539, 506, 0,
2890 0, 0, 0, 0, 74, 75, 0, 199, 208, 209,
2891 210, 211, 212, 213, 214, 215, 216, 217, 218, 0,
2892 88, 20, 0, 21, 258, 259, 260, 261, 262, 263,
2893 264, 265, 266, 267, 268, 269, 270, 271, 350, 0,
2894 350, 74, 75, 0, 350, 0, 0, 89, 0, 0,
2895 0, 0, 350, 350, 350, 0, 0, -82, 20, 20,
2896 21, 21, 315, 0, 0, 0, 0, 0, 6, -82,
2897 -82, 0, 0, 0, 316, 317, 0, 0, -82, -82,
2898 -82, -82, -82, -82, -82, 0, 0, -82, 22, 0,
2899 0, 0, 0, 350, 350, 23, 350, 350, 0, 24,
2900 0, 0, 0, 350, 0, 0, 0, 0, 0, 0,
2901 0, 0, 350, 0, 0, 125, 126, 127, 128, 129,
2902 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
2903 140, 141, 142, 143, 144, 145, 146, 147, 148, 318,
2904 319, 0, 0, 0, 0, 0, 320, 350, 321, 0,
2905 322, 323, 324, 90, 0, 0, 91, 0, 0, 92,
2906 0, 93, 404, 0, 0, 0, 0, 0, 0, 0,
2907 0, 0, 0, 0, 0, 163, 164, 165, 166, 167,
2908 168, 169, 170, 171, 172, 173, 174, 175, 350, 0,
2909 0, 0, 0, 325, 0, 0, 326, 0, 327, 0,
2910 0, 328, 0, 350, 0, 0, 0, 0, 0, 0,
2911 350, 0, 0, 0, 350, 350, 74, 75, 0, 199,
2912 208, 209, 210, 211, 212, 213, 214, 215, 216, 217,
2913 218, 0, 88, 20, 0, 21, 0, 0, 0, 338,
2914 339, 74, 75, 340, 0, 0, 0, 0, 0, 0,
2915 0, 0, 0, 0, 0, 0, 0, 0, 20, 89,
2916 21, 0, 341, 342, 343, 0, 0, 0, 0, 0,
2917 0, 0, 0, 0, 344, 345, 0, 0, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002918 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002919 0, 0, 0, 0, 0, 0, 0, 346, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002920 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002921 0, 0, 0, 0, 0, 125, 126, 127, 128, 129,
2922 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
2923 140, 141, 142, 143, 144, 145, 146, 147, 148, 318,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002924 319, 0, 0, 0, 0, 0, 320, 0, 321, 0,
2925 322, 323, 324, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002926 0, 0, 0, 0, 0, 90, 338, 339, 91, 0,
2927 340, 92, 0, 93, 465, 163, 164, 165, 166, 167,
2928 168, 169, 170, 171, 172, 173, 174, 175, 0, 341,
2929 342, 343, 0, 0, 0, 0, 347, 0, 0, 0,
2930 0, 344, 345, 0, 0, 0, 0, 0, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002931 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002932 0, 0, 0, 0, 346, 0, 0, 0, 0, 0,
2933 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2934 0, 0, 125, 126, 127, 128, 129, 130, 131, 132,
2935 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
2936 143, 144, 145, 146, 147, 148, 318, 319, 0, 0,
2937 0, 0, 0, 320, 0, 321, 0, 322, 323, 324,
2938 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2939 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2940 0, 0, 163, 164, 165, 166, 167, 168, 169, 170,
2941 171, 172, 173, 174, 175, 0, 0, 0, 0, 0,
2942 0, 74, 75, 347, 199, 77, 78, 79, 80, 81,
2943 82, 83, 84, 85, 86, 87, 0, 88, 20, 0,
2944 21, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2945 0, 0, 0, 302, 0, 0, 0, 0, 0, 0,
2946 0, 0, 74, 75, 89, 199, 208, 209, 210, 211,
2947 212, 213, 214, 215, 216, 217, 218, 0, 88, 20,
2948 0, 21, 74, 75, 0, 199, 77, 78, 79, 80,
2949 81, 82, 83, 84, 85, 86, 87, 0, 88, 20,
2950 0, 21, 0, 0, 0, 89, 0, 0, 0, 0,
2951 0, 0, 0, 0, 413, 0, 0, 0, 0, 0,
2952 0, 0, 0, 74, 75, 89, 199, 77, 78, 79,
2953 80, 81, 82, 83, 84, 85, 86, 87, 0, 88,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002954 20, 0, 21, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002955 0, 0, 0, 0, 0, 451, 0, 0, 0, 0,
2956 0, 0, 0, 0, 0, 0, 89, 0, 0, 0,
2957 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
2958 74, 75, 0, 199, 77, 78, 79, 80, 81, 82,
2959 83, 84, 85, 86, 87, 0, 88, 20, 0, 21,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002960 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002961 0, 90, 519, 0, 91, 0, 399, 92, 0, 93,
2962 0, 0, 0, 89, 0, 0, 0, 0, 0, 0,
2963 0, 90, 0, 0, 91, 0, 0, 92, 0, 93,
2964 74, 75, 0, 76, 77, 78, 79, 80, 81, 82,
2965 83, 84, 85, 86, 87, 0, 88, 20, 0, 21,
2966 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2967 0, 0, 90, 0, 0, 91, 0, 0, 92, 0,
2968 93, 74, 75, 89, 199, 77, 78, 79, 80, 81,
2969 82, 83, 84, 85, 86, 87, 0, 88, 20, 0,
2970 21, 74, 75, 0, 199, 208, 209, 210, 211, 212,
2971 213, 214, 215, 216, 217, 218, 0, 88, 20, 0,
2972 21, 0, 0, 0, 89, 0, 0, 0, 0, 90,
2973 0, 0, 91, 0, 0, 92, 0, 93, 0, 0,
2974 0, 0, 74, 75, 89, 229, 77, 78, 79, 80,
2975 81, 82, 83, 84, 85, 86, 87, 0, 88, 20,
2976 0, 21, 74, 75, 0, 199, 208, 209, 210, 211,
2977 212, 213, 214, 215, 216, 217, 218, 0, 88, 20,
2978 0, 21, 0, 0, 0, 89, 0, 0, 0, 90,
2979 0, 0, 91, 0, 0, 92, 0, 93, 0, 0,
2980 0, 0, 0, 0, 0, 89, 0, 0, 0, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002981 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2982 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002983 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002984 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002985 90, 0, 0, 91, 0, 0, 92, 0, 93, 0,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00002986 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2987 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
Reid Spencerd2920cd2007-03-21 17:27:53 +00002988 0, 0, 0, 0, 114, 0, 0, 0, 0, 0,
2989 0, 90, 0, 0, 91, 0, 0, 92, 115, 93,
2990 0, 0, 0, 0, 0, 0, 0, 0, 116, 117,
2991 0, 90, 0, 0, 91, 0, 0, 92, 0, 402,
2992 0, 118, 119, 120, 121, 122, 123, 124, 125, 126,
2993 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
2994 137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
2995 147, 148, 149, 150, 151, 152, 153, 0, 0, 154,
2996 155, 156, 157, 158, 159, 160, 161, 162, 0, 0,
2997 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2998 0, 0, 0, 0, 0, 0, 0, 0, 163, 164,
2999 165, 166, 167, 168, 169, 170, 171, 172, 173, 174,
3000 175
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003001};
3002
David Greene5fd22a82007-09-04 18:46:50 +00003003static const short yycheck[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003004{
Reid Spencerd2920cd2007-03-21 17:27:53 +00003005 45, 120, 115, 63, 120, 118, 107, 274, 4, 23,
3006 29, 3, 161, 0, 121, 164, 30, 558, 63, 93,
3007 5, 6, 15, 8, 9, 10, 11, 12, 13, 14,
3008 15, 16, 17, 18, 19, 15, 21, 22, 579, 24,
3009 153, 33, 23, 156, 157, 158, 159, 160, 161, 162,
3010 578, 10, 11, 12, 13, 14, 15, 16, 17, 104,
3011 105, 106, 590, 48, 57, 152, 179, 180, 306, 307,
3012 115, 153, 153, 118, 326, 327, 183, 57, 34, 161,
3013 5, 6, 163, 8, 9, 10, 11, 12, 13, 14,
3014 15, 16, 17, 18, 19, 347, 21, 22, 336, 24,
3015 159, 57, 52, 53, 54, 164, 151, 152, 153, 154,
3016 155, 156, 157, 158, 159, 160, 161, 162, 110, 153,
3017 22, 71, 24, 48, 198, 9, 153, 161, 153, 203,
3018 155, 176, 177, 178, 179, 180, 163, 21, 163, 164,
3019 153, 231, 232, 162, 61, 153, 159, 198, 61, 163,
3020 402, 159, 203, 243, 10, 11, 12, 13, 14, 15,
3021 16, 17, 0, 153, 153, 24, 162, 155, 45, 154,
3022 47, 157, 157, 163, 163, 160, 164, 162, 163, 152,
3023 293, 47, 48, 49, 244, 152, 276, 25, 32, 33,
3024 55, 56, 152, 31, 108, 109, 286, 287, 288, 244,
3025 159, 27, 28, 41, 42, 43, 44, 45, 46, 47,
3026 255, 3, 4, 3, 4, 3, 4, 455, 152, 486,
3027 152, 488, 296, 297, 62, 4, 300, 272, 24, 154,
3028 4, 291, 157, 3, 4, 160, 155, 162, 163, 64,
3029 65, 66, 67, 68, 69, 70, 291, 292, 293, 3,
3030 4, 24, 365, 20, 367, 368, 369, 77, 78, 24,
3031 4, 4, 375, 155, 59, 355, 356, 357, 158, 158,
3032 4, 4, 4, 363, 41, 42, 43, 44, 45, 46,
3033 47, 4, 7, 50, 4, 7, 7, 377, 378, 157,
3034 153, 155, 337, 394, 395, 396, 397, 398, 153, 153,
3035 153, 153, 153, 159, 153, 153, 407, 408, 409, 410,
3036 411, 153, 386, 153, 153, 24, 161, 36, 153, 156,
3037 365, 366, 367, 368, 369, 370, 371, 155, 402, 153,
3038 375, 376, 155, 155, 155, 24, 426, 155, 428, 155,
3039 155, 155, 432, 155, 155, 63, 153, 153, 153, 157,
3040 440, 441, 442, 153, 153, 456, 457, 161, 155, 153,
3041 153, 24, 463, 21, 222, 156, 155, 153, 226, 21,
3042 155, 153, 153, 231, 232, 4, 153, 153, 153, 4,
3043 493, 494, 495, 155, 429, 243, 24, 153, 36, 153,
3044 153, 481, 482, 153, 484, 485, 153, 153, 153, 161,
3045 153, 491, 447, 153, 34, 153, 507, 508, 509, 510,
3046 500, 153, 153, 514, 515, 516, 517, 153, 276, 156,
3047 533, 161, 414, 153, 153, 57, 24, 153, 286, 287,
3048 288, 57, 477, 157, 4, 21, 153, 153, 483, 558,
3049 541, 542, 558, 156, 159, 535, 156, 153, 493, 494,
3050 495, 156, 156, 156, 499, 156, 27, 28, 156, 156,
3051 579, 36, 156, 579, 159, 566, 156, 568, 569, 21,
3052 156, 156, 156, 518, 119, 120, 121, 122, 123, 124,
3053 125, 126, 127, 128, 153, 21, 576, 153, 533, 10,
3054 11, 12, 13, 14, 15, 16, 17, 355, 356, 357,
3055 65, 591, 21, 21, 65, 363, 65, 65, 598, 318,
3056 65, 33, 602, 603, 25, 478, 319, 44, 108, 377,
3057 378, 3, 222, 477, 19, 597, 429, 499, 458, -1,
3058 -1, -1, -1, -1, 5, 6, -1, 8, 9, 10,
3059 11, 12, 13, 14, 15, 16, 17, 18, 19, -1,
3060 21, 22, -1, 24, 125, 126, 127, 128, 129, 130,
3061 131, 132, 133, 134, 135, 136, 137, 138, 426, -1,
3062 428, 5, 6, -1, 432, -1, -1, 48, -1, -1,
3063 -1, -1, 440, 441, 442, -1, -1, 20, 22, 22,
3064 24, 24, 26, -1, -1, -1, -1, -1, 31, 32,
3065 33, -1, -1, -1, 38, 39, -1, -1, 41, 42,
3066 43, 44, 45, 46, 47, -1, -1, 50, 51, -1,
3067 -1, -1, -1, 481, 482, 58, 484, 485, -1, 62,
3068 -1, -1, -1, 491, -1, -1, -1, -1, -1, -1,
3069 -1, -1, 500, -1, -1, 79, 80, 81, 82, 83,
3070 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3071 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3072 104, -1, -1, -1, -1, -1, 110, 535, 112, -1,
3073 114, 115, 116, 154, -1, -1, 157, -1, -1, 160,
3074 -1, 162, 163, -1, -1, -1, -1, -1, -1, -1,
3075 -1, -1, -1, -1, -1, 139, 140, 141, 142, 143,
3076 144, 145, 146, 147, 148, 149, 150, 151, 576, -1,
3077 -1, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3078 -1, 165, -1, 591, -1, -1, -1, -1, -1, -1,
3079 598, -1, -1, -1, 602, 603, 5, 6, -1, 8,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003080 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003081 19, -1, 21, 22, -1, 24, -1, -1, -1, 3,
3082 4, 5, 6, 7, -1, -1, -1, -1, -1, -1,
3083 -1, -1, -1, -1, -1, -1, -1, -1, 22, 48,
3084 24, -1, 26, 27, 28, -1, -1, -1, -1, -1,
3085 -1, -1, -1, -1, 38, 39, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003086 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3087 -1, -1, -1, -1, -1, -1, -1, 61, -1, -1,
3088 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3089 -1, -1, -1, -1, -1, 79, 80, 81, 82, 83,
3090 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3091 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3092 104, -1, -1, -1, -1, -1, 110, -1, 112, -1,
3093 114, 115, 116, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003094 -1, -1, -1, -1, -1, 154, 3, 4, 157, -1,
3095 7, 160, -1, 162, 163, 139, 140, 141, 142, 143,
3096 144, 145, 146, 147, 148, 149, 150, 151, -1, 26,
3097 27, 28, -1, -1, -1, -1, 160, -1, -1, -1,
3098 -1, 38, 39, -1, -1, -1, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003099 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003100 -1, -1, -1, -1, 61, -1, -1, -1, -1, -1,
3101 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3102 -1, -1, 79, 80, 81, 82, 83, 84, 85, 86,
3103 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
3104 97, 98, 99, 100, 101, 102, 103, 104, -1, -1,
3105 -1, -1, -1, 110, -1, 112, -1, 114, 115, 116,
3106 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3107 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3108 -1, -1, 139, 140, 141, 142, 143, 144, 145, 146,
3109 147, 148, 149, 150, 151, -1, -1, -1, -1, -1,
3110 -1, 5, 6, 160, 8, 9, 10, 11, 12, 13,
3111 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3112 24, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3113 -1, -1, -1, 37, -1, -1, -1, -1, -1, -1,
3114 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003115 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003116 -1, 24, 5, 6, -1, 8, 9, 10, 11, 12,
3117 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3118 -1, 24, -1, -1, -1, 48, -1, -1, -1, -1,
3119 -1, -1, -1, -1, 37, -1, -1, -1, -1, -1,
3120 -1, -1, -1, 5, 6, 48, 8, 9, 10, 11,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003121 12, 13, 14, 15, 16, 17, 18, 19, -1, 21,
3122 22, -1, 24, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003123 -1, -1, -1, -1, -1, 37, -1, -1, -1, -1,
3124 -1, -1, -1, -1, -1, -1, 48, -1, -1, -1,
3125 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
3126 5, 6, -1, 8, 9, 10, 11, 12, 13, 14,
3127 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
3128 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3129 -1, 154, 37, -1, 157, -1, 159, 160, -1, 162,
3130 -1, -1, -1, 48, -1, -1, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003131 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003132 5, 6, -1, 8, 9, 10, 11, 12, 13, 14,
3133 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003134 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003135 -1, -1, 154, -1, -1, 157, -1, -1, 160, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003136 162, 5, 6, 48, 8, 9, 10, 11, 12, 13,
3137 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3138 24, 5, 6, -1, 8, 9, 10, 11, 12, 13,
3139 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
3140 24, -1, -1, -1, 48, -1, -1, -1, -1, 154,
3141 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
3142 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
3143 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3144 -1, 24, 5, 6, -1, 8, 9, 10, 11, 12,
3145 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
3146 -1, 24, -1, -1, -1, 48, -1, -1, -1, 154,
3147 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
3148 -1, -1, -1, -1, -1, 48, -1, -1, -1, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003149 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3150 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003151 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003152 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003153 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003154 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3155 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003156 -1, -1, -1, -1, 35, -1, -1, -1, -1, -1,
3157 -1, 154, -1, -1, 157, -1, -1, 160, 49, 162,
3158 -1, -1, -1, -1, -1, -1, -1, -1, 59, 60,
3159 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
3160 -1, 72, 73, 74, 75, 76, 77, 78, 79, 80,
3161 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
3162 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
3163 101, 102, 103, 104, 105, 106, 107, -1, -1, 110,
3164 111, 112, 113, 114, 115, 116, 117, 118, -1, -1,
3165 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
3166 -1, -1, -1, -1, -1, -1, -1, -1, 139, 140,
3167 141, 142, 143, 144, 145, 146, 147, 148, 149, 150,
3168 151
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003169};
3170
3171/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
3172 symbol of state STATE-NUM. */
David Greene5fd22a82007-09-04 18:46:50 +00003173static const unsigned char yystos[] =
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003174{
3175 0, 200, 201, 202, 0, 25, 31, 41, 42, 43,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003176 44, 45, 46, 47, 62, 181, 219, 222, 224, 232,
3177 22, 24, 51, 58, 62, 180, 212, 224, 225, 61,
3178 220, 23, 233, 234, 30, 163, 221, 233, 52, 53,
3179 54, 71, 209, 152, 61, 20, 45, 47, 50, 181,
3180 152, 45, 47, 223, 24, 207, 64, 65, 66, 67,
3181 68, 69, 70, 182, 217, 180, 238, 152, 152, 152,
3182 152, 157, 210, 207, 5, 6, 8, 9, 10, 11,
3183 12, 13, 14, 15, 16, 17, 18, 19, 21, 48,
3184 154, 157, 160, 162, 167, 189, 190, 191, 192, 193,
3185 212, 229, 32, 33, 199, 199, 199, 199, 226, 4,
3186 189, 29, 162, 218, 35, 49, 59, 60, 72, 73,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003187 74, 75, 76, 77, 78, 79, 80, 81, 82, 83,
3188 84, 85, 86, 87, 88, 89, 90, 91, 92, 93,
3189 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
3190 104, 105, 106, 107, 110, 111, 112, 113, 114, 115,
3191 116, 117, 118, 139, 140, 141, 142, 143, 144, 145,
3192 146, 147, 148, 149, 150, 151, 169, 170, 171, 174,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003193 175, 235, 236, 242, 243, 245, 246, 24, 55, 56,
3194 208, 4, 24, 24, 211, 4, 4, 4, 162, 8,
3195 163, 193, 194, 155, 164, 191, 191, 191, 9, 10,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003196 11, 12, 13, 14, 15, 16, 17, 18, 19, 176,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003197 177, 179, 191, 196, 217, 212, 191, 231, 59, 8,
3198 231, 9, 21, 10, 11, 12, 13, 14, 15, 16,
3199 17, 176, 177, 178, 182, 119, 120, 121, 122, 123,
3200 124, 125, 126, 127, 128, 172, 27, 28, 125, 126,
3201 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
3202 137, 138, 173, 191, 191, 231, 191, 191, 239, 231,
3203 231, 231, 231, 231, 231, 231, 191, 191, 191, 231,
3204 231, 182, 108, 109, 153, 159, 158, 158, 163, 194,
3205 153, 163, 37, 194, 195, 205, 206, 204, 27, 28,
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003206 3, 4, 168, 4, 7, 26, 38, 39, 103, 104,
3207 110, 112, 114, 115, 116, 157, 160, 162, 165, 169,
Reid Spencerd2920cd2007-03-21 17:27:53 +00003208 170, 171, 174, 175, 197, 229, 203, 155, 3, 4,
3209 7, 26, 27, 28, 38, 39, 61, 160, 197, 228,
3210 229, 230, 230, 230, 230, 189, 191, 191, 153, 184,
3211 153, 184, 230, 157, 153, 153, 153, 153, 153, 153,
3212 153, 153, 230, 230, 230, 153, 36, 189, 191, 231,
3213 24, 193, 193, 161, 163, 193, 153, 156, 153, 187,
3214 187, 187, 172, 173, 155, 155, 155, 155, 155, 159,
3215 196, 198, 162, 198, 163, 198, 24, 155, 155, 155,
3216 155, 155, 187, 37, 191, 214, 215, 216, 63, 227,
3217 198, 153, 153, 230, 230, 230, 15, 57, 15, 153,
3218 244, 230, 157, 231, 191, 231, 231, 231, 191, 191,
3219 153, 153, 153, 231, 191, 230, 230, 153, 159, 161,
3220 161, 37, 34, 57, 185, 188, 155, 155, 196, 196,
3221 196, 196, 196, 153, 159, 163, 193, 198, 161, 163,
3222 196, 196, 196, 196, 196, 212, 213, 153, 156, 24,
3223 161, 21, 21, 155, 153, 153, 230, 4, 230, 231,
3224 240, 153, 230, 153, 153, 153, 230, 230, 230, 155,
3225 191, 24, 4, 187, 196, 196, 244, 153, 153, 153,
3226 153, 196, 161, 163, 153, 153, 153, 153, 36, 37,
3227 214, 185, 186, 153, 230, 230, 240, 241, 230, 230,
3228 153, 184, 184, 153, 230, 153, 231, 231, 231, 241,
3229 230, 153, 153, 156, 196, 196, 196, 196, 161, 196,
3230 196, 196, 196, 191, 57, 183, 24, 153, 157, 156,
3231 231, 159, 230, 156, 196, 196, 153, 156, 153, 153,
3232 156, 156, 156, 156, 156, 4, 21, 159, 178, 237,
3233 36, 159, 156, 156, 196, 196, 196, 230, 228, 159,
3234 178, 21, 156, 156, 156, 153, 228, 230, 21, 153,
3235 235, 230, 21, 21, 230, 230
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003236};
Reid Spencere7c3c602006-11-30 06:36:44 +00003237
David Greene5fd22a82007-09-04 18:46:50 +00003238#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
3239# define YYSIZE_T __SIZE_TYPE__
3240#endif
3241#if ! defined (YYSIZE_T) && defined (size_t)
3242# define YYSIZE_T size_t
3243#endif
3244#if ! defined (YYSIZE_T)
3245# if defined (__STDC__) || defined (__cplusplus)
3246# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
3247# define YYSIZE_T size_t
3248# endif
3249#endif
3250#if ! defined (YYSIZE_T)
3251# define YYSIZE_T unsigned int
3252#endif
3253
Reid Spencere7c3c602006-11-30 06:36:44 +00003254#define yyerrok (yyerrstatus = 0)
3255#define yyclearin (yychar = YYEMPTY)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003256#define YYEMPTY (-2)
Reid Spencere7c3c602006-11-30 06:36:44 +00003257#define YYEOF 0
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003258
Reid Spencere7c3c602006-11-30 06:36:44 +00003259#define YYACCEPT goto yyacceptlab
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003260#define YYABORT goto yyabortlab
3261#define YYERROR goto yyerrorlab
3262
3263
3264/* Like YYERROR except do call yyerror. This remains here temporarily
3265 to ease the transition to the new meaning of YYERROR, for GCC.
Reid Spencere7c3c602006-11-30 06:36:44 +00003266 Once GCC version 2 has supplanted version 1, this can go. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003267
Reid Spencere7c3c602006-11-30 06:36:44 +00003268#define YYFAIL goto yyerrlab
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003269
Reid Spencere7c3c602006-11-30 06:36:44 +00003270#define YYRECOVERING() (!!yyerrstatus)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003271
3272#define YYBACKUP(Token, Value) \
Reid Spencere7c3c602006-11-30 06:36:44 +00003273do \
3274 if (yychar == YYEMPTY && yylen == 1) \
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003275 { \
3276 yychar = (Token); \
3277 yylval = (Value); \
3278 yytoken = YYTRANSLATE (yychar); \
David Greene5fd22a82007-09-04 18:46:50 +00003279 YYPOPSTACK; \
Reid Spencere7c3c602006-11-30 06:36:44 +00003280 goto yybackup; \
3281 } \
3282 else \
David Greene5fd22a82007-09-04 18:46:50 +00003283 { \
3284 yyerror ("syntax error: cannot back up");\
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003285 YYERROR; \
3286 } \
David Greene5fd22a82007-09-04 18:46:50 +00003287while (0)
Reid Spencere7c3c602006-11-30 06:36:44 +00003288
Reid Spencere7c3c602006-11-30 06:36:44 +00003289#define YYTERROR 1
3290#define YYERRCODE 256
3291
David Greene5fd22a82007-09-04 18:46:50 +00003292/* YYLLOC_DEFAULT -- Compute the default location (before the actions
3293 are run). */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003294
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003295#ifndef YYLLOC_DEFAULT
David Greene5fd22a82007-09-04 18:46:50 +00003296# define YYLLOC_DEFAULT(Current, Rhs, N) \
3297 ((Current).first_line = (Rhs)[1].first_line, \
3298 (Current).first_column = (Rhs)[1].first_column, \
3299 (Current).last_line = (Rhs)[N].last_line, \
3300 (Current).last_column = (Rhs)[N].last_column)
Reid Spencere7c3c602006-11-30 06:36:44 +00003301#endif
3302
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003303/* YYLEX -- calling `yylex' with the right arguments. */
3304
Reid Spencer950bf602007-01-26 08:19:09 +00003305#ifdef YYLEX_PARAM
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003306# define YYLEX yylex (YYLEX_PARAM)
Reid Spencer950bf602007-01-26 08:19:09 +00003307#else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003308# define YYLEX yylex ()
Chris Lattner4227bdb2007-02-19 07:34:02 +00003309#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003310
3311/* Enable debugging if requested. */
3312#if YYDEBUG
3313
3314# ifndef YYFPRINTF
3315# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
3316# define YYFPRINTF fprintf
3317# endif
3318
3319# define YYDPRINTF(Args) \
3320do { \
3321 if (yydebug) \
3322 YYFPRINTF Args; \
David Greene5fd22a82007-09-04 18:46:50 +00003323} while (0)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003324
David Greene5fd22a82007-09-04 18:46:50 +00003325# define YYDSYMPRINT(Args) \
3326do { \
3327 if (yydebug) \
3328 yysymprint Args; \
3329} while (0)
David Greene718fda32007-08-01 03:59:32 +00003330
David Greene5fd22a82007-09-04 18:46:50 +00003331# define YYDSYMPRINTF(Title, Token, Value, Location) \
3332do { \
3333 if (yydebug) \
3334 { \
3335 YYFPRINTF (stderr, "%s ", Title); \
3336 yysymprint (stderr, \
3337 Token, Value); \
3338 YYFPRINTF (stderr, "\n"); \
3339 } \
3340} while (0)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003341
3342/*------------------------------------------------------------------.
3343| yy_stack_print -- Print the state stack from its BOTTOM up to its |
3344| TOP (included). |
3345`------------------------------------------------------------------*/
3346
David Greene5fd22a82007-09-04 18:46:50 +00003347#if defined (__STDC__) || defined (__cplusplus)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003348static void
David Greene5fd22a82007-09-04 18:46:50 +00003349yy_stack_print (short *bottom, short *top)
Chris Lattner4227bdb2007-02-19 07:34:02 +00003350#else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003351static void
3352yy_stack_print (bottom, top)
David Greene5fd22a82007-09-04 18:46:50 +00003353 short *bottom;
3354 short *top;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003355#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003356{
3357 YYFPRINTF (stderr, "Stack now");
David Greene5fd22a82007-09-04 18:46:50 +00003358 for (/* Nothing. */; bottom <= top; ++bottom)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003359 YYFPRINTF (stderr, " %d", *bottom);
3360 YYFPRINTF (stderr, "\n");
3361}
3362
3363# define YY_STACK_PRINT(Bottom, Top) \
3364do { \
3365 if (yydebug) \
3366 yy_stack_print ((Bottom), (Top)); \
David Greene5fd22a82007-09-04 18:46:50 +00003367} while (0)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003368
3369
3370/*------------------------------------------------.
3371| Report that the YYRULE is going to be reduced. |
3372`------------------------------------------------*/
3373
David Greene5fd22a82007-09-04 18:46:50 +00003374#if defined (__STDC__) || defined (__cplusplus)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003375static void
David Greene5fd22a82007-09-04 18:46:50 +00003376yy_reduce_print (int yyrule)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003377#else
3378static void
David Greene5fd22a82007-09-04 18:46:50 +00003379yy_reduce_print (yyrule)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003380 int yyrule;
Chris Lattnercf3d0612007-02-13 06:04:17 +00003381#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003382{
3383 int yyi;
David Greene5fd22a82007-09-04 18:46:50 +00003384 unsigned int yylno = yyrline[yyrule];
3385 YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ",
3386 yyrule - 1, yylno);
3387 /* Print the symbols being reduced, and their result. */
3388 for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
3389 YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]);
3390 YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003391}
Reid Spencer9d6565a2007-02-15 02:26:10 +00003392
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003393# define YY_REDUCE_PRINT(Rule) \
3394do { \
3395 if (yydebug) \
David Greene5fd22a82007-09-04 18:46:50 +00003396 yy_reduce_print (Rule); \
3397} while (0)
Reid Spencer9d6565a2007-02-15 02:26:10 +00003398
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003399/* Nonzero means print parse trace. It is left uninitialized so that
3400 multiple parsers can coexist. */
3401int yydebug;
3402#else /* !YYDEBUG */
3403# define YYDPRINTF(Args)
David Greene5fd22a82007-09-04 18:46:50 +00003404# define YYDSYMPRINT(Args)
3405# define YYDSYMPRINTF(Title, Token, Value, Location)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003406# define YY_STACK_PRINT(Bottom, Top)
3407# define YY_REDUCE_PRINT(Rule)
3408#endif /* !YYDEBUG */
Reid Spencer9d6565a2007-02-15 02:26:10 +00003409
Reid Spencer9d6565a2007-02-15 02:26:10 +00003410
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003411/* YYINITDEPTH -- initial size of the parser's stacks. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003412#ifndef YYINITDEPTH
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003413# define YYINITDEPTH 200
Reid Spencere7c3c602006-11-30 06:36:44 +00003414#endif
3415
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003416/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
3417 if the built-in stack extension method is used).
Reid Spencere7c3c602006-11-30 06:36:44 +00003418
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003419 Do not make this value too large; the results are undefined if
David Greene5fd22a82007-09-04 18:46:50 +00003420 SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003421 evaluated with infinite-precision integer arithmetic. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003422
David Greene5fd22a82007-09-04 18:46:50 +00003423#if defined (YYMAXDEPTH) && YYMAXDEPTH == 0
3424# undef YYMAXDEPTH
3425#endif
3426
Reid Spencere7c3c602006-11-30 06:36:44 +00003427#ifndef YYMAXDEPTH
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003428# define YYMAXDEPTH 10000
Reid Spencere7c3c602006-11-30 06:36:44 +00003429#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003430
Reid Spencere7c3c602006-11-30 06:36:44 +00003431
3432
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003433#if YYERROR_VERBOSE
Reid Spencere7c3c602006-11-30 06:36:44 +00003434
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003435# ifndef yystrlen
David Greene5fd22a82007-09-04 18:46:50 +00003436# if defined (__GLIBC__) && defined (_STRING_H)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003437# define yystrlen strlen
3438# else
3439/* Return the length of YYSTR. */
3440static YYSIZE_T
David Greene5fd22a82007-09-04 18:46:50 +00003441# if defined (__STDC__) || defined (__cplusplus)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003442yystrlen (const char *yystr)
David Greene5fd22a82007-09-04 18:46:50 +00003443# else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003444yystrlen (yystr)
David Greene5fd22a82007-09-04 18:46:50 +00003445 const char *yystr;
3446# endif
Chris Lattner4227bdb2007-02-19 07:34:02 +00003447{
David Greene5fd22a82007-09-04 18:46:50 +00003448 register const char *yys = yystr;
3449
3450 while (*yys++ != '\0')
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003451 continue;
David Greene5fd22a82007-09-04 18:46:50 +00003452
3453 return yys - yystr - 1;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003454}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003455# endif
3456# endif
Chris Lattner4227bdb2007-02-19 07:34:02 +00003457
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003458# ifndef yystpcpy
David Greene5fd22a82007-09-04 18:46:50 +00003459# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003460# define yystpcpy stpcpy
3461# else
3462/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
3463 YYDEST. */
3464static char *
David Greene5fd22a82007-09-04 18:46:50 +00003465# if defined (__STDC__) || defined (__cplusplus)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003466yystpcpy (char *yydest, const char *yysrc)
David Greene5fd22a82007-09-04 18:46:50 +00003467# else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003468yystpcpy (yydest, yysrc)
David Greene5fd22a82007-09-04 18:46:50 +00003469 char *yydest;
3470 const char *yysrc;
3471# endif
Chris Lattner4227bdb2007-02-19 07:34:02 +00003472{
David Greene5fd22a82007-09-04 18:46:50 +00003473 register char *yyd = yydest;
3474 register const char *yys = yysrc;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003475
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003476 while ((*yyd++ = *yys++) != '\0')
3477 continue;
3478
3479 return yyd - 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
David Greene5fd22a82007-09-04 18:46:50 +00003484#endif /* !YYERROR_VERBOSE */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003485
Reid Spencer9d6565a2007-02-15 02:26:10 +00003486
3487
David Greene5fd22a82007-09-04 18:46:50 +00003488#if YYDEBUG
3489/*--------------------------------.
3490| Print this symbol on YYOUTPUT. |
3491`--------------------------------*/
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003492
David Greene5fd22a82007-09-04 18:46:50 +00003493#if defined (__STDC__) || defined (__cplusplus)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003494static void
David Greene5fd22a82007-09-04 18:46:50 +00003495yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003496#else
3497static void
David Greene5fd22a82007-09-04 18:46:50 +00003498yysymprint (yyoutput, yytype, yyvaluep)
3499 FILE *yyoutput;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003500 int yytype;
3501 YYSTYPE *yyvaluep;
3502#endif
3503{
David Greene5fd22a82007-09-04 18:46:50 +00003504 /* Pacify ``unused variable'' warnings. */
3505 (void) yyvaluep;
Chandler Carruth02202192007-08-04 01:56:21 +00003506
David Greene5fd22a82007-09-04 18:46:50 +00003507 if (yytype < YYNTOKENS)
3508 {
3509 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
3510# ifdef YYPRINT
3511 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
3512# endif
3513 }
3514 else
3515 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
3516
3517 switch (yytype)
3518 {
3519 default:
3520 break;
3521 }
3522 YYFPRINTF (yyoutput, ")");
3523}
3524
3525#endif /* ! YYDEBUG */
3526/*-----------------------------------------------.
3527| Release the memory associated to this symbol. |
3528`-----------------------------------------------*/
3529
3530#if defined (__STDC__) || defined (__cplusplus)
3531static void
3532yydestruct (int yytype, YYSTYPE *yyvaluep)
3533#else
3534static void
3535yydestruct (yytype, yyvaluep)
3536 int yytype;
3537 YYSTYPE *yyvaluep;
3538#endif
3539{
3540 /* Pacify ``unused variable'' warnings. */
3541 (void) yyvaluep;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003542
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003543 switch (yytype)
3544 {
3545
3546 default:
David Greene5fd22a82007-09-04 18:46:50 +00003547 break;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003548 }
3549}
3550
3551
3552/* Prevent warnings from -Wmissing-prototypes. */
3553
3554#ifdef YYPARSE_PARAM
David Greene5fd22a82007-09-04 18:46:50 +00003555# if defined (__STDC__) || defined (__cplusplus)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003556int yyparse (void *YYPARSE_PARAM);
David Greene5fd22a82007-09-04 18:46:50 +00003557# else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003558int yyparse ();
David Greene5fd22a82007-09-04 18:46:50 +00003559# endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003560#else /* ! YYPARSE_PARAM */
David Greene5fd22a82007-09-04 18:46:50 +00003561#if defined (__STDC__) || defined (__cplusplus)
Reid Spencere7c3c602006-11-30 06:36:44 +00003562int yyparse (void);
Chris Lattner4227bdb2007-02-19 07:34:02 +00003563#else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003564int yyparse ();
3565#endif
3566#endif /* ! YYPARSE_PARAM */
3567
3568
3569
David Greene5fd22a82007-09-04 18:46:50 +00003570/* The lookahead symbol. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003571int yychar;
3572
David Greene5fd22a82007-09-04 18:46:50 +00003573/* The semantic value of the lookahead symbol. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003574YYSTYPE yylval;
3575
3576/* Number of syntax errors so far. */
3577int yynerrs;
3578
3579
3580
3581/*----------.
3582| yyparse. |
3583`----------*/
3584
3585#ifdef YYPARSE_PARAM
David Greene5fd22a82007-09-04 18:46:50 +00003586# if defined (__STDC__) || defined (__cplusplus)
3587int yyparse (void *YYPARSE_PARAM)
3588# else
3589int yyparse (YYPARSE_PARAM)
3590 void *YYPARSE_PARAM;
3591# endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003592#else /* ! YYPARSE_PARAM */
David Greene5fd22a82007-09-04 18:46:50 +00003593#if defined (__STDC__) || defined (__cplusplus)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003594int
3595yyparse (void)
3596#else
3597int
3598yyparse ()
3599
3600#endif
3601#endif
3602{
3603
David Greene5fd22a82007-09-04 18:46:50 +00003604 register int yystate;
3605 register int yyn;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003606 int yyresult;
3607 /* Number of tokens to shift before error messages enabled. */
3608 int yyerrstatus;
David Greene5fd22a82007-09-04 18:46:50 +00003609 /* Lookahead token as an internal (translated) token number. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003610 int yytoken = 0;
3611
3612 /* Three stacks and their tools:
3613 `yyss': related to states,
3614 `yyvs': related to semantic values,
3615 `yyls': related to locations.
3616
3617 Refer to the stacks thru separate pointers, to allow yyoverflow
3618 to reallocate them elsewhere. */
3619
3620 /* The state stack. */
David Greene5fd22a82007-09-04 18:46:50 +00003621 short yyssa[YYINITDEPTH];
3622 short *yyss = yyssa;
3623 register short *yyssp;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003624
3625 /* The semantic value stack. */
3626 YYSTYPE yyvsa[YYINITDEPTH];
3627 YYSTYPE *yyvs = yyvsa;
David Greene5fd22a82007-09-04 18:46:50 +00003628 register YYSTYPE *yyvsp;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003629
3630
3631
David Greene5fd22a82007-09-04 18:46:50 +00003632#define YYPOPSTACK (yyvsp--, yyssp--)
Reid Spencere7c3c602006-11-30 06:36:44 +00003633
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003634 YYSIZE_T yystacksize = YYINITDEPTH;
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003635
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003636 /* The variables used to return semantic value and location from the
3637 action routines. */
3638 YYSTYPE yyval;
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003639
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003640
David Greene5fd22a82007-09-04 18:46:50 +00003641 /* When reducing, the number of symbols on the RHS of the reduced
3642 rule. */
3643 int yylen;
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003644
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003645 YYDPRINTF ((stderr, "Starting parse\n"));
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003646
Reid Spencere7c3c602006-11-30 06:36:44 +00003647 yystate = 0;
3648 yyerrstatus = 0;
3649 yynerrs = 0;
3650 yychar = YYEMPTY; /* Cause a token to be read. */
3651
3652 /* Initialize stack pointers.
3653 Waste one element of value and location stack
3654 so that they stay on the same level as the state stack.
3655 The wasted elements are never initialized. */
3656
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003657 yyssp = yyss;
Reid Spencere7c3c602006-11-30 06:36:44 +00003658 yyvsp = yyvs;
3659
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003660 goto yysetstate;
Reid Spencere7c3c602006-11-30 06:36:44 +00003661
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003662/*------------------------------------------------------------.
3663| yynewstate -- Push a new state, which is found in yystate. |
3664`------------------------------------------------------------*/
3665 yynewstate:
3666 /* In all cases, when you get here, the value and location stacks
David Greene5fd22a82007-09-04 18:46:50 +00003667 have just been pushed. so pushing a state here evens the stacks.
3668 */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003669 yyssp++;
Reid Spencere7c3c602006-11-30 06:36:44 +00003670
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003671 yysetstate:
3672 *yyssp = yystate;
3673
3674 if (yyss + yystacksize - 1 <= yyssp)
Reid Spencere7c3c602006-11-30 06:36:44 +00003675 {
3676 /* Get the current used size of the three stacks, in elements. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003677 YYSIZE_T yysize = yyssp - yyss + 1;
Reid Spencere7c3c602006-11-30 06:36:44 +00003678
3679#ifdef yyoverflow
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003680 {
David Greene5fd22a82007-09-04 18:46:50 +00003681 /* Give user a chance to reallocate the stack. Use copies of
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003682 these so that the &'s don't force the real ones into
3683 memory. */
3684 YYSTYPE *yyvs1 = yyvs;
David Greene5fd22a82007-09-04 18:46:50 +00003685 short *yyss1 = yyss;
Reid Spencere7c3c602006-11-30 06:36:44 +00003686
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003687
3688 /* Each stack pointer address is followed by the size of the
3689 data in use in that stack, in bytes. This used to be a
3690 conditional around just the two extra args, but that might
3691 be undefined if yyoverflow is a macro. */
David Greene5fd22a82007-09-04 18:46:50 +00003692 yyoverflow ("parser stack overflow",
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003693 &yyss1, yysize * sizeof (*yyssp),
3694 &yyvs1, yysize * sizeof (*yyvsp),
3695
3696 &yystacksize);
3697
3698 yyss = yyss1;
3699 yyvs = yyvs1;
3700 }
Reid Spencere7c3c602006-11-30 06:36:44 +00003701#else /* no yyoverflow */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003702# ifndef YYSTACK_RELOCATE
David Greene5fd22a82007-09-04 18:46:50 +00003703 goto yyoverflowlab;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003704# else
Reid Spencere7c3c602006-11-30 06:36:44 +00003705 /* Extend the stack our own way. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003706 if (YYMAXDEPTH <= yystacksize)
David Greene5fd22a82007-09-04 18:46:50 +00003707 goto yyoverflowlab;
Reid Spencere7c3c602006-11-30 06:36:44 +00003708 yystacksize *= 2;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003709 if (YYMAXDEPTH < yystacksize)
Reid Spencere7c3c602006-11-30 06:36:44 +00003710 yystacksize = YYMAXDEPTH;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003711
3712 {
David Greene5fd22a82007-09-04 18:46:50 +00003713 short *yyss1 = yyss;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003714 union yyalloc *yyptr =
3715 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
3716 if (! yyptr)
David Greene5fd22a82007-09-04 18:46:50 +00003717 goto yyoverflowlab;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003718 YYSTACK_RELOCATE (yyss);
3719 YYSTACK_RELOCATE (yyvs);
3720
3721# undef YYSTACK_RELOCATE
3722 if (yyss1 != yyssa)
3723 YYSTACK_FREE (yyss1);
3724 }
3725# endif
Reid Spencere7c3c602006-11-30 06:36:44 +00003726#endif /* no yyoverflow */
3727
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003728 yyssp = yyss + yysize - 1;
3729 yyvsp = yyvs + yysize - 1;
Reid Spencere7c3c602006-11-30 06:36:44 +00003730
3731
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003732 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
3733 (unsigned long int) yystacksize));
3734
3735 if (yyss + yystacksize - 1 <= yyssp)
Reid Spencere7c3c602006-11-30 06:36:44 +00003736 YYABORT;
3737 }
3738
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003739 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
Reid Spencere7c3c602006-11-30 06:36:44 +00003740
3741 goto yybackup;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003742
3743/*-----------.
3744| yybackup. |
3745`-----------*/
3746yybackup:
Reid Spencere7c3c602006-11-30 06:36:44 +00003747
David Greene5fd22a82007-09-04 18:46:50 +00003748/* Do appropriate processing given the current state. */
3749/* Read a lookahead token if we need one and don't already have one. */
3750/* yyresume: */
Reid Spencere7c3c602006-11-30 06:36:44 +00003751
David Greene5fd22a82007-09-04 18:46:50 +00003752 /* First try to decide what to do without reference to lookahead token. */
3753
Reid Spencere7c3c602006-11-30 06:36:44 +00003754 yyn = yypact[yystate];
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003755 if (yyn == YYPACT_NINF)
Reid Spencere7c3c602006-11-30 06:36:44 +00003756 goto yydefault;
3757
David Greene5fd22a82007-09-04 18:46:50 +00003758 /* Not known => get a lookahead token if don't already have one. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003759
David Greene5fd22a82007-09-04 18:46:50 +00003760 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003761 if (yychar == YYEMPTY)
3762 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003763 YYDPRINTF ((stderr, "Reading a token: "));
Reid Spencere7c3c602006-11-30 06:36:44 +00003764 yychar = YYLEX;
3765 }
3766
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003767 if (yychar <= YYEOF)
Reid Spencere7c3c602006-11-30 06:36:44 +00003768 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003769 yychar = yytoken = YYEOF;
3770 YYDPRINTF ((stderr, "Now at end of input.\n"));
Reid Spencere7c3c602006-11-30 06:36:44 +00003771 }
3772 else
3773 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003774 yytoken = YYTRANSLATE (yychar);
David Greene5fd22a82007-09-04 18:46:50 +00003775 YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc);
Reid Spencere7c3c602006-11-30 06:36:44 +00003776 }
3777
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003778 /* If the proper action on seeing token YYTOKEN is to reduce or to
3779 detect an error, take that action. */
3780 yyn += yytoken;
3781 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
Reid Spencere7c3c602006-11-30 06:36:44 +00003782 goto yydefault;
3783 yyn = yytable[yyn];
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003784 if (yyn <= 0)
Reid Spencere7c3c602006-11-30 06:36:44 +00003785 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003786 if (yyn == 0 || yyn == YYTABLE_NINF)
Reid Spencere7c3c602006-11-30 06:36:44 +00003787 goto yyerrlab;
3788 yyn = -yyn;
3789 goto yyreduce;
3790 }
3791
3792 if (yyn == YYFINAL)
3793 YYACCEPT;
3794
David Greene5fd22a82007-09-04 18:46:50 +00003795 /* Shift the lookahead token. */
3796 YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken]));
3797
3798 /* Discard the token being shifted unless it is eof. */
3799 if (yychar != YYEOF)
3800 yychar = YYEMPTY;
3801
3802 *++yyvsp = yylval;
3803
3804
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003805 /* Count tokens shifted since error; after three, turn off error
3806 status. */
3807 if (yyerrstatus)
3808 yyerrstatus--;
Chris Lattnercf3d0612007-02-13 06:04:17 +00003809
3810 yystate = yyn;
Reid Spencere7c3c602006-11-30 06:36:44 +00003811 goto yynewstate;
3812
Chris Lattner4227bdb2007-02-19 07:34:02 +00003813
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003814/*-----------------------------------------------------------.
3815| yydefault -- do the default action for the current state. |
3816`-----------------------------------------------------------*/
3817yydefault:
Reid Spencere7c3c602006-11-30 06:36:44 +00003818 yyn = yydefact[yystate];
3819 if (yyn == 0)
3820 goto yyerrlab;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003821 goto yyreduce;
Reid Spencere7c3c602006-11-30 06:36:44 +00003822
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003823
3824/*-----------------------------.
3825| yyreduce -- Do a reduction. |
3826`-----------------------------*/
Reid Spencere7c3c602006-11-30 06:36:44 +00003827yyreduce:
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003828 /* yyn is the number of a rule to reduce with. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003829 yylen = yyr2[yyn];
3830
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003831 /* If YYLEN is nonzero, implement the default value of the action:
3832 `$$ = $1'.
3833
3834 Otherwise, the following line sets YYVAL to garbage.
3835 This behavior is undocumented and Bison
3836 users should not rely upon it. Assigning to YYVAL
3837 unconditionally makes the parser a bit smaller, and it avoids a
3838 GCC warning that YYVAL may be used uninitialized. */
3839 yyval = yyvsp[1-yylen];
3840
3841
3842 YY_REDUCE_PRINT (yyn);
3843 switch (yyn)
Reid Spencere7c3c602006-11-30 06:36:44 +00003844 {
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003845 case 3:
David Greene5fd22a82007-09-04 18:46:50 +00003846#line 1891 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003847 {
David Greene5fd22a82007-09-04 18:46:50 +00003848 if (yyvsp[0].UIntVal > (uint32_t)INT32_MAX) // Outside of my range!
Reid Spencer950bf602007-01-26 08:19:09 +00003849 error("Value too large for type");
David Greene5fd22a82007-09-04 18:46:50 +00003850 yyval.SIntVal = (int32_t)yyvsp[0].UIntVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003851 ;}
3852 break;
3853
3854 case 5:
David Greene5fd22a82007-09-04 18:46:50 +00003855#line 1900 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003856 {
David Greene5fd22a82007-09-04 18:46:50 +00003857 if (yyvsp[0].UInt64Val > (uint64_t)INT64_MAX) // Outside of my range!
Reid Spencer950bf602007-01-26 08:19:09 +00003858 error("Value too large for type");
David Greene5fd22a82007-09-04 18:46:50 +00003859 yyval.SInt64Val = (int64_t)yyvsp[0].UInt64Val;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003860 ;}
3861 break;
3862
3863 case 26:
David Greene5fd22a82007-09-04 18:46:50 +00003864#line 1922 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3865 { yyval.IPred = ICmpInst::ICMP_EQ; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003866 break;
3867
3868 case 27:
David Greene5fd22a82007-09-04 18:46:50 +00003869#line 1922 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3870 { yyval.IPred = ICmpInst::ICMP_NE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003871 break;
3872
3873 case 28:
David Greene5fd22a82007-09-04 18:46:50 +00003874#line 1923 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3875 { yyval.IPred = ICmpInst::ICMP_SLT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003876 break;
3877
3878 case 29:
David Greene5fd22a82007-09-04 18:46:50 +00003879#line 1923 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3880 { yyval.IPred = ICmpInst::ICMP_SGT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003881 break;
3882
3883 case 30:
David Greene5fd22a82007-09-04 18:46:50 +00003884#line 1924 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3885 { yyval.IPred = ICmpInst::ICMP_SLE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003886 break;
3887
3888 case 31:
David Greene5fd22a82007-09-04 18:46:50 +00003889#line 1924 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3890 { yyval.IPred = ICmpInst::ICMP_SGE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003891 break;
3892
3893 case 32:
David Greene5fd22a82007-09-04 18:46:50 +00003894#line 1925 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3895 { yyval.IPred = ICmpInst::ICMP_ULT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003896 break;
3897
3898 case 33:
David Greene5fd22a82007-09-04 18:46:50 +00003899#line 1925 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3900 { yyval.IPred = ICmpInst::ICMP_UGT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003901 break;
3902
3903 case 34:
David Greene5fd22a82007-09-04 18:46:50 +00003904#line 1926 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3905 { yyval.IPred = ICmpInst::ICMP_ULE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003906 break;
3907
3908 case 35:
David Greene5fd22a82007-09-04 18:46:50 +00003909#line 1926 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3910 { yyval.IPred = ICmpInst::ICMP_UGE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003911 break;
3912
3913 case 36:
David Greene5fd22a82007-09-04 18:46:50 +00003914#line 1930 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3915 { yyval.FPred = FCmpInst::FCMP_OEQ; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003916 break;
3917
3918 case 37:
David Greene5fd22a82007-09-04 18:46:50 +00003919#line 1930 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3920 { yyval.FPred = FCmpInst::FCMP_ONE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003921 break;
3922
3923 case 38:
David Greene5fd22a82007-09-04 18:46:50 +00003924#line 1931 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3925 { yyval.FPred = FCmpInst::FCMP_OLT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003926 break;
3927
3928 case 39:
David Greene5fd22a82007-09-04 18:46:50 +00003929#line 1931 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3930 { yyval.FPred = FCmpInst::FCMP_OGT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003931 break;
3932
3933 case 40:
David Greene5fd22a82007-09-04 18:46:50 +00003934#line 1932 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3935 { yyval.FPred = FCmpInst::FCMP_OLE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003936 break;
3937
3938 case 41:
David Greene5fd22a82007-09-04 18:46:50 +00003939#line 1932 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3940 { yyval.FPred = FCmpInst::FCMP_OGE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003941 break;
3942
3943 case 42:
David Greene5fd22a82007-09-04 18:46:50 +00003944#line 1933 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3945 { yyval.FPred = FCmpInst::FCMP_ORD; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003946 break;
3947
3948 case 43:
David Greene5fd22a82007-09-04 18:46:50 +00003949#line 1933 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3950 { yyval.FPred = FCmpInst::FCMP_UNO; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003951 break;
3952
3953 case 44:
David Greene5fd22a82007-09-04 18:46:50 +00003954#line 1934 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3955 { yyval.FPred = FCmpInst::FCMP_UEQ; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003956 break;
3957
3958 case 45:
David Greene5fd22a82007-09-04 18:46:50 +00003959#line 1934 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3960 { yyval.FPred = FCmpInst::FCMP_UNE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003961 break;
3962
3963 case 46:
David Greene5fd22a82007-09-04 18:46:50 +00003964#line 1935 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3965 { yyval.FPred = FCmpInst::FCMP_ULT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003966 break;
3967
3968 case 47:
David Greene5fd22a82007-09-04 18:46:50 +00003969#line 1935 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3970 { yyval.FPred = FCmpInst::FCMP_UGT; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003971 break;
3972
3973 case 48:
David Greene5fd22a82007-09-04 18:46:50 +00003974#line 1936 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3975 { yyval.FPred = FCmpInst::FCMP_ULE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003976 break;
3977
3978 case 49:
David Greene5fd22a82007-09-04 18:46:50 +00003979#line 1936 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3980 { yyval.FPred = FCmpInst::FCMP_UGE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003981 break;
3982
3983 case 50:
David Greene5fd22a82007-09-04 18:46:50 +00003984#line 1937 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3985 { yyval.FPred = FCmpInst::FCMP_TRUE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003986 break;
3987
3988 case 51:
David Greene5fd22a82007-09-04 18:46:50 +00003989#line 1938 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
3990 { yyval.FPred = FCmpInst::FCMP_FALSE; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003991 break;
3992
3993 case 81:
David Greene5fd22a82007-09-04 18:46:50 +00003994#line 1969 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003995 {
David Greene5fd22a82007-09-04 18:46:50 +00003996 yyval.StrVal = yyvsp[-1].StrVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00003997 ;}
3998 break;
3999
4000 case 82:
David Greene5fd22a82007-09-04 18:46:50 +00004001#line 1972 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004002 {
David Greene5fd22a82007-09-04 18:46:50 +00004003 yyval.StrVal = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004004 ;}
4005 break;
4006
4007 case 83:
David Greene5fd22a82007-09-04 18:46:50 +00004008#line 1977 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4009 { yyval.Linkage = GlobalValue::InternalLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004010 break;
4011
4012 case 84:
David Greene5fd22a82007-09-04 18:46:50 +00004013#line 1978 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4014 { yyval.Linkage = GlobalValue::LinkOnceLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004015 break;
4016
4017 case 85:
David Greene5fd22a82007-09-04 18:46:50 +00004018#line 1979 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4019 { yyval.Linkage = GlobalValue::WeakLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004020 break;
4021
4022 case 86:
David Greene5fd22a82007-09-04 18:46:50 +00004023#line 1980 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4024 { yyval.Linkage = GlobalValue::AppendingLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004025 break;
4026
4027 case 87:
David Greene5fd22a82007-09-04 18:46:50 +00004028#line 1981 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4029 { yyval.Linkage = GlobalValue::DLLImportLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004030 break;
4031
4032 case 88:
David Greene5fd22a82007-09-04 18:46:50 +00004033#line 1982 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4034 { yyval.Linkage = GlobalValue::DLLExportLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004035 break;
4036
4037 case 89:
David Greene5fd22a82007-09-04 18:46:50 +00004038#line 1983 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4039 { yyval.Linkage = GlobalValue::ExternalWeakLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004040 break;
4041
4042 case 90:
David Greene5fd22a82007-09-04 18:46:50 +00004043#line 1984 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4044 { yyval.Linkage = GlobalValue::ExternalLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004045 break;
4046
4047 case 91:
David Greene5fd22a82007-09-04 18:46:50 +00004048#line 1988 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4049 { yyval.UIntVal = lastCallingConv = OldCallingConv::C; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004050 break;
4051
Reid Spencere59f4932007-04-16 03:05:01 +00004052 case 92:
David Greene5fd22a82007-09-04 18:46:50 +00004053#line 1989 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4054 { yyval.UIntVal = lastCallingConv = OldCallingConv::C; ;}
Reid Spencere59f4932007-04-16 03:05:01 +00004055 break;
4056
4057 case 93:
David Greene5fd22a82007-09-04 18:46:50 +00004058#line 1990 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4059 { yyval.UIntVal = lastCallingConv = OldCallingConv::CSRet; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004060 break;
4061
4062 case 94:
David Greene5fd22a82007-09-04 18:46:50 +00004063#line 1991 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4064 { yyval.UIntVal = lastCallingConv = OldCallingConv::Fast; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004065 break;
4066
4067 case 95:
David Greene5fd22a82007-09-04 18:46:50 +00004068#line 1992 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4069 { yyval.UIntVal = lastCallingConv = OldCallingConv::Cold; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004070 break;
4071
4072 case 96:
David Greene5fd22a82007-09-04 18:46:50 +00004073#line 1993 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4074 { yyval.UIntVal = lastCallingConv = OldCallingConv::X86_StdCall; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004075 break;
4076
4077 case 97:
David Greene5fd22a82007-09-04 18:46:50 +00004078#line 1994 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4079 { yyval.UIntVal = lastCallingConv = OldCallingConv::X86_FastCall; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004080 break;
4081
4082 case 98:
David Greene5fd22a82007-09-04 18:46:50 +00004083#line 1995 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004084 {
David Greene5fd22a82007-09-04 18:46:50 +00004085 if ((unsigned)yyvsp[0].UInt64Val != yyvsp[0].UInt64Val)
Reid Spencer950bf602007-01-26 08:19:09 +00004086 error("Calling conv too large");
David Greene5fd22a82007-09-04 18:46:50 +00004087 yyval.UIntVal = lastCallingConv = yyvsp[0].UInt64Val;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004088 ;}
4089 break;
4090
4091 case 99:
David Greene5fd22a82007-09-04 18:46:50 +00004092#line 2005 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4093 { yyval.UIntVal = 0; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004094 break;
4095
4096 case 100:
David Greene5fd22a82007-09-04 18:46:50 +00004097#line 2006 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004098 {
David Greene5fd22a82007-09-04 18:46:50 +00004099 yyval.UIntVal = yyvsp[0].UInt64Val;
4100 if (yyval.UIntVal != 0 && !isPowerOf2_32(yyval.UIntVal))
Reid Spencer950bf602007-01-26 08:19:09 +00004101 error("Alignment must be a power of two");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004102 ;}
4103 break;
4104
4105 case 101:
David Greene5fd22a82007-09-04 18:46:50 +00004106#line 2014 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4107 { yyval.UIntVal = 0; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004108 break;
4109
4110 case 102:
David Greene5fd22a82007-09-04 18:46:50 +00004111#line 2015 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004112 {
David Greene5fd22a82007-09-04 18:46:50 +00004113 yyval.UIntVal = yyvsp[0].UInt64Val;
4114 if (yyval.UIntVal != 0 && !isPowerOf2_32(yyval.UIntVal))
Reid Spencer950bf602007-01-26 08:19:09 +00004115 error("Alignment must be a power of two");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004116 ;}
4117 break;
4118
4119 case 103:
David Greene5fd22a82007-09-04 18:46:50 +00004120#line 2023 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004121 {
David Greene5fd22a82007-09-04 18:46:50 +00004122 for (unsigned i = 0, e = strlen(yyvsp[0].StrVal); i != e; ++i)
4123 if (yyvsp[0].StrVal[i] == '"' || yyvsp[0].StrVal[i] == '\\')
Reid Spencer950bf602007-01-26 08:19:09 +00004124 error("Invalid character in section name");
David Greene5fd22a82007-09-04 18:46:50 +00004125 yyval.StrVal = yyvsp[0].StrVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004126 ;}
4127 break;
4128
4129 case 104:
David Greene5fd22a82007-09-04 18:46:50 +00004130#line 2032 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4131 { yyval.StrVal = 0; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004132 break;
4133
4134 case 105:
David Greene5fd22a82007-09-04 18:46:50 +00004135#line 2033 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4136 { yyval.StrVal = yyvsp[0].StrVal; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004137 break;
4138
4139 case 106:
David Greene5fd22a82007-09-04 18:46:50 +00004140#line 2040 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004141 {;}
4142 break;
4143
Reid Spencere59f4932007-04-16 03:05:01 +00004144 case 107:
David Greene5fd22a82007-09-04 18:46:50 +00004145#line 2041 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencere59f4932007-04-16 03:05:01 +00004146 {;}
4147 break;
4148
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004149 case 108:
David Greene5fd22a82007-09-04 18:46:50 +00004150#line 2045 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004151 {
David Greene5fd22a82007-09-04 18:46:50 +00004152 CurGV->setSection(yyvsp[0].StrVal);
4153 free(yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004154 ;}
4155 break;
4156
4157 case 109:
David Greene5fd22a82007-09-04 18:46:50 +00004158#line 2049 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004159 {
David Greene5fd22a82007-09-04 18:46:50 +00004160 if (yyvsp[0].UInt64Val != 0 && !isPowerOf2_32(yyvsp[0].UInt64Val))
Reid Spencer950bf602007-01-26 08:19:09 +00004161 error("Alignment must be a power of two");
David Greene5fd22a82007-09-04 18:46:50 +00004162 CurGV->setAlignment(yyvsp[0].UInt64Val);
Reid Spencer950bf602007-01-26 08:19:09 +00004163
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004164 ;}
4165 break;
4166
4167 case 111:
David Greene5fd22a82007-09-04 18:46:50 +00004168#line 2066 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004169 {
David Greene5fd22a82007-09-04 18:46:50 +00004170 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
4171 yyval.TypeVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004172 ;}
4173 break;
4174
4175 case 113:
David Greene5fd22a82007-09-04 18:46:50 +00004176#line 2074 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004177 {
David Greene5fd22a82007-09-04 18:46:50 +00004178 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
4179 yyval.TypeVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004180 ;}
4181 break;
4182
4183 case 114:
David Greene5fd22a82007-09-04 18:46:50 +00004184#line 2081 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004185 {
Reid Spencer950bf602007-01-26 08:19:09 +00004186 if (!UpRefs.empty())
David Greene5fd22a82007-09-04 18:46:50 +00004187 error("Invalid upreference in type: " + (*yyvsp[0].TypeVal.PAT)->getDescription());
4188 yyval.TypeVal = yyvsp[0].TypeVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004189 ;}
4190 break;
4191
4192 case 127:
David Greene5fd22a82007-09-04 18:46:50 +00004193#line 2095 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004194 {
David Greene5fd22a82007-09-04 18:46:50 +00004195 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
4196 yyval.TypeVal.S.copy(yyvsp[0].PrimType.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004197 ;}
4198 break;
4199
4200 case 128:
David Greene5fd22a82007-09-04 18:46:50 +00004201#line 2099 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004202 {
David Greene5fd22a82007-09-04 18:46:50 +00004203 yyval.TypeVal.PAT = new PATypeHolder(OpaqueType::get());
4204 yyval.TypeVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004205 ;}
4206 break;
4207
4208 case 129:
David Greene5fd22a82007-09-04 18:46:50 +00004209#line 2103 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004210 { // Named types are also simple types...
David Greene5fd22a82007-09-04 18:46:50 +00004211 yyval.TypeVal.S.copy(getTypeSign(yyvsp[0].ValIDVal));
4212 const Type* tmp = getType(yyvsp[0].ValIDVal);
4213 yyval.TypeVal.PAT = new PATypeHolder(tmp);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004214 ;}
4215 break;
4216
4217 case 130:
David Greene5fd22a82007-09-04 18:46:50 +00004218#line 2108 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004219 { // Type UpReference
David Greene5fd22a82007-09-04 18:46:50 +00004220 if (yyvsp[0].UInt64Val > (uint64_t)~0U)
Reid Spencer950bf602007-01-26 08:19:09 +00004221 error("Value out of range");
4222 OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder
David Greene5fd22a82007-09-04 18:46:50 +00004223 UpRefs.push_back(UpRefRecord((unsigned)yyvsp[0].UInt64Val, OT)); // Add to vector...
4224 yyval.TypeVal.PAT = new PATypeHolder(OT);
4225 yyval.TypeVal.S.makeSignless();
Reid Spencer950bf602007-01-26 08:19:09 +00004226 UR_OUT("New Upreference!\n");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004227 ;}
4228 break;
4229
4230 case 131:
David Greene5fd22a82007-09-04 18:46:50 +00004231#line 2117 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004232 { // Function derived type?
David Greene5fd22a82007-09-04 18:46:50 +00004233 yyval.TypeVal.S.makeComposite(yyvsp[-3].TypeVal.S);
Reid Spencer950bf602007-01-26 08:19:09 +00004234 std::vector<const Type*> Params;
David Greene5fd22a82007-09-04 18:46:50 +00004235 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-1].TypeList->begin(),
4236 E = yyvsp[-1].TypeList->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004237 Params.push_back(I->PAT->get());
David Greene5fd22a82007-09-04 18:46:50 +00004238 yyval.TypeVal.S.add(I->S);
Reid Spencer52402b02007-01-02 05:45:11 +00004239 }
Reid Spencer950bf602007-01-26 08:19:09 +00004240 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
4241 if (isVarArg) Params.pop_back();
4242
Reid Spencer7eea8ff2007-05-18 05:48:07 +00004243 ParamAttrsList *PAL = 0;
4244 if (lastCallingConv == OldCallingConv::CSRet) {
4245 ParamAttrsVector Attrs;
4246 ParamAttrsWithIndex PAWI;
4247 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
4248 Attrs.push_back(PAWI);
4249 PAL = ParamAttrsList::get(Attrs);
4250 }
4251
Reid Spencer7b5d4662007-04-09 06:16:21 +00004252 const FunctionType *FTy =
David Greene5fd22a82007-09-04 18:46:50 +00004253 FunctionType::get(yyvsp[-3].TypeVal.PAT->get(), Params, isVarArg, PAL);
Reid Spencer7b5d4662007-04-09 06:16:21 +00004254
David Greene5fd22a82007-09-04 18:46:50 +00004255 yyval.TypeVal.PAT = new PATypeHolder( HandleUpRefs(FTy, yyval.TypeVal.S) );
4256 delete yyvsp[-3].TypeVal.PAT; // Delete the return type handle
4257 delete yyvsp[-1].TypeList; // Delete the argument list
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004258 ;}
4259 break;
4260
4261 case 132:
David Greene5fd22a82007-09-04 18:46:50 +00004262#line 2144 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004263 { // Sized array type?
David Greene5fd22a82007-09-04 18:46:50 +00004264 yyval.TypeVal.S.makeComposite(yyvsp[-1].TypeVal.S);
4265 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(ArrayType::get(yyvsp[-1].TypeVal.PAT->get(),
4266 (unsigned)yyvsp[-3].UInt64Val), yyval.TypeVal.S));
4267 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004268 ;}
4269 break;
4270
4271 case 133:
David Greene5fd22a82007-09-04 18:46:50 +00004272#line 2150 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004273 { // Vector type?
David Greene5fd22a82007-09-04 18:46:50 +00004274 const llvm::Type* ElemTy = yyvsp[-1].TypeVal.PAT->get();
4275 if ((unsigned)yyvsp[-3].UInt64Val != yyvsp[-3].UInt64Val)
Reid Spencerbb1fd572007-03-21 17:15:50 +00004276 error("Unsigned result not equal to signed result");
4277 if (!(ElemTy->isInteger() || ElemTy->isFloatingPoint()))
4278 error("Elements of a VectorType must be integer or floating point");
David Greene5fd22a82007-09-04 18:46:50 +00004279 if (!isPowerOf2_32(yyvsp[-3].UInt64Val))
Reid Spencerbb1fd572007-03-21 17:15:50 +00004280 error("VectorType length should be a power of 2");
David Greene5fd22a82007-09-04 18:46:50 +00004281 yyval.TypeVal.S.makeComposite(yyvsp[-1].TypeVal.S);
4282 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(VectorType::get(ElemTy,
4283 (unsigned)yyvsp[-3].UInt64Val), yyval.TypeVal.S));
4284 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004285 ;}
4286 break;
4287
4288 case 134:
David Greene5fd22a82007-09-04 18:46:50 +00004289#line 2163 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004290 { // Structure type?
Reid Spencer950bf602007-01-26 08:19:09 +00004291 std::vector<const Type*> Elements;
David Greene5fd22a82007-09-04 18:46:50 +00004292 yyval.TypeVal.S.makeComposite();
4293 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-1].TypeList->begin(),
4294 E = yyvsp[-1].TypeList->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004295 Elements.push_back(I->PAT->get());
David Greene5fd22a82007-09-04 18:46:50 +00004296 yyval.TypeVal.S.add(I->S);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004297 }
David Greene5fd22a82007-09-04 18:46:50 +00004298 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements), yyval.TypeVal.S));
4299 delete yyvsp[-1].TypeList;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004300 ;}
4301 break;
4302
4303 case 135:
David Greene5fd22a82007-09-04 18:46:50 +00004304#line 2174 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004305 { // Empty structure type?
David Greene5fd22a82007-09-04 18:46:50 +00004306 yyval.TypeVal.PAT = new PATypeHolder(StructType::get(std::vector<const Type*>()));
4307 yyval.TypeVal.S.makeComposite();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004308 ;}
4309 break;
4310
4311 case 136:
David Greene5fd22a82007-09-04 18:46:50 +00004312#line 2178 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004313 { // Packed Structure type?
David Greene5fd22a82007-09-04 18:46:50 +00004314 yyval.TypeVal.S.makeComposite();
Reid Spencer950bf602007-01-26 08:19:09 +00004315 std::vector<const Type*> Elements;
David Greene5fd22a82007-09-04 18:46:50 +00004316 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-2].TypeList->begin(),
4317 E = yyvsp[-2].TypeList->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004318 Elements.push_back(I->PAT->get());
David Greene5fd22a82007-09-04 18:46:50 +00004319 yyval.TypeVal.S.add(I->S);
Reid Spencered96d1e2007-02-08 09:08:52 +00004320 delete I->PAT;
Reid Spencer52402b02007-01-02 05:45:11 +00004321 }
David Greene5fd22a82007-09-04 18:46:50 +00004322 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements, true),
4323 yyval.TypeVal.S));
4324 delete yyvsp[-2].TypeList;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004325 ;}
4326 break;
4327
4328 case 137:
David Greene5fd22a82007-09-04 18:46:50 +00004329#line 2191 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004330 { // Empty packed structure type?
David Greene5fd22a82007-09-04 18:46:50 +00004331 yyval.TypeVal.PAT = new PATypeHolder(StructType::get(std::vector<const Type*>(),true));
4332 yyval.TypeVal.S.makeComposite();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004333 ;}
4334 break;
4335
4336 case 138:
David Greene5fd22a82007-09-04 18:46:50 +00004337#line 2195 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004338 { // Pointer type?
David Greene5fd22a82007-09-04 18:46:50 +00004339 if (yyvsp[-1].TypeVal.PAT->get() == Type::LabelTy)
Reid Spencer950bf602007-01-26 08:19:09 +00004340 error("Cannot form a pointer to a basic block");
David Greene5fd22a82007-09-04 18:46:50 +00004341 yyval.TypeVal.S.makeComposite(yyvsp[-1].TypeVal.S);
4342 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(PointerType::get(yyvsp[-1].TypeVal.PAT->get()),
4343 yyval.TypeVal.S));
4344 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004345 ;}
4346 break;
4347
4348 case 139:
David Greene5fd22a82007-09-04 18:46:50 +00004349#line 2209 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004350 {
David Greene5fd22a82007-09-04 18:46:50 +00004351 yyval.TypeList = new std::list<PATypeInfo>();
4352 yyval.TypeList->push_back(yyvsp[0].TypeVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004353 ;}
4354 break;
4355
4356 case 140:
David Greene5fd22a82007-09-04 18:46:50 +00004357#line 2213 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004358 {
David Greene5fd22a82007-09-04 18:46:50 +00004359 (yyval.TypeList=yyvsp[-2].TypeList)->push_back(yyvsp[0].TypeVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004360 ;}
4361 break;
4362
4363 case 142:
David Greene5fd22a82007-09-04 18:46:50 +00004364#line 2221 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004365 {
Reid Spencer950bf602007-01-26 08:19:09 +00004366 PATypeInfo VoidTI;
Reid Spencered96d1e2007-02-08 09:08:52 +00004367 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004368 VoidTI.S.makeSignless();
David Greene5fd22a82007-09-04 18:46:50 +00004369 (yyval.TypeList=yyvsp[-2].TypeList)->push_back(VoidTI);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004370 ;}
4371 break;
4372
4373 case 143:
David Greene5fd22a82007-09-04 18:46:50 +00004374#line 2227 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004375 {
David Greene5fd22a82007-09-04 18:46:50 +00004376 yyval.TypeList = new std::list<PATypeInfo>();
Reid Spencer950bf602007-01-26 08:19:09 +00004377 PATypeInfo VoidTI;
Reid Spencered96d1e2007-02-08 09:08:52 +00004378 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00004379 VoidTI.S.makeSignless();
David Greene5fd22a82007-09-04 18:46:50 +00004380 yyval.TypeList->push_back(VoidTI);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004381 ;}
4382 break;
4383
4384 case 144:
David Greene5fd22a82007-09-04 18:46:50 +00004385#line 2234 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004386 {
David Greene5fd22a82007-09-04 18:46:50 +00004387 yyval.TypeList = new std::list<PATypeInfo>();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004388 ;}
4389 break;
4390
4391 case 145:
David Greene5fd22a82007-09-04 18:46:50 +00004392#line 2246 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004393 { // Nonempty unsized arr
David Greene5fd22a82007-09-04 18:46:50 +00004394 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-3].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004395 if (ATy == 0)
4396 error("Cannot make array constant with type: '" +
David Greene5fd22a82007-09-04 18:46:50 +00004397 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004398 const Type *ETy = ATy->getElementType();
4399 int NumElements = ATy->getNumElements();
4400
4401 // Verify that we have the correct size...
David Greene5fd22a82007-09-04 18:46:50 +00004402 if (NumElements != -1 && NumElements != (int)yyvsp[-1].ConstVector->size())
Reid Spencer950bf602007-01-26 08:19:09 +00004403 error("Type mismatch: constant sized array initialized with " +
David Greene5fd22a82007-09-04 18:46:50 +00004404 utostr(yyvsp[-1].ConstVector->size()) + " arguments, but has size of " +
Reid Spencer950bf602007-01-26 08:19:09 +00004405 itostr(NumElements) + "");
4406
4407 // Verify all elements are correct type!
4408 std::vector<Constant*> Elems;
David Greene5fd22a82007-09-04 18:46:50 +00004409 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
4410 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004411 const Type* ValTy = C->getType();
4412 if (ETy != ValTy)
4413 error("Element #" + utostr(i) + " is not of type '" +
4414 ETy->getDescription() +"' as required!\nIt is of type '"+
4415 ValTy->getDescription() + "'");
4416 Elems.push_back(C);
4417 }
David Greene5fd22a82007-09-04 18:46:50 +00004418 yyval.ConstVal.C = ConstantArray::get(ATy, Elems);
4419 yyval.ConstVal.S.copy(yyvsp[-3].TypeVal.S);
4420 delete yyvsp[-3].TypeVal.PAT;
4421 delete yyvsp[-1].ConstVector;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004422 ;}
4423 break;
4424
4425 case 146:
David Greene5fd22a82007-09-04 18:46:50 +00004426#line 2276 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004427 {
David Greene5fd22a82007-09-04 18:46:50 +00004428 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-2].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004429 if (ATy == 0)
4430 error("Cannot make array constant with type: '" +
David Greene5fd22a82007-09-04 18:46:50 +00004431 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004432 int NumElements = ATy->getNumElements();
4433 if (NumElements != -1 && NumElements != 0)
4434 error("Type mismatch: constant sized array initialized with 0"
4435 " arguments, but has size of " + itostr(NumElements) +"");
David Greene5fd22a82007-09-04 18:46:50 +00004436 yyval.ConstVal.C = ConstantArray::get(ATy, std::vector<Constant*>());
4437 yyval.ConstVal.S.copy(yyvsp[-2].TypeVal.S);
4438 delete yyvsp[-2].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004439 ;}
4440 break;
4441
4442 case 147:
David Greene5fd22a82007-09-04 18:46:50 +00004443#line 2289 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004444 {
David Greene5fd22a82007-09-04 18:46:50 +00004445 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-2].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004446 if (ATy == 0)
4447 error("Cannot make array constant with type: '" +
David Greene5fd22a82007-09-04 18:46:50 +00004448 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004449 int NumElements = ATy->getNumElements();
4450 const Type *ETy = dyn_cast<IntegerType>(ATy->getElementType());
4451 if (!ETy || cast<IntegerType>(ETy)->getBitWidth() != 8)
4452 error("String arrays require type i8, not '" + ETy->getDescription() +
4453 "'");
David Greene5fd22a82007-09-04 18:46:50 +00004454 char *EndStr = UnEscapeLexed(yyvsp[0].StrVal, true);
4455 if (NumElements != -1 && NumElements != (EndStr-yyvsp[0].StrVal))
Reid Spencer950bf602007-01-26 08:19:09 +00004456 error("Can't build string constant of size " +
David Greene5fd22a82007-09-04 18:46:50 +00004457 itostr((int)(EndStr-yyvsp[0].StrVal)) + " when array has size " +
Reid Spencer950bf602007-01-26 08:19:09 +00004458 itostr(NumElements) + "");
4459 std::vector<Constant*> Vals;
David Greene5fd22a82007-09-04 18:46:50 +00004460 for (char *C = (char *)yyvsp[0].StrVal; C != (char *)EndStr; ++C)
Reid Spencer950bf602007-01-26 08:19:09 +00004461 Vals.push_back(ConstantInt::get(ETy, *C));
David Greene5fd22a82007-09-04 18:46:50 +00004462 free(yyvsp[0].StrVal);
4463 yyval.ConstVal.C = ConstantArray::get(ATy, Vals);
4464 yyval.ConstVal.S.copy(yyvsp[-2].TypeVal.S);
4465 delete yyvsp[-2].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004466 ;}
4467 break;
4468
4469 case 148:
David Greene5fd22a82007-09-04 18:46:50 +00004470#line 2312 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004471 { // Nonempty unsized arr
David Greene5fd22a82007-09-04 18:46:50 +00004472 const VectorType *PTy = dyn_cast<VectorType>(yyvsp[-3].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004473 if (PTy == 0)
4474 error("Cannot make packed constant with type: '" +
David Greene5fd22a82007-09-04 18:46:50 +00004475 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004476 const Type *ETy = PTy->getElementType();
4477 int NumElements = PTy->getNumElements();
4478 // Verify that we have the correct size...
David Greene5fd22a82007-09-04 18:46:50 +00004479 if (NumElements != -1 && NumElements != (int)yyvsp[-1].ConstVector->size())
Reid Spencer950bf602007-01-26 08:19:09 +00004480 error("Type mismatch: constant sized packed initialized with " +
David Greene5fd22a82007-09-04 18:46:50 +00004481 utostr(yyvsp[-1].ConstVector->size()) + " arguments, but has size of " +
Reid Spencer950bf602007-01-26 08:19:09 +00004482 itostr(NumElements) + "");
4483 // Verify all elements are correct type!
4484 std::vector<Constant*> Elems;
David Greene5fd22a82007-09-04 18:46:50 +00004485 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
4486 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004487 const Type* ValTy = C->getType();
4488 if (ETy != ValTy)
4489 error("Element #" + utostr(i) + " is not of type '" +
4490 ETy->getDescription() +"' as required!\nIt is of type '"+
4491 ValTy->getDescription() + "'");
4492 Elems.push_back(C);
4493 }
David Greene5fd22a82007-09-04 18:46:50 +00004494 yyval.ConstVal.C = ConstantVector::get(PTy, Elems);
4495 yyval.ConstVal.S.copy(yyvsp[-3].TypeVal.S);
4496 delete yyvsp[-3].TypeVal.PAT;
4497 delete yyvsp[-1].ConstVector;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004498 ;}
4499 break;
4500
4501 case 149:
David Greene5fd22a82007-09-04 18:46:50 +00004502#line 2340 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004503 {
David Greene5fd22a82007-09-04 18:46:50 +00004504 const StructType *STy = dyn_cast<StructType>(yyvsp[-3].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004505 if (STy == 0)
4506 error("Cannot make struct constant with type: '" +
David Greene5fd22a82007-09-04 18:46:50 +00004507 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
4508 if (yyvsp[-1].ConstVector->size() != STy->getNumContainedTypes())
Reid Spencer950bf602007-01-26 08:19:09 +00004509 error("Illegal number of initializers for structure type");
4510
4511 // Check to ensure that constants are compatible with the type initializer!
4512 std::vector<Constant*> Fields;
David Greene5fd22a82007-09-04 18:46:50 +00004513 for (unsigned i = 0, e = yyvsp[-1].ConstVector->size(); i != e; ++i) {
4514 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004515 if (C->getType() != STy->getElementType(i))
4516 error("Expected type '" + STy->getElementType(i)->getDescription() +
4517 "' for element #" + utostr(i) + " of structure initializer");
4518 Fields.push_back(C);
4519 }
David Greene5fd22a82007-09-04 18:46:50 +00004520 yyval.ConstVal.C = ConstantStruct::get(STy, Fields);
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 150:
David Greene5fd22a82007-09-04 18:46:50 +00004528#line 2362 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004529 {
David Greene5fd22a82007-09-04 18:46:50 +00004530 const StructType *STy = dyn_cast<StructType>(yyvsp[-2].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004531 if (STy == 0)
4532 error("Cannot make struct constant with type: '" +
David Greene5fd22a82007-09-04 18:46:50 +00004533 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004534 if (STy->getNumContainedTypes() != 0)
4535 error("Illegal number of initializers for structure type");
David Greene5fd22a82007-09-04 18:46:50 +00004536 yyval.ConstVal.C = ConstantStruct::get(STy, std::vector<Constant*>());
4537 yyval.ConstVal.S.copy(yyvsp[-2].TypeVal.S);
4538 delete yyvsp[-2].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004539 ;}
4540 break;
4541
4542 case 151:
David Greene5fd22a82007-09-04 18:46:50 +00004543#line 2373 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004544 {
David Greene5fd22a82007-09-04 18:46:50 +00004545 const StructType *STy = dyn_cast<StructType>(yyvsp[-5].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004546 if (STy == 0)
4547 error("Cannot make packed struct constant with type: '" +
David Greene5fd22a82007-09-04 18:46:50 +00004548 yyvsp[-5].TypeVal.PAT->get()->getDescription() + "'");
4549 if (yyvsp[-2].ConstVector->size() != STy->getNumContainedTypes())
Reid Spencer950bf602007-01-26 08:19:09 +00004550 error("Illegal number of initializers for packed structure type");
4551
4552 // Check to ensure that constants are compatible with the type initializer!
4553 std::vector<Constant*> Fields;
David Greene5fd22a82007-09-04 18:46:50 +00004554 for (unsigned i = 0, e = yyvsp[-2].ConstVector->size(); i != e; ++i) {
4555 Constant *C = (*yyvsp[-2].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004556 if (C->getType() != STy->getElementType(i))
4557 error("Expected type '" + STy->getElementType(i)->getDescription() +
4558 "' for element #" + utostr(i) + " of packed struct initializer");
4559 Fields.push_back(C);
4560 }
David Greene5fd22a82007-09-04 18:46:50 +00004561 yyval.ConstVal.C = ConstantStruct::get(STy, Fields);
4562 yyval.ConstVal.S.copy(yyvsp[-5].TypeVal.S);
4563 delete yyvsp[-5].TypeVal.PAT;
4564 delete yyvsp[-2].ConstVector;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004565 ;}
4566 break;
4567
4568 case 152:
David Greene5fd22a82007-09-04 18:46:50 +00004569#line 2395 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004570 {
David Greene5fd22a82007-09-04 18:46:50 +00004571 const StructType *STy = dyn_cast<StructType>(yyvsp[-4].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004572 if (STy == 0)
4573 error("Cannot make packed struct constant with type: '" +
David Greene5fd22a82007-09-04 18:46:50 +00004574 yyvsp[-4].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00004575 if (STy->getNumContainedTypes() != 0)
4576 error("Illegal number of initializers for packed structure type");
David Greene5fd22a82007-09-04 18:46:50 +00004577 yyval.ConstVal.C = ConstantStruct::get(STy, std::vector<Constant*>());
4578 yyval.ConstVal.S.copy(yyvsp[-4].TypeVal.S);
4579 delete yyvsp[-4].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004580 ;}
4581 break;
4582
4583 case 153:
David Greene5fd22a82007-09-04 18:46:50 +00004584#line 2406 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004585 {
David Greene5fd22a82007-09-04 18:46:50 +00004586 const PointerType *PTy = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004587 if (PTy == 0)
4588 error("Cannot make null pointer constant with type: '" +
David Greene5fd22a82007-09-04 18:46:50 +00004589 yyvsp[-1].TypeVal.PAT->get()->getDescription() + "'");
4590 yyval.ConstVal.C = ConstantPointerNull::get(PTy);
4591 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4592 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004593 ;}
4594 break;
4595
4596 case 154:
David Greene5fd22a82007-09-04 18:46:50 +00004597#line 2415 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004598 {
David Greene5fd22a82007-09-04 18:46:50 +00004599 yyval.ConstVal.C = UndefValue::get(yyvsp[-1].TypeVal.PAT->get());
4600 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4601 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004602 ;}
4603 break;
4604
4605 case 155:
David Greene5fd22a82007-09-04 18:46:50 +00004606#line 2420 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004607 {
David Greene5fd22a82007-09-04 18:46:50 +00004608 const PointerType *Ty = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00004609 if (Ty == 0)
4610 error("Global const reference must be a pointer type, not" +
David Greene5fd22a82007-09-04 18:46:50 +00004611 yyvsp[-1].TypeVal.PAT->get()->getDescription());
Reid Spencer950bf602007-01-26 08:19:09 +00004612
4613 // ConstExprs can exist in the body of a function, thus creating
4614 // GlobalValues whenever they refer to a variable. Because we are in
4615 // the context of a function, getExistingValue will search the functions
4616 // symbol table instead of the module symbol table for the global symbol,
4617 // which throws things all off. To get around this, we just tell
4618 // getExistingValue that we are at global scope here.
4619 //
4620 Function *SavedCurFn = CurFun.CurrentFunction;
4621 CurFun.CurrentFunction = 0;
David Greene5fd22a82007-09-04 18:46:50 +00004622 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
4623 Value *V = getExistingValue(Ty, yyvsp[0].ValIDVal);
Reid Spencer950bf602007-01-26 08:19:09 +00004624 CurFun.CurrentFunction = SavedCurFn;
4625
4626 // If this is an initializer for a constant pointer, which is referencing a
4627 // (currently) undefined variable, create a stub now that shall be replaced
4628 // in the future with the right type of variable.
4629 //
4630 if (V == 0) {
4631 assert(isa<PointerType>(Ty) && "Globals may only be used as pointers");
4632 const PointerType *PT = cast<PointerType>(Ty);
4633
4634 // First check to see if the forward references value is already created!
4635 PerModuleInfo::GlobalRefsType::iterator I =
David Greene5fd22a82007-09-04 18:46:50 +00004636 CurModule.GlobalRefs.find(std::make_pair(PT, yyvsp[0].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00004637
4638 if (I != CurModule.GlobalRefs.end()) {
4639 V = I->second; // Placeholder already exists, use it...
David Greene5fd22a82007-09-04 18:46:50 +00004640 yyvsp[0].ValIDVal.destroy();
Reid Spencer950bf602007-01-26 08:19:09 +00004641 } else {
4642 std::string Name;
David Greene5fd22a82007-09-04 18:46:50 +00004643 if (yyvsp[0].ValIDVal.Type == ValID::NameVal) Name = yyvsp[0].ValIDVal.Name;
Reid Spencer950bf602007-01-26 08:19:09 +00004644
4645 // Create the forward referenced global.
4646 GlobalValue *GV;
4647 if (const FunctionType *FTy =
4648 dyn_cast<FunctionType>(PT->getElementType())) {
4649 GV = new Function(FTy, GlobalValue::ExternalLinkage, Name,
4650 CurModule.CurrentModule);
4651 } else {
4652 GV = new GlobalVariable(PT->getElementType(), false,
4653 GlobalValue::ExternalLinkage, 0,
4654 Name, CurModule.CurrentModule);
4655 }
4656
4657 // Keep track of the fact that we have a forward ref to recycle it
David Greene5fd22a82007-09-04 18:46:50 +00004658 CurModule.GlobalRefs.insert(std::make_pair(std::make_pair(PT, yyvsp[0].ValIDVal), GV));
Reid Spencer950bf602007-01-26 08:19:09 +00004659 V = GV;
4660 }
4661 }
David Greene5fd22a82007-09-04 18:46:50 +00004662 yyval.ConstVal.C = cast<GlobalValue>(V);
4663 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4664 delete yyvsp[-1].TypeVal.PAT; // Free the type handle
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004665 ;}
4666 break;
4667
4668 case 156:
David Greene5fd22a82007-09-04 18:46:50 +00004669#line 2479 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004670 {
David Greene5fd22a82007-09-04 18:46:50 +00004671 if (yyvsp[-1].TypeVal.PAT->get() != yyvsp[0].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004672 error("Mismatched types for constant expression");
David Greene5fd22a82007-09-04 18:46:50 +00004673 yyval.ConstVal = yyvsp[0].ConstVal;
4674 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4675 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004676 ;}
4677 break;
4678
4679 case 157:
David Greene5fd22a82007-09-04 18:46:50 +00004680#line 2486 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004681 {
David Greene5fd22a82007-09-04 18:46:50 +00004682 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00004683 if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
4684 error("Cannot create a null initialized value of this type");
David Greene5fd22a82007-09-04 18:46:50 +00004685 yyval.ConstVal.C = Constant::getNullValue(Ty);
4686 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4687 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004688 ;}
4689 break;
4690
4691 case 158:
David Greene5fd22a82007-09-04 18:46:50 +00004692#line 2494 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004693 { // integral constants
David Greene5fd22a82007-09-04 18:46:50 +00004694 const Type *Ty = yyvsp[-1].PrimType.T;
4695 if (!ConstantInt::isValueValidForType(Ty, yyvsp[0].SInt64Val))
Reid Spencer950bf602007-01-26 08:19:09 +00004696 error("Constant value doesn't fit in type");
David Greene5fd22a82007-09-04 18:46:50 +00004697 yyval.ConstVal.C = ConstantInt::get(Ty, yyvsp[0].SInt64Val);
4698 yyval.ConstVal.S.makeSigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004699 ;}
4700 break;
4701
4702 case 159:
David Greene5fd22a82007-09-04 18:46:50 +00004703#line 2501 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004704 { // integral constants
David Greene5fd22a82007-09-04 18:46:50 +00004705 const Type *Ty = yyvsp[-1].PrimType.T;
4706 if (!ConstantInt::isValueValidForType(Ty, yyvsp[0].UInt64Val))
Reid Spencer950bf602007-01-26 08:19:09 +00004707 error("Constant value doesn't fit in type");
David Greene5fd22a82007-09-04 18:46:50 +00004708 yyval.ConstVal.C = ConstantInt::get(Ty, yyvsp[0].UInt64Val);
4709 yyval.ConstVal.S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004710 ;}
4711 break;
4712
4713 case 160:
David Greene5fd22a82007-09-04 18:46:50 +00004714#line 2508 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004715 { // Boolean constants
David Greene5fd22a82007-09-04 18:46:50 +00004716 yyval.ConstVal.C = ConstantInt::get(Type::Int1Ty, true);
4717 yyval.ConstVal.S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004718 ;}
4719 break;
4720
4721 case 161:
David Greene5fd22a82007-09-04 18:46:50 +00004722#line 2512 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004723 { // Boolean constants
David Greene5fd22a82007-09-04 18:46:50 +00004724 yyval.ConstVal.C = ConstantInt::get(Type::Int1Ty, false);
4725 yyval.ConstVal.S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004726 ;}
4727 break;
4728
4729 case 162:
David Greene5fd22a82007-09-04 18:46:50 +00004730#line 2516 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004731 { // Float & Double constants
David Greene5fd22a82007-09-04 18:46:50 +00004732 if (!ConstantFP::isValueValidForType(yyvsp[-1].PrimType.T, yyvsp[0].FPVal))
Reid Spencer950bf602007-01-26 08:19:09 +00004733 error("Floating point constant invalid for type");
David Greene5fd22a82007-09-04 18:46:50 +00004734 yyval.ConstVal.C = ConstantFP::get(yyvsp[-1].PrimType.T, yyvsp[0].FPVal);
4735 yyval.ConstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004736 ;}
4737 break;
4738
4739 case 163:
David Greene5fd22a82007-09-04 18:46:50 +00004740#line 2525 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004741 {
David Greene5fd22a82007-09-04 18:46:50 +00004742 const Type* SrcTy = yyvsp[-3].ConstVal.C->getType();
4743 const Type* DstTy = yyvsp[-1].TypeVal.PAT->get();
4744 Signedness SrcSign(yyvsp[-3].ConstVal.S);
4745 Signedness DstSign(yyvsp[-1].TypeVal.S);
Reid Spencer950bf602007-01-26 08:19:09 +00004746 if (!SrcTy->isFirstClassType())
4747 error("cast constant expression from a non-primitive type: '" +
4748 SrcTy->getDescription() + "'");
4749 if (!DstTy->isFirstClassType())
4750 error("cast constant expression to a non-primitive type: '" +
4751 DstTy->getDescription() + "'");
David Greene5fd22a82007-09-04 18:46:50 +00004752 yyval.ConstVal.C = cast<Constant>(getCast(yyvsp[-5].CastOpVal, yyvsp[-3].ConstVal.C, SrcSign, DstTy, DstSign));
4753 yyval.ConstVal.S.copy(DstSign);
4754 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004755 ;}
4756 break;
4757
4758 case 164:
David Greene5fd22a82007-09-04 18:46:50 +00004759#line 2540 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004760 {
David Greene5fd22a82007-09-04 18:46:50 +00004761 const Type *Ty = yyvsp[-2].ConstVal.C->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00004762 if (!isa<PointerType>(Ty))
4763 error("GetElementPtr requires a pointer operand");
4764
Reid Spencer950bf602007-01-26 08:19:09 +00004765 std::vector<Constant*> CIndices;
David Greene5fd22a82007-09-04 18:46:50 +00004766 upgradeGEPCEIndices(yyvsp[-2].ConstVal.C->getType(), yyvsp[-1].ValueList, CIndices);
Reid Spencer950bf602007-01-26 08:19:09 +00004767
David Greene5fd22a82007-09-04 18:46:50 +00004768 delete yyvsp[-1].ValueList;
4769 yyval.ConstVal.C = ConstantExpr::getGetElementPtr(yyvsp[-2].ConstVal.C, &CIndices[0], CIndices.size());
4770 yyval.ConstVal.S.copy(getElementSign(yyvsp[-2].ConstVal, CIndices));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004771 ;}
4772 break;
4773
4774 case 165:
David Greene5fd22a82007-09-04 18:46:50 +00004775#line 2552 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004776 {
David Greene5fd22a82007-09-04 18:46:50 +00004777 if (!yyvsp[-5].ConstVal.C->getType()->isInteger() ||
4778 cast<IntegerType>(yyvsp[-5].ConstVal.C->getType())->getBitWidth() != 1)
Reid Spencer950bf602007-01-26 08:19:09 +00004779 error("Select condition must be bool type");
David Greene5fd22a82007-09-04 18:46:50 +00004780 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004781 error("Select operand types must match");
David Greene5fd22a82007-09-04 18:46:50 +00004782 yyval.ConstVal.C = ConstantExpr::getSelect(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4783 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004784 ;}
4785 break;
4786
4787 case 166:
David Greene5fd22a82007-09-04 18:46:50 +00004788#line 2561 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004789 {
David Greene5fd22a82007-09-04 18:46:50 +00004790 const Type *Ty = yyvsp[-3].ConstVal.C->getType();
4791 if (Ty != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004792 error("Binary operator types must match");
4793 // First, make sure we're dealing with the right opcode by upgrading from
4794 // obsolete versions.
David Greene5fd22a82007-09-04 18:46:50 +00004795 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S);
Reid Spencer950bf602007-01-26 08:19:09 +00004796
4797 // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs.
4798 // To retain backward compatibility with these early compilers, we emit a
4799 // cast to the appropriate integer type automatically if we are in the
4800 // broken case. See PR424 for more information.
4801 if (!isa<PointerType>(Ty)) {
David Greene5fd22a82007-09-04 18:46:50 +00004802 yyval.ConstVal.C = ConstantExpr::get(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
Reid Spencer950bf602007-01-26 08:19:09 +00004803 } else {
4804 const Type *IntPtrTy = 0;
4805 switch (CurModule.CurrentModule->getPointerSize()) {
4806 case Module::Pointer32: IntPtrTy = Type::Int32Ty; break;
4807 case Module::Pointer64: IntPtrTy = Type::Int64Ty; break;
4808 default: error("invalid pointer binary constant expr");
4809 }
David Greene5fd22a82007-09-04 18:46:50 +00004810 yyval.ConstVal.C = ConstantExpr::get(Opcode,
4811 ConstantExpr::getCast(Instruction::PtrToInt, yyvsp[-3].ConstVal.C, IntPtrTy),
4812 ConstantExpr::getCast(Instruction::PtrToInt, yyvsp[-1].ConstVal.C, IntPtrTy));
4813 yyval.ConstVal.C = ConstantExpr::getCast(Instruction::IntToPtr, yyval.ConstVal.C, Ty);
Reid Spencer950bf602007-01-26 08:19:09 +00004814 }
David Greene5fd22a82007-09-04 18:46:50 +00004815 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004816 ;}
4817 break;
4818
4819 case 167:
David Greene5fd22a82007-09-04 18:46:50 +00004820#line 2589 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004821 {
David Greene5fd22a82007-09-04 18:46:50 +00004822 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
4823 if (Ty != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004824 error("Logical operator types must match");
4825 if (!Ty->isInteger()) {
Reid Spencer9d6565a2007-02-15 02:26:10 +00004826 if (!isa<VectorType>(Ty) ||
4827 !cast<VectorType>(Ty)->getElementType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00004828 error("Logical operator requires integer operands");
4829 }
David Greene5fd22a82007-09-04 18:46:50 +00004830 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S);
4831 yyval.ConstVal.C = ConstantExpr::get(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4832 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004833 ;}
4834 break;
4835
4836 case 168:
David Greene5fd22a82007-09-04 18:46:50 +00004837#line 2602 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004838 {
David Greene5fd22a82007-09-04 18:46:50 +00004839 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
4840 if (Ty != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004841 error("setcc operand types must match");
4842 unsigned short pred;
David Greene5fd22a82007-09-04 18:46:50 +00004843 Instruction::OtherOps Opcode = getCompareOp(yyvsp[-5].BinaryOpVal, pred, Ty, yyvsp[-3].ConstVal.S);
4844 yyval.ConstVal.C = ConstantExpr::getCompare(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4845 yyval.ConstVal.S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004846 ;}
4847 break;
4848
4849 case 169:
David Greene5fd22a82007-09-04 18:46:50 +00004850#line 2611 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004851 {
David Greene5fd22a82007-09-04 18:46:50 +00004852 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004853 error("icmp operand types must match");
David Greene5fd22a82007-09-04 18:46:50 +00004854 yyval.ConstVal.C = ConstantExpr::getCompare(yyvsp[-5].IPred, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4855 yyval.ConstVal.S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004856 ;}
4857 break;
4858
4859 case 170:
David Greene5fd22a82007-09-04 18:46:50 +00004860#line 2617 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004861 {
David Greene5fd22a82007-09-04 18:46:50 +00004862 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00004863 error("fcmp operand types must match");
David Greene5fd22a82007-09-04 18:46:50 +00004864 yyval.ConstVal.C = ConstantExpr::getCompare(yyvsp[-5].FPred, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4865 yyval.ConstVal.S.makeUnsigned();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004866 ;}
4867 break;
4868
4869 case 171:
David Greene5fd22a82007-09-04 18:46:50 +00004870#line 2623 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004871 {
David Greene5fd22a82007-09-04 18:46:50 +00004872 if (!yyvsp[-1].ConstVal.C->getType()->isInteger() ||
4873 cast<IntegerType>(yyvsp[-1].ConstVal.C->getType())->getBitWidth() != 8)
Reid Spencer950bf602007-01-26 08:19:09 +00004874 error("Shift count for shift constant must be unsigned byte");
David Greene5fd22a82007-09-04 18:46:50 +00004875 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
4876 if (!yyvsp[-3].ConstVal.C->getType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00004877 error("Shift constant expression requires integer operand");
David Greene5fd22a82007-09-04 18:46:50 +00004878 Constant *ShiftAmt = ConstantExpr::getZExt(yyvsp[-1].ConstVal.C, Ty);
4879 yyval.ConstVal.C = ConstantExpr::get(getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S), yyvsp[-3].ConstVal.C, ShiftAmt);
4880 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004881 ;}
4882 break;
4883
4884 case 172:
David Greene5fd22a82007-09-04 18:46:50 +00004885#line 2634 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004886 {
David Greene5fd22a82007-09-04 18:46:50 +00004887 if (!ExtractElementInst::isValidOperands(yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Reid Spencer950bf602007-01-26 08:19:09 +00004888 error("Invalid extractelement operands");
David Greene5fd22a82007-09-04 18:46:50 +00004889 yyval.ConstVal.C = ConstantExpr::getExtractElement(yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4890 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S.get(0));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004891 ;}
4892 break;
4893
4894 case 173:
David Greene5fd22a82007-09-04 18:46:50 +00004895#line 2640 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004896 {
David Greene5fd22a82007-09-04 18:46:50 +00004897 if (!InsertElementInst::isValidOperands(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Reid Spencer950bf602007-01-26 08:19:09 +00004898 error("Invalid insertelement operands");
David Greene5fd22a82007-09-04 18:46:50 +00004899 yyval.ConstVal.C = ConstantExpr::getInsertElement(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4900 yyval.ConstVal.S.copy(yyvsp[-5].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004901 ;}
4902 break;
4903
4904 case 174:
David Greene5fd22a82007-09-04 18:46:50 +00004905#line 2646 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004906 {
David Greene5fd22a82007-09-04 18:46:50 +00004907 if (!ShuffleVectorInst::isValidOperands(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Reid Spencer950bf602007-01-26 08:19:09 +00004908 error("Invalid shufflevector operands");
David Greene5fd22a82007-09-04 18:46:50 +00004909 yyval.ConstVal.C = ConstantExpr::getShuffleVector(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4910 yyval.ConstVal.S.copy(yyvsp[-5].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004911 ;}
4912 break;
4913
4914 case 175:
David Greene5fd22a82007-09-04 18:46:50 +00004915#line 2657 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4916 { (yyval.ConstVector = yyvsp[-2].ConstVector)->push_back(yyvsp[0].ConstVal); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004917 break;
4918
4919 case 176:
David Greene5fd22a82007-09-04 18:46:50 +00004920#line 2658 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004921 {
David Greene5fd22a82007-09-04 18:46:50 +00004922 yyval.ConstVector = new std::vector<ConstInfo>();
4923 yyval.ConstVector->push_back(yyvsp[0].ConstVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004924 ;}
4925 break;
4926
4927 case 177:
David Greene5fd22a82007-09-04 18:46:50 +00004928#line 2667 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4929 { yyval.BoolVal = false; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004930 break;
4931
4932 case 178:
David Greene5fd22a82007-09-04 18:46:50 +00004933#line 2668 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4934 { yyval.BoolVal = true; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004935 break;
4936
4937 case 179:
David Greene5fd22a82007-09-04 18:46:50 +00004938#line 2680 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004939 {
David Greene5fd22a82007-09-04 18:46:50 +00004940 yyval.ModuleVal = ParserResult = yyvsp[0].ModuleVal;
Reid Spencer950bf602007-01-26 08:19:09 +00004941 CurModule.ModuleDone();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004942 ;}
4943 break;
4944
4945 case 180:
David Greene5fd22a82007-09-04 18:46:50 +00004946#line 2689 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4947 { yyval.ModuleVal = yyvsp[-1].ModuleVal; CurFun.FunctionDone(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004948 break;
4949
4950 case 181:
David Greene5fd22a82007-09-04 18:46:50 +00004951#line 2690 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4952 { yyval.ModuleVal = yyvsp[-1].ModuleVal; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004953 break;
4954
4955 case 182:
David Greene5fd22a82007-09-04 18:46:50 +00004956#line 2691 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4957 { yyval.ModuleVal = yyvsp[-3].ModuleVal; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004958 break;
4959
4960 case 183:
David Greene5fd22a82007-09-04 18:46:50 +00004961#line 2692 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
4962 { yyval.ModuleVal = yyvsp[-1].ModuleVal; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004963 break;
4964
4965 case 184:
David Greene5fd22a82007-09-04 18:46:50 +00004966#line 2693 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004967 {
David Greene5fd22a82007-09-04 18:46:50 +00004968 yyval.ModuleVal = CurModule.CurrentModule;
Reid Spencer950bf602007-01-26 08:19:09 +00004969 // Emit an error if there are any unresolved types left.
4970 if (!CurModule.LateResolveTypes.empty()) {
4971 const ValID &DID = CurModule.LateResolveTypes.begin()->first;
4972 if (DID.Type == ValID::NameVal) {
4973 error("Reference to an undefined type: '"+DID.getName() + "'");
4974 } else {
4975 error("Reference to an undefined type: #" + itostr(DID.Num));
4976 }
4977 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004978 ;}
4979 break;
4980
4981 case 185:
David Greene5fd22a82007-09-04 18:46:50 +00004982#line 2709 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00004983 {
Reid Spencer950bf602007-01-26 08:19:09 +00004984 // Eagerly resolve types. This is not an optimization, this is a
4985 // requirement that is due to the fact that we could have this:
4986 //
4987 // %list = type { %list * }
4988 // %list = type { %list * } ; repeated type decl
4989 //
4990 // If types are not resolved eagerly, then the two types will not be
4991 // determined to be the same type!
4992 //
David Greene5fd22a82007-09-04 18:46:50 +00004993 ResolveTypeTo(yyvsp[-2].StrVal, yyvsp[0].TypeVal.PAT->get(), yyvsp[0].TypeVal.S);
Reid Spencer950bf602007-01-26 08:19:09 +00004994
David Greene5fd22a82007-09-04 18:46:50 +00004995 if (!setTypeName(yyvsp[0].TypeVal, yyvsp[-2].StrVal) && !yyvsp[-2].StrVal) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00004996 // If this is a numbered type that is not a redefinition, add it to the
4997 // slot table.
David Greene5fd22a82007-09-04 18:46:50 +00004998 CurModule.Types.push_back(yyvsp[0].TypeVal.PAT->get());
4999 CurModule.TypeSigns.push_back(yyvsp[0].TypeVal.S);
Reid Spencera50d5962006-12-02 04:11:07 +00005000 }
David Greene5fd22a82007-09-04 18:46:50 +00005001 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005002 ;}
5003 break;
5004
5005 case 186:
David Greene5fd22a82007-09-04 18:46:50 +00005006#line 2729 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005007 { // Function prototypes can be in const pool
5008 ;}
5009 break;
5010
5011 case 187:
David Greene5fd22a82007-09-04 18:46:50 +00005012#line 2731 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005013 { // Asm blocks can be in the const pool
5014 ;}
5015 break;
5016
5017 case 188:
David Greene5fd22a82007-09-04 18:46:50 +00005018#line 2733 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005019 {
David Greene5fd22a82007-09-04 18:46:50 +00005020 if (yyvsp[0].ConstVal.C == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00005021 error("Global value initializer is not a constant");
David Greene5fd22a82007-09-04 18:46:50 +00005022 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 +00005023 ;}
5024 break;
5025
5026 case 189:
David Greene5fd22a82007-09-04 18:46:50 +00005027#line 2737 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005028 {
Reid Spencer950bf602007-01-26 08:19:09 +00005029 CurGV = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005030 ;}
5031 break;
5032
5033 case 190:
David Greene5fd22a82007-09-04 18:46:50 +00005034#line 2740 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005035 {
David Greene5fd22a82007-09-04 18:46:50 +00005036 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
5037 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::ExternalLinkage, yyvsp[-1].BoolVal, Ty, 0,
5038 yyvsp[0].TypeVal.S);
5039 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005040 ;}
5041 break;
5042
5043 case 191:
David Greene5fd22a82007-09-04 18:46:50 +00005044#line 2745 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005045 {
Reid Spencer950bf602007-01-26 08:19:09 +00005046 CurGV = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005047 ;}
5048 break;
5049
5050 case 192:
David Greene5fd22a82007-09-04 18:46:50 +00005051#line 2748 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005052 {
David Greene5fd22a82007-09-04 18:46:50 +00005053 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
5054 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::DLLImportLinkage, yyvsp[-1].BoolVal, Ty, 0,
5055 yyvsp[0].TypeVal.S);
5056 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005057 ;}
5058 break;
5059
5060 case 193:
David Greene5fd22a82007-09-04 18:46:50 +00005061#line 2753 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005062 {
Reid Spencer950bf602007-01-26 08:19:09 +00005063 CurGV = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005064 ;}
5065 break;
5066
5067 case 194:
David Greene5fd22a82007-09-04 18:46:50 +00005068#line 2756 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005069 {
David Greene5fd22a82007-09-04 18:46:50 +00005070 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005071 CurGV =
David Greene5fd22a82007-09-04 18:46:50 +00005072 ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::ExternalWeakLinkage, yyvsp[-1].BoolVal, Ty, 0,
5073 yyvsp[0].TypeVal.S);
5074 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005075 ;}
5076 break;
5077
5078 case 195:
David Greene5fd22a82007-09-04 18:46:50 +00005079#line 2762 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005080 {
Reid Spencer950bf602007-01-26 08:19:09 +00005081 CurGV = 0;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005082 ;}
5083 break;
5084
5085 case 196:
David Greene5fd22a82007-09-04 18:46:50 +00005086#line 2765 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005087 {
5088 ;}
5089 break;
5090
5091 case 197:
David Greene5fd22a82007-09-04 18:46:50 +00005092#line 2767 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005093 {
5094 ;}
5095 break;
5096
5097 case 198:
David Greene5fd22a82007-09-04 18:46:50 +00005098#line 2769 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005099 {
5100 ;}
5101 break;
5102
5103 case 199:
David Greene5fd22a82007-09-04 18:46:50 +00005104#line 2774 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005105 {
Reid Spencer950bf602007-01-26 08:19:09 +00005106 const std::string &AsmSoFar = CurModule.CurrentModule->getModuleInlineAsm();
David Greene5fd22a82007-09-04 18:46:50 +00005107 char *EndStr = UnEscapeLexed(yyvsp[0].StrVal, true);
5108 std::string NewAsm(yyvsp[0].StrVal, EndStr);
5109 free(yyvsp[0].StrVal);
Reid Spencer950bf602007-01-26 08:19:09 +00005110
5111 if (AsmSoFar.empty())
5112 CurModule.CurrentModule->setModuleInlineAsm(NewAsm);
5113 else
5114 CurModule.CurrentModule->setModuleInlineAsm(AsmSoFar+"\n"+NewAsm);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005115 ;}
5116 break;
5117
5118 case 200:
David Greene5fd22a82007-09-04 18:46:50 +00005119#line 2788 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5120 { yyval.Endianness = Module::BigEndian; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005121 break;
5122
5123 case 201:
David Greene5fd22a82007-09-04 18:46:50 +00005124#line 2789 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5125 { yyval.Endianness = Module::LittleEndian; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005126 break;
5127
5128 case 202:
David Greene5fd22a82007-09-04 18:46:50 +00005129#line 2793 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005130 {
David Greene5fd22a82007-09-04 18:46:50 +00005131 CurModule.setEndianness(yyvsp[0].Endianness);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005132 ;}
5133 break;
5134
5135 case 203:
David Greene5fd22a82007-09-04 18:46:50 +00005136#line 2796 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005137 {
David Greene5fd22a82007-09-04 18:46:50 +00005138 if (yyvsp[0].UInt64Val == 32)
Reid Spencer950bf602007-01-26 08:19:09 +00005139 CurModule.setPointerSize(Module::Pointer32);
David Greene5fd22a82007-09-04 18:46:50 +00005140 else if (yyvsp[0].UInt64Val == 64)
Reid Spencer950bf602007-01-26 08:19:09 +00005141 CurModule.setPointerSize(Module::Pointer64);
5142 else
David Greene5fd22a82007-09-04 18:46:50 +00005143 error("Invalid pointer size: '" + utostr(yyvsp[0].UInt64Val) + "'");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005144 ;}
5145 break;
Reid Spencer9d6565a2007-02-15 02:26:10 +00005146
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005147 case 204:
David Greene5fd22a82007-09-04 18:46:50 +00005148#line 2804 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005149 {
David Greene5fd22a82007-09-04 18:46:50 +00005150 CurModule.CurrentModule->setTargetTriple(yyvsp[0].StrVal);
5151 free(yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005152 ;}
5153 break;
5154
5155 case 205:
David Greene5fd22a82007-09-04 18:46:50 +00005156#line 2808 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005157 {
David Greene5fd22a82007-09-04 18:46:50 +00005158 CurModule.CurrentModule->setDataLayout(yyvsp[0].StrVal);
5159 free(yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005160 ;}
5161 break;
5162
5163 case 207:
David Greene5fd22a82007-09-04 18:46:50 +00005164#line 2819 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005165 {
David Greene5fd22a82007-09-04 18:46:50 +00005166 CurModule.CurrentModule->addLibrary(yyvsp[0].StrVal);
5167 free(yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005168 ;}
5169 break;
5170
5171 case 208:
David Greene5fd22a82007-09-04 18:46:50 +00005172#line 2823 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005173 {
David Greene5fd22a82007-09-04 18:46:50 +00005174 CurModule.CurrentModule->addLibrary(yyvsp[0].StrVal);
5175 free(yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005176 ;}
5177 break;
5178
5179 case 209:
David Greene5fd22a82007-09-04 18:46:50 +00005180#line 2827 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005181 { ;}
5182 break;
5183
5184 case 213:
David Greene5fd22a82007-09-04 18:46:50 +00005185#line 2840 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5186 { yyval.StrVal = 0; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005187 break;
5188
5189 case 214:
David Greene5fd22a82007-09-04 18:46:50 +00005190#line 2844 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005191 {
David Greene5fd22a82007-09-04 18:46:50 +00005192 if (yyvsp[-1].TypeVal.PAT->get() == Type::VoidTy)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005193 error("void typed arguments are invalid");
David Greene5fd22a82007-09-04 18:46:50 +00005194 yyval.ArgVal = new std::pair<PATypeInfo, char*>(yyvsp[-1].TypeVal, yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005195 ;}
5196 break;
5197
5198 case 215:
David Greene5fd22a82007-09-04 18:46:50 +00005199#line 2852 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005200 {
David Greene5fd22a82007-09-04 18:46:50 +00005201 yyval.ArgList = yyvsp[-2].ArgList;
5202 yyval.ArgList->push_back(*yyvsp[0].ArgVal);
5203 delete yyvsp[0].ArgVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005204 ;}
5205 break;
5206
5207 case 216:
David Greene5fd22a82007-09-04 18:46:50 +00005208#line 2857 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005209 {
David Greene5fd22a82007-09-04 18:46:50 +00005210 yyval.ArgList = new std::vector<std::pair<PATypeInfo,char*> >();
5211 yyval.ArgList->push_back(*yyvsp[0].ArgVal);
5212 delete yyvsp[0].ArgVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005213 ;}
5214 break;
5215
5216 case 217:
David Greene5fd22a82007-09-04 18:46:50 +00005217#line 2865 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5218 { yyval.ArgList = yyvsp[0].ArgList; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005219 break;
5220
5221 case 218:
David Greene5fd22a82007-09-04 18:46:50 +00005222#line 2866 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005223 {
David Greene5fd22a82007-09-04 18:46:50 +00005224 yyval.ArgList = yyvsp[-2].ArgList;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005225 PATypeInfo VoidTI;
5226 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005227 VoidTI.S.makeSignless();
David Greene5fd22a82007-09-04 18:46:50 +00005228 yyval.ArgList->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005229 ;}
5230 break;
5231
5232 case 219:
David Greene5fd22a82007-09-04 18:46:50 +00005233#line 2873 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005234 {
David Greene5fd22a82007-09-04 18:46:50 +00005235 yyval.ArgList = new std::vector<std::pair<PATypeInfo,char*> >();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005236 PATypeInfo VoidTI;
5237 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005238 VoidTI.S.makeSignless();
David Greene5fd22a82007-09-04 18:46:50 +00005239 yyval.ArgList->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005240 ;}
5241 break;
5242
5243 case 220:
David Greene5fd22a82007-09-04 18:46:50 +00005244#line 2880 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5245 { yyval.ArgList = 0; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005246 break;
5247
5248 case 221:
David Greene5fd22a82007-09-04 18:46:50 +00005249#line 2884 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005250 {
David Greene5fd22a82007-09-04 18:46:50 +00005251 UnEscapeLexed(yyvsp[-5].StrVal);
5252 std::string FunctionName(yyvsp[-5].StrVal);
5253 free(yyvsp[-5].StrVal); // Free strdup'd memory!
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005254
David Greene5fd22a82007-09-04 18:46:50 +00005255 const Type* RetTy = yyvsp[-6].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005256
5257 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
5258 error("LLVM functions cannot return aggregate types");
5259
Reid Spencerbb1fd572007-03-21 17:15:50 +00005260 Signedness FTySign;
David Greene5fd22a82007-09-04 18:46:50 +00005261 FTySign.makeComposite(yyvsp[-6].TypeVal.S);
Reid Spenceref9b9a72007-02-05 20:47:22 +00005262 std::vector<const Type*> ParamTyList;
Reid Spencer950bf602007-01-26 08:19:09 +00005263
5264 // In LLVM 2.0 the signatures of three varargs intrinsics changed to take
5265 // i8*. We check here for those names and override the parameter list
5266 // types to ensure the prototype is correct.
5267 if (FunctionName == "llvm.va_start" || FunctionName == "llvm.va_end") {
Reid Spenceref9b9a72007-02-05 20:47:22 +00005268 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
Reid Spencer950bf602007-01-26 08:19:09 +00005269 } else if (FunctionName == "llvm.va_copy") {
Reid Spenceref9b9a72007-02-05 20:47:22 +00005270 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
5271 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
David Greene5fd22a82007-09-04 18:46:50 +00005272 } else if (yyvsp[-3].ArgList) { // If there are arguments...
Reid Spencer950bf602007-01-26 08:19:09 +00005273 for (std::vector<std::pair<PATypeInfo,char*> >::iterator
David Greene5fd22a82007-09-04 18:46:50 +00005274 I = yyvsp[-3].ArgList->begin(), E = yyvsp[-3].ArgList->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00005275 const Type *Ty = I->first.PAT->get();
Reid Spenceref9b9a72007-02-05 20:47:22 +00005276 ParamTyList.push_back(Ty);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005277 FTySign.add(I->first.S);
Reid Spencer950bf602007-01-26 08:19:09 +00005278 }
5279 }
5280
Reid Spenceref9b9a72007-02-05 20:47:22 +00005281 bool isVarArg = ParamTyList.size() && ParamTyList.back() == Type::VoidTy;
5282 if (isVarArg)
5283 ParamTyList.pop_back();
Reid Spencer950bf602007-01-26 08:19:09 +00005284
Reid Spencerb7046c72007-01-29 05:41:34 +00005285 // Convert the CSRet calling convention into the corresponding parameter
5286 // attribute.
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005287 ParamAttrsList *PAL = 0;
David Greene5fd22a82007-09-04 18:46:50 +00005288 if (yyvsp[-7].UIntVal == OldCallingConv::CSRet) {
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005289 ParamAttrsVector Attrs;
5290 ParamAttrsWithIndex PAWI;
5291 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
5292 Attrs.push_back(PAWI);
5293 PAL = ParamAttrsList::get(Attrs);
Reid Spencerb7046c72007-01-29 05:41:34 +00005294 }
5295
Reid Spencer7b5d4662007-04-09 06:16:21 +00005296 const FunctionType *FT =
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005297 FunctionType::get(RetTy, ParamTyList, isVarArg, PAL);
Reid Spencer950bf602007-01-26 08:19:09 +00005298 const PointerType *PFT = PointerType::get(FT);
David Greene5fd22a82007-09-04 18:46:50 +00005299 delete yyvsp[-6].TypeVal.PAT;
Reid Spencer950bf602007-01-26 08:19:09 +00005300
5301 ValID ID;
5302 if (!FunctionName.empty()) {
Reid Spencer5eb77c72007-03-15 03:26:42 +00005303 ID = ValID::create((char*)FunctionName.c_str());
Reid Spencer950bf602007-01-26 08:19:09 +00005304 } else {
Reid Spencer5eb77c72007-03-15 03:26:42 +00005305 ID = ValID::create((int)CurModule.Values[PFT].size());
Reid Spencer950bf602007-01-26 08:19:09 +00005306 }
Reid Spencerbb1fd572007-03-21 17:15:50 +00005307 ID.S.makeComposite(FTySign);
Reid Spencer950bf602007-01-26 08:19:09 +00005308
5309 Function *Fn = 0;
Reid Spencered96d1e2007-02-08 09:08:52 +00005310 Module* M = CurModule.CurrentModule;
5311
Reid Spencer950bf602007-01-26 08:19:09 +00005312 // See if this function was forward referenced. If so, recycle the object.
5313 if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, ID)) {
5314 // Move the function to the end of the list, from whereever it was
5315 // previously inserted.
5316 Fn = cast<Function>(FWRef);
Reid Spencered96d1e2007-02-08 09:08:52 +00005317 M->getFunctionList().remove(Fn);
5318 M->getFunctionList().push_back(Fn);
5319 } else if (!FunctionName.empty()) {
5320 GlobalValue *Conflict = M->getFunction(FunctionName);
5321 if (!Conflict)
5322 Conflict = M->getNamedGlobal(FunctionName);
5323 if (Conflict && PFT == Conflict->getType()) {
5324 if (!CurFun.isDeclare && !Conflict->isDeclaration()) {
5325 // We have two function definitions that conflict, same type, same
5326 // name. We should really check to make sure that this is the result
5327 // of integer type planes collapsing and generate an error if it is
5328 // not, but we'll just rename on the assumption that it is. However,
5329 // let's do it intelligently and rename the internal linkage one
5330 // if there is one.
5331 std::string NewName(makeNameUnique(FunctionName));
5332 if (Conflict->hasInternalLinkage()) {
5333 Conflict->setName(NewName);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005334 RenameMapKey Key =
5335 makeRenameMapKey(FunctionName, Conflict->getType(), ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00005336 CurModule.RenameMap[Key] = NewName;
5337 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5338 InsertValue(Fn, CurModule.Values);
5339 } else {
5340 Fn = new Function(FT, CurFun.Linkage, NewName, M);
5341 InsertValue(Fn, CurModule.Values);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005342 RenameMapKey Key =
5343 makeRenameMapKey(FunctionName, PFT, ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00005344 CurModule.RenameMap[Key] = NewName;
5345 }
5346 } else {
5347 // If they are not both definitions, then just use the function we
5348 // found since the types are the same.
5349 Fn = cast<Function>(Conflict);
Reid Spenceref9b9a72007-02-05 20:47:22 +00005350
Reid Spencered96d1e2007-02-08 09:08:52 +00005351 // Make sure to strip off any argument names so we can't get
5352 // conflicts.
5353 if (Fn->isDeclaration())
5354 for (Function::arg_iterator AI = Fn->arg_begin(),
5355 AE = Fn->arg_end(); AI != AE; ++AI)
5356 AI->setName("");
5357 }
5358 } else if (Conflict) {
Reid Spencere59f4932007-04-16 03:05:01 +00005359 // We have two globals with the same name and different types.
Reid Spencered96d1e2007-02-08 09:08:52 +00005360 // Previously, this was permitted because the symbol table had
5361 // "type planes" and names only needed to be distinct within a
5362 // type plane. After PR411 was fixed, this is no loner the case.
5363 // To resolve this we must rename one of the two.
5364 if (Conflict->hasInternalLinkage()) {
Reid Spencerbb1fd572007-03-21 17:15:50 +00005365 // We can safely rename the Conflict.
5366 RenameMapKey Key =
5367 makeRenameMapKey(Conflict->getName(), Conflict->getType(),
5368 CurModule.NamedValueSigns[Conflict->getName()]);
Reid Spencered96d1e2007-02-08 09:08:52 +00005369 Conflict->setName(makeNameUnique(Conflict->getName()));
Reid Spencered96d1e2007-02-08 09:08:52 +00005370 CurModule.RenameMap[Key] = Conflict->getName();
5371 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5372 InsertValue(Fn, CurModule.Values);
Reid Spencerd2920cd2007-03-21 17:27:53 +00005373 } else {
Reid Spencered96d1e2007-02-08 09:08:52 +00005374 // We can't quietly rename either of these things, but we must
Reid Spencerd2920cd2007-03-21 17:27:53 +00005375 // rename one of them. Only if the function's linkage is internal can
5376 // we forgo a warning message about the renamed function.
Reid Spencered96d1e2007-02-08 09:08:52 +00005377 std::string NewName = makeNameUnique(FunctionName);
Reid Spencerd2920cd2007-03-21 17:27:53 +00005378 if (CurFun.Linkage != GlobalValue::InternalLinkage) {
5379 warning("Renaming function '" + FunctionName + "' as '" + NewName +
5380 "' may cause linkage errors");
5381 }
5382 // Elect to rename the thing we're now defining.
Reid Spencered96d1e2007-02-08 09:08:52 +00005383 Fn = new Function(FT, CurFun.Linkage, NewName, M);
5384 InsertValue(Fn, CurModule.Values);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005385 RenameMapKey Key = makeRenameMapKey(FunctionName, PFT, ID.S);
Reid Spencered96d1e2007-02-08 09:08:52 +00005386 CurModule.RenameMap[Key] = NewName;
Reid Spencerd2920cd2007-03-21 17:27:53 +00005387 }
Reid Spenceref9b9a72007-02-05 20:47:22 +00005388 } else {
Reid Spencered96d1e2007-02-08 09:08:52 +00005389 // There's no conflict, just define the function
5390 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5391 InsertValue(Fn, CurModule.Values);
Reid Spenceref9b9a72007-02-05 20:47:22 +00005392 }
Reid Spencere59f4932007-04-16 03:05:01 +00005393 } else {
5394 // There's no conflict, just define the function
5395 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
5396 InsertValue(Fn, CurModule.Values);
Reid Spencer950bf602007-01-26 08:19:09 +00005397 }
5398
Reid Spencere59f4932007-04-16 03:05:01 +00005399
Reid Spencer950bf602007-01-26 08:19:09 +00005400 CurFun.FunctionStart(Fn);
5401
5402 if (CurFun.isDeclare) {
5403 // If we have declaration, always overwrite linkage. This will allow us
5404 // to correctly handle cases, when pointer to function is passed as
5405 // argument to another function.
5406 Fn->setLinkage(CurFun.Linkage);
5407 }
David Greene5fd22a82007-09-04 18:46:50 +00005408 Fn->setCallingConv(upgradeCallingConv(yyvsp[-7].UIntVal));
5409 Fn->setAlignment(yyvsp[0].UIntVal);
5410 if (yyvsp[-1].StrVal) {
5411 Fn->setSection(yyvsp[-1].StrVal);
5412 free(yyvsp[-1].StrVal);
Reid Spencer950bf602007-01-26 08:19:09 +00005413 }
5414
5415 // Add all of the arguments we parsed to the function...
David Greene5fd22a82007-09-04 18:46:50 +00005416 if (yyvsp[-3].ArgList) { // Is null if empty...
Reid Spencer950bf602007-01-26 08:19:09 +00005417 if (isVarArg) { // Nuke the last entry
David Greene5fd22a82007-09-04 18:46:50 +00005418 assert(yyvsp[-3].ArgList->back().first.PAT->get() == Type::VoidTy &&
5419 yyvsp[-3].ArgList->back().second == 0 && "Not a varargs marker");
5420 delete yyvsp[-3].ArgList->back().first.PAT;
5421 yyvsp[-3].ArgList->pop_back(); // Delete the last entry
Reid Spencer950bf602007-01-26 08:19:09 +00005422 }
5423 Function::arg_iterator ArgIt = Fn->arg_begin();
Reid Spenceref9b9a72007-02-05 20:47:22 +00005424 Function::arg_iterator ArgEnd = Fn->arg_end();
David Greene5fd22a82007-09-04 18:46:50 +00005425 std::vector<std::pair<PATypeInfo,char*> >::iterator I = yyvsp[-3].ArgList->begin();
5426 std::vector<std::pair<PATypeInfo,char*> >::iterator E = yyvsp[-3].ArgList->end();
Reid Spenceref9b9a72007-02-05 20:47:22 +00005427 for ( ; I != E && ArgIt != ArgEnd; ++I, ++ArgIt) {
Reid Spencered96d1e2007-02-08 09:08:52 +00005428 delete I->first.PAT; // Delete the typeholder...
Reid Spencerbb1fd572007-03-21 17:15:50 +00005429 ValueInfo VI; VI.V = ArgIt; VI.S.copy(I->first.S);
5430 setValueName(VI, I->second); // Insert arg into symtab...
Reid Spencer950bf602007-01-26 08:19:09 +00005431 InsertValue(ArgIt);
5432 }
David Greene5fd22a82007-09-04 18:46:50 +00005433 delete yyvsp[-3].ArgList; // We're now done with the argument list
Reid Spencer950bf602007-01-26 08:19:09 +00005434 }
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005435 lastCallingConv = OldCallingConv::C;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005436 ;}
5437 break;
5438
5439 case 224:
David Greene5fd22a82007-09-04 18:46:50 +00005440#line 3078 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5441 { CurFun.Linkage = yyvsp[0].Linkage; ;}
Reid Spencerd2920cd2007-03-21 17:27:53 +00005442 break;
5443
5444 case 225:
David Greene5fd22a82007-09-04 18:46:50 +00005445#line 3078 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005446 {
David Greene5fd22a82007-09-04 18:46:50 +00005447 yyval.FunctionVal = CurFun.CurrentFunction;
Reid Spencer950bf602007-01-26 08:19:09 +00005448
5449 // Make sure that we keep track of the linkage type even if there was a
5450 // previous "declare".
David Greene5fd22a82007-09-04 18:46:50 +00005451 yyval.FunctionVal->setLinkage(yyvsp[-3].Linkage);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005452 ;}
5453 break;
5454
Reid Spencerd2920cd2007-03-21 17:27:53 +00005455 case 228:
David Greene5fd22a82007-09-04 18:46:50 +00005456#line 3092 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005457 {
David Greene5fd22a82007-09-04 18:46:50 +00005458 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005459 ;}
5460 break;
5461
Reid Spencerd2920cd2007-03-21 17:27:53 +00005462 case 229:
David Greene5fd22a82007-09-04 18:46:50 +00005463#line 3097 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5464 { yyval.Linkage = GlobalValue::ExternalLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005465 break;
5466
Reid Spencerd2920cd2007-03-21 17:27:53 +00005467 case 230:
David Greene5fd22a82007-09-04 18:46:50 +00005468#line 3098 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5469 { yyval.Linkage = GlobalValue::DLLImportLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005470 break;
5471
Reid Spencerd2920cd2007-03-21 17:27:53 +00005472 case 231:
David Greene5fd22a82007-09-04 18:46:50 +00005473#line 3099 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5474 { yyval.Linkage = GlobalValue::ExternalWeakLinkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005475 break;
5476
Reid Spencerd2920cd2007-03-21 17:27:53 +00005477 case 232:
David Greene5fd22a82007-09-04 18:46:50 +00005478#line 3103 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005479 { CurFun.isDeclare = true; ;}
5480 break;
5481
Reid Spencerd2920cd2007-03-21 17:27:53 +00005482 case 233:
David Greene5fd22a82007-09-04 18:46:50 +00005483#line 3104 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5484 { CurFun.Linkage = yyvsp[0].Linkage; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005485 break;
5486
Reid Spencerd2920cd2007-03-21 17:27:53 +00005487 case 234:
David Greene5fd22a82007-09-04 18:46:50 +00005488#line 3104 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005489 {
David Greene5fd22a82007-09-04 18:46:50 +00005490 yyval.FunctionVal = CurFun.CurrentFunction;
Reid Spencer950bf602007-01-26 08:19:09 +00005491 CurFun.FunctionDone();
5492
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005493 ;}
5494 break;
5495
Reid Spencerd2920cd2007-03-21 17:27:53 +00005496 case 235:
David Greene5fd22a82007-09-04 18:46:50 +00005497#line 3116 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5498 { yyval.BoolVal = false; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005499 break;
5500
Reid Spencerd2920cd2007-03-21 17:27:53 +00005501 case 236:
David Greene5fd22a82007-09-04 18:46:50 +00005502#line 3117 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5503 { yyval.BoolVal = true; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005504 break;
5505
Reid Spencerd2920cd2007-03-21 17:27:53 +00005506 case 237:
David Greene5fd22a82007-09-04 18:46:50 +00005507#line 3122 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5508 { yyval.ValIDVal = ValID::create(yyvsp[0].SInt64Val); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005509 break;
5510
Reid Spencerd2920cd2007-03-21 17:27:53 +00005511 case 238:
David Greene5fd22a82007-09-04 18:46:50 +00005512#line 3123 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5513 { yyval.ValIDVal = ValID::create(yyvsp[0].UInt64Val); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005514 break;
5515
Reid Spencerd2920cd2007-03-21 17:27:53 +00005516 case 239:
David Greene5fd22a82007-09-04 18:46:50 +00005517#line 3124 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5518 { yyval.ValIDVal = ValID::create(yyvsp[0].FPVal); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005519 break;
5520
Reid Spencerd2920cd2007-03-21 17:27:53 +00005521 case 240:
David Greene5fd22a82007-09-04 18:46:50 +00005522#line 3125 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencerbb1fd572007-03-21 17:15:50 +00005523 {
David Greene5fd22a82007-09-04 18:46:50 +00005524 yyval.ValIDVal = ValID::create(ConstantInt::get(Type::Int1Ty, true));
5525 yyval.ValIDVal.S.makeUnsigned();
Reid Spencerbb1fd572007-03-21 17:15:50 +00005526 ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005527 break;
5528
Reid Spencerd2920cd2007-03-21 17:27:53 +00005529 case 241:
David Greene5fd22a82007-09-04 18:46:50 +00005530#line 3129 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencerbb1fd572007-03-21 17:15:50 +00005531 {
David Greene5fd22a82007-09-04 18:46:50 +00005532 yyval.ValIDVal = ValID::create(ConstantInt::get(Type::Int1Ty, false));
5533 yyval.ValIDVal.S.makeUnsigned();
Reid Spencerbb1fd572007-03-21 17:15:50 +00005534 ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005535 break;
5536
Reid Spencerd2920cd2007-03-21 17:27:53 +00005537 case 242:
David Greene5fd22a82007-09-04 18:46:50 +00005538#line 3133 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5539 { yyval.ValIDVal = ValID::createNull(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005540 break;
5541
Reid Spencerd2920cd2007-03-21 17:27:53 +00005542 case 243:
David Greene5fd22a82007-09-04 18:46:50 +00005543#line 3134 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5544 { yyval.ValIDVal = ValID::createUndef(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005545 break;
5546
Reid Spencerd2920cd2007-03-21 17:27:53 +00005547 case 244:
David Greene5fd22a82007-09-04 18:46:50 +00005548#line 3135 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5549 { yyval.ValIDVal = ValID::createZeroInit(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005550 break;
5551
Reid Spencerd2920cd2007-03-21 17:27:53 +00005552 case 245:
David Greene5fd22a82007-09-04 18:46:50 +00005553#line 3136 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005554 { // Nonempty unsized packed vector
David Greene5fd22a82007-09-04 18:46:50 +00005555 const Type *ETy = (*yyvsp[-1].ConstVector)[0].C->getType();
5556 int NumElements = yyvsp[-1].ConstVector->size();
Reid Spencer9d6565a2007-02-15 02:26:10 +00005557 VectorType* pt = VectorType::get(ETy, NumElements);
David Greene5fd22a82007-09-04 18:46:50 +00005558 yyval.ValIDVal.S.makeComposite((*yyvsp[-1].ConstVector)[0].S);
5559 PATypeHolder* PTy = new PATypeHolder(HandleUpRefs(pt, yyval.ValIDVal.S));
Reid Spencer950bf602007-01-26 08:19:09 +00005560
5561 // Verify all elements are correct type!
5562 std::vector<Constant*> Elems;
David Greene5fd22a82007-09-04 18:46:50 +00005563 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
5564 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00005565 const Type *CTy = C->getType();
5566 if (ETy != CTy)
5567 error("Element #" + utostr(i) + " is not of type '" +
5568 ETy->getDescription() +"' as required!\nIt is of type '" +
5569 CTy->getDescription() + "'");
5570 Elems.push_back(C);
Reid Spencere77e35e2006-12-01 20:26:20 +00005571 }
David Greene5fd22a82007-09-04 18:46:50 +00005572 yyval.ValIDVal = ValID::create(ConstantVector::get(pt, Elems));
5573 delete PTy; delete yyvsp[-1].ConstVector;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005574 ;}
5575 break;
5576
Reid Spencerd2920cd2007-03-21 17:27:53 +00005577 case 246:
David Greene5fd22a82007-09-04 18:46:50 +00005578#line 3157 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005579 {
David Greene5fd22a82007-09-04 18:46:50 +00005580 yyval.ValIDVal = ValID::create(yyvsp[0].ConstVal.C);
5581 yyval.ValIDVal.S.copy(yyvsp[0].ConstVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005582 ;}
5583 break;
5584
Reid Spencerd2920cd2007-03-21 17:27:53 +00005585 case 247:
David Greene5fd22a82007-09-04 18:46:50 +00005586#line 3161 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005587 {
David Greene5fd22a82007-09-04 18:46:50 +00005588 char *End = UnEscapeLexed(yyvsp[-2].StrVal, true);
5589 std::string AsmStr = std::string(yyvsp[-2].StrVal, End);
5590 End = UnEscapeLexed(yyvsp[0].StrVal, true);
5591 std::string Constraints = std::string(yyvsp[0].StrVal, End);
5592 yyval.ValIDVal = ValID::createInlineAsm(AsmStr, Constraints, yyvsp[-3].BoolVal);
5593 free(yyvsp[-2].StrVal);
5594 free(yyvsp[0].StrVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005595 ;}
5596 break;
5597
Reid Spencerd2920cd2007-03-21 17:27:53 +00005598 case 248:
David Greene5fd22a82007-09-04 18:46:50 +00005599#line 3175 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5600 { yyval.ValIDVal = ValID::create(yyvsp[0].SIntVal); yyval.ValIDVal.S.makeSignless(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005601 break;
5602
Reid Spencerd2920cd2007-03-21 17:27:53 +00005603 case 249:
David Greene5fd22a82007-09-04 18:46:50 +00005604#line 3176 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5605 { yyval.ValIDVal = ValID::create(yyvsp[0].StrVal); yyval.ValIDVal.S.makeSignless(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005606 break;
5607
Reid Spencerd2920cd2007-03-21 17:27:53 +00005608 case 252:
David Greene5fd22a82007-09-04 18:46:50 +00005609#line 3189 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005610 {
David Greene5fd22a82007-09-04 18:46:50 +00005611 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
5612 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
5613 yyval.ValueVal.V = getVal(Ty, yyvsp[0].ValIDVal);
5614 yyval.ValueVal.S.copy(yyvsp[-1].TypeVal.S);
5615 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005616 ;}
5617 break;
5618
Reid Spencerd2920cd2007-03-21 17:27:53 +00005619 case 253:
David Greene5fd22a82007-09-04 18:46:50 +00005620#line 3199 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005621 {
David Greene5fd22a82007-09-04 18:46:50 +00005622 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005623 ;}
5624 break;
5625
Reid Spencerd2920cd2007-03-21 17:27:53 +00005626 case 254:
David Greene5fd22a82007-09-04 18:46:50 +00005627#line 3202 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005628 { // Do not allow functions with 0 basic blocks
David Greene5fd22a82007-09-04 18:46:50 +00005629 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005630 ;}
5631 break;
5632
Reid Spencerd2920cd2007-03-21 17:27:53 +00005633 case 255:
David Greene5fd22a82007-09-04 18:46:50 +00005634#line 3211 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005635 {
David Greene5fd22a82007-09-04 18:46:50 +00005636 ValueInfo VI; VI.V = yyvsp[0].TermInstVal.TI; VI.S.copy(yyvsp[0].TermInstVal.S);
5637 setValueName(VI, yyvsp[-1].StrVal);
5638 InsertValue(yyvsp[0].TermInstVal.TI);
5639 yyvsp[-2].BasicBlockVal->getInstList().push_back(yyvsp[0].TermInstVal.TI);
5640 InsertValue(yyvsp[-2].BasicBlockVal);
5641 yyval.BasicBlockVal = yyvsp[-2].BasicBlockVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005642 ;}
5643 break;
5644
Reid Spencerd2920cd2007-03-21 17:27:53 +00005645 case 256:
David Greene5fd22a82007-09-04 18:46:50 +00005646#line 3222 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005647 {
David Greene5fd22a82007-09-04 18:46:50 +00005648 if (yyvsp[0].InstVal.I)
5649 yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].InstVal.I);
5650 yyval.BasicBlockVal = yyvsp[-1].BasicBlockVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005651 ;}
5652 break;
5653
Reid Spencerd2920cd2007-03-21 17:27:53 +00005654 case 257:
David Greene5fd22a82007-09-04 18:46:50 +00005655#line 3227 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005656 {
David Greene5fd22a82007-09-04 18:46:50 +00005657 yyval.BasicBlockVal = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++),true);
Reid Spencer950bf602007-01-26 08:19:09 +00005658 // Make sure to move the basic block to the correct location in the
5659 // function, instead of leaving it inserted wherever it was first
5660 // referenced.
5661 Function::BasicBlockListType &BBL =
5662 CurFun.CurrentFunction->getBasicBlockList();
David Greene5fd22a82007-09-04 18:46:50 +00005663 BBL.splice(BBL.end(), BBL, yyval.BasicBlockVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005664 ;}
5665 break;
5666
Reid Spencerd2920cd2007-03-21 17:27:53 +00005667 case 258:
David Greene5fd22a82007-09-04 18:46:50 +00005668#line 3236 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005669 {
David Greene5fd22a82007-09-04 18:46:50 +00005670 yyval.BasicBlockVal = CurBB = getBBVal(ValID::create(yyvsp[0].StrVal), true);
Reid Spencer950bf602007-01-26 08:19:09 +00005671 // Make sure to move the basic block to the correct location in the
5672 // function, instead of leaving it inserted wherever it was first
5673 // referenced.
5674 Function::BasicBlockListType &BBL =
5675 CurFun.CurrentFunction->getBasicBlockList();
David Greene5fd22a82007-09-04 18:46:50 +00005676 BBL.splice(BBL.end(), BBL, yyval.BasicBlockVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005677 ;}
5678 break;
5679
Reid Spencerd2920cd2007-03-21 17:27:53 +00005680 case 261:
David Greene5fd22a82007-09-04 18:46:50 +00005681#line 3250 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005682 { // Return with a result...
David Greene5fd22a82007-09-04 18:46:50 +00005683 yyval.TermInstVal.TI = new ReturnInst(yyvsp[0].ValueVal.V);
5684 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005685 ;}
5686 break;
5687
Reid Spencerd2920cd2007-03-21 17:27:53 +00005688 case 262:
David Greene5fd22a82007-09-04 18:46:50 +00005689#line 3254 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005690 { // Return with no result...
David Greene5fd22a82007-09-04 18:46:50 +00005691 yyval.TermInstVal.TI = new ReturnInst();
5692 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005693 ;}
5694 break;
5695
Reid Spencerd2920cd2007-03-21 17:27:53 +00005696 case 263:
David Greene5fd22a82007-09-04 18:46:50 +00005697#line 3258 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005698 { // Unconditional Branch...
David Greene5fd22a82007-09-04 18:46:50 +00005699 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
5700 yyval.TermInstVal.TI = new BranchInst(tmpBB);
5701 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005702 ;}
5703 break;
5704
Reid Spencerd2920cd2007-03-21 17:27:53 +00005705 case 264:
David Greene5fd22a82007-09-04 18:46:50 +00005706#line 3263 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005707 {
David Greene5fd22a82007-09-04 18:46:50 +00005708 yyvsp[-3].ValIDVal.S.makeSignless();
5709 yyvsp[0].ValIDVal.S.makeSignless();
5710 BasicBlock* tmpBBA = getBBVal(yyvsp[-3].ValIDVal);
5711 BasicBlock* tmpBBB = getBBVal(yyvsp[0].ValIDVal);
5712 yyvsp[-6].ValIDVal.S.makeUnsigned();
5713 Value* tmpVal = getVal(Type::Int1Ty, yyvsp[-6].ValIDVal);
5714 yyval.TermInstVal.TI = new BranchInst(tmpBBA, tmpBBB, tmpVal);
5715 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005716 ;}
5717 break;
5718
Reid Spencerd2920cd2007-03-21 17:27:53 +00005719 case 265:
David Greene5fd22a82007-09-04 18:46:50 +00005720#line 3273 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005721 {
David Greene5fd22a82007-09-04 18:46:50 +00005722 yyvsp[-6].ValIDVal.S.copy(yyvsp[-7].PrimType.S);
5723 Value* tmpVal = getVal(yyvsp[-7].PrimType.T, yyvsp[-6].ValIDVal);
5724 yyvsp[-3].ValIDVal.S.makeSignless();
5725 BasicBlock* tmpBB = getBBVal(yyvsp[-3].ValIDVal);
5726 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, yyvsp[-1].JumpTable->size());
5727 yyval.TermInstVal.TI = S;
5728 yyval.TermInstVal.S.makeSignless();
5729 std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = yyvsp[-1].JumpTable->begin(),
5730 E = yyvsp[-1].JumpTable->end();
Reid Spencer950bf602007-01-26 08:19:09 +00005731 for (; I != E; ++I) {
5732 if (ConstantInt *CI = dyn_cast<ConstantInt>(I->first))
5733 S->addCase(CI, I->second);
5734 else
5735 error("Switch case is constant, but not a simple integer");
5736 }
David Greene5fd22a82007-09-04 18:46:50 +00005737 delete yyvsp[-1].JumpTable;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005738 ;}
5739 break;
5740
Reid Spencerd2920cd2007-03-21 17:27:53 +00005741 case 266:
David Greene5fd22a82007-09-04 18:46:50 +00005742#line 3291 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005743 {
David Greene5fd22a82007-09-04 18:46:50 +00005744 yyvsp[-5].ValIDVal.S.copy(yyvsp[-6].PrimType.S);
5745 Value* tmpVal = getVal(yyvsp[-6].PrimType.T, yyvsp[-5].ValIDVal);
5746 yyvsp[-2].ValIDVal.S.makeSignless();
5747 BasicBlock* tmpBB = getBBVal(yyvsp[-2].ValIDVal);
Reid Spencer950bf602007-01-26 08:19:09 +00005748 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0);
David Greene5fd22a82007-09-04 18:46:50 +00005749 yyval.TermInstVal.TI = S;
5750 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005751 ;}
5752 break;
5753
Reid Spencerd2920cd2007-03-21 17:27:53 +00005754 case 267:
David Greene5fd22a82007-09-04 18:46:50 +00005755#line 3301 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005756 {
Reid Spencer950bf602007-01-26 08:19:09 +00005757 const PointerType *PFTy;
5758 const FunctionType *Ty;
Reid Spencerbb1fd572007-03-21 17:15:50 +00005759 Signedness FTySign;
Reid Spencer950bf602007-01-26 08:19:09 +00005760
David Greene5fd22a82007-09-04 18:46:50 +00005761 if (!(PFTy = dyn_cast<PointerType>(yyvsp[-10].TypeVal.PAT->get())) ||
Reid Spencer950bf602007-01-26 08:19:09 +00005762 !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
5763 // Pull out the types of all of the arguments...
5764 std::vector<const Type*> ParamTypes;
David Greene5fd22a82007-09-04 18:46:50 +00005765 FTySign.makeComposite(yyvsp[-10].TypeVal.S);
5766 if (yyvsp[-7].ValueList) {
5767 for (std::vector<ValueInfo>::iterator I = yyvsp[-7].ValueList->begin(), E = yyvsp[-7].ValueList->end();
Reid Spencerbb1fd572007-03-21 17:15:50 +00005768 I != E; ++I) {
Reid Spencer950bf602007-01-26 08:19:09 +00005769 ParamTypes.push_back((*I).V->getType());
Reid Spencerbb1fd572007-03-21 17:15:50 +00005770 FTySign.add(I->S);
5771 }
Reid Spencer950bf602007-01-26 08:19:09 +00005772 }
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005773 ParamAttrsList *PAL = 0;
David Greene5fd22a82007-09-04 18:46:50 +00005774 if (yyvsp[-11].UIntVal == OldCallingConv::CSRet) {
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005775 ParamAttrsVector Attrs;
5776 ParamAttrsWithIndex PAWI;
5777 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
5778 Attrs.push_back(PAWI);
5779 PAL = ParamAttrsList::get(Attrs);
Reid Spencerb7046c72007-01-29 05:41:34 +00005780 }
Reid Spencer950bf602007-01-26 08:19:09 +00005781 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
5782 if (isVarArg) ParamTypes.pop_back();
David Greene5fd22a82007-09-04 18:46:50 +00005783 Ty = FunctionType::get(yyvsp[-10].TypeVal.PAT->get(), ParamTypes, isVarArg, PAL);
Reid Spencer950bf602007-01-26 08:19:09 +00005784 PFTy = PointerType::get(Ty);
David Greene5fd22a82007-09-04 18:46:50 +00005785 yyval.TermInstVal.S.copy(yyvsp[-10].TypeVal.S);
Reid Spencerbb1fd572007-03-21 17:15:50 +00005786 } else {
David Greene5fd22a82007-09-04 18:46:50 +00005787 FTySign = yyvsp[-10].TypeVal.S;
Reid Spencera3b12dd2007-04-07 16:14:01 +00005788 // Get the signedness of the result type. $3 is the pointer to the
5789 // function type so we get the 0th element to extract the function type,
5790 // and then the 0th element again to get the result type.
David Greene5fd22a82007-09-04 18:46:50 +00005791 yyval.TermInstVal.S.copy(yyvsp[-10].TypeVal.S.get(0).get(0));
Reid Spencer950bf602007-01-26 08:19:09 +00005792 }
Reid Spencer7b5d4662007-04-09 06:16:21 +00005793
David Greene5fd22a82007-09-04 18:46:50 +00005794 yyvsp[-9].ValIDVal.S.makeComposite(FTySign);
5795 Value *V = getVal(PFTy, yyvsp[-9].ValIDVal); // Get the function we're calling...
5796 BasicBlock *Normal = getBBVal(yyvsp[-3].ValIDVal);
5797 BasicBlock *Except = getBBVal(yyvsp[0].ValIDVal);
Reid Spencer950bf602007-01-26 08:19:09 +00005798
5799 // Create the call node...
David Greene5fd22a82007-09-04 18:46:50 +00005800 if (!yyvsp[-7].ValueList) { // Has no arguments?
5801 std::vector<Value*> Args;
5802 yyval.TermInstVal.TI = new InvokeInst(V, Normal, Except, Args.begin(), Args.end());
Reid Spencer950bf602007-01-26 08:19:09 +00005803 } else { // Has arguments?
5804 // Loop through FunctionType's arguments and ensure they are specified
5805 // correctly!
5806 //
5807 FunctionType::param_iterator I = Ty->param_begin();
5808 FunctionType::param_iterator E = Ty->param_end();
David Greene5fd22a82007-09-04 18:46:50 +00005809 std::vector<ValueInfo>::iterator ArgI = yyvsp[-7].ValueList->begin(), ArgE = yyvsp[-7].ValueList->end();
Reid Spencer950bf602007-01-26 08:19:09 +00005810
5811 std::vector<Value*> Args;
5812 for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
5813 if ((*ArgI).V->getType() != *I)
5814 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
5815 (*I)->getDescription() + "'");
5816 Args.push_back((*ArgI).V);
5817 }
5818
5819 if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
5820 error("Invalid number of parameters detected");
5821
David Greene5fd22a82007-09-04 18:46:50 +00005822 yyval.TermInstVal.TI = new InvokeInst(V, Normal, Except, Args.begin(), Args.end());
Reid Spencer950bf602007-01-26 08:19:09 +00005823 }
David Greene5fd22a82007-09-04 18:46:50 +00005824 cast<InvokeInst>(yyval.TermInstVal.TI)->setCallingConv(upgradeCallingConv(yyvsp[-11].UIntVal));
5825 delete yyvsp[-10].TypeVal.PAT;
5826 delete yyvsp[-7].ValueList;
Reid Spencer7eea8ff2007-05-18 05:48:07 +00005827 lastCallingConv = OldCallingConv::C;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005828 ;}
5829 break;
5830
Reid Spencerd2920cd2007-03-21 17:27:53 +00005831 case 268:
David Greene5fd22a82007-09-04 18:46:50 +00005832#line 3374 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005833 {
David Greene5fd22a82007-09-04 18:46:50 +00005834 yyval.TermInstVal.TI = new UnwindInst();
5835 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005836 ;}
5837 break;
5838
Reid Spencerd2920cd2007-03-21 17:27:53 +00005839 case 269:
David Greene5fd22a82007-09-04 18:46:50 +00005840#line 3378 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005841 {
David Greene5fd22a82007-09-04 18:46:50 +00005842 yyval.TermInstVal.TI = new UnreachableInst();
5843 yyval.TermInstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005844 ;}
5845 break;
5846
Reid Spencerd2920cd2007-03-21 17:27:53 +00005847 case 270:
David Greene5fd22a82007-09-04 18:46:50 +00005848#line 3385 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005849 {
David Greene5fd22a82007-09-04 18:46:50 +00005850 yyval.JumpTable = yyvsp[-5].JumpTable;
5851 yyvsp[-3].ValIDVal.S.copy(yyvsp[-4].PrimType.S);
5852 Constant *V = cast<Constant>(getExistingValue(yyvsp[-4].PrimType.T, yyvsp[-3].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00005853
5854 if (V == 0)
5855 error("May only switch on a constant pool value");
5856
David Greene5fd22a82007-09-04 18:46:50 +00005857 yyvsp[0].ValIDVal.S.makeSignless();
5858 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
5859 yyval.JumpTable->push_back(std::make_pair(V, tmpBB));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005860 ;}
5861 break;
5862
Reid Spencerd2920cd2007-03-21 17:27:53 +00005863 case 271:
David Greene5fd22a82007-09-04 18:46:50 +00005864#line 3397 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005865 {
David Greene5fd22a82007-09-04 18:46:50 +00005866 yyval.JumpTable = new std::vector<std::pair<Constant*, BasicBlock*> >();
5867 yyvsp[-3].ValIDVal.S.copy(yyvsp[-4].PrimType.S);
5868 Constant *V = cast<Constant>(getExistingValue(yyvsp[-4].PrimType.T, yyvsp[-3].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00005869
5870 if (V == 0)
5871 error("May only switch on a constant pool value");
5872
David Greene5fd22a82007-09-04 18:46:50 +00005873 yyvsp[0].ValIDVal.S.makeSignless();
5874 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
5875 yyval.JumpTable->push_back(std::make_pair(V, tmpBB));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005876 ;}
5877 break;
5878
Reid Spencerd2920cd2007-03-21 17:27:53 +00005879 case 272:
David Greene5fd22a82007-09-04 18:46:50 +00005880#line 3412 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005881 {
Reid Spencer950bf602007-01-26 08:19:09 +00005882 bool omit = false;
David Greene5fd22a82007-09-04 18:46:50 +00005883 if (yyvsp[-1].StrVal)
5884 if (BitCastInst *BCI = dyn_cast<BitCastInst>(yyvsp[0].InstVal.I))
Reid Spencer950bf602007-01-26 08:19:09 +00005885 if (BCI->getSrcTy() == BCI->getDestTy() &&
David Greene5fd22a82007-09-04 18:46:50 +00005886 BCI->getOperand(0)->getName() == yyvsp[-1].StrVal)
Reid Spencer950bf602007-01-26 08:19:09 +00005887 // This is a useless bit cast causing a name redefinition. It is
5888 // a bit cast from a type to the same type of an operand with the
5889 // same name as the name we would give this instruction. Since this
5890 // instruction results in no code generation, it is safe to omit
5891 // the instruction. This situation can occur because of collapsed
5892 // type planes. For example:
5893 // %X = add int %Y, %Z
5894 // %X = cast int %Y to uint
5895 // After upgrade, this looks like:
5896 // %X = add i32 %Y, %Z
5897 // %X = bitcast i32 to i32
5898 // The bitcast is clearly useless so we omit it.
5899 omit = true;
5900 if (omit) {
David Greene5fd22a82007-09-04 18:46:50 +00005901 yyval.InstVal.I = 0;
5902 yyval.InstVal.S.makeSignless();
Reid Spencer950bf602007-01-26 08:19:09 +00005903 } else {
David Greene5fd22a82007-09-04 18:46:50 +00005904 ValueInfo VI; VI.V = yyvsp[0].InstVal.I; VI.S.copy(yyvsp[0].InstVal.S);
5905 setValueName(VI, yyvsp[-1].StrVal);
5906 InsertValue(yyvsp[0].InstVal.I);
5907 yyval.InstVal = yyvsp[0].InstVal;
Reid Spencer950bf602007-01-26 08:19:09 +00005908 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005909 ;}
5910 break;
5911
Reid Spencerd2920cd2007-03-21 17:27:53 +00005912 case 273:
David Greene5fd22a82007-09-04 18:46:50 +00005913#line 3442 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005914 { // Used for PHI nodes
David Greene5fd22a82007-09-04 18:46:50 +00005915 yyval.PHIList.P = new std::list<std::pair<Value*, BasicBlock*> >();
5916 yyval.PHIList.S.copy(yyvsp[-5].TypeVal.S);
5917 yyvsp[-3].ValIDVal.S.copy(yyvsp[-5].TypeVal.S);
5918 Value* tmpVal = getVal(yyvsp[-5].TypeVal.PAT->get(), yyvsp[-3].ValIDVal);
5919 yyvsp[-1].ValIDVal.S.makeSignless();
5920 BasicBlock* tmpBB = getBBVal(yyvsp[-1].ValIDVal);
5921 yyval.PHIList.P->push_back(std::make_pair(tmpVal, tmpBB));
5922 delete yyvsp[-5].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005923 ;}
5924 break;
5925
Reid Spencerd2920cd2007-03-21 17:27:53 +00005926 case 274:
David Greene5fd22a82007-09-04 18:46:50 +00005927#line 3452 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005928 {
David Greene5fd22a82007-09-04 18:46:50 +00005929 yyval.PHIList = yyvsp[-6].PHIList;
5930 yyvsp[-3].ValIDVal.S.copy(yyvsp[-6].PHIList.S);
5931 Value* tmpVal = getVal(yyvsp[-6].PHIList.P->front().first->getType(), yyvsp[-3].ValIDVal);
5932 yyvsp[-1].ValIDVal.S.makeSignless();
5933 BasicBlock* tmpBB = getBBVal(yyvsp[-1].ValIDVal);
5934 yyvsp[-6].PHIList.P->push_back(std::make_pair(tmpVal, tmpBB));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005935 ;}
5936 break;
5937
Reid Spencerd2920cd2007-03-21 17:27:53 +00005938 case 275:
David Greene5fd22a82007-09-04 18:46:50 +00005939#line 3462 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005940 { // Used for call statements, and memory insts...
David Greene5fd22a82007-09-04 18:46:50 +00005941 yyval.ValueList = new std::vector<ValueInfo>();
5942 yyval.ValueList->push_back(yyvsp[0].ValueVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005943 ;}
5944 break;
5945
Reid Spencerd2920cd2007-03-21 17:27:53 +00005946 case 276:
David Greene5fd22a82007-09-04 18:46:50 +00005947#line 3466 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005948 {
David Greene5fd22a82007-09-04 18:46:50 +00005949 yyval.ValueList = yyvsp[-2].ValueList;
5950 yyvsp[-2].ValueList->push_back(yyvsp[0].ValueVal);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005951 ;}
5952 break;
5953
Reid Spencerd2920cd2007-03-21 17:27:53 +00005954 case 278:
David Greene5fd22a82007-09-04 18:46:50 +00005955#line 3474 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
5956 { yyval.ValueList = 0; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005957 break;
5958
Reid Spencerd2920cd2007-03-21 17:27:53 +00005959 case 279:
David Greene5fd22a82007-09-04 18:46:50 +00005960#line 3478 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005961 {
David Greene5fd22a82007-09-04 18:46:50 +00005962 yyval.BoolVal = true;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005963 ;}
5964 break;
5965
Reid Spencerd2920cd2007-03-21 17:27:53 +00005966 case 280:
David Greene5fd22a82007-09-04 18:46:50 +00005967#line 3481 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005968 {
David Greene5fd22a82007-09-04 18:46:50 +00005969 yyval.BoolVal = false;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005970 ;}
5971 break;
5972
Reid Spencerd2920cd2007-03-21 17:27:53 +00005973 case 281:
David Greene5fd22a82007-09-04 18:46:50 +00005974#line 3487 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005975 {
David Greene5fd22a82007-09-04 18:46:50 +00005976 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
5977 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
5978 const Type* Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00005979 if (!Ty->isInteger() && !Ty->isFloatingPoint() && !isa<VectorType>(Ty))
Reid Spencer950bf602007-01-26 08:19:09 +00005980 error("Arithmetic operator requires integer, FP, or packed operands");
Reid Spencer9d6565a2007-02-15 02:26:10 +00005981 if (isa<VectorType>(Ty) &&
David Greene5fd22a82007-09-04 18:46:50 +00005982 (yyvsp[-4].BinaryOpVal == URemOp || yyvsp[-4].BinaryOpVal == SRemOp || yyvsp[-4].BinaryOpVal == FRemOp || yyvsp[-4].BinaryOpVal == RemOp))
Chris Lattner4227bdb2007-02-19 07:34:02 +00005983 error("Remainder not supported on vector types");
Reid Spencer950bf602007-01-26 08:19:09 +00005984 // Upgrade the opcode from obsolete versions before we do anything with it.
David Greene5fd22a82007-09-04 18:46:50 +00005985 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-4].BinaryOpVal, Ty, yyvsp[-3].TypeVal.S);
5986 Value* val1 = getVal(Ty, yyvsp[-2].ValIDVal);
5987 Value* val2 = getVal(Ty, yyvsp[0].ValIDVal);
5988 yyval.InstVal.I = BinaryOperator::create(Opcode, val1, val2);
5989 if (yyval.InstVal.I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00005990 error("binary operator returned null");
David Greene5fd22a82007-09-04 18:46:50 +00005991 yyval.InstVal.S.copy(yyvsp[-3].TypeVal.S);
5992 delete yyvsp[-3].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005993 ;}
5994 break;
5995
Reid Spencerd2920cd2007-03-21 17:27:53 +00005996 case 282:
David Greene5fd22a82007-09-04 18:46:50 +00005997#line 3506 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00005998 {
David Greene5fd22a82007-09-04 18:46:50 +00005999 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6000 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6001 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006002 if (!Ty->isInteger()) {
Reid Spencer9d6565a2007-02-15 02:26:10 +00006003 if (!isa<VectorType>(Ty) ||
6004 !cast<VectorType>(Ty)->getElementType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00006005 error("Logical operator requires integral operands");
6006 }
David Greene5fd22a82007-09-04 18:46:50 +00006007 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-4].BinaryOpVal, Ty, yyvsp[-3].TypeVal.S);
6008 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
6009 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
6010 yyval.InstVal.I = BinaryOperator::create(Opcode, tmpVal1, tmpVal2);
6011 if (yyval.InstVal.I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006012 error("binary operator returned null");
David Greene5fd22a82007-09-04 18:46:50 +00006013 yyval.InstVal.S.copy(yyvsp[-3].TypeVal.S);
6014 delete yyvsp[-3].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006015 ;}
6016 break;
6017
Reid Spencerd2920cd2007-03-21 17:27:53 +00006018 case 283:
David Greene5fd22a82007-09-04 18:46:50 +00006019#line 3524 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006020 {
David Greene5fd22a82007-09-04 18:46:50 +00006021 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6022 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6023 const Type* Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006024 if(isa<VectorType>(Ty))
6025 error("VectorTypes currently not supported in setcc instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00006026 unsigned short pred;
David Greene5fd22a82007-09-04 18:46:50 +00006027 Instruction::OtherOps Opcode = getCompareOp(yyvsp[-4].BinaryOpVal, pred, Ty, yyvsp[-3].TypeVal.S);
6028 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
6029 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
6030 yyval.InstVal.I = CmpInst::create(Opcode, pred, tmpVal1, tmpVal2);
6031 if (yyval.InstVal.I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006032 error("binary operator returned null");
David Greene5fd22a82007-09-04 18:46:50 +00006033 yyval.InstVal.S.makeUnsigned();
6034 delete yyvsp[-3].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006035 ;}
6036 break;
6037
Reid Spencerd2920cd2007-03-21 17:27:53 +00006038 case 284:
David Greene5fd22a82007-09-04 18:46:50 +00006039#line 3540 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006040 {
David Greene5fd22a82007-09-04 18:46:50 +00006041 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6042 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6043 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006044 if (isa<VectorType>(Ty))
6045 error("VectorTypes currently not supported in icmp instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00006046 else if (!Ty->isInteger() && !isa<PointerType>(Ty))
6047 error("icmp requires integer or pointer typed operands");
David Greene5fd22a82007-09-04 18:46:50 +00006048 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
6049 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
6050 yyval.InstVal.I = new ICmpInst(yyvsp[-4].IPred, tmpVal1, tmpVal2);
6051 yyval.InstVal.S.makeUnsigned();
6052 delete yyvsp[-3].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006053 ;}
6054 break;
6055
Reid Spencerd2920cd2007-03-21 17:27:53 +00006056 case 285:
David Greene5fd22a82007-09-04 18:46:50 +00006057#line 3554 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006058 {
David Greene5fd22a82007-09-04 18:46:50 +00006059 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6060 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
6061 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00006062 if (isa<VectorType>(Ty))
6063 error("VectorTypes currently not supported in fcmp instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00006064 else if (!Ty->isFloatingPoint())
6065 error("fcmp instruction requires floating point operands");
David Greene5fd22a82007-09-04 18:46:50 +00006066 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
6067 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
6068 yyval.InstVal.I = new FCmpInst(yyvsp[-4].FPred, tmpVal1, tmpVal2);
6069 yyval.InstVal.S.makeUnsigned();
6070 delete yyvsp[-3].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006071 ;}
6072 break;
6073
Reid Spencerd2920cd2007-03-21 17:27:53 +00006074 case 286:
David Greene5fd22a82007-09-04 18:46:50 +00006075#line 3568 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006076 {
Reid Spencer950bf602007-01-26 08:19:09 +00006077 warning("Use of obsolete 'not' instruction: Replacing with 'xor");
David Greene5fd22a82007-09-04 18:46:50 +00006078 const Type *Ty = yyvsp[0].ValueVal.V->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00006079 Value *Ones = ConstantInt::getAllOnesValue(Ty);
6080 if (Ones == 0)
6081 error("Expected integral type for not instruction");
David Greene5fd22a82007-09-04 18:46:50 +00006082 yyval.InstVal.I = BinaryOperator::create(Instruction::Xor, yyvsp[0].ValueVal.V, Ones);
6083 if (yyval.InstVal.I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00006084 error("Could not create a xor instruction");
David Greene5fd22a82007-09-04 18:46:50 +00006085 yyval.InstVal.S.copy(yyvsp[0].ValueVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006086 ;}
6087 break;
6088
Reid Spencerd2920cd2007-03-21 17:27:53 +00006089 case 287:
David Greene5fd22a82007-09-04 18:46:50 +00006090#line 3579 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006091 {
David Greene5fd22a82007-09-04 18:46:50 +00006092 if (!yyvsp[0].ValueVal.V->getType()->isInteger() ||
6093 cast<IntegerType>(yyvsp[0].ValueVal.V->getType())->getBitWidth() != 8)
Reid Spencer950bf602007-01-26 08:19:09 +00006094 error("Shift amount must be int8");
David Greene5fd22a82007-09-04 18:46:50 +00006095 const Type* Ty = yyvsp[-2].ValueVal.V->getType();
Reid Spencer832254e2007-02-02 02:16:23 +00006096 if (!Ty->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00006097 error("Shift constant expression requires integer operand");
Reid Spencer832254e2007-02-02 02:16:23 +00006098 Value* ShiftAmt = 0;
6099 if (cast<IntegerType>(Ty)->getBitWidth() > Type::Int8Ty->getBitWidth())
David Greene5fd22a82007-09-04 18:46:50 +00006100 if (Constant *C = dyn_cast<Constant>(yyvsp[0].ValueVal.V))
Reid Spencer832254e2007-02-02 02:16:23 +00006101 ShiftAmt = ConstantExpr::getZExt(C, Ty);
6102 else
David Greene5fd22a82007-09-04 18:46:50 +00006103 ShiftAmt = new ZExtInst(yyvsp[0].ValueVal.V, Ty, makeNameUnique("shift"), CurBB);
Reid Spencer832254e2007-02-02 02:16:23 +00006104 else
David Greene5fd22a82007-09-04 18:46:50 +00006105 ShiftAmt = yyvsp[0].ValueVal.V;
6106 yyval.InstVal.I = BinaryOperator::create(getBinaryOp(yyvsp[-3].BinaryOpVal, Ty, yyvsp[-2].ValueVal.S), yyvsp[-2].ValueVal.V, ShiftAmt);
6107 yyval.InstVal.S.copy(yyvsp[-2].ValueVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006108 ;}
6109 break;
6110
Reid Spencerd2920cd2007-03-21 17:27:53 +00006111 case 288:
David Greene5fd22a82007-09-04 18:46:50 +00006112#line 3597 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006113 {
David Greene5fd22a82007-09-04 18:46:50 +00006114 const Type *DstTy = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006115 if (!DstTy->isFirstClassType())
6116 error("cast instruction to a non-primitive type: '" +
6117 DstTy->getDescription() + "'");
David Greene5fd22a82007-09-04 18:46:50 +00006118 yyval.InstVal.I = cast<Instruction>(getCast(yyvsp[-3].CastOpVal, yyvsp[-2].ValueVal.V, yyvsp[-2].ValueVal.S, DstTy, yyvsp[0].TypeVal.S, true));
6119 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
6120 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006121 ;}
6122 break;
6123
Reid Spencerd2920cd2007-03-21 17:27:53 +00006124 case 289:
David Greene5fd22a82007-09-04 18:46:50 +00006125#line 3606 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006126 {
David Greene5fd22a82007-09-04 18:46:50 +00006127 if (!yyvsp[-4].ValueVal.V->getType()->isInteger() ||
6128 cast<IntegerType>(yyvsp[-4].ValueVal.V->getType())->getBitWidth() != 1)
Reid Spencer950bf602007-01-26 08:19:09 +00006129 error("select condition must be bool");
David Greene5fd22a82007-09-04 18:46:50 +00006130 if (yyvsp[-2].ValueVal.V->getType() != yyvsp[0].ValueVal.V->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00006131 error("select value types should match");
David Greene5fd22a82007-09-04 18:46:50 +00006132 yyval.InstVal.I = new SelectInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
6133 yyval.InstVal.S.copy(yyvsp[-2].ValueVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006134 ;}
6135 break;
6136
Reid Spencerd2920cd2007-03-21 17:27:53 +00006137 case 290:
David Greene5fd22a82007-09-04 18:46:50 +00006138#line 3615 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006139 {
David Greene5fd22a82007-09-04 18:46:50 +00006140 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006141 NewVarArgs = true;
David Greene5fd22a82007-09-04 18:46:50 +00006142 yyval.InstVal.I = new VAArgInst(yyvsp[-2].ValueVal.V, Ty);
6143 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
6144 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006145 ;}
6146 break;
6147
Reid Spencerd2920cd2007-03-21 17:27:53 +00006148 case 291:
David Greene5fd22a82007-09-04 18:46:50 +00006149#line 3622 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006150 {
David Greene5fd22a82007-09-04 18:46:50 +00006151 const Type* ArgTy = yyvsp[-2].ValueVal.V->getType();
6152 const Type* DstTy = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006153 ObsoleteVarArgs = true;
6154 Function* NF = cast<Function>(CurModule.CurrentModule->
6155 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
6156
6157 //b = vaarg a, t ->
6158 //foo = alloca 1 of t
6159 //bar = vacopy a
6160 //store bar -> foo
6161 //b = vaarg foo, t
6162 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vaarg.fix");
6163 CurBB->getInstList().push_back(foo);
David Greene5fd22a82007-09-04 18:46:50 +00006164 CallInst* bar = new CallInst(NF, yyvsp[-2].ValueVal.V);
Reid Spencer950bf602007-01-26 08:19:09 +00006165 CurBB->getInstList().push_back(bar);
6166 CurBB->getInstList().push_back(new StoreInst(bar, foo));
David Greene5fd22a82007-09-04 18:46:50 +00006167 yyval.InstVal.I = new VAArgInst(foo, DstTy);
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 292:
David Greene5fd22a82007-09-04 18:46:50 +00006174#line 3643 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006175 {
David Greene5fd22a82007-09-04 18:46:50 +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 = vanext a, t ->
6183 //foo = alloca 1 of t
6184 //bar = vacopy a
6185 //store bar -> foo
6186 //tmp = vaarg foo, t
6187 //b = load foo
6188 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vanext.fix");
6189 CurBB->getInstList().push_back(foo);
David Greene5fd22a82007-09-04 18:46:50 +00006190 CallInst* bar = new CallInst(NF, yyvsp[-2].ValueVal.V);
Reid Spencer950bf602007-01-26 08:19:09 +00006191 CurBB->getInstList().push_back(bar);
6192 CurBB->getInstList().push_back(new StoreInst(bar, foo));
6193 Instruction* tmp = new VAArgInst(foo, DstTy);
6194 CurBB->getInstList().push_back(tmp);
David Greene5fd22a82007-09-04 18:46:50 +00006195 yyval.InstVal.I = new LoadInst(foo);
6196 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
6197 delete yyvsp[0].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006198 ;}
6199 break;
6200
Reid Spencerd2920cd2007-03-21 17:27:53 +00006201 case 293:
David Greene5fd22a82007-09-04 18:46:50 +00006202#line 3667 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006203 {
David Greene5fd22a82007-09-04 18:46:50 +00006204 if (!ExtractElementInst::isValidOperands(yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Reid Spencer950bf602007-01-26 08:19:09 +00006205 error("Invalid extractelement operands");
David Greene5fd22a82007-09-04 18:46:50 +00006206 yyval.InstVal.I = new ExtractElementInst(yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
6207 yyval.InstVal.S.copy(yyvsp[-2].ValueVal.S.get(0));
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006208 ;}
6209 break;
6210
Reid Spencerd2920cd2007-03-21 17:27:53 +00006211 case 294:
David Greene5fd22a82007-09-04 18:46:50 +00006212#line 3673 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006213 {
David Greene5fd22a82007-09-04 18:46:50 +00006214 if (!InsertElementInst::isValidOperands(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Reid Spencer950bf602007-01-26 08:19:09 +00006215 error("Invalid insertelement operands");
David Greene5fd22a82007-09-04 18:46:50 +00006216 yyval.InstVal.I = new InsertElementInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
6217 yyval.InstVal.S.copy(yyvsp[-4].ValueVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006218 ;}
6219 break;
6220
Reid Spencerd2920cd2007-03-21 17:27:53 +00006221 case 295:
David Greene5fd22a82007-09-04 18:46:50 +00006222#line 3679 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006223 {
David Greene5fd22a82007-09-04 18:46:50 +00006224 if (!ShuffleVectorInst::isValidOperands(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Reid Spencer950bf602007-01-26 08:19:09 +00006225 error("Invalid shufflevector operands");
David Greene5fd22a82007-09-04 18:46:50 +00006226 yyval.InstVal.I = new ShuffleVectorInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
6227 yyval.InstVal.S.copy(yyvsp[-4].ValueVal.S);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006228 ;}
6229 break;
6230
Reid Spencerd2920cd2007-03-21 17:27:53 +00006231 case 296:
David Greene5fd22a82007-09-04 18:46:50 +00006232#line 3685 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006233 {
David Greene5fd22a82007-09-04 18:46:50 +00006234 const Type *Ty = yyvsp[0].PHIList.P->front().first->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00006235 if (!Ty->isFirstClassType())
6236 error("PHI node operands must be of first class type");
6237 PHINode *PHI = new PHINode(Ty);
David Greene5fd22a82007-09-04 18:46:50 +00006238 PHI->reserveOperandSpace(yyvsp[0].PHIList.P->size());
6239 while (yyvsp[0].PHIList.P->begin() != yyvsp[0].PHIList.P->end()) {
6240 if (yyvsp[0].PHIList.P->front().first->getType() != Ty)
Reid Spencer950bf602007-01-26 08:19:09 +00006241 error("All elements of a PHI node must be of the same type");
David Greene5fd22a82007-09-04 18:46:50 +00006242 PHI->addIncoming(yyvsp[0].PHIList.P->front().first, yyvsp[0].PHIList.P->front().second);
6243 yyvsp[0].PHIList.P->pop_front();
Reid Spencer950bf602007-01-26 08:19:09 +00006244 }
David Greene5fd22a82007-09-04 18:46:50 +00006245 yyval.InstVal.I = PHI;
6246 yyval.InstVal.S.copy(yyvsp[0].PHIList.S);
6247 delete yyvsp[0].PHIList.P; // Free the list...
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006248 ;}
6249 break;
Reid Spencer950bf602007-01-26 08:19:09 +00006250
Reid Spencerd2920cd2007-03-21 17:27:53 +00006251 case 297:
David Greene5fd22a82007-09-04 18:46:50 +00006252#line 3701 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006253 {
Reid Spencer950bf602007-01-26 08:19:09 +00006254 // Handle the short call syntax
6255 const PointerType *PFTy;
6256 const FunctionType *FTy;
Reid Spencerbb1fd572007-03-21 17:15:50 +00006257 Signedness FTySign;
David Greene5fd22a82007-09-04 18:46:50 +00006258 if (!(PFTy = dyn_cast<PointerType>(yyvsp[-4].TypeVal.PAT->get())) ||
Reid Spencer950bf602007-01-26 08:19:09 +00006259 !(FTy = dyn_cast<FunctionType>(PFTy->getElementType()))) {
6260 // Pull out the types of all of the arguments...
6261 std::vector<const Type*> ParamTypes;
David Greene5fd22a82007-09-04 18:46:50 +00006262 FTySign.makeComposite(yyvsp[-4].TypeVal.S);
6263 if (yyvsp[-1].ValueList) {
6264 for (std::vector<ValueInfo>::iterator I = yyvsp[-1].ValueList->begin(), E = yyvsp[-1].ValueList->end();
Reid Spencerbb1fd572007-03-21 17:15:50 +00006265 I != E; ++I) {
Reid Spencer950bf602007-01-26 08:19:09 +00006266 ParamTypes.push_back((*I).V->getType());
Reid Spencerbb1fd572007-03-21 17:15:50 +00006267 FTySign.add(I->S);
6268 }
Reid Spencer950bf602007-01-26 08:19:09 +00006269 }
6270
6271 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
6272 if (isVarArg) ParamTypes.pop_back();
6273
David Greene5fd22a82007-09-04 18:46:50 +00006274 const Type *RetTy = yyvsp[-4].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006275 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
6276 error("Functions cannot return aggregate types");
6277
Reid Spencer7b5d4662007-04-09 06:16:21 +00006278 // Deal with CSRetCC
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006279 ParamAttrsList *PAL = 0;
David Greene5fd22a82007-09-04 18:46:50 +00006280 if (yyvsp[-5].UIntVal == OldCallingConv::CSRet) {
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006281 ParamAttrsVector Attrs;
6282 ParamAttrsWithIndex PAWI;
6283 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
6284 Attrs.push_back(PAWI);
6285 PAL = ParamAttrsList::get(Attrs);
Reid Spencer7b5d4662007-04-09 06:16:21 +00006286 }
6287
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006288 FTy = FunctionType::get(RetTy, ParamTypes, isVarArg, PAL);
Reid Spencer950bf602007-01-26 08:19:09 +00006289 PFTy = PointerType::get(FTy);
David Greene5fd22a82007-09-04 18:46:50 +00006290 yyval.InstVal.S.copy(yyvsp[-4].TypeVal.S);
Reid Spencerbb1fd572007-03-21 17:15:50 +00006291 } else {
David Greene5fd22a82007-09-04 18:46:50 +00006292 FTySign = yyvsp[-4].TypeVal.S;
Reid Spencera3b12dd2007-04-07 16:14:01 +00006293 // Get the signedness of the result type. $3 is the pointer to the
6294 // function type so we get the 0th element to extract the function type,
6295 // and then the 0th element again to get the result type.
David Greene5fd22a82007-09-04 18:46:50 +00006296 yyval.InstVal.S.copy(yyvsp[-4].TypeVal.S.get(0).get(0));
Reid Spencer950bf602007-01-26 08:19:09 +00006297 }
David Greene5fd22a82007-09-04 18:46:50 +00006298 yyvsp[-3].ValIDVal.S.makeComposite(FTySign);
Reid Spencer950bf602007-01-26 08:19:09 +00006299
6300 // First upgrade any intrinsic calls.
6301 std::vector<Value*> Args;
David Greene5fd22a82007-09-04 18:46:50 +00006302 if (yyvsp[-1].ValueList)
6303 for (unsigned i = 0, e = yyvsp[-1].ValueList->size(); i < e; ++i)
6304 Args.push_back((*yyvsp[-1].ValueList)[i].V);
6305 Instruction *Inst = upgradeIntrinsicCall(FTy->getReturnType(), yyvsp[-3].ValIDVal, Args);
Reid Spencer950bf602007-01-26 08:19:09 +00006306
6307 // If we got an upgraded intrinsic
6308 if (Inst) {
David Greene5fd22a82007-09-04 18:46:50 +00006309 yyval.InstVal.I = Inst;
Reid Spencer950bf602007-01-26 08:19:09 +00006310 } else {
6311 // Get the function we're calling
David Greene5fd22a82007-09-04 18:46:50 +00006312 Value *V = getVal(PFTy, yyvsp[-3].ValIDVal);
Reid Spencer950bf602007-01-26 08:19:09 +00006313
6314 // Check the argument values match
David Greene5fd22a82007-09-04 18:46:50 +00006315 if (!yyvsp[-1].ValueList) { // Has no arguments?
Reid Spencer950bf602007-01-26 08:19:09 +00006316 // Make sure no arguments is a good thing!
6317 if (FTy->getNumParams() != 0)
6318 error("No arguments passed to a function that expects arguments");
6319 } else { // Has arguments?
6320 // Loop through FunctionType's arguments and ensure they are specified
6321 // correctly!
6322 //
6323 FunctionType::param_iterator I = FTy->param_begin();
6324 FunctionType::param_iterator E = FTy->param_end();
David Greene5fd22a82007-09-04 18:46:50 +00006325 std::vector<ValueInfo>::iterator ArgI = yyvsp[-1].ValueList->begin(), ArgE = yyvsp[-1].ValueList->end();
Reid Spencer950bf602007-01-26 08:19:09 +00006326
6327 for (; ArgI != ArgE && I != E; ++ArgI, ++I)
6328 if ((*ArgI).V->getType() != *I)
6329 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
6330 (*I)->getDescription() + "'");
6331
6332 if (I != E || (ArgI != ArgE && !FTy->isVarArg()))
6333 error("Invalid number of parameters detected");
6334 }
6335
6336 // Create the call instruction
David Greene718fda32007-08-01 03:59:32 +00006337 CallInst *CI = new CallInst(V, Args.begin(), Args.end());
David Greene5fd22a82007-09-04 18:46:50 +00006338 CI->setTailCall(yyvsp[-6].BoolVal);
6339 CI->setCallingConv(upgradeCallingConv(yyvsp[-5].UIntVal));
6340 yyval.InstVal.I = CI;
Reid Spencer950bf602007-01-26 08:19:09 +00006341 }
David Greene5fd22a82007-09-04 18:46:50 +00006342 delete yyvsp[-4].TypeVal.PAT;
6343 delete yyvsp[-1].ValueList;
Reid Spencer7eea8ff2007-05-18 05:48:07 +00006344 lastCallingConv = OldCallingConv::C;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006345 ;}
6346 break;
6347
Reid Spencerd2920cd2007-03-21 17:27:53 +00006348 case 298:
David Greene5fd22a82007-09-04 18:46:50 +00006349#line 3794 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006350 {
David Greene5fd22a82007-09-04 18:46:50 +00006351 yyval.InstVal = yyvsp[0].InstVal;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006352 ;}
6353 break;
6354
Reid Spencerd2920cd2007-03-21 17:27:53 +00006355 case 299:
David Greene5fd22a82007-09-04 18:46:50 +00006356#line 3802 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
6357 { yyval.ValueList = yyvsp[0].ValueList; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006358 break;
6359
Reid Spencerd2920cd2007-03-21 17:27:53 +00006360 case 300:
David Greene5fd22a82007-09-04 18:46:50 +00006361#line 3803 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
6362 { yyval.ValueList = new std::vector<ValueInfo>(); ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006363 break;
6364
Reid Spencerd2920cd2007-03-21 17:27:53 +00006365 case 301:
David Greene5fd22a82007-09-04 18:46:50 +00006366#line 3807 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
6367 { yyval.BoolVal = true; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006368 break;
6369
Reid Spencerd2920cd2007-03-21 17:27:53 +00006370 case 302:
David Greene5fd22a82007-09-04 18:46:50 +00006371#line 3808 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
6372 { yyval.BoolVal = false; ;}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006373 break;
6374
Reid Spencerd2920cd2007-03-21 17:27:53 +00006375 case 303:
David Greene5fd22a82007-09-04 18:46:50 +00006376#line 3812 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006377 {
David Greene5fd22a82007-09-04 18:46:50 +00006378 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
6379 yyval.InstVal.S.makeComposite(yyvsp[-1].TypeVal.S);
6380 yyval.InstVal.I = new MallocInst(Ty, 0, yyvsp[0].UIntVal);
6381 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006382 ;}
6383 break;
6384
Reid Spencerd2920cd2007-03-21 17:27:53 +00006385 case 304:
David Greene5fd22a82007-09-04 18:46:50 +00006386#line 3818 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006387 {
David Greene5fd22a82007-09-04 18:46:50 +00006388 const Type *Ty = yyvsp[-4].TypeVal.PAT->get();
6389 yyvsp[-1].ValIDVal.S.makeUnsigned();
6390 yyval.InstVal.S.makeComposite(yyvsp[-4].TypeVal.S);
6391 yyval.InstVal.I = new MallocInst(Ty, getVal(yyvsp[-2].PrimType.T, yyvsp[-1].ValIDVal), yyvsp[0].UIntVal);
6392 delete yyvsp[-4].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006393 ;}
6394 break;
6395
Reid Spencerd2920cd2007-03-21 17:27:53 +00006396 case 305:
David Greene5fd22a82007-09-04 18:46:50 +00006397#line 3825 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006398 {
David Greene5fd22a82007-09-04 18:46:50 +00006399 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
6400 yyval.InstVal.S.makeComposite(yyvsp[-1].TypeVal.S);
6401 yyval.InstVal.I = new AllocaInst(Ty, 0, yyvsp[0].UIntVal);
6402 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006403 ;}
6404 break;
6405
Reid Spencerd2920cd2007-03-21 17:27:53 +00006406 case 306:
David Greene5fd22a82007-09-04 18:46:50 +00006407#line 3831 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006408 {
David Greene5fd22a82007-09-04 18:46:50 +00006409 const Type *Ty = yyvsp[-4].TypeVal.PAT->get();
6410 yyvsp[-1].ValIDVal.S.makeUnsigned();
6411 yyval.InstVal.S.makeComposite(yyvsp[-2].PrimType.S);
6412 yyval.InstVal.I = new AllocaInst(Ty, getVal(yyvsp[-2].PrimType.T, yyvsp[-1].ValIDVal), yyvsp[0].UIntVal);
6413 delete yyvsp[-4].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006414 ;}
6415 break;
6416
Reid Spencerd2920cd2007-03-21 17:27:53 +00006417 case 307:
David Greene5fd22a82007-09-04 18:46:50 +00006418#line 3838 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006419 {
David Greene5fd22a82007-09-04 18:46:50 +00006420 const Type *PTy = yyvsp[0].ValueVal.V->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00006421 if (!isa<PointerType>(PTy))
6422 error("Trying to free nonpointer type '" + PTy->getDescription() + "'");
David Greene5fd22a82007-09-04 18:46:50 +00006423 yyval.InstVal.I = new FreeInst(yyvsp[0].ValueVal.V);
6424 yyval.InstVal.S.makeSignless();
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006425 ;}
6426 break;
6427
Reid Spencerd2920cd2007-03-21 17:27:53 +00006428 case 308:
David Greene5fd22a82007-09-04 18:46:50 +00006429#line 3845 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006430 {
David Greene5fd22a82007-09-04 18:46:50 +00006431 const Type* Ty = yyvsp[-1].TypeVal.PAT->get();
6432 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
Reid Spencer950bf602007-01-26 08:19:09 +00006433 if (!isa<PointerType>(Ty))
6434 error("Can't load from nonpointer type: " + Ty->getDescription());
6435 if (!cast<PointerType>(Ty)->getElementType()->isFirstClassType())
6436 error("Can't load from pointer of non-first-class type: " +
6437 Ty->getDescription());
David Greene5fd22a82007-09-04 18:46:50 +00006438 Value* tmpVal = getVal(Ty, yyvsp[0].ValIDVal);
6439 yyval.InstVal.I = new LoadInst(tmpVal, "", yyvsp[-3].BoolVal);
6440 yyval.InstVal.S.copy(yyvsp[-1].TypeVal.S.get(0));
6441 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006442 ;}
6443 break;
6444
Reid Spencerd2920cd2007-03-21 17:27:53 +00006445 case 309:
David Greene5fd22a82007-09-04 18:46:50 +00006446#line 3858 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006447 {
David Greene5fd22a82007-09-04 18:46:50 +00006448 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
6449 const PointerType *PTy = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Reid Spencered96d1e2007-02-08 09:08:52 +00006450 if (!PTy)
6451 error("Can't store to a nonpointer type: " +
David Greene5fd22a82007-09-04 18:46:50 +00006452 yyvsp[-1].TypeVal.PAT->get()->getDescription());
Reid Spencered96d1e2007-02-08 09:08:52 +00006453 const Type *ElTy = PTy->getElementType();
David Greene5fd22a82007-09-04 18:46:50 +00006454 Value *StoreVal = yyvsp[-3].ValueVal.V;
6455 Value* tmpVal = getVal(PTy, yyvsp[0].ValIDVal);
6456 if (ElTy != yyvsp[-3].ValueVal.V->getType()) {
6457 StoreVal = handleSRetFuncTypeMerge(yyvsp[-3].ValueVal.V, ElTy);
Reid Spencered96d1e2007-02-08 09:08:52 +00006458 if (!StoreVal)
David Greene5fd22a82007-09-04 18:46:50 +00006459 error("Can't store '" + yyvsp[-3].ValueVal.V->getType()->getDescription() +
Reid Spencered96d1e2007-02-08 09:08:52 +00006460 "' into space of type '" + ElTy->getDescription() + "'");
6461 else {
6462 PTy = PointerType::get(StoreVal->getType());
6463 if (Constant *C = dyn_cast<Constant>(tmpVal))
6464 tmpVal = ConstantExpr::getBitCast(C, PTy);
6465 else
6466 tmpVal = new BitCastInst(tmpVal, PTy, "upgrd.cast", CurBB);
6467 }
6468 }
David Greene5fd22a82007-09-04 18:46:50 +00006469 yyval.InstVal.I = new StoreInst(StoreVal, tmpVal, yyvsp[-5].BoolVal);
6470 yyval.InstVal.S.makeSignless();
6471 delete yyvsp[-1].TypeVal.PAT;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006472 ;}
6473 break;
6474
Reid Spencerd2920cd2007-03-21 17:27:53 +00006475 case 310:
David Greene5fd22a82007-09-04 18:46:50 +00006476#line 3884 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006477 {
David Greene5fd22a82007-09-04 18:46:50 +00006478 yyvsp[-1].ValIDVal.S.copy(yyvsp[-2].TypeVal.S);
6479 const Type* Ty = yyvsp[-2].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00006480 if (!isa<PointerType>(Ty))
6481 error("getelementptr insn requires pointer operand");
6482
6483 std::vector<Value*> VIndices;
David Greene5fd22a82007-09-04 18:46:50 +00006484 upgradeGEPInstIndices(Ty, yyvsp[0].ValueList, VIndices);
Reid Spencer950bf602007-01-26 08:19:09 +00006485
David Greene5fd22a82007-09-04 18:46:50 +00006486 Value* tmpVal = getVal(Ty, yyvsp[-1].ValIDVal);
6487 yyval.InstVal.I = new GetElementPtrInst(tmpVal, VIndices.begin(), VIndices.end());
6488 ValueInfo VI; VI.V = tmpVal; VI.S.copy(yyvsp[-2].TypeVal.S);
6489 yyval.InstVal.S.copy(getElementSign(VI, VIndices));
6490 delete yyvsp[-2].TypeVal.PAT;
6491 delete yyvsp[0].ValueList;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006492 ;}
6493 break;
6494
6495
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006496 }
6497
David Greene5fd22a82007-09-04 18:46:50 +00006498/* Line 993 of yacc.c. */
6499#line 6500 "UpgradeParser.tab.c"
6500
6501 yyvsp -= yylen;
6502 yyssp -= yylen;
6503
6504
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006505 YY_STACK_PRINT (yyss, yyssp);
Reid Spencere7c3c602006-11-30 06:36:44 +00006506
6507 *++yyvsp = yyval;
6508
6509
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006510 /* Now `shift' the result of the reduction. Determine what state
6511 that goes to, based on the state we popped back to and the rule
6512 number reduced by. */
Reid Spencere7c3c602006-11-30 06:36:44 +00006513
6514 yyn = yyr1[yyn];
6515
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006516 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
6517 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
Reid Spencere7c3c602006-11-30 06:36:44 +00006518 yystate = yytable[yystate];
6519 else
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006520 yystate = yydefgoto[yyn - YYNTOKENS];
Reid Spencere7c3c602006-11-30 06:36:44 +00006521
6522 goto yynewstate;
6523
6524
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006525/*------------------------------------.
6526| yyerrlab -- here on detecting error |
6527`------------------------------------*/
6528yyerrlab:
6529 /* If not already recovering from an error, report this error. */
6530 if (!yyerrstatus)
Reid Spencere7c3c602006-11-30 06:36:44 +00006531 {
6532 ++yynerrs;
David Greene5fd22a82007-09-04 18:46:50 +00006533#if YYERROR_VERBOSE
6534 yyn = yypact[yystate];
Chandler Carruth02202192007-08-04 01:56:21 +00006535
David Greene5fd22a82007-09-04 18:46:50 +00006536 if (YYPACT_NINF < yyn && yyn < YYLAST)
6537 {
6538 YYSIZE_T yysize = 0;
6539 int yytype = YYTRANSLATE (yychar);
6540 const char* yyprefix;
6541 char *yymsg;
6542 int yyx;
6543
6544 /* Start YYX at -YYN if negative to avoid negative indexes in
6545 YYCHECK. */
6546 int yyxbegin = yyn < 0 ? -yyn : 0;
6547
6548 /* Stay within bounds of both yycheck and yytname. */
6549 int yychecklim = YYLAST - yyn;
6550 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
6551 int yycount = 0;
6552
6553 yyprefix = ", expecting ";
6554 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
6555 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
6556 {
6557 yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]);
6558 yycount += 1;
6559 if (yycount == 5)
6560 {
6561 yysize = 0;
6562 break;
6563 }
6564 }
6565 yysize += (sizeof ("syntax error, unexpected ")
6566 + yystrlen (yytname[yytype]));
6567 yymsg = (char *) YYSTACK_ALLOC (yysize);
6568 if (yymsg != 0)
6569 {
6570 char *yyp = yystpcpy (yymsg, "syntax error, unexpected ");
6571 yyp = yystpcpy (yyp, yytname[yytype]);
6572
6573 if (yycount < 5)
6574 {
6575 yyprefix = ", expecting ";
6576 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
6577 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
6578 {
6579 yyp = yystpcpy (yyp, yyprefix);
6580 yyp = yystpcpy (yyp, yytname[yyx]);
6581 yyprefix = " or ";
6582 }
6583 }
6584 yyerror (yymsg);
6585 YYSTACK_FREE (yymsg);
6586 }
6587 else
6588 yyerror ("syntax error; also virtual memory exhausted");
6589 }
6590 else
6591#endif /* YYERROR_VERBOSE */
6592 yyerror ("syntax error");
Reid Spencere7c3c602006-11-30 06:36:44 +00006593 }
Reid Spencer950bf602007-01-26 08:19:09 +00006594
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006595
Reid Spencer950bf602007-01-26 08:19:09 +00006596
6597 if (yyerrstatus == 3)
6598 {
David Greene5fd22a82007-09-04 18:46:50 +00006599 /* If just tried and failed to reuse lookahead token after an
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006600 error, discard it. */
Reid Spencer950bf602007-01-26 08:19:09 +00006601
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006602 if (yychar <= YYEOF)
David Greene5fd22a82007-09-04 18:46:50 +00006603 {
6604 /* If at end of input, pop the error token,
6605 then the rest of the stack, then return failure. */
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006606 if (yychar == YYEOF)
David Greene5fd22a82007-09-04 18:46:50 +00006607 for (;;)
6608 {
6609 YYPOPSTACK;
6610 if (yyssp == yyss)
6611 YYABORT;
6612 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
6613 yydestruct (yystos[*yyssp], yyvsp);
6614 }
6615 }
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006616 else
6617 {
David Greene5fd22a82007-09-04 18:46:50 +00006618 YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc);
6619 yydestruct (yytoken, &yylval);
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006620 yychar = YYEMPTY;
David Greene5fd22a82007-09-04 18:46:50 +00006621
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006622 }
6623 }
6624
David Greene5fd22a82007-09-04 18:46:50 +00006625 /* Else will try to reuse lookahead token after shifting the error
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006626 token. */
6627 goto yyerrlab1;
6628
6629
6630/*---------------------------------------------------.
6631| yyerrorlab -- error raised explicitly by YYERROR. |
6632`---------------------------------------------------*/
6633yyerrorlab:
6634
David Greene5fd22a82007-09-04 18:46:50 +00006635#ifdef __GNUC__
6636 /* Pacify GCC when the user code never invokes YYERROR and the label
6637 yyerrorlab therefore never appears in user code. */
6638 if (0)
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006639 goto yyerrorlab;
David Greene5fd22a82007-09-04 18:46:50 +00006640#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006641
David Greene5fd22a82007-09-04 18:46:50 +00006642 yyvsp -= yylen;
6643 yyssp -= yylen;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006644 yystate = *yyssp;
6645 goto yyerrlab1;
6646
6647
6648/*-------------------------------------------------------------.
6649| yyerrlab1 -- common code for both syntax error and YYERROR. |
6650`-------------------------------------------------------------*/
6651yyerrlab1:
6652 yyerrstatus = 3; /* Each real token shifted decrements this. */
6653
6654 for (;;)
6655 {
6656 yyn = yypact[yystate];
6657 if (yyn != YYPACT_NINF)
6658 {
6659 yyn += YYTERROR;
6660 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
6661 {
6662 yyn = yytable[yyn];
6663 if (0 < yyn)
6664 break;
6665 }
6666 }
6667
6668 /* Pop the current state because it cannot handle the error token. */
6669 if (yyssp == yyss)
Reid Spencere7c3c602006-11-30 06:36:44 +00006670 YYABORT;
6671
David Greene5fd22a82007-09-04 18:46:50 +00006672 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
6673 yydestruct (yystos[yystate], yyvsp);
6674 YYPOPSTACK;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006675 yystate = *yyssp;
6676 YY_STACK_PRINT (yyss, yyssp);
Reid Spencere7c3c602006-11-30 06:36:44 +00006677 }
6678
6679 if (yyn == YYFINAL)
6680 YYACCEPT;
6681
David Greene5fd22a82007-09-04 18:46:50 +00006682 YYDPRINTF ((stderr, "Shifting error token, "));
6683
Reid Spencere7c3c602006-11-30 06:36:44 +00006684 *++yyvsp = yylval;
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006685
6686
Reid Spencere7c3c602006-11-30 06:36:44 +00006687 yystate = yyn;
6688 goto yynewstate;
6689
Chris Lattner4227bdb2007-02-19 07:34:02 +00006690
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006691/*-------------------------------------.
6692| yyacceptlab -- YYACCEPT comes here. |
6693`-------------------------------------*/
6694yyacceptlab:
6695 yyresult = 0;
6696 goto yyreturn;
6697
6698/*-----------------------------------.
6699| yyabortlab -- YYABORT comes here. |
6700`-----------------------------------*/
6701yyabortlab:
6702 yyresult = 1;
6703 goto yyreturn;
6704
6705#ifndef yyoverflow
David Greene5fd22a82007-09-04 18:46:50 +00006706/*----------------------------------------------.
6707| yyoverflowlab -- parser overflow comes here. |
6708`----------------------------------------------*/
6709yyoverflowlab:
6710 yyerror ("parser stack overflow");
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006711 yyresult = 2;
6712 /* Fall through. */
Chris Lattner4227bdb2007-02-19 07:34:02 +00006713#endif
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006714
6715yyreturn:
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006716#ifndef yyoverflow
6717 if (yyss != yyssa)
6718 YYSTACK_FREE (yyss);
6719#endif
David Greene5fd22a82007-09-04 18:46:50 +00006720 return yyresult;
Reid Spencere7c3c602006-11-30 06:36:44 +00006721}
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006722
6723
David Greene5fd22a82007-09-04 18:46:50 +00006724#line 3902 "/users/dag/projects/cascade/llvm.modified/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencere7c3c602006-11-30 06:36:44 +00006725
6726
6727int yyerror(const char *ErrorMsg) {
6728 std::string where
6729 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
Reid Spencered96d1e2007-02-08 09:08:52 +00006730 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
Reid Spencer950bf602007-01-26 08:19:09 +00006731 std::string errMsg = where + "error: " + std::string(ErrorMsg);
6732 if (yychar != YYEMPTY && yychar != 0)
6733 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
6734 "'.";
Reid Spencer71d2ec92006-12-31 06:02:26 +00006735 std::cerr << "llvm-upgrade: " << errMsg << '\n';
Reid Spencer950bf602007-01-26 08:19:09 +00006736 std::cout << "llvm-upgrade: parse failed.\n";
Reid Spencere7c3c602006-11-30 06:36:44 +00006737 exit(1);
6738}
Reid Spencer319a7302007-01-05 17:20:02 +00006739
Reid Spencer30d0c582007-01-15 00:26:18 +00006740void warning(const std::string& ErrorMsg) {
Reid Spencer319a7302007-01-05 17:20:02 +00006741 std::string where
6742 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
Reid Spencered96d1e2007-02-08 09:08:52 +00006743 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
Reid Spencer950bf602007-01-26 08:19:09 +00006744 std::string errMsg = where + "warning: " + std::string(ErrorMsg);
6745 if (yychar != YYEMPTY && yychar != 0)
6746 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
6747 "'.";
Reid Spencer319a7302007-01-05 17:20:02 +00006748 std::cerr << "llvm-upgrade: " << errMsg << '\n';
6749}
6750
Reid Spencer950bf602007-01-26 08:19:09 +00006751void error(const std::string& ErrorMsg, int LineNo) {
6752 if (LineNo == -1) LineNo = Upgradelineno;
6753 Upgradelineno = LineNo;
6754 yyerror(ErrorMsg.c_str());
6755}
6756
Reid Spencer3fae7ba2007-03-14 23:13:06 +00006757