llvm.org GIT mirror llvm / 17463b3
Make MCInstrInfo available to the MCInstPrinter. This will be used to remove getInstructionName and the static data it contains since the same tables are already in MCInstrInfo. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@153860 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 8 years ago
27 changed file(s) with 89 addition(s) and 41 deletion(s). Raw diff Collapse all Expand all
1313 class MCInst;
1414 class raw_ostream;
1515 class MCAsmInfo;
16 class MCInstrInfo;
1617 class MCRegisterInfo;
1718 class StringRef;
1819
2526 /// assembly emission is disable.
2627 raw_ostream *CommentStream;
2728 const MCAsmInfo &MAI;
29 const MCInstrInfo &MII;
2830 const MCRegisterInfo &MRI;
2931
3032 /// The current set of available features.
3335 /// Utility function for printing annotations.
3436 void printAnnotation(raw_ostream &OS, StringRef Annot);
3537 public:
36 MCInstPrinter(const MCAsmInfo &mai, const MCRegisterInfo &mri)
37 : CommentStream(0), MAI(mai), MRI(mri), AvailableFeatures(0) {}
38 MCInstPrinter(const MCAsmInfo &mai, const MCInstrInfo &mii,
39 const MCRegisterInfo &mri)
40 : CommentStream(0), MAI(mai), MII(mii), MRI(mri), AvailableFeatures(0) {}
3841
3942 virtual ~MCInstPrinter();
4043
103103 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
104104 unsigned SyntaxVariant,
105105 const MCAsmInfo &MAI,
106 const MCInstrInfo &MII,
106107 const MCRegisterInfo &MRI,
107108 const MCSubtargetInfo &STI);
108109 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
392393
393394 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
394395 const MCAsmInfo &MAI,
396 const MCInstrInfo &MII,
395397 const MCRegisterInfo &MRI,
396398 const MCSubtargetInfo &STI) const {
397399 if (!MCInstPrinterCtorFn)
398400 return 0;
399 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MRI, STI);
401 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MII, MRI, STI);
400402 }
401403
402404
171171 case CGFT_AssemblyFile: {
172172 MCInstPrinter *InstPrinter =
173173 getTarget().createMCInstPrinter(MAI.getAssemblerDialect(), MAI,
174 *getInstrInfo(),
174175 Context->getRegisterInfo(), STI);
175176
176177 // Create a code emitter if asked to show the encoding.
5656 const MCAsmInfo *MAI = TheTarget->createMCAsmInfo(TripleName);
5757 assert(MAI && "Unable to create target asm info!");
5858
59 const MCInstrInfo *MII = TheTarget->createMCInstrInfo();
60 assert(MII && "Unable to create target instruction info!");
61
5962 const MCRegisterInfo *MRI = TheTarget->createMCRegInfo(TripleName);
6063 assert(MRI && "Unable to create target register info!");
6164
7982 // Set up the instruction printer.
8083 int AsmPrinterVariant = MAI->getAssemblerDialect();
8184 MCInstPrinter *IP = TheTarget->createMCInstPrinter(AsmPrinterVariant,
82 *MAI, *MRI, *STI);
85 *MAI, *MII, *MRI, *STI);
8386 assert(IP && "Unable to create instruction printer!");
8487
8588 LLVMDisasmContext *DC = new LLVMDisasmContext(TripleName, DisInfo, TagType,
2121 #include "llvm/MC/MCExpr.h"
2222 #include "llvm/MC/MCInst.h"
2323 #include "llvm/MC/MCInstPrinter.h"
24 #include "llvm/MC/MCInstrInfo.h"
2425 #include "llvm/MC/MCRegisterInfo.h"
2526 #include "llvm/MC/MCStreamer.h"
2627 #include "llvm/MC/MCSubtargetInfo.h"
164165 return;
165166
166167 InstInfos = Disassembler->getEDInfo();
167
168
169 MII.reset(Tgt->createMCInstrInfo());
170
171 if (!MII)
172 return;
173
168174 InstString.reset(new std::string);
169175 InstStream.reset(new raw_string_ostream(*InstString));
170176 InstPrinter.reset(Tgt->createMCInstPrinter(LLVMSyntaxVariant, *AsmInfo,
171 *MRI, *STI));
177 *MII, *MRI, *STI));
172178
173179 if (!InstPrinter)
174180 return;
3535 class MCAsmInfo;
3636 class MCAsmLexer;
3737 class MCDisassembler;
38 class MCInst;
3839 class MCInstPrinter;
39 class MCInst;
40 class MCInstrInfo;
4041 class MCParsedAsmOperand;
4142 class MCRegisterInfo;
4243 class MCStreamer;
136137 llvm::OwningPtr AsmInfo;
137138 /// The subtarget information for the target architecture
138139 llvm::OwningPtr STI;
140 // The instruction information for the target architecture.
141 llvm::OwningPtr MII;
139142 // The register information for the target architecture.
140143 llvm::OwningPtr MRI;
141144 /// The disassembler for the target architecture
3535
3636
3737 ARMInstPrinter::ARMInstPrinter(const MCAsmInfo &MAI,
38 const MCInstrInfo &MII,
3839 const MCRegisterInfo &MRI,
3940 const MCSubtargetInfo &STI) :
40 MCInstPrinter(MAI, MRI) {
41 MCInstPrinter(MAI, MII, MRI) {
4142 // Initialize the set of available features.
4243 setAvailableFeatures(STI.getFeatureBits());
4344 }
2222
2323 class ARMInstPrinter : public MCInstPrinter {
2424 public:
25 ARMInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI,
26 const MCSubtargetInfo &STI);
25 ARMInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
26 const MCRegisterInfo &MRI, const MCSubtargetInfo &STI);
2727
2828 virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot);
2929 virtual StringRef getOpcodeName(unsigned Opcode) const;
162162 static MCInstPrinter *createARMMCInstPrinter(const Target &T,
163163 unsigned SyntaxVariant,
164164 const MCAsmInfo &MAI,
165 const MCInstrInfo &MII,
165166 const MCRegisterInfo &MRI,
166167 const MCSubtargetInfo &STI) {
167168 if (SyntaxVariant == 0)
168 return new ARMInstPrinter(MAI, MRI, STI);
169 return new ARMInstPrinter(MAI, MII, MRI, STI);
169170 return 0;
170171 }
171172
2020
2121 class MBlazeInstPrinter : public MCInstPrinter {
2222 public:
23 MBlazeInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI)
24 : MCInstPrinter(MAI, MRI) {}
23 MBlazeInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
24 const MCRegisterInfo &MRI)
25 : MCInstPrinter(MAI, MII, MRI) {}
2526
2627 virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot);
2728
9494 static MCInstPrinter *createMBlazeMCInstPrinter(const Target &T,
9595 unsigned SyntaxVariant,
9696 const MCAsmInfo &MAI,
97 const MCInstrInfo &MII,
9798 const MCRegisterInfo &MRI,
9899 const MCSubtargetInfo &STI) {
99100 if (SyntaxVariant == 0)
100 return new MBlazeInstPrinter(MAI, MRI);
101 return new MBlazeInstPrinter(MAI, MII, MRI);
101102 return 0;
102103 }
103104
2020
2121 class MSP430InstPrinter : public MCInstPrinter {
2222 public:
23 MSP430InstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI)
24 : MCInstPrinter(MAI, MRI) {}
23 MSP430InstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
24 const MCRegisterInfo &MRI)
25 : MCInstPrinter(MAI, MII, MRI) {}
2526
2627 virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot);
2728
6060 static MCInstPrinter *createMSP430MCInstPrinter(const Target &T,
6161 unsigned SyntaxVariant,
6262 const MCAsmInfo &MAI,
63 const MCInstrInfo &MII,
6364 const MCRegisterInfo &MRI,
6465 const MCSubtargetInfo &STI) {
6566 if (SyntaxVariant == 0)
66 return new MSP430InstPrinter(MAI, MRI);
67 return new MSP430InstPrinter(MAI, MII, MRI);
6768 return 0;
6869 }
6970
7676
7777 class MipsInstPrinter : public MCInstPrinter {
7878 public:
79 MipsInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI) :
80 MCInstPrinter(MAI, MRI) {}
79 MipsInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
80 const MCRegisterInfo &MRI)
81 : MCInstPrinter(MAI, MII, MRI) {}
8182
8283 // Autogenerated by tblgen.
8384 void printInstruction(const MCInst *MI, raw_ostream &O);
7777 static MCInstPrinter *createMipsMCInstPrinter(const Target &T,
7878 unsigned SyntaxVariant,
7979 const MCAsmInfo &MAI,
80 const MCInstrInfo &MII,
8081 const MCRegisterInfo &MRI,
8182 const MCSubtargetInfo &STI) {
82 return new MipsInstPrinter(MAI, MRI);
83 return new MipsInstPrinter(MAI, MII, MRI);
8384 }
8485
8586 static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
2727 #include "PTXGenAsmWriter.inc"
2828
2929 PTXInstPrinter::PTXInstPrinter(const MCAsmInfo &MAI,
30 const MCInstrInfo &MII,
3031 const MCRegisterInfo &MRI,
3132 const MCSubtargetInfo &STI) :
32 MCInstPrinter(MAI, MRI) {
33 MCInstPrinter(MAI, MII, MRI) {
3334 // Initialize the set of available features.
3435 setAvailableFeatures(STI.getFeatureBits());
3536 }
2222
2323 class PTXInstPrinter : public MCInstPrinter {
2424 public:
25 PTXInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI,
26 const MCSubtargetInfo &STI);
25 PTXInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
26 const MCRegisterInfo &MRI, const MCSubtargetInfo &STI);
2727
2828 virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot);
2929 virtual StringRef getOpcodeName(unsigned Opcode) const;
6161 static MCInstPrinter *createPTXMCInstPrinter(const Target &T,
6262 unsigned SyntaxVariant,
6363 const MCAsmInfo &MAI,
64 const MCInstrInfo &MII,
6465 const MCRegisterInfo &MRI,
6566 const MCSubtargetInfo &STI) {
6667 assert(SyntaxVariant == 0 && "We only have one syntax variant");
67 return new PTXInstPrinter(MAI, MRI, STI);
68 return new PTXInstPrinter(MAI, MII, MRI, STI);
6869 }
6970
7071 extern "C" void LLVMInitializePTXTargetMC() {
2323 // 0 -> AIX, 1 -> Darwin.
2424 unsigned SyntaxVariant;
2525 public:
26 PPCInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI,
27 unsigned syntaxVariant)
28 : MCInstPrinter(MAI, MRI), SyntaxVariant(syntaxVariant) {}
26 PPCInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
27 const MCRegisterInfo &MRI, unsigned syntaxVariant)
28 : MCInstPrinter(MAI, MII, MRI), SyntaxVariant(syntaxVariant) {}
2929
3030 bool isDarwinSyntax() const {
3131 return SyntaxVariant == 1;
107107 static MCInstPrinter *createPPCMCInstPrinter(const Target &T,
108108 unsigned SyntaxVariant,
109109 const MCAsmInfo &MAI,
110 const MCInstrInfo &MII,
110111 const MCRegisterInfo &MRI,
111112 const MCSubtargetInfo &STI) {
112 return new PPCInstPrinter(MAI, MRI, SyntaxVariant);
113 return new PPCInstPrinter(MAI, MII, MRI, SyntaxVariant);
113114 }
114115
115116 extern "C" void LLVMInitializePowerPCTargetMC() {
2121
2222 class X86ATTInstPrinter : public MCInstPrinter {
2323 public:
24 X86ATTInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI)
25 : MCInstPrinter(MAI, MRI) {}
24 X86ATTInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
25 const MCRegisterInfo &MRI)
26 : MCInstPrinter(MAI, MII, MRI) {}
2627
2728 virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
2829 virtual void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot);
2222
2323 class X86IntelInstPrinter : public MCInstPrinter {
2424 public:
25 X86IntelInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI)
26 : MCInstPrinter(MAI, MRI) {}
25 X86IntelInstPrinter(const MCAsmInfo &MAI, const MCInstrInfo &MII,
26 const MCRegisterInfo &MRI)
27 : MCInstPrinter(MAI, MII, MRI) {}
2728
2829 virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
2930 virtual void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot);
473473 static MCInstPrinter *createX86MCInstPrinter(const Target &T,
474474 unsigned SyntaxVariant,
475475 const MCAsmInfo &MAI,
476 const MCInstrInfo &MII,
476477 const MCRegisterInfo &MRI,
477478 const MCSubtargetInfo &STI) {
478479 if (SyntaxVariant == 0)
479 return new X86ATTInstPrinter(MAI, MRI);
480 return new X86ATTInstPrinter(MAI, MII, MRI);
480481 if (SyntaxVariant == 1)
481 return new X86IntelInstPrinter(MAI, MRI);
482 return new X86IntelInstPrinter(MAI, MII, MRI);
482483 return 0;
483484 }
484485
2020 #include "llvm/MC/MCDisassembler.h"
2121 #include "llvm/MC/MCInst.h"
2222 #include "llvm/MC/MCInstPrinter.h"
23 #include "llvm/MC/MCInstrInfo.h"
2324 #include "llvm/MC/MCRegisterInfo.h"
2425 #include "llvm/MC/MCSubtargetInfo.h"
2526 #include "llvm/ADT/OwningPtr.h"
155156 return -1;
156157 }
157158
158 OwningPtr STI(T.createMCSubtargetInfo(Triple, Cpu, FeaturesStr));
159 OwningPtr STI(T.createMCSubtargetInfo(Triple, Cpu,
160 FeaturesStr));
159161 if (!STI) {
160162 errs() << "error: no subtarget info for target " << Triple << "\n";
161163 return -1;
173175 return -1;
174176 }
175177
178 OwningPtr MII(T.createMCInstrInfo());
179 if (!MII) {
180 errs() << "error: no instruction info for target " << Triple << "\n";
181 return -1;
182 }
183
176184 int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
177 OwningPtr IP(T.createMCInstPrinter(AsmPrinterVariant,
178 *AsmInfo, *MRI, *STI));
185 OwningPtr IP(T.createMCInstPrinter(AsmPrinterVariant, *AsmInfo,
186 *MII, *MRI, *STI));
179187 if (!IP) {
180188 errs() << "error: no instruction printer for target " << Triple << '\n';
181189 return -1;
415415 // FIXME: There is a bit of code duplication with addPassesToEmitFile.
416416 if (FileType == OFT_AssemblyFile) {
417417 MCInstPrinter *IP =
418 TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *MRI, *STI);
418 TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *MCII, *MRI, *STI);
419419 MCCodeEmitter *CE = 0;
420420 MCAsmBackend *MAB = 0;
421421 if (ShowEncoding) {
259259 OwningPtr DisAsm(TheTarget->createMCDisassembler(*STI));
260260 OwningPtr MRI(TheTarget->createMCRegInfo(TripleName));
261261 int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
262 OwningPtr IP(TheTarget->createMCInstPrinter(
263 AsmPrinterVariant, *AsmInfo, *MRI, *STI));
262 OwningPtr
263 IP(TheTarget->createMCInstPrinter(AsmPrinterVariant, *AsmInfo, *InstrInfo,
264 *MRI, *STI));
264265
265266 if (!InstrAnalysis || !AsmInfo || !STI || !DisAsm || !IP) {
266267 errs() << "error: couldn't initialize disassembler for target "
2525 #include "llvm/MC/MCDisassembler.h"
2626 #include "llvm/MC/MCInst.h"
2727 #include "llvm/MC/MCInstPrinter.h"
28 #include "llvm/MC/MCInstrInfo.h"
2829 #include "llvm/MC/MCRegisterInfo.h"
2930 #include "llvm/MC/MCSubtargetInfo.h"
3031 #include "llvm/Support/Casting.h"
253254 return;
254255 }
255256
257 OwningPtr MII(TheTarget->createMCInstrInfo());
258 if (!MII) {
259 errs() << "error: no instruction info for target " << TripleName << "\n";
260 return;
261 }
262
256263 int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
257264 OwningPtr IP(TheTarget->createMCInstPrinter(
258 AsmPrinterVariant, *AsmInfo, *MRI, *STI));
265 AsmPrinterVariant, *AsmInfo, *MII, *MRI, *STI));
259266 if (!IP) {
260267 errs() << "error: no instruction printer for target " << TripleName
261268 << '\n';