This patch implements runtime Mips specific
[oota-llvm.git] / lib / Target / Mips / MCTargetDesc / MipsELFStreamer.cpp
1 //===-- MipsELFStreamer.cpp - MipsELFStreamer ---------------------------===//
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 #include "MCTargetDesc/MipsELFStreamer.h"
10 #include "MipsSubtarget.h"
11 #include "llvm/MC/MCAssembler.h"
12 #include "llvm/Support/ELF.h"
13 #include "llvm/Support/ErrorHandling.h"
14
15 namespace llvm {
16
17   MCELFStreamer* createMipsELFStreamer(MCContext &Context, MCAsmBackend &TAB,
18                                        raw_ostream &OS, MCCodeEmitter *Emitter,
19                                        bool RelaxAll, bool NoExecStack) {
20     MipsELFStreamer *S = new MipsELFStreamer(Context, TAB, OS, Emitter,
21                                              RelaxAll, NoExecStack);
22     return S;
23   }
24
25   // For llc. Set a group of ELF header flags
26   void
27   MipsELFStreamer::emitELFHeaderFlagsCG(const MipsSubtarget &Subtarget) {
28
29     if (hasRawTextSupport())
30       return;
31
32     // Update e_header flags
33     MCAssembler& MCA = getAssembler();
34     unsigned EFlags = MCA.getELFHeaderEFlags();
35
36     EFlags |= ELF::EF_MIPS_NOREORDER;
37
38     // Architecture
39     if (Subtarget.hasMips64r2())
40       EFlags |= ELF::EF_MIPS_ARCH_64R2;
41     else if (Subtarget.hasMips64())
42       EFlags |= ELF::EF_MIPS_ARCH_64;
43     else if (Subtarget.hasMips32r2())
44       EFlags |= ELF::EF_MIPS_ARCH_32R2;
45     else
46       EFlags |= ELF::EF_MIPS_ARCH_32;
47
48     // Relocation Model
49     Reloc::Model RM = Subtarget.getRelocationModel();
50     if (RM == Reloc::PIC_ || RM == Reloc::Default)
51       EFlags |= ELF::EF_MIPS_PIC;
52     else if (RM == Reloc::Static)
53       ; // Do nothing for Reloc::Static
54     else
55       llvm_unreachable("Unsupported relocation model for e_flags");
56
57     MCA.setELFHeaderEFlags(EFlags);
58
59
60   }
61 }