1 | //===-- SparcTargetStreamer.cpp - Sparc 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 Sparc specific target streamer methods. |
10 | // |
11 | //===----------------------------------------------------------------------===// |
12 | |
13 | #include "SparcTargetStreamer.h" |
14 | #include "SparcInstPrinter.h" |
15 | #include "SparcMCTargetDesc.h" |
16 | #include "llvm/BinaryFormat/ELF.h" |
17 | #include "llvm/MC/MCELFObjectWriter.h" |
18 | #include "llvm/MC/MCRegister.h" |
19 | #include "llvm/MC/MCSubtargetInfo.h" |
20 | #include "llvm/Support/FormattedStream.h" |
21 | |
22 | using namespace llvm; |
23 | |
24 | static unsigned getEFlagsForFeatureSet(const MCSubtargetInfo &STI) { |
25 | unsigned EFlags = 0; |
26 | |
27 | if (STI.hasFeature(Feature: Sparc::FeatureV8Plus)) |
28 | EFlags |= ELF::EF_SPARC_32PLUS; |
29 | |
30 | if (STI.hasFeature(Feature: Sparc::FeatureVIS)) |
31 | EFlags |= ELF::EF_SPARC_SUN_US1; |
32 | |
33 | if (STI.hasFeature(Feature: Sparc::FeatureVIS2)) |
34 | EFlags |= ELF::EF_SPARC_SUN_US3; |
35 | |
36 | // VIS 3 and other ISA extensions doesn't set any flags. |
37 | |
38 | return EFlags; |
39 | } |
40 | |
41 | // pin vtable to this file |
42 | SparcTargetStreamer::SparcTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {} |
43 | |
44 | void SparcTargetStreamer::anchor() {} |
45 | |
46 | SparcTargetAsmStreamer::SparcTargetAsmStreamer(MCStreamer &S, |
47 | formatted_raw_ostream &OS) |
48 | : SparcTargetStreamer(S), OS(OS) {} |
49 | |
50 | void SparcTargetAsmStreamer::emitSparcRegisterIgnore(unsigned reg) { |
51 | OS << "\t.register " |
52 | << "%"<< StringRef(SparcInstPrinter::getRegisterName(Reg: reg)).lower() |
53 | << ", #ignore\n"; |
54 | } |
55 | |
56 | void SparcTargetAsmStreamer::emitSparcRegisterScratch(unsigned reg) { |
57 | OS << "\t.register " |
58 | << "%"<< StringRef(SparcInstPrinter::getRegisterName(Reg: reg)).lower() |
59 | << ", #scratch\n"; |
60 | } |
61 | |
62 | SparcTargetELFStreamer::SparcTargetELFStreamer(MCStreamer &S, |
63 | const MCSubtargetInfo &STI) |
64 | : SparcTargetStreamer(S) { |
65 | ELFObjectWriter &W = getStreamer().getWriter(); |
66 | unsigned EFlags = W.getELFHeaderEFlags(); |
67 | |
68 | EFlags |= getEFlagsForFeatureSet(STI); |
69 | |
70 | W.setELFHeaderEFlags(EFlags); |
71 | } |
72 | |
73 | MCELFStreamer &SparcTargetELFStreamer::getStreamer() { |
74 | return static_cast<MCELFStreamer &>(Streamer); |
75 | } |
76 |