//
// 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.
//
//===----------------------------------------------------------------------===//
//
#ifndef LLVM_SUPPORT_OUTPUTBUFFER_H
#define LLVM_SUPPORT_OUTPUTBUFFER_H
+#include <string>
#include <vector>
namespace llvm {
/// machine directly, indicating what header values and flags to set.
bool is64Bit, isLittleEndian;
public:
- OutputBuffer(const TargetMachine& TM,
- std::vector<unsigned char> &Out) : Output(Out) {
- is64Bit = TM.getTargetData()->getPointerSizeInBits() == 64;
- isLittleEndian = TM.getTargetData()->isLittleEndian();
- }
+ OutputBuffer(std::vector<unsigned char> &Out,
+ bool is64bit, bool le)
+ : Output(Out), is64Bit(is64bit), isLittleEndian(le) {}
// align - Emit padding into the file until the current output position is
// aligned to the specified power of two boundary.
void align(unsigned Boundary) {
assert(Boundary && (Boundary & (Boundary - 1)) == 0 &&
- "Must alitypedef std::vector<unsigned char> DataBuffer;gn to 2^k boundary");
+ "Must align to 2^k boundary");
size_t Size = Output.size();
if (Size & (Boundary - 1)) {
else
outxword(X);
}
- void outstring(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;
+ void outstring(const std::string &S, unsigned Length) {
+ unsigned len_to_copy = static_cast<unsigned>(S.length()) < Length
+ ? static_cast<unsigned>(S.length()) : Length;
+ unsigned len_to_fill = static_cast<unsigned>(S.length()) < Length
+ ? Length - static_cast<unsigned>(S.length()) : 0;
for (unsigned i = 0; i < len_to_copy; ++i)
outbyte(S[i]);
else
assert(0 && "Emission of 64-bit data not implemented yet!");
}
+
+ unsigned char &operator[](unsigned Index) {
+ return Output[Index];
+ }
+ const unsigned char &operator[](unsigned Index) const {
+ return Output[Index];
+ }
};
} // end llvm namespace