1Pull in r198028 from upstream llvm trunk (by Venkatraman Govindaraju): 2 3 [Sparc] Add MCInstPrinter implementation for SPARC. 4 5Introduced here: http://svn.freebsd.org/changeset/base/262261 6 7Index: lib/Target/Sparc/InstPrinter/LLVMBuild.txt 8=================================================================== 9--- lib/Target/Sparc/InstPrinter/LLVMBuild.txt 10+++ lib/Target/Sparc/InstPrinter/LLVMBuild.txt 11@@ -0,0 +1,23 @@ 12+;===- ./lib/Target/Sparc/InstPrinter/LLVMBuild.txt -------------*- Conf -*--===; 13+; 14+; The LLVM Compiler Infrastructure 15+; 16+; This file is distributed under the University of Illinois Open Source 17+; License. See LICENSE.TXT for details. 18+; 19+;===------------------------------------------------------------------------===; 20+; 21+; This is an LLVMBuild description file for the components in this subdirectory. 22+; 23+; For more information on the LLVMBuild system, please see: 24+; 25+; http://llvm.org/docs/LLVMBuild.html 26+; 27+;===------------------------------------------------------------------------===; 28+ 29+[component_0] 30+type = Library 31+name = SparcAsmPrinter 32+parent = Sparc 33+required_libraries = MC Support 34+add_to_library_groups = Sparc 35Index: lib/Target/Sparc/InstPrinter/SparcInstPrinter.cpp 36=================================================================== 37--- lib/Target/Sparc/InstPrinter/SparcInstPrinter.cpp 38+++ lib/Target/Sparc/InstPrinter/SparcInstPrinter.cpp 39@@ -0,0 +1,95 @@ 40+//===-- SparcInstPrinter.cpp - Convert Sparc MCInst to assembly syntax -----==// 41+// 42+// The LLVM Compiler Infrastructure 43+// 44+// This file is distributed under the University of Illinois Open Source 45+// License. See LICENSE.TXT for details. 46+// 47+//===----------------------------------------------------------------------===// 48+// 49+// This class prints an Sparc MCInst to a .s file. 50+// 51+//===----------------------------------------------------------------------===// 52+ 53+#define DEBUG_TYPE "asm-printer" 54+#include "SparcInstPrinter.h" 55+ 56+#include "Sparc.h" 57+#include "MCTargetDesc/SparcBaseInfo.h" 58+#include "llvm/MC/MCExpr.h" 59+#include "llvm/MC/MCInst.h" 60+#include "llvm/MC/MCSymbol.h" 61+#include "llvm/Support/raw_ostream.h" 62+using namespace llvm; 63+ 64+#define GET_INSTRUCTION_NAME 65+// Uncomment the following line once we are ready to use MCAsmWriter. 66+//#include "SparcGenAsmWriter.inc" 67+ 68+void SparcInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const 69+{ 70+ OS << '%' << StringRef(getRegisterName(RegNo)).lower(); 71+} 72+ 73+void SparcInstPrinter::printInst(const MCInst *MI, raw_ostream &O, 74+ StringRef Annot) 75+{ 76+ printInstruction(MI, O); 77+ printAnnotation(O, Annot); 78+} 79+ 80+void SparcInstPrinter::printOperand(const MCInst *MI, int opNum, 81+ raw_ostream &O) 82+{ 83+ const MCOperand &MO = MI->getOperand (opNum); 84+ 85+ if (MO.isReg()) { 86+ printRegName(O, MO.getReg()); 87+ return ; 88+ } 89+ 90+ if (MO.isImm()) { 91+ O << (int)MO.getImm(); 92+ return; 93+ } 94+ 95+ assert(MO.isExpr() && "Unknown operand kind in printOperand"); 96+ MO.getExpr()->print(O); 97+} 98+ 99+void SparcInstPrinter::printMemOperand(const MCInst *MI, int opNum, 100+ raw_ostream &O, const char *Modifier) 101+{ 102+ printOperand(MI, opNum, O); 103+ 104+ // If this is an ADD operand, emit it like normal operands. 105+ if (Modifier && !strcmp(Modifier, "arith")) { 106+ O << ", "; 107+ printOperand(MI, opNum+1, O); 108+ return; 109+ } 110+ const MCOperand &MO = MI->getOperand(opNum+1); 111+ 112+ if (MO.isReg() && MO.getReg() == SP::G0) 113+ return; // don't print "+%g0" 114+ if (MO.isImm() && MO.getImm() == 0) 115+ return; // don't print "+0" 116+ 117+ O << "+"; 118+ 119+ printOperand(MI, opNum+1, O); 120+} 121+ 122+void SparcInstPrinter::printCCOperand(const MCInst *MI, int opNum, 123+ raw_ostream &O) 124+{ 125+ int CC = (int)MI->getOperand(opNum).getImm(); 126+ O << SPARCCondCodeToString((SPCC::CondCodes)CC); 127+} 128+ 129+bool SparcInstPrinter::printGetPCX(const MCInst *MI, unsigned opNum, 130+ raw_ostream &O) 131+{ 132+ assert(0 && "FIXME: Implement SparcInstPrinter::printGetPCX."); 133+ return true; 134+} 135Index: lib/Target/Sparc/InstPrinter/CMakeLists.txt 136=================================================================== 137--- lib/Target/Sparc/InstPrinter/CMakeLists.txt 138+++ lib/Target/Sparc/InstPrinter/CMakeLists.txt 139@@ -0,0 +1,3 @@ 140+add_llvm_library(LLVMSparcAsmPrinter 141+ SparcInstPrinter.cpp 142+ ) 143Index: lib/Target/Sparc/InstPrinter/Makefile 144=================================================================== 145--- lib/Target/Sparc/InstPrinter/Makefile 146+++ lib/Target/Sparc/InstPrinter/Makefile 147@@ -0,0 +1,16 @@ 148+##===- lib/Target/Sparc/InstPrinter/Makefile ---------------*- Makefile -*-===## 149+# 150+# The LLVM Compiler Infrastructure 151+# 152+# This file is distributed under the University of Illinois Open Source 153+# License. See LICENSE.TXT for details. 154+# 155+##===----------------------------------------------------------------------===## 156+ 157+LEVEL = ../../../.. 158+LIBRARYNAME = LLVMSparcAsmPrinter 159+ 160+# Hack: we need to include 'main' target directory to grab private headers 161+CPP.Flags += -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/.. 162+ 163+include $(LEVEL)/Makefile.common 164Index: lib/Target/Sparc/InstPrinter/SparcInstPrinter.h 165=================================================================== 166--- lib/Target/Sparc/InstPrinter/SparcInstPrinter.h 167+++ lib/Target/Sparc/InstPrinter/SparcInstPrinter.h 168@@ -0,0 +1,46 @@ 169+//===-- SparcInstPrinter.h - Convert Sparc MCInst to assembly syntax ------===// 170+// 171+// The LLVM Compiler Infrastructure 172+// 173+// This file is distributed under the University of Illinois Open Source 174+// License. See LICENSE.TXT for details. 175+// 176+//===----------------------------------------------------------------------===// 177+// 178+// This class prints an Sparc MCInst to a .s file. 179+// 180+//===----------------------------------------------------------------------===// 181+ 182+#ifndef SparcINSTPRINTER_H 183+#define SparcINSTPRINTER_H 184+ 185+#include "llvm/MC/MCInstPrinter.h" 186+ 187+namespace llvm { 188+ 189+class MCOperand; 190+ 191+class SparcInstPrinter : public MCInstPrinter { 192+public: 193+ SparcInstPrinter(const MCAsmInfo &MAI, 194+ const MCInstrInfo &MII, 195+ const MCRegisterInfo &MRI) 196+ : MCInstPrinter(MAI, MII, MRI) {} 197+ 198+ virtual void printRegName(raw_ostream &OS, unsigned RegNo) const; 199+ virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot); 200+ 201+ // Autogenerated by tblgen. 202+ void printInstruction(const MCInst *MI, raw_ostream &O); 203+ static const char *getRegisterName(unsigned RegNo); 204+ 205+ void printOperand(const MCInst *MI, int opNum, raw_ostream &OS); 206+ void printMemOperand(const MCInst *MI, int opNum, raw_ostream &OS, 207+ const char *Modifier = 0); 208+ void printCCOperand(const MCInst *MI, int opNum, raw_ostream &OS); 209+ bool printGetPCX(const MCInst *MI, unsigned OpNo, raw_ostream &OS); 210+ 211+}; 212+} // end namespace llvm 213+ 214+#endif 215Index: lib/Target/Sparc/LLVMBuild.txt 216=================================================================== 217--- lib/Target/Sparc/LLVMBuild.txt 218+++ lib/Target/Sparc/LLVMBuild.txt 219@@ -16,7 +16,7 @@ 220 ;===------------------------------------------------------------------------===; 221 222 [common] 223-subdirectories = MCTargetDesc TargetInfo 224+subdirectories = InstPrinter MCTargetDesc TargetInfo 225 226 [component_0] 227 type = TargetGroup 228@@ -29,6 +29,6 @@ has_jit = 1 229 type = Library 230 name = SparcCodeGen 231 parent = Sparc 232-required_libraries = AsmPrinter CodeGen Core MC SelectionDAG SparcDesc 233- SparcInfo Support Target 234+required_libraries = AsmPrinter CodeGen Core MC SelectionDAG SparcAsmPrinter 235+ SparcDesc SparcInfo Support Target 236 add_to_library_groups = Sparc 237Index: lib/Target/Sparc/CMakeLists.txt 238=================================================================== 239--- lib/Target/Sparc/CMakeLists.txt 240+++ lib/Target/Sparc/CMakeLists.txt 241@@ -29,3 +29,4 @@ add_dependencies(LLVMSparcCodeGen SparcCommonTable 242 243 add_subdirectory(TargetInfo) 244 add_subdirectory(MCTargetDesc) 245+add_subdirectory(InstPrinter) 246Index: lib/Target/Sparc/Makefile 247=================================================================== 248--- lib/Target/Sparc/Makefile 249+++ lib/Target/Sparc/Makefile 250@@ -17,7 +17,7 @@ BUILT_SOURCES = SparcGenRegisterInfo.inc SparcGenI 251 SparcGenSubtargetInfo.inc SparcGenCallingConv.inc \ 252 SparcGenCodeEmitter.inc 253 254-DIRS = TargetInfo MCTargetDesc 255+DIRS = InstPrinter TargetInfo MCTargetDesc 256 257 include $(LEVEL)/Makefile.common 258 259