X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FOutputBuffer.h;h=6b98e99e28e06face9cbef5997206ee4d9e5a5a5;hb=b09c146b116359616f6cbd4c8b3328607e00ff42;hp=73a4a631debd11be328ac539bcf8448f561aed21;hpb=c904a5b925ce9981ad7501b14ee39cbc8795e23c;p=oota-llvm.git diff --git a/include/llvm/Support/OutputBuffer.h b/include/llvm/Support/OutputBuffer.h index 73a4a631deb..6b98e99e28e 100644 --- a/include/llvm/Support/OutputBuffer.h +++ b/include/llvm/Support/OutputBuffer.h @@ -2,8 +2,8 @@ // // The LLVM Compiler Infrastructure // -// This file was developed by Bill Wendling and is distributed under the -// University of Illinois Open Source License. See LICENSE.TXT for details. +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// // @@ -14,11 +14,12 @@ #ifndef LLVM_SUPPORT_OUTPUTBUFFER_H #define LLVM_SUPPORT_OUTPUTBUFFER_H +#include #include #include namespace llvm { - + class OutputBuffer { /// Output buffer. std::vector &Output; @@ -35,9 +36,9 @@ namespace llvm { // aligned to the specified power of two boundary. void align(unsigned Boundary) { assert(Boundary && (Boundary & (Boundary - 1)) == 0 && - "Must alitypedef std::vector DataBuffer;gn to 2^k boundary"); + "Must align to 2^k boundary"); size_t Size = Output.size(); - + if (Size & (Boundary - 1)) { // Add padding to get alignment to the correct place. size_t Pad = Boundary - (Size & (Boundary - 1)); @@ -107,12 +108,14 @@ namespace llvm { outxword(X); } void outstring(const std::string &S, unsigned Length) { - unsigned len_to_copy = S.length() < Length ? S.length() : Length; - unsigned len_to_fill = S.length() < Length ? Length - S.length() : 0; - + unsigned len_to_copy = static_cast(S.length()) < Length + ? static_cast(S.length()) : Length; + unsigned len_to_fill = static_cast(S.length()) < Length + ? Length - static_cast(S.length()) : 0; + for (unsigned i = 0; i < len_to_copy; ++i) outbyte(S[i]); - + for (unsigned i = 0; i < len_to_fill; ++i) outbyte(0); } @@ -132,14 +135,32 @@ namespace llvm { P[2] = (X >> (isLittleEndian ? 16 : 8)) & 255; P[3] = (X >> (isLittleEndian ? 24 : 0)) & 255; } + void fixxword(uint64_t X, unsigned Offset) { + unsigned char *P = &Output[Offset]; + P[0] = (X >> (isLittleEndian ? 0 : 56)) & 255; + P[1] = (X >> (isLittleEndian ? 8 : 48)) & 255; + P[2] = (X >> (isLittleEndian ? 16 : 40)) & 255; + P[3] = (X >> (isLittleEndian ? 24 : 32)) & 255; + P[4] = (X >> (isLittleEndian ? 32 : 24)) & 255; + P[5] = (X >> (isLittleEndian ? 40 : 16)) & 255; + P[6] = (X >> (isLittleEndian ? 48 : 8)) & 255; + P[7] = (X >> (isLittleEndian ? 56 : 0)) & 255; + } void fixaddr(uint64_t X, unsigned Offset) { if (!is64Bit) fixword((unsigned)X, Offset); else - assert(0 && "Emission of 64-bit data not implemented yet!"); + fixxword(X, Offset); + } + + unsigned char &operator[](unsigned Index) { + return Output[Index]; + } + const unsigned char &operator[](unsigned Index) const { + return Output[Index]; } }; - + } // end llvm namespace #endif // LLVM_SUPPORT_OUTPUTBUFFER_H