aboutsummaryrefslogtreecommitdiff
path: root/tools/llvm-upgrade/UpgradeParser.cpp.cvs
diff options
context:
space:
mode:
Diffstat (limited to 'tools/llvm-upgrade/UpgradeParser.cpp.cvs')
-rw-r--r--tools/llvm-upgrade/UpgradeParser.cpp.cvs7002
1 files changed, 0 insertions, 7002 deletions
diff --git a/tools/llvm-upgrade/UpgradeParser.cpp.cvs b/tools/llvm-upgrade/UpgradeParser.cpp.cvs
deleted file mode 100644
index 6bddc30917..0000000000
--- a/tools/llvm-upgrade/UpgradeParser.cpp.cvs
+++ /dev/null
@@ -1,7002 +0,0 @@
-/* A Bison parser, made by GNU Bison 2.3. */
-
-/* Skeleton implementation for Bison's Yacc-like parsers in C
-
- Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
- Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor,
- Boston, MA 02110-1301, USA. */
-
-/* As a special exception, you may create a larger work that contains
- part or all of the Bison parser skeleton and distribute that work
- under terms of your choice, so long as that work isn't itself a
- parser generator using the skeleton or a modified version thereof
- as a parser skeleton. Alternatively, if you modify or redistribute
- the parser skeleton itself, you may (at your option) remove this
- special exception, which will cause the skeleton and the resulting
- Bison output files to be licensed under the GNU General Public
- License without this special exception.
-
- This special exception was added by the Free Software Foundation in
- version 2.2 of Bison. */
-
-/* C LALR(1) parser skeleton written by Richard Stallman, by
- simplifying the original so-called "semantic" parser. */
-
-/* All symbols defined below should begin with yy or YY, to avoid
- infringing on user name space. This should be done even for local
- variables, as they might otherwise be expanded by user macros.
- There are some unavoidable exceptions within include files to
- define necessary library symbols; they are noted "INFRINGES ON
- USER NAME SPACE" below. */
-
-/* Identify Bison output. */
-#define YYBISON 1
-
-/* Bison version. */
-#define YYBISON_VERSION "2.3"
-
-/* Skeleton name. */
-#define YYSKELETON_NAME "yacc.c"
-
-/* Pure parsers. */
-#define YYPURE 0
-
-/* Using locations. */
-#define YYLSP_NEEDED 0
-
-/* Substitute the variable and function names. */
-#define yyparse Upgradeparse
-#define yylex Upgradelex
-#define yyerror Upgradeerror
-#define yylval Upgradelval
-#define yychar Upgradechar
-#define yydebug Upgradedebug
-#define yynerrs Upgradenerrs
-
-
-/* Tokens. */
-#ifndef YYTOKENTYPE
-# define YYTOKENTYPE
- /* Put the tokens into the symbol table, so that GDB and other debuggers
- know about them. */
- enum yytokentype {
- ESINT64VAL = 258,
- EUINT64VAL = 259,
- SINTVAL = 260,
- UINTVAL = 261,
- FPVAL = 262,
- VOID = 263,
- BOOL = 264,
- SBYTE = 265,
- UBYTE = 266,
- SHORT = 267,
- USHORT = 268,
- INT = 269,
- UINT = 270,
- LONG = 271,
- ULONG = 272,
- FLOAT = 273,
- DOUBLE = 274,
- TYPE = 275,
- LABEL = 276,
- VAR_ID = 277,
- LABELSTR = 278,
- STRINGCONSTANT = 279,
- IMPLEMENTATION = 280,
- ZEROINITIALIZER = 281,
- TRUETOK = 282,
- FALSETOK = 283,
- BEGINTOK = 284,
- ENDTOK = 285,
- DECLARE = 286,
- GLOBAL = 287,
- CONSTANT = 288,
- SECTION = 289,
- VOLATILE = 290,
- TO = 291,
- DOTDOTDOT = 292,
- NULL_TOK = 293,
- UNDEF = 294,
- CONST = 295,
- INTERNAL = 296,
- LINKONCE = 297,
- WEAK = 298,
- APPENDING = 299,
- DLLIMPORT = 300,
- DLLEXPORT = 301,
- EXTERN_WEAK = 302,
- OPAQUE = 303,
- NOT = 304,
- EXTERNAL = 305,
- TARGET = 306,
- TRIPLE = 307,
- ENDIAN = 308,
- POINTERSIZE = 309,
- LITTLE = 310,
- BIG = 311,
- ALIGN = 312,
- DEPLIBS = 313,
- CALL = 314,
- TAIL = 315,
- ASM_TOK = 316,
- MODULE = 317,
- SIDEEFFECT = 318,
- CC_TOK = 319,
- CCC_TOK = 320,
- CSRETCC_TOK = 321,
- FASTCC_TOK = 322,
- COLDCC_TOK = 323,
- X86_STDCALLCC_TOK = 324,
- X86_FASTCALLCC_TOK = 325,
- DATALAYOUT = 326,
- RET = 327,
- BR = 328,
- SWITCH = 329,
- INVOKE = 330,
- UNREACHABLE = 331,
- UNWIND = 332,
- EXCEPT = 333,
- ADD = 334,
- SUB = 335,
- MUL = 336,
- DIV = 337,
- UDIV = 338,
- SDIV = 339,
- FDIV = 340,
- REM = 341,
- UREM = 342,
- SREM = 343,
- FREM = 344,
- AND = 345,
- OR = 346,
- XOR = 347,
- SHL = 348,
- SHR = 349,
- ASHR = 350,
- LSHR = 351,
- SETLE = 352,
- SETGE = 353,
- SETLT = 354,
- SETGT = 355,
- SETEQ = 356,
- SETNE = 357,
- ICMP = 358,
- FCMP = 359,
- MALLOC = 360,
- ALLOCA = 361,
- FREE = 362,
- LOAD = 363,
- STORE = 364,
- GETELEMENTPTR = 365,
- PHI_TOK = 366,
- SELECT = 367,
- VAARG = 368,
- EXTRACTELEMENT = 369,
- INSERTELEMENT = 370,
- SHUFFLEVECTOR = 371,
- VAARG_old = 372,
- VANEXT_old = 373,
- EQ = 374,
- NE = 375,
- SLT = 376,
- SGT = 377,
- SLE = 378,
- SGE = 379,
- ULT = 380,
- UGT = 381,
- ULE = 382,
- UGE = 383,
- OEQ = 384,
- ONE = 385,
- OLT = 386,
- OGT = 387,
- OLE = 388,
- OGE = 389,
- ORD = 390,
- UNO = 391,
- UEQ = 392,
- UNE = 393,
- CAST = 394,
- TRUNC = 395,
- ZEXT = 396,
- SEXT = 397,
- FPTRUNC = 398,
- FPEXT = 399,
- FPTOUI = 400,
- FPTOSI = 401,
- UITOFP = 402,
- SITOFP = 403,
- PTRTOINT = 404,
- INTTOPTR = 405,
- BITCAST = 406
- };
-#endif
-/* Tokens. */
-#define ESINT64VAL 258
-#define EUINT64VAL 259
-#define SINTVAL 260
-#define UINTVAL 261
-#define FPVAL 262
-#define VOID 263
-#define BOOL 264
-#define SBYTE 265
-#define UBYTE 266
-#define SHORT 267
-#define USHORT 268
-#define INT 269
-#define UINT 270
-#define LONG 271
-#define ULONG 272
-#define FLOAT 273
-#define DOUBLE 274
-#define TYPE 275
-#define LABEL 276
-#define VAR_ID 277
-#define LABELSTR 278
-#define STRINGCONSTANT 279
-#define IMPLEMENTATION 280
-#define ZEROINITIALIZER 281
-#define TRUETOK 282
-#define FALSETOK 283
-#define BEGINTOK 284
-#define ENDTOK 285
-#define DECLARE 286
-#define GLOBAL 287
-#define CONSTANT 288
-#define SECTION 289
-#define VOLATILE 290
-#define TO 291
-#define DOTDOTDOT 292
-#define NULL_TOK 293
-#define UNDEF 294
-#define CONST 295
-#define INTERNAL 296
-#define LINKONCE 297
-#define WEAK 298
-#define APPENDING 299
-#define DLLIMPORT 300
-#define DLLEXPORT 301
-#define EXTERN_WEAK 302
-#define OPAQUE 303
-#define NOT 304
-#define EXTERNAL 305
-#define TARGET 306
-#define TRIPLE 307
-#define ENDIAN 308
-#define POINTERSIZE 309
-#define LITTLE 310
-#define BIG 311
-#define ALIGN 312
-#define DEPLIBS 313
-#define CALL 314
-#define TAIL 315
-#define ASM_TOK 316
-#define MODULE 317
-#define SIDEEFFECT 318
-#define CC_TOK 319
-#define CCC_TOK 320
-#define CSRETCC_TOK 321
-#define FASTCC_TOK 322
-#define COLDCC_TOK 323
-#define X86_STDCALLCC_TOK 324
-#define X86_FASTCALLCC_TOK 325
-#define DATALAYOUT 326
-#define RET 327
-#define BR 328
-#define SWITCH 329
-#define INVOKE 330
-#define UNREACHABLE 331
-#define UNWIND 332
-#define EXCEPT 333
-#define ADD 334
-#define SUB 335
-#define MUL 336
-#define DIV 337
-#define UDIV 338
-#define SDIV 339
-#define FDIV 340
-#define REM 341
-#define UREM 342
-#define SREM 343
-#define FREM 344
-#define AND 345
-#define OR 346
-#define XOR 347
-#define SHL 348
-#define SHR 349
-#define ASHR 350
-#define LSHR 351
-#define SETLE 352
-#define SETGE 353
-#define SETLT 354
-#define SETGT 355
-#define SETEQ 356
-#define SETNE 357
-#define ICMP 358
-#define FCMP 359
-#define MALLOC 360
-#define ALLOCA 361
-#define FREE 362
-#define LOAD 363
-#define STORE 364
-#define GETELEMENTPTR 365
-#define PHI_TOK 366
-#define SELECT 367
-#define VAARG 368
-#define EXTRACTELEMENT 369
-#define INSERTELEMENT 370
-#define SHUFFLEVECTOR 371
-#define VAARG_old 372
-#define VANEXT_old 373
-#define EQ 374
-#define NE 375
-#define SLT 376
-#define SGT 377
-#define SLE 378
-#define SGE 379
-#define ULT 380
-#define UGT 381
-#define ULE 382
-#define UGE 383
-#define OEQ 384
-#define ONE 385
-#define OLT 386
-#define OGT 387
-#define OLE 388
-#define OGE 389
-#define ORD 390
-#define UNO 391
-#define UEQ 392
-#define UNE 393
-#define CAST 394
-#define TRUNC 395
-#define ZEXT 396
-#define SEXT 397
-#define FPTRUNC 398
-#define FPEXT 399
-#define FPTOUI 400
-#define FPTOSI 401
-#define UITOFP 402
-#define SITOFP 403
-#define PTRTOINT 404
-#define INTTOPTR 405
-#define BITCAST 406
-
-
-
-
-/* Copy the first part of user declarations. */
-#line 14 "/Users/sabre/llvm/tools/llvm-upgrade/UpgradeParser.y"
-
-#include "UpgradeInternals.h"
-#include "llvm/CallingConv.h"
-#include "llvm/InlineAsm.h"
-#include "llvm/Instructions.h"
-#include "llvm/Module.h"
-#include "llvm/ValueSymbolTable.h"
-#include "llvm/Support/GetElementPtrTypeIterator.h"
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/Support/MathExtras.h"
-#include <algorithm>
-#include <iostream>
-#include <map>
-#include <list>
-#include <utility>
-
-// DEBUG_UPREFS - Define this symbol if you want to enable debugging output
-// relating to upreferences in the input stream.
-//
-//#define DEBUG_UPREFS 1
-#ifdef DEBUG_UPREFS
-#define UR_OUT(X) std::cerr << X
-#else
-#define UR_OUT(X)
-#endif
-
-#define YYERROR_VERBOSE 1
-#define YYINCLUDED_STDLIB_H
-#define YYDEBUG 1
-
-int yylex();
-int yyparse();
-
-int yyerror(const char*);
-static void warning(const std::string& WarningMsg);
-
-namespace llvm {
-
-std::istream* LexInput;
-static std::string CurFilename;
-
-// This bool controls whether attributes are ever added to function declarations
-// definitions and calls.
-static bool AddAttributes = false;
-
-static Module *ParserResult;
-static bool ObsoleteVarArgs;
-static bool NewVarArgs;
-static BasicBlock *CurBB;
-static GlobalVariable *CurGV;
-static unsigned lastCallingConv;
-
-// This contains info used when building the body of a function. It is
-// destroyed when the function is completed.
-//
-typedef std::vector<Value *> ValueList; // Numbered defs
-
-typedef std::pair<std::string,TypeInfo> RenameMapKey;
-typedef std::map<RenameMapKey,std::string> RenameMapType;
-
-static void
-ResolveDefinitions(std::map<const Type *,ValueList> &LateResolvers,
- std::map<const Type *,ValueList> *FutureLateResolvers = 0);
-
-static struct PerModuleInfo {
- Module *CurrentModule;
- std::map<const Type *, ValueList> Values; // Module level numbered definitions
- std::map<const Type *,ValueList> LateResolveValues;
- std::vector<PATypeHolder> Types;
- std::vector<Signedness> TypeSigns;
- std::map<std::string,Signedness> NamedTypeSigns;
- std::map<std::string,Signedness> NamedValueSigns;
- std::map<ValID, PATypeHolder> LateResolveTypes;
- static Module::Endianness Endian;
- static Module::PointerSize PointerSize;
- RenameMapType RenameMap;
-
- /// PlaceHolderInfo - When temporary placeholder objects are created, remember
- /// how they were referenced and on which line of the input they came from so
- /// that we can resolve them later and print error messages as appropriate.
- std::map<Value*, std::pair<ValID, int> > PlaceHolderInfo;
-
- // GlobalRefs - This maintains a mapping between <Type, ValID>'s and forward
- // references to global values. Global values may be referenced before they
- // are defined, and if so, the temporary object that they represent is held
- // here. This is used for forward references of GlobalValues.
- //
- typedef std::map<std::pair<const PointerType *, ValID>, GlobalValue*>
- GlobalRefsType;
- GlobalRefsType GlobalRefs;
-
- void ModuleDone() {
- // If we could not resolve some functions at function compilation time
- // (calls to functions before they are defined), resolve them now... Types
- // are resolved when the constant pool has been completely parsed.
- //
- ResolveDefinitions(LateResolveValues);
-
- // Check to make sure that all global value forward references have been
- // resolved!
- //
- if (!GlobalRefs.empty()) {
- std::string UndefinedReferences = "Unresolved global references exist:\n";
-
- for (GlobalRefsType::iterator I = GlobalRefs.begin(), E =GlobalRefs.end();
- I != E; ++I) {
- UndefinedReferences += " " + I->first.first->getDescription() + " " +
- I->first.second.getName() + "\n";
- }
- error(UndefinedReferences);
- return;
- }
-
- if (CurrentModule->getDataLayout().empty()) {
- std::string dataLayout;
- if (Endian != Module::AnyEndianness)
- dataLayout.append(Endian == Module::BigEndian ? "E" : "e");
- if (PointerSize != Module::AnyPointerSize) {
- if (!dataLayout.empty())
- dataLayout += "-";
- dataLayout.append(PointerSize == Module::Pointer64 ?
- "p:64:64" : "p:32:32");
- }
- CurrentModule->setDataLayout(dataLayout);
- }
-
- Values.clear(); // Clear out function local definitions
- Types.clear();
- TypeSigns.clear();
- NamedTypeSigns.clear();
- NamedValueSigns.clear();
- CurrentModule = 0;
- }
-
- // GetForwardRefForGlobal - Check to see if there is a forward reference
- // for this global. If so, remove it from the GlobalRefs map and return it.
- // If not, just return null.
- GlobalValue *GetForwardRefForGlobal(const PointerType *PTy, ValID ID) {
- // Check to see if there is a forward reference to this global variable...
- // if there is, eliminate it and patch the reference to use the new def'n.
- GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(PTy, ID));
- GlobalValue *Ret = 0;
- if (I != GlobalRefs.end()) {
- Ret = I->second;
- GlobalRefs.erase(I);
- }
- return Ret;
- }
- void setEndianness(Module::Endianness E) { Endian = E; }
- void setPointerSize(Module::PointerSize sz) { PointerSize = sz; }
-} CurModule;
-
-Module::Endianness PerModuleInfo::Endian = Module::AnyEndianness;
-Module::PointerSize PerModuleInfo::PointerSize = Module::AnyPointerSize;
-
-static struct PerFunctionInfo {
- Function *CurrentFunction; // Pointer to current function being created
-
- std::map<const Type*, ValueList> Values; // Keep track of #'d definitions
- std::map<const Type*, ValueList> LateResolveValues;
- bool isDeclare; // Is this function a forward declararation?
- GlobalValue::LinkageTypes Linkage;// Linkage for forward declaration.
-
- /// BBForwardRefs - When we see forward references to basic blocks, keep
- /// track of them here.
- std::map<BasicBlock*, std::pair<ValID, int> > BBForwardRefs;
- std::vector<BasicBlock*> NumberedBlocks;
- RenameMapType RenameMap;
- unsigned NextBBNum;
-
- inline PerFunctionInfo() {
- CurrentFunction = 0;
- isDeclare = false;
- Linkage = GlobalValue::ExternalLinkage;
- }
-
- inline void FunctionStart(Function *M) {
- CurrentFunction = M;
- NextBBNum = 0;
- }
-
- void FunctionDone() {
- NumberedBlocks.clear();
-
- // Any forward referenced blocks left?
- if (!BBForwardRefs.empty()) {
- error("Undefined reference to label " +
- BBForwardRefs.begin()->first->getName());
- return;
- }
-
- // Resolve all forward references now.
- ResolveDefinitions(LateResolveValues, &CurModule.LateResolveValues);
-
- Values.clear(); // Clear out function local definitions
- RenameMap.clear();
- CurrentFunction = 0;
- isDeclare = false;
- Linkage = GlobalValue::ExternalLinkage;
- }
-} CurFun; // Info for the current function...
-
-static bool inFunctionScope() { return CurFun.CurrentFunction != 0; }
-
-/// This function is just a utility to make a Key value for the rename map.
-/// The Key is a combination of the name, type, Signedness of the original
-/// value (global/function). This just constructs the key and ensures that
-/// named Signedness values are resolved to the actual Signedness.
-/// @brief Make a key for the RenameMaps
-static RenameMapKey makeRenameMapKey(const std::string &Name, const Type* Ty,
- const Signedness &Sign) {
- TypeInfo TI;
- TI.T = Ty;
- if (Sign.isNamed())
- // Don't allow Named Signedness nodes because they won't match. The actual
- // Signedness must be looked up in the NamedTypeSigns map.
- TI.S.copy(CurModule.NamedTypeSigns[Sign.getName()]);
- else
- TI.S.copy(Sign);
- return std::make_pair(Name, TI);
-}
-
-
-//===----------------------------------------------------------------------===//
-// Code to handle definitions of all the types
-//===----------------------------------------------------------------------===//
-
-static int InsertValue(Value *V,
- std::map<const Type*,ValueList> &ValueTab = CurFun.Values) {
- if (V->hasName()) return -1; // Is this a numbered definition?
-
- // Yes, insert the value into the value table...
- ValueList &List = ValueTab[V->getType()];
- List.push_back(V);
- return List.size()-1;
-}
-
-static const Type *getType(const ValID &D, bool DoNotImprovise = false) {
- switch (D.Type) {
- case ValID::NumberVal: // Is it a numbered definition?
- // Module constants occupy the lowest numbered slots...
- if ((unsigned)D.Num < CurModule.Types.size()) {
- return CurModule.Types[(unsigned)D.Num];
- }
- break;
- case ValID::NameVal: // Is it a named definition?
- if (const Type *N = CurModule.CurrentModule->getTypeByName(D.Name)) {
- return N;
- }
- break;
- default:
- error("Internal parser error: Invalid symbol type reference");
- return 0;
- }
-
- // If we reached here, we referenced either a symbol that we don't know about
- // or an id number that hasn't been read yet. We may be referencing something
- // forward, so just create an entry to be resolved later and get to it...
- //
- if (DoNotImprovise) return 0; // Do we just want a null to be returned?
-
- if (inFunctionScope()) {
- if (D.Type == ValID::NameVal) {
- error("Reference to an undefined type: '" + D.getName() + "'");
- return 0;
- } else {
- error("Reference to an undefined type: #" + itostr(D.Num));
- return 0;
- }
- }
-
- std::map<ValID, PATypeHolder>::iterator I =CurModule.LateResolveTypes.find(D);
- if (I != CurModule.LateResolveTypes.end())
- return I->second;
-
- Type *Typ = OpaqueType::get();
- CurModule.LateResolveTypes.insert(std::make_pair(D, Typ));
- return Typ;
-}
-
-/// This is like the getType method except that instead of looking up the type
-/// for a given ID, it looks up that type's sign.
-/// @brief Get the signedness of a referenced type
-static Signedness getTypeSign(const ValID &D) {
- switch (D.Type) {
- case ValID::NumberVal: // Is it a numbered definition?
- // Module constants occupy the lowest numbered slots...
- if ((unsigned)D.Num < CurModule.TypeSigns.size()) {
- return CurModule.TypeSigns[(unsigned)D.Num];
- }
- break;
- case ValID::NameVal: { // Is it a named definition?
- std::map<std::string,Signedness>::const_iterator I =
- CurModule.NamedTypeSigns.find(D.Name);
- if (I != CurModule.NamedTypeSigns.end())
- return I->second;
- // Perhaps its a named forward .. just cache the name
- Signedness S;
- S.makeNamed(D.Name);
- return S;
- }
- default:
- break;
- }
- // If we don't find it, its signless
- Signedness S;
- S.makeSignless();
- return S;
-}
-
-/// This function is analagous to getElementType in LLVM. It provides the same
-/// function except that it looks up the Signedness instead of the type. This is
-/// used when processing GEP instructions that need to extract the type of an
-/// indexed struct/array/ptr member.
-/// @brief Look up an element's sign.
-static Signedness getElementSign(const ValueInfo& VI,
- const std::vector<Value*> &Indices) {
- const Type *Ptr = VI.V->getType();
- assert(isa<PointerType>(Ptr) && "Need pointer type");
-
- unsigned CurIdx = 0;
- Signedness S(VI.S);
- while (const CompositeType *CT = dyn_cast<CompositeType>(Ptr)) {
- if (CurIdx == Indices.size())
- break;
-
- Value *Index = Indices[CurIdx++];
- assert(!isa<PointerType>(CT) || CurIdx == 1 && "Invalid type");
- Ptr = CT->getTypeAtIndex(Index);
- if (const Type* Ty = Ptr->getForwardedType())
- Ptr = Ty;
- assert(S.isComposite() && "Bad Signedness type");
- if (isa<StructType>(CT)) {
- S = S.get(cast<ConstantInt>(Index)->getZExtValue());
- } else {
- S = S.get(0UL);
- }
- if (S.isNamed())
- S = CurModule.NamedTypeSigns[S.getName()];
- }
- Signedness Result;
- Result.makeComposite(S);
- return Result;
-}
-
-/// This function just translates a ConstantInfo into a ValueInfo and calls
-/// getElementSign(ValueInfo,...). Its just a convenience.
-/// @brief ConstantInfo version of getElementSign.
-static Signedness getElementSign(const ConstInfo& CI,
- const std::vector<Constant*> &Indices) {
- ValueInfo VI;
- VI.V = CI.C;
- VI.S.copy(CI.S);
- std::vector<Value*> Idx;
- for (unsigned i = 0; i < Indices.size(); ++i)
- Idx.push_back(Indices[i]);
- Signedness result = getElementSign(VI, Idx);
- VI.destroy();
- return result;
-}
-
-// getExistingValue - Look up the value specified by the provided type and
-// the provided ValID. If the value exists and has already been defined, return
-// it. Otherwise return null.
-//
-static Value *getExistingValue(const Type *Ty, const ValID &D) {
- if (isa<FunctionType>(Ty)) {
- error("Functions are not values and must be referenced as pointers");
- }
-
- switch (D.Type) {
- case ValID::NumberVal: { // Is it a numbered definition?
- unsigned Num = (unsigned)D.Num;
-
- // Module constants occupy the lowest numbered slots...
- std::map<const Type*,ValueList>::iterator VI = CurModule.Values.find(Ty);
- if (VI != CurModule.Values.end()) {
- if (Num < VI->second.size())
- return VI->second[Num];
- Num -= VI->second.size();
- }
-
- // Make sure that our type is within bounds
- VI = CurFun.Values.find(Ty);
- if (VI == CurFun.Values.end()) return 0;
-
- // Check that the number is within bounds...
- if (VI->second.size() <= Num) return 0;
-
- return VI->second[Num];
- }
-
- case ValID::NameVal: { // Is it a named definition?
- // Get the name out of the ID
- RenameMapKey Key = makeRenameMapKey(D.Name, Ty, D.S);
- Value *V = 0;
- if (inFunctionScope()) {
- // See if the name was renamed
- RenameMapType::const_iterator I = CurFun.RenameMap.find(Key);
- std::string LookupName;
- if (I != CurFun.RenameMap.end())
- LookupName = I->second;
- else
- LookupName = D.Name;
- ValueSymbolTable &SymTab = CurFun.CurrentFunction->getValueSymbolTable();
- V = SymTab.lookup(LookupName);
- if (V && V->getType() != Ty)
- V = 0;
- }
- if (!V) {
- RenameMapType::const_iterator I = CurModule.RenameMap.find(Key);
- std::string LookupName;
- if (I != CurModule.RenameMap.end())
- LookupName = I->second;
- else
- LookupName = D.Name;
- V = CurModule.CurrentModule->getValueSymbolTable().lookup(LookupName);
- if (V && V->getType() != Ty)
- V = 0;
- }
- if (!V)
- return 0;
-
- D.destroy(); // Free old strdup'd memory...
- return V;
- }
-
- // Check to make sure that "Ty" is an integral type, and that our
- // value will fit into the specified type...
- case ValID::ConstSIntVal: // Is it a constant pool reference??
- if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64)) {
- error("Signed integral constant '" + itostr(D.ConstPool64) +
- "' is invalid for type '" + Ty->getDescription() + "'");
- }
- return ConstantInt::get(Ty, D.ConstPool64);
-
- case ValID::ConstUIntVal: // Is it an unsigned const pool reference?
- if (!ConstantInt::isValueValidForType(Ty, D.UConstPool64)) {
- if (!ConstantInt::isValueValidForType(Ty, D.ConstPool64))
- error("Integral constant '" + utostr(D.UConstPool64) +
- "' is invalid or out of range");
- else // This is really a signed reference. Transmogrify.
- return ConstantInt::get(Ty, D.ConstPool64);
- } else
- return ConstantInt::get(Ty, D.UConstPool64);
-
- case ValID::ConstFPVal: // Is it a floating point const pool reference?
- if (!ConstantFP::isValueValidForType(Ty, *D.ConstPoolFP))
- error("FP constant invalid for type");
- // Lexer has no type info, so builds all FP constants as double.
- // Fix this here.
- if (Ty==Type::FloatTy)
- D.ConstPoolFP->convert(APFloat::IEEEsingle, APFloat::rmNearestTiesToEven);
- return ConstantFP::get(Ty, *D.ConstPoolFP);
-
- case ValID::ConstNullVal: // Is it a null value?
- if (!isa<PointerType>(Ty))
- error("Cannot create a a non pointer null");
- return ConstantPointerNull::get(cast<PointerType>(Ty));
-
- case ValID::ConstUndefVal: // Is it an undef value?
- return UndefValue::get(Ty);
-
- case ValID::ConstZeroVal: // Is it a zero value?
- return Constant::getNullValue(Ty);
-
- case ValID::ConstantVal: // Fully resolved constant?
- if (D.ConstantValue->getType() != Ty)
- error("Constant expression type different from required type");
- return D.ConstantValue;
-
- case ValID::InlineAsmVal: { // Inline asm expression
- const PointerType *PTy = dyn_cast<PointerType>(Ty);
- const FunctionType *FTy =
- PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
- if (!FTy || !InlineAsm::Verify(FTy, D.IAD->Constraints))
- error("Invalid type for asm constraint string");
- InlineAsm *IA = InlineAsm::get(FTy, D.IAD->AsmString, D.IAD->Constraints,
- D.IAD->HasSideEffects);
- D.destroy(); // Free InlineAsmDescriptor.
- return IA;
- }
- default:
- assert(0 && "Unhandled case");
- return 0;
- } // End of switch
-
- assert(0 && "Unhandled case");
- return 0;
-}
-
-// getVal - This function is identical to getExistingValue, except that if a
-// value is not already defined, it "improvises" by creating a placeholder var
-// that looks and acts just like the requested variable. When the value is
-// defined later, all uses of the placeholder variable are replaced with the
-// real thing.
-//
-static Value *getVal(const Type *Ty, const ValID &ID) {
- if (Ty == Type::LabelTy)
- error("Cannot use a basic block here");
-
- // See if the value has already been defined.
- Value *V = getExistingValue(Ty, ID);
- if (V) return V;
-
- if (!Ty->isFirstClassType() && !isa<OpaqueType>(Ty))
- error("Invalid use of a composite type");
-
- // If we reached here, we referenced either a symbol that we don't know about
- // or an id number that hasn't been read yet. We may be referencing something
- // forward, so just create an entry to be resolved later and get to it...
- V = new Argument(Ty);
-
- // Remember where this forward reference came from. FIXME, shouldn't we try
- // to recycle these things??
- CurModule.PlaceHolderInfo.insert(
- std::make_pair(V, std::make_pair(ID, Upgradelineno)));
-
- if (inFunctionScope())
- InsertValue(V, CurFun.LateResolveValues);
- else
- InsertValue(V, CurModule.LateResolveValues);
- return V;
-}
-
-/// @brief This just makes any name given to it unique, up to MAX_UINT times.
-static std::string makeNameUnique(const std::string& Name) {
- static unsigned UniqueNameCounter = 1;
- std::string Result(Name);
- Result += ".upgrd." + llvm::utostr(UniqueNameCounter++);
- return Result;
-}
-
-/// getBBVal - This is used for two purposes:
-/// * If isDefinition is true, a new basic block with the specified ID is being
-/// defined.
-/// * If isDefinition is true, this is a reference to a basic block, which may
-/// or may not be a forward reference.
-///
-static BasicBlock *getBBVal(const ValID &ID, bool isDefinition = false) {
- assert(inFunctionScope() && "Can't get basic block at global scope");
-
- std::string Name;
- BasicBlock *BB = 0;
- switch (ID.Type) {
- default:
- error("Illegal label reference " + ID.getName());
- break;
- case ValID::NumberVal: // Is it a numbered definition?
- if (unsigned(ID.Num) >= CurFun.NumberedBlocks.size())
- CurFun.NumberedBlocks.resize(ID.Num+1);
- BB = CurFun.NumberedBlocks[ID.Num];
- break;
- case ValID::NameVal: // Is it a named definition?
- Name = ID.Name;
- if (Value *N = CurFun.CurrentFunction->getValueSymbolTable().lookup(Name)) {
- if (N->getType() != Type::LabelTy) {
- // Register names didn't use to conflict with basic block names
- // because of type planes. Now they all have to be unique. So, we just
- // rename the register and treat this name as if no basic block
- // had been found.
- RenameMapKey Key = makeRenameMapKey(ID.Name, N->getType(), ID.S);
- N->setName(makeNameUnique(N->getName()));
- CurModule.RenameMap[Key] = N->getName();
- BB = 0;
- } else {
- BB = cast<BasicBlock>(N);
- }
- }
- break;
- }
-
- // See if the block has already been defined.
- if (BB) {
- // If this is the definition of the block, make sure the existing value was
- // just a forward reference. If it was a forward reference, there will be
- // an entry for it in the PlaceHolderInfo map.
- if (isDefinition && !CurFun.BBForwardRefs.erase(BB))
- // The existing value was a definition, not a forward reference.
- error("Redefinition of label " + ID.getName());
-
- ID.destroy(); // Free strdup'd memory.
- return BB;
- }
-
- // Otherwise this block has not been seen before.
- BB = new BasicBlock("", CurFun.CurrentFunction);
- if (ID.Type == ValID::NameVal) {
- BB->setName(ID.Name);
- } else {
- CurFun.NumberedBlocks[ID.Num] = BB;
- }
-
- // If this is not a definition, keep track of it so we can use it as a forward
- // reference.
- if (!isDefinition) {
- // Remember where this forward reference came from.
- CurFun.BBForwardRefs[BB] = std::make_pair(ID, Upgradelineno);
- } else {
- // The forward declaration could have been inserted anywhere in the
- // function: insert it into the correct place now.
- CurFun.CurrentFunction->getBasicBlockList().remove(BB);
- CurFun.CurrentFunction->getBasicBlockList().push_back(BB);
- }
- ID.destroy();
- return BB;
-}
-
-
-//===----------------------------------------------------------------------===//
-// Code to handle forward references in instructions
-//===----------------------------------------------------------------------===//
-//
-// This code handles the late binding needed with statements that reference
-// values not defined yet... for example, a forward branch, or the PHI node for
-// a loop body.
-//
-// This keeps a table (CurFun.LateResolveValues) of all such forward references
-// and back patchs after we are done.
-//
-
-// ResolveDefinitions - If we could not resolve some defs at parsing
-// time (forward branches, phi functions for loops, etc...) resolve the
-// defs now...
-//
-static void
-ResolveDefinitions(std::map<const Type*,ValueList> &LateResolvers,
- std::map<const Type*,ValueList> *FutureLateResolvers) {
-
- // Loop over LateResolveDefs fixing up stuff that couldn't be resolved
- for (std::map<const Type*,ValueList>::iterator LRI = LateResolvers.begin(),
- E = LateResolvers.end(); LRI != E; ++LRI) {
- const Type* Ty = LRI->first;
- ValueList &List = LRI->second;
- while (!List.empty()) {
- Value *V = List.back();
- List.pop_back();
-
- std::map<Value*, std::pair<ValID, int> >::iterator PHI =
- CurModule.PlaceHolderInfo.find(V);
- assert(PHI != CurModule.PlaceHolderInfo.end() && "Placeholder error");
-
- ValID &DID = PHI->second.first;
-
- Value *TheRealValue = getExistingValue(Ty, DID);
- if (TheRealValue) {
- V->replaceAllUsesWith(TheRealValue);
- delete V;
- CurModule.PlaceHolderInfo.erase(PHI);
- } else if (FutureLateResolvers) {
- // Functions have their unresolved items forwarded to the module late
- // resolver table
- InsertValue(V, *FutureLateResolvers);
- } else {
- if (DID.Type == ValID::NameVal) {
- error("Reference to an invalid definition: '" + DID.getName() +
- "' of type '" + V->getType()->getDescription() + "'",
- PHI->second.second);
- return;
- } else {
- error("Reference to an invalid definition: #" +
- itostr(DID.Num) + " of type '" +
- V->getType()->getDescription() + "'", PHI->second.second);
- return;
- }
- }
- }
- }
-
- LateResolvers.clear();
-}
-
-/// This function is used for type resolution and upref handling. When a type
-/// becomes concrete, this function is called to adjust the signedness for the
-/// concrete type.
-static void ResolveTypeSign(const Type* oldTy, const Signedness &Sign) {
- std::string TyName = CurModule.CurrentModule->getTypeName(oldTy);
- if (!TyName.empty())
- CurModule.NamedTypeSigns[TyName] = Sign;
-}
-
-/// ResolveTypeTo - A brand new type was just declared. Thi