aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/MSP430/MCTargetDesc/MSP430ELFStreamer.cpp
blob: 9449cb2780249bcc7f63093db27ac1c3b56c8209 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//===-- MSP430ELFStreamer.cpp - MSP430 ELF Target Streamer Methods --------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file provides MSP430 specific target streamer methods.
//
//===----------------------------------------------------------------------===//

#include "MSP430MCTargetDesc.h"
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCELFStreamer.h"
#include "llvm/MC/MCSectionELF.h"
#include "llvm/MC/MCStreamer.h"
#include "llvm/MC/MCSubtargetInfo.h"

using namespace llvm;

namespace llvm {

class MSP430TargetELFStreamer : public MCTargetStreamer {
public:
  MCELFStreamer &getStreamer();
  MSP430TargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
};

// This part is for ELF object output.
MSP430TargetELFStreamer::MSP430TargetELFStreamer(MCStreamer &S,
                                                 const MCSubtargetInfo &STI)
    : MCTargetStreamer(S) {
  MCAssembler &MCA = getStreamer().getAssembler();
  unsigned EFlags = MCA.getELFHeaderEFlags();
  MCA.setELFHeaderEFlags(EFlags);

  // Emit build attributes section according to
  // MSP430 EABI (slaa534.pdf, part 13).
  MCSection *AttributeSection = getStreamer().getContext().getELFSection(
      ".MSP430.attributes", ELF::SHT_MSP430_ATTRIBUTES, 0);
  Streamer.SwitchSection(AttributeSection);

  // Format version.
  Streamer.EmitIntValue(0x41, 1);
  // Subsection length.
  Streamer.EmitIntValue(22, 4);
  // Vendor name string, zero-terminated.
  Streamer.EmitBytes("mspabi");
  Streamer.EmitIntValue(0, 1);

  // Attribute vector scope tag. 1 stands for the entire file.
  Streamer.EmitIntValue(1, 1);
  // Attribute vector length.
  Streamer.EmitIntValue(11, 4);
  // OFBA_MSPABI_Tag_ISA(4) = 1, MSP430
  Streamer.EmitIntValue(4, 1);
  Streamer.EmitIntValue(1, 1);
  // OFBA_MSPABI_Tag_Code_Model(6) = 1, Small
  Streamer.EmitIntValue(6, 1);
  Streamer.EmitIntValue(1, 1);
  // OFBA_MSPABI_Tag_Data_Model(8) = 1, Small
  Streamer.EmitIntValue(8, 1);
  Streamer.EmitIntValue(1, 1);
}

MCELFStreamer &MSP430TargetELFStreamer::getStreamer() {
  return static_cast<MCELFStreamer &>(Streamer);
}

MCTargetStreamer *
createMSP430ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
  const Triple &TT = STI.getTargetTriple();
  if (TT.isOSBinFormatELF())
    return new MSP430TargetELFStreamer(S, STI);
  return nullptr;
}

} // namespace llvm