Move TargetData to DataLayout.
[oota-llvm.git] / lib / Target / Mips / MipsELFWriterInfo.cpp
1 //===-- MipsELFWriterInfo.cpp - ELF Writer Info for the Mips backend ------===//
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 implements ELF writer information for the Mips backend.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "MipsELFWriterInfo.h"
15 #include "MipsRelocations.h"
16 #include "llvm/Function.h"
17 #include "llvm/Support/ErrorHandling.h"
18 #include "llvm/DataLayout.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include "llvm/Support/ELF.h"
21
22 using namespace llvm;
23
24 //===----------------------------------------------------------------------===//
25 //  Implementation of the MipsELFWriterInfo class
26 //===----------------------------------------------------------------------===//
27
28 MipsELFWriterInfo::MipsELFWriterInfo(bool is64Bit_, bool isLittleEndian_)
29   : TargetELFWriterInfo(is64Bit_, isLittleEndian_) {
30   EMachine = EM_MIPS;
31 }
32
33 MipsELFWriterInfo::~MipsELFWriterInfo() {}
34
35 unsigned MipsELFWriterInfo::getRelocationType(unsigned MachineRelTy) const {
36   switch(MachineRelTy) {
37   case Mips::reloc_mips_pc16:
38     return ELF::R_MIPS_GOT16;
39   case Mips::reloc_mips_hi:
40     return ELF::R_MIPS_HI16;
41   case Mips::reloc_mips_lo:
42     return ELF::R_MIPS_LO16;
43   case Mips::reloc_mips_26:
44     return ELF::R_MIPS_26;
45   default:
46     llvm_unreachable("unknown Mips machine relocation type");
47   }
48 }
49
50 long int MipsELFWriterInfo::getDefaultAddendForRelTy(unsigned RelTy,
51                                                      long int Modifier) const {
52   switch(RelTy) {
53   case ELF::R_MIPS_26: return Modifier;
54   default:
55     llvm_unreachable("unknown Mips relocation type");
56   }
57 }
58
59 unsigned MipsELFWriterInfo::getRelocationTySize(unsigned RelTy) const {
60   switch(RelTy) {
61   case ELF::R_MIPS_GOT16:
62   case ELF::R_MIPS_26:
63       return 32;
64   default:
65     llvm_unreachable("unknown Mips relocation type");
66   }
67 }
68
69 bool MipsELFWriterInfo::isPCRelativeRel(unsigned RelTy) const {
70   switch(RelTy) {
71   case ELF::R_MIPS_GOT16:
72       return true;
73   case ELF::R_MIPS_26:
74       return false;
75   default:
76     llvm_unreachable("unknown Mips relocation type");
77   }
78 }
79
80 unsigned MipsELFWriterInfo::getAbsoluteLabelMachineRelTy() const {
81   return Mips::reloc_mips_26;
82 }
83
84 long int MipsELFWriterInfo::computeRelocation(unsigned SymOffset,
85                                               unsigned RelOffset,
86                                               unsigned RelTy) const {
87
88   if (RelTy == ELF::R_MIPS_GOT16)
89     return SymOffset - (RelOffset + 4);
90
91   llvm_unreachable("computeRelocation unknown for this relocation type");
92 }