1/* 2 * Copyright 2011, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#include "raw_ostream.h" 18 19#include <llvm/Support/raw_ostream.h> 20#include <llvm/Support/Format.h> 21#include <cstdarg> 22#include <cstring> 23 24llvm::raw_ostream &out() { 25 static llvm::raw_ostream &singleton = llvm::outs(); 26 return singleton; 27} 28 29MyFormat const fillformat(char const fill_char, // Fill character. 30 int const length, // Fill Width. 31 char const *format_s, // Format string. 32 ...) { // Format variable. 33 using namespace std; 34 struct MyFormat t_format; 35 va_list valist; 36 va_start(valist, format_s); 37 t_format.ptr = new char[length+1]; 38 t_format.ptr[length] = '\0'; 39 vsnprintf(t_format.ptr, length, format_s, valist); 40 int real_len = strlen(t_format.ptr); 41 int fill_len = length; 42 memmove(t_format.ptr + fill_len, t_format.ptr, real_len); 43 memset(t_format.ptr, fill_char, fill_len); 44 return t_format; 45} 46 47llvm::raw_ostream &operator<<(llvm::raw_ostream &os, MyFormat const &mf) { 48 os << mf.ptr; 49 delete mf.ptr; 50 return os; 51} 52