blob: 5da669b9d27f280d7e77482bf1dc24395f976aa6 [file] [log] [blame]
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00001//===-- MipsAsmPrinter.cpp - Mips LLVM assembly writer --------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file contains a printer that converts from our internal representation
11// of machine-dependent LLVM code to GAS-format MIPS assembly language.
12//
13//===----------------------------------------------------------------------===//
14
15#define DEBUG_TYPE "mips-asm-printer"
16
17#include "Mips.h"
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +000018#include "MipsSubtarget.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000019#include "MipsInstrInfo.h"
20#include "MipsTargetMachine.h"
Bruno Cardoso Lopesbcda5e22007-07-11 23:24:41 +000021#include "MipsMachineFunction.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000022#include "llvm/CodeGen/AsmPrinter.h"
Bill Wendling0f4c5812009-02-18 23:12:06 +000023#include "llvm/CodeGen/DwarfWriter.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000024#include "llvm/CodeGen/MachineFunctionPass.h"
25#include "llvm/CodeGen/MachineConstantPool.h"
Bruno Cardoso Lopesbcda5e22007-07-11 23:24:41 +000026#include "llvm/CodeGen/MachineFrameInfo.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000027#include "llvm/CodeGen/MachineInstr.h"
Chris Lattner4b7dadb2009-08-19 05:49:37 +000028#include "llvm/MC/MCStreamer.h"
Chris Lattner7b26fce2009-08-22 20:48:53 +000029#include "llvm/MC/MCAsmInfo.h"
Chris Lattner4cd44982009-09-13 17:14:04 +000030#include "llvm/MC/MCSymbol.h"
Chris Lattner0b822ab2010-03-12 21:19:23 +000031#include "llvm/Target/Mangler.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000032#include "llvm/Target/TargetData.h"
Chris Lattner5e693ed2009-07-28 03:13:23 +000033#include "llvm/Target/TargetLoweringObjectFile.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000034#include "llvm/Target/TargetMachine.h"
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +000035#include "llvm/Target/TargetOptions.h"
Daniel Dunbare8338102009-07-15 20:24:03 +000036#include "llvm/Target/TargetRegistry.h"
Chris Lattner3d86cd62010-04-04 06:12:20 +000037#include "llvm/ADT/SmallString.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000038#include "llvm/ADT/StringExtras.h"
Chris Lattnerd20699b2010-04-04 08:18:47 +000039#include "llvm/ADT/Twine.h"
40#include "llvm/Support/raw_ostream.h"
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000041using namespace llvm;
42
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000043namespace {
Nick Lewycky02d5f772009-10-25 06:33:48 +000044 class MipsAsmPrinter : public AsmPrinter {
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +000045 const MipsSubtarget *Subtarget;
Bill Wendlingc5437ea2009-02-24 08:30:20 +000046 public:
Chris Lattnerd20699b2010-04-04 08:18:47 +000047 explicit MipsAsmPrinter(TargetMachine &TM, MCStreamer &Streamer)
48 : AsmPrinter(TM, Streamer) {
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +000049 Subtarget = &TM.getSubtarget<MipsSubtarget>();
50 }
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000051
52 virtual const char *getPassName() const {
53 return "Mips Assembly Printer";
54 }
55
Bruno Cardoso Lopes3d4bdcc2008-08-02 19:42:36 +000056 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Chris Lattner3bb09762010-04-04 05:29:35 +000057 unsigned AsmVariant, const char *ExtraCode,
58 raw_ostream &O);
Chris Lattner76c564b2010-04-04 04:47:45 +000059 void printOperand(const MachineInstr *MI, int opNum, raw_ostream &O);
60 void printUnsignedImm(const MachineInstr *MI, int opNum, raw_ostream &O);
61 void printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000062 const char *Modifier = 0);
Chris Lattner76c564b2010-04-04 04:47:45 +000063 void printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +000064 const char *Modifier = 0);
Chris Lattner76c564b2010-04-04 04:47:45 +000065 void printSavedRegsBitmask(raw_ostream &O);
66 void printHex32(unsigned int Value, raw_ostream &O);
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +000067
Chris Lattner5e596182010-04-04 07:05:53 +000068 const char *getCurrentABIString() const;
69 void emitFrameDirective();
Anton Korobeynikovbb247912008-07-19 13:16:11 +000070
Chris Lattner76c564b2010-04-04 04:47:45 +000071 void printInstruction(const MachineInstr *MI, raw_ostream &O); // autogen'd.
Chris Lattner996ec842010-02-03 01:09:55 +000072 void EmitInstruction(const MachineInstr *MI) {
Chris Lattner3d86cd62010-04-04 06:12:20 +000073 SmallString<128> Str;
74 raw_svector_ostream OS(Str);
75 printInstruction(MI, OS);
76 OutStreamer.EmitRawText(OS.str());
Chris Lattner996ec842010-02-03 01:09:55 +000077 }
Chris Lattnercc9a6f02010-01-28 06:22:43 +000078 virtual void EmitFunctionBodyStart();
79 virtual void EmitFunctionBodyEnd();
Chris Lattnerad10b3b2009-09-13 20:19:22 +000080 static const char *getRegisterName(unsigned RegNo);
Chris Lattner06c5eed2009-09-13 20:08:00 +000081
Chris Lattner5d9fb4b2010-01-27 23:23:58 +000082 virtual void EmitFunctionEntryLabel();
Bob Wilsonb633d7a2009-09-30 22:06:26 +000083 void EmitStartOfAsmFile(Module &M);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +000084 };
85} // end of anonymous namespace
86
87#include "MipsGenAsmWriter.inc"
88
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +000089//===----------------------------------------------------------------------===//
90//
91// Mips Asm Directives
92//
93// -- Frame directive "frame Stackpointer, Stacksize, RARegister"
94// Describe the stack frame.
95//
96// -- Mask directives "(f)mask bitmask, offset"
97// Tells the assembler which registers are saved and where.
98// bitmask - contain a little endian bitset indicating which registers are
99// saved on function prologue (e.g. with a 0x80000000 mask, the
100// assembler knows the register 31 (RA) is saved at prologue.
101// offset - the position before stack pointer subtraction indicating where
102// the first saved register on prologue is located. (e.g. with a
103//
104// Consider the following function prologue:
105//
Bill Wendling97925ec2008-02-27 06:33:05 +0000106// .frame $fp,48,$ra
107// .mask 0xc0000000,-8
108// addiu $sp, $sp, -48
109// sw $ra, 40($sp)
110// sw $fp, 36($sp)
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000111//
112// With a 0xc0000000 mask, the assembler knows the register 31 (RA) and
113// 30 (FP) are saved at prologue. As the save order on prologue is from
114// left to right, RA is saved first. A -8 offset means that after the
115// stack pointer subtration, the first register in the mask (RA) will be
116// saved at address 48-8=40.
117//
118//===----------------------------------------------------------------------===//
119
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000120//===----------------------------------------------------------------------===//
121// Mask directives
122//===----------------------------------------------------------------------===//
123
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000124// Create a bitmask with all callee saved registers for CPU or Floating Point
125// registers. For CPU registers consider RA, GP and FP for saving if necessary.
Chris Lattner76c564b2010-04-04 04:47:45 +0000126void MipsAsmPrinter::printSavedRegsBitmask(raw_ostream &O) {
Dan Gohman3a4be0f2008-02-10 18:45:23 +0000127 const TargetRegisterInfo &RI = *TM.getRegisterInfo();
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000128 const MipsFunctionInfo *MipsFI = MF->getInfo<MipsFunctionInfo>();
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000129
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000130 // CPU and FPU Saved Registers Bitmasks
131 unsigned int CPUBitmask = 0;
132 unsigned int FPUBitmask = 0;
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000133
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000134 // Set the CPU and FPU Bitmasks
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000135 const MachineFrameInfo *MFI = MF->getFrameInfo();
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000136 const std::vector<CalleeSavedInfo> &CSI = MFI->getCalleeSavedInfo();
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000137 for (unsigned i = 0, e = CSI.size(); i != e; ++i) {
138 unsigned RegNum = MipsRegisterInfo::getRegisterNumbering(CSI[i].getReg());
139 if (CSI[i].getRegClass() == Mips::CPURegsRegisterClass)
140 CPUBitmask |= (1 << RegNum);
141 else
142 FPUBitmask |= (1 << RegNum);
143 }
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000144
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000145 // Return Address and Frame registers must also be set in CPUBitmask.
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000146 if (RI.hasFP(*MF))
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000147 CPUBitmask |= (1 << MipsRegisterInfo::
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000148 getRegisterNumbering(RI.getFrameRegister(*MF)));
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000149
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000150 if (MFI->hasCalls())
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000151 CPUBitmask |= (1 << MipsRegisterInfo::
Bruno Cardoso Lopes35d86e62007-10-09 03:01:19 +0000152 getRegisterNumbering(RI.getRARegister()));
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000153
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000154 // Print CPUBitmask
Chris Lattner76c564b2010-04-04 04:47:45 +0000155 O << "\t.mask \t"; printHex32(CPUBitmask, O);
156 O << ',' << MipsFI->getCPUTopSavedRegOff() << '\n';
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000157
158 // Print FPUBitmask
Chris Lattner76c564b2010-04-04 04:47:45 +0000159 O << "\t.fmask\t"; printHex32(FPUBitmask, O); O << ","
Bruno Cardoso Lopes4659aad2008-08-06 06:14:43 +0000160 << MipsFI->getFPUTopSavedRegOff() << '\n';
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000161}
162
163// Print a 32 bit hex number with all numbers.
Chris Lattner76c564b2010-04-04 04:47:45 +0000164void MipsAsmPrinter::printHex32(unsigned Value, raw_ostream &O) {
Owen Anderson93719642008-08-21 00:14:44 +0000165 O << "0x";
Bruno Cardoso Lopescfd16382007-08-28 05:06:17 +0000166 for (int i = 7; i >= 0; i--)
Chris Lattner76c564b2010-04-04 04:47:45 +0000167 O << utohexstr((Value & (0xF << (i*4))) >> (i*4));
Bruno Cardoso Lopesbcda5e22007-07-11 23:24:41 +0000168}
169
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000170//===----------------------------------------------------------------------===//
171// Frame and Set directives
172//===----------------------------------------------------------------------===//
173
174/// Frame Directive
Chris Lattner5e596182010-04-04 07:05:53 +0000175void MipsAsmPrinter::emitFrameDirective() {
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000176 const TargetRegisterInfo &RI = *TM.getRegisterInfo();
177
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000178 unsigned stackReg = RI.getFrameRegister(*MF);
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000179 unsigned returnReg = RI.getRARegister();
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000180 unsigned stackSize = MF->getFrameInfo()->getStackSize();
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000181
Chris Lattner5e596182010-04-04 07:05:53 +0000182 OutStreamer.EmitRawText("\t.frame\t$" +
183 Twine(LowercaseString(getRegisterName(stackReg))) +
184 "," + Twine(stackSize) + ",$" +
185 Twine(LowercaseString(getRegisterName(returnReg))));
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000186}
187
188/// Emit Set directives.
Chris Lattner5e596182010-04-04 07:05:53 +0000189const char *MipsAsmPrinter::getCurrentABIString() const {
190 switch (Subtarget->getTargetABI()) {
191 case MipsSubtarget::O32: return "abi32";
192 case MipsSubtarget::O64: return "abiO64";
193 case MipsSubtarget::N32: return "abiN32";
194 case MipsSubtarget::N64: return "abi64";
195 case MipsSubtarget::EABI: return "eabi32"; // TODO: handle eabi64
196 default: break;
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000197 }
198
Torok Edwinfbcc6632009-07-14 16:55:14 +0000199 llvm_unreachable("Unknown Mips ABI");
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000200 return NULL;
201}
202
Chris Lattner5d9fb4b2010-01-27 23:23:58 +0000203void MipsAsmPrinter::EmitFunctionEntryLabel() {
Chris Lattner5e596182010-04-04 07:05:53 +0000204 OutStreamer.EmitRawText("\t.ent\t" + Twine(CurrentFnSym->getName()));
Chris Lattner5d9fb4b2010-01-27 23:23:58 +0000205 OutStreamer.EmitLabel(CurrentFnSym);
206}
207
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000208/// EmitFunctionBodyStart - Targets can override this to emit stuff before
209/// the first basic block in the function.
210void MipsAsmPrinter::EmitFunctionBodyStart() {
Chris Lattner5e596182010-04-04 07:05:53 +0000211 emitFrameDirective();
212
213 SmallString<128> Str;
214 raw_svector_ostream OS(Str);
215 printSavedRegsBitmask(OS);
216 OutStreamer.EmitRawText(OS.str());
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000217}
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000218
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000219/// EmitFunctionBodyEnd - Targets can override this to emit stuff after
220/// the last basic block in the function.
221void MipsAsmPrinter::EmitFunctionBodyEnd() {
Chris Lattnerfd97a332010-01-28 01:48:52 +0000222 // There are instruction for this macros, but they must
223 // always be at the function end, and we can't emit and
224 // break with BB logic.
Chris Lattner5e596182010-04-04 07:05:53 +0000225 OutStreamer.EmitRawText(StringRef("\t.set\tmacro"));
226 OutStreamer.EmitRawText(StringRef("\t.set\treorder"));
227 OutStreamer.EmitRawText("\t.end\t" + Twine(CurrentFnSym->getName()));
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000228}
229
Chris Lattnercc9a6f02010-01-28 06:22:43 +0000230
Bruno Cardoso Lopes3d4bdcc2008-08-02 19:42:36 +0000231// Print out an operand for an inline asm expression.
Chris Lattner50343292009-07-29 05:09:30 +0000232bool MipsAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Chris Lattner3bb09762010-04-04 05:29:35 +0000233 unsigned AsmVariant,const char *ExtraCode,
234 raw_ostream &O) {
Bruno Cardoso Lopes3d4bdcc2008-08-02 19:42:36 +0000235 // Does this asm operand have a single letter operand modifier?
236 if (ExtraCode && ExtraCode[0])
237 return true; // Unknown modifier.
238
Chris Lattner76c564b2010-04-04 04:47:45 +0000239 printOperand(MI, OpNo, O);
Bruno Cardoso Lopes3d4bdcc2008-08-02 19:42:36 +0000240 return false;
241}
242
Chris Lattner76c564b2010-04-04 04:47:45 +0000243void MipsAsmPrinter::printOperand(const MachineInstr *MI, int opNum,
244 raw_ostream &O) {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000245 const MachineOperand &MO = MI->getOperand(opNum);
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +0000246 bool closeP = false;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000247
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000248 if (MO.getTargetFlags())
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000249 closeP = true;
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000250
251 switch(MO.getTargetFlags()) {
252 case MipsII::MO_GPREL: O << "%gp_rel("; break;
253 case MipsII::MO_GOT_CALL: O << "%call16("; break;
254 case MipsII::MO_GOT:
255 if (MI->getOpcode() == Mips::LW)
256 O << "%got(";
Bruno Cardoso Lopese5d1fcf2008-07-21 18:52:34 +0000257 else
258 O << "%lo(";
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000259 break;
260 case MipsII::MO_ABS_HILO:
261 if (MI->getOpcode() == Mips::LUi)
262 O << "%hi(";
263 else
264 O << "%lo(";
265 break;
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000266 }
Bruno Cardoso Lopes0f20a5b2009-09-01 17:27:58 +0000267
Chris Lattnereb2cc682009-09-13 20:31:40 +0000268 switch (MO.getType()) {
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000269 case MachineOperand::MO_Register:
Chris Lattnereb2cc682009-09-13 20:31:40 +0000270 O << '$' << LowercaseString(getRegisterName(MO.getReg()));
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000271 break;
272
273 case MachineOperand::MO_Immediate:
Bruno Cardoso Lopes92c64ae2008-08-13 07:13:40 +0000274 O << (short int)MO.getImm();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000275 break;
276
277 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner29bdac42010-03-13 21:04:28 +0000278 O << *MO.getMBB()->getSymbol();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000279 return;
280
281 case MachineOperand::MO_GlobalAddress:
Chris Lattner0b822ab2010-03-12 21:19:23 +0000282 O << *Mang->getSymbol(MO.getGlobal());
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000283 break;
284
285 case MachineOperand::MO_ExternalSymbol:
Chris Lattner8b5d55e2010-01-17 21:43:43 +0000286 O << *GetExternalSymbolSymbol(MO.getSymbolName());
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000287 break;
288
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +0000289 case MachineOperand::MO_JumpTableIndex:
Chris Lattnere9a75a62009-08-22 21:43:10 +0000290 O << MAI->getPrivateGlobalPrefix() << "JTI" << getFunctionNumber()
Chris Lattner719e9082010-01-16 00:21:18 +0000291 << '_' << MO.getIndex();
Bruno Cardoso Lopesb4391322007-11-12 19:49:57 +0000292 break;
293
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000294 case MachineOperand::MO_ConstantPoolIndex:
Chris Lattnere9a75a62009-08-22 21:43:10 +0000295 O << MAI->getPrivateGlobalPrefix() << "CPI"
Chris Lattnera5bb3702007-12-30 23:10:15 +0000296 << getFunctionNumber() << "_" << MO.getIndex();
Bruno Cardoso Lopes4713b282009-11-19 06:06:13 +0000297 if (MO.getOffset())
298 O << "+" << MO.getOffset();
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000299 break;
300
301 default:
Torok Edwinfbcc6632009-07-14 16:55:14 +0000302 llvm_unreachable("<unknown operand type>");
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000303 }
304
305 if (closeP) O << ")";
306}
307
Chris Lattner76c564b2010-04-04 04:47:45 +0000308void MipsAsmPrinter::printUnsignedImm(const MachineInstr *MI, int opNum,
309 raw_ostream &O) {
Bruno Cardoso Lopes92c64ae2008-08-13 07:13:40 +0000310 const MachineOperand &MO = MI->getOperand(opNum);
311 if (MO.getType() == MachineOperand::MO_Immediate)
312 O << (unsigned short int)MO.getImm();
313 else
Chris Lattner76c564b2010-04-04 04:47:45 +0000314 printOperand(MI, opNum, O);
Bruno Cardoso Lopes92c64ae2008-08-13 07:13:40 +0000315}
316
317void MipsAsmPrinter::
Chris Lattner76c564b2010-04-04 04:47:45 +0000318printMemOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
319 const char *Modifier) {
Bruno Cardoso Lopes6d5ada22007-09-24 20:15:11 +0000320 // when using stack locations for not load/store instructions
321 // print the same way as all normal 3 operand instructions.
322 if (Modifier && !strcmp(Modifier, "stackloc")) {
Chris Lattner76c564b2010-04-04 04:47:45 +0000323 printOperand(MI, opNum+1, O);
Bruno Cardoso Lopes6d5ada22007-09-24 20:15:11 +0000324 O << ", ";
Chris Lattner76c564b2010-04-04 04:47:45 +0000325 printOperand(MI, opNum, O);
Bruno Cardoso Lopes6d5ada22007-09-24 20:15:11 +0000326 return;
327 }
328
Bruno Cardoso Lopes3e0d0302007-11-05 03:02:32 +0000329 // Load/Store memory operands -- imm($reg)
330 // If PIC target the target is loaded as the
331 // pattern lw $25,%call16($28)
Chris Lattner76c564b2010-04-04 04:47:45 +0000332 printOperand(MI, opNum, O);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000333 O << "(";
Chris Lattner76c564b2010-04-04 04:47:45 +0000334 printOperand(MI, opNum+1, O);
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000335 O << ")";
336}
337
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000338void MipsAsmPrinter::
Chris Lattner76c564b2010-04-04 04:47:45 +0000339printFCCOperand(const MachineInstr *MI, int opNum, raw_ostream &O,
340 const char *Modifier) {
Bruno Cardoso Lopesc9c3f492008-07-05 19:05:21 +0000341 const MachineOperand& MO = MI->getOperand(opNum);
342 O << Mips::MipsFCCToString((Mips::CondCode)MO.getImm());
343}
344
Bob Wilsonb633d7a2009-09-30 22:06:26 +0000345void MipsAsmPrinter::EmitStartOfAsmFile(Module &M) {
Chris Lattner4b7dadb2009-08-19 05:49:37 +0000346 // FIXME: Use SwitchSection.
Chris Lattner767e90ef2009-07-21 17:39:48 +0000347
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000348 // Tell the assembler which ABI we are using
Chris Lattner5e596182010-04-04 07:05:53 +0000349 OutStreamer.EmitRawText("\t.section .mdebug." + Twine(getCurrentABIString()));
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000350
351 // TODO: handle O64 ABI
352 if (Subtarget->isABI_EABI())
Chris Lattner5e596182010-04-04 07:05:53 +0000353 if (Subtarget->isGP32bit())
354 OutStreamer.EmitRawText(StringRef("\t.section .gcc_compiled_long32"));
355 else
356 OutStreamer.EmitRawText(StringRef("\t.section .gcc_compiled_long64"));
Bruno Cardoso Lopes80ab8f92008-07-14 14:42:54 +0000357
358 // return to previous section
Chris Lattner5e596182010-04-04 07:05:53 +0000359 OutStreamer.EmitRawText(StringRef("\t.previous"));
Bruno Cardoso Lopes35e43c42007-06-06 07:42:06 +0000360}
361
Bob Wilson5a495fe2009-06-23 23:59:40 +0000362// Force static initialization.
Daniel Dunbare8338102009-07-15 20:24:03 +0000363extern "C" void LLVMInitializeMipsAsmPrinter() {
Daniel Dunbar5680b4f2009-07-25 06:49:55 +0000364 RegisterAsmPrinter<MipsAsmPrinter> X(TheMipsTarget);
365 RegisterAsmPrinter<MipsAsmPrinter> Y(TheMipselTarget);
Daniel Dunbare8338102009-07-15 20:24:03 +0000366}