Moved UnaryOperator::create to InstrTypes.cpp until there is an iUnaryOps.cpp
authorChris Lattner <sabre@nondot.org>
Mon, 25 Jun 2001 07:33:13 +0000 (07:33 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 25 Jun 2001 07:33:13 +0000 (07:33 +0000)
Moved BinaryOperator::create to iBinaryOperators.cpp
Add getUniqueName to SymbolTable

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@76 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/InstrTypes.cpp
lib/VMCore/Instruction.cpp
lib/VMCore/SymbolTable.cpp
lib/VMCore/iOperators.cpp

index 15db9e07a7104a4247d7d6acd1d1420acc94279f..142019b93d2320a5abbd74a16b8d643654f3d099 100644 (file)
 #include "llvm/Type.h"
 #include <algorithm>
 
+// TODO: Move to getUnaryOperator iUnary.cpp when and if it exists!
+UnaryOperator *UnaryOperator::create(unsigned Op, Value *Source) {
+  switch (Op) {
+  default:
+    cerr << "Don't know how to GetUnaryOperator " << Op << endl;
+    return 0;
+  }
+}
+
 //===----------------------------------------------------------------------===//
 //                            TerminatorInst Class
 //===----------------------------------------------------------------------===//
index 6cb62ea374aac864994b97460f8196f564f375b6..bd3596debfa2e12c3d0c9b74c0bf1cf3a3ebf11e 100644 (file)
@@ -8,8 +8,6 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/Method.h"
 #include "llvm/SymbolTable.h"
-#include "llvm/iBinary.h"
-#include "llvm/iUnary.h"
 
 Instruction::Instruction(const Type *ty, unsigned it, const string &Name) 
   : User(ty, Value::InstructionVal, Name) {
@@ -29,34 +27,3 @@ void Instruction::setName(const string &name) {
   Value::setName(name);
   if (PP && hasName()) PP->getSymbolTableSure()->insert(this);
 }
-
-BinaryOperator *BinaryOperator::getBinaryOperator(unsigned Op, 
-                                                 Value *S1, Value *S2) {
-  switch (Op) {
-  case Add:
-    return new AddInst(S1, S2);
-  case Sub:
-    return new SubInst(S1, S2);
-
-  case SetLT:
-  case SetGT:
-  case SetLE:
-  case SetGE:
-  case SetEQ:
-  case SetNE:
-    return new SetCondInst((BinaryOps)Op, S1, S2);
-
-  default:
-    cerr << "Don't know how to GetBinaryOperator " << Op << endl;
-    return 0;
-  }
-}
-
-
-UnaryOperator *UnaryOperator::getUnaryOperator(unsigned Op, Value *Source) {
-  switch (Op) {
-  default:
-    cerr << "Don't know how to GetUnaryOperator " << Op << endl;
-    return 0;
-  }
-}
index 395c23f2abc944ac0a2e704defb7e1d0fb6c4041..214f41f169e6bd301c897a46e8e33384a93d8eb6 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "llvm/SymbolTable.h"
 #include "llvm/InstrTypes.h"
+#include "llvm/Tools/StringExtras.h"
 #ifndef NDEBUG
 #include "llvm/BasicBlock.h"   // Required for assertions to work.
 #include "llvm/Type.h"
@@ -45,6 +46,24 @@ SymbolTable::type_iterator SymbolTable::type_find(const Type *Ty,
   return I->second.find(Name);
 }
 
+// getUniqueName - Given a base name, return a string that is either equal to
+// it (or derived from it) that does not already occur in the symbol table for
+// the specified type.
+//
+string SymbolTable::getUniqueName(const Type *Ty, const string &BaseName) {
+  iterator I = find(Ty);
+  if (I == end()) return BaseName;
+
+  string TryName = BaseName;
+  unsigned Counter = 0;
+  type_iterator End = I->second.end();
+
+  while (I->second.find(TryName) != End)     // Loop until we find unoccupied
+    TryName = BaseName + utostr(++Counter);  // Name in the symbol table
+  return TryName;
+}
+
+
 
 // lookup - Returns null on failure...
 Value *SymbolTable::lookup(const Type *Ty, const string &Name) {
index c754f42b6f0cb6827df3e13d3d6717e4d76707ba..d856a20d0a5a7afb8712735469ff93bb5b747f89 100644 (file)
@@ -7,6 +7,25 @@
 #include "llvm/iBinary.h"
 #include "llvm/Type.h"
 
+BinaryOperator *BinaryOperator::create(unsigned Op, Value *S1, Value *S2,
+                                      const string &Name) {
+  switch (Op) {
+  case Add: return new AddInst(S1, S2, Name);
+  case Sub: return new SubInst(S1, S2, Name);
+  case SetLT:
+  case SetGT:
+  case SetLE:
+  case SetGE:
+  case SetEQ:
+  case SetNE:
+    return new SetCondInst((BinaryOps)Op, S1, S2, Name);
+
+  default:
+    cerr << "Don't know how to GetBinaryOperator " << Op << endl;
+    return 0;
+  }
+}
+
 //===----------------------------------------------------------------------===//
 //                             SetCondInst Class
 //===----------------------------------------------------------------------===//