809846a0fbe6e86da46664bf1011e2893626dfa0
[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 #include "llvm/Target/TargetData.h"
18 #include "llvm/Target/TargetMachine.h"
19 #include "llvm/Function.h"
20
21 namespace llvm {
22
23   //===--------------------------------------------------------------------===//
24   //                          TargetELFWriterInfo
25   //===--------------------------------------------------------------------===//
26
27   class TargetELFWriterInfo {
28   protected:
29     // EMachine - This field is the target specific value to emit as the
30     // e_machine member of the ELF header.
31     unsigned short EMachine;
32     TargetMachine &TM;
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     explicit TargetELFWriterInfo(TargetMachine &tm) : TM(tm) {}
54     virtual ~TargetELFWriterInfo() {}
55
56     unsigned short getEMachine() const { return EMachine; }
57
58     /// getFunctionAlignment - Returns the alignment for function 'F', targets
59     /// with different alignment constraints should overload this method
60     virtual unsigned getFunctionAlignment(const Function *F) const {
61       const TargetData *TD = TM.getTargetData();
62       unsigned FnAlign = F->getAlignment();
63       unsigned TDAlign = TD->getPointerABIAlignment();
64       unsigned Align = std::max(FnAlign, TDAlign);
65       assert(!(Align & (Align-1)) && "Alignment is not a power of two!");
66       return Align;
67     }
68   };
69
70 } // end llvm namespace
71
72 #endif // LLVM_TARGET_TARGETELFWRITERINFO_H