* Removed `using' declaration, now use full namespace qualifier std::string

* Simplified code by using an inline function instead of copy-pasted code


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7597 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Misha Brukman 2003-08-05 16:01:50 +00:00
parent 47ae4a1cee
commit f4de783582

View File

@ -11,7 +11,6 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "SparcInternals.h"
#include "llvm/CodeGen/MachineInstr.h" #include "llvm/CodeGen/MachineInstr.h"
#include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunction.h"
#include "llvm/CodeGen/MachineFunctionInfo.h" #include "llvm/CodeGen/MachineFunctionInfo.h"
@ -22,7 +21,8 @@
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/Assembly/Writer.h" #include "llvm/Assembly/Writer.h"
#include "Support/StringExtras.h" #include "Support/StringExtras.h"
using std::string; #include "SparcInternals.h"
#include <string>
namespace { namespace {
@ -108,8 +108,8 @@ public:
toAsm << "\n"; toAsm << "\n";
} }
static string getValidSymbolName(const string &S) { static std::string getValidSymbolName(const std::string &S) {
string Result; std::string Result;
// Symbol names in Sparc assembly language have these rules: // Symbol names in Sparc assembly language have these rules:
// (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }* // (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }*
@ -138,10 +138,10 @@ public:
// use a numbered value based on prefix otherwise. // use a numbered value based on prefix otherwise.
// FPrefix is always prepended to the output identifier. // FPrefix is always prepended to the output identifier.
// //
string getID(const Value *V, const char *Prefix, const char *FPrefix = 0) { std::string getID(const Value *V, const char *Prefix, const char *FPrefix = 0) {
string Result = FPrefix ? FPrefix : ""; // "Forced prefix" std::string Result = FPrefix ? FPrefix : ""; // "Forced prefix"
Result += V->hasName() ? V->getName() : string(Prefix); Result += V->hasName() ? V->getName() : std::string(Prefix);
// Qualify all internal names with a unique id. // Qualify all internal names with a unique id.
if (!isExternal(V)) { if (!isExternal(V)) {
@ -163,19 +163,19 @@ public:
} }
// getID Wrappers - Ensure consistent usage... // getID Wrappers - Ensure consistent usage...
string getID(const Function *F) { std::string getID(const Function *F) {
return getID(F, "LLVMFunction_"); return getID(F, "LLVMFunction_");
} }
string getID(const BasicBlock *BB) { std::string getID(const BasicBlock *BB) {
return getID(BB, "LL", (".L_"+getID(BB->getParent())+"_").c_str()); return getID(BB, "LL", (".L_"+getID(BB->getParent())+"_").c_str());
} }
string getID(const GlobalVariable *GV) { std::string getID(const GlobalVariable *GV) {
return getID(GV, "LLVMGlobal_"); return getID(GV, "LLVMGlobal_");
} }
string getID(const Constant *CV) { std::string getID(const Constant *CV) {
return getID(CV, "LLVMConst_", ".C_"); return getID(CV, "LLVMConst_", ".C_");
} }
string getID(const GlobalValue *GV) { std::string getID(const GlobalValue *GV) {
if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV)) if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV))
return getID(V); return getID(V);
else if (const Function *F = dyn_cast<Function>(GV)) else if (const Function *F = dyn_cast<Function>(GV))
@ -184,17 +184,25 @@ public:
return ""; return "";
} }
// Combines expressions
inline std::string ConstantArithExprToString(const ConstantExpr* CE,
const TargetMachine &TM,
const std::string &op) {
return "(" + valToExprString(CE->getOperand(0), TM) + op
+ valToExprString(CE->getOperand(1), TM) + ")";
}
// ConstantExprToString() - Convert a ConstantExpr to an asm expression // ConstantExprToString() - Convert a ConstantExpr to an asm expression
// and return this as a string. // and return this as a string.
string ConstantExprToString(const ConstantExpr* CE, std::string ConstantExprToString(const ConstantExpr* CE,
const TargetMachine& target) { const TargetMachine& target) {
string S; std::string S;
switch(CE->getOpcode()) { switch(CE->getOpcode()) {
case Instruction::GetElementPtr: case Instruction::GetElementPtr:
{ // generate a symbolic expression for the byte address { // generate a symbolic expression for the byte address
const Value* ptrVal = CE->getOperand(0); const Value* ptrVal = CE->getOperand(0);
std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end()); std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
const TargetData &TD = target.getTargetData(); const TargetData &TD = target.getTargetData();
S += "(" + valToExprString(ptrVal, target) + ") + (" S += "(" + valToExprString(ptrVal, target) + ") + ("
+ utostr(TD.getIndexedOffset(ptrVal->getType(),idxVec)) + ")"; + utostr(TD.getIndexedOffset(ptrVal->getType(),idxVec)) + ")";
break; break;
@ -209,48 +217,40 @@ public:
break; break;
case Instruction::Add: case Instruction::Add:
S += "(" + valToExprString(CE->getOperand(0), target) + ") + (" S += ConstantArithExprToString(CE, target, ") + (");
+ valToExprString(CE->getOperand(1), target) + ")";
break; break;
case Instruction::Sub: case Instruction::Sub:
S += "(" + valToExprString(CE->getOperand(0), target) + ") - (" S += ConstantArithExprToString(CE, target, ") - (");
+ valToExprString(CE->getOperand(1), target) + ")";
break; break;
case Instruction::Mul: case Instruction::Mul:
S += "(" + valToExprString(CE->getOperand(0), target) + ") * (" S += ConstantArithExprToString(CE, target, ") * (");
+ valToExprString(CE->getOperand(1), target) + ")";
break; break;
case Instruction::Div: case Instruction::Div:
S += "(" + valToExprString(CE->getOperand(0), target) + ") / (" S += ConstantArithExprToString(CE, target, ") / (");
+ valToExprString(CE->getOperand(1), target) + ")";
break; break;
case Instruction::Rem: case Instruction::Rem:
S += "(" + valToExprString(CE->getOperand(0), target) + ") % (" S += ConstantArithExprToString(CE, target, ") % (");
+ valToExprString(CE->getOperand(1), target) + ")";
break; break;
case Instruction::And: case Instruction::And:
// Logical && for booleans; bitwise & otherwise // Logical && for booleans; bitwise & otherwise
S += "(" + valToExprString(CE->getOperand(0), target) S += ConstantArithExprToString(CE, target,
+ ((CE->getType() == Type::BoolTy)? ") && (" : ") & (") ((CE->getType() == Type::BoolTy)? ") && (" : ") & ("));
+ valToExprString(CE->getOperand(1), target) + ")";
break; break;
case Instruction::Or: case Instruction::Or:
// Logical || for booleans; bitwise | otherwise // Logical || for booleans; bitwise | otherwise
S += "(" + valToExprString(CE->getOperand(0), target) S += ConstantArithExprToString(CE, target,
+ ((CE->getType() == Type::BoolTy)? ") || (" : ") | (") ((CE->getType() == Type::BoolTy)? ") || (" : ") | ("));
+ valToExprString(CE->getOperand(1), target) + ")";
break; break;
case Instruction::Xor: case Instruction::Xor:
// Bitwise ^ for all types // Bitwise ^ for all types
S += "(" + valToExprString(CE->getOperand(0), target) + ") ^ (" S += ConstantArithExprToString(CE, target, ") ^ (");
+ valToExprString(CE->getOperand(1), target) + ")";
break; break;
default: default:
@ -264,13 +264,13 @@ public:
// valToExprString - Helper function for ConstantExprToString(). // valToExprString - Helper function for ConstantExprToString().
// Appends result to argument string S. // Appends result to argument string S.
// //
string valToExprString(const Value* V, const TargetMachine& target) { std::string valToExprString(const Value* V, const TargetMachine& target) {
string S; std::string S;
bool failed = false; bool failed = false;
if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known
if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV))
S += string(CB == ConstantBool::True ? "1" : "0"); S += std::string(CB == ConstantBool::True ? "1" : "0");
else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV)) else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
S += itostr(CI->getValue()); S += itostr(CI->getValue());
else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV)) else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
@ -525,7 +525,7 @@ SparcFunctionAsmPrinter::emitBasicBlock(const MachineBasicBlock &MBB)
void void
SparcFunctionAsmPrinter::emitFunction(const Function &F) SparcFunctionAsmPrinter::emitFunction(const Function &F)
{ {
string methName = getID(&F); std::string methName = getID(&F);
toAsm << "!****** Outputing Function: " << methName << " ******\n"; toAsm << "!****** Outputing Function: " << methName << " ******\n";
enterSection(AsmPrinter::Text); enterSection(AsmPrinter::Text);
toAsm << "\t.align\t4\n\t.global\t" << methName << "\n"; toAsm << "\t.align\t4\n\t.global\t" << methName << "\n";
@ -588,7 +588,7 @@ private:
void PrintZeroBytesToPad (int numBytes); void PrintZeroBytesToPad (int numBytes);
void printSingleConstantValue (const Constant* CV); void printSingleConstantValue (const Constant* CV);
void printConstantValueOnly (const Constant* CV, int numPadBytesAfter = 0); void printConstantValueOnly (const Constant* CV, int numPadBytesAfter = 0);
void printConstant (const Constant* CV, string valID = ""); void printConstant (const Constant* CV, std::string valID = "");
static void FoldConstants (const Module &M, static void FoldConstants (const Module &M,
hash_set<const Constant*> &moduleConstants); hash_set<const Constant*> &moduleConstants);
@ -618,10 +618,10 @@ static inline char toOctal(int X) {
// getAsCString - Return the specified array as a C compatible string, only if // getAsCString - Return the specified array as a C compatible string, only if
// the predicate isStringCompatible is true. // the predicate isStringCompatible is true.
// //
static string getAsCString(const ConstantArray *CVA) { static std::string getAsCString(const ConstantArray *CVA) {
assert(isStringCompatible(CVA) && "Array is not string compatible!"); assert(isStringCompatible(CVA) && "Array is not string compatible!");
string Result; std::string Result;
const Type *ETy = cast<ArrayType>(CVA->getType())->getElementType(); const Type *ETy = cast<ArrayType>(CVA->getType())->getElementType();
Result = "\""; Result = "\"";
for (unsigned i = 0; i < CVA->getNumOperands(); ++i) { for (unsigned i = 0; i < CVA->getNumOperands(); ++i) {
@ -653,7 +653,7 @@ ArrayTypeIsString(const ArrayType* arrayType)
} }
inline const string inline const std::string
TypeToDataDirective(const Type* type) TypeToDataDirective(const Type* type)
{ {
switch(type->getPrimitiveID()) switch(type->getPrimitiveID())
@ -866,7 +866,7 @@ SparcModuleAsmPrinter::printConstantValueOnly(const Constant* CV,
// appropriate directives. Uses printConstantValueOnly() to print the // appropriate directives. Uses printConstantValueOnly() to print the
// value or values. // value or values.
void void
SparcModuleAsmPrinter::printConstant(const Constant* CV, string valID) SparcModuleAsmPrinter::printConstant(const Constant* CV, std::string valID)
{ {
if (valID.length() == 0) if (valID.length() == 0)
valID = getID(CV); valID = getID(CV);