Path: blob/main/contrib/llvm-project/llvm/lib/Target/MSP430/MCTargetDesc/MSP430ELFStreamer.cpp
35294 views
//===-- MSP430ELFStreamer.cpp - MSP430 ELF Target Streamer Methods --------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file provides MSP430 specific target streamer methods.9//10//===----------------------------------------------------------------------===//1112#include "MSP430MCTargetDesc.h"13#include "llvm/BinaryFormat/ELF.h"14#include "llvm/MC/MCAssembler.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#include "llvm/Support/MSP430Attributes.h"2122using namespace llvm;23using namespace llvm::MSP430Attrs;2425namespace llvm {2627class MSP430TargetELFStreamer : public MCTargetStreamer {28public:29MCELFStreamer &getStreamer();30MSP430TargetELFStreamer(MCStreamer &S, const MCSubtargetInfo &STI);31};3233// This part is for ELF object output.34MSP430TargetELFStreamer::MSP430TargetELFStreamer(MCStreamer &S,35const MCSubtargetInfo &STI)36: MCTargetStreamer(S) {37// Emit build attributes section according to38// MSP430 EABI (slaa534.pdf, part 13).39MCSection *AttributeSection = getStreamer().getContext().getELFSection(40".MSP430.attributes", ELF::SHT_MSP430_ATTRIBUTES, 0);41Streamer.switchSection(AttributeSection);4243// Format version.44Streamer.emitInt8(0x41);45// Subsection length.46Streamer.emitInt32(22);47// Vendor name string, zero-terminated.48Streamer.emitBytes("mspabi");49Streamer.emitInt8(0);5051// Attribute vector scope tag. 1 stands for the entire file.52Streamer.emitInt8(1);53// Attribute vector length.54Streamer.emitInt32(11);5556Streamer.emitInt8(TagISA);57Streamer.emitInt8(STI.hasFeature(MSP430::FeatureX) ? ISAMSP430X : ISAMSP430);58Streamer.emitInt8(TagCodeModel);59Streamer.emitInt8(CMSmall);60Streamer.emitInt8(TagDataModel);61Streamer.emitInt8(DMSmall);62// Don't emit TagEnumSize, for full GCC compatibility.63}6465MCELFStreamer &MSP430TargetELFStreamer::getStreamer() {66return static_cast<MCELFStreamer &>(Streamer);67}6869MCTargetStreamer *70createMSP430ObjectTargetStreamer(MCStreamer &S, const MCSubtargetInfo &STI) {71const Triple &TT = STI.getTargetTriple();72if (TT.isOSBinFormatELF())73return new MSP430TargetELFStreamer(S, STI);74return nullptr;75}7677} // namespace llvm787980