[Darwin][Driver][clang] apple-none-macho orders the resource directory after internal...
[llvm-project.git] / llvm / lib / Target / XCore / MCTargetDesc / XCoreMCTargetDesc.cpp
blob098d874f21490bdf6a35548bb383909064d484d7
1 //===-- XCoreMCTargetDesc.cpp - XCore Target Descriptions -----------------===//
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 XCore specific target descriptions.
11 //===----------------------------------------------------------------------===//
13 #include "MCTargetDesc/XCoreMCTargetDesc.h"
14 #include "MCTargetDesc/XCoreInstPrinter.h"
15 #include "MCTargetDesc/XCoreMCAsmInfo.h"
16 #include "TargetInfo/XCoreTargetInfo.h"
17 #include "XCoreTargetStreamer.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/MC/MCDwarf.h"
20 #include "llvm/MC/MCInstrInfo.h"
21 #include "llvm/MC/MCRegisterInfo.h"
22 #include "llvm/MC/MCSubtargetInfo.h"
23 #include "llvm/MC/TargetRegistry.h"
24 #include "llvm/Support/ErrorHandling.h"
25 #include "llvm/Support/FormattedStream.h"
26 #include "llvm/Support/raw_ostream.h"
28 using namespace llvm;
30 #define GET_INSTRINFO_MC_DESC
31 #define ENABLE_INSTR_PREDICATE_VERIFIER
32 #include "XCoreGenInstrInfo.inc"
34 #define GET_SUBTARGETINFO_MC_DESC
35 #include "XCoreGenSubtargetInfo.inc"
37 #define GET_REGINFO_MC_DESC
38 #include "XCoreGenRegisterInfo.inc"
40 static MCInstrInfo *createXCoreMCInstrInfo() {
41 MCInstrInfo *X = new MCInstrInfo();
42 InitXCoreMCInstrInfo(X);
43 return X;
46 static MCRegisterInfo *createXCoreMCRegisterInfo(const Triple &TT) {
47 MCRegisterInfo *X = new MCRegisterInfo();
48 InitXCoreMCRegisterInfo(X, XCore::LR);
49 return X;
52 static MCSubtargetInfo *
53 createXCoreMCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
54 return createXCoreMCSubtargetInfoImpl(TT, CPU, /*TuneCPU*/ CPU, FS);
57 static MCAsmInfo *createXCoreMCAsmInfo(const MCRegisterInfo &MRI,
58 const Triple &TT,
59 const MCTargetOptions &Options) {
60 MCAsmInfo *MAI = new XCoreMCAsmInfo(TT);
62 // Initial state of the frame pointer is SP.
63 MCCFIInstruction Inst = MCCFIInstruction::cfiDefCfa(nullptr, XCore::SP, 0);
64 MAI->addInitialFrameState(Inst);
66 return MAI;
69 static MCInstPrinter *createXCoreMCInstPrinter(const Triple &T,
70 unsigned SyntaxVariant,
71 const MCAsmInfo &MAI,
72 const MCInstrInfo &MII,
73 const MCRegisterInfo &MRI) {
74 return new XCoreInstPrinter(MAI, MII, MRI);
77 XCoreTargetStreamer::XCoreTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
79 XCoreTargetStreamer::~XCoreTargetStreamer() = default;
81 namespace {
83 class XCoreTargetAsmStreamer : public XCoreTargetStreamer {
84 formatted_raw_ostream &OS;
86 public:
87 XCoreTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
89 void emitCCTopData(StringRef Name) override;
90 void emitCCTopFunction(StringRef Name) override;
91 void emitCCBottomData(StringRef Name) override;
92 void emitCCBottomFunction(StringRef Name) override;
95 } // end anonymous namespace
97 XCoreTargetAsmStreamer::XCoreTargetAsmStreamer(MCStreamer &S,
98 formatted_raw_ostream &OS)
99 : XCoreTargetStreamer(S), OS(OS) {}
101 void XCoreTargetAsmStreamer::emitCCTopData(StringRef Name) {
102 OS << "\t.cc_top " << Name << ".data," << Name << '\n';
105 void XCoreTargetAsmStreamer::emitCCTopFunction(StringRef Name) {
106 OS << "\t.cc_top " << Name << ".function," << Name << '\n';
109 void XCoreTargetAsmStreamer::emitCCBottomData(StringRef Name) {
110 OS << "\t.cc_bottom " << Name << ".data\n";
113 void XCoreTargetAsmStreamer::emitCCBottomFunction(StringRef Name) {
114 OS << "\t.cc_bottom " << Name << ".function\n";
117 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
118 formatted_raw_ostream &OS,
119 MCInstPrinter *InstPrint) {
120 return new XCoreTargetAsmStreamer(S, OS);
123 static MCTargetStreamer *createNullTargetStreamer(MCStreamer &S) {
124 return new XCoreTargetStreamer(S);
127 // Force static initialization.
128 extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeXCoreTargetMC() {
129 // Register the MC asm info.
130 RegisterMCAsmInfoFn X(getTheXCoreTarget(), createXCoreMCAsmInfo);
132 // Register the MC instruction info.
133 TargetRegistry::RegisterMCInstrInfo(getTheXCoreTarget(),
134 createXCoreMCInstrInfo);
136 // Register the MC register info.
137 TargetRegistry::RegisterMCRegInfo(getTheXCoreTarget(),
138 createXCoreMCRegisterInfo);
140 // Register the MC subtarget info.
141 TargetRegistry::RegisterMCSubtargetInfo(getTheXCoreTarget(),
142 createXCoreMCSubtargetInfo);
144 // Register the MCInstPrinter
145 TargetRegistry::RegisterMCInstPrinter(getTheXCoreTarget(),
146 createXCoreMCInstPrinter);
148 TargetRegistry::RegisterAsmTargetStreamer(getTheXCoreTarget(),
149 createTargetAsmStreamer);
151 TargetRegistry::RegisterNullTargetStreamer(getTheXCoreTarget(),
152 createNullTargetStreamer);