Adding working version of assembly parser for the MBlaze backend
[oota-llvm.git] / lib / Target / MBlaze / MBlazeELFWriterInfo.cpp
1 //===-- MBlazeELFWriterInfo.cpp - ELF Writer Info for the MBlaze 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 MBlaze backend.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "MBlazeELFWriterInfo.h"
15 #include "MBlazeRelocations.h"
16 #include "llvm/Function.h"
17 #include "llvm/Support/ErrorHandling.h"
18 #include "llvm/Target/TargetData.h"
19 #include "llvm/Target/TargetMachine.h"
20
21 using namespace llvm;
22
23 //===----------------------------------------------------------------------===//
24 //  Implementation of the MBlazeELFWriterInfo class
25 //===----------------------------------------------------------------------===//
26
27 MBlazeELFWriterInfo::MBlazeELFWriterInfo(TargetMachine &TM)
28   : TargetELFWriterInfo(TM.getTargetData()->getPointerSizeInBits() == 64,
29                         TM.getTargetData()->isLittleEndian()) {
30 }
31
32 MBlazeELFWriterInfo::~MBlazeELFWriterInfo() {}
33
34 unsigned MBlazeELFWriterInfo::getRelocationType(unsigned MachineRelTy) const {
35   switch (MachineRelTy) {
36   case MBlaze::reloc_pcrel_word:
37     return R_MICROBLAZE_64_PCREL;
38   case MBlaze::reloc_absolute_word:
39     return R_MICROBLAZE_NONE;
40   default:
41     llvm_unreachable("unknown mblaze machine relocation type");
42   }
43   return 0;
44 }
45
46 long int MBlazeELFWriterInfo::getDefaultAddendForRelTy(unsigned RelTy,
47                                                     long int Modifier) const {
48   switch (RelTy) {
49   case R_MICROBLAZE_32_PCREL:
50     return Modifier - 4;
51   case R_MICROBLAZE_32:
52     return Modifier;
53   default:
54     llvm_unreachable("unknown mblaze relocation type");
55   }
56   return 0;
57 }
58
59 unsigned MBlazeELFWriterInfo::getRelocationTySize(unsigned RelTy) const {
60   // FIXME: Most of these sizes are guesses based on the name
61   switch (RelTy) {
62   case R_MICROBLAZE_32:
63   case R_MICROBLAZE_32_PCREL:
64   case R_MICROBLAZE_32_PCREL_LO:
65   case R_MICROBLAZE_32_LO:
66   case R_MICROBLAZE_SRO32:
67   case R_MICROBLAZE_SRW32:
68   case R_MICROBLAZE_32_SYM_OP_SYM:
69   case R_MICROBLAZE_GOTOFF_32:
70     return 32;
71
72   case R_MICROBLAZE_64_PCREL:
73   case R_MICROBLAZE_64:
74   case R_MICROBLAZE_GOTPC_64:
75   case R_MICROBLAZE_GOT_64:
76   case R_MICROBLAZE_PLT_64:
77   case R_MICROBLAZE_GOTOFF_64:
78     return 64;
79   }
80
81   return 0;
82 }
83
84 bool MBlazeELFWriterInfo::isPCRelativeRel(unsigned RelTy) const {
85   // FIXME: Most of these are guesses based on the name
86   switch (RelTy) {
87   case R_MICROBLAZE_32_PCREL:
88   case R_MICROBLAZE_64_PCREL:
89   case R_MICROBLAZE_32_PCREL_LO:
90   case R_MICROBLAZE_GOTPC_64:
91     return true;
92   }
93
94   return false;
95 }
96
97 unsigned MBlazeELFWriterInfo::getAbsoluteLabelMachineRelTy() const {
98   return MBlaze::reloc_absolute_word;
99 }
100
101 long int MBlazeELFWriterInfo::computeRelocation(unsigned SymOffset,
102                                                 unsigned RelOffset,
103                                                 unsigned RelTy) const {
104   if (RelTy == R_MICROBLAZE_32_PCREL || R_MICROBLAZE_64_PCREL)
105     return SymOffset - (RelOffset + 4);
106   else
107     assert("computeRelocation unknown for this relocation type");
108
109   return 0;
110 }