blob: c30f1c3943523216d26f84c56f535991e3b408f1 [file] [log] [blame]
Reid Spencere7c3c602006-11-30 06:36:44 +00001
Chris Lattner4227bdb2007-02-19 07:34:02 +00002/* A Bison parser, made from /Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y
3 by GNU Bison version 1.28 */
Reid Spencere7c3c602006-11-30 06:36:44 +00004
Chris Lattner4227bdb2007-02-19 07:34:02 +00005#define YYBISON 1 /* Identify Bison output. */
Reid Spencere7c3c602006-11-30 06:36:44 +00006
Reid Spencere7c3c602006-11-30 06:36:44 +00007#define yyparse Upgradeparse
Chris Lattner4227bdb2007-02-19 07:34:02 +00008#define yylex Upgradelex
Reid Spencere7c3c602006-11-30 06:36:44 +00009#define yyerror Upgradeerror
Chris Lattner4227bdb2007-02-19 07:34:02 +000010#define yylval Upgradelval
11#define yychar Upgradechar
Reid Spencere7c3c602006-11-30 06:36:44 +000012#define yydebug Upgradedebug
13#define yynerrs Upgradenerrs
Chris Lattner4227bdb2007-02-19 07:34:02 +000014#define ESINT64VAL 257
15#define EUINT64VAL 258
16#define SINTVAL 259
17#define UINTVAL 260
18#define FPVAL 261
19#define VOID 262
20#define BOOL 263
21#define SBYTE 264
22#define UBYTE 265
23#define SHORT 266
24#define USHORT 267
25#define INT 268
26#define UINT 269
27#define LONG 270
28#define ULONG 271
29#define FLOAT 272
30#define DOUBLE 273
31#define TYPE 274
32#define LABEL 275
33#define VAR_ID 276
34#define LABELSTR 277
35#define STRINGCONSTANT 278
36#define IMPLEMENTATION 279
37#define ZEROINITIALIZER 280
38#define TRUETOK 281
39#define FALSETOK 282
40#define BEGINTOK 283
41#define ENDTOK 284
42#define DECLARE 285
43#define GLOBAL 286
44#define CONSTANT 287
45#define SECTION 288
46#define VOLATILE 289
47#define TO 290
48#define DOTDOTDOT 291
49#define NULL_TOK 292
50#define UNDEF 293
51#define CONST 294
52#define INTERNAL 295
53#define LINKONCE 296
54#define WEAK 297
55#define APPENDING 298
56#define DLLIMPORT 299
57#define DLLEXPORT 300
58#define EXTERN_WEAK 301
59#define OPAQUE 302
60#define NOT 303
61#define EXTERNAL 304
62#define TARGET 305
63#define TRIPLE 306
64#define ENDIAN 307
65#define POINTERSIZE 308
66#define LITTLE 309
67#define BIG 310
68#define ALIGN 311
69#define DEPLIBS 312
70#define CALL 313
71#define TAIL 314
72#define ASM_TOK 315
73#define MODULE 316
74#define SIDEEFFECT 317
75#define CC_TOK 318
76#define CCC_TOK 319
77#define CSRETCC_TOK 320
78#define FASTCC_TOK 321
79#define COLDCC_TOK 322
80#define X86_STDCALLCC_TOK 323
81#define X86_FASTCALLCC_TOK 324
82#define DATALAYOUT 325
83#define RET 326
84#define BR 327
85#define SWITCH 328
86#define INVOKE 329
87#define UNREACHABLE 330
88#define UNWIND 331
89#define EXCEPT 332
90#define ADD 333
91#define SUB 334
92#define MUL 335
93#define DIV 336
94#define UDIV 337
95#define SDIV 338
96#define FDIV 339
97#define REM 340
98#define UREM 341
99#define SREM 342
100#define FREM 343
101#define AND 344
102#define OR 345
103#define XOR 346
104#define SHL 347
105#define SHR 348
106#define ASHR 349
107#define LSHR 350
108#define SETLE 351
109#define SETGE 352
110#define SETLT 353
111#define SETGT 354
112#define SETEQ 355
113#define SETNE 356
114#define ICMP 357
115#define FCMP 358
116#define MALLOC 359
117#define ALLOCA 360
118#define FREE 361
119#define LOAD 362
120#define STORE 363
121#define GETELEMENTPTR 364
122#define PHI_TOK 365
123#define SELECT 366
124#define VAARG 367
125#define EXTRACTELEMENT 368
126#define INSERTELEMENT 369
127#define SHUFFLEVECTOR 370
128#define VAARG_old 371
129#define VANEXT_old 372
130#define EQ 373
131#define NE 374
132#define SLT 375
133#define SGT 376
134#define SLE 377
135#define SGE 378
136#define ULT 379
137#define UGT 380
138#define ULE 381
139#define UGE 382
140#define OEQ 383
141#define ONE 384
142#define OLT 385
143#define OGT 386
144#define OLE 387
145#define OGE 388
146#define ORD 389
147#define UNO 390
148#define UEQ 391
149#define UNE 392
150#define CAST 393
151#define TRUNC 394
152#define ZEXT 395
153#define SEXT 396
154#define FPTRUNC 397
155#define FPEXT 398
156#define FPTOUI 399
157#define FPTOSI 400
158#define UITOFP 401
159#define SITOFP 402
160#define PTRTOINT 403
161#define INTTOPTR 404
162#define BITCAST 405
Reid Spencere7c3c602006-11-30 06:36:44 +0000163
Chris Lattner4227bdb2007-02-19 07:34:02 +0000164#line 14 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencer319a7302007-01-05 17:20:02 +0000165
166#include "UpgradeInternals.h"
Reid Spencer950bf602007-01-26 08:19:09 +0000167#include "llvm/CallingConv.h"
168#include "llvm/InlineAsm.h"
169#include "llvm/Instructions.h"
170#include "llvm/Module.h"
Reid Spenceref9b9a72007-02-05 20:47:22 +0000171#include "llvm/ValueSymbolTable.h"
Reid Spencer950bf602007-01-26 08:19:09 +0000172#include "llvm/Support/GetElementPtrTypeIterator.h"
173#include "llvm/ADT/STLExtras.h"
174#include "llvm/Support/MathExtras.h"
Reid Spencere7c3c602006-11-30 06:36:44 +0000175#include <algorithm>
Reid Spencere7c3c602006-11-30 06:36:44 +0000176#include <iostream>
Chris Lattner8adde282007-02-11 21:40:10 +0000177#include <map>
Reid Spencer950bf602007-01-26 08:19:09 +0000178#include <list>
179#include <utility>
180
181// DEBUG_UPREFS - Define this symbol if you want to enable debugging output
182// relating to upreferences in the input stream.
183//
184//#define DEBUG_UPREFS 1
185#ifdef DEBUG_UPREFS
186#define UR_OUT(X) std::cerr << X
187#else
188#define UR_OUT(X)
189#endif
Reid Spencere7c3c602006-11-30 06:36:44 +0000190
Reid Spencere77e35e2006-12-01 20:26:20 +0000191#define YYERROR_VERBOSE 1
Reid Spencer96839be2006-11-30 16:50:26 +0000192#define YYINCLUDED_STDLIB_H
Reid Spencere77e35e2006-12-01 20:26:20 +0000193#define YYDEBUG 1
Reid Spencere7c3c602006-11-30 06:36:44 +0000194
Reid Spencer950bf602007-01-26 08:19:09 +0000195int yylex();
Reid Spencere7c3c602006-11-30 06:36:44 +0000196int yyparse();
197
Reid Spencer950bf602007-01-26 08:19:09 +0000198int yyerror(const char*);
199static void warning(const std::string& WarningMsg);
200
201namespace llvm {
202
Reid Spencer950bf602007-01-26 08:19:09 +0000203std::istream* LexInput;
Reid Spencere7c3c602006-11-30 06:36:44 +0000204static std::string CurFilename;
Reid Spencer96839be2006-11-30 16:50:26 +0000205
Reid Spencer71d2ec92006-12-31 06:02:26 +0000206// This bool controls whether attributes are ever added to function declarations
207// definitions and calls.
208static bool AddAttributes = false;
209
Reid Spencer950bf602007-01-26 08:19:09 +0000210static Module *ParserResult;
211static bool ObsoleteVarArgs;
212static bool NewVarArgs;
213static BasicBlock *CurBB;
214static GlobalVariable *CurGV;
Reid Spencera50d5962006-12-02 04:11:07 +0000215
Reid Spencer950bf602007-01-26 08:19:09 +0000216// This contains info used when building the body of a function. It is
217// destroyed when the function is completed.
218//
219typedef std::vector<Value *> ValueList; // Numbered defs
220
221typedef std::pair<std::string,const Type*> RenameMapKey;
222typedef std::map<RenameMapKey,std::string> RenameMapType;
223
224static void
225ResolveDefinitions(std::map<const Type *,ValueList> &LateResolvers,
226 std::map<const Type *,ValueList> *FutureLateResolvers = 0);
227
228static struct PerModuleInfo {
229 Module *CurrentModule;
230 std::map<const Type *, ValueList> Values; // Module level numbered definitions
231 std::map<const Type *,ValueList> LateResolveValues;
232 std::vector<PATypeHolder> Types;
233 std::map<ValID, PATypeHolder> LateResolveTypes;
234 static Module::Endianness Endian;
235 static Module::PointerSize PointerSize;
236 RenameMapType RenameMap;
237
238 /// PlaceHolderInfo - When temporary placeholder objects are created, remember
239 /// how they were referenced and on which line of the input they came from so
240 /// that we can resolve them later and print error messages as appropriate.
241 std::map<Value*, std::pair<ValID, int> > PlaceHolderInfo;
242
243 // GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
244 // references to global values. Global values may be referenced before they
245 // are defined, and if so, the temporary object that they represent is held
246 // here. This is used for forward references of GlobalValues.
247 //
248 typedef std::map<std::pair<const PointerType *, ValID>, GlobalValue*>
249 GlobalRefsType;
250 GlobalRefsType GlobalRefs;
251
252 void ModuleDone() {
253 // If we could not resolve some functions at function compilation time
254 // (calls to functions before they are defined), resolve them now... Types
255 // are resolved when the constant pool has been completely parsed.
256 //
257 ResolveDefinitions(LateResolveValues);
258
259 // Check to make sure that all global value forward references have been
260 // resolved!
261 //
262 if (!GlobalRefs.empty()) {
263 std::string UndefinedReferences = "Unresolved global references exist:\n";
264
265 for (GlobalRefsType::iterator I = GlobalRefs.begin(), E =GlobalRefs.end();
266 I != E; ++I) {
267 UndefinedReferences += " " + I->first.first->getDescription() + " " +
268 I->first.second.getName() + "\n";
269 }
270 error(UndefinedReferences);
271 return;
272 }
273
274 if (CurrentModule->getDataLayout().empty()) {
275 std::string dataLayout;
276 if (Endian != Module::AnyEndianness)
277 dataLayout.append(Endian == Module::BigEndian ? "E" : "e");
278 if (PointerSize != Module::AnyPointerSize) {
279 if (!dataLayout.empty())
280 dataLayout += "-";
281 dataLayout.append(PointerSize == Module::Pointer64 ?
282 "p:64:64" : "p:32:32");
283 }
284 CurrentModule->setDataLayout(dataLayout);
285 }
286
287 Values.clear(); // Clear out function local definitions
288 Types.clear();
289 CurrentModule = 0;
290 }
291
292 // GetForwardRefForGlobal - Check to see if there is a forward reference
293 // for this global. If so, remove it from the GlobalRefs map and return it.
294 // If not, just return null.
295 GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ValID ID) {
296 // Check to see if there is a forward reference to this global variable...
297 // if there is, eliminate it and patch the reference to use the new def'n.
298 GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PTy, ID));
299 GlobalValue *Ret = 0;
300 if (I != GlobalRefs.end()) {
301 Ret = I->second;
302 GlobalRefs.erase(I);
303 }
304 return Ret;
305 }
306 void setEndianness(Module::Endianness E) { Endian = E; }
307 void setPointerSize(Module::PointerSize sz) { PointerSize = sz; }
308} CurModule;
309
310Module::Endianness PerModuleInfo::Endian = Module::AnyEndianness;
311Module::PointerSize PerModuleInfo::PointerSize = Module::AnyPointerSize;
312
313static struct PerFunctionInfo {
314 Function *CurrentFunction; // Pointer to current function being created
315
316 std::map<const Type*, ValueList> Values; // Keep track of #'d definitions
317 std::map<const Type*, ValueList> LateResolveValues;
318 bool isDeclare; // Is this function a forward declararation?
319 GlobalValue::LinkageTypes Linkage;// Linkage for forward declaration.
320
321 /// BBForwardRefs - When we see forward references to basic blocks, keep
322 /// track of them here.
323 std::map<BasicBlock*, std::pair<ValID, int> > BBForwardRefs;
324 std::vector<BasicBlock*> NumberedBlocks;
325 RenameMapType RenameMap;
Reid Spencer950bf602007-01-26 08:19:09 +0000326 unsigned NextBBNum;
327
328 inline PerFunctionInfo() {
329 CurrentFunction = 0;
330 isDeclare = false;
331 Linkage = GlobalValue::ExternalLinkage;
332 }
333
334 inline void FunctionStart(Function *M) {
335 CurrentFunction = M;
336 NextBBNum = 0;
337 }
338
339 void FunctionDone() {
340 NumberedBlocks.clear();
341
342 // Any forward referenced blocks left?
343 if (!BBForwardRefs.empty()) {
344 error("Undefined reference to label " +
345 BBForwardRefs.begin()->first->getName());
346 return;
347 }
348
349 // Resolve all forward references now.
350 ResolveDefinitions(LateResolveValues, &CurModule.LateResolveValues);
351
352 Values.clear(); // Clear out function local definitions
353 RenameMap.clear();
Reid Spencer950bf602007-01-26 08:19:09 +0000354 CurrentFunction = 0;
355 isDeclare = false;
356 Linkage = GlobalValue::ExternalLinkage;
357 }
358} CurFun; // Info for the current function...
359
360static bool inFunctionScope() { return CurFun.CurrentFunction != 0; }
361
362
363//===----------------------------------------------------------------------===//
364// Code to handle definitions of all the types
365//===----------------------------------------------------------------------===//
366
367static int InsertValue(Value *V,
368 std::map<const Type*,ValueList> &ValueTab = CurFun.Values) {
369 if (V->hasName()) return -1; // Is this a numbered definition?
370
371 // Yes, insert the value into the value table...
372 ValueList &List = ValueTab[V->getType()];
373 List.push_back(V);
374 return List.size()-1;
375}
376
Reid Spencerd7c4f8c2007-01-26 19:59:25 +0000377static const Type *getType(const ValID &D, bool DoNotImprovise = false) {
Reid Spencer950bf602007-01-26 08:19:09 +0000378 switch (D.Type) {
379 case ValID::NumberVal: // Is it a numbered definition?
380 // Module constants occupy the lowest numbered slots...
381 if ((unsigned)D.Num < CurModule.Types.size()) {
382 return CurModule.Types[(unsigned)D.Num];
383 }
384 break;
385 case ValID::NameVal: // Is it a named definition?
386 if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) {
387 D.destroy(); // Free old strdup'd memory...
388 return N;
389 }
390 break;
391 default:
392 error("Internal parser error: Invalid symbol type reference");
393 return 0;
394 }
395
396 // If we reached here, we referenced either a symbol that we don't know about
397 // or an id number that hasn't been read yet. We may be referencing something
398 // forward, so just create an entry to be resolved later and get to it...
399 //
400 if (DoNotImprovise) return 0; // Do we just want a null to be returned?
401
402
403 if (inFunctionScope()) {
404 if (D.Type == ValID::NameVal) {
405 error("Reference to an undefined type: '" + D.getName() + "'");
406 return 0;
407 } else {
408 error("Reference to an undefined type: #" + itostr(D.Num));
409 return 0;
410 }
411 }
412
413 std::map<ValID, PATypeHolder>::iterator I =CurModule.LateResolveTypes.find(D);
414 if (I != CurModule.LateResolveTypes.end())
415 return I->second;
416
417 Type *Typ = OpaqueType::get();
418 CurModule.LateResolveTypes.insert(std::make_pair(D, Typ));
419 return Typ;
420 }
421
Reid Spencered96d1e2007-02-08 09:08:52 +0000422/// This function determines if two function types differ only in their use of
423/// the sret parameter attribute in the first argument. If they are identical
424/// in all other respects, it returns true. Otherwise, it returns false.
425bool FuncTysDifferOnlyBySRet(const FunctionType *F1,
426 const FunctionType *F2) {
427 if (F1->getReturnType() != F2->getReturnType() ||
428 F1->getNumParams() != F2->getNumParams() ||
429 F1->getParamAttrs(0) != F2->getParamAttrs(0))
430 return false;
431 unsigned SRetMask = ~unsigned(FunctionType::StructRetAttribute);
432 for (unsigned i = 0; i < F1->getNumParams(); ++i) {
433 if (F1->getParamType(i) != F2->getParamType(i) ||
434 unsigned(F1->getParamAttrs(i+1)) & SRetMask !=
435 unsigned(F2->getParamAttrs(i+1)) & SRetMask)
436 return false;
437 }
438 return true;
439}
440
441// The upgrade of csretcc to sret param attribute may have caused a function
442// to not be found because the param attribute changed the type of the called
443// function. This helper function, used in getExistingValue, detects that
444// situation and returns V if it occurs and 0 otherwise.
445static Value* handleSRetFuncTypeMerge(Value *V, const Type* Ty) {
446 // Handle degenerate cases
447 if (!V)
448 return 0;
449 if (V->getType() == Ty)
450 return V;
451
452 Value* Result = 0;
453 const PointerType *PF1 = dyn_cast<PointerType>(Ty);
454 const PointerType *PF2 = dyn_cast<PointerType>(V->getType());
455 if (PF1 && PF2) {
456 const FunctionType *FT1 =
457 dyn_cast<FunctionType>(PF1->getElementType());
458 const FunctionType *FT2 =
459 dyn_cast<FunctionType>(PF2->getElementType());
460 if (FT1 && FT2 && FuncTysDifferOnlyBySRet(FT1, FT2))
461 if (FT2->paramHasAttr(1, FunctionType::StructRetAttribute))
462 Result = V;
463 else if (Constant *C = dyn_cast<Constant>(V))
464 Result = ConstantExpr::getBitCast(C, PF1);
465 else
466 Result = new BitCastInst(V, PF1, "upgrd.cast", CurBB);
467 }
468 return Result;
469}
470
Reid Spencer950bf602007-01-26 08:19:09 +0000471// getExistingValue - Look up the value specified by the provided type and
472// the provided ValID. If the value exists and has already been defined, return
473// it. Otherwise return null.
474//
475static Value *getExistingValue(const Type *Ty, const ValID &D) {
476 if (isa<FunctionType>(Ty)) {
477 error("Functions are not values and must be referenced as pointers");
478 }
479
480 switch (D.Type) {
481 case ValID::NumberVal: { // Is it a numbered definition?
482 unsigned Num = (unsigned)D.Num;
483
484 // Module constants occupy the lowest numbered slots...
485 std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
486 if (VI != CurModule.Values.end()) {
487 if (Num < VI->second.size())
488 return VI->second[Num];
489 Num -= VI->second.size();
490 }
491
492 // Make sure that our type is within bounds
493 VI = CurFun.Values.find(Ty);
494 if (VI == CurFun.Values.end()) return 0;
495
496 // Check that the number is within bounds...
497 if (VI->second.size() <= Num) return 0;
498
499 return VI->second[Num];
500 }
501
502 case ValID::NameVal: { // Is it a named definition?
503 // Get the name out of the ID
504 std::string Name(D.Name);
505 Value* V = 0;
506 RenameMapKey Key = std::make_pair(Name, Ty);
507 if (inFunctionScope()) {
508 // See if the name was renamed
509 RenameMapType::const_iterator I = CurFun.RenameMap.find(Key);
510 std::string LookupName;
511 if (I != CurFun.RenameMap.end())
512 LookupName = I->second;
513 else
514 LookupName = Name;
Reid Spenceref9b9a72007-02-05 20:47:22 +0000515 ValueSymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable();
516 V = SymTab.lookup(LookupName);
Reid Spencered96d1e2007-02-08 09:08:52 +0000517 V = handleSRetFuncTypeMerge(V, Ty);
Reid Spencer950bf602007-01-26 08:19:09 +0000518 }
519 if (!V) {
520 RenameMapType::const_iterator I = CurModule.RenameMap.find(Key);
521 std::string LookupName;
522 if (I != CurModule.RenameMap.end())
523 LookupName = I->second;
524 else
525 LookupName = Name;
Reid Spenceref9b9a72007-02-05 20:47:22 +0000526 V = CurModule.CurrentModule->getValueSymbolTable().lookup(LookupName);
Reid Spencered96d1e2007-02-08 09:08:52 +0000527 V = handleSRetFuncTypeMerge(V, Ty);
Reid Spencer950bf602007-01-26 08:19:09 +0000528 }
Reid Spenceref9b9a72007-02-05 20:47:22 +0000529 if (!V)
Reid Spencer950bf602007-01-26 08:19:09 +0000530 return 0;
531
532 D.destroy(); // Free old strdup'd memory...
533 return V;
534 }
535
536 // Check to make sure that "Ty" is an integral type, and that our
537 // value will fit into the specified type...
538 case ValID::ConstSIntVal: // Is it a constant pool reference??
539 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
540 error("Signed integral constant '" + itostr(D.ConstPool64) +
541 "' is invalid for type '" + Ty->getDescription() + "'");
542 }
543 return ConstantInt::get(Ty, D.ConstPool64);
544
545 case ValID::ConstUIntVal: // Is it an unsigned const pool reference?
546 if (!ConstantInt::isValueValidForType(Ty, D.UConstPool64)) {
547 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64))
548 error("Integral constant '" + utostr(D.UConstPool64) +
549 "' is invalid or out of range");
550 else // This is really a signed reference. Transmogrify.
551 return ConstantInt::get(Ty, D.ConstPool64);
552 } else
553 return ConstantInt::get(Ty, D.UConstPool64);
554
555 case ValID::ConstFPVal: // Is it a floating point const pool reference?
556 if (!ConstantFP::isValueValidForType(Ty, D.ConstPoolFP))
557 error("FP constant invalid for type");
558 return ConstantFP::get(Ty, D.ConstPoolFP);
559
560 case ValID::ConstNullVal: // Is it a null value?
561 if (!isa<PointerType>(Ty))
562 error("Cannot create a a non pointer null");
563 return ConstantPointerNull::get(cast<PointerType>(Ty));
564
565 case ValID::ConstUndefVal: // Is it an undef value?
566 return UndefValue::get(Ty);
567
568 case ValID::ConstZeroVal: // Is it a zero value?
569 return Constant::getNullValue(Ty);
570
571 case ValID::ConstantVal: // Fully resolved constant?
572 if (D.ConstantValue->getType() != Ty)
573 error("Constant expression type different from required type");
574 return D.ConstantValue;
575
576 case ValID::InlineAsmVal: { // Inline asm expression
577 const PointerType *PTy = dyn_cast<PointerType>(Ty);
578 const FunctionType *FTy =
579 PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
580 if (!FTy || !InlineAsm::Verify(FTy, D.IAD->Constraints))
581 error("Invalid type for asm constraint string");
582 InlineAsm *IA = InlineAsm::get(FTy, D.IAD->AsmString, D.IAD->Constraints,
583 D.IAD->HasSideEffects);
584 D.destroy(); // Free InlineAsmDescriptor.
585 return IA;
586 }
587 default:
588 assert(0 && "Unhandled case");
589 return 0;
590 } // End of switch
591
592 assert(0 && "Unhandled case");
593 return 0;
594}
595
596// getVal - This function is identical to getExistingValue, except that if a
597// value is not already defined, it "improvises" by creating a placeholder var
598// that looks and acts just like the requested variable. When the value is
599// defined later, all uses of the placeholder variable are replaced with the
600// real thing.
601//
602static Value *getVal(const Type *Ty, const ValID &ID) {
603 if (Ty == Type::LabelTy)
604 error("Cannot use a basic block here");
605
606 // See if the value has already been defined.
607 Value *V = getExistingValue(Ty, ID);
608 if (V) return V;
609
610 if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty))
611 error("Invalid use of a composite type");
612
613 // If we reached here, we referenced either a symbol that we don't know about
614 // or an id number that hasn't been read yet. We may be referencing something
615 // forward, so just create an entry to be resolved later and get to it...
Reid Spencer950bf602007-01-26 08:19:09 +0000616 V = new Argument(Ty);
617
618 // Remember where this forward reference came from. FIXME, shouldn't we try
619 // to recycle these things??
620 CurModule.PlaceHolderInfo.insert(
Reid Spenceref9b9a72007-02-05 20:47:22 +0000621 std::make_pair(V, std::make_pair(ID, Upgradelineno)));
Reid Spencer950bf602007-01-26 08:19:09 +0000622
623 if (inFunctionScope())
624 InsertValue(V, CurFun.LateResolveValues);
625 else
626 InsertValue(V, CurModule.LateResolveValues);
627 return V;
628}
629
Reid Spencered96d1e2007-02-08 09:08:52 +0000630/// @brief This just makes any name given to it unique, up to MAX_UINT times.
631static std::string makeNameUnique(const std::string& Name) {
632 static unsigned UniqueNameCounter = 1;
633 std::string Result(Name);
634 Result += ".upgrd." + llvm::utostr(UniqueNameCounter++);
635 return Result;
636}
637
Reid Spencer950bf602007-01-26 08:19:09 +0000638/// getBBVal - This is used for two purposes:
639/// * If isDefinition is true, a new basic block with the specified ID is being
640/// defined.
641/// * If isDefinition is true, this is a reference to a basic block, which may
642/// or may not be a forward reference.
643///
644static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
645 assert(inFunctionScope() && "Can't get basic block at global scope");
646
647 std::string Name;
648 BasicBlock *BB = 0;
649 switch (ID.Type) {
650 default:
651 error("Illegal label reference " + ID.getName());
652 break;
653 case ValID::NumberVal: // Is it a numbered definition?
654 if (unsigned(ID.Num) >= CurFun.NumberedBlocks.size())
655 CurFun.NumberedBlocks.resize(ID.Num+1);
656 BB = CurFun.NumberedBlocks[ID.Num];
657 break;
658 case ValID::NameVal: // Is it a named definition?
659 Name = ID.Name;
660 if (Value *N = CurFun.CurrentFunction->
Reid Spenceref9b9a72007-02-05 20:47:22 +0000661 getValueSymbolTable().lookup(Name)) {
Reid Spencered96d1e2007-02-08 09:08:52 +0000662 if (N->getType() != Type::LabelTy) {
663 // Register names didn't use to conflict with basic block names
664 // because of type planes. Now they all have to be unique. So, we just
665 // rename the register and treat this name as if no basic block
666 // had been found.
667 RenameMapKey Key = std::make_pair(N->getName(),N->getType());
668 N->setName(makeNameUnique(N->getName()));
669 CurModule.RenameMap[Key] = N->getName();
670 BB = 0;
671 } else {
672 BB = cast<BasicBlock>(N);
673 }
Reid Spencer950bf602007-01-26 08:19:09 +0000674 }
675 break;
676 }
677
678 // See if the block has already been defined.
679 if (BB) {
680 // If this is the definition of the block, make sure the existing value was
681 // just a forward reference. If it was a forward reference, there will be
682 // an entry for it in the PlaceHolderInfo map.
683 if (isDefinition && !CurFun.BBForwardRefs.erase(BB))
684 // The existing value was a definition, not a forward reference.
685 error("Redefinition of label " + ID.getName());
686
687 ID.destroy(); // Free strdup'd memory.
688 return BB;
689 }
690
691 // Otherwise this block has not been seen before.
692 BB = new BasicBlock("", CurFun.CurrentFunction);
693 if (ID.Type == ValID::NameVal) {
694 BB->setName(ID.Name);
695 } else {
696 CurFun.NumberedBlocks[ID.Num] = BB;
697 }
698
699 // If this is not a definition, keep track of it so we can use it as a forward
700 // reference.
701 if (!isDefinition) {
702 // Remember where this forward reference came from.
703 CurFun.BBForwardRefs[BB] = std::make_pair(ID, Upgradelineno);
704 } else {
705 // The forward declaration could have been inserted anywhere in the
706 // function: insert it into the correct place now.
707 CurFun.CurrentFunction->getBasicBlockList().remove(BB);
708 CurFun.CurrentFunction->getBasicBlockList().push_back(BB);
709 }
710 ID.destroy();
711 return BB;
712}
713
714
715//===----------------------------------------------------------------------===//
716// Code to handle forward references in instructions
717//===----------------------------------------------------------------------===//
718//
719// This code handles the late binding needed with statements that reference
720// values not defined yet... for example, a forward branch, or the PHI node for
721// a loop body.
722//
723// This keeps a table (CurFun.LateResolveValues) of all such forward references
724// and back patchs after we are done.
725//
726
727// ResolveDefinitions - If we could not resolve some defs at parsing
728// time (forward branches, phi functions for loops, etc...) resolve the
729// defs now...
730//
731static void
732ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
733 std::map<const Type*,ValueList> *FutureLateResolvers) {
Reid Spencered96d1e2007-02-08 09:08:52 +0000734
Reid Spencer950bf602007-01-26 08:19:09 +0000735 // Loop over LateResolveDefs fixing up stuff that couldn't be resolved
736 for (std::map<const Type*,ValueList>::iterator LRI = LateResolvers.begin(),
737 E = LateResolvers.end(); LRI != E; ++LRI) {
Reid Spencered96d1e2007-02-08 09:08:52 +0000738 const Type* Ty = LRI->first;
Reid Spencer950bf602007-01-26 08:19:09 +0000739 ValueList &List = LRI->second;
740 while (!List.empty()) {
741 Value *V = List.back();
742 List.pop_back();
743
744 std::map<Value*, std::pair<ValID, int> >::iterator PHI =
745 CurModule.PlaceHolderInfo.find(V);
746 assert(PHI != CurModule.PlaceHolderInfo.end() && "Placeholder error");
747
748 ValID &DID = PHI->second.first;
749
Reid Spencered96d1e2007-02-08 09:08:52 +0000750 Value *TheRealValue = getExistingValue(Ty, DID);
Reid Spencer950bf602007-01-26 08:19:09 +0000751 if (TheRealValue) {
752 V->replaceAllUsesWith(TheRealValue);
753 delete V;
754 CurModule.PlaceHolderInfo.erase(PHI);
755 } else if (FutureLateResolvers) {
756 // Functions have their unresolved items forwarded to the module late
757 // resolver table
758 InsertValue(V, *FutureLateResolvers);
759 } else {
760 if (DID.Type == ValID::NameVal) {
Reid Spencered96d1e2007-02-08 09:08:52 +0000761 error("Reference to an invalid definition: '" + DID.getName() +
762 "' of type '" + V->getType()->getDescription() + "'",
763 PHI->second.second);
Reid Spencer7de2e012007-01-29 19:08:46 +0000764 return;
Reid Spencer950bf602007-01-26 08:19:09 +0000765 } else {
766 error("Reference to an invalid definition: #" +
767 itostr(DID.Num) + " of type '" +
768 V->getType()->getDescription() + "'", PHI->second.second);
769 return;
770 }
771 }
772 }
773 }
774
775 LateResolvers.clear();
776}
777
778// ResolveTypeTo - A brand new type was just declared. This means that (if
779// name is not null) things referencing Name can be resolved. Otherwise, things
780// refering to the number can be resolved. Do this now.
781//
782static void ResolveTypeTo(char *Name, const Type *ToTy) {
783 ValID D;
784 if (Name) D = ValID::create(Name);
785 else D = ValID::create((int)CurModule.Types.size());
786
787 std::map<ValID, PATypeHolder>::iterator I =
788 CurModule.LateResolveTypes.find(D);
789 if (I != CurModule.LateResolveTypes.end()) {
790 ((DerivedType*)I->second.get())->refineAbstractTypeTo(ToTy);
791 CurModule.LateResolveTypes.erase(I);
792 }
793}
794
Anton Korobeynikovce13b852007-01-28 15:25:24 +0000795/// This is the implementation portion of TypeHasInteger. It traverses the
796/// type given, avoiding recursive types, and returns true as soon as it finds
797/// an integer type. If no integer type is found, it returns false.
798static bool TypeHasIntegerI(const Type *Ty, std::vector<const Type*> Stack) {
799 // Handle some easy cases
800 if (Ty->isPrimitiveType() || (Ty->getTypeID() == Type::OpaqueTyID))
801 return false;
802 if (Ty->isInteger())
803 return true;
804 if (const SequentialType *STy = dyn_cast<SequentialType>(Ty))
805 return STy->getElementType()->isInteger();
806
807 // Avoid type structure recursion
808 for (std::vector<const Type*>::iterator I = Stack.begin(), E = Stack.end();
809 I != E; ++I)
810 if (Ty == *I)
811 return false;
812
813 // Push us on the type stack
814 Stack.push_back(Ty);
815
816 if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
817 if (TypeHasIntegerI(FTy->getReturnType(), Stack))
818 return true;
819 FunctionType::param_iterator I = FTy->param_begin();
820 FunctionType::param_iterator E = FTy->param_end();
821 for (; I != E; ++I)
822 if (TypeHasIntegerI(*I, Stack))
823 return true;
824 return false;
825 } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
826 StructType::element_iterator I = STy->element_begin();
827 StructType::element_iterator E = STy->element_end();
828 for (; I != E; ++I) {
829 if (TypeHasIntegerI(*I, Stack))
830 return true;
831 }
832 return false;
833 }
834 // There shouldn't be anything else, but its definitely not integer
835 assert(0 && "What type is this?");
836 return false;
837}
838
839/// This is the interface to TypeHasIntegerI. It just provides the type stack,
840/// to avoid recursion, and then calls TypeHasIntegerI.
841static inline bool TypeHasInteger(const Type *Ty) {
842 std::vector<const Type*> TyStack;
843 return TypeHasIntegerI(Ty, TyStack);
844}
845
Reid Spencer950bf602007-01-26 08:19:09 +0000846// setValueName - Set the specified value to the name given. The name may be
847// null potentially, in which case this is a noop. The string passed in is
848// assumed to be a malloc'd string buffer, and is free'd by this function.
849//
850static void setValueName(Value *V, char *NameStr) {
851 if (NameStr) {
852 std::string Name(NameStr); // Copy string
853 free(NameStr); // Free old string
854
855 if (V->getType() == Type::VoidTy) {
856 error("Can't assign name '" + Name + "' to value with void type");
857 return;
858 }
859
Reid Spencer950bf602007-01-26 08:19:09 +0000860 assert(inFunctionScope() && "Must be in function scope");
861
862 // Search the function's symbol table for an existing value of this name
Reid Spenceref9b9a72007-02-05 20:47:22 +0000863 ValueSymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
864 Value* Existing = ST.lookup(Name);
Reid Spencer950bf602007-01-26 08:19:09 +0000865 if (Existing) {
Anton Korobeynikovce13b852007-01-28 15:25:24 +0000866 // An existing value of the same name was found. This might have happened
867 // because of the integer type planes collapsing in LLVM 2.0.
868 if (Existing->getType() == V->getType() &&
869 !TypeHasInteger(Existing->getType())) {
870 // If the type does not contain any integers in them then this can't be
871 // a type plane collapsing issue. It truly is a redefinition and we
872 // should error out as the assembly is invalid.
873 error("Redefinition of value named '" + Name + "' of type '" +
874 V->getType()->getDescription() + "'");
875 return;
Reid Spencer950bf602007-01-26 08:19:09 +0000876 }
877 // In LLVM 2.0 we don't allow names to be re-used for any values in a
878 // function, regardless of Type. Previously re-use of names was okay as
879 // long as they were distinct types. With type planes collapsing because
880 // of the signedness change and because of PR411, this can no longer be
881 // supported. We must search the entire symbol table for a conflicting
882 // name and make the name unique. No warning is needed as this can't
883 // cause a problem.
884 std::string NewName = makeNameUnique(Name);
885 // We're changing the name but it will probably be used by other
886 // instructions as operands later on. Consequently we have to retain
887 // a mapping of the renaming that we're doing.
888 RenameMapKey Key = std::make_pair(Name,V->getType());
889 CurFun.RenameMap[Key] = NewName;
890 Name = NewName;
891 }
892
893 // Set the name.
894 V->setName(Name);
895 }
896}
897
898/// ParseGlobalVariable - Handle parsing of a global. If Initializer is null,
899/// this is a declaration, otherwise it is a definition.
900static GlobalVariable *
901ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
902 bool isConstantGlobal, const Type *Ty,
903 Constant *Initializer) {
904 if (isa<FunctionType>(Ty))
905 error("Cannot declare global vars of function type");
906
907 const PointerType *PTy = PointerType::get(Ty);
908
909 std::string Name;
910 if (NameStr) {
911 Name = NameStr; // Copy string
912 free(NameStr); // Free old string
913 }
914
915 // See if this global value was forward referenced. If so, recycle the
916 // object.
917 ValID ID;
918 if (!Name.empty()) {
919 ID = ValID::create((char*)Name.c_str());
920 } else {
921 ID = ValID::create((int)CurModule.Values[PTy].size());
922 }
923
924 if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) {
925 // Move the global to the end of the list, from whereever it was
926 // previously inserted.
927 GlobalVariable *GV = cast<GlobalVariable>(FWGV);
928 CurModule.CurrentModule->getGlobalList().remove(GV);
929 CurModule.CurrentModule->getGlobalList().push_back(GV);
930 GV->setInitializer(Initializer);
931 GV->setLinkage(Linkage);
932 GV->setConstant(isConstantGlobal);
933 InsertValue(GV, CurModule.Values);
934 return GV;
935 }
936
937 // If this global has a name, check to see if there is already a definition
938 // of this global in the module and emit warnings if there are conflicts.
939 if (!Name.empty()) {
940 // The global has a name. See if there's an existing one of the same name.
941 if (CurModule.CurrentModule->getNamedGlobal(Name)) {
942 // We found an existing global ov the same name. This isn't allowed
943 // in LLVM 2.0. Consequently, we must alter the name of the global so it
944 // can at least compile. This can happen because of type planes
945 // There is alread a global of the same name which means there is a
946 // conflict. Let's see what we can do about it.
947 std::string NewName(makeNameUnique(Name));
948 if (Linkage == GlobalValue::InternalLinkage) {
949 // The linkage type is internal so just warn about the rename without
950 // invoking "scarey language" about linkage failures. GVars with
951 // InternalLinkage can be renamed at will.
952 warning("Global variable '" + Name + "' was renamed to '"+
953 NewName + "'");
954 } else {
955 // The linkage of this gval is external so we can't reliably rename
956 // it because it could potentially create a linking problem.
957 // However, we can't leave the name conflict in the output either or
958 // it won't assemble with LLVM 2.0. So, all we can do is rename
959 // this one to something unique and emit a warning about the problem.
960 warning("Renaming global variable '" + Name + "' to '" + NewName +
961 "' may cause linkage errors");
962 }
963
964 // Put the renaming in the global rename map
965 RenameMapKey Key = std::make_pair(Name,PointerType::get(Ty));
966 CurModule.RenameMap[Key] = NewName;
967
968 // Rename it
969 Name = NewName;
970 }
971 }
972
973 // Otherwise there is no existing GV to use, create one now.
974 GlobalVariable *GV =
975 new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name,
976 CurModule.CurrentModule);
977 InsertValue(GV, CurModule.Values);
978 return GV;
979}
980
981// setTypeName - Set the specified type to the name given. The name may be
982// null potentially, in which case this is a noop. The string passed in is
983// assumed to be a malloc'd string buffer, and is freed by this function.
984//
985// This function returns true if the type has already been defined, but is
986// allowed to be redefined in the specified context. If the name is a new name
987// for the type plane, it is inserted and false is returned.
988static bool setTypeName(const Type *T, char *NameStr) {
989 assert(!inFunctionScope() && "Can't give types function-local names");
990 if (NameStr == 0) return false;
991
992 std::string Name(NameStr); // Copy string
993 free(NameStr); // Free old string
994
995 // We don't allow assigning names to void type
996 if (T == Type::VoidTy) {
997 error("Can't assign name '" + Name + "' to the void type");
998 return false;
999 }
1000
1001 // Set the type name, checking for conflicts as we do so.
1002 bool AlreadyExists = CurModule.CurrentModule->addTypeName(Name, T);
1003
1004 if (AlreadyExists) { // Inserting a name that is already defined???
1005 const Type *Existing = CurModule.CurrentModule->getTypeByName(Name);
1006 assert(Existing && "Conflict but no matching type?");
1007
1008 // There is only one case where this is allowed: when we are refining an
1009 // opaque type. In this case, Existing will be an opaque type.
1010 if (const OpaqueType *OpTy = dyn_cast<OpaqueType>(Existing)) {
1011 // We ARE replacing an opaque type!
1012 const_cast<OpaqueType*>(OpTy)->refineAbstractTypeTo(T);
1013 return true;
1014 }
1015
1016 // Otherwise, this is an attempt to redefine a type. That's okay if
1017 // the redefinition is identical to the original. This will be so if
1018 // Existing and T point to the same Type object. In this one case we
1019 // allow the equivalent redefinition.
1020 if (Existing == T) return true; // Yes, it's equal.
1021
1022 // Any other kind of (non-equivalent) redefinition is an error.
1023 error("Redefinition of type named '" + Name + "' in the '" +
1024 T->getDescription() + "' type plane");
1025 }
1026
1027 return false;
1028}
1029
1030//===----------------------------------------------------------------------===//
1031// Code for handling upreferences in type names...
1032//
1033
1034// TypeContains - Returns true if Ty directly contains E in it.
1035//
1036static bool TypeContains(const Type *Ty, const Type *E) {
1037 return std::find(Ty->subtype_begin(), Ty->subtype_end(),
1038 E) != Ty->subtype_end();
1039}
1040
1041namespace {
1042 struct UpRefRecord {
1043 // NestingLevel - The number of nesting levels that need to be popped before
1044 // this type is resolved.
1045 unsigned NestingLevel;
1046
1047 // LastContainedTy - This is the type at the current binding level for the
1048 // type. Every time we reduce the nesting level, this gets updated.
1049 const Type *LastContainedTy;
1050
1051 // UpRefTy - This is the actual opaque type that the upreference is
1052 // represented with.
1053 OpaqueType *UpRefTy;
1054
1055 UpRefRecord(unsigned NL, OpaqueType *URTy)
1056 : NestingLevel(NL), LastContainedTy(URTy), UpRefTy(URTy) {}
1057 };
1058}
1059
1060// UpRefs - A list of the outstanding upreferences that need to be resolved.
1061static std::vector<UpRefRecord> UpRefs;
1062
1063/// HandleUpRefs - Every time we finish a new layer of types, this function is
1064/// called. It loops through the UpRefs vector, which is a list of the
1065/// currently active types. For each type, if the up reference is contained in
1066/// the newly completed type, we decrement the level count. When the level
1067/// count reaches zero, the upreferenced type is the type that is passed in:
1068/// thus we can complete the cycle.
1069///
1070static PATypeHolder HandleUpRefs(const Type *ty) {
1071 // If Ty isn't abstract, or if there are no up-references in it, then there is
1072 // nothing to resolve here.
1073 if (!ty->isAbstract() || UpRefs.empty()) return ty;
1074
1075 PATypeHolder Ty(ty);
1076 UR_OUT("Type '" << Ty->getDescription() <<
1077 "' newly formed. Resolving upreferences.\n" <<
1078 UpRefs.size() << " upreferences active!\n");
1079
1080 // If we find any resolvable upreferences (i.e., those whose NestingLevel goes
1081 // to zero), we resolve them all together before we resolve them to Ty. At
1082 // the end of the loop, if there is anything to resolve to Ty, it will be in
1083 // this variable.
1084 OpaqueType *TypeToResolve = 0;
1085
1086 for (unsigned i = 0; i != UpRefs.size(); ++i) {
1087 UR_OUT(" UR#" << i << " - TypeContains(" << Ty->getDescription() << ", "
1088 << UpRefs[i].second->getDescription() << ") = "
1089 << (TypeContains(Ty, UpRefs[i].second) ? "true" : "false") << "\n");
1090 if (TypeContains(Ty, UpRefs[i].LastContainedTy)) {
1091 // Decrement level of upreference
1092 unsigned Level = --UpRefs[i].NestingLevel;
1093 UpRefs[i].LastContainedTy = Ty;
1094 UR_OUT(" Uplevel Ref Level = " << Level << "\n");
1095 if (Level == 0) { // Upreference should be resolved!
1096 if (!TypeToResolve) {
1097 TypeToResolve = UpRefs[i].UpRefTy;
1098 } else {
1099 UR_OUT(" * Resolving upreference for "
1100 << UpRefs[i].second->getDescription() << "\n";
1101 std::string OldName = UpRefs[i].UpRefTy->getDescription());
1102 UpRefs[i].UpRefTy->refineAbstractTypeTo(TypeToResolve);
1103 UR_OUT(" * Type '" << OldName << "' refined upreference to: "
1104 << (const void*)Ty << ", " << Ty->getDescription() << "\n");
1105 }
1106 UpRefs.erase(UpRefs.begin()+i); // Remove from upreference list...
1107 --i; // Do not skip the next element...
1108 }
1109 }
1110 }
1111
1112 if (TypeToResolve) {
1113 UR_OUT(" * Resolving upreference for "
1114 << UpRefs[i].second->getDescription() << "\n";
1115 std::string OldName = TypeToResolve->getDescription());
1116 TypeToResolve->refineAbstractTypeTo(Ty);
1117 }
1118
1119 return Ty;
1120}
1121
1122static inline Instruction::TermOps
1123getTermOp(TermOps op) {
1124 switch (op) {
1125 default : assert(0 && "Invalid OldTermOp");
1126 case RetOp : return Instruction::Ret;
1127 case BrOp : return Instruction::Br;
1128 case SwitchOp : return Instruction::Switch;
1129 case InvokeOp : return Instruction::Invoke;
1130 case UnwindOp : return Instruction::Unwind;
1131 case UnreachableOp: return Instruction::Unreachable;
1132 }
1133}
1134
1135static inline Instruction::BinaryOps
1136getBinaryOp(BinaryOps op, const Type *Ty, Signedness Sign) {
1137 switch (op) {
1138 default : assert(0 && "Invalid OldBinaryOps");
1139 case SetEQ :
1140 case SetNE :
1141 case SetLE :
1142 case SetGE :
1143 case SetLT :
1144 case SetGT : assert(0 && "Should use getCompareOp");
1145 case AddOp : return Instruction::Add;
1146 case SubOp : return Instruction::Sub;
1147 case MulOp : return Instruction::Mul;
1148 case DivOp : {
1149 // This is an obsolete instruction so we must upgrade it based on the
1150 // types of its operands.
1151 bool isFP = Ty->isFloatingPoint();
Reid Spencer9d6565a2007-02-15 02:26:10 +00001152 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
Chris Lattner4227bdb2007-02-19 07:34:02 +00001153 // If its a vector type we want to use the element type
Reid Spencer950bf602007-01-26 08:19:09 +00001154 isFP = PTy->getElementType()->isFloatingPoint();
1155 if (isFP)
1156 return Instruction::FDiv;
1157 else if (Sign == Signed)
1158 return Instruction::SDiv;
1159 return Instruction::UDiv;
1160 }
1161 case UDivOp : return Instruction::UDiv;
1162 case SDivOp : return Instruction::SDiv;
1163 case FDivOp : return Instruction::FDiv;
1164 case RemOp : {
1165 // This is an obsolete instruction so we must upgrade it based on the
1166 // types of its operands.
1167 bool isFP = Ty->isFloatingPoint();
Reid Spencer9d6565a2007-02-15 02:26:10 +00001168 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
Chris Lattner4227bdb2007-02-19 07:34:02 +00001169 // If its a vector type we want to use the element type
Reid Spencer950bf602007-01-26 08:19:09 +00001170 isFP = PTy->getElementType()->isFloatingPoint();
1171 // Select correct opcode
1172 if (isFP)
1173 return Instruction::FRem;
1174 else if (Sign == Signed)
1175 return Instruction::SRem;
1176 return Instruction::URem;
1177 }
1178 case URemOp : return Instruction::URem;
1179 case SRemOp : return Instruction::SRem;
1180 case FRemOp : return Instruction::FRem;
Reid Spencer832254e2007-02-02 02:16:23 +00001181 case LShrOp : return Instruction::LShr;
1182 case AShrOp : return Instruction::AShr;
1183 case ShlOp : return Instruction::Shl;
1184 case ShrOp :
1185 if (Sign == Signed)
1186 return Instruction::AShr;
1187 return Instruction::LShr;
Reid Spencer950bf602007-01-26 08:19:09 +00001188 case AndOp : return Instruction::And;
1189 case OrOp : return Instruction::Or;
1190 case XorOp : return Instruction::Xor;
1191 }
1192}
1193
1194static inline Instruction::OtherOps
1195getCompareOp(BinaryOps op, unsigned short &predicate, const Type* &Ty,
1196 Signedness Sign) {
1197 bool isSigned = Sign == Signed;
1198 bool isFP = Ty->isFloatingPoint();
1199 switch (op) {
1200 default : assert(0 && "Invalid OldSetCC");
1201 case SetEQ :
1202 if (isFP) {
1203 predicate = FCmpInst::FCMP_OEQ;
1204 return Instruction::FCmp;
1205 } else {
1206 predicate = ICmpInst::ICMP_EQ;
1207 return Instruction::ICmp;
1208 }
1209 case SetNE :
1210 if (isFP) {
1211 predicate = FCmpInst::FCMP_UNE;
1212 return Instruction::FCmp;
1213 } else {
1214 predicate = ICmpInst::ICMP_NE;
1215 return Instruction::ICmp;
1216 }
1217 case SetLE :
1218 if (isFP) {
1219 predicate = FCmpInst::FCMP_OLE;
1220 return Instruction::FCmp;
1221 } else {
1222 if (isSigned)
1223 predicate = ICmpInst::ICMP_SLE;
1224 else
1225 predicate = ICmpInst::ICMP_ULE;
1226 return Instruction::ICmp;
1227 }
1228 case SetGE :
1229 if (isFP) {
1230 predicate = FCmpInst::FCMP_OGE;
1231 return Instruction::FCmp;
1232 } else {
1233 if (isSigned)
1234 predicate = ICmpInst::ICMP_SGE;
1235 else
1236 predicate = ICmpInst::ICMP_UGE;
1237 return Instruction::ICmp;
1238 }
1239 case SetLT :
1240 if (isFP) {
1241 predicate = FCmpInst::FCMP_OLT;
1242 return Instruction::FCmp;
1243 } else {
1244 if (isSigned)
1245 predicate = ICmpInst::ICMP_SLT;
1246 else
1247 predicate = ICmpInst::ICMP_ULT;
1248 return Instruction::ICmp;
1249 }
1250 case SetGT :
1251 if (isFP) {
1252 predicate = FCmpInst::FCMP_OGT;
1253 return Instruction::FCmp;
1254 } else {
1255 if (isSigned)
1256 predicate = ICmpInst::ICMP_SGT;
1257 else
1258 predicate = ICmpInst::ICMP_UGT;
1259 return Instruction::ICmp;
1260 }
1261 }
1262}
1263
1264static inline Instruction::MemoryOps getMemoryOp(MemoryOps op) {
1265 switch (op) {
1266 default : assert(0 && "Invalid OldMemoryOps");
1267 case MallocOp : return Instruction::Malloc;
1268 case FreeOp : return Instruction::Free;
1269 case AllocaOp : return Instruction::Alloca;
1270 case LoadOp : return Instruction::Load;
1271 case StoreOp : return Instruction::Store;
1272 case GetElementPtrOp : return Instruction::GetElementPtr;
1273 }
1274}
1275
1276static inline Instruction::OtherOps
1277getOtherOp(OtherOps op, Signedness Sign) {
1278 switch (op) {
1279 default : assert(0 && "Invalid OldOtherOps");
1280 case PHIOp : return Instruction::PHI;
1281 case CallOp : return Instruction::Call;
Reid Spencer950bf602007-01-26 08:19:09 +00001282 case SelectOp : return Instruction::Select;
1283 case UserOp1 : return Instruction::UserOp1;
1284 case UserOp2 : return Instruction::UserOp2;
1285 case VAArg : return Instruction::VAArg;
1286 case ExtractElementOp : return Instruction::ExtractElement;
1287 case InsertElementOp : return Instruction::InsertElement;
1288 case ShuffleVectorOp : return Instruction::ShuffleVector;
1289 case ICmpOp : return Instruction::ICmp;
1290 case FCmpOp : return Instruction::FCmp;
Reid Spencer950bf602007-01-26 08:19:09 +00001291 };
1292}
1293
1294static inline Value*
1295getCast(CastOps op, Value *Src, Signedness SrcSign, const Type *DstTy,
1296 Signedness DstSign, bool ForceInstruction = false) {
1297 Instruction::CastOps Opcode;
1298 const Type* SrcTy = Src->getType();
1299 if (op == CastOp) {
1300 if (SrcTy->isFloatingPoint() && isa<PointerType>(DstTy)) {
1301 // fp -> ptr cast is no longer supported but we must upgrade this
1302 // by doing a double cast: fp -> int -> ptr
1303 SrcTy = Type::Int64Ty;
1304 Opcode = Instruction::IntToPtr;
1305 if (isa<Constant>(Src)) {
1306 Src = ConstantExpr::getCast(Instruction::FPToUI,
1307 cast<Constant>(Src), SrcTy);
1308 } else {
1309 std::string NewName(makeNameUnique(Src->getName()));
1310 Src = new FPToUIInst(Src, SrcTy, NewName, CurBB);
1311 }
1312 } else if (isa<IntegerType>(DstTy) &&
1313 cast<IntegerType>(DstTy)->getBitWidth() == 1) {
1314 // cast type %x to bool was previously defined as setne type %x, null
1315 // The cast semantic is now to truncate, not compare so we must retain
1316 // the original intent by replacing the cast with a setne
1317 Constant* Null = Constant::getNullValue(SrcTy);
1318 Instruction::OtherOps Opcode = Instruction::ICmp;
1319 unsigned short predicate = ICmpInst::ICMP_NE;
1320 if (SrcTy->isFloatingPoint()) {
1321 Opcode = Instruction::FCmp;
1322 predicate = FCmpInst::FCMP_ONE;
1323 } else if (!SrcTy->isInteger() && !isa<PointerType>(SrcTy)) {
1324 error("Invalid cast to bool");
1325 }
1326 if (isa<Constant>(Src) && !ForceInstruction)
1327 return ConstantExpr::getCompare(predicate, cast<Constant>(Src), Null);
1328 else
1329 return CmpInst::create(Opcode, predicate, Src, Null);
1330 }
1331 // Determine the opcode to use by calling CastInst::getCastOpcode
1332 Opcode =
1333 CastInst::getCastOpcode(Src, SrcSign == Signed, DstTy, DstSign == Signed);
1334
1335 } else switch (op) {
1336 default: assert(0 && "Invalid cast token");
1337 case TruncOp: Opcode = Instruction::Trunc; break;
1338 case ZExtOp: Opcode = Instruction::ZExt; break;
1339 case SExtOp: Opcode = Instruction::SExt; break;
1340 case FPTruncOp: Opcode = Instruction::FPTrunc; break;
1341 case FPExtOp: Opcode = Instruction::FPExt; break;
1342 case FPToUIOp: Opcode = Instruction::FPToUI; break;
1343 case FPToSIOp: Opcode = Instruction::FPToSI; break;
1344 case UIToFPOp: Opcode = Instruction::UIToFP; break;
1345 case SIToFPOp: Opcode = Instruction::SIToFP; break;
1346 case PtrToIntOp: Opcode = Instruction::PtrToInt; break;
1347 case IntToPtrOp: Opcode = Instruction::IntToPtr; break;
1348 case BitCastOp: Opcode = Instruction::BitCast; break;
1349 }
1350
1351 if (isa<Constant>(Src) && !ForceInstruction)
1352 return ConstantExpr::getCast(Opcode, cast<Constant>(Src), DstTy);
1353 return CastInst::create(Opcode, Src, DstTy);
1354}
1355
1356static Instruction *
1357upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
1358 std::vector<Value*>& Args) {
1359
1360 std::string Name = ID.Type == ValID::NameVal ? ID.Name : "";
1361 if (Name == "llvm.isunordered.f32" || Name == "llvm.isunordered.f64") {
1362 if (Args.size() != 2)
1363 error("Invalid prototype for " + Name + " prototype");
1364 return new FCmpInst(FCmpInst::FCMP_UNO, Args[0], Args[1]);
1365 } else {
Reid Spencer950bf602007-01-26 08:19:09 +00001366 const Type* PtrTy = PointerType::get(Type::Int8Ty);
1367 std::vector<const Type*> Params;
1368 if (Name == "llvm.va_start" || Name == "llvm.va_end") {
1369 if (Args.size() != 1)
1370 error("Invalid prototype for " + Name + " prototype");
1371 Params.push_back(PtrTy);
1372 const FunctionType *FTy = FunctionType::get(Type::VoidTy, Params, false);
1373 const PointerType *PFTy = PointerType::get(FTy);
1374 Value* Func = getVal(PFTy, ID);
Reid Spencer832254e2007-02-02 02:16:23 +00001375 Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
Chris Lattnercf3d0612007-02-13 06:04:17 +00001376 return new CallInst(Func, &Args[0], Args.size());
Reid Spencer950bf602007-01-26 08:19:09 +00001377 } else if (Name == "llvm.va_copy") {
1378 if (Args.size() != 2)
1379 error("Invalid prototype for " + Name + " prototype");
1380 Params.push_back(PtrTy);
1381 Params.push_back(PtrTy);
1382 const FunctionType *FTy = FunctionType::get(Type::VoidTy, Params, false);
1383 const PointerType *PFTy = PointerType::get(FTy);
1384 Value* Func = getVal(PFTy, ID);
Reid Spencer832254e2007-02-02 02:16:23 +00001385 std::string InstName0(makeNameUnique("va0"));
1386 std::string InstName1(makeNameUnique("va1"));
Reid Spencer950bf602007-01-26 08:19:09 +00001387 Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
1388 Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
Chris Lattnercf3d0612007-02-13 06:04:17 +00001389 return new CallInst(Func, &Args[0], Args.size());
Reid Spencer950bf602007-01-26 08:19:09 +00001390 }
1391 }
1392 return 0;
1393}
1394
1395const Type* upgradeGEPIndices(const Type* PTy,
1396 std::vector<ValueInfo> *Indices,
1397 std::vector<Value*> &VIndices,
1398 std::vector<Constant*> *CIndices = 0) {
1399 // Traverse the indices with a gep_type_iterator so we can build the list
1400 // of constant and value indices for use later. Also perform upgrades
1401 VIndices.clear();
1402 if (CIndices) CIndices->clear();
1403 for (unsigned i = 0, e = Indices->size(); i != e; ++i)
1404 VIndices.push_back((*Indices)[i].V);
1405 generic_gep_type_iterator<std::vector<Value*>::iterator>
1406 GTI = gep_type_begin(PTy, VIndices.begin(), VIndices.end()),
1407 GTE = gep_type_end(PTy, VIndices.begin(), VIndices.end());
1408 for (unsigned i = 0, e = Indices->size(); i != e && GTI != GTE; ++i, ++GTI) {
1409 Value *Index = VIndices[i];
1410 if (CIndices && !isa<Constant>(Index))
1411 error("Indices to constant getelementptr must be constants");
1412 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1413 // struct indices to i32 struct indices with ZExt for compatibility.
1414 else if (isa<StructType>(*GTI)) { // Only change struct indices
1415 if (ConstantInt *CUI = dyn_cast<ConstantInt>(Index))
1416 if (CUI->getType()->getBitWidth() == 8)
1417 Index =
1418 ConstantExpr::getCast(Instruction::ZExt, CUI, Type::Int32Ty);
1419 } else {
1420 // Make sure that unsigned SequentialType indices are zext'd to
1421 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1422 // all indices for SequentialType elements. We must retain the same
1423 // semantic (zext) for unsigned types.
1424 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType()))
Reid Spencer38f682b2007-01-26 20:31:18 +00001425 if (Ity->getBitWidth() < 64 && (*Indices)[i].S == Unsigned) {
Reid Spencer950bf602007-01-26 08:19:09 +00001426 if (CIndices)
1427 Index = ConstantExpr::getCast(Instruction::ZExt,
1428 cast<Constant>(Index), Type::Int64Ty);
1429 else
1430 Index = CastInst::create(Instruction::ZExt, Index, Type::Int64Ty,
Reid Spencer832254e2007-02-02 02:16:23 +00001431 makeNameUnique("gep"), CurBB);
Reid Spencer38f682b2007-01-26 20:31:18 +00001432 VIndices[i] = Index;
1433 }
Reid Spencer950bf602007-01-26 08:19:09 +00001434 }
1435 // Add to the CIndices list, if requested.
1436 if (CIndices)
1437 CIndices->push_back(cast<Constant>(Index));
1438 }
1439
1440 const Type *IdxTy =
Chris Lattner1bc3fa62007-02-12 22:58:38 +00001441 GetElementPtrInst::getIndexedType(PTy, &VIndices[0], VIndices.size(), true);
Reid Spencer950bf602007-01-26 08:19:09 +00001442 if (!IdxTy)
1443 error("Index list invalid for constant getelementptr");
1444 return IdxTy;
1445}
1446
Reid Spencerb7046c72007-01-29 05:41:34 +00001447unsigned upgradeCallingConv(unsigned CC) {
1448 switch (CC) {
1449 case OldCallingConv::C : return CallingConv::C;
1450 case OldCallingConv::CSRet : return CallingConv::C;
1451 case OldCallingConv::Fast : return CallingConv::Fast;
1452 case OldCallingConv::Cold : return CallingConv::Cold;
1453 case OldCallingConv::X86_StdCall : return CallingConv::X86_StdCall;
1454 case OldCallingConv::X86_FastCall: return CallingConv::X86_FastCall;
1455 default:
1456 return CC;
1457 }
1458}
1459
Reid Spencer950bf602007-01-26 08:19:09 +00001460Module* UpgradeAssembly(const std::string &infile, std::istream& in,
1461 bool debug, bool addAttrs)
Reid Spencere7c3c602006-11-30 06:36:44 +00001462{
1463 Upgradelineno = 1;
1464 CurFilename = infile;
Reid Spencer96839be2006-11-30 16:50:26 +00001465 LexInput = &in;
Reid Spencere77e35e2006-12-01 20:26:20 +00001466 yydebug = debug;
Reid Spencer71d2ec92006-12-31 06:02:26 +00001467 AddAttributes = addAttrs;
Reid Spencer950bf602007-01-26 08:19:09 +00001468 ObsoleteVarArgs = false;
1469 NewVarArgs = false;
Reid Spencere7c3c602006-11-30 06:36:44 +00001470
Reid Spencer950bf602007-01-26 08:19:09 +00001471 CurModule.CurrentModule = new Module(CurFilename);
1472
1473 // Check to make sure the parser succeeded
Reid Spencere7c3c602006-11-30 06:36:44 +00001474 if (yyparse()) {
Reid Spencer950bf602007-01-26 08:19:09 +00001475 if (ParserResult)
1476 delete ParserResult;
Reid Spencer30d0c582007-01-15 00:26:18 +00001477 std::cerr << "llvm-upgrade: parse failed.\n";
Reid Spencer30d0c582007-01-15 00:26:18 +00001478 return 0;
1479 }
1480
Reid Spencer950bf602007-01-26 08:19:09 +00001481 // Check to make sure that parsing produced a result
1482 if (!ParserResult) {
1483 std::cerr << "llvm-upgrade: no parse result.\n";
1484 return 0;
Reid Spencer30d0c582007-01-15 00:26:18 +00001485 }
1486
Reid Spencer950bf602007-01-26 08:19:09 +00001487 // Reset ParserResult variable while saving its value for the result.
1488 Module *Result = ParserResult;
1489 ParserResult = 0;
Reid Spencer30d0c582007-01-15 00:26:18 +00001490
Reid Spencer950bf602007-01-26 08:19:09 +00001491 //Not all functions use vaarg, so make a second check for ObsoleteVarArgs
Reid Spencer30d0c582007-01-15 00:26:18 +00001492 {
Reid Spencer950bf602007-01-26 08:19:09 +00001493 Function* F;
Reid Spencer688b0492007-02-05 21:19:13 +00001494 if ((F = Result->getFunction("llvm.va_start"))
Reid Spencer950bf602007-01-26 08:19:09 +00001495 && F->getFunctionType()->getNumParams() == 0)
1496 ObsoleteVarArgs = true;
Reid Spencer688b0492007-02-05 21:19:13 +00001497 if((F = Result->getFunction("llvm.va_copy"))
Reid Spencer950bf602007-01-26 08:19:09 +00001498 && F->getFunctionType()->getNumParams() == 1)
1499 ObsoleteVarArgs = true;
Reid Spencer280d8012006-12-01 23:40:53 +00001500 }
Reid Spencer319a7302007-01-05 17:20:02 +00001501
Reid Spencer950bf602007-01-26 08:19:09 +00001502 if (ObsoleteVarArgs && NewVarArgs) {
1503 error("This file is corrupt: it uses both new and old style varargs");
1504 return 0;
Reid Spencer319a7302007-01-05 17:20:02 +00001505 }
Reid Spencer319a7302007-01-05 17:20:02 +00001506
Reid Spencer950bf602007-01-26 08:19:09 +00001507 if(ObsoleteVarArgs) {
Reid Spencer688b0492007-02-05 21:19:13 +00001508 if(Function* F = Result->getFunction("llvm.va_start")) {
Reid Spencer950bf602007-01-26 08:19:09 +00001509 if (F->arg_size() != 0) {
1510 error("Obsolete va_start takes 0 argument");
Reid Spencer319a7302007-01-05 17:20:02 +00001511 return 0;
1512 }
Reid Spencer950bf602007-01-26 08:19:09 +00001513
1514 //foo = va_start()
1515 // ->
1516 //bar = alloca typeof(foo)
1517 //va_start(bar)
1518 //foo = load bar
Reid Spencer319a7302007-01-05 17:20:02 +00001519
Reid Spencer950bf602007-01-26 08:19:09 +00001520 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1521 const Type* ArgTy = F->getFunctionType()->getReturnType();
1522 const Type* ArgTyPtr = PointerType::get(ArgTy);
1523 Function* NF = cast<Function>(Result->getOrInsertFunction(
1524 "llvm.va_start", RetTy, ArgTyPtr, (Type *)0));
1525
1526 while (!F->use_empty()) {
1527 CallInst* CI = cast<CallInst>(F->use_back());
1528 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vastart.fix.1", CI);
1529 new CallInst(NF, bar, "", CI);
1530 Value* foo = new LoadInst(bar, "vastart.fix.2", CI);
1531 CI->replaceAllUsesWith(foo);
1532 CI->getParent()->getInstList().erase(CI);
Reid Spencerf8383de2007-01-06 06:04:32 +00001533 }
Reid Spencer950bf602007-01-26 08:19:09 +00001534 Result->getFunctionList().erase(F);
Reid Spencerf8383de2007-01-06 06:04:32 +00001535 }
Reid Spencer950bf602007-01-26 08:19:09 +00001536
Reid Spencer688b0492007-02-05 21:19:13 +00001537 if(Function* F = Result->getFunction("llvm.va_end")) {
Reid Spencer950bf602007-01-26 08:19:09 +00001538 if(F->arg_size() != 1) {
1539 error("Obsolete va_end takes 1 argument");
1540 return 0;
Reid Spencerf8383de2007-01-06 06:04:32 +00001541 }
Reid Spencerf8383de2007-01-06 06:04:32 +00001542
Reid Spencer950bf602007-01-26 08:19:09 +00001543 //vaend foo
1544 // ->
1545 //bar = alloca 1 of typeof(foo)
1546 //vaend bar
1547 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1548 const Type* ArgTy = F->getFunctionType()->getParamType(0);
1549 const Type* ArgTyPtr = PointerType::get(ArgTy);
1550 Function* NF = cast<Function>(Result->getOrInsertFunction(
1551 "llvm.va_end", RetTy, ArgTyPtr, (Type *)0));
Reid Spencerf8383de2007-01-06 06:04:32 +00001552
Reid Spencer950bf602007-01-26 08:19:09 +00001553 while (!F->use_empty()) {
1554 CallInst* CI = cast<CallInst>(F->use_back());
1555 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vaend.fix.1", CI);
1556 new StoreInst(CI->getOperand(1), bar, CI);
1557 new CallInst(NF, bar, "", CI);
1558 CI->getParent()->getInstList().erase(CI);
Reid Spencere77e35e2006-12-01 20:26:20 +00001559 }
Reid Spencer950bf602007-01-26 08:19:09 +00001560 Result->getFunctionList().erase(F);
Reid Spencere77e35e2006-12-01 20:26:20 +00001561 }
Reid Spencer950bf602007-01-26 08:19:09 +00001562
Reid Spencer688b0492007-02-05 21:19:13 +00001563 if(Function* F = Result->getFunction("llvm.va_copy")) {
Reid Spencer950bf602007-01-26 08:19:09 +00001564 if(F->arg_size() != 1) {
1565 error("Obsolete va_copy takes 1 argument");
1566 return 0;
Reid Spencere77e35e2006-12-01 20:26:20 +00001567 }
Reid Spencer950bf602007-01-26 08:19:09 +00001568 //foo = vacopy(bar)
1569 // ->
1570 //a = alloca 1 of typeof(foo)
1571 //b = alloca 1 of typeof(foo)
1572 //store bar -> b
1573 //vacopy(a, b)
1574 //foo = load a
1575
1576 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1577 const Type* ArgTy = F->getFunctionType()->getReturnType();
1578 const Type* ArgTyPtr = PointerType::get(ArgTy);
1579 Function* NF = cast<Function>(Result->getOrInsertFunction(
1580 "llvm.va_copy", RetTy, ArgTyPtr, ArgTyPtr, (Type *)0));
Reid Spencere77e35e2006-12-01 20:26:20 +00001581
Reid Spencer950bf602007-01-26 08:19:09 +00001582 while (!F->use_empty()) {
1583 CallInst* CI = cast<CallInst>(F->use_back());
1584 AllocaInst* a = new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI);
1585 AllocaInst* b = new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI);
1586 new StoreInst(CI->getOperand(1), b, CI);
1587 new CallInst(NF, a, b, "", CI);
1588 Value* foo = new LoadInst(a, "vacopy.fix.3", CI);
1589 CI->replaceAllUsesWith(foo);
1590 CI->getParent()->getInstList().erase(CI);
1591 }
1592 Result->getFunctionList().erase(F);
Reid Spencer319a7302007-01-05 17:20:02 +00001593 }
1594 }
1595
Reid Spencer52402b02007-01-02 05:45:11 +00001596 return Result;
1597}
1598
Reid Spencer950bf602007-01-26 08:19:09 +00001599} // end llvm namespace
Reid Spencer319a7302007-01-05 17:20:02 +00001600
Reid Spencer950bf602007-01-26 08:19:09 +00001601using namespace llvm;
Reid Spencer30d0c582007-01-15 00:26:18 +00001602
1603
Chris Lattner4227bdb2007-02-19 07:34:02 +00001604#line 1454 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
1605typedef union {
Reid Spencer950bf602007-01-26 08:19:09 +00001606 llvm::Module *ModuleVal;
1607 llvm::Function *FunctionVal;
1608 std::pair<llvm::PATypeInfo, char*> *ArgVal;
1609 llvm::BasicBlock *BasicBlockVal;
1610 llvm::TerminatorInst *TermInstVal;
1611 llvm::InstrInfo InstVal;
1612 llvm::ConstInfo ConstVal;
1613 llvm::ValueInfo ValueVal;
1614 llvm::PATypeInfo TypeVal;
1615 llvm::TypeInfo PrimType;
1616 llvm::PHIListInfo PHIList;
1617 std::list<llvm::PATypeInfo> *TypeList;
1618 std::vector<llvm::ValueInfo> *ValueList;
1619 std::vector<llvm::ConstInfo> *ConstVector;
1620
1621
1622 std::vector<std::pair<llvm::PATypeInfo,char*> > *ArgList;
1623 // Represent the RHS of PHI node
1624 std::vector<std::pair<llvm::Constant*, llvm::BasicBlock*> > *JumpTable;
1625
1626 llvm::GlobalValue::LinkageTypes Linkage;
1627 int64_t SInt64Val;
1628 uint64_t UInt64Val;
1629 int SIntVal;
1630 unsigned UIntVal;
1631 double FPVal;
1632 bool BoolVal;
1633
1634 char *StrVal; // This memory is strdup'd!
1635 llvm::ValID ValIDVal; // strdup'd memory maybe!
1636
1637 llvm::BinaryOps BinaryOpVal;
1638 llvm::TermOps TermOpVal;
1639 llvm::MemoryOps MemOpVal;
1640 llvm::OtherOps OtherOpVal;
1641 llvm::CastOps CastOpVal;
1642 llvm::ICmpInst::Predicate IPred;
1643 llvm::FCmpInst::Predicate FPred;
1644 llvm::Module::Endianness Endianness;
Chris Lattnercf3d0612007-02-13 06:04:17 +00001645} YYSTYPE;
Chris Lattner4227bdb2007-02-19 07:34:02 +00001646#include <stdio.h>
1647
1648#ifndef __cplusplus
1649#ifndef __STDC__
1650#define const
1651#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00001652#endif
1653
Reid Spencer950bf602007-01-26 08:19:09 +00001654
Reid Spencere7c3c602006-11-30 06:36:44 +00001655
Chris Lattner4227bdb2007-02-19 07:34:02 +00001656#define YYFINAL 605
1657#define YYFLAG -32768
1658#define YYNTBASE 166
Reid Spencere7c3c602006-11-30 06:36:44 +00001659
Chris Lattner4227bdb2007-02-19 07:34:02 +00001660#define YYTRANSLATE(x) ((unsigned)(x) <= 405 ? yytranslate[x] : 245)
Reid Spencere7c3c602006-11-30 06:36:44 +00001661
Chris Lattner4227bdb2007-02-19 07:34:02 +00001662static const short yytranslate[] = { 0,
1663 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1664 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1665 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1666 2, 2, 2, 2, 2, 2, 2, 2, 2, 155,
1667 156, 164, 2, 153, 2, 2, 2, 2, 2, 2,
1668 2, 2, 2, 2, 2, 2, 2, 2, 2, 160,
1669 152, 161, 2, 2, 2, 2, 2, 2, 2, 2,
1670 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1671 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1672 157, 154, 159, 2, 2, 2, 2, 2, 165, 2,
1673 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1674 2, 2, 2, 2, 2, 2, 2, 2, 2, 158,
1675 2, 2, 162, 2, 163, 2, 2, 2, 2, 2,
1676 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1677 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1678 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1679 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1680 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1681 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1682 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1683 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1684 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1685 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1686 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1687 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1688 2, 2, 2, 2, 2, 1, 3, 4, 5, 6,
1689 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
1690 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
1691 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
1692 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
1693 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
1694 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
1695 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
1696 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
1697 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
1698 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
1699 107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
1700 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
1701 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
1702 137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
1703 147, 148, 149, 150, 151
1704};
Reid Spencer950bf602007-01-26 08:19:09 +00001705
Chris Lattner4227bdb2007-02-19 07:34:02 +00001706#if YYDEBUG != 0
1707static const short yyprhs[] = { 0,
1708 0, 2, 4, 6, 8, 10, 12, 14, 16, 18,
1709 20, 22, 24, 26, 28, 30, 32, 34, 36, 38,
1710 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
1711 60, 62, 64, 66, 68, 70, 72, 74, 76, 78,
1712 80, 82, 84, 86, 88, 90, 92, 94, 96, 98,
1713 100, 102, 104, 106, 108, 110, 112, 114, 116, 118,
1714 120, 122, 124, 126, 128, 130, 132, 134, 136, 138,
1715 140, 142, 144, 146, 148, 150, 152, 154, 156, 158,
1716 161, 162, 164, 166, 168, 170, 172, 174, 176, 177,
1717 178, 180, 182, 184, 186, 188, 190, 193, 194, 197,
1718 198, 202, 205, 206, 208, 209, 213, 215, 218, 220,
1719 222, 224, 226, 228, 230, 232, 234, 236, 238, 240,
1720 242, 244, 246, 248, 250, 252, 254, 256, 258, 261,
1721 266, 272, 278, 282, 285, 291, 296, 299, 301, 305,
1722 307, 311, 313, 314, 319, 323, 327, 332, 337, 341,
1723 348, 354, 357, 360, 363, 366, 369, 372, 375, 378,
1724 381, 384, 391, 397, 406, 413, 420, 427, 435, 443,
1725 450, 457, 466, 475, 479, 481, 483, 485, 487, 490,
1726 493, 498, 501, 503, 508, 511, 516, 517, 525, 526,
1727 534, 535, 543, 544, 552, 556, 561, 562, 564, 566,
1728 568, 572, 576, 580, 584, 588, 592, 594, 595, 597,
1729 599, 601, 602, 605, 609, 611, 613, 617, 619, 620,
1730 629, 631, 633, 637, 639, 641, 644, 645, 647, 649,
1731 650, 651, 657, 658, 660, 662, 664, 666, 668, 670,
1732 672, 674, 676, 680, 682, 688, 690, 692, 694, 696,
1733 699, 702, 705, 709, 712, 713, 715, 717, 719, 722,
1734 725, 729, 739, 749, 758, 772, 774, 776, 783, 789,
1735 792, 799, 807, 809, 813, 815, 816, 819, 821, 827,
1736 833, 839, 846, 853, 856, 861, 866, 873, 878, 883,
1737 888, 893, 900, 907, 910, 918, 920, 923, 924, 926,
1738 927, 931, 938, 942, 949, 952, 957, 964
1739};
Chris Lattnercf3d0612007-02-13 06:04:17 +00001740
Chris Lattner4227bdb2007-02-19 07:34:02 +00001741static const short yyrhs[] = { 5,
1742 0, 6, 0, 3, 0, 4, 0, 79, 0, 80,
1743 0, 81, 0, 82, 0, 83, 0, 84, 0, 85,
1744 0, 86, 0, 87, 0, 88, 0, 89, 0, 90,
1745 0, 91, 0, 92, 0, 97, 0, 98, 0, 99,
1746 0, 100, 0, 101, 0, 102, 0, 119, 0, 120,
1747 0, 121, 0, 122, 0, 123, 0, 124, 0, 125,
1748 0, 126, 0, 127, 0, 128, 0, 129, 0, 130,
1749 0, 131, 0, 132, 0, 133, 0, 134, 0, 135,
1750 0, 136, 0, 137, 0, 138, 0, 125, 0, 126,
1751 0, 127, 0, 128, 0, 27, 0, 28, 0, 93,
1752 0, 94, 0, 95, 0, 96, 0, 140, 0, 141,
1753 0, 142, 0, 143, 0, 144, 0, 145, 0, 146,
1754 0, 147, 0, 148, 0, 149, 0, 150, 0, 151,
1755 0, 139, 0, 16, 0, 14, 0, 12, 0, 10,
1756 0, 17, 0, 15, 0, 13, 0, 11, 0, 175,
1757 0, 176, 0, 18, 0, 19, 0, 211, 152, 0,
1758 0, 41, 0, 42, 0, 43, 0, 44, 0, 45,
1759 0, 46, 0, 47, 0, 0, 0, 65, 0, 66,
1760 0, 67, 0, 68, 0, 69, 0, 70, 0, 64,
1761 4, 0, 0, 57, 4, 0, 0, 153, 57, 4,
1762 0, 34, 24, 0, 0, 184, 0, 0, 153, 187,
1763 186, 0, 184, 0, 57, 4, 0, 190, 0, 8,
1764 0, 192, 0, 8, 0, 192, 0, 9, 0, 10,
1765 0, 11, 0, 12, 0, 13, 0, 14, 0, 15,
1766 0, 16, 0, 17, 0, 18, 0, 19, 0, 21,
1767 0, 191, 0, 48, 0, 227, 0, 154, 4, 0,
1768 189, 155, 194, 156, 0, 157, 4, 158, 192, 159,
1769 0, 160, 4, 158, 192, 161, 0, 162, 193, 163,
1770 0, 162, 163, 0, 160, 162, 193, 163, 161, 0,
1771 160, 162, 163, 161, 0, 192, 164, 0, 192, 0,
1772 193, 153, 192, 0, 193, 0, 193, 153, 37, 0,
1773 37, 0, 0, 190, 157, 197, 159, 0, 190, 157,
1774 159, 0, 190, 165, 24, 0, 190, 160, 197, 161,
1775 0, 190, 162, 197, 163, 0, 190, 162, 163, 0,
1776 190, 160, 162, 197, 163, 161, 0, 190, 160, 162,
1777 163, 161, 0, 190, 38, 0, 190, 39, 0, 190,
1778 227, 0, 190, 196, 0, 190, 26, 0, 175, 167,
1779 0, 176, 4, 0, 9, 27, 0, 9, 28, 0,
1780 178, 7, 0, 174, 155, 195, 36, 190, 156, 0,
1781 110, 155, 195, 242, 156, 0, 112, 155, 195, 153,
1782 195, 153, 195, 156, 0, 168, 155, 195, 153, 195,
1783 156, 0, 169, 155, 195, 153, 195, 156, 0, 170,
1784 155, 195, 153, 195, 156, 0, 103, 171, 155, 195,
1785 153, 195, 156, 0, 104, 172, 155, 195, 153, 195,
1786 156, 0, 173, 155, 195, 153, 195, 156, 0, 114,
1787 155, 195, 153, 195, 156, 0, 115, 155, 195, 153,
1788 195, 153, 195, 156, 0, 116, 155, 195, 153, 195,
1789 153, 195, 156, 0, 197, 153, 195, 0, 195, 0,
1790 32, 0, 33, 0, 200, 0, 200, 220, 0, 200,
1791 222, 0, 200, 62, 61, 206, 0, 200, 25, 0,
1792 201, 0, 201, 179, 20, 188, 0, 201, 222, 0,
1793 201, 62, 61, 206, 0, 0, 201, 179, 180, 198,
1794 195, 202, 186, 0, 0, 201, 179, 50, 198, 190,
1795 203, 186, 0, 0, 201, 179, 45, 198, 190, 204,
1796 186, 0, 0, 201, 179, 47, 198, 190, 205, 186,
1797 0, 201, 51, 208, 0, 201, 58, 152, 209, 0,
1798 0, 24, 0, 56, 0, 55, 0, 53, 152, 207,
1799 0, 54, 152, 4, 0, 52, 152, 24, 0, 71,
1800 152, 24, 0, 157, 210, 159, 0, 210, 153, 24,
1801 0, 24, 0, 0, 22, 0, 24, 0, 211, 0,
1802 0, 190, 212, 0, 214, 153, 213, 0, 213, 0,
1803 214, 0, 214, 153, 37, 0, 37, 0, 0, 181,
1804 188, 211, 155, 215, 156, 185, 182, 0, 29, 0,
1805 162, 0, 180, 216, 217, 0, 30, 0, 163, 0,
1806 230, 219, 0, 0, 45, 0, 47, 0, 0, 0,
1807 31, 223, 221, 224, 216, 0, 0, 63, 0, 3,
1808 0, 4, 0, 7, 0, 27, 0, 28, 0, 38,
1809 0, 39, 0, 26, 0, 160, 197, 161, 0, 196,
1810 0, 61, 225, 24, 153, 24, 0, 166, 0, 211,
1811 0, 227, 0, 226, 0, 190, 228, 0, 230, 231,
1812 0, 218, 231, 0, 232, 179, 234, 0, 232, 236,
1813 0, 0, 23, 0, 77, 0, 78, 0, 72, 229,
1814 0, 72, 8, 0, 73, 21, 228, 0, 73, 9,
1815 228, 153, 21, 228, 153, 21, 228, 0, 74, 177,
1816 228, 153, 21, 228, 157, 235, 159, 0, 74, 177,
1817 228, 153, 21, 228, 157, 159, 0, 75, 181, 188,
1818 228, 155, 239, 156, 36, 21, 228, 233, 21, 228,
1819 0, 233, 0, 76, 0, 235, 177, 226, 153, 21,
1820 228, 0, 177, 226, 153, 21, 228, 0, 179, 241,
1821 0, 190, 157, 228, 153, 228, 159, 0, 237, 153,
1822 157, 228, 153, 228, 159, 0, 229, 0, 238, 153,
1823 229, 0, 238, 0, 0, 60, 59, 0, 59, 0,
1824 168, 190, 228, 153, 228, 0, 169, 190, 228, 153,
1825 228, 0, 170, 190, 228, 153, 228, 0, 103, 171,
1826 190, 228, 153, 228, 0, 104, 172, 190, 228, 153,
1827 228, 0, 49, 229, 0, 173, 229, 153, 229, 0,
1828 174, 229, 36, 190, 0, 112, 229, 153, 229, 153,
1829 229, 0, 113, 229, 153, 190, 0, 117, 229, 153,
1830 190, 0, 118, 229, 153, 190, 0, 114, 229, 153,
1831 229, 0, 115, 229, 153, 229, 153, 229, 0, 116,
1832 229, 153, 229, 153, 229, 0, 111, 237, 0, 240,
1833 181, 188, 228, 155, 239, 156, 0, 244, 0, 153,
1834 238, 0, 0, 35, 0, 0, 105, 190, 183, 0,
1835 105, 190, 153, 15, 228, 183, 0, 106, 190, 183,
1836 0, 106, 190, 153, 15, 228, 183, 0, 107, 229,
1837 0, 243, 108, 190, 228, 0, 243, 109, 229, 153,
1838 190, 228, 0, 110, 190, 228, 242, 0
1839};
Chris Lattnercf3d0612007-02-13 06:04:17 +00001840
Reid Spencere7c3c602006-11-30 06:36:44 +00001841#endif
1842
Chris Lattner4227bdb2007-02-19 07:34:02 +00001843#if YYDEBUG != 0
1844static const short yyrline[] = { 0,
1845 1594, 1595, 1603, 1604, 1614, 1614, 1614, 1614, 1614, 1614,
1846 1614, 1614, 1614, 1614, 1614, 1618, 1618, 1618, 1622, 1622,
1847 1622, 1622, 1622, 1622, 1626, 1626, 1627, 1627, 1628, 1628,
1848 1629, 1629, 1630, 1630, 1634, 1634, 1635, 1635, 1636, 1636,
1849 1637, 1637, 1638, 1638, 1639, 1639, 1640, 1640, 1641, 1642,
1850 1645, 1645, 1645, 1645, 1649, 1649, 1649, 1649, 1649, 1649,
1851 1649, 1650, 1650, 1650, 1650, 1650, 1650, 1656, 1656, 1656,
1852 1656, 1660, 1660, 1660, 1660, 1664, 1664, 1668, 1668, 1673,
1853 1676, 1681, 1682, 1683, 1684, 1685, 1686, 1687, 1688, 1692,
1854 1693, 1694, 1695, 1696, 1697, 1698, 1699, 1709, 1710, 1718,
1855 1719, 1727, 1736, 1737, 1744, 1745, 1749, 1753, 1769, 1770,
1856 1777, 1778, 1785, 1793, 1793, 1793, 1793, 1793, 1793, 1793,
1857 1794, 1794, 1794, 1794, 1794, 1799, 1803, 1807, 1812, 1821,
1858 1838, 1844, 1857, 1866, 1870, 1881, 1885, 1898, 1902, 1909,
1859 1910, 1916, 1923, 1935, 1965, 1978, 2001, 2029, 2051, 2062,
1860 2084, 2095, 2104, 2109, 2167, 2174, 2182, 2189, 2196, 2200,
1861 2204, 2213, 2228, 2241, 2250, 2278, 2291, 2300, 2306, 2312,
1862 2323, 2329, 2335, 2346, 2347, 2356, 2357, 2369, 2378, 2379,
1863 2380, 2381, 2382, 2398, 2418, 2420, 2422, 2426, 2429, 2433,
1864 2436, 2440, 2443, 2448, 2451, 2453, 2455, 2460, 2474, 2475,
1865 2479, 2482, 2490, 2494, 2501, 2505, 2509, 2513, 2521, 2521,
1866 2525, 2526, 2530, 2538, 2543, 2551, 2552, 2559, 2566, 2570,
1867 2746, 2746, 2750, 2760, 2760, 2764, 2769, 2770, 2771, 2775,
1868 2776, 2776, 2788, 2789, 2794, 2795, 2796, 2797, 2798, 2799,
1869 2800, 2801, 2802, 2823, 2826, 2841, 2842, 2847, 2847, 2855,
1870 2864, 2867, 2876, 2886, 2891, 2900, 2911, 2911, 2914, 2917,
1871 2920, 2924, 2930, 2945, 2951, 3007, 3010, 3016, 3026, 3039,
1872 3068, 3076, 3084, 3088, 3095, 3096, 3100, 3103, 3109, 3126,
1873 3142, 3156, 3168, 3180, 3191, 3209, 3218, 3227, 3234, 3255,
1874 3279, 3285, 3291, 3297, 3313, 3391, 3399, 3400, 3404, 3405,
1875 3409, 3415, 3421, 3427, 3433, 3440, 3452, 3477
1876};
1877#endif
1878
1879
1880#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
1881
1882static const char * const yytname[] = { "$","error","$undefined.","ESINT64VAL",
1883"EUINT64VAL","SINTVAL","UINTVAL","FPVAL","VOID","BOOL","SBYTE","UBYTE","SHORT",
1884"USHORT","INT","UINT","LONG","ULONG","FLOAT","DOUBLE","TYPE","LABEL","VAR_ID",
1885"LABELSTR","STRINGCONSTANT","IMPLEMENTATION","ZEROINITIALIZER","TRUETOK","FALSETOK",
1886"BEGINTOK","ENDTOK","DECLARE","GLOBAL","CONSTANT","SECTION","VOLATILE","TO",
1887"DOTDOTDOT","NULL_TOK","UNDEF","CONST","INTERNAL","LINKONCE","WEAK","APPENDING",
1888"DLLIMPORT","DLLEXPORT","EXTERN_WEAK","OPAQUE","NOT","EXTERNAL","TARGET","TRIPLE",
1889"ENDIAN","POINTERSIZE","LITTLE","BIG","ALIGN","DEPLIBS","CALL","TAIL","ASM_TOK",
1890"MODULE","SIDEEFFECT","CC_TOK","CCC_TOK","CSRETCC_TOK","FASTCC_TOK","COLDCC_TOK",
1891"X86_STDCALLCC_TOK","X86_FASTCALLCC_TOK","DATALAYOUT","RET","BR","SWITCH","INVOKE",
1892"UNREACHABLE","UNWIND","EXCEPT","ADD","SUB","MUL","DIV","UDIV","SDIV","FDIV",
1893"REM","UREM","SREM","FREM","AND","OR","XOR","SHL","SHR","ASHR","LSHR","SETLE",
1894"SETGE","SETLT","SETGT","SETEQ","SETNE","ICMP","FCMP","MALLOC","ALLOCA","FREE",
1895"LOAD","STORE","GETELEMENTPTR","PHI_TOK","SELECT","VAARG","EXTRACTELEMENT","INSERTELEMENT",
1896"SHUFFLEVECTOR","VAARG_old","VANEXT_old","EQ","NE","SLT","SGT","SLE","SGE","ULT",
1897"UGT","ULE","UGE","OEQ","ONE","OLT","OGT","OLE","OGE","ORD","UNO","UEQ","UNE",
1898"CAST","TRUNC","ZEXT","SEXT","FPTRUNC","FPEXT","FPTOUI","FPTOSI","UITOFP","SITOFP",
1899"PTRTOINT","INTTOPTR","BITCAST","'='","','","'\\\\'","'('","')'","'['","'x'",
1900"']'","'<'","'>'","'{'","'}'","'*'","'c'","INTVAL","EINT64VAL","ArithmeticOps",
1901"LogicalOps","SetCondOps","IPredicates","FPredicates","ShiftOps","CastOps","SIntType",
1902"UIntType","IntType","FPType","OptAssign","OptLinkage","OptCallingConv","OptAlign",
1903"OptCAlign","SectionString","OptSection","GlobalVarAttributes","GlobalVarAttribute",
1904"TypesV","UpRTypesV","Types","PrimType","UpRTypes","TypeListI","ArgTypeListI",
1905"ConstVal","ConstExpr","ConstVector","GlobalType","Module","FunctionList","ConstPool",
1906"@1","@2","@3","@4","AsmBlock","BigOrLittle","TargetDefinition","LibrariesDefinition",
1907"LibList","Name","OptName","ArgVal","ArgListH","ArgList","FunctionHeaderH","BEGIN",
1908"FunctionHeader","END","Function","FnDeclareLinkage","FunctionProto","@5","@6",
1909"OptSideEffect","ConstValueRef","SymbolicValueRef","ValueRef","ResolvedVal",
1910"BasicBlockList","BasicBlock","InstructionList","Unwind","BBTerminatorInst",
1911"JumpTable","Inst","PHIList","ValueRefList","ValueRefListE","OptTailCall","InstVal",
1912"IndexList","OptVolatile","MemoryInst", NULL
1913};
1914#endif
1915
1916static const short yyr1[] = { 0,
1917 166, 166, 167, 167, 168, 168, 168, 168, 168, 168,
1918 168, 168, 168, 168, 168, 169, 169, 169, 170, 170,
1919 170, 170, 170, 170, 171, 171, 171, 171, 171, 171,
1920 171, 171, 171, 171, 172, 172, 172, 172, 172, 172,
1921 172, 172, 172, 172, 172, 172, 172, 172, 172, 172,
1922 173, 173, 173, 173, 174, 174, 174, 174, 174, 174,
1923 174, 174, 174, 174, 174, 174, 174, 175, 175, 175,
1924 175, 176, 176, 176, 176, 177, 177, 178, 178, 179,
1925 179, 180, 180, 180, 180, 180, 180, 180, 180, 181,
1926 181, 181, 181, 181, 181, 181, 181, 182, 182, 183,
1927 183, 184, 185, 185, 186, 186, 187, 187, 188, 188,
1928 189, 189, 190, 191, 191, 191, 191, 191, 191, 191,
1929 191, 191, 191, 191, 191, 192, 192, 192, 192, 192,
1930 192, 192, 192, 192, 192, 192, 192, 193, 193, 194,
1931 194, 194, 194, 195, 195, 195, 195, 195, 195, 195,
1932 195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
1933 195, 196, 196, 196, 196, 196, 196, 196, 196, 196,
1934 196, 196, 196, 197, 197, 198, 198, 199, 200, 200,
1935 200, 200, 200, 201, 201, 201, 202, 201, 203, 201,
1936 204, 201, 205, 201, 201, 201, 201, 206, 207, 207,
1937 208, 208, 208, 208, 209, 210, 210, 210, 211, 211,
1938 212, 212, 213, 214, 214, 215, 215, 215, 215, 216,
1939 217, 217, 218, 219, 219, 220, 221, 221, 221, 223,
1940 224, 222, 225, 225, 226, 226, 226, 226, 226, 226,
1941 226, 226, 226, 226, 226, 227, 227, 228, 228, 229,
1942 230, 230, 231, 232, 232, 232, 233, 233, 234, 234,
1943 234, 234, 234, 234, 234, 234, 234, 235, 235, 236,
1944 237, 237, 238, 238, 239, 239, 240, 240, 241, 241,
1945 241, 241, 241, 241, 241, 241, 241, 241, 241, 241,
1946 241, 241, 241, 241, 241, 241, 242, 242, 243, 243,
1947 244, 244, 244, 244, 244, 244, 244, 244
1948};
1949
1950static const short yyr2[] = { 0,
1951 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1952 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1953 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1954 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1955 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1956 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1957 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1958 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
1959 0, 1, 1, 1, 1, 1, 1, 1, 0, 0,
1960 1, 1, 1, 1, 1, 1, 2, 0, 2, 0,
1961 3, 2, 0, 1, 0, 3, 1, 2, 1, 1,
1962 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1963 1, 1, 1, 1, 1, 1, 1, 1, 2, 4,
1964 5, 5, 3, 2, 5, 4, 2, 1, 3, 1,
1965 3, 1, 0, 4, 3, 3, 4, 4, 3, 6,
1966 5, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1967 2, 6, 5, 8, 6, 6, 6, 7, 7, 6,
1968 6, 8, 8, 3, 1, 1, 1, 1, 2, 2,
1969 4, 2, 1, 4, 2, 4, 0, 7, 0, 7,
1970 0, 7, 0, 7, 3, 4, 0, 1, 1, 1,
1971 3, 3, 3, 3, 3, 3, 1, 0, 1, 1,
1972 1, 0, 2, 3, 1, 1, 3, 1, 0, 8,
1973 1, 1, 3, 1, 1, 2, 0, 1, 1, 0,
1974 0, 5, 0, 1, 1, 1, 1, 1, 1, 1,
1975 1, 1, 3, 1, 5, 1, 1, 1, 1, 2,
1976 2, 2, 3, 2, 0, 1, 1, 1, 2, 2,
1977 3, 9, 9, 8, 13, 1, 1, 6, 5, 2,
1978 6, 7, 1, 3, 1, 0, 2, 1, 5, 5,
1979 5, 6, 6, 2, 4, 4, 6, 4, 4, 4,
1980 4, 6, 6, 2, 7, 1, 2, 0, 1, 0,
1981 3, 6, 3, 6, 2, 4, 6, 4
1982};
1983
1984static const short yydefact[] = { 197,
1985 89, 183, 182, 230, 82, 83, 84, 85, 86, 87,
1986 88, 0, 90, 255, 179, 180, 255, 209, 210, 0,
1987 0, 0, 89, 0, 185, 227, 0, 0, 91, 92,
1988 93, 94, 95, 96, 0, 0, 256, 252, 81, 224,
1989 225, 226, 251, 0, 0, 0, 0, 195, 0, 0,
1990 0, 0, 0, 0, 0, 80, 228, 229, 231, 198,
1991 181, 97, 1, 2, 110, 114, 115, 116, 117, 118,
1992 119, 120, 121, 122, 123, 124, 125, 127, 0, 0,
1993 0, 0, 246, 0, 0, 109, 126, 113, 247, 128,
1994 221, 222, 223, 300, 254, 0, 0, 0, 0, 208,
1995 196, 186, 184, 176, 177, 0, 0, 0, 0, 90,
1996 129, 0, 0, 0, 112, 134, 138, 0, 0, 143,
1997 137, 299, 0, 278, 0, 0, 0, 0, 90, 267,
1998 257, 258, 5, 6, 7, 8, 9, 10, 11, 12,
1999 13, 14, 15, 16, 17, 18, 51, 52, 53, 54,
2000 19, 20, 21, 22, 23, 24, 0, 0, 0, 0,
2001 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2002 67, 55, 56, 57, 58, 59, 60, 61, 62, 63,
2003 64, 65, 66, 0, 0, 0, 0, 0, 266, 253,
2004 90, 270, 0, 296, 203, 200, 199, 201, 202, 204,
2005 207, 0, 191, 193, 189, 114, 115, 116, 117, 118,
2006 119, 120, 121, 122, 123, 124, 0, 0, 0, 0,
2007 187, 232, 0, 0, 0, 0, 0, 133, 219, 142,
2008 140, 0, 0, 284, 277, 260, 259, 0, 0, 71,
2009 75, 70, 74, 69, 73, 68, 72, 76, 77, 0,
2010 0, 25, 26, 27, 28, 29, 30, 31, 32, 33,
2011 34, 0, 49, 50, 45, 46, 47, 48, 35, 36,
2012 37, 38, 39, 40, 41, 42, 43, 44, 0, 100,
2013 100, 305, 0, 0, 294, 0, 0, 0, 0, 0,
2014 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2015 0, 205, 105, 105, 105, 159, 160, 3, 4, 157,
2016 158, 161, 156, 152, 153, 0, 0, 0, 0, 0,
2017 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2018 0, 155, 154, 105, 111, 111, 136, 0, 139, 218,
2019 212, 215, 216, 0, 0, 130, 235, 236, 237, 242,
2020 238, 239, 240, 241, 233, 0, 244, 249, 248, 250,
2021 0, 261, 0, 0, 0, 0, 0, 301, 0, 303,
2022 298, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2023 0, 0, 0, 0, 0, 0, 0, 0, 206, 0,
2024 192, 194, 190, 0, 0, 0, 0, 0, 0, 0,
2025 145, 175, 0, 0, 0, 149, 0, 146, 0, 0,
2026 0, 0, 0, 188, 131, 132, 135, 211, 213, 0,
2027 103, 141, 234, 0, 0, 0, 0, 0, 0, 0,
2028 0, 0, 0, 0, 308, 0, 0, 0, 288, 291,
2029 0, 0, 289, 290, 0, 0, 0, 285, 286, 0,
2030 306, 0, 0, 0, 107, 105, 0, 0, 298, 0,
2031 0, 0, 0, 0, 144, 134, 113, 0, 147, 148,
2032 0, 0, 0, 0, 0, 217, 214, 104, 98, 0,
2033 243, 0, 0, 276, 0, 0, 100, 101, 100, 273,
2034 297, 0, 0, 0, 0, 0, 279, 280, 281, 276,
2035 0, 102, 108, 106, 0, 0, 0, 0, 0, 0,
2036 0, 174, 151, 0, 0, 0, 0, 0, 0, 0,
2037 220, 0, 0, 0, 275, 0, 282, 283, 0, 302,
2038 304, 0, 0, 0, 287, 292, 293, 0, 307, 0,
2039 0, 163, 0, 0, 0, 0, 150, 0, 0, 0,
2040 0, 0, 99, 245, 0, 0, 0, 274, 271, 0,
2041 295, 0, 0, 0, 171, 0, 0, 165, 166, 167,
2042 170, 162, 0, 264, 0, 0, 0, 272, 168, 169,
2043 0, 0, 0, 262, 0, 263, 0, 0, 164, 172,
2044 173, 0, 0, 0, 0, 0, 0, 269, 0, 0,
2045 268, 265, 0, 0, 0
2046};
2047
2048static const short yydefgoto[] = { 83,
2049 310, 327, 328, 329, 262, 279, 330, 331, 217, 218,
2050 250, 219, 23, 13, 35, 521, 368, 455, 479, 391,
2051 456, 84, 85, 220, 87, 88, 118, 232, 402, 357,
2052 403, 106, 603, 1, 2, 334, 305, 303, 304, 61,
2053 198, 48, 101, 202, 89, 419, 342, 343, 344, 36,
2054 93, 14, 42, 15, 59, 16, 26, 110, 424, 358,
2055 90, 360, 490, 17, 38, 39, 189, 190, 576, 95,
2056 285, 525, 526, 191, 192, 435, 193, 194
2057};
2058
2059static const short yypact[] = {-32768,
2060 58, 247,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2061-32768, -44, 181, 69,-32768,-32768, 10,-32768,-32768, 16,
2062 -116, 34, 65, -38,-32768, 112, 118, 144,-32768,-32768,
2063-32768,-32768,-32768,-32768, 1357, -19,-32768,-32768, 39,-32768,
2064-32768,-32768,-32768, 6, 12, 20, 23,-32768, 55, 118,
2065 1357, 86, 86, 86, 86,-32768,-32768,-32768,-32768,-32768,
2066-32768,-32768,-32768,-32768, 36,-32768,-32768,-32768,-32768,-32768,
2067-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 210, 218,
2068 1, 171,-32768, 39, 73,-32768,-32768, -42,-32768,-32768,
2069-32768,-32768,-32768, 1611,-32768, 215, 83, 236, 219, 233,
2070-32768,-32768,-32768,-32768,-32768, 1418, 1418, 1418, 1459, 181,
2071-32768, 84, 100, 737,-32768,-32768, -42, -99, 104, 803,
2072-32768,-32768, 1418,-32768, 201, 1479, 14, 221, 181,-32768,
2073-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2074-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2075-32768,-32768,-32768,-32768,-32768,-32768, 77, 377, 1418, 1418,
2076 1418, 1418, 1418, 1418, 1418, 1418, 1418, 1418, 1418, 1418,
2077-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2078-32768,-32768,-32768, 1418, 1418, 1418, 1418, 1418,-32768,-32768,
2079 181,-32768, 53,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2080-32768, -36,-32768,-32768,-32768, 140, 167, 257, 204, 262,
2081 206, 264, 214, 266, 265, 268, 217, 269, 270, 579,
2082-32768,-32768, 1418, 1418, 115, -96, 1418,-32768, 1199,-32768,
2083 128, 126, 920,-32768,-32768, 36,-32768, 920, 920,-32768,
2084-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 920,
2085 1357,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2086-32768, 1418,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2087-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 1418, 130,
2088 142,-32768, 920, 139, 151, 153, 154, 155, 157, 158,
2089 164, 165, 920, 920, 920, 166, 284, 1357, 1418, 1418,
2090 297,-32768, 169, 169, 169,-32768,-32768,-32768,-32768,-32768,
2091-32768,-32768,-32768,-32768,-32768, 77, 377, 168, 172, 174,
2092 175, 177, 1240, 1520, 757, 300, 180, 182, 183, 192,
2093 193,-32768,-32768, 169, -43, -71,-32768, 190, -42,-32768,
2094 39,-32768, 173, 202, 1260,-32768,-32768,-32768,-32768,-32768,
2095-32768,-32768,-32768,-32768, 273, 1459,-32768,-32768,-32768,-32768,
2096 209,-32768, 212, 920, 920, 920, -4,-32768, -2,-32768,
2097 213, 920, 211, 1418, 1418, 1418, 1418, 1418, 1418, 1418,
2098 216, 222, 223, 1418, 1418, 920, 920, 226,-32768, -20,
2099-32768,-32768,-32768, 225, 227, 1459, 1459, 1459, 1459, 1459,
2100-32768,-32768, -13, 778, -17,-32768, -69,-32768, 1459, 1459,
2101 1459, 1459, 1459,-32768,-32768,-32768,-32768,-32768,-32768, 1301,
2102 325,-32768,-32768, 346, -16, 350, 360, 228, 231, 234,
2103 920, 382, 920, 1418,-32768, 235, 920, 237,-32768,-32768,
2104 238, 239,-32768,-32768, 920, 920, 920,-32768,-32768, 240,
2105-32768, 1418, 365, 389,-32768, 169, 1459, 1459, 213, 241,
2106 243, 245, 248, 1459,-32768, 242, -104, -67,-32768,-32768,
2107 249, 253, 263, 272, 364,-32768,-32768,-32768, 358, 274,
2108-32768, 920, 920, 1418, 920, 920, 276,-32768, 276,-32768,
2109 279, 920, 280, 1418, 1418, 1418,-32768,-32768,-32768, 1418,
2110 920,-32768,-32768,-32768, 281, 282, 267, 1459, 1459, 1459,
2111 1459,-32768,-32768, 278, 1459, 1459, 1459, 1459, 1418, 422,
2112-32768, 416, 288, 285, 279, 289,-32768,-32768, 390,-32768,
2113-32768, 1418, 287, 920,-32768,-32768,-32768, 292,-32768, 1459,
2114 1459,-32768, 299, 298, 302, 303,-32768, 301, 306, 307,
2115 308, 310,-32768,-32768, 432, 15, 435,-32768,-32768, 309,
2116-32768, 316, 319, 1459,-32768, 1459, 1459,-32768,-32768,-32768,
2117-32768,-32768, 920,-32768, 1046, 64, 437,-32768,-32768,-32768,
2118 326, 329, 331,-32768, 328,-32768, 1046, 920,-32768,-32768,
2119-32768, 467, 336, 148, 920, 469, 470,-32768, 920, 920,
2120-32768,-32768, 493, 494,-32768
2121};
2122
2123static const short yypgoto[] = {-32768,
2124-32768, 401, 402, 404, 200, 203, 405, 423, -126, -125,
2125 -535,-32768, 479, 496, -109,-32768, -274, 102,-32768, -296,
2126-32768, -45,-32768, -35,-32768, -58, 27,-32768, -97, 304,
2127 -306, 101,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 471,
2128-32768,-32768,-32768,-32768, 13,-32768, 106,-32768,-32768, 412,
2129-32768,-32768,-32768,-32768,-32768, 525,-32768,-32768,-32768, -553,
2130 -9, 114, -122,-32768, 511,-32768, -65,-32768,-32768,-32768,
2131-32768, 96, 31,-32768,-32768, 74,-32768,-32768
2132};
2133
2134
2135#define YYLAST 1762
2136
2137
2138static const short yytable[] = { 86,
2139 234, 248, 249, 237, 113, 103, 370, 392, 393, 91,
2140 431, 221, 433, 453, 24, 86, 27, 405, 407, 251,
2141 575, 585, 238, 117, 240, 241, 242, 243, 244, 245,
2142 246, 247, 37, 593, 239, 49, 454, 414, 282, 40,
2143 587, 286, 287, 288, 289, 290, 291, 292, -138, 425,
2144 -111, 24, 432, 227, 432, 117, 227, -178, -138, 121,
2145 18, 117, 19, 228, 296, 297, 338, 44, 45, 46,
2146 203, 204, 205, 240, 241, 242, 243, 244, 245, 246,
2147 247, 298, 3, 464, 51, 464, 47, 233, 4, 416,
2148 233, 37, 121, 470, 50, 514, 119, 468, 5, 6,
2149 7, 8, 9, 10, 11, 5, 6, 7, 8, 52,
2150 10, 53, -111, 56, 54, 415, 301, 104, 105, 12,
2151 121, 121, 302, 280, 281, 233, 283, 284, 233, 233,
2152 233, 233, 233, 233, 233, 464, 464, 196, 197, 464,
2153 226, 60, 92, 469, 481, 465, 231, 62, 293, 294,
2154 295, 233, 233, 107, 108, 109, 57, 96, 58, 504,
2155 299, 300, 114, 97, 335, 336, 306, 307, 339, -71,
2156 -71, 98, 41, 574, 99, 63, 64, 388, 115, 66,
2157 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
2158 -112, 77, 18, 341, 19, 252, 253, 254, 255, 256,
2159 257, 258, 259, 260, 261, 364, -70, -70, -69, -69,
2160 333, 100, 530, 111, 531, 86, -68, -68, 78, 308,
2161 309, 112, 586, 359, 131, 132, 365, 120, 359, 359,
2162 240, 241, 242, 243, 244, 245, 246, 247, 195, 199,
2163 359, 223, 200, 366, 28, 29, 30, 31, 32, 33,
2164 34, 438, 386, 440, 441, 442, 201, 224, 229, 235,
2165 -75, 448, 86, 387, 233, -74, -81, -73, 18, -72,
2166 19, -78, 311, 359, -79, 337, 312, 4, -81, -81,
2167 345, 346, 367, 359, 359, 359, 339, -81, -81, -81,
2168 -81, -81, -81, -81, 369, 372, -81, 20, 459, 460,
2169 461, 462, 463, 373, 21, 374, 375, 376, 22, 377,
2170 378, 471, 472, 473, 474, 475, 379, 380, 384, 385,
2171 389, 390, 396, 408, 79, 420, 397, 80, 398, 399,
2172 81, 400, 82, 116, 409, 423, 410, 411, 233, 439,
2173 233, 233, 233, 443, 444, 467, 412, 413, 233, 449,
2174 417, 361, 362, 418, 359, 359, 359, 421, 453, 505,
2175 506, 426, 359, 363, 427, 434, 512, 437, 445, 480,
2176 482, 535, 536, 537, 446, 447, 359, 359, 452, 457,
2177 483, 458, 484, 485, 341, 488, 486, 492, 502, 494,
2178 495, 496, 503, 508, 500, 509, 371, 510, 233, 519,
2179 511, 515, 513, 263, 264, 516, 381, 382, 383, 558,
2180 543, 544, 545, 546, 520, 517, 501, 548, 549, 550,
2181 551, 359, 542, 359, 518, 553, 522, 359, 529, 248,
2182 249, 532, 534, 540, 541, 359, 359, 359, 547, 554,
2183 555, 556, 562, 563, 557, 559, 432, 561, 233, 248,
2184 249, 564, 573, 565, 566, 567, 568, 588, 233, 233,
2185 233, 569, 570, 571, 233, 572, 581, 578, 582, 583,
2186 577, 579, 359, 359, 580, 359, 359, 428, 429, 430,
2187 592, 589, 359, 552, 590, 436, 591, 595, 596, 599,
2188 600, 359, 604, 605, 184, 185, 233, 186, 187, 450,
2189 451, 265, 266, 267, 268, 269, 270, 271, 272, 273,
2190 274, 275, 276, 277, 278, 394, 188, 94, 55, 395,
2191 102, 222, 478, 332, 359, 477, 25, 43, 597, 491,
2192 538, 0, 507, 0, 0, 0, 0, 0, 0, 0,
2193 0, 0, 0, 0, 487, 0, 489, 0, 0, 0,
2194 493, 0, 0, 0, 0, 0, 0, 0, 497, 498,
2195 499, 0, 0, 359, 0, 0, 0, 0, 0, 0,
2196 0, 0, 0, 0, 0, 0, 0, 0, 359, 0,
2197 0, 0, 0, 63, 64, 359, 0, 0, 0, 359,
2198 359, 0, 0, 0, 0, 523, 524, 0, 527, 528,
2199 18, 0, 19, 0, 313, 533, 0, 0, 0, 0,
2200 0, 0, 0, 0, 539, 0, 314, 315, 0, 0,
2201 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2202 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2203 0, 0, 0, 0, 0, 0, 0, 560, 0, 0,
2204 0, 0, 0, 0, 0, 0, 0, 133, 134, 135,
2205 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
2206 146, 147, 148, 149, 150, 151, 152, 153, 154, 155,
2207 156, 316, 317, 0, 0, 0, 584, 0, 318, 0,
2208 319, 0, 320, 321, 322, 0, 0, 0, 0, 0,
2209 0, 594, 0, 0, 0, 0, 0, 0, 598, 0,
2210 0, 0, 601, 602, 0, 0, 0, 171, 172, 173,
2211 174, 175, 176, 177, 178, 179, 180, 181, 182, 183,
2212 0, 0, 0, 0, 0, 323, 0, 0, 324, 0,
2213 325, 63, 64, 326, 115, 66, 67, 68, 69, 70,
2214 71, 72, 73, 74, 75, 76, 0, 77, 18, 0,
2215 19, 63, 64, 0, 115, 206, 207, 208, 209, 210,
2216 211, 212, 213, 214, 215, 216, 0, 77, 18, 0,
2217 19, 0, 63, 64, 78, 115, 206, 207, 208, 209,
2218 210, 211, 212, 213, 214, 215, 216, 0, 77, 18,
2219 0, 19, 0, 0, 78, 0, 0, 63, 64, 0,
2220 115, 66, 67, 68, 69, 70, 71, 72, 73, 74,
2221 75, 76, 0, 77, 18, 78, 19, 0, 0, 0,
2222 0, 0, 0, 0, 0, 0, 0, 0, 0, 230,
2223 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2224 78, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2225 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2226 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2227 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2228 79, 0, 0, 80, 0, 0, 81, 0, 82, 225,
2229 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2230 79, 0, 0, 80, 0, 0, 81, 0, 82, 406,
2231 0, 0, 347, 348, 63, 64, 349, 0, 0, 0,
2232 0, 79, 0, 0, 80, 0, 0, 81, 0, 82,
2233 466, 18, 0, 19, 0, 350, 351, 352, 0, 0,
2234 0, 0, 0, 0, 0, 0, 79, 353, 354, 80,
2235 0, 0, 81, 0, 82, 0, 0, 0, 0, 0,
2236 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2237 355, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2238 0, 0, 0, 0, 0, 0, 0, 0, 133, 134,
2239 135, 136, 137, 138, 139, 140, 141, 142, 143, 144,
2240 145, 146, 147, 148, 149, 150, 151, 152, 153, 154,
2241 155, 156, 316, 317, 0, 0, 0, 0, 0, 318,
2242 0, 319, 0, 320, 321, 322, 0, 0, 0, 0,
2243 0, 0, 0, 0, 0, 0, 0, 0, 347, 348,
2244 0, 0, 349, 0, 0, 0, 0, 0, 171, 172,
2245 173, 174, 175, 176, 177, 178, 179, 180, 181, 182,
2246 183, 350, 351, 352, 0, 0, 0, 0, 0, 356,
2247 0, 0, 0, 353, 354, 0, 0, 0, 0, 0,
2248 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2249 0, 0, 0, 0, 0, 0, 355, 0, 0, 0,
2250 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2251 0, 0, 0, 0, 133, 134, 135, 136, 137, 138,
2252 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
2253 149, 150, 151, 152, 153, 154, 155, 156, 316, 317,
2254 0, 0, 0, 0, 0, 318, 0, 319, 0, 320,
2255 321, 322, 0, 0, 0, 0, 0, 0, 0, 0,
2256 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2257 0, 0, 0, 0, 171, 172, 173, 174, 175, 176,
2258 177, 178, 179, 180, 181, 182, 183, 0, 0, 0,
2259 0, 0, 0, 63, 64, 356, 115, 66, 67, 68,
2260 69, 70, 71, 72, 73, 74, 75, 76, 0, 77,
2261 18, 0, 19, 0, 0, 0, 0, 0, 0, 0,
2262 0, 0, 0, 0, 0, 340, 0, 0, 0, 0,
2263 0, 0, 0, 0, 63, 64, 78, 115, 206, 207,
2264 208, 209, 210, 211, 212, 213, 214, 215, 216, 0,
2265 77, 18, 0, 19, 63, 64, 0, 115, 66, 67,
2266 68, 69, 70, 71, 72, 73, 74, 75, 76, 0,
2267 77, 18, 0, 19, 0, 0, 0, 78, 0, 0,
2268 0, 0, 0, 0, 0, 0, 422, 0, 0, 0,
2269 0, 0, 0, 0, 0, 63, 64, 78, 115, 66,
2270 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
2271 0, 77, 18, 0, 19, 0, 0, 0, 0, 0,
2272 0, 0, 0, 0, 0, 0, 0, 476, 0, 0,
2273 0, 0, 0, 0, 0, 0, 0, 0, 78, 0,
2274 0, 0, 79, 0, 0, 80, 0, 0, 81, 0,
2275 82, 63, 64, 0, 65, 66, 67, 68, 69, 70,
2276 71, 72, 73, 74, 75, 76, 0, 77, 18, 0,
2277 19, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2278 0, 0, 0, 79, 0, 0, 80, 0, 401, 81,
2279 0, 82, 0, 0, 78, 0, 0, 0, 0, 0,
2280 0, 0, 0, 79, 0, 0, 80, 0, 0, 81,
2281 0, 82, 63, 64, 0, 115, 66, 67, 68, 69,
2282 70, 71, 72, 73, 74, 75, 76, 0, 77, 18,
2283 0, 19, 0, 0, 0, 0, 0, 0, 0, 0,
2284 0, 0, 0, 0, 79, 0, 0, 80, 0, 0,
2285 81, 0, 82, 63, 64, 78, 115, 206, 207, 208,
2286 209, 210, 211, 212, 213, 214, 215, 216, 0, 77,
2287 18, 0, 19, 63, 64, 0, 236, 66, 67, 68,
2288 69, 70, 71, 72, 73, 74, 75, 76, 0, 77,
2289 18, 0, 19, 0, 0, 0, 78, 0, 0, 0,
2290 79, 0, 0, 80, 0, 0, 81, 0, 82, 0,
2291 0, 0, 0, 0, 63, 64, 78, 115, 206, 207,
2292 208, 209, 210, 211, 212, 213, 214, 215, 216, 0,
2293 77, 18, 0, 19, 0, 0, 0, 0, 0, 0,
2294 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2295 0, 0, 0, 0, 0, 0, 0, 78, 0, 0,
2296 0, 79, 0, 0, 80, 0, 0, 81, 0, 82,
2297 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2298 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2299 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2300 0, 0, 79, 0, 0, 80, 0, 0, 81, 0,
2301 82, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2302 0, 0, 79, 0, 0, 80, 0, 0, 81, 0,
2303 82, 0, 0, 0, 0, 122, 0, 0, 0, 0,
2304 0, 0, 0, 0, 0, 0, 0, 0, 0, 123,
2305 0, 0, 0, 0, 0, 0, 0, 0, 0, 124,
2306 125, 0, 0, 79, 0, 0, 80, 0, 0, 81,
2307 0, 404, 126, 127, 128, 129, 130, 131, 132, 133,
2308 134, 135, 136, 137, 138, 139, 140, 141, 142, 143,
2309 144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
2310 154, 155, 156, 157, 158, 159, 160, 161, 0, 0,
2311 162, 163, 164, 165, 166, 167, 168, 169, 170, 0,
2312 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2313 0, 0, 0, 0, 0, 0, 0, 0, 0, 171,
2314 172, 173, 174, 175, 176, 177, 178, 179, 180, 181,
2315 182, 183
2316};
2317
2318static const short yycheck[] = { 35,
2319 123, 128, 128, 126, 4, 51, 281, 304, 305, 29,
2320 15, 109, 15, 34, 2, 51, 61, 324, 325, 129,
2321 556, 575, 9, 82, 10, 11, 12, 13, 14, 15,
2322 16, 17, 23, 587, 21, 152, 57, 334, 161, 30,
2323 576, 164, 165, 166, 167, 168, 169, 170, 153, 356,
2324 155, 39, 57, 153, 57, 114, 153, 0, 163, 164,
2325 22, 120, 24, 163, 187, 188, 163, 52, 53, 54,
2326 106, 107, 108, 10, 11, 12, 13, 14, 15, 16,
2327 17, 191, 25, 153, 20, 153, 71, 123, 31, 161,
2328 126, 23, 164, 163, 61, 163, 84, 404, 41, 42,
2329 43, 44, 45, 46, 47, 41, 42, 43, 44, 45,
2330 46, 47, 155, 152, 50, 159, 153, 32, 33, 62,
2331 164, 164, 159, 159, 160, 161, 162, 163, 164, 165,
2332 166, 167, 168, 169, 170, 153, 153, 55, 56, 153,
2333 114, 24, 162, 161, 161, 159, 120, 4, 184, 185,
2334 186, 187, 188, 53, 54, 55, 45, 152, 47, 456,
2335 108, 109, 162, 152, 223, 224, 27, 28, 227, 3,
2336 4, 152, 163, 159, 152, 5, 6, 300, 8, 9,
2337 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
2338 155, 21, 22, 229, 24, 119, 120, 121, 122, 123,
2339 124, 125, 126, 127, 128, 251, 3, 4, 3, 4,
2340 220, 157, 487, 4, 489, 251, 3, 4, 48, 3,
2341 4, 4, 159, 233, 77, 78, 262, 155, 238, 239,
2342 10, 11, 12, 13, 14, 15, 16, 17, 24, 4,
2343 250, 158, 24, 279, 64, 65, 66, 67, 68, 69,
2344 70, 374, 298, 376, 377, 378, 24, 158, 155, 59,
2345 4, 384, 298, 299, 300, 4, 20, 4, 22, 4,
2346 24, 7, 4, 283, 7, 161, 7, 31, 32, 33,
2347 153, 156, 153, 293, 294, 295, 345, 41, 42, 43,
2348 44, 45, 46, 47, 153, 157, 50, 51, 396, 397,
2349 398, 399, 400, 153, 58, 153, 153, 153, 62, 153,
2350 153, 409, 410, 411, 412, 413, 153, 153, 153, 36,
2351 24, 153, 155, 24, 154, 153, 155, 157, 155, 155,
2352 160, 155, 162, 163, 155, 63, 155, 155, 374, 375,
2353 376, 377, 378, 379, 380, 404, 155, 155, 384, 385,
2354 161, 238, 239, 341, 364, 365, 366, 156, 34, 457,
2355 458, 153, 372, 250, 153, 153, 464, 157, 153, 24,
2356 21, 494, 495, 496, 153, 153, 386, 387, 153, 155,
2357 21, 155, 155, 153, 420, 4, 153, 153, 24, 153,
2358 153, 153, 4, 153, 155, 153, 283, 153, 434, 36,
2359 153, 153, 161, 27, 28, 153, 293, 294, 295, 532,
2360 508, 509, 510, 511, 57, 153, 452, 515, 516, 517,
2361 518, 431, 156, 433, 153, 4, 153, 437, 153, 556,
2362 556, 153, 153, 153, 153, 445, 446, 447, 161, 24,
2363 153, 157, 540, 541, 156, 159, 57, 156, 484, 576,
2364 576, 153, 21, 156, 153, 153, 156, 21, 494, 495,
2365 496, 156, 156, 156, 500, 156, 564, 159, 566, 567,
2366 36, 156, 482, 483, 156, 485, 486, 364, 365, 366,
2367 153, 156, 492, 519, 156, 372, 156, 21, 153, 21,
2368 21, 501, 0, 0, 94, 94, 532, 94, 94, 386,
2369 387, 125, 126, 127, 128, 129, 130, 131, 132, 133,
2370 134, 135, 136, 137, 138, 316, 94, 39, 23, 317,
2371 50, 110, 421, 220, 534, 420, 2, 17, 594, 434,
2372 500, -1, 459, -1, -1, -1, -1, -1, -1, -1,
2373 -1, -1, -1, -1, 431, -1, 433, -1, -1, -1,
2374 437, -1, -1, -1, -1, -1, -1, -1, 445, 446,
2375 447, -1, -1, 573, -1, -1, -1, -1, -1, -1,
2376 -1, -1, -1, -1, -1, -1, -1, -1, 588, -1,
2377 -1, -1, -1, 5, 6, 595, -1, -1, -1, 599,
2378 600, -1, -1, -1, -1, 482, 483, -1, 485, 486,
2379 22, -1, 24, -1, 26, 492, -1, -1, -1, -1,
2380 -1, -1, -1, -1, 501, -1, 38, 39, -1, -1,
2381 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2382 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2383 -1, -1, -1, -1, -1, -1, -1, 534, -1, -1,
2384 -1, -1, -1, -1, -1, -1, -1, 79, 80, 81,
2385 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
2386 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
2387 102, 103, 104, -1, -1, -1, 573, -1, 110, -1,
2388 112, -1, 114, 115, 116, -1, -1, -1, -1, -1,
2389 -1, 588, -1, -1, -1, -1, -1, -1, 595, -1,
2390 -1, -1, 599, 600, -1, -1, -1, 139, 140, 141,
2391 142, 143, 144, 145, 146, 147, 148, 149, 150, 151,
2392 -1, -1, -1, -1, -1, 157, -1, -1, 160, -1,
2393 162, 5, 6, 165, 8, 9, 10, 11, 12, 13,
2394 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
2395 24, 5, 6, -1, 8, 9, 10, 11, 12, 13,
2396 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
2397 24, -1, 5, 6, 48, 8, 9, 10, 11, 12,
2398 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
2399 -1, 24, -1, -1, 48, -1, -1, 5, 6, -1,
2400 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
2401 18, 19, -1, 21, 22, 48, 24, -1, -1, -1,
2402 -1, -1, -1, -1, -1, -1, -1, -1, -1, 37,
2403 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2404 48, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2405 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2406 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2407 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2408 154, -1, -1, 157, -1, -1, 160, -1, 162, 163,
2409 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2410 154, -1, -1, 157, -1, -1, 160, -1, 162, 163,
2411 -1, -1, 3, 4, 5, 6, 7, -1, -1, -1,
2412 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
2413 163, 22, -1, 24, -1, 26, 27, 28, -1, -1,
2414 -1, -1, -1, -1, -1, -1, 154, 38, 39, 157,
2415 -1, -1, 160, -1, 162, -1, -1, -1, -1, -1,
2416 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2417 61, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2418 -1, -1, -1, -1, -1, -1, -1, -1, 79, 80,
2419 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
2420 91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
2421 101, 102, 103, 104, -1, -1, -1, -1, -1, 110,
2422 -1, 112, -1, 114, 115, 116, -1, -1, -1, -1,
2423 -1, -1, -1, -1, -1, -1, -1, -1, 3, 4,
2424 -1, -1, 7, -1, -1, -1, -1, -1, 139, 140,
2425 141, 142, 143, 144, 145, 146, 147, 148, 149, 150,
2426 151, 26, 27, 28, -1, -1, -1, -1, -1, 160,
2427 -1, -1, -1, 38, 39, -1, -1, -1, -1, -1,
2428 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2429 -1, -1, -1, -1, -1, -1, 61, -1, -1, -1,
2430 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2431 -1, -1, -1, -1, 79, 80, 81, 82, 83, 84,
2432 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
2433 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
2434 -1, -1, -1, -1, -1, 110, -1, 112, -1, 114,
2435 115, 116, -1, -1, -1, -1, -1, -1, -1, -1,
2436 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2437 -1, -1, -1, -1, 139, 140, 141, 142, 143, 144,
2438 145, 146, 147, 148, 149, 150, 151, -1, -1, -1,
2439 -1, -1, -1, 5, 6, 160, 8, 9, 10, 11,
2440 12, 13, 14, 15, 16, 17, 18, 19, -1, 21,
2441 22, -1, 24, -1, -1, -1, -1, -1, -1, -1,
2442 -1, -1, -1, -1, -1, 37, -1, -1, -1, -1,
2443 -1, -1, -1, -1, 5, 6, 48, 8, 9, 10,
2444 11, 12, 13, 14, 15, 16, 17, 18, 19, -1,
2445 21, 22, -1, 24, 5, 6, -1, 8, 9, 10,
2446 11, 12, 13, 14, 15, 16, 17, 18, 19, -1,
2447 21, 22, -1, 24, -1, -1, -1, 48, -1, -1,
2448 -1, -1, -1, -1, -1, -1, 37, -1, -1, -1,
2449 -1, -1, -1, -1, -1, 5, 6, 48, 8, 9,
2450 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
2451 -1, 21, 22, -1, 24, -1, -1, -1, -1, -1,
2452 -1, -1, -1, -1, -1, -1, -1, 37, -1, -1,
2453 -1, -1, -1, -1, -1, -1, -1, -1, 48, -1,
2454 -1, -1, 154, -1, -1, 157, -1, -1, 160, -1,
2455 162, 5, 6, -1, 8, 9, 10, 11, 12, 13,
2456 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
2457 24, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2458 -1, -1, -1, 154, -1, -1, 157, -1, 159, 160,
2459 -1, 162, -1, -1, 48, -1, -1, -1, -1, -1,
2460 -1, -1, -1, 154, -1, -1, 157, -1, -1, 160,
2461 -1, 162, 5, 6, -1, 8, 9, 10, 11, 12,
2462 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
2463 -1, 24, -1, -1, -1, -1, -1, -1, -1, -1,
2464 -1, -1, -1, -1, 154, -1, -1, 157, -1, -1,
2465 160, -1, 162, 5, 6, 48, 8, 9, 10, 11,
2466 12, 13, 14, 15, 16, 17, 18, 19, -1, 21,
2467 22, -1, 24, 5, 6, -1, 8, 9, 10, 11,
2468 12, 13, 14, 15, 16, 17, 18, 19, -1, 21,
2469 22, -1, 24, -1, -1, -1, 48, -1, -1, -1,
2470 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
2471 -1, -1, -1, -1, 5, 6, 48, 8, 9, 10,
2472 11, 12, 13, 14, 15, 16, 17, 18, 19, -1,
2473 21, 22, -1, 24, -1, -1, -1, -1, -1, -1,
2474 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2475 -1, -1, -1, -1, -1, -1, -1, 48, -1, -1,
2476 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
2477 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2478 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2479 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2480 -1, -1, 154, -1, -1, 157, -1, -1, 160, -1,
2481 162, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2482 -1, -1, 154, -1, -1, 157, -1, -1, 160, -1,
2483 162, -1, -1, -1, -1, 35, -1, -1, -1, -1,
2484 -1, -1, -1, -1, -1, -1, -1, -1, -1, 49,
2485 -1, -1, -1, -1, -1, -1, -1, -1, -1, 59,
2486 60, -1, -1, 154, -1, -1, 157, -1, -1, 160,
2487 -1, 162, 72, 73, 74, 75, 76, 77, 78, 79,
2488 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
2489 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
2490 100, 101, 102, 103, 104, 105, 106, 107, -1, -1,
2491 110, 111, 112, 113, 114, 115, 116, 117, 118, -1,
2492 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2493 -1, -1, -1, -1, -1, -1, -1, -1, -1, 139,
2494 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
2495 150, 151
2496};
2497/* -*-C-*- Note some compilers choke on comments on `#line' lines. */
2498#line 3 "/usr/share/bison.simple"
2499/* This file comes from bison-1.28. */
2500
2501/* Skeleton output parser for bison,
2502 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
2503
2504 This program is free software; you can redistribute it and/or modify
2505 it under the terms of the GNU General Public License as published by
2506 the Free Software Foundation; either version 2, or (at your option)
2507 any later version.
2508
2509 This program is distributed in the hope that it will be useful,
2510 but WITHOUT ANY WARRANTY; without even the implied warranty of
2511 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2512 GNU General Public License for more details.
2513
2514 You should have received a copy of the GNU General Public License
2515 along with this program; if not, write to the Free Software
2516 Foundation, Inc., 59 Temple Place - Suite 330,
2517 Boston, MA 02111-1307, USA. */
2518
2519/* As a special exception, when this file is copied by Bison into a
2520 Bison output file, you may use that output file without restriction.
2521 This special exception was added by the Free Software Foundation
2522 in version 1.24 of Bison. */
2523
2524/* This is the parser code that is written into each bison parser
2525 when the %semantic_parser declaration is not specified in the grammar.
2526 It was written by Richard Stallman by simplifying the hairy parser
2527 used when %semantic_parser is specified. */
2528
2529#ifndef YYSTACK_USE_ALLOCA
2530#ifdef alloca
2531#define YYSTACK_USE_ALLOCA
2532#else /* alloca not defined */
2533#ifdef __GNUC__
2534#define YYSTACK_USE_ALLOCA
2535#define alloca __builtin_alloca
2536#else /* not GNU C. */
2537#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
2538#define YYSTACK_USE_ALLOCA
2539#include <alloca.h>
2540#else /* not sparc */
2541/* We think this test detects Watcom and Microsoft C. */
2542/* This used to test MSDOS, but that is a bad idea
2543 since that symbol is in the user namespace. */
2544#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
2545#if 0 /* No need for malloc.h, which pollutes the namespace;
2546 instead, just don't use alloca. */
2547#include <malloc.h>
2548#endif
2549#else /* not MSDOS, or __TURBOC__ */
2550#if defined(_AIX)
2551/* I don't know what this was needed for, but it pollutes the namespace.
2552 So I turned it off. rms, 2 May 1997. */
2553/* #include <malloc.h> */
2554 #pragma alloca
2555#define YYSTACK_USE_ALLOCA
2556#else /* not MSDOS, or __TURBOC__, or _AIX */
2557#if 0
2558#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
2559 and on HPUX 10. Eventually we can turn this on. */
2560#define YYSTACK_USE_ALLOCA
2561#define alloca __builtin_alloca
2562#endif /* __hpux */
2563#endif
2564#endif /* not _AIX */
2565#endif /* not MSDOS, or __TURBOC__ */
2566#endif /* not sparc */
2567#endif /* not GNU C */
2568#endif /* alloca not defined */
2569#endif /* YYSTACK_USE_ALLOCA not defined */
2570
2571#ifdef YYSTACK_USE_ALLOCA
2572#define YYSTACK_ALLOC alloca
Reid Spencerb7046c72007-01-29 05:41:34 +00002573#else
Chris Lattner4227bdb2007-02-19 07:34:02 +00002574#define YYSTACK_ALLOC malloc
Reid Spencerb7046c72007-01-29 05:41:34 +00002575#endif
2576
Chris Lattner4227bdb2007-02-19 07:34:02 +00002577/* Note: there must be only one dollar sign in this file.
2578 It is replaced by the list of actions, each action
2579 as one case of the switch. */
Reid Spencere7c3c602006-11-30 06:36:44 +00002580
2581#define yyerrok (yyerrstatus = 0)
2582#define yyclearin (yychar = YYEMPTY)
Chris Lattner4227bdb2007-02-19 07:34:02 +00002583#define YYEMPTY -2
Reid Spencere7c3c602006-11-30 06:36:44 +00002584#define YYEOF 0
Reid Spencere7c3c602006-11-30 06:36:44 +00002585#define YYACCEPT goto yyacceptlab
Chris Lattner4227bdb2007-02-19 07:34:02 +00002586#define YYABORT goto yyabortlab
2587#define YYERROR goto yyerrlab1
2588/* Like YYERROR except do call yyerror.
2589 This remains here temporarily to ease the
2590 transition to the new meaning of YYERROR, for GCC.
Reid Spencere7c3c602006-11-30 06:36:44 +00002591 Once GCC version 2 has supplanted version 1, this can go. */
Reid Spencere7c3c602006-11-30 06:36:44 +00002592#define YYFAIL goto yyerrlab
Reid Spencere7c3c602006-11-30 06:36:44 +00002593#define YYRECOVERING() (!!yyerrstatus)
Chris Lattner4227bdb2007-02-19 07:34:02 +00002594#define YYBACKUP(token, value) \
Reid Spencere7c3c602006-11-30 06:36:44 +00002595do \
2596 if (yychar == YYEMPTY && yylen == 1) \
Chris Lattner4227bdb2007-02-19 07:34:02 +00002597 { yychar = (token), yylval = (value); \
2598 yychar1 = YYTRANSLATE (yychar); \
Chris Lattnercf3d0612007-02-13 06:04:17 +00002599 YYPOPSTACK; \
Reid Spencere7c3c602006-11-30 06:36:44 +00002600 goto yybackup; \
2601 } \
2602 else \
Chris Lattner4227bdb2007-02-19 07:34:02 +00002603 { yyerror ("syntax error: cannot back up"); YYERROR; } \
Chris Lattnercf3d0612007-02-13 06:04:17 +00002604while (0)
Reid Spencere7c3c602006-11-30 06:36:44 +00002605
Reid Spencere7c3c602006-11-30 06:36:44 +00002606#define YYTERROR 1
2607#define YYERRCODE 256
2608
Chris Lattner4227bdb2007-02-19 07:34:02 +00002609#ifndef YYPURE
2610#define YYLEX yylex()
Reid Spencere7c3c602006-11-30 06:36:44 +00002611#endif
2612
Chris Lattner4227bdb2007-02-19 07:34:02 +00002613#ifdef YYPURE
2614#ifdef YYLSP_NEEDED
Reid Spencer950bf602007-01-26 08:19:09 +00002615#ifdef YYLEX_PARAM
Chris Lattner4227bdb2007-02-19 07:34:02 +00002616#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
Reid Spencer950bf602007-01-26 08:19:09 +00002617#else
Chris Lattner4227bdb2007-02-19 07:34:02 +00002618#define YYLEX yylex(&yylval, &yylloc)
2619#endif
2620#else /* not YYLSP_NEEDED */
2621#ifdef YYLEX_PARAM
2622#define YYLEX yylex(&yylval, YYLEX_PARAM)
2623#else
2624#define YYLEX yylex(&yylval)
2625#endif
2626#endif /* not YYLSP_NEEDED */
Chris Lattnercf3d0612007-02-13 06:04:17 +00002627#endif
Reid Spencer9d6565a2007-02-15 02:26:10 +00002628
Chris Lattner4227bdb2007-02-19 07:34:02 +00002629/* If nonreentrant, generate the variables here */
Reid Spencer9d6565a2007-02-15 02:26:10 +00002630
Chris Lattner4227bdb2007-02-19 07:34:02 +00002631#ifndef YYPURE
Reid Spencer9d6565a2007-02-15 02:26:10 +00002632
Chris Lattner4227bdb2007-02-19 07:34:02 +00002633int yychar; /* the lookahead symbol */
2634YYSTYPE yylval; /* the semantic value of the */
2635 /* lookahead symbol */
Reid Spencer9d6565a2007-02-15 02:26:10 +00002636
Chris Lattner4227bdb2007-02-19 07:34:02 +00002637#ifdef YYLSP_NEEDED
2638YYLTYPE yylloc; /* location data for the lookahead */
2639 /* symbol */
Chris Lattnercf3d0612007-02-13 06:04:17 +00002640#endif
Reid Spencer9d6565a2007-02-15 02:26:10 +00002641
Chris Lattner4227bdb2007-02-19 07:34:02 +00002642int yynerrs; /* number of parse errors so far */
2643#endif /* not YYPURE */
Reid Spencer9d6565a2007-02-15 02:26:10 +00002644
Chris Lattner4227bdb2007-02-19 07:34:02 +00002645#if YYDEBUG != 0
2646int yydebug; /* nonzero means print parse trace */
2647/* Since this is uninitialized, it does not stop multiple parsers
2648 from coexisting. */
Chris Lattner8adde282007-02-11 21:40:10 +00002649#endif
Chris Lattner1bc3fa62007-02-12 22:58:38 +00002650
Chris Lattner4227bdb2007-02-19 07:34:02 +00002651/* YYINITDEPTH indicates the initial size of the parser's stacks */
Chris Lattner1bc3fa62007-02-12 22:58:38 +00002652
Reid Spencere7c3c602006-11-30 06:36:44 +00002653#ifndef YYINITDEPTH
Chris Lattner4227bdb2007-02-19 07:34:02 +00002654#define YYINITDEPTH 200
Reid Spencere7c3c602006-11-30 06:36:44 +00002655#endif
2656
Chris Lattner4227bdb2007-02-19 07:34:02 +00002657/* YYMAXDEPTH is the maximum size the stacks can grow to
2658 (effective only if the built-in stack extension method is used). */
Reid Spencere7c3c602006-11-30 06:36:44 +00002659
Chris Lattner4227bdb2007-02-19 07:34:02 +00002660#if YYMAXDEPTH == 0
2661#undef YYMAXDEPTH
2662#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00002663
2664#ifndef YYMAXDEPTH
Chris Lattner4227bdb2007-02-19 07:34:02 +00002665#define YYMAXDEPTH 10000
Reid Spencere7c3c602006-11-30 06:36:44 +00002666#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00002667
Chris Lattner4227bdb2007-02-19 07:34:02 +00002668/* Define __yy_memcpy. Note that the size argument
2669 should be passed with type unsigned int, because that is what the non-GCC
2670 definitions require. With GCC, __builtin_memcpy takes an arg
2671 of type size_t, but it can handle unsigned int. */
Reid Spencere7c3c602006-11-30 06:36:44 +00002672
Chris Lattner4227bdb2007-02-19 07:34:02 +00002673#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
2674#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
2675#else /* not GNU C or C++ */
2676#ifndef __cplusplus
Reid Spencere7c3c602006-11-30 06:36:44 +00002677
Chris Lattner4227bdb2007-02-19 07:34:02 +00002678/* This is the most reliable way to avoid incompatibilities
2679 in available built-in functions on various systems. */
Reid Spencer9d6565a2007-02-15 02:26:10 +00002680static void
Chris Lattner4227bdb2007-02-19 07:34:02 +00002681__yy_memcpy (to, from, count)
2682 char *to;
2683 char *from;
2684 unsigned int count;
2685{
2686 register char *f = from;
2687 register char *t = to;
2688 register int i = count;
2689
2690 while (i-- > 0)
2691 *t++ = *f++;
2692}
2693
2694#else /* __cplusplus */
2695
2696/* This is the most reliable way to avoid incompatibilities
2697 in available built-in functions on various systems. */
Reid Spencer9d6565a2007-02-15 02:26:10 +00002698static void
Chris Lattner4227bdb2007-02-19 07:34:02 +00002699__yy_memcpy (char *to, char *from, unsigned int count)
2700{
2701 register char *t = to;
2702 register char *f = from;
2703 register int i = count;
2704
2705 while (i-- > 0)
2706 *t++ = *f++;
2707}
2708
Reid Spencer9d6565a2007-02-15 02:26:10 +00002709#endif
Reid Spencer9d6565a2007-02-15 02:26:10 +00002710#endif
Reid Spencer9d6565a2007-02-15 02:26:10 +00002711
Chris Lattner4227bdb2007-02-19 07:34:02 +00002712#line 217 "/usr/share/bison.simple"
Reid Spencer9d6565a2007-02-15 02:26:10 +00002713
Chris Lattner4227bdb2007-02-19 07:34:02 +00002714/* The user can define YYPARSE_PARAM as the name of an argument to be passed
2715 into yyparse. The argument should have type void *.
2716 It should actually point to an object.
2717 Grammar actions can access the variable by casting it
2718 to the proper pointer type. */
Reid Spencer9d6565a2007-02-15 02:26:10 +00002719
2720#ifdef YYPARSE_PARAM
Chris Lattner4227bdb2007-02-19 07:34:02 +00002721#ifdef __cplusplus
2722#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
2723#define YYPARSE_PARAM_DECL
2724#else /* not __cplusplus */
2725#define YYPARSE_PARAM_ARG YYPARSE_PARAM
2726#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
2727#endif /* not __cplusplus */
2728#else /* not YYPARSE_PARAM */
2729#define YYPARSE_PARAM_ARG
2730#define YYPARSE_PARAM_DECL
2731#endif /* not YYPARSE_PARAM */
2732
2733/* Prevent warning if -Wstrict-prototypes. */
2734#ifdef __GNUC__
2735#ifdef YYPARSE_PARAM
2736int yyparse (void *);
2737#else
Reid Spencere7c3c602006-11-30 06:36:44 +00002738int yyparse (void);
Reid Spencer9d6565a2007-02-15 02:26:10 +00002739#endif
Chris Lattner4227bdb2007-02-19 07:34:02 +00002740#endif
Reid Spencer9d6565a2007-02-15 02:26:10 +00002741
Reid Spencer9d6565a2007-02-15 02:26:10 +00002742int
Chris Lattner4227bdb2007-02-19 07:34:02 +00002743yyparse(YYPARSE_PARAM_ARG)
2744 YYPARSE_PARAM_DECL
Reid Spencer9d6565a2007-02-15 02:26:10 +00002745{
Chris Lattner4227bdb2007-02-19 07:34:02 +00002746 register int yystate;
2747 register int yyn;
2748 register short *yyssp;
2749 register YYSTYPE *yyvsp;
2750 int yyerrstatus; /* number of tokens to shift before error messages enabled */
2751 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
Reid Spencer9d6565a2007-02-15 02:26:10 +00002752
Chris Lattner4227bdb2007-02-19 07:34:02 +00002753 short yyssa[YYINITDEPTH]; /* the state stack */
2754 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
Reid Spencer9d6565a2007-02-15 02:26:10 +00002755
Chris Lattner4227bdb2007-02-19 07:34:02 +00002756 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
2757 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
Reid Spencer9d6565a2007-02-15 02:26:10 +00002758
Chris Lattner4227bdb2007-02-19 07:34:02 +00002759#ifdef YYLSP_NEEDED
2760 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
2761 YYLTYPE *yyls = yylsa;
2762 YYLTYPE *yylsp;
Reid Spencer9d6565a2007-02-15 02:26:10 +00002763
Chris Lattner4227bdb2007-02-19 07:34:02 +00002764#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
2765#else
Chris Lattnercf3d0612007-02-13 06:04:17 +00002766#define YYPOPSTACK (yyvsp--, yyssp--)
Chris Lattner4227bdb2007-02-19 07:34:02 +00002767#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00002768
Chris Lattner4227bdb2007-02-19 07:34:02 +00002769 int yystacksize = YYINITDEPTH;
2770 int yyfree_stacks = 0;
Chris Lattner1bc3fa62007-02-12 22:58:38 +00002771
Chris Lattner4227bdb2007-02-19 07:34:02 +00002772#ifdef YYPURE
2773 int yychar;
2774 YYSTYPE yylval;
2775 int yynerrs;
2776#ifdef YYLSP_NEEDED
2777 YYLTYPE yylloc;
2778#endif
2779#endif
Chris Lattner1bc3fa62007-02-12 22:58:38 +00002780
Chris Lattner4227bdb2007-02-19 07:34:02 +00002781 YYSTYPE yyval; /* the variable used to return */
2782 /* semantic values from the action */
2783 /* routines */
Chris Lattner1bc3fa62007-02-12 22:58:38 +00002784
Chris Lattnercf3d0612007-02-13 06:04:17 +00002785 int yylen;
Chris Lattner1bc3fa62007-02-12 22:58:38 +00002786
Chris Lattner4227bdb2007-02-19 07:34:02 +00002787#if YYDEBUG != 0
2788 if (yydebug)
2789 fprintf(stderr, "Starting parse\n");
2790#endif
Chris Lattner1bc3fa62007-02-12 22:58:38 +00002791
Reid Spencere7c3c602006-11-30 06:36:44 +00002792 yystate = 0;
2793 yyerrstatus = 0;
2794 yynerrs = 0;
2795 yychar = YYEMPTY; /* Cause a token to be read. */
2796
2797 /* Initialize stack pointers.
2798 Waste one element of value and location stack
2799 so that they stay on the same level as the state stack.
2800 The wasted elements are never initialized. */
2801
Chris Lattner4227bdb2007-02-19 07:34:02 +00002802 yyssp = yyss - 1;
Reid Spencere7c3c602006-11-30 06:36:44 +00002803 yyvsp = yyvs;
Chris Lattner4227bdb2007-02-19 07:34:02 +00002804#ifdef YYLSP_NEEDED
2805 yylsp = yyls;
2806#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00002807
Chris Lattner4227bdb2007-02-19 07:34:02 +00002808/* Push a new state, which is found in yystate . */
2809/* In all cases, when you get here, the value and location stacks
2810 have just been pushed. so pushing a state here evens the stacks. */
2811yynewstate:
Reid Spencere7c3c602006-11-30 06:36:44 +00002812
Chris Lattner4227bdb2007-02-19 07:34:02 +00002813 *++yyssp = yystate;
Reid Spencere7c3c602006-11-30 06:36:44 +00002814
Chris Lattner4227bdb2007-02-19 07:34:02 +00002815 if (yyssp >= yyss + yystacksize - 1)
Reid Spencere7c3c602006-11-30 06:36:44 +00002816 {
Chris Lattner4227bdb2007-02-19 07:34:02 +00002817 /* Give user a chance to reallocate the stack */
2818 /* Use copies of these so that the &'s don't force the real ones into memory. */
2819 YYSTYPE *yyvs1 = yyvs;
2820 short *yyss1 = yyss;
2821#ifdef YYLSP_NEEDED
2822 YYLTYPE *yyls1 = yyls;
2823#endif
2824
Reid Spencere7c3c602006-11-30 06:36:44 +00002825 /* Get the current used size of the three stacks, in elements. */
Chris Lattner4227bdb2007-02-19 07:34:02 +00002826 int size = yyssp - yyss + 1;
Reid Spencere7c3c602006-11-30 06:36:44 +00002827
2828#ifdef yyoverflow
Chris Lattner4227bdb2007-02-19 07:34:02 +00002829 /* Each stack pointer address is followed by the size of
2830 the data in use in that stack, in bytes. */
2831#ifdef YYLSP_NEEDED
2832 /* This used to be a conditional around just the two extra args,
2833 but that might be undefined if yyoverflow is a macro. */
2834 yyoverflow("parser stack overflow",
2835 &yyss1, size * sizeof (*yyssp),
2836 &yyvs1, size * sizeof (*yyvsp),
2837 &yyls1, size * sizeof (*yylsp),
2838 &yystacksize);
2839#else
2840 yyoverflow("parser stack overflow",
2841 &yyss1, size * sizeof (*yyssp),
2842 &yyvs1, size * sizeof (*yyvsp),
2843 &yystacksize);
2844#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00002845
Chris Lattner4227bdb2007-02-19 07:34:02 +00002846 yyss = yyss1; yyvs = yyvs1;
2847#ifdef YYLSP_NEEDED
2848 yyls = yyls1;
2849#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00002850#else /* no yyoverflow */
Reid Spencere7c3c602006-11-30 06:36:44 +00002851 /* Extend the stack our own way. */
Chris Lattner4227bdb2007-02-19 07:34:02 +00002852 if (yystacksize >= YYMAXDEPTH)
2853 {
2854 yyerror("parser stack overflow");
2855 if (yyfree_stacks)
2856 {
2857 free (yyss);
2858 free (yyvs);
2859#ifdef YYLSP_NEEDED
2860 free (yyls);
2861#endif
2862 }
2863 return 2;
2864 }
Reid Spencere7c3c602006-11-30 06:36:44 +00002865 yystacksize *= 2;
Chris Lattner4227bdb2007-02-19 07:34:02 +00002866 if (yystacksize > YYMAXDEPTH)
Reid Spencere7c3c602006-11-30 06:36:44 +00002867 yystacksize = YYMAXDEPTH;
Chris Lattner4227bdb2007-02-19 07:34:02 +00002868#ifndef YYSTACK_USE_ALLOCA
2869 yyfree_stacks = 1;
2870#endif
2871 yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
2872 __yy_memcpy ((char *)yyss, (char *)yyss1,
2873 size * (unsigned int) sizeof (*yyssp));
2874 yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
2875 __yy_memcpy ((char *)yyvs, (char *)yyvs1,
2876 size * (unsigned int) sizeof (*yyvsp));
2877#ifdef YYLSP_NEEDED
2878 yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
2879 __yy_memcpy ((char *)yyls, (char *)yyls1,
2880 size * (unsigned int) sizeof (*yylsp));
2881#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00002882#endif /* no yyoverflow */
2883
Chris Lattner4227bdb2007-02-19 07:34:02 +00002884 yyssp = yyss + size - 1;
2885 yyvsp = yyvs + size - 1;
2886#ifdef YYLSP_NEEDED
2887 yylsp = yyls + size - 1;
2888#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00002889
Chris Lattner4227bdb2007-02-19 07:34:02 +00002890#if YYDEBUG != 0
2891 if (yydebug)
2892 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
2893#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00002894
Chris Lattner4227bdb2007-02-19 07:34:02 +00002895 if (yyssp >= yyss + yystacksize - 1)
Reid Spencere7c3c602006-11-30 06:36:44 +00002896 YYABORT;
2897 }
2898
Chris Lattner4227bdb2007-02-19 07:34:02 +00002899#if YYDEBUG != 0
2900 if (yydebug)
2901 fprintf(stderr, "Entering state %d\n", yystate);
2902#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00002903
2904 goto yybackup;
Chris Lattner4227bdb2007-02-19 07:34:02 +00002905 yybackup:
Reid Spencere7c3c602006-11-30 06:36:44 +00002906
Chris Lattnercf3d0612007-02-13 06:04:17 +00002907/* Do appropriate processing given the current state. */
Chris Lattner4227bdb2007-02-19 07:34:02 +00002908/* Read a lookahead token if we need one and don't already have one. */
Chris Lattnercf3d0612007-02-13 06:04:17 +00002909/* yyresume: */
Reid Spencere7c3c602006-11-30 06:36:44 +00002910
Chris Lattner4227bdb2007-02-19 07:34:02 +00002911 /* First try to decide what to do without reference to lookahead token. */
Reid Spencerb7046c72007-01-29 05:41:34 +00002912
Reid Spencere7c3c602006-11-30 06:36:44 +00002913 yyn = yypact[yystate];
Chris Lattner4227bdb2007-02-19 07:34:02 +00002914 if (yyn == YYFLAG)
Reid Spencere7c3c602006-11-30 06:36:44 +00002915 goto yydefault;
2916
Chris Lattner4227bdb2007-02-19 07:34:02 +00002917 /* Not known => get a lookahead token if don't already have one. */
Reid Spencere7c3c602006-11-30 06:36:44 +00002918
Chris Lattner4227bdb2007-02-19 07:34:02 +00002919 /* yychar is either YYEMPTY or YYEOF
2920 or a valid token in external form. */
2921
Reid Spencere7c3c602006-11-30 06:36:44 +00002922 if (yychar == YYEMPTY)
2923 {
Chris Lattner4227bdb2007-02-19 07:34:02 +00002924#if YYDEBUG != 0
2925 if (yydebug)
2926 fprintf(stderr, "Reading a token: ");
2927#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00002928 yychar = YYLEX;
2929 }
2930
Chris Lattner4227bdb2007-02-19 07:34:02 +00002931 /* Convert token to internal form (in yychar1) for indexing tables with */
2932
2933 if (yychar <= 0) /* This means end of input. */
Reid Spencere7c3c602006-11-30 06:36:44 +00002934 {
Chris Lattner4227bdb2007-02-19 07:34:02 +00002935 yychar1 = 0;
2936 yychar = YYEOF; /* Don't call YYLEX any more */
2937
2938#if YYDEBUG != 0
2939 if (yydebug)
2940 fprintf(stderr, "Now at end of input.\n");
2941#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00002942 }
2943 else
2944 {
Chris Lattner4227bdb2007-02-19 07:34:02 +00002945 yychar1 = YYTRANSLATE(yychar);
2946
2947#if YYDEBUG != 0
2948 if (yydebug)
2949 {
2950 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
2951 /* Give the individual parser a way to print the precise meaning
2952 of a token, for further debugging info. */
2953#ifdef YYPRINT
2954 YYPRINT (stderr, yychar, yylval);
2955#endif
2956 fprintf (stderr, ")\n");
2957 }
2958#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00002959 }
2960
Chris Lattner4227bdb2007-02-19 07:34:02 +00002961 yyn += yychar1;
2962 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
Reid Spencere7c3c602006-11-30 06:36:44 +00002963 goto yydefault;
Chris Lattner4227bdb2007-02-19 07:34:02 +00002964
Reid Spencere7c3c602006-11-30 06:36:44 +00002965 yyn = yytable[yyn];
Chris Lattner4227bdb2007-02-19 07:34:02 +00002966
2967 /* yyn is what to do for this token type in this state.
2968 Negative => reduce, -yyn is rule number.
2969 Positive => shift, yyn is new state.
2970 New state is final state => don't bother to shift,
2971 just return success.
2972 0, or most negative number => error. */
2973
2974 if (yyn < 0)
Reid Spencere7c3c602006-11-30 06:36:44 +00002975 {
Chris Lattner4227bdb2007-02-19 07:34:02 +00002976 if (yyn == YYFLAG)
Reid Spencere7c3c602006-11-30 06:36:44 +00002977 goto yyerrlab;
2978 yyn = -yyn;
2979 goto yyreduce;
2980 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00002981 else if (yyn == 0)
2982 goto yyerrlab;
Reid Spencere7c3c602006-11-30 06:36:44 +00002983
2984 if (yyn == YYFINAL)
2985 YYACCEPT;
2986
Chris Lattner4227bdb2007-02-19 07:34:02 +00002987 /* Shift the lookahead token. */
2988
2989#if YYDEBUG != 0
2990 if (yydebug)
2991 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
2992#endif
Reid Spencerb7046c72007-01-29 05:41:34 +00002993
Chris Lattnercf3d0612007-02-13 06:04:17 +00002994 /* Discard the token being shifted unless it is eof. */
Reid Spencerb7046c72007-01-29 05:41:34 +00002995 if (yychar != YYEOF)
2996 yychar = YYEMPTY;
2997
Chris Lattner1bc3fa62007-02-12 22:58:38 +00002998 *++yyvsp = yylval;
Chris Lattner4227bdb2007-02-19 07:34:02 +00002999#ifdef YYLSP_NEEDED
3000 *++yylsp = yylloc;
3001#endif
Chris Lattner1bc3fa62007-02-12 22:58:38 +00003002
Chris Lattner4227bdb2007-02-19 07:34:02 +00003003 /* count tokens shifted since error; after three, turn off error status. */
3004 if (yyerrstatus) yyerrstatus--;
Chris Lattnercf3d0612007-02-13 06:04:17 +00003005
3006 yystate = yyn;
Reid Spencere7c3c602006-11-30 06:36:44 +00003007 goto yynewstate;
3008
Chris Lattner4227bdb2007-02-19 07:34:02 +00003009/* Do the default action for the current state. */
Reid Spencer9d6565a2007-02-15 02:26:10 +00003010yydefault:
Chris Lattner4227bdb2007-02-19 07:34:02 +00003011
Reid Spencere7c3c602006-11-30 06:36:44 +00003012 yyn = yydefact[yystate];
3013 if (yyn == 0)
3014 goto yyerrlab;
Reid Spencere7c3c602006-11-30 06:36:44 +00003015
Chris Lattner4227bdb2007-02-19 07:34:02 +00003016/* Do a reduction. yyn is the number of a rule to reduce with. */
Reid Spencere7c3c602006-11-30 06:36:44 +00003017yyreduce:
Reid Spencere7c3c602006-11-30 06:36:44 +00003018 yylen = yyr2[yyn];
Chris Lattner4227bdb2007-02-19 07:34:02 +00003019 if (yylen > 0)
3020 yyval = yyvsp[1-yylen]; /* implement default value of the action */
Reid Spencere7c3c602006-11-30 06:36:44 +00003021
Chris Lattner4227bdb2007-02-19 07:34:02 +00003022#if YYDEBUG != 0
3023 if (yydebug)
Reid Spencere7c3c602006-11-30 06:36:44 +00003024 {
Chris Lattner4227bdb2007-02-19 07:34:02 +00003025 int i;
3026
3027 fprintf (stderr, "Reducing via rule %d (line %d), ",
3028 yyn, yyrline[yyn]);
3029
3030 /* Print the symbols being reduced, and their result. */
3031 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
3032 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
3033 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
3034 }
3035#endif
3036
3037
3038 switch (yyn) {
3039
3040case 2:
3041#line 1595 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3042{
3043 if (yyvsp[0].UIntVal > (uint32_t)INT32_MAX) // Outside of my range!
Reid Spencer950bf602007-01-26 08:19:09 +00003044 error("Value too large for type");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003045 yyval.SIntVal = (int32_t)yyvsp[0].UIntVal;
3046 ;
3047 break;}
3048case 4:
3049#line 1604 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3050{
3051 if (yyvsp[0].UInt64Val > (uint64_t)INT64_MAX) // Outside of my range!
Reid Spencer950bf602007-01-26 08:19:09 +00003052 error("Value too large for type");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003053 yyval.SInt64Val = (int64_t)yyvsp[0].UInt64Val;
3054 ;
3055 break;}
3056case 25:
3057#line 1626 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3058{ yyval.IPred = ICmpInst::ICMP_EQ; ;
3059 break;}
3060case 26:
3061#line 1626 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3062{ yyval.IPred = ICmpInst::ICMP_NE; ;
3063 break;}
3064case 27:
3065#line 1627 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3066{ yyval.IPred = ICmpInst::ICMP_SLT; ;
3067 break;}
3068case 28:
3069#line 1627 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3070{ yyval.IPred = ICmpInst::ICMP_SGT; ;
3071 break;}
3072case 29:
3073#line 1628 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3074{ yyval.IPred = ICmpInst::ICMP_SLE; ;
3075 break;}
3076case 30:
3077#line 1628 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3078{ yyval.IPred = ICmpInst::ICMP_SGE; ;
3079 break;}
3080case 31:
3081#line 1629 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3082{ yyval.IPred = ICmpInst::ICMP_ULT; ;
3083 break;}
3084case 32:
3085#line 1629 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3086{ yyval.IPred = ICmpInst::ICMP_UGT; ;
3087 break;}
3088case 33:
3089#line 1630 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3090{ yyval.IPred = ICmpInst::ICMP_ULE; ;
3091 break;}
3092case 34:
3093#line 1630 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3094{ yyval.IPred = ICmpInst::ICMP_UGE; ;
3095 break;}
3096case 35:
3097#line 1634 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3098{ yyval.FPred = FCmpInst::FCMP_OEQ; ;
3099 break;}
3100case 36:
3101#line 1634 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3102{ yyval.FPred = FCmpInst::FCMP_ONE; ;
3103 break;}
3104case 37:
3105#line 1635 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3106{ yyval.FPred = FCmpInst::FCMP_OLT; ;
3107 break;}
3108case 38:
3109#line 1635 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3110{ yyval.FPred = FCmpInst::FCMP_OGT; ;
3111 break;}
3112case 39:
3113#line 1636 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3114{ yyval.FPred = FCmpInst::FCMP_OLE; ;
3115 break;}
3116case 40:
3117#line 1636 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3118{ yyval.FPred = FCmpInst::FCMP_OGE; ;
3119 break;}
3120case 41:
3121#line 1637 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3122{ yyval.FPred = FCmpInst::FCMP_ORD; ;
3123 break;}
3124case 42:
3125#line 1637 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3126{ yyval.FPred = FCmpInst::FCMP_UNO; ;
3127 break;}
3128case 43:
3129#line 1638 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3130{ yyval.FPred = FCmpInst::FCMP_UEQ; ;
3131 break;}
3132case 44:
3133#line 1638 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3134{ yyval.FPred = FCmpInst::FCMP_UNE; ;
3135 break;}
3136case 45:
3137#line 1639 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3138{ yyval.FPred = FCmpInst::FCMP_ULT; ;
3139 break;}
3140case 46:
3141#line 1639 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3142{ yyval.FPred = FCmpInst::FCMP_UGT; ;
3143 break;}
3144case 47:
3145#line 1640 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3146{ yyval.FPred = FCmpInst::FCMP_ULE; ;
3147 break;}
3148case 48:
3149#line 1640 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3150{ yyval.FPred = FCmpInst::FCMP_UGE; ;
3151 break;}
3152case 49:
3153#line 1641 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3154{ yyval.FPred = FCmpInst::FCMP_TRUE; ;
3155 break;}
3156case 50:
3157#line 1642 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3158{ yyval.FPred = FCmpInst::FCMP_FALSE; ;
3159 break;}
3160case 80:
3161#line 1673 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3162{
3163 yyval.StrVal = yyvsp[-1].StrVal;
3164 ;
3165 break;}
3166case 81:
3167#line 1676 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3168{
3169 yyval.StrVal = 0;
3170 ;
3171 break;}
3172case 82:
3173#line 1681 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3174{ yyval.Linkage = GlobalValue::InternalLinkage; ;
3175 break;}
3176case 83:
3177#line 1682 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3178{ yyval.Linkage = GlobalValue::LinkOnceLinkage; ;
3179 break;}
3180case 84:
3181#line 1683 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3182{ yyval.Linkage = GlobalValue::WeakLinkage; ;
3183 break;}
3184case 85:
3185#line 1684 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3186{ yyval.Linkage = GlobalValue::AppendingLinkage; ;
3187 break;}
3188case 86:
3189#line 1685 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3190{ yyval.Linkage = GlobalValue::DLLImportLinkage; ;
3191 break;}
3192case 87:
3193#line 1686 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3194{ yyval.Linkage = GlobalValue::DLLExportLinkage; ;
3195 break;}
3196case 88:
3197#line 1687 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3198{ yyval.Linkage = GlobalValue::ExternalWeakLinkage; ;
3199 break;}
3200case 89:
3201#line 1688 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3202{ yyval.Linkage = GlobalValue::ExternalLinkage; ;
3203 break;}
3204case 90:
3205#line 1692 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3206{ yyval.UIntVal = OldCallingConv::C; ;
3207 break;}
3208case 91:
3209#line 1693 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3210{ yyval.UIntVal = OldCallingConv::C; ;
3211 break;}
3212case 92:
3213#line 1694 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3214{ yyval.UIntVal = OldCallingConv::CSRet; ;
3215 break;}
3216case 93:
3217#line 1695 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3218{ yyval.UIntVal = OldCallingConv::Fast; ;
3219 break;}
3220case 94:
3221#line 1696 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3222{ yyval.UIntVal = OldCallingConv::Cold; ;
3223 break;}
3224case 95:
3225#line 1697 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3226{ yyval.UIntVal = OldCallingConv::X86_StdCall; ;
3227 break;}
3228case 96:
3229#line 1698 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3230{ yyval.UIntVal = OldCallingConv::X86_FastCall; ;
3231 break;}
3232case 97:
3233#line 1699 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3234{
3235 if ((unsigned)yyvsp[0].UInt64Val != yyvsp[0].UInt64Val)
Reid Spencer950bf602007-01-26 08:19:09 +00003236 error("Calling conv too large");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003237 yyval.UIntVal = yyvsp[0].UInt64Val;
3238 ;
3239 break;}
3240case 98:
3241#line 1709 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3242{ yyval.UIntVal = 0; ;
3243 break;}
3244case 99:
3245#line 1710 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3246{
3247 yyval.UIntVal = yyvsp[0].UInt64Val;
3248 if (yyval.UIntVal != 0 && !isPowerOf2_32(yyval.UIntVal))
Reid Spencer950bf602007-01-26 08:19:09 +00003249 error("Alignment must be a power of two");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003250 ;
3251 break;}
3252case 100:
3253#line 1718 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3254{ yyval.UIntVal = 0; ;
3255 break;}
3256case 101:
3257#line 1719 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3258{
3259 yyval.UIntVal = yyvsp[0].UInt64Val;
3260 if (yyval.UIntVal != 0 && !isPowerOf2_32(yyval.UIntVal))
Reid Spencer950bf602007-01-26 08:19:09 +00003261 error("Alignment must be a power of two");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003262 ;
3263 break;}
3264case 102:
3265#line 1727 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3266{
3267 for (unsigned i = 0, e = strlen(yyvsp[0].StrVal); i != e; ++i)
3268 if (yyvsp[0].StrVal[i] == '"' || yyvsp[0].StrVal[i] == '\\')
Reid Spencer950bf602007-01-26 08:19:09 +00003269 error("Invalid character in section name");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003270 yyval.StrVal = yyvsp[0].StrVal;
3271 ;
3272 break;}
3273case 103:
3274#line 1736 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3275{ yyval.StrVal = 0; ;
3276 break;}
3277case 104:
3278#line 1737 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3279{ yyval.StrVal = yyvsp[0].StrVal; ;
3280 break;}
3281case 105:
3282#line 1744 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3283{;
3284 break;}
3285case 106:
3286#line 1745 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3287{;
3288 break;}
3289case 107:
3290#line 1749 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3291{
3292 CurGV->setSection(yyvsp[0].StrVal);
3293 free(yyvsp[0].StrVal);
3294 ;
3295 break;}
3296case 108:
3297#line 1753 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3298{
3299 if (yyvsp[0].UInt64Val != 0 && !isPowerOf2_32(yyvsp[0].UInt64Val))
Reid Spencer950bf602007-01-26 08:19:09 +00003300 error("Alignment must be a power of two");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003301 CurGV->setAlignment(yyvsp[0].UInt64Val);
Reid Spencer950bf602007-01-26 08:19:09 +00003302
Chris Lattner4227bdb2007-02-19 07:34:02 +00003303 ;
3304 break;}
3305case 110:
3306#line 1770 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3307{
3308 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
3309 yyval.TypeVal.S = Signless;
3310 ;
3311 break;}
3312case 112:
3313#line 1778 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3314{
3315 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
3316 yyval.TypeVal.S = Signless;
3317 ;
3318 break;}
3319case 113:
3320#line 1785 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3321{
Reid Spencer950bf602007-01-26 08:19:09 +00003322 if (!UpRefs.empty())
Chris Lattner4227bdb2007-02-19 07:34:02 +00003323 error("Invalid upreference in type: " + (*yyvsp[0].TypeVal.PAT)->getDescription());
3324 yyval.TypeVal = yyvsp[0].TypeVal;
3325 ;
3326 break;}
3327case 126:
3328#line 1799 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3329{
3330 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
3331 yyval.TypeVal.S = yyvsp[0].PrimType.S;
3332 ;
3333 break;}
3334case 127:
3335#line 1803 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3336{
3337 yyval.TypeVal.PAT = new PATypeHolder(OpaqueType::get());
3338 yyval.TypeVal.S = Signless;
3339 ;
3340 break;}
3341case 128:
3342#line 1807 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3343{ // Named types are also simple types...
3344 const Type* tmp = getType(yyvsp[0].ValIDVal);
3345 yyval.TypeVal.PAT = new PATypeHolder(tmp);
3346 yyval.TypeVal.S = Signless; // FIXME: what if its signed?
3347 ;
3348 break;}
3349case 129:
3350#line 1812 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3351{ // Type UpReference
3352 if (yyvsp[0].UInt64Val > (uint64_t)~0U)
Reid Spencer950bf602007-01-26 08:19:09 +00003353 error("Value out of range");
3354 OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder
Chris Lattner4227bdb2007-02-19 07:34:02 +00003355 UpRefs.push_back(UpRefRecord((unsigned)yyvsp[0].UInt64Val, OT)); // Add to vector...
3356 yyval.TypeVal.PAT = new PATypeHolder(OT);
3357 yyval.TypeVal.S = Signless;
Reid Spencer950bf602007-01-26 08:19:09 +00003358 UR_OUT("New Upreference!\n");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003359 ;
3360 break;}
3361case 130:
3362#line 1821 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3363{ // Function derived type?
Reid Spencer950bf602007-01-26 08:19:09 +00003364 std::vector<const Type*> Params;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003365 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-1].TypeList->begin(),
3366 E = yyvsp[-1].TypeList->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00003367 Params.push_back(I->PAT->get());
Reid Spencer52402b02007-01-02 05:45:11 +00003368 }
Reid Spencerb7046c72007-01-29 05:41:34 +00003369 FunctionType::ParamAttrsList ParamAttrs;
Reid Spencer950bf602007-01-26 08:19:09 +00003370 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
3371 if (isVarArg) Params.pop_back();
3372
Chris Lattner4227bdb2007-02-19 07:34:02 +00003373 yyval.TypeVal.PAT = new PATypeHolder(
3374 HandleUpRefs(FunctionType::get(yyvsp[-3].TypeVal.PAT->get(), Params, isVarArg,
Reid Spencered96d1e2007-02-08 09:08:52 +00003375 ParamAttrs)));
Chris Lattner4227bdb2007-02-19 07:34:02 +00003376 yyval.TypeVal.S = yyvsp[-3].TypeVal.S;
3377 delete yyvsp[-3].TypeVal.PAT; // Delete the return type handle
3378 delete yyvsp[-1].TypeList; // Delete the argument list
3379 ;
3380 break;}
3381case 131:
3382#line 1838 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3383{ // Sized array type?
3384 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(ArrayType::get(yyvsp[-1].TypeVal.PAT->get(),
3385 (unsigned)yyvsp[-3].UInt64Val)));
3386 yyval.TypeVal.S = yyvsp[-1].TypeVal.S;
3387 delete yyvsp[-1].TypeVal.PAT;
3388 ;
3389 break;}
3390case 132:
3391#line 1844 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3392{ // Vector type?
3393 const llvm::Type* ElemTy = yyvsp[-1].TypeVal.PAT->get();
3394 if ((unsigned)yyvsp[-3].UInt64Val != yyvsp[-3].UInt64Val)
Reid Spencer950bf602007-01-26 08:19:09 +00003395 error("Unsigned result not equal to signed result");
3396 if (!(ElemTy->isInteger() || ElemTy->isFloatingPoint()))
Reid Spencer9d6565a2007-02-15 02:26:10 +00003397 error("Elements of a VectorType must be integer or floating point");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003398 if (!isPowerOf2_32(yyvsp[-3].UInt64Val))
Reid Spencer9d6565a2007-02-15 02:26:10 +00003399 error("VectorType length should be a power of 2");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003400 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(VectorType::get(ElemTy,
3401 (unsigned)yyvsp[-3].UInt64Val)));
3402 yyval.TypeVal.S = yyvsp[-1].TypeVal.S;
3403 delete yyvsp[-1].TypeVal.PAT;
3404 ;
3405 break;}
3406case 133:
3407#line 1857 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3408{ // Structure type?
Reid Spencer950bf602007-01-26 08:19:09 +00003409 std::vector<const Type*> Elements;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003410 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-1].TypeList->begin(),
3411 E = yyvsp[-1].TypeList->end(); I != E; ++I)
Reid Spencered96d1e2007-02-08 09:08:52 +00003412 Elements.push_back(I->PAT->get());
Chris Lattner4227bdb2007-02-19 07:34:02 +00003413 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements)));
3414 yyval.TypeVal.S = Signless;
3415 delete yyvsp[-1].TypeList;
3416 ;
3417 break;}
3418case 134:
3419#line 1866 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3420{ // Empty structure type?
3421 yyval.TypeVal.PAT = new PATypeHolder(StructType::get(std::vector<const Type*>()));
3422 yyval.TypeVal.S = Signless;
3423 ;
3424 break;}
3425case 135:
3426#line 1870 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3427{ // Packed Structure type?
Reid Spencer950bf602007-01-26 08:19:09 +00003428 std::vector<const Type*> Elements;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003429 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-2].TypeList->begin(),
3430 E = yyvsp[-2].TypeList->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00003431 Elements.push_back(I->PAT->get());
3432 delete I->PAT;
Reid Spencer52402b02007-01-02 05:45:11 +00003433 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00003434 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements, true)));
3435 yyval.TypeVal.S = Signless;
3436 delete yyvsp[-2].TypeList;
3437 ;
3438 break;}
3439case 136:
3440#line 1881 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3441{ // Empty packed structure type?
3442 yyval.TypeVal.PAT = new PATypeHolder(StructType::get(std::vector<const Type*>(),true));
3443 yyval.TypeVal.S = Signless;
3444 ;
3445 break;}
3446case 137:
3447#line 1885 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3448{ // Pointer type?
3449 if (yyvsp[-1].TypeVal.PAT->get() == Type::LabelTy)
Reid Spencer950bf602007-01-26 08:19:09 +00003450 error("Cannot form a pointer to a basic block");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003451 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(PointerType::get(yyvsp[-1].TypeVal.PAT->get())));
3452 yyval.TypeVal.S = yyvsp[-1].TypeVal.S;
3453 delete yyvsp[-1].TypeVal.PAT;
3454 ;
3455 break;}
3456case 138:
3457#line 1898 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3458{
3459 yyval.TypeList = new std::list<PATypeInfo>();
3460 yyval.TypeList->push_back(yyvsp[0].TypeVal);
3461 ;
3462 break;}
3463case 139:
3464#line 1902 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3465{
3466 (yyval.TypeList=yyvsp[-2].TypeList)->push_back(yyvsp[0].TypeVal);
3467 ;
3468 break;}
3469case 141:
3470#line 1910 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3471{
Reid Spencer950bf602007-01-26 08:19:09 +00003472 PATypeInfo VoidTI;
Reid Spencered96d1e2007-02-08 09:08:52 +00003473 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencer950bf602007-01-26 08:19:09 +00003474 VoidTI.S = Signless;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003475 (yyval.TypeList=yyvsp[-2].TypeList)->push_back(VoidTI);
3476 ;
3477 break;}
3478case 142:
3479#line 1916 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3480{
3481 yyval.TypeList = new std::list<PATypeInfo>();
Reid Spencer950bf602007-01-26 08:19:09 +00003482 PATypeInfo VoidTI;
Reid Spencered96d1e2007-02-08 09:08:52 +00003483 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
Reid Spencer950bf602007-01-26 08:19:09 +00003484 VoidTI.S = Signless;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003485 yyval.TypeList->push_back(VoidTI);
3486 ;
3487 break;}
3488case 143:
3489#line 1923 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3490{
3491 yyval.TypeList = new std::list<PATypeInfo>();
3492 ;
3493 break;}
3494case 144:
3495#line 1935 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3496{ // Nonempty unsized arr
3497 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-3].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00003498 if (ATy == 0)
3499 error("Cannot make array constant with type: '" +
Chris Lattner4227bdb2007-02-19 07:34:02 +00003500 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00003501 const Type *ETy = ATy->getElementType();
3502 int NumElements = ATy->getNumElements();
3503
3504 // Verify that we have the correct size...
Chris Lattner4227bdb2007-02-19 07:34:02 +00003505 if (NumElements != -1 && NumElements != (int)yyvsp[-1].ConstVector->size())
Reid Spencer950bf602007-01-26 08:19:09 +00003506 error("Type mismatch: constant sized array initialized with " +
Chris Lattner4227bdb2007-02-19 07:34:02 +00003507 utostr(yyvsp[-1].ConstVector->size()) + " arguments, but has size of " +
Reid Spencer950bf602007-01-26 08:19:09 +00003508 itostr(NumElements) + "");
3509
3510 // Verify all elements are correct type!
3511 std::vector<Constant*> Elems;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003512 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
3513 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00003514 const Type* ValTy = C->getType();
3515 if (ETy != ValTy)
3516 error("Element #" + utostr(i) + " is not of type '" +
3517 ETy->getDescription() +"' as required!\nIt is of type '"+
3518 ValTy->getDescription() + "'");
3519 Elems.push_back(C);
3520 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00003521 yyval.ConstVal.C = ConstantArray::get(ATy, Elems);
3522 yyval.ConstVal.S = yyvsp[-3].TypeVal.S;
3523 delete yyvsp[-3].TypeVal.PAT;
3524 delete yyvsp[-1].ConstVector;
3525 ;
3526 break;}
3527case 145:
3528#line 1965 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3529{
3530 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-2].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00003531 if (ATy == 0)
3532 error("Cannot make array constant with type: '" +
Chris Lattner4227bdb2007-02-19 07:34:02 +00003533 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00003534 int NumElements = ATy->getNumElements();
3535 if (NumElements != -1 && NumElements != 0)
3536 error("Type mismatch: constant sized array initialized with 0"
3537 " arguments, but has size of " + itostr(NumElements) +"");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003538 yyval.ConstVal.C = ConstantArray::get(ATy, std::vector<Constant*>());
3539 yyval.ConstVal.S = yyvsp[-2].TypeVal.S;
3540 delete yyvsp[-2].TypeVal.PAT;
3541 ;
3542 break;}
3543case 146:
3544#line 1978 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3545{
3546 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-2].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00003547 if (ATy == 0)
3548 error("Cannot make array constant with type: '" +
Chris Lattner4227bdb2007-02-19 07:34:02 +00003549 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00003550 int NumElements = ATy->getNumElements();
3551 const Type *ETy = dyn_cast<IntegerType>(ATy->getElementType());
3552 if (!ETy || cast<IntegerType>(ETy)->getBitWidth() != 8)
3553 error("String arrays require type i8, not '" + ETy->getDescription() +
3554 "'");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003555 char *EndStr = UnEscapeLexed(yyvsp[0].StrVal, true);
3556 if (NumElements != -1 && NumElements != (EndStr-yyvsp[0].StrVal))
Reid Spencer950bf602007-01-26 08:19:09 +00003557 error("Can't build string constant of size " +
Chris Lattner4227bdb2007-02-19 07:34:02 +00003558 itostr((int)(EndStr-yyvsp[0].StrVal)) + " when array has size " +
Reid Spencer950bf602007-01-26 08:19:09 +00003559 itostr(NumElements) + "");
3560 std::vector<Constant*> Vals;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003561 for (char *C = (char *)yyvsp[0].StrVal; C != (char *)EndStr; ++C)
Reid Spencer950bf602007-01-26 08:19:09 +00003562 Vals.push_back(ConstantInt::get(ETy, *C));
Chris Lattner4227bdb2007-02-19 07:34:02 +00003563 free(yyvsp[0].StrVal);
3564 yyval.ConstVal.C = ConstantArray::get(ATy, Vals);
3565 yyval.ConstVal.S = yyvsp[-2].TypeVal.S;
3566 delete yyvsp[-2].TypeVal.PAT;
3567 ;
3568 break;}
3569case 147:
3570#line 2001 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3571{ // Nonempty unsized arr
3572 const VectorType *PTy = dyn_cast<VectorType>(yyvsp[-3].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00003573 if (PTy == 0)
3574 error("Cannot make packed constant with type: '" +
Chris Lattner4227bdb2007-02-19 07:34:02 +00003575 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00003576 const Type *ETy = PTy->getElementType();
3577 int NumElements = PTy->getNumElements();
3578 // Verify that we have the correct size...
Chris Lattner4227bdb2007-02-19 07:34:02 +00003579 if (NumElements != -1 && NumElements != (int)yyvsp[-1].ConstVector->size())
Reid Spencer950bf602007-01-26 08:19:09 +00003580 error("Type mismatch: constant sized packed initialized with " +
Chris Lattner4227bdb2007-02-19 07:34:02 +00003581 utostr(yyvsp[-1].ConstVector->size()) + " arguments, but has size of " +
Reid Spencer950bf602007-01-26 08:19:09 +00003582 itostr(NumElements) + "");
3583 // Verify all elements are correct type!
3584 std::vector<Constant*> Elems;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003585 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
3586 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00003587 const Type* ValTy = C->getType();
3588 if (ETy != ValTy)
3589 error("Element #" + utostr(i) + " is not of type '" +
3590 ETy->getDescription() +"' as required!\nIt is of type '"+
3591 ValTy->getDescription() + "'");
3592 Elems.push_back(C);
3593 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00003594 yyval.ConstVal.C = ConstantVector::get(PTy, Elems);
3595 yyval.ConstVal.S = yyvsp[-3].TypeVal.S;
3596 delete yyvsp[-3].TypeVal.PAT;
3597 delete yyvsp[-1].ConstVector;
3598 ;
3599 break;}
3600case 148:
3601#line 2029 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3602{
3603 const StructType *STy = dyn_cast<StructType>(yyvsp[-3].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00003604 if (STy == 0)
3605 error("Cannot make struct constant with type: '" +
Chris Lattner4227bdb2007-02-19 07:34:02 +00003606 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
3607 if (yyvsp[-1].ConstVector->size() != STy->getNumContainedTypes())
Reid Spencer950bf602007-01-26 08:19:09 +00003608 error("Illegal number of initializers for structure type");
3609
3610 // Check to ensure that constants are compatible with the type initializer!
3611 std::vector<Constant*> Fields;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003612 for (unsigned i = 0, e = yyvsp[-1].ConstVector->size(); i != e; ++i) {
3613 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00003614 if (C->getType() != STy->getElementType(i))
3615 error("Expected type '" + STy->getElementType(i)->getDescription() +
3616 "' for element #" + utostr(i) + " of structure initializer");
3617 Fields.push_back(C);
3618 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00003619 yyval.ConstVal.C = ConstantStruct::get(STy, Fields);
3620 yyval.ConstVal.S = yyvsp[-3].TypeVal.S;
3621 delete yyvsp[-3].TypeVal.PAT;
3622 delete yyvsp[-1].ConstVector;
3623 ;
3624 break;}
3625case 149:
3626#line 2051 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3627{
3628 const StructType *STy = dyn_cast<StructType>(yyvsp[-2].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00003629 if (STy == 0)
3630 error("Cannot make struct constant with type: '" +
Chris Lattner4227bdb2007-02-19 07:34:02 +00003631 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00003632 if (STy->getNumContainedTypes() != 0)
3633 error("Illegal number of initializers for structure type");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003634 yyval.ConstVal.C = ConstantStruct::get(STy, std::vector<Constant*>());
3635 yyval.ConstVal.S = yyvsp[-2].TypeVal.S;
3636 delete yyvsp[-2].TypeVal.PAT;
3637 ;
3638 break;}
3639case 150:
3640#line 2062 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3641{
3642 const StructType *STy = dyn_cast<StructType>(yyvsp[-5].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00003643 if (STy == 0)
3644 error("Cannot make packed struct constant with type: '" +
Chris Lattner4227bdb2007-02-19 07:34:02 +00003645 yyvsp[-5].TypeVal.PAT->get()->getDescription() + "'");
3646 if (yyvsp[-2].ConstVector->size() != STy->getNumContainedTypes())
Reid Spencer950bf602007-01-26 08:19:09 +00003647 error("Illegal number of initializers for packed structure type");
3648
3649 // Check to ensure that constants are compatible with the type initializer!
3650 std::vector<Constant*> Fields;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003651 for (unsigned i = 0, e = yyvsp[-2].ConstVector->size(); i != e; ++i) {
3652 Constant *C = (*yyvsp[-2].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00003653 if (C->getType() != STy->getElementType(i))
3654 error("Expected type '" + STy->getElementType(i)->getDescription() +
3655 "' for element #" + utostr(i) + " of packed struct initializer");
3656 Fields.push_back(C);
3657 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00003658 yyval.ConstVal.C = ConstantStruct::get(STy, Fields);
3659 yyval.ConstVal.S = yyvsp[-5].TypeVal.S;
3660 delete yyvsp[-5].TypeVal.PAT;
3661 delete yyvsp[-2].ConstVector;
3662 ;
3663 break;}
3664case 151:
3665#line 2084 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3666{
3667 const StructType *STy = dyn_cast<StructType>(yyvsp[-4].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00003668 if (STy == 0)
3669 error("Cannot make packed struct constant with type: '" +
Chris Lattner4227bdb2007-02-19 07:34:02 +00003670 yyvsp[-4].TypeVal.PAT->get()->getDescription() + "'");
Reid Spencer950bf602007-01-26 08:19:09 +00003671 if (STy->getNumContainedTypes() != 0)
3672 error("Illegal number of initializers for packed structure type");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003673 yyval.ConstVal.C = ConstantStruct::get(STy, std::vector<Constant*>());
3674 yyval.ConstVal.S = yyvsp[-4].TypeVal.S;
3675 delete yyvsp[-4].TypeVal.PAT;
3676 ;
3677 break;}
3678case 152:
3679#line 2095 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3680{
3681 const PointerType *PTy = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00003682 if (PTy == 0)
3683 error("Cannot make null pointer constant with type: '" +
Chris Lattner4227bdb2007-02-19 07:34:02 +00003684 yyvsp[-1].TypeVal.PAT->get()->getDescription() + "'");
3685 yyval.ConstVal.C = ConstantPointerNull::get(PTy);
3686 yyval.ConstVal.S = yyvsp[-1].TypeVal.S;
3687 delete yyvsp[-1].TypeVal.PAT;
3688 ;
3689 break;}
3690case 153:
3691#line 2104 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3692{
3693 yyval.ConstVal.C = UndefValue::get(yyvsp[-1].TypeVal.PAT->get());
3694 yyval.ConstVal.S = yyvsp[-1].TypeVal.S;
3695 delete yyvsp[-1].TypeVal.PAT;
3696 ;
3697 break;}
3698case 154:
3699#line 2109 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3700{
3701 const PointerType *Ty = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Reid Spencer950bf602007-01-26 08:19:09 +00003702 if (Ty == 0)
3703 error("Global const reference must be a pointer type, not" +
Chris Lattner4227bdb2007-02-19 07:34:02 +00003704 yyvsp[-1].TypeVal.PAT->get()->getDescription());
Reid Spencer950bf602007-01-26 08:19:09 +00003705
3706 // ConstExprs can exist in the body of a function, thus creating
3707 // GlobalValues whenever they refer to a variable. Because we are in
3708 // the context of a function, getExistingValue will search the functions
3709 // symbol table instead of the module symbol table for the global symbol,
3710 // which throws things all off. To get around this, we just tell
3711 // getExistingValue that we are at global scope here.
3712 //
3713 Function *SavedCurFn = CurFun.CurrentFunction;
3714 CurFun.CurrentFunction = 0;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003715 Value *V = getExistingValue(Ty, yyvsp[0].ValIDVal);
Reid Spencer950bf602007-01-26 08:19:09 +00003716 CurFun.CurrentFunction = SavedCurFn;
3717
3718 // If this is an initializer for a constant pointer, which is referencing a
3719 // (currently) undefined variable, create a stub now that shall be replaced
3720 // in the future with the right type of variable.
3721 //
3722 if (V == 0) {
3723 assert(isa<PointerType>(Ty) && "Globals may only be used as pointers");
3724 const PointerType *PT = cast<PointerType>(Ty);
3725
3726 // First check to see if the forward references value is already created!
3727 PerModuleInfo::GlobalRefsType::iterator I =
Chris Lattner4227bdb2007-02-19 07:34:02 +00003728 CurModule.GlobalRefs.find(std::make_pair(PT, yyvsp[0].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00003729
3730 if (I != CurModule.GlobalRefs.end()) {
3731 V = I->second; // Placeholder already exists, use it...
Chris Lattner4227bdb2007-02-19 07:34:02 +00003732 yyvsp[0].ValIDVal.destroy();
Reid Spencer950bf602007-01-26 08:19:09 +00003733 } else {
3734 std::string Name;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003735 if (yyvsp[0].ValIDVal.Type == ValID::NameVal) Name = yyvsp[0].ValIDVal.Name;
Reid Spencer950bf602007-01-26 08:19:09 +00003736
3737 // Create the forward referenced global.
3738 GlobalValue *GV;
3739 if (const FunctionType *FTy =
3740 dyn_cast<FunctionType>(PT->getElementType())) {
3741 GV = new Function(FTy, GlobalValue::ExternalLinkage, Name,
3742 CurModule.CurrentModule);
3743 } else {
3744 GV = new GlobalVariable(PT->getElementType(), false,
3745 GlobalValue::ExternalLinkage, 0,
3746 Name, CurModule.CurrentModule);
3747 }
3748
3749 // Keep track of the fact that we have a forward ref to recycle it
Chris Lattner4227bdb2007-02-19 07:34:02 +00003750 CurModule.GlobalRefs.insert(std::make_pair(std::make_pair(PT, yyvsp[0].ValIDVal), GV));
Reid Spencer950bf602007-01-26 08:19:09 +00003751 V = GV;
3752 }
3753 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00003754 yyval.ConstVal.C = cast<GlobalValue>(V);
3755 yyval.ConstVal.S = yyvsp[-1].TypeVal.S;
3756 delete yyvsp[-1].TypeVal.PAT; // Free the type handle
3757 ;
3758 break;}
3759case 155:
3760#line 2167 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3761{
3762 if (yyvsp[-1].TypeVal.PAT->get() != yyvsp[0].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00003763 error("Mismatched types for constant expression");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003764 yyval.ConstVal = yyvsp[0].ConstVal;
3765 yyval.ConstVal.S = yyvsp[-1].TypeVal.S;
3766 delete yyvsp[-1].TypeVal.PAT;
3767 ;
3768 break;}
3769case 156:
3770#line 2174 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3771{
3772 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00003773 if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
3774 error("Cannot create a null initialized value of this type");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003775 yyval.ConstVal.C = Constant::getNullValue(Ty);
3776 yyval.ConstVal.S = yyvsp[-1].TypeVal.S;
3777 delete yyvsp[-1].TypeVal.PAT;
3778 ;
3779 break;}
3780case 157:
3781#line 2182 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3782{ // integral constants
3783 const Type *Ty = yyvsp[-1].PrimType.T;
3784 if (!ConstantInt::isValueValidForType(Ty, yyvsp[0].SInt64Val))
Reid Spencer950bf602007-01-26 08:19:09 +00003785 error("Constant value doesn't fit in type");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003786 yyval.ConstVal.C = ConstantInt::get(Ty, yyvsp[0].SInt64Val);
3787 yyval.ConstVal.S = Signed;
3788 ;
3789 break;}
3790case 158:
3791#line 2189 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3792{ // integral constants
3793 const Type *Ty = yyvsp[-1].PrimType.T;
3794 if (!ConstantInt::isValueValidForType(Ty, yyvsp[0].UInt64Val))
Reid Spencer950bf602007-01-26 08:19:09 +00003795 error("Constant value doesn't fit in type");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003796 yyval.ConstVal.C = ConstantInt::get(Ty, yyvsp[0].UInt64Val);
3797 yyval.ConstVal.S = Unsigned;
3798 ;
3799 break;}
3800case 159:
3801#line 2196 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3802{ // Boolean constants
3803 yyval.ConstVal.C = ConstantInt::get(Type::Int1Ty, true);
3804 yyval.ConstVal.S = Unsigned;
3805 ;
3806 break;}
3807case 160:
3808#line 2200 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3809{ // Boolean constants
3810 yyval.ConstVal.C = ConstantInt::get(Type::Int1Ty, false);
3811 yyval.ConstVal.S = Unsigned;
3812 ;
3813 break;}
3814case 161:
3815#line 2204 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3816{ // Float & Double constants
3817 if (!ConstantFP::isValueValidForType(yyvsp[-1].PrimType.T, yyvsp[0].FPVal))
Reid Spencer950bf602007-01-26 08:19:09 +00003818 error("Floating point constant invalid for type");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003819 yyval.ConstVal.C = ConstantFP::get(yyvsp[-1].PrimType.T, yyvsp[0].FPVal);
3820 yyval.ConstVal.S = Signless;
3821 ;
3822 break;}
3823case 162:
3824#line 2213 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3825{
3826 const Type* SrcTy = yyvsp[-3].ConstVal.C->getType();
3827 const Type* DstTy = yyvsp[-1].TypeVal.PAT->get();
3828 Signedness SrcSign = yyvsp[-3].ConstVal.S;
3829 Signedness DstSign = yyvsp[-1].TypeVal.S;
Reid Spencer950bf602007-01-26 08:19:09 +00003830 if (!SrcTy->isFirstClassType())
3831 error("cast constant expression from a non-primitive type: '" +
3832 SrcTy->getDescription() + "'");
3833 if (!DstTy->isFirstClassType())
3834 error("cast constant expression to a non-primitive type: '" +
3835 DstTy->getDescription() + "'");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003836 yyval.ConstVal.C = cast<Constant>(getCast(yyvsp[-5].CastOpVal, yyvsp[-3].ConstVal.C, SrcSign, DstTy, DstSign));
3837 yyval.ConstVal.S = DstSign;
3838 delete yyvsp[-1].TypeVal.PAT;
3839 ;
3840 break;}
3841case 163:
3842#line 2228 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3843{
3844 const Type *Ty = yyvsp[-2].ConstVal.C->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00003845 if (!isa<PointerType>(Ty))
3846 error("GetElementPtr requires a pointer operand");
3847
3848 std::vector<Value*> VIndices;
3849 std::vector<Constant*> CIndices;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003850 upgradeGEPIndices(yyvsp[-2].ConstVal.C->getType(), yyvsp[-1].ValueList, VIndices, &CIndices);
Reid Spencer950bf602007-01-26 08:19:09 +00003851
Chris Lattner4227bdb2007-02-19 07:34:02 +00003852 delete yyvsp[-1].ValueList;
3853 yyval.ConstVal.C = ConstantExpr::getGetElementPtr(yyvsp[-2].ConstVal.C, &CIndices[0], CIndices.size());
3854 yyval.ConstVal.S = Signless;
3855 ;
3856 break;}
3857case 164:
3858#line 2241 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3859{
3860 if (!yyvsp[-5].ConstVal.C->getType()->isInteger() ||
3861 cast<IntegerType>(yyvsp[-5].ConstVal.C->getType())->getBitWidth() != 1)
Reid Spencer950bf602007-01-26 08:19:09 +00003862 error("Select condition must be bool type");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003863 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00003864 error("Select operand types must match");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003865 yyval.ConstVal.C = ConstantExpr::getSelect(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
3866 yyval.ConstVal.S = Unsigned;
3867 ;
3868 break;}
3869case 165:
3870#line 2250 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3871{
3872 const Type *Ty = yyvsp[-3].ConstVal.C->getType();
3873 if (Ty != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00003874 error("Binary operator types must match");
3875 // First, make sure we're dealing with the right opcode by upgrading from
3876 // obsolete versions.
Chris Lattner4227bdb2007-02-19 07:34:02 +00003877 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S);
Reid Spencer950bf602007-01-26 08:19:09 +00003878
3879 // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs.
3880 // To retain backward compatibility with these early compilers, we emit a
3881 // cast to the appropriate integer type automatically if we are in the
3882 // broken case. See PR424 for more information.
3883 if (!isa<PointerType>(Ty)) {
Chris Lattner4227bdb2007-02-19 07:34:02 +00003884 yyval.ConstVal.C = ConstantExpr::get(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
Reid Spencer950bf602007-01-26 08:19:09 +00003885 } else {
3886 const Type *IntPtrTy = 0;
3887 switch (CurModule.CurrentModule->getPointerSize()) {
3888 case Module::Pointer32: IntPtrTy = Type::Int32Ty; break;
3889 case Module::Pointer64: IntPtrTy = Type::Int64Ty; break;
3890 default: error("invalid pointer binary constant expr");
3891 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00003892 yyval.ConstVal.C = ConstantExpr::get(Opcode,
3893 ConstantExpr::getCast(Instruction::PtrToInt, yyvsp[-3].ConstVal.C, IntPtrTy),
3894 ConstantExpr::getCast(Instruction::PtrToInt, yyvsp[-1].ConstVal.C, IntPtrTy));
3895 yyval.ConstVal.C = ConstantExpr::getCast(Instruction::IntToPtr, yyval.ConstVal.C, Ty);
Reid Spencer950bf602007-01-26 08:19:09 +00003896 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00003897 yyval.ConstVal.S = yyvsp[-3].ConstVal.S;
3898 ;
3899 break;}
3900case 166:
3901#line 2278 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3902{
3903 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
3904 if (Ty != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00003905 error("Logical operator types must match");
3906 if (!Ty->isInteger()) {
Reid Spencer9d6565a2007-02-15 02:26:10 +00003907 if (!isa<VectorType>(Ty) ||
3908 !cast<VectorType>(Ty)->getElementType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00003909 error("Logical operator requires integer operands");
3910 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00003911 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S);
3912 yyval.ConstVal.C = ConstantExpr::get(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
3913 yyval.ConstVal.S = yyvsp[-3].ConstVal.S;
3914 ;
3915 break;}
3916case 167:
3917#line 2291 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3918{
3919 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
3920 if (Ty != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00003921 error("setcc operand types must match");
3922 unsigned short pred;
Chris Lattner4227bdb2007-02-19 07:34:02 +00003923 Instruction::OtherOps Opcode = getCompareOp(yyvsp[-5].BinaryOpVal, pred, Ty, yyvsp[-3].ConstVal.S);
3924 yyval.ConstVal.C = ConstantExpr::getCompare(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
3925 yyval.ConstVal.S = Unsigned;
3926 ;
3927 break;}
3928case 168:
3929#line 2300 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3930{
3931 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00003932 error("icmp operand types must match");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003933 yyval.ConstVal.C = ConstantExpr::getCompare(yyvsp[-5].IPred, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
3934 yyval.ConstVal.S = Unsigned;
3935 ;
3936 break;}
3937case 169:
3938#line 2306 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3939{
3940 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00003941 error("fcmp operand types must match");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003942 yyval.ConstVal.C = ConstantExpr::getCompare(yyvsp[-5].FPred, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
3943 yyval.ConstVal.S = Unsigned;
3944 ;
3945 break;}
3946case 170:
3947#line 2312 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3948{
3949 if (!yyvsp[-1].ConstVal.C->getType()->isInteger() ||
3950 cast<IntegerType>(yyvsp[-1].ConstVal.C->getType())->getBitWidth() != 8)
Reid Spencer950bf602007-01-26 08:19:09 +00003951 error("Shift count for shift constant must be unsigned byte");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003952 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
3953 if (!yyvsp[-3].ConstVal.C->getType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00003954 error("Shift constant expression requires integer operand");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003955 Constant *ShiftAmt = ConstantExpr::getZExt(yyvsp[-1].ConstVal.C, Ty);
3956 yyval.ConstVal.C = ConstantExpr::get(getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S), yyvsp[-3].ConstVal.C, ShiftAmt);
3957 yyval.ConstVal.S = yyvsp[-3].ConstVal.S;
3958 ;
3959 break;}
3960case 171:
3961#line 2323 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3962{
3963 if (!ExtractElementInst::isValidOperands(yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Reid Spencer950bf602007-01-26 08:19:09 +00003964 error("Invalid extractelement operands");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003965 yyval.ConstVal.C = ConstantExpr::getExtractElement(yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
3966 yyval.ConstVal.S = yyvsp[-3].ConstVal.S;
3967 ;
3968 break;}
3969case 172:
3970#line 2329 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3971{
3972 if (!InsertElementInst::isValidOperands(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Reid Spencer950bf602007-01-26 08:19:09 +00003973 error("Invalid insertelement operands");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003974 yyval.ConstVal.C = ConstantExpr::getInsertElement(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
3975 yyval.ConstVal.S = yyvsp[-5].ConstVal.S;
3976 ;
3977 break;}
3978case 173:
3979#line 2335 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3980{
3981 if (!ShuffleVectorInst::isValidOperands(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Reid Spencer950bf602007-01-26 08:19:09 +00003982 error("Invalid shufflevector operands");
Chris Lattner4227bdb2007-02-19 07:34:02 +00003983 yyval.ConstVal.C = ConstantExpr::getShuffleVector(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
3984 yyval.ConstVal.S = yyvsp[-5].ConstVal.S;
3985 ;
3986 break;}
3987case 174:
3988#line 2346 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3989{ (yyval.ConstVector = yyvsp[-2].ConstVector)->push_back(yyvsp[0].ConstVal); ;
3990 break;}
3991case 175:
3992#line 2347 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
3993{
3994 yyval.ConstVector = new std::vector<ConstInfo>();
3995 yyval.ConstVector->push_back(yyvsp[0].ConstVal);
3996 ;
3997 break;}
3998case 176:
3999#line 2356 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4000{ yyval.BoolVal = false; ;
4001 break;}
4002case 177:
4003#line 2357 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4004{ yyval.BoolVal = true; ;
4005 break;}
4006case 178:
4007#line 2369 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4008{
4009 yyval.ModuleVal = ParserResult = yyvsp[0].ModuleVal;
Reid Spencer950bf602007-01-26 08:19:09 +00004010 CurModule.ModuleDone();
Chris Lattner4227bdb2007-02-19 07:34:02 +00004011 ;
4012 break;}
4013case 179:
4014#line 2378 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4015{ yyval.ModuleVal = yyvsp[-1].ModuleVal; CurFun.FunctionDone(); ;
4016 break;}
4017case 180:
4018#line 2379 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4019{ yyval.ModuleVal = yyvsp[-1].ModuleVal; ;
4020 break;}
4021case 181:
4022#line 2380 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4023{ yyval.ModuleVal = yyvsp[-3].ModuleVal; ;
4024 break;}
4025case 182:
4026#line 2381 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4027{ yyval.ModuleVal = yyvsp[-1].ModuleVal; ;
4028 break;}
4029case 183:
4030#line 2382 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4031{
4032 yyval.ModuleVal = CurModule.CurrentModule;
Reid Spencer950bf602007-01-26 08:19:09 +00004033 // Emit an error if there are any unresolved types left.
4034 if (!CurModule.LateResolveTypes.empty()) {
4035 const ValID &DID = CurModule.LateResolveTypes.begin()->first;
4036 if (DID.Type == ValID::NameVal) {
4037 error("Reference to an undefined type: '"+DID.getName() + "'");
4038 } else {
4039 error("Reference to an undefined type: #" + itostr(DID.Num));
4040 }
4041 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00004042 ;
4043 break;}
4044case 184:
4045#line 2398 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4046{
Reid Spencer950bf602007-01-26 08:19:09 +00004047 // Eagerly resolve types. This is not an optimization, this is a
4048 // requirement that is due to the fact that we could have this:
4049 //
4050 // %list = type { %list * }
4051 // %list = type { %list * } ; repeated type decl
4052 //
4053 // If types are not resolved eagerly, then the two types will not be
4054 // determined to be the same type!
4055 //
Chris Lattner4227bdb2007-02-19 07:34:02 +00004056 const Type* Ty = yyvsp[0].TypeVal.PAT->get();
4057 ResolveTypeTo(yyvsp[-2].StrVal, Ty);
Reid Spencer950bf602007-01-26 08:19:09 +00004058
Chris Lattner4227bdb2007-02-19 07:34:02 +00004059 if (!setTypeName(Ty, yyvsp[-2].StrVal) && !yyvsp[-2].StrVal) {
Reid Spencer950bf602007-01-26 08:19:09 +00004060 // If this is a named type that is not a redefinition, add it to the slot
4061 // table.
4062 CurModule.Types.push_back(Ty);
Reid Spencera50d5962006-12-02 04:11:07 +00004063 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00004064 delete yyvsp[0].TypeVal.PAT;
4065 ;
4066 break;}
4067case 185:
4068#line 2418 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4069{ // Function prototypes can be in const pool
4070 ;
4071 break;}
4072case 186:
4073#line 2420 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4074{ // Asm blocks can be in the const pool
4075 ;
4076 break;}
4077case 187:
4078#line 2422 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4079{
4080 if (yyvsp[0].ConstVal.C == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00004081 error("Global value initializer is not a constant");
Chris Lattner4227bdb2007-02-19 07:34:02 +00004082 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, yyvsp[-2].Linkage, yyvsp[-1].BoolVal, yyvsp[0].ConstVal.C->getType(), yyvsp[0].ConstVal.C);
4083 ;
4084 break;}
4085case 188:
4086#line 2426 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4087{
Reid Spencer950bf602007-01-26 08:19:09 +00004088 CurGV = 0;
Chris Lattner4227bdb2007-02-19 07:34:02 +00004089 ;
4090 break;}
4091case 189:
4092#line 2429 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4093{
4094 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
4095 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::ExternalLinkage, yyvsp[-1].BoolVal, Ty, 0);
4096 delete yyvsp[0].TypeVal.PAT;
4097 ;
4098 break;}
4099case 190:
4100#line 2433 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4101{
Reid Spencer950bf602007-01-26 08:19:09 +00004102 CurGV = 0;
Chris Lattner4227bdb2007-02-19 07:34:02 +00004103 ;
4104 break;}
4105case 191:
4106#line 2436 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4107{
4108 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
4109 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::DLLImportLinkage, yyvsp[-1].BoolVal, Ty, 0);
4110 delete yyvsp[0].TypeVal.PAT;
4111 ;
4112 break;}
4113case 192:
4114#line 2440 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4115{
Reid Spencer950bf602007-01-26 08:19:09 +00004116 CurGV = 0;
Chris Lattner4227bdb2007-02-19 07:34:02 +00004117 ;
4118 break;}
4119case 193:
4120#line 2443 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4121{
4122 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00004123 CurGV =
Chris Lattner4227bdb2007-02-19 07:34:02 +00004124 ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::ExternalWeakLinkage, yyvsp[-1].BoolVal, Ty, 0);
4125 delete yyvsp[0].TypeVal.PAT;
4126 ;
4127 break;}
4128case 194:
4129#line 2448 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4130{
Reid Spencer950bf602007-01-26 08:19:09 +00004131 CurGV = 0;
Chris Lattner4227bdb2007-02-19 07:34:02 +00004132 ;
4133 break;}
4134case 195:
4135#line 2451 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4136{
4137 ;
4138 break;}
4139case 196:
4140#line 2453 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4141{
4142 ;
4143 break;}
4144case 197:
4145#line 2455 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4146{
4147 ;
4148 break;}
4149case 198:
4150#line 2460 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4151{
Reid Spencer950bf602007-01-26 08:19:09 +00004152 const std::string &AsmSoFar = CurModule.CurrentModule->getModuleInlineAsm();
Chris Lattner4227bdb2007-02-19 07:34:02 +00004153 char *EndStr = UnEscapeLexed(yyvsp[0].StrVal, true);
4154 std::string NewAsm(yyvsp[0].StrVal, EndStr);
4155 free(yyvsp[0].StrVal);
Reid Spencer950bf602007-01-26 08:19:09 +00004156
4157 if (AsmSoFar.empty())
4158 CurModule.CurrentModule->setModuleInlineAsm(NewAsm);
4159 else
4160 CurModule.CurrentModule->setModuleInlineAsm(AsmSoFar+"\n"+NewAsm);
Chris Lattner4227bdb2007-02-19 07:34:02 +00004161 ;
4162 break;}
4163case 199:
4164#line 2474 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4165{ yyval.Endianness = Module::BigEndian; ;
4166 break;}
4167case 200:
4168#line 2475 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4169{ yyval.Endianness = Module::LittleEndian; ;
4170 break;}
4171case 201:
4172#line 2479 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4173{
4174 CurModule.setEndianness(yyvsp[0].Endianness);
4175 ;
4176 break;}
4177case 202:
4178#line 2482 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4179{
4180 if (yyvsp[0].UInt64Val == 32)
Reid Spencer950bf602007-01-26 08:19:09 +00004181 CurModule.setPointerSize(Module::Pointer32);
Chris Lattner4227bdb2007-02-19 07:34:02 +00004182 else if (yyvsp[0].UInt64Val == 64)
Reid Spencer950bf602007-01-26 08:19:09 +00004183 CurModule.setPointerSize(Module::Pointer64);
4184 else
Chris Lattner4227bdb2007-02-19 07:34:02 +00004185 error("Invalid pointer size: '" + utostr(yyvsp[0].UInt64Val) + "'");
4186 ;
4187 break;}
4188case 203:
4189#line 2490 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4190{
4191 CurModule.CurrentModule->setTargetTriple(yyvsp[0].StrVal);
4192 free(yyvsp[0].StrVal);
4193 ;
4194 break;}
4195case 204:
4196#line 2494 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4197{
4198 CurModule.CurrentModule->setDataLayout(yyvsp[0].StrVal);
4199 free(yyvsp[0].StrVal);
4200 ;
4201 break;}
4202case 206:
4203#line 2505 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4204{
4205 CurModule.CurrentModule->addLibrary(yyvsp[0].StrVal);
4206 free(yyvsp[0].StrVal);
4207 ;
4208 break;}
4209case 207:
4210#line 2509 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4211{
4212 CurModule.CurrentModule->addLibrary(yyvsp[0].StrVal);
4213 free(yyvsp[0].StrVal);
4214 ;
4215 break;}
4216case 208:
4217#line 2513 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4218{ ;
4219 break;}
4220case 212:
4221#line 2526 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4222{ yyval.StrVal = 0; ;
4223 break;}
4224case 213:
4225#line 2530 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4226{
4227 if (yyvsp[-1].TypeVal.PAT->get() == Type::VoidTy)
Reid Spencer9d6565a2007-02-15 02:26:10 +00004228 error("void typed arguments are invalid");
Chris Lattner4227bdb2007-02-19 07:34:02 +00004229 yyval.ArgVal = new std::pair<PATypeInfo, char*>(yyvsp[-1].TypeVal, yyvsp[0].StrVal);
4230 ;
4231 break;}
4232case 214:
4233#line 2538 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4234{
4235 yyval.ArgList = yyvsp[-2].ArgList;
4236 yyval.ArgList->push_back(*yyvsp[0].ArgVal);
4237 delete yyvsp[0].ArgVal;
4238 ;
4239 break;}
4240case 215:
4241#line 2543 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4242{
4243 yyval.ArgList = new std::vector<std::pair<PATypeInfo,char*> >();
4244 yyval.ArgList->push_back(*yyvsp[0].ArgVal);
4245 delete yyvsp[0].ArgVal;
4246 ;
4247 break;}
4248case 216:
4249#line 2551 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4250{ yyval.ArgList = yyvsp[0].ArgList; ;
4251 break;}
4252case 217:
4253#line 2552 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4254{
4255 yyval.ArgList = yyvsp[-2].ArgList;
Reid Spencer9d6565a2007-02-15 02:26:10 +00004256 PATypeInfo VoidTI;
4257 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
4258 VoidTI.S = Signless;
Chris Lattner4227bdb2007-02-19 07:34:02 +00004259 yyval.ArgList->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
4260 ;
4261 break;}
4262case 218:
4263#line 2559 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4264{
4265 yyval.ArgList = new std::vector<std::pair<PATypeInfo,char*> >();
Reid Spencer9d6565a2007-02-15 02:26:10 +00004266 PATypeInfo VoidTI;
4267 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
4268 VoidTI.S = Signless;
Chris Lattner4227bdb2007-02-19 07:34:02 +00004269 yyval.ArgList->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
4270 ;
4271 break;}
4272case 219:
4273#line 2566 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4274{ yyval.ArgList = 0; ;
4275 break;}
4276case 220:
4277#line 2570 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4278{
4279 UnEscapeLexed(yyvsp[-5].StrVal);
4280 std::string FunctionName(yyvsp[-5].StrVal);
4281 free(yyvsp[-5].StrVal); // Free strdup'd memory!
Reid Spencer9d6565a2007-02-15 02:26:10 +00004282
Chris Lattner4227bdb2007-02-19 07:34:02 +00004283 const Type* RetTy = yyvsp[-6].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00004284
4285 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
4286 error("LLVM functions cannot return aggregate types");
4287
Reid Spenceref9b9a72007-02-05 20:47:22 +00004288 std::vector<const Type*> ParamTyList;
Reid Spencer950bf602007-01-26 08:19:09 +00004289
4290 // In LLVM 2.0 the signatures of three varargs intrinsics changed to take
4291 // i8*. We check here for those names and override the parameter list
4292 // types to ensure the prototype is correct.
4293 if (FunctionName == "llvm.va_start" || FunctionName == "llvm.va_end") {
Reid Spenceref9b9a72007-02-05 20:47:22 +00004294 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
Reid Spencer950bf602007-01-26 08:19:09 +00004295 } else if (FunctionName == "llvm.va_copy") {
Reid Spenceref9b9a72007-02-05 20:47:22 +00004296 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
4297 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
Chris Lattner4227bdb2007-02-19 07:34:02 +00004298 } else if (yyvsp[-3].ArgList) { // If there are arguments...
Reid Spencer950bf602007-01-26 08:19:09 +00004299 for (std::vector<std::pair<PATypeInfo,char*> >::iterator
Chris Lattner4227bdb2007-02-19 07:34:02 +00004300 I = yyvsp[-3].ArgList->begin(), E = yyvsp[-3].ArgList->end(); I != E; ++I) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004301 const Type *Ty = I->first.PAT->get();
Reid Spenceref9b9a72007-02-05 20:47:22 +00004302 ParamTyList.push_back(Ty);
Reid Spencer950bf602007-01-26 08:19:09 +00004303 }
4304 }
4305
Reid Spenceref9b9a72007-02-05 20:47:22 +00004306 bool isVarArg = ParamTyList.size() && ParamTyList.back() == Type::VoidTy;
4307 if (isVarArg)
4308 ParamTyList.pop_back();
Reid Spencer950bf602007-01-26 08:19:09 +00004309
Reid Spencerb7046c72007-01-29 05:41:34 +00004310 // Convert the CSRet calling convention into the corresponding parameter
4311 // attribute.
4312 FunctionType::ParamAttrsList ParamAttrs;
Chris Lattner4227bdb2007-02-19 07:34:02 +00004313 if (yyvsp[-7].UIntVal == OldCallingConv::CSRet) {
Reid Spencerb7046c72007-01-29 05:41:34 +00004314 ParamAttrs.push_back(FunctionType::NoAttributeSet); // result
4315 ParamAttrs.push_back(FunctionType::StructRetAttribute); // first arg
4316 }
4317
Reid Spenceref9b9a72007-02-05 20:47:22 +00004318 const FunctionType *FT = FunctionType::get(RetTy, ParamTyList, isVarArg,
Reid Spencerb7046c72007-01-29 05:41:34 +00004319 ParamAttrs);
Reid Spencer950bf602007-01-26 08:19:09 +00004320 const PointerType *PFT = PointerType::get(FT);
Chris Lattner4227bdb2007-02-19 07:34:02 +00004321 delete yyvsp[-6].TypeVal.PAT;
Reid Spencer950bf602007-01-26 08:19:09 +00004322
4323 ValID ID;
4324 if (!FunctionName.empty()) {
4325 ID = ValID::create((char*)FunctionName.c_str());
4326 } else {
4327 ID = ValID::create((int)CurModule.Values[PFT].size());
4328 }
4329
4330 Function *Fn = 0;
Reid Spencered96d1e2007-02-08 09:08:52 +00004331 Module* M = CurModule.CurrentModule;
4332
Reid Spencer950bf602007-01-26 08:19:09 +00004333 // See if this function was forward referenced. If so, recycle the object.
4334 if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, ID)) {
4335 // Move the function to the end of the list, from whereever it was
4336 // previously inserted.
4337 Fn = cast<Function>(FWRef);
Reid Spencered96d1e2007-02-08 09:08:52 +00004338 M->getFunctionList().remove(Fn);
4339 M->getFunctionList().push_back(Fn);
4340 } else if (!FunctionName.empty()) {
4341 GlobalValue *Conflict = M->getFunction(FunctionName);
4342 if (!Conflict)
4343 Conflict = M->getNamedGlobal(FunctionName);
4344 if (Conflict && PFT == Conflict->getType()) {
4345 if (!CurFun.isDeclare && !Conflict->isDeclaration()) {
4346 // We have two function definitions that conflict, same type, same
4347 // name. We should really check to make sure that this is the result
4348 // of integer type planes collapsing and generate an error if it is
4349 // not, but we'll just rename on the assumption that it is. However,
4350 // let's do it intelligently and rename the internal linkage one
4351 // if there is one.
4352 std::string NewName(makeNameUnique(FunctionName));
4353 if (Conflict->hasInternalLinkage()) {
4354 Conflict->setName(NewName);
4355 RenameMapKey Key = std::make_pair(FunctionName,Conflict->getType());
4356 CurModule.RenameMap[Key] = NewName;
4357 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
4358 InsertValue(Fn, CurModule.Values);
4359 } else {
4360 Fn = new Function(FT, CurFun.Linkage, NewName, M);
4361 InsertValue(Fn, CurModule.Values);
4362 RenameMapKey Key = std::make_pair(FunctionName,PFT);
4363 CurModule.RenameMap[Key] = NewName;
4364 }
4365 } else {
4366 // If they are not both definitions, then just use the function we
4367 // found since the types are the same.
4368 Fn = cast<Function>(Conflict);
Reid Spenceref9b9a72007-02-05 20:47:22 +00004369
Reid Spencered96d1e2007-02-08 09:08:52 +00004370 // Make sure to strip off any argument names so we can't get
4371 // conflicts.
4372 if (Fn->isDeclaration())
4373 for (Function::arg_iterator AI = Fn->arg_begin(),
4374 AE = Fn->arg_end(); AI != AE; ++AI)
4375 AI->setName("");
4376 }
4377 } else if (Conflict) {
4378 // We have two globals with the same name and different types.
4379 // Previously, this was permitted because the symbol table had
4380 // "type planes" and names only needed to be distinct within a
4381 // type plane. After PR411 was fixed, this is no loner the case.
4382 // To resolve this we must rename one of the two.
4383 if (Conflict->hasInternalLinkage()) {
4384 // We can safely renamed the Conflict.
4385 Conflict->setName(makeNameUnique(Conflict->getName()));
4386 RenameMapKey Key = std::make_pair(FunctionName,Conflict->getType());
4387 CurModule.RenameMap[Key] = Conflict->getName();
4388 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
4389 InsertValue(Fn, CurModule.Values);
4390 } else if (CurFun.Linkage == GlobalValue::InternalLinkage) {
4391 // We can safely rename the function we're defining
4392 std::string NewName = makeNameUnique(FunctionName);
4393 Fn = new Function(FT, CurFun.Linkage, NewName, M);
4394 InsertValue(Fn, CurModule.Values);
4395 RenameMapKey Key = std::make_pair(FunctionName,PFT);
4396 CurModule.RenameMap[Key] = NewName;
4397 } else {
4398 // We can't quietly rename either of these things, but we must
4399 // rename one of them. Generate a warning about the renaming and
4400 // elect to rename the thing we're now defining.
4401 std::string NewName = makeNameUnique(FunctionName);
4402 warning("Renaming function '" + FunctionName + "' as '" + NewName +
4403 "' may cause linkage errors");
4404 Fn = new Function(FT, CurFun.Linkage, NewName, M);
4405 InsertValue(Fn, CurModule.Values);
4406 RenameMapKey Key = std::make_pair(FunctionName,PFT);
4407 CurModule.RenameMap[Key] = NewName;
4408 }
Reid Spenceref9b9a72007-02-05 20:47:22 +00004409 } else {
Reid Spencered96d1e2007-02-08 09:08:52 +00004410 // There's no conflict, just define the function
4411 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
4412 InsertValue(Fn, CurModule.Values);
Reid Spenceref9b9a72007-02-05 20:47:22 +00004413 }
Reid Spencer950bf602007-01-26 08:19:09 +00004414 }
4415
4416 CurFun.FunctionStart(Fn);
4417
4418 if (CurFun.isDeclare) {
4419 // If we have declaration, always overwrite linkage. This will allow us
4420 // to correctly handle cases, when pointer to function is passed as
4421 // argument to another function.
4422 Fn->setLinkage(CurFun.Linkage);
4423 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00004424 Fn->setCallingConv(upgradeCallingConv(yyvsp[-7].UIntVal));
4425 Fn->setAlignment(yyvsp[0].UIntVal);
4426 if (yyvsp[-1].StrVal) {
4427 Fn->setSection(yyvsp[-1].StrVal);
4428 free(yyvsp[-1].StrVal);
Reid Spencer950bf602007-01-26 08:19:09 +00004429 }
4430
4431 // Add all of the arguments we parsed to the function...
Chris Lattner4227bdb2007-02-19 07:34:02 +00004432 if (yyvsp[-3].ArgList) { // Is null if empty...
Reid Spencer950bf602007-01-26 08:19:09 +00004433 if (isVarArg) { // Nuke the last entry
Chris Lattner4227bdb2007-02-19 07:34:02 +00004434 assert(yyvsp[-3].ArgList->back().first.PAT->get() == Type::VoidTy &&
4435 yyvsp[-3].ArgList->back().second == 0 && "Not a varargs marker");
4436 delete yyvsp[-3].ArgList->back().first.PAT;
4437 yyvsp[-3].ArgList->pop_back(); // Delete the last entry
Reid Spencer950bf602007-01-26 08:19:09 +00004438 }
4439 Function::arg_iterator ArgIt = Fn->arg_begin();
Reid Spenceref9b9a72007-02-05 20:47:22 +00004440 Function::arg_iterator ArgEnd = Fn->arg_end();
Chris Lattner4227bdb2007-02-19 07:34:02 +00004441 std::vector<std::pair<PATypeInfo,char*> >::iterator I = yyvsp[-3].ArgList->begin();
4442 std::vector<std::pair<PATypeInfo,char*> >::iterator E = yyvsp[-3].ArgList->end();
Reid Spenceref9b9a72007-02-05 20:47:22 +00004443 for ( ; I != E && ArgIt != ArgEnd; ++I, ++ArgIt) {
Reid Spencered96d1e2007-02-08 09:08:52 +00004444 delete I->first.PAT; // Delete the typeholder...
Reid Spencer950bf602007-01-26 08:19:09 +00004445 setValueName(ArgIt, I->second); // Insert arg into symtab...
4446 InsertValue(ArgIt);
4447 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00004448 delete yyvsp[-3].ArgList; // We're now done with the argument list
Reid Spencer950bf602007-01-26 08:19:09 +00004449 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00004450 ;
4451 break;}
4452case 223:
4453#line 2750 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4454{
4455 yyval.FunctionVal = CurFun.CurrentFunction;
Reid Spencer950bf602007-01-26 08:19:09 +00004456
4457 // Make sure that we keep track of the linkage type even if there was a
4458 // previous "declare".
Chris Lattner4227bdb2007-02-19 07:34:02 +00004459 yyval.FunctionVal->setLinkage(yyvsp[-2].Linkage);
4460 ;
4461 break;}
4462case 226:
4463#line 2764 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4464{
4465 yyval.FunctionVal = yyvsp[-1].FunctionVal;
4466 ;
4467 break;}
4468case 227:
4469#line 2769 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4470{ yyval.Linkage = GlobalValue::ExternalLinkage; ;
4471 break;}
4472case 228:
4473#line 2770 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4474{ yyval.Linkage = GlobalValue::DLLImportLinkage; ;
4475 break;}
4476case 229:
4477#line 2771 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4478{ yyval.Linkage = GlobalValue::ExternalWeakLinkage; ;
4479 break;}
4480case 230:
4481#line 2775 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4482{ CurFun.isDeclare = true; ;
4483 break;}
4484case 231:
4485#line 2776 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4486{ CurFun.Linkage = yyvsp[0].Linkage; ;
4487 break;}
4488case 232:
4489#line 2776 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4490{
4491 yyval.FunctionVal = CurFun.CurrentFunction;
Reid Spencer950bf602007-01-26 08:19:09 +00004492 CurFun.FunctionDone();
4493
Chris Lattner4227bdb2007-02-19 07:34:02 +00004494 ;
4495 break;}
4496case 233:
4497#line 2788 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4498{ yyval.BoolVal = false; ;
4499 break;}
4500case 234:
4501#line 2789 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4502{ yyval.BoolVal = true; ;
4503 break;}
4504case 235:
4505#line 2794 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4506{ yyval.ValIDVal = ValID::create(yyvsp[0].SInt64Val); ;
4507 break;}
4508case 236:
4509#line 2795 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4510{ yyval.ValIDVal = ValID::create(yyvsp[0].UInt64Val); ;
4511 break;}
4512case 237:
4513#line 2796 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4514{ yyval.ValIDVal = ValID::create(yyvsp[0].FPVal); ;
4515 break;}
4516case 238:
4517#line 2797 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4518{ yyval.ValIDVal = ValID::create(ConstantInt::get(Type::Int1Ty, true)); ;
4519 break;}
4520case 239:
4521#line 2798 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4522{ yyval.ValIDVal = ValID::create(ConstantInt::get(Type::Int1Ty, false)); ;
4523 break;}
4524case 240:
4525#line 2799 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4526{ yyval.ValIDVal = ValID::createNull(); ;
4527 break;}
4528case 241:
4529#line 2800 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4530{ yyval.ValIDVal = ValID::createUndef(); ;
4531 break;}
4532case 242:
4533#line 2801 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4534{ yyval.ValIDVal = ValID::createZeroInit(); ;
4535 break;}
4536case 243:
4537#line 2802 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4538{ // Nonempty unsized packed vector
4539 const Type *ETy = (*yyvsp[-1].ConstVector)[0].C->getType();
4540 int NumElements = yyvsp[-1].ConstVector->size();
Reid Spencer9d6565a2007-02-15 02:26:10 +00004541 VectorType* pt = VectorType::get(ETy, NumElements);
Reid Spencer950bf602007-01-26 08:19:09 +00004542 PATypeHolder* PTy = new PATypeHolder(
Reid Spencer9d6565a2007-02-15 02:26:10 +00004543 HandleUpRefs(VectorType::get(ETy, NumElements)));
Reid Spencer950bf602007-01-26 08:19:09 +00004544
4545 // Verify all elements are correct type!
4546 std::vector<Constant*> Elems;
Chris Lattner4227bdb2007-02-19 07:34:02 +00004547 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
4548 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Reid Spencer950bf602007-01-26 08:19:09 +00004549 const Type *CTy = C->getType();
4550 if (ETy != CTy)
4551 error("Element #" + utostr(i) + " is not of type '" +
4552 ETy->getDescription() +"' as required!\nIt is of type '" +
4553 CTy->getDescription() + "'");
4554 Elems.push_back(C);
Reid Spencere77e35e2006-12-01 20:26:20 +00004555 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00004556 yyval.ValIDVal = ValID::create(ConstantVector::get(pt, Elems));
4557 delete PTy; delete yyvsp[-1].ConstVector;
4558 ;
4559 break;}
4560case 244:
4561#line 2823 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4562{
4563 yyval.ValIDVal = ValID::create(yyvsp[0].ConstVal.C);
4564 ;
4565 break;}
4566case 245:
4567#line 2826 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4568{
4569 char *End = UnEscapeLexed(yyvsp[-2].StrVal, true);
4570 std::string AsmStr = std::string(yyvsp[-2].StrVal, End);
4571 End = UnEscapeLexed(yyvsp[0].StrVal, true);
4572 std::string Constraints = std::string(yyvsp[0].StrVal, End);
4573 yyval.ValIDVal = ValID::createInlineAsm(AsmStr, Constraints, yyvsp[-3].BoolVal);
4574 free(yyvsp[-2].StrVal);
4575 free(yyvsp[0].StrVal);
4576 ;
4577 break;}
4578case 246:
4579#line 2841 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4580{ yyval.ValIDVal = ValID::create(yyvsp[0].SIntVal); ;
4581 break;}
4582case 247:
4583#line 2842 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4584{ yyval.ValIDVal = ValID::create(yyvsp[0].StrVal); ;
4585 break;}
4586case 250:
4587#line 2855 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4588{
4589 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
4590 yyval.ValueVal.S = yyvsp[-1].TypeVal.S;
4591 yyval.ValueVal.V = getVal(Ty, yyvsp[0].ValIDVal);
4592 delete yyvsp[-1].TypeVal.PAT;
4593 ;
4594 break;}
4595case 251:
4596#line 2864 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4597{
4598 yyval.FunctionVal = yyvsp[-1].FunctionVal;
4599 ;
4600 break;}
4601case 252:
4602#line 2867 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4603{ // Do not allow functions with 0 basic blocks
4604 yyval.FunctionVal = yyvsp[-1].FunctionVal;
4605 ;
4606 break;}
4607case 253:
4608#line 2876 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4609{
4610 setValueName(yyvsp[0].TermInstVal, yyvsp[-1].StrVal);
4611 InsertValue(yyvsp[0].TermInstVal);
4612 yyvsp[-2].BasicBlockVal->getInstList().push_back(yyvsp[0].TermInstVal);
4613 InsertValue(yyvsp[-2].BasicBlockVal);
4614 yyval.BasicBlockVal = yyvsp[-2].BasicBlockVal;
4615 ;
4616 break;}
4617case 254:
4618#line 2886 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4619{
4620 if (yyvsp[0].InstVal.I)
4621 yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].InstVal.I);
4622 yyval.BasicBlockVal = yyvsp[-1].BasicBlockVal;
4623 ;
4624 break;}
4625case 255:
4626#line 2891 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4627{
4628 yyval.BasicBlockVal = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++), true);
Reid Spencer950bf602007-01-26 08:19:09 +00004629 // Make sure to move the basic block to the correct location in the
4630 // function, instead of leaving it inserted wherever it was first
4631 // referenced.
4632 Function::BasicBlockListType &BBL =
4633 CurFun.CurrentFunction->getBasicBlockList();
Chris Lattner4227bdb2007-02-19 07:34:02 +00004634 BBL.splice(BBL.end(), BBL, yyval.BasicBlockVal);
4635 ;
4636 break;}
4637case 256:
4638#line 2900 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4639{
4640 yyval.BasicBlockVal = CurBB = getBBVal(ValID::create(yyvsp[0].StrVal), true);
Reid Spencer950bf602007-01-26 08:19:09 +00004641 // Make sure to move the basic block to the correct location in the
4642 // function, instead of leaving it inserted wherever it was first
4643 // referenced.
4644 Function::BasicBlockListType &BBL =
4645 CurFun.CurrentFunction->getBasicBlockList();
Chris Lattner4227bdb2007-02-19 07:34:02 +00004646 BBL.splice(BBL.end(), BBL, yyval.BasicBlockVal);
4647 ;
4648 break;}
4649case 259:
4650#line 2914 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4651{ // Return with a result...
4652 yyval.TermInstVal = new ReturnInst(yyvsp[0].ValueVal.V);
4653 ;
4654 break;}
4655case 260:
4656#line 2917 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4657{ // Return with no result...
4658 yyval.TermInstVal = new ReturnInst();
4659 ;
4660 break;}
4661case 261:
4662#line 2920 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4663{ // Unconditional Branch...
4664 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
4665 yyval.TermInstVal = new BranchInst(tmpBB);
4666 ;
4667 break;}
4668case 262:
4669#line 2924 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4670{
4671 BasicBlock* tmpBBA = getBBVal(yyvsp[-3].ValIDVal);
4672 BasicBlock* tmpBBB = getBBVal(yyvsp[0].ValIDVal);
4673 Value* tmpVal = getVal(Type::Int1Ty, yyvsp[-6].ValIDVal);
4674 yyval.TermInstVal = new BranchInst(tmpBBA, tmpBBB, tmpVal);
4675 ;
4676 break;}
4677case 263:
4678#line 2930 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4679{
4680 Value* tmpVal = getVal(yyvsp[-7].PrimType.T, yyvsp[-6].ValIDVal);
4681 BasicBlock* tmpBB = getBBVal(yyvsp[-3].ValIDVal);
4682 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, yyvsp[-1].JumpTable->size());
4683 yyval.TermInstVal = S;
4684 std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = yyvsp[-1].JumpTable->begin(),
4685 E = yyvsp[-1].JumpTable->end();
Reid Spencer950bf602007-01-26 08:19:09 +00004686 for (; I != E; ++I) {
4687 if (ConstantInt *CI = dyn_cast<ConstantInt>(I->first))
4688 S->addCase(CI, I->second);
4689 else
4690 error("Switch case is constant, but not a simple integer");
4691 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00004692 delete yyvsp[-1].JumpTable;
4693 ;
4694 break;}
4695case 264:
4696#line 2945 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4697{
4698 Value* tmpVal = getVal(yyvsp[-6].PrimType.T, yyvsp[-5].ValIDVal);
4699 BasicBlock* tmpBB = getBBVal(yyvsp[-2].ValIDVal);
Reid Spencer950bf602007-01-26 08:19:09 +00004700 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0);
Chris Lattner4227bdb2007-02-19 07:34:02 +00004701 yyval.TermInstVal = S;
4702 ;
4703 break;}
4704case 265:
4705#line 2952 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4706{
Reid Spencer950bf602007-01-26 08:19:09 +00004707 const PointerType *PFTy;
4708 const FunctionType *Ty;
4709
Chris Lattner4227bdb2007-02-19 07:34:02 +00004710 if (!(PFTy = dyn_cast<PointerType>(yyvsp[-10].TypeVal.PAT->get())) ||
Reid Spencer950bf602007-01-26 08:19:09 +00004711 !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
4712 // Pull out the types of all of the arguments...
4713 std::vector<const Type*> ParamTypes;
Chris Lattner4227bdb2007-02-19 07:34:02 +00004714 if (yyvsp[-7].ValueList) {
4715 for (std::vector<ValueInfo>::iterator I = yyvsp[-7].ValueList->begin(), E = yyvsp[-7].ValueList->end();
Reid Spencer950bf602007-01-26 08:19:09 +00004716 I != E; ++I)
4717 ParamTypes.push_back((*I).V->getType());
4718 }
Reid Spencerb7046c72007-01-29 05:41:34 +00004719 FunctionType::ParamAttrsList ParamAttrs;
Chris Lattner4227bdb2007-02-19 07:34:02 +00004720 if (yyvsp[-11].UIntVal == OldCallingConv::CSRet) {
Reid Spencerb7046c72007-01-29 05:41:34 +00004721 ParamAttrs.push_back(FunctionType::NoAttributeSet);
4722 ParamAttrs.push_back(FunctionType::StructRetAttribute);
4723 }
Reid Spencer950bf602007-01-26 08:19:09 +00004724 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
4725 if (isVarArg) ParamTypes.pop_back();
Chris Lattner4227bdb2007-02-19 07:34:02 +00004726 Ty = FunctionType::get(yyvsp[-10].TypeVal.PAT->get(), ParamTypes, isVarArg, ParamAttrs);
Reid Spencer950bf602007-01-26 08:19:09 +00004727 PFTy = PointerType::get(Ty);
4728 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00004729 Value *V = getVal(PFTy, yyvsp[-9].ValIDVal); // Get the function we're calling...
4730 BasicBlock *Normal = getBBVal(yyvsp[-3].ValIDVal);
4731 BasicBlock *Except = getBBVal(yyvsp[0].ValIDVal);
Reid Spencer950bf602007-01-26 08:19:09 +00004732
4733 // Create the call node...
Chris Lattner4227bdb2007-02-19 07:34:02 +00004734 if (!yyvsp[-7].ValueList) { // Has no arguments?
4735 yyval.TermInstVal = new InvokeInst(V, Normal, Except, 0, 0);
Reid Spencer950bf602007-01-26 08:19:09 +00004736 } else { // Has arguments?
4737 // Loop through FunctionType's arguments and ensure they are specified
4738 // correctly!
4739 //
4740 FunctionType::param_iterator I = Ty->param_begin();
4741 FunctionType::param_iterator E = Ty->param_end();
Chris Lattner4227bdb2007-02-19 07:34:02 +00004742 std::vector<ValueInfo>::iterator ArgI = yyvsp[-7].ValueList->begin(), ArgE = yyvsp[-7].ValueList->end();
Reid Spencer950bf602007-01-26 08:19:09 +00004743
4744 std::vector<Value*> Args;
4745 for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
4746 if ((*ArgI).V->getType() != *I)
4747 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
4748 (*I)->getDescription() + "'");
4749 Args.push_back((*ArgI).V);
4750 }
4751
4752 if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
4753 error("Invalid number of parameters detected");
4754
Chris Lattner4227bdb2007-02-19 07:34:02 +00004755 yyval.TermInstVal = new InvokeInst(V, Normal, Except, &Args[0], Args.size());
Reid Spencer950bf602007-01-26 08:19:09 +00004756 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00004757 cast<InvokeInst>(yyval.TermInstVal)->setCallingConv(upgradeCallingConv(yyvsp[-11].UIntVal));
4758 delete yyvsp[-10].TypeVal.PAT;
4759 delete yyvsp[-7].ValueList;
4760 ;
4761 break;}
4762case 266:
4763#line 3007 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4764{
4765 yyval.TermInstVal = new UnwindInst();
4766 ;
4767 break;}
4768case 267:
4769#line 3010 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4770{
4771 yyval.TermInstVal = new UnreachableInst();
4772 ;
4773 break;}
4774case 268:
4775#line 3016 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4776{
4777 yyval.JumpTable = yyvsp[-5].JumpTable;
4778 Constant *V = cast<Constant>(getExistingValue(yyvsp[-4].PrimType.T, yyvsp[-3].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00004779
4780 if (V == 0)
4781 error("May only switch on a constant pool value");
4782
Chris Lattner4227bdb2007-02-19 07:34:02 +00004783 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
4784 yyval.JumpTable->push_back(std::make_pair(V, tmpBB));
4785 ;
4786 break;}
4787case 269:
4788#line 3026 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4789{
4790 yyval.JumpTable = new std::vector<std::pair<Constant*, BasicBlock*> >();
4791 Constant *V = cast<Constant>(getExistingValue(yyvsp[-4].PrimType.T, yyvsp[-3].ValIDVal));
Reid Spencer950bf602007-01-26 08:19:09 +00004792
4793 if (V == 0)
4794 error("May only switch on a constant pool value");
4795
Chris Lattner4227bdb2007-02-19 07:34:02 +00004796 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
4797 yyval.JumpTable->push_back(std::make_pair(V, tmpBB));
4798 ;
4799 break;}
4800case 270:
4801#line 3039 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4802{
Reid Spencer950bf602007-01-26 08:19:09 +00004803 bool omit = false;
Chris Lattner4227bdb2007-02-19 07:34:02 +00004804 if (yyvsp[-1].StrVal)
4805 if (BitCastInst *BCI = dyn_cast<BitCastInst>(yyvsp[0].InstVal.I))
Reid Spencer950bf602007-01-26 08:19:09 +00004806 if (BCI->getSrcTy() == BCI->getDestTy() &&
Chris Lattner4227bdb2007-02-19 07:34:02 +00004807 BCI->getOperand(0)->getName() == yyvsp[-1].StrVal)
Reid Spencer950bf602007-01-26 08:19:09 +00004808 // This is a useless bit cast causing a name redefinition. It is
4809 // a bit cast from a type to the same type of an operand with the
4810 // same name as the name we would give this instruction. Since this
4811 // instruction results in no code generation, it is safe to omit
4812 // the instruction. This situation can occur because of collapsed
4813 // type planes. For example:
4814 // %X = add int %Y, %Z
4815 // %X = cast int %Y to uint
4816 // After upgrade, this looks like:
4817 // %X = add i32 %Y, %Z
4818 // %X = bitcast i32 to i32
4819 // The bitcast is clearly useless so we omit it.
4820 omit = true;
4821 if (omit) {
Chris Lattner4227bdb2007-02-19 07:34:02 +00004822 yyval.InstVal.I = 0;
4823 yyval.InstVal.S = Signless;
Reid Spencer950bf602007-01-26 08:19:09 +00004824 } else {
Chris Lattner4227bdb2007-02-19 07:34:02 +00004825 setValueName(yyvsp[0].InstVal.I, yyvsp[-1].StrVal);
4826 InsertValue(yyvsp[0].InstVal.I);
4827 yyval.InstVal = yyvsp[0].InstVal;
Reid Spencer950bf602007-01-26 08:19:09 +00004828 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00004829 ;
4830 break;}
4831case 271:
4832#line 3068 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4833{ // Used for PHI nodes
4834 yyval.PHIList.P = new std::list<std::pair<Value*, BasicBlock*> >();
4835 yyval.PHIList.S = yyvsp[-5].TypeVal.S;
4836 Value* tmpVal = getVal(yyvsp[-5].TypeVal.PAT->get(), yyvsp[-3].ValIDVal);
4837 BasicBlock* tmpBB = getBBVal(yyvsp[-1].ValIDVal);
4838 yyval.PHIList.P->push_back(std::make_pair(tmpVal, tmpBB));
4839 delete yyvsp[-5].TypeVal.PAT;
4840 ;
4841 break;}
4842case 272:
4843#line 3076 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4844{
4845 yyval.PHIList = yyvsp[-6].PHIList;
4846 Value* tmpVal = getVal(yyvsp[-6].PHIList.P->front().first->getType(), yyvsp[-3].ValIDVal);
4847 BasicBlock* tmpBB = getBBVal(yyvsp[-1].ValIDVal);
4848 yyvsp[-6].PHIList.P->push_back(std::make_pair(tmpVal, tmpBB));
4849 ;
4850 break;}
4851case 273:
4852#line 3084 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4853{ // Used for call statements, and memory insts...
4854 yyval.ValueList = new std::vector<ValueInfo>();
4855 yyval.ValueList->push_back(yyvsp[0].ValueVal);
4856 ;
4857 break;}
4858case 274:
4859#line 3088 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4860{
4861 yyval.ValueList = yyvsp[-2].ValueList;
4862 yyvsp[-2].ValueList->push_back(yyvsp[0].ValueVal);
4863 ;
4864 break;}
4865case 276:
4866#line 3096 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4867{ yyval.ValueList = 0; ;
4868 break;}
4869case 277:
4870#line 3100 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4871{
4872 yyval.BoolVal = true;
4873 ;
4874 break;}
4875case 278:
4876#line 3103 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4877{
4878 yyval.BoolVal = false;
4879 ;
4880 break;}
4881case 279:
4882#line 3109 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4883{
4884 const Type* Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00004885 if (!Ty->isInteger() && !Ty->isFloatingPoint() && !isa<VectorType>(Ty))
Reid Spencer950bf602007-01-26 08:19:09 +00004886 error("Arithmetic operator requires integer, FP, or packed operands");
Reid Spencer9d6565a2007-02-15 02:26:10 +00004887 if (isa<VectorType>(Ty) &&
Chris Lattner4227bdb2007-02-19 07:34:02 +00004888 (yyvsp[-4].BinaryOpVal == URemOp || yyvsp[-4].BinaryOpVal == SRemOp || yyvsp[-4].BinaryOpVal == FRemOp || yyvsp[-4].BinaryOpVal == RemOp))
4889 error("Remainder not supported on vector types");
Reid Spencer950bf602007-01-26 08:19:09 +00004890 // Upgrade the opcode from obsolete versions before we do anything with it.
Chris Lattner4227bdb2007-02-19 07:34:02 +00004891 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-4].BinaryOpVal, Ty, yyvsp[-3].TypeVal.S);
4892 Value* val1 = getVal(Ty, yyvsp[-2].ValIDVal);
4893 Value* val2 = getVal(Ty, yyvsp[0].ValIDVal);
4894 yyval.InstVal.I = BinaryOperator::create(Opcode, val1, val2);
4895 if (yyval.InstVal.I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00004896 error("binary operator returned null");
Chris Lattner4227bdb2007-02-19 07:34:02 +00004897 yyval.InstVal.S = yyvsp[-3].TypeVal.S;
4898 delete yyvsp[-3].TypeVal.PAT;
4899 ;
4900 break;}
4901case 280:
4902#line 3126 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4903{
4904 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00004905 if (!Ty->isInteger()) {
Reid Spencer9d6565a2007-02-15 02:26:10 +00004906 if (!isa<VectorType>(Ty) ||
4907 !cast<VectorType>(Ty)->getElementType()->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00004908 error("Logical operator requires integral operands");
4909 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00004910 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-4].BinaryOpVal, Ty, yyvsp[-3].TypeVal.S);
4911 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
4912 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
4913 yyval.InstVal.I = BinaryOperator::create(Opcode, tmpVal1, tmpVal2);
4914 if (yyval.InstVal.I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00004915 error("binary operator returned null");
Chris Lattner4227bdb2007-02-19 07:34:02 +00004916 yyval.InstVal.S = yyvsp[-3].TypeVal.S;
4917 delete yyvsp[-3].TypeVal.PAT;
4918 ;
4919 break;}
4920case 281:
4921#line 3142 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4922{
4923 const Type* Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00004924 if(isa<VectorType>(Ty))
4925 error("VectorTypes currently not supported in setcc instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00004926 unsigned short pred;
Chris Lattner4227bdb2007-02-19 07:34:02 +00004927 Instruction::OtherOps Opcode = getCompareOp(yyvsp[-4].BinaryOpVal, pred, Ty, yyvsp[-3].TypeVal.S);
4928 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
4929 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
4930 yyval.InstVal.I = CmpInst::create(Opcode, pred, tmpVal1, tmpVal2);
4931 if (yyval.InstVal.I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00004932 error("binary operator returned null");
Chris Lattner4227bdb2007-02-19 07:34:02 +00004933 yyval.InstVal.S = Unsigned;
4934 delete yyvsp[-3].TypeVal.PAT;
4935 ;
4936 break;}
4937case 282:
4938#line 3156 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4939{
4940 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00004941 if (isa<VectorType>(Ty))
4942 error("VectorTypes currently not supported in icmp instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00004943 else if (!Ty->isInteger() && !isa<PointerType>(Ty))
4944 error("icmp requires integer or pointer typed operands");
Chris Lattner4227bdb2007-02-19 07:34:02 +00004945 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
4946 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
4947 yyval.InstVal.I = new ICmpInst(yyvsp[-4].IPred, tmpVal1, tmpVal2);
4948 yyval.InstVal.S = Unsigned;
4949 delete yyvsp[-3].TypeVal.PAT;
4950 ;
4951 break;}
4952case 283:
4953#line 3168 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4954{
4955 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Reid Spencer9d6565a2007-02-15 02:26:10 +00004956 if (isa<VectorType>(Ty))
4957 error("VectorTypes currently not supported in fcmp instructions");
Reid Spencer950bf602007-01-26 08:19:09 +00004958 else if (!Ty->isFloatingPoint())
4959 error("fcmp instruction requires floating point operands");
Chris Lattner4227bdb2007-02-19 07:34:02 +00004960 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
4961 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
4962 yyval.InstVal.I = new FCmpInst(yyvsp[-4].FPred, tmpVal1, tmpVal2);
4963 yyval.InstVal.S = Unsigned;
4964 delete yyvsp[-3].TypeVal.PAT;
4965 ;
4966 break;}
4967case 284:
4968#line 3180 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4969{
Reid Spencer950bf602007-01-26 08:19:09 +00004970 warning("Use of obsolete 'not' instruction: Replacing with 'xor");
Chris Lattner4227bdb2007-02-19 07:34:02 +00004971 const Type *Ty = yyvsp[0].ValueVal.V->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00004972 Value *Ones = ConstantInt::getAllOnesValue(Ty);
4973 if (Ones == 0)
4974 error("Expected integral type for not instruction");
Chris Lattner4227bdb2007-02-19 07:34:02 +00004975 yyval.InstVal.I = BinaryOperator::create(Instruction::Xor, yyvsp[0].ValueVal.V, Ones);
4976 if (yyval.InstVal.I == 0)
Reid Spencer950bf602007-01-26 08:19:09 +00004977 error("Could not create a xor instruction");
Chris Lattner4227bdb2007-02-19 07:34:02 +00004978 yyval.InstVal.S = yyvsp[0].ValueVal.S
4979 ;
4980 break;}
4981case 285:
4982#line 3191 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
4983{
4984 if (!yyvsp[0].ValueVal.V->getType()->isInteger() ||
4985 cast<IntegerType>(yyvsp[0].ValueVal.V->getType())->getBitWidth() != 8)
Reid Spencer950bf602007-01-26 08:19:09 +00004986 error("Shift amount must be int8");
Chris Lattner4227bdb2007-02-19 07:34:02 +00004987 const Type* Ty = yyvsp[-2].ValueVal.V->getType();
Reid Spencer832254e2007-02-02 02:16:23 +00004988 if (!Ty->isInteger())
Reid Spencer950bf602007-01-26 08:19:09 +00004989 error("Shift constant expression requires integer operand");
Reid Spencer832254e2007-02-02 02:16:23 +00004990 Value* ShiftAmt = 0;
4991 if (cast<IntegerType>(Ty)->getBitWidth() > Type::Int8Ty->getBitWidth())
Chris Lattner4227bdb2007-02-19 07:34:02 +00004992 if (Constant *C = dyn_cast<Constant>(yyvsp[0].ValueVal.V))
Reid Spencer832254e2007-02-02 02:16:23 +00004993 ShiftAmt = ConstantExpr::getZExt(C, Ty);
4994 else
Chris Lattner4227bdb2007-02-19 07:34:02 +00004995 ShiftAmt = new ZExtInst(yyvsp[0].ValueVal.V, Ty, makeNameUnique("shift"), CurBB);
Reid Spencer832254e2007-02-02 02:16:23 +00004996 else
Chris Lattner4227bdb2007-02-19 07:34:02 +00004997 ShiftAmt = yyvsp[0].ValueVal.V;
4998 yyval.InstVal.I = BinaryOperator::create(getBinaryOp(yyvsp[-3].BinaryOpVal, Ty, yyvsp[-2].ValueVal.S), yyvsp[-2].ValueVal.V, ShiftAmt);
4999 yyval.InstVal.S = yyvsp[-2].ValueVal.S;
5000 ;
5001 break;}
5002case 286:
5003#line 3209 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5004{
5005 const Type *DstTy = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005006 if (!DstTy->isFirstClassType())
5007 error("cast instruction to a non-primitive type: '" +
5008 DstTy->getDescription() + "'");
Chris Lattner4227bdb2007-02-19 07:34:02 +00005009 yyval.InstVal.I = cast<Instruction>(getCast(yyvsp[-3].CastOpVal, yyvsp[-2].ValueVal.V, yyvsp[-2].ValueVal.S, DstTy, yyvsp[0].TypeVal.S, true));
5010 yyval.InstVal.S = yyvsp[0].TypeVal.S;
5011 delete yyvsp[0].TypeVal.PAT;
5012 ;
5013 break;}
5014case 287:
5015#line 3218 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5016{
5017 if (!yyvsp[-4].ValueVal.V->getType()->isInteger() ||
5018 cast<IntegerType>(yyvsp[-4].ValueVal.V->getType())->getBitWidth() != 1)
Reid Spencer950bf602007-01-26 08:19:09 +00005019 error("select condition must be bool");
Chris Lattner4227bdb2007-02-19 07:34:02 +00005020 if (yyvsp[-2].ValueVal.V->getType() != yyvsp[0].ValueVal.V->getType())
Reid Spencer950bf602007-01-26 08:19:09 +00005021 error("select value types should match");
Chris Lattner4227bdb2007-02-19 07:34:02 +00005022 yyval.InstVal.I = new SelectInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
5023 yyval.InstVal.S = yyvsp[-4].ValueVal.S;
5024 ;
5025 break;}
5026case 288:
5027#line 3227 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5028{
5029 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005030 NewVarArgs = true;
Chris Lattner4227bdb2007-02-19 07:34:02 +00005031 yyval.InstVal.I = new VAArgInst(yyvsp[-2].ValueVal.V, Ty);
5032 yyval.InstVal.S = yyvsp[0].TypeVal.S;
5033 delete yyvsp[0].TypeVal.PAT;
5034 ;
5035 break;}
5036case 289:
5037#line 3234 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5038{
5039 const Type* ArgTy = yyvsp[-2].ValueVal.V->getType();
5040 const Type* DstTy = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005041 ObsoleteVarArgs = true;
5042 Function* NF = cast<Function>(CurModule.CurrentModule->
5043 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
5044
5045 //b = vaarg a, t ->
5046 //foo = alloca 1 of t
5047 //bar = vacopy a
5048 //store bar -> foo
5049 //b = vaarg foo, t
5050 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vaarg.fix");
5051 CurBB->getInstList().push_back(foo);
Chris Lattner4227bdb2007-02-19 07:34:02 +00005052 CallInst* bar = new CallInst(NF, yyvsp[-2].ValueVal.V);
Reid Spencer950bf602007-01-26 08:19:09 +00005053 CurBB->getInstList().push_back(bar);
5054 CurBB->getInstList().push_back(new StoreInst(bar, foo));
Chris Lattner4227bdb2007-02-19 07:34:02 +00005055 yyval.InstVal.I = new VAArgInst(foo, DstTy);
5056 yyval.InstVal.S = yyvsp[0].TypeVal.S;
5057 delete yyvsp[0].TypeVal.PAT;
5058 ;
5059 break;}
5060case 290:
5061#line 3255 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5062{
5063 const Type* ArgTy = yyvsp[-2].ValueVal.V->getType();
5064 const Type* DstTy = yyvsp[0].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005065 ObsoleteVarArgs = true;
5066 Function* NF = cast<Function>(CurModule.CurrentModule->
5067 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
5068
5069 //b = vanext a, t ->
5070 //foo = alloca 1 of t
5071 //bar = vacopy a
5072 //store bar -> foo
5073 //tmp = vaarg foo, t
5074 //b = load foo
5075 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vanext.fix");
5076 CurBB->getInstList().push_back(foo);
Chris Lattner4227bdb2007-02-19 07:34:02 +00005077 CallInst* bar = new CallInst(NF, yyvsp[-2].ValueVal.V);
Reid Spencer950bf602007-01-26 08:19:09 +00005078 CurBB->getInstList().push_back(bar);
5079 CurBB->getInstList().push_back(new StoreInst(bar, foo));
5080 Instruction* tmp = new VAArgInst(foo, DstTy);
5081 CurBB->getInstList().push_back(tmp);
Chris Lattner4227bdb2007-02-19 07:34:02 +00005082 yyval.InstVal.I = new LoadInst(foo);
5083 yyval.InstVal.S = yyvsp[0].TypeVal.S;
5084 delete yyvsp[0].TypeVal.PAT;
5085 ;
5086 break;}
5087case 291:
5088#line 3279 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5089{
5090 if (!ExtractElementInst::isValidOperands(yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Reid Spencer950bf602007-01-26 08:19:09 +00005091 error("Invalid extractelement operands");
Chris Lattner4227bdb2007-02-19 07:34:02 +00005092 yyval.InstVal.I = new ExtractElementInst(yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
5093 yyval.InstVal.S = yyvsp[-2].ValueVal.S;
5094 ;
5095 break;}
5096case 292:
5097#line 3285 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5098{
5099 if (!InsertElementInst::isValidOperands(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Reid Spencer950bf602007-01-26 08:19:09 +00005100 error("Invalid insertelement operands");
Chris Lattner4227bdb2007-02-19 07:34:02 +00005101 yyval.InstVal.I = new InsertElementInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
5102 yyval.InstVal.S = yyvsp[-4].ValueVal.S;
5103 ;
5104 break;}
5105case 293:
5106#line 3291 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5107{
5108 if (!ShuffleVectorInst::isValidOperands(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Reid Spencer950bf602007-01-26 08:19:09 +00005109 error("Invalid shufflevector operands");
Chris Lattner4227bdb2007-02-19 07:34:02 +00005110 yyval.InstVal.I = new ShuffleVectorInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
5111 yyval.InstVal.S = yyvsp[-4].ValueVal.S;
5112 ;
5113 break;}
5114case 294:
5115#line 3297 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5116{
5117 const Type *Ty = yyvsp[0].PHIList.P->front().first->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00005118 if (!Ty->isFirstClassType())
5119 error("PHI node operands must be of first class type");
5120 PHINode *PHI = new PHINode(Ty);
Chris Lattner4227bdb2007-02-19 07:34:02 +00005121 PHI->reserveOperandSpace(yyvsp[0].PHIList.P->size());
5122 while (yyvsp[0].PHIList.P->begin() != yyvsp[0].PHIList.P->end()) {
5123 if (yyvsp[0].PHIList.P->front().first->getType() != Ty)
Reid Spencer950bf602007-01-26 08:19:09 +00005124 error("All elements of a PHI node must be of the same type");
Chris Lattner4227bdb2007-02-19 07:34:02 +00005125 PHI->addIncoming(yyvsp[0].PHIList.P->front().first, yyvsp[0].PHIList.P->front().second);
5126 yyvsp[0].PHIList.P->pop_front();
Reid Spencer950bf602007-01-26 08:19:09 +00005127 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00005128 yyval.InstVal.I = PHI;
5129 yyval.InstVal.S = yyvsp[0].PHIList.S;
5130 delete yyvsp[0].PHIList.P; // Free the list...
5131 ;
5132 break;}
5133case 295:
5134#line 3313 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5135{
Reid Spencer950bf602007-01-26 08:19:09 +00005136
5137 // Handle the short call syntax
5138 const PointerType *PFTy;
5139 const FunctionType *FTy;
Chris Lattner4227bdb2007-02-19 07:34:02 +00005140 if (!(PFTy = dyn_cast<PointerType>(yyvsp[-4].TypeVal.PAT->get())) ||
Reid Spencer950bf602007-01-26 08:19:09 +00005141 !(FTy = dyn_cast<FunctionType>(PFTy->getElementType()))) {
5142 // Pull out the types of all of the arguments...
5143 std::vector<const Type*> ParamTypes;
Chris Lattner4227bdb2007-02-19 07:34:02 +00005144 if (yyvsp[-1].ValueList) {
5145 for (std::vector<ValueInfo>::iterator I = yyvsp[-1].ValueList->begin(), E = yyvsp[-1].ValueList->end();
Reid Spencer950bf602007-01-26 08:19:09 +00005146 I != E; ++I)
5147 ParamTypes.push_back((*I).V->getType());
5148 }
5149
Reid Spencerb7046c72007-01-29 05:41:34 +00005150 FunctionType::ParamAttrsList ParamAttrs;
Chris Lattner4227bdb2007-02-19 07:34:02 +00005151 if (yyvsp[-5].UIntVal == OldCallingConv::CSRet) {
Reid Spencerb7046c72007-01-29 05:41:34 +00005152 ParamAttrs.push_back(FunctionType::NoAttributeSet);
5153 ParamAttrs.push_back(FunctionType::StructRetAttribute);
5154 }
Reid Spencer950bf602007-01-26 08:19:09 +00005155 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
5156 if (isVarArg) ParamTypes.pop_back();
5157
Chris Lattner4227bdb2007-02-19 07:34:02 +00005158 const Type *RetTy = yyvsp[-4].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005159 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
5160 error("Functions cannot return aggregate types");
5161
Reid Spencerb7046c72007-01-29 05:41:34 +00005162 FTy = FunctionType::get(RetTy, ParamTypes, isVarArg, ParamAttrs);
Reid Spencer950bf602007-01-26 08:19:09 +00005163 PFTy = PointerType::get(FTy);
5164 }
5165
5166 // First upgrade any intrinsic calls.
5167 std::vector<Value*> Args;
Chris Lattner4227bdb2007-02-19 07:34:02 +00005168 if (yyvsp[-1].ValueList)
5169 for (unsigned i = 0, e = yyvsp[-1].ValueList->size(); i < e; ++i)
5170 Args.push_back((*yyvsp[-1].ValueList)[i].V);
5171 Instruction *Inst = upgradeIntrinsicCall(FTy, yyvsp[-3].ValIDVal, Args);
Reid Spencer950bf602007-01-26 08:19:09 +00005172
5173 // If we got an upgraded intrinsic
5174 if (Inst) {
Chris Lattner4227bdb2007-02-19 07:34:02 +00005175 yyval.InstVal.I = Inst;
5176 yyval.InstVal.S = Signless;
Reid Spencer950bf602007-01-26 08:19:09 +00005177 } else {
5178 // Get the function we're calling
Chris Lattner4227bdb2007-02-19 07:34:02 +00005179 Value *V = getVal(PFTy, yyvsp[-3].ValIDVal);
Reid Spencer950bf602007-01-26 08:19:09 +00005180
5181 // Check the argument values match
Chris Lattner4227bdb2007-02-19 07:34:02 +00005182 if (!yyvsp[-1].ValueList) { // Has no arguments?
Reid Spencer950bf602007-01-26 08:19:09 +00005183 // Make sure no arguments is a good thing!
5184 if (FTy->getNumParams() != 0)
5185 error("No arguments passed to a function that expects arguments");
5186 } else { // Has arguments?
5187 // Loop through FunctionType's arguments and ensure they are specified
5188 // correctly!
5189 //
5190 FunctionType::param_iterator I = FTy->param_begin();
5191 FunctionType::param_iterator E = FTy->param_end();
Chris Lattner4227bdb2007-02-19 07:34:02 +00005192 std::vector<ValueInfo>::iterator ArgI = yyvsp[-1].ValueList->begin(), ArgE = yyvsp[-1].ValueList->end();
Reid Spencer950bf602007-01-26 08:19:09 +00005193
5194 for (; ArgI != ArgE && I != E; ++ArgI, ++I)
5195 if ((*ArgI).V->getType() != *I)
5196 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
5197 (*I)->getDescription() + "'");
5198
5199 if (I != E || (ArgI != ArgE && !FTy->isVarArg()))
5200 error("Invalid number of parameters detected");
5201 }
5202
5203 // Create the call instruction
Chris Lattnercf3d0612007-02-13 06:04:17 +00005204 CallInst *CI = new CallInst(V, &Args[0], Args.size());
Chris Lattner4227bdb2007-02-19 07:34:02 +00005205 CI->setTailCall(yyvsp[-6].BoolVal);
5206 CI->setCallingConv(upgradeCallingConv(yyvsp[-5].UIntVal));
5207 yyval.InstVal.I = CI;
5208 yyval.InstVal.S = yyvsp[-4].TypeVal.S;
Reid Spencer950bf602007-01-26 08:19:09 +00005209 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00005210 delete yyvsp[-4].TypeVal.PAT;
5211 delete yyvsp[-1].ValueList;
5212 ;
5213 break;}
5214case 296:
5215#line 3391 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5216{
5217 yyval.InstVal = yyvsp[0].InstVal;
5218 ;
5219 break;}
5220case 297:
5221#line 3399 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5222{ yyval.ValueList = yyvsp[0].ValueList; ;
5223 break;}
5224case 298:
5225#line 3400 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5226{ yyval.ValueList = new std::vector<ValueInfo>(); ;
5227 break;}
5228case 299:
5229#line 3404 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5230{ yyval.BoolVal = true; ;
5231 break;}
5232case 300:
5233#line 3405 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5234{ yyval.BoolVal = false; ;
5235 break;}
5236case 301:
5237#line 3409 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5238{
5239 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
5240 yyval.InstVal.S = yyvsp[-1].TypeVal.S;
5241 yyval.InstVal.I = new MallocInst(Ty, 0, yyvsp[0].UIntVal);
5242 delete yyvsp[-1].TypeVal.PAT;
5243 ;
5244 break;}
5245case 302:
5246#line 3415 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5247{
5248 const Type *Ty = yyvsp[-4].TypeVal.PAT->get();
5249 yyval.InstVal.S = yyvsp[-4].TypeVal.S;
5250 yyval.InstVal.I = new MallocInst(Ty, getVal(yyvsp[-2].PrimType.T, yyvsp[-1].ValIDVal), yyvsp[0].UIntVal);
5251 delete yyvsp[-4].TypeVal.PAT;
5252 ;
5253 break;}
5254case 303:
5255#line 3421 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5256{
5257 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
5258 yyval.InstVal.S = yyvsp[-1].TypeVal.S;
5259 yyval.InstVal.I = new AllocaInst(Ty, 0, yyvsp[0].UIntVal);
5260 delete yyvsp[-1].TypeVal.PAT;
5261 ;
5262 break;}
5263case 304:
5264#line 3427 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5265{
5266 const Type *Ty = yyvsp[-4].TypeVal.PAT->get();
5267 yyval.InstVal.S = yyvsp[-4].TypeVal.S;
5268 yyval.InstVal.I = new AllocaInst(Ty, getVal(yyvsp[-2].PrimType.T, yyvsp[-1].ValIDVal), yyvsp[0].UIntVal);
5269 delete yyvsp[-4].TypeVal.PAT;
5270 ;
5271 break;}
5272case 305:
5273#line 3433 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5274{
5275 const Type *PTy = yyvsp[0].ValueVal.V->getType();
Reid Spencer950bf602007-01-26 08:19:09 +00005276 if (!isa<PointerType>(PTy))
5277 error("Trying to free nonpointer type '" + PTy->getDescription() + "'");
Chris Lattner4227bdb2007-02-19 07:34:02 +00005278 yyval.InstVal.I = new FreeInst(yyvsp[0].ValueVal.V);
5279 yyval.InstVal.S = Signless;
5280 ;
5281 break;}
5282case 306:
5283#line 3440 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5284{
5285 const Type* Ty = yyvsp[-1].TypeVal.PAT->get();
5286 yyval.InstVal.S = yyvsp[-1].TypeVal.S;
Reid Spencer950bf602007-01-26 08:19:09 +00005287 if (!isa<PointerType>(Ty))
5288 error("Can't load from nonpointer type: " + Ty->getDescription());
5289 if (!cast<PointerType>(Ty)->getElementType()->isFirstClassType())
5290 error("Can't load from pointer of non-first-class type: " +
5291 Ty->getDescription());
Chris Lattner4227bdb2007-02-19 07:34:02 +00005292 Value* tmpVal = getVal(Ty, yyvsp[0].ValIDVal);
5293 yyval.InstVal.I = new LoadInst(tmpVal, "", yyvsp[-3].BoolVal);
5294 delete yyvsp[-1].TypeVal.PAT;
5295 ;
5296 break;}
5297case 307:
5298#line 3452 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5299{
5300 const PointerType *PTy = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Reid Spencered96d1e2007-02-08 09:08:52 +00005301 if (!PTy)
5302 error("Can't store to a nonpointer type: " +
Chris Lattner4227bdb2007-02-19 07:34:02 +00005303 yyvsp[-1].TypeVal.PAT->get()->getDescription());
Reid Spencered96d1e2007-02-08 09:08:52 +00005304 const Type *ElTy = PTy->getElementType();
Chris Lattner4227bdb2007-02-19 07:34:02 +00005305 Value *StoreVal = yyvsp[-3].ValueVal.V;
5306 Value* tmpVal = getVal(PTy, yyvsp[0].ValIDVal);
5307 if (ElTy != yyvsp[-3].ValueVal.V->getType()) {
5308 StoreVal = handleSRetFuncTypeMerge(yyvsp[-3].ValueVal.V, ElTy);
Reid Spencered96d1e2007-02-08 09:08:52 +00005309 if (!StoreVal)
Chris Lattner4227bdb2007-02-19 07:34:02 +00005310 error("Can't store '" + yyvsp[-3].ValueVal.V->getType()->getDescription() +
Reid Spencered96d1e2007-02-08 09:08:52 +00005311 "' into space of type '" + ElTy->getDescription() + "'");
5312 else {
5313 PTy = PointerType::get(StoreVal->getType());
5314 if (Constant *C = dyn_cast<Constant>(tmpVal))
5315 tmpVal = ConstantExpr::getBitCast(C, PTy);
5316 else
5317 tmpVal = new BitCastInst(tmpVal, PTy, "upgrd.cast", CurBB);
5318 }
5319 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00005320 yyval.InstVal.I = new StoreInst(StoreVal, tmpVal, yyvsp[-5].BoolVal);
5321 yyval.InstVal.S = Signless;
5322 delete yyvsp[-1].TypeVal.PAT;
5323 ;
5324 break;}
5325case 308:
5326#line 3477 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
5327{
5328 const Type* Ty = yyvsp[-2].TypeVal.PAT->get();
Reid Spencer950bf602007-01-26 08:19:09 +00005329 if (!isa<PointerType>(Ty))
5330 error("getelementptr insn requires pointer operand");
5331
5332 std::vector<Value*> VIndices;
Chris Lattner4227bdb2007-02-19 07:34:02 +00005333 upgradeGEPIndices(Ty, yyvsp[0].ValueList, VIndices);
Reid Spencer950bf602007-01-26 08:19:09 +00005334
Chris Lattner4227bdb2007-02-19 07:34:02 +00005335 Value* tmpVal = getVal(Ty, yyvsp[-1].ValIDVal);
5336 yyval.InstVal.I = new GetElementPtrInst(tmpVal, &VIndices[0], VIndices.size());
5337 yyval.InstVal.S = Signless;
5338 delete yyvsp[-2].TypeVal.PAT;
5339 delete yyvsp[0].ValueList;
5340 ;
5341 break;}
5342}
5343 /* the action file gets copied in in place of this dollarsign */
5344#line 543 "/usr/share/bison.simple"
Chris Lattnercf3d0612007-02-13 06:04:17 +00005345
5346 yyvsp -= yylen;
5347 yyssp -= yylen;
Chris Lattner4227bdb2007-02-19 07:34:02 +00005348#ifdef YYLSP_NEEDED
5349 yylsp -= yylen;
5350#endif
Reid Spencerb7046c72007-01-29 05:41:34 +00005351
Chris Lattner4227bdb2007-02-19 07:34:02 +00005352#if YYDEBUG != 0
5353 if (yydebug)
5354 {
5355 short *ssp1 = yyss - 1;
5356 fprintf (stderr, "state stack now");
5357 while (ssp1 != yyssp)
5358 fprintf (stderr, " %d", *++ssp1);
5359 fprintf (stderr, "\n");
5360 }
5361#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00005362
5363 *++yyvsp = yyval;
5364
Chris Lattner4227bdb2007-02-19 07:34:02 +00005365#ifdef YYLSP_NEEDED
5366 yylsp++;
5367 if (yylen == 0)
5368 {
5369 yylsp->first_line = yylloc.first_line;
5370 yylsp->first_column = yylloc.first_column;
5371 yylsp->last_line = (yylsp-1)->last_line;
5372 yylsp->last_column = (yylsp-1)->last_column;
5373 yylsp->text = 0;
5374 }
5375 else
5376 {
5377 yylsp->last_line = (yylsp+yylen-1)->last_line;
5378 yylsp->last_column = (yylsp+yylen-1)->last_column;
5379 }
5380#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00005381
Chris Lattner4227bdb2007-02-19 07:34:02 +00005382 /* Now "shift" the result of the reduction.
5383 Determine what state that goes to,
5384 based on the state we popped back to
5385 and the rule number reduced by. */
Reid Spencere7c3c602006-11-30 06:36:44 +00005386
5387 yyn = yyr1[yyn];
5388
Chris Lattner4227bdb2007-02-19 07:34:02 +00005389 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
5390 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
Reid Spencere7c3c602006-11-30 06:36:44 +00005391 yystate = yytable[yystate];
5392 else
Chris Lattner4227bdb2007-02-19 07:34:02 +00005393 yystate = yydefgoto[yyn - YYNTBASE];
Reid Spencere7c3c602006-11-30 06:36:44 +00005394
5395 goto yynewstate;
5396
Chris Lattner4227bdb2007-02-19 07:34:02 +00005397yyerrlab: /* here on detecting error */
Reid Spencere7c3c602006-11-30 06:36:44 +00005398
Chris Lattner4227bdb2007-02-19 07:34:02 +00005399 if (! yyerrstatus)
5400 /* If not already recovering from an error, report this error. */
Reid Spencere7c3c602006-11-30 06:36:44 +00005401 {
5402 ++yynerrs;
Chris Lattner4227bdb2007-02-19 07:34:02 +00005403
5404#ifdef YYERROR_VERBOSE
Chris Lattnercf3d0612007-02-13 06:04:17 +00005405 yyn = yypact[yystate];
5406
Chris Lattner4227bdb2007-02-19 07:34:02 +00005407 if (yyn > YYFLAG && yyn < YYLAST)
Chris Lattnercf3d0612007-02-13 06:04:17 +00005408 {
Chris Lattner4227bdb2007-02-19 07:34:02 +00005409 int size = 0;
5410 char *msg;
5411 int x, count;
Chris Lattnercf3d0612007-02-13 06:04:17 +00005412
Chris Lattner4227bdb2007-02-19 07:34:02 +00005413 count = 0;
5414 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
5415 for (x = (yyn < 0 ? -yyn : 0);
5416 x < (sizeof(yytname) / sizeof(char *)); x++)
5417 if (yycheck[x + yyn] == x)
5418 size += strlen(yytname[x]) + 15, count++;
5419 msg = (char *) malloc(size + 15);
5420 if (msg != 0)
Chris Lattnercf3d0612007-02-13 06:04:17 +00005421 {
Chris Lattner4227bdb2007-02-19 07:34:02 +00005422 strcpy(msg, "parse error");
5423
5424 if (count < 5)
Chris Lattnercf3d0612007-02-13 06:04:17 +00005425 {
Chris Lattner4227bdb2007-02-19 07:34:02 +00005426 count = 0;
5427 for (x = (yyn < 0 ? -yyn : 0);
5428 x < (sizeof(yytname) / sizeof(char *)); x++)
5429 if (yycheck[x + yyn] == x)
5430 {
5431 strcat(msg, count == 0 ? ", expecting `" : " or `");
5432 strcat(msg, yytname[x]);
5433 strcat(msg, "'");
5434 count++;
5435 }
Chris Lattnercf3d0612007-02-13 06:04:17 +00005436 }
Chris Lattner4227bdb2007-02-19 07:34:02 +00005437 yyerror(msg);
5438 free(msg);
Chris Lattnercf3d0612007-02-13 06:04:17 +00005439 }
5440 else
Chris Lattner4227bdb2007-02-19 07:34:02 +00005441 yyerror ("parse error; also virtual memory exceeded");
Chris Lattnercf3d0612007-02-13 06:04:17 +00005442 }
5443 else
5444#endif /* YYERROR_VERBOSE */
Chris Lattner4227bdb2007-02-19 07:34:02 +00005445 yyerror("parse error");
Reid Spencere7c3c602006-11-30 06:36:44 +00005446 }
Reid Spencer950bf602007-01-26 08:19:09 +00005447
Chris Lattner4227bdb2007-02-19 07:34:02 +00005448 goto yyerrlab1;
5449yyerrlab1: /* here on error raised explicitly by an action */
Reid Spencer950bf602007-01-26 08:19:09 +00005450
5451 if (yyerrstatus == 3)
5452 {
Chris Lattner4227bdb2007-02-19 07:34:02 +00005453 /* if just tried and failed to reuse lookahead token after an error, discard it. */
Reid Spencer950bf602007-01-26 08:19:09 +00005454
Chris Lattner4227bdb2007-02-19 07:34:02 +00005455 /* return failure if at end of input */
5456 if (yychar == YYEOF)
Reid Spencere7c3c602006-11-30 06:36:44 +00005457 YYABORT;
5458
Chris Lattner4227bdb2007-02-19 07:34:02 +00005459#if YYDEBUG != 0
5460 if (yydebug)
5461 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
5462#endif
Reid Spencere7c3c602006-11-30 06:36:44 +00005463
Chris Lattner4227bdb2007-02-19 07:34:02 +00005464 yychar = YYEMPTY;
Reid Spencere7c3c602006-11-30 06:36:44 +00005465 }
5466
Chris Lattner4227bdb2007-02-19 07:34:02 +00005467 /* Else will try to reuse lookahead token
5468 after shifting the error token. */
5469
5470 yyerrstatus = 3; /* Each real token shifted decrements this */
5471
5472 goto yyerrhandle;
5473
5474yyerrdefault: /* current state does not do anything special for the error token. */
5475
5476#if 0
5477 /* This is wrong; only states that explicitly want error tokens
5478 should shift them. */
5479 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
5480 if (yyn) goto yydefault;
5481#endif
5482
5483yyerrpop: /* pop the current state because it cannot handle the error token */
5484
5485 if (yyssp == yyss) YYABORT;
5486 yyvsp--;
5487 yystate = *--yyssp;
5488#ifdef YYLSP_NEEDED
5489 yylsp--;
5490#endif
5491
5492#if YYDEBUG != 0
5493 if (yydebug)
5494 {
5495 short *ssp1 = yyss - 1;
5496 fprintf (stderr, "Error: state stack now");
5497 while (ssp1 != yyssp)
5498 fprintf (stderr, " %d", *++ssp1);
5499 fprintf (stderr, "\n");
5500 }
5501#endif
5502
5503yyerrhandle:
5504
5505 yyn = yypact[yystate];
5506 if (yyn == YYFLAG)
5507 goto yyerrdefault;
5508
5509 yyn += YYTERROR;
5510 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
5511 goto yyerrdefault;
5512
5513 yyn = yytable[yyn];
5514 if (yyn < 0)
5515 {
5516 if (yyn == YYFLAG)
5517 goto yyerrpop;
5518 yyn = -yyn;
5519 goto yyreduce;
5520 }
5521 else if (yyn == 0)
5522 goto yyerrpop;
5523
Reid Spencere7c3c602006-11-30 06:36:44 +00005524 if (yyn == YYFINAL)
5525 YYACCEPT;
5526
Chris Lattner4227bdb2007-02-19 07:34:02 +00005527#if YYDEBUG != 0
5528 if (yydebug)
5529 fprintf(stderr, "Shifting error token, ");
5530#endif
5531
Reid Spencere7c3c602006-11-30 06:36:44 +00005532 *++yyvsp = yylval;
Chris Lattner4227bdb2007-02-19 07:34:02 +00005533#ifdef YYLSP_NEEDED
5534 *++yylsp = yylloc;
5535#endif
Reid Spencer950bf602007-01-26 08:19:09 +00005536
Reid Spencere7c3c602006-11-30 06:36:44 +00005537 yystate = yyn;
5538 goto yynewstate;
5539
Chris Lattner4227bdb2007-02-19 07:34:02 +00005540 yyacceptlab:
5541 /* YYACCEPT comes here. */
5542 if (yyfree_stacks)
Reid Spencer9d6565a2007-02-15 02:26:10 +00005543 {
Chris Lattner4227bdb2007-02-19 07:34:02 +00005544 free (yyss);
5545 free (yyvs);
5546#ifdef YYLSP_NEEDED
5547 free (yyls);
Reid Spencer9d6565a2007-02-15 02:26:10 +00005548#endif
Chris Lattner4227bdb2007-02-19 07:34:02 +00005549 }
5550 return 0;
5551
5552 yyabortlab:
5553 /* YYABORT comes here. */
5554 if (yyfree_stacks)
5555 {
5556 free (yyss);
5557 free (yyvs);
5558#ifdef YYLSP_NEEDED
5559 free (yyls);
5560#endif
5561 }
5562 return 1;
Reid Spencere7c3c602006-11-30 06:36:44 +00005563}
Chris Lattner4227bdb2007-02-19 07:34:02 +00005564#line 3493 "/Users/sabre/cvs/llvm/tools/llvm-upgrade/UpgradeParser.y"
Reid Spencere7c3c602006-11-30 06:36:44 +00005565
5566
5567int yyerror(const char *ErrorMsg) {
5568 std::string where
5569 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
Reid Spencered96d1e2007-02-08 09:08:52 +00005570 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
Reid Spencer950bf602007-01-26 08:19:09 +00005571 std::string errMsg = where + "error: " + std::string(ErrorMsg);
5572 if (yychar != YYEMPTY && yychar != 0)
5573 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
5574 "'.";
Reid Spencer71d2ec92006-12-31 06:02:26 +00005575 std::cerr << "llvm-upgrade: " << errMsg << '\n';
Reid Spencer950bf602007-01-26 08:19:09 +00005576 std::cout << "llvm-upgrade: parse failed.\n";
Reid Spencere7c3c602006-11-30 06:36:44 +00005577 exit(1);
5578}
Reid Spencer319a7302007-01-05 17:20:02 +00005579
Reid Spencer30d0c582007-01-15 00:26:18 +00005580void warning(const std::string& ErrorMsg) {
Reid Spencer319a7302007-01-05 17:20:02 +00005581 std::string where
5582 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
Reid Spencered96d1e2007-02-08 09:08:52 +00005583 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
Reid Spencer950bf602007-01-26 08:19:09 +00005584 std::string errMsg = where + "warning: " + std::string(ErrorMsg);
5585 if (yychar != YYEMPTY && yychar != 0)
5586 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
5587 "'.";
Reid Spencer319a7302007-01-05 17:20:02 +00005588 std::cerr << "llvm-upgrade: " << errMsg << '\n';
5589}
5590
Reid Spencer950bf602007-01-26 08:19:09 +00005591void error(const std::string& ErrorMsg, int LineNo) {
5592 if (LineNo == -1) LineNo = Upgradelineno;
5593 Upgradelineno = LineNo;
5594 yyerror(ErrorMsg.c_str());
5595}
5596