summaryrefslogtreecommitdiff
path: root/tools/llvm-upgrade/UpgradeInternals.h
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-01-05 17:18:58 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-01-05 17:18:58 +0000
commit90eb4d653c413991b577fde2edde023ff4a66318 (patch)
treed3432286b5f70df9d9b6397049987ab60c691ddd /tools/llvm-upgrade/UpgradeInternals.h
parent218ded2fc98b4f27c341247bafa745bc7a7721c2 (diff)
downloadllvm-90eb4d653c413991b577fde2edde023ff4a66318.tar.gz
llvm-90eb4d653c413991b577fde2edde023ff4a66318.tar.bz2
llvm-90eb4d653c413991b577fde2edde023ff4a66318.tar.xz
Major update of llvm-upgrade:
1. Completely revise the type system so that types are handled as const objects and not created multiple times, cloned, or otherwise copied. This gets around memory issues, saves memory, and also emulates LLVM's no-two-types-of-the-same-shape-created semantics. 2. Adjust the handling of global names. Basically, we cannot rename them for a variety of reasons: linking, forward references, etc. 3. Detect global names that have name conflicts as the result of collapsed type planes or redefinitions that llvm-as no longer accepts. These will produce warnings on stderr and one of the globals will be renamed. 4. Rename ParserInternals.h as UpgradeInternals.h so it doesn't conflict in the debugger with ParserInternals.h from lib/AsmParser. 5. Move the guts of the TypeInfo class into the grammar so we aren't implementing large functions in a header file. This also helps with debugging a bit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32906 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-upgrade/UpgradeInternals.h')
-rw-r--r--tools/llvm-upgrade/UpgradeInternals.h210
1 files changed, 210 insertions, 0 deletions
diff --git a/tools/llvm-upgrade/UpgradeInternals.h b/tools/llvm-upgrade/UpgradeInternals.h
new file mode 100644
index 0000000000..5616c511e2
--- /dev/null
+++ b/tools/llvm-upgrade/UpgradeInternals.h
@@ -0,0 +1,210 @@
+//===-- UpgradeInternals.h - Internal parser definitionsr -------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer 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.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef UPGRADE_INTERNALS_H
+#define UPGRADE_INTERNALS_H
+
+#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 Upgradelineno;
+extern std::istream* LexInput;
+
+struct TypeInfo;
+typedef std::vector<const TypeInfo*> TypeList;
+
+void UpgradeAssembly(
+ const std::string & infile, std::istream& in, std::ostream &out, bool debug,
+ bool addAttrs);
+
+// Globals exported by the parser...
+extern char* Upgradetext;
+extern int Upgradeleng;
+extern unsigned SizeOfPointer;
+
+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.
+enum Types {
+ BoolTy, SByteTy, UByteTy, ShortTy, UShortTy, IntTy, UIntTy, LongTy, ULongTy,
+ FloatTy, DoubleTy, PointerTy, PackedTy, ArrayTy, StructTy, PackedStructTy,
+ OpaqueTy, VoidTy, LabelTy, FunctionTy, UnresolvedTy, UpRefTy
+};
+
+/// This type is used to keep track of the signedness of values. Instead
+/// of creating llvm::Value directly, the parser will create ValueInfo which
+/// associates a Value* with a Signedness indication.
+struct ValueInfo {
+ std::string* val;
+ const TypeInfo* type;
+ bool constant;
+ bool isConstant() const { return constant; }
+ inline void destroy();
+};
+
+/// This type is used to keep track of the signedness of the obsolete
+/// integer types. Instead of creating an llvm::Type directly, the Lexer will
+/// create instances of TypeInfo which retains the signedness indication so
+/// it can be used by the parser for upgrade decisions.
+/// For example if "uint" is encountered then the "first" field will be set
+/// to "int32" and the "second" field will be set to "isUnsigned". If the
+/// type is not obsolete then "second" will be set to "isSignless".
+struct TypeInfo {
+
+ static const TypeInfo* get(const std::string &newType, Types oldType);
+ static const TypeInfo* get(const std::string& newType, Types oldType,
+ const TypeInfo* eTy, const TypeInfo* rTy);
+
+ static const TypeInfo* get(const std::string& newType, Types oldType,
+ const TypeInfo *eTy, uint64_t elems);
+
+ static const TypeInfo* get(const std::string& newType, Types oldType,
+ TypeList* TL);
+
+ static const TypeInfo* get(const std::string& newType, const TypeInfo* resTy,
+ TypeList* TL);
+
+ const TypeInfo* resolve() const;
+ bool operator<(const TypeInfo& that) const;
+
+ bool sameNewTyAs(const TypeInfo* that) const {
+ return this->newTy == that->newTy;
+ }
+
+ bool sameOldTyAs(const TypeInfo* that) const;
+
+ Types getElementTy() const {
+ if (elemTy) {
+ return elemTy->oldTy;
+ }
+ return UnresolvedTy;
+ }
+
+ unsigned getUpRefNum() const {
+ assert(oldTy == UpRefTy && "Can't getUpRefNum on non upreference");
+ return atoi(&((getNewTy().c_str())[1])); // skip the slash
+ }
+
+ const std::string& getNewTy() const { return newTy; }
+ const TypeInfo* getResultType() const { return resultTy; }
+ const TypeInfo* getElementType() const { return elemTy; }
+
+ const TypeInfo* getPointerType() const {
+ return get(newTy + "*", PointerTy, this, (TypeInfo*)0);
+ }
+
+ bool isUnresolved() const { return oldTy == UnresolvedTy; }
+ bool isUpReference() const { return oldTy == UpRefTy; }
+ bool isVoid() const { return oldTy == VoidTy; }
+ bool isBool() const { return oldTy == BoolTy; }
+ bool isSigned() const {
+ return oldTy == SByteTy || oldTy == ShortTy ||
+ oldTy == IntTy || oldTy == LongTy;
+ }
+
+ bool isUnsigned() const {
+ return oldTy == UByteTy || oldTy == UShortTy ||
+ oldTy == UIntTy || oldTy == ULongTy;
+ }
+ bool isSignless() const { return !isSigned() && !isUnsigned(); }
+ bool isInteger() const { return isSigned() || isUnsigned(); }
+ bool isIntegral() const { return oldTy == BoolTy || isInteger(); }
+ bool isFloatingPoint() const { return oldTy == DoubleTy || oldTy == FloatTy; }
+ bool isPacked() const { return oldTy == PackedTy; }
+ bool isPointer() const { return oldTy == PointerTy; }
+ bool isStruct() const { return oldTy == StructTy || oldTy == PackedStructTy; }
+ bool isArray() const { return oldTy == ArrayTy; }
+ bool isOther() const {
+ return !isPacked() && !isPointer() && !isFloatingPoint() && !isIntegral(); }
+ bool isFunction() const { return oldTy == FunctionTy; }
+ bool isComposite() const {
+ return isStruct() || isPointer() || isArray() || isPacked();
+ }
+
+ bool isAttributeCandidate() const {
+ return isIntegral() && getBitWidth() < 32;
+ }
+
+ bool isUnresolvedDeep() const;
+
+ unsigned getBitWidth() const;
+
+ const TypeInfo* getIndexedType(const ValueInfo& VI) const;
+
+ unsigned getNumStructElements() const {
+ return (elements ? elements->size() : 0);
+ }
+
+ const TypeInfo* getElement(unsigned idx) const {
+ if (elements)
+ if (idx < elements->size())
+ return (*elements)[idx];
+ return 0;
+ }
+
+
+private:
+ TypeInfo()
+ : newTy(), oldTy(UnresolvedTy), elemTy(0), resultTy(0), elements(0),
+ nelems(0) {
+ }
+
+ TypeInfo(const TypeInfo& that); // do not implement
+ TypeInfo& operator=(const TypeInfo& that); // do not implement
+
+ ~TypeInfo() { delete elements; }
+
+ struct ltfunctor
+ {
+ bool operator()(const TypeInfo* X, const TypeInfo* Y) const {
+ assert(X && "Can't compare null pointer");
+ assert(Y && "Can't compare null pointer");
+ return *X < *Y;
+ }
+ };
+
+ typedef std::set<const TypeInfo*, ltfunctor> TypeRegMap;
+ static const TypeInfo* add_new_type(TypeInfo* existing);
+
+ std::string newTy;
+ Types oldTy;
+ TypeInfo *elemTy;
+ TypeInfo *resultTy;
+ TypeList *elements;
+ uint64_t nelems;
+ static TypeRegMap registry;
+};
+
+/// This type is used to keep track of the signedness of constants.
+struct ConstInfo {
+ std::string *cnst;
+ const TypeInfo *type;
+ void destroy() { delete cnst; }
+};
+
+typedef std::vector<ValueInfo> ValueList;
+
+inline void ValueInfo::destroy() { delete val; }
+
+#endif