llvm.org GIT mirror llvm / c6449b6
Make MCRegisterInfo available to the the MCInstPrinter. Used to allow context sensitive printing of super-register or sub-register references. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152043 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Grosbach 8 years ago
27 changed file(s) with 70 addition(s) and 38 deletion(s). Raw diff Collapse all Expand all
1313 class MCInst;
1414 class raw_ostream;
1515 class MCAsmInfo;
16 class MCRegisterInfo;
1617 class StringRef;
1718
1819 /// MCInstPrinter - This is an instance of a target assembly language printer
2425 /// assembly emission is disable.
2526 raw_ostream *CommentStream;
2627 const MCAsmInfo &MAI;
28 const MCRegisterInfo &MRI;
2729
2830 /// The current set of available features.
2931 unsigned AvailableFeatures;
3133 /// Utility function for printing annotations.
3234 void printAnnotation(raw_ostream &OS, StringRef Annot);
3335 public:
34 MCInstPrinter(const MCAsmInfo &mai)
35 : CommentStream(0), MAI(mai), AvailableFeatures(0) {}
36 MCInstPrinter(const MCAsmInfo &mai, const MCRegisterInfo &mri)
37 : CommentStream(0), MAI(mai), MRI(mri), AvailableFeatures(0) {}
3638
3739 virtual ~MCInstPrinter();
3840
103103 typedef MCInstPrinter *(*MCInstPrinterCtorTy)(const Target &T,
104104 unsigned SyntaxVariant,
105105 const MCAsmInfo &MAI,
106 const MCRegisterInfo &MRI,
106107 const MCSubtargetInfo &STI);
107108 typedef MCCodeEmitter *(*MCCodeEmitterCtorTy)(const MCInstrInfo &II,
108109 const MCSubtargetInfo &STI,
391392
392393 MCInstPrinter *createMCInstPrinter(unsigned SyntaxVariant,
393394 const MCAsmInfo &MAI,
395 const MCRegisterInfo &MRI,
394396 const MCSubtargetInfo &STI) const {
395397 if (!MCInstPrinterCtorFn)
396398 return 0;
397 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, STI);
399 return MCInstPrinterCtorFn(*this, SyntaxVariant, MAI, MRI, STI);
398400 }
399401
400402
170170 switch (FileType) {
171171 case CGFT_AssemblyFile: {
172172 MCInstPrinter *InstPrinter =
173 getTarget().createMCInstPrinter(MAI.getAssemblerDialect(), MAI, STI);
173 getTarget().createMCInstPrinter(MAI.getAssemblerDialect(), MAI,
174 Context->getRegisterInfo(), STI);
174175
175176 // Create a code emitter if asked to show the encoding.
176177 MCCodeEmitter *MCE = 0;
7979 // Set up the instruction printer.
8080 int AsmPrinterVariant = MAI->getAssemblerDialect();
8181 MCInstPrinter *IP = TheTarget->createMCInstPrinter(AsmPrinterVariant,
82 *MAI, *STI);
82 *MAI, *MRI, *STI);
8383 assert(IP && "Unable to create instruction printer!");
8484
8585 LLVMDisasmContext *DC = new LLVMDisasmContext(TripleName, DisInfo, TagType,
167167
168168 InstString.reset(new std::string);
169169 InstStream.reset(new raw_string_ostream(*InstString));
170 InstPrinter.reset(Tgt->createMCInstPrinter(LLVMSyntaxVariant, *AsmInfo, *STI));
170 InstPrinter.reset(Tgt->createMCInstPrinter(LLVMSyntaxVariant, *AsmInfo,
171 *MRI, *STI));
171172
172173 if (!InstPrinter)
173174 return;
3434
3535
3636 ARMInstPrinter::ARMInstPrinter(const MCAsmInfo &MAI,
37 const MCRegisterInfo &MRI,
3738 const MCSubtargetInfo &STI) :
38 MCInstPrinter(MAI) {
39 MCInstPrinter(MAI, MRI) {
3940 // Initialize the set of available features.
4041 setAvailableFeatures(STI.getFeatureBits());
4142 }
2222
2323 class ARMInstPrinter : public MCInstPrinter {
2424 public:
25 ARMInstPrinter(const MCAsmInfo &MAI, const MCSubtargetInfo &STI);
25 ARMInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI,
26 const MCSubtargetInfo &STI);
2627
2728 virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot);
2829 virtual StringRef getOpcodeName(unsigned Opcode) const;
162162 static MCInstPrinter *createARMMCInstPrinter(const Target &T,
163163 unsigned SyntaxVariant,
164164 const MCAsmInfo &MAI,
165 const MCRegisterInfo &MRI,
165166 const MCSubtargetInfo &STI) {
166167 if (SyntaxVariant == 0)
167 return new ARMInstPrinter(MAI, STI);
168 return new ARMInstPrinter(MAI, MRI, STI);
168169 return 0;
169170 }
170171
2020
2121 class MBlazeInstPrinter : public MCInstPrinter {
2222 public:
23 MBlazeInstPrinter(const MCAsmInfo &MAI)
24 : MCInstPrinter(MAI) {}
23 MBlazeInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI)
24 : MCInstPrinter(MAI, MRI) {}
2525
2626 virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot);
2727
9494 static MCInstPrinter *createMBlazeMCInstPrinter(const Target &T,
9595 unsigned SyntaxVariant,
9696 const MCAsmInfo &MAI,
97 const MCRegisterInfo &MRI,
9798 const MCSubtargetInfo &STI) {
9899 if (SyntaxVariant == 0)
99 return new MBlazeInstPrinter(MAI);
100 return new MBlazeInstPrinter(MAI, MRI);
100101 return 0;
101102 }
102103
2020
2121 class MSP430InstPrinter : public MCInstPrinter {
2222 public:
23 MSP430InstPrinter(const MCAsmInfo &MAI)
24 : MCInstPrinter(MAI) {}
23 MSP430InstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI)
24 : MCInstPrinter(MAI, MRI) {}
2525
2626 virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot);
2727
6060 static MCInstPrinter *createMSP430MCInstPrinter(const Target &T,
6161 unsigned SyntaxVariant,
6262 const MCAsmInfo &MAI,
63 const MCRegisterInfo &MRI,
6364 const MCSubtargetInfo &STI) {
6465 if (SyntaxVariant == 0)
65 return new MSP430InstPrinter(MAI);
66 return new MSP430InstPrinter(MAI, MRI);
6667 return 0;
6768 }
6869
7676
7777 class MipsInstPrinter : public MCInstPrinter {
7878 public:
79 MipsInstPrinter(const MCAsmInfo &MAI) : MCInstPrinter(MAI) {}
79 MipsInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI) :
80 MCInstPrinter(MAI, MRI) {}
8081
8182 // Autogenerated by tblgen.
8283 void printInstruction(const MCInst *MI, raw_ostream &O);
7575 static MCInstPrinter *createMipsMCInstPrinter(const Target &T,
7676 unsigned SyntaxVariant,
7777 const MCAsmInfo &MAI,
78 const MCRegisterInfo &MRI,
7879 const MCSubtargetInfo &STI) {
79 return new MipsInstPrinter(MAI);
80 return new MipsInstPrinter(MAI, MRI);
8081 }
8182
8283 static MCStreamer *createMCStreamer(const Target &T, StringRef TT,
2626 #include "PTXGenAsmWriter.inc"
2727
2828 PTXInstPrinter::PTXInstPrinter(const MCAsmInfo &MAI,
29 const MCRegisterInfo &MRI,
2930 const MCSubtargetInfo &STI) :
30 MCInstPrinter(MAI) {
31 MCInstPrinter(MAI, MRI) {
3132 // Initialize the set of available features.
3233 setAvailableFeatures(STI.getFeatureBits());
3334 }
2222
2323 class PTXInstPrinter : public MCInstPrinter {
2424 public:
25 PTXInstPrinter(const MCAsmInfo &MAI, const MCSubtargetInfo &STI);
25 PTXInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI,
26 const MCSubtargetInfo &STI);
2627
2728 virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot);
2829 virtual StringRef getOpcodeName(unsigned Opcode) const;
6161 static MCInstPrinter *createPTXMCInstPrinter(const Target &T,
6262 unsigned SyntaxVariant,
6363 const MCAsmInfo &MAI,
64 const MCRegisterInfo &MRI,
6465 const MCSubtargetInfo &STI) {
6566 assert(SyntaxVariant == 0 && "We only have one syntax variant");
66 return new PTXInstPrinter(MAI, STI);
67 return new PTXInstPrinter(MAI, MRI, STI);
6768 }
6869
6970 extern "C" void LLVMInitializePTXTargetMC() {
2323 // 0 -> AIX, 1 -> Darwin.
2424 unsigned SyntaxVariant;
2525 public:
26 PPCInstPrinter(const MCAsmInfo &MAI, unsigned syntaxVariant)
27 : MCInstPrinter(MAI), SyntaxVariant(syntaxVariant) {}
26 PPCInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI,
27 unsigned syntaxVariant)
28 : MCInstPrinter(MAI, MRI), SyntaxVariant(syntaxVariant) {}
2829
2930 bool isDarwinSyntax() const {
3031 return SyntaxVariant == 1;
107107 static MCInstPrinter *createPPCMCInstPrinter(const Target &T,
108108 unsigned SyntaxVariant,
109109 const MCAsmInfo &MAI,
110 const MCRegisterInfo &MRI,
110111 const MCSubtargetInfo &STI) {
111 return new PPCInstPrinter(MAI, SyntaxVariant);
112 return new PPCInstPrinter(MAI, MRI, SyntaxVariant);
112113 }
113114
114115 extern "C" void LLVMInitializePowerPCTargetMC() {
2828 #define GET_INSTRUCTION_NAME
2929 #define PRINT_ALIAS_INSTR
3030 #include "X86GenAsmWriter.inc"
31
32 X86ATTInstPrinter::X86ATTInstPrinter(const MCAsmInfo &MAI)
33 : MCInstPrinter(MAI) {
34 }
3531
3632 void X86ATTInstPrinter::printRegName(raw_ostream &OS,
3733 unsigned RegNo) const {
2121
2222 class X86ATTInstPrinter : public MCInstPrinter {
2323 public:
24 X86ATTInstPrinter(const MCAsmInfo &MAI);
25
24 X86ATTInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI)
25 : MCInstPrinter(MAI, MRI) {}
26
2627 virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
2728 virtual void printInst(const MCInst *MI, raw_ostream &OS, StringRef Annot);
2829 virtual StringRef getOpcodeName(unsigned Opcode) const;
2222
2323 class X86IntelInstPrinter : public MCInstPrinter {
2424 public:
25 X86IntelInstPrinter(const MCAsmInfo &MAI)
26 : MCInstPrinter(MAI) {}
25 X86IntelInstPrinter(const MCAsmInfo &MAI, const MCRegisterInfo &MRI)
26 : MCInstPrinter(MAI, MRI) {}
2727
2828 virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
2929 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 MCRegisterInfo &MRI,
476477 const MCSubtargetInfo &STI) {
477478 if (SyntaxVariant == 0)
478 return new X86ATTInstPrinter(MAI);
479 return new X86ATTInstPrinter(MAI, MRI);
479480 if (SyntaxVariant == 1)
480 return new X86IntelInstPrinter(MAI);
481 return new X86IntelInstPrinter(MAI, MRI);
481482 return 0;
482483 }
483484
2020 #include "llvm/MC/MCDisassembler.h"
2121 #include "llvm/MC/MCInst.h"
2222 #include "llvm/MC/MCInstPrinter.h"
23 #include "llvm/MC/MCRegisterInfo.h"
2324 #include "llvm/MC/MCSubtargetInfo.h"
2425 #include "llvm/ADT/OwningPtr.h"
2526 #include "llvm/ADT/Triple.h"
159160 errs() << "error: no subtarget info for target " << Triple << "\n";
160161 return -1;
161162 }
162
163
163164 OwningPtr DisAsm(T.createMCDisassembler(*STI));
164165 if (!DisAsm) {
165166 errs() << "error: no disassembler for target " << Triple << "\n";
166167 return -1;
167168 }
168169
170 OwningPtr MRI(T.createMCRegInfo(Triple));
171 if (!MRI) {
172 errs() << "error: no register info for target " << Triple << "\n";
173 return -1;
174 }
175
169176 int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
170177 OwningPtr IP(T.createMCInstPrinter(AsmPrinterVariant,
171 *AsmInfo, *STI));
178 *AsmInfo, *MRI, *STI));
172179 if (!IP) {
173180 errs() << "error: no instruction printer for target " << Triple << '\n';
174181 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, *STI);
418 TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *MRI, *STI);
419419 MCCodeEmitter *CE = 0;
420420 MCAsmBackend *MAB = 0;
421421 if (ShowEncoding) {
2525 #include "llvm/MC/MCInstrAnalysis.h"
2626 #include "llvm/MC/MCInstrDesc.h"
2727 #include "llvm/MC/MCInstrInfo.h"
28 #include "llvm/MC/MCRegisterInfo.h"
2829 #include "llvm/MC/MCSubtargetInfo.h"
2930 #include "llvm/Support/CommandLine.h"
3031 #include "llvm/Support/Debug.h"
256257 OwningPtr
257258 STI(TheTarget->createMCSubtargetInfo(TripleName, "", ""));
258259 OwningPtr DisAsm(TheTarget->createMCDisassembler(*STI));
260 OwningPtr MRI(TheTarget->createMCRegInfo(TripleName));
259261 int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
260262 OwningPtr IP(TheTarget->createMCInstPrinter(
261 AsmPrinterVariant, *AsmInfo, *STI));
263 AsmPrinterVariant, *AsmInfo, *MRI, *STI));
262264
263265 if (!InstrAnalysis || !AsmInfo || !STI || !DisAsm || !IP) {
264266 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/MCRegisterInfo.h"
2829 #include "llvm/MC/MCSubtargetInfo.h"
2930 #include "llvm/Support/Casting.h"
3031 #include "llvm/Support/CommandLine.h"
245246 return;
246247 }
247248
249 OwningPtr MRI(TheTarget->createMCRegInfo(TripleName));
250 if (!MRI) {
251 errs() << "error: no register info for target " << TripleName << "\n";
252 return;
253 }
254
248255 int AsmPrinterVariant = AsmInfo->getAssemblerDialect();
249256 OwningPtr IP(TheTarget->createMCInstPrinter(
250 AsmPrinterVariant, *AsmInfo, *STI));
257 AsmPrinterVariant, *AsmInfo, *MRI, *STI));
251258 if (!IP) {
252259 errs() << "error: no instruction printer for target " << TripleName
253260 << '\n';