Moved UnaryOperator::create to InstrTypes.cpp until there is an iUnaryOps.cpp

Moved BinaryOperator::create to iBinaryOperators.cpp
Add getUniqueName to SymbolTable

llvm-svn: 76
This commit is contained in:
Chris Lattner 2001-06-25 07:33:13 +00:00
parent dbdaaef7d5
commit 01683cca32
4 changed files with 47 additions and 33 deletions

View file

@ -11,6 +11,15 @@
#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
//===----------------------------------------------------------------------===//

View 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;
}
}

View 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) {

View 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
//===----------------------------------------------------------------------===//