eliminate some extraneous methods in SDNode
[oota-llvm.git] / include / llvm / CodeGen / MachOWriter.h
index dd98b950d5b359bfca2c3fe1c95aac4171e51ed8..bff94b4b2f4848d6c5772c2f5f0e000e01941506 100644 (file)
@@ -14,6 +14,7 @@
 #ifndef LLVM_CODEGEN_MACHOWRITER_H
 #define LLVM_CODEGEN_MACHOWRITER_H
 
+#include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
 #include "llvm/CodeGen/MachineRelocation.h"
@@ -26,6 +27,7 @@ namespace llvm {
   class Mangler;
   class MachineCodeEmitter;
   class MachOCodeEmitter;
+  class OutputBuffer;
 
   /// MachOSym - This struct contains information about each symbol that is
   /// added to logical symbol table for the module.  This is eventually
@@ -85,11 +87,13 @@ namespace llvm {
     MachineCodeEmitter &getMachineCodeEmitter() const {
       return *(MachineCodeEmitter*)MCE;
     }
+    virtual ~MachOWriter();
 
-    ~MachOWriter();
+    virtual const char *getPassName() const {
+      return "Mach-O Writer";
+    }
 
     typedef std::vector<unsigned char> DataBuffer;
-
   protected:
     MachOWriter(std::ostream &O, TargetMachine &TM);
 
@@ -295,28 +299,6 @@ namespace llvm {
           initprot(VM_PROT_ALL), nsects(0), flags(0) { }
     };
 
-    /// MachORelocation - This struct contains information about each relocation
-    /// that needs to be emitted to the file.
-    /// see <mach-o/reloc.h>
-    struct MachORelocation {
-      uint32_t r_address;   // offset in the section to what is being  relocated
-      uint32_t r_symbolnum; // symbol index if r_extern == 1 else section index
-      bool     r_pcrel;     // was relocated pc-relative already
-      uint8_t  r_length;    // length = 2 ^ r_length
-      bool     r_extern;    // 
-      uint8_t  r_type;      // if not 0, machine-specific relocation type.
-      
-      uint32_t getPackedFields() { 
-        return (r_symbolnum << 8) | (r_pcrel << 7) | ((r_length & 3) << 5) |
-               (r_extern << 4) | (r_type & 15);
-      }
-      
-      MachORelocation(uint32_t addr, uint32_t index, bool pcrel, uint8_t len,
-                      bool ext, uint8_t type) : r_address(addr),
-        r_symbolnum(index), r_pcrel(pcrel), r_length(len), r_extern(ext),
-        r_type(type) {}
-    };
-
     /// MachOSection - This struct contains information about each section in a 
     /// particular segment that is emitted to the file.  This is eventually
     /// turned into the SectionCommand in the load command for a particlar
@@ -475,8 +457,13 @@ namespace llvm {
     MachOSection *getDataSection() {
       return getSection("__DATA", "__data");
     }
-    MachOSection *getConstSection(const Type *Ty) {
-      // FIXME: support cstring literals and pointer literal
+    MachOSection *getConstSection(Constant *C) {
+      const ConstantArray *CVA = dyn_cast<ConstantArray>(C);
+      if (CVA && CVA->isCString())
+        return getSection("__TEXT", "__cstring", 
+                          MachOSection::S_CSTRING_LITERALS);
+      
+      const Type *Ty = C->getType();
       if (Ty->isPrimitiveType() || Ty->isInteger()) {
         unsigned Size = TM.getTargetData()->getTypeSize(Ty);
         switch(Size) {
@@ -618,8 +605,19 @@ namespace llvm {
                                       MachineBasicBlock *MBB) const {
       return TM.getMachOWriterInfo()->GetJTRelocation(Offset, MBB);
     }
-    virtual void GetTargetRelocation(MachineRelocation &MR, MachOSection &From,
-                                     MachOSection &To) = 0;
+
+    /// GetTargetRelocation - Returns the number of relocations.
+    unsigned GetTargetRelocation(MachineRelocation &MR,
+                                 unsigned FromIdx,
+                                 unsigned ToAddr,
+                                 unsigned ToIndex,
+                                 OutputBuffer &RelocOut,
+                                 OutputBuffer &SecOut,
+                                 bool Scattered) {
+      return TM.getMachOWriterInfo()->GetTargetRelocation(MR, FromIdx, ToAddr,
+                                                          ToIndex, RelocOut,
+                                                          SecOut, Scattered);
+    }
   };
 }