aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDaniel Dunbar <daniel@zuster.org>2009-07-29 07:08:44 +0000
committerDaniel Dunbar <daniel@zuster.org>2009-07-29 07:08:44 +0000
commitc5f961a953379306a2cff86e1bb1e399c72e2cd3 (patch)
tree377376c3b2be90bda1f666bec5aec817ffe5df1b /include
parent2ece02ff7eb63815c7700dac3fa66326f950f70c (diff)
downloadexternal_llvm-c5f961a953379306a2cff86e1bb1e399c72e2cd3.zip
external_llvm-c5f961a953379306a2cff86e1bb1e399c72e2cd3.tar.gz
external_llvm-c5f961a953379306a2cff86e1bb1e399c72e2cd3.tar.bz2
Twines: Support numeric conversion directly (uitostr, etc).
- Provides static constructors for doing number to string conversions without using temporaries. - There are several ways to do this, I think given the Twine constraints this is the simplest one. - One FIXME for fast number -> hex conversion. - Added another comment on one last major bit of perf work Twines need, which is to make raw_svector_ostream more efficient. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77445 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ADT/Twine.h53
1 files changed, 45 insertions, 8 deletions
diff --git a/include/llvm/ADT/Twine.h b/include/llvm/ADT/Twine.h
index 93ff52c..8518395 100644
--- a/include/llvm/ADT/Twine.h
+++ b/include/llvm/ADT/Twine.h
@@ -86,6 +86,9 @@ namespace llvm {
/// The empty string.
EmptyKind,
+ /// A pointer to a Twine instance.
+ TwineKind,
+
/// A pointer to a C string instance.
CStringKind,
@@ -95,8 +98,16 @@ namespace llvm {
/// A pointer to a StringRef instance.
StringRefKind,
- /// A pointer to a Twine instance.
- TwineKind
+ /// A pointer to a uint64_t value, to render as an unsigned decimal
+ /// integer.
+ UDecKind,
+
+ /// A pointer to a uint64_t value, to render as an unsigned hexadecimal
+ /// integer.
+ UHexKind,
+
+ /// A pointer to a uint64_t value, to render as a signed decimal integer.
+ SDecKind
};
private:
@@ -232,12 +243,6 @@ namespace llvm {
assert(isValid() && "Invalid twine!");
}
- /// Create a 'null' string, which is an empty string that always
- /// concatenates to form another empty string.
- static Twine createNull() {
- return Twine(NullKind);
- }
-
// FIXME: Unfortunately, to make sure this is as efficient as possible we
// need extra binary constructors from particular types. We can't rely on
// the compiler to be smart enough to fold operator+()/concat() down to the
@@ -255,6 +260,38 @@ namespace llvm {
assert(isValid() && "Invalid twine!");
}
+ /// Create a 'null' string, which is an empty string that always
+ /// concatenates to form another empty string.
+ static Twine createNull() {
+ return Twine(NullKind);
+ }
+
+ /// @}
+ /// @name Numeric Conversions
+ /// @{
+
+ /// Construct a twine to print \arg Val as an unsigned decimal integer.
+ static Twine utostr(const uint64_t &Val) {
+ return Twine(&Val, UDecKind, 0, EmptyKind);
+ }
+
+ /// Construct a twine to print \arg Val as a signed decimal integer.
+ static Twine itostr(const int64_t &Val) {
+ return Twine(&Val, SDecKind, 0, EmptyKind);
+ }
+
+ // Construct a twine to print \arg Val as an unsigned hexadecimal integer.
+ static Twine utohexstr(const uint64_t &Val) {
+ return Twine(&Val, UHexKind, 0, EmptyKind);
+ }
+
+ // Construct a twine to print \arg Val as an unsigned hexadecimal
+ // integer. This routine is provided as a convenience to sign extend values
+ // before printing.
+ static Twine itohexstr(const int64_t &Val) {
+ return Twine(&Val, UHexKind, 0, EmptyKind);
+ }
+
/// @}
/// @name String Operations
/// @{