1 //===- ARCMCTargetDesc.cpp - ARC Target Descriptions ------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file provides ARC specific target descriptions.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "ARCMCTargetDesc.h"
15 #include "ARCMCAsmInfo.h"
16 #include "ARCTargetStreamer.h"
17 #include "InstPrinter/ARCInstPrinter.h"
18 #include "llvm/MC/MCInstrInfo.h"
19 #include "llvm/MC/MCRegisterInfo.h"
20 #include "llvm/MC/MCSubtargetInfo.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/FormattedStream.h"
23 #include "llvm/Support/TargetRegistry.h"
24 
25 using namespace llvm;
26 
27 #define GET_INSTRINFO_MC_DESC
28 #include "ARCGenInstrInfo.inc"
29 
30 #define GET_SUBTARGETINFO_MC_DESC
31 #include "ARCGenSubtargetInfo.inc"
32 
33 #define GET_REGINFO_MC_DESC
34 #include "ARCGenRegisterInfo.inc"
35 
createARCMCInstrInfo()36 static MCInstrInfo *createARCMCInstrInfo() {
37   auto *X = new MCInstrInfo();
38   InitARCMCInstrInfo(X);
39   return X;
40 }
41 
createARCMCRegisterInfo(const Triple & TT)42 static MCRegisterInfo *createARCMCRegisterInfo(const Triple &TT) {
43   auto *X = new MCRegisterInfo();
44   InitARCMCRegisterInfo(X, ARC::BLINK);
45   return X;
46 }
47 
createARCMCSubtargetInfo(const Triple & TT,StringRef CPU,StringRef FS)48 static MCSubtargetInfo *createARCMCSubtargetInfo(const Triple &TT,
49                                                  StringRef CPU, StringRef FS) {
50   return createARCMCSubtargetInfoImpl(TT, CPU, FS);
51 }
52 
createARCMCAsmInfo(const MCRegisterInfo & MRI,const Triple & TT)53 static MCAsmInfo *createARCMCAsmInfo(const MCRegisterInfo &MRI,
54                                      const Triple &TT) {
55   MCAsmInfo *MAI = new ARCMCAsmInfo(TT);
56 
57   // Initial state of the frame pointer is SP.
58   MCCFIInstruction Inst = MCCFIInstruction::createDefCfa(nullptr, ARC::SP, 0);
59   MAI->addInitialFrameState(Inst);
60 
61   return MAI;
62 }
63 
createARCMCInstPrinter(const Triple & T,unsigned SyntaxVariant,const MCAsmInfo & MAI,const MCInstrInfo & MII,const MCRegisterInfo & MRI)64 static MCInstPrinter *createARCMCInstPrinter(const Triple &T,
65                                              unsigned SyntaxVariant,
66                                              const MCAsmInfo &MAI,
67                                              const MCInstrInfo &MII,
68                                              const MCRegisterInfo &MRI) {
69   return new ARCInstPrinter(MAI, MII, MRI);
70 }
71 
ARCTargetStreamer(MCStreamer & S)72 ARCTargetStreamer::ARCTargetStreamer(MCStreamer &S) : MCTargetStreamer(S) {}
73 ARCTargetStreamer::~ARCTargetStreamer() = default;
74 
createTargetAsmStreamer(MCStreamer & S,formatted_raw_ostream & OS,MCInstPrinter * InstPrint,bool isVerboseAsm)75 static MCTargetStreamer *createTargetAsmStreamer(MCStreamer &S,
76                                                  formatted_raw_ostream &OS,
77                                                  MCInstPrinter *InstPrint,
78                                                  bool isVerboseAsm) {
79   return new ARCTargetStreamer(S);
80 }
81 
82 // Force static initialization.
LLVMInitializeARCTargetMC()83 extern "C" void LLVMInitializeARCTargetMC() {
84   // Register the MC asm info.
85   Target &TheARCTarget = getTheARCTarget();
86   RegisterMCAsmInfoFn X(TheARCTarget, createARCMCAsmInfo);
87 
88   // Register the MC instruction info.
89   TargetRegistry::RegisterMCInstrInfo(TheARCTarget, createARCMCInstrInfo);
90 
91   // Register the MC register info.
92   TargetRegistry::RegisterMCRegInfo(TheARCTarget, createARCMCRegisterInfo);
93 
94   // Register the MC subtarget info.
95   TargetRegistry::RegisterMCSubtargetInfo(TheARCTarget,
96                                           createARCMCSubtargetInfo);
97 
98   // Register the MCInstPrinter
99   TargetRegistry::RegisterMCInstPrinter(TheARCTarget, createARCMCInstPrinter);
100 
101   TargetRegistry::RegisterAsmTargetStreamer(TheARCTarget,
102                                             createTargetAsmStreamer);
103 }
104