#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
//===----------------------------------------------------------------------===//
#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) {
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;
- }
-}
#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"
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) {
#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
//===----------------------------------------------------------------------===//