blob: 2f6c02a216fb82ec27ed7c8ec44c8f0aef9470d7 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001
Dale Johannesen3afee192007-09-07 21:07:57 +00002/* A Bison parser, made from /Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y
3 by GNU Bison version 1.28 */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004
Dale Johannesen3afee192007-09-07 21:07:57 +00005#define YYBISON 1 /* Identify Bison output. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00006
Dan Gohmanf17a25c2007-07-18 16:29:46 +00007#define yyparse Upgradeparse
Dale Johannesen3afee192007-09-07 21:07:57 +00008#define yylex Upgradelex
Dan Gohmanf17a25c2007-07-18 16:29:46 +00009#define yyerror Upgradeerror
Dale Johannesen3afee192007-09-07 21:07:57 +000010#define yylval Upgradelval
11#define yychar Upgradechar
Dan Gohmanf17a25c2007-07-18 16:29:46 +000012#define yydebug Upgradedebug
13#define yynerrs Upgradenerrs
Dale Johannesen3afee192007-09-07 21:07:57 +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
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000163
Dale Johannesen3afee192007-09-07 21:07:57 +0000164#line 14 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000165
166#include "UpgradeInternals.h"
167#include "llvm/CallingConv.h"
168#include "llvm/InlineAsm.h"
169#include "llvm/Instructions.h"
170#include "llvm/Module.h"
171#include "llvm/ParameterAttributes.h"
172#include "llvm/ValueSymbolTable.h"
173#include "llvm/Support/GetElementPtrTypeIterator.h"
174#include "llvm/ADT/STLExtras.h"
175#include "llvm/Support/MathExtras.h"
176#include <algorithm>
177#include <iostream>
178#include <map>
179#include <list>
180#include <utility>
181
182// DEBUG_UPREFS - Define this symbol if you want to enable debugging output
183// relating to upreferences in the input stream.
184//
185//#define DEBUG_UPREFS 1
186#ifdef DEBUG_UPREFS
187#define UR_OUT(X) std::cerr << X
188#else
189#define UR_OUT(X)
190#endif
191
192#define YYERROR_VERBOSE 1
193#define YYINCLUDED_STDLIB_H
194#define YYDEBUG 1
195
196int yylex();
197int yyparse();
198
199int yyerror(const char*);
200static void warning(const std::string& WarningMsg);
201
202namespace llvm {
203
204std::istream* LexInput;
205static std::string CurFilename;
206
207// This bool controls whether attributes are ever added to function declarations
208// definitions and calls.
209static bool AddAttributes = false;
210
211static Module *ParserResult;
212static bool ObsoleteVarArgs;
213static bool NewVarArgs;
214static BasicBlock *CurBB;
215static GlobalVariable *CurGV;
216static unsigned lastCallingConv;
217
218// This contains info used when building the body of a function. It is
219// destroyed when the function is completed.
220//
221typedef std::vector<Value *> ValueList; // Numbered defs
222
223typedef std::pair<std::string,TypeInfo> RenameMapKey;
224typedef std::map<RenameMapKey,std::string> RenameMapType;
225
226static void
227ResolveDefinitions(std::map<const Type *,ValueList> &LateResolvers,
228 std::map<const Type *,ValueList> *FutureLateResolvers = 0);
229
230static struct PerModuleInfo {
231 Module *CurrentModule;
232 std::map<const Type *, ValueList> Values; // Module level numbered definitions
233 std::map<const Type *,ValueList> LateResolveValues;
234 std::vector<PATypeHolder> Types;
235 std::vector<Signedness> TypeSigns;
236 std::map<std::string,Signedness> NamedTypeSigns;
237 std::map<std::string,Signedness> NamedValueSigns;
238 std::map<ValID, PATypeHolder> LateResolveTypes;
239 static Module::Endianness Endian;
240 static Module::PointerSize PointerSize;
241 RenameMapType RenameMap;
242
243 /// PlaceHolderInfo - When temporary placeholder objects are created, remember
244 /// how they were referenced and on which line of the input they came from so
245 /// that we can resolve them later and print error messages as appropriate.
246 std::map<Value*, std::pair<ValID, int> > PlaceHolderInfo;
247
248 // GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
249 // references to global values. Global values may be referenced before they
250 // are defined, and if so, the temporary object that they represent is held
251 // here. This is used for forward references of GlobalValues.
252 //
253 typedef std::map<std::pair<const PointerType *, ValID>, GlobalValue*>
254 GlobalRefsType;
255 GlobalRefsType GlobalRefs;
256
257 void ModuleDone() {
258 // If we could not resolve some functions at function compilation time
259 // (calls to functions before they are defined), resolve them now... Types
260 // are resolved when the constant pool has been completely parsed.
261 //
262 ResolveDefinitions(LateResolveValues);
263
264 // Check to make sure that all global value forward references have been
265 // resolved!
266 //
267 if (!GlobalRefs.empty()) {
268 std::string UndefinedReferences = "Unresolved global references exist:\n";
269
270 for (GlobalRefsType::iterator I = GlobalRefs.begin(), E =GlobalRefs.end();
271 I != E; ++I) {
272 UndefinedReferences += " " + I->first.first->getDescription() + " " +
273 I->first.second.getName() + "\n";
274 }
275 error(UndefinedReferences);
276 return;
277 }
278
279 if (CurrentModule->getDataLayout().empty()) {
280 std::string dataLayout;
281 if (Endian != Module::AnyEndianness)
282 dataLayout.append(Endian == Module::BigEndian ? "E" : "e");
283 if (PointerSize != Module::AnyPointerSize) {
284 if (!dataLayout.empty())
285 dataLayout += "-";
286 dataLayout.append(PointerSize == Module::Pointer64 ?
287 "p:64:64" : "p:32:32");
288 }
289 CurrentModule->setDataLayout(dataLayout);
290 }
291
292 Values.clear(); // Clear out function local definitions
293 Types.clear();
294 TypeSigns.clear();
295 NamedTypeSigns.clear();
296 NamedValueSigns.clear();
297 CurrentModule = 0;
298 }
299
300 // GetForwardRefForGlobal - Check to see if there is a forward reference
301 // for this global. If so, remove it from the GlobalRefs map and return it.
302 // If not, just return null.
303 GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ValID ID) {
304 // Check to see if there is a forward reference to this global variable...
305 // if there is, eliminate it and patch the reference to use the new def'n.
306 GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PTy, ID));
307 GlobalValue *Ret = 0;
308 if (I != GlobalRefs.end()) {
309 Ret = I->second;
310 GlobalRefs.erase(I);
311 }
312 return Ret;
313 }
314 void setEndianness(Module::Endianness E) { Endian = E; }
315 void setPointerSize(Module::PointerSize sz) { PointerSize = sz; }
316} CurModule;
317
318Module::Endianness PerModuleInfo::Endian = Module::AnyEndianness;
319Module::PointerSize PerModuleInfo::PointerSize = Module::AnyPointerSize;
320
321static struct PerFunctionInfo {
322 Function *CurrentFunction; // Pointer to current function being created
323
324 std::map<const Type*, ValueList> Values; // Keep track of #'d definitions
325 std::map<const Type*, ValueList> LateResolveValues;
326 bool isDeclare; // Is this function a forward declararation?
327 GlobalValue::LinkageTypes Linkage;// Linkage for forward declaration.
328
329 /// BBForwardRefs - When we see forward references to basic blocks, keep
330 /// track of them here.
331 std::map<BasicBlock*, std::pair<ValID, int> > BBForwardRefs;
332 std::vector<BasicBlock*> NumberedBlocks;
333 RenameMapType RenameMap;
334 unsigned NextBBNum;
335
336 inline PerFunctionInfo() {
337 CurrentFunction = 0;
338 isDeclare = false;
339 Linkage = GlobalValue::ExternalLinkage;
340 }
341
342 inline void FunctionStart(Function *M) {
343 CurrentFunction = M;
344 NextBBNum = 0;
345 }
346
347 void FunctionDone() {
348 NumberedBlocks.clear();
349
350 // Any forward referenced blocks left?
351 if (!BBForwardRefs.empty()) {
352 error("Undefined reference to label " +
353 BBForwardRefs.begin()->first->getName());
354 return;
355 }
356
357 // Resolve all forward references now.
358 ResolveDefinitions(LateResolveValues, &CurModule.LateResolveValues);
359
360 Values.clear(); // Clear out function local definitions
361 RenameMap.clear();
362 CurrentFunction = 0;
363 isDeclare = false;
364 Linkage = GlobalValue::ExternalLinkage;
365 }
366} CurFun; // Info for the current function...
367
368static bool inFunctionScope() { return CurFun.CurrentFunction != 0; }
369
370/// This function is just a utility to make a Key value for the rename map.
371/// The Key is a combination of the name, type, Signedness of the original
372/// value (global/function). This just constructs the key and ensures that
373/// named Signedness values are resolved to the actual Signedness.
374/// @brief Make a key for the RenameMaps
375static RenameMapKey makeRenameMapKey(const std::string &Name, const Type* Ty,
376 const Signedness &Sign) {
377 TypeInfo TI;
378 TI.T = Ty;
379 if (Sign.isNamed())
380 // Don't allow Named Signedness nodes because they won't match. The actual
381 // Signedness must be looked up in the NamedTypeSigns map.
382 TI.S.copy(CurModule.NamedTypeSigns[Sign.getName()]);
383 else
384 TI.S.copy(Sign);
385 return std::make_pair(Name, TI);
386}
387
388
389//===----------------------------------------------------------------------===//
390// Code to handle definitions of all the types
391//===----------------------------------------------------------------------===//
392
393static int InsertValue(Value *V,
394 std::map<const Type*,ValueList> &ValueTab = CurFun.Values) {
395 if (V->hasName()) return -1; // Is this a numbered definition?
396
397 // Yes, insert the value into the value table...
398 ValueList &List = ValueTab[V->getType()];
399 List.push_back(V);
400 return List.size()-1;
401}
402
403static const Type *getType(const ValID &D, bool DoNotImprovise = false) {
404 switch (D.Type) {
405 case ValID::NumberVal: // Is it a numbered definition?
406 // Module constants occupy the lowest numbered slots...
407 if ((unsigned)D.Num < CurModule.Types.size()) {
408 return CurModule.Types[(unsigned)D.Num];
409 }
410 break;
411 case ValID::NameVal: // Is it a named definition?
412 if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) {
413 return N;
414 }
415 break;
416 default:
417 error("Internal parser error: Invalid symbol type reference");
418 return 0;
419 }
420
421 // If we reached here, we referenced either a symbol that we don't know about
422 // or an id number that hasn't been read yet. We may be referencing something
423 // forward, so just create an entry to be resolved later and get to it...
424 //
425 if (DoNotImprovise) return 0; // Do we just want a null to be returned?
426
427 if (inFunctionScope()) {
428 if (D.Type == ValID::NameVal) {
429 error("Reference to an undefined type: '" + D.getName() + "'");
430 return 0;
431 } else {
432 error("Reference to an undefined type: #" + itostr(D.Num));
433 return 0;
434 }
435 }
436
437 std::map<ValID, PATypeHolder>::iterator I =CurModule.LateResolveTypes.find(D);
438 if (I != CurModule.LateResolveTypes.end())
439 return I->second;
440
441 Type *Typ = OpaqueType::get();
442 CurModule.LateResolveTypes.insert(std::make_pair(D, Typ));
443 return Typ;
444}
445
446/// This is like the getType method except that instead of looking up the type
447/// for a given ID, it looks up that type's sign.
448/// @brief Get the signedness of a referenced type
449static Signedness getTypeSign(const ValID &D) {
450 switch (D.Type) {
451 case ValID::NumberVal: // Is it a numbered definition?
452 // Module constants occupy the lowest numbered slots...
453 if ((unsigned)D.Num < CurModule.TypeSigns.size()) {
454 return CurModule.TypeSigns[(unsigned)D.Num];
455 }
456 break;
457 case ValID::NameVal: { // Is it a named definition?
458 std::map<std::string,Signedness>::const_iterator I =
459 CurModule.NamedTypeSigns.find(D.Name);
460 if (I != CurModule.NamedTypeSigns.end())
461 return I->second;
462 // Perhaps its a named forward .. just cache the name
463 Signedness S;
464 S.makeNamed(D.Name);
465 return S;
466 }
467 default:
468 break;
469 }
470 // If we don't find it, its signless
471 Signedness S;
472 S.makeSignless();
473 return S;
474}
475
476/// This function is analagous to getElementType in LLVM. It provides the same
477/// function except that it looks up the Signedness instead of the type. This is
478/// used when processing GEP instructions that need to extract the type of an
479/// indexed struct/array/ptr member.
480/// @brief Look up an element's sign.
481static Signedness getElementSign(const ValueInfo& VI,
482 const std::vector<Value*> &Indices) {
483 const Type *Ptr = VI.V->getType();
484 assert(isa<PointerType>(Ptr) && "Need pointer type");
485
486 unsigned CurIdx = 0;
487 Signedness S(VI.S);
488 while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) {
489 if (CurIdx == Indices.size())
490 break;
491
492 Value *Index = Indices[CurIdx++];
493 assert(!isa<PointerType>(CT) || CurIdx == 1 && "Invalid type");
494 Ptr = CT->getTypeAtIndex(Index);
495 if (const Type* Ty = Ptr->getForwardedType())
496 Ptr = Ty;
497 assert(S.isComposite() && "Bad Signedness type");
498 if (isa<StructType>(CT)) {
499 S = S.get(cast<ConstantInt>(Index)->getZExtValue());
500 } else {
501 S = S.get(0UL);
502 }
503 if (S.isNamed())
504 S = CurModule.NamedTypeSigns[S.getName()];
505 }
506 Signedness Result;
507 Result.makeComposite(S);
508 return Result;
509}
510
511/// This function just translates a ConstantInfo into a ValueInfo and calls
512/// getElementSign(ValueInfo,...). Its just a convenience.
513/// @brief ConstantInfo version of getElementSign.
514static Signedness getElementSign(const ConstInfo& CI,
515 const std::vector<Constant*> &Indices) {
516 ValueInfo VI;
517 VI.V = CI.C;
518 VI.S.copy(CI.S);
519 std::vector<Value*> Idx;
520 for (unsigned i = 0; i < Indices.size(); ++i)
521 Idx.push_back(Indices[i]);
522 Signedness result = getElementSign(VI, Idx);
523 VI.destroy();
524 return result;
525}
526
527/// This function determines if two function types differ only in their use of
528/// the sret parameter attribute in the first argument. If they are identical
529/// in all other respects, it returns true. Otherwise, it returns false.
530static bool FuncTysDifferOnlyBySRet(const FunctionType *F1,
531 const FunctionType *F2) {
532 if (F1->getReturnType() != F2->getReturnType() ||
533 F1->getNumParams() != F2->getNumParams())
534 return false;
535 const ParamAttrsList *PAL1 = F1->getParamAttrs();
536 const ParamAttrsList *PAL2 = F2->getParamAttrs();
537 if (PAL1 && !PAL2 || PAL2 && !PAL1)
538 return false;
539 if (PAL1 && PAL2 && ((PAL1->size() != PAL2->size()) ||
540 (PAL1->getParamAttrs(0) != PAL2->getParamAttrs(0))))
541 return false;
542 unsigned SRetMask = ~unsigned(ParamAttr::StructRet);
543 for (unsigned i = 0; i < F1->getNumParams(); ++i) {
544 if (F1->getParamType(i) != F2->getParamType(i) || (PAL1 && PAL2 &&
545 (unsigned(PAL1->getParamAttrs(i+1)) & SRetMask !=
546 unsigned(PAL2->getParamAttrs(i+1)) & SRetMask)))
547 return false;
548 }
549 return true;
550}
551
552/// This function determines if the type of V and Ty differ only by the SRet
553/// parameter attribute. This is a more generalized case of
554/// FuncTysDIfferOnlyBySRet since it doesn't require FunctionType arguments.
555static bool TypesDifferOnlyBySRet(Value *V, const Type* Ty) {
556 if (V->getType() == Ty)
557 return true;
558 const PointerType *PF1 = dyn_cast<PointerType>(Ty);
559 const PointerType *PF2 = dyn_cast<PointerType>(V->getType());
560 if (PF1 && PF2) {
561 const FunctionType* FT1 = dyn_cast<FunctionType>(PF1->getElementType());
562 const FunctionType* FT2 = dyn_cast<FunctionType>(PF2->getElementType());
563 if (FT1 && FT2)
564 return FuncTysDifferOnlyBySRet(FT1, FT2);
565 }
566 return false;
567}
568
569// The upgrade of csretcc to sret param attribute may have caused a function
570// to not be found because the param attribute changed the type of the called
571// function. This helper function, used in getExistingValue, detects that
572// situation and bitcasts the function to the correct type.
573static Value* handleSRetFuncTypeMerge(Value *V, const Type* Ty) {
574 // Handle degenerate cases
575 if (!V)
576 return 0;
577 if (V->getType() == Ty)
578 return V;
579
580 const PointerType *PF1 = dyn_cast<PointerType>(Ty);
581 const PointerType *PF2 = dyn_cast<PointerType>(V->getType());
582 if (PF1 && PF2) {
583 const FunctionType *FT1 = dyn_cast<FunctionType>(PF1->getElementType());
584 const FunctionType *FT2 = dyn_cast<FunctionType>(PF2->getElementType());
585 if (FT1 && FT2 && FuncTysDifferOnlyBySRet(FT1, FT2)) {
586 const ParamAttrsList *PAL2 = FT2->getParamAttrs();
587 if (PAL2 && PAL2->paramHasAttr(1, ParamAttr::StructRet))
588 return V;
589 else if (Constant *C = dyn_cast<Constant>(V))
590 return ConstantExpr::getBitCast(C, PF1);
591 else
592 return new BitCastInst(V, PF1, "upgrd.cast", CurBB);
593 }
594
595 }
596 return 0;
597}
598
599// getExistingValue - Look up the value specified by the provided type and
600// the provided ValID. If the value exists and has already been defined, return
601// it. Otherwise return null.
602//
603static Value *getExistingValue(const Type *Ty, const ValID &D) {
604 if (isa<FunctionType>(Ty)) {
605 error("Functions are not values and must be referenced as pointers");
606 }
607
608 switch (D.Type) {
609 case ValID::NumberVal: { // Is it a numbered definition?
610 unsigned Num = (unsigned)D.Num;
611
612 // Module constants occupy the lowest numbered slots...
613 std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
614 if (VI != CurModule.Values.end()) {
615 if (Num < VI->second.size())
616 return VI->second[Num];
617 Num -= VI->second.size();
618 }
619
620 // Make sure that our type is within bounds
621 VI = CurFun.Values.find(Ty);
622 if (VI == CurFun.Values.end()) return 0;
623
624 // Check that the number is within bounds...
625 if (VI->second.size() <= Num) return 0;
626
627 return VI->second[Num];
628 }
629
630 case ValID::NameVal: { // Is it a named definition?
631 // Get the name out of the ID
632 RenameMapKey Key = makeRenameMapKey(D.Name, Ty, D.S);
633 Value *V = 0;
634 if (inFunctionScope()) {
635 // See if the name was renamed
636 RenameMapType::const_iterator I = CurFun.RenameMap.find(Key);
637 std::string LookupName;
638 if (I != CurFun.RenameMap.end())
639 LookupName = I->second;
640 else
641 LookupName = D.Name;
642 ValueSymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable();
643 V = SymTab.lookup(LookupName);
644 if (V && V->getType() != Ty)
645 V = handleSRetFuncTypeMerge(V, Ty);
646 assert((!V || TypesDifferOnlyBySRet(V, Ty)) && "Found wrong type");
647 }
648 if (!V) {
649 RenameMapType::const_iterator I = CurModule.RenameMap.find(Key);
650 std::string LookupName;
651 if (I != CurModule.RenameMap.end())
652 LookupName = I->second;
653 else
654 LookupName = D.Name;
655 V = CurModule.CurrentModule->getValueSymbolTable().lookup(LookupName);
656 if (V && V->getType() != Ty)
657 V = handleSRetFuncTypeMerge(V, Ty);
658 assert((!V || TypesDifferOnlyBySRet(V, Ty)) && "Found wrong type");
659 }
660 if (!V)
661 return 0;
662
663 D.destroy(); // Free old strdup'd memory...
664 return V;
665 }
666
667 // Check to make sure that "Ty" is an integral type, and that our
668 // value will fit into the specified type...
669 case ValID::ConstSIntVal: // Is it a constant pool reference??
670 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
671 error("Signed integral constant '" + itostr(D.ConstPool64) +
672 "' is invalid for type '" + Ty->getDescription() + "'");
673 }
674 return ConstantInt::get(Ty, D.ConstPool64);
675
676 case ValID::ConstUIntVal: // Is it an unsigned const pool reference?
677 if (!ConstantInt::isValueValidForType(Ty, D.UConstPool64)) {
678 if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64))
679 error("Integral constant '" + utostr(D.UConstPool64) +
680 "' is invalid or out of range");
681 else // This is really a signed reference. Transmogrify.
682 return ConstantInt::get(Ty, D.ConstPool64);
683 } else
684 return ConstantInt::get(Ty, D.UConstPool64);
685
686 case ValID::ConstFPVal: // Is it a floating point const pool reference?
Dale Johannesen3afee192007-09-07 21:07:57 +0000687 if (!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP))
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000688 error("FP constant invalid for type");
Dale Johannesen3afee192007-09-07 21:07:57 +0000689 // Lexer has no type info, so builds all FP constants as double.
690 // Fix this here.
691 if (Ty==Type::FloatTy)
692 D.ConstPoolFP->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
693 return ConstantFP::get(Ty, *D.ConstPoolFP);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000694
695 case ValID::ConstNullVal: // Is it a null value?
696 if (!isa<PointerType>(Ty))
697 error("Cannot create a a non pointer null");
698 return ConstantPointerNull::get(cast<PointerType>(Ty));
699
700 case ValID::ConstUndefVal: // Is it an undef value?
701 return UndefValue::get(Ty);
702
703 case ValID::ConstZeroVal: // Is it a zero value?
704 return Constant::getNullValue(Ty);
705
706 case ValID::ConstantVal: // Fully resolved constant?
707 if (D.ConstantValue->getType() != Ty)
708 error("Constant expression type different from required type");
709 return D.ConstantValue;
710
711 case ValID::InlineAsmVal: { // Inline asm expression
712 const PointerType *PTy = dyn_cast<PointerType>(Ty);
713 const FunctionType *FTy =
714 PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
715 if (!FTy || !InlineAsm::Verify(FTy, D.IAD->Constraints))
716 error("Invalid type for asm constraint string");
717 InlineAsm *IA = InlineAsm::get(FTy, D.IAD->AsmString, D.IAD->Constraints,
718 D.IAD->HasSideEffects);
719 D.destroy(); // Free InlineAsmDescriptor.
720 return IA;
721 }
722 default:
723 assert(0 && "Unhandled case");
724 return 0;
725 } // End of switch
726
727 assert(0 && "Unhandled case");
728 return 0;
729}
730
731// getVal - This function is identical to getExistingValue, except that if a
732// value is not already defined, it "improvises" by creating a placeholder var
733// that looks and acts just like the requested variable. When the value is
734// defined later, all uses of the placeholder variable are replaced with the
735// real thing.
736//
737static Value *getVal(const Type *Ty, const ValID &ID) {
738 if (Ty == Type::LabelTy)
739 error("Cannot use a basic block here");
740
741 // See if the value has already been defined.
742 Value *V = getExistingValue(Ty, ID);
743 if (V) return V;
744
745 if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty))
746 error("Invalid use of a composite type");
747
748 // If we reached here, we referenced either a symbol that we don't know about
749 // or an id number that hasn't been read yet. We may be referencing something
750 // forward, so just create an entry to be resolved later and get to it...
751 V = new Argument(Ty);
752
753 // Remember where this forward reference came from. FIXME, shouldn't we try
754 // to recycle these things??
755 CurModule.PlaceHolderInfo.insert(
756 std::make_pair(V, std::make_pair(ID, Upgradelineno)));
757
758 if (inFunctionScope())
759 InsertValue(V, CurFun.LateResolveValues);
760 else
761 InsertValue(V, CurModule.LateResolveValues);
762 return V;
763}
764
765/// @brief This just makes any name given to it unique, up to MAX_UINT times.
766static std::string makeNameUnique(const std::string& Name) {
767 static unsigned UniqueNameCounter = 1;
768 std::string Result(Name);
769 Result += ".upgrd." + llvm::utostr(UniqueNameCounter++);
770 return Result;
771}
772
773/// getBBVal - This is used for two purposes:
774/// * If isDefinition is true, a new basic block with the specified ID is being
775/// defined.
776/// * If isDefinition is true, this is a reference to a basic block, which may
777/// or may not be a forward reference.
778///
779static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
780 assert(inFunctionScope() && "Can't get basic block at global scope");
781
782 std::string Name;
783 BasicBlock *BB = 0;
784 switch (ID.Type) {
785 default:
786 error("Illegal label reference " + ID.getName());
787 break;
788 case ValID::NumberVal: // Is it a numbered definition?
789 if (unsigned(ID.Num) >= CurFun.NumberedBlocks.size())
790 CurFun.NumberedBlocks.resize(ID.Num+1);
791 BB = CurFun.NumberedBlocks[ID.Num];
792 break;
793 case ValID::NameVal: // Is it a named definition?
794 Name = ID.Name;
795 if (Value *N = CurFun.CurrentFunction->getValueSymbolTable().lookup(Name)) {
796 if (N->getType() != Type::LabelTy) {
797 // Register names didn't use to conflict with basic block names
798 // because of type planes. Now they all have to be unique. So, we just
799 // rename the register and treat this name as if no basic block
800 // had been found.
801 RenameMapKey Key = makeRenameMapKey(ID.Name, N->getType(), ID.S);
802 N->setName(makeNameUnique(N->getName()));
803 CurModule.RenameMap[Key] = N->getName();
804 BB = 0;
805 } else {
806 BB = cast<BasicBlock>(N);
807 }
808 }
809 break;
810 }
811
812 // See if the block has already been defined.
813 if (BB) {
814 // If this is the definition of the block, make sure the existing value was
815 // just a forward reference. If it was a forward reference, there will be
816 // an entry for it in the PlaceHolderInfo map.
817 if (isDefinition && !CurFun.BBForwardRefs.erase(BB))
818 // The existing value was a definition, not a forward reference.
819 error("Redefinition of label " + ID.getName());
820
821 ID.destroy(); // Free strdup'd memory.
822 return BB;
823 }
824
825 // Otherwise this block has not been seen before.
826 BB = new BasicBlock("", CurFun.CurrentFunction);
827 if (ID.Type == ValID::NameVal) {
828 BB->setName(ID.Name);
829 } else {
830 CurFun.NumberedBlocks[ID.Num] = BB;
831 }
832
833 // If this is not a definition, keep track of it so we can use it as a forward
834 // reference.
835 if (!isDefinition) {
836 // Remember where this forward reference came from.
837 CurFun.BBForwardRefs[BB] = std::make_pair(ID, Upgradelineno);
838 } else {
839 // The forward declaration could have been inserted anywhere in the
840 // function: insert it into the correct place now.
841 CurFun.CurrentFunction->getBasicBlockList().remove(BB);
842 CurFun.CurrentFunction->getBasicBlockList().push_back(BB);
843 }
844 ID.destroy();
845 return BB;
846}
847
848
849//===----------------------------------------------------------------------===//
850// Code to handle forward references in instructions
851//===----------------------------------------------------------------------===//
852//
853// This code handles the late binding needed with statements that reference
854// values not defined yet... for example, a forward branch, or the PHI node for
855// a loop body.
856//
857// This keeps a table (CurFun.LateResolveValues) of all such forward references
858// and back patchs after we are done.
859//
860
861// ResolveDefinitions - If we could not resolve some defs at parsing
862// time (forward branches, phi functions for loops, etc...) resolve the
863// defs now...
864//
865static void
866ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
867 std::map<const Type*,ValueList> *FutureLateResolvers) {
868
869 // Loop over LateResolveDefs fixing up stuff that couldn't be resolved
870 for (std::map<const Type*,ValueList>::iterator LRI = LateResolvers.begin(),
871 E = LateResolvers.end(); LRI != E; ++LRI) {
872 const Type* Ty = LRI->first;
873 ValueList &List = LRI->second;
874 while (!List.empty()) {
875 Value *V = List.back();
876 List.pop_back();
877
878 std::map<Value*, std::pair<ValID, int> >::iterator PHI =
879 CurModule.PlaceHolderInfo.find(V);
880 assert(PHI != CurModule.PlaceHolderInfo.end() && "Placeholder error");
881
882 ValID &DID = PHI->second.first;
883
884 Value *TheRealValue = getExistingValue(Ty, DID);
885 if (TheRealValue) {
886 V->replaceAllUsesWith(TheRealValue);
887 delete V;
888 CurModule.PlaceHolderInfo.erase(PHI);
889 } else if (FutureLateResolvers) {
890 // Functions have their unresolved items forwarded to the module late
891 // resolver table
892 InsertValue(V, *FutureLateResolvers);
893 } else {
894 if (DID.Type == ValID::NameVal) {
895 error("Reference to an invalid definition: '" + DID.getName() +
896 "' of type '" + V->getType()->getDescription() + "'",
897 PHI->second.second);
898 return;
899 } else {
900 error("Reference to an invalid definition: #" +
901 itostr(DID.Num) + " of type '" +
902 V->getType()->getDescription() + "'", PHI->second.second);
903 return;
904 }
905 }
906 }
907 }
908
909 LateResolvers.clear();
910}
911
912/// This function is used for type resolution and upref handling. When a type
913/// becomes concrete, this function is called to adjust the signedness for the
914/// concrete type.
915static void ResolveTypeSign(const Type* oldTy, const Signedness &Sign) {
916 std::string TyName = CurModule.CurrentModule->getTypeName(oldTy);
917 if (!TyName.empty())
918 CurModule.NamedTypeSigns[TyName] = Sign;
919}
920
921/// ResolveTypeTo - A brand new type was just declared. This means that (if
922/// name is not null) things referencing Name can be resolved. Otherwise,
923/// things refering to the number can be resolved. Do this now.
924static void ResolveTypeTo(char *Name, const Type *ToTy, const Signedness& Sign){
925 ValID D;
926 if (Name)
927 D = ValID::create(Name);
928 else
929 D = ValID::create((int)CurModule.Types.size());
930 D.S.copy(Sign);
931
932 if (Name)
933 CurModule.NamedTypeSigns[Name] = Sign;
934
935 std::map<ValID, PATypeHolder>::iterator I =
936 CurModule.LateResolveTypes.find(D);
937 if (I != CurModule.LateResolveTypes.end()) {
938 const Type *OldTy = I->second.get();
939 ((DerivedType*)OldTy)->refineAbstractTypeTo(ToTy);
940 CurModule.LateResolveTypes.erase(I);
941 }
942}
943
944/// This is the implementation portion of TypeHasInteger. It traverses the
945/// type given, avoiding recursive types, and returns true as soon as it finds
946/// an integer type. If no integer type is found, it returns false.
947static bool TypeHasIntegerI(const Type *Ty, std::vector<const Type*> Stack) {
948 // Handle some easy cases
949 if (Ty->isPrimitiveType() || (Ty->getTypeID() == Type::OpaqueTyID))
950 return false;
951 if (Ty->isInteger())
952 return true;
953 if (const SequentialType *STy = dyn_cast<SequentialType>(Ty))
954 return STy->getElementType()->isInteger();
955
956 // Avoid type structure recursion
957 for (std::vector<const Type*>::iterator I = Stack.begin(), E = Stack.end();
958 I != E; ++I)
959 if (Ty == *I)
960 return false;
961
962 // Push us on the type stack
963 Stack.push_back(Ty);
964
965 if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
966 if (TypeHasIntegerI(FTy->getReturnType(), Stack))
967 return true;
968 FunctionType::param_iterator I = FTy->param_begin();
969 FunctionType::param_iterator E = FTy->param_end();
970 for (; I != E; ++I)
971 if (TypeHasIntegerI(*I, Stack))
972 return true;
973 return false;
974 } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
975 StructType::element_iterator I = STy->element_begin();
976 StructType::element_iterator E = STy->element_end();
977 for (; I != E; ++I) {
978 if (TypeHasIntegerI(*I, Stack))
979 return true;
980 }
981 return false;
982 }
983 // There shouldn't be anything else, but its definitely not integer
984 assert(0 && "What type is this?");
985 return false;
986}
987
988/// This is the interface to TypeHasIntegerI. It just provides the type stack,
989/// to avoid recursion, and then calls TypeHasIntegerI.
990static inline bool TypeHasInteger(const Type *Ty) {
991 std::vector<const Type*> TyStack;
992 return TypeHasIntegerI(Ty, TyStack);
993}
994
995// setValueName - Set the specified value to the name given. The name may be
996// null potentially, in which case this is a noop. The string passed in is
997// assumed to be a malloc'd string buffer, and is free'd by this function.
998//
999static void setValueName(const ValueInfo &V, char *NameStr) {
1000 if (NameStr) {
1001 std::string Name(NameStr); // Copy string
1002 free(NameStr); // Free old string
1003
1004 if (V.V->getType() == Type::VoidTy) {
1005 error("Can't assign name '" + Name + "' to value with void type");
1006 return;
1007 }
1008
1009 assert(inFunctionScope() && "Must be in function scope");
1010
1011 // Search the function's symbol table for an existing value of this name
1012 ValueSymbolTable &ST = CurFun.CurrentFunction->getValueSymbolTable();
1013 Value* Existing = ST.lookup(Name);
1014 if (Existing) {
1015 // An existing value of the same name was found. This might have happened
1016 // because of the integer type planes collapsing in LLVM 2.0.
1017 if (Existing->getType() == V.V->getType() &&
1018 !TypeHasInteger(Existing->getType())) {
1019 // If the type does not contain any integers in them then this can't be
1020 // a type plane collapsing issue. It truly is a redefinition and we
1021 // should error out as the assembly is invalid.
1022 error("Redefinition of value named '" + Name + "' of type '" +
1023 V.V->getType()->getDescription() + "'");
1024 return;
1025 }
1026 // In LLVM 2.0 we don't allow names to be re-used for any values in a
1027 // function, regardless of Type. Previously re-use of names was okay as
1028 // long as they were distinct types. With type planes collapsing because
1029 // of the signedness change and because of PR411, this can no longer be
1030 // supported. We must search the entire symbol table for a conflicting
1031 // name and make the name unique. No warning is needed as this can't
1032 // cause a problem.
1033 std::string NewName = makeNameUnique(Name);
1034 // We're changing the name but it will probably be used by other
1035 // instructions as operands later on. Consequently we have to retain
1036 // a mapping of the renaming that we're doing.
1037 RenameMapKey Key = makeRenameMapKey(Name, V.V->getType(), V.S);
1038 CurFun.RenameMap[Key] = NewName;
1039 Name = NewName;
1040 }
1041
1042 // Set the name.
1043 V.V->setName(Name);
1044 }
1045}
1046
1047/// ParseGlobalVariable - Handle parsing of a global. If Initializer is null,
1048/// this is a declaration, otherwise it is a definition.
1049static GlobalVariable *
1050ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
1051 bool isConstantGlobal, const Type *Ty,
1052 Constant *Initializer,
1053 const Signedness &Sign) {
1054 if (isa<FunctionType>(Ty))
1055 error("Cannot declare global vars of function type");
1056
1057 const PointerType *PTy = PointerType::get(Ty);
1058
1059 std::string Name;
1060 if (NameStr) {
1061 Name = NameStr; // Copy string
1062 free(NameStr); // Free old string
1063 }
1064
1065 // See if this global value was forward referenced. If so, recycle the
1066 // object.
1067 ValID ID;
1068 if (!Name.empty()) {
1069 ID = ValID::create((char*)Name.c_str());
1070 } else {
1071 ID = ValID::create((int)CurModule.Values[PTy].size());
1072 }
1073 ID.S.makeComposite(Sign);
1074
1075 if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) {
1076 // Move the global to the end of the list, from whereever it was
1077 // previously inserted.
1078 GlobalVariable *GV = cast<GlobalVariable>(FWGV);
1079 CurModule.CurrentModule->getGlobalList().remove(GV);
1080 CurModule.CurrentModule->getGlobalList().push_back(GV);
1081 GV->setInitializer(Initializer);
1082 GV->setLinkage(Linkage);
1083 GV->setConstant(isConstantGlobal);
1084 InsertValue(GV, CurModule.Values);
1085 return GV;
1086 }
1087
1088 // If this global has a name, check to see if there is already a definition
1089 // of this global in the module and emit warnings if there are conflicts.
1090 if (!Name.empty()) {
1091 // The global has a name. See if there's an existing one of the same name.
1092 if (CurModule.CurrentModule->getNamedGlobal(Name) ||
1093 CurModule.CurrentModule->getFunction(Name)) {
1094 // We found an existing global of the same name. This isn't allowed
1095 // in LLVM 2.0. Consequently, we must alter the name of the global so it
1096 // can at least compile. This can happen because of type planes
1097 // There is alread a global of the same name which means there is a
1098 // conflict. Let's see what we can do about it.
1099 std::string NewName(makeNameUnique(Name));
1100 if (Linkage != GlobalValue::InternalLinkage) {
1101 // The linkage of this gval is external so we can't reliably rename
1102 // it because it could potentially create a linking problem.
1103 // However, we can't leave the name conflict in the output either or
1104 // it won't assemble with LLVM 2.0. So, all we can do is rename
1105 // this one to something unique and emit a warning about the problem.
1106 warning("Renaming global variable '" + Name + "' to '" + NewName +
1107 "' may cause linkage errors");
1108 }
1109
1110 // Put the renaming in the global rename map
1111 RenameMapKey Key = makeRenameMapKey(Name, PointerType::get(Ty), ID.S);
1112 CurModule.RenameMap[Key] = NewName;
1113
1114 // Rename it
1115 Name = NewName;
1116 }
1117 }
1118
1119 // Otherwise there is no existing GV to use, create one now.
1120 GlobalVariable *GV =
1121 new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name,
1122 CurModule.CurrentModule);
1123 InsertValue(GV, CurModule.Values);
1124 // Remember the sign of this global.
1125 CurModule.NamedValueSigns[Name] = ID.S;
1126 return GV;
1127}
1128
1129// setTypeName - Set the specified type to the name given. The name may be
1130// null potentially, in which case this is a noop. The string passed in is
1131// assumed to be a malloc'd string buffer, and is freed by this function.
1132//
1133// This function returns true if the type has already been defined, but is
1134// allowed to be redefined in the specified context. If the name is a new name
1135// for the type plane, it is inserted and false is returned.
1136static bool setTypeName(const PATypeInfo& TI, char *NameStr) {
1137 assert(!inFunctionScope() && "Can't give types function-local names");
1138 if (NameStr == 0) return false;
1139
1140 std::string Name(NameStr); // Copy string
1141 free(NameStr); // Free old string
1142
1143 const Type* Ty = TI.PAT->get();
1144
1145 // We don't allow assigning names to void type
1146 if (Ty == Type::VoidTy) {
1147 error("Can't assign name '" + Name + "' to the void type");
1148 return false;
1149 }
1150
1151 // Set the type name, checking for conflicts as we do so.
1152 bool AlreadyExists = CurModule.CurrentModule->addTypeName(Name, Ty);
1153
1154 // Save the sign information for later use
1155 CurModule.NamedTypeSigns[Name] = TI.S;
1156
1157 if (AlreadyExists) { // Inserting a name that is already defined???
1158 const Type *Existing = CurModule.CurrentModule->getTypeByName(Name);
1159 assert(Existing && "Conflict but no matching type?");
1160
1161 // There is only one case where this is allowed: when we are refining an
1162 // opaque type. In this case, Existing will be an opaque type.
1163 if (const OpaqueType *OpTy = dyn_cast<OpaqueType>(Existing)) {
1164 // We ARE replacing an opaque type!
1165 const_cast<OpaqueType*>(OpTy)->refineAbstractTypeTo(Ty);
1166 return true;
1167 }
1168
1169 // Otherwise, this is an attempt to redefine a type. That's okay if
1170 // the redefinition is identical to the original. This will be so if
1171 // Existing and T point to the same Type object. In this one case we
1172 // allow the equivalent redefinition.
1173 if (Existing == Ty) return true; // Yes, it's equal.
1174
1175 // Any other kind of (non-equivalent) redefinition is an error.
1176 error("Redefinition of type named '" + Name + "' in the '" +
1177 Ty->getDescription() + "' type plane");
1178 }
1179
1180 return false;
1181}
1182
1183//===----------------------------------------------------------------------===//
1184// Code for handling upreferences in type names...
1185//
1186
1187// TypeContains - Returns true if Ty directly contains E in it.
1188//
1189static bool TypeContains(const Type *Ty, const Type *E) {
1190 return std::find(Ty->subtype_begin(), Ty->subtype_end(),
1191 E) != Ty->subtype_end();
1192}
1193
1194namespace {
1195 struct UpRefRecord {
1196 // NestingLevel - The number of nesting levels that need to be popped before
1197 // this type is resolved.
1198 unsigned NestingLevel;
1199
1200 // LastContainedTy - This is the type at the current binding level for the
1201 // type. Every time we reduce the nesting level, this gets updated.
1202 const Type *LastContainedTy;
1203
1204 // UpRefTy - This is the actual opaque type that the upreference is
1205 // represented with.
1206 OpaqueType *UpRefTy;
1207
1208 UpRefRecord(unsigned NL, OpaqueType *URTy)
1209 : NestingLevel(NL), LastContainedTy(URTy), UpRefTy(URTy) { }
1210 };
1211}
1212
1213// UpRefs - A list of the outstanding upreferences that need to be resolved.
1214static std::vector<UpRefRecord> UpRefs;
1215
1216/// HandleUpRefs - Every time we finish a new layer of types, this function is
1217/// called. It loops through the UpRefs vector, which is a list of the
1218/// currently active types. For each type, if the up reference is contained in
1219/// the newly completed type, we decrement the level count. When the level
1220/// count reaches zero, the upreferenced type is the type that is passed in:
1221/// thus we can complete the cycle.
1222///
1223static PATypeHolder HandleUpRefs(const Type *ty, const Signedness& Sign) {
1224 // If Ty isn't abstract, or if there are no up-references in it, then there is
1225 // nothing to resolve here.
1226 if (!ty->isAbstract() || UpRefs.empty()) return ty;
1227
1228 PATypeHolder Ty(ty);
1229 UR_OUT("Type '" << Ty->getDescription() <<
1230 "' newly formed. Resolving upreferences.\n" <<
1231 UpRefs.size() << " upreferences active!\n");
1232
1233 // If we find any resolvable upreferences (i.e., those whose NestingLevel goes
1234 // to zero), we resolve them all together before we resolve them to Ty. At
1235 // the end of the loop, if there is anything to resolve to Ty, it will be in
1236 // this variable.
1237 OpaqueType *TypeToResolve = 0;
1238
1239 unsigned i = 0;
1240 for (; i != UpRefs.size(); ++i) {
1241 UR_OUT(" UR#" << i << " - TypeContains(" << Ty->getDescription() << ", "
1242 << UpRefs[i].UpRefTy->getDescription() << ") = "
1243 << (TypeContains(Ty, UpRefs[i].UpRefTy) ? "true" : "false") << "\n");
1244 if (TypeContains(Ty, UpRefs[i].LastContainedTy)) {
1245 // Decrement level of upreference
1246 unsigned Level = --UpRefs[i].NestingLevel;
1247 UpRefs[i].LastContainedTy = Ty;
1248 UR_OUT(" Uplevel Ref Level = " << Level << "\n");
1249 if (Level == 0) { // Upreference should be resolved!
1250 if (!TypeToResolve) {
1251 TypeToResolve = UpRefs[i].UpRefTy;
1252 } else {
1253 UR_OUT(" * Resolving upreference for "
1254 << UpRefs[i].UpRefTy->getDescription() << "\n";
1255 std::string OldName = UpRefs[i].UpRefTy->getDescription());
1256 ResolveTypeSign(UpRefs[i].UpRefTy, Sign);
1257 UpRefs[i].UpRefTy->refineAbstractTypeTo(TypeToResolve);
1258 UR_OUT(" * Type '" << OldName << "' refined upreference to: "
1259 << (const void*)Ty << ", " << Ty->getDescription() << "\n");
1260 }
1261 UpRefs.erase(UpRefs.begin()+i); // Remove from upreference list...
1262 --i; // Do not skip the next element...
1263 }
1264 }
1265 }
1266
1267 if (TypeToResolve) {
1268 UR_OUT(" * Resolving upreference for "
1269 << UpRefs[i].UpRefTy->getDescription() << "\n";
1270 std::string OldName = TypeToResolve->getDescription());
1271 ResolveTypeSign(TypeToResolve, Sign);
1272 TypeToResolve->refineAbstractTypeTo(Ty);
1273 }
1274
1275 return Ty;
1276}
1277
1278bool Signedness::operator<(const Signedness &that) const {
1279 if (isNamed()) {
1280 if (that.isNamed())
1281 return *(this->name) < *(that.name);
1282 else
1283 return CurModule.NamedTypeSigns[*name] < that;
1284 } else if (that.isNamed()) {
1285 return *this < CurModule.NamedTypeSigns[*that.name];
1286 }
1287
1288 if (isComposite() && that.isComposite()) {
1289 if (sv->size() == that.sv->size()) {
1290 SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1291 SignVector::const_iterator thatI = that.sv->begin(),
1292 thatE = that.sv->end();
1293 for (; thisI != thisE; ++thisI, ++thatI) {
1294 if (*thisI < *thatI)
1295 return true;
1296 else if (!(*thisI == *thatI))
1297 return false;
1298 }
1299 return false;
1300 }
1301 return sv->size() < that.sv->size();
1302 }
1303 return kind < that.kind;
1304}
1305
1306bool Signedness::operator==(const Signedness &that) const {
1307 if (isNamed())
1308 if (that.isNamed())
1309 return *(this->name) == *(that.name);
1310 else
1311 return CurModule.NamedTypeSigns[*(this->name)] == that;
1312 else if (that.isNamed())
1313 return *this == CurModule.NamedTypeSigns[*(that.name)];
1314 if (isComposite() && that.isComposite()) {
1315 if (sv->size() == that.sv->size()) {
1316 SignVector::const_iterator thisI = sv->begin(), thisE = sv->end();
1317 SignVector::const_iterator thatI = that.sv->begin(),
1318 thatE = that.sv->end();
1319 for (; thisI != thisE; ++thisI, ++thatI) {
1320 if (!(*thisI == *thatI))
1321 return false;
1322 }
1323 return true;
1324 }
1325 return false;
1326 }
1327 return kind == that.kind;
1328}
1329
1330void Signedness::copy(const Signedness &that) {
1331 if (that.isNamed()) {
1332 kind = Named;
1333 name = new std::string(*that.name);
1334 } else if (that.isComposite()) {
1335 kind = Composite;
1336 sv = new SignVector();
1337 *sv = *that.sv;
1338 } else {
1339 kind = that.kind;
1340 sv = 0;
1341 }
1342}
1343
1344void Signedness::destroy() {
1345 if (isNamed()) {
1346 delete name;
1347 } else if (isComposite()) {
1348 delete sv;
1349 }
1350}
1351
1352#ifndef NDEBUG
1353void Signedness::dump() const {
1354 if (isComposite()) {
1355 if (sv->size() == 1) {
1356 (*sv)[0].dump();
1357 std::cerr << "*";
1358 } else {
1359 std::cerr << "{ " ;
1360 for (unsigned i = 0; i < sv->size(); ++i) {
1361 if (i != 0)
1362 std::cerr << ", ";
1363 (*sv)[i].dump();
1364 }
1365 std::cerr << "} " ;
1366 }
1367 } else if (isNamed()) {
1368 std::cerr << *name;
1369 } else if (isSigned()) {
1370 std::cerr << "S";
1371 } else if (isUnsigned()) {
1372 std::cerr << "U";
1373 } else
1374 std::cerr << ".";
1375}
1376#endif
1377
1378static inline Instruction::TermOps
1379getTermOp(TermOps op) {
1380 switch (op) {
1381 default : assert(0 && "Invalid OldTermOp");
1382 case RetOp : return Instruction::Ret;
1383 case BrOp : return Instruction::Br;
1384 case SwitchOp : return Instruction::Switch;
1385 case InvokeOp : return Instruction::Invoke;
1386 case UnwindOp : return Instruction::Unwind;
1387 case UnreachableOp: return Instruction::Unreachable;
1388 }
1389}
1390
1391static inline Instruction::BinaryOps
1392getBinaryOp(BinaryOps op, const Type *Ty, const Signedness& Sign) {
1393 switch (op) {
1394 default : assert(0 && "Invalid OldBinaryOps");
1395 case SetEQ :
1396 case SetNE :
1397 case SetLE :
1398 case SetGE :
1399 case SetLT :
1400 case SetGT : assert(0 && "Should use getCompareOp");
1401 case AddOp : return Instruction::Add;
1402 case SubOp : return Instruction::Sub;
1403 case MulOp : return Instruction::Mul;
1404 case DivOp : {
1405 // This is an obsolete instruction so we must upgrade it based on the
1406 // types of its operands.
1407 bool isFP = Ty->isFloatingPoint();
1408 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
1409 // If its a vector type we want to use the element type
1410 isFP = PTy->getElementType()->isFloatingPoint();
1411 if (isFP)
1412 return Instruction::FDiv;
1413 else if (Sign.isSigned())
1414 return Instruction::SDiv;
1415 return Instruction::UDiv;
1416 }
1417 case UDivOp : return Instruction::UDiv;
1418 case SDivOp : return Instruction::SDiv;
1419 case FDivOp : return Instruction::FDiv;
1420 case RemOp : {
1421 // This is an obsolete instruction so we must upgrade it based on the
1422 // types of its operands.
1423 bool isFP = Ty->isFloatingPoint();
1424 if (const VectorType* PTy = dyn_cast<VectorType>(Ty))
1425 // If its a vector type we want to use the element type
1426 isFP = PTy->getElementType()->isFloatingPoint();
1427 // Select correct opcode
1428 if (isFP)
1429 return Instruction::FRem;
1430 else if (Sign.isSigned())
1431 return Instruction::SRem;
1432 return Instruction::URem;
1433 }
1434 case URemOp : return Instruction::URem;
1435 case SRemOp : return Instruction::SRem;
1436 case FRemOp : return Instruction::FRem;
1437 case LShrOp : return Instruction::LShr;
1438 case AShrOp : return Instruction::AShr;
1439 case ShlOp : return Instruction::Shl;
1440 case ShrOp :
1441 if (Sign.isSigned())
1442 return Instruction::AShr;
1443 return Instruction::LShr;
1444 case AndOp : return Instruction::And;
1445 case OrOp : return Instruction::Or;
1446 case XorOp : return Instruction::Xor;
1447 }
1448}
1449
1450static inline Instruction::OtherOps
1451getCompareOp(BinaryOps op, unsigned short &predicate, const Type* &Ty,
1452 const Signedness &Sign) {
1453 bool isSigned = Sign.isSigned();
1454 bool isFP = Ty->isFloatingPoint();
1455 switch (op) {
1456 default : assert(0 && "Invalid OldSetCC");
1457 case SetEQ :
1458 if (isFP) {
1459 predicate = FCmpInst::FCMP_OEQ;
1460 return Instruction::FCmp;
1461 } else {
1462 predicate = ICmpInst::ICMP_EQ;
1463 return Instruction::ICmp;
1464 }
1465 case SetNE :
1466 if (isFP) {
1467 predicate = FCmpInst::FCMP_UNE;
1468 return Instruction::FCmp;
1469 } else {
1470 predicate = ICmpInst::ICMP_NE;
1471 return Instruction::ICmp;
1472 }
1473 case SetLE :
1474 if (isFP) {
1475 predicate = FCmpInst::FCMP_OLE;
1476 return Instruction::FCmp;
1477 } else {
1478 if (isSigned)
1479 predicate = ICmpInst::ICMP_SLE;
1480 else
1481 predicate = ICmpInst::ICMP_ULE;
1482 return Instruction::ICmp;
1483 }
1484 case SetGE :
1485 if (isFP) {
1486 predicate = FCmpInst::FCMP_OGE;
1487 return Instruction::FCmp;
1488 } else {
1489 if (isSigned)
1490 predicate = ICmpInst::ICMP_SGE;
1491 else
1492 predicate = ICmpInst::ICMP_UGE;
1493 return Instruction::ICmp;
1494 }
1495 case SetLT :
1496 if (isFP) {
1497 predicate = FCmpInst::FCMP_OLT;
1498 return Instruction::FCmp;
1499 } else {
1500 if (isSigned)
1501 predicate = ICmpInst::ICMP_SLT;
1502 else
1503 predicate = ICmpInst::ICMP_ULT;
1504 return Instruction::ICmp;
1505 }
1506 case SetGT :
1507 if (isFP) {
1508 predicate = FCmpInst::FCMP_OGT;
1509 return Instruction::FCmp;
1510 } else {
1511 if (isSigned)
1512 predicate = ICmpInst::ICMP_SGT;
1513 else
1514 predicate = ICmpInst::ICMP_UGT;
1515 return Instruction::ICmp;
1516 }
1517 }
1518}
1519
1520static inline Instruction::MemoryOps getMemoryOp(MemoryOps op) {
1521 switch (op) {
1522 default : assert(0 && "Invalid OldMemoryOps");
1523 case MallocOp : return Instruction::Malloc;
1524 case FreeOp : return Instruction::Free;
1525 case AllocaOp : return Instruction::Alloca;
1526 case LoadOp : return Instruction::Load;
1527 case StoreOp : return Instruction::Store;
1528 case GetElementPtrOp : return Instruction::GetElementPtr;
1529 }
1530}
1531
1532static inline Instruction::OtherOps
1533getOtherOp(OtherOps op, const Signedness &Sign) {
1534 switch (op) {
1535 default : assert(0 && "Invalid OldOtherOps");
1536 case PHIOp : return Instruction::PHI;
1537 case CallOp : return Instruction::Call;
1538 case SelectOp : return Instruction::Select;
1539 case UserOp1 : return Instruction::UserOp1;
1540 case UserOp2 : return Instruction::UserOp2;
1541 case VAArg : return Instruction::VAArg;
1542 case ExtractElementOp : return Instruction::ExtractElement;
1543 case InsertElementOp : return Instruction::InsertElement;
1544 case ShuffleVectorOp : return Instruction::ShuffleVector;
1545 case ICmpOp : return Instruction::ICmp;
1546 case FCmpOp : return Instruction::FCmp;
1547 };
1548}
1549
1550static inline Value*
1551getCast(CastOps op, Value *Src, const Signedness &SrcSign, const Type *DstTy,
1552 const Signedness &DstSign, bool ForceInstruction = false) {
1553 Instruction::CastOps Opcode;
1554 const Type* SrcTy = Src->getType();
1555 if (op == CastOp) {
1556 if (SrcTy->isFloatingPoint() && isa<PointerType>(DstTy)) {
1557 // fp -> ptr cast is no longer supported but we must upgrade this
1558 // by doing a double cast: fp -> int -> ptr
1559 SrcTy = Type::Int64Ty;
1560 Opcode = Instruction::IntToPtr;
1561 if (isa<Constant>(Src)) {
1562 Src = ConstantExpr::getCast(Instruction::FPToUI,
1563 cast<Constant>(Src), SrcTy);
1564 } else {
1565 std::string NewName(makeNameUnique(Src->getName()));
1566 Src = new FPToUIInst(Src, SrcTy, NewName, CurBB);
1567 }
1568 } else if (isa<IntegerType>(DstTy) &&
1569 cast<IntegerType>(DstTy)->getBitWidth() == 1) {
1570 // cast type %x to bool was previously defined as setne type %x, null
1571 // The cast semantic is now to truncate, not compare so we must retain
1572 // the original intent by replacing the cast with a setne
1573 Constant* Null = Constant::getNullValue(SrcTy);
1574 Instruction::OtherOps Opcode = Instruction::ICmp;
1575 unsigned short predicate = ICmpInst::ICMP_NE;
1576 if (SrcTy->isFloatingPoint()) {
1577 Opcode = Instruction::FCmp;
1578 predicate = FCmpInst::FCMP_ONE;
1579 } else if (!SrcTy->isInteger() && !isa<PointerType>(SrcTy)) {
1580 error("Invalid cast to bool");
1581 }
1582 if (isa<Constant>(Src) && !ForceInstruction)
1583 return ConstantExpr::getCompare(predicate, cast<Constant>(Src), Null);
1584 else
1585 return CmpInst::create(Opcode, predicate, Src, Null);
1586 }
1587 // Determine the opcode to use by calling CastInst::getCastOpcode
1588 Opcode =
1589 CastInst::getCastOpcode(Src, SrcSign.isSigned(), DstTy,
1590 DstSign.isSigned());
1591
1592 } else switch (op) {
1593 default: assert(0 && "Invalid cast token");
1594 case TruncOp: Opcode = Instruction::Trunc; break;
1595 case ZExtOp: Opcode = Instruction::ZExt; break;
1596 case SExtOp: Opcode = Instruction::SExt; break;
1597 case FPTruncOp: Opcode = Instruction::FPTrunc; break;
1598 case FPExtOp: Opcode = Instruction::FPExt; break;
1599 case FPToUIOp: Opcode = Instruction::FPToUI; break;
1600 case FPToSIOp: Opcode = Instruction::FPToSI; break;
1601 case UIToFPOp: Opcode = Instruction::UIToFP; break;
1602 case SIToFPOp: Opcode = Instruction::SIToFP; break;
1603 case PtrToIntOp: Opcode = Instruction::PtrToInt; break;
1604 case IntToPtrOp: Opcode = Instruction::IntToPtr; break;
1605 case BitCastOp: Opcode = Instruction::BitCast; break;
1606 }
1607
1608 if (isa<Constant>(Src) && !ForceInstruction)
1609 return ConstantExpr::getCast(Opcode, cast<Constant>(Src), DstTy);
1610 return CastInst::create(Opcode, Src, DstTy);
1611}
1612
1613static Instruction *
1614upgradeIntrinsicCall(const Type* RetTy, const ValID &ID,
1615 std::vector<Value*>& Args) {
1616
1617 std::string Name = ID.Type == ValID::NameVal ? ID.Name : "";
1618 if (Name.length() <= 5 || Name[0] != 'l' || Name[1] != 'l' ||
1619 Name[2] != 'v' || Name[3] != 'm' || Name[4] != '.')
1620 return 0;
1621
1622 switch (Name[5]) {
1623 case 'i':
1624 if (Name == "llvm.isunordered.f32" || Name == "llvm.isunordered.f64") {
1625 if (Args.size() != 2)
1626 error("Invalid prototype for " + Name);
1627 return new FCmpInst(FCmpInst::FCMP_UNO, Args[0], Args[1]);
1628 }
1629 break;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001630
1631 case 'v' : {
1632 const Type* PtrTy = PointerType::get(Type::Int8Ty);
1633 std::vector<const Type*> Params;
1634 if (Name == "llvm.va_start" || Name == "llvm.va_end") {
1635 if (Args.size() != 1)
1636 error("Invalid prototype for " + Name + " prototype");
1637 Params.push_back(PtrTy);
1638 const FunctionType *FTy =
1639 FunctionType::get(Type::VoidTy, Params, false);
1640 const PointerType *PFTy = PointerType::get(FTy);
1641 Value* Func = getVal(PFTy, ID);
1642 Args[0] = new BitCastInst(Args[0], PtrTy, makeNameUnique("va"), CurBB);
David Greene9145dd22007-08-01 03:59:32 +00001643 return new CallInst(Func, Args.begin(), Args.end());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001644 } else if (Name == "llvm.va_copy") {
1645 if (Args.size() != 2)
1646 error("Invalid prototype for " + Name + " prototype");
1647 Params.push_back(PtrTy);
1648 Params.push_back(PtrTy);
1649 const FunctionType *FTy =
1650 FunctionType::get(Type::VoidTy, Params, false);
1651 const PointerType *PFTy = PointerType::get(FTy);
1652 Value* Func = getVal(PFTy, ID);
1653 std::string InstName0(makeNameUnique("va0"));
1654 std::string InstName1(makeNameUnique("va1"));
1655 Args[0] = new BitCastInst(Args[0], PtrTy, InstName0, CurBB);
1656 Args[1] = new BitCastInst(Args[1], PtrTy, InstName1, CurBB);
David Greene9145dd22007-08-01 03:59:32 +00001657 return new CallInst(Func, Args.begin(), Args.end());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001658 }
1659 }
1660 }
1661 return 0;
1662}
1663
1664const Type* upgradeGEPCEIndices(const Type* PTy,
1665 std::vector<ValueInfo> *Indices,
1666 std::vector<Constant*> &Result) {
1667 const Type *Ty = PTy;
1668 Result.clear();
1669 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1670 Constant *Index = cast<Constant>((*Indices)[i].V);
1671
1672 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1673 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1674 // struct indices to i32 struct indices with ZExt for compatibility.
1675 if (CI->getBitWidth() < 32)
1676 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1677 }
1678
1679 if (isa<SequentialType>(Ty)) {
1680 // Make sure that unsigned SequentialType indices are zext'd to
1681 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1682 // all indices for SequentialType elements. We must retain the same
1683 // semantic (zext) for unsigned types.
1684 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
1685 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
1686 Index = ConstantExpr::getCast(Instruction::ZExt, Index,Type::Int64Ty);
1687 }
1688 }
1689 }
1690 Result.push_back(Index);
David Greene48556392007-09-04 18:46:50 +00001691 Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(),
1692 Result.end(),true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001693 if (!Ty)
1694 error("Index list invalid for constant getelementptr");
1695 }
1696 return Ty;
1697}
1698
1699const Type* upgradeGEPInstIndices(const Type* PTy,
1700 std::vector<ValueInfo> *Indices,
1701 std::vector<Value*> &Result) {
1702 const Type *Ty = PTy;
1703 Result.clear();
1704 for (unsigned i = 0, e = Indices->size(); i != e ; ++i) {
1705 Value *Index = (*Indices)[i].V;
1706
1707 if (ConstantInt *CI = dyn_cast<ConstantInt>(Index)) {
1708 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte
1709 // struct indices to i32 struct indices with ZExt for compatibility.
1710 if (CI->getBitWidth() < 32)
1711 Index = ConstantExpr::getCast(Instruction::ZExt, CI, Type::Int32Ty);
1712 }
1713
1714
1715 if (isa<StructType>(Ty)) { // Only change struct indices
1716 if (!isa<Constant>(Index)) {
1717 error("Invalid non-constant structure index");
1718 return 0;
1719 }
1720 } else {
1721 // Make sure that unsigned SequentialType indices are zext'd to
1722 // 64-bits if they were smaller than that because LLVM 2.0 will sext
1723 // all indices for SequentialType elements. We must retain the same
1724 // semantic (zext) for unsigned types.
1725 if (const IntegerType *Ity = dyn_cast<IntegerType>(Index->getType())) {
1726 if (Ity->getBitWidth() < 64 && (*Indices)[i].S.isUnsigned()) {
1727 if (isa<Constant>(Index))
1728 Index = ConstantExpr::getCast(Instruction::ZExt,
1729 cast<Constant>(Index), Type::Int64Ty);
1730 else
1731 Index = CastInst::create(Instruction::ZExt, Index, Type::Int64Ty,
1732 makeNameUnique("gep"), CurBB);
1733 }
1734 }
1735 }
1736 Result.push_back(Index);
David Greene48556392007-09-04 18:46:50 +00001737 Ty = GetElementPtrInst::getIndexedType(PTy, Result.begin(),
1738 Result.end(),true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001739 if (!Ty)
1740 error("Index list invalid for constant getelementptr");
1741 }
1742 return Ty;
1743}
1744
1745unsigned upgradeCallingConv(unsigned CC) {
1746 switch (CC) {
1747 case OldCallingConv::C : return CallingConv::C;
1748 case OldCallingConv::CSRet : return CallingConv::C;
1749 case OldCallingConv::Fast : return CallingConv::Fast;
1750 case OldCallingConv::Cold : return CallingConv::Cold;
1751 case OldCallingConv::X86_StdCall : return CallingConv::X86_StdCall;
1752 case OldCallingConv::X86_FastCall: return CallingConv::X86_FastCall;
1753 default:
1754 return CC;
1755 }
1756}
1757
1758Module* UpgradeAssembly(const std::string &infile, std::istream& in,
1759 bool debug, bool addAttrs)
1760{
1761 Upgradelineno = 1;
1762 CurFilename = infile;
1763 LexInput = &in;
1764 yydebug = debug;
1765 AddAttributes = addAttrs;
1766 ObsoleteVarArgs = false;
1767 NewVarArgs = false;
1768
1769 CurModule.CurrentModule = new Module(CurFilename);
1770
1771 // Check to make sure the parser succeeded
1772 if (yyparse()) {
1773 if (ParserResult)
1774 delete ParserResult;
1775 std::cerr << "llvm-upgrade: parse failed.\n";
1776 return 0;
1777 }
1778
1779 // Check to make sure that parsing produced a result
1780 if (!ParserResult) {
1781 std::cerr << "llvm-upgrade: no parse result.\n";
1782 return 0;
1783 }
1784
1785 // Reset ParserResult variable while saving its value for the result.
1786 Module *Result = ParserResult;
1787 ParserResult = 0;
1788
1789 //Not all functions use vaarg, so make a second check for ObsoleteVarArgs
1790 {
1791 Function* F;
1792 if ((F = Result->getFunction("llvm.va_start"))
1793 && F->getFunctionType()->getNumParams() == 0)
1794 ObsoleteVarArgs = true;
1795 if((F = Result->getFunction("llvm.va_copy"))
1796 && F->getFunctionType()->getNumParams() == 1)
1797 ObsoleteVarArgs = true;
1798 }
1799
1800 if (ObsoleteVarArgs && NewVarArgs) {
1801 error("This file is corrupt: it uses both new and old style varargs");
1802 return 0;
1803 }
1804
1805 if(ObsoleteVarArgs) {
1806 if(Function* F = Result->getFunction("llvm.va_start")) {
1807 if (F->arg_size() != 0) {
1808 error("Obsolete va_start takes 0 argument");
1809 return 0;
1810 }
1811
1812 //foo = va_start()
1813 // ->
1814 //bar = alloca typeof(foo)
1815 //va_start(bar)
1816 //foo = load bar
1817
1818 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1819 const Type* ArgTy = F->getFunctionType()->getReturnType();
1820 const Type* ArgTyPtr = PointerType::get(ArgTy);
1821 Function* NF = cast<Function>(Result->getOrInsertFunction(
1822 "llvm.va_start", RetTy, ArgTyPtr, (Type *)0));
1823
1824 while (!F->use_empty()) {
1825 CallInst* CI = cast<CallInst>(F->use_back());
1826 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vastart.fix.1", CI);
1827 new CallInst(NF, bar, "", CI);
1828 Value* foo = new LoadInst(bar, "vastart.fix.2", CI);
1829 CI->replaceAllUsesWith(foo);
1830 CI->getParent()->getInstList().erase(CI);
1831 }
1832 Result->getFunctionList().erase(F);
1833 }
1834
1835 if(Function* F = Result->getFunction("llvm.va_end")) {
1836 if(F->arg_size() != 1) {
1837 error("Obsolete va_end takes 1 argument");
1838 return 0;
1839 }
1840
1841 //vaend foo
1842 // ->
1843 //bar = alloca 1 of typeof(foo)
1844 //vaend bar
1845 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1846 const Type* ArgTy = F->getFunctionType()->getParamType(0);
1847 const Type* ArgTyPtr = PointerType::get(ArgTy);
1848 Function* NF = cast<Function>(Result->getOrInsertFunction(
1849 "llvm.va_end", RetTy, ArgTyPtr, (Type *)0));
1850
1851 while (!F->use_empty()) {
1852 CallInst* CI = cast<CallInst>(F->use_back());
1853 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vaend.fix.1", CI);
1854 new StoreInst(CI->getOperand(1), bar, CI);
1855 new CallInst(NF, bar, "", CI);
1856 CI->getParent()->getInstList().erase(CI);
1857 }
1858 Result->getFunctionList().erase(F);
1859 }
1860
1861 if(Function* F = Result->getFunction("llvm.va_copy")) {
1862 if(F->arg_size() != 1) {
1863 error("Obsolete va_copy takes 1 argument");
1864 return 0;
1865 }
1866 //foo = vacopy(bar)
1867 // ->
1868 //a = alloca 1 of typeof(foo)
1869 //b = alloca 1 of typeof(foo)
1870 //store bar -> b
1871 //vacopy(a, b)
1872 //foo = load a
1873
1874 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1875 const Type* ArgTy = F->getFunctionType()->getReturnType();
1876 const Type* ArgTyPtr = PointerType::get(ArgTy);
1877 Function* NF = cast<Function>(Result->getOrInsertFunction(
1878 "llvm.va_copy", RetTy, ArgTyPtr, ArgTyPtr, (Type *)0));
1879
1880 while (!F->use_empty()) {
1881 CallInst* CI = cast<CallInst>(F->use_back());
David Greene48556392007-09-04 18:46:50 +00001882 Value *Args[2] = {
1883 new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI),
1884 new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI)
1885 };
David Greene9145dd22007-08-01 03:59:32 +00001886 new StoreInst(CI->getOperand(1), Args[1], CI);
David Greene48556392007-09-04 18:46:50 +00001887 new CallInst(NF, Args, Args + 2, "", CI);
David Greene9145dd22007-08-01 03:59:32 +00001888 Value* foo = new LoadInst(Args[0], "vacopy.fix.3", CI);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001889 CI->replaceAllUsesWith(foo);
1890 CI->getParent()->getInstList().erase(CI);
1891 }
1892 Result->getFunctionList().erase(F);
1893 }
1894 }
1895
1896 return Result;
1897}
1898
1899} // end llvm namespace
1900
1901using namespace llvm;
1902
1903
Dale Johannesen3afee192007-09-07 21:07:57 +00001904#line 1754 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
1905typedef union {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001906 llvm::Module *ModuleVal;
1907 llvm::Function *FunctionVal;
1908 std::pair<llvm::PATypeInfo, char*> *ArgVal;
1909 llvm::BasicBlock *BasicBlockVal;
1910 llvm::TermInstInfo TermInstVal;
1911 llvm::InstrInfo InstVal;
1912 llvm::ConstInfo ConstVal;
1913 llvm::ValueInfo ValueVal;
1914 llvm::PATypeInfo TypeVal;
1915 llvm::TypeInfo PrimType;
1916 llvm::PHIListInfo PHIList;
1917 std::list<llvm::PATypeInfo> *TypeList;
1918 std::vector<llvm::ValueInfo> *ValueList;
1919 std::vector<llvm::ConstInfo> *ConstVector;
1920
1921
1922 std::vector<std::pair<llvm::PATypeInfo,char*> > *ArgList;
1923 // Represent the RHS of PHI node
1924 std::vector<std::pair<llvm::Constant*, llvm::BasicBlock*> > *JumpTable;
1925
1926 llvm::GlobalValue::LinkageTypes Linkage;
1927 int64_t SInt64Val;
1928 uint64_t UInt64Val;
1929 int SIntVal;
1930 unsigned UIntVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00001931 llvm::APFloat *FPVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001932 bool BoolVal;
1933
1934 char *StrVal; // This memory is strdup'd!
1935 llvm::ValID ValIDVal; // strdup'd memory maybe!
1936
1937 llvm::BinaryOps BinaryOpVal;
1938 llvm::TermOps TermOpVal;
1939 llvm::MemoryOps MemOpVal;
1940 llvm::OtherOps OtherOpVal;
1941 llvm::CastOps CastOpVal;
1942 llvm::ICmpInst::Predicate IPred;
1943 llvm::FCmpInst::Predicate FPred;
1944 llvm::Module::Endianness Endianness;
David Greene48556392007-09-04 18:46:50 +00001945} YYSTYPE;
Dale Johannesen3afee192007-09-07 21:07:57 +00001946#include <stdio.h>
1947
1948#ifndef __cplusplus
1949#ifndef __STDC__
1950#define const
1951#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001952#endif
1953
1954
1955
Dale Johannesen3afee192007-09-07 21:07:57 +00001956#define YYFINAL 606
1957#define YYFLAG -32768
1958#define YYNTBASE 166
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001959
Dale Johannesen3afee192007-09-07 21:07:57 +00001960#define YYTRANSLATE(x) ((unsigned)(x) <= 405 ? yytranslate[x] : 246)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001961
Dale Johannesen3afee192007-09-07 21:07:57 +00001962static const short yytranslate[] = { 0,
1963 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1964 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1965 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1966 2, 2, 2, 2, 2, 2, 2, 2, 2, 155,
1967 156, 164, 2, 153, 2, 2, 2, 2, 2, 2,
1968 2, 2, 2, 2, 2, 2, 2, 2, 2, 160,
1969 152, 161, 2, 2, 2, 2, 2, 2, 2, 2,
1970 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1971 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1972 157, 154, 159, 2, 2, 2, 2, 2, 165, 2,
1973 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1974 2, 2, 2, 2, 2, 2, 2, 2, 2, 158,
1975 2, 2, 162, 2, 163, 2, 2, 2, 2, 2,
1976 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1977 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1978 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1979 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1980 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1981 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1982 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1983 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1984 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1985 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1986 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1987 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1988 2, 2, 2, 2, 2, 1, 3, 4, 5, 6,
1989 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
1990 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
1991 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
1992 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
1993 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
1994 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
1995 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
1996 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
1997 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
1998 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
1999 107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
2000 117, 118, 119, 120, 121, 122, 123, 124, 125, 126,
2001 127, 128, 129, 130, 131, 132, 133, 134, 135, 136,
2002 137, 138, 139, 140, 141, 142, 143, 144, 145, 146,
2003 147, 148, 149, 150, 151
2004};
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002005
Dale Johannesen3afee192007-09-07 21:07:57 +00002006#if YYDEBUG != 0
2007static const short yyprhs[] = { 0,
2008 0, 2, 4, 6, 8, 10, 12, 14, 16, 18,
2009 20, 22, 24, 26, 28, 30, 32, 34, 36, 38,
2010 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
2011 60, 62, 64, 66, 68, 70, 72, 74, 76, 78,
2012 80, 82, 84, 86, 88, 90, 92, 94, 96, 98,
2013 100, 102, 104, 106, 108, 110, 112, 114, 116, 118,
2014 120, 122, 124, 126, 128, 130, 132, 134, 136, 138,
2015 140, 142, 144, 146, 148, 150, 152, 154, 156, 158,
2016 161, 162, 164, 166, 168, 170, 172, 174, 176, 177,
2017 178, 180, 182, 184, 186, 188, 190, 193, 194, 197,
2018 198, 202, 205, 206, 208, 209, 213, 215, 218, 220,
2019 222, 224, 226, 228, 230, 232, 234, 236, 238, 240,
2020 242, 244, 246, 248, 250, 252, 254, 256, 258, 261,
2021 266, 272, 278, 282, 285, 291, 296, 299, 301, 305,
2022 307, 311, 313, 314, 319, 323, 327, 332, 337, 341,
2023 348, 354, 357, 360, 363, 366, 369, 372, 375, 378,
2024 381, 384, 391, 397, 406, 413, 420, 427, 435, 443,
2025 450, 457, 466, 475, 479, 481, 483, 485, 487, 490,
2026 493, 498, 501, 503, 508, 511, 516, 517, 525, 526,
2027 534, 535, 543, 544, 552, 556, 561, 562, 564, 566,
2028 568, 572, 576, 580, 584, 588, 592, 594, 595, 597,
2029 599, 601, 602, 605, 609, 611, 613, 617, 619, 620,
2030 629, 631, 633, 634, 639, 641, 643, 646, 647, 649,
2031 651, 652, 653, 659, 660, 662, 664, 666, 668, 670,
2032 672, 674, 676, 678, 682, 684, 690, 692, 694, 696,
2033 698, 701, 704, 707, 711, 714, 715, 717, 719, 721,
2034 724, 727, 731, 741, 751, 760, 774, 776, 778, 785,
2035 791, 794, 801, 809, 811, 815, 817, 818, 821, 823,
2036 829, 835, 841, 848, 855, 858, 863, 868, 875, 880,
2037 885, 890, 895, 902, 909, 912, 920, 922, 925, 926,
2038 928, 929, 933, 940, 944, 951, 954, 959, 966
2039};
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002040
Dale Johannesen3afee192007-09-07 21:07:57 +00002041static const short yyrhs[] = { 5,
2042 0, 6, 0, 3, 0, 4, 0, 79, 0, 80,
2043 0, 81, 0, 82, 0, 83, 0, 84, 0, 85,
2044 0, 86, 0, 87, 0, 88, 0, 89, 0, 90,
2045 0, 91, 0, 92, 0, 97, 0, 98, 0, 99,
2046 0, 100, 0, 101, 0, 102, 0, 119, 0, 120,
2047 0, 121, 0, 122, 0, 123, 0, 124, 0, 125,
2048 0, 126, 0, 127, 0, 128, 0, 129, 0, 130,
2049 0, 131, 0, 132, 0, 133, 0, 134, 0, 135,
2050 0, 136, 0, 137, 0, 138, 0, 125, 0, 126,
2051 0, 127, 0, 128, 0, 27, 0, 28, 0, 93,
2052 0, 94, 0, 95, 0, 96, 0, 140, 0, 141,
2053 0, 142, 0, 143, 0, 144, 0, 145, 0, 146,
2054 0, 147, 0, 148, 0, 149, 0, 150, 0, 151,
2055 0, 139, 0, 16, 0, 14, 0, 12, 0, 10,
2056 0, 17, 0, 15, 0, 13, 0, 11, 0, 175,
2057 0, 176, 0, 18, 0, 19, 0, 211, 152, 0,
2058 0, 41, 0, 42, 0, 43, 0, 44, 0, 45,
2059 0, 46, 0, 47, 0, 0, 0, 65, 0, 66,
2060 0, 67, 0, 68, 0, 69, 0, 70, 0, 64,
2061 4, 0, 0, 57, 4, 0, 0, 153, 57, 4,
2062 0, 34, 24, 0, 0, 184, 0, 0, 153, 187,
2063 186, 0, 184, 0, 57, 4, 0, 190, 0, 8,
2064 0, 192, 0, 8, 0, 192, 0, 9, 0, 10,
2065 0, 11, 0, 12, 0, 13, 0, 14, 0, 15,
2066 0, 16, 0, 17, 0, 18, 0, 19, 0, 21,
2067 0, 191, 0, 48, 0, 228, 0, 154, 4, 0,
2068 189, 155, 194, 156, 0, 157, 4, 158, 192, 159,
2069 0, 160, 4, 158, 192, 161, 0, 162, 193, 163,
2070 0, 162, 163, 0, 160, 162, 193, 163, 161, 0,
2071 160, 162, 163, 161, 0, 192, 164, 0, 192, 0,
2072 193, 153, 192, 0, 193, 0, 193, 153, 37, 0,
2073 37, 0, 0, 190, 157, 197, 159, 0, 190, 157,
2074 159, 0, 190, 165, 24, 0, 190, 160, 197, 161,
2075 0, 190, 162, 197, 163, 0, 190, 162, 163, 0,
2076 190, 160, 162, 197, 163, 161, 0, 190, 160, 162,
2077 163, 161, 0, 190, 38, 0, 190, 39, 0, 190,
2078 228, 0, 190, 196, 0, 190, 26, 0, 175, 167,
2079 0, 176, 4, 0, 9, 27, 0, 9, 28, 0,
2080 178, 7, 0, 174, 155, 195, 36, 190, 156, 0,
2081 110, 155, 195, 243, 156, 0, 112, 155, 195, 153,
2082 195, 153, 195, 156, 0, 168, 155, 195, 153, 195,
2083 156, 0, 169, 155, 195, 153, 195, 156, 0, 170,
2084 155, 195, 153, 195, 156, 0, 103, 171, 155, 195,
2085 153, 195, 156, 0, 104, 172, 155, 195, 153, 195,
2086 156, 0, 173, 155, 195, 153, 195, 156, 0, 114,
2087 155, 195, 153, 195, 156, 0, 115, 155, 195, 153,
2088 195, 153, 195, 156, 0, 116, 155, 195, 153, 195,
2089 153, 195, 156, 0, 197, 153, 195, 0, 195, 0,
2090 32, 0, 33, 0, 200, 0, 200, 221, 0, 200,
2091 223, 0, 200, 62, 61, 206, 0, 200, 25, 0,
2092 201, 0, 201, 179, 20, 188, 0, 201, 223, 0,
2093 201, 62, 61, 206, 0, 0, 201, 179, 180, 198,
2094 195, 202, 186, 0, 0, 201, 179, 50, 198, 190,
2095 203, 186, 0, 0, 201, 179, 45, 198, 190, 204,
2096 186, 0, 0, 201, 179, 47, 198, 190, 205, 186,
2097 0, 201, 51, 208, 0, 201, 58, 152, 209, 0,
2098 0, 24, 0, 56, 0, 55, 0, 53, 152, 207,
2099 0, 54, 152, 4, 0, 52, 152, 24, 0, 71,
2100 152, 24, 0, 157, 210, 159, 0, 210, 153, 24,
2101 0, 24, 0, 0, 22, 0, 24, 0, 211, 0,
2102 0, 190, 212, 0, 214, 153, 213, 0, 213, 0,
2103 214, 0, 214, 153, 37, 0, 37, 0, 0, 181,
2104 188, 211, 155, 215, 156, 185, 182, 0, 29, 0,
2105 162, 0, 0, 180, 219, 216, 217, 0, 30, 0,
2106 163, 0, 231, 220, 0, 0, 45, 0, 47, 0,
2107 0, 0, 31, 224, 222, 225, 216, 0, 0, 63,
2108 0, 3, 0, 4, 0, 7, 0, 27, 0, 28,
2109 0, 38, 0, 39, 0, 26, 0, 160, 197, 161,
2110 0, 196, 0, 61, 226, 24, 153, 24, 0, 166,
2111 0, 211, 0, 228, 0, 227, 0, 190, 229, 0,
2112 231, 232, 0, 218, 232, 0, 233, 179, 235, 0,
2113 233, 237, 0, 0, 23, 0, 77, 0, 78, 0,
2114 72, 230, 0, 72, 8, 0, 73, 21, 229, 0,
2115 73, 9, 229, 153, 21, 229, 153, 21, 229, 0,
2116 74, 177, 229, 153, 21, 229, 157, 236, 159, 0,
2117 74, 177, 229, 153, 21, 229, 157, 159, 0, 75,
2118 181, 188, 229, 155, 240, 156, 36, 21, 229, 234,
2119 21, 229, 0, 234, 0, 76, 0, 236, 177, 227,
2120 153, 21, 229, 0, 177, 227, 153, 21, 229, 0,
2121 179, 242, 0, 190, 157, 229, 153, 229, 159, 0,
2122 238, 153, 157, 229, 153, 229, 159, 0, 230, 0,
2123 239, 153, 230, 0, 239, 0, 0, 60, 59, 0,
2124 59, 0, 168, 190, 229, 153, 229, 0, 169, 190,
2125 229, 153, 229, 0, 170, 190, 229, 153, 229, 0,
2126 103, 171, 190, 229, 153, 229, 0, 104, 172, 190,
2127 229, 153, 229, 0, 49, 230, 0, 173, 230, 153,
2128 230, 0, 174, 230, 36, 190, 0, 112, 230, 153,
2129 230, 153, 230, 0, 113, 230, 153, 190, 0, 117,
2130 230, 153, 190, 0, 118, 230, 153, 190, 0, 114,
2131 230, 153, 230, 0, 115, 230, 153, 230, 153, 230,
2132 0, 116, 230, 153, 230, 153, 230, 0, 111, 238,
2133 0, 241, 181, 188, 229, 155, 240, 156, 0, 245,
2134 0, 153, 239, 0, 0, 35, 0, 0, 105, 190,
2135 183, 0, 105, 190, 153, 15, 229, 183, 0, 106,
2136 190, 183, 0, 106, 190, 153, 15, 229, 183, 0,
2137 107, 230, 0, 244, 108, 190, 229, 0, 244, 109,
2138 230, 153, 190, 229, 0, 110, 190, 229, 243, 0
2139};
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002140
2141#endif
2142
Dale Johannesen3afee192007-09-07 21:07:57 +00002143#if YYDEBUG != 0
2144static const short yyrline[] = { 0,
2145 1894, 1895, 1903, 1904, 1914, 1914, 1914, 1914, 1914, 1914,
2146 1914, 1914, 1914, 1914, 1914, 1918, 1918, 1918, 1922, 1922,
2147 1922, 1922, 1922, 1922, 1926, 1926, 1927, 1927, 1928, 1928,
2148 1929, 1929, 1930, 1930, 1934, 1934, 1935, 1935, 1936, 1936,
2149 1937, 1937, 1938, 1938, 1939, 1939, 1940, 1940, 1941, 1942,
2150 1945, 1945, 1945, 1945, 1949, 1949, 1949, 1949, 1949, 1949,
2151 1949, 1950, 1950, 1950, 1950, 1950, 1950, 1956, 1956, 1956,
2152 1956, 1960, 1960, 1960, 1960, 1964, 1964, 1968, 1968, 1973,
2153 1976, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1992,
2154 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2009, 2010, 2018,
2155 2019, 2027, 2036, 2037, 2044, 2045, 2049, 2053, 2069, 2070,
2156 2077, 2078, 2085, 2093, 2093, 2093, 2093, 2093, 2093, 2093,
2157 2094, 2094, 2094, 2094, 2094, 2099, 2103, 2107, 2112, 2121,
2158 2148, 2154, 2167, 2178, 2182, 2195, 2199, 2213, 2217, 2224,
2159 2225, 2231, 2238, 2250, 2280, 2293, 2316, 2344, 2366, 2377,
2160 2399, 2410, 2419, 2424, 2483, 2490, 2498, 2505, 2512, 2516,
2161 2520, 2534, 2549, 2561, 2570, 2598, 2611, 2620, 2626, 2632,
2162 2643, 2649, 2655, 2666, 2667, 2676, 2677, 2689, 2698, 2699,
2163 2700, 2701, 2702, 2718, 2738, 2740, 2742, 2746, 2749, 2754,
2164 2757, 2762, 2765, 2771, 2774, 2776, 2778, 2783, 2797, 2798,
2165 2802, 2805, 2813, 2817, 2824, 2828, 2832, 2836, 2844, 2844,
2166 2848, 2849, 2853, 2861, 2866, 2874, 2875, 2882, 2889, 2893,
2167 3083, 3083, 3087, 3087, 3097, 3097, 3101, 3106, 3107, 3108,
2168 3112, 3113, 3113, 3125, 3126, 3131, 3132, 3133, 3134, 3138,
2169 3142, 3143, 3144, 3145, 3166, 3170, 3184, 3185, 3190, 3190,
2170 3198, 3208, 3211, 3220, 3231, 3236, 3245, 3256, 3256, 3259,
2171 3263, 3267, 3272, 3282, 3300, 3309, 3383, 3387, 3394, 3406,
2172 3421, 3451, 3461, 3471, 3475, 3482, 3483, 3487, 3490, 3496,
2173 3515, 3533, 3549, 3563, 3577, 3588, 3606, 3615, 3624, 3631,
2174 3652, 3676, 3682, 3688, 3694, 3710, 3803, 3811, 3812, 3816,
2175 3817, 3821, 3827, 3834, 3840, 3847, 3854, 3867, 3893
2176};
2177#endif
2178
2179
2180#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
2181
2182static const char * const yytname[] = { "$","error","$undefined.","ESINT64VAL",
2183"EUINT64VAL","SINTVAL","UINTVAL","FPVAL","VOID","BOOL","SBYTE","UBYTE","SHORT",
2184"USHORT","INT","UINT","LONG","ULONG","FLOAT","DOUBLE","TYPE","LABEL","VAR_ID",
2185"LABELSTR","STRINGCONSTANT","IMPLEMENTATION","ZEROINITIALIZER","TRUETOK","FALSETOK",
2186"BEGINTOK","ENDTOK","DECLARE","GLOBAL","CONSTANT","SECTION","VOLATILE","TO",
2187"DOTDOTDOT","NULL_TOK","UNDEF","CONST","INTERNAL","LINKONCE","WEAK","APPENDING",
2188"DLLIMPORT","DLLEXPORT","EXTERN_WEAK","OPAQUE","NOT","EXTERNAL","TARGET","TRIPLE",
2189"ENDIAN","POINTERSIZE","LITTLE","BIG","ALIGN","DEPLIBS","CALL","TAIL","ASM_TOK",
2190"MODULE","SIDEEFFECT","CC_TOK","CCC_TOK","CSRETCC_TOK","FASTCC_TOK","COLDCC_TOK",
2191"X86_STDCALLCC_TOK","X86_FASTCALLCC_TOK","DATALAYOUT","RET","BR","SWITCH","INVOKE",
2192"UNREACHABLE","UNWIND","EXCEPT","ADD","SUB","MUL","DIV","UDIV","SDIV","FDIV",
2193"REM","UREM","SREM","FREM","AND","OR","XOR","SHL","SHR","ASHR","LSHR","SETLE",
2194"SETGE","SETLT","SETGT","SETEQ","SETNE","ICMP","FCMP","MALLOC","ALLOCA","FREE",
2195"LOAD","STORE","GETELEMENTPTR","PHI_TOK","SELECT","VAARG","EXTRACTELEMENT","INSERTELEMENT",
2196"SHUFFLEVECTOR","VAARG_old","VANEXT_old","EQ","NE","SLT","SGT","SLE","SGE","ULT",
2197"UGT","ULE","UGE","OEQ","ONE","OLT","OGT","OLE","OGE","ORD","UNO","UEQ","UNE",
2198"CAST","TRUNC","ZEXT","SEXT","FPTRUNC","FPEXT","FPTOUI","FPTOSI","UITOFP","SITOFP",
2199"PTRTOINT","INTTOPTR","BITCAST","'='","','","'\\\\'","'('","')'","'['","'x'",
2200"']'","'<'","'>'","'{'","'}'","'*'","'c'","INTVAL","EINT64VAL","ArithmeticOps",
2201"LogicalOps","SetCondOps","IPredicates","FPredicates","ShiftOps","CastOps","SIntType",
2202"UIntType","IntType","FPType","OptAssign","OptLinkage","OptCallingConv","OptAlign",
2203"OptCAlign","SectionString","OptSection","GlobalVarAttributes","GlobalVarAttribute",
2204"TypesV","UpRTypesV","Types","PrimType","UpRTypes","TypeListI","ArgTypeListI",
2205"ConstVal","ConstExpr","ConstVector","GlobalType","Module","FunctionList","ConstPool",
2206"@1","@2","@3","@4","AsmBlock","BigOrLittle","TargetDefinition","LibrariesDefinition",
2207"LibList","Name","OptName","ArgVal","ArgListH","ArgList","FunctionHeaderH","BEGIN",
2208"FunctionHeader","@5","END","Function","FnDeclareLinkage","FunctionProto","@6",
2209"@7","OptSideEffect","ConstValueRef","SymbolicValueRef","ValueRef","ResolvedVal",
2210"BasicBlockList","BasicBlock","InstructionList","Unwind","BBTerminatorInst",
2211"JumpTable","Inst","PHIList","ValueRefList","ValueRefListE","OptTailCall","InstVal",
2212"IndexList","OptVolatile","MemoryInst", NULL
2213};
2214#endif
2215
2216static const short yyr1[] = { 0,
2217 166, 166, 167, 167, 168, 168, 168, 168, 168, 168,
2218 168, 168, 168, 168, 168, 169, 169, 169, 170, 170,
2219 170, 170, 170, 170, 171, 171, 171, 171, 171, 171,
2220 171, 171, 171, 171, 172, 172, 172, 172, 172, 172,
2221 172, 172, 172, 172, 172, 172, 172, 172, 172, 172,
2222 173, 173, 173, 173, 174, 174, 174, 174, 174, 174,
2223 174, 174, 174, 174, 174, 174, 174, 175, 175, 175,
2224 175, 176, 176, 176, 176, 177, 177, 178, 178, 179,
2225 179, 180, 180, 180, 180, 180, 180, 180, 180, 181,
2226 181, 181, 181, 181, 181, 181, 181, 182, 182, 183,
2227 183, 184, 185, 185, 186, 186, 187, 187, 188, 188,
2228 189, 189, 190, 191, 191, 191, 191, 191, 191, 191,
2229 191, 191, 191, 191, 191, 192, 192, 192, 192, 192,
2230 192, 192, 192, 192, 192, 192, 192, 193, 193, 194,
2231 194, 194, 194, 195, 195, 195, 195, 195, 195, 195,
2232 195, 195, 195, 195, 195, 195, 195, 195, 195, 195,
2233 195, 196, 196, 196, 196, 196, 196, 196, 196, 196,
2234 196, 196, 196, 197, 197, 198, 198, 199, 200, 200,
2235 200, 200, 200, 201, 201, 201, 202, 201, 203, 201,
2236 204, 201, 205, 201, 201, 201, 201, 206, 207, 207,
2237 208, 208, 208, 208, 209, 210, 210, 210, 211, 211,
2238 212, 212, 213, 214, 214, 215, 215, 215, 215, 216,
2239 217, 217, 219, 218, 220, 220, 221, 222, 222, 222,
2240 224, 225, 223, 226, 226, 227, 227, 227, 227, 227,
2241 227, 227, 227, 227, 227, 227, 228, 228, 229, 229,
2242 230, 231, 231, 232, 233, 233, 233, 234, 234, 235,
2243 235, 235, 235, 235, 235, 235, 235, 235, 236, 236,
2244 237, 238, 238, 239, 239, 240, 240, 241, 241, 242,
2245 242, 242, 242, 242, 242, 242, 242, 242, 242, 242,
2246 242, 242, 242, 242, 242, 242, 242, 243, 243, 244,
2247 244, 245, 245, 245, 245, 245, 245, 245, 245
2248};
2249
2250static const short yyr2[] = { 0,
2251 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2252 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2253 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2254 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2255 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2256 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2257 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2258 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
2259 0, 1, 1, 1, 1, 1, 1, 1, 0, 0,
2260 1, 1, 1, 1, 1, 1, 2, 0, 2, 0,
2261 3, 2, 0, 1, 0, 3, 1, 2, 1, 1,
2262 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
2263 1, 1, 1, 1, 1, 1, 1, 1, 2, 4,
2264 5, 5, 3, 2, 5, 4, 2, 1, 3, 1,
2265 3, 1, 0, 4, 3, 3, 4, 4, 3, 6,
2266 5, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2267 2, 6, 5, 8, 6, 6, 6, 7, 7, 6,
2268 6, 8, 8, 3, 1, 1, 1, 1, 2, 2,
2269 4, 2, 1, 4, 2, 4, 0, 7, 0, 7,
2270 0, 7, 0, 7, 3, 4, 0, 1, 1, 1,
2271 3, 3, 3, 3, 3, 3, 1, 0, 1, 1,
2272 1, 0, 2, 3, 1, 1, 3, 1, 0, 8,
2273 1, 1, 0, 4, 1, 1, 2, 0, 1, 1,
2274 0, 0, 5, 0, 1, 1, 1, 1, 1, 1,
2275 1, 1, 1, 3, 1, 5, 1, 1, 1, 1,
2276 2, 2, 2, 3, 2, 0, 1, 1, 1, 2,
2277 2, 3, 9, 9, 8, 13, 1, 1, 6, 5,
2278 2, 6, 7, 1, 3, 1, 0, 2, 1, 5,
2279 5, 5, 6, 6, 2, 4, 4, 6, 4, 4,
2280 4, 4, 6, 6, 2, 7, 1, 2, 0, 1,
2281 0, 3, 6, 3, 6, 2, 4, 6, 4
2282};
2283
2284static const short yydefact[] = { 197,
2285 89, 183, 182, 231, 82, 83, 84, 85, 86, 87,
2286 88, 0, 223, 256, 179, 180, 256, 209, 210, 0,
2287 0, 0, 89, 0, 185, 228, 0, 90, 257, 253,
2288 81, 225, 226, 227, 252, 0, 0, 0, 0, 195,
2289 0, 0, 0, 0, 0, 0, 0, 80, 229, 230,
2290 232, 198, 181, 0, 91, 92, 93, 94, 95, 96,
2291 0, 0, 301, 255, 0, 0, 0, 0, 208, 196,
2292 186, 1, 2, 110, 114, 115, 116, 117, 118, 119,
2293 120, 121, 122, 123, 124, 125, 127, 0, 0, 0,
2294 0, 247, 184, 0, 109, 126, 113, 248, 128, 176,
2295 177, 0, 0, 0, 0, 90, 97, 0, 221, 222,
2296 224, 300, 0, 279, 0, 0, 0, 0, 90, 268,
2297 258, 259, 5, 6, 7, 8, 9, 10, 11, 12,
2298 13, 14, 15, 16, 17, 18, 51, 52, 53, 54,
2299 19, 20, 21, 22, 23, 24, 0, 0, 0, 0,
2300 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2301 67, 55, 56, 57, 58, 59, 60, 61, 62, 63,
2302 64, 65, 66, 0, 0, 0, 0, 0, 267, 254,
2303 90, 271, 0, 297, 203, 200, 199, 201, 202, 204,
2304 207, 0, 129, 0, 0, 0, 112, 134, 138, 0,
2305 143, 137, 191, 193, 189, 114, 115, 116, 117, 118,
2306 119, 120, 121, 122, 123, 124, 0, 0, 0, 0,
2307 187, 233, 0, 0, 285, 278, 261, 260, 0, 0,
2308 71, 75, 70, 74, 69, 73, 68, 72, 76, 77,
2309 0, 0, 25, 26, 27, 28, 29, 30, 31, 32,
2310 33, 34, 0, 49, 50, 45, 46, 47, 48, 35,
2311 36, 37, 38, 39, 40, 41, 42, 43, 44, 0,
2312 100, 100, 306, 0, 0, 295, 0, 0, 0, 0,
2313 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2314 0, 0, 205, 0, 0, 0, 0, 0, 133, 142,
2315 140, 0, 105, 105, 105, 159, 160, 3, 4, 157,
2316 158, 161, 156, 152, 153, 0, 0, 0, 0, 0,
2317 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2318 0, 155, 154, 105, 219, 236, 237, 238, 243, 239,
2319 240, 241, 242, 234, 0, 245, 250, 249, 251, 0,
2320 262, 0, 0, 0, 0, 0, 302, 0, 304, 299,
2321 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2322 0, 0, 0, 0, 0, 0, 0, 206, 111, 111,
2323 136, 0, 139, 0, 130, 0, 192, 194, 190, 0,
2324 0, 0, 0, 0, 0, 0, 145, 175, 0, 0,
2325 0, 149, 0, 146, 0, 0, 0, 0, 0, 188,
2326 218, 212, 215, 216, 0, 235, 0, 0, 0, 0,
2327 0, 0, 0, 0, 0, 0, 0, 309, 0, 0,
2328 0, 289, 292, 0, 0, 290, 291, 0, 0, 0,
2329 286, 287, 0, 307, 0, 131, 132, 135, 141, 0,
2330 0, 107, 105, 0, 0, 299, 0, 0, 0, 0,
2331 0, 144, 134, 113, 0, 147, 148, 0, 0, 0,
2332 0, 0, 211, 213, 0, 103, 0, 244, 0, 0,
2333 277, 0, 0, 100, 101, 100, 274, 298, 0, 0,
2334 0, 0, 0, 280, 281, 282, 277, 0, 102, 108,
2335 106, 0, 0, 0, 0, 0, 0, 0, 174, 151,
2336 0, 0, 0, 0, 0, 0, 217, 214, 104, 98,
2337 0, 0, 0, 276, 0, 283, 284, 0, 303, 305,
2338 0, 0, 0, 288, 293, 294, 0, 308, 0, 0,
2339 163, 0, 0, 0, 0, 150, 0, 0, 0, 0,
2340 0, 0, 220, 246, 0, 0, 0, 275, 272, 0,
2341 296, 0, 0, 0, 171, 0, 0, 165, 166, 167,
2342 170, 162, 99, 0, 265, 0, 0, 0, 273, 168,
2343 169, 0, 0, 0, 263, 0, 264, 0, 0, 164,
2344 172, 173, 0, 0, 0, 0, 0, 0, 270, 0,
2345 0, 269, 266, 0, 0, 0
2346};
2347
2348static const short yydefgoto[] = { 92,
2349 310, 327, 328, 329, 253, 270, 330, 331, 217, 218,
2350 241, 219, 23, 13, 61, 553, 357, 452, 520, 387,
2351 453, 93, 94, 220, 96, 97, 200, 302, 398, 346,
2352 399, 102, 604, 1, 2, 334, 305, 303, 304, 53,
2353 188, 40, 70, 192, 98, 474, 413, 414, 415, 62,
2354 111, 14, 28, 34, 15, 51, 16, 26, 106, 417,
2355 347, 99, 349, 487, 17, 30, 31, 179, 180, 577,
2356 64, 276, 524, 525, 181, 182, 428, 183, 184
2357};
2358
2359static const short yypact[] = {-32768,
2360 239, 567,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2361-32768, -46,-32768, 55,-32768,-32768, -14,-32768,-32768, 48,
2362 -6, 104, 161, 19,-32768, -34, 155, 249,-32768,-32768,
2363 98,-32768,-32768,-32768,-32768, 33, 43, 49, 57,-32768,
2364 59, 155, 1265, 150, 150, 150, 150,-32768,-32768,-32768,
2365-32768,-32768,-32768, 214,-32768,-32768,-32768,-32768,-32768,-32768,
2366 1265, -19, 1479,-32768, 196, 157, 224, 206, 212,-32768,
2367-32768,-32768,-32768, 87,-32768,-32768,-32768,-32768,-32768,-32768,
2368-32768,-32768,-32768,-32768,-32768,-32768,-32768, 241, 247, 4,
2369 15,-32768,-32768, 108,-32768,-32768, 12,-32768,-32768,-32768,
2370-32768, 1306, 1306, 1306, 1326, 249,-32768, 98,-32768,-32768,
2371-32768,-32768, 1306,-32768, 194, 1367, 116, 177, 249,-32768,
2372-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2373-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2374-32768,-32768,-32768,-32768,-32768,-32768, 355, 429, 1306, 1306,
2375 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 1306,
2376-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2377-32768,-32768,-32768, 1306, 1306, 1306, 1306, 1306,-32768,-32768,
2378 249,-32768, 106,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2379-32768, -32,-32768, 103, 110, 75,-32768,-32768, 12, -81,
2380 1046,-32768,-32768,-32768,-32768, 197, 230, 265, 237, 267,
2381 240, 268, 246, 270, 269, 271, 254, 273, 272, 566,
2382-32768,-32768, 120, 766,-32768,-32768, 87,-32768, 766, 766,
2383-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2384 766, 1265,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2385-32768,-32768, 1306,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
2386-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 1306,
2387 136, 137,-32768, 766, 134, 146, 147, 149, 152, 158,
2388 174, 176, 179, 766, 766, 766, 180, 262, 1265, 1306,
2389 1306, 279,-32768, 1306, 1306, 173, -27, 1306,-32768,-32768,
2390 184, 183, 187, 187, 187,-32768,-32768,-32768,-32768,-32768,
2391-32768,-32768,-32768,-32768,-32768, 355, 429, 186, 188, 189,
2392 190, 191, 1087, 1387, 529, 311, 192, 193, 198, 199,
2393 202,-32768,-32768, 187, 1107,-32768,-32768,-32768,-32768,-32768,
2394-32768,-32768,-32768, 286, 1326,-32768,-32768,-32768,-32768, 205,
2395-32768, 207, 766, 766, 766, 7,-32768, 20,-32768, 208,
2396 766, 209, 1306, 1306, 1306, 1306, 1306, 1306, 1306, 210,
2397 216, 217, 1306, 1306, 766, 766, 218,-32768, -12, 9,
2398-32768, 204, 12, 1148,-32768, 8,-32768,-32768,-32768, 220,
2399 221, 1326, 1326, 1326, 1326, 1326,-32768,-32768, -8, 741,
2400 -82,-32768, -9,-32768, 1326, 1326, 1326, 1326, 1326,-32768,
2401-32768, 98,-32768, 219, 203,-32768, 343, -13, 356, 357,
2402 228, 226, 233, 766, 383, 766, 1306,-32768, 235, 766,
2403 236,-32768,-32768, 243, 244,-32768,-32768, 766, 766, 766,
2404-32768,-32768, 238,-32768, 1306,-32768,-32768,-32768,-32768, 366,
2405 394,-32768, 187, 1326, 1326, 208, 250, 251, 252, 258,
2406 1326,-32768, 256, -25, 11,-32768,-32768, 259, 266, 274,
2407 278, 363,-32768,-32768, 1205, 387, 280,-32768, 766, 766,
2408 1306, 766, 766, 281,-32768, 281,-32768, 282, 766, 283,
2409 1306, 1306, 1306,-32768,-32768,-32768, 1306, 766,-32768,-32768,
2410-32768, 284, 290, 288, 1326, 1326, 1326, 1326,-32768,-32768,
2411 263, 1326, 1326, 1326, 1326, 1306,-32768,-32768,-32768, 368,
2412 376, 293, 294, 282, 291,-32768,-32768, 369,-32768,-32768,
2413 1306, 264, 766,-32768,-32768,-32768, 296,-32768, 1326, 1326,
2414-32768, 300, 299, 305, 306,-32768, 308, 310, 313, 314,
2415 315, 457,-32768,-32768, 441, 41, 436,-32768,-32768, 325,
2416-32768, 329, 331, 1326,-32768, 1326, 1326,-32768,-32768,-32768,
2417-32768,-32768,-32768, 766,-32768, 893, 145, 468,-32768,-32768,
2418-32768, 334, 335, 336,-32768, 340,-32768, 893, 766,-32768,
2419-32768,-32768, 473, 342, 182, 766, 475, 479,-32768, 766,
2420 766,-32768,-32768, 502, 503,-32768
2421};
2422
2423static const short yypgoto[] = {-32768,
2424-32768, 443, 444, 446, 195, 200, 447, 451, -117, -114,
2425 -539,-32768, 484, 481, -105,-32768, -265, 40,-32768, -236,
2426-32768, -58,-32768, -43,-32768, -72, -33,-32768, -99, 298,
2427 -250, 58,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 480,
2428-32768,-32768,-32768,-32768, 10,-32768, 46,-32768,-32768, 417,
2429-32768,-32768,-32768,-32768,-32768,-32768, 522,-32768,-32768,-32768,
2430 -526, 144, -88, -111,-32768, 508,-32768, -69,-32768,-32768,
2431-32768,-32768, 100, 31,-32768,-32768, 73,-32768,-32768
2432};
2433
2434
2435#define YYLAST 1630
2436
2437
2438static const short yytable[] = { 95,
2439 239, 225, 108, 240, 228, 221, 359, 195, 29, 109,
2440 49, 24, 50, 242, 27, 32, 576, 95, 199, 72,
2441 73, 424, 197, 75, 76, 77, 78, 79, 80, 81,
2442 82, 83, 84, 85, 426, 86, 18, 588, 19, 273,
2443 24, 450, 277, 278, 279, 280, 281, 282, 283, 586,
2444 231, 232, 233, 234, 235, 236, 237, 238, 203, 204,
2445 205, 594, 87, 425, 451, 287, 288, 388, 389, 224,
2446 461, 298, 224, 401, 403, 289, 425, 29, 466, 72,
2447 73, 299, 197, 75, 76, 77, 78, 79, 80, 81,
2448 82, 83, 84, 85, 418, 86, 18, 410, 19, 36,
2449 37, 38, 103, 104, 105, 271, 272, 224, 274, 275,
2450 224, 224, 224, 224, 224, 224, 224, 223, 39, 18,
2451 292, 19, 87, 199, 229, 298, 293, -138, 199, -111,
2452 284, 285, 286, 224, 224, 382, 230, -138, 202, 461,
2453 350, 351, 110, 461, 461, 41, 446, 478, 33, 465,
2454 462, 202, 352, 467, 231, 232, 233, 234, 235, 236,
2455 237, 238, 297, 461, 42, 196, -111, 301, 88, 447,
2456 48, 89, 202, 511, 90, 202, 91, 198, 52, 377,
2457 43, 100, 101, 353, 65, 360, 231, 232, 233, 234,
2458 235, 236, 237, 238, 66, 370, 371, 372, 95, 575,
2459 67, 5, 6, 7, 8, 44, 10, 45, 68, 354,
2460 46, 186, 187, 290, 291, 69, 501, 107, 529, 185,
2461 530, 379, 380, 306, 307, 383, 355, 189, 88, 190,
2462 375, 89, -71, -71, 90, 191, 91, 296, -178, -70,
2463 -70, -112, -69, -69, 193, 95, 376, 224, -68, -68,
2464 194, 431, 226, 433, 434, 435, 308, 309, 121, 122,
2465 294, 441, 201, 3, 421, 422, 423, 295, -75, 4,
2466 -74, -73, 429, -72, 335, -78, 311, -79, 312, 5,
2467 6, 7, 8, 9, 10, 11, 443, 444, 356, 358,
2468 361, 412, 456, 457, 458, 459, 460, 374, 362, 363,
2469 12, 364, 378, 587, 365, 468, 469, 470, 471, 472,
2470 366, 383, 54, 55, 56, 57, 58, 59, 60, 224,
2471 432, 224, 224, 224, 436, 437, 367, 464, 368, 224,
2472 442, 369, 373, 381, 404, 484, 384, 486, 385, 386,
2473 392, 490, 393, 394, 395, 396, 405, 406, 416, 494,
2474 495, 496, 407, 408, 502, 503, 409, 419, 476, 420,
2475 427, 509, 438, 333, 448, 430, 477, 348, 439, 440,
2476 445, 475, 348, 348, 454, 455, 479, 480, 482, 534,
2477 535, 536, 481, 224, 348, 483, 485, 489, 491, 499,
2478 522, 523, 497, 526, 527, 492, 493, 500, 516, 554,
2479 532, 498, 505, 506, 507, 542, 543, 544, 545, 538,
2480 508, 512, 547, 548, 549, 550, 510, 348, 513, 558,
2481 450, 473, 559, 546, 552, 425, 514, 348, 348, 348,
2482 515, 412, 521, 528, 531, 533, 539, 224, 239, 562,
2483 563, 240, 540, 541, 560, 555, 557, 224, 224, 224,
2484 556, 561, 564, 224, 565, 254, 255, 566, 567, 239,
2485 573, 574, 240, 568, 582, 569, 583, 584, 570, 571,
2486 572, 578, 551, 243, 244, 245, 246, 247, 248, 249,
2487 250, 251, 252, 579, 580, 585, 581, 224, 589, 590,
2488 591, 592, 593, 596, 597, 600, 348, 348, 348, 601,
2489 595, 605, 606, 47, 348, 174, 175, 599, 176, 177,
2490 390, 602, 603, 178, 63, 519, 391, 332, 348, 348,
2491 518, 71, 222, 25, 35, 598, 488, 537, 504, 0,
2492 0, 0, 0, 72, 73, 0, 197, 206, 207, 208,
2493 209, 210, 211, 212, 213, 214, 215, 216, 0, 86,
2494 18, 0, 19, 256, 257, 258, 259, 260, 261, 262,
2495 263, 264, 265, 266, 267, 268, 269, 348, 0, 348,
2496 72, 73, 0, 348, 0, 0, 87, 0, 0, 0,
2497 0, 348, 348, 348, 0, 0, -81, 18, 18, 19,
2498 19, 313, 0, 0, 0, 0, 0, 4, -81, -81,
2499 0, 0, 0, 314, 315, 0, 0, -81, -81, -81,
2500 -81, -81, -81, -81, 0, 0, -81, 20, 0, 0,
2501 0, 0, 348, 348, 21, 348, 348, 0, 22, 0,
2502 0, 0, 348, 0, 0, 0, 0, 0, 0, 0,
2503 0, 348, 0, 0, 123, 124, 125, 126, 127, 128,
2504 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,
2505 139, 140, 141, 142, 143, 144, 145, 146, 316, 317,
2506 0, 0, 0, 0, 0, 318, 348, 319, 0, 320,
2507 321, 322, 88, 0, 0, 89, 0, 0, 90, 0,
2508 91, 402, 0, 0, 0, 0, 0, 0, 0, 0,
2509 0, 0, 0, 0, 161, 162, 163, 164, 165, 166,
2510 167, 168, 169, 170, 171, 172, 173, 348, 0, 0,
2511 0, 0, 323, 0, 0, 324, 0, 325, 0, 0,
2512 326, 0, 348, 0, 0, 0, 0, 0, 0, 348,
2513 0, 0, 0, 348, 348, 72, 73, 0, 197, 206,
2514 207, 208, 209, 210, 211, 212, 213, 214, 215, 216,
2515 0, 86, 18, 0, 19, 0, 0, 0, 336, 337,
2516 72, 73, 338, 0, 0, 0, 0, 0, 0, 0,
2517 0, 0, 0, 0, 0, 0, 0, 18, 87, 19,
2518 0, 339, 340, 341, 0, 0, 0, 0, 0, 0,
2519 0, 0, 0, 342, 343, 0, 0, 0, 0, 0,
2520 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2521 0, 0, 0, 0, 0, 0, 344, 0, 0, 0,
2522 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2523 0, 0, 0, 0, 123, 124, 125, 126, 127, 128,
2524 129, 130, 131, 132, 133, 134, 135, 136, 137, 138,
2525 139, 140, 141, 142, 143, 144, 145, 146, 316, 317,
2526 0, 0, 0, 0, 0, 318, 0, 319, 0, 320,
2527 321, 322, 0, 0, 0, 0, 0, 0, 0, 0,
2528 0, 0, 0, 0, 88, 336, 337, 89, 0, 338,
2529 90, 0, 91, 463, 161, 162, 163, 164, 165, 166,
2530 167, 168, 169, 170, 171, 172, 173, 0, 339, 340,
2531 341, 0, 0, 0, 0, 345, 0, 0, 0, 0,
2532 342, 343, 0, 0, 0, 0, 0, 0, 0, 0,
2533 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2534 0, 0, 0, 344, 0, 0, 0, 0, 0, 0,
2535 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2536 0, 123, 124, 125, 126, 127, 128, 129, 130, 131,
2537 132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
2538 142, 143, 144, 145, 146, 316, 317, 0, 0, 0,
2539 0, 0, 318, 0, 319, 0, 320, 321, 322, 0,
2540 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2541 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2542 0, 161, 162, 163, 164, 165, 166, 167, 168, 169,
2543 170, 171, 172, 173, 0, 0, 0, 0, 0, 0,
2544 72, 73, 345, 197, 75, 76, 77, 78, 79, 80,
2545 81, 82, 83, 84, 85, 0, 86, 18, 0, 19,
2546 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2547 0, 0, 300, 0, 0, 0, 0, 0, 0, 0,
2548 0, 72, 73, 87, 197, 206, 207, 208, 209, 210,
2549 211, 212, 213, 214, 215, 216, 0, 86, 18, 0,
2550 19, 72, 73, 0, 197, 75, 76, 77, 78, 79,
2551 80, 81, 82, 83, 84, 85, 0, 86, 18, 0,
2552 19, 0, 0, 0, 87, 0, 0, 0, 0, 0,
2553 0, 0, 0, 411, 0, 0, 0, 0, 0, 0,
2554 0, 0, 72, 73, 87, 197, 75, 76, 77, 78,
2555 79, 80, 81, 82, 83, 84, 85, 0, 86, 18,
2556 0, 19, 0, 0, 0, 0, 0, 0, 0, 0,
2557 0, 0, 0, 0, 449, 0, 0, 0, 0, 0,
2558 0, 0, 0, 0, 0, 87, 0, 0, 0, 88,
2559 0, 0, 89, 0, 0, 90, 0, 91, 0, 72,
2560 73, 0, 197, 75, 76, 77, 78, 79, 80, 81,
2561 82, 83, 84, 85, 0, 86, 18, 0, 19, 0,
2562 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2563 88, 517, 0, 89, 0, 397, 90, 0, 91, 0,
2564 0, 0, 87, 0, 0, 0, 0, 0, 0, 0,
2565 88, 0, 0, 89, 0, 0, 90, 0, 91, 72,
2566 73, 0, 74, 75, 76, 77, 78, 79, 80, 81,
2567 82, 83, 84, 85, 0, 86, 18, 0, 19, 0,
2568 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2569 0, 88, 0, 0, 89, 0, 0, 90, 0, 91,
2570 72, 73, 87, 197, 75, 76, 77, 78, 79, 80,
2571 81, 82, 83, 84, 85, 0, 86, 18, 0, 19,
2572 72, 73, 0, 197, 206, 207, 208, 209, 210, 211,
2573 212, 213, 214, 215, 216, 0, 86, 18, 0, 19,
2574 0, 0, 0, 87, 0, 0, 0, 0, 88, 0,
2575 0, 89, 0, 0, 90, 0, 91, 0, 0, 0,
2576 0, 72, 73, 87, 227, 75, 76, 77, 78, 79,
2577 80, 81, 82, 83, 84, 85, 0, 86, 18, 0,
2578 19, 72, 73, 0, 197, 206, 207, 208, 209, 210,
2579 211, 212, 213, 214, 215, 216, 0, 86, 18, 0,
2580 19, 0, 0, 0, 87, 0, 0, 0, 88, 0,
2581 0, 89, 0, 0, 90, 0, 91, 0, 0, 0,
2582 0, 0, 0, 0, 87, 0, 0, 0, 0, 0,
2583 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2584 0, 0, 0, 0, 0, 0, 0, 0, 0, 88,
2585 0, 0, 89, 0, 0, 90, 0, 91, 0, 0,
2586 0, 0, 0, 0, 0, 0, 0, 0, 0, 88,
2587 0, 0, 89, 0, 0, 90, 0, 91, 0, 0,
2588 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2589 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2590 0, 0, 0, 112, 0, 0, 0, 0, 0, 0,
2591 88, 0, 0, 89, 0, 0, 90, 113, 91, 0,
2592 0, 0, 0, 0, 0, 0, 0, 114, 115, 0,
2593 88, 0, 0, 89, 0, 0, 90, 0, 400, 0,
2594 116, 117, 118, 119, 120, 121, 122, 123, 124, 125,
2595 126, 127, 128, 129, 130, 131, 132, 133, 134, 135,
2596 136, 137, 138, 139, 140, 141, 142, 143, 144, 145,
2597 146, 147, 148, 149, 150, 151, 0, 0, 152, 153,
2598 154, 155, 156, 157, 158, 159, 160, 0, 0, 0,
2599 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2600 0, 0, 0, 0, 0, 0, 0, 161, 162, 163,
2601 164, 165, 166, 167, 168, 169, 170, 171, 172, 173
2602};
2603
2604static const short yycheck[] = { 43,
2605 118, 113, 61, 118, 116, 105, 272, 4, 23, 29,
2606 45, 2, 47, 119, 61, 30, 556, 61, 91, 5,
2607 6, 15, 8, 9, 10, 11, 12, 13, 14, 15,
2608 16, 17, 18, 19, 15, 21, 22, 577, 24, 151,
2609 31, 34, 154, 155, 156, 157, 158, 159, 160, 576,
2610 10, 11, 12, 13, 14, 15, 16, 17, 102, 103,
2611 104, 588, 48, 57, 57, 177, 178, 304, 305, 113,
2612 153, 153, 116, 324, 325, 181, 57, 23, 161, 5,
2613 6, 163, 8, 9, 10, 11, 12, 13, 14, 15,
2614 16, 17, 18, 19, 345, 21, 22, 334, 24, 52,
2615 53, 54, 45, 46, 47, 149, 150, 151, 152, 153,
2616 154, 155, 156, 157, 158, 159, 160, 108, 71, 22,
2617 153, 24, 48, 196, 9, 153, 159, 153, 201, 155,
2618 174, 175, 176, 177, 178, 163, 21, 163, 164, 153,
2619 229, 230, 162, 153, 153, 152, 159, 161, 163, 400,
2620 159, 164, 241, 163, 10, 11, 12, 13, 14, 15,
2621 16, 17, 196, 153, 61, 162, 155, 201, 154, 161,
2622 152, 157, 164, 163, 160, 164, 162, 163, 24, 291,
2623 20, 32, 33, 242, 152, 274, 10, 11, 12, 13,
2624 14, 15, 16, 17, 152, 284, 285, 286, 242, 159,
2625 152, 41, 42, 43, 44, 45, 46, 47, 152, 253,
2626 50, 55, 56, 108, 109, 157, 453, 4, 484, 24,
2627 486, 294, 295, 27, 28, 298, 270, 4, 154, 24,
2628 289, 157, 3, 4, 160, 24, 162, 163, 0, 3,
2629 4, 155, 3, 4, 4, 289, 290, 291, 3, 4,
2630 4, 363, 59, 365, 366, 367, 3, 4, 77, 78,
2631 158, 373, 155, 25, 353, 354, 355, 158, 4, 31,
2632 4, 4, 361, 4, 155, 7, 4, 7, 7, 41,
2633 42, 43, 44, 45, 46, 47, 375, 376, 153, 153,
2634 157, 335, 392, 393, 394, 395, 396, 36, 153, 153,
2635 62, 153, 24, 159, 153, 405, 406, 407, 408, 409,
2636 153, 384, 64, 65, 66, 67, 68, 69, 70, 363,
2637 364, 365, 366, 367, 368, 369, 153, 400, 153, 373,
2638 374, 153, 153, 161, 24, 424, 153, 426, 156, 153,
2639 155, 430, 155, 155, 155, 155, 155, 155, 63, 438,
2640 439, 440, 155, 155, 454, 455, 155, 153, 156, 153,
2641 153, 461, 153, 220, 161, 157, 24, 224, 153, 153,
2642 153, 153, 229, 230, 155, 155, 21, 21, 153, 491,
2643 492, 493, 155, 427, 241, 153, 4, 153, 153, 24,
2644 479, 480, 155, 482, 483, 153, 153, 4, 36, 24,
2645 489, 445, 153, 153, 153, 505, 506, 507, 508, 498,
2646 153, 153, 512, 513, 514, 515, 161, 274, 153, 531,
2647 34, 412, 159, 161, 57, 57, 153, 284, 285, 286,
2648 153, 475, 153, 153, 153, 153, 153, 481, 556, 539,
2649 540, 556, 153, 156, 533, 153, 156, 491, 492, 493,
2650 157, 156, 153, 497, 156, 27, 28, 153, 153, 577,
2651 4, 21, 577, 156, 564, 156, 566, 567, 156, 156,
2652 156, 36, 516, 119, 120, 121, 122, 123, 124, 125,
2653 126, 127, 128, 159, 156, 574, 156, 531, 21, 156,
2654 156, 156, 153, 21, 153, 21, 353, 354, 355, 21,
2655 589, 0, 0, 23, 361, 63, 63, 596, 63, 63,
2656 316, 600, 601, 63, 31, 476, 317, 220, 375, 376,
2657 475, 42, 106, 2, 17, 595, 427, 497, 456, -1,
2658 -1, -1, -1, 5, 6, -1, 8, 9, 10, 11,
2659 12, 13, 14, 15, 16, 17, 18, 19, -1, 21,
2660 22, -1, 24, 125, 126, 127, 128, 129, 130, 131,
2661 132, 133, 134, 135, 136, 137, 138, 424, -1, 426,
2662 5, 6, -1, 430, -1, -1, 48, -1, -1, -1,
2663 -1, 438, 439, 440, -1, -1, 20, 22, 22, 24,
2664 24, 26, -1, -1, -1, -1, -1, 31, 32, 33,
2665 -1, -1, -1, 38, 39, -1, -1, 41, 42, 43,
2666 44, 45, 46, 47, -1, -1, 50, 51, -1, -1,
2667 -1, -1, 479, 480, 58, 482, 483, -1, 62, -1,
2668 -1, -1, 489, -1, -1, -1, -1, -1, -1, -1,
2669 -1, 498, -1, -1, 79, 80, 81, 82, 83, 84,
2670 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
2671 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
2672 -1, -1, -1, -1, -1, 110, 533, 112, -1, 114,
2673 115, 116, 154, -1, -1, 157, -1, -1, 160, -1,
2674 162, 163, -1, -1, -1, -1, -1, -1, -1, -1,
2675 -1, -1, -1, -1, 139, 140, 141, 142, 143, 144,
2676 145, 146, 147, 148, 149, 150, 151, 574, -1, -1,
2677 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
2678 165, -1, 589, -1, -1, -1, -1, -1, -1, 596,
2679 -1, -1, -1, 600, 601, 5, 6, -1, 8, 9,
2680 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
2681 -1, 21, 22, -1, 24, -1, -1, -1, 3, 4,
2682 5, 6, 7, -1, -1, -1, -1, -1, -1, -1,
2683 -1, -1, -1, -1, -1, -1, -1, 22, 48, 24,
2684 -1, 26, 27, 28, -1, -1, -1, -1, -1, -1,
2685 -1, -1, -1, 38, 39, -1, -1, -1, -1, -1,
2686 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2687 -1, -1, -1, -1, -1, -1, 61, -1, -1, -1,
2688 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2689 -1, -1, -1, -1, 79, 80, 81, 82, 83, 84,
2690 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
2691 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
2692 -1, -1, -1, -1, -1, 110, -1, 112, -1, 114,
2693 115, 116, -1, -1, -1, -1, -1, -1, -1, -1,
2694 -1, -1, -1, -1, 154, 3, 4, 157, -1, 7,
2695 160, -1, 162, 163, 139, 140, 141, 142, 143, 144,
2696 145, 146, 147, 148, 149, 150, 151, -1, 26, 27,
2697 28, -1, -1, -1, -1, 160, -1, -1, -1, -1,
2698 38, 39, -1, -1, -1, -1, -1, -1, -1, -1,
2699 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2700 -1, -1, -1, 61, -1, -1, -1, -1, -1, -1,
2701 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2702 -1, 79, 80, 81, 82, 83, 84, 85, 86, 87,
2703 88, 89, 90, 91, 92, 93, 94, 95, 96, 97,
2704 98, 99, 100, 101, 102, 103, 104, -1, -1, -1,
2705 -1, -1, 110, -1, 112, -1, 114, 115, 116, -1,
2706 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2707 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2708 -1, 139, 140, 141, 142, 143, 144, 145, 146, 147,
2709 148, 149, 150, 151, -1, -1, -1, -1, -1, -1,
2710 5, 6, 160, 8, 9, 10, 11, 12, 13, 14,
2711 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
2712 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2713 -1, -1, 37, -1, -1, -1, -1, -1, -1, -1,
2714 -1, 5, 6, 48, 8, 9, 10, 11, 12, 13,
2715 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
2716 24, 5, 6, -1, 8, 9, 10, 11, 12, 13,
2717 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
2718 24, -1, -1, -1, 48, -1, -1, -1, -1, -1,
2719 -1, -1, -1, 37, -1, -1, -1, -1, -1, -1,
2720 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
2721 13, 14, 15, 16, 17, 18, 19, -1, 21, 22,
2722 -1, 24, -1, -1, -1, -1, -1, -1, -1, -1,
2723 -1, -1, -1, -1, 37, -1, -1, -1, -1, -1,
2724 -1, -1, -1, -1, -1, 48, -1, -1, -1, 154,
2725 -1, -1, 157, -1, -1, 160, -1, 162, -1, 5,
2726 6, -1, 8, 9, 10, 11, 12, 13, 14, 15,
2727 16, 17, 18, 19, -1, 21, 22, -1, 24, -1,
2728 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2729 154, 37, -1, 157, -1, 159, 160, -1, 162, -1,
2730 -1, -1, 48, -1, -1, -1, -1, -1, -1, -1,
2731 154, -1, -1, 157, -1, -1, 160, -1, 162, 5,
2732 6, -1, 8, 9, 10, 11, 12, 13, 14, 15,
2733 16, 17, 18, 19, -1, 21, 22, -1, 24, -1,
2734 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2735 -1, 154, -1, -1, 157, -1, -1, 160, -1, 162,
2736 5, 6, 48, 8, 9, 10, 11, 12, 13, 14,
2737 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
2738 5, 6, -1, 8, 9, 10, 11, 12, 13, 14,
2739 15, 16, 17, 18, 19, -1, 21, 22, -1, 24,
2740 -1, -1, -1, 48, -1, -1, -1, -1, 154, -1,
2741 -1, 157, -1, -1, 160, -1, 162, -1, -1, -1,
2742 -1, 5, 6, 48, 8, 9, 10, 11, 12, 13,
2743 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
2744 24, 5, 6, -1, 8, 9, 10, 11, 12, 13,
2745 14, 15, 16, 17, 18, 19, -1, 21, 22, -1,
2746 24, -1, -1, -1, 48, -1, -1, -1, 154, -1,
2747 -1, 157, -1, -1, 160, -1, 162, -1, -1, -1,
2748 -1, -1, -1, -1, 48, -1, -1, -1, -1, -1,
2749 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2750 -1, -1, -1, -1, -1, -1, -1, -1, -1, 154,
2751 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
2752 -1, -1, -1, -1, -1, -1, -1, -1, -1, 154,
2753 -1, -1, 157, -1, -1, 160, -1, 162, -1, -1,
2754 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2755 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2756 -1, -1, -1, 35, -1, -1, -1, -1, -1, -1,
2757 154, -1, -1, 157, -1, -1, 160, 49, 162, -1,
2758 -1, -1, -1, -1, -1, -1, -1, 59, 60, -1,
2759 154, -1, -1, 157, -1, -1, 160, -1, 162, -1,
2760 72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
2761 82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
2762 92, 93, 94, 95, 96, 97, 98, 99, 100, 101,
2763 102, 103, 104, 105, 106, 107, -1, -1, 110, 111,
2764 112, 113, 114, 115, 116, 117, 118, -1, -1, -1,
2765 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
2766 -1, -1, -1, -1, -1, -1, -1, 139, 140, 141,
2767 142, 143, 144, 145, 146, 147, 148, 149, 150, 151
2768};
2769/* -*-C-*- Note some compilers choke on comments on `#line' lines. */
2770#line 3 "/usr/share/bison.simple"
2771/* This file comes from bison-1.28. */
2772
2773/* Skeleton output parser for bison,
2774 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
2775
2776 This program is free software; you can redistribute it and/or modify
2777 it under the terms of the GNU General Public License as published by
2778 the Free Software Foundation; either version 2, or (at your option)
2779 any later version.
2780
2781 This program is distributed in the hope that it will be useful,
2782 but WITHOUT ANY WARRANTY; without even the implied warranty of
2783 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2784 GNU General Public License for more details.
2785
2786 You should have received a copy of the GNU General Public License
2787 along with this program; if not, write to the Free Software
2788 Foundation, Inc., 59 Temple Place - Suite 330,
2789 Boston, MA 02111-1307, USA. */
2790
2791/* As a special exception, when this file is copied by Bison into a
2792 Bison output file, you may use that output file without restriction.
2793 This special exception was added by the Free Software Foundation
2794 in version 1.24 of Bison. */
2795
2796/* This is the parser code that is written into each bison parser
2797 when the %semantic_parser declaration is not specified in the grammar.
2798 It was written by Richard Stallman by simplifying the hairy parser
2799 used when %semantic_parser is specified. */
2800
2801#ifndef YYSTACK_USE_ALLOCA
2802#ifdef alloca
2803#define YYSTACK_USE_ALLOCA
2804#else /* alloca not defined */
2805#ifdef __GNUC__
2806#define YYSTACK_USE_ALLOCA
2807#define alloca __builtin_alloca
2808#else /* not GNU C. */
2809#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
2810#define YYSTACK_USE_ALLOCA
2811#include <alloca.h>
2812#else /* not sparc */
2813/* We think this test detects Watcom and Microsoft C. */
2814/* This used to test MSDOS, but that is a bad idea
2815 since that symbol is in the user namespace. */
2816#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
2817#if 0 /* No need for malloc.h, which pollutes the namespace;
2818 instead, just don't use alloca. */
2819#include <malloc.h>
2820#endif
2821#else /* not MSDOS, or __TURBOC__ */
2822#if defined(_AIX)
2823/* I don't know what this was needed for, but it pollutes the namespace.
2824 So I turned it off. rms, 2 May 1997. */
2825/* #include <malloc.h> */
2826 #pragma alloca
2827#define YYSTACK_USE_ALLOCA
2828#else /* not MSDOS, or __TURBOC__, or _AIX */
2829#if 0
2830#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
2831 and on HPUX 10. Eventually we can turn this on. */
2832#define YYSTACK_USE_ALLOCA
2833#define alloca __builtin_alloca
2834#endif /* __hpux */
2835#endif
2836#endif /* not _AIX */
2837#endif /* not MSDOS, or __TURBOC__ */
2838#endif /* not sparc */
2839#endif /* not GNU C */
2840#endif /* alloca not defined */
2841#endif /* YYSTACK_USE_ALLOCA not defined */
2842
2843#ifdef YYSTACK_USE_ALLOCA
2844#define YYSTACK_ALLOC alloca
David Greene48556392007-09-04 18:46:50 +00002845#else
Dale Johannesen3afee192007-09-07 21:07:57 +00002846#define YYSTACK_ALLOC malloc
David Greene48556392007-09-04 18:46:50 +00002847#endif
2848
Dale Johannesen3afee192007-09-07 21:07:57 +00002849/* Note: there must be only one dollar sign in this file.
2850 It is replaced by the list of actions, each action
2851 as one case of the switch. */
David Greene48556392007-09-04 18:46:50 +00002852
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002853#define yyerrok (yyerrstatus = 0)
2854#define yyclearin (yychar = YYEMPTY)
Dale Johannesen3afee192007-09-07 21:07:57 +00002855#define YYEMPTY -2
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002856#define YYEOF 0
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002857#define YYACCEPT goto yyacceptlab
Dale Johannesen3afee192007-09-07 21:07:57 +00002858#define YYABORT goto yyabortlab
2859#define YYERROR goto yyerrlab1
2860/* Like YYERROR except do call yyerror.
2861 This remains here temporarily to ease the
2862 transition to the new meaning of YYERROR, for GCC.
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002863 Once GCC version 2 has supplanted version 1, this can go. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002864#define YYFAIL goto yyerrlab
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002865#define YYRECOVERING() (!!yyerrstatus)
Dale Johannesen3afee192007-09-07 21:07:57 +00002866#define YYBACKUP(token, value) \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002867do \
2868 if (yychar == YYEMPTY && yylen == 1) \
Dale Johannesen3afee192007-09-07 21:07:57 +00002869 { yychar = (token), yylval = (value); \
2870 yychar1 = YYTRANSLATE (yychar); \
David Greene48556392007-09-04 18:46:50 +00002871 YYPOPSTACK; \
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002872 goto yybackup; \
2873 } \
2874 else \
Dale Johannesen3afee192007-09-07 21:07:57 +00002875 { yyerror ("syntax error: cannot back up"); YYERROR; } \
David Greene48556392007-09-04 18:46:50 +00002876while (0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002877
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002878#define YYTERROR 1
2879#define YYERRCODE 256
2880
Dale Johannesen3afee192007-09-07 21:07:57 +00002881#ifndef YYPURE
2882#define YYLEX yylex()
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002883#endif
2884
Dale Johannesen3afee192007-09-07 21:07:57 +00002885#ifdef YYPURE
2886#ifdef YYLSP_NEEDED
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002887#ifdef YYLEX_PARAM
Dale Johannesen3afee192007-09-07 21:07:57 +00002888#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002889#else
Dale Johannesen3afee192007-09-07 21:07:57 +00002890#define YYLEX yylex(&yylval, &yylloc)
2891#endif
2892#else /* not YYLSP_NEEDED */
2893#ifdef YYLEX_PARAM
2894#define YYLEX yylex(&yylval, YYLEX_PARAM)
2895#else
2896#define YYLEX yylex(&yylval)
2897#endif
2898#endif /* not YYLSP_NEEDED */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002899#endif
2900
Dale Johannesen3afee192007-09-07 21:07:57 +00002901/* If nonreentrant, generate the variables here */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002902
Dale Johannesen3afee192007-09-07 21:07:57 +00002903#ifndef YYPURE
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002904
Dale Johannesen3afee192007-09-07 21:07:57 +00002905int yychar; /* the lookahead symbol */
2906YYSTYPE yylval; /* the semantic value of the */
2907 /* lookahead symbol */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002908
Dale Johannesen3afee192007-09-07 21:07:57 +00002909#ifdef YYLSP_NEEDED
2910YYLTYPE yylloc; /* location data for the lookahead */
2911 /* symbol */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002912#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002913
Dale Johannesen3afee192007-09-07 21:07:57 +00002914int yynerrs; /* number of parse errors so far */
2915#endif /* not YYPURE */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002916
Dale Johannesen3afee192007-09-07 21:07:57 +00002917#if YYDEBUG != 0
2918int yydebug; /* nonzero means print parse trace */
2919/* Since this is uninitialized, it does not stop multiple parsers
2920 from coexisting. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002921#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002922
Dale Johannesen3afee192007-09-07 21:07:57 +00002923/* YYINITDEPTH indicates the initial size of the parser's stacks */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002924
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002925#ifndef YYINITDEPTH
Dale Johannesen3afee192007-09-07 21:07:57 +00002926#define YYINITDEPTH 200
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002927#endif
2928
Dale Johannesen3afee192007-09-07 21:07:57 +00002929/* YYMAXDEPTH is the maximum size the stacks can grow to
2930 (effective only if the built-in stack extension method is used). */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002931
Dale Johannesen3afee192007-09-07 21:07:57 +00002932#if YYMAXDEPTH == 0
2933#undef YYMAXDEPTH
David Greene48556392007-09-04 18:46:50 +00002934#endif
2935
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002936#ifndef YYMAXDEPTH
Dale Johannesen3afee192007-09-07 21:07:57 +00002937#define YYMAXDEPTH 10000
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002938#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002939
Dale Johannesen3afee192007-09-07 21:07:57 +00002940/* Define __yy_memcpy. Note that the size argument
2941 should be passed with type unsigned int, because that is what the non-GCC
2942 definitions require. With GCC, __builtin_memcpy takes an arg
2943 of type size_t, but it can handle unsigned int. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002944
Dale Johannesen3afee192007-09-07 21:07:57 +00002945#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
2946#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
2947#else /* not GNU C or C++ */
2948#ifndef __cplusplus
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002949
Dale Johannesen3afee192007-09-07 21:07:57 +00002950/* This is the most reliable way to avoid incompatibilities
2951 in available built-in functions on various systems. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002952static void
Dale Johannesen3afee192007-09-07 21:07:57 +00002953__yy_memcpy (to, from, count)
2954 char *to;
2955 char *from;
2956 unsigned int count;
2957{
2958 register char *f = from;
2959 register char *t = to;
2960 register int i = count;
2961
2962 while (i-- > 0)
2963 *t++ = *f++;
2964}
2965
2966#else /* __cplusplus */
2967
2968/* This is the most reliable way to avoid incompatibilities
2969 in available built-in functions on various systems. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002970static void
Dale Johannesen3afee192007-09-07 21:07:57 +00002971__yy_memcpy (char *to, char *from, unsigned int count)
2972{
2973 register char *t = to;
2974 register char *f = from;
2975 register int i = count;
2976
2977 while (i-- > 0)
2978 *t++ = *f++;
2979}
2980
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002981#endif
David Greene48556392007-09-04 18:46:50 +00002982#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002983
Dale Johannesen3afee192007-09-07 21:07:57 +00002984#line 217 "/usr/share/bison.simple"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002985
Dale Johannesen3afee192007-09-07 21:07:57 +00002986/* The user can define YYPARSE_PARAM as the name of an argument to be passed
2987 into yyparse. The argument should have type void *.
2988 It should actually point to an object.
2989 Grammar actions can access the variable by casting it
2990 to the proper pointer type. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00002991
2992#ifdef YYPARSE_PARAM
Dale Johannesen3afee192007-09-07 21:07:57 +00002993#ifdef __cplusplus
2994#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
2995#define YYPARSE_PARAM_DECL
2996#else /* not __cplusplus */
2997#define YYPARSE_PARAM_ARG YYPARSE_PARAM
2998#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
2999#endif /* not __cplusplus */
3000#else /* not YYPARSE_PARAM */
3001#define YYPARSE_PARAM_ARG
3002#define YYPARSE_PARAM_DECL
3003#endif /* not YYPARSE_PARAM */
3004
3005/* Prevent warning if -Wstrict-prototypes. */
3006#ifdef __GNUC__
3007#ifdef YYPARSE_PARAM
3008int yyparse (void *);
3009#else
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003010int yyparse (void);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003011#endif
Dale Johannesen3afee192007-09-07 21:07:57 +00003012#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003013
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003014int
Dale Johannesen3afee192007-09-07 21:07:57 +00003015yyparse(YYPARSE_PARAM_ARG)
3016 YYPARSE_PARAM_DECL
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003017{
David Greene48556392007-09-04 18:46:50 +00003018 register int yystate;
3019 register int yyn;
David Greene48556392007-09-04 18:46:50 +00003020 register short *yyssp;
David Greene48556392007-09-04 18:46:50 +00003021 register YYSTYPE *yyvsp;
Dale Johannesen3afee192007-09-07 21:07:57 +00003022 int yyerrstatus; /* number of tokens to shift before error messages enabled */
3023 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003024
Dale Johannesen3afee192007-09-07 21:07:57 +00003025 short yyssa[YYINITDEPTH]; /* the state stack */
3026 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003027
Dale Johannesen3afee192007-09-07 21:07:57 +00003028 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
3029 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003030
Dale Johannesen3afee192007-09-07 21:07:57 +00003031#ifdef YYLSP_NEEDED
3032 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
3033 YYLTYPE *yyls = yylsa;
3034 YYLTYPE *yylsp;
3035
3036#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
3037#else
David Greene48556392007-09-04 18:46:50 +00003038#define YYPOPSTACK (yyvsp--, yyssp--)
Dale Johannesen3afee192007-09-07 21:07:57 +00003039#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003040
Dale Johannesen3afee192007-09-07 21:07:57 +00003041 int yystacksize = YYINITDEPTH;
3042 int yyfree_stacks = 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003043
Dale Johannesen3afee192007-09-07 21:07:57 +00003044#ifdef YYPURE
3045 int yychar;
3046 YYSTYPE yylval;
3047 int yynerrs;
3048#ifdef YYLSP_NEEDED
3049 YYLTYPE yylloc;
3050#endif
3051#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003052
Dale Johannesen3afee192007-09-07 21:07:57 +00003053 YYSTYPE yyval; /* the variable used to return */
3054 /* semantic values from the action */
3055 /* routines */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003056
David Greene48556392007-09-04 18:46:50 +00003057 int yylen;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003058
Dale Johannesen3afee192007-09-07 21:07:57 +00003059#if YYDEBUG != 0
3060 if (yydebug)
3061 fprintf(stderr, "Starting parse\n");
3062#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003063
3064 yystate = 0;
3065 yyerrstatus = 0;
3066 yynerrs = 0;
3067 yychar = YYEMPTY; /* Cause a token to be read. */
3068
3069 /* Initialize stack pointers.
3070 Waste one element of value and location stack
3071 so that they stay on the same level as the state stack.
3072 The wasted elements are never initialized. */
3073
Dale Johannesen3afee192007-09-07 21:07:57 +00003074 yyssp = yyss - 1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003075 yyvsp = yyvs;
Dale Johannesen3afee192007-09-07 21:07:57 +00003076#ifdef YYLSP_NEEDED
3077 yylsp = yyls;
3078#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003079
Dale Johannesen3afee192007-09-07 21:07:57 +00003080/* Push a new state, which is found in yystate . */
3081/* In all cases, when you get here, the value and location stacks
3082 have just been pushed. so pushing a state here evens the stacks. */
3083yynewstate:
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003084
Dale Johannesen3afee192007-09-07 21:07:57 +00003085 *++yyssp = yystate;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003086
Dale Johannesen3afee192007-09-07 21:07:57 +00003087 if (yyssp >= yyss + yystacksize - 1)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003088 {
Dale Johannesen3afee192007-09-07 21:07:57 +00003089 /* Give user a chance to reallocate the stack */
3090 /* Use copies of these so that the &'s don't force the real ones into memory. */
3091 YYSTYPE *yyvs1 = yyvs;
3092 short *yyss1 = yyss;
3093#ifdef YYLSP_NEEDED
3094 YYLTYPE *yyls1 = yyls;
3095#endif
3096
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003097 /* Get the current used size of the three stacks, in elements. */
Dale Johannesen3afee192007-09-07 21:07:57 +00003098 int size = yyssp - yyss + 1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003099
3100#ifdef yyoverflow
Dale Johannesen3afee192007-09-07 21:07:57 +00003101 /* Each stack pointer address is followed by the size of
3102 the data in use in that stack, in bytes. */
3103#ifdef YYLSP_NEEDED
3104 /* This used to be a conditional around just the two extra args,
3105 but that might be undefined if yyoverflow is a macro. */
3106 yyoverflow("parser stack overflow",
3107 &yyss1, size * sizeof (*yyssp),
3108 &yyvs1, size * sizeof (*yyvsp),
3109 &yyls1, size * sizeof (*yylsp),
3110 &yystacksize);
3111#else
3112 yyoverflow("parser stack overflow",
3113 &yyss1, size * sizeof (*yyssp),
3114 &yyvs1, size * sizeof (*yyvsp),
3115 &yystacksize);
3116#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003117
Dale Johannesen3afee192007-09-07 21:07:57 +00003118 yyss = yyss1; yyvs = yyvs1;
3119#ifdef YYLSP_NEEDED
3120 yyls = yyls1;
3121#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003122#else /* no yyoverflow */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003123 /* Extend the stack our own way. */
Dale Johannesen3afee192007-09-07 21:07:57 +00003124 if (yystacksize >= YYMAXDEPTH)
3125 {
3126 yyerror("parser stack overflow");
3127 if (yyfree_stacks)
3128 {
3129 free (yyss);
3130 free (yyvs);
3131#ifdef YYLSP_NEEDED
3132 free (yyls);
3133#endif
3134 }
3135 return 2;
3136 }
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003137 yystacksize *= 2;
Dale Johannesen3afee192007-09-07 21:07:57 +00003138 if (yystacksize > YYMAXDEPTH)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003139 yystacksize = YYMAXDEPTH;
Dale Johannesen3afee192007-09-07 21:07:57 +00003140#ifndef YYSTACK_USE_ALLOCA
3141 yyfree_stacks = 1;
3142#endif
3143 yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
3144 __yy_memcpy ((char *)yyss, (char *)yyss1,
3145 size * (unsigned int) sizeof (*yyssp));
3146 yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
3147 __yy_memcpy ((char *)yyvs, (char *)yyvs1,
3148 size * (unsigned int) sizeof (*yyvsp));
3149#ifdef YYLSP_NEEDED
3150 yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
3151 __yy_memcpy ((char *)yyls, (char *)yyls1,
3152 size * (unsigned int) sizeof (*yylsp));
3153#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003154#endif /* no yyoverflow */
3155
Dale Johannesen3afee192007-09-07 21:07:57 +00003156 yyssp = yyss + size - 1;
3157 yyvsp = yyvs + size - 1;
3158#ifdef YYLSP_NEEDED
3159 yylsp = yyls + size - 1;
3160#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003161
Dale Johannesen3afee192007-09-07 21:07:57 +00003162#if YYDEBUG != 0
3163 if (yydebug)
3164 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
3165#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003166
Dale Johannesen3afee192007-09-07 21:07:57 +00003167 if (yyssp >= yyss + yystacksize - 1)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003168 YYABORT;
3169 }
3170
Dale Johannesen3afee192007-09-07 21:07:57 +00003171#if YYDEBUG != 0
3172 if (yydebug)
3173 fprintf(stderr, "Entering state %d\n", yystate);
3174#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003175
3176 goto yybackup;
Dale Johannesen3afee192007-09-07 21:07:57 +00003177 yybackup:
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003178
David Greene48556392007-09-04 18:46:50 +00003179/* Do appropriate processing given the current state. */
3180/* Read a lookahead token if we need one and don't already have one. */
3181/* yyresume: */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003182
David Greene48556392007-09-04 18:46:50 +00003183 /* First try to decide what to do without reference to lookahead token. */
3184
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003185 yyn = yypact[yystate];
Dale Johannesen3afee192007-09-07 21:07:57 +00003186 if (yyn == YYFLAG)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003187 goto yydefault;
3188
David Greene48556392007-09-04 18:46:50 +00003189 /* Not known => get a lookahead token if don't already have one. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003190
Dale Johannesen3afee192007-09-07 21:07:57 +00003191 /* yychar is either YYEMPTY or YYEOF
3192 or a valid token in external form. */
3193
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003194 if (yychar == YYEMPTY)
3195 {
Dale Johannesen3afee192007-09-07 21:07:57 +00003196#if YYDEBUG != 0
3197 if (yydebug)
3198 fprintf(stderr, "Reading a token: ");
3199#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003200 yychar = YYLEX;
3201 }
3202
Dale Johannesen3afee192007-09-07 21:07:57 +00003203 /* Convert token to internal form (in yychar1) for indexing tables with */
3204
3205 if (yychar <= 0) /* This means end of input. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003206 {
Dale Johannesen3afee192007-09-07 21:07:57 +00003207 yychar1 = 0;
3208 yychar = YYEOF; /* Don't call YYLEX any more */
3209
3210#if YYDEBUG != 0
3211 if (yydebug)
3212 fprintf(stderr, "Now at end of input.\n");
3213#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003214 }
3215 else
3216 {
Dale Johannesen3afee192007-09-07 21:07:57 +00003217 yychar1 = YYTRANSLATE(yychar);
3218
3219#if YYDEBUG != 0
3220 if (yydebug)
3221 {
3222 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
3223 /* Give the individual parser a way to print the precise meaning
3224 of a token, for further debugging info. */
3225#ifdef YYPRINT
3226 YYPRINT (stderr, yychar, yylval);
3227#endif
3228 fprintf (stderr, ")\n");
3229 }
3230#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003231 }
3232
Dale Johannesen3afee192007-09-07 21:07:57 +00003233 yyn += yychar1;
3234 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003235 goto yydefault;
Dale Johannesen3afee192007-09-07 21:07:57 +00003236
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003237 yyn = yytable[yyn];
Dale Johannesen3afee192007-09-07 21:07:57 +00003238
3239 /* yyn is what to do for this token type in this state.
3240 Negative => reduce, -yyn is rule number.
3241 Positive => shift, yyn is new state.
3242 New state is final state => don't bother to shift,
3243 just return success.
3244 0, or most negative number => error. */
3245
3246 if (yyn < 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003247 {
Dale Johannesen3afee192007-09-07 21:07:57 +00003248 if (yyn == YYFLAG)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003249 goto yyerrlab;
3250 yyn = -yyn;
3251 goto yyreduce;
3252 }
Dale Johannesen3afee192007-09-07 21:07:57 +00003253 else if (yyn == 0)
3254 goto yyerrlab;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003255
3256 if (yyn == YYFINAL)
3257 YYACCEPT;
3258
David Greene48556392007-09-04 18:46:50 +00003259 /* Shift the lookahead token. */
Dale Johannesen3afee192007-09-07 21:07:57 +00003260
3261#if YYDEBUG != 0
3262 if (yydebug)
3263 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
3264#endif
David Greene48556392007-09-04 18:46:50 +00003265
3266 /* Discard the token being shifted unless it is eof. */
3267 if (yychar != YYEOF)
3268 yychar = YYEMPTY;
3269
3270 *++yyvsp = yylval;
Dale Johannesen3afee192007-09-07 21:07:57 +00003271#ifdef YYLSP_NEEDED
3272 *++yylsp = yylloc;
3273#endif
David Greene48556392007-09-04 18:46:50 +00003274
Dale Johannesen3afee192007-09-07 21:07:57 +00003275 /* count tokens shifted since error; after three, turn off error status. */
3276 if (yyerrstatus) yyerrstatus--;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003277
3278 yystate = yyn;
3279 goto yynewstate;
3280
Dale Johannesen3afee192007-09-07 21:07:57 +00003281/* Do the default action for the current state. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003282yydefault:
Dale Johannesen3afee192007-09-07 21:07:57 +00003283
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003284 yyn = yydefact[yystate];
3285 if (yyn == 0)
3286 goto yyerrlab;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003287
Dale Johannesen3afee192007-09-07 21:07:57 +00003288/* Do a reduction. yyn is the number of a rule to reduce with. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003289yyreduce:
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003290 yylen = yyr2[yyn];
Dale Johannesen3afee192007-09-07 21:07:57 +00003291 if (yylen > 0)
3292 yyval = yyvsp[1-yylen]; /* implement default value of the action */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003293
Dale Johannesen3afee192007-09-07 21:07:57 +00003294#if YYDEBUG != 0
3295 if (yydebug)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003296 {
Dale Johannesen3afee192007-09-07 21:07:57 +00003297 int i;
3298
3299 fprintf (stderr, "Reducing via rule %d (line %d), ",
3300 yyn, yyrline[yyn]);
3301
3302 /* Print the symbols being reduced, and their result. */
3303 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
3304 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
3305 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
3306 }
3307#endif
3308
3309
3310 switch (yyn) {
3311
3312case 2:
3313#line 1895 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3314{
David Greene48556392007-09-04 18:46:50 +00003315 if (yyvsp[0].UIntVal > (uint32_t)INT32_MAX) // Outside of my range!
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003316 error("Value too large for type");
David Greene48556392007-09-04 18:46:50 +00003317 yyval.SIntVal = (int32_t)yyvsp[0].UIntVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00003318 ;
3319 break;}
3320case 4:
3321#line 1904 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3322{
David Greene48556392007-09-04 18:46:50 +00003323 if (yyvsp[0].UInt64Val > (uint64_t)INT64_MAX) // Outside of my range!
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003324 error("Value too large for type");
David Greene48556392007-09-04 18:46:50 +00003325 yyval.SInt64Val = (int64_t)yyvsp[0].UInt64Val;
Dale Johannesen3afee192007-09-07 21:07:57 +00003326 ;
3327 break;}
3328case 25:
3329#line 1926 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3330{ yyval.IPred = ICmpInst::ICMP_EQ; ;
3331 break;}
3332case 26:
3333#line 1926 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3334{ yyval.IPred = ICmpInst::ICMP_NE; ;
3335 break;}
3336case 27:
3337#line 1927 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3338{ yyval.IPred = ICmpInst::ICMP_SLT; ;
3339 break;}
3340case 28:
3341#line 1927 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3342{ yyval.IPred = ICmpInst::ICMP_SGT; ;
3343 break;}
3344case 29:
3345#line 1928 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3346{ yyval.IPred = ICmpInst::ICMP_SLE; ;
3347 break;}
3348case 30:
3349#line 1928 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3350{ yyval.IPred = ICmpInst::ICMP_SGE; ;
3351 break;}
3352case 31:
3353#line 1929 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3354{ yyval.IPred = ICmpInst::ICMP_ULT; ;
3355 break;}
3356case 32:
3357#line 1929 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3358{ yyval.IPred = ICmpInst::ICMP_UGT; ;
3359 break;}
3360case 33:
3361#line 1930 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3362{ yyval.IPred = ICmpInst::ICMP_ULE; ;
3363 break;}
3364case 34:
3365#line 1930 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3366{ yyval.IPred = ICmpInst::ICMP_UGE; ;
3367 break;}
3368case 35:
3369#line 1934 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3370{ yyval.FPred = FCmpInst::FCMP_OEQ; ;
3371 break;}
3372case 36:
3373#line 1934 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3374{ yyval.FPred = FCmpInst::FCMP_ONE; ;
3375 break;}
3376case 37:
3377#line 1935 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3378{ yyval.FPred = FCmpInst::FCMP_OLT; ;
3379 break;}
3380case 38:
3381#line 1935 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3382{ yyval.FPred = FCmpInst::FCMP_OGT; ;
3383 break;}
3384case 39:
3385#line 1936 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3386{ yyval.FPred = FCmpInst::FCMP_OLE; ;
3387 break;}
3388case 40:
3389#line 1936 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3390{ yyval.FPred = FCmpInst::FCMP_OGE; ;
3391 break;}
3392case 41:
3393#line 1937 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3394{ yyval.FPred = FCmpInst::FCMP_ORD; ;
3395 break;}
3396case 42:
3397#line 1937 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3398{ yyval.FPred = FCmpInst::FCMP_UNO; ;
3399 break;}
3400case 43:
3401#line 1938 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3402{ yyval.FPred = FCmpInst::FCMP_UEQ; ;
3403 break;}
3404case 44:
3405#line 1938 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3406{ yyval.FPred = FCmpInst::FCMP_UNE; ;
3407 break;}
3408case 45:
3409#line 1939 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3410{ yyval.FPred = FCmpInst::FCMP_ULT; ;
3411 break;}
3412case 46:
3413#line 1939 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3414{ yyval.FPred = FCmpInst::FCMP_UGT; ;
3415 break;}
3416case 47:
3417#line 1940 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3418{ yyval.FPred = FCmpInst::FCMP_ULE; ;
3419 break;}
3420case 48:
3421#line 1940 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3422{ yyval.FPred = FCmpInst::FCMP_UGE; ;
3423 break;}
3424case 49:
3425#line 1941 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3426{ yyval.FPred = FCmpInst::FCMP_TRUE; ;
3427 break;}
3428case 50:
3429#line 1942 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3430{ yyval.FPred = FCmpInst::FCMP_FALSE; ;
3431 break;}
3432case 80:
3433#line 1973 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3434{
David Greene48556392007-09-04 18:46:50 +00003435 yyval.StrVal = yyvsp[-1].StrVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00003436 ;
3437 break;}
3438case 81:
3439#line 1976 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3440{
David Greene48556392007-09-04 18:46:50 +00003441 yyval.StrVal = 0;
Dale Johannesen3afee192007-09-07 21:07:57 +00003442 ;
3443 break;}
3444case 82:
3445#line 1981 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3446{ yyval.Linkage = GlobalValue::InternalLinkage; ;
3447 break;}
3448case 83:
3449#line 1982 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3450{ yyval.Linkage = GlobalValue::LinkOnceLinkage; ;
3451 break;}
3452case 84:
3453#line 1983 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3454{ yyval.Linkage = GlobalValue::WeakLinkage; ;
3455 break;}
3456case 85:
3457#line 1984 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3458{ yyval.Linkage = GlobalValue::AppendingLinkage; ;
3459 break;}
3460case 86:
3461#line 1985 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3462{ yyval.Linkage = GlobalValue::DLLImportLinkage; ;
3463 break;}
3464case 87:
3465#line 1986 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3466{ yyval.Linkage = GlobalValue::DLLExportLinkage; ;
3467 break;}
3468case 88:
3469#line 1987 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3470{ yyval.Linkage = GlobalValue::ExternalWeakLinkage; ;
3471 break;}
3472case 89:
3473#line 1988 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3474{ yyval.Linkage = GlobalValue::ExternalLinkage; ;
3475 break;}
3476case 90:
3477#line 1992 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3478{ yyval.UIntVal = lastCallingConv = OldCallingConv::C; ;
3479 break;}
3480case 91:
3481#line 1993 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3482{ yyval.UIntVal = lastCallingConv = OldCallingConv::C; ;
3483 break;}
3484case 92:
3485#line 1994 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3486{ yyval.UIntVal = lastCallingConv = OldCallingConv::CSRet; ;
3487 break;}
3488case 93:
3489#line 1995 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3490{ yyval.UIntVal = lastCallingConv = OldCallingConv::Fast; ;
3491 break;}
3492case 94:
3493#line 1996 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3494{ yyval.UIntVal = lastCallingConv = OldCallingConv::Cold; ;
3495 break;}
3496case 95:
3497#line 1997 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3498{ yyval.UIntVal = lastCallingConv = OldCallingConv::X86_StdCall; ;
3499 break;}
3500case 96:
3501#line 1998 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3502{ yyval.UIntVal = lastCallingConv = OldCallingConv::X86_FastCall; ;
3503 break;}
3504case 97:
3505#line 1999 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3506{
David Greene48556392007-09-04 18:46:50 +00003507 if ((unsigned)yyvsp[0].UInt64Val != yyvsp[0].UInt64Val)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003508 error("Calling conv too large");
David Greene48556392007-09-04 18:46:50 +00003509 yyval.UIntVal = lastCallingConv = yyvsp[0].UInt64Val;
Dale Johannesen3afee192007-09-07 21:07:57 +00003510 ;
3511 break;}
3512case 98:
3513#line 2009 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3514{ yyval.UIntVal = 0; ;
3515 break;}
3516case 99:
3517#line 2010 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3518{
David Greene48556392007-09-04 18:46:50 +00003519 yyval.UIntVal = yyvsp[0].UInt64Val;
3520 if (yyval.UIntVal != 0 && !isPowerOf2_32(yyval.UIntVal))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003521 error("Alignment must be a power of two");
Dale Johannesen3afee192007-09-07 21:07:57 +00003522 ;
3523 break;}
3524case 100:
3525#line 2018 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3526{ yyval.UIntVal = 0; ;
3527 break;}
3528case 101:
3529#line 2019 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3530{
David Greene48556392007-09-04 18:46:50 +00003531 yyval.UIntVal = yyvsp[0].UInt64Val;
3532 if (yyval.UIntVal != 0 && !isPowerOf2_32(yyval.UIntVal))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003533 error("Alignment must be a power of two");
Dale Johannesen3afee192007-09-07 21:07:57 +00003534 ;
3535 break;}
3536case 102:
3537#line 2027 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3538{
David Greene48556392007-09-04 18:46:50 +00003539 for (unsigned i = 0, e = strlen(yyvsp[0].StrVal); i != e; ++i)
3540 if (yyvsp[0].StrVal[i] == '"' || yyvsp[0].StrVal[i] == '\\')
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003541 error("Invalid character in section name");
David Greene48556392007-09-04 18:46:50 +00003542 yyval.StrVal = yyvsp[0].StrVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00003543 ;
3544 break;}
3545case 103:
3546#line 2036 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3547{ yyval.StrVal = 0; ;
3548 break;}
3549case 104:
3550#line 2037 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3551{ yyval.StrVal = yyvsp[0].StrVal; ;
3552 break;}
3553case 105:
3554#line 2044 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3555{;
3556 break;}
3557case 106:
3558#line 2045 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3559{;
3560 break;}
3561case 107:
3562#line 2049 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3563{
David Greene48556392007-09-04 18:46:50 +00003564 CurGV->setSection(yyvsp[0].StrVal);
3565 free(yyvsp[0].StrVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00003566 ;
3567 break;}
3568case 108:
3569#line 2053 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3570{
David Greene48556392007-09-04 18:46:50 +00003571 if (yyvsp[0].UInt64Val != 0 && !isPowerOf2_32(yyvsp[0].UInt64Val))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003572 error("Alignment must be a power of two");
David Greene48556392007-09-04 18:46:50 +00003573 CurGV->setAlignment(yyvsp[0].UInt64Val);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003574
Dale Johannesen3afee192007-09-07 21:07:57 +00003575 ;
3576 break;}
3577case 110:
3578#line 2070 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3579{
David Greene48556392007-09-04 18:46:50 +00003580 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
3581 yyval.TypeVal.S.makeSignless();
Dale Johannesen3afee192007-09-07 21:07:57 +00003582 ;
3583 break;}
3584case 112:
3585#line 2078 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3586{
David Greene48556392007-09-04 18:46:50 +00003587 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
3588 yyval.TypeVal.S.makeSignless();
Dale Johannesen3afee192007-09-07 21:07:57 +00003589 ;
3590 break;}
3591case 113:
3592#line 2085 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3593{
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003594 if (!UpRefs.empty())
David Greene48556392007-09-04 18:46:50 +00003595 error("Invalid upreference in type: " + (*yyvsp[0].TypeVal.PAT)->getDescription());
3596 yyval.TypeVal = yyvsp[0].TypeVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00003597 ;
3598 break;}
3599case 126:
3600#line 2099 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3601{
David Greene48556392007-09-04 18:46:50 +00003602 yyval.TypeVal.PAT = new PATypeHolder(yyvsp[0].PrimType.T);
3603 yyval.TypeVal.S.copy(yyvsp[0].PrimType.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00003604 ;
3605 break;}
3606case 127:
3607#line 2103 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3608{
David Greene48556392007-09-04 18:46:50 +00003609 yyval.TypeVal.PAT = new PATypeHolder(OpaqueType::get());
3610 yyval.TypeVal.S.makeSignless();
Dale Johannesen3afee192007-09-07 21:07:57 +00003611 ;
3612 break;}
3613case 128:
3614#line 2107 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3615{ // Named types are also simple types...
David Greene48556392007-09-04 18:46:50 +00003616 yyval.TypeVal.S.copy(getTypeSign(yyvsp[0].ValIDVal));
3617 const Type* tmp = getType(yyvsp[0].ValIDVal);
3618 yyval.TypeVal.PAT = new PATypeHolder(tmp);
Dale Johannesen3afee192007-09-07 21:07:57 +00003619 ;
3620 break;}
3621case 129:
3622#line 2112 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3623{ // Type UpReference
David Greene48556392007-09-04 18:46:50 +00003624 if (yyvsp[0].UInt64Val > (uint64_t)~0U)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003625 error("Value out of range");
3626 OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder
David Greene48556392007-09-04 18:46:50 +00003627 UpRefs.push_back(UpRefRecord((unsigned)yyvsp[0].UInt64Val, OT)); // Add to vector...
3628 yyval.TypeVal.PAT = new PATypeHolder(OT);
3629 yyval.TypeVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003630 UR_OUT("New Upreference!\n");
Dale Johannesen3afee192007-09-07 21:07:57 +00003631 ;
3632 break;}
3633case 130:
3634#line 2121 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3635{ // Function derived type?
David Greene48556392007-09-04 18:46:50 +00003636 yyval.TypeVal.S.makeComposite(yyvsp[-3].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003637 std::vector<const Type*> Params;
David Greene48556392007-09-04 18:46:50 +00003638 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-1].TypeList->begin(),
3639 E = yyvsp[-1].TypeList->end(); I != E; ++I) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003640 Params.push_back(I->PAT->get());
David Greene48556392007-09-04 18:46:50 +00003641 yyval.TypeVal.S.add(I->S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003642 }
3643 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
3644 if (isVarArg) Params.pop_back();
3645
3646 ParamAttrsList *PAL = 0;
3647 if (lastCallingConv == OldCallingConv::CSRet) {
3648 ParamAttrsVector Attrs;
3649 ParamAttrsWithIndex PAWI;
3650 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
3651 Attrs.push_back(PAWI);
3652 PAL = ParamAttrsList::get(Attrs);
3653 }
3654
3655 const FunctionType *FTy =
David Greene48556392007-09-04 18:46:50 +00003656 FunctionType::get(yyvsp[-3].TypeVal.PAT->get(), Params, isVarArg, PAL);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003657
David Greene48556392007-09-04 18:46:50 +00003658 yyval.TypeVal.PAT = new PATypeHolder( HandleUpRefs(FTy, yyval.TypeVal.S) );
3659 delete yyvsp[-3].TypeVal.PAT; // Delete the return type handle
3660 delete yyvsp[-1].TypeList; // Delete the argument list
Dale Johannesen3afee192007-09-07 21:07:57 +00003661 ;
3662 break;}
3663case 131:
3664#line 2148 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3665{ // Sized array type?
David Greene48556392007-09-04 18:46:50 +00003666 yyval.TypeVal.S.makeComposite(yyvsp[-1].TypeVal.S);
3667 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(ArrayType::get(yyvsp[-1].TypeVal.PAT->get(),
3668 (unsigned)yyvsp[-3].UInt64Val), yyval.TypeVal.S));
3669 delete yyvsp[-1].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00003670 ;
3671 break;}
3672case 132:
3673#line 2154 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3674{ // Vector type?
David Greene48556392007-09-04 18:46:50 +00003675 const llvm::Type* ElemTy = yyvsp[-1].TypeVal.PAT->get();
3676 if ((unsigned)yyvsp[-3].UInt64Val != yyvsp[-3].UInt64Val)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003677 error("Unsigned result not equal to signed result");
3678 if (!(ElemTy->isInteger() || ElemTy->isFloatingPoint()))
3679 error("Elements of a VectorType must be integer or floating point");
David Greene48556392007-09-04 18:46:50 +00003680 if (!isPowerOf2_32(yyvsp[-3].UInt64Val))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003681 error("VectorType length should be a power of 2");
David Greene48556392007-09-04 18:46:50 +00003682 yyval.TypeVal.S.makeComposite(yyvsp[-1].TypeVal.S);
3683 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(VectorType::get(ElemTy,
3684 (unsigned)yyvsp[-3].UInt64Val), yyval.TypeVal.S));
3685 delete yyvsp[-1].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00003686 ;
3687 break;}
3688case 133:
3689#line 2167 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3690{ // Structure type?
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003691 std::vector<const Type*> Elements;
David Greene48556392007-09-04 18:46:50 +00003692 yyval.TypeVal.S.makeComposite();
3693 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-1].TypeList->begin(),
3694 E = yyvsp[-1].TypeList->end(); I != E; ++I) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003695 Elements.push_back(I->PAT->get());
David Greene48556392007-09-04 18:46:50 +00003696 yyval.TypeVal.S.add(I->S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003697 }
David Greene48556392007-09-04 18:46:50 +00003698 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements), yyval.TypeVal.S));
3699 delete yyvsp[-1].TypeList;
Dale Johannesen3afee192007-09-07 21:07:57 +00003700 ;
3701 break;}
3702case 134:
3703#line 2178 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3704{ // Empty structure type?
David Greene48556392007-09-04 18:46:50 +00003705 yyval.TypeVal.PAT = new PATypeHolder(StructType::get(std::vector<const Type*>()));
3706 yyval.TypeVal.S.makeComposite();
Dale Johannesen3afee192007-09-07 21:07:57 +00003707 ;
3708 break;}
3709case 135:
3710#line 2182 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3711{ // Packed Structure type?
David Greene48556392007-09-04 18:46:50 +00003712 yyval.TypeVal.S.makeComposite();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003713 std::vector<const Type*> Elements;
David Greene48556392007-09-04 18:46:50 +00003714 for (std::list<llvm::PATypeInfo>::iterator I = yyvsp[-2].TypeList->begin(),
3715 E = yyvsp[-2].TypeList->end(); I != E; ++I) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003716 Elements.push_back(I->PAT->get());
David Greene48556392007-09-04 18:46:50 +00003717 yyval.TypeVal.S.add(I->S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003718 delete I->PAT;
3719 }
David Greene48556392007-09-04 18:46:50 +00003720 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(StructType::get(Elements, true),
3721 yyval.TypeVal.S));
3722 delete yyvsp[-2].TypeList;
Dale Johannesen3afee192007-09-07 21:07:57 +00003723 ;
3724 break;}
3725case 136:
3726#line 2195 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3727{ // Empty packed structure type?
David Greene48556392007-09-04 18:46:50 +00003728 yyval.TypeVal.PAT = new PATypeHolder(StructType::get(std::vector<const Type*>(),true));
3729 yyval.TypeVal.S.makeComposite();
Dale Johannesen3afee192007-09-07 21:07:57 +00003730 ;
3731 break;}
3732case 137:
3733#line 2199 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3734{ // Pointer type?
David Greene48556392007-09-04 18:46:50 +00003735 if (yyvsp[-1].TypeVal.PAT->get() == Type::LabelTy)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003736 error("Cannot form a pointer to a basic block");
David Greene48556392007-09-04 18:46:50 +00003737 yyval.TypeVal.S.makeComposite(yyvsp[-1].TypeVal.S);
3738 yyval.TypeVal.PAT = new PATypeHolder(HandleUpRefs(PointerType::get(yyvsp[-1].TypeVal.PAT->get()),
3739 yyval.TypeVal.S));
3740 delete yyvsp[-1].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00003741 ;
3742 break;}
3743case 138:
3744#line 2213 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3745{
David Greene48556392007-09-04 18:46:50 +00003746 yyval.TypeList = new std::list<PATypeInfo>();
3747 yyval.TypeList->push_back(yyvsp[0].TypeVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00003748 ;
3749 break;}
3750case 139:
3751#line 2217 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3752{
David Greene48556392007-09-04 18:46:50 +00003753 (yyval.TypeList=yyvsp[-2].TypeList)->push_back(yyvsp[0].TypeVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00003754 ;
3755 break;}
3756case 141:
3757#line 2225 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3758{
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003759 PATypeInfo VoidTI;
3760 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
3761 VoidTI.S.makeSignless();
David Greene48556392007-09-04 18:46:50 +00003762 (yyval.TypeList=yyvsp[-2].TypeList)->push_back(VoidTI);
Dale Johannesen3afee192007-09-07 21:07:57 +00003763 ;
3764 break;}
3765case 142:
3766#line 2231 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3767{
David Greene48556392007-09-04 18:46:50 +00003768 yyval.TypeList = new std::list<PATypeInfo>();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003769 PATypeInfo VoidTI;
3770 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
3771 VoidTI.S.makeSignless();
David Greene48556392007-09-04 18:46:50 +00003772 yyval.TypeList->push_back(VoidTI);
Dale Johannesen3afee192007-09-07 21:07:57 +00003773 ;
3774 break;}
3775case 143:
3776#line 2238 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3777{
David Greene48556392007-09-04 18:46:50 +00003778 yyval.TypeList = new std::list<PATypeInfo>();
Dale Johannesen3afee192007-09-07 21:07:57 +00003779 ;
3780 break;}
3781case 144:
3782#line 2250 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3783{ // Nonempty unsized arr
David Greene48556392007-09-04 18:46:50 +00003784 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-3].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003785 if (ATy == 0)
3786 error("Cannot make array constant with type: '" +
David Greene48556392007-09-04 18:46:50 +00003787 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003788 const Type *ETy = ATy->getElementType();
3789 int NumElements = ATy->getNumElements();
3790
3791 // Verify that we have the correct size...
David Greene48556392007-09-04 18:46:50 +00003792 if (NumElements != -1 && NumElements != (int)yyvsp[-1].ConstVector->size())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003793 error("Type mismatch: constant sized array initialized with " +
David Greene48556392007-09-04 18:46:50 +00003794 utostr(yyvsp[-1].ConstVector->size()) + " arguments, but has size of " +
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003795 itostr(NumElements) + "");
3796
3797 // Verify all elements are correct type!
3798 std::vector<Constant*> Elems;
David Greene48556392007-09-04 18:46:50 +00003799 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
3800 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003801 const Type* ValTy = C->getType();
3802 if (ETy != ValTy)
3803 error("Element #" + utostr(i) + " is not of type '" +
3804 ETy->getDescription() +"' as required!\nIt is of type '"+
3805 ValTy->getDescription() + "'");
3806 Elems.push_back(C);
3807 }
David Greene48556392007-09-04 18:46:50 +00003808 yyval.ConstVal.C = ConstantArray::get(ATy, Elems);
3809 yyval.ConstVal.S.copy(yyvsp[-3].TypeVal.S);
3810 delete yyvsp[-3].TypeVal.PAT;
3811 delete yyvsp[-1].ConstVector;
Dale Johannesen3afee192007-09-07 21:07:57 +00003812 ;
3813 break;}
3814case 145:
3815#line 2280 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3816{
David Greene48556392007-09-04 18:46:50 +00003817 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-2].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003818 if (ATy == 0)
3819 error("Cannot make array constant with type: '" +
David Greene48556392007-09-04 18:46:50 +00003820 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003821 int NumElements = ATy->getNumElements();
3822 if (NumElements != -1 && NumElements != 0)
3823 error("Type mismatch: constant sized array initialized with 0"
3824 " arguments, but has size of " + itostr(NumElements) +"");
David Greene48556392007-09-04 18:46:50 +00003825 yyval.ConstVal.C = ConstantArray::get(ATy, std::vector<Constant*>());
3826 yyval.ConstVal.S.copy(yyvsp[-2].TypeVal.S);
3827 delete yyvsp[-2].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00003828 ;
3829 break;}
3830case 146:
3831#line 2293 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3832{
David Greene48556392007-09-04 18:46:50 +00003833 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-2].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003834 if (ATy == 0)
3835 error("Cannot make array constant with type: '" +
David Greene48556392007-09-04 18:46:50 +00003836 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003837 int NumElements = ATy->getNumElements();
3838 const Type *ETy = dyn_cast<IntegerType>(ATy->getElementType());
3839 if (!ETy || cast<IntegerType>(ETy)->getBitWidth() != 8)
3840 error("String arrays require type i8, not '" + ETy->getDescription() +
3841 "'");
David Greene48556392007-09-04 18:46:50 +00003842 char *EndStr = UnEscapeLexed(yyvsp[0].StrVal, true);
3843 if (NumElements != -1 && NumElements != (EndStr-yyvsp[0].StrVal))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003844 error("Can't build string constant of size " +
David Greene48556392007-09-04 18:46:50 +00003845 itostr((int)(EndStr-yyvsp[0].StrVal)) + " when array has size " +
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003846 itostr(NumElements) + "");
3847 std::vector<Constant*> Vals;
David Greene48556392007-09-04 18:46:50 +00003848 for (char *C = (char *)yyvsp[0].StrVal; C != (char *)EndStr; ++C)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003849 Vals.push_back(ConstantInt::get(ETy, *C));
David Greene48556392007-09-04 18:46:50 +00003850 free(yyvsp[0].StrVal);
3851 yyval.ConstVal.C = ConstantArray::get(ATy, Vals);
3852 yyval.ConstVal.S.copy(yyvsp[-2].TypeVal.S);
3853 delete yyvsp[-2].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00003854 ;
3855 break;}
3856case 147:
3857#line 2316 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3858{ // Nonempty unsized arr
David Greene48556392007-09-04 18:46:50 +00003859 const VectorType *PTy = dyn_cast<VectorType>(yyvsp[-3].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003860 if (PTy == 0)
3861 error("Cannot make packed constant with type: '" +
David Greene48556392007-09-04 18:46:50 +00003862 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003863 const Type *ETy = PTy->getElementType();
3864 int NumElements = PTy->getNumElements();
3865 // Verify that we have the correct size...
David Greene48556392007-09-04 18:46:50 +00003866 if (NumElements != -1 && NumElements != (int)yyvsp[-1].ConstVector->size())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003867 error("Type mismatch: constant sized packed initialized with " +
David Greene48556392007-09-04 18:46:50 +00003868 utostr(yyvsp[-1].ConstVector->size()) + " arguments, but has size of " +
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003869 itostr(NumElements) + "");
3870 // Verify all elements are correct type!
3871 std::vector<Constant*> Elems;
David Greene48556392007-09-04 18:46:50 +00003872 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
3873 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003874 const Type* ValTy = C->getType();
3875 if (ETy != ValTy)
3876 error("Element #" + utostr(i) + " is not of type '" +
3877 ETy->getDescription() +"' as required!\nIt is of type '"+
3878 ValTy->getDescription() + "'");
3879 Elems.push_back(C);
3880 }
David Greene48556392007-09-04 18:46:50 +00003881 yyval.ConstVal.C = ConstantVector::get(PTy, Elems);
3882 yyval.ConstVal.S.copy(yyvsp[-3].TypeVal.S);
3883 delete yyvsp[-3].TypeVal.PAT;
3884 delete yyvsp[-1].ConstVector;
Dale Johannesen3afee192007-09-07 21:07:57 +00003885 ;
3886 break;}
3887case 148:
3888#line 2344 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3889{
David Greene48556392007-09-04 18:46:50 +00003890 const StructType *STy = dyn_cast<StructType>(yyvsp[-3].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003891 if (STy == 0)
3892 error("Cannot make struct constant with type: '" +
David Greene48556392007-09-04 18:46:50 +00003893 yyvsp[-3].TypeVal.PAT->get()->getDescription() + "'");
3894 if (yyvsp[-1].ConstVector->size() != STy->getNumContainedTypes())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003895 error("Illegal number of initializers for structure type");
3896
3897 // Check to ensure that constants are compatible with the type initializer!
3898 std::vector<Constant*> Fields;
David Greene48556392007-09-04 18:46:50 +00003899 for (unsigned i = 0, e = yyvsp[-1].ConstVector->size(); i != e; ++i) {
3900 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003901 if (C->getType() != STy->getElementType(i))
3902 error("Expected type '" + STy->getElementType(i)->getDescription() +
3903 "' for element #" + utostr(i) + " of structure initializer");
3904 Fields.push_back(C);
3905 }
David Greene48556392007-09-04 18:46:50 +00003906 yyval.ConstVal.C = ConstantStruct::get(STy, Fields);
3907 yyval.ConstVal.S.copy(yyvsp[-3].TypeVal.S);
3908 delete yyvsp[-3].TypeVal.PAT;
3909 delete yyvsp[-1].ConstVector;
Dale Johannesen3afee192007-09-07 21:07:57 +00003910 ;
3911 break;}
3912case 149:
3913#line 2366 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3914{
David Greene48556392007-09-04 18:46:50 +00003915 const StructType *STy = dyn_cast<StructType>(yyvsp[-2].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003916 if (STy == 0)
3917 error("Cannot make struct constant with type: '" +
David Greene48556392007-09-04 18:46:50 +00003918 yyvsp[-2].TypeVal.PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003919 if (STy->getNumContainedTypes() != 0)
3920 error("Illegal number of initializers for structure type");
David Greene48556392007-09-04 18:46:50 +00003921 yyval.ConstVal.C = ConstantStruct::get(STy, std::vector<Constant*>());
3922 yyval.ConstVal.S.copy(yyvsp[-2].TypeVal.S);
3923 delete yyvsp[-2].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00003924 ;
3925 break;}
3926case 150:
3927#line 2377 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3928{
David Greene48556392007-09-04 18:46:50 +00003929 const StructType *STy = dyn_cast<StructType>(yyvsp[-5].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003930 if (STy == 0)
3931 error("Cannot make packed struct constant with type: '" +
David Greene48556392007-09-04 18:46:50 +00003932 yyvsp[-5].TypeVal.PAT->get()->getDescription() + "'");
3933 if (yyvsp[-2].ConstVector->size() != STy->getNumContainedTypes())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003934 error("Illegal number of initializers for packed structure type");
3935
3936 // Check to ensure that constants are compatible with the type initializer!
3937 std::vector<Constant*> Fields;
David Greene48556392007-09-04 18:46:50 +00003938 for (unsigned i = 0, e = yyvsp[-2].ConstVector->size(); i != e; ++i) {
3939 Constant *C = (*yyvsp[-2].ConstVector)[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003940 if (C->getType() != STy->getElementType(i))
3941 error("Expected type '" + STy->getElementType(i)->getDescription() +
3942 "' for element #" + utostr(i) + " of packed struct initializer");
3943 Fields.push_back(C);
3944 }
David Greene48556392007-09-04 18:46:50 +00003945 yyval.ConstVal.C = ConstantStruct::get(STy, Fields);
3946 yyval.ConstVal.S.copy(yyvsp[-5].TypeVal.S);
3947 delete yyvsp[-5].TypeVal.PAT;
3948 delete yyvsp[-2].ConstVector;
Dale Johannesen3afee192007-09-07 21:07:57 +00003949 ;
3950 break;}
3951case 151:
3952#line 2399 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3953{
David Greene48556392007-09-04 18:46:50 +00003954 const StructType *STy = dyn_cast<StructType>(yyvsp[-4].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003955 if (STy == 0)
3956 error("Cannot make packed struct constant with type: '" +
David Greene48556392007-09-04 18:46:50 +00003957 yyvsp[-4].TypeVal.PAT->get()->getDescription() + "'");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003958 if (STy->getNumContainedTypes() != 0)
3959 error("Illegal number of initializers for packed structure type");
David Greene48556392007-09-04 18:46:50 +00003960 yyval.ConstVal.C = ConstantStruct::get(STy, std::vector<Constant*>());
3961 yyval.ConstVal.S.copy(yyvsp[-4].TypeVal.S);
3962 delete yyvsp[-4].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00003963 ;
3964 break;}
3965case 152:
3966#line 2410 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3967{
David Greene48556392007-09-04 18:46:50 +00003968 const PointerType *PTy = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003969 if (PTy == 0)
3970 error("Cannot make null pointer constant with type: '" +
David Greene48556392007-09-04 18:46:50 +00003971 yyvsp[-1].TypeVal.PAT->get()->getDescription() + "'");
3972 yyval.ConstVal.C = ConstantPointerNull::get(PTy);
3973 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
3974 delete yyvsp[-1].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00003975 ;
3976 break;}
3977case 153:
3978#line 2419 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3979{
David Greene48556392007-09-04 18:46:50 +00003980 yyval.ConstVal.C = UndefValue::get(yyvsp[-1].TypeVal.PAT->get());
3981 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
3982 delete yyvsp[-1].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00003983 ;
3984 break;}
3985case 154:
3986#line 2424 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
3987{
David Greene48556392007-09-04 18:46:50 +00003988 const PointerType *Ty = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003989 if (Ty == 0)
3990 error("Global const reference must be a pointer type, not" +
David Greene48556392007-09-04 18:46:50 +00003991 yyvsp[-1].TypeVal.PAT->get()->getDescription());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00003992
3993 // ConstExprs can exist in the body of a function, thus creating
3994 // GlobalValues whenever they refer to a variable. Because we are in
3995 // the context of a function, getExistingValue will search the functions
3996 // symbol table instead of the module symbol table for the global symbol,
3997 // which throws things all off. To get around this, we just tell
3998 // getExistingValue that we are at global scope here.
3999 //
4000 Function *SavedCurFn = CurFun.CurrentFunction;
4001 CurFun.CurrentFunction = 0;
David Greene48556392007-09-04 18:46:50 +00004002 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
4003 Value *V = getExistingValue(Ty, yyvsp[0].ValIDVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004004 CurFun.CurrentFunction = SavedCurFn;
4005
4006 // If this is an initializer for a constant pointer, which is referencing a
4007 // (currently) undefined variable, create a stub now that shall be replaced
4008 // in the future with the right type of variable.
4009 //
4010 if (V == 0) {
4011 assert(isa<PointerType>(Ty) && "Globals may only be used as pointers");
4012 const PointerType *PT = cast<PointerType>(Ty);
4013
4014 // First check to see if the forward references value is already created!
4015 PerModuleInfo::GlobalRefsType::iterator I =
David Greene48556392007-09-04 18:46:50 +00004016 CurModule.GlobalRefs.find(std::make_pair(PT, yyvsp[0].ValIDVal));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004017
4018 if (I != CurModule.GlobalRefs.end()) {
4019 V = I->second; // Placeholder already exists, use it...
David Greene48556392007-09-04 18:46:50 +00004020 yyvsp[0].ValIDVal.destroy();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004021 } else {
4022 std::string Name;
David Greene48556392007-09-04 18:46:50 +00004023 if (yyvsp[0].ValIDVal.Type == ValID::NameVal) Name = yyvsp[0].ValIDVal.Name;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004024
4025 // Create the forward referenced global.
4026 GlobalValue *GV;
4027 if (const FunctionType *FTy =
4028 dyn_cast<FunctionType>(PT->getElementType())) {
4029 GV = new Function(FTy, GlobalValue::ExternalLinkage, Name,
4030 CurModule.CurrentModule);
4031 } else {
4032 GV = new GlobalVariable(PT->getElementType(), false,
4033 GlobalValue::ExternalLinkage, 0,
4034 Name, CurModule.CurrentModule);
4035 }
4036
4037 // Keep track of the fact that we have a forward ref to recycle it
David Greene48556392007-09-04 18:46:50 +00004038 CurModule.GlobalRefs.insert(std::make_pair(std::make_pair(PT, yyvsp[0].ValIDVal), GV));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004039 V = GV;
4040 }
4041 }
David Greene48556392007-09-04 18:46:50 +00004042 yyval.ConstVal.C = cast<GlobalValue>(V);
4043 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4044 delete yyvsp[-1].TypeVal.PAT; // Free the type handle
Dale Johannesen3afee192007-09-07 21:07:57 +00004045 ;
4046 break;}
4047case 155:
4048#line 2483 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4049{
David Greene48556392007-09-04 18:46:50 +00004050 if (yyvsp[-1].TypeVal.PAT->get() != yyvsp[0].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004051 error("Mismatched types for constant expression");
David Greene48556392007-09-04 18:46:50 +00004052 yyval.ConstVal = yyvsp[0].ConstVal;
4053 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4054 delete yyvsp[-1].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00004055 ;
4056 break;}
4057case 156:
4058#line 2490 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4059{
David Greene48556392007-09-04 18:46:50 +00004060 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004061 if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
4062 error("Cannot create a null initialized value of this type");
David Greene48556392007-09-04 18:46:50 +00004063 yyval.ConstVal.C = Constant::getNullValue(Ty);
4064 yyval.ConstVal.S.copy(yyvsp[-1].TypeVal.S);
4065 delete yyvsp[-1].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00004066 ;
4067 break;}
4068case 157:
4069#line 2498 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4070{ // integral constants
David Greene48556392007-09-04 18:46:50 +00004071 const Type *Ty = yyvsp[-1].PrimType.T;
4072 if (!ConstantInt::isValueValidForType(Ty, yyvsp[0].SInt64Val))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004073 error("Constant value doesn't fit in type");
David Greene48556392007-09-04 18:46:50 +00004074 yyval.ConstVal.C = ConstantInt::get(Ty, yyvsp[0].SInt64Val);
4075 yyval.ConstVal.S.makeSigned();
Dale Johannesen3afee192007-09-07 21:07:57 +00004076 ;
4077 break;}
4078case 158:
4079#line 2505 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4080{ // integral constants
David Greene48556392007-09-04 18:46:50 +00004081 const Type *Ty = yyvsp[-1].PrimType.T;
4082 if (!ConstantInt::isValueValidForType(Ty, yyvsp[0].UInt64Val))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004083 error("Constant value doesn't fit in type");
David Greene48556392007-09-04 18:46:50 +00004084 yyval.ConstVal.C = ConstantInt::get(Ty, yyvsp[0].UInt64Val);
4085 yyval.ConstVal.S.makeUnsigned();
Dale Johannesen3afee192007-09-07 21:07:57 +00004086 ;
4087 break;}
4088case 159:
4089#line 2512 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4090{ // Boolean constants
David Greene48556392007-09-04 18:46:50 +00004091 yyval.ConstVal.C = ConstantInt::get(Type::Int1Ty, true);
4092 yyval.ConstVal.S.makeUnsigned();
Dale Johannesen3afee192007-09-07 21:07:57 +00004093 ;
4094 break;}
4095case 160:
4096#line 2516 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4097{ // Boolean constants
David Greene48556392007-09-04 18:46:50 +00004098 yyval.ConstVal.C = ConstantInt::get(Type::Int1Ty, false);
4099 yyval.ConstVal.S.makeUnsigned();
Dale Johannesen3afee192007-09-07 21:07:57 +00004100 ;
4101 break;}
4102case 161:
4103#line 2520 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4104{ // Float & Double constants
4105 if (!ConstantFP::isValueValidForType(yyvsp[-1].PrimType.T, *yyvsp[0].FPVal))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004106 error("Floating point constant invalid for type");
Dale Johannesen3afee192007-09-07 21:07:57 +00004107 // Lexer has no type info, so builds all FP constants as double.
4108 // Fix this here.
4109 if (yyvsp[-1].PrimType.T==Type::FloatTy)
4110 yyvsp[0].FPVal->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
4111 yyval.ConstVal.C = ConstantFP::get(yyvsp[-1].PrimType.T, *yyvsp[0].FPVal);
4112 delete yyvsp[0].FPVal;
David Greene48556392007-09-04 18:46:50 +00004113 yyval.ConstVal.S.makeSignless();
Dale Johannesen3afee192007-09-07 21:07:57 +00004114 ;
4115 break;}
4116case 162:
4117#line 2534 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4118{
David Greene48556392007-09-04 18:46:50 +00004119 const Type* SrcTy = yyvsp[-3].ConstVal.C->getType();
4120 const Type* DstTy = yyvsp[-1].TypeVal.PAT->get();
4121 Signedness SrcSign(yyvsp[-3].ConstVal.S);
4122 Signedness DstSign(yyvsp[-1].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004123 if (!SrcTy->isFirstClassType())
4124 error("cast constant expression from a non-primitive type: '" +
4125 SrcTy->getDescription() + "'");
4126 if (!DstTy->isFirstClassType())
4127 error("cast constant expression to a non-primitive type: '" +
4128 DstTy->getDescription() + "'");
David Greene48556392007-09-04 18:46:50 +00004129 yyval.ConstVal.C = cast<Constant>(getCast(yyvsp[-5].CastOpVal, yyvsp[-3].ConstVal.C, SrcSign, DstTy, DstSign));
4130 yyval.ConstVal.S.copy(DstSign);
4131 delete yyvsp[-1].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00004132 ;
4133 break;}
4134case 163:
4135#line 2549 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4136{
David Greene48556392007-09-04 18:46:50 +00004137 const Type *Ty = yyvsp[-2].ConstVal.C->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004138 if (!isa<PointerType>(Ty))
4139 error("GetElementPtr requires a pointer operand");
4140
4141 std::vector<Constant*> CIndices;
David Greene48556392007-09-04 18:46:50 +00004142 upgradeGEPCEIndices(yyvsp[-2].ConstVal.C->getType(), yyvsp[-1].ValueList, CIndices);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004143
David Greene48556392007-09-04 18:46:50 +00004144 delete yyvsp[-1].ValueList;
4145 yyval.ConstVal.C = ConstantExpr::getGetElementPtr(yyvsp[-2].ConstVal.C, &CIndices[0], CIndices.size());
4146 yyval.ConstVal.S.copy(getElementSign(yyvsp[-2].ConstVal, CIndices));
Dale Johannesen3afee192007-09-07 21:07:57 +00004147 ;
4148 break;}
4149case 164:
4150#line 2561 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4151{
David Greene48556392007-09-04 18:46:50 +00004152 if (!yyvsp[-5].ConstVal.C->getType()->isInteger() ||
4153 cast<IntegerType>(yyvsp[-5].ConstVal.C->getType())->getBitWidth() != 1)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004154 error("Select condition must be bool type");
David Greene48556392007-09-04 18:46:50 +00004155 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004156 error("Select operand types must match");
David Greene48556392007-09-04 18:46:50 +00004157 yyval.ConstVal.C = ConstantExpr::getSelect(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4158 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00004159 ;
4160 break;}
4161case 165:
4162#line 2570 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4163{
David Greene48556392007-09-04 18:46:50 +00004164 const Type *Ty = yyvsp[-3].ConstVal.C->getType();
4165 if (Ty != yyvsp[-1].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004166 error("Binary operator types must match");
4167 // First, make sure we're dealing with the right opcode by upgrading from
4168 // obsolete versions.
David Greene48556392007-09-04 18:46:50 +00004169 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004170
4171 // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs.
4172 // To retain backward compatibility with these early compilers, we emit a
4173 // cast to the appropriate integer type automatically if we are in the
4174 // broken case. See PR424 for more information.
4175 if (!isa<PointerType>(Ty)) {
David Greene48556392007-09-04 18:46:50 +00004176 yyval.ConstVal.C = ConstantExpr::get(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004177 } else {
4178 const Type *IntPtrTy = 0;
4179 switch (CurModule.CurrentModule->getPointerSize()) {
4180 case Module::Pointer32: IntPtrTy = Type::Int32Ty; break;
4181 case Module::Pointer64: IntPtrTy = Type::Int64Ty; break;
4182 default: error("invalid pointer binary constant expr");
4183 }
David Greene48556392007-09-04 18:46:50 +00004184 yyval.ConstVal.C = ConstantExpr::get(Opcode,
4185 ConstantExpr::getCast(Instruction::PtrToInt, yyvsp[-3].ConstVal.C, IntPtrTy),
4186 ConstantExpr::getCast(Instruction::PtrToInt, yyvsp[-1].ConstVal.C, IntPtrTy));
4187 yyval.ConstVal.C = ConstantExpr::getCast(Instruction::IntToPtr, yyval.ConstVal.C, Ty);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004188 }
David Greene48556392007-09-04 18:46:50 +00004189 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00004190 ;
4191 break;}
4192case 166:
4193#line 2598 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4194{
David Greene48556392007-09-04 18:46:50 +00004195 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
4196 if (Ty != yyvsp[-1].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004197 error("Logical operator types must match");
4198 if (!Ty->isInteger()) {
4199 if (!isa<VectorType>(Ty) ||
4200 !cast<VectorType>(Ty)->getElementType()->isInteger())
4201 error("Logical operator requires integer operands");
4202 }
David Greene48556392007-09-04 18:46:50 +00004203 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S);
4204 yyval.ConstVal.C = ConstantExpr::get(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4205 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00004206 ;
4207 break;}
4208case 167:
4209#line 2611 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4210{
David Greene48556392007-09-04 18:46:50 +00004211 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
4212 if (Ty != yyvsp[-1].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004213 error("setcc operand types must match");
4214 unsigned short pred;
David Greene48556392007-09-04 18:46:50 +00004215 Instruction::OtherOps Opcode = getCompareOp(yyvsp[-5].BinaryOpVal, pred, Ty, yyvsp[-3].ConstVal.S);
4216 yyval.ConstVal.C = ConstantExpr::getCompare(Opcode, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4217 yyval.ConstVal.S.makeUnsigned();
Dale Johannesen3afee192007-09-07 21:07:57 +00004218 ;
4219 break;}
4220case 168:
4221#line 2620 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4222{
David Greene48556392007-09-04 18:46:50 +00004223 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004224 error("icmp operand types must match");
David Greene48556392007-09-04 18:46:50 +00004225 yyval.ConstVal.C = ConstantExpr::getCompare(yyvsp[-5].IPred, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4226 yyval.ConstVal.S.makeUnsigned();
Dale Johannesen3afee192007-09-07 21:07:57 +00004227 ;
4228 break;}
4229case 169:
4230#line 2626 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4231{
David Greene48556392007-09-04 18:46:50 +00004232 if (yyvsp[-3].ConstVal.C->getType() != yyvsp[-1].ConstVal.C->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004233 error("fcmp operand types must match");
David Greene48556392007-09-04 18:46:50 +00004234 yyval.ConstVal.C = ConstantExpr::getCompare(yyvsp[-5].FPred, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4235 yyval.ConstVal.S.makeUnsigned();
Dale Johannesen3afee192007-09-07 21:07:57 +00004236 ;
4237 break;}
4238case 170:
4239#line 2632 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4240{
David Greene48556392007-09-04 18:46:50 +00004241 if (!yyvsp[-1].ConstVal.C->getType()->isInteger() ||
4242 cast<IntegerType>(yyvsp[-1].ConstVal.C->getType())->getBitWidth() != 8)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004243 error("Shift count for shift constant must be unsigned byte");
David Greene48556392007-09-04 18:46:50 +00004244 const Type* Ty = yyvsp[-3].ConstVal.C->getType();
4245 if (!yyvsp[-3].ConstVal.C->getType()->isInteger())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004246 error("Shift constant expression requires integer operand");
David Greene48556392007-09-04 18:46:50 +00004247 Constant *ShiftAmt = ConstantExpr::getZExt(yyvsp[-1].ConstVal.C, Ty);
4248 yyval.ConstVal.C = ConstantExpr::get(getBinaryOp(yyvsp[-5].BinaryOpVal, Ty, yyvsp[-3].ConstVal.S), yyvsp[-3].ConstVal.C, ShiftAmt);
4249 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00004250 ;
4251 break;}
4252case 171:
4253#line 2643 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4254{
David Greene48556392007-09-04 18:46:50 +00004255 if (!ExtractElementInst::isValidOperands(yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004256 error("Invalid extractelement operands");
David Greene48556392007-09-04 18:46:50 +00004257 yyval.ConstVal.C = ConstantExpr::getExtractElement(yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4258 yyval.ConstVal.S.copy(yyvsp[-3].ConstVal.S.get(0));
Dale Johannesen3afee192007-09-07 21:07:57 +00004259 ;
4260 break;}
4261case 172:
4262#line 2649 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4263{
David Greene48556392007-09-04 18:46:50 +00004264 if (!InsertElementInst::isValidOperands(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004265 error("Invalid insertelement operands");
David Greene48556392007-09-04 18:46:50 +00004266 yyval.ConstVal.C = ConstantExpr::getInsertElement(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4267 yyval.ConstVal.S.copy(yyvsp[-5].ConstVal.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00004268 ;
4269 break;}
4270case 173:
4271#line 2655 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4272{
David Greene48556392007-09-04 18:46:50 +00004273 if (!ShuffleVectorInst::isValidOperands(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004274 error("Invalid shufflevector operands");
David Greene48556392007-09-04 18:46:50 +00004275 yyval.ConstVal.C = ConstantExpr::getShuffleVector(yyvsp[-5].ConstVal.C, yyvsp[-3].ConstVal.C, yyvsp[-1].ConstVal.C);
4276 yyval.ConstVal.S.copy(yyvsp[-5].ConstVal.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00004277 ;
4278 break;}
4279case 174:
4280#line 2666 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4281{ (yyval.ConstVector = yyvsp[-2].ConstVector)->push_back(yyvsp[0].ConstVal); ;
4282 break;}
4283case 175:
4284#line 2667 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4285{
David Greene48556392007-09-04 18:46:50 +00004286 yyval.ConstVector = new std::vector<ConstInfo>();
4287 yyval.ConstVector->push_back(yyvsp[0].ConstVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00004288 ;
4289 break;}
4290case 176:
4291#line 2676 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4292{ yyval.BoolVal = false; ;
4293 break;}
4294case 177:
4295#line 2677 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4296{ yyval.BoolVal = true; ;
4297 break;}
4298case 178:
4299#line 2689 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4300{
David Greene48556392007-09-04 18:46:50 +00004301 yyval.ModuleVal = ParserResult = yyvsp[0].ModuleVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004302 CurModule.ModuleDone();
Dale Johannesen3afee192007-09-07 21:07:57 +00004303 ;
4304 break;}
4305case 179:
4306#line 2698 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4307{ yyval.ModuleVal = yyvsp[-1].ModuleVal; CurFun.FunctionDone(); ;
4308 break;}
4309case 180:
4310#line 2699 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4311{ yyval.ModuleVal = yyvsp[-1].ModuleVal; ;
4312 break;}
4313case 181:
4314#line 2700 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4315{ yyval.ModuleVal = yyvsp[-3].ModuleVal; ;
4316 break;}
4317case 182:
4318#line 2701 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4319{ yyval.ModuleVal = yyvsp[-1].ModuleVal; ;
4320 break;}
4321case 183:
4322#line 2702 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4323{
David Greene48556392007-09-04 18:46:50 +00004324 yyval.ModuleVal = CurModule.CurrentModule;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004325 // Emit an error if there are any unresolved types left.
4326 if (!CurModule.LateResolveTypes.empty()) {
4327 const ValID &DID = CurModule.LateResolveTypes.begin()->first;
4328 if (DID.Type == ValID::NameVal) {
4329 error("Reference to an undefined type: '"+DID.getName() + "'");
4330 } else {
4331 error("Reference to an undefined type: #" + itostr(DID.Num));
4332 }
4333 }
Dale Johannesen3afee192007-09-07 21:07:57 +00004334 ;
4335 break;}
4336case 184:
4337#line 2718 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4338{
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004339 // Eagerly resolve types. This is not an optimization, this is a
4340 // requirement that is due to the fact that we could have this:
4341 //
4342 // %list = type { %list * }
4343 // %list = type { %list * } ; repeated type decl
4344 //
4345 // If types are not resolved eagerly, then the two types will not be
4346 // determined to be the same type!
4347 //
David Greene48556392007-09-04 18:46:50 +00004348 ResolveTypeTo(yyvsp[-2].StrVal, yyvsp[0].TypeVal.PAT->get(), yyvsp[0].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004349
David Greene48556392007-09-04 18:46:50 +00004350 if (!setTypeName(yyvsp[0].TypeVal, yyvsp[-2].StrVal) && !yyvsp[-2].StrVal) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004351 // If this is a numbered type that is not a redefinition, add it to the
4352 // slot table.
David Greene48556392007-09-04 18:46:50 +00004353 CurModule.Types.push_back(yyvsp[0].TypeVal.PAT->get());
4354 CurModule.TypeSigns.push_back(yyvsp[0].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004355 }
David Greene48556392007-09-04 18:46:50 +00004356 delete yyvsp[0].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00004357 ;
4358 break;}
4359case 185:
4360#line 2738 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4361{ // Function prototypes can be in const pool
4362 ;
4363 break;}
4364case 186:
4365#line 2740 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4366{ // Asm blocks can be in the const pool
4367 ;
4368 break;}
4369case 187:
4370#line 2742 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4371{
David Greene48556392007-09-04 18:46:50 +00004372 if (yyvsp[0].ConstVal.C == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004373 error("Global value initializer is not a constant");
David Greene48556392007-09-04 18:46:50 +00004374 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, yyvsp[-2].Linkage, yyvsp[-1].BoolVal, yyvsp[0].ConstVal.C->getType(), yyvsp[0].ConstVal.C, yyvsp[0].ConstVal.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00004375 ;
4376 break;}
4377case 188:
4378#line 2746 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4379{
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004380 CurGV = 0;
Dale Johannesen3afee192007-09-07 21:07:57 +00004381 ;
4382 break;}
4383case 189:
4384#line 2749 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4385{
David Greene48556392007-09-04 18:46:50 +00004386 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
4387 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::ExternalLinkage, yyvsp[-1].BoolVal, Ty, 0,
4388 yyvsp[0].TypeVal.S);
4389 delete yyvsp[0].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00004390 ;
4391 break;}
4392case 190:
4393#line 2754 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4394{
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004395 CurGV = 0;
Dale Johannesen3afee192007-09-07 21:07:57 +00004396 ;
4397 break;}
4398case 191:
4399#line 2757 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4400{
David Greene48556392007-09-04 18:46:50 +00004401 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
4402 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::DLLImportLinkage, yyvsp[-1].BoolVal, Ty, 0,
4403 yyvsp[0].TypeVal.S);
4404 delete yyvsp[0].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00004405 ;
4406 break;}
4407case 192:
4408#line 2762 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4409{
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004410 CurGV = 0;
Dale Johannesen3afee192007-09-07 21:07:57 +00004411 ;
4412 break;}
4413case 193:
4414#line 2765 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4415{
David Greene48556392007-09-04 18:46:50 +00004416 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004417 CurGV =
David Greene48556392007-09-04 18:46:50 +00004418 ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::ExternalWeakLinkage, yyvsp[-1].BoolVal, Ty, 0,
4419 yyvsp[0].TypeVal.S);
4420 delete yyvsp[0].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00004421 ;
4422 break;}
4423case 194:
4424#line 2771 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4425{
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004426 CurGV = 0;
Dale Johannesen3afee192007-09-07 21:07:57 +00004427 ;
4428 break;}
4429case 195:
4430#line 2774 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4431{
4432 ;
4433 break;}
4434case 196:
4435#line 2776 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4436{
4437 ;
4438 break;}
4439case 197:
4440#line 2778 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4441{
4442 ;
4443 break;}
4444case 198:
4445#line 2783 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4446{
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004447 const std::string &AsmSoFar = CurModule.CurrentModule->getModuleInlineAsm();
David Greene48556392007-09-04 18:46:50 +00004448 char *EndStr = UnEscapeLexed(yyvsp[0].StrVal, true);
4449 std::string NewAsm(yyvsp[0].StrVal, EndStr);
4450 free(yyvsp[0].StrVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004451
4452 if (AsmSoFar.empty())
4453 CurModule.CurrentModule->setModuleInlineAsm(NewAsm);
4454 else
4455 CurModule.CurrentModule->setModuleInlineAsm(AsmSoFar+"\n"+NewAsm);
Dale Johannesen3afee192007-09-07 21:07:57 +00004456 ;
4457 break;}
4458case 199:
4459#line 2797 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4460{ yyval.Endianness = Module::BigEndian; ;
4461 break;}
4462case 200:
4463#line 2798 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4464{ yyval.Endianness = Module::LittleEndian; ;
4465 break;}
4466case 201:
4467#line 2802 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4468{
David Greene48556392007-09-04 18:46:50 +00004469 CurModule.setEndianness(yyvsp[0].Endianness);
Dale Johannesen3afee192007-09-07 21:07:57 +00004470 ;
4471 break;}
4472case 202:
4473#line 2805 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4474{
David Greene48556392007-09-04 18:46:50 +00004475 if (yyvsp[0].UInt64Val == 32)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004476 CurModule.setPointerSize(Module::Pointer32);
David Greene48556392007-09-04 18:46:50 +00004477 else if (yyvsp[0].UInt64Val == 64)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004478 CurModule.setPointerSize(Module::Pointer64);
4479 else
David Greene48556392007-09-04 18:46:50 +00004480 error("Invalid pointer size: '" + utostr(yyvsp[0].UInt64Val) + "'");
Dale Johannesen3afee192007-09-07 21:07:57 +00004481 ;
4482 break;}
4483case 203:
4484#line 2813 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4485{
David Greene48556392007-09-04 18:46:50 +00004486 CurModule.CurrentModule->setTargetTriple(yyvsp[0].StrVal);
4487 free(yyvsp[0].StrVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00004488 ;
4489 break;}
4490case 204:
4491#line 2817 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4492{
David Greene48556392007-09-04 18:46:50 +00004493 CurModule.CurrentModule->setDataLayout(yyvsp[0].StrVal);
4494 free(yyvsp[0].StrVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00004495 ;
4496 break;}
4497case 206:
4498#line 2828 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4499{
David Greene48556392007-09-04 18:46:50 +00004500 CurModule.CurrentModule->addLibrary(yyvsp[0].StrVal);
4501 free(yyvsp[0].StrVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00004502 ;
4503 break;}
4504case 207:
4505#line 2832 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4506{
David Greene48556392007-09-04 18:46:50 +00004507 CurModule.CurrentModule->addLibrary(yyvsp[0].StrVal);
4508 free(yyvsp[0].StrVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00004509 ;
4510 break;}
4511case 208:
4512#line 2836 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4513{ ;
4514 break;}
4515case 212:
4516#line 2849 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4517{ yyval.StrVal = 0; ;
4518 break;}
4519case 213:
4520#line 2853 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4521{
David Greene48556392007-09-04 18:46:50 +00004522 if (yyvsp[-1].TypeVal.PAT->get() == Type::VoidTy)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004523 error("void typed arguments are invalid");
David Greene48556392007-09-04 18:46:50 +00004524 yyval.ArgVal = new std::pair<PATypeInfo, char*>(yyvsp[-1].TypeVal, yyvsp[0].StrVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00004525 ;
4526 break;}
4527case 214:
4528#line 2861 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4529{
David Greene48556392007-09-04 18:46:50 +00004530 yyval.ArgList = yyvsp[-2].ArgList;
4531 yyval.ArgList->push_back(*yyvsp[0].ArgVal);
4532 delete yyvsp[0].ArgVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00004533 ;
4534 break;}
4535case 215:
4536#line 2866 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4537{
David Greene48556392007-09-04 18:46:50 +00004538 yyval.ArgList = new std::vector<std::pair<PATypeInfo,char*> >();
4539 yyval.ArgList->push_back(*yyvsp[0].ArgVal);
4540 delete yyvsp[0].ArgVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00004541 ;
4542 break;}
4543case 216:
4544#line 2874 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4545{ yyval.ArgList = yyvsp[0].ArgList; ;
4546 break;}
4547case 217:
4548#line 2875 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4549{
David Greene48556392007-09-04 18:46:50 +00004550 yyval.ArgList = yyvsp[-2].ArgList;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004551 PATypeInfo VoidTI;
4552 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
4553 VoidTI.S.makeSignless();
David Greene48556392007-09-04 18:46:50 +00004554 yyval.ArgList->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
Dale Johannesen3afee192007-09-07 21:07:57 +00004555 ;
4556 break;}
4557case 218:
4558#line 2882 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4559{
David Greene48556392007-09-04 18:46:50 +00004560 yyval.ArgList = new std::vector<std::pair<PATypeInfo,char*> >();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004561 PATypeInfo VoidTI;
4562 VoidTI.PAT = new PATypeHolder(Type::VoidTy);
4563 VoidTI.S.makeSignless();
David Greene48556392007-09-04 18:46:50 +00004564 yyval.ArgList->push_back(std::pair<PATypeInfo, char*>(VoidTI, 0));
Dale Johannesen3afee192007-09-07 21:07:57 +00004565 ;
4566 break;}
4567case 219:
4568#line 2889 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4569{ yyval.ArgList = 0; ;
4570 break;}
4571case 220:
4572#line 2893 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4573{
David Greene48556392007-09-04 18:46:50 +00004574 UnEscapeLexed(yyvsp[-5].StrVal);
4575 std::string FunctionName(yyvsp[-5].StrVal);
4576 free(yyvsp[-5].StrVal); // Free strdup'd memory!
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004577
David Greene48556392007-09-04 18:46:50 +00004578 const Type* RetTy = yyvsp[-6].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004579
4580 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
4581 error("LLVM functions cannot return aggregate types");
4582
4583 Signedness FTySign;
David Greene48556392007-09-04 18:46:50 +00004584 FTySign.makeComposite(yyvsp[-6].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004585 std::vector<const Type*> ParamTyList;
4586
4587 // In LLVM 2.0 the signatures of three varargs intrinsics changed to take
4588 // i8*. We check here for those names and override the parameter list
4589 // types to ensure the prototype is correct.
4590 if (FunctionName == "llvm.va_start" || FunctionName == "llvm.va_end") {
4591 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
4592 } else if (FunctionName == "llvm.va_copy") {
4593 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
4594 ParamTyList.push_back(PointerType::get(Type::Int8Ty));
David Greene48556392007-09-04 18:46:50 +00004595 } else if (yyvsp[-3].ArgList) { // If there are arguments...
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004596 for (std::vector<std::pair<PATypeInfo,char*> >::iterator
David Greene48556392007-09-04 18:46:50 +00004597 I = yyvsp[-3].ArgList->begin(), E = yyvsp[-3].ArgList->end(); I != E; ++I) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004598 const Type *Ty = I->first.PAT->get();
4599 ParamTyList.push_back(Ty);
4600 FTySign.add(I->first.S);
4601 }
4602 }
4603
4604 bool isVarArg = ParamTyList.size() && ParamTyList.back() == Type::VoidTy;
4605 if (isVarArg)
4606 ParamTyList.pop_back();
4607
4608 // Convert the CSRet calling convention into the corresponding parameter
4609 // attribute.
4610 ParamAttrsList *PAL = 0;
David Greene48556392007-09-04 18:46:50 +00004611 if (yyvsp[-7].UIntVal == OldCallingConv::CSRet) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004612 ParamAttrsVector Attrs;
4613 ParamAttrsWithIndex PAWI;
4614 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
4615 Attrs.push_back(PAWI);
4616 PAL = ParamAttrsList::get(Attrs);
4617 }
4618
4619 const FunctionType *FT =
4620 FunctionType::get(RetTy, ParamTyList, isVarArg, PAL);
4621 const PointerType *PFT = PointerType::get(FT);
David Greene48556392007-09-04 18:46:50 +00004622 delete yyvsp[-6].TypeVal.PAT;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004623
4624 ValID ID;
4625 if (!FunctionName.empty()) {
4626 ID = ValID::create((char*)FunctionName.c_str());
4627 } else {
4628 ID = ValID::create((int)CurModule.Values[PFT].size());
4629 }
4630 ID.S.makeComposite(FTySign);
4631
4632 Function *Fn = 0;
4633 Module* M = CurModule.CurrentModule;
4634
4635 // See if this function was forward referenced. If so, recycle the object.
4636 if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, ID)) {
4637 // Move the function to the end of the list, from whereever it was
4638 // previously inserted.
4639 Fn = cast<Function>(FWRef);
4640 M->getFunctionList().remove(Fn);
4641 M->getFunctionList().push_back(Fn);
4642 } else if (!FunctionName.empty()) {
4643 GlobalValue *Conflict = M->getFunction(FunctionName);
4644 if (!Conflict)
4645 Conflict = M->getNamedGlobal(FunctionName);
4646 if (Conflict && PFT == Conflict->getType()) {
4647 if (!CurFun.isDeclare && !Conflict->isDeclaration()) {
4648 // We have two function definitions that conflict, same type, same
4649 // name. We should really check to make sure that this is the result
4650 // of integer type planes collapsing and generate an error if it is
4651 // not, but we'll just rename on the assumption that it is. However,
4652 // let's do it intelligently and rename the internal linkage one
4653 // if there is one.
4654 std::string NewName(makeNameUnique(FunctionName));
4655 if (Conflict->hasInternalLinkage()) {
4656 Conflict->setName(NewName);
4657 RenameMapKey Key =
4658 makeRenameMapKey(FunctionName, Conflict->getType(), ID.S);
4659 CurModule.RenameMap[Key] = NewName;
4660 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
4661 InsertValue(Fn, CurModule.Values);
4662 } else {
4663 Fn = new Function(FT, CurFun.Linkage, NewName, M);
4664 InsertValue(Fn, CurModule.Values);
4665 RenameMapKey Key =
4666 makeRenameMapKey(FunctionName, PFT, ID.S);
4667 CurModule.RenameMap[Key] = NewName;
4668 }
4669 } else {
4670 // If they are not both definitions, then just use the function we
4671 // found since the types are the same.
4672 Fn = cast<Function>(Conflict);
4673
4674 // Make sure to strip off any argument names so we can't get
4675 // conflicts.
4676 if (Fn->isDeclaration())
4677 for (Function::arg_iterator AI = Fn->arg_begin(),
4678 AE = Fn->arg_end(); AI != AE; ++AI)
4679 AI->setName("");
4680 }
4681 } else if (Conflict) {
4682 // We have two globals with the same name and different types.
4683 // Previously, this was permitted because the symbol table had
4684 // "type planes" and names only needed to be distinct within a
4685 // type plane. After PR411 was fixed, this is no loner the case.
4686 // To resolve this we must rename one of the two.
4687 if (Conflict->hasInternalLinkage()) {
4688 // We can safely rename the Conflict.
4689 RenameMapKey Key =
4690 makeRenameMapKey(Conflict->getName(), Conflict->getType(),
4691 CurModule.NamedValueSigns[Conflict->getName()]);
4692 Conflict->setName(makeNameUnique(Conflict->getName()));
4693 CurModule.RenameMap[Key] = Conflict->getName();
4694 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
4695 InsertValue(Fn, CurModule.Values);
4696 } else {
4697 // We can't quietly rename either of these things, but we must
4698 // rename one of them. Only if the function's linkage is internal can
4699 // we forgo a warning message about the renamed function.
4700 std::string NewName = makeNameUnique(FunctionName);
4701 if (CurFun.Linkage != GlobalValue::InternalLinkage) {
4702 warning("Renaming function '" + FunctionName + "' as '" + NewName +
4703 "' may cause linkage errors");
4704 }
4705 // Elect to rename the thing we're now defining.
4706 Fn = new Function(FT, CurFun.Linkage, NewName, M);
4707 InsertValue(Fn, CurModule.Values);
4708 RenameMapKey Key = makeRenameMapKey(FunctionName, PFT, ID.S);
4709 CurModule.RenameMap[Key] = NewName;
4710 }
4711 } else {
4712 // There's no conflict, just define the function
4713 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
4714 InsertValue(Fn, CurModule.Values);
4715 }
4716 } else {
4717 // There's no conflict, just define the function
4718 Fn = new Function(FT, CurFun.Linkage, FunctionName, M);
4719 InsertValue(Fn, CurModule.Values);
4720 }
4721
4722
4723 CurFun.FunctionStart(Fn);
4724
4725 if (CurFun.isDeclare) {
4726 // If we have declaration, always overwrite linkage. This will allow us
4727 // to correctly handle cases, when pointer to function is passed as
4728 // argument to another function.
4729 Fn->setLinkage(CurFun.Linkage);
4730 }
David Greene48556392007-09-04 18:46:50 +00004731 Fn->setCallingConv(upgradeCallingConv(yyvsp[-7].UIntVal));
4732 Fn->setAlignment(yyvsp[0].UIntVal);
4733 if (yyvsp[-1].StrVal) {
4734 Fn->setSection(yyvsp[-1].StrVal);
4735 free(yyvsp[-1].StrVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004736 }
4737
4738 // Add all of the arguments we parsed to the function...
David Greene48556392007-09-04 18:46:50 +00004739 if (yyvsp[-3].ArgList) { // Is null if empty...
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004740 if (isVarArg) { // Nuke the last entry
David Greene48556392007-09-04 18:46:50 +00004741 assert(yyvsp[-3].ArgList->back().first.PAT->get() == Type::VoidTy &&
4742 yyvsp[-3].ArgList->back().second == 0 && "Not a varargs marker");
4743 delete yyvsp[-3].ArgList->back().first.PAT;
4744 yyvsp[-3].ArgList->pop_back(); // Delete the last entry
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004745 }
4746 Function::arg_iterator ArgIt = Fn->arg_begin();
4747 Function::arg_iterator ArgEnd = Fn->arg_end();
David Greene48556392007-09-04 18:46:50 +00004748 std::vector<std::pair<PATypeInfo,char*> >::iterator I = yyvsp[-3].ArgList->begin();
4749 std::vector<std::pair<PATypeInfo,char*> >::iterator E = yyvsp[-3].ArgList->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004750 for ( ; I != E && ArgIt != ArgEnd; ++I, ++ArgIt) {
4751 delete I->first.PAT; // Delete the typeholder...
4752 ValueInfo VI; VI.V = ArgIt; VI.S.copy(I->first.S);
4753 setValueName(VI, I->second); // Insert arg into symtab...
4754 InsertValue(ArgIt);
4755 }
David Greene48556392007-09-04 18:46:50 +00004756 delete yyvsp[-3].ArgList; // We're now done with the argument list
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004757 }
4758 lastCallingConv = OldCallingConv::C;
Dale Johannesen3afee192007-09-07 21:07:57 +00004759 ;
4760 break;}
4761case 223:
4762#line 3087 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4763{ CurFun.Linkage = yyvsp[0].Linkage; ;
4764 break;}
4765case 224:
4766#line 3087 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4767{
David Greene48556392007-09-04 18:46:50 +00004768 yyval.FunctionVal = CurFun.CurrentFunction;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004769
4770 // Make sure that we keep track of the linkage type even if there was a
4771 // previous "declare".
David Greene48556392007-09-04 18:46:50 +00004772 yyval.FunctionVal->setLinkage(yyvsp[-3].Linkage);
Dale Johannesen3afee192007-09-07 21:07:57 +00004773 ;
4774 break;}
4775case 227:
4776#line 3101 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4777{
David Greene48556392007-09-04 18:46:50 +00004778 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00004779 ;
4780 break;}
4781case 228:
4782#line 3106 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4783{ yyval.Linkage = GlobalValue::ExternalLinkage; ;
4784 break;}
4785case 229:
4786#line 3107 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4787{ yyval.Linkage = GlobalValue::DLLImportLinkage; ;
4788 break;}
4789case 230:
4790#line 3108 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4791{ yyval.Linkage = GlobalValue::ExternalWeakLinkage; ;
4792 break;}
4793case 231:
4794#line 3112 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4795{ CurFun.isDeclare = true; ;
4796 break;}
4797case 232:
4798#line 3113 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4799{ CurFun.Linkage = yyvsp[0].Linkage; ;
4800 break;}
4801case 233:
4802#line 3113 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4803{
David Greene48556392007-09-04 18:46:50 +00004804 yyval.FunctionVal = CurFun.CurrentFunction;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004805 CurFun.FunctionDone();
4806
Dale Johannesen3afee192007-09-07 21:07:57 +00004807 ;
4808 break;}
4809case 234:
4810#line 3125 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4811{ yyval.BoolVal = false; ;
4812 break;}
4813case 235:
4814#line 3126 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4815{ yyval.BoolVal = true; ;
4816 break;}
4817case 236:
4818#line 3131 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4819{ yyval.ValIDVal = ValID::create(yyvsp[0].SInt64Val); ;
4820 break;}
4821case 237:
4822#line 3132 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4823{ yyval.ValIDVal = ValID::create(yyvsp[0].UInt64Val); ;
4824 break;}
4825case 238:
4826#line 3133 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4827{ yyval.ValIDVal = ValID::create(yyvsp[0].FPVal); ;
4828 break;}
4829case 239:
4830#line 3134 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4831{
David Greene48556392007-09-04 18:46:50 +00004832 yyval.ValIDVal = ValID::create(ConstantInt::get(Type::Int1Ty, true));
4833 yyval.ValIDVal.S.makeUnsigned();
Dale Johannesen3afee192007-09-07 21:07:57 +00004834 ;
4835 break;}
4836case 240:
4837#line 3138 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4838{
David Greene48556392007-09-04 18:46:50 +00004839 yyval.ValIDVal = ValID::create(ConstantInt::get(Type::Int1Ty, false));
4840 yyval.ValIDVal.S.makeUnsigned();
Dale Johannesen3afee192007-09-07 21:07:57 +00004841 ;
4842 break;}
4843case 241:
4844#line 3142 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4845{ yyval.ValIDVal = ValID::createNull(); ;
4846 break;}
4847case 242:
4848#line 3143 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4849{ yyval.ValIDVal = ValID::createUndef(); ;
4850 break;}
4851case 243:
4852#line 3144 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4853{ yyval.ValIDVal = ValID::createZeroInit(); ;
4854 break;}
4855case 244:
4856#line 3145 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4857{ // Nonempty unsized packed vector
David Greene48556392007-09-04 18:46:50 +00004858 const Type *ETy = (*yyvsp[-1].ConstVector)[0].C->getType();
4859 int NumElements = yyvsp[-1].ConstVector->size();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004860 VectorType* pt = VectorType::get(ETy, NumElements);
David Greene48556392007-09-04 18:46:50 +00004861 yyval.ValIDVal.S.makeComposite((*yyvsp[-1].ConstVector)[0].S);
4862 PATypeHolder* PTy = new PATypeHolder(HandleUpRefs(pt, yyval.ValIDVal.S));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004863
4864 // Verify all elements are correct type!
4865 std::vector<Constant*> Elems;
David Greene48556392007-09-04 18:46:50 +00004866 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
4867 Constant *C = (*yyvsp[-1].ConstVector)[i].C;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004868 const Type *CTy = C->getType();
4869 if (ETy != CTy)
4870 error("Element #" + utostr(i) + " is not of type '" +
4871 ETy->getDescription() +"' as required!\nIt is of type '" +
4872 CTy->getDescription() + "'");
4873 Elems.push_back(C);
4874 }
David Greene48556392007-09-04 18:46:50 +00004875 yyval.ValIDVal = ValID::create(ConstantVector::get(pt, Elems));
4876 delete PTy; delete yyvsp[-1].ConstVector;
Dale Johannesen3afee192007-09-07 21:07:57 +00004877 ;
4878 break;}
4879case 245:
4880#line 3166 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4881{
David Greene48556392007-09-04 18:46:50 +00004882 yyval.ValIDVal = ValID::create(yyvsp[0].ConstVal.C);
4883 yyval.ValIDVal.S.copy(yyvsp[0].ConstVal.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00004884 ;
4885 break;}
4886case 246:
4887#line 3170 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4888{
David Greene48556392007-09-04 18:46:50 +00004889 char *End = UnEscapeLexed(yyvsp[-2].StrVal, true);
4890 std::string AsmStr = std::string(yyvsp[-2].StrVal, End);
4891 End = UnEscapeLexed(yyvsp[0].StrVal, true);
4892 std::string Constraints = std::string(yyvsp[0].StrVal, End);
4893 yyval.ValIDVal = ValID::createInlineAsm(AsmStr, Constraints, yyvsp[-3].BoolVal);
4894 free(yyvsp[-2].StrVal);
4895 free(yyvsp[0].StrVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00004896 ;
4897 break;}
4898case 247:
4899#line 3184 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4900{ yyval.ValIDVal = ValID::create(yyvsp[0].SIntVal); yyval.ValIDVal.S.makeSignless(); ;
4901 break;}
4902case 248:
4903#line 3185 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4904{ yyval.ValIDVal = ValID::create(yyvsp[0].StrVal); yyval.ValIDVal.S.makeSignless(); ;
4905 break;}
4906case 251:
4907#line 3198 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4908{
David Greene48556392007-09-04 18:46:50 +00004909 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
4910 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
4911 yyval.ValueVal.V = getVal(Ty, yyvsp[0].ValIDVal);
4912 yyval.ValueVal.S.copy(yyvsp[-1].TypeVal.S);
4913 delete yyvsp[-1].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00004914 ;
4915 break;}
4916case 252:
4917#line 3208 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4918{
David Greene48556392007-09-04 18:46:50 +00004919 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00004920 ;
4921 break;}
4922case 253:
4923#line 3211 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4924{ // Do not allow functions with 0 basic blocks
David Greene48556392007-09-04 18:46:50 +00004925 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00004926 ;
4927 break;}
4928case 254:
4929#line 3220 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4930{
David Greene48556392007-09-04 18:46:50 +00004931 ValueInfo VI; VI.V = yyvsp[0].TermInstVal.TI; VI.S.copy(yyvsp[0].TermInstVal.S);
4932 setValueName(VI, yyvsp[-1].StrVal);
4933 InsertValue(yyvsp[0].TermInstVal.TI);
4934 yyvsp[-2].BasicBlockVal->getInstList().push_back(yyvsp[0].TermInstVal.TI);
4935 InsertValue(yyvsp[-2].BasicBlockVal);
4936 yyval.BasicBlockVal = yyvsp[-2].BasicBlockVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00004937 ;
4938 break;}
4939case 255:
4940#line 3231 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4941{
David Greene48556392007-09-04 18:46:50 +00004942 if (yyvsp[0].InstVal.I)
4943 yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].InstVal.I);
4944 yyval.BasicBlockVal = yyvsp[-1].BasicBlockVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00004945 ;
4946 break;}
4947case 256:
4948#line 3236 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4949{
David Greene48556392007-09-04 18:46:50 +00004950 yyval.BasicBlockVal = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++),true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004951 // Make sure to move the basic block to the correct location in the
4952 // function, instead of leaving it inserted wherever it was first
4953 // referenced.
4954 Function::BasicBlockListType &BBL =
4955 CurFun.CurrentFunction->getBasicBlockList();
David Greene48556392007-09-04 18:46:50 +00004956 BBL.splice(BBL.end(), BBL, yyval.BasicBlockVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00004957 ;
4958 break;}
4959case 257:
4960#line 3245 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4961{
David Greene48556392007-09-04 18:46:50 +00004962 yyval.BasicBlockVal = CurBB = getBBVal(ValID::create(yyvsp[0].StrVal), true);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00004963 // Make sure to move the basic block to the correct location in the
4964 // function, instead of leaving it inserted wherever it was first
4965 // referenced.
4966 Function::BasicBlockListType &BBL =
4967 CurFun.CurrentFunction->getBasicBlockList();
David Greene48556392007-09-04 18:46:50 +00004968 BBL.splice(BBL.end(), BBL, yyval.BasicBlockVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00004969 ;
4970 break;}
4971case 260:
4972#line 3259 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4973{ // Return with a result...
David Greene48556392007-09-04 18:46:50 +00004974 yyval.TermInstVal.TI = new ReturnInst(yyvsp[0].ValueVal.V);
4975 yyval.TermInstVal.S.makeSignless();
Dale Johannesen3afee192007-09-07 21:07:57 +00004976 ;
4977 break;}
4978case 261:
4979#line 3263 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4980{ // Return with no result...
David Greene48556392007-09-04 18:46:50 +00004981 yyval.TermInstVal.TI = new ReturnInst();
4982 yyval.TermInstVal.S.makeSignless();
Dale Johannesen3afee192007-09-07 21:07:57 +00004983 ;
4984 break;}
4985case 262:
4986#line 3267 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4987{ // Unconditional Branch...
David Greene48556392007-09-04 18:46:50 +00004988 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
4989 yyval.TermInstVal.TI = new BranchInst(tmpBB);
4990 yyval.TermInstVal.S.makeSignless();
Dale Johannesen3afee192007-09-07 21:07:57 +00004991 ;
4992 break;}
4993case 263:
4994#line 3272 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
4995{
David Greene48556392007-09-04 18:46:50 +00004996 yyvsp[-3].ValIDVal.S.makeSignless();
4997 yyvsp[0].ValIDVal.S.makeSignless();
4998 BasicBlock* tmpBBA = getBBVal(yyvsp[-3].ValIDVal);
4999 BasicBlock* tmpBBB = getBBVal(yyvsp[0].ValIDVal);
5000 yyvsp[-6].ValIDVal.S.makeUnsigned();
5001 Value* tmpVal = getVal(Type::Int1Ty, yyvsp[-6].ValIDVal);
5002 yyval.TermInstVal.TI = new BranchInst(tmpBBA, tmpBBB, tmpVal);
5003 yyval.TermInstVal.S.makeSignless();
Dale Johannesen3afee192007-09-07 21:07:57 +00005004 ;
5005 break;}
5006case 264:
5007#line 3282 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5008{
David Greene48556392007-09-04 18:46:50 +00005009 yyvsp[-6].ValIDVal.S.copy(yyvsp[-7].PrimType.S);
5010 Value* tmpVal = getVal(yyvsp[-7].PrimType.T, yyvsp[-6].ValIDVal);
5011 yyvsp[-3].ValIDVal.S.makeSignless();
5012 BasicBlock* tmpBB = getBBVal(yyvsp[-3].ValIDVal);
5013 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, yyvsp[-1].JumpTable->size());
5014 yyval.TermInstVal.TI = S;
5015 yyval.TermInstVal.S.makeSignless();
5016 std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = yyvsp[-1].JumpTable->begin(),
5017 E = yyvsp[-1].JumpTable->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005018 for (; I != E; ++I) {
5019 if (ConstantInt *CI = dyn_cast<ConstantInt>(I->first))
5020 S->addCase(CI, I->second);
5021 else
5022 error("Switch case is constant, but not a simple integer");
5023 }
David Greene48556392007-09-04 18:46:50 +00005024 delete yyvsp[-1].JumpTable;
Dale Johannesen3afee192007-09-07 21:07:57 +00005025 ;
5026 break;}
5027case 265:
5028#line 3300 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5029{
David Greene48556392007-09-04 18:46:50 +00005030 yyvsp[-5].ValIDVal.S.copy(yyvsp[-6].PrimType.S);
5031 Value* tmpVal = getVal(yyvsp[-6].PrimType.T, yyvsp[-5].ValIDVal);
5032 yyvsp[-2].ValIDVal.S.makeSignless();
5033 BasicBlock* tmpBB = getBBVal(yyvsp[-2].ValIDVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005034 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0);
David Greene48556392007-09-04 18:46:50 +00005035 yyval.TermInstVal.TI = S;
5036 yyval.TermInstVal.S.makeSignless();
Dale Johannesen3afee192007-09-07 21:07:57 +00005037 ;
5038 break;}
5039case 266:
5040#line 3310 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5041{
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005042 const PointerType *PFTy;
5043 const FunctionType *Ty;
5044 Signedness FTySign;
5045
David Greene48556392007-09-04 18:46:50 +00005046 if (!(PFTy = dyn_cast<PointerType>(yyvsp[-10].TypeVal.PAT->get())) ||
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005047 !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
5048 // Pull out the types of all of the arguments...
5049 std::vector<const Type*> ParamTypes;
David Greene48556392007-09-04 18:46:50 +00005050 FTySign.makeComposite(yyvsp[-10].TypeVal.S);
5051 if (yyvsp[-7].ValueList) {
5052 for (std::vector<ValueInfo>::iterator I = yyvsp[-7].ValueList->begin(), E = yyvsp[-7].ValueList->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005053 I != E; ++I) {
5054 ParamTypes.push_back((*I).V->getType());
5055 FTySign.add(I->S);
5056 }
5057 }
5058 ParamAttrsList *PAL = 0;
David Greene48556392007-09-04 18:46:50 +00005059 if (yyvsp[-11].UIntVal == OldCallingConv::CSRet) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005060 ParamAttrsVector Attrs;
5061 ParamAttrsWithIndex PAWI;
5062 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
5063 Attrs.push_back(PAWI);
5064 PAL = ParamAttrsList::get(Attrs);
5065 }
5066 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
5067 if (isVarArg) ParamTypes.pop_back();
David Greene48556392007-09-04 18:46:50 +00005068 Ty = FunctionType::get(yyvsp[-10].TypeVal.PAT->get(), ParamTypes, isVarArg, PAL);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005069 PFTy = PointerType::get(Ty);
David Greene48556392007-09-04 18:46:50 +00005070 yyval.TermInstVal.S.copy(yyvsp[-10].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005071 } else {
David Greene48556392007-09-04 18:46:50 +00005072 FTySign = yyvsp[-10].TypeVal.S;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005073 // Get the signedness of the result type. $3 is the pointer to the
5074 // function type so we get the 0th element to extract the function type,
5075 // and then the 0th element again to get the result type.
David Greene48556392007-09-04 18:46:50 +00005076 yyval.TermInstVal.S.copy(yyvsp[-10].TypeVal.S.get(0).get(0));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005077 }
5078
David Greene48556392007-09-04 18:46:50 +00005079 yyvsp[-9].ValIDVal.S.makeComposite(FTySign);
5080 Value *V = getVal(PFTy, yyvsp[-9].ValIDVal); // Get the function we're calling...
5081 BasicBlock *Normal = getBBVal(yyvsp[-3].ValIDVal);
5082 BasicBlock *Except = getBBVal(yyvsp[0].ValIDVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005083
5084 // Create the call node...
David Greene48556392007-09-04 18:46:50 +00005085 if (!yyvsp[-7].ValueList) { // Has no arguments?
5086 std::vector<Value*> Args;
5087 yyval.TermInstVal.TI = new InvokeInst(V, Normal, Except, Args.begin(), Args.end());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005088 } else { // Has arguments?
5089 // Loop through FunctionType's arguments and ensure they are specified
5090 // correctly!
5091 //
5092 FunctionType::param_iterator I = Ty->param_begin();
5093 FunctionType::param_iterator E = Ty->param_end();
David Greene48556392007-09-04 18:46:50 +00005094 std::vector<ValueInfo>::iterator ArgI = yyvsp[-7].ValueList->begin(), ArgE = yyvsp[-7].ValueList->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005095
5096 std::vector<Value*> Args;
5097 for (; ArgI != ArgE && I != E; ++ArgI, ++I) {
5098 if ((*ArgI).V->getType() != *I)
5099 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
5100 (*I)->getDescription() + "'");
5101 Args.push_back((*ArgI).V);
5102 }
5103
5104 if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
5105 error("Invalid number of parameters detected");
5106
David Greene48556392007-09-04 18:46:50 +00005107 yyval.TermInstVal.TI = new InvokeInst(V, Normal, Except, Args.begin(), Args.end());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005108 }
David Greene48556392007-09-04 18:46:50 +00005109 cast<InvokeInst>(yyval.TermInstVal.TI)->setCallingConv(upgradeCallingConv(yyvsp[-11].UIntVal));
5110 delete yyvsp[-10].TypeVal.PAT;
5111 delete yyvsp[-7].ValueList;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005112 lastCallingConv = OldCallingConv::C;
Dale Johannesen3afee192007-09-07 21:07:57 +00005113 ;
5114 break;}
5115case 267:
5116#line 3383 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5117{
David Greene48556392007-09-04 18:46:50 +00005118 yyval.TermInstVal.TI = new UnwindInst();
5119 yyval.TermInstVal.S.makeSignless();
Dale Johannesen3afee192007-09-07 21:07:57 +00005120 ;
5121 break;}
5122case 268:
5123#line 3387 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5124{
David Greene48556392007-09-04 18:46:50 +00005125 yyval.TermInstVal.TI = new UnreachableInst();
5126 yyval.TermInstVal.S.makeSignless();
Dale Johannesen3afee192007-09-07 21:07:57 +00005127 ;
5128 break;}
5129case 269:
5130#line 3394 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5131{
David Greene48556392007-09-04 18:46:50 +00005132 yyval.JumpTable = yyvsp[-5].JumpTable;
5133 yyvsp[-3].ValIDVal.S.copy(yyvsp[-4].PrimType.S);
5134 Constant *V = cast<Constant>(getExistingValue(yyvsp[-4].PrimType.T, yyvsp[-3].ValIDVal));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005135
5136 if (V == 0)
5137 error("May only switch on a constant pool value");
5138
David Greene48556392007-09-04 18:46:50 +00005139 yyvsp[0].ValIDVal.S.makeSignless();
5140 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
5141 yyval.JumpTable->push_back(std::make_pair(V, tmpBB));
Dale Johannesen3afee192007-09-07 21:07:57 +00005142 ;
5143 break;}
5144case 270:
5145#line 3406 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5146{
David Greene48556392007-09-04 18:46:50 +00005147 yyval.JumpTable = new std::vector<std::pair<Constant*, BasicBlock*> >();
5148 yyvsp[-3].ValIDVal.S.copy(yyvsp[-4].PrimType.S);
5149 Constant *V = cast<Constant>(getExistingValue(yyvsp[-4].PrimType.T, yyvsp[-3].ValIDVal));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005150
5151 if (V == 0)
5152 error("May only switch on a constant pool value");
5153
David Greene48556392007-09-04 18:46:50 +00005154 yyvsp[0].ValIDVal.S.makeSignless();
5155 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
5156 yyval.JumpTable->push_back(std::make_pair(V, tmpBB));
Dale Johannesen3afee192007-09-07 21:07:57 +00005157 ;
5158 break;}
5159case 271:
5160#line 3421 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5161{
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005162 bool omit = false;
David Greene48556392007-09-04 18:46:50 +00005163 if (yyvsp[-1].StrVal)
5164 if (BitCastInst *BCI = dyn_cast<BitCastInst>(yyvsp[0].InstVal.I))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005165 if (BCI->getSrcTy() == BCI->getDestTy() &&
David Greene48556392007-09-04 18:46:50 +00005166 BCI->getOperand(0)->getName() == yyvsp[-1].StrVal)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005167 // This is a useless bit cast causing a name redefinition. It is
5168 // a bit cast from a type to the same type of an operand with the
5169 // same name as the name we would give this instruction. Since this
5170 // instruction results in no code generation, it is safe to omit
5171 // the instruction. This situation can occur because of collapsed
5172 // type planes. For example:
5173 // %X = add int %Y, %Z
5174 // %X = cast int %Y to uint
5175 // After upgrade, this looks like:
5176 // %X = add i32 %Y, %Z
5177 // %X = bitcast i32 to i32
5178 // The bitcast is clearly useless so we omit it.
5179 omit = true;
5180 if (omit) {
David Greene48556392007-09-04 18:46:50 +00005181 yyval.InstVal.I = 0;
5182 yyval.InstVal.S.makeSignless();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005183 } else {
David Greene48556392007-09-04 18:46:50 +00005184 ValueInfo VI; VI.V = yyvsp[0].InstVal.I; VI.S.copy(yyvsp[0].InstVal.S);
5185 setValueName(VI, yyvsp[-1].StrVal);
5186 InsertValue(yyvsp[0].InstVal.I);
5187 yyval.InstVal = yyvsp[0].InstVal;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005188 }
Dale Johannesen3afee192007-09-07 21:07:57 +00005189 ;
5190 break;}
5191case 272:
5192#line 3451 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5193{ // Used for PHI nodes
David Greene48556392007-09-04 18:46:50 +00005194 yyval.PHIList.P = new std::list<std::pair<Value*, BasicBlock*> >();
5195 yyval.PHIList.S.copy(yyvsp[-5].TypeVal.S);
5196 yyvsp[-3].ValIDVal.S.copy(yyvsp[-5].TypeVal.S);
5197 Value* tmpVal = getVal(yyvsp[-5].TypeVal.PAT->get(), yyvsp[-3].ValIDVal);
5198 yyvsp[-1].ValIDVal.S.makeSignless();
5199 BasicBlock* tmpBB = getBBVal(yyvsp[-1].ValIDVal);
5200 yyval.PHIList.P->push_back(std::make_pair(tmpVal, tmpBB));
5201 delete yyvsp[-5].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005202 ;
5203 break;}
5204case 273:
5205#line 3461 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5206{
David Greene48556392007-09-04 18:46:50 +00005207 yyval.PHIList = yyvsp[-6].PHIList;
5208 yyvsp[-3].ValIDVal.S.copy(yyvsp[-6].PHIList.S);
5209 Value* tmpVal = getVal(yyvsp[-6].PHIList.P->front().first->getType(), yyvsp[-3].ValIDVal);
5210 yyvsp[-1].ValIDVal.S.makeSignless();
5211 BasicBlock* tmpBB = getBBVal(yyvsp[-1].ValIDVal);
5212 yyvsp[-6].PHIList.P->push_back(std::make_pair(tmpVal, tmpBB));
Dale Johannesen3afee192007-09-07 21:07:57 +00005213 ;
5214 break;}
5215case 274:
5216#line 3471 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5217{ // Used for call statements, and memory insts...
David Greene48556392007-09-04 18:46:50 +00005218 yyval.ValueList = new std::vector<ValueInfo>();
5219 yyval.ValueList->push_back(yyvsp[0].ValueVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00005220 ;
5221 break;}
5222case 275:
5223#line 3475 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5224{
David Greene48556392007-09-04 18:46:50 +00005225 yyval.ValueList = yyvsp[-2].ValueList;
5226 yyvsp[-2].ValueList->push_back(yyvsp[0].ValueVal);
Dale Johannesen3afee192007-09-07 21:07:57 +00005227 ;
5228 break;}
5229case 277:
5230#line 3483 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5231{ yyval.ValueList = 0; ;
5232 break;}
5233case 278:
5234#line 3487 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5235{
David Greene48556392007-09-04 18:46:50 +00005236 yyval.BoolVal = true;
Dale Johannesen3afee192007-09-07 21:07:57 +00005237 ;
5238 break;}
5239case 279:
5240#line 3490 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5241{
David Greene48556392007-09-04 18:46:50 +00005242 yyval.BoolVal = false;
Dale Johannesen3afee192007-09-07 21:07:57 +00005243 ;
5244 break;}
5245case 280:
5246#line 3496 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5247{
David Greene48556392007-09-04 18:46:50 +00005248 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
5249 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
5250 const Type* Ty = yyvsp[-3].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005251 if (!Ty->isInteger() && !Ty->isFloatingPoint() && !isa<VectorType>(Ty))
5252 error("Arithmetic operator requires integer, FP, or packed operands");
5253 if (isa<VectorType>(Ty) &&
David Greene48556392007-09-04 18:46:50 +00005254 (yyvsp[-4].BinaryOpVal == URemOp || yyvsp[-4].BinaryOpVal == SRemOp || yyvsp[-4].BinaryOpVal == FRemOp || yyvsp[-4].BinaryOpVal == RemOp))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005255 error("Remainder not supported on vector types");
5256 // Upgrade the opcode from obsolete versions before we do anything with it.
David Greene48556392007-09-04 18:46:50 +00005257 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-4].BinaryOpVal, Ty, yyvsp[-3].TypeVal.S);
5258 Value* val1 = getVal(Ty, yyvsp[-2].ValIDVal);
5259 Value* val2 = getVal(Ty, yyvsp[0].ValIDVal);
5260 yyval.InstVal.I = BinaryOperator::create(Opcode, val1, val2);
5261 if (yyval.InstVal.I == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005262 error("binary operator returned null");
David Greene48556392007-09-04 18:46:50 +00005263 yyval.InstVal.S.copy(yyvsp[-3].TypeVal.S);
5264 delete yyvsp[-3].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005265 ;
5266 break;}
5267case 281:
5268#line 3515 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5269{
David Greene48556392007-09-04 18:46:50 +00005270 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
5271 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
5272 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005273 if (!Ty->isInteger()) {
5274 if (!isa<VectorType>(Ty) ||
5275 !cast<VectorType>(Ty)->getElementType()->isInteger())
5276 error("Logical operator requires integral operands");
5277 }
David Greene48556392007-09-04 18:46:50 +00005278 Instruction::BinaryOps Opcode = getBinaryOp(yyvsp[-4].BinaryOpVal, Ty, yyvsp[-3].TypeVal.S);
5279 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
5280 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
5281 yyval.InstVal.I = BinaryOperator::create(Opcode, tmpVal1, tmpVal2);
5282 if (yyval.InstVal.I == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005283 error("binary operator returned null");
David Greene48556392007-09-04 18:46:50 +00005284 yyval.InstVal.S.copy(yyvsp[-3].TypeVal.S);
5285 delete yyvsp[-3].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005286 ;
5287 break;}
5288case 282:
5289#line 3533 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5290{
David Greene48556392007-09-04 18:46:50 +00005291 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
5292 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
5293 const Type* Ty = yyvsp[-3].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005294 if(isa<VectorType>(Ty))
5295 error("VectorTypes currently not supported in setcc instructions");
5296 unsigned short pred;
David Greene48556392007-09-04 18:46:50 +00005297 Instruction::OtherOps Opcode = getCompareOp(yyvsp[-4].BinaryOpVal, pred, Ty, yyvsp[-3].TypeVal.S);
5298 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
5299 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
5300 yyval.InstVal.I = CmpInst::create(Opcode, pred, tmpVal1, tmpVal2);
5301 if (yyval.InstVal.I == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005302 error("binary operator returned null");
David Greene48556392007-09-04 18:46:50 +00005303 yyval.InstVal.S.makeUnsigned();
5304 delete yyvsp[-3].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005305 ;
5306 break;}
5307case 283:
5308#line 3549 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5309{
David Greene48556392007-09-04 18:46:50 +00005310 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
5311 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
5312 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005313 if (isa<VectorType>(Ty))
5314 error("VectorTypes currently not supported in icmp instructions");
5315 else if (!Ty->isInteger() && !isa<PointerType>(Ty))
5316 error("icmp requires integer or pointer typed operands");
David Greene48556392007-09-04 18:46:50 +00005317 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
5318 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
5319 yyval.InstVal.I = new ICmpInst(yyvsp[-4].IPred, tmpVal1, tmpVal2);
5320 yyval.InstVal.S.makeUnsigned();
5321 delete yyvsp[-3].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005322 ;
5323 break;}
5324case 284:
5325#line 3563 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5326{
David Greene48556392007-09-04 18:46:50 +00005327 yyvsp[-2].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
5328 yyvsp[0].ValIDVal.S.copy(yyvsp[-3].TypeVal.S);
5329 const Type *Ty = yyvsp[-3].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005330 if (isa<VectorType>(Ty))
5331 error("VectorTypes currently not supported in fcmp instructions");
5332 else if (!Ty->isFloatingPoint())
5333 error("fcmp instruction requires floating point operands");
David Greene48556392007-09-04 18:46:50 +00005334 Value* tmpVal1 = getVal(Ty, yyvsp[-2].ValIDVal);
5335 Value* tmpVal2 = getVal(Ty, yyvsp[0].ValIDVal);
5336 yyval.InstVal.I = new FCmpInst(yyvsp[-4].FPred, tmpVal1, tmpVal2);
5337 yyval.InstVal.S.makeUnsigned();
5338 delete yyvsp[-3].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005339 ;
5340 break;}
5341case 285:
5342#line 3577 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5343{
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005344 warning("Use of obsolete 'not' instruction: Replacing with 'xor");
David Greene48556392007-09-04 18:46:50 +00005345 const Type *Ty = yyvsp[0].ValueVal.V->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005346 Value *Ones = ConstantInt::getAllOnesValue(Ty);
5347 if (Ones == 0)
5348 error("Expected integral type for not instruction");
David Greene48556392007-09-04 18:46:50 +00005349 yyval.InstVal.I = BinaryOperator::create(Instruction::Xor, yyvsp[0].ValueVal.V, Ones);
5350 if (yyval.InstVal.I == 0)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005351 error("Could not create a xor instruction");
David Greene48556392007-09-04 18:46:50 +00005352 yyval.InstVal.S.copy(yyvsp[0].ValueVal.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00005353 ;
5354 break;}
5355case 286:
5356#line 3588 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5357{
David Greene48556392007-09-04 18:46:50 +00005358 if (!yyvsp[0].ValueVal.V->getType()->isInteger() ||
5359 cast<IntegerType>(yyvsp[0].ValueVal.V->getType())->getBitWidth() != 8)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005360 error("Shift amount must be int8");
David Greene48556392007-09-04 18:46:50 +00005361 const Type* Ty = yyvsp[-2].ValueVal.V->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005362 if (!Ty->isInteger())
5363 error("Shift constant expression requires integer operand");
5364 Value* ShiftAmt = 0;
5365 if (cast<IntegerType>(Ty)->getBitWidth() > Type::Int8Ty->getBitWidth())
David Greene48556392007-09-04 18:46:50 +00005366 if (Constant *C = dyn_cast<Constant>(yyvsp[0].ValueVal.V))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005367 ShiftAmt = ConstantExpr::getZExt(C, Ty);
5368 else
David Greene48556392007-09-04 18:46:50 +00005369 ShiftAmt = new ZExtInst(yyvsp[0].ValueVal.V, Ty, makeNameUnique("shift"), CurBB);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005370 else
David Greene48556392007-09-04 18:46:50 +00005371 ShiftAmt = yyvsp[0].ValueVal.V;
5372 yyval.InstVal.I = BinaryOperator::create(getBinaryOp(yyvsp[-3].BinaryOpVal, Ty, yyvsp[-2].ValueVal.S), yyvsp[-2].ValueVal.V, ShiftAmt);
5373 yyval.InstVal.S.copy(yyvsp[-2].ValueVal.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00005374 ;
5375 break;}
5376case 287:
5377#line 3606 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5378{
David Greene48556392007-09-04 18:46:50 +00005379 const Type *DstTy = yyvsp[0].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005380 if (!DstTy->isFirstClassType())
5381 error("cast instruction to a non-primitive type: '" +
5382 DstTy->getDescription() + "'");
David Greene48556392007-09-04 18:46:50 +00005383 yyval.InstVal.I = cast<Instruction>(getCast(yyvsp[-3].CastOpVal, yyvsp[-2].ValueVal.V, yyvsp[-2].ValueVal.S, DstTy, yyvsp[0].TypeVal.S, true));
5384 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
5385 delete yyvsp[0].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005386 ;
5387 break;}
5388case 288:
5389#line 3615 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5390{
David Greene48556392007-09-04 18:46:50 +00005391 if (!yyvsp[-4].ValueVal.V->getType()->isInteger() ||
5392 cast<IntegerType>(yyvsp[-4].ValueVal.V->getType())->getBitWidth() != 1)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005393 error("select condition must be bool");
David Greene48556392007-09-04 18:46:50 +00005394 if (yyvsp[-2].ValueVal.V->getType() != yyvsp[0].ValueVal.V->getType())
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005395 error("select value types should match");
David Greene48556392007-09-04 18:46:50 +00005396 yyval.InstVal.I = new SelectInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
5397 yyval.InstVal.S.copy(yyvsp[-2].ValueVal.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00005398 ;
5399 break;}
5400case 289:
5401#line 3624 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5402{
David Greene48556392007-09-04 18:46:50 +00005403 const Type *Ty = yyvsp[0].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005404 NewVarArgs = true;
David Greene48556392007-09-04 18:46:50 +00005405 yyval.InstVal.I = new VAArgInst(yyvsp[-2].ValueVal.V, Ty);
5406 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
5407 delete yyvsp[0].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005408 ;
5409 break;}
5410case 290:
5411#line 3631 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5412{
David Greene48556392007-09-04 18:46:50 +00005413 const Type* ArgTy = yyvsp[-2].ValueVal.V->getType();
5414 const Type* DstTy = yyvsp[0].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005415 ObsoleteVarArgs = true;
5416 Function* NF = cast<Function>(CurModule.CurrentModule->
5417 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
5418
5419 //b = vaarg a, t ->
5420 //foo = alloca 1 of t
5421 //bar = vacopy a
5422 //store bar -> foo
5423 //b = vaarg foo, t
5424 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vaarg.fix");
5425 CurBB->getInstList().push_back(foo);
David Greene48556392007-09-04 18:46:50 +00005426 CallInst* bar = new CallInst(NF, yyvsp[-2].ValueVal.V);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005427 CurBB->getInstList().push_back(bar);
5428 CurBB->getInstList().push_back(new StoreInst(bar, foo));
David Greene48556392007-09-04 18:46:50 +00005429 yyval.InstVal.I = new VAArgInst(foo, DstTy);
5430 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
5431 delete yyvsp[0].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005432 ;
5433 break;}
5434case 291:
5435#line 3652 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5436{
David Greene48556392007-09-04 18:46:50 +00005437 const Type* ArgTy = yyvsp[-2].ValueVal.V->getType();
5438 const Type* DstTy = yyvsp[0].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005439 ObsoleteVarArgs = true;
5440 Function* NF = cast<Function>(CurModule.CurrentModule->
5441 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0));
5442
5443 //b = vanext a, t ->
5444 //foo = alloca 1 of t
5445 //bar = vacopy a
5446 //store bar -> foo
5447 //tmp = vaarg foo, t
5448 //b = load foo
5449 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vanext.fix");
5450 CurBB->getInstList().push_back(foo);
David Greene48556392007-09-04 18:46:50 +00005451 CallInst* bar = new CallInst(NF, yyvsp[-2].ValueVal.V);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005452 CurBB->getInstList().push_back(bar);
5453 CurBB->getInstList().push_back(new StoreInst(bar, foo));
5454 Instruction* tmp = new VAArgInst(foo, DstTy);
5455 CurBB->getInstList().push_back(tmp);
David Greene48556392007-09-04 18:46:50 +00005456 yyval.InstVal.I = new LoadInst(foo);
5457 yyval.InstVal.S.copy(yyvsp[0].TypeVal.S);
5458 delete yyvsp[0].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005459 ;
5460 break;}
5461case 292:
5462#line 3676 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5463{
David Greene48556392007-09-04 18:46:50 +00005464 if (!ExtractElementInst::isValidOperands(yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005465 error("Invalid extractelement operands");
David Greene48556392007-09-04 18:46:50 +00005466 yyval.InstVal.I = new ExtractElementInst(yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
5467 yyval.InstVal.S.copy(yyvsp[-2].ValueVal.S.get(0));
Dale Johannesen3afee192007-09-07 21:07:57 +00005468 ;
5469 break;}
5470case 293:
5471#line 3682 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5472{
David Greene48556392007-09-04 18:46:50 +00005473 if (!InsertElementInst::isValidOperands(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005474 error("Invalid insertelement operands");
David Greene48556392007-09-04 18:46:50 +00005475 yyval.InstVal.I = new InsertElementInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
5476 yyval.InstVal.S.copy(yyvsp[-4].ValueVal.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00005477 ;
5478 break;}
5479case 294:
5480#line 3688 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5481{
David Greene48556392007-09-04 18:46:50 +00005482 if (!ShuffleVectorInst::isValidOperands(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V))
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005483 error("Invalid shufflevector operands");
David Greene48556392007-09-04 18:46:50 +00005484 yyval.InstVal.I = new ShuffleVectorInst(yyvsp[-4].ValueVal.V, yyvsp[-2].ValueVal.V, yyvsp[0].ValueVal.V);
5485 yyval.InstVal.S.copy(yyvsp[-4].ValueVal.S);
Dale Johannesen3afee192007-09-07 21:07:57 +00005486 ;
5487 break;}
5488case 295:
5489#line 3694 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5490{
David Greene48556392007-09-04 18:46:50 +00005491 const Type *Ty = yyvsp[0].PHIList.P->front().first->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005492 if (!Ty->isFirstClassType())
5493 error("PHI node operands must be of first class type");
5494 PHINode *PHI = new PHINode(Ty);
David Greene48556392007-09-04 18:46:50 +00005495 PHI->reserveOperandSpace(yyvsp[0].PHIList.P->size());
5496 while (yyvsp[0].PHIList.P->begin() != yyvsp[0].PHIList.P->end()) {
5497 if (yyvsp[0].PHIList.P->front().first->getType() != Ty)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005498 error("All elements of a PHI node must be of the same type");
David Greene48556392007-09-04 18:46:50 +00005499 PHI->addIncoming(yyvsp[0].PHIList.P->front().first, yyvsp[0].PHIList.P->front().second);
5500 yyvsp[0].PHIList.P->pop_front();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005501 }
David Greene48556392007-09-04 18:46:50 +00005502 yyval.InstVal.I = PHI;
5503 yyval.InstVal.S.copy(yyvsp[0].PHIList.S);
5504 delete yyvsp[0].PHIList.P; // Free the list...
Dale Johannesen3afee192007-09-07 21:07:57 +00005505 ;
5506 break;}
5507case 296:
5508#line 3710 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5509{
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005510 // Handle the short call syntax
5511 const PointerType *PFTy;
5512 const FunctionType *FTy;
5513 Signedness FTySign;
David Greene48556392007-09-04 18:46:50 +00005514 if (!(PFTy = dyn_cast<PointerType>(yyvsp[-4].TypeVal.PAT->get())) ||
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005515 !(FTy = dyn_cast<FunctionType>(PFTy->getElementType()))) {
5516 // Pull out the types of all of the arguments...
5517 std::vector<const Type*> ParamTypes;
David Greene48556392007-09-04 18:46:50 +00005518 FTySign.makeComposite(yyvsp[-4].TypeVal.S);
5519 if (yyvsp[-1].ValueList) {
5520 for (std::vector<ValueInfo>::iterator I = yyvsp[-1].ValueList->begin(), E = yyvsp[-1].ValueList->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005521 I != E; ++I) {
5522 ParamTypes.push_back((*I).V->getType());
5523 FTySign.add(I->S);
5524 }
5525 }
5526
5527 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
5528 if (isVarArg) ParamTypes.pop_back();
5529
David Greene48556392007-09-04 18:46:50 +00005530 const Type *RetTy = yyvsp[-4].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005531 if (!RetTy->isFirstClassType() && RetTy != Type::VoidTy)
5532 error("Functions cannot return aggregate types");
5533
5534 // Deal with CSRetCC
5535 ParamAttrsList *PAL = 0;
David Greene48556392007-09-04 18:46:50 +00005536 if (yyvsp[-5].UIntVal == OldCallingConv::CSRet) {
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005537 ParamAttrsVector Attrs;
5538 ParamAttrsWithIndex PAWI;
5539 PAWI.index = 1; PAWI.attrs = ParamAttr::StructRet; // first arg
5540 Attrs.push_back(PAWI);
5541 PAL = ParamAttrsList::get(Attrs);
5542 }
5543
5544 FTy = FunctionType::get(RetTy, ParamTypes, isVarArg, PAL);
5545 PFTy = PointerType::get(FTy);
David Greene48556392007-09-04 18:46:50 +00005546 yyval.InstVal.S.copy(yyvsp[-4].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005547 } else {
David Greene48556392007-09-04 18:46:50 +00005548 FTySign = yyvsp[-4].TypeVal.S;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005549 // Get the signedness of the result type. $3 is the pointer to the
5550 // function type so we get the 0th element to extract the function type,
5551 // and then the 0th element again to get the result type.
David Greene48556392007-09-04 18:46:50 +00005552 yyval.InstVal.S.copy(yyvsp[-4].TypeVal.S.get(0).get(0));
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005553 }
David Greene48556392007-09-04 18:46:50 +00005554 yyvsp[-3].ValIDVal.S.makeComposite(FTySign);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005555
5556 // First upgrade any intrinsic calls.
5557 std::vector<Value*> Args;
David Greene48556392007-09-04 18:46:50 +00005558 if (yyvsp[-1].ValueList)
5559 for (unsigned i = 0, e = yyvsp[-1].ValueList->size(); i < e; ++i)
5560 Args.push_back((*yyvsp[-1].ValueList)[i].V);
5561 Instruction *Inst = upgradeIntrinsicCall(FTy->getReturnType(), yyvsp[-3].ValIDVal, Args);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005562
5563 // If we got an upgraded intrinsic
5564 if (Inst) {
David Greene48556392007-09-04 18:46:50 +00005565 yyval.InstVal.I = Inst;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005566 } else {
5567 // Get the function we're calling
David Greene48556392007-09-04 18:46:50 +00005568 Value *V = getVal(PFTy, yyvsp[-3].ValIDVal);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005569
5570 // Check the argument values match
David Greene48556392007-09-04 18:46:50 +00005571 if (!yyvsp[-1].ValueList) { // Has no arguments?
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005572 // Make sure no arguments is a good thing!
5573 if (FTy->getNumParams() != 0)
5574 error("No arguments passed to a function that expects arguments");
5575 } else { // Has arguments?
5576 // Loop through FunctionType's arguments and ensure they are specified
5577 // correctly!
5578 //
5579 FunctionType::param_iterator I = FTy->param_begin();
5580 FunctionType::param_iterator E = FTy->param_end();
David Greene48556392007-09-04 18:46:50 +00005581 std::vector<ValueInfo>::iterator ArgI = yyvsp[-1].ValueList->begin(), ArgE = yyvsp[-1].ValueList->end();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005582
5583 for (; ArgI != ArgE && I != E; ++ArgI, ++I)
5584 if ((*ArgI).V->getType() != *I)
5585 error("Parameter " +(*ArgI).V->getName()+ " is not of type '" +
5586 (*I)->getDescription() + "'");
5587
5588 if (I != E || (ArgI != ArgE && !FTy->isVarArg()))
5589 error("Invalid number of parameters detected");
5590 }
5591
5592 // Create the call instruction
David Greene9145dd22007-08-01 03:59:32 +00005593 CallInst *CI = new CallInst(V, Args.begin(), Args.end());
David Greene48556392007-09-04 18:46:50 +00005594 CI->setTailCall(yyvsp[-6].BoolVal);
5595 CI->setCallingConv(upgradeCallingConv(yyvsp[-5].UIntVal));
5596 yyval.InstVal.I = CI;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005597 }
David Greene48556392007-09-04 18:46:50 +00005598 delete yyvsp[-4].TypeVal.PAT;
5599 delete yyvsp[-1].ValueList;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005600 lastCallingConv = OldCallingConv::C;
Dale Johannesen3afee192007-09-07 21:07:57 +00005601 ;
5602 break;}
5603case 297:
5604#line 3803 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5605{
David Greene48556392007-09-04 18:46:50 +00005606 yyval.InstVal = yyvsp[0].InstVal;
Dale Johannesen3afee192007-09-07 21:07:57 +00005607 ;
5608 break;}
5609case 298:
5610#line 3811 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5611{ yyval.ValueList = yyvsp[0].ValueList; ;
5612 break;}
5613case 299:
5614#line 3812 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5615{ yyval.ValueList = new std::vector<ValueInfo>(); ;
5616 break;}
5617case 300:
5618#line 3816 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5619{ yyval.BoolVal = true; ;
5620 break;}
5621case 301:
5622#line 3817 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5623{ yyval.BoolVal = false; ;
5624 break;}
5625case 302:
5626#line 3821 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5627{
David Greene48556392007-09-04 18:46:50 +00005628 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
5629 yyval.InstVal.S.makeComposite(yyvsp[-1].TypeVal.S);
5630 yyval.InstVal.I = new MallocInst(Ty, 0, yyvsp[0].UIntVal);
5631 delete yyvsp[-1].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005632 ;
5633 break;}
5634case 303:
5635#line 3827 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5636{
David Greene48556392007-09-04 18:46:50 +00005637 const Type *Ty = yyvsp[-4].TypeVal.PAT->get();
5638 yyvsp[-1].ValIDVal.S.makeUnsigned();
5639 yyval.InstVal.S.makeComposite(yyvsp[-4].TypeVal.S);
5640 yyval.InstVal.I = new MallocInst(Ty, getVal(yyvsp[-2].PrimType.T, yyvsp[-1].ValIDVal), yyvsp[0].UIntVal);
5641 delete yyvsp[-4].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005642 ;
5643 break;}
5644case 304:
5645#line 3834 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5646{
David Greene48556392007-09-04 18:46:50 +00005647 const Type *Ty = yyvsp[-1].TypeVal.PAT->get();
5648 yyval.InstVal.S.makeComposite(yyvsp[-1].TypeVal.S);
5649 yyval.InstVal.I = new AllocaInst(Ty, 0, yyvsp[0].UIntVal);
5650 delete yyvsp[-1].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005651 ;
5652 break;}
5653case 305:
5654#line 3840 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5655{
David Greene48556392007-09-04 18:46:50 +00005656 const Type *Ty = yyvsp[-4].TypeVal.PAT->get();
5657 yyvsp[-1].ValIDVal.S.makeUnsigned();
5658 yyval.InstVal.S.makeComposite(yyvsp[-2].PrimType.S);
5659 yyval.InstVal.I = new AllocaInst(Ty, getVal(yyvsp[-2].PrimType.T, yyvsp[-1].ValIDVal), yyvsp[0].UIntVal);
5660 delete yyvsp[-4].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005661 ;
5662 break;}
5663case 306:
5664#line 3847 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5665{
David Greene48556392007-09-04 18:46:50 +00005666 const Type *PTy = yyvsp[0].ValueVal.V->getType();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005667 if (!isa<PointerType>(PTy))
5668 error("Trying to free nonpointer type '" + PTy->getDescription() + "'");
David Greene48556392007-09-04 18:46:50 +00005669 yyval.InstVal.I = new FreeInst(yyvsp[0].ValueVal.V);
5670 yyval.InstVal.S.makeSignless();
Dale Johannesen3afee192007-09-07 21:07:57 +00005671 ;
5672 break;}
5673case 307:
5674#line 3854 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5675{
David Greene48556392007-09-04 18:46:50 +00005676 const Type* Ty = yyvsp[-1].TypeVal.PAT->get();
5677 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005678 if (!isa<PointerType>(Ty))
5679 error("Can't load from nonpointer type: " + Ty->getDescription());
5680 if (!cast<PointerType>(Ty)->getElementType()->isFirstClassType())
5681 error("Can't load from pointer of non-first-class type: " +
5682 Ty->getDescription());
David Greene48556392007-09-04 18:46:50 +00005683 Value* tmpVal = getVal(Ty, yyvsp[0].ValIDVal);
5684 yyval.InstVal.I = new LoadInst(tmpVal, "", yyvsp[-3].BoolVal);
5685 yyval.InstVal.S.copy(yyvsp[-1].TypeVal.S.get(0));
5686 delete yyvsp[-1].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005687 ;
5688 break;}
5689case 308:
5690#line 3867 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5691{
David Greene48556392007-09-04 18:46:50 +00005692 yyvsp[0].ValIDVal.S.copy(yyvsp[-1].TypeVal.S);
5693 const PointerType *PTy = dyn_cast<PointerType>(yyvsp[-1].TypeVal.PAT->get());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005694 if (!PTy)
5695 error("Can't store to a nonpointer type: " +
David Greene48556392007-09-04 18:46:50 +00005696 yyvsp[-1].TypeVal.PAT->get()->getDescription());
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005697 const Type *ElTy = PTy->getElementType();
David Greene48556392007-09-04 18:46:50 +00005698 Value *StoreVal = yyvsp[-3].ValueVal.V;
5699 Value* tmpVal = getVal(PTy, yyvsp[0].ValIDVal);
5700 if (ElTy != yyvsp[-3].ValueVal.V->getType()) {
5701 StoreVal = handleSRetFuncTypeMerge(yyvsp[-3].ValueVal.V, ElTy);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005702 if (!StoreVal)
David Greene48556392007-09-04 18:46:50 +00005703 error("Can't store '" + yyvsp[-3].ValueVal.V->getType()->getDescription() +
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005704 "' into space of type '" + ElTy->getDescription() + "'");
5705 else {
5706 PTy = PointerType::get(StoreVal->getType());
5707 if (Constant *C = dyn_cast<Constant>(tmpVal))
5708 tmpVal = ConstantExpr::getBitCast(C, PTy);
5709 else
5710 tmpVal = new BitCastInst(tmpVal, PTy, "upgrd.cast", CurBB);
5711 }
5712 }
David Greene48556392007-09-04 18:46:50 +00005713 yyval.InstVal.I = new StoreInst(StoreVal, tmpVal, yyvsp[-5].BoolVal);
5714 yyval.InstVal.S.makeSignless();
5715 delete yyvsp[-1].TypeVal.PAT;
Dale Johannesen3afee192007-09-07 21:07:57 +00005716 ;
5717 break;}
5718case 309:
5719#line 3893 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
5720{
David Greene48556392007-09-04 18:46:50 +00005721 yyvsp[-1].ValIDVal.S.copy(yyvsp[-2].TypeVal.S);
5722 const Type* Ty = yyvsp[-2].TypeVal.PAT->get();
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005723 if (!isa<PointerType>(Ty))
5724 error("getelementptr insn requires pointer operand");
5725
5726 std::vector<Value*> VIndices;
David Greene48556392007-09-04 18:46:50 +00005727 upgradeGEPInstIndices(Ty, yyvsp[0].ValueList, VIndices);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005728
David Greene48556392007-09-04 18:46:50 +00005729 Value* tmpVal = getVal(Ty, yyvsp[-1].ValIDVal);
5730 yyval.InstVal.I = new GetElementPtrInst(tmpVal, VIndices.begin(), VIndices.end());
5731 ValueInfo VI; VI.V = tmpVal; VI.S.copy(yyvsp[-2].TypeVal.S);
5732 yyval.InstVal.S.copy(getElementSign(VI, VIndices));
5733 delete yyvsp[-2].TypeVal.PAT;
5734 delete yyvsp[0].ValueList;
Dale Johannesen3afee192007-09-07 21:07:57 +00005735 ;
5736 break;}
5737}
5738 /* the action file gets copied in in place of this dollarsign */
5739#line 543 "/usr/share/bison.simple"
David Greene48556392007-09-04 18:46:50 +00005740
5741 yyvsp -= yylen;
5742 yyssp -= yylen;
Dale Johannesen3afee192007-09-07 21:07:57 +00005743#ifdef YYLSP_NEEDED
5744 yylsp -= yylen;
5745#endif
David Greene48556392007-09-04 18:46:50 +00005746
Dale Johannesen3afee192007-09-07 21:07:57 +00005747#if YYDEBUG != 0
5748 if (yydebug)
5749 {
5750 short *ssp1 = yyss - 1;
5751 fprintf (stderr, "state stack now");
5752 while (ssp1 != yyssp)
5753 fprintf (stderr, " %d", *++ssp1);
5754 fprintf (stderr, "\n");
5755 }
5756#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005757
5758 *++yyvsp = yyval;
5759
Dale Johannesen3afee192007-09-07 21:07:57 +00005760#ifdef YYLSP_NEEDED
5761 yylsp++;
5762 if (yylen == 0)
5763 {
5764 yylsp->first_line = yylloc.first_line;
5765 yylsp->first_column = yylloc.first_column;
5766 yylsp->last_line = (yylsp-1)->last_line;
5767 yylsp->last_column = (yylsp-1)->last_column;
5768 yylsp->text = 0;
5769 }
5770 else
5771 {
5772 yylsp->last_line = (yylsp+yylen-1)->last_line;
5773 yylsp->last_column = (yylsp+yylen-1)->last_column;
5774 }
5775#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005776
Dale Johannesen3afee192007-09-07 21:07:57 +00005777 /* Now "shift" the result of the reduction.
5778 Determine what state that goes to,
5779 based on the state we popped back to
5780 and the rule number reduced by. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005781
5782 yyn = yyr1[yyn];
5783
Dale Johannesen3afee192007-09-07 21:07:57 +00005784 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
5785 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005786 yystate = yytable[yystate];
5787 else
Dale Johannesen3afee192007-09-07 21:07:57 +00005788 yystate = yydefgoto[yyn - YYNTBASE];
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005789
5790 goto yynewstate;
5791
Dale Johannesen3afee192007-09-07 21:07:57 +00005792yyerrlab: /* here on detecting error */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005793
Dale Johannesen3afee192007-09-07 21:07:57 +00005794 if (! yyerrstatus)
5795 /* If not already recovering from an error, report this error. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005796 {
5797 ++yynerrs;
Dale Johannesen3afee192007-09-07 21:07:57 +00005798
5799#ifdef YYERROR_VERBOSE
David Greene48556392007-09-04 18:46:50 +00005800 yyn = yypact[yystate];
Chandler Carruth563d4a42007-08-04 01:56:21 +00005801
Dale Johannesen3afee192007-09-07 21:07:57 +00005802 if (yyn > YYFLAG && yyn < YYLAST)
David Greene48556392007-09-04 18:46:50 +00005803 {
Dale Johannesen3afee192007-09-07 21:07:57 +00005804 int size = 0;
5805 char *msg;
5806 int x, count;
David Greene48556392007-09-04 18:46:50 +00005807
Dale Johannesen3afee192007-09-07 21:07:57 +00005808 count = 0;
5809 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
5810 for (x = (yyn < 0 ? -yyn : 0);
5811 x < (sizeof(yytname) / sizeof(char *)); x++)
5812 if (yycheck[x + yyn] == x)
5813 size += strlen(yytname[x]) + 15, count++;
5814 msg = (char *) malloc(size + 15);
5815 if (msg != 0)
David Greene48556392007-09-04 18:46:50 +00005816 {
Dale Johannesen3afee192007-09-07 21:07:57 +00005817 strcpy(msg, "parse error");
David Greene48556392007-09-04 18:46:50 +00005818
Dale Johannesen3afee192007-09-07 21:07:57 +00005819 if (count < 5)
David Greene48556392007-09-04 18:46:50 +00005820 {
Dale Johannesen3afee192007-09-07 21:07:57 +00005821 count = 0;
5822 for (x = (yyn < 0 ? -yyn : 0);
5823 x < (sizeof(yytname) / sizeof(char *)); x++)
5824 if (yycheck[x + yyn] == x)
David Greene48556392007-09-04 18:46:50 +00005825 {
Dale Johannesen3afee192007-09-07 21:07:57 +00005826 strcat(msg, count == 0 ? ", expecting `" : " or `");
5827 strcat(msg, yytname[x]);
5828 strcat(msg, "'");
5829 count++;
David Greene48556392007-09-04 18:46:50 +00005830 }
5831 }
Dale Johannesen3afee192007-09-07 21:07:57 +00005832 yyerror(msg);
5833 free(msg);
David Greene48556392007-09-04 18:46:50 +00005834 }
5835 else
Dale Johannesen3afee192007-09-07 21:07:57 +00005836 yyerror ("parse error; also virtual memory exceeded");
David Greene48556392007-09-04 18:46:50 +00005837 }
5838 else
5839#endif /* YYERROR_VERBOSE */
Dale Johannesen3afee192007-09-07 21:07:57 +00005840 yyerror("parse error");
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005841 }
5842
Dale Johannesen3afee192007-09-07 21:07:57 +00005843 goto yyerrlab1;
5844yyerrlab1: /* here on error raised explicitly by an action */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005845
5846 if (yyerrstatus == 3)
5847 {
Dale Johannesen3afee192007-09-07 21:07:57 +00005848 /* if just tried and failed to reuse lookahead token after an error, discard it. */
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005849
Dale Johannesen3afee192007-09-07 21:07:57 +00005850 /* return failure if at end of input */
5851 if (yychar == YYEOF)
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005852 YYABORT;
5853
Dale Johannesen3afee192007-09-07 21:07:57 +00005854#if YYDEBUG != 0
5855 if (yydebug)
5856 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
5857#endif
5858
5859 yychar = YYEMPTY;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005860 }
5861
Dale Johannesen3afee192007-09-07 21:07:57 +00005862 /* Else will try to reuse lookahead token
5863 after shifting the error token. */
5864
5865 yyerrstatus = 3; /* Each real token shifted decrements this */
5866
5867 goto yyerrhandle;
5868
5869yyerrdefault: /* current state does not do anything special for the error token. */
5870
5871#if 0
5872 /* This is wrong; only states that explicitly want error tokens
5873 should shift them. */
5874 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
5875 if (yyn) goto yydefault;
5876#endif
5877
5878yyerrpop: /* pop the current state because it cannot handle the error token */
5879
5880 if (yyssp == yyss) YYABORT;
5881 yyvsp--;
5882 yystate = *--yyssp;
5883#ifdef YYLSP_NEEDED
5884 yylsp--;
5885#endif
5886
5887#if YYDEBUG != 0
5888 if (yydebug)
5889 {
5890 short *ssp1 = yyss - 1;
5891 fprintf (stderr, "Error: state stack now");
5892 while (ssp1 != yyssp)
5893 fprintf (stderr, " %d", *++ssp1);
5894 fprintf (stderr, "\n");
5895 }
5896#endif
5897
5898yyerrhandle:
5899
5900 yyn = yypact[yystate];
5901 if (yyn == YYFLAG)
5902 goto yyerrdefault;
5903
5904 yyn += YYTERROR;
5905 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
5906 goto yyerrdefault;
5907
5908 yyn = yytable[yyn];
5909 if (yyn < 0)
5910 {
5911 if (yyn == YYFLAG)
5912 goto yyerrpop;
5913 yyn = -yyn;
5914 goto yyreduce;
5915 }
5916 else if (yyn == 0)
5917 goto yyerrpop;
5918
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005919 if (yyn == YYFINAL)
5920 YYACCEPT;
5921
Dale Johannesen3afee192007-09-07 21:07:57 +00005922#if YYDEBUG != 0
5923 if (yydebug)
5924 fprintf(stderr, "Shifting error token, ");
5925#endif
David Greene48556392007-09-04 18:46:50 +00005926
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005927 *++yyvsp = yylval;
Dale Johannesen3afee192007-09-07 21:07:57 +00005928#ifdef YYLSP_NEEDED
5929 *++yylsp = yylloc;
5930#endif
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005931
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005932 yystate = yyn;
5933 goto yynewstate;
5934
Dale Johannesen3afee192007-09-07 21:07:57 +00005935 yyacceptlab:
5936 /* YYACCEPT comes here. */
5937 if (yyfree_stacks)
5938 {
5939 free (yyss);
5940 free (yyvs);
5941#ifdef YYLSP_NEEDED
5942 free (yyls);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005943#endif
Dale Johannesen3afee192007-09-07 21:07:57 +00005944 }
5945 return 0;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005946
Dale Johannesen3afee192007-09-07 21:07:57 +00005947 yyabortlab:
5948 /* YYABORT comes here. */
5949 if (yyfree_stacks)
5950 {
5951 free (yyss);
5952 free (yyvs);
5953#ifdef YYLSP_NEEDED
5954 free (yyls);
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005955#endif
Dale Johannesen3afee192007-09-07 21:07:57 +00005956 }
5957 return 1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005958}
Dale Johannesen3afee192007-09-07 21:07:57 +00005959#line 3911 "/Volumes/MacOS9/gcc/llvm/tools/llvm-upgrade/UpgradeParser.y"
Dan Gohmanf17a25c2007-07-18 16:29:46 +00005960
5961
5962int yyerror(const char *ErrorMsg) {
5963 std::string where
5964 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
5965 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
5966 std::string errMsg = where + "error: " + std::string(ErrorMsg);
5967 if (yychar != YYEMPTY && yychar != 0)
5968 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
5969 "'.";
5970 std::cerr << "llvm-upgrade: " << errMsg << '\n';
5971 std::cout << "llvm-upgrade: parse failed.\n";
5972 exit(1);
5973}
5974
5975void warning(const std::string& ErrorMsg) {
5976 std::string where
5977 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
5978 + ":" + llvm::utostr((unsigned) Upgradelineno) + ": ";
5979 std::string errMsg = where + "warning: " + std::string(ErrorMsg);
5980 if (yychar != YYEMPTY && yychar != 0)
5981 errMsg += " while reading token '" + std::string(Upgradetext, Upgradeleng) +
5982 "'.";
5983 std::cerr << "llvm-upgrade: " << errMsg << '\n';
5984}
5985
5986void error(const std::string& ErrorMsg, int LineNo) {
5987 if (LineNo == -1) LineNo = Upgradelineno;
5988 Upgradelineno = LineNo;
5989 yyerror(ErrorMsg.c_str());
5990}
5991