Skip to content

Commit 23a11f9

Browse files
authored
Merge pull request #22 from compnerd/standard
Support: use C++11 `std::to_string` instead of pointerToString
2 parents fba8b17 + 35a799d commit 23a11f9

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

include/glow/Support/Support.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,6 @@ class TimerGuard {
2828
}
2929
};
3030

31-
/// Convert the ptr \p ptr into an ascii representation in the format
32-
/// "0xFFF...";
33-
std::string pointerToString(void *ptr);
34-
3531
/// \returns the escaped content of string \p str.
3632
/// The char '\n' becomes '\'+'n' and quotes are handled correctly.
3733
std::string escapeDottyString(const std::string &str);
@@ -72,4 +68,9 @@ class DescriptionBuilder {
7268

7369
} // namespace glow
7470

71+
namespace std {
72+
/// Convert the ptr \p ptr into an ascii representation in the format "0xFFF..."
73+
std::string to_string(void *ptr);
74+
}
75+
7576
#endif // GLOW_SUPPORT_SUPPORT_H

src/glow/IR/IR.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ static const char *getDottyArrowForCC(OperandKind k) {
258258

259259
/// Dump a dotty graph that depicts the module.
260260
void Module::dumpDAG() {
261-
std::string filename = "dotty_network_dump_" + pointerToString(this) + ".dot";
261+
std::string filename = "dotty_network_dump_" + std::to_string(this) + ".dot";
262262
std::cout << "Writing dotty graph to: " << filename << '\n';
263263

264264
std::string sb;
@@ -270,7 +270,7 @@ void Module::dumpDAG() {
270270
for (auto &I : instrs_) {
271271
std::string desc = getDottyDesc(I);
272272

273-
sb += quote(pointerToString(I)) + "[\n";
273+
sb += quote(std::to_string(I)) + "[\n";
274274
std::string repr = quote(desc);
275275
sb += "\tlabel = " + repr + "\n";
276276
sb += "\tshape = \"record\"\n";
@@ -282,7 +282,7 @@ void Module::dumpDAG() {
282282
sb += " style=invis;\n";
283283

284284
for (auto &v : weights_) {
285-
sb += quote(pointerToString(v)) + "[\n";
285+
sb += quote(std::to_string(v)) + "[\n";
286286
std::string desc = escapeDottyString(getDottyDesc(v));
287287
sb += "\tlabel = " + desc + "\n";
288288
sb += "\tshape = \"record\"\n";
@@ -298,8 +298,8 @@ void Module::dumpDAG() {
298298
for (auto &I : instrs_) {
299299
for (int i = 0, e = I->getNumOperands(); i < e; i++) {
300300
auto op = I->getOperand(i);
301-
std::string from = quote(pointerToString(I)) + ":f" + std::to_string(i);
302-
std::string to = quote(pointerToString(op.first));
301+
std::string from = quote(std::to_string(I)) + ":f" + std::to_string(i);
302+
std::string to = quote(std::to_string(op.first));
303303

304304
sb += from + "->" + to + "[dir=" + getDottyArrowForCC(op.second) + "];\n";
305305
}
@@ -309,8 +309,8 @@ void Module::dumpDAG() {
309309
Instruction *prev = nullptr;
310310
for (auto &I : instrs_) {
311311
if (prev) {
312-
std::string from = quote(pointerToString(prev));
313-
std::string to = quote(pointerToString(I));
312+
std::string from = quote(std::to_string(prev));
313+
std::string to = quote(std::to_string(I));
314314
sb += from + "->" + to + "[color=\"blue\"];\n";
315315
}
316316
prev = I;

src/glow/Support/Support.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@
66

77
using namespace glow;
88

9-
std::string glow::pointerToString(void *ptr) {
10-
std::ostringstream oss;
11-
oss << ptr;
12-
return oss.str();
13-
}
14-
159
std::string glow::escapeDottyString(const std::string &str) {
1610
std::string out;
1711
out += "\"";
@@ -66,3 +60,11 @@ DescriptionBuilder &DescriptionBuilder::addDim(const std::string &name,
6660
return *this;
6761
}
6862

63+
namespace std {
64+
std::string to_string(void *ptr) {
65+
std::ostringstream oss;
66+
oss << ptr;
67+
return oss.str();
68+
}
69+
}
70+

0 commit comments

Comments
 (0)