Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Target/MSP430/MCTargetDesc/MSP430ELFStreamer.cpp
Line
Count
Source (jump to first uncovered line)
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"
19
#include "llvm/MC/MCSubtargetInfo.h"
20
21
using namespace llvm;
22
23
namespace llvm {
24
25
class MSP430TargetELFStreamer : public MCTargetStreamer {
26
public:
27
  MCELFStreamer &getStreamer();
28
  MSP430TargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);
29
};
30
31
// This part is for ELF object output.
32
MSP430TargetELFStreamer::MSP430TargetELFStreamer(MCStreamer &S,
33
                                                 const MCSubtargetInfo &STI)
34
5
    : MCTargetStreamer(S) {
35
5
  MCAssembler &MCA = getStreamer().getAssembler();
36
5
  unsigned EFlags = MCA.getELFHeaderEFlags();
37
5
  MCA.setELFHeaderEFlags(EFlags);
38
5
39
5
  // Emit build attributes section according to
40
5
  // MSP430 EABI (slaa534.pdf, part 13).
41
5
  MCSection *AttributeSection = getStreamer().getContext().getELFSection(
42
5
      ".MSP430.attributes", ELF::SHT_MSP430_ATTRIBUTES, 0);
43
5
  Streamer.SwitchSection(AttributeSection);
44
5
45
5
  // Format version.
46
5
  Streamer.EmitIntValue(0x41, 1);
47
5
  // Subsection length.
48
5
  Streamer.EmitIntValue(22, 4);
49
5
  // Vendor name string, zero-terminated.
50
5
  Streamer.EmitBytes("mspabi");
51
5
  Streamer.EmitIntValue(0, 1);
52
5
53
5
  // Attribute vector scope tag. 1 stands for the entire file.
54
5
  Streamer.EmitIntValue(1, 1);
55
5
  // Attribute vector length.
56
5
  Streamer.EmitIntValue(11, 4);
57
5
  // OFBA_MSPABI_Tag_ISA(4) = 1, MSP430
58
5
  Streamer.EmitIntValue(4, 1);
59
5
  Streamer.EmitIntValue(1, 1);
60
5
  // OFBA_MSPABI_Tag_Code_Model(6) = 1, Small
61
5
  Streamer.EmitIntValue(6, 1);
62
5
  Streamer.EmitIntValue(1, 1);
63
5
  // OFBA_MSPABI_Tag_Data_Model(8) = 1, Small
64
5
  Streamer.EmitIntValue(8, 1);
65
5
  Streamer.EmitIntValue(1, 1);
66
5
}
67
68
10
MCELFStreamer &MSP430TargetELFStreamer::getStreamer() {
69
10
  return static_cast<MCELFStreamer &>(Streamer);
70
10
}
71
72
MCTargetStreamer *
73
5
createMSP430ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {
74
5
  const Triple &TT = STI.getTargetTriple();
75
5
  if (TT.isOSBinFormatELF())
76
5
    return new MSP430TargetELFStreamer(S, STI);
77
0
  return nullptr;
78
0
}
79
80
} // namespace llvm