github.com/llir/llvm@v0.3.6/ir/helper.txt (about)

     1  // --- [ Formatted I/O writer ] ------------------------------------------------
     2  
     3  // fmtWriter is a formatted I/O writer.
     4  //
     5  // A formatted I/O writer keeps track of the total number of bytes written to w
     6  // and the first non-nil error encountered.
     7  type fmtWriter struct {
     8  	// underlying io.Writer.
     9  	w io.Writer
    10  	// Number of bytes written to w.
    11  	size int
    12  	// First non-nil error encountered.
    13  	err error
    14  }
    15  
    16  // Fprint formats using the default formats for its operands and writes to w.
    17  // Spaces are added between operands when neither is a string. It returns the
    18  // number of bytes written and any write error encountered.
    19  func (fw *fmtWriter) Fprint(a ...interface{}) (n int, err error) {
    20  	if fw.err != nil {
    21  		return 0, nil
    22  	}
    23  	n, err = fmt.Fprint(fw.w, a...)
    24  	fw.size += n
    25  	fw.err = err
    26  	return n, err
    27  }
    28  
    29  // Fprintf formats according to a format specifier and writes to w. It returns
    30  // the number of bytes written and any write error encountered.
    31  func (fw *fmtWriter) Fprintf(format string, a ...interface{}) (n int, err error) {
    32  	if fw.err != nil {
    33  		return 0, nil
    34  	}
    35  	n, err = fmt.Fprintf(fw.w, format, a...)
    36  	fw.size += n
    37  	fw.err = err
    38  	return n, err
    39  }
    40  
    41  // Fprintln formats using the default formats for its operands and writes to w.
    42  // Spaces are always added between operands and a newline is appended. It
    43  // returns the number of bytes written and any write error encountered.
    44  func (fw *fmtWriter) Fprintln(a ...interface{}) (n int, err error) {
    45  	if fw.err != nil {
    46  		return 0, nil
    47  	}
    48  	n, err = fmt.Fprintln(fw.w, a...)
    49  	fw.size += n
    50  	fw.err = err
    51  	return n, err
    52  }