zpu: wip - add pass to convert registers to stack slots
[llvm/zpu.git] / lib / Support / Twine.cpp
blobb3ea0132e4aceb0454a5c4bb8c19443068a5dcc7
1 //===-- Twine.cpp - Fast Temporary String Concatenation -------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/ADT/Twine.h"
11 #include "llvm/ADT/SmallString.h"
12 #include "llvm/Support/Debug.h"
13 #include "llvm/Support/raw_ostream.h"
14 using namespace llvm;
16 std::string Twine::str() const {
17 SmallString<256> Vec;
18 return toStringRef(Vec).str();
21 void Twine::toVector(SmallVectorImpl<char> &Out) const {
22 raw_svector_ostream OS(Out);
23 print(OS);
26 StringRef Twine::toStringRef(SmallVectorImpl<char> &Out) const {
27 if (isSingleStringRef())
28 return getSingleStringRef();
29 toVector(Out);
30 return StringRef(Out.data(), Out.size());
33 void Twine::printOneChild(raw_ostream &OS, const void *Ptr,
34 NodeKind Kind) const {
35 switch (Kind) {
36 case Twine::NullKind: break;
37 case Twine::EmptyKind: break;
38 case Twine::TwineKind:
39 static_cast<const Twine*>(Ptr)->print(OS);
40 break;
41 case Twine::CStringKind:
42 OS << static_cast<const char*>(Ptr);
43 break;
44 case Twine::StdStringKind:
45 OS << *static_cast<const std::string*>(Ptr);
46 break;
47 case Twine::StringRefKind:
48 OS << *static_cast<const StringRef*>(Ptr);
49 break;
50 case Twine::DecUIKind:
51 OS << (unsigned)(uintptr_t)Ptr;
52 break;
53 case Twine::DecIKind:
54 OS << (int)(intptr_t)Ptr;
55 break;
56 case Twine::DecULKind:
57 OS << *static_cast<const unsigned long*>(Ptr);
58 break;
59 case Twine::DecLKind:
60 OS << *static_cast<const long*>(Ptr);
61 break;
62 case Twine::DecULLKind:
63 OS << *static_cast<const unsigned long long*>(Ptr);
64 break;
65 case Twine::DecLLKind:
66 OS << *static_cast<const long long*>(Ptr);
67 break;
68 case Twine::UHexKind:
69 OS.write_hex(*static_cast<const uint64_t*>(Ptr));
70 break;
74 void Twine::printOneChildRepr(raw_ostream &OS, const void *Ptr,
75 NodeKind Kind) const {
76 switch (Kind) {
77 case Twine::NullKind:
78 OS << "null"; break;
79 case Twine::EmptyKind:
80 OS << "empty"; break;
81 case Twine::TwineKind:
82 OS << "rope:";
83 static_cast<const Twine*>(Ptr)->printRepr(OS);
84 break;
85 case Twine::CStringKind:
86 OS << "cstring:\""
87 << static_cast<const char*>(Ptr) << "\"";
88 break;
89 case Twine::StdStringKind:
90 OS << "std::string:\""
91 << static_cast<const std::string*>(Ptr) << "\"";
92 break;
93 case Twine::StringRefKind:
94 OS << "stringref:\""
95 << static_cast<const StringRef*>(Ptr) << "\"";
96 break;
97 case Twine::DecUIKind:
98 OS << "decUI:\"" << (unsigned)(uintptr_t)Ptr << "\"";
99 break;
100 case Twine::DecIKind:
101 OS << "decI:\"" << (int)(intptr_t)Ptr << "\"";
102 break;
103 case Twine::DecULKind:
104 OS << "decUL:\"" << *static_cast<const unsigned long*>(Ptr) << "\"";
105 break;
106 case Twine::DecLKind:
107 OS << "decL:\"" << *static_cast<const long*>(Ptr) << "\"";
108 break;
109 case Twine::DecULLKind:
110 OS << "decULL:\"" << *static_cast<const unsigned long long*>(Ptr) << "\"";
111 break;
112 case Twine::DecLLKind:
113 OS << "decLL:\"" << *static_cast<const long long*>(Ptr) << "\"";
114 break;
115 case Twine::UHexKind:
116 OS << "uhex:\"" << static_cast<const uint64_t*>(Ptr) << "\"";
117 break;
121 void Twine::print(raw_ostream &OS) const {
122 printOneChild(OS, LHS, getLHSKind());
123 printOneChild(OS, RHS, getRHSKind());
126 void Twine::printRepr(raw_ostream &OS) const {
127 OS << "(Twine ";
128 printOneChildRepr(OS, LHS, getLHSKind());
129 OS << " ";
130 printOneChildRepr(OS, RHS, getRHSKind());
131 OS << ")";
134 void Twine::dump() const {
135 print(llvm::dbgs());
138 void Twine::dumpRepr() const {
139 printRepr(llvm::dbgs());