1 //===-- Nios2MCTargetDesc.cpp - Nios2 Target Descriptions -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file provides Nios2 specific target descriptions.
12 //===----------------------------------------------------------------------===//
14 #include "Nios2MCTargetDesc.h"
15 #include "InstPrinter/Nios2InstPrinter.h"
16 #include "Nios2MCAsmInfo.h"
17 #include "Nios2TargetStreamer.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/Support/TargetRegistry.h"
25 #define GET_INSTRINFO_MC_DESC
26 #include "Nios2GenInstrInfo.inc"
28 #define GET_SUBTARGETINFO_MC_DESC
29 #include "Nios2GenSubtargetInfo.inc"
31 #define GET_REGINFO_MC_DESC
32 #include "Nios2GenRegisterInfo.inc"
34 static MCInstrInfo *createNios2MCInstrInfo() {
35 MCInstrInfo *X = new MCInstrInfo();
36 InitNios2MCInstrInfo(X); // defined in Nios2GenInstrInfo.inc
40 static MCRegisterInfo *createNios2MCRegisterInfo(const Triple &TT) {
41 MCRegisterInfo *X = new MCRegisterInfo();
42 InitNios2MCRegisterInfo(X, Nios2::R15); // defined in Nios2GenRegisterInfo.inc
46 static MCSubtargetInfo *
47 createNios2MCSubtargetInfo(const Triple &TT, StringRef CPU, StringRef FS) {
48 if (CPU.empty() || CPU == "generic")
50 return createNios2MCSubtargetInfoImpl(TT, CPU, FS);
51 // createNios2MCSubtargetInfoImpl defined in Nios2GenSubtargetInfo.inc
54 static MCAsmInfo *createNios2MCAsmInfo(const MCRegisterInfo &MRI,
56 MCAsmInfo *MAI = new Nios2MCAsmInfo(TT);
58 unsigned SP = MRI.getDwarfRegNum(Nios2::SP, true);
59 MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, SP, 0);
60 MAI->addInitialFrameState(Inst);
65 static MCInstPrinter *createNios2MCInstPrinter(const Triple &T,
66 unsigned SyntaxVariant,
68 const MCInstrInfo &MII,
69 const MCRegisterInfo &MRI) {
70 return new Nios2InstPrinter(MAI, MII, MRI);
73 static MCTargetStreamer *createNios2AsmTargetStreamer(MCStreamer &S,
74 formatted_raw_ostream &OS,
75 MCInstPrinter *InstPrint,
77 return new Nios2TargetAsmStreamer(S, OS);
80 extern "C" void LLVMInitializeNios2TargetMC() {
81 Target *T = &getTheNios2Target();
83 // Register the MC asm info.
84 RegisterMCAsmInfoFn X(*T, createNios2MCAsmInfo);
86 // Register the MC instruction info.
87 TargetRegistry::RegisterMCInstrInfo(*T, createNios2MCInstrInfo);
89 // Register the MC register info.
90 TargetRegistry::RegisterMCRegInfo(*T, createNios2MCRegisterInfo);
92 // Register the asm target streamer.
93 TargetRegistry::RegisterAsmTargetStreamer(*T, createNios2AsmTargetStreamer);
95 // Register the MC subtarget info.
96 TargetRegistry::RegisterMCSubtargetInfo(*T, createNios2MCSubtargetInfo);
97 // Register the MCInstPrinter.
98 TargetRegistry::RegisterMCInstPrinter(*T, createNios2MCInstPrinter);
100 // Register the asm backend.
101 TargetRegistry::RegisterMCAsmBackend(*T, createNios2AsmBackend);