1 Pull in r198028 from upstream llvm trunk (by Venkatraman Govindaraju):
3 [Sparc] Add MCInstPrinter implementation for SPARC.
5 Introduced here: http://svnweb.freebsd.org/changeset/base/262261
7 Index: lib/Target/Sparc/InstPrinter/LLVMBuild.txt
8 ===================================================================
9 --- lib/Target/Sparc/InstPrinter/LLVMBuild.txt
10 +++ lib/Target/Sparc/InstPrinter/LLVMBuild.txt
12 +;===- ./lib/Target/Sparc/InstPrinter/LLVMBuild.txt -------------*- Conf -*--===;
14 +; The LLVM Compiler Infrastructure
16 +; This file is distributed under the University of Illinois Open Source
17 +; License. See LICENSE.TXT for details.
19 +;===------------------------------------------------------------------------===;
21 +; This is an LLVMBuild description file for the components in this subdirectory.
23 +; For more information on the LLVMBuild system, please see:
25 +; http://llvm.org/docs/LLVMBuild.html
27 +;===------------------------------------------------------------------------===;
31 +name = SparcAsmPrinter
33 +required_libraries = MC Support
34 +add_to_library_groups = Sparc
35 Index: lib/Target/Sparc/InstPrinter/SparcInstPrinter.cpp
36 ===================================================================
37 --- lib/Target/Sparc/InstPrinter/SparcInstPrinter.cpp
38 +++ lib/Target/Sparc/InstPrinter/SparcInstPrinter.cpp
40 +//===-- SparcInstPrinter.cpp - Convert Sparc MCInst to assembly syntax -----==//
42 +// The LLVM Compiler Infrastructure
44 +// This file is distributed under the University of Illinois Open Source
45 +// License. See LICENSE.TXT for details.
47 +//===----------------------------------------------------------------------===//
49 +// This class prints an Sparc MCInst to a .s file.
51 +//===----------------------------------------------------------------------===//
53 +#define DEBUG_TYPE "asm-printer"
54 +#include "SparcInstPrinter.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;
64 +#define GET_INSTRUCTION_NAME
65 +// Uncomment the following line once we are ready to use MCAsmWriter.
66 +//#include "SparcGenAsmWriter.inc"
68 +void SparcInstPrinter::printRegName(raw_ostream &OS, unsigned RegNo) const
70 + OS << '%' << StringRef(getRegisterName(RegNo)).lower();
73 +void SparcInstPrinter::printInst(const MCInst *MI, raw_ostream &O,
76 + printInstruction(MI, O);
77 + printAnnotation(O, Annot);
80 +void SparcInstPrinter::printOperand(const MCInst *MI, int opNum,
83 + const MCOperand &MO = MI->getOperand (opNum);
86 + printRegName(O, MO.getReg());
91 + O << (int)MO.getImm();
95 + assert(MO.isExpr() && "Unknown operand kind in printOperand");
96 + MO.getExpr()->print(O);
99 +void SparcInstPrinter::printMemOperand(const MCInst *MI, int opNum,
100 + raw_ostream &O, const char *Modifier)
102 + printOperand(MI, opNum, O);
104 + // If this is an ADD operand, emit it like normal operands.
105 + if (Modifier && !strcmp(Modifier, "arith")) {
107 + printOperand(MI, opNum+1, O);
110 + const MCOperand &MO = MI->getOperand(opNum+1);
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"
119 + printOperand(MI, opNum+1, O);
122 +void SparcInstPrinter::printCCOperand(const MCInst *MI, int opNum,
125 + int CC = (int)MI->getOperand(opNum).getImm();
126 + O << SPARCCondCodeToString((SPCC::CondCodes)CC);
129 +bool SparcInstPrinter::printGetPCX(const MCInst *MI, unsigned opNum,
132 + assert(0 && "FIXME: Implement SparcInstPrinter::printGetPCX.");
135 Index: lib/Target/Sparc/InstPrinter/CMakeLists.txt
136 ===================================================================
137 --- lib/Target/Sparc/InstPrinter/CMakeLists.txt
138 +++ lib/Target/Sparc/InstPrinter/CMakeLists.txt
140 +add_llvm_library(LLVMSparcAsmPrinter
141 + SparcInstPrinter.cpp
143 Index: lib/Target/Sparc/InstPrinter/Makefile
144 ===================================================================
145 --- lib/Target/Sparc/InstPrinter/Makefile
146 +++ lib/Target/Sparc/InstPrinter/Makefile
148 +##===- lib/Target/Sparc/InstPrinter/Makefile ---------------*- Makefile -*-===##
150 +# The LLVM Compiler Infrastructure
152 +# This file is distributed under the University of Illinois Open Source
153 +# License. See LICENSE.TXT for details.
155 +##===----------------------------------------------------------------------===##
158 +LIBRARYNAME = LLVMSparcAsmPrinter
160 +# Hack: we need to include 'main' target directory to grab private headers
161 +CPP.Flags += -I$(PROJ_OBJ_DIR)/.. -I$(PROJ_SRC_DIR)/..
163 +include $(LEVEL)/Makefile.common
164 Index: lib/Target/Sparc/InstPrinter/SparcInstPrinter.h
165 ===================================================================
166 --- lib/Target/Sparc/InstPrinter/SparcInstPrinter.h
167 +++ lib/Target/Sparc/InstPrinter/SparcInstPrinter.h
169 +//===-- SparcInstPrinter.h - Convert Sparc MCInst to assembly syntax ------===//
171 +// The LLVM Compiler Infrastructure
173 +// This file is distributed under the University of Illinois Open Source
174 +// License. See LICENSE.TXT for details.
176 +//===----------------------------------------------------------------------===//
178 +// This class prints an Sparc MCInst to a .s file.
180 +//===----------------------------------------------------------------------===//
182 +#ifndef SparcINSTPRINTER_H
183 +#define SparcINSTPRINTER_H
185 +#include "llvm/MC/MCInstPrinter.h"
191 +class SparcInstPrinter : public MCInstPrinter {
193 + SparcInstPrinter(const MCAsmInfo &MAI,
194 + const MCInstrInfo &MII,
195 + const MCRegisterInfo &MRI)
196 + : MCInstPrinter(MAI, MII, MRI) {}
198 + virtual void printRegName(raw_ostream &OS, unsigned RegNo) const;
199 + virtual void printInst(const MCInst *MI, raw_ostream &O, StringRef Annot);
201 + // Autogenerated by tblgen.
202 + void printInstruction(const MCInst *MI, raw_ostream &O);
203 + static const char *getRegisterName(unsigned RegNo);
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);
212 +} // end namespace llvm
215 Index: lib/Target/Sparc/LLVMBuild.txt
216 ===================================================================
217 --- lib/Target/Sparc/LLVMBuild.txt
218 +++ lib/Target/Sparc/LLVMBuild.txt
220 ;===------------------------------------------------------------------------===;
223 -subdirectories = MCTargetDesc TargetInfo
224 +subdirectories = InstPrinter MCTargetDesc TargetInfo
228 @@ -29,6 +29,6 @@ has_jit = 1
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
237 Index: 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
243 add_subdirectory(TargetInfo)
244 add_subdirectory(MCTargetDesc)
245 +add_subdirectory(InstPrinter)
246 Index: 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
254 -DIRS = TargetInfo MCTargetDesc
255 +DIRS = InstPrinter TargetInfo MCTargetDesc
257 include $(LEVEL)/Makefile.common