Fold the useful features of alist and alist_node into ilist, and
[oota-llvm.git] / include / llvm / Support / OutputBuffer.h
index 24a655cef6c16352b6d65a8a1537753f454fddd2..0fedb15e40507a64faf9edef7d9fbc2f832488bf 100644 (file)
@@ -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,6 +14,7 @@
 #ifndef LLVM_SUPPORT_OUTPUTBUFFER_H
 #define LLVM_SUPPORT_OUTPUTBUFFER_H
 
+#include <string>
 #include <vector>
 
 namespace llvm {
@@ -26,17 +27,15 @@ 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)) {
@@ -107,9 +106,11 @@ namespace llvm {
       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]);
@@ -139,6 +140,13 @@ namespace llvm {
       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