summaryrefslogtreecommitdiff
path: root/tools/llvm-upgrade/UpgradeInternals.h
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-01-26 08:18:34 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-01-26 08:18:34 +0000
commitefd53d57a6606bfe0549a7e4bd1f29c5582d5b75 (patch)
tree74488649e9867b25e877fa85d2d049af9c782de5 /tools/llvm-upgrade/UpgradeInternals.h
parent26f238589f9bb372d24b6fb2bc32edbf046fd9ee (diff)
downloadllvm-efd53d57a6606bfe0549a7e4bd1f29c5582d5b75.tar.gz
llvm-efd53d57a6606bfe0549a7e4bd1f29c5582d5b75.tar.bz2
llvm-efd53d57a6606bfe0549a7e4bd1f29c5582d5b75.tar.xz
For All These Bugs:
PR645 PR761 PR1082 PR1122 Completely rewrite llvm-upgrade. This should be its final design. Any future changes will use this same design. The changes involve the following: 1. Make this work very much like the 1.9 AsmParser 2. Retain old upgrades dating back to release 1.2 time frame. 3. Merge in some of the upgrades between 1.9 and 2.0 (e.g. icmp/fcmp). 4. Attach a Signedness value (Signless, Unsigned, Signed) to every type, Value, Constant, Instruction, and list of those things in the Parser. Use these to make signedness decisions for instruction upgrades. 5. Implement unique name upgrade for function values and global values. 6. Identify rename cases that might cause problems and warn about them. For example: renaming a global variable with external linkage. 7. Generate a 2.0 IR using VMCore. This is necessary for numerous reasons and has the advantage that it never goes out of date. 8. Use the AsmPrinter to make the output nice. 9. Clean up error and warning messages from 1.9 form. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33531 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-upgrade/UpgradeInternals.h')
-rw-r--r--tools/llvm-upgrade/UpgradeInternals.h300
1 files changed, 257 insertions, 43 deletions
diff --git a/tools/llvm-upgrade/UpgradeInternals.h b/tools/llvm-upgrade/UpgradeInternals.h
index f01d415f6b..4fe0ed0756 100644
--- a/tools/llvm-upgrade/UpgradeInternals.h
+++ b/tools/llvm-upgrade/UpgradeInternals.h
@@ -1,65 +1,279 @@
-//===-- UpgradeInternals.h - Internal parser definitionsr -------*- C++ -*-===//
+//===-- ParserInternals.h - Definitions internal to the parser --*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
-// This file was developed by Reid Spencer and is distributed under
+// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
-// This header file defines the variables that are shared between the lexer,
-// the parser, and the main program.
+// This header file defines the various variables that are shared among the
+// different components of the parser...
//
//===----------------------------------------------------------------------===//
-#ifndef UPGRADE_INTERNALS_H
-#define UPGRADE_INTERNALS_H
+#ifndef PARSER_INTERNALS_H
+#define PARSER_INTERNALS_H
+
+#include "llvm/Constants.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/Function.h"
+#include "llvm/Instructions.h"
+#include "llvm/ADT/StringExtras.h"
+#include <list>
-#include <llvm/ADT/StringExtras.h>
-#include <string>
-#include <istream>
-#include <vector>
-#include <set>
-#include <cassert>
// Global variables exported from the lexer.
-extern std::string CurFileName;
-extern std::string Textin;
+extern int yydebug;
+extern void error(const std::string& msg, int line = -1);
+extern char* Upgradetext;
+extern int Upgradeleng;
extern int Upgradelineno;
+
+namespace llvm {
+
+
+class Module;
+Module* UpgradeAssembly(const std::string &infile, std::istream& in,
+ bool debug, bool addAttrs);
+
+
+class SignedType : public IntegerType {
+ const IntegerType *base_type;
+ static SignedType *SByteTy;
+ static SignedType *SShortTy;
+ static SignedType *SIntTy;
+ static SignedType *SLongTy;
+ SignedType(const IntegerType* ITy);
+public:
+ static const SignedType *get(const IntegerType* ITy);
+
+ bool isSigned() const { return true; }
+ const IntegerType* getBaseType() const {
+ return base_type;
+ }
+ const IntegerType* resolve() const {
+ ForwardType = base_type;
+ return base_type;
+ }
+
+ // Methods for support type inquiry through isa, cast, and dyn_cast:
+ static inline bool classof(const SignedType *T) { return true; }
+ static inline bool classof(const Type *T);
+};
+
extern std::istream* LexInput;
-// Global variables exported from the parser.
-extern char* Upgradetext;
-extern int Upgradeleng;
-extern unsigned SizeOfPointer;
-
-// Functions exported by the parser
-void UpgradeAssembly(
- const std::string & infile, std::istream& in, std::ostream &out, bool debug,
- bool addAttrs);
-int yyerror(const char *ErrorMsg) ;
-
-/// This enum is used to keep track of the original (1.9) type used to form
-/// a type. These are needed for type upgrades and to determine how to upgrade
-/// signed instructions with signless operands. The Lexer uses thse in its
-/// calls to getType
-enum TypeIDs {
- BoolTy, SByteTy, UByteTy, ShortTy, UShortTy, IntTy, UIntTy, LongTy, ULongTy,
- FloatTy, DoubleTy, PointerTy, PackedTy, ArrayTy, StructTy, PackedStructTy,
- OpaqueTy, VoidTy, LabelTy, FunctionTy, UnresolvedTy, UpRefTy
+// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
+// appropriate character. If AllowNull is set to false, a \00 value will cause
+// an error.
+//
+// If AllowNull is set to true, the return value of the function points to the
+// last character of the string in memory.
+//
+char *UnEscapeLexed(char *Buffer, bool AllowNull = false);
+
+/// InlineAsmDescriptor - This is a simple class that holds info about inline
+/// asm blocks, for use by ValID.
+struct InlineAsmDescriptor {
+ std::string AsmString, Constraints;
+ bool HasSideEffects;
+
+ InlineAsmDescriptor(const std::string &as, const std::string &c, bool HSE)
+ : AsmString(as), Constraints(c), HasSideEffects(HSE) {}
+};
+
+
+// ValID - Represents a reference of a definition of some sort. This may either
+// be a numeric reference or a symbolic (%var) reference. This is just a
+// discriminated union.
+//
+// Note that I can't implement this class in a straight forward manner with
+// constructors and stuff because it goes in a union.
+//
+struct ValID {
+ enum {
+ NumberVal, NameVal, ConstSIntVal, ConstUIntVal, ConstFPVal, ConstNullVal,
+ ConstUndefVal, ConstZeroVal, ConstantVal, InlineAsmVal
+ } Type;
+
+ union {
+ int Num; // If it's a numeric reference
+ char *Name; // If it's a named reference. Memory must be free'd.
+ int64_t ConstPool64; // Constant pool reference. This is the value
+ uint64_t UConstPool64;// Unsigned constant pool reference.
+ double ConstPoolFP; // Floating point constant pool reference
+ Constant *ConstantValue; // Fully resolved constant for ConstantVal case.
+ InlineAsmDescriptor *IAD;
+ };
+
+ static ValID create(int Num) {
+ ValID D; D.Type = NumberVal; D.Num = Num; return D;
+ }
+
+ static ValID create(char *Name) {
+ ValID D; D.Type = NameVal; D.Name = Name; return D;
+ }
+
+ static ValID create(int64_t Val) {
+ ValID D; D.Type = ConstSIntVal; D.ConstPool64 = Val; return D;
+ }
+
+ static ValID create(uint64_t Val) {
+ ValID D; D.Type = ConstUIntVal; D.UConstPool64 = Val; return D;
+ }
+
+ static ValID create(double Val) {
+ ValID D; D.Type = ConstFPVal; D.ConstPoolFP = Val; return D;
+ }
+
+ static ValID createNull() {
+ ValID D; D.Type = ConstNullVal; return D;
+ }
+
+ static ValID createUndef() {
+ ValID D; D.Type = ConstUndefVal; return D;
+ }
+
+ static ValID createZeroInit() {
+ ValID D; D.Type = ConstZeroVal; return D;
+ }
+
+ static ValID create(Constant *Val) {
+ ValID D; D.Type = ConstantVal; D.ConstantValue = Val; return D;
+ }
+
+ static ValID createInlineAsm(const std::string &AsmString,
+ const std::string &Constraints,
+ bool HasSideEffects) {
+ ValID D;
+ D.Type = InlineAsmVal;
+ D.IAD = new InlineAsmDescriptor(AsmString, Constraints, HasSideEffects);
+ return D;
+ }
+
+ inline void destroy() const {
+ if (Type == NameVal)
+ free(Name); // Free this strdup'd memory.
+ else if (Type == InlineAsmVal)
+ delete IAD;
+ }
+
+ inline ValID copy() const {
+ if (Type != NameVal) return *this;
+ ValID Result = *this;
+ Result.Name = strdup(Name);
+ return Result;
+ }
+
+ inline std::string getName() const {
+ switch (Type) {
+ case NumberVal : return std::string("#") + itostr(Num);
+ case NameVal : return Name;
+ case ConstFPVal : return ftostr(ConstPoolFP);
+ case ConstNullVal : return "null";
+ case ConstUndefVal : return "undef";
+ case ConstZeroVal : return "zeroinitializer";
+ case ConstUIntVal :
+ case ConstSIntVal : return std::string("%") + itostr(ConstPool64);
+ case ConstantVal:
+ if (ConstantValue == ConstantInt::get(Type::Int1Ty, true))
+ return "true";
+ if (ConstantValue == ConstantInt::get(Type::Int1Ty, false))
+ return "false";
+ return "<constant expression>";
+ default:
+ assert(0 && "Unknown value!");
+ abort();
+ return "";
+ }
+ }
+
+ bool operator<(const ValID &V) const {
+ if (Type != V.Type) return Type < V.Type;
+ switch (Type) {
+ case NumberVal: return Num < V.Num;
+ case NameVal: return strcmp(Name, V.Name) < 0;
+ case ConstSIntVal: return ConstPool64 < V.ConstPool64;
+ case ConstUIntVal: return UConstPool64 < V.UConstPool64;
+ case ConstFPVal: return ConstPoolFP < V.ConstPoolFP;
+ case ConstNullVal: return false;
+ case ConstUndefVal: return false;
+ case ConstZeroVal: return false;
+ case ConstantVal: return ConstantValue < V.ConstantValue;
+ default: assert(0 && "Unknown value type!"); return false;
+ }
+ }
};
-namespace {
-class Type;
-class Value;
-class Constant;
-class Instruction;
-}
-typedef std::vector<const Type*> TypeList;
-typedef std::vector<Value*> ValueList;
+// This structure is used to keep track of obsolete opcodes. The lexer will
+// retain the ability to parse obsolete opcode mnemonics. In this case it will
+// set "obsolete" to true and the opcode will be the replacement opcode. For
+// example if "rem" is encountered then opcode will be set to "urem" and the
+// "obsolete" flag will be true. If the opcode is not obsolete then "obsolete"
+// will be false.
+
+enum TermOps {
+ RetOp, BrOp, SwitchOp, InvokeOp, UnwindOp, UnreachableOp
+};
+
+enum BinaryOps {
+ AddOp, SubOp, MulOp,
+ DivOp, UDivOp, SDivOp, FDivOp,
+ RemOp, URemOp, SRemOp, FRemOp,
+ AndOp, OrOp, XorOp,
+ SetEQ, SetNE, SetLE, SetGE, SetLT, SetGT
+};
+
+enum MemoryOps {
+ MallocOp, FreeOp, AllocaOp, LoadOp, StoreOp, GetElementPtrOp
+};
+
+enum OtherOps {
+ PHIOp, CallOp, ShlOp, ShrOp, SelectOp, UserOp1, UserOp2, VAArg,
+ ExtractElementOp, InsertElementOp, ShuffleVectorOp,
+ ICmpOp, FCmpOp,
+ LShrOp, AShrOp
+};
+
+enum CastOps {
+ CastOp, TruncOp, ZExtOp, SExtOp, FPTruncOp, FPExtOp, FPToUIOp, FPToSIOp,
+ UIToFPOp, SIToFPOp, PtrToIntOp, IntToPtrOp, BitCastOp
+};
+
+enum Signedness { Signless, Unsigned, Signed };
+
+struct TypeInfo {
+ const llvm::Type *T;
+ Signedness S;
+};
+
+struct PATypeInfo {
+ llvm::PATypeHolder* T;
+ Signedness S;
+};
+
+struct ConstInfo {
+ llvm::Constant* C;
+ Signedness S;
+};
+
+struct ValueInfo {
+ llvm::Value* V;
+ Signedness S;
+};
+
+struct InstrInfo {
+ llvm::Instruction *I;
+ Signedness S;
+};
+
+struct PHIListInfo {
+ std::list<std::pair<llvm::Value*, llvm::BasicBlock*> > *P;
+ Signedness S;
+};
-/// A function to create a Typeo* used in the Lexer.
-extern const Type* getType(const std::string& newTy, TypeIDs oldTy);
+} // End llvm namespace
#endif