LLVM API Documentation

XCoreMCTargetDesc.cpp
Go to the documentation of this file.
00001 //===-- XCoreMCTargetDesc.cpp - XCore Target Descriptions -----------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file provides XCore specific target descriptions.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "XCoreMCTargetDesc.h"
00015 #include "InstPrinter/XCoreInstPrinter.h"
00016 #include "XCoreMCAsmInfo.h"
00017 #include "XCoreTargetStreamer.h"
00018 #include "llvm/MC/MCCodeGenInfo.h"
00019 #include "llvm/MC/MCInstrInfo.h"
00020 #include "llvm/MC/MCRegisterInfo.h"
00021 #include "llvm/MC/MCSubtargetInfo.h"
00022 #include "llvm/Support/ErrorHandling.h"
00023 #include "llvm/Support/FormattedStream.h"
00024 #include "llvm/Support/TargetRegistry.h"
00025 
00026 using namespace llvm;
00027 
00028 #define GET_INSTRINFO_MC_DESC
00029 #include "XCoreGenInstrInfo.inc"
00030 
00031 #define GET_SUBTARGETINFO_MC_DESC
00032 #include "XCoreGenSubtargetInfo.inc"
00033 
00034 #define GET_REGINFO_MC_DESC
00035 #include "XCoreGenRegisterInfo.inc"
00036 
00037 static MCInstrInfo *createXCoreMCInstrInfo() {
00038   MCInstrInfo *X = new MCInstrInfo();
00039   InitXCoreMCInstrInfo(X);
00040   return X;
00041 }
00042 
00043 static MCRegisterInfo *createXCoreMCRegisterInfo(StringRef TT) {
00044   MCRegisterInfo *X = new MCRegisterInfo();
00045   InitXCoreMCRegisterInfo(X, XCore::LR);
00046   return X;
00047 }
00048 
00049 static MCSubtargetInfo *createXCoreMCSubtargetInfo(StringRef TT, StringRef CPU,
00050                                                    StringRef FS) {
00051   MCSubtargetInfo *X = new MCSubtargetInfo();
00052   InitXCoreMCSubtargetInfo(X, TT, CPU, FS);
00053   return X;
00054 }
00055 
00056 static MCAsmInfo *createXCoreMCAsmInfo(const MCRegisterInfo &MRI,
00057                                        StringRef TT) {
00058   MCAsmInfo *MAI = new XCoreMCAsmInfo(TT);
00059 
00060   // Initial state of the frame pointer is SP.
00061   MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, XCore::SP, 0);
00062   MAI->addInitialFrameState(Inst);
00063 
00064   return MAI;
00065 }
00066 
00067 static MCCodeGenInfo *createXCoreMCCodeGenInfo(StringRef TT, Reloc::Model RM,
00068                                                CodeModel::Model CM,
00069                                                CodeGenOpt::Level OL) {
00070   MCCodeGenInfo *X = new MCCodeGenInfo();
00071   if (RM == Reloc::Default) {
00072     RM = Reloc::Static;
00073   }
00074   if (CM == CodeModel::Default) {
00075     CM = CodeModel::Small;
00076   }
00077   if (CM != CodeModel::Small && CM != CodeModel::Large)
00078     report_fatal_error("Target only supports CodeModel Small or Large");
00079 
00080   X->InitMCCodeGenInfo(RM, CM, OL);
00081   return X;
00082 }
00083 
00084 static MCInstPrinter *createXCoreMCInstPrinter(const Target &T,
00085                                                unsigned SyntaxVariant,
00086                                                const MCAsmInfo &MAI,
00087                                                const MCInstrInfo &MII,
00088                                                const MCRegisterInfo &MRI,
00089                                                const MCSubtargetInfo &STI) {
00090   return new XCoreInstPrinter(MAI, MII, MRI);
00091 }
00092 
00093 XCoreTargetStreamer::XCoreTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
00094 XCoreTargetStreamer::~XCoreTargetStreamer() {}
00095 
00096 namespace {
00097 
00098 class XCoreTargetAsmStreamer : public XCoreTargetStreamer {
00099   formatted_raw_ostream &OS;
00100 public:
00101   XCoreTargetAsmStreamer(MCStreamer &S, formatted_raw_ostream &OS);
00102   void emitCCTopData(StringRef Name) override;
00103   void emitCCTopFunction(StringRef Name) override;
00104   void emitCCBottomData(StringRef Name) override;
00105   void emitCCBottomFunction(StringRef Name) override;
00106 };
00107 
00108 XCoreTargetAsmStreamer::XCoreTargetAsmStreamer(MCStreamer &S,
00109                                                formatted_raw_ostream &OS)
00110     : XCoreTargetStreamer(S), OS(OS) {}
00111 
00112 void XCoreTargetAsmStreamer::emitCCTopData(StringRef Name) {
00113   OS << "\t.cc_top " << Name << ".data," << Name << '\n';
00114 }
00115 
00116 void XCoreTargetAsmStreamer::emitCCTopFunction(StringRef Name) {
00117   OS << "\t.cc_top " << Name << ".function," << Name << '\n';
00118 }
00119 
00120 void XCoreTargetAsmStreamer::emitCCBottomData(StringRef Name) {
00121   OS << "\t.cc_bottom " << Name << ".data\n";
00122 }
00123 
00124 void XCoreTargetAsmStreamer::emitCCBottomFunction(StringRef Name) {
00125   OS << "\t.cc_bottom " << Name << ".function\n";
00126 }
00127 }
00128 
00129 static MCStreamer *
00130 createXCoreMCAsmStreamer(MCContext &Ctx, formatted_raw_ostream &OS,
00131                          bool isVerboseAsm, bool useDwarfDirectory,
00132                          MCInstPrinter *InstPrint, MCCodeEmitter *CE,
00133                          MCAsmBackend *TAB, bool ShowInst) {
00134   MCStreamer *S = llvm::createAsmStreamer(
00135       Ctx, OS, isVerboseAsm, useDwarfDirectory, InstPrint, CE, TAB, ShowInst);
00136   new XCoreTargetAsmStreamer(*S, OS);
00137   return S;
00138 }
00139 
00140 // Force static initialization.
00141 extern "C" void LLVMInitializeXCoreTargetMC() {
00142   // Register the MC asm info.
00143   RegisterMCAsmInfoFn X(TheXCoreTarget, createXCoreMCAsmInfo);
00144 
00145   // Register the MC codegen info.
00146   TargetRegistry::RegisterMCCodeGenInfo(TheXCoreTarget,
00147                                         createXCoreMCCodeGenInfo);
00148 
00149   // Register the MC instruction info.
00150   TargetRegistry::RegisterMCInstrInfo(TheXCoreTarget, createXCoreMCInstrInfo);
00151 
00152   // Register the MC register info.
00153   TargetRegistry::RegisterMCRegInfo(TheXCoreTarget, createXCoreMCRegisterInfo);
00154 
00155   // Register the MC subtarget info.
00156   TargetRegistry::RegisterMCSubtargetInfo(TheXCoreTarget,
00157                                           createXCoreMCSubtargetInfo);
00158 
00159   // Register the MCInstPrinter
00160   TargetRegistry::RegisterMCInstPrinter(TheXCoreTarget,
00161                                         createXCoreMCInstPrinter);
00162 
00163   TargetRegistry::RegisterAsmStreamer(TheXCoreTarget, createXCoreMCAsmStreamer);
00164 }