blob: 488d93e2b50c161ff46394bf40d2140c4d18cb50 [file] [log] [blame]
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001
Chris Lattnerff20ba32006-10-15 23:27:25 +00002/* A Bison parser, made from /Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y
3 by GNU Bison version 1.28 */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004
Chris Lattnerff20ba32006-10-15 23:27:25 +00005#define YYBISON 1 /* Identify Bison output. */
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00006
Reid Spencerdfb3fb42005-08-27 18:50:39 +00007#define yyparse llvmAsmparse
Chris Lattnerff20ba32006-10-15 23:27:25 +00008#define yylex llvmAsmlex
Reid Spencerdfb3fb42005-08-27 18:50:39 +00009#define yyerror llvmAsmerror
Chris Lattnerff20ba32006-10-15 23:27:25 +000010#define yylval llvmAsmlval
11#define yychar llvmAsmchar
Reid Spencerdfb3fb42005-08-27 18:50:39 +000012#define yydebug llvmAsmdebug
13#define yynerrs llvmAsmnerrs
Chris Lattnerff20ba32006-10-15 23:27:25 +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 RET 325
83#define BR 326
84#define SWITCH 327
85#define INVOKE 328
86#define UNWIND 329
87#define UNREACHABLE 330
88#define ADD 331
89#define SUB 332
90#define MUL 333
91#define DIV 334
92#define REM 335
93#define AND 336
94#define OR 337
95#define XOR 338
96#define SETLE 339
97#define SETGE 340
98#define SETLT 341
99#define SETGT 342
100#define SETEQ 343
101#define SETNE 344
102#define MALLOC 345
103#define ALLOCA 346
104#define FREE 347
105#define LOAD 348
106#define STORE 349
107#define GETELEMENTPTR 350
108#define PHI_TOK 351
109#define CAST 352
110#define SELECT 353
111#define SHL 354
112#define SHR 355
113#define VAARG 356
114#define EXTRACTELEMENT 357
115#define INSERTELEMENT 358
116#define SHUFFLEVECTOR 359
117#define VAARG_old 360
118#define VANEXT_old 361
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000119
Chris Lattnerff20ba32006-10-15 23:27:25 +0000120#line 14 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000121
122#include "ParserInternals.h"
123#include "llvm/CallingConv.h"
Chris Lattnere0a4ee92006-01-25 22:27:16 +0000124#include "llvm/InlineAsm.h"
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000125#include "llvm/Instructions.h"
126#include "llvm/Module.h"
127#include "llvm/SymbolTable.h"
Reid Spencerb4f9a6f2006-01-16 21:12:35 +0000128#include "llvm/Assembly/AutoUpgrade.h"
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000129#include "llvm/Support/GetElementPtrTypeIterator.h"
130#include "llvm/ADT/STLExtras.h"
Chris Lattner840f7892005-11-06 06:46:53 +0000131#include "llvm/Support/MathExtras.h"
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000132#include <algorithm>
133#include <iostream>
134#include <list>
135#include <utility>
136
Reid Spencerb50974a2006-08-18 17:32:55 +0000137// The following is a gross hack. In order to rid the libAsmParser library of
138// exceptions, we have to have a way of getting the yyparse function to go into
139// an error situation. So, whenever we want an error to occur, the GenerateError
140// function (see bottom of file) sets TriggerError. Then, at the end of each
141// production in the grammer we use CHECK_FOR_ERROR which will invoke YYERROR
142// (a goto) to put YACC in error state. Furthermore, several calls to
143// GenerateError are made from inside productions and they must simulate the
144// previous exception behavior by exiting the production immediately. We have
145// replaced these with the GEN_ERROR macro which calls GeneratError and then
146// immediately invokes YYERROR. This would be so much cleaner if it was a
147// recursive descent parser.
Reid Spencer713eedc2006-08-18 08:43:06 +0000148static bool TriggerError = false;
Reid Spencerff359002006-10-09 17:36:59 +0000149#define CHECK_FOR_ERROR { if (TriggerError) { TriggerError = false; YYABORT; } }
Reid Spencer713eedc2006-08-18 08:43:06 +0000150#define GEN_ERROR(msg) { GenerateError(msg); YYERROR; }
151
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000152int yyerror(const char *ErrorMsg); // Forward declarations to prevent "implicit
153int yylex(); // declaration" of xxx warnings.
154int yyparse();
155
156namespace llvm {
157 std::string CurFilename;
158}
159using namespace llvm;
160
161static Module *ParserResult;
162
163// DEBUG_UPREFS - Define this symbol if you want to enable debugging output
164// relating to upreferences in the input stream.
165//
166//#define DEBUG_UPREFS 1
167#ifdef DEBUG_UPREFS
168#define UR_OUT(X) std::cerr << X
169#else
170#define UR_OUT(X)
171#endif
172
173#define YYERROR_VERBOSE 1
174
175static bool ObsoleteVarArgs;
176static bool NewVarArgs;
Chris Lattner11ca4d62005-11-12 18:22:38 +0000177static BasicBlock *CurBB;
178static GlobalVariable *CurGV;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000179
180
181// This contains info used when building the body of a function. It is
182// destroyed when the function is completed.
183//
184typedef std::vector<Value *> ValueList; // Numbered defs
185static void
186ResolveDefinitions(std::map<const Type *,ValueList> &LateResolvers,
187 std::map<const Type *,ValueList> *FutureLateResolvers = 0);
188
189static struct PerModuleInfo {
190 Module *CurrentModule;
191 std::map<const Type *, ValueList> Values; // Module level numbered definitions
192 std::map<const Type *,ValueList> LateResolveValues;
193 std::vector<PATypeHolder> Types;
194 std::map<ValID, PATypeHolder> LateResolveTypes;
195
196 /// PlaceHolderInfo - When temporary placeholder objects are created, remember
Chris Lattner7aa45902006-06-21 16:53:00 +0000197 /// how they were referenced and on which line of the input they came from so
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000198 /// that we can resolve them later and print error messages as appropriate.
199 std::map<Value*, std::pair<ValID, int> > PlaceHolderInfo;
200
201 // GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
202 // references to global values. Global values may be referenced before they
203 // are defined, and if so, the temporary object that they represent is held
204 // here. This is used for forward references of GlobalValues.
205 //
206 typedef std::map<std::pair<const PointerType *,
207 ValID>, GlobalValue*> GlobalRefsType;
208 GlobalRefsType GlobalRefs;
209
210 void ModuleDone() {
211 // If we could not resolve some functions at function compilation time
212 // (calls to functions before they are defined), resolve them now... Types
213 // are resolved when the constant pool has been completely parsed.
214 //
215 ResolveDefinitions(LateResolveValues);
Reid Spencer309080a2006-09-28 19:28:24 +0000216 if (TriggerError)
217 return;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000218
219 // Check to make sure that all global value forward references have been
220 // resolved!
221 //
222 if (!GlobalRefs.empty()) {
223 std::string UndefinedReferences = "Unresolved global references exist:\n";
224
225 for (GlobalRefsType::iterator I = GlobalRefs.begin(), E =GlobalRefs.end();
226 I != E; ++I) {
227 UndefinedReferences += " " + I->first.first->getDescription() + " " +
228 I->first.second.getName() + "\n";
229 }
Reid Spencer713eedc2006-08-18 08:43:06 +0000230 GenerateError(UndefinedReferences);
Reid Spencer309080a2006-09-28 19:28:24 +0000231 return;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000232 }
233
Reid Spencerc8a9faf2006-01-19 01:21:04 +0000234 // Look for intrinsic functions and CallInst that need to be upgraded
Chris Lattner9ff96a72006-04-08 01:18:56 +0000235 for (Module::iterator FI = CurrentModule->begin(),
236 FE = CurrentModule->end(); FI != FE; )
Chris Lattneradf5ec62006-03-04 07:53:41 +0000237 UpgradeCallsToIntrinsic(FI++);
Reid Spencerb4f9a6f2006-01-16 21:12:35 +0000238
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000239 Values.clear(); // Clear out function local definitions
240 Types.clear();
241 CurrentModule = 0;
242 }
243
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000244 // GetForwardRefForGlobal - Check to see if there is a forward reference
245 // for this global. If so, remove it from the GlobalRefs map and return it.
246 // If not, just return null.
247 GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ValID ID) {
248 // Check to see if there is a forward reference to this global variable...
249 // if there is, eliminate it and patch the reference to use the new def'n.
250 GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PTy, ID));
251 GlobalValue *Ret = 0;
252 if (I != GlobalRefs.end()) {
253 Ret = I->second;
254 GlobalRefs.erase(I);
255 }
256 return Ret;
257 }
258} CurModule;
259
260static struct PerFunctionInfo {
261 Function *CurrentFunction; // Pointer to current function being created
262
Anton Korobeynikov73441cd2006-09-14 18:25:26 +0000263 std::map<const Type*, ValueList> Values; // Keep track of #'d definitions
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000264 std::map<const Type*, ValueList> LateResolveValues;
Anton Korobeynikov73441cd2006-09-14 18:25:26 +0000265 bool isDeclare; // Is this function a forward declararation?
266 GlobalValue::LinkageTypes Linkage; // Linkage for forward declaration.
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000267
268 /// BBForwardRefs - When we see forward references to basic blocks, keep
269 /// track of them here.
270 std::map<BasicBlock*, std::pair<ValID, int> > BBForwardRefs;
271 std::vector<BasicBlock*> NumberedBlocks;
272 unsigned NextBBNum;
273
274 inline PerFunctionInfo() {
275 CurrentFunction = 0;
276 isDeclare = false;
Anton Korobeynikov73441cd2006-09-14 18:25:26 +0000277 Linkage = GlobalValue::ExternalLinkage;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000278 }
279
280 inline void FunctionStart(Function *M) {
281 CurrentFunction = M;
282 NextBBNum = 0;
283 }
284
285 void FunctionDone() {
286 NumberedBlocks.clear();
287
288 // Any forward referenced blocks left?
Reid Spencer309080a2006-09-28 19:28:24 +0000289 if (!BBForwardRefs.empty()) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000290 GenerateError("Undefined reference to label " +
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000291 BBForwardRefs.begin()->first->getName());
Reid Spencer309080a2006-09-28 19:28:24 +0000292 return;
293 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000294
295 // Resolve all forward references now.
296 ResolveDefinitions(LateResolveValues, &CurModule.LateResolveValues);
297
298 Values.clear(); // Clear out function local definitions
299 CurrentFunction = 0;
300 isDeclare = false;
Anton Korobeynikov73441cd2006-09-14 18:25:26 +0000301 Linkage = GlobalValue::ExternalLinkage;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000302 }
303} CurFun; // Info for the current function...
304
305static bool inFunctionScope() { return CurFun.CurrentFunction != 0; }
306
307
308//===----------------------------------------------------------------------===//
309// Code to handle definitions of all the types
310//===----------------------------------------------------------------------===//
311
312static int InsertValue(Value *V,
313 std::map<const Type*,ValueList> &ValueTab = CurFun.Values) {
314 if (V->hasName()) return -1; // Is this a numbered definition?
315
316 // Yes, insert the value into the value table...
317 ValueList &List = ValueTab[V->getType()];
318 List.push_back(V);
319 return List.size()-1;
320}
321
322static const Type *getTypeVal(const ValID &D, bool DoNotImprovise = false) {
323 switch (D.Type) {
324 case ValID::NumberVal: // Is it a numbered definition?
325 // Module constants occupy the lowest numbered slots...
326 if ((unsigned)D.Num < CurModule.Types.size())
327 return CurModule.Types[(unsigned)D.Num];
328 break;
329 case ValID::NameVal: // Is it a named definition?
330 if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) {
331 D.destroy(); // Free old strdup'd memory...
332 return N;
333 }
334 break;
335 default:
Reid Spencer713eedc2006-08-18 08:43:06 +0000336 GenerateError("Internal parser error: Invalid symbol type reference!");
Reid Spencer309080a2006-09-28 19:28:24 +0000337 return 0;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000338 }
339
340 // If we reached here, we referenced either a symbol that we don't know about
341 // or an id number that hasn't been read yet. We may be referencing something
342 // forward, so just create an entry to be resolved later and get to it...
343 //
344 if (DoNotImprovise) return 0; // Do we just want a null to be returned?
345
346
347 if (inFunctionScope()) {
Reid Spencer309080a2006-09-28 19:28:24 +0000348 if (D.Type == ValID::NameVal) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000349 GenerateError("Reference to an undefined type: '" + D.getName() + "'");
Reid Spencer309080a2006-09-28 19:28:24 +0000350 return 0;
351 } else {
Reid Spencer713eedc2006-08-18 08:43:06 +0000352 GenerateError("Reference to an undefined type: #" + itostr(D.Num));
Reid Spencer309080a2006-09-28 19:28:24 +0000353 return 0;
354 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000355 }
356
357 std::map<ValID, PATypeHolder>::iterator I =CurModule.LateResolveTypes.find(D);
358 if (I != CurModule.LateResolveTypes.end())
359 return I->second;
360
361 Type *Typ = OpaqueType::get();
362 CurModule.LateResolveTypes.insert(std::make_pair(D, Typ));
363 return Typ;
364 }
365
366static Value *lookupInSymbolTable(const Type *Ty, const std::string &Name) {
367 SymbolTable &SymTab =
368 inFunctionScope() ? CurFun.CurrentFunction->getSymbolTable() :
369 CurModule.CurrentModule->getSymbolTable();
370 return SymTab.lookup(Ty, Name);
371}
372
373// getValNonImprovising - Look up the value specified by the provided type and
374// the provided ValID. If the value exists and has already been defined, return
375// it. Otherwise return null.
376//
377static Value *getValNonImprovising(const Type *Ty, const ValID &D) {
Reid Spencer309080a2006-09-28 19:28:24 +0000378 if (isa<FunctionType>(Ty)) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000379 GenerateError("Functions are not values and "
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000380 "must be referenced as pointers");
Reid Spencer309080a2006-09-28 19:28:24 +0000381 return 0;
382 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000383
384 switch (D.Type) {
385 case ValID::NumberVal: { // Is it a numbered definition?
386 unsigned Num = (unsigned)D.Num;
387
388 // Module constants occupy the lowest numbered slots...
389 std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
390 if (VI != CurModule.Values.end()) {
391 if (Num < VI->second.size())
392 return VI->second[Num];
393 Num -= VI->second.size();
394 }
395
396 // Make sure that our type is within bounds
397 VI = CurFun.Values.find(Ty);
398 if (VI == CurFun.Values.end()) return 0;
399
400 // Check that the number is within bounds...
401 if (VI->second.size() <= Num) return 0;
402
403 return VI->second[Num];
404 }
405
406 case ValID::NameVal: { // Is it a named definition?
407 Value *N = lookupInSymbolTable(Ty, std::string(D.Name));
408 if (N == 0) return 0;
409
410 D.destroy(); // Free old strdup'd memory...
411 return N;
412 }
413
414 // Check to make sure that "Ty" is an integral type, and that our
415 // value will fit into the specified type...
416 case ValID::ConstSIntVal: // Is it a constant pool reference??
Reid Spencer309080a2006-09-28 19:28:24 +0000417 if (!ConstantSInt::isValueValidForType(Ty, D.ConstPool64)) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000418 GenerateError("Signed integral constant '" +
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000419 itostr(D.ConstPool64) + "' is invalid for type '" +
420 Ty->getDescription() + "'!");
Reid Spencer309080a2006-09-28 19:28:24 +0000421 return 0;
422 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000423 return ConstantSInt::get(Ty, D.ConstPool64);
424
425 case ValID::ConstUIntVal: // Is it an unsigned const pool reference?
426 if (!ConstantUInt::isValueValidForType(Ty, D.UConstPool64)) {
427 if (!ConstantSInt::isValueValidForType(Ty, D.ConstPool64)) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000428 GenerateError("Integral constant '" + utostr(D.UConstPool64) +
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000429 "' is invalid or out of range!");
Reid Spencer309080a2006-09-28 19:28:24 +0000430 return 0;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000431 } else { // This is really a signed reference. Transmogrify.
432 return ConstantSInt::get(Ty, D.ConstPool64);
433 }
434 } else {
435 return ConstantUInt::get(Ty, D.UConstPool64);
436 }
437
438 case ValID::ConstFPVal: // Is it a floating point const pool reference?
Reid Spencer309080a2006-09-28 19:28:24 +0000439 if (!ConstantFP::isValueValidForType(Ty, D.ConstPoolFP)) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000440 GenerateError("FP constant invalid for type!!");
Reid Spencer309080a2006-09-28 19:28:24 +0000441 return 0;
442 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000443 return ConstantFP::get(Ty, D.ConstPoolFP);
444
445 case ValID::ConstNullVal: // Is it a null value?
Reid Spencer309080a2006-09-28 19:28:24 +0000446 if (!isa<PointerType>(Ty)) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000447 GenerateError("Cannot create a a non pointer null!");
Reid Spencer309080a2006-09-28 19:28:24 +0000448 return 0;
449 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000450 return ConstantPointerNull::get(cast<PointerType>(Ty));
451
452 case ValID::ConstUndefVal: // Is it an undef value?
453 return UndefValue::get(Ty);
454
Chris Lattnera054d122005-12-21 17:53:23 +0000455 case ValID::ConstZeroVal: // Is it a zero value?
456 return Constant::getNullValue(Ty);
457
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000458 case ValID::ConstantVal: // Fully resolved constant?
Reid Spencer309080a2006-09-28 19:28:24 +0000459 if (D.ConstantValue->getType() != Ty) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000460 GenerateError("Constant expression type different from required type!");
Reid Spencer309080a2006-09-28 19:28:24 +0000461 return 0;
462 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000463 return D.ConstantValue;
464
Chris Lattnere0a4ee92006-01-25 22:27:16 +0000465 case ValID::InlineAsmVal: { // Inline asm expression
466 const PointerType *PTy = dyn_cast<PointerType>(Ty);
467 const FunctionType *FTy =
468 PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
Reid Spencer309080a2006-09-28 19:28:24 +0000469 if (!FTy || !InlineAsm::Verify(FTy, D.IAD->Constraints)) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000470 GenerateError("Invalid type for asm constraint string!");
Reid Spencer309080a2006-09-28 19:28:24 +0000471 return 0;
472 }
Chris Lattnere0a4ee92006-01-25 22:27:16 +0000473 InlineAsm *IA = InlineAsm::get(FTy, D.IAD->AsmString, D.IAD->Constraints,
474 D.IAD->HasSideEffects);
475 D.destroy(); // Free InlineAsmDescriptor.
476 return IA;
477 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000478 default:
479 assert(0 && "Unhandled case!");
480 return 0;
481 } // End of switch
482
483 assert(0 && "Unhandled case!");
484 return 0;
485}
486
487// getVal - This function is identical to getValNonImprovising, except that if a
488// value is not already defined, it "improvises" by creating a placeholder var
489// that looks and acts just like the requested variable. When the value is
490// defined later, all uses of the placeholder variable are replaced with the
491// real thing.
492//
493static Value *getVal(const Type *Ty, const ValID &ID) {
Reid Spencer309080a2006-09-28 19:28:24 +0000494 if (Ty == Type::LabelTy) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000495 GenerateError("Cannot use a basic block here");
Reid Spencer309080a2006-09-28 19:28:24 +0000496 return 0;
497 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000498
499 // See if the value has already been defined.
500 Value *V = getValNonImprovising(Ty, ID);
501 if (V) return V;
Reid Spencer309080a2006-09-28 19:28:24 +0000502 if (TriggerError) return 0;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000503
Reid Spencer309080a2006-09-28 19:28:24 +0000504 if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty)) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000505 GenerateError("Invalid use of a composite type!");
Reid Spencer309080a2006-09-28 19:28:24 +0000506 return 0;
507 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000508
509 // If we reached here, we referenced either a symbol that we don't know about
510 // or an id number that hasn't been read yet. We may be referencing something
511 // forward, so just create an entry to be resolved later and get to it...
512 //
513 V = new Argument(Ty);
514
515 // Remember where this forward reference came from. FIXME, shouldn't we try
516 // to recycle these things??
517 CurModule.PlaceHolderInfo.insert(std::make_pair(V, std::make_pair(ID,
518 llvmAsmlineno)));
519
520 if (inFunctionScope())
521 InsertValue(V, CurFun.LateResolveValues);
522 else
523 InsertValue(V, CurModule.LateResolveValues);
524 return V;
525}
526
527/// getBBVal - This is used for two purposes:
528/// * If isDefinition is true, a new basic block with the specified ID is being
529/// defined.
530/// * If isDefinition is true, this is a reference to a basic block, which may
531/// or may not be a forward reference.
532///
533static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
534 assert(inFunctionScope() && "Can't get basic block at global scope!");
535
536 std::string Name;
537 BasicBlock *BB = 0;
538 switch (ID.Type) {
Reid Spencer309080a2006-09-28 19:28:24 +0000539 default:
540 GenerateError("Illegal label reference " + ID.getName());
541 return 0;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000542 case ValID::NumberVal: // Is it a numbered definition?
543 if (unsigned(ID.Num) >= CurFun.NumberedBlocks.size())
544 CurFun.NumberedBlocks.resize(ID.Num+1);
545 BB = CurFun.NumberedBlocks[ID.Num];
546 break;
547 case ValID::NameVal: // Is it a named definition?
548 Name = ID.Name;
549 if (Value *N = CurFun.CurrentFunction->
550 getSymbolTable().lookup(Type::LabelTy, Name))
551 BB = cast<BasicBlock>(N);
552 break;
553 }
554
555 // See if the block has already been defined.
556 if (BB) {
557 // If this is the definition of the block, make sure the existing value was
558 // just a forward reference. If it was a forward reference, there will be
559 // an entry for it in the PlaceHolderInfo map.
Reid Spencer309080a2006-09-28 19:28:24 +0000560 if (isDefinition && !CurFun.BBForwardRefs.erase(BB)) {
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000561 // The existing value was a definition, not a forward reference.
Reid Spencer713eedc2006-08-18 08:43:06 +0000562 GenerateError("Redefinition of label " + ID.getName());
Reid Spencer309080a2006-09-28 19:28:24 +0000563 return 0;
564 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000565
566 ID.destroy(); // Free strdup'd memory.
567 return BB;
568 }
569
570 // Otherwise this block has not been seen before.
571 BB = new BasicBlock("", CurFun.CurrentFunction);
572 if (ID.Type == ValID::NameVal) {
573 BB->setName(ID.Name);
574 } else {
575 CurFun.NumberedBlocks[ID.Num] = BB;
576 }
577
578 // If this is not a definition, keep track of it so we can use it as a forward
579 // reference.
580 if (!isDefinition) {
581 // Remember where this forward reference came from.
582 CurFun.BBForwardRefs[BB] = std::make_pair(ID, llvmAsmlineno);
583 } else {
584 // The forward declaration could have been inserted anywhere in the
585 // function: insert it into the correct place now.
586 CurFun.CurrentFunction->getBasicBlockList().remove(BB);
587 CurFun.CurrentFunction->getBasicBlockList().push_back(BB);
588 }
589 ID.destroy();
590 return BB;
591}
592
593
594//===----------------------------------------------------------------------===//
595// Code to handle forward references in instructions
596//===----------------------------------------------------------------------===//
597//
598// This code handles the late binding needed with statements that reference
599// values not defined yet... for example, a forward branch, or the PHI node for
600// a loop body.
601//
602// This keeps a table (CurFun.LateResolveValues) of all such forward references
603// and back patchs after we are done.
604//
605
606// ResolveDefinitions - If we could not resolve some defs at parsing
607// time (forward branches, phi functions for loops, etc...) resolve the
608// defs now...
609//
610static void
611ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
612 std::map<const Type*,ValueList> *FutureLateResolvers) {
613 // Loop over LateResolveDefs fixing up stuff that couldn't be resolved
614 for (std::map<const Type*,ValueList>::iterator LRI = LateResolvers.begin(),
615 E = LateResolvers.end(); LRI != E; ++LRI) {
616 ValueList &List = LRI->second;
617 while (!List.empty()) {
618 Value *V = List.back();
619 List.pop_back();
620
621 std::map<Value*, std::pair<ValID, int> >::iterator PHI =
622 CurModule.PlaceHolderInfo.find(V);
623 assert(PHI != CurModule.PlaceHolderInfo.end() && "Placeholder error!");
624
625 ValID &DID = PHI->second.first;
626
627 Value *TheRealValue = getValNonImprovising(LRI->first, DID);
Reid Spencer309080a2006-09-28 19:28:24 +0000628 if (TriggerError)
629 return;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000630 if (TheRealValue) {
631 V->replaceAllUsesWith(TheRealValue);
632 delete V;
633 CurModule.PlaceHolderInfo.erase(PHI);
634 } else if (FutureLateResolvers) {
635 // Functions have their unresolved items forwarded to the module late
636 // resolver table
637 InsertValue(V, *FutureLateResolvers);
638 } else {
Reid Spencer309080a2006-09-28 19:28:24 +0000639 if (DID.Type == ValID::NameVal) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000640 GenerateError("Reference to an invalid definition: '" +DID.getName()+
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000641 "' of type '" + V->getType()->getDescription() + "'",
642 PHI->second.second);
Reid Spencer309080a2006-09-28 19:28:24 +0000643 return;
644 } else {
Reid Spencer713eedc2006-08-18 08:43:06 +0000645 GenerateError("Reference to an invalid definition: #" +
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000646 itostr(DID.Num) + " of type '" +
647 V->getType()->getDescription() + "'",
648 PHI->second.second);
Reid Spencer309080a2006-09-28 19:28:24 +0000649 return;
650 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000651 }
652 }
653 }
654
655 LateResolvers.clear();
656}
657
658// ResolveTypeTo - A brand new type was just declared. This means that (if
659// name is not null) things referencing Name can be resolved. Otherwise, things
660// refering to the number can be resolved. Do this now.
661//
662static void ResolveTypeTo(char *Name, const Type *ToTy) {
663 ValID D;
664 if (Name) D = ValID::create(Name);
665 else D = ValID::create((int)CurModule.Types.size());
666
667 std::map<ValID, PATypeHolder>::iterator I =
668 CurModule.LateResolveTypes.find(D);
669 if (I != CurModule.LateResolveTypes.end()) {
670 ((DerivedType*)I->second.get())->refineAbstractTypeTo(ToTy);
671 CurModule.LateResolveTypes.erase(I);
672 }
673}
674
675// setValueName - Set the specified value to the name given. The name may be
676// null potentially, in which case this is a noop. The string passed in is
677// assumed to be a malloc'd string buffer, and is free'd by this function.
678//
679static void setValueName(Value *V, char *NameStr) {
680 if (NameStr) {
681 std::string Name(NameStr); // Copy string
682 free(NameStr); // Free old string
683
Reid Spencer309080a2006-09-28 19:28:24 +0000684 if (V->getType() == Type::VoidTy) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000685 GenerateError("Can't assign name '" + Name+"' to value with void type!");
Reid Spencer309080a2006-09-28 19:28:24 +0000686 return;
687 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000688
689 assert(inFunctionScope() && "Must be in function scope!");
690 SymbolTable &ST = CurFun.CurrentFunction->getSymbolTable();
Reid Spencer309080a2006-09-28 19:28:24 +0000691 if (ST.lookup(V->getType(), Name)) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000692 GenerateError("Redefinition of value named '" + Name + "' in the '" +
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000693 V->getType()->getDescription() + "' type plane!");
Reid Spencer309080a2006-09-28 19:28:24 +0000694 return;
695 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000696
697 // Set the name.
698 V->setName(Name);
699 }
700}
701
702/// ParseGlobalVariable - Handle parsing of a global. If Initializer is null,
703/// this is a declaration, otherwise it is a definition.
Chris Lattner11ca4d62005-11-12 18:22:38 +0000704static GlobalVariable *
705ParseGlobalVariable(char *NameStr,GlobalValue::LinkageTypes Linkage,
706 bool isConstantGlobal, const Type *Ty,
707 Constant *Initializer) {
Reid Spencer309080a2006-09-28 19:28:24 +0000708 if (isa<FunctionType>(Ty)) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000709 GenerateError("Cannot declare global vars of function type!");
Reid Spencer309080a2006-09-28 19:28:24 +0000710 return 0;
711 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000712
713 const PointerType *PTy = PointerType::get(Ty);
714
715 std::string Name;
716 if (NameStr) {
717 Name = NameStr; // Copy string
718 free(NameStr); // Free old string
719 }
720
721 // See if this global value was forward referenced. If so, recycle the
722 // object.
723 ValID ID;
724 if (!Name.empty()) {
725 ID = ValID::create((char*)Name.c_str());
726 } else {
727 ID = ValID::create((int)CurModule.Values[PTy].size());
728 }
729
730 if (GlobalValue *FWGV = CurModule.GetForwardRefForGlobal(PTy, ID)) {
731 // Move the global to the end of the list, from whereever it was
732 // previously inserted.
733 GlobalVariable *GV = cast<GlobalVariable>(FWGV);
734 CurModule.CurrentModule->getGlobalList().remove(GV);
735 CurModule.CurrentModule->getGlobalList().push_back(GV);
736 GV->setInitializer(Initializer);
737 GV->setLinkage(Linkage);
738 GV->setConstant(isConstantGlobal);
739 InsertValue(GV, CurModule.Values);
Chris Lattner11ca4d62005-11-12 18:22:38 +0000740 return GV;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000741 }
742
743 // If this global has a name, check to see if there is already a definition
744 // of this global in the module. If so, merge as appropriate. Note that
745 // this is really just a hack around problems in the CFE. :(
746 if (!Name.empty()) {
747 // We are a simple redefinition of a value, check to see if it is defined
748 // the same as the old one.
749 if (GlobalVariable *EGV =
750 CurModule.CurrentModule->getGlobalVariable(Name, Ty)) {
751 // We are allowed to redefine a global variable in two circumstances:
752 // 1. If at least one of the globals is uninitialized or
753 // 2. If both initializers have the same value.
754 //
755 if (!EGV->hasInitializer() || !Initializer ||
756 EGV->getInitializer() == Initializer) {
757
758 // Make sure the existing global version gets the initializer! Make
759 // sure that it also gets marked const if the new version is.
760 if (Initializer && !EGV->hasInitializer())
761 EGV->setInitializer(Initializer);
762 if (isConstantGlobal)
763 EGV->setConstant(true);
764 EGV->setLinkage(Linkage);
Chris Lattner11ca4d62005-11-12 18:22:38 +0000765 return EGV;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000766 }
767
Reid Spencer713eedc2006-08-18 08:43:06 +0000768 GenerateError("Redefinition of global variable named '" + Name +
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000769 "' in the '" + Ty->getDescription() + "' type plane!");
Reid Spencer309080a2006-09-28 19:28:24 +0000770 return 0;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000771 }
772 }
773
774 // Otherwise there is no existing GV to use, create one now.
775 GlobalVariable *GV =
776 new GlobalVariable(Ty, isConstantGlobal, Linkage, Initializer, Name,
777 CurModule.CurrentModule);
778 InsertValue(GV, CurModule.Values);
Chris Lattner11ca4d62005-11-12 18:22:38 +0000779 return GV;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000780}
781
782// setTypeName - Set the specified type to the name given. The name may be
783// null potentially, in which case this is a noop. The string passed in is
784// assumed to be a malloc'd string buffer, and is freed by this function.
785//
786// This function returns true if the type has already been defined, but is
787// allowed to be redefined in the specified context. If the name is a new name
788// for the type plane, it is inserted and false is returned.
789static bool setTypeName(const Type *T, char *NameStr) {
790 assert(!inFunctionScope() && "Can't give types function-local names!");
791 if (NameStr == 0) return false;
792
793 std::string Name(NameStr); // Copy string
794 free(NameStr); // Free old string
795
796 // We don't allow assigning names to void type
Reid Spencer309080a2006-09-28 19:28:24 +0000797 if (T == Type::VoidTy) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000798 GenerateError("Can't assign name '" + Name + "' to the void type!");
Reid Spencer309080a2006-09-28 19:28:24 +0000799 return false;
800 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000801
802 // Set the type name, checking for conflicts as we do so.
803 bool AlreadyExists = CurModule.CurrentModule->addTypeName(Name, T);
804
805 if (AlreadyExists) { // Inserting a name that is already defined???
806 const Type *Existing = CurModule.CurrentModule->getTypeByName(Name);
807 assert(Existing && "Conflict but no matching type?");
808
809 // There is only one case where this is allowed: when we are refining an
810 // opaque type. In this case, Existing will be an opaque type.
811 if (const OpaqueType *OpTy = dyn_cast<OpaqueType>(Existing)) {
812 // We ARE replacing an opaque type!
813 const_cast<OpaqueType*>(OpTy)->refineAbstractTypeTo(T);
814 return true;
815 }
816
817 // Otherwise, this is an attempt to redefine a type. That's okay if
818 // the redefinition is identical to the original. This will be so if
819 // Existing and T point to the same Type object. In this one case we
820 // allow the equivalent redefinition.
821 if (Existing == T) return true; // Yes, it's equal.
822
823 // Any other kind of (non-equivalent) redefinition is an error.
Reid Spencer713eedc2006-08-18 08:43:06 +0000824 GenerateError("Redefinition of type named '" + Name + "' in the '" +
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000825 T->getDescription() + "' type plane!");
826 }
827
828 return false;
829}
830
831//===----------------------------------------------------------------------===//
832// Code for handling upreferences in type names...
833//
834
835// TypeContains - Returns true if Ty directly contains E in it.
836//
837static bool TypeContains(const Type *Ty, const Type *E) {
838 return std::find(Ty->subtype_begin(), Ty->subtype_end(),
839 E) != Ty->subtype_end();
840}
841
842namespace {
843 struct UpRefRecord {
844 // NestingLevel - The number of nesting levels that need to be popped before
845 // this type is resolved.
846 unsigned NestingLevel;
847
848 // LastContainedTy - This is the type at the current binding level for the
849 // type. Every time we reduce the nesting level, this gets updated.
850 const Type *LastContainedTy;
851
852 // UpRefTy - This is the actual opaque type that the upreference is
853 // represented with.
854 OpaqueType *UpRefTy;
855
856 UpRefRecord(unsigned NL, OpaqueType *URTy)
857 : NestingLevel(NL), LastContainedTy(URTy), UpRefTy(URTy) {}
858 };
859}
860
861// UpRefs - A list of the outstanding upreferences that need to be resolved.
862static std::vector<UpRefRecord> UpRefs;
863
864/// HandleUpRefs - Every time we finish a new layer of types, this function is
865/// called. It loops through the UpRefs vector, which is a list of the
866/// currently active types. For each type, if the up reference is contained in
867/// the newly completed type, we decrement the level count. When the level
868/// count reaches zero, the upreferenced type is the type that is passed in:
869/// thus we can complete the cycle.
870///
871static PATypeHolder HandleUpRefs(const Type *ty) {
Chris Lattner680aab62006-08-18 17:34:45 +0000872 // If Ty isn't abstract, or if there are no up-references in it, then there is
873 // nothing to resolve here.
874 if (!ty->isAbstract() || UpRefs.empty()) return ty;
875
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000876 PATypeHolder Ty(ty);
877 UR_OUT("Type '" << Ty->getDescription() <<
878 "' newly formed. Resolving upreferences.\n" <<
879 UpRefs.size() << " upreferences active!\n");
880
881 // If we find any resolvable upreferences (i.e., those whose NestingLevel goes
882 // to zero), we resolve them all together before we resolve them to Ty. At
883 // the end of the loop, if there is anything to resolve to Ty, it will be in
884 // this variable.
885 OpaqueType *TypeToResolve = 0;
886
887 for (unsigned i = 0; i != UpRefs.size(); ++i) {
888 UR_OUT(" UR#" << i << " - TypeContains(" << Ty->getDescription() << ", "
889 << UpRefs[i].second->getDescription() << ") = "
890 << (TypeContains(Ty, UpRefs[i].second) ? "true" : "false") << "\n");
891 if (TypeContains(Ty, UpRefs[i].LastContainedTy)) {
892 // Decrement level of upreference
893 unsigned Level = --UpRefs[i].NestingLevel;
894 UpRefs[i].LastContainedTy = Ty;
895 UR_OUT(" Uplevel Ref Level = " << Level << "\n");
896 if (Level == 0) { // Upreference should be resolved!
897 if (!TypeToResolve) {
898 TypeToResolve = UpRefs[i].UpRefTy;
899 } else {
900 UR_OUT(" * Resolving upreference for "
901 << UpRefs[i].second->getDescription() << "\n";
902 std::string OldName = UpRefs[i].UpRefTy->getDescription());
903 UpRefs[i].UpRefTy->refineAbstractTypeTo(TypeToResolve);
904 UR_OUT(" * Type '" << OldName << "' refined upreference to: "
905 << (const void*)Ty << ", " << Ty->getDescription() << "\n");
906 }
907 UpRefs.erase(UpRefs.begin()+i); // Remove from upreference list...
908 --i; // Do not skip the next element...
909 }
910 }
911 }
912
913 if (TypeToResolve) {
914 UR_OUT(" * Resolving upreference for "
915 << UpRefs[i].second->getDescription() << "\n";
916 std::string OldName = TypeToResolve->getDescription());
917 TypeToResolve->refineAbstractTypeTo(Ty);
918 }
919
920 return Ty;
921}
922
923
924// common code from the two 'RunVMAsmParser' functions
Reid Spencer309080a2006-09-28 19:28:24 +0000925static Module* RunParser(Module * M) {
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000926
927 llvmAsmlineno = 1; // Reset the current line number...
928 ObsoleteVarArgs = false;
929 NewVarArgs = false;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000930 CurModule.CurrentModule = M;
Reid Spencerff359002006-10-09 17:36:59 +0000931
932 // Check to make sure the parser succeeded
933 if (yyparse()) {
934 if (ParserResult)
935 delete ParserResult;
936 return 0;
937 }
938
939 // Check to make sure that parsing produced a result
Reid Spencer713eedc2006-08-18 08:43:06 +0000940 if (!ParserResult)
941 return 0;
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000942
Reid Spencerff359002006-10-09 17:36:59 +0000943 // Reset ParserResult variable while saving its value for the result.
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000944 Module *Result = ParserResult;
945 ParserResult = 0;
946
947 //Not all functions use vaarg, so make a second check for ObsoleteVarArgs
948 {
949 Function* F;
950 if ((F = Result->getNamedFunction("llvm.va_start"))
951 && F->getFunctionType()->getNumParams() == 0)
952 ObsoleteVarArgs = true;
953 if((F = Result->getNamedFunction("llvm.va_copy"))
954 && F->getFunctionType()->getNumParams() == 1)
955 ObsoleteVarArgs = true;
956 }
957
Reid Spencer309080a2006-09-28 19:28:24 +0000958 if (ObsoleteVarArgs && NewVarArgs) {
959 GenerateError(
960 "This file is corrupt: it uses both new and old style varargs");
961 return 0;
962 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000963
964 if(ObsoleteVarArgs) {
965 if(Function* F = Result->getNamedFunction("llvm.va_start")) {
Reid Spencer309080a2006-09-28 19:28:24 +0000966 if (F->arg_size() != 0) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000967 GenerateError("Obsolete va_start takes 0 argument!");
Reid Spencer309080a2006-09-28 19:28:24 +0000968 return 0;
969 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000970
971 //foo = va_start()
972 // ->
973 //bar = alloca typeof(foo)
974 //va_start(bar)
975 //foo = load bar
976
977 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
978 const Type* ArgTy = F->getFunctionType()->getReturnType();
979 const Type* ArgTyPtr = PointerType::get(ArgTy);
980 Function* NF = Result->getOrInsertFunction("llvm.va_start",
Jeff Cohen11e26b52005-10-23 04:37:20 +0000981 RetTy, ArgTyPtr, (Type *)0);
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000982
983 while (!F->use_empty()) {
984 CallInst* CI = cast<CallInst>(F->use_back());
985 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vastart.fix.1", CI);
986 new CallInst(NF, bar, "", CI);
987 Value* foo = new LoadInst(bar, "vastart.fix.2", CI);
988 CI->replaceAllUsesWith(foo);
989 CI->getParent()->getInstList().erase(CI);
990 }
991 Result->getFunctionList().erase(F);
992 }
993
994 if(Function* F = Result->getNamedFunction("llvm.va_end")) {
Reid Spencer309080a2006-09-28 19:28:24 +0000995 if(F->arg_size() != 1) {
Reid Spencer713eedc2006-08-18 08:43:06 +0000996 GenerateError("Obsolete va_end takes 1 argument!");
Reid Spencer309080a2006-09-28 19:28:24 +0000997 return 0;
998 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +0000999
1000 //vaend foo
1001 // ->
1002 //bar = alloca 1 of typeof(foo)
1003 //vaend bar
1004 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1005 const Type* ArgTy = F->getFunctionType()->getParamType(0);
1006 const Type* ArgTyPtr = PointerType::get(ArgTy);
1007 Function* NF = Result->getOrInsertFunction("llvm.va_end",
Jeff Cohen11e26b52005-10-23 04:37:20 +00001008 RetTy, ArgTyPtr, (Type *)0);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001009
1010 while (!F->use_empty()) {
1011 CallInst* CI = cast<CallInst>(F->use_back());
1012 AllocaInst* bar = new AllocaInst(ArgTy, 0, "vaend.fix.1", CI);
1013 new StoreInst(CI->getOperand(1), bar, CI);
1014 new CallInst(NF, bar, "", CI);
1015 CI->getParent()->getInstList().erase(CI);
1016 }
1017 Result->getFunctionList().erase(F);
1018 }
1019
1020 if(Function* F = Result->getNamedFunction("llvm.va_copy")) {
Reid Spencer309080a2006-09-28 19:28:24 +00001021 if(F->arg_size() != 1) {
Reid Spencer713eedc2006-08-18 08:43:06 +00001022 GenerateError("Obsolete va_copy takes 1 argument!");
Reid Spencer309080a2006-09-28 19:28:24 +00001023 return 0;
1024 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001025 //foo = vacopy(bar)
1026 // ->
1027 //a = alloca 1 of typeof(foo)
1028 //b = alloca 1 of typeof(foo)
1029 //store bar -> b
1030 //vacopy(a, b)
1031 //foo = load a
1032
1033 const Type* RetTy = Type::getPrimitiveType(Type::VoidTyID);
1034 const Type* ArgTy = F->getFunctionType()->getReturnType();
1035 const Type* ArgTyPtr = PointerType::get(ArgTy);
1036 Function* NF = Result->getOrInsertFunction("llvm.va_copy",
Jeff Cohen11e26b52005-10-23 04:37:20 +00001037 RetTy, ArgTyPtr, ArgTyPtr,
1038 (Type *)0);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001039
1040 while (!F->use_empty()) {
1041 CallInst* CI = cast<CallInst>(F->use_back());
1042 AllocaInst* a = new AllocaInst(ArgTy, 0, "vacopy.fix.1", CI);
1043 AllocaInst* b = new AllocaInst(ArgTy, 0, "vacopy.fix.2", CI);
1044 new StoreInst(CI->getOperand(1), b, CI);
1045 new CallInst(NF, a, b, "", CI);
1046 Value* foo = new LoadInst(a, "vacopy.fix.3", CI);
1047 CI->replaceAllUsesWith(foo);
1048 CI->getParent()->getInstList().erase(CI);
1049 }
1050 Result->getFunctionList().erase(F);
1051 }
1052 }
1053
1054 return Result;
Reid Spencer309080a2006-09-28 19:28:24 +00001055}
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001056
1057//===----------------------------------------------------------------------===//
1058// RunVMAsmParser - Define an interface to this parser
1059//===----------------------------------------------------------------------===//
1060//
1061Module *llvm::RunVMAsmParser(const std::string &Filename, FILE *F) {
1062 set_scan_file(F);
1063
1064 CurFilename = Filename;
1065 return RunParser(new Module(CurFilename));
1066}
1067
1068Module *llvm::RunVMAsmParser(const char * AsmString, Module * M) {
1069 set_scan_string(AsmString);
1070
1071 CurFilename = "from_memory";
1072 if (M == NULL) {
1073 return RunParser(new Module (CurFilename));
1074 } else {
1075 return RunParser(M);
1076 }
1077}
1078
1079
Chris Lattnerff20ba32006-10-15 23:27:25 +00001080#line 974 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
1081typedef union {
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001082 llvm::Module *ModuleVal;
1083 llvm::Function *FunctionVal;
1084 std::pair<llvm::PATypeHolder*, char*> *ArgVal;
1085 llvm::BasicBlock *BasicBlockVal;
1086 llvm::TerminatorInst *TermInstVal;
1087 llvm::Instruction *InstVal;
1088 llvm::Constant *ConstVal;
1089
1090 const llvm::Type *PrimType;
1091 llvm::PATypeHolder *TypeVal;
1092 llvm::Value *ValueVal;
1093
1094 std::vector<std::pair<llvm::PATypeHolder*,char*> > *ArgList;
1095 std::vector<llvm::Value*> *ValueList;
1096 std::list<llvm::PATypeHolder> *TypeList;
1097 // Represent the RHS of PHI node
1098 std::list<std::pair<llvm::Value*,
1099 llvm::BasicBlock*> > *PHIList;
1100 std::vector<std::pair<llvm::Constant*, llvm::BasicBlock*> > *JumpTable;
1101 std::vector<llvm::Constant*> *ConstVector;
1102
1103 llvm::GlobalValue::LinkageTypes Linkage;
1104 int64_t SInt64Val;
1105 uint64_t UInt64Val;
1106 int SIntVal;
1107 unsigned UIntVal;
1108 double FPVal;
1109 bool BoolVal;
1110
1111 char *StrVal; // This memory is strdup'd!
1112 llvm::ValID ValIDVal; // strdup'd memory maybe!
1113
1114 llvm::Instruction::BinaryOps BinaryOpVal;
1115 llvm::Instruction::TermOps TermOpVal;
1116 llvm::Instruction::MemoryOps MemOpVal;
1117 llvm::Instruction::OtherOps OtherOpVal;
1118 llvm::Module::Endianness Endianness;
Reid Spencer309080a2006-09-28 19:28:24 +00001119} YYSTYPE;
Chris Lattnerff20ba32006-10-15 23:27:25 +00001120#include <stdio.h>
1121
1122#ifndef __cplusplus
1123#ifndef __STDC__
1124#define const
1125#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001126#endif
1127
1128
1129
Chris Lattnerff20ba32006-10-15 23:27:25 +00001130#define YYFINAL 514
1131#define YYFLAG -32768
1132#define YYNTBASE 122
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001133
Chris Lattnerff20ba32006-10-15 23:27:25 +00001134#define YYTRANSLATE(x) ((unsigned)(x) <= 361 ? yytranslate[x] : 196)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001135
Chris Lattnerff20ba32006-10-15 23:27:25 +00001136static const char yytranslate[] = { 0,
1137 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1138 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1139 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1140 2, 2, 2, 2, 2, 2, 2, 2, 2, 111,
1141 112, 120, 2, 109, 2, 2, 2, 2, 2, 2,
1142 2, 2, 2, 2, 2, 2, 2, 2, 2, 116,
1143 108, 117, 2, 2, 2, 2, 2, 2, 2, 2,
1144 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1145 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1146 113, 110, 115, 2, 2, 2, 2, 2, 121, 2,
1147 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1148 2, 2, 2, 2, 2, 2, 2, 2, 2, 114,
1149 2, 2, 118, 2, 119, 2, 2, 2, 2, 2,
1150 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1151 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1152 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1153 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1154 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1155 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1156 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1157 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1158 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1159 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1160 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1161 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1162 2, 2, 2, 2, 2, 1, 3, 4, 5, 6,
1163 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
1164 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
1165 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
1166 37, 38, 39, 40, 41, 42, 43, 44, 45, 46,
1167 47, 48, 49, 50, 51, 52, 53, 54, 55, 56,
1168 57, 58, 59, 60, 61, 62, 63, 64, 65, 66,
1169 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
1170 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
1171 87, 88, 89, 90, 91, 92, 93, 94, 95, 96,
1172 97, 98, 99, 100, 101, 102, 103, 104, 105, 106,
1173 107
1174};
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001175
Chris Lattnerff20ba32006-10-15 23:27:25 +00001176#if YYDEBUG != 0
1177static const short yyprhs[] = { 0,
1178 0, 2, 4, 6, 8, 10, 12, 14, 16, 18,
1179 20, 22, 24, 26, 28, 30, 32, 34, 36, 38,
1180 40, 42, 44, 46, 48, 50, 52, 54, 56, 58,
1181 60, 62, 64, 67, 68, 70, 72, 74, 76, 78,
1182 80, 82, 83, 84, 86, 88, 90, 92, 94, 96,
1183 99, 100, 103, 104, 108, 111, 112, 114, 115, 119,
1184 121, 124, 126, 128, 130, 132, 134, 136, 138, 140,
1185 142, 144, 146, 148, 150, 152, 154, 156, 158, 160,
1186 162, 164, 166, 169, 174, 180, 186, 190, 193, 196,
1187 198, 202, 204, 208, 210, 211, 216, 220, 224, 229,
1188 234, 238, 241, 244, 247, 250, 253, 256, 259, 262,
1189 265, 268, 275, 281, 290, 297, 304, 311, 318, 325,
1190 334, 343, 347, 349, 351, 353, 355, 358, 361, 366,
1191 369, 371, 376, 379, 384, 385, 393, 394, 402, 403,
1192 411, 412, 420, 424, 429, 430, 432, 434, 436, 440,
1193 444, 448, 452, 456, 458, 459, 461, 463, 465, 466,
1194 469, 473, 475, 477, 481, 483, 484, 493, 495, 497,
1195 501, 503, 505, 508, 509, 511, 513, 514, 519, 520,
1196 522, 524, 526, 528, 530, 532, 534, 536, 538, 542,
1197 544, 550, 552, 554, 556, 558, 561, 564, 567, 571,
1198 574, 575, 577, 580, 583, 587, 597, 607, 616, 630,
1199 632, 634, 641, 647, 650, 657, 665, 667, 671, 673,
1200 674, 677, 679, 685, 691, 697, 700, 705, 710, 717,
1201 722, 727, 732, 737, 744, 751, 754, 762, 764, 767,
1202 768, 770, 771, 775, 782, 786, 793, 796, 801, 808
1203};
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00001204
Chris Lattnerff20ba32006-10-15 23:27:25 +00001205static const short yyrhs[] = { 5,
1206 0, 6, 0, 3, 0, 4, 0, 77, 0, 78,
1207 0, 79, 0, 80, 0, 81, 0, 82, 0, 83,
1208 0, 84, 0, 85, 0, 86, 0, 87, 0, 88,
1209 0, 89, 0, 90, 0, 100, 0, 101, 0, 16,
1210 0, 14, 0, 12, 0, 10, 0, 17, 0, 15,
1211 0, 13, 0, 11, 0, 128, 0, 129, 0, 18,
1212 0, 19, 0, 164, 108, 0, 0, 41, 0, 42,
1213 0, 43, 0, 44, 0, 45, 0, 46, 0, 47,
1214 0, 0, 0, 65, 0, 66, 0, 67, 0, 68,
1215 0, 69, 0, 70, 0, 64, 4, 0, 0, 57,
1216 4, 0, 0, 109, 57, 4, 0, 34, 24, 0,
1217 0, 137, 0, 0, 109, 140, 139, 0, 137, 0,
1218 57, 4, 0, 143, 0, 8, 0, 145, 0, 8,
1219 0, 145, 0, 9, 0, 10, 0, 11, 0, 12,
1220 0, 13, 0, 14, 0, 15, 0, 16, 0, 17,
1221 0, 18, 0, 19, 0, 20, 0, 21, 0, 48,
1222 0, 144, 0, 179, 0, 110, 4, 0, 142, 111,
1223 147, 112, 0, 113, 4, 114, 145, 115, 0, 116,
1224 4, 114, 145, 117, 0, 118, 146, 119, 0, 118,
1225 119, 0, 145, 120, 0, 145, 0, 146, 109, 145,
1226 0, 146, 0, 146, 109, 37, 0, 37, 0, 0,
1227 143, 113, 150, 115, 0, 143, 113, 115, 0, 143,
1228 121, 24, 0, 143, 116, 150, 117, 0, 143, 118,
1229 150, 119, 0, 143, 118, 119, 0, 143, 38, 0,
1230 143, 39, 0, 143, 179, 0, 143, 149, 0, 143,
1231 26, 0, 128, 123, 0, 129, 4, 0, 9, 27,
1232 0, 9, 28, 0, 131, 7, 0, 98, 111, 148,
1233 36, 143, 112, 0, 96, 111, 148, 193, 112, 0,
1234 99, 111, 148, 109, 148, 109, 148, 112, 0, 124,
1235 111, 148, 109, 148, 112, 0, 125, 111, 148, 109,
1236 148, 112, 0, 126, 111, 148, 109, 148, 112, 0,
1237 127, 111, 148, 109, 148, 112, 0, 103, 111, 148,
1238 109, 148, 112, 0, 104, 111, 148, 109, 148, 109,
1239 148, 112, 0, 105, 111, 148, 109, 148, 109, 148,
1240 112, 0, 150, 109, 148, 0, 148, 0, 32, 0,
1241 33, 0, 153, 0, 153, 173, 0, 153, 175, 0,
1242 153, 62, 61, 159, 0, 153, 25, 0, 154, 0,
1243 154, 132, 20, 141, 0, 154, 175, 0, 154, 62,
1244 61, 159, 0, 0, 154, 132, 133, 151, 148, 155,
1245 139, 0, 0, 154, 132, 50, 151, 143, 156, 139,
1246 0, 0, 154, 132, 45, 151, 143, 157, 139, 0,
1247 0, 154, 132, 47, 151, 143, 158, 139, 0, 154,
1248 51, 161, 0, 154, 58, 108, 162, 0, 0, 24,
1249 0, 56, 0, 55, 0, 53, 108, 160, 0, 54,
1250 108, 4, 0, 52, 108, 24, 0, 113, 163, 115,
1251 0, 163, 109, 24, 0, 24, 0, 0, 22, 0,
1252 24, 0, 164, 0, 0, 143, 165, 0, 167, 109,
1253 166, 0, 166, 0, 167, 0, 167, 109, 37, 0,
1254 37, 0, 0, 134, 141, 164, 111, 168, 112, 138,
1255 135, 0, 29, 0, 118, 0, 133, 169, 170, 0,
1256 30, 0, 119, 0, 182, 172, 0, 0, 45, 0,
1257 47, 0, 0, 31, 176, 174, 169, 0, 0, 63,
1258 0, 3, 0, 4, 0, 7, 0, 27, 0, 28,
1259 0, 38, 0, 39, 0, 26, 0, 116, 150, 117,
1260 0, 149, 0, 61, 177, 24, 109, 24, 0, 122,
1261 0, 164, 0, 179, 0, 178, 0, 143, 180, 0,
1262 182, 183, 0, 171, 183, 0, 184, 132, 185, 0,
1263 184, 187, 0, 0, 23, 0, 71, 181, 0, 71,
1264 8, 0, 72, 21, 180, 0, 72, 9, 180, 109,
1265 21, 180, 109, 21, 180, 0, 73, 130, 180, 109,
1266 21, 180, 113, 186, 115, 0, 73, 130, 180, 109,
1267 21, 180, 113, 115, 0, 74, 134, 141, 180, 111,
1268 190, 112, 36, 21, 180, 75, 21, 180, 0, 75,
1269 0, 76, 0, 186, 130, 178, 109, 21, 180, 0,
1270 130, 178, 109, 21, 180, 0, 132, 192, 0, 143,
1271 113, 180, 109, 180, 115, 0, 188, 109, 113, 180,
1272 109, 180, 115, 0, 181, 0, 189, 109, 181, 0,
1273 189, 0, 0, 60, 59, 0, 59, 0, 124, 143,
1274 180, 109, 180, 0, 125, 143, 180, 109, 180, 0,
1275 126, 143, 180, 109, 180, 0, 49, 181, 0, 127,
1276 181, 109, 181, 0, 98, 181, 36, 143, 0, 99,
1277 181, 109, 181, 109, 181, 0, 102, 181, 109, 143,
1278 0, 106, 181, 109, 143, 0, 107, 181, 109, 143,
1279 0, 103, 181, 109, 181, 0, 104, 181, 109, 181,
1280 109, 181, 0, 105, 181, 109, 181, 109, 181, 0,
1281 97, 188, 0, 191, 134, 141, 180, 111, 190, 112,
1282 0, 195, 0, 109, 189, 0, 0, 35, 0, 0,
1283 91, 143, 136, 0, 91, 143, 109, 15, 180, 136,
1284 0, 92, 143, 136, 0, 92, 143, 109, 15, 180,
1285 136, 0, 93, 181, 0, 194, 94, 143, 180, 0,
1286 194, 95, 181, 109, 143, 180, 0, 96, 143, 180,
1287 193, 0
1288};
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00001289
1290#endif
1291
Chris Lattnerff20ba32006-10-15 23:27:25 +00001292#if YYDEBUG != 0
1293static const short yyrline[] = { 0,
1294 1096, 1097, 1105, 1106, 1116, 1116, 1116, 1116, 1116, 1117,
1295 1117, 1117, 1118, 1118, 1118, 1118, 1118, 1118, 1120, 1120,
1296 1124, 1124, 1124, 1124, 1125, 1125, 1125, 1125, 1126, 1126,
1297 1127, 1127, 1130, 1134, 1139, 1139, 1140, 1141, 1142, 1143,
1298 1144, 1145, 1148, 1148, 1149, 1150, 1151, 1152, 1153, 1154,
1299 1164, 1164, 1171, 1171, 1180, 1188, 1188, 1194, 1194, 1196,
1300 1201, 1215, 1215, 1216, 1216, 1218, 1228, 1228, 1228, 1228,
1301 1228, 1228, 1228, 1229, 1229, 1229, 1229, 1229, 1229, 1230,
1302 1234, 1238, 1246, 1254, 1267, 1272, 1284, 1294, 1298, 1309,
1303 1314, 1320, 1321, 1325, 1329, 1340, 1366, 1380, 1410, 1436,
1304 1457, 1470, 1480, 1485, 1546, 1553, 1562, 1568, 1574, 1578,
1305 1582, 1590, 1601, 1633, 1641, 1663, 1674, 1680, 1688, 1694,
1306 1700, 1709, 1713, 1721, 1721, 1731, 1739, 1744, 1748, 1752,
1307 1756, 1771, 1793, 1796, 1799, 1804, 1807, 1811, 1815, 1819,
1308 1823, 1828, 1832, 1835, 1838, 1842, 1855, 1856, 1858, 1862,
1309 1871, 1877, 1879, 1884, 1889, 1898, 1898, 1899, 1899, 1901,
1310 1908, 1914, 1921, 1925, 1931, 1936, 1941, 2036, 2036, 2038,
1311 2046, 2046, 2048, 2053, 2053, 2054, 2057, 2057, 2067, 2071,
1312 2076, 2080, 2084, 2088, 2092, 2096, 2100, 2104, 2108, 2133,
1313 2137, 2151, 2155, 2161, 2161, 2167, 2172, 2176, 2185, 2196,
1314 2201, 2213, 2226, 2230, 2234, 2239, 2248, 2267, 2276, 2332,
1315 2336, 2343, 2354, 2367, 2376, 2385, 2395, 2399, 2406, 2406,
1316 2408, 2412, 2417, 2433, 2448, 2462, 2475, 2483, 2491, 2499,
1317 2505, 2525, 2548, 2554, 2560, 2566, 2581, 2640, 2647, 2650,
1318 2655, 2659, 2666, 2671, 2677, 2682, 2688, 2696, 2708, 2723
1319};
1320#endif
1321
1322
1323#if YYDEBUG != 0 || defined (YYERROR_VERBOSE)
1324
1325static const char * const yytname[] = { "$","error","$undefined.","ESINT64VAL",
1326"EUINT64VAL","SINTVAL","UINTVAL","FPVAL","VOID","BOOL","SBYTE","UBYTE","SHORT",
1327"USHORT","INT","UINT","LONG","ULONG","FLOAT","DOUBLE","TYPE","LABEL","VAR_ID",
1328"LABELSTR","STRINGCONSTANT","IMPLEMENTATION","ZEROINITIALIZER","TRUETOK","FALSETOK",
1329"BEGINTOK","ENDTOK","DECLARE","GLOBAL","CONSTANT","SECTION","VOLATILE","TO",
1330"DOTDOTDOT","NULL_TOK","UNDEF","CONST","INTERNAL","LINKONCE","WEAK","APPENDING",
1331"DLLIMPORT","DLLEXPORT","EXTERN_WEAK","OPAQUE","NOT","EXTERNAL","TARGET","TRIPLE",
1332"ENDIAN","POINTERSIZE","LITTLE","BIG","ALIGN","DEPLIBS","CALL","TAIL","ASM_TOK",
1333"MODULE","SIDEEFFECT","CC_TOK","CCC_TOK","CSRETCC_TOK","FASTCC_TOK","COLDCC_TOK",
1334"X86_STDCALLCC_TOK","X86_FASTCALLCC_TOK","RET","BR","SWITCH","INVOKE","UNWIND",
1335"UNREACHABLE","ADD","SUB","MUL","DIV","REM","AND","OR","XOR","SETLE","SETGE",
1336"SETLT","SETGT","SETEQ","SETNE","MALLOC","ALLOCA","FREE","LOAD","STORE","GETELEMENTPTR",
1337"PHI_TOK","CAST","SELECT","SHL","SHR","VAARG","EXTRACTELEMENT","INSERTELEMENT",
1338"SHUFFLEVECTOR","VAARG_old","VANEXT_old","'='","','","'\\\\'","'('","')'","'['",
1339"'x'","']'","'<'","'>'","'{'","'}'","'*'","'c'","INTVAL","EINT64VAL","ArithmeticOps",
1340"LogicalOps","SetCondOps","ShiftOps","SIntType","UIntType","IntType","FPType",
1341"OptAssign","OptLinkage","OptCallingConv","OptAlign","OptCAlign","SectionString",
1342"OptSection","GlobalVarAttributes","GlobalVarAttribute","TypesV","UpRTypesV",
1343"Types","PrimType","UpRTypes","TypeListI","ArgTypeListI","ConstVal","ConstExpr",
1344"ConstVector","GlobalType","Module","FunctionList","ConstPool","@1","@2","@3",
1345"@4","AsmBlock","BigOrLittle","TargetDefinition","LibrariesDefinition","LibList",
1346"Name","OptName","ArgVal","ArgListH","ArgList","FunctionHeaderH","BEGIN","FunctionHeader",
1347"END","Function","FnDeclareLinkage","FunctionProto","@5","OptSideEffect","ConstValueRef",
1348"SymbolicValueRef","ValueRef","ResolvedVal","BasicBlockList","BasicBlock","InstructionList",
1349"BBTerminatorInst","JumpTable","Inst","PHIList","ValueRefList","ValueRefListE",
1350"OptTailCall","InstVal","IndexList","OptVolatile","MemoryInst", NULL
1351};
1352#endif
1353
1354static const short yyr1[] = { 0,
1355 122, 122, 123, 123, 124, 124, 124, 124, 124, 125,
1356 125, 125, 126, 126, 126, 126, 126, 126, 127, 127,
1357 128, 128, 128, 128, 129, 129, 129, 129, 130, 130,
1358 131, 131, 132, 132, 133, 133, 133, 133, 133, 133,
1359 133, 133, 134, 134, 134, 134, 134, 134, 134, 134,
1360 135, 135, 136, 136, 137, 138, 138, 139, 139, 140,
1361 140, 141, 141, 142, 142, 143, 144, 144, 144, 144,
1362 144, 144, 144, 144, 144, 144, 144, 144, 144, 145,
1363 145, 145, 145, 145, 145, 145, 145, 145, 145, 146,
1364 146, 147, 147, 147, 147, 148, 148, 148, 148, 148,
1365 148, 148, 148, 148, 148, 148, 148, 148, 148, 148,
1366 148, 149, 149, 149, 149, 149, 149, 149, 149, 149,
1367 149, 150, 150, 151, 151, 152, 153, 153, 153, 153,
1368 153, 154, 154, 154, 155, 154, 156, 154, 157, 154,
1369 158, 154, 154, 154, 154, 159, 160, 160, 161, 161,
1370 161, 162, 163, 163, 163, 164, 164, 165, 165, 166,
1371 167, 167, 168, 168, 168, 168, 169, 170, 170, 171,
1372 172, 172, 173, 174, 174, 174, 176, 175, 177, 177,
1373 178, 178, 178, 178, 178, 178, 178, 178, 178, 178,
1374 178, 179, 179, 180, 180, 181, 182, 182, 183, 184,
1375 184, 184, 185, 185, 185, 185, 185, 185, 185, 185,
1376 185, 186, 186, 187, 188, 188, 189, 189, 190, 190,
1377 191, 191, 192, 192, 192, 192, 192, 192, 192, 192,
1378 192, 192, 192, 192, 192, 192, 192, 192, 193, 193,
1379 194, 194, 195, 195, 195, 195, 195, 195, 195, 195
1380};
1381
1382static const short yyr2[] = { 0,
1383 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1384 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1385 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1386 1, 1, 2, 0, 1, 1, 1, 1, 1, 1,
1387 1, 0, 0, 1, 1, 1, 1, 1, 1, 2,
1388 0, 2, 0, 3, 2, 0, 1, 0, 3, 1,
1389 2, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1390 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1391 1, 1, 2, 4, 5, 5, 3, 2, 2, 1,
1392 3, 1, 3, 1, 0, 4, 3, 3, 4, 4,
1393 3, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1394 2, 6, 5, 8, 6, 6, 6, 6, 6, 8,
1395 8, 3, 1, 1, 1, 1, 2, 2, 4, 2,
1396 1, 4, 2, 4, 0, 7, 0, 7, 0, 7,
1397 0, 7, 3, 4, 0, 1, 1, 1, 3, 3,
1398 3, 3, 3, 1, 0, 1, 1, 1, 0, 2,
1399 3, 1, 1, 3, 1, 0, 8, 1, 1, 3,
1400 1, 1, 2, 0, 1, 1, 0, 4, 0, 1,
1401 1, 1, 1, 1, 1, 1, 1, 1, 3, 1,
1402 5, 1, 1, 1, 1, 2, 2, 2, 3, 2,
1403 0, 1, 2, 2, 3, 9, 9, 8, 13, 1,
1404 1, 6, 5, 2, 6, 7, 1, 3, 1, 0,
1405 2, 1, 5, 5, 5, 2, 4, 4, 6, 4,
1406 4, 4, 4, 6, 6, 2, 7, 1, 2, 0,
1407 1, 0, 3, 6, 3, 6, 2, 4, 6, 4
1408};
1409
1410static const short yydefact[] = { 145,
1411 42, 131, 130, 177, 35, 36, 37, 38, 39, 40,
1412 41, 0, 43, 201, 127, 128, 201, 156, 157, 0,
1413 0, 0, 42, 0, 133, 174, 0, 0, 44, 45,
1414 46, 47, 48, 49, 0, 0, 202, 198, 34, 171,
1415 172, 173, 197, 0, 0, 0, 143, 0, 0, 0,
1416 0, 0, 0, 0, 33, 175, 176, 43, 146, 129,
1417 50, 1, 2, 63, 67, 68, 69, 70, 71, 72,
1418 73, 74, 75, 76, 77, 78, 79, 80, 0, 0,
1419 0, 0, 192, 0, 0, 62, 81, 66, 193, 82,
1420 168, 169, 170, 242, 200, 0, 0, 0, 155, 144,
1421 134, 132, 124, 125, 0, 0, 0, 0, 178, 83,
1422 0, 0, 65, 88, 90, 0, 0, 95, 89, 241,
1423 0, 222, 0, 0, 0, 0, 43, 210, 211, 5,
1424 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
1425 16, 17, 18, 0, 0, 0, 0, 0, 0, 0,
1426 19, 20, 0, 0, 0, 0, 0, 0, 0, 0,
1427 0, 0, 199, 43, 214, 0, 238, 151, 148, 147,
1428 149, 150, 154, 0, 139, 141, 137, 67, 68, 69,
1429 70, 71, 72, 73, 74, 75, 76, 77, 0, 0,
1430 0, 0, 135, 0, 0, 0, 87, 166, 94, 92,
1431 0, 0, 226, 221, 204, 203, 0, 0, 24, 28,
1432 23, 27, 22, 26, 21, 25, 29, 30, 0, 0,
1433 53, 53, 247, 0, 0, 236, 0, 0, 0, 0,
1434 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1435 0, 0, 152, 58, 58, 58, 109, 110, 3, 4,
1436 107, 108, 111, 106, 102, 103, 0, 0, 0, 0,
1437 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1438 105, 104, 58, 64, 64, 91, 165, 159, 162, 163,
1439 0, 0, 84, 181, 182, 183, 188, 184, 185, 186,
1440 187, 179, 0, 190, 195, 194, 196, 0, 205, 0,
1441 0, 0, 243, 0, 245, 240, 0, 0, 0, 0,
1442 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1443 0, 0, 0, 153, 0, 140, 142, 138, 0, 0,
1444 0, 0, 0, 0, 97, 123, 0, 0, 101, 0,
1445 98, 0, 0, 0, 0, 136, 85, 86, 158, 160,
1446 0, 56, 93, 180, 0, 0, 0, 0, 0, 0,
1447 0, 0, 0, 250, 0, 0, 228, 0, 230, 233,
1448 0, 0, 231, 232, 0, 0, 0, 227, 0, 248,
1449 0, 0, 0, 60, 58, 240, 0, 0, 0, 0,
1450 0, 0, 96, 99, 100, 0, 0, 0, 0, 164,
1451 161, 57, 51, 0, 189, 0, 0, 220, 53, 54,
1452 53, 217, 239, 0, 0, 0, 0, 0, 223, 224,
1453 225, 220, 0, 55, 61, 59, 0, 0, 0, 0,
1454 0, 0, 122, 0, 0, 0, 0, 0, 167, 0,
1455 0, 0, 219, 0, 0, 244, 246, 0, 0, 0,
1456 229, 234, 235, 0, 249, 113, 0, 0, 0, 0,
1457 0, 0, 0, 0, 0, 52, 191, 0, 0, 0,
1458 218, 215, 0, 237, 112, 0, 119, 0, 0, 115,
1459 116, 117, 118, 0, 208, 0, 0, 0, 216, 0,
1460 0, 0, 206, 0, 207, 0, 0, 114, 120, 121,
1461 0, 0, 0, 0, 0, 0, 213, 0, 0, 212,
1462 209, 0, 0, 0
1463};
1464
1465static const short yydefgoto[] = { 83,
1466 251, 267, 268, 269, 270, 189, 190, 219, 191, 23,
1467 13, 35, 439, 303, 384, 403, 326, 385, 84, 85,
1468 192, 87, 88, 116, 201, 336, 294, 337, 105, 512,
1469 1, 2, 273, 246, 244, 245, 60, 171, 47, 100,
1470 174, 89, 350, 279, 280, 281, 36, 93, 14, 42,
1471 15, 58, 16, 26, 355, 295, 90, 297, 412, 17,
1472 38, 39, 163, 487, 95, 226, 443, 444, 164, 165,
1473 364, 166, 167
1474};
1475
1476static const short yypact[] = {-32768,
1477 194, 602,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
1478-32768, -20, 38, 59,-32768,-32768, -18,-32768,-32768, 13,
1479 -8, 75, 115, 58,-32768, 40, 124, 163,-32768,-32768,
1480-32768,-32768,-32768,-32768, 1052, -22,-32768,-32768, -3,-32768,
1481-32768,-32768,-32768, 60, 65, 67,-32768, 57, 124, 1052,
1482 62, 62, 62, 62,-32768,-32768,-32768, 38,-32768,-32768,
1483-32768,-32768,-32768, 61,-32768,-32768,-32768,-32768,-32768,-32768,
1484-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 167, 172,
1485 173, 569,-32768, -3, 68,-32768,-32768, -30,-32768,-32768,
1486-32768,-32768,-32768, 1223,-32768, 159, 42, 180, 162,-32768,
1487-32768,-32768,-32768,-32768, 1093, 1093, 1093, 1134,-32768,-32768,
1488 73, 74,-32768,-32768, -30, -75, 78, 847,-32768,-32768,
1489 1093,-32768, 132, 1175, 14, 185, 38,-32768,-32768,-32768,
1490-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
1491-32768,-32768,-32768, 1093, 1093, 1093, 1093, 1093, 1093, 1093,
1492-32768,-32768, 1093, 1093, 1093, 1093, 1093, 1093, 1093, 1093,
1493 1093, 1093,-32768, 38,-32768, 22,-32768,-32768,-32768,-32768,
1494-32768,-32768,-32768, -47,-32768,-32768,-32768, 111, 137, 199,
1495 140, 203, 142, 204, 147, 205, 210, 211, 151, 206,
1496 213, 412,-32768, 1093, 1093, 1093,-32768, 888,-32768, 103,
1497 110, 635,-32768,-32768, 61,-32768, 635, 635,-32768,-32768,
1498-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768, 635, 1052,
1499 114, 117,-32768, 635, 134, 118, 188, 119, 139, 141,
1500 144, 145, 146, 148, 635, 635, 635, 149, 1052, 1093,
1501 1093, 225,-32768, 150, 150, 150,-32768,-32768,-32768,-32768,
1502-32768,-32768,-32768,-32768,-32768,-32768, 152, 153, 154, 157,
1503 158, 175, 929, 1134, 589, 227, 176, 178, 179, 182,
1504-32768,-32768, 150, -51, -72, -30,-32768, -3,-32768, 161,
1505 183, 970,-32768,-32768,-32768,-32768,-32768,-32768,-32768,-32768,
1506-32768, 197, 1134,-32768,-32768,-32768,-32768, 164,-32768, 187,
1507 635, -4,-32768, 3,-32768, 189, 635, 171, 1093, 1093,
1508 1093, 1093, 1093, 1093, 1093, 1093, 193, 195, 200, 1093,
1509 635, 635, 201,-32768, -17,-32768,-32768,-32768, 1134, 1134,
1510 1134, 1134, 1134, 1134,-32768,-32768, -16, -26,-32768, -73,
1511-32768, 1134, 1134, 1134, 1134,-32768,-32768,-32768,-32768,-32768,
1512 1011, 228,-32768,-32768, 237, -25, 270, 273, 186, 635,
1513 299, 635, 1093,-32768, 214, 635,-32768, 215,-32768,-32768,
1514 216, 217,-32768,-32768, 635, 635, 635,-32768, 202,-32768,
1515 1093, 282, 304,-32768, 150, 189, 276, 218, 224, 229,
1516 230, 1134,-32768,-32768,-32768, 231, 232, 233, 234,-32768,
1517-32768,-32768, 257, 238,-32768, 635, 635, 1093, 239,-32768,
1518 239,-32768, 241, 635, 244, 1093, 1093, 1093,-32768,-32768,
1519-32768, 1093, 635,-32768,-32768,-32768, 242, 1093, 1134, 1134,
1520 1134, 1134,-32768, 1134, 1134, 1134, 1134, 311,-32768, 331,
1521 247, 245, 241, 248, 300,-32768,-32768, 1093, 246, 635,
1522-32768,-32768,-32768, 252,-32768,-32768, 254, 258, 260, 261,
1523 265, 263, 268, 272, 277,-32768,-32768, 348, 16, 341,
1524-32768,-32768, 275,-32768,-32768, 1134,-32768, 1134, 1134,-32768,
1525-32768,-32768,-32768, 635,-32768, 738, 63, 367,-32768, 279,
1526 280, 284,-32768, 285,-32768, 738, 635,-32768,-32768,-32768,
1527 376, 289, 324, 635, 379, 380,-32768, 635, 635,-32768,
1528-32768, 402, 403,-32768
1529};
1530
1531static const short yypgoto[] = {-32768,
1532-32768, 310, 312, 313, 314, -125, -124, -449,-32768, 366,
1533 386, -103,-32768, -219, 69,-32768, -236,-32768, -46,-32768,
1534 -35,-32768, -66, 292,-32768, -100, 219, -251, 80,-32768,
1535-32768,-32768,-32768,-32768,-32768,-32768, 363,-32768,-32768,-32768,
1536-32768, 4,-32768, 71,-32768,-32768, 356,-32768,-32768,-32768,
1537-32768,-32768, 413,-32768,-32768, -447, -55, 64, -99,-32768,
1538 399,-32768,-32768,-32768,-32768,-32768, 56, -2,-32768,-32768,
1539 37,-32768,-32768
1540};
1541
1542
1543#define YYLAST 1330
1544
1545
1546static const short yytable[] = { 86,
1547 217, 218, 305, 102, 37, 24, 91, 193, 327, 328,
1548 360, 40, 338, 340, 86, 115, 382, 362, 18, 486,
1549 19, 203, 207, 220, 206, 209, 210, 211, 212, 213,
1550 214, 215, 216, 196, 208, 392, 346, 496, 494, 383,
1551 27, 356, 24, 197, 348, 395, 223, 119, 502, 227,
1552 228, 115, 361, 229, 230, 231, 232, 233, 234, 361,
1553 239, 242, 238, 347, 44, 45, 46, 243, 119, 175,
1554 176, 177, 209, 210, 211, 212, 213, 214, 215, 216,
1555 -64, 37, 392, 392, 56, 202, 57, 117, 202, 119,
1556 394, 405, 392, 103, 104, 92, 169, 170, 393, 48,
1557 41, 28, 29, 30, 31, 32, 33, 34, 221, 222,
1558 202, 224, 225, 202, 202, 240, 241, 202, 202, 202,
1559 202, 202, 202, 235, 236, 237, 202, 274, 275, 276,
1560 485, 106, 107, 108, 50, 49, 272, 247, 248, -24,
1561 -24, 323, -23, -23, -22, -22, 296, 59, 426, -21,
1562 -21, 296, 296, 249, 250, 5, 6, 7, 8, 51,
1563 10, 52, 278, 296, 53, 55, 61, 96, 296, 99,
1564 110, -65, 97, 301, 98, 111, 112, 495, 118, 296,
1565 296, 296, 168, 172, 86, 173, 194, 195, 198, 446,
1566 204, 447, 321, -126, 209, 210, 211, 212, 213, 214,
1567 215, 216, -28, 86, 322, 202, -27, -26, -25, 252,
1568 368, 282, 370, 371, 372, 276, -31, -32, 3, 253,
1569 378, 283, 302, 309, 4, 304, 308, 310, 386, 387,
1570 388, 389, 390, 391, 5, 6, 7, 8, 9, 10,
1571 11, 396, 397, 398, 399, 296, 307, 311, 324, 312,
1572 341, 296, 313, 314, 315, 12, 316, 320, 325, 354,
1573 404, 382, 329, 330, 331, 296, 296, 332, 333, 351,
1574 298, 299, 357, 367, 202, 369, 202, 202, 202, 373,
1575 374, 349, 300, 366, 202, 334, 342, 306, 343, 344,
1576 406, 433, 345, 407, 352, 358, 408, 363, 317, 318,
1577 319, 375, 410, 376, 296, 424, 296, 425, 377, 381,
1578 296, 428, 422, 438, 466, 278, 451, 452, 453, 296,
1579 296, 296, 414, 416, 417, 418, 429, 202, 458, 459,
1580 460, 461, 430, 462, 463, 464, 465, 431, 432, 434,
1581 435, 436, 437, 217, 218, 423, 440, 445, 471, 448,
1582 296, 296, 450, 456, 467, 468, 361, 469, 296, 470,
1583 472, 217, 218, 474, 359, 475, 476, 296, 484, 478,
1584 365, 477, 202, 479, 480, 490, 488, 491, 492, 481,
1585 202, 202, 202, 482, 379, 380, 202, 497, 483, 489,
1586 498, 499, 457, 501, 296, 500, 504, 505, 506, 508,
1587 509, 513, 514, 159, 94, 160, 161, 162, 54, 200,
1588 271, 101, 202, 109, 25, 43, 62, 63, 413, 454,
1589 402, 401, 427, 409, 0, 411, 0, 0, 296, 415,
1590 0, 0, 0, 18, 0, 19, 0, 254, 419, 420,
1591 421, 296, 0, 0, 0, 0, 0, 0, 296, 255,
1592 256, 0, 296, 296, 0, 0, 0, 0, 0, 0,
1593 0, 0, 0, 0, 0, 0, 0, 0, 0, 441,
1594 442, 0, 0, 0, 0, 0, 0, 449, 0, 0,
1595 0, 0, 0, 0, 0, 0, 455, 0, 130, 131,
1596 132, 133, 134, 135, 136, 137, 138, 139, 140, 141,
1597 142, 143, 0, 0, 0, 0, 0, 257, 0, 258,
1598 259, 151, 152, 473, 260, 261, 262, 0, 0, 0,
1599 0, 0, 0, 0, 263, 0, 0, 264, 0, 265,
1600 0, 0, 266, 0, 0, 0, 0, 0, 0, 0,
1601 0, 0, 0, 0, 0, 0, 0, 493, 0, 0,
1602 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1603 503, 0, 0, 0, 0, 0, 0, 507, 0, 0,
1604 0, 510, 511, 62, 63, 0, 113, 65, 66, 67,
1605 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
1606 18, 0, 19, 62, 63, 0, 113, 178, 179, 180,
1607 181, 182, 183, 184, 185, 186, 187, 188, 76, 77,
1608 18, 0, 19, 0, 0, 0, 78, 0, 0, 0,
1609 0, -34, 0, 18, 0, 19, 0, 0, 0, 0,
1610 0, 0, 4, -34, -34, 0, 78, 284, 285, 62,
1611 63, 286, -34, -34, -34, -34, -34, -34, -34, 0,
1612 0, -34, 20, 0, 0, 0, 18, 0, 19, 21,
1613 287, 288, 289, 22, 0, 0, 0, 0, 0, 0,
1614 0, 0, 290, 291, 0, 0, 0, 0, 79, 0,
1615 0, 80, 0, 0, 81, 0, 82, 114, 0, 0,
1616 0, 0, 0, 0, 0, 292, 0, 0, 79, 0,
1617 0, 80, 0, 0, 81, 0, 82, 339, 0, 0,
1618 0, 130, 131, 132, 133, 134, 135, 136, 137, 138,
1619 139, 140, 141, 142, 143, 0, 0, 0, 0, 0,
1620 257, 0, 258, 259, 151, 152, 0, 260, 261, 262,
1621 284, 285, 0, 0, 286, 0, 0, 0, 0, 0,
1622 293, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1623 0, 0, 0, 287, 288, 289, 0, 0, 0, 0,
1624 0, 0, 0, 0, 0, 290, 291, 0, 0, 0,
1625 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1626 0, 0, 0, 0, 0, 0, 0, 0, 292, 0,
1627 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1628 0, 0, 0, 0, 130, 131, 132, 133, 134, 135,
1629 136, 137, 138, 139, 140, 141, 142, 143, 0, 0,
1630 0, 0, 0, 257, 0, 258, 259, 151, 152, 0,
1631 260, 261, 262, 0, 0, 0, 0, 0, 0, 0,
1632 0, 62, 63, 293, 113, 65, 66, 67, 68, 69,
1633 70, 71, 72, 73, 74, 75, 76, 77, 18, 0,
1634 19, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1635 0, 0, 0, 199, 0, 0, 0, 0, 0, 0,
1636 0, 0, 62, 63, 78, 113, 65, 66, 67, 68,
1637 69, 70, 71, 72, 73, 74, 75, 76, 77, 18,
1638 0, 19, 0, 0, 0, 0, 0, 0, 0, 0,
1639 0, 0, 0, 0, 277, 0, 0, 0, 0, 0,
1640 0, 0, 0, 62, 63, 78, 113, 178, 179, 180,
1641 181, 182, 183, 184, 185, 186, 187, 188, 76, 77,
1642 18, 0, 19, 0, 0, 0, 79, 0, 0, 80,
1643 0, 0, 81, 0, 82, 0, 0, 0, 0, 0,
1644 0, 0, 0, 0, 62, 63, 78, 113, 65, 66,
1645 67, 68, 69, 70, 71, 72, 73, 74, 75, 76,
1646 77, 18, 0, 19, 0, 0, 0, 79, 0, 0,
1647 80, 0, 0, 81, 0, 82, 353, 0, 0, 0,
1648 0, 0, 0, 0, 0, 62, 63, 78, 113, 65,
1649 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
1650 76, 77, 18, 0, 19, 0, 0, 0, 79, 0,
1651 0, 80, 0, 335, 81, 0, 82, 400, 0, 0,
1652 0, 0, 0, 0, 0, 0, 62, 63, 78, 64,
1653 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
1654 75, 76, 77, 18, 0, 19, 0, 0, 0, 79,
1655 0, 0, 80, 0, 0, 81, 0, 82, 0, 0,
1656 0, 0, 0, 0, 0, 0, 0, 62, 63, 78,
1657 113, 65, 66, 67, 68, 69, 70, 71, 72, 73,
1658 74, 75, 76, 77, 18, 0, 19, 0, 0, 0,
1659 79, 0, 0, 80, 0, 0, 81, 0, 82, 0,
1660 0, 0, 0, 0, 0, 0, 0, 0, 62, 63,
1661 78, 113, 178, 179, 180, 181, 182, 183, 184, 185,
1662 186, 187, 188, 76, 77, 18, 0, 19, 0, 0,
1663 0, 79, 0, 0, 80, 0, 0, 81, 0, 82,
1664 0, 0, 0, 0, 0, 0, 0, 0, 0, 62,
1665 63, 78, 205, 65, 66, 67, 68, 69, 70, 71,
1666 72, 73, 74, 75, 76, 77, 18, 0, 19, 0,
1667 0, 0, 79, 0, 0, 80, 0, 0, 81, 0,
1668 82, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1669 0, 0, 78, 0, 0, 0, 0, 0, 0, 0,
1670 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1671 0, 0, 0, 79, 0, 0, 80, 0, 0, 81,
1672 0, 82, 0, 0, 0, 0, 0, 120, 0, 0,
1673 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1674 0, 121, 0, 0, 0, 0, 0, 0, 0, 0,
1675 0, 122, 123, 0, 79, 0, 0, 80, 0, 0,
1676 81, 0, 82, 124, 125, 126, 127, 128, 129, 130,
1677 131, 132, 133, 134, 135, 136, 137, 138, 139, 140,
1678 141, 142, 143, 144, 145, 146, 0, 0, 147, 148,
1679 149, 150, 151, 152, 153, 154, 155, 156, 157, 158
1680};
1681
1682static const short yycheck[] = { 35,
1683 126, 126, 222, 50, 23, 2, 29, 108, 245, 246,
1684 15, 30, 264, 265, 50, 82, 34, 15, 22, 469,
1685 24, 121, 9, 127, 124, 10, 11, 12, 13, 14,
1686 15, 16, 17, 109, 21, 109, 273, 487, 486, 57,
1687 61, 293, 39, 119, 117, 119, 146, 120, 496, 149,
1688 150, 118, 57, 153, 154, 155, 156, 157, 158, 57,
1689 164, 109, 162, 115, 52, 53, 54, 115, 120, 105,
1690 106, 107, 10, 11, 12, 13, 14, 15, 16, 17,
1691 111, 23, 109, 109, 45, 121, 47, 84, 124, 120,
1692 117, 117, 109, 32, 33, 118, 55, 56, 115, 108,
1693 119, 64, 65, 66, 67, 68, 69, 70, 144, 145,
1694 146, 147, 148, 149, 150, 94, 95, 153, 154, 155,
1695 156, 157, 158, 159, 160, 161, 162, 194, 195, 196,
1696 115, 52, 53, 54, 20, 61, 192, 27, 28, 3,
1697 4, 241, 3, 4, 3, 4, 202, 24, 385, 3,
1698 4, 207, 208, 3, 4, 41, 42, 43, 44, 45,
1699 46, 47, 198, 219, 50, 108, 4, 108, 224, 113,
1700 4, 111, 108, 220, 108, 4, 4, 115, 111, 235,
1701 236, 237, 24, 4, 220, 24, 114, 114, 111, 409,
1702 59, 411, 239, 0, 10, 11, 12, 13, 14, 15,
1703 16, 17, 4, 239, 240, 241, 4, 4, 4, 4,
1704 310, 109, 312, 313, 314, 282, 7, 7, 25, 7,
1705 320, 112, 109, 36, 31, 109, 109, 109, 329, 330,
1706 331, 332, 333, 334, 41, 42, 43, 44, 45, 46,
1707 47, 342, 343, 344, 345, 301, 113, 109, 24, 109,
1708 24, 307, 109, 109, 109, 62, 109, 109, 109, 63,
1709 24, 34, 111, 111, 111, 321, 322, 111, 111, 109,
1710 207, 208, 109, 309, 310, 311, 312, 313, 314, 315,
1711 316, 278, 219, 113, 320, 111, 111, 224, 111, 111,
1712 21, 392, 111, 21, 112, 109, 111, 109, 235, 236,
1713 237, 109, 4, 109, 360, 24, 362, 4, 109, 109,
1714 366, 36, 111, 57, 4, 351, 416, 417, 418, 375,
1715 376, 377, 109, 109, 109, 109, 109, 363, 429, 430,
1716 431, 432, 109, 434, 435, 436, 437, 109, 109, 109,
1717 109, 109, 109, 469, 469, 381, 109, 109, 448, 109,
1718 406, 407, 109, 112, 24, 109, 57, 113, 414, 112,
1719 115, 487, 487, 112, 301, 112, 109, 423, 21, 109,
1720 307, 112, 408, 109, 112, 476, 36, 478, 479, 112,
1721 416, 417, 418, 112, 321, 322, 422, 21, 112, 115,
1722 112, 112, 428, 109, 450, 112, 21, 109, 75, 21,
1723 21, 0, 0, 94, 39, 94, 94, 94, 23, 118,
1724 192, 49, 448, 58, 2, 17, 5, 6, 363, 422,
1725 352, 351, 386, 360, -1, 362, -1, -1, 484, 366,
1726 -1, -1, -1, 22, -1, 24, -1, 26, 375, 376,
1727 377, 497, -1, -1, -1, -1, -1, -1, 504, 38,
1728 39, -1, 508, 509, -1, -1, -1, -1, -1, -1,
1729 -1, -1, -1, -1, -1, -1, -1, -1, -1, 406,
1730 407, -1, -1, -1, -1, -1, -1, 414, -1, -1,
1731 -1, -1, -1, -1, -1, -1, 423, -1, 77, 78,
1732 79, 80, 81, 82, 83, 84, 85, 86, 87, 88,
1733 89, 90, -1, -1, -1, -1, -1, 96, -1, 98,
1734 99, 100, 101, 450, 103, 104, 105, -1, -1, -1,
1735 -1, -1, -1, -1, 113, -1, -1, 116, -1, 118,
1736 -1, -1, 121, -1, -1, -1, -1, -1, -1, -1,
1737 -1, -1, -1, -1, -1, -1, -1, 484, -1, -1,
1738 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1739 497, -1, -1, -1, -1, -1, -1, 504, -1, -1,
1740 -1, 508, 509, 5, 6, -1, 8, 9, 10, 11,
1741 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
1742 22, -1, 24, 5, 6, -1, 8, 9, 10, 11,
1743 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
1744 22, -1, 24, -1, -1, -1, 48, -1, -1, -1,
1745 -1, 20, -1, 22, -1, 24, -1, -1, -1, -1,
1746 -1, -1, 31, 32, 33, -1, 48, 3, 4, 5,
1747 6, 7, 41, 42, 43, 44, 45, 46, 47, -1,
1748 -1, 50, 51, -1, -1, -1, 22, -1, 24, 58,
1749 26, 27, 28, 62, -1, -1, -1, -1, -1, -1,
1750 -1, -1, 38, 39, -1, -1, -1, -1, 110, -1,
1751 -1, 113, -1, -1, 116, -1, 118, 119, -1, -1,
1752 -1, -1, -1, -1, -1, 61, -1, -1, 110, -1,
1753 -1, 113, -1, -1, 116, -1, 118, 119, -1, -1,
1754 -1, 77, 78, 79, 80, 81, 82, 83, 84, 85,
1755 86, 87, 88, 89, 90, -1, -1, -1, -1, -1,
1756 96, -1, 98, 99, 100, 101, -1, 103, 104, 105,
1757 3, 4, -1, -1, 7, -1, -1, -1, -1, -1,
1758 116, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1759 -1, -1, -1, 26, 27, 28, -1, -1, -1, -1,
1760 -1, -1, -1, -1, -1, 38, 39, -1, -1, -1,
1761 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1762 -1, -1, -1, -1, -1, -1, -1, -1, 61, -1,
1763 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1764 -1, -1, -1, -1, 77, 78, 79, 80, 81, 82,
1765 83, 84, 85, 86, 87, 88, 89, 90, -1, -1,
1766 -1, -1, -1, 96, -1, 98, 99, 100, 101, -1,
1767 103, 104, 105, -1, -1, -1, -1, -1, -1, -1,
1768 -1, 5, 6, 116, 8, 9, 10, 11, 12, 13,
1769 14, 15, 16, 17, 18, 19, 20, 21, 22, -1,
1770 24, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1771 -1, -1, -1, 37, -1, -1, -1, -1, -1, -1,
1772 -1, -1, 5, 6, 48, 8, 9, 10, 11, 12,
1773 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
1774 -1, 24, -1, -1, -1, -1, -1, -1, -1, -1,
1775 -1, -1, -1, -1, 37, -1, -1, -1, -1, -1,
1776 -1, -1, -1, 5, 6, 48, 8, 9, 10, 11,
1777 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
1778 22, -1, 24, -1, -1, -1, 110, -1, -1, 113,
1779 -1, -1, 116, -1, 118, -1, -1, -1, -1, -1,
1780 -1, -1, -1, -1, 5, 6, 48, 8, 9, 10,
1781 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
1782 21, 22, -1, 24, -1, -1, -1, 110, -1, -1,
1783 113, -1, -1, 116, -1, 118, 37, -1, -1, -1,
1784 -1, -1, -1, -1, -1, 5, 6, 48, 8, 9,
1785 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
1786 20, 21, 22, -1, 24, -1, -1, -1, 110, -1,
1787 -1, 113, -1, 115, 116, -1, 118, 37, -1, -1,
1788 -1, -1, -1, -1, -1, -1, 5, 6, 48, 8,
1789 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
1790 19, 20, 21, 22, -1, 24, -1, -1, -1, 110,
1791 -1, -1, 113, -1, -1, 116, -1, 118, -1, -1,
1792 -1, -1, -1, -1, -1, -1, -1, 5, 6, 48,
1793 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
1794 18, 19, 20, 21, 22, -1, 24, -1, -1, -1,
1795 110, -1, -1, 113, -1, -1, 116, -1, 118, -1,
1796 -1, -1, -1, -1, -1, -1, -1, -1, 5, 6,
1797 48, 8, 9, 10, 11, 12, 13, 14, 15, 16,
1798 17, 18, 19, 20, 21, 22, -1, 24, -1, -1,
1799 -1, 110, -1, -1, 113, -1, -1, 116, -1, 118,
1800 -1, -1, -1, -1, -1, -1, -1, -1, -1, 5,
1801 6, 48, 8, 9, 10, 11, 12, 13, 14, 15,
1802 16, 17, 18, 19, 20, 21, 22, -1, 24, -1,
1803 -1, -1, 110, -1, -1, 113, -1, -1, 116, -1,
1804 118, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1805 -1, -1, 48, -1, -1, -1, -1, -1, -1, -1,
1806 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1807 -1, -1, -1, 110, -1, -1, 113, -1, -1, 116,
1808 -1, 118, -1, -1, -1, -1, -1, 35, -1, -1,
1809 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
1810 -1, 49, -1, -1, -1, -1, -1, -1, -1, -1,
1811 -1, 59, 60, -1, 110, -1, -1, 113, -1, -1,
1812 116, -1, 118, 71, 72, 73, 74, 75, 76, 77,
1813 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
1814 88, 89, 90, 91, 92, 93, -1, -1, 96, 97,
1815 98, 99, 100, 101, 102, 103, 104, 105, 106, 107
1816};
1817/* -*-C-*- Note some compilers choke on comments on `#line' lines. */
1818#line 3 "/usr/share/bison.simple"
1819/* This file comes from bison-1.28. */
1820
1821/* Skeleton output parser for bison,
1822 Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc.
1823
1824 This program is free software; you can redistribute it and/or modify
1825 it under the terms of the GNU General Public License as published by
1826 the Free Software Foundation; either version 2, or (at your option)
1827 any later version.
1828
1829 This program is distributed in the hope that it will be useful,
1830 but WITHOUT ANY WARRANTY; without even the implied warranty of
1831 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1832 GNU General Public License for more details.
1833
1834 You should have received a copy of the GNU General Public License
1835 along with this program; if not, write to the Free Software
1836 Foundation, Inc., 59 Temple Place - Suite 330,
1837 Boston, MA 02111-1307, USA. */
1838
1839/* As a special exception, when this file is copied by Bison into a
1840 Bison output file, you may use that output file without restriction.
1841 This special exception was added by the Free Software Foundation
1842 in version 1.24 of Bison. */
1843
1844/* This is the parser code that is written into each bison parser
1845 when the %semantic_parser declaration is not specified in the grammar.
1846 It was written by Richard Stallman by simplifying the hairy parser
1847 used when %semantic_parser is specified. */
1848
1849#ifndef YYSTACK_USE_ALLOCA
1850#ifdef alloca
1851#define YYSTACK_USE_ALLOCA
1852#else /* alloca not defined */
1853#ifdef __GNUC__
1854#define YYSTACK_USE_ALLOCA
1855#define alloca __builtin_alloca
1856#else /* not GNU C. */
1857#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386))
1858#define YYSTACK_USE_ALLOCA
1859#include <alloca.h>
1860#else /* not sparc */
1861/* We think this test detects Watcom and Microsoft C. */
1862/* This used to test MSDOS, but that is a bad idea
1863 since that symbol is in the user namespace. */
1864#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__)
1865#if 0 /* No need for malloc.h, which pollutes the namespace;
1866 instead, just don't use alloca. */
1867#include <malloc.h>
1868#endif
1869#else /* not MSDOS, or __TURBOC__ */
1870#if defined(_AIX)
1871/* I don't know what this was needed for, but it pollutes the namespace.
1872 So I turned it off. rms, 2 May 1997. */
1873/* #include <malloc.h> */
1874 #pragma alloca
1875#define YYSTACK_USE_ALLOCA
1876#else /* not MSDOS, or __TURBOC__, or _AIX */
1877#if 0
1878#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up,
1879 and on HPUX 10. Eventually we can turn this on. */
1880#define YYSTACK_USE_ALLOCA
1881#define alloca __builtin_alloca
1882#endif /* __hpux */
1883#endif
1884#endif /* not _AIX */
1885#endif /* not MSDOS, or __TURBOC__ */
1886#endif /* not sparc */
1887#endif /* not GNU C */
1888#endif /* alloca not defined */
1889#endif /* YYSTACK_USE_ALLOCA not defined */
1890
1891#ifdef YYSTACK_USE_ALLOCA
1892#define YYSTACK_ALLOC alloca
Reid Spencer309080a2006-09-28 19:28:24 +00001893#else
Chris Lattnerff20ba32006-10-15 23:27:25 +00001894#define YYSTACK_ALLOC malloc
Reid Spencer309080a2006-09-28 19:28:24 +00001895#endif
1896
Chris Lattnerff20ba32006-10-15 23:27:25 +00001897/* Note: there must be only one dollar sign in this file.
1898 It is replaced by the list of actions, each action
1899 as one case of the switch. */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001900
1901#define yyerrok (yyerrstatus = 0)
1902#define yyclearin (yychar = YYEMPTY)
Chris Lattnerff20ba32006-10-15 23:27:25 +00001903#define YYEMPTY -2
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001904#define YYEOF 0
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001905#define YYACCEPT goto yyacceptlab
Chris Lattnerff20ba32006-10-15 23:27:25 +00001906#define YYABORT goto yyabortlab
1907#define YYERROR goto yyerrlab1
1908/* Like YYERROR except do call yyerror.
1909 This remains here temporarily to ease the
1910 transition to the new meaning of YYERROR, for GCC.
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001911 Once GCC version 2 has supplanted version 1, this can go. */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001912#define YYFAIL goto yyerrlab
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001913#define YYRECOVERING() (!!yyerrstatus)
Chris Lattnerff20ba32006-10-15 23:27:25 +00001914#define YYBACKUP(token, value) \
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001915do \
1916 if (yychar == YYEMPTY && yylen == 1) \
Chris Lattnerff20ba32006-10-15 23:27:25 +00001917 { yychar = (token), yylval = (value); \
1918 yychar1 = YYTRANSLATE (yychar); \
Reid Spencer309080a2006-09-28 19:28:24 +00001919 YYPOPSTACK; \
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001920 goto yybackup; \
1921 } \
1922 else \
Chris Lattnerff20ba32006-10-15 23:27:25 +00001923 { yyerror ("syntax error: cannot back up"); YYERROR; } \
Reid Spencer309080a2006-09-28 19:28:24 +00001924while (0)
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00001925
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001926#define YYTERROR 1
1927#define YYERRCODE 256
1928
Chris Lattnerff20ba32006-10-15 23:27:25 +00001929#ifndef YYPURE
1930#define YYLEX yylex()
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001931#endif
1932
Chris Lattnerff20ba32006-10-15 23:27:25 +00001933#ifdef YYPURE
1934#ifdef YYLSP_NEEDED
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001935#ifdef YYLEX_PARAM
Chris Lattnerff20ba32006-10-15 23:27:25 +00001936#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001937#else
Chris Lattnerff20ba32006-10-15 23:27:25 +00001938#define YYLEX yylex(&yylval, &yylloc)
1939#endif
1940#else /* not YYLSP_NEEDED */
1941#ifdef YYLEX_PARAM
1942#define YYLEX yylex(&yylval, YYLEX_PARAM)
1943#else
1944#define YYLEX yylex(&yylval)
1945#endif
1946#endif /* not YYLSP_NEEDED */
Chris Lattner6ab03f62006-09-28 23:35:22 +00001947#endif
Reid Spencerff359002006-10-09 17:36:59 +00001948
Chris Lattnerff20ba32006-10-15 23:27:25 +00001949/* If nonreentrant, generate the variables here */
Reid Spencerff359002006-10-09 17:36:59 +00001950
Chris Lattnerff20ba32006-10-15 23:27:25 +00001951#ifndef YYPURE
Reid Spencerff359002006-10-09 17:36:59 +00001952
Chris Lattnerff20ba32006-10-15 23:27:25 +00001953int yychar; /* the lookahead symbol */
1954YYSTYPE yylval; /* the semantic value of the */
1955 /* lookahead symbol */
Reid Spencerff359002006-10-09 17:36:59 +00001956
Chris Lattnerff20ba32006-10-15 23:27:25 +00001957#ifdef YYLSP_NEEDED
1958YYLTYPE yylloc; /* location data for the lookahead */
1959 /* symbol */
Chris Lattner6ab03f62006-09-28 23:35:22 +00001960#endif
Reid Spencerff359002006-10-09 17:36:59 +00001961
Chris Lattnerff20ba32006-10-15 23:27:25 +00001962int yynerrs; /* number of parse errors so far */
1963#endif /* not YYPURE */
Reid Spencerff359002006-10-09 17:36:59 +00001964
Chris Lattnerff20ba32006-10-15 23:27:25 +00001965#if YYDEBUG != 0
1966int yydebug; /* nonzero means print parse trace */
1967/* Since this is uninitialized, it does not stop multiple parsers
1968 from coexisting. */
Chris Lattner680aab62006-08-18 17:34:45 +00001969#endif
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00001970
Chris Lattnerff20ba32006-10-15 23:27:25 +00001971/* YYINITDEPTH indicates the initial size of the parser's stacks */
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00001972
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001973#ifndef YYINITDEPTH
Chris Lattnerff20ba32006-10-15 23:27:25 +00001974#define YYINITDEPTH 200
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001975#endif
1976
Chris Lattnerff20ba32006-10-15 23:27:25 +00001977/* YYMAXDEPTH is the maximum size the stacks can grow to
1978 (effective only if the built-in stack extension method is used). */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001979
Chris Lattnerff20ba32006-10-15 23:27:25 +00001980#if YYMAXDEPTH == 0
1981#undef YYMAXDEPTH
1982#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001983
1984#ifndef YYMAXDEPTH
Chris Lattnerff20ba32006-10-15 23:27:25 +00001985#define YYMAXDEPTH 10000
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001986#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001987
Chris Lattnerff20ba32006-10-15 23:27:25 +00001988/* Define __yy_memcpy. Note that the size argument
1989 should be passed with type unsigned int, because that is what the non-GCC
1990 definitions require. With GCC, __builtin_memcpy takes an arg
1991 of type size_t, but it can handle unsigned int. */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001992
Chris Lattnerff20ba32006-10-15 23:27:25 +00001993#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */
1994#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT)
1995#else /* not GNU C or C++ */
1996#ifndef __cplusplus
Reid Spencerdfb3fb42005-08-27 18:50:39 +00001997
Chris Lattnerff20ba32006-10-15 23:27:25 +00001998/* This is the most reliable way to avoid incompatibilities
1999 in available built-in functions on various systems. */
Reid Spencerff359002006-10-09 17:36:59 +00002000static void
Chris Lattnerff20ba32006-10-15 23:27:25 +00002001__yy_memcpy (to, from, count)
2002 char *to;
2003 char *from;
2004 unsigned int count;
2005{
2006 register char *f = from;
2007 register char *t = to;
2008 register int i = count;
2009
2010 while (i-- > 0)
2011 *t++ = *f++;
2012}
2013
2014#else /* __cplusplus */
2015
2016/* This is the most reliable way to avoid incompatibilities
2017 in available built-in functions on various systems. */
Reid Spencerff359002006-10-09 17:36:59 +00002018static void
Chris Lattnerff20ba32006-10-15 23:27:25 +00002019__yy_memcpy (char *to, char *from, unsigned int count)
2020{
2021 register char *t = to;
2022 register char *f = from;
2023 register int i = count;
2024
2025 while (i-- > 0)
2026 *t++ = *f++;
2027}
2028
Reid Spencerff359002006-10-09 17:36:59 +00002029#endif
Reid Spencerff359002006-10-09 17:36:59 +00002030#endif
Reid Spencerff359002006-10-09 17:36:59 +00002031
Chris Lattnerff20ba32006-10-15 23:27:25 +00002032#line 217 "/usr/share/bison.simple"
Reid Spencerff359002006-10-09 17:36:59 +00002033
Chris Lattnerff20ba32006-10-15 23:27:25 +00002034/* The user can define YYPARSE_PARAM as the name of an argument to be passed
2035 into yyparse. The argument should have type void *.
2036 It should actually point to an object.
2037 Grammar actions can access the variable by casting it
2038 to the proper pointer type. */
Reid Spencerff359002006-10-09 17:36:59 +00002039
2040#ifdef YYPARSE_PARAM
Chris Lattnerff20ba32006-10-15 23:27:25 +00002041#ifdef __cplusplus
2042#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
2043#define YYPARSE_PARAM_DECL
2044#else /* not __cplusplus */
2045#define YYPARSE_PARAM_ARG YYPARSE_PARAM
2046#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
2047#endif /* not __cplusplus */
2048#else /* not YYPARSE_PARAM */
2049#define YYPARSE_PARAM_ARG
2050#define YYPARSE_PARAM_DECL
2051#endif /* not YYPARSE_PARAM */
2052
2053/* Prevent warning if -Wstrict-prototypes. */
2054#ifdef __GNUC__
2055#ifdef YYPARSE_PARAM
2056int yyparse (void *);
2057#else
Reid Spencerc8a9faf2006-01-19 01:21:04 +00002058int yyparse (void);
Reid Spencerff359002006-10-09 17:36:59 +00002059#endif
Chris Lattnerff20ba32006-10-15 23:27:25 +00002060#endif
Reid Spencerff359002006-10-09 17:36:59 +00002061
Reid Spencerff359002006-10-09 17:36:59 +00002062int
Chris Lattnerff20ba32006-10-15 23:27:25 +00002063yyparse(YYPARSE_PARAM_ARG)
2064 YYPARSE_PARAM_DECL
Reid Spencerff359002006-10-09 17:36:59 +00002065{
Chris Lattnerff20ba32006-10-15 23:27:25 +00002066 register int yystate;
2067 register int yyn;
2068 register short *yyssp;
2069 register YYSTYPE *yyvsp;
2070 int yyerrstatus; /* number of tokens to shift before error messages enabled */
2071 int yychar1 = 0; /* lookahead token as an internal (translated) token number */
Reid Spencerff359002006-10-09 17:36:59 +00002072
Chris Lattnerff20ba32006-10-15 23:27:25 +00002073 short yyssa[YYINITDEPTH]; /* the state stack */
2074 YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
Reid Spencerff359002006-10-09 17:36:59 +00002075
Chris Lattnerff20ba32006-10-15 23:27:25 +00002076 short *yyss = yyssa; /* refer to the stacks thru separate pointers */
2077 YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
Reid Spencerff359002006-10-09 17:36:59 +00002078
Chris Lattnerff20ba32006-10-15 23:27:25 +00002079#ifdef YYLSP_NEEDED
2080 YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */
2081 YYLTYPE *yyls = yylsa;
2082 YYLTYPE *yylsp;
Reid Spencerff359002006-10-09 17:36:59 +00002083
Chris Lattnerff20ba32006-10-15 23:27:25 +00002084#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
2085#else
Reid Spencer309080a2006-09-28 19:28:24 +00002086#define YYPOPSTACK (yyvsp--, yyssp--)
Chris Lattnerff20ba32006-10-15 23:27:25 +00002087#endif
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00002088
Chris Lattnerff20ba32006-10-15 23:27:25 +00002089 int yystacksize = YYINITDEPTH;
2090 int yyfree_stacks = 0;
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00002091
Chris Lattnerff20ba32006-10-15 23:27:25 +00002092#ifdef YYPURE
2093 int yychar;
2094 YYSTYPE yylval;
2095 int yynerrs;
2096#ifdef YYLSP_NEEDED
2097 YYLTYPE yylloc;
2098#endif
2099#endif
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00002100
Chris Lattnerff20ba32006-10-15 23:27:25 +00002101 YYSTYPE yyval; /* the variable used to return */
2102 /* semantic values from the action */
2103 /* routines */
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00002104
Reid Spencer309080a2006-09-28 19:28:24 +00002105 int yylen;
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00002106
Chris Lattnerff20ba32006-10-15 23:27:25 +00002107#if YYDEBUG != 0
2108 if (yydebug)
2109 fprintf(stderr, "Starting parse\n");
2110#endif
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00002111
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002112 yystate = 0;
2113 yyerrstatus = 0;
2114 yynerrs = 0;
2115 yychar = YYEMPTY; /* Cause a token to be read. */
2116
2117 /* Initialize stack pointers.
2118 Waste one element of value and location stack
2119 so that they stay on the same level as the state stack.
2120 The wasted elements are never initialized. */
2121
Chris Lattnerff20ba32006-10-15 23:27:25 +00002122 yyssp = yyss - 1;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002123 yyvsp = yyvs;
Chris Lattnerff20ba32006-10-15 23:27:25 +00002124#ifdef YYLSP_NEEDED
2125 yylsp = yyls;
2126#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002127
Chris Lattnerff20ba32006-10-15 23:27:25 +00002128/* Push a new state, which is found in yystate . */
2129/* In all cases, when you get here, the value and location stacks
2130 have just been pushed. so pushing a state here evens the stacks. */
2131yynewstate:
Jeff Cohen11e26b52005-10-23 04:37:20 +00002132
Chris Lattnerff20ba32006-10-15 23:27:25 +00002133 *++yyssp = yystate;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002134
Chris Lattnerff20ba32006-10-15 23:27:25 +00002135 if (yyssp >= yyss + yystacksize - 1)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002136 {
Chris Lattnerff20ba32006-10-15 23:27:25 +00002137 /* Give user a chance to reallocate the stack */
2138 /* Use copies of these so that the &'s don't force the real ones into memory. */
2139 YYSTYPE *yyvs1 = yyvs;
2140 short *yyss1 = yyss;
2141#ifdef YYLSP_NEEDED
2142 YYLTYPE *yyls1 = yyls;
2143#endif
2144
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002145 /* Get the current used size of the three stacks, in elements. */
Chris Lattnerff20ba32006-10-15 23:27:25 +00002146 int size = yyssp - yyss + 1;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002147
2148#ifdef yyoverflow
Chris Lattnerff20ba32006-10-15 23:27:25 +00002149 /* Each stack pointer address is followed by the size of
2150 the data in use in that stack, in bytes. */
2151#ifdef YYLSP_NEEDED
2152 /* This used to be a conditional around just the two extra args,
2153 but that might be undefined if yyoverflow is a macro. */
2154 yyoverflow("parser stack overflow",
2155 &yyss1, size * sizeof (*yyssp),
2156 &yyvs1, size * sizeof (*yyvsp),
2157 &yyls1, size * sizeof (*yylsp),
2158 &yystacksize);
2159#else
2160 yyoverflow("parser stack overflow",
2161 &yyss1, size * sizeof (*yyssp),
2162 &yyvs1, size * sizeof (*yyvsp),
2163 &yystacksize);
2164#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002165
Chris Lattnerff20ba32006-10-15 23:27:25 +00002166 yyss = yyss1; yyvs = yyvs1;
2167#ifdef YYLSP_NEEDED
2168 yyls = yyls1;
2169#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002170#else /* no yyoverflow */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002171 /* Extend the stack our own way. */
Chris Lattnerff20ba32006-10-15 23:27:25 +00002172 if (yystacksize >= YYMAXDEPTH)
2173 {
2174 yyerror("parser stack overflow");
2175 if (yyfree_stacks)
2176 {
2177 free (yyss);
2178 free (yyvs);
2179#ifdef YYLSP_NEEDED
2180 free (yyls);
2181#endif
2182 }
2183 return 2;
2184 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002185 yystacksize *= 2;
Chris Lattnerff20ba32006-10-15 23:27:25 +00002186 if (yystacksize > YYMAXDEPTH)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002187 yystacksize = YYMAXDEPTH;
Chris Lattnerff20ba32006-10-15 23:27:25 +00002188#ifndef YYSTACK_USE_ALLOCA
2189 yyfree_stacks = 1;
2190#endif
2191 yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp));
2192 __yy_memcpy ((char *)yyss, (char *)yyss1,
2193 size * (unsigned int) sizeof (*yyssp));
2194 yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp));
2195 __yy_memcpy ((char *)yyvs, (char *)yyvs1,
2196 size * (unsigned int) sizeof (*yyvsp));
2197#ifdef YYLSP_NEEDED
2198 yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp));
2199 __yy_memcpy ((char *)yyls, (char *)yyls1,
2200 size * (unsigned int) sizeof (*yylsp));
2201#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002202#endif /* no yyoverflow */
2203
Chris Lattnerff20ba32006-10-15 23:27:25 +00002204 yyssp = yyss + size - 1;
2205 yyvsp = yyvs + size - 1;
2206#ifdef YYLSP_NEEDED
2207 yylsp = yyls + size - 1;
2208#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002209
Chris Lattnerff20ba32006-10-15 23:27:25 +00002210#if YYDEBUG != 0
2211 if (yydebug)
2212 fprintf(stderr, "Stack size increased to %d\n", yystacksize);
2213#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002214
Chris Lattnerff20ba32006-10-15 23:27:25 +00002215 if (yyssp >= yyss + yystacksize - 1)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002216 YYABORT;
2217 }
2218
Chris Lattnerff20ba32006-10-15 23:27:25 +00002219#if YYDEBUG != 0
2220 if (yydebug)
2221 fprintf(stderr, "Entering state %d\n", yystate);
2222#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002223
2224 goto yybackup;
Chris Lattnerff20ba32006-10-15 23:27:25 +00002225 yybackup:
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002226
Reid Spencer309080a2006-09-28 19:28:24 +00002227/* Do appropriate processing given the current state. */
Chris Lattnerff20ba32006-10-15 23:27:25 +00002228/* Read a lookahead token if we need one and don't already have one. */
Reid Spencer309080a2006-09-28 19:28:24 +00002229/* yyresume: */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002230
Chris Lattnerff20ba32006-10-15 23:27:25 +00002231 /* First try to decide what to do without reference to lookahead token. */
Reid Spencer309080a2006-09-28 19:28:24 +00002232
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002233 yyn = yypact[yystate];
Chris Lattnerff20ba32006-10-15 23:27:25 +00002234 if (yyn == YYFLAG)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002235 goto yydefault;
2236
Chris Lattnerff20ba32006-10-15 23:27:25 +00002237 /* Not known => get a lookahead token if don't already have one. */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002238
Chris Lattnerff20ba32006-10-15 23:27:25 +00002239 /* yychar is either YYEMPTY or YYEOF
2240 or a valid token in external form. */
2241
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002242 if (yychar == YYEMPTY)
2243 {
Chris Lattnerff20ba32006-10-15 23:27:25 +00002244#if YYDEBUG != 0
2245 if (yydebug)
2246 fprintf(stderr, "Reading a token: ");
2247#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002248 yychar = YYLEX;
2249 }
2250
Chris Lattnerff20ba32006-10-15 23:27:25 +00002251 /* Convert token to internal form (in yychar1) for indexing tables with */
2252
2253 if (yychar <= 0) /* This means end of input. */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002254 {
Chris Lattnerff20ba32006-10-15 23:27:25 +00002255 yychar1 = 0;
2256 yychar = YYEOF; /* Don't call YYLEX any more */
2257
2258#if YYDEBUG != 0
2259 if (yydebug)
2260 fprintf(stderr, "Now at end of input.\n");
2261#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002262 }
2263 else
2264 {
Chris Lattnerff20ba32006-10-15 23:27:25 +00002265 yychar1 = YYTRANSLATE(yychar);
2266
2267#if YYDEBUG != 0
2268 if (yydebug)
2269 {
2270 fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]);
2271 /* Give the individual parser a way to print the precise meaning
2272 of a token, for further debugging info. */
2273#ifdef YYPRINT
2274 YYPRINT (stderr, yychar, yylval);
2275#endif
2276 fprintf (stderr, ")\n");
2277 }
2278#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002279 }
2280
Chris Lattnerff20ba32006-10-15 23:27:25 +00002281 yyn += yychar1;
2282 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002283 goto yydefault;
Chris Lattnerff20ba32006-10-15 23:27:25 +00002284
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002285 yyn = yytable[yyn];
Chris Lattnerff20ba32006-10-15 23:27:25 +00002286
2287 /* yyn is what to do for this token type in this state.
2288 Negative => reduce, -yyn is rule number.
2289 Positive => shift, yyn is new state.
2290 New state is final state => don't bother to shift,
2291 just return success.
2292 0, or most negative number => error. */
2293
2294 if (yyn < 0)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002295 {
Chris Lattnerff20ba32006-10-15 23:27:25 +00002296 if (yyn == YYFLAG)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002297 goto yyerrlab;
2298 yyn = -yyn;
2299 goto yyreduce;
2300 }
Chris Lattnerff20ba32006-10-15 23:27:25 +00002301 else if (yyn == 0)
2302 goto yyerrlab;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002303
2304 if (yyn == YYFINAL)
2305 YYACCEPT;
2306
Chris Lattnerff20ba32006-10-15 23:27:25 +00002307 /* Shift the lookahead token. */
2308
2309#if YYDEBUG != 0
2310 if (yydebug)
2311 fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]);
2312#endif
Reid Spencer309080a2006-09-28 19:28:24 +00002313
2314 /* Discard the token being shifted unless it is eof. */
2315 if (yychar != YYEOF)
2316 yychar = YYEMPTY;
2317
2318 *++yyvsp = yylval;
Chris Lattnerff20ba32006-10-15 23:27:25 +00002319#ifdef YYLSP_NEEDED
2320 *++yylsp = yylloc;
2321#endif
Reid Spencer309080a2006-09-28 19:28:24 +00002322
Chris Lattnerff20ba32006-10-15 23:27:25 +00002323 /* count tokens shifted since error; after three, turn off error status. */
2324 if (yyerrstatus) yyerrstatus--;
Chris Lattner680aab62006-08-18 17:34:45 +00002325
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002326 yystate = yyn;
2327 goto yynewstate;
2328
Chris Lattnerff20ba32006-10-15 23:27:25 +00002329/* Do the default action for the current state. */
Reid Spencerff359002006-10-09 17:36:59 +00002330yydefault:
Chris Lattnerff20ba32006-10-15 23:27:25 +00002331
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002332 yyn = yydefact[yystate];
2333 if (yyn == 0)
2334 goto yyerrlab;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002335
Chris Lattnerff20ba32006-10-15 23:27:25 +00002336/* Do a reduction. yyn is the number of a rule to reduce with. */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002337yyreduce:
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002338 yylen = yyr2[yyn];
Chris Lattnerff20ba32006-10-15 23:27:25 +00002339 if (yylen > 0)
2340 yyval = yyvsp[1-yylen]; /* implement default value of the action */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002341
Chris Lattnerff20ba32006-10-15 23:27:25 +00002342#if YYDEBUG != 0
2343 if (yydebug)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002344 {
Chris Lattnerff20ba32006-10-15 23:27:25 +00002345 int i;
2346
2347 fprintf (stderr, "Reducing via rule %d (line %d), ",
2348 yyn, yyrline[yyn]);
2349
2350 /* Print the symbols being reduced, and their result. */
2351 for (i = yyprhs[yyn]; yyrhs[i] > 0; i++)
2352 fprintf (stderr, "%s ", yytname[yyrhs[i]]);
2353 fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]);
2354 }
2355#endif
2356
2357
2358 switch (yyn) {
2359
2360case 2:
2361#line 1097 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2362{
2363 if (yyvsp[0].UIntVal > (uint32_t)INT32_MAX) // Outside of my range!
Reid Spencer713eedc2006-08-18 08:43:06 +00002364 GEN_ERROR("Value too large for type!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00002365 yyval.SIntVal = (int32_t)yyvsp[0].UIntVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002366 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002367;
2368 break;}
2369case 4:
2370#line 1106 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2371{
2372 if (yyvsp[0].UInt64Val > (uint64_t)INT64_MAX) // Outside of my range!
Reid Spencer713eedc2006-08-18 08:43:06 +00002373 GEN_ERROR("Value too large for type!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00002374 yyval.SInt64Val = (int64_t)yyvsp[0].UInt64Val;
Reid Spencer713eedc2006-08-18 08:43:06 +00002375 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002376;
2377 break;}
2378case 33:
2379#line 1130 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2380{
2381 yyval.StrVal = yyvsp[-1].StrVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002382 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002383 ;
2384 break;}
2385case 34:
2386#line 1134 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2387{
2388 yyval.StrVal = 0;
Reid Spencer713eedc2006-08-18 08:43:06 +00002389 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002390 ;
2391 break;}
2392case 35:
2393#line 1139 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2394{ yyval.Linkage = GlobalValue::InternalLinkage; ;
2395 break;}
2396case 36:
2397#line 1140 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2398{ yyval.Linkage = GlobalValue::LinkOnceLinkage; ;
2399 break;}
2400case 37:
2401#line 1141 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2402{ yyval.Linkage = GlobalValue::WeakLinkage; ;
2403 break;}
2404case 38:
2405#line 1142 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2406{ yyval.Linkage = GlobalValue::AppendingLinkage; ;
2407 break;}
2408case 39:
2409#line 1143 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2410{ yyval.Linkage = GlobalValue::DLLImportLinkage; ;
2411 break;}
2412case 40:
2413#line 1144 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2414{ yyval.Linkage = GlobalValue::DLLExportLinkage; ;
2415 break;}
2416case 41:
2417#line 1145 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2418{ yyval.Linkage = GlobalValue::ExternalWeakLinkage; ;
2419 break;}
2420case 42:
2421#line 1146 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2422{ yyval.Linkage = GlobalValue::ExternalLinkage; ;
2423 break;}
2424case 43:
2425#line 1148 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2426{ yyval.UIntVal = CallingConv::C; ;
2427 break;}
2428case 44:
2429#line 1149 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2430{ yyval.UIntVal = CallingConv::C; ;
2431 break;}
2432case 45:
2433#line 1150 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2434{ yyval.UIntVal = CallingConv::CSRet; ;
2435 break;}
2436case 46:
2437#line 1151 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2438{ yyval.UIntVal = CallingConv::Fast; ;
2439 break;}
2440case 47:
2441#line 1152 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2442{ yyval.UIntVal = CallingConv::Cold; ;
2443 break;}
2444case 48:
2445#line 1153 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2446{ yyval.UIntVal = CallingConv::X86_StdCall; ;
2447 break;}
2448case 49:
2449#line 1154 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2450{ yyval.UIntVal = CallingConv::X86_FastCall; ;
2451 break;}
2452case 50:
2453#line 1155 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2454{
2455 if ((unsigned)yyvsp[0].UInt64Val != yyvsp[0].UInt64Val)
Reid Spencer713eedc2006-08-18 08:43:06 +00002456 GEN_ERROR("Calling conv too large!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00002457 yyval.UIntVal = yyvsp[0].UInt64Val;
Reid Spencer713eedc2006-08-18 08:43:06 +00002458 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002459 ;
2460 break;}
2461case 51:
2462#line 1164 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2463{ yyval.UIntVal = 0; ;
2464 break;}
2465case 52:
2466#line 1165 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2467{
2468 yyval.UIntVal = yyvsp[0].UInt64Val;
2469 if (yyval.UIntVal != 0 && !isPowerOf2_32(yyval.UIntVal))
Reid Spencer713eedc2006-08-18 08:43:06 +00002470 GEN_ERROR("Alignment must be a power of two!");
2471 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002472;
2473 break;}
2474case 53:
2475#line 1171 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2476{ yyval.UIntVal = 0; ;
2477 break;}
2478case 54:
2479#line 1172 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2480{
2481 yyval.UIntVal = yyvsp[0].UInt64Val;
2482 if (yyval.UIntVal != 0 && !isPowerOf2_32(yyval.UIntVal))
Reid Spencer713eedc2006-08-18 08:43:06 +00002483 GEN_ERROR("Alignment must be a power of two!");
2484 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002485;
2486 break;}
2487case 55:
2488#line 1180 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2489{
2490 for (unsigned i = 0, e = strlen(yyvsp[0].StrVal); i != e; ++i)
2491 if (yyvsp[0].StrVal[i] == '"' || yyvsp[0].StrVal[i] == '\\')
Reid Spencer713eedc2006-08-18 08:43:06 +00002492 GEN_ERROR("Invalid character in section name!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00002493 yyval.StrVal = yyvsp[0].StrVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002494 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002495;
2496 break;}
2497case 56:
2498#line 1188 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2499{ yyval.StrVal = 0; ;
2500 break;}
2501case 57:
2502#line 1189 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2503{ yyval.StrVal = yyvsp[0].StrVal; ;
2504 break;}
2505case 58:
2506#line 1194 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2507{;
2508 break;}
2509case 59:
2510#line 1195 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2511{;
2512 break;}
2513case 60:
2514#line 1196 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2515{
2516 CurGV->setSection(yyvsp[0].StrVal);
2517 free(yyvsp[0].StrVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00002518 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002519 ;
2520 break;}
2521case 61:
2522#line 1201 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2523{
2524 if (yyvsp[0].UInt64Val != 0 && !isPowerOf2_32(yyvsp[0].UInt64Val))
Reid Spencer713eedc2006-08-18 08:43:06 +00002525 GEN_ERROR("Alignment must be a power of two!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00002526 CurGV->setAlignment(yyvsp[0].UInt64Val);
Reid Spencer713eedc2006-08-18 08:43:06 +00002527 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002528 ;
2529 break;}
2530case 63:
2531#line 1215 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2532{ yyval.TypeVal = new PATypeHolder(yyvsp[0].PrimType); ;
2533 break;}
2534case 65:
2535#line 1216 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2536{ yyval.TypeVal = new PATypeHolder(yyvsp[0].PrimType); ;
2537 break;}
2538case 66:
2539#line 1218 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2540{
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002541 if (!UpRefs.empty())
Chris Lattnerff20ba32006-10-15 23:27:25 +00002542 GEN_ERROR("Invalid upreference in type: " + (*yyvsp[0].TypeVal)->getDescription());
2543 yyval.TypeVal = yyvsp[0].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002544 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002545 ;
2546 break;}
2547case 80:
2548#line 1230 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2549{
2550 yyval.TypeVal = new PATypeHolder(OpaqueType::get());
Reid Spencer713eedc2006-08-18 08:43:06 +00002551 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002552 ;
2553 break;}
2554case 81:
2555#line 1234 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2556{
2557 yyval.TypeVal = new PATypeHolder(yyvsp[0].PrimType);
Reid Spencer713eedc2006-08-18 08:43:06 +00002558 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002559 ;
2560 break;}
2561case 82:
2562#line 1238 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2563{ // Named types are also simple types...
2564 const Type* tmp = getTypeVal(yyvsp[0].ValIDVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00002565 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002566 yyval.TypeVal = new PATypeHolder(tmp);
2567;
2568 break;}
2569case 83:
2570#line 1246 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2571{ // Type UpReference
2572 if (yyvsp[0].UInt64Val > (uint64_t)~0U) GEN_ERROR("Value out of range!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002573 OpaqueType *OT = OpaqueType::get(); // Use temporary placeholder
Chris Lattnerff20ba32006-10-15 23:27:25 +00002574 UpRefs.push_back(UpRefRecord((unsigned)yyvsp[0].UInt64Val, OT)); // Add to vector...
2575 yyval.TypeVal = new PATypeHolder(OT);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002576 UR_OUT("New Upreference!\n");
Reid Spencer713eedc2006-08-18 08:43:06 +00002577 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002578 ;
2579 break;}
2580case 84:
2581#line 1254 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2582{ // Function derived type?
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002583 std::vector<const Type*> Params;
Chris Lattnerff20ba32006-10-15 23:27:25 +00002584 for (std::list<llvm::PATypeHolder>::iterator I = yyvsp[-1].TypeList->begin(),
2585 E = yyvsp[-1].TypeList->end(); I != E; ++I)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002586 Params.push_back(*I);
2587 bool isVarArg = Params.size() && Params.back() == Type::VoidTy;
2588 if (isVarArg) Params.pop_back();
2589
Chris Lattnerff20ba32006-10-15 23:27:25 +00002590 yyval.TypeVal = new PATypeHolder(HandleUpRefs(FunctionType::get(*yyvsp[-3].TypeVal,Params,isVarArg)));
2591 delete yyvsp[-1].TypeList; // Delete the argument list
2592 delete yyvsp[-3].TypeVal; // Delete the return type handle
Reid Spencer713eedc2006-08-18 08:43:06 +00002593 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002594 ;
2595 break;}
2596case 85:
2597#line 1267 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2598{ // Sized array type?
2599 yyval.TypeVal = new PATypeHolder(HandleUpRefs(ArrayType::get(*yyvsp[-1].TypeVal, (unsigned)yyvsp[-3].UInt64Val)));
2600 delete yyvsp[-1].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002601 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002602 ;
2603 break;}
2604case 86:
2605#line 1272 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2606{ // Packed array type?
2607 const llvm::Type* ElemTy = yyvsp[-1].TypeVal->get();
2608 if ((unsigned)yyvsp[-3].UInt64Val != yyvsp[-3].UInt64Val)
Reid Spencer713eedc2006-08-18 08:43:06 +00002609 GEN_ERROR("Unsigned result not equal to signed result");
Chris Lattner625b9c82005-11-10 01:42:43 +00002610 if (!ElemTy->isPrimitiveType())
Reid Spencer713eedc2006-08-18 08:43:06 +00002611 GEN_ERROR("Elemental type of a PackedType must be primitive");
Chris Lattnerff20ba32006-10-15 23:27:25 +00002612 if (!isPowerOf2_32(yyvsp[-3].UInt64Val))
Reid Spencer713eedc2006-08-18 08:43:06 +00002613 GEN_ERROR("Vector length should be a power of 2!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00002614 yyval.TypeVal = new PATypeHolder(HandleUpRefs(PackedType::get(*yyvsp[-1].TypeVal, (unsigned)yyvsp[-3].UInt64Val)));
2615 delete yyvsp[-1].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002616 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002617 ;
2618 break;}
2619case 87:
2620#line 1284 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2621{ // Structure type?
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002622 std::vector<const Type*> Elements;
Chris Lattnerff20ba32006-10-15 23:27:25 +00002623 for (std::list<llvm::PATypeHolder>::iterator I = yyvsp[-1].TypeList->begin(),
2624 E = yyvsp[-1].TypeList->end(); I != E; ++I)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002625 Elements.push_back(*I);
2626
Chris Lattnerff20ba32006-10-15 23:27:25 +00002627 yyval.TypeVal = new PATypeHolder(HandleUpRefs(StructType::get(Elements)));
2628 delete yyvsp[-1].TypeList;
Reid Spencer713eedc2006-08-18 08:43:06 +00002629 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002630 ;
2631 break;}
2632case 88:
2633#line 1294 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2634{ // Empty structure type?
2635 yyval.TypeVal = new PATypeHolder(StructType::get(std::vector<const Type*>()));
Reid Spencer713eedc2006-08-18 08:43:06 +00002636 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002637 ;
2638 break;}
2639case 89:
2640#line 1298 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2641{ // Pointer type?
2642 if (*yyvsp[-1].TypeVal == Type::LabelTy)
2643 GEN_ERROR("Cannot form a pointer to a basic block");
2644 yyval.TypeVal = new PATypeHolder(HandleUpRefs(PointerType::get(*yyvsp[-1].TypeVal)));
2645 delete yyvsp[-1].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002646 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002647 ;
2648 break;}
2649case 90:
2650#line 1309 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2651{
2652 yyval.TypeList = new std::list<PATypeHolder>();
2653 yyval.TypeList->push_back(*yyvsp[0].TypeVal); delete yyvsp[0].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002654 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002655 ;
2656 break;}
2657case 91:
2658#line 1314 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2659{
2660 (yyval.TypeList=yyvsp[-2].TypeList)->push_back(*yyvsp[0].TypeVal); delete yyvsp[0].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002661 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002662 ;
2663 break;}
2664case 93:
2665#line 1321 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2666{
2667 (yyval.TypeList=yyvsp[-2].TypeList)->push_back(Type::VoidTy);
Reid Spencer713eedc2006-08-18 08:43:06 +00002668 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002669 ;
2670 break;}
2671case 94:
2672#line 1325 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2673{
2674 (yyval.TypeList = new std::list<PATypeHolder>())->push_back(Type::VoidTy);
Reid Spencer713eedc2006-08-18 08:43:06 +00002675 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002676 ;
2677 break;}
2678case 95:
2679#line 1329 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2680{
2681 yyval.TypeList = new std::list<PATypeHolder>();
Reid Spencer713eedc2006-08-18 08:43:06 +00002682 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002683 ;
2684 break;}
2685case 96:
2686#line 1340 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2687{ // Nonempty unsized arr
2688 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-3].TypeVal->get());
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002689 if (ATy == 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00002690 GEN_ERROR("Cannot make array constant with type: '" +
Chris Lattnerff20ba32006-10-15 23:27:25 +00002691 (*yyvsp[-3].TypeVal)->getDescription() + "'!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002692 const Type *ETy = ATy->getElementType();
2693 int NumElements = ATy->getNumElements();
2694
2695 // Verify that we have the correct size...
Chris Lattnerff20ba32006-10-15 23:27:25 +00002696 if (NumElements != -1 && NumElements != (int)yyvsp[-1].ConstVector->size())
Reid Spencer713eedc2006-08-18 08:43:06 +00002697 GEN_ERROR("Type mismatch: constant sized array initialized with " +
Chris Lattnerff20ba32006-10-15 23:27:25 +00002698 utostr(yyvsp[-1].ConstVector->size()) + " arguments, but has size of " +
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002699 itostr(NumElements) + "!");
2700
2701 // Verify all elements are correct type!
Chris Lattnerff20ba32006-10-15 23:27:25 +00002702 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
2703 if (ETy != (*yyvsp[-1].ConstVector)[i]->getType())
Reid Spencer713eedc2006-08-18 08:43:06 +00002704 GEN_ERROR("Element #" + utostr(i) + " is not of type '" +
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002705 ETy->getDescription() +"' as required!\nIt is of type '"+
Chris Lattnerff20ba32006-10-15 23:27:25 +00002706 (*yyvsp[-1].ConstVector)[i]->getType()->getDescription() + "'.");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002707 }
2708
Chris Lattnerff20ba32006-10-15 23:27:25 +00002709 yyval.ConstVal = ConstantArray::get(ATy, *yyvsp[-1].ConstVector);
2710 delete yyvsp[-3].TypeVal; delete yyvsp[-1].ConstVector;
Reid Spencer713eedc2006-08-18 08:43:06 +00002711 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002712 ;
2713 break;}
2714case 97:
2715#line 1366 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2716{
2717 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-2].TypeVal->get());
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002718 if (ATy == 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00002719 GEN_ERROR("Cannot make array constant with type: '" +
Chris Lattnerff20ba32006-10-15 23:27:25 +00002720 (*yyvsp[-2].TypeVal)->getDescription() + "'!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002721
2722 int NumElements = ATy->getNumElements();
2723 if (NumElements != -1 && NumElements != 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00002724 GEN_ERROR("Type mismatch: constant sized array initialized with 0"
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002725 " arguments, but has size of " + itostr(NumElements) +"!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00002726 yyval.ConstVal = ConstantArray::get(ATy, std::vector<Constant*>());
2727 delete yyvsp[-2].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002728 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002729 ;
2730 break;}
2731case 98:
2732#line 1380 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2733{
2734 const ArrayType *ATy = dyn_cast<ArrayType>(yyvsp[-2].TypeVal->get());
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002735 if (ATy == 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00002736 GEN_ERROR("Cannot make array constant with type: '" +
Chris Lattnerff20ba32006-10-15 23:27:25 +00002737 (*yyvsp[-2].TypeVal)->getDescription() + "'!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002738
2739 int NumElements = ATy->getNumElements();
2740 const Type *ETy = ATy->getElementType();
Chris Lattnerff20ba32006-10-15 23:27:25 +00002741 char *EndStr = UnEscapeLexed(yyvsp[0].StrVal, true);
2742 if (NumElements != -1 && NumElements != (EndStr-yyvsp[0].StrVal))
Reid Spencer713eedc2006-08-18 08:43:06 +00002743 GEN_ERROR("Can't build string constant of size " +
Chris Lattnerff20ba32006-10-15 23:27:25 +00002744 itostr((int)(EndStr-yyvsp[0].StrVal)) +
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002745 " when array has size " + itostr(NumElements) + "!");
2746 std::vector<Constant*> Vals;
2747 if (ETy == Type::SByteTy) {
Chris Lattnerff20ba32006-10-15 23:27:25 +00002748 for (signed char *C = (signed char *)yyvsp[0].StrVal; C != (signed char *)EndStr; ++C)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002749 Vals.push_back(ConstantSInt::get(ETy, *C));
2750 } else if (ETy == Type::UByteTy) {
Chris Lattnerff20ba32006-10-15 23:27:25 +00002751 for (unsigned char *C = (unsigned char *)yyvsp[0].StrVal;
Chris Lattner8ebd2162006-01-24 04:14:29 +00002752 C != (unsigned char*)EndStr; ++C)
2753 Vals.push_back(ConstantUInt::get(ETy, *C));
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002754 } else {
Chris Lattnerff20ba32006-10-15 23:27:25 +00002755 free(yyvsp[0].StrVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00002756 GEN_ERROR("Cannot build string arrays of non byte sized elements!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002757 }
Chris Lattnerff20ba32006-10-15 23:27:25 +00002758 free(yyvsp[0].StrVal);
2759 yyval.ConstVal = ConstantArray::get(ATy, Vals);
2760 delete yyvsp[-2].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002761 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002762 ;
2763 break;}
2764case 99:
2765#line 1410 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2766{ // Nonempty unsized arr
2767 const PackedType *PTy = dyn_cast<PackedType>(yyvsp[-3].TypeVal->get());
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002768 if (PTy == 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00002769 GEN_ERROR("Cannot make packed constant with type: '" +
Chris Lattnerff20ba32006-10-15 23:27:25 +00002770 (*yyvsp[-3].TypeVal)->getDescription() + "'!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002771 const Type *ETy = PTy->getElementType();
2772 int NumElements = PTy->getNumElements();
2773
2774 // Verify that we have the correct size...
Chris Lattnerff20ba32006-10-15 23:27:25 +00002775 if (NumElements != -1 && NumElements != (int)yyvsp[-1].ConstVector->size())
Reid Spencer713eedc2006-08-18 08:43:06 +00002776 GEN_ERROR("Type mismatch: constant sized packed initialized with " +
Chris Lattnerff20ba32006-10-15 23:27:25 +00002777 utostr(yyvsp[-1].ConstVector->size()) + " arguments, but has size of " +
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002778 itostr(NumElements) + "!");
2779
2780 // Verify all elements are correct type!
Chris Lattnerff20ba32006-10-15 23:27:25 +00002781 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
2782 if (ETy != (*yyvsp[-1].ConstVector)[i]->getType())
Reid Spencer713eedc2006-08-18 08:43:06 +00002783 GEN_ERROR("Element #" + utostr(i) + " is not of type '" +
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002784 ETy->getDescription() +"' as required!\nIt is of type '"+
Chris Lattnerff20ba32006-10-15 23:27:25 +00002785 (*yyvsp[-1].ConstVector)[i]->getType()->getDescription() + "'.");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002786 }
2787
Chris Lattnerff20ba32006-10-15 23:27:25 +00002788 yyval.ConstVal = ConstantPacked::get(PTy, *yyvsp[-1].ConstVector);
2789 delete yyvsp[-3].TypeVal; delete yyvsp[-1].ConstVector;
Reid Spencer713eedc2006-08-18 08:43:06 +00002790 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002791 ;
2792 break;}
2793case 100:
2794#line 1436 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2795{
2796 const StructType *STy = dyn_cast<StructType>(yyvsp[-3].TypeVal->get());
Reid Spencer713eedc2006-08-18 08:43:06 +00002797 if (STy == 0)
2798 GEN_ERROR("Cannot make struct constant with type: '" +
Chris Lattnerff20ba32006-10-15 23:27:25 +00002799 (*yyvsp[-3].TypeVal)->getDescription() + "'!");
Reid Spencer713eedc2006-08-18 08:43:06 +00002800
Chris Lattnerff20ba32006-10-15 23:27:25 +00002801 if (yyvsp[-1].ConstVector->size() != STy->getNumContainedTypes())
Reid Spencer713eedc2006-08-18 08:43:06 +00002802 GEN_ERROR("Illegal number of initializers for structure type!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002803
2804 // Check to ensure that constants are compatible with the type initializer!
Chris Lattnerff20ba32006-10-15 23:27:25 +00002805 for (unsigned i = 0, e = yyvsp[-1].ConstVector->size(); i != e; ++i)
2806 if ((*yyvsp[-1].ConstVector)[i]->getType() != STy->getElementType(i))
Reid Spencer713eedc2006-08-18 08:43:06 +00002807 GEN_ERROR("Expected type '" +
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002808 STy->getElementType(i)->getDescription() +
2809 "' for element #" + utostr(i) +
2810 " of structure initializer!");
2811
Chris Lattnerff20ba32006-10-15 23:27:25 +00002812 yyval.ConstVal = ConstantStruct::get(STy, *yyvsp[-1].ConstVector);
2813 delete yyvsp[-3].TypeVal; delete yyvsp[-1].ConstVector;
Reid Spencer713eedc2006-08-18 08:43:06 +00002814 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002815 ;
2816 break;}
2817case 101:
2818#line 1457 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2819{
2820 const StructType *STy = dyn_cast<StructType>(yyvsp[-2].TypeVal->get());
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002821 if (STy == 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00002822 GEN_ERROR("Cannot make struct constant with type: '" +
Chris Lattnerff20ba32006-10-15 23:27:25 +00002823 (*yyvsp[-2].TypeVal)->getDescription() + "'!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002824
2825 if (STy->getNumContainedTypes() != 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00002826 GEN_ERROR("Illegal number of initializers for structure type!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002827
Chris Lattnerff20ba32006-10-15 23:27:25 +00002828 yyval.ConstVal = ConstantStruct::get(STy, std::vector<Constant*>());
2829 delete yyvsp[-2].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002830 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002831 ;
2832 break;}
2833case 102:
2834#line 1470 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2835{
2836 const PointerType *PTy = dyn_cast<PointerType>(yyvsp[-1].TypeVal->get());
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002837 if (PTy == 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00002838 GEN_ERROR("Cannot make null pointer constant with type: '" +
Chris Lattnerff20ba32006-10-15 23:27:25 +00002839 (*yyvsp[-1].TypeVal)->getDescription() + "'!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002840
Chris Lattnerff20ba32006-10-15 23:27:25 +00002841 yyval.ConstVal = ConstantPointerNull::get(PTy);
2842 delete yyvsp[-1].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002843 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002844 ;
2845 break;}
2846case 103:
2847#line 1480 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2848{
2849 yyval.ConstVal = UndefValue::get(yyvsp[-1].TypeVal->get());
2850 delete yyvsp[-1].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002851 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002852 ;
2853 break;}
2854case 104:
2855#line 1485 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2856{
2857 const PointerType *Ty = dyn_cast<PointerType>(yyvsp[-1].TypeVal->get());
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002858 if (Ty == 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00002859 GEN_ERROR("Global const reference must be a pointer type!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002860
2861 // ConstExprs can exist in the body of a function, thus creating
2862 // GlobalValues whenever they refer to a variable. Because we are in
2863 // the context of a function, getValNonImprovising will search the functions
2864 // symbol table instead of the module symbol table for the global symbol,
2865 // which throws things all off. To get around this, we just tell
2866 // getValNonImprovising that we are at global scope here.
2867 //
2868 Function *SavedCurFn = CurFun.CurrentFunction;
2869 CurFun.CurrentFunction = 0;
2870
Chris Lattnerff20ba32006-10-15 23:27:25 +00002871 Value *V = getValNonImprovising(Ty, yyvsp[0].ValIDVal);
Reid Spencer309080a2006-09-28 19:28:24 +00002872 CHECK_FOR_ERROR
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002873
2874 CurFun.CurrentFunction = SavedCurFn;
2875
2876 // If this is an initializer for a constant pointer, which is referencing a
2877 // (currently) undefined variable, create a stub now that shall be replaced
2878 // in the future with the right type of variable.
2879 //
2880 if (V == 0) {
2881 assert(isa<PointerType>(Ty) && "Globals may only be used as pointers!");
2882 const PointerType *PT = cast<PointerType>(Ty);
2883
2884 // First check to see if the forward references value is already created!
2885 PerModuleInfo::GlobalRefsType::iterator I =
Chris Lattnerff20ba32006-10-15 23:27:25 +00002886 CurModule.GlobalRefs.find(std::make_pair(PT, yyvsp[0].ValIDVal));
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002887
2888 if (I != CurModule.GlobalRefs.end()) {
2889 V = I->second; // Placeholder already exists, use it...
Chris Lattnerff20ba32006-10-15 23:27:25 +00002890 yyvsp[0].ValIDVal.destroy();
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002891 } else {
2892 std::string Name;
Chris Lattnerff20ba32006-10-15 23:27:25 +00002893 if (yyvsp[0].ValIDVal.Type == ValID::NameVal) Name = yyvsp[0].ValIDVal.Name;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002894
2895 // Create the forward referenced global.
2896 GlobalValue *GV;
2897 if (const FunctionType *FTy =
2898 dyn_cast<FunctionType>(PT->getElementType())) {
2899 GV = new Function(FTy, GlobalValue::ExternalLinkage, Name,
2900 CurModule.CurrentModule);
2901 } else {
2902 GV = new GlobalVariable(PT->getElementType(), false,
2903 GlobalValue::ExternalLinkage, 0,
2904 Name, CurModule.CurrentModule);
2905 }
2906
2907 // Keep track of the fact that we have a forward ref to recycle it
Chris Lattnerff20ba32006-10-15 23:27:25 +00002908 CurModule.GlobalRefs.insert(std::make_pair(std::make_pair(PT, yyvsp[0].ValIDVal), GV));
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002909 V = GV;
2910 }
2911 }
2912
Chris Lattnerff20ba32006-10-15 23:27:25 +00002913 yyval.ConstVal = cast<GlobalValue>(V);
2914 delete yyvsp[-1].TypeVal; // Free the type handle
Reid Spencer713eedc2006-08-18 08:43:06 +00002915 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002916 ;
2917 break;}
2918case 105:
2919#line 1546 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2920{
2921 if (yyvsp[-1].TypeVal->get() != yyvsp[0].ConstVal->getType())
Reid Spencer713eedc2006-08-18 08:43:06 +00002922 GEN_ERROR("Mismatched types for constant expression!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00002923 yyval.ConstVal = yyvsp[0].ConstVal;
2924 delete yyvsp[-1].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002925 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002926 ;
2927 break;}
2928case 106:
2929#line 1553 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2930{
2931 const Type *Ty = yyvsp[-1].TypeVal->get();
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002932 if (isa<FunctionType>(Ty) || Ty == Type::LabelTy || isa<OpaqueType>(Ty))
Reid Spencer713eedc2006-08-18 08:43:06 +00002933 GEN_ERROR("Cannot create a null initialized value of this type!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00002934 yyval.ConstVal = Constant::getNullValue(Ty);
2935 delete yyvsp[-1].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002936 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002937 ;
2938 break;}
2939case 107:
2940#line 1562 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2941{ // integral constants
2942 if (!ConstantSInt::isValueValidForType(yyvsp[-1].PrimType, yyvsp[0].SInt64Val))
Reid Spencer713eedc2006-08-18 08:43:06 +00002943 GEN_ERROR("Constant value doesn't fit in type!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00002944 yyval.ConstVal = ConstantSInt::get(yyvsp[-1].PrimType, yyvsp[0].SInt64Val);
Reid Spencer713eedc2006-08-18 08:43:06 +00002945 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002946 ;
2947 break;}
2948case 108:
2949#line 1568 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2950{ // integral constants
2951 if (!ConstantUInt::isValueValidForType(yyvsp[-1].PrimType, yyvsp[0].UInt64Val))
Reid Spencer713eedc2006-08-18 08:43:06 +00002952 GEN_ERROR("Constant value doesn't fit in type!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00002953 yyval.ConstVal = ConstantUInt::get(yyvsp[-1].PrimType, yyvsp[0].UInt64Val);
Reid Spencer713eedc2006-08-18 08:43:06 +00002954 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002955 ;
2956 break;}
2957case 109:
2958#line 1574 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2959{ // Boolean constants
2960 yyval.ConstVal = ConstantBool::getTrue();
Reid Spencer713eedc2006-08-18 08:43:06 +00002961 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002962 ;
2963 break;}
2964case 110:
2965#line 1578 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2966{ // Boolean constants
2967 yyval.ConstVal = ConstantBool::getFalse();
Reid Spencer713eedc2006-08-18 08:43:06 +00002968 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002969 ;
2970 break;}
2971case 111:
2972#line 1582 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2973{ // Float & Double constants
2974 if (!ConstantFP::isValueValidForType(yyvsp[-1].PrimType, yyvsp[0].FPVal))
Reid Spencer713eedc2006-08-18 08:43:06 +00002975 GEN_ERROR("Floating point constant invalid for type!!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00002976 yyval.ConstVal = ConstantFP::get(yyvsp[-1].PrimType, yyvsp[0].FPVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00002977 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002978 ;
2979 break;}
2980case 112:
2981#line 1590 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2982{
2983 if (!yyvsp[-3].ConstVal->getType()->isFirstClassType())
Reid Spencer713eedc2006-08-18 08:43:06 +00002984 GEN_ERROR("cast constant expression from a non-primitive type: '" +
Chris Lattnerff20ba32006-10-15 23:27:25 +00002985 yyvsp[-3].ConstVal->getType()->getDescription() + "'!");
2986 if (!yyvsp[-1].TypeVal->get()->isFirstClassType())
Reid Spencer713eedc2006-08-18 08:43:06 +00002987 GEN_ERROR("cast constant expression to a non-primitive type: '" +
Chris Lattnerff20ba32006-10-15 23:27:25 +00002988 yyvsp[-1].TypeVal->get()->getDescription() + "'!");
2989 yyval.ConstVal = ConstantExpr::getCast(yyvsp[-3].ConstVal, yyvsp[-1].TypeVal->get());
2990 delete yyvsp[-1].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00002991 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00002992 ;
2993 break;}
2994case 113:
2995#line 1601 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
2996{
2997 if (!isa<PointerType>(yyvsp[-2].ConstVal->getType()))
Reid Spencer713eedc2006-08-18 08:43:06 +00002998 GEN_ERROR("GetElementPtr requires a pointer operand!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00002999
3000 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte struct
3001 // indices to uint struct indices for compatibility.
3002 generic_gep_type_iterator<std::vector<Value*>::iterator>
Chris Lattnerff20ba32006-10-15 23:27:25 +00003003 GTI = gep_type_begin(yyvsp[-2].ConstVal->getType(), yyvsp[-1].ValueList->begin(), yyvsp[-1].ValueList->end()),
3004 GTE = gep_type_end(yyvsp[-2].ConstVal->getType(), yyvsp[-1].ValueList->begin(), yyvsp[-1].ValueList->end());
3005 for (unsigned i = 0, e = yyvsp[-1].ValueList->size(); i != e && GTI != GTE; ++i, ++GTI)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003006 if (isa<StructType>(*GTI)) // Only change struct indices
Chris Lattnerff20ba32006-10-15 23:27:25 +00003007 if (ConstantUInt *CUI = dyn_cast<ConstantUInt>((*yyvsp[-1].ValueList)[i]))
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003008 if (CUI->getType() == Type::UByteTy)
Chris Lattnerff20ba32006-10-15 23:27:25 +00003009 (*yyvsp[-1].ValueList)[i] = ConstantExpr::getCast(CUI, Type::UIntTy);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003010
3011 const Type *IdxTy =
Chris Lattnerff20ba32006-10-15 23:27:25 +00003012 GetElementPtrInst::getIndexedType(yyvsp[-2].ConstVal->getType(), *yyvsp[-1].ValueList, true);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003013 if (!IdxTy)
Reid Spencer713eedc2006-08-18 08:43:06 +00003014 GEN_ERROR("Index list invalid for constant getelementptr!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003015
3016 std::vector<Constant*> IdxVec;
Chris Lattnerff20ba32006-10-15 23:27:25 +00003017 for (unsigned i = 0, e = yyvsp[-1].ValueList->size(); i != e; ++i)
3018 if (Constant *C = dyn_cast<Constant>((*yyvsp[-1].ValueList)[i]))
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003019 IdxVec.push_back(C);
3020 else
Reid Spencer713eedc2006-08-18 08:43:06 +00003021 GEN_ERROR("Indices to constant getelementptr must be constants!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003022
Chris Lattnerff20ba32006-10-15 23:27:25 +00003023 delete yyvsp[-1].ValueList;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003024
Chris Lattnerff20ba32006-10-15 23:27:25 +00003025 yyval.ConstVal = ConstantExpr::getGetElementPtr(yyvsp[-2].ConstVal, IdxVec);
Reid Spencer713eedc2006-08-18 08:43:06 +00003026 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003027 ;
3028 break;}
3029case 114:
3030#line 1633 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3031{
3032 if (yyvsp[-5].ConstVal->getType() != Type::BoolTy)
Reid Spencer713eedc2006-08-18 08:43:06 +00003033 GEN_ERROR("Select condition must be of boolean type!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00003034 if (yyvsp[-3].ConstVal->getType() != yyvsp[-1].ConstVal->getType())
Reid Spencer713eedc2006-08-18 08:43:06 +00003035 GEN_ERROR("Select operand types must match!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00003036 yyval.ConstVal = ConstantExpr::getSelect(yyvsp[-5].ConstVal, yyvsp[-3].ConstVal, yyvsp[-1].ConstVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003037 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003038 ;
3039 break;}
3040case 115:
3041#line 1641 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3042{
3043 if (yyvsp[-3].ConstVal->getType() != yyvsp[-1].ConstVal->getType())
Reid Spencer713eedc2006-08-18 08:43:06 +00003044 GEN_ERROR("Binary operator types must match!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003045 // HACK: llvm 1.3 and earlier used to emit invalid pointer constant exprs.
3046 // To retain backward compatibility with these early compilers, we emit a
3047 // cast to the appropriate integer type automatically if we are in the
3048 // broken case. See PR424 for more information.
Chris Lattnerff20ba32006-10-15 23:27:25 +00003049 if (!isa<PointerType>(yyvsp[-3].ConstVal->getType())) {
3050 yyval.ConstVal = ConstantExpr::get(yyvsp[-5].BinaryOpVal, yyvsp[-3].ConstVal, yyvsp[-1].ConstVal);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003051 } else {
3052 const Type *IntPtrTy = 0;
3053 switch (CurModule.CurrentModule->getPointerSize()) {
3054 case Module::Pointer32: IntPtrTy = Type::IntTy; break;
3055 case Module::Pointer64: IntPtrTy = Type::LongTy; break;
Reid Spencer713eedc2006-08-18 08:43:06 +00003056 default: GEN_ERROR("invalid pointer binary constant expr!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003057 }
Chris Lattnerff20ba32006-10-15 23:27:25 +00003058 yyval.ConstVal = ConstantExpr::get(yyvsp[-5].BinaryOpVal, ConstantExpr::getCast(yyvsp[-3].ConstVal, IntPtrTy),
3059 ConstantExpr::getCast(yyvsp[-1].ConstVal, IntPtrTy));
3060 yyval.ConstVal = ConstantExpr::getCast(yyval.ConstVal, yyvsp[-3].ConstVal->getType());
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003061 }
Reid Spencer713eedc2006-08-18 08:43:06 +00003062 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003063 ;
3064 break;}
3065case 116:
3066#line 1663 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3067{
3068 if (yyvsp[-3].ConstVal->getType() != yyvsp[-1].ConstVal->getType())
Reid Spencer713eedc2006-08-18 08:43:06 +00003069 GEN_ERROR("Logical operator types must match!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00003070 if (!yyvsp[-3].ConstVal->getType()->isIntegral()) {
3071 if (!isa<PackedType>(yyvsp[-3].ConstVal->getType()) ||
3072 !cast<PackedType>(yyvsp[-3].ConstVal->getType())->getElementType()->isIntegral())
Reid Spencer713eedc2006-08-18 08:43:06 +00003073 GEN_ERROR("Logical operator requires integral operands!");
Chris Lattner15f5a182005-12-21 18:31:50 +00003074 }
Chris Lattnerff20ba32006-10-15 23:27:25 +00003075 yyval.ConstVal = ConstantExpr::get(yyvsp[-5].BinaryOpVal, yyvsp[-3].ConstVal, yyvsp[-1].ConstVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003076 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003077 ;
3078 break;}
3079case 117:
3080#line 1674 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3081{
3082 if (yyvsp[-3].ConstVal->getType() != yyvsp[-1].ConstVal->getType())
Reid Spencer713eedc2006-08-18 08:43:06 +00003083 GEN_ERROR("setcc operand types must match!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00003084 yyval.ConstVal = ConstantExpr::get(yyvsp[-5].BinaryOpVal, yyvsp[-3].ConstVal, yyvsp[-1].ConstVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003085 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003086 ;
3087 break;}
3088case 118:
3089#line 1680 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3090{
3091 if (yyvsp[-1].ConstVal->getType() != Type::UByteTy)
Reid Spencer713eedc2006-08-18 08:43:06 +00003092 GEN_ERROR("Shift count for shift constant must be unsigned byte!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00003093 if (!yyvsp[-3].ConstVal->getType()->isInteger())
Reid Spencer713eedc2006-08-18 08:43:06 +00003094 GEN_ERROR("Shift constant expression requires integer operand!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00003095 yyval.ConstVal = ConstantExpr::get(yyvsp[-5].OtherOpVal, yyvsp[-3].ConstVal, yyvsp[-1].ConstVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003096 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003097 ;
3098 break;}
3099case 119:
3100#line 1688 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3101{
3102 if (!ExtractElementInst::isValidOperands(yyvsp[-3].ConstVal, yyvsp[-1].ConstVal))
Reid Spencer713eedc2006-08-18 08:43:06 +00003103 GEN_ERROR("Invalid extractelement operands!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00003104 yyval.ConstVal = ConstantExpr::getExtractElement(yyvsp[-3].ConstVal, yyvsp[-1].ConstVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003105 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003106 ;
3107 break;}
3108case 120:
3109#line 1694 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3110{
3111 if (!InsertElementInst::isValidOperands(yyvsp[-5].ConstVal, yyvsp[-3].ConstVal, yyvsp[-1].ConstVal))
Reid Spencer713eedc2006-08-18 08:43:06 +00003112 GEN_ERROR("Invalid insertelement operands!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00003113 yyval.ConstVal = ConstantExpr::getInsertElement(yyvsp[-5].ConstVal, yyvsp[-3].ConstVal, yyvsp[-1].ConstVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003114 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003115 ;
3116 break;}
3117case 121:
3118#line 1700 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3119{
3120 if (!ShuffleVectorInst::isValidOperands(yyvsp[-5].ConstVal, yyvsp[-3].ConstVal, yyvsp[-1].ConstVal))
Reid Spencer713eedc2006-08-18 08:43:06 +00003121 GEN_ERROR("Invalid shufflevector operands!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00003122 yyval.ConstVal = ConstantExpr::getShuffleVector(yyvsp[-5].ConstVal, yyvsp[-3].ConstVal, yyvsp[-1].ConstVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003123 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003124 ;
3125 break;}
3126case 122:
3127#line 1709 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3128{
3129 (yyval.ConstVector = yyvsp[-2].ConstVector)->push_back(yyvsp[0].ConstVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003130 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003131 ;
3132 break;}
3133case 123:
3134#line 1713 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3135{
3136 yyval.ConstVector = new std::vector<Constant*>();
3137 yyval.ConstVector->push_back(yyvsp[0].ConstVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003138 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003139 ;
3140 break;}
3141case 124:
3142#line 1721 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3143{ yyval.BoolVal = false; ;
3144 break;}
3145case 125:
3146#line 1721 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3147{ yyval.BoolVal = true; ;
3148 break;}
3149case 126:
3150#line 1731 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3151{
3152 yyval.ModuleVal = ParserResult = yyvsp[0].ModuleVal;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003153 CurModule.ModuleDone();
Reid Spencerff359002006-10-09 17:36:59 +00003154 CHECK_FOR_ERROR;
Chris Lattnerff20ba32006-10-15 23:27:25 +00003155;
3156 break;}
3157case 127:
3158#line 1739 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3159{
3160 yyval.ModuleVal = yyvsp[-1].ModuleVal;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003161 CurFun.FunctionDone();
Reid Spencer713eedc2006-08-18 08:43:06 +00003162 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003163 ;
3164 break;}
3165case 128:
3166#line 1744 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3167{
3168 yyval.ModuleVal = yyvsp[-1].ModuleVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00003169 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003170 ;
3171 break;}
3172case 129:
3173#line 1748 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3174{
3175 yyval.ModuleVal = yyvsp[-3].ModuleVal;
Anton Korobeynikov6f7072c2006-09-17 20:25:45 +00003176 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003177 ;
3178 break;}
3179case 130:
3180#line 1752 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3181{
3182 yyval.ModuleVal = yyvsp[-1].ModuleVal;
Anton Korobeynikov6f7072c2006-09-17 20:25:45 +00003183 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003184 ;
3185 break;}
3186case 131:
3187#line 1756 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3188{
3189 yyval.ModuleVal = CurModule.CurrentModule;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003190 // Emit an error if there are any unresolved types left.
3191 if (!CurModule.LateResolveTypes.empty()) {
3192 const ValID &DID = CurModule.LateResolveTypes.begin()->first;
Reid Spencer713eedc2006-08-18 08:43:06 +00003193 if (DID.Type == ValID::NameVal) {
3194 GEN_ERROR("Reference to an undefined type: '"+DID.getName() + "'");
3195 } else {
3196 GEN_ERROR("Reference to an undefined type: #" + itostr(DID.Num));
3197 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003198 }
Reid Spencer713eedc2006-08-18 08:43:06 +00003199 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003200 ;
3201 break;}
3202case 132:
3203#line 1771 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3204{
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003205 // Eagerly resolve types. This is not an optimization, this is a
3206 // requirement that is due to the fact that we could have this:
3207 //
3208 // %list = type { %list * }
3209 // %list = type { %list * } ; repeated type decl
3210 //
3211 // If types are not resolved eagerly, then the two types will not be
3212 // determined to be the same type!
3213 //
Chris Lattnerff20ba32006-10-15 23:27:25 +00003214 ResolveTypeTo(yyvsp[-2].StrVal, *yyvsp[0].TypeVal);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003215
Chris Lattnerff20ba32006-10-15 23:27:25 +00003216 if (!setTypeName(*yyvsp[0].TypeVal, yyvsp[-2].StrVal) && !yyvsp[-2].StrVal) {
Reid Spencer309080a2006-09-28 19:28:24 +00003217 CHECK_FOR_ERROR
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003218 // If this is a named type that is not a redefinition, add it to the slot
3219 // table.
Chris Lattnerff20ba32006-10-15 23:27:25 +00003220 CurModule.Types.push_back(*yyvsp[0].TypeVal);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003221 }
3222
Chris Lattnerff20ba32006-10-15 23:27:25 +00003223 delete yyvsp[0].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00003224 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003225 ;
3226 break;}
3227case 133:
3228#line 1793 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3229{ // Function prototypes can be in const pool
Reid Spencer713eedc2006-08-18 08:43:06 +00003230 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003231 ;
3232 break;}
3233case 134:
3234#line 1796 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3235{ // Asm blocks can be in the const pool
Reid Spencer713eedc2006-08-18 08:43:06 +00003236 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003237 ;
3238 break;}
3239case 135:
3240#line 1799 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3241{
3242 if (yyvsp[0].ConstVal == 0)
Reid Spencer309080a2006-09-28 19:28:24 +00003243 GEN_ERROR("Global value initializer is not a constant!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00003244 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, yyvsp[-2].Linkage, yyvsp[-1].BoolVal, yyvsp[0].ConstVal->getType(), yyvsp[0].ConstVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003245 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003246 ;
3247 break;}
3248case 136:
3249#line 1804 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3250{
Reid Spencer309080a2006-09-28 19:28:24 +00003251 CurGV = 0;
Chris Lattnerff20ba32006-10-15 23:27:25 +00003252 ;
3253 break;}
3254case 137:
3255#line 1807 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3256{
3257 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::ExternalLinkage, yyvsp[-1].BoolVal, *yyvsp[0].TypeVal, 0);
Reid Spencer309080a2006-09-28 19:28:24 +00003258 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003259 delete yyvsp[0].TypeVal;
3260 ;
3261 break;}
3262case 138:
3263#line 1811 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3264{
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00003265 CurGV = 0;
Reid Spencer713eedc2006-08-18 08:43:06 +00003266 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003267 ;
3268 break;}
3269case 139:
3270#line 1815 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3271{
3272 CurGV = ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::DLLImportLinkage, yyvsp[-1].BoolVal, *yyvsp[0].TypeVal, 0);
Reid Spencer309080a2006-09-28 19:28:24 +00003273 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003274 delete yyvsp[0].TypeVal;
3275 ;
3276 break;}
3277case 140:
3278#line 1819 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3279{
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00003280 CurGV = 0;
Reid Spencer713eedc2006-08-18 08:43:06 +00003281 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003282 ;
3283 break;}
3284case 141:
3285#line 1823 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3286{
Reid Spencer309080a2006-09-28 19:28:24 +00003287 CurGV =
Chris Lattnerff20ba32006-10-15 23:27:25 +00003288 ParseGlobalVariable(yyvsp[-3].StrVal, GlobalValue::ExternalWeakLinkage, yyvsp[-1].BoolVal, *yyvsp[0].TypeVal, 0);
Reid Spencer309080a2006-09-28 19:28:24 +00003289 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003290 delete yyvsp[0].TypeVal;
3291 ;
3292 break;}
3293case 142:
3294#line 1828 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3295{
Anton Korobeynikov6f7072c2006-09-17 20:25:45 +00003296 CurGV = 0;
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00003297 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003298 ;
3299 break;}
3300case 143:
3301#line 1832 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3302{
Anton Korobeynikov6f7072c2006-09-17 20:25:45 +00003303 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003304 ;
3305 break;}
3306case 144:
3307#line 1835 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3308{
Anton Korobeynikov6f7072c2006-09-17 20:25:45 +00003309 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003310 ;
3311 break;}
3312case 145:
3313#line 1838 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3314{
3315 ;
3316 break;}
3317case 146:
3318#line 1842 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3319{
Chris Lattner8ebd2162006-01-24 04:14:29 +00003320 const std::string &AsmSoFar = CurModule.CurrentModule->getModuleInlineAsm();
Chris Lattnerff20ba32006-10-15 23:27:25 +00003321 char *EndStr = UnEscapeLexed(yyvsp[0].StrVal, true);
3322 std::string NewAsm(yyvsp[0].StrVal, EndStr);
3323 free(yyvsp[0].StrVal);
Chris Lattner8ebd2162006-01-24 04:14:29 +00003324
3325 if (AsmSoFar.empty())
3326 CurModule.CurrentModule->setModuleInlineAsm(NewAsm);
3327 else
3328 CurModule.CurrentModule->setModuleInlineAsm(AsmSoFar+"\n"+NewAsm);
Reid Spencer713eedc2006-08-18 08:43:06 +00003329 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003330;
3331 break;}
3332case 147:
3333#line 1855 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3334{ yyval.Endianness = Module::BigEndian; ;
3335 break;}
3336case 148:
3337#line 1856 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3338{ yyval.Endianness = Module::LittleEndian; ;
3339 break;}
3340case 149:
3341#line 1858 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3342{
3343 CurModule.CurrentModule->setEndianness(yyvsp[0].Endianness);
Reid Spencer713eedc2006-08-18 08:43:06 +00003344 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003345 ;
3346 break;}
3347case 150:
3348#line 1862 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3349{
3350 if (yyvsp[0].UInt64Val == 32)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003351 CurModule.CurrentModule->setPointerSize(Module::Pointer32);
Chris Lattnerff20ba32006-10-15 23:27:25 +00003352 else if (yyvsp[0].UInt64Val == 64)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003353 CurModule.CurrentModule->setPointerSize(Module::Pointer64);
3354 else
Chris Lattnerff20ba32006-10-15 23:27:25 +00003355 GEN_ERROR("Invalid pointer size: '" + utostr(yyvsp[0].UInt64Val) + "'!");
Reid Spencer713eedc2006-08-18 08:43:06 +00003356 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003357 ;
3358 break;}
3359case 151:
3360#line 1871 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3361{
3362 CurModule.CurrentModule->setTargetTriple(yyvsp[0].StrVal);
3363 free(yyvsp[0].StrVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003364 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003365 ;
3366 break;}
3367case 153:
3368#line 1879 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3369{
3370 CurModule.CurrentModule->addLibrary(yyvsp[0].StrVal);
3371 free(yyvsp[0].StrVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003372 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003373 ;
3374 break;}
3375case 154:
3376#line 1884 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3377{
3378 CurModule.CurrentModule->addLibrary(yyvsp[0].StrVal);
3379 free(yyvsp[0].StrVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003380 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003381 ;
3382 break;}
3383case 155:
3384#line 1889 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3385{
Reid Spencer713eedc2006-08-18 08:43:06 +00003386 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003387 ;
3388 break;}
3389case 159:
3390#line 1899 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3391{ yyval.StrVal = 0; ;
3392 break;}
3393case 160:
3394#line 1901 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3395{
3396 if (*yyvsp[-1].TypeVal == Type::VoidTy)
Reid Spencer713eedc2006-08-18 08:43:06 +00003397 GEN_ERROR("void typed arguments are invalid!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00003398 yyval.ArgVal = new std::pair<PATypeHolder*, char*>(yyvsp[-1].TypeVal, yyvsp[0].StrVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003399 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003400;
3401 break;}
3402case 161:
3403#line 1908 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3404{
3405 yyval.ArgList = yyvsp[-2].ArgList;
3406 yyvsp[-2].ArgList->push_back(*yyvsp[0].ArgVal);
3407 delete yyvsp[0].ArgVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00003408 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003409 ;
3410 break;}
3411case 162:
3412#line 1914 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3413{
3414 yyval.ArgList = new std::vector<std::pair<PATypeHolder*,char*> >();
3415 yyval.ArgList->push_back(*yyvsp[0].ArgVal);
3416 delete yyvsp[0].ArgVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00003417 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003418 ;
3419 break;}
3420case 163:
3421#line 1921 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3422{
3423 yyval.ArgList = yyvsp[0].ArgList;
Reid Spencer713eedc2006-08-18 08:43:06 +00003424 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003425 ;
3426 break;}
3427case 164:
3428#line 1925 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3429{
3430 yyval.ArgList = yyvsp[-2].ArgList;
3431 yyval.ArgList->push_back(std::pair<PATypeHolder*,
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003432 char*>(new PATypeHolder(Type::VoidTy), 0));
Reid Spencer713eedc2006-08-18 08:43:06 +00003433 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003434 ;
3435 break;}
3436case 165:
3437#line 1931 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3438{
3439 yyval.ArgList = new std::vector<std::pair<PATypeHolder*,char*> >();
3440 yyval.ArgList->push_back(std::make_pair(new PATypeHolder(Type::VoidTy), (char*)0));
Reid Spencer713eedc2006-08-18 08:43:06 +00003441 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003442 ;
3443 break;}
3444case 166:
3445#line 1936 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3446{
3447 yyval.ArgList = 0;
Reid Spencer713eedc2006-08-18 08:43:06 +00003448 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003449 ;
3450 break;}
3451case 167:
3452#line 1942 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3453{
3454 UnEscapeLexed(yyvsp[-5].StrVal);
3455 std::string FunctionName(yyvsp[-5].StrVal);
3456 free(yyvsp[-5].StrVal); // Free strdup'd memory!
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003457
Chris Lattnerff20ba32006-10-15 23:27:25 +00003458 if (!(*yyvsp[-6].TypeVal)->isFirstClassType() && *yyvsp[-6].TypeVal != Type::VoidTy)
Reid Spencer713eedc2006-08-18 08:43:06 +00003459 GEN_ERROR("LLVM functions cannot return aggregate types!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003460
3461 std::vector<const Type*> ParamTypeList;
Chris Lattnerff20ba32006-10-15 23:27:25 +00003462 if (yyvsp[-3].ArgList) { // If there are arguments...
3463 for (std::vector<std::pair<PATypeHolder*,char*> >::iterator I = yyvsp[-3].ArgList->begin();
3464 I != yyvsp[-3].ArgList->end(); ++I)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003465 ParamTypeList.push_back(I->first->get());
3466 }
3467
3468 bool isVarArg = ParamTypeList.size() && ParamTypeList.back() == Type::VoidTy;
3469 if (isVarArg) ParamTypeList.pop_back();
3470
Chris Lattnerff20ba32006-10-15 23:27:25 +00003471 const FunctionType *FT = FunctionType::get(*yyvsp[-6].TypeVal, ParamTypeList, isVarArg);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003472 const PointerType *PFT = PointerType::get(FT);
Chris Lattnerff20ba32006-10-15 23:27:25 +00003473 delete yyvsp[-6].TypeVal;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003474
3475 ValID ID;
3476 if (!FunctionName.empty()) {
3477 ID = ValID::create((char*)FunctionName.c_str());
3478 } else {
3479 ID = ValID::create((int)CurModule.Values[PFT].size());
3480 }
3481
3482 Function *Fn = 0;
3483 // See if this function was forward referenced. If so, recycle the object.
3484 if (GlobalValue *FWRef = CurModule.GetForwardRefForGlobal(PFT, ID)) {
3485 // Move the function to the end of the list, from whereever it was
3486 // previously inserted.
3487 Fn = cast<Function>(FWRef);
3488 CurModule.CurrentModule->getFunctionList().remove(Fn);
3489 CurModule.CurrentModule->getFunctionList().push_back(Fn);
3490 } else if (!FunctionName.empty() && // Merge with an earlier prototype?
3491 (Fn = CurModule.CurrentModule->getFunction(FunctionName, FT))) {
3492 // If this is the case, either we need to be a forward decl, or it needs
3493 // to be.
3494 if (!CurFun.isDeclare && !Fn->isExternal())
Reid Spencer713eedc2006-08-18 08:43:06 +00003495 GEN_ERROR("Redefinition of function '" + FunctionName + "'!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003496
3497 // Make sure to strip off any argument names so we can't get conflicts.
3498 if (Fn->isExternal())
3499 for (Function::arg_iterator AI = Fn->arg_begin(), AE = Fn->arg_end();
3500 AI != AE; ++AI)
3501 AI->setName("");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003502 } else { // Not already defined?
3503 Fn = new Function(FT, GlobalValue::ExternalLinkage, FunctionName,
3504 CurModule.CurrentModule);
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00003505
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003506 InsertValue(Fn, CurModule.Values);
3507 }
3508
3509 CurFun.FunctionStart(Fn);
Anton Korobeynikov0ab01ff2006-09-17 13:06:18 +00003510
3511 if (CurFun.isDeclare) {
3512 // If we have declaration, always overwrite linkage. This will allow us to
3513 // correctly handle cases, when pointer to function is passed as argument to
3514 // another function.
3515 Fn->setLinkage(CurFun.Linkage);
3516 }
Chris Lattnerff20ba32006-10-15 23:27:25 +00003517 Fn->setCallingConv(yyvsp[-7].UIntVal);
3518 Fn->setAlignment(yyvsp[0].UIntVal);
3519 if (yyvsp[-1].StrVal) {
3520 Fn->setSection(yyvsp[-1].StrVal);
3521 free(yyvsp[-1].StrVal);
Chris Lattnera0c20b42005-11-12 00:11:49 +00003522 }
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003523
3524 // Add all of the arguments we parsed to the function...
Chris Lattnerff20ba32006-10-15 23:27:25 +00003525 if (yyvsp[-3].ArgList) { // Is null if empty...
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003526 if (isVarArg) { // Nuke the last entry
Chris Lattnerff20ba32006-10-15 23:27:25 +00003527 assert(yyvsp[-3].ArgList->back().first->get() == Type::VoidTy && yyvsp[-3].ArgList->back().second == 0&&
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003528 "Not a varargs marker!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00003529 delete yyvsp[-3].ArgList->back().first;
3530 yyvsp[-3].ArgList->pop_back(); // Delete the last entry
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003531 }
3532 Function::arg_iterator ArgIt = Fn->arg_begin();
Chris Lattnerff20ba32006-10-15 23:27:25 +00003533 for (std::vector<std::pair<PATypeHolder*,char*> >::iterator I = yyvsp[-3].ArgList->begin();
3534 I != yyvsp[-3].ArgList->end(); ++I, ++ArgIt) {
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003535 delete I->first; // Delete the typeholder...
3536
3537 setValueName(ArgIt, I->second); // Insert arg into symtab...
Reid Spencer309080a2006-09-28 19:28:24 +00003538 CHECK_FOR_ERROR
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003539 InsertValue(ArgIt);
3540 }
3541
Chris Lattnerff20ba32006-10-15 23:27:25 +00003542 delete yyvsp[-3].ArgList; // We're now done with the argument list
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003543 }
Reid Spencer713eedc2006-08-18 08:43:06 +00003544 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003545;
3546 break;}
3547case 170:
3548#line 2038 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3549{
3550 yyval.FunctionVal = CurFun.CurrentFunction;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003551
3552 // Make sure that we keep track of the linkage type even if there was a
3553 // previous "declare".
Chris Lattnerff20ba32006-10-15 23:27:25 +00003554 yyval.FunctionVal->setLinkage(yyvsp[-2].Linkage);
3555;
3556 break;}
3557case 173:
3558#line 2048 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3559{
3560 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00003561 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003562;
3563 break;}
3564case 175:
3565#line 2054 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3566{ CurFun.Linkage = GlobalValue::DLLImportLinkage ;
3567 break;}
3568case 176:
3569#line 2055 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3570{ CurFun.Linkage = GlobalValue::DLLImportLinkage ;
3571 break;}
3572case 177:
3573#line 2057 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3574{ CurFun.isDeclare = true; ;
3575 break;}
3576case 178:
3577#line 2057 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3578{
3579 yyval.FunctionVal = CurFun.CurrentFunction;
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00003580 CurFun.FunctionDone();
Reid Spencer713eedc2006-08-18 08:43:06 +00003581 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003582 ;
3583 break;}
3584case 179:
3585#line 2067 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3586{
3587 yyval.BoolVal = false;
Reid Spencer713eedc2006-08-18 08:43:06 +00003588 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003589 ;
3590 break;}
3591case 180:
3592#line 2071 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3593{
3594 yyval.BoolVal = true;
Reid Spencer713eedc2006-08-18 08:43:06 +00003595 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003596 ;
3597 break;}
3598case 181:
3599#line 2076 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3600{ // A reference to a direct constant
3601 yyval.ValIDVal = ValID::create(yyvsp[0].SInt64Val);
Reid Spencer713eedc2006-08-18 08:43:06 +00003602 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003603 ;
3604 break;}
3605case 182:
3606#line 2080 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3607{
3608 yyval.ValIDVal = ValID::create(yyvsp[0].UInt64Val);
Reid Spencer713eedc2006-08-18 08:43:06 +00003609 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003610 ;
3611 break;}
3612case 183:
3613#line 2084 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3614{ // Perhaps it's an FP constant?
3615 yyval.ValIDVal = ValID::create(yyvsp[0].FPVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003616 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003617 ;
3618 break;}
3619case 184:
3620#line 2088 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3621{
3622 yyval.ValIDVal = ValID::create(ConstantBool::getTrue());
Reid Spencer713eedc2006-08-18 08:43:06 +00003623 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003624 ;
3625 break;}
3626case 185:
3627#line 2092 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3628{
3629 yyval.ValIDVal = ValID::create(ConstantBool::getFalse());
Reid Spencer713eedc2006-08-18 08:43:06 +00003630 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003631 ;
3632 break;}
3633case 186:
3634#line 2096 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3635{
3636 yyval.ValIDVal = ValID::createNull();
Reid Spencer713eedc2006-08-18 08:43:06 +00003637 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003638 ;
3639 break;}
3640case 187:
3641#line 2100 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3642{
3643 yyval.ValIDVal = ValID::createUndef();
Reid Spencer713eedc2006-08-18 08:43:06 +00003644 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003645 ;
3646 break;}
3647case 188:
3648#line 2104 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3649{ // A vector zero constant.
3650 yyval.ValIDVal = ValID::createZeroInit();
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00003651 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003652 ;
3653 break;}
3654case 189:
3655#line 2108 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3656{ // Nonempty unsized packed vector
3657 const Type *ETy = (*yyvsp[-1].ConstVector)[0]->getType();
3658 int NumElements = yyvsp[-1].ConstVector->size();
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003659
3660 PackedType* pt = PackedType::get(ETy, NumElements);
3661 PATypeHolder* PTy = new PATypeHolder(
3662 HandleUpRefs(
3663 PackedType::get(
3664 ETy,
3665 NumElements)
3666 )
3667 );
3668
3669 // Verify all elements are correct type!
Chris Lattnerff20ba32006-10-15 23:27:25 +00003670 for (unsigned i = 0; i < yyvsp[-1].ConstVector->size(); i++) {
3671 if (ETy != (*yyvsp[-1].ConstVector)[i]->getType())
Reid Spencer713eedc2006-08-18 08:43:06 +00003672 GEN_ERROR("Element #" + utostr(i) + " is not of type '" +
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003673 ETy->getDescription() +"' as required!\nIt is of type '" +
Chris Lattnerff20ba32006-10-15 23:27:25 +00003674 (*yyvsp[-1].ConstVector)[i]->getType()->getDescription() + "'.");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003675 }
3676
Chris Lattnerff20ba32006-10-15 23:27:25 +00003677 yyval.ValIDVal = ValID::create(ConstantPacked::get(pt, *yyvsp[-1].ConstVector));
3678 delete PTy; delete yyvsp[-1].ConstVector;
Reid Spencer713eedc2006-08-18 08:43:06 +00003679 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003680 ;
3681 break;}
3682case 190:
3683#line 2133 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3684{
3685 yyval.ValIDVal = ValID::create(yyvsp[0].ConstVal);
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00003686 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003687 ;
3688 break;}
3689case 191:
3690#line 2137 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3691{
3692 char *End = UnEscapeLexed(yyvsp[-2].StrVal, true);
3693 std::string AsmStr = std::string(yyvsp[-2].StrVal, End);
3694 End = UnEscapeLexed(yyvsp[0].StrVal, true);
3695 std::string Constraints = std::string(yyvsp[0].StrVal, End);
3696 yyval.ValIDVal = ValID::createInlineAsm(AsmStr, Constraints, yyvsp[-3].BoolVal);
3697 free(yyvsp[-2].StrVal);
3698 free(yyvsp[0].StrVal);
Anton Korobeynikov73441cd2006-09-14 18:25:26 +00003699 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003700 ;
3701 break;}
3702case 192:
3703#line 2151 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3704{ // Is it an integer reference...?
3705 yyval.ValIDVal = ValID::create(yyvsp[0].SIntVal);
Reid Spencerff359002006-10-09 17:36:59 +00003706 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003707 ;
3708 break;}
3709case 193:
3710#line 2155 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3711{ // Is it a named reference...?
3712 yyval.ValIDVal = ValID::create(yyvsp[0].StrVal);
Reid Spencerff359002006-10-09 17:36:59 +00003713 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003714 ;
3715 break;}
3716case 196:
3717#line 2167 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3718{
3719 yyval.ValueVal = getVal(*yyvsp[-1].TypeVal, yyvsp[0].ValIDVal); delete yyvsp[-1].TypeVal;
Reid Spencerff359002006-10-09 17:36:59 +00003720 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003721 ;
3722 break;}
3723case 197:
3724#line 2172 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3725{
3726 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Reid Spencerff359002006-10-09 17:36:59 +00003727 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003728 ;
3729 break;}
3730case 198:
3731#line 2176 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3732{ // Do not allow functions with 0 basic blocks
3733 yyval.FunctionVal = yyvsp[-1].FunctionVal;
Reid Spencerff359002006-10-09 17:36:59 +00003734 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003735 ;
3736 break;}
3737case 199:
3738#line 2185 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3739{
3740 setValueName(yyvsp[0].TermInstVal, yyvsp[-1].StrVal);
Reid Spencerff359002006-10-09 17:36:59 +00003741 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003742 InsertValue(yyvsp[0].TermInstVal);
Reid Spencerff359002006-10-09 17:36:59 +00003743
Chris Lattnerff20ba32006-10-15 23:27:25 +00003744 yyvsp[-2].BasicBlockVal->getInstList().push_back(yyvsp[0].TermInstVal);
3745 InsertValue(yyvsp[-2].BasicBlockVal);
3746 yyval.BasicBlockVal = yyvsp[-2].BasicBlockVal;
Reid Spencerff359002006-10-09 17:36:59 +00003747 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003748 ;
3749 break;}
3750case 200:
3751#line 2196 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3752{
3753 yyvsp[-1].BasicBlockVal->getInstList().push_back(yyvsp[0].InstVal);
3754 yyval.BasicBlockVal = yyvsp[-1].BasicBlockVal;
Reid Spencerff359002006-10-09 17:36:59 +00003755 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003756 ;
3757 break;}
3758case 201:
3759#line 2201 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3760{
3761 yyval.BasicBlockVal = CurBB = getBBVal(ValID::create((int)CurFun.NextBBNum++), true);
Reid Spencer309080a2006-09-28 19:28:24 +00003762 CHECK_FOR_ERROR
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003763
3764 // Make sure to move the basic block to the correct location in the
3765 // function, instead of leaving it inserted wherever it was first
3766 // referenced.
3767 Function::BasicBlockListType &BBL =
3768 CurFun.CurrentFunction->getBasicBlockList();
Chris Lattnerff20ba32006-10-15 23:27:25 +00003769 BBL.splice(BBL.end(), BBL, yyval.BasicBlockVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003770 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003771 ;
3772 break;}
3773case 202:
3774#line 2213 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3775{
3776 yyval.BasicBlockVal = CurBB = getBBVal(ValID::create(yyvsp[0].StrVal), true);
Reid Spencer309080a2006-09-28 19:28:24 +00003777 CHECK_FOR_ERROR
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003778
3779 // Make sure to move the basic block to the correct location in the
3780 // function, instead of leaving it inserted wherever it was first
3781 // referenced.
3782 Function::BasicBlockListType &BBL =
3783 CurFun.CurrentFunction->getBasicBlockList();
Chris Lattnerff20ba32006-10-15 23:27:25 +00003784 BBL.splice(BBL.end(), BBL, yyval.BasicBlockVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003785 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003786 ;
3787 break;}
3788case 203:
3789#line 2226 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3790{ // Return with a result...
3791 yyval.TermInstVal = new ReturnInst(yyvsp[0].ValueVal);
3792 CHECK_FOR_ERROR
3793 ;
3794 break;}
3795case 204:
3796#line 2230 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3797{ // Return with no result...
3798 yyval.TermInstVal = new ReturnInst();
3799 CHECK_FOR_ERROR
3800 ;
3801 break;}
3802case 205:
3803#line 2234 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3804{ // Unconditional Branch...
3805 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
3806 CHECK_FOR_ERROR
3807 yyval.TermInstVal = new BranchInst(tmpBB);
3808 ;
3809 break;}
3810case 206:
3811#line 2239 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3812{
3813 BasicBlock* tmpBBA = getBBVal(yyvsp[-3].ValIDVal);
3814 CHECK_FOR_ERROR
3815 BasicBlock* tmpBBB = getBBVal(yyvsp[0].ValIDVal);
3816 CHECK_FOR_ERROR
3817 Value* tmpVal = getVal(Type::BoolTy, yyvsp[-6].ValIDVal);
3818 CHECK_FOR_ERROR
3819 yyval.TermInstVal = new BranchInst(tmpBBA, tmpBBB, tmpVal);
3820 ;
3821 break;}
3822case 207:
3823#line 2248 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3824{
3825 Value* tmpVal = getVal(yyvsp[-7].PrimType, yyvsp[-6].ValIDVal);
3826 CHECK_FOR_ERROR
3827 BasicBlock* tmpBB = getBBVal(yyvsp[-3].ValIDVal);
3828 CHECK_FOR_ERROR
3829 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, yyvsp[-1].JumpTable->size());
3830 yyval.TermInstVal = S;
Reid Spencer713eedc2006-08-18 08:43:06 +00003831
Chris Lattnerff20ba32006-10-15 23:27:25 +00003832 std::vector<std::pair<Constant*,BasicBlock*> >::iterator I = yyvsp[-1].JumpTable->begin(),
3833 E = yyvsp[-1].JumpTable->end();
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003834 for (; I != E; ++I) {
3835 if (ConstantInt *CI = dyn_cast<ConstantInt>(I->first))
3836 S->addCase(CI, I->second);
3837 else
Reid Spencer713eedc2006-08-18 08:43:06 +00003838 GEN_ERROR("Switch case is constant, but not a simple integer!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003839 }
Chris Lattnerff20ba32006-10-15 23:27:25 +00003840 delete yyvsp[-1].JumpTable;
Reid Spencer713eedc2006-08-18 08:43:06 +00003841 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003842 ;
3843 break;}
3844case 208:
3845#line 2267 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3846{
3847 Value* tmpVal = getVal(yyvsp[-6].PrimType, yyvsp[-5].ValIDVal);
Reid Spencer309080a2006-09-28 19:28:24 +00003848 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003849 BasicBlock* tmpBB = getBBVal(yyvsp[-2].ValIDVal);
Reid Spencer309080a2006-09-28 19:28:24 +00003850 CHECK_FOR_ERROR
3851 SwitchInst *S = new SwitchInst(tmpVal, tmpBB, 0);
Chris Lattnerff20ba32006-10-15 23:27:25 +00003852 yyval.TermInstVal = S;
Reid Spencer713eedc2006-08-18 08:43:06 +00003853 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003854 ;
3855 break;}
3856case 209:
3857#line 2277 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3858{
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003859 const PointerType *PFTy;
3860 const FunctionType *Ty;
3861
Chris Lattnerff20ba32006-10-15 23:27:25 +00003862 if (!(PFTy = dyn_cast<PointerType>(yyvsp[-10].TypeVal->get())) ||
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003863 !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
3864 // Pull out the types of all of the arguments...
3865 std::vector<const Type*> ParamTypes;
Chris Lattnerff20ba32006-10-15 23:27:25 +00003866 if (yyvsp[-7].ValueList) {
3867 for (std::vector<Value*>::iterator I = yyvsp[-7].ValueList->begin(), E = yyvsp[-7].ValueList->end();
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003868 I != E; ++I)
3869 ParamTypes.push_back((*I)->getType());
3870 }
3871
3872 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
3873 if (isVarArg) ParamTypes.pop_back();
3874
Chris Lattnerff20ba32006-10-15 23:27:25 +00003875 Ty = FunctionType::get(yyvsp[-10].TypeVal->get(), ParamTypes, isVarArg);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003876 PFTy = PointerType::get(Ty);
3877 }
3878
Chris Lattnerff20ba32006-10-15 23:27:25 +00003879 Value *V = getVal(PFTy, yyvsp[-9].ValIDVal); // Get the function we're calling...
Reid Spencer309080a2006-09-28 19:28:24 +00003880 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003881 BasicBlock *Normal = getBBVal(yyvsp[-3].ValIDVal);
Reid Spencer309080a2006-09-28 19:28:24 +00003882 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003883 BasicBlock *Except = getBBVal(yyvsp[0].ValIDVal);
Reid Spencer309080a2006-09-28 19:28:24 +00003884 CHECK_FOR_ERROR
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003885
3886 // Create the call node...
Chris Lattnerff20ba32006-10-15 23:27:25 +00003887 if (!yyvsp[-7].ValueList) { // Has no arguments?
3888 yyval.TermInstVal = new InvokeInst(V, Normal, Except, std::vector<Value*>());
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003889 } else { // Has arguments?
3890 // Loop through FunctionType's arguments and ensure they are specified
3891 // correctly!
3892 //
3893 FunctionType::param_iterator I = Ty->param_begin();
3894 FunctionType::param_iterator E = Ty->param_end();
Chris Lattnerff20ba32006-10-15 23:27:25 +00003895 std::vector<Value*>::iterator ArgI = yyvsp[-7].ValueList->begin(), ArgE = yyvsp[-7].ValueList->end();
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003896
3897 for (; ArgI != ArgE && I != E; ++ArgI, ++I)
3898 if ((*ArgI)->getType() != *I)
Reid Spencer713eedc2006-08-18 08:43:06 +00003899 GEN_ERROR("Parameter " +(*ArgI)->getName()+ " is not of type '" +
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003900 (*I)->getDescription() + "'!");
3901
3902 if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
Reid Spencer713eedc2006-08-18 08:43:06 +00003903 GEN_ERROR("Invalid number of parameters detected!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003904
Chris Lattnerff20ba32006-10-15 23:27:25 +00003905 yyval.TermInstVal = new InvokeInst(V, Normal, Except, *yyvsp[-7].ValueList);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003906 }
Chris Lattnerff20ba32006-10-15 23:27:25 +00003907 cast<InvokeInst>(yyval.TermInstVal)->setCallingConv(yyvsp[-11].UIntVal);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003908
Chris Lattnerff20ba32006-10-15 23:27:25 +00003909 delete yyvsp[-10].TypeVal;
3910 delete yyvsp[-7].ValueList;
Reid Spencer713eedc2006-08-18 08:43:06 +00003911 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003912 ;
3913 break;}
3914case 210:
3915#line 2332 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3916{
3917 yyval.TermInstVal = new UnwindInst();
Reid Spencer713eedc2006-08-18 08:43:06 +00003918 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003919 ;
3920 break;}
3921case 211:
3922#line 2336 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3923{
3924 yyval.TermInstVal = new UnreachableInst();
Reid Spencer713eedc2006-08-18 08:43:06 +00003925 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003926 ;
3927 break;}
3928case 212:
3929#line 2343 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3930{
3931 yyval.JumpTable = yyvsp[-5].JumpTable;
3932 Constant *V = cast<Constant>(getValNonImprovising(yyvsp[-4].PrimType, yyvsp[-3].ValIDVal));
Reid Spencer309080a2006-09-28 19:28:24 +00003933 CHECK_FOR_ERROR
Reid Spencer713eedc2006-08-18 08:43:06 +00003934 if (V == 0)
3935 GEN_ERROR("May only switch on a constant pool value!");
3936
Chris Lattnerff20ba32006-10-15 23:27:25 +00003937 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003938 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003939 yyval.JumpTable->push_back(std::make_pair(V, tmpBB));
3940 ;
3941 break;}
3942case 213:
3943#line 2354 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3944{
3945 yyval.JumpTable = new std::vector<std::pair<Constant*, BasicBlock*> >();
3946 Constant *V = cast<Constant>(getValNonImprovising(yyvsp[-4].PrimType, yyvsp[-3].ValIDVal));
Reid Spencer309080a2006-09-28 19:28:24 +00003947 CHECK_FOR_ERROR
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003948
3949 if (V == 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00003950 GEN_ERROR("May only switch on a constant pool value!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003951
Chris Lattnerff20ba32006-10-15 23:27:25 +00003952 BasicBlock* tmpBB = getBBVal(yyvsp[0].ValIDVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003953 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003954 yyval.JumpTable->push_back(std::make_pair(V, tmpBB));
3955 ;
3956 break;}
3957case 214:
3958#line 2367 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3959{
Reid Spencerdfb3fb42005-08-27 18:50:39 +00003960 // Is this definition named?? if so, assign the name...
Chris Lattnerff20ba32006-10-15 23:27:25 +00003961 setValueName(yyvsp[0].InstVal, yyvsp[-1].StrVal);
Reid Spencer309080a2006-09-28 19:28:24 +00003962 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003963 InsertValue(yyvsp[0].InstVal);
3964 yyval.InstVal = yyvsp[0].InstVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00003965 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003966;
3967 break;}
3968case 215:
3969#line 2376 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3970{ // Used for PHI nodes
3971 yyval.PHIList = new std::list<std::pair<Value*, BasicBlock*> >();
3972 Value* tmpVal = getVal(*yyvsp[-5].TypeVal, yyvsp[-3].ValIDVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003973 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003974 BasicBlock* tmpBB = getBBVal(yyvsp[-1].ValIDVal);
Reid Spencer309080a2006-09-28 19:28:24 +00003975 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003976 yyval.PHIList->push_back(std::make_pair(tmpVal, tmpBB));
3977 delete yyvsp[-5].TypeVal;
3978 ;
3979 break;}
3980case 216:
3981#line 2385 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3982{
3983 yyval.PHIList = yyvsp[-6].PHIList;
3984 Value* tmpVal = getVal(yyvsp[-6].PHIList->front().first->getType(), yyvsp[-3].ValIDVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00003985 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003986 BasicBlock* tmpBB = getBBVal(yyvsp[-1].ValIDVal);
Reid Spencer309080a2006-09-28 19:28:24 +00003987 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00003988 yyvsp[-6].PHIList->push_back(std::make_pair(tmpVal, tmpBB));
3989 ;
3990 break;}
3991case 217:
3992#line 2395 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
3993{ // Used for call statements, and memory insts...
3994 yyval.ValueList = new std::vector<Value*>();
3995 yyval.ValueList->push_back(yyvsp[0].ValueVal);
3996 ;
3997 break;}
3998case 218:
3999#line 2399 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4000{
4001 yyval.ValueList = yyvsp[-2].ValueList;
4002 yyvsp[-2].ValueList->push_back(yyvsp[0].ValueVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00004003 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004004 ;
4005 break;}
4006case 220:
4007#line 2406 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4008{ yyval.ValueList = 0; ;
4009 break;}
4010case 221:
4011#line 2408 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4012{
4013 yyval.BoolVal = true;
Reid Spencer713eedc2006-08-18 08:43:06 +00004014 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004015 ;
4016 break;}
4017case 222:
4018#line 2412 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4019{
4020 yyval.BoolVal = false;
Reid Spencer713eedc2006-08-18 08:43:06 +00004021 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004022 ;
4023 break;}
4024case 223:
4025#line 2417 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4026{
4027 if (!(*yyvsp[-3].TypeVal)->isInteger() && !(*yyvsp[-3].TypeVal)->isFloatingPoint() &&
4028 !isa<PackedType>((*yyvsp[-3].TypeVal).get()))
Reid Spencer713eedc2006-08-18 08:43:06 +00004029 GEN_ERROR(
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004030 "Arithmetic operator requires integer, FP, or packed operands!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004031 if (isa<PackedType>((*yyvsp[-3].TypeVal).get()) && yyvsp[-4].BinaryOpVal == Instruction::Rem)
Reid Spencer713eedc2006-08-18 08:43:06 +00004032 GEN_ERROR("Rem not supported on packed types!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004033 Value* val1 = getVal(*yyvsp[-3].TypeVal, yyvsp[-2].ValIDVal);
Reid Spencer309080a2006-09-28 19:28:24 +00004034 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004035 Value* val2 = getVal(*yyvsp[-3].TypeVal, yyvsp[0].ValIDVal);
Reid Spencer309080a2006-09-28 19:28:24 +00004036 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004037 yyval.InstVal = BinaryOperator::create(yyvsp[-4].BinaryOpVal, val1, val2);
4038 if (yyval.InstVal == 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00004039 GEN_ERROR("binary operator returned null!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004040 delete yyvsp[-3].TypeVal;
4041 ;
4042 break;}
4043case 224:
4044#line 2433 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4045{
4046 if (!(*yyvsp[-3].TypeVal)->isIntegral()) {
4047 if (!isa<PackedType>(yyvsp[-3].TypeVal->get()) ||
4048 !cast<PackedType>(yyvsp[-3].TypeVal->get())->getElementType()->isIntegral())
Reid Spencer713eedc2006-08-18 08:43:06 +00004049 GEN_ERROR("Logical operator requires integral operands!");
Chris Lattner15f5a182005-12-21 18:31:50 +00004050 }
Chris Lattnerff20ba32006-10-15 23:27:25 +00004051 Value* tmpVal1 = getVal(*yyvsp[-3].TypeVal, yyvsp[-2].ValIDVal);
Reid Spencer309080a2006-09-28 19:28:24 +00004052 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004053 Value* tmpVal2 = getVal(*yyvsp[-3].TypeVal, yyvsp[0].ValIDVal);
Reid Spencer309080a2006-09-28 19:28:24 +00004054 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004055 yyval.InstVal = BinaryOperator::create(yyvsp[-4].BinaryOpVal, tmpVal1, tmpVal2);
4056 if (yyval.InstVal == 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00004057 GEN_ERROR("binary operator returned null!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004058 delete yyvsp[-3].TypeVal;
4059 ;
4060 break;}
4061case 225:
4062#line 2448 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4063{
4064 if(isa<PackedType>((*yyvsp[-3].TypeVal).get())) {
Reid Spencer713eedc2006-08-18 08:43:06 +00004065 GEN_ERROR(
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004066 "PackedTypes currently not supported in setcc instructions!");
4067 }
Chris Lattnerff20ba32006-10-15 23:27:25 +00004068 Value* tmpVal1 = getVal(*yyvsp[-3].TypeVal, yyvsp[-2].ValIDVal);
Reid Spencer309080a2006-09-28 19:28:24 +00004069 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004070 Value* tmpVal2 = getVal(*yyvsp[-3].TypeVal, yyvsp[0].ValIDVal);
Reid Spencer309080a2006-09-28 19:28:24 +00004071 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004072 yyval.InstVal = new SetCondInst(yyvsp[-4].BinaryOpVal, tmpVal1, tmpVal2);
4073 if (yyval.InstVal == 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00004074 GEN_ERROR("binary operator returned null!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004075 delete yyvsp[-3].TypeVal;
4076 ;
4077 break;}
4078case 226:
4079#line 2462 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4080{
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004081 std::cerr << "WARNING: Use of eliminated 'not' instruction:"
4082 << " Replacing with 'xor'.\n";
4083
Chris Lattnerff20ba32006-10-15 23:27:25 +00004084 Value *Ones = ConstantIntegral::getAllOnesValue(yyvsp[0].ValueVal->getType());
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004085 if (Ones == 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00004086 GEN_ERROR("Expected integral type for not instruction!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004087
Chris Lattnerff20ba32006-10-15 23:27:25 +00004088 yyval.InstVal = BinaryOperator::create(Instruction::Xor, yyvsp[0].ValueVal, Ones);
4089 if (yyval.InstVal == 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00004090 GEN_ERROR("Could not create a xor instruction!");
4091 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004092 ;
4093 break;}
4094case 227:
4095#line 2475 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4096{
4097 if (yyvsp[0].ValueVal->getType() != Type::UByteTy)
Reid Spencer713eedc2006-08-18 08:43:06 +00004098 GEN_ERROR("Shift amount must be ubyte!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004099 if (!yyvsp[-2].ValueVal->getType()->isInteger())
Reid Spencer713eedc2006-08-18 08:43:06 +00004100 GEN_ERROR("Shift constant expression requires integer operand!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004101 yyval.InstVal = new ShiftInst(yyvsp[-3].OtherOpVal, yyvsp[-2].ValueVal, yyvsp[0].ValueVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00004102 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004103 ;
4104 break;}
4105case 228:
4106#line 2483 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4107{
4108 if (!yyvsp[0].TypeVal->get()->isFirstClassType())
Reid Spencer713eedc2006-08-18 08:43:06 +00004109 GEN_ERROR("cast instruction to a non-primitive type: '" +
Chris Lattnerff20ba32006-10-15 23:27:25 +00004110 yyvsp[0].TypeVal->get()->getDescription() + "'!");
4111 yyval.InstVal = new CastInst(yyvsp[-2].ValueVal, *yyvsp[0].TypeVal);
4112 delete yyvsp[0].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00004113 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004114 ;
4115 break;}
4116case 229:
4117#line 2491 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4118{
4119 if (yyvsp[-4].ValueVal->getType() != Type::BoolTy)
Reid Spencer713eedc2006-08-18 08:43:06 +00004120 GEN_ERROR("select condition must be boolean!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004121 if (yyvsp[-2].ValueVal->getType() != yyvsp[0].ValueVal->getType())
Reid Spencer713eedc2006-08-18 08:43:06 +00004122 GEN_ERROR("select value types should match!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004123 yyval.InstVal = new SelectInst(yyvsp[-4].ValueVal, yyvsp[-2].ValueVal, yyvsp[0].ValueVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00004124 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004125 ;
4126 break;}
4127case 230:
4128#line 2499 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4129{
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004130 NewVarArgs = true;
Chris Lattnerff20ba32006-10-15 23:27:25 +00004131 yyval.InstVal = new VAArgInst(yyvsp[-2].ValueVal, *yyvsp[0].TypeVal);
4132 delete yyvsp[0].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00004133 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004134 ;
4135 break;}
4136case 231:
4137#line 2505 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4138{
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004139 ObsoleteVarArgs = true;
Chris Lattnerff20ba32006-10-15 23:27:25 +00004140 const Type* ArgTy = yyvsp[-2].ValueVal->getType();
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004141 Function* NF = CurModule.CurrentModule->
Jeff Cohen11e26b52005-10-23 04:37:20 +00004142 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004143
4144 //b = vaarg a, t ->
4145 //foo = alloca 1 of t
4146 //bar = vacopy a
4147 //store bar -> foo
4148 //b = vaarg foo, t
4149 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vaarg.fix");
4150 CurBB->getInstList().push_back(foo);
Chris Lattnerff20ba32006-10-15 23:27:25 +00004151 CallInst* bar = new CallInst(NF, yyvsp[-2].ValueVal);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004152 CurBB->getInstList().push_back(bar);
4153 CurBB->getInstList().push_back(new StoreInst(bar, foo));
Chris Lattnerff20ba32006-10-15 23:27:25 +00004154 yyval.InstVal = new VAArgInst(foo, *yyvsp[0].TypeVal);
4155 delete yyvsp[0].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00004156 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004157 ;
4158 break;}
4159case 232:
4160#line 2525 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4161{
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004162 ObsoleteVarArgs = true;
Chris Lattnerff20ba32006-10-15 23:27:25 +00004163 const Type* ArgTy = yyvsp[-2].ValueVal->getType();
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004164 Function* NF = CurModule.CurrentModule->
Jeff Cohen11e26b52005-10-23 04:37:20 +00004165 getOrInsertFunction("llvm.va_copy", ArgTy, ArgTy, (Type *)0);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004166
4167 //b = vanext a, t ->
4168 //foo = alloca 1 of t
4169 //bar = vacopy a
4170 //store bar -> foo
4171 //tmp = vaarg foo, t
4172 //b = load foo
4173 AllocaInst* foo = new AllocaInst(ArgTy, 0, "vanext.fix");
4174 CurBB->getInstList().push_back(foo);
Chris Lattnerff20ba32006-10-15 23:27:25 +00004175 CallInst* bar = new CallInst(NF, yyvsp[-2].ValueVal);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004176 CurBB->getInstList().push_back(bar);
4177 CurBB->getInstList().push_back(new StoreInst(bar, foo));
Chris Lattnerff20ba32006-10-15 23:27:25 +00004178 Instruction* tmp = new VAArgInst(foo, *yyvsp[0].TypeVal);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004179 CurBB->getInstList().push_back(tmp);
Chris Lattnerff20ba32006-10-15 23:27:25 +00004180 yyval.InstVal = new LoadInst(foo);
4181 delete yyvsp[0].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00004182 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004183 ;
4184 break;}
4185case 233:
4186#line 2548 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4187{
4188 if (!ExtractElementInst::isValidOperands(yyvsp[-2].ValueVal, yyvsp[0].ValueVal))
Reid Spencer713eedc2006-08-18 08:43:06 +00004189 GEN_ERROR("Invalid extractelement operands!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004190 yyval.InstVal = new ExtractElementInst(yyvsp[-2].ValueVal, yyvsp[0].ValueVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00004191 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004192 ;
4193 break;}
4194case 234:
4195#line 2554 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4196{
4197 if (!InsertElementInst::isValidOperands(yyvsp[-4].ValueVal, yyvsp[-2].ValueVal, yyvsp[0].ValueVal))
Reid Spencer713eedc2006-08-18 08:43:06 +00004198 GEN_ERROR("Invalid insertelement operands!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004199 yyval.InstVal = new InsertElementInst(yyvsp[-4].ValueVal, yyvsp[-2].ValueVal, yyvsp[0].ValueVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00004200 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004201 ;
4202 break;}
4203case 235:
4204#line 2560 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4205{
4206 if (!ShuffleVectorInst::isValidOperands(yyvsp[-4].ValueVal, yyvsp[-2].ValueVal, yyvsp[0].ValueVal))
Reid Spencer713eedc2006-08-18 08:43:06 +00004207 GEN_ERROR("Invalid shufflevector operands!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004208 yyval.InstVal = new ShuffleVectorInst(yyvsp[-4].ValueVal, yyvsp[-2].ValueVal, yyvsp[0].ValueVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00004209 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004210 ;
4211 break;}
4212case 236:
4213#line 2566 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4214{
4215 const Type *Ty = yyvsp[0].PHIList->front().first->getType();
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004216 if (!Ty->isFirstClassType())
Reid Spencer713eedc2006-08-18 08:43:06 +00004217 GEN_ERROR("PHI node operands must be of first class type!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004218 yyval.InstVal = new PHINode(Ty);
4219 ((PHINode*)yyval.InstVal)->reserveOperandSpace(yyvsp[0].PHIList->size());
4220 while (yyvsp[0].PHIList->begin() != yyvsp[0].PHIList->end()) {
4221 if (yyvsp[0].PHIList->front().first->getType() != Ty)
Reid Spencer713eedc2006-08-18 08:43:06 +00004222 GEN_ERROR("All elements of a PHI node must be of the same type!");
Chris Lattnerff20ba32006-10-15 23:27:25 +00004223 cast<PHINode>(yyval.InstVal)->addIncoming(yyvsp[0].PHIList->front().first, yyvsp[0].PHIList->front().second);
4224 yyvsp[0].PHIList->pop_front();
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004225 }
Chris Lattnerff20ba32006-10-15 23:27:25 +00004226 delete yyvsp[0].PHIList; // Free the list...
Reid Spencer713eedc2006-08-18 08:43:06 +00004227 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004228 ;
4229 break;}
4230case 237:
4231#line 2581 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4232{
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004233 const PointerType *PFTy;
4234 const FunctionType *Ty;
4235
Chris Lattnerff20ba32006-10-15 23:27:25 +00004236 if (!(PFTy = dyn_cast<PointerType>(yyvsp[-4].TypeVal->get())) ||
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004237 !(Ty = dyn_cast<FunctionType>(PFTy->getElementType()))) {
4238 // Pull out the types of all of the arguments...
4239 std::vector<const Type*> ParamTypes;
Chris Lattnerff20ba32006-10-15 23:27:25 +00004240 if (yyvsp[-1].ValueList) {
4241 for (std::vector<Value*>::iterator I = yyvsp[-1].ValueList->begin(), E = yyvsp[-1].ValueList->end();
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004242 I != E; ++I)
4243 ParamTypes.push_back((*I)->getType());
4244 }
4245
4246 bool isVarArg = ParamTypes.size() && ParamTypes.back() == Type::VoidTy;
4247 if (isVarArg) ParamTypes.pop_back();
4248
Chris Lattnerff20ba32006-10-15 23:27:25 +00004249 if (!(*yyvsp[-4].TypeVal)->isFirstClassType() && *yyvsp[-4].TypeVal != Type::VoidTy)
Reid Spencer713eedc2006-08-18 08:43:06 +00004250 GEN_ERROR("LLVM functions cannot return aggregate types!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004251
Chris Lattnerff20ba32006-10-15 23:27:25 +00004252 Ty = FunctionType::get(yyvsp[-4].TypeVal->get(), ParamTypes, isVarArg);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004253 PFTy = PointerType::get(Ty);
4254 }
4255
Chris Lattnerff20ba32006-10-15 23:27:25 +00004256 Value *V = getVal(PFTy, yyvsp[-3].ValIDVal); // Get the function we're calling...
Reid Spencer309080a2006-09-28 19:28:24 +00004257 CHECK_FOR_ERROR
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004258
4259 // Create the call node...
Chris Lattnerff20ba32006-10-15 23:27:25 +00004260 if (!yyvsp[-1].ValueList) { // Has no arguments?
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004261 // Make sure no arguments is a good thing!
4262 if (Ty->getNumParams() != 0)
Reid Spencer713eedc2006-08-18 08:43:06 +00004263 GEN_ERROR("No arguments passed to a function that "
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004264 "expects arguments!");
4265
Chris Lattnerff20ba32006-10-15 23:27:25 +00004266 yyval.InstVal = new CallInst(V, std::vector<Value*>());
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004267 } else { // Has arguments?
4268 // Loop through FunctionType's arguments and ensure they are specified
4269 // correctly!
4270 //
4271 FunctionType::param_iterator I = Ty->param_begin();
4272 FunctionType::param_iterator E = Ty->param_end();
Chris Lattnerff20ba32006-10-15 23:27:25 +00004273 std::vector<Value*>::iterator ArgI = yyvsp[-1].ValueList->begin(), ArgE = yyvsp[-1].ValueList->end();
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004274
4275 for (; ArgI != ArgE && I != E; ++ArgI, ++I)
4276 if ((*ArgI)->getType() != *I)
Reid Spencer713eedc2006-08-18 08:43:06 +00004277 GEN_ERROR("Parameter " +(*ArgI)->getName()+ " is not of type '" +
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004278 (*I)->getDescription() + "'!");
4279
4280 if (I != E || (ArgI != ArgE && !Ty->isVarArg()))
Reid Spencer713eedc2006-08-18 08:43:06 +00004281 GEN_ERROR("Invalid number of parameters detected!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004282
Chris Lattnerff20ba32006-10-15 23:27:25 +00004283 yyval.InstVal = new CallInst(V, *yyvsp[-1].ValueList);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004284 }
Chris Lattnerff20ba32006-10-15 23:27:25 +00004285 cast<CallInst>(yyval.InstVal)->setTailCall(yyvsp[-6].BoolVal);
4286 cast<CallInst>(yyval.InstVal)->setCallingConv(yyvsp[-5].UIntVal);
4287 delete yyvsp[-4].TypeVal;
4288 delete yyvsp[-1].ValueList;
Reid Spencer713eedc2006-08-18 08:43:06 +00004289 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004290 ;
4291 break;}
4292case 238:
4293#line 2640 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4294{
4295 yyval.InstVal = yyvsp[0].InstVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00004296 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004297 ;
4298 break;}
4299case 239:
4300#line 2647 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4301{
4302 yyval.ValueList = yyvsp[0].ValueList;
Reid Spencer713eedc2006-08-18 08:43:06 +00004303 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004304 ;
4305 break;}
4306case 240:
4307#line 2650 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4308{
4309 yyval.ValueList = new std::vector<Value*>();
Reid Spencer713eedc2006-08-18 08:43:06 +00004310 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004311 ;
4312 break;}
4313case 241:
4314#line 2655 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4315{
4316 yyval.BoolVal = true;
Reid Spencer713eedc2006-08-18 08:43:06 +00004317 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004318 ;
4319 break;}
4320case 242:
4321#line 2659 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4322{
4323 yyval.BoolVal = false;
Reid Spencer713eedc2006-08-18 08:43:06 +00004324 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004325 ;
4326 break;}
4327case 243:
4328#line 2666 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4329{
4330 yyval.InstVal = new MallocInst(*yyvsp[-1].TypeVal, 0, yyvsp[0].UIntVal);
4331 delete yyvsp[-1].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00004332 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004333 ;
4334 break;}
4335case 244:
4336#line 2671 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4337{
4338 Value* tmpVal = getVal(yyvsp[-2].PrimType, yyvsp[-1].ValIDVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00004339 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004340 yyval.InstVal = new MallocInst(*yyvsp[-4].TypeVal, tmpVal, yyvsp[0].UIntVal);
4341 delete yyvsp[-4].TypeVal;
4342 ;
4343 break;}
4344case 245:
4345#line 2677 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4346{
4347 yyval.InstVal = new AllocaInst(*yyvsp[-1].TypeVal, 0, yyvsp[0].UIntVal);
4348 delete yyvsp[-1].TypeVal;
Reid Spencer713eedc2006-08-18 08:43:06 +00004349 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004350 ;
4351 break;}
4352case 246:
4353#line 2682 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4354{
4355 Value* tmpVal = getVal(yyvsp[-2].PrimType, yyvsp[-1].ValIDVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00004356 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004357 yyval.InstVal = new AllocaInst(*yyvsp[-4].TypeVal, tmpVal, yyvsp[0].UIntVal);
4358 delete yyvsp[-4].TypeVal;
4359 ;
4360 break;}
4361case 247:
4362#line 2688 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4363{
4364 if (!isa<PointerType>(yyvsp[0].ValueVal->getType()))
Reid Spencer713eedc2006-08-18 08:43:06 +00004365 GEN_ERROR("Trying to free nonpointer type " +
Chris Lattnerff20ba32006-10-15 23:27:25 +00004366 yyvsp[0].ValueVal->getType()->getDescription() + "!");
4367 yyval.InstVal = new FreeInst(yyvsp[0].ValueVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00004368 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004369 ;
4370 break;}
4371case 248:
4372#line 2696 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4373{
4374 if (!isa<PointerType>(yyvsp[-1].TypeVal->get()))
Reid Spencer713eedc2006-08-18 08:43:06 +00004375 GEN_ERROR("Can't load from nonpointer type: " +
Chris Lattnerff20ba32006-10-15 23:27:25 +00004376 (*yyvsp[-1].TypeVal)->getDescription());
4377 if (!cast<PointerType>(yyvsp[-1].TypeVal->get())->getElementType()->isFirstClassType())
Reid Spencer713eedc2006-08-18 08:43:06 +00004378 GEN_ERROR("Can't load from pointer of non-first-class type: " +
Chris Lattnerff20ba32006-10-15 23:27:25 +00004379 (*yyvsp[-1].TypeVal)->getDescription());
4380 Value* tmpVal = getVal(*yyvsp[-1].TypeVal, yyvsp[0].ValIDVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00004381 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004382 yyval.InstVal = new LoadInst(tmpVal, "", yyvsp[-3].BoolVal);
4383 delete yyvsp[-1].TypeVal;
4384 ;
4385 break;}
4386case 249:
4387#line 2708 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4388{
4389 const PointerType *PT = dyn_cast<PointerType>(yyvsp[-1].TypeVal->get());
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004390 if (!PT)
Reid Spencer713eedc2006-08-18 08:43:06 +00004391 GEN_ERROR("Can't store to a nonpointer type: " +
Chris Lattnerff20ba32006-10-15 23:27:25 +00004392 (*yyvsp[-1].TypeVal)->getDescription());
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004393 const Type *ElTy = PT->getElementType();
Chris Lattnerff20ba32006-10-15 23:27:25 +00004394 if (ElTy != yyvsp[-3].ValueVal->getType())
4395 GEN_ERROR("Can't store '" + yyvsp[-3].ValueVal->getType()->getDescription() +
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004396 "' into space of type '" + ElTy->getDescription() + "'!");
4397
Chris Lattnerff20ba32006-10-15 23:27:25 +00004398 Value* tmpVal = getVal(*yyvsp[-1].TypeVal, yyvsp[0].ValIDVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00004399 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004400 yyval.InstVal = new StoreInst(yyvsp[-3].ValueVal, tmpVal, yyvsp[-5].BoolVal);
4401 delete yyvsp[-1].TypeVal;
4402 ;
4403 break;}
4404case 250:
4405#line 2723 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
4406{
4407 if (!isa<PointerType>(yyvsp[-2].TypeVal->get()))
Reid Spencer713eedc2006-08-18 08:43:06 +00004408 GEN_ERROR("getelementptr insn requires pointer operand!");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004409
4410 // LLVM 1.2 and earlier used ubyte struct indices. Convert any ubyte struct
4411 // indices to uint struct indices for compatibility.
4412 generic_gep_type_iterator<std::vector<Value*>::iterator>
Chris Lattnerff20ba32006-10-15 23:27:25 +00004413 GTI = gep_type_begin(yyvsp[-2].TypeVal->get(), yyvsp[0].ValueList->begin(), yyvsp[0].ValueList->end()),
4414 GTE = gep_type_end(yyvsp[-2].TypeVal->get(), yyvsp[0].ValueList->begin(), yyvsp[0].ValueList->end());
4415 for (unsigned i = 0, e = yyvsp[0].ValueList->size(); i != e && GTI != GTE; ++i, ++GTI)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004416 if (isa<StructType>(*GTI)) // Only change struct indices
Chris Lattnerff20ba32006-10-15 23:27:25 +00004417 if (ConstantUInt *CUI = dyn_cast<ConstantUInt>((*yyvsp[0].ValueList)[i]))
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004418 if (CUI->getType() == Type::UByteTy)
Chris Lattnerff20ba32006-10-15 23:27:25 +00004419 (*yyvsp[0].ValueList)[i] = ConstantExpr::getCast(CUI, Type::UIntTy);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004420
Chris Lattnerff20ba32006-10-15 23:27:25 +00004421 if (!GetElementPtrInst::getIndexedType(*yyvsp[-2].TypeVal, *yyvsp[0].ValueList, true))
Reid Spencer713eedc2006-08-18 08:43:06 +00004422 GEN_ERROR("Invalid getelementptr indices for type '" +
Chris Lattnerff20ba32006-10-15 23:27:25 +00004423 (*yyvsp[-2].TypeVal)->getDescription()+ "'!");
4424 Value* tmpVal = getVal(*yyvsp[-2].TypeVal, yyvsp[-1].ValIDVal);
Reid Spencer713eedc2006-08-18 08:43:06 +00004425 CHECK_FOR_ERROR
Chris Lattnerff20ba32006-10-15 23:27:25 +00004426 yyval.InstVal = new GetElementPtrInst(tmpVal, *yyvsp[0].ValueList);
4427 delete yyvsp[-2].TypeVal;
4428 delete yyvsp[0].ValueList;
4429 ;
4430 break;}
4431}
4432 /* the action file gets copied in in place of this dollarsign */
4433#line 543 "/usr/share/bison.simple"
Reid Spencer309080a2006-09-28 19:28:24 +00004434
4435 yyvsp -= yylen;
4436 yyssp -= yylen;
Chris Lattnerff20ba32006-10-15 23:27:25 +00004437#ifdef YYLSP_NEEDED
4438 yylsp -= yylen;
4439#endif
Reid Spencer309080a2006-09-28 19:28:24 +00004440
Chris Lattnerff20ba32006-10-15 23:27:25 +00004441#if YYDEBUG != 0
4442 if (yydebug)
4443 {
4444 short *ssp1 = yyss - 1;
4445 fprintf (stderr, "state stack now");
4446 while (ssp1 != yyssp)
4447 fprintf (stderr, " %d", *++ssp1);
4448 fprintf (stderr, "\n");
4449 }
4450#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004451
4452 *++yyvsp = yyval;
4453
Chris Lattnerff20ba32006-10-15 23:27:25 +00004454#ifdef YYLSP_NEEDED
4455 yylsp++;
4456 if (yylen == 0)
4457 {
4458 yylsp->first_line = yylloc.first_line;
4459 yylsp->first_column = yylloc.first_column;
4460 yylsp->last_line = (yylsp-1)->last_line;
4461 yylsp->last_column = (yylsp-1)->last_column;
4462 yylsp->text = 0;
4463 }
4464 else
4465 {
4466 yylsp->last_line = (yylsp+yylen-1)->last_line;
4467 yylsp->last_column = (yylsp+yylen-1)->last_column;
4468 }
4469#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004470
Chris Lattnerff20ba32006-10-15 23:27:25 +00004471 /* Now "shift" the result of the reduction.
4472 Determine what state that goes to,
4473 based on the state we popped back to
4474 and the rule number reduced by. */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004475
4476 yyn = yyr1[yyn];
4477
Chris Lattnerff20ba32006-10-15 23:27:25 +00004478 yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
4479 if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004480 yystate = yytable[yystate];
4481 else
Chris Lattnerff20ba32006-10-15 23:27:25 +00004482 yystate = yydefgoto[yyn - YYNTBASE];
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004483
4484 goto yynewstate;
4485
Chris Lattnerff20ba32006-10-15 23:27:25 +00004486yyerrlab: /* here on detecting error */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004487
Chris Lattnerff20ba32006-10-15 23:27:25 +00004488 if (! yyerrstatus)
4489 /* If not already recovering from an error, report this error. */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004490 {
4491 ++yynerrs;
Chris Lattnerff20ba32006-10-15 23:27:25 +00004492
4493#ifdef YYERROR_VERBOSE
Reid Spencer309080a2006-09-28 19:28:24 +00004494 yyn = yypact[yystate];
Chris Lattner680aab62006-08-18 17:34:45 +00004495
Chris Lattnerff20ba32006-10-15 23:27:25 +00004496 if (yyn > YYFLAG && yyn < YYLAST)
Reid Spencer309080a2006-09-28 19:28:24 +00004497 {
Chris Lattnerff20ba32006-10-15 23:27:25 +00004498 int size = 0;
4499 char *msg;
4500 int x, count;
Reid Spencer309080a2006-09-28 19:28:24 +00004501
Chris Lattnerff20ba32006-10-15 23:27:25 +00004502 count = 0;
4503 /* Start X at -yyn if nec to avoid negative indexes in yycheck. */
4504 for (x = (yyn < 0 ? -yyn : 0);
4505 x < (sizeof(yytname) / sizeof(char *)); x++)
4506 if (yycheck[x + yyn] == x)
4507 size += strlen(yytname[x]) + 15, count++;
4508 msg = (char *) malloc(size + 15);
4509 if (msg != 0)
Reid Spencer309080a2006-09-28 19:28:24 +00004510 {
Chris Lattnerff20ba32006-10-15 23:27:25 +00004511 strcpy(msg, "parse error");
4512
4513 if (count < 5)
Reid Spencer309080a2006-09-28 19:28:24 +00004514 {
Chris Lattnerff20ba32006-10-15 23:27:25 +00004515 count = 0;
4516 for (x = (yyn < 0 ? -yyn : 0);
4517 x < (sizeof(yytname) / sizeof(char *)); x++)
4518 if (yycheck[x + yyn] == x)
4519 {
4520 strcat(msg, count == 0 ? ", expecting `" : " or `");
4521 strcat(msg, yytname[x]);
4522 strcat(msg, "'");
4523 count++;
4524 }
Reid Spencer309080a2006-09-28 19:28:24 +00004525 }
Chris Lattnerff20ba32006-10-15 23:27:25 +00004526 yyerror(msg);
4527 free(msg);
Reid Spencer309080a2006-09-28 19:28:24 +00004528 }
4529 else
Chris Lattnerff20ba32006-10-15 23:27:25 +00004530 yyerror ("parse error; also virtual memory exceeded");
Reid Spencer309080a2006-09-28 19:28:24 +00004531 }
4532 else
4533#endif /* YYERROR_VERBOSE */
Chris Lattnerff20ba32006-10-15 23:27:25 +00004534 yyerror("parse error");
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004535 }
4536
Chris Lattnerff20ba32006-10-15 23:27:25 +00004537 goto yyerrlab1;
4538yyerrlab1: /* here on error raised explicitly by an action */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004539
4540 if (yyerrstatus == 3)
4541 {
Chris Lattnerff20ba32006-10-15 23:27:25 +00004542 /* if just tried and failed to reuse lookahead token after an error, discard it. */
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004543
Chris Lattnerff20ba32006-10-15 23:27:25 +00004544 /* return failure if at end of input */
4545 if (yychar == YYEOF)
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004546 YYABORT;
4547
Chris Lattnerff20ba32006-10-15 23:27:25 +00004548#if YYDEBUG != 0
4549 if (yydebug)
4550 fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]);
4551#endif
Chris Lattneredd9b032006-01-23 23:05:42 +00004552
Chris Lattnerff20ba32006-10-15 23:27:25 +00004553 yychar = YYEMPTY;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004554 }
4555
Chris Lattnerff20ba32006-10-15 23:27:25 +00004556 /* Else will try to reuse lookahead token
4557 after shifting the error token. */
4558
4559 yyerrstatus = 3; /* Each real token shifted decrements this */
4560
4561 goto yyerrhandle;
4562
4563yyerrdefault: /* current state does not do anything special for the error token. */
4564
4565#if 0
4566 /* This is wrong; only states that explicitly want error tokens
4567 should shift them. */
4568 yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
4569 if (yyn) goto yydefault;
4570#endif
4571
4572yyerrpop: /* pop the current state because it cannot handle the error token */
4573
4574 if (yyssp == yyss) YYABORT;
4575 yyvsp--;
4576 yystate = *--yyssp;
4577#ifdef YYLSP_NEEDED
4578 yylsp--;
4579#endif
4580
4581#if YYDEBUG != 0
4582 if (yydebug)
4583 {
4584 short *ssp1 = yyss - 1;
4585 fprintf (stderr, "Error: state stack now");
4586 while (ssp1 != yyssp)
4587 fprintf (stderr, " %d", *++ssp1);
4588 fprintf (stderr, "\n");
4589 }
4590#endif
4591
4592yyerrhandle:
4593
4594 yyn = yypact[yystate];
4595 if (yyn == YYFLAG)
4596 goto yyerrdefault;
4597
4598 yyn += YYTERROR;
4599 if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
4600 goto yyerrdefault;
4601
4602 yyn = yytable[yyn];
4603 if (yyn < 0)
4604 {
4605 if (yyn == YYFLAG)
4606 goto yyerrpop;
4607 yyn = -yyn;
4608 goto yyreduce;
4609 }
4610 else if (yyn == 0)
4611 goto yyerrpop;
4612
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004613 if (yyn == YYFINAL)
4614 YYACCEPT;
4615
Chris Lattnerff20ba32006-10-15 23:27:25 +00004616#if YYDEBUG != 0
4617 if (yydebug)
4618 fprintf(stderr, "Shifting error token, ");
4619#endif
4620
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004621 *++yyvsp = yylval;
Chris Lattnerff20ba32006-10-15 23:27:25 +00004622#ifdef YYLSP_NEEDED
4623 *++yylsp = yylloc;
4624#endif
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004625
4626 yystate = yyn;
4627 goto yynewstate;
4628
Chris Lattnerff20ba32006-10-15 23:27:25 +00004629 yyacceptlab:
4630 /* YYACCEPT comes here. */
4631 if (yyfree_stacks)
Reid Spencerff359002006-10-09 17:36:59 +00004632 {
Chris Lattnerff20ba32006-10-15 23:27:25 +00004633 free (yyss);
4634 free (yyvs);
4635#ifdef YYLSP_NEEDED
4636 free (yyls);
Reid Spencerff359002006-10-09 17:36:59 +00004637#endif
Chris Lattnerff20ba32006-10-15 23:27:25 +00004638 }
4639 return 0;
4640
4641 yyabortlab:
4642 /* YYABORT comes here. */
4643 if (yyfree_stacks)
4644 {
4645 free (yyss);
4646 free (yyvs);
4647#ifdef YYLSP_NEEDED
4648 free (yyls);
4649#endif
4650 }
4651 return 1;
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004652}
Chris Lattnerff20ba32006-10-15 23:27:25 +00004653#line 2749 "/Users/sabre/cvs/llvm/lib/AsmParser/llvmAsmParser.y"
Reid Spencer713eedc2006-08-18 08:43:06 +00004654
4655
4656void llvm::GenerateError(const std::string &message, int LineNo) {
4657 if (LineNo == -1) LineNo = llvmAsmlineno;
4658 // TODO: column number in exception
4659 if (TheParseError)
4660 TheParseError->setError(CurFilename, message, LineNo);
4661 TriggerError = 1;
4662}
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004663
4664int yyerror(const char *ErrorMsg) {
4665 std::string where
4666 = std::string((CurFilename == "-") ? std::string("<stdin>") : CurFilename)
4667 + ":" + utostr((unsigned) llvmAsmlineno) + ": ";
4668 std::string errMsg = std::string(ErrorMsg) + "\n" + where + " while reading ";
4669 if (yychar == YYEMPTY || yychar == 0)
4670 errMsg += "end-of-file.";
4671 else
4672 errMsg += "token: '" + std::string(llvmAsmtext, llvmAsmleng) + "'";
Reid Spencer713eedc2006-08-18 08:43:06 +00004673 GenerateError(errMsg);
Reid Spencerdfb3fb42005-08-27 18:50:39 +00004674 return 0;
4675}