New "TargetMachOWriterInfo" class. It holds target-specific information
authorBill Wendling <isanbard@gmail.com>
Wed, 24 Jan 2007 03:36:05 +0000 (03:36 +0000)
committerBill Wendling <isanbard@gmail.com>
Wed, 24 Jan 2007 03:36:05 +0000 (03:36 +0000)
that the MachOWriter needs in order to do its writing stuff 'n things.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33475 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/TargetMachOWriterInfo.h [new file with mode: 0644]
lib/Target/PowerPC/PPCMachOWriterInfo.cpp [new file with mode: 0644]
lib/Target/PowerPC/PPCMachOWriterInfo.h [new file with mode: 0644]
lib/Target/TargetMachOWriterInfo.cpp [new file with mode: 0644]

diff --git a/include/llvm/Target/TargetMachOWriterInfo.h b/include/llvm/Target/TargetMachOWriterInfo.h
new file mode 100644 (file)
index 0000000..6276bcf
--- /dev/null
@@ -0,0 +1,103 @@
+//===-- llvm/Target/TargetMachOWriterInfo.h - MachO Writer Info--*- C++ -*-===//
+//
+//                     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 defines the TargetMachOWriterInfo class.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_TARGET_TARGETMACHOWRITERINFO_H
+#define LLVM_TARGET_TARGETMACHOWRITERINFO_H
+
+#include "llvm/CodeGen/MachineRelocation.h"
+
+namespace llvm {
+
+  class MachineBasicBlock;
+
+  //===--------------------------------------------------------------------===//
+  //                        TargetMachOWriterInfo
+  //===--------------------------------------------------------------------===//
+
+  struct TargetMachOWriterInfo {
+    uint32_t CPUType;                 // CPU specifier
+    uint32_t CPUSubType;              // Machine specifier
+
+    // The various CPU_TYPE_* constants are already defined by at least one
+    // system header file and create compilation errors if not respected.
+#if !defined(CPU_TYPE_I386)
+#define CPU_TYPE_I386       7
+#endif
+#if !defined(CPU_TYPE_X86_64)
+#define CPU_TYPE_X86_64     (CPU_TYPE_I386 | 0x1000000)
+#endif
+#if !defined(CPU_TYPE_ARM)
+#define CPU_TYPE_ARM        12
+#endif
+#if !defined(CPU_TYPE_SPARC)
+#define CPU_TYPE_SPARC      14
+#endif
+#if !defined(CPU_TYPE_POWERPC)
+#define CPU_TYPE_POWERPC    18
+#endif
+#if !defined(CPU_TYPE_POWERPC64)
+#define CPU_TYPE_POWERPC64  (CPU_TYPE_POWERPC | 0x1000000)
+#endif
+
+    // Constants for the cputype field
+    // see <mach/machine.h>
+    enum {
+      HDR_CPU_TYPE_I386      = CPU_TYPE_I386,
+      HDR_CPU_TYPE_X86_64    = CPU_TYPE_X86_64,
+      HDR_CPU_TYPE_ARM       = CPU_TYPE_ARM,
+      HDR_CPU_TYPE_SPARC     = CPU_TYPE_SPARC,
+      HDR_CPU_TYPE_POWERPC   = CPU_TYPE_POWERPC,
+      HDR_CPU_TYPE_POWERPC64 = CPU_TYPE_POWERPC64
+    };
+      
+#if !defined(CPU_SUBTYPE_I386_ALL)
+#define CPU_SUBTYPE_I386_ALL    3
+#endif
+#if !defined(CPU_SUBTYPE_X86_64_ALL)
+#define CPU_SUBTYPE_X86_64_ALL  3
+#endif
+#if !defined(CPU_SUBTYPE_ARM_ALL)
+#define CPU_SUBTYPE_ARM_ALL     0
+#endif
+#if !defined(CPU_SUBTYPE_SPARC_ALL)
+#define CPU_SUBTYPE_SPARC_ALL   0
+#endif
+#if !defined(CPU_SUBTYPE_POWERPC_ALL)
+#define CPU_SUBTYPE_POWERPC_ALL 0
+#endif
+
+    // Constants for the cpusubtype field
+    // see <mach/machine.h>
+    enum {
+      HDR_CPU_SUBTYPE_I386_ALL    = CPU_SUBTYPE_I386_ALL,
+      HDR_CPU_SUBTYPE_X86_64_ALL  = CPU_SUBTYPE_X86_64_ALL,
+      HDR_CPU_SUBTYPE_ARM_ALL     = CPU_SUBTYPE_ARM_ALL,
+      HDR_CPU_SUBTYPE_SPARC_ALL   = CPU_SUBTYPE_SPARC_ALL,
+      HDR_CPU_SUBTYPE_POWERPC_ALL = CPU_SUBTYPE_POWERPC_ALL
+    };
+
+    TargetMachOWriterInfo(uint32_t cputype, uint32_t cpusubtype)
+      : CPUType(cputype), CPUSubType(cpusubtype) {}
+    virtual ~TargetMachOWriterInfo() {}
+
+    virtual MachineRelocation GetJTRelocation(unsigned Offset,
+                                              MachineBasicBlock *MBB) const;
+
+    virtual const char *getPassName() const {
+      return "Mach-O Writer";
+    }
+  };
+
+} // end llvm namespace
+
+#endif // LLVM_TARGET_TARGETMACHOWRITERINFO_H
diff --git a/lib/Target/PowerPC/PPCMachOWriterInfo.cpp b/lib/Target/PowerPC/PPCMachOWriterInfo.cpp
new file mode 100644 (file)
index 0000000..54e0681
--- /dev/null
@@ -0,0 +1,22 @@
+//===-- PPCMachOWriterInfo.cpp - Mach-O Writer Info for the PowerPC -------===//
+//
+//                     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 implements Mach-O writer information for the PowerPC backend.
+//
+//===----------------------------------------------------------------------===//
+
+#include "PPCMachOWriterInfo.h"
+#include "PPCTargetMachine.h"
+using namespace llvm;
+
+PPCMachOWriterInfo::PPCMachOWriterInfo(const PPCTargetMachine &TM)
+  : TargetMachOWriterInfo(TM.getTargetData()->getPointerSizeInBits() == 64 ?
+                          HDR_CPU_TYPE_POWERPC64 :
+                          HDR_CPU_TYPE_POWERPC,
+                          HDR_CPU_SUBTYPE_POWERPC_ALL) {}
diff --git a/lib/Target/PowerPC/PPCMachOWriterInfo.h b/lib/Target/PowerPC/PPCMachOWriterInfo.h
new file mode 100644 (file)
index 0000000..af47833
--- /dev/null
@@ -0,0 +1,35 @@
+//===-- PPCMachOWriterInfo.h - Mach-O Writer Info for PowerPC ---*- C++ -*-===//
+//
+//                     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 implements Mach-O writer information for the PowerPC backend.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef PPC_MACHO_WRITER_INFO_H
+#define PPC_MACHO_WRITER_INFO_H
+
+#include "llvm/Target/TargetMachOWriterInfo.h"
+
+namespace llvm {
+
+  // Forward declarations
+  class PPCTargetMachine;
+
+  struct PPCMachOWriterInfo : public TargetMachOWriterInfo {
+    PPCMachOWriterInfo(const PPCTargetMachine &TM);
+    virtual ~PPCMachOWriterInfo() {}
+
+    virtual const char *getPassName() const {
+      return "PowerPC Mach-O Writer";
+    }
+  };
+
+} // end llvm namespace
+
+#endif // PPC_MACHO_WRITER_INFO_H
diff --git a/lib/Target/TargetMachOWriterInfo.cpp b/lib/Target/TargetMachOWriterInfo.cpp
new file mode 100644 (file)
index 0000000..3cf2974
--- /dev/null
@@ -0,0 +1,23 @@
+//===-- llvm/Target/TargetMachOWriterInfo.h - MachO Writer Info -*- C++ -*-===//
+//
+//                     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 defines the TargetMachOWriterInfo class.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/Target/TargetMachOWriterInfo.h"
+#include "llvm/CodeGen/MachineRelocation.h"
+using namespace llvm;
+
+MachineRelocation
+TargetMachOWriterInfo::GetJTRelocation(unsigned Offset,
+                                       MachineBasicBlock *MBB) const {
+  // FIXME: do something about PIC
+  return MachineRelocation::getBB(Offset, MachineRelocation::VANILLA, MBB);
+}