From 9132a2b81842b0e2b77703fab3e6fe7467f859bb Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 23 Aug 2007 05:15:32 +0000 Subject: [PATCH] rename APInt::toString -> toStringUnsigned for symmetry with toStringSigned() Add an APSInt::toString() method. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@41309 91177308-0d34-0410-b5e6-96231b3b80d8 --- examples/Fibonacci/fibonacci.cpp | 2 +- examples/HowToUseJIT/HowToUseJIT.cpp | 2 +- include/llvm/ADT/APInt.h | 2 +- include/llvm/ADT/APSInt.h | 6 ++++++ lib/ExecutionEngine/Interpreter/Execution.cpp | 5 +++-- lib/Support/APInt.cpp | 4 ++-- lib/Transforms/IPO/ArgumentPromotion.cpp | 2 +- 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/examples/Fibonacci/fibonacci.cpp b/examples/Fibonacci/fibonacci.cpp index cd35417fb3e..d0ffb9ac53d 100644 --- a/examples/Fibonacci/fibonacci.cpp +++ b/examples/Fibonacci/fibonacci.cpp @@ -116,6 +116,6 @@ int main(int argc, char **argv) { GenericValue GV = EE->runFunction(FibF, Args); // import result of execution - std::cout << "Result: " << GV.IntVal.toString(10) << "\n"; + std::cout << "Result: " << GV.IntVal.toStringUnsigned(10) << "\n"; return 0; } diff --git a/examples/HowToUseJIT/HowToUseJIT.cpp b/examples/HowToUseJIT/HowToUseJIT.cpp index 621621dc46d..a4f6f3748e3 100644 --- a/examples/HowToUseJIT/HowToUseJIT.cpp +++ b/examples/HowToUseJIT/HowToUseJIT.cpp @@ -107,6 +107,6 @@ int main() { GenericValue gv = EE->runFunction(FooF, noargs); // Import result of execution: - std::cout << "Result: " << gv.IntVal.toString(10) << "\n"; + std::cout << "Result: " << gv.IntVal.toStringUnsigned(10) << "\n"; return 0; } diff --git a/include/llvm/ADT/APInt.h b/include/llvm/ADT/APInt.h index 971822f1bd4..0102d67e07e 100644 --- a/include/llvm/ADT/APInt.h +++ b/include/llvm/ADT/APInt.h @@ -932,7 +932,7 @@ public: /// radix given. The radix can be 2, 8, 10 or 16. /// @returns a character interpretation of the APInt /// @brief Convert unsigned APInt to string representation. - inline std::string toString(uint8_t radix = 10) const { + inline std::string toStringUnsigned(uint8_t radix = 10) const { return toString(radix, false); } diff --git a/include/llvm/ADT/APSInt.h b/include/llvm/ADT/APSInt.h index 7e515da704b..91dd709000c 100644 --- a/include/llvm/ADT/APSInt.h +++ b/include/llvm/ADT/APSInt.h @@ -52,6 +52,12 @@ public: void setIsUnsigned(bool Val) { IsUnsigned = Val; } void setIsSigned(bool Val) { IsUnsigned = !Val; } + /// This is used internally to convert an APInt to a string. + /// @brief Converts an APInt to a std::string + std::string toString(uint8_t Radix) const { + return toString(Radix, isSigned()); + } + const APSInt &operator%=(const APSInt &RHS) { assert(IsUnsigned == RHS.IsUnsigned && "Signedness mismatch!"); diff --git a/lib/ExecutionEngine/Interpreter/Execution.cpp b/lib/ExecutionEngine/Interpreter/Execution.cpp index 281f774193f..53df5443659 100644 --- a/lib/ExecutionEngine/Interpreter/Execution.cpp +++ b/lib/ExecutionEngine/Interpreter/Execution.cpp @@ -1346,8 +1346,9 @@ static void PrintGenericValue(const GenericValue &Val, const Type* Ty) { case Type::DoubleTyID: DOUT << "double " << Val.DoubleVal; break; case Type::PointerTyID: DOUT << "void* " << intptr_t(Val.PointerVal); break; case Type::IntegerTyID: - DOUT << "i" << Val.IntVal.getBitWidth() << " " << Val.IntVal.toString(10) - << " (0x" << Val.IntVal.toString(16) << ")\n"; + DOUT << "i" << Val.IntVal.getBitWidth() << " " + << Val.IntVal.toStringUnsigned(10) + << " (0x" << Val.IntVal.toStringUnsigned(16) << ")\n"; break; } } diff --git a/lib/Support/APInt.cpp b/lib/Support/APInt.cpp index 173f28c8d19..277a0b0c113 100644 --- a/lib/Support/APInt.cpp +++ b/lib/Support/APInt.cpp @@ -2008,8 +2008,8 @@ void APInt::dump() const else for (unsigned i = getNumWords(); i > 0; i--) { cerr << pVal[i-1] << " "; } - cerr << " U(" << this->toString(10) << ") S(" << this->toStringSigned(10) - << ")\n" << std::setbase(10); + cerr << " U(" << this->toStringUnsigned(10) << ") S(" + << this->toStringSigned(10) << ")\n" << std::setbase(10); } #endif diff --git a/lib/Transforms/IPO/ArgumentPromotion.cpp b/lib/Transforms/IPO/ArgumentPromotion.cpp index 78703a40b74..d40df48b29a 100644 --- a/lib/Transforms/IPO/ArgumentPromotion.cpp +++ b/lib/Transforms/IPO/ArgumentPromotion.cpp @@ -519,7 +519,7 @@ Function *ArgPromotion::DoPromotion(Function *F, std::string NewName = I->getName(); for (unsigned i = 0, e = Operands.size(); i != e; ++i) if (ConstantInt *CI = dyn_cast(Operands[i])) - NewName += "." + CI->getValue().toString(10); + NewName += "." + CI->getValue().toStringUnsigned(10); else NewName += ".x"; TheArg->setName(NewName+".val"); -- 2.34.1