Add the Object Code Emitter class. Original patch by Aaron Gray, I did some
[oota-llvm.git] / include / llvm / Target / TargetELFWriterInfo.h
1 //===-- llvm/Target/TargetELFWriterInfo.h - ELF Writer Info -----*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the TargetELFWriterInfo class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_TARGET_TARGETELFWRITERINFO_H
15 #define LLVM_TARGET_TARGETELFWRITERINFO_H
16
17 namespace llvm {
18   class Function;
19   class TargetData;
20   class TargetMachine;
21
22   //===--------------------------------------------------------------------===//
23   //                          TargetELFWriterInfo
24   //===--------------------------------------------------------------------===//
25
26   class TargetELFWriterInfo {
27   protected:
28     // EMachine - This field is the target specific value to emit as the
29     // e_machine member of the ELF header.
30     unsigned short EMachine;
31     TargetMachine &TM;
32     bool is64Bit, isLittleEndian;
33   public:
34
35     // Machine architectures
36     enum MachineType {
37       EM_NONE = 0,     // No machine
38       EM_M32 = 1,      // AT&T WE 32100
39       EM_SPARC = 2,    // SPARC
40       EM_386 = 3,      // Intel 386
41       EM_68K = 4,      // Motorola 68000
42       EM_88K = 5,      // Motorola 88000
43       EM_486 = 6,      // Intel 486 (deprecated)
44       EM_860 = 7,      // Intel 80860
45       EM_MIPS = 8,     // MIPS R3000
46       EM_PPC = 20,     // PowerPC
47       EM_ARM = 40,     // ARM
48       EM_ALPHA = 41,   // DEC Alpha
49       EM_SPARCV9 = 43, // SPARC V9
50       EM_X86_64 = 62   // AMD64
51     };
52
53     // ELF File classes
54     enum {
55       ELFCLASS32 = 1, // 32-bit object file
56       ELFCLASS64 = 2  // 64-bit object file
57     };
58
59     // ELF Endianess
60     enum {
61       ELFDATA2LSB = 1, // Little-endian object file
62       ELFDATA2MSB = 2  // Big-endian object file
63     };
64
65     explicit TargetELFWriterInfo(TargetMachine &tm);
66     virtual ~TargetELFWriterInfo();
67
68     unsigned short getEMachine() const { return EMachine; }
69     unsigned getEFlags() const { return 0; }
70     unsigned getEIClass() const { return is64Bit ? ELFCLASS64 : ELFCLASS32; }
71     unsigned getEIData() const {
72       return isLittleEndian ? ELFDATA2LSB : ELFDATA2MSB;
73     }
74
75     /// ELF Header and ELF Section Header Info
76     unsigned getHdrSize() const { return is64Bit ? 64 : 52; }
77     unsigned getSHdrSize() const { return is64Bit ? 64 : 40; }
78
79     /// Symbol Table Info
80     unsigned getSymTabEntrySize() const { return is64Bit ? 24 : 16; }
81
82     /// getPrefELFAlignment - Returns the preferred alignment for ELF. This
83     /// is used to align some sections.
84     unsigned getPrefELFAlignment() const { return is64Bit ? 8 : 4; }
85
86     /// getRelocationEntrySize - Entry size used in the relocation section
87     unsigned getRelocationEntrySize() const {
88       return is64Bit ? (hasRelocationAddend() ? 24 : 16)
89                      : (hasRelocationAddend() ? 12 : 8);
90     }
91
92     /// getRelocationType - Returns the target specific ELF Relocation type.
93     /// 'MachineRelTy' contains the object code independent relocation type
94     virtual unsigned getRelocationType(unsigned MachineRelTy) const = 0;
95
96     /// hasRelocationAddend - True if the target uses an addend in the
97     /// ELF relocation entry.
98     virtual bool hasRelocationAddend() const = 0;
99
100     /// getAddendForRelTy - Gets the addend value for an ELF relocation entry
101     /// based on the target relocation type. If addend is not used returns 0.
102     virtual long int getAddendForRelTy(unsigned RelTy) const = 0;
103   };
104
105 } // end llvm namespace
106
107 #endif // LLVM_TARGET_TARGETELFWRITERINFO_H