LLVM  8.0.1
MSP430ELFStreamer.cpp
Go to the documentation of this file.
1 //===-- MSP430ELFStreamer.cpp - MSP430 ELF Target Streamer Methods --------===//
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 provides MSP430 specific target streamer methods.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "MSP430MCTargetDesc.h"
15 #include "llvm/BinaryFormat/ELF.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"
21 
22 using namespace llvm;
23 
24 namespace llvm {
25 
27 public:
30 };
31 
32 // This part is for ELF object output.
34  const MCSubtargetInfo &STI)
35  : MCTargetStreamer(S) {
37  unsigned EFlags = MCA.getELFHeaderEFlags();
38  MCA.setELFHeaderEFlags(EFlags);
39 
40  // Emit build attributes section according to
41  // MSP430 EABI (slaa534.pdf, part 13).
42  MCSection *AttributeSection = getStreamer().getContext().getELFSection(
43  ".MSP430.attributes", ELF::SHT_MSP430_ATTRIBUTES, 0);
44  Streamer.SwitchSection(AttributeSection);
45 
46  // Format version.
47  Streamer.EmitIntValue(0x41, 1);
48  // Subsection length.
49  Streamer.EmitIntValue(22, 4);
50  // Vendor name string, zero-terminated.
51  Streamer.EmitBytes("mspabi");
52  Streamer.EmitIntValue(0, 1);
53 
54  // Attribute vector scope tag. 1 stands for the entire file.
55  Streamer.EmitIntValue(1, 1);
56  // Attribute vector length.
57  Streamer.EmitIntValue(11, 4);
58  // OFBA_MSPABI_Tag_ISA(4) = 1, MSP430
59  Streamer.EmitIntValue(4, 1);
60  Streamer.EmitIntValue(1, 1);
61  // OFBA_MSPABI_Tag_Code_Model(6) = 1, Small
62  Streamer.EmitIntValue(6, 1);
63  Streamer.EmitIntValue(1, 1);
64  // OFBA_MSPABI_Tag_Data_Model(8) = 1, Small
65  Streamer.EmitIntValue(8, 1);
66  Streamer.EmitIntValue(1, 1);
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
void setELFHeaderEFlags(unsigned Flags)
Definition: MCAssembler.h:256
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
This class represents lattice values for constants.
Definition: AllocatorList.h:24
bool isOSBinFormatELF() const
Tests whether the OS uses the ELF binary format.
Definition: Triple.h:604
virtual void EmitBytes(StringRef Data)
Emit the bytes in Data into the output.
Target specific streamer interface.
Definition: MCStreamer.h:84
const Triple & getTargetTriple() const
MCContext & getContext() const
Definition: MCStreamer.h:251
virtual void EmitIntValue(uint64_t Value, unsigned Size)
Special case of EmitValue that avoids the client having to pass in a MCExpr for constant integers...
Definition: MCStreamer.cpp:124
Streaming machine code generation interface.
Definition: MCStreamer.h:189
virtual void SwitchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
MCAssembler & getAssembler()
unsigned getELFHeaderEFlags() const
ELF e_header flags.
Definition: MCAssembler.h:255
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
MCStreamer & Streamer
Definition: MCStreamer.h:86
MSP430TargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
MCTargetStreamer * createMSP430ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI)
Generic base class for all target subtargets.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Definition: MCContext.h:389