1 //===-- MSP430ELFStreamer.cpp - MSP430 ELF Target Streamer Methods --------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file provides MSP430 specific target streamer methods.
11 //===----------------------------------------------------------------------===//
13 #include "MSP430MCTargetDesc.h"
14 #include "llvm/BinaryFormat/ELF.h"
15 #include "llvm/MC/MCAssembler.h"
16 #include "llvm/MC/MCContext.h"
17 #include "llvm/MC/MCELFStreamer.h"
18 #include "llvm/MC/MCSectionELF.h"
19 #include "llvm/MC/MCStreamer.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/Support/MSP430Attributes.h"
24 using namespace llvm::MSP430Attrs
;
28 class MSP430TargetELFStreamer
: public MCTargetStreamer
{
30 MCELFStreamer
&getStreamer();
31 MSP430TargetELFStreamer(MCStreamer
&S
, const MCSubtargetInfo
&STI
);
34 // This part is for ELF object output.
35 MSP430TargetELFStreamer::MSP430TargetELFStreamer(MCStreamer
&S
,
36 const MCSubtargetInfo
&STI
)
37 : MCTargetStreamer(S
) {
38 MCAssembler
&MCA
= getStreamer().getAssembler();
39 unsigned EFlags
= MCA
.getELFHeaderEFlags();
40 MCA
.setELFHeaderEFlags(EFlags
);
42 // Emit build attributes section according to
43 // MSP430 EABI (slaa534.pdf, part 13).
44 MCSection
*AttributeSection
= getStreamer().getContext().getELFSection(
45 ".MSP430.attributes", ELF::SHT_MSP430_ATTRIBUTES
, 0);
46 Streamer
.switchSection(AttributeSection
);
49 Streamer
.emitInt8(0x41);
51 Streamer
.emitInt32(22);
52 // Vendor name string, zero-terminated.
53 Streamer
.emitBytes("mspabi");
56 // Attribute vector scope tag. 1 stands for the entire file.
58 // Attribute vector length.
59 Streamer
.emitInt32(11);
61 Streamer
.emitInt8(TagISA
);
62 Streamer
.emitInt8(STI
.hasFeature(MSP430::FeatureX
) ? ISAMSP430X
: ISAMSP430
);
63 Streamer
.emitInt8(TagCodeModel
);
64 Streamer
.emitInt8(CMSmall
);
65 Streamer
.emitInt8(TagDataModel
);
66 Streamer
.emitInt8(DMSmall
);
67 // Don't emit TagEnumSize, for full GCC compatibility.
70 MCELFStreamer
&MSP430TargetELFStreamer::getStreamer() {
71 return static_cast<MCELFStreamer
&>(Streamer
);
75 createMSP430ObjectTargetStreamer(MCStreamer
&S
, const MCSubtargetInfo
&STI
) {
76 const Triple
&TT
= STI
.getTargetTriple();
77 if (TT
.isOSBinFormatELF())
78 return new MSP430TargetELFStreamer(S
, STI
);