summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorPeter Collingbourne <peter@pcc.me.uk>2018-05-17 22:11:43 +0000
committerPeter Collingbourne <peter@pcc.me.uk>2018-05-17 22:11:43 +0000
commit070777dbdd3995137316252005020d68e0e1dcd9 (patch)
treeb934bad5d490fb2f1f05380bf7b7f0c8c72b5cd6 /llvm/lib
parentc6526176cf7c3678f9d7c96338f63365c4d5f8ab (diff)
downloadbcm5719-llvm-070777dbdd3995137316252005020d68e0e1dcd9.tar.gz
bcm5719-llvm-070777dbdd3995137316252005020d68e0e1dcd9.zip
Support: Add a raw_ostream::write_zeros() function. NFCI.
This will eventually replace MCObjectWriter::WriteZeros. Part of PR37466. Differential Revision: https://reviews.llvm.org/D47033 llvm-svn: 332675
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Support/raw_ostream.cpp40
1 files changed, 26 insertions, 14 deletions
diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp
index 68f2f7ac714..a4ab75c2735 100644
--- a/llvm/lib/Support/raw_ostream.cpp
+++ b/llvm/lib/Support/raw_ostream.cpp
@@ -455,23 +455,35 @@ raw_ostream &raw_ostream::operator<<(const FormattedBytes &FB) {
return *this;
}
-/// indent - Insert 'NumSpaces' spaces.
-raw_ostream &raw_ostream::indent(unsigned NumSpaces) {
- static const char Spaces[] = " "
- " "
- " ";
+template <char C>
+static raw_ostream &write_padding(raw_ostream &OS, unsigned NumChars) {
+ static const char Chars[] = {C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C,
+ C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C,
+ C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C,
+ C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C,
+ C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C};
// Usually the indentation is small, handle it with a fastpath.
- if (NumSpaces < array_lengthof(Spaces))
- return write(Spaces, NumSpaces);
-
- while (NumSpaces) {
- unsigned NumToWrite = std::min(NumSpaces,
- (unsigned)array_lengthof(Spaces)-1);
- write(Spaces, NumToWrite);
- NumSpaces -= NumToWrite;
+ if (NumChars < array_lengthof(Chars))
+ return OS.write(Chars, NumChars);
+
+ while (NumChars) {
+ unsigned NumToWrite = std::min(NumChars,
+ (unsigned)array_lengthof(Chars)-1);
+ OS.write(Chars, NumToWrite);
+ NumChars -= NumToWrite;
}
- return *this;
+ return OS;
+}
+
+/// indent - Insert 'NumSpaces' spaces.
+raw_ostream &raw_ostream::indent(unsigned NumSpaces) {
+ return write_padding<' '>(*this, NumSpaces);
+}
+
+/// write_zeros - Insert 'NumZeros' nulls.
+raw_ostream &raw_ostream::write_zeros(unsigned NumZeros) {
+ return write_padding<'\0'>(*this, NumZeros);
}
void raw_ostream::anchor() {}
OpenPOWER on IntegriCloud