LLVM  14.0.0git
MSP430ELFStreamer.cpp
Go to the documentation of this file.
1 //===-- MSP430ELFStreamer.cpp - MSP430 ELF Target Streamer Methods --------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file provides MSP430 specific target streamer methods.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "MSP430MCTargetDesc.h"
14 #include "llvm/BinaryFormat/ELF.h"
15 #include "llvm/MC/MCContext.h"
16 #include "llvm/MC/MCELFStreamer.h"
17 #include "llvm/MC/MCSectionELF.h"
18 #include "llvm/MC/MCStreamer.h"
21 
22 using namespace llvm;
23 using namespace llvm::MSP430Attrs;
24 
25 namespace llvm {
26 
28 public:
29  MCELFStreamer &getStreamer();
31 };
32 
33 // This part is for ELF object output.
35  const MCSubtargetInfo &STI)
36  : MCTargetStreamer(S) {
38  unsigned EFlags = MCA.getELFHeaderEFlags();
39  MCA.setELFHeaderEFlags(EFlags);
40 
41  // Emit build attributes section according to
42  // MSP430 EABI (slaa534.pdf, part 13).
43  MCSection *AttributeSection = getStreamer().getContext().getELFSection(
44  ".MSP430.attributes", ELF::SHT_MSP430_ATTRIBUTES, 0);
45  Streamer.SwitchSection(AttributeSection);
46 
47  // Format version.
48  Streamer.emitInt8(0x41);
49  // Subsection length.
50  Streamer.emitInt32(22);
51  // Vendor name string, zero-terminated.
52  Streamer.emitBytes("mspabi");
53  Streamer.emitInt8(0);
54 
55  // Attribute vector scope tag. 1 stands for the entire file.
56  Streamer.emitInt8(1);
57  // Attribute vector length.
58  Streamer.emitInt32(11);
59 
61  Streamer.emitInt8(STI.hasFeature(MSP430::FeatureX) ? ISAMSP430X : ISAMSP430);
66  // Don't emit TagEnumSize, for full GCC compatibility.
67 }
68 
70  return static_cast<MCELFStreamer &>(Streamer);
71 }
72 
75  const Triple &TT = STI.getTargetTriple();
76  if (TT.isOSBinFormatELF())
77  return new MSP430TargetELFStreamer(S, STI);
78  return nullptr;
79 }
80 
81 } // namespace llvm
llvm::MCAssembler::getELFHeaderEFlags
unsigned getELFHeaderEFlags() const
ELF e_header flags.
Definition: MCAssembler.h:262
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::MSP430Attrs::TagISA
@ TagISA
Definition: MSP430Attributes.h:30
llvm::MSP430Attrs
Definition: MSP430Attributes.h:24
llvm::MSP430TargetELFStreamer::getStreamer
MCELFStreamer & getStreamer()
Definition: MSP430ELFStreamer.cpp:69
MCSectionELF.h
llvm::MCStreamer::emitInt8
void emitInt8(uint64_t Value)
Definition: MCStreamer.h:705
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:45
llvm::MCStreamer::emitInt32
void emitInt32(uint64_t Value)
Definition: MCStreamer.h:707
llvm::MSP430Attrs::CMSmall
@ CMSmall
Definition: MSP430Attributes.h:37
llvm::MSP430TargetELFStreamer
Definition: MSP430ELFStreamer.cpp:27
MCELFStreamer.h
llvm::MCStreamer
Streaming machine code generation interface.
Definition: MCStreamer.h:199
ELF.h
llvm::MCELFStreamer
Definition: MCELFStreamer.h:24
llvm::MSP430TargetELFStreamer::MSP430TargetELFStreamer
MSP430TargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
Definition: MSP430ELFStreamer.cpp:34
llvm::MCSubtargetInfo::hasFeature
bool hasFeature(unsigned Feature) const
Definition: MCSubtargetInfo.h:118
MSP430Attributes.h
llvm::MCSubtargetInfo::getTargetTriple
const Triple & getTargetTriple() const
Definition: MCSubtargetInfo.h:107
MCContext.h
llvm::MSP430Attrs::ISAMSP430X
@ ISAMSP430X
Definition: MSP430Attributes.h:36
llvm::MCContext::getELFSection
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:540
MCSubtargetInfo.h
llvm::MCTargetStreamer
Target specific streamer interface.
Definition: MCStreamer.h:91
llvm::createMSP430ObjectTargetStreamer
MCTargetStreamer * createMSP430ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
Definition: MSP430ELFStreamer.cpp:74
MSP430MCTargetDesc.h
llvm::MSP430Attrs::DMSmall
@ DMSmall
Definition: MSP430Attributes.h:38
llvm::MCAssembler
Definition: MCAssembler.h:60
llvm::MCTargetStreamer::Streamer
MCStreamer & Streamer
Definition: MCStreamer.h:93
llvm::MCAssembler::setELFHeaderEFlags
void setELFHeaderEFlags(unsigned Flags)
Definition: MCAssembler.h:263
llvm::MCObjectStreamer::getAssembler
MCAssembler & getAssembler()
Definition: MCObjectStreamer.h:112
llvm::MCSection
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:39
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::MSP430Attrs::ISAMSP430
@ ISAMSP430
Definition: MSP430Attributes.h:36
llvm::MSP430Attrs::TagDataModel
@ TagDataModel
Definition: MSP430Attributes.h:32
llvm::MCStreamer::getContext
MCContext & getContext() const
Definition: MCStreamer.h:280
llvm::MSP430Attrs::TagCodeModel
@ TagCodeModel
Definition: MSP430Attributes.h:31
MCStreamer.h
llvm::MCStreamer::emitBytes
virtual void emitBytes(StringRef Data)
Emit the bytes in Data into the output.
Definition: MCStreamer.cpp:1189
llvm::ELF::SHT_MSP430_ATTRIBUTES
@ SHT_MSP430_ATTRIBUTES
Definition: ELF.h:979
llvm::MCStreamer::SwitchSection
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Definition: MCStreamer.cpp:1212
llvm::MCSubtargetInfo
Generic base class for all target subtargets.
Definition: MCSubtargetInfo.h:75