1 //===-- RISCVTargetStreamer.cpp - RISCV 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 RISCV specific target streamer methods. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "RISCVTargetStreamer.h" 14 #include "RISCVBaseInfo.h" 15 #include "RISCVMCTargetDesc.h" 16 #include "llvm/Support/FormattedStream.h" 17 #include "llvm/Support/RISCVAttributes.h" 18 #include "llvm/Support/RISCVISAInfo.h" 19 20 using namespace llvm; 21 22 RISCVTargetStreamer::RISCVTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} 23 24 void RISCVTargetStreamer::finish() { finishAttributeSection(); } 25 26 void RISCVTargetStreamer::emitDirectiveOptionPush() {} 27 void RISCVTargetStreamer::emitDirectiveOptionPop() {} 28 void RISCVTargetStreamer::emitDirectiveOptionPIC() {} 29 void RISCVTargetStreamer::emitDirectiveOptionNoPIC() {} 30 void RISCVTargetStreamer::emitDirectiveOptionRVC() {} 31 void RISCVTargetStreamer::emitDirectiveOptionNoRVC() {} 32 void RISCVTargetStreamer::emitDirectiveOptionRelax() {} 33 void RISCVTargetStreamer::emitDirectiveOptionNoRelax() {} 34 void RISCVTargetStreamer::emitAttribute(unsigned Attribute, unsigned Value) {} 35 void RISCVTargetStreamer::finishAttributeSection() {} 36 void RISCVTargetStreamer::emitTextAttribute(unsigned Attribute, 37 StringRef String) {} 38 void RISCVTargetStreamer::emitIntTextAttribute(unsigned Attribute, 39 unsigned IntValue, 40 StringRef StringValue) {} 41 42 void RISCVTargetStreamer::emitTargetAttributes(const MCSubtargetInfo &STI) { 43 if (STI.hasFeature(RISCV::FeatureRV32E)) 44 emitAttribute(RISCVAttrs::STACK_ALIGN, RISCVAttrs::ALIGN_4); 45 else 46 emitAttribute(RISCVAttrs::STACK_ALIGN, RISCVAttrs::ALIGN_16); 47 48 auto ParseResult = RISCVFeatures::parseFeatureBits( 49 STI.hasFeature(RISCV::Feature64Bit), STI.getFeatureBits()); 50 if (!ParseResult) { 51 report_fatal_error(ParseResult.takeError()); 52 } else { 53 auto &ISAInfo = *ParseResult; 54 emitTextAttribute(RISCVAttrs::ARCH, ISAInfo->toString()); 55 } 56 } 57 58 // This part is for ascii assembly output 59 RISCVTargetAsmStreamer::RISCVTargetAsmStreamer(MCStreamer &S, 60 formatted_raw_ostream &OS) 61 : RISCVTargetStreamer(S), OS(OS) {} 62 63 void RISCVTargetAsmStreamer::emitDirectiveOptionPush() { 64 OS << "\t.option\tpush\n"; 65 } 66 67 void RISCVTargetAsmStreamer::emitDirectiveOptionPop() { 68 OS << "\t.option\tpop\n"; 69 } 70 71 void RISCVTargetAsmStreamer::emitDirectiveOptionPIC() { 72 OS << "\t.option\tpic\n"; 73 } 74 75 void RISCVTargetAsmStreamer::emitDirectiveOptionNoPIC() { 76 OS << "\t.option\tnopic\n"; 77 } 78 79 void RISCVTargetAsmStreamer::emitDirectiveOptionRVC() { 80 OS << "\t.option\trvc\n"; 81 } 82 83 void RISCVTargetAsmStreamer::emitDirectiveOptionNoRVC() { 84 OS << "\t.option\tnorvc\n"; 85 } 86 87 void RISCVTargetAsmStreamer::emitDirectiveOptionRelax() { 88 OS << "\t.option\trelax\n"; 89 } 90 91 void RISCVTargetAsmStreamer::emitDirectiveOptionNoRelax() { 92 OS << "\t.option\tnorelax\n"; 93 } 94 95 void RISCVTargetAsmStreamer::emitAttribute(unsigned Attribute, unsigned Value) { 96 OS << "\t.attribute\t" << Attribute << ", " << Twine(Value) << "\n"; 97 } 98 99 void RISCVTargetAsmStreamer::emitTextAttribute(unsigned Attribute, 100 StringRef String) { 101 OS << "\t.attribute\t" << Attribute << ", \"" << String << "\"\n"; 102 } 103 104 void RISCVTargetAsmStreamer::emitIntTextAttribute(unsigned Attribute, 105 unsigned IntValue, 106 StringRef StringValue) {} 107 108 void RISCVTargetAsmStreamer::finishAttributeSection() {} 109