1 //===-- llvm/CodeGen/AsmStream.cpp - AsmStream Framework --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains instantiations of "standard" AsmOStreams.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/FormattedStream.h"
17 /// ComputeColumn - Examine the current output and figure out which
18 /// column we end up in after output.
20 void formatted_raw_ostream::ComputeColumn(const char *Ptr, unsigned Size)
22 // Keep track of the current column by scanning the string for
25 // Find the last newline. This is our column start. If there
26 // is no newline, start with the current column.
27 const char *nlpos = NULL;
28 for (const char *pos = Ptr + Size, *epos = Ptr; pos > epos; --pos) {
29 if (*(pos-1) == '\n') {
31 // The newline will be counted, setting this to zero. We
32 // need to do it this way in case nlpos is Ptr.
42 // Walk through looking for tabs and advance column as appropriate
43 for (const char *pos = nlpos, *epos = Ptr + Size; pos != epos; ++pos) {
46 // Advance to next tab stop (every eight characters)
47 Column += ((8 - (Column & 0x7)) & 0x7);
48 assert(!(Column & 0x3) && "Column out of alignment");
53 /// PadToColumn - Align the output to some column number
55 /// \param NewCol - The column to move to
56 /// \param MinPad - The minimum space to give after the most recent
57 /// I/O, even if the current column + minpad > newcol
59 void formatted_raw_ostream::PadToColumn(unsigned NewCol, unsigned MinPad)
63 // Output spaces until we reach the desired column
64 unsigned num = NewCol - Column;
65 if (NewCol < Column || num < MinPad) {
69 // TODO: Write a whole string at a time