blob: 3247cecc9785781e44772d05bfe3b23b0d90b9ad [file] [log] [blame]
Chris Lattner7c90f732006-02-05 05:50:24 +00001//===-- SparcAsmPrinter.cpp - Sparc LLVM assembly writer ------------------===//
Misha Brukmanb5f662f2005-04-21 23:30:14 +00002//
Brian Gaeke4acfd032004-03-04 06:00:41 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanb5f662f2005-04-21 23:30:14 +00007//
Brian Gaeke4acfd032004-03-04 06:00:41 +00008//===----------------------------------------------------------------------===//
9//
10// This file contains a printer that converts from our internal representation
Chris Lattner7c90f732006-02-05 05:50:24 +000011// of machine-dependent LLVM code to GAS-format SPARC assembly language.
Brian Gaeke4acfd032004-03-04 06:00:41 +000012//
13//===----------------------------------------------------------------------===//
14
Chris Lattner95b2c7d2006-12-19 22:59:26 +000015#define DEBUG_TYPE "asm-printer"
Chris Lattner7c90f732006-02-05 05:50:24 +000016#include "Sparc.h"
17#include "SparcInstrInfo.h"
Chris Lattner225503a2009-06-19 15:48:10 +000018#include "SparcTargetMachine.h"
Brian Gaeke4acfd032004-03-04 06:00:41 +000019#include "llvm/Constants.h"
20#include "llvm/DerivedTypes.h"
21#include "llvm/Module.h"
Devang Patele4c0c0f2009-06-25 00:47:42 +000022#include "llvm/MDNode.h"
Chris Lattner1dbed162005-12-17 07:04:29 +000023#include "llvm/CodeGen/AsmPrinter.h"
Bill Wendlingcb819f12009-02-18 23:12:06 +000024#include "llvm/CodeGen/DwarfWriter.h"
Brian Gaeke4acfd032004-03-04 06:00:41 +000025#include "llvm/CodeGen/MachineFunctionPass.h"
26#include "llvm/CodeGen/MachineConstantPool.h"
27#include "llvm/CodeGen/MachineInstr.h"
Jim Laskey563321a2006-09-06 18:34:40 +000028#include "llvm/Target/TargetAsmInfo.h"
Daniel Dunbar51b198a2009-07-15 20:24:03 +000029#include "llvm/Target/TargetRegistry.h"
Torok Edwin804e0fe2009-07-08 19:04:27 +000030#include "llvm/Support/ErrorHandling.h"
David Greene71847812009-07-14 20:18:05 +000031#include "llvm/Support/FormattedStream.h"
Brian Gaeke4acfd032004-03-04 06:00:41 +000032#include "llvm/Support/Mangler.h"
Brian Gaeke74dfcf12004-09-02 02:37:43 +000033#include "llvm/ADT/Statistic.h"
34#include "llvm/ADT/StringExtras.h"
35#include "llvm/Support/CommandLine.h"
Jim Laskeyb8df7c22005-08-17 20:04:34 +000036#include "llvm/Support/MathExtras.h"
Brian Gaekea8b00ca2004-03-06 05:30:21 +000037#include <cctype>
Anton Korobeynikovae9f3a32008-02-20 11:08:44 +000038#include <cstring>
Owen Andersonc0078482008-07-10 01:44:27 +000039#include <map>
Brian Gaeke4acfd032004-03-04 06:00:41 +000040using namespace llvm;
41
Chris Lattner95b2c7d2006-12-19 22:59:26 +000042STATISTIC(EmittedInsts, "Number of machine instrs printed");
Brian Gaeke4acfd032004-03-04 06:00:41 +000043
Chris Lattner95b2c7d2006-12-19 22:59:26 +000044namespace {
Bill Wendling57f0db82009-02-24 08:30:20 +000045 class VISIBILITY_HIDDEN SparcAsmPrinter : public AsmPrinter {
Brian Gaeke4acfd032004-03-04 06:00:41 +000046 /// We name each basic block in a Function with a unique number, so
47 /// that we can consistently refer to them later. This is cleared
48 /// at the beginning of each call to runOnMachineFunction().
49 ///
50 typedef std::map<const Value *, unsigned> ValueMapTy;
51 ValueMapTy NumberForBB;
Owen Anderson2af72d42009-06-26 21:45:04 +000052 unsigned BBNumber;
Bill Wendling57f0db82009-02-24 08:30:20 +000053 public:
David Greene71847812009-07-14 20:18:05 +000054 explicit SparcAsmPrinter(formatted_raw_ostream &O, TargetMachine &TM,
Daniel Dunbar5bcc8bd2009-07-01 01:48:54 +000055 const TargetAsmInfo *T, bool V)
56 : AsmPrinter(O, TM, T, V), BBNumber(0) {}
Brian Gaeke4acfd032004-03-04 06:00:41 +000057
Brian Gaeke4acfd032004-03-04 06:00:41 +000058 virtual const char *getPassName() const {
Chris Lattner7c90f732006-02-05 05:50:24 +000059 return "Sparc Assembly Printer";
Brian Gaeke4acfd032004-03-04 06:00:41 +000060 }
61
Anton Korobeynikov5b794b92008-08-07 09:51:25 +000062 void printModuleLevelGV(const GlobalVariable* GVar);
Brian Gaeke446ae112004-06-15 19:52:59 +000063 void printOperand(const MachineInstr *MI, int opNum);
Chris Lattnerad7a3e62006-02-10 07:35:42 +000064 void printMemOperand(const MachineInstr *MI, int opNum,
65 const char *Modifier = 0);
Chris Lattner7c90f732006-02-05 05:50:24 +000066 void printCCOperand(const MachineInstr *MI, int opNum);
Chris Lattner6788faa2006-01-31 06:49:09 +000067
Chris Lattner994b7352005-12-16 06:34:17 +000068 bool printInstruction(const MachineInstr *MI); // autogenerated.
Misha Brukmanb5f662f2005-04-21 23:30:14 +000069 bool runOnMachineFunction(MachineFunction &F);
Brian Gaeke4acfd032004-03-04 06:00:41 +000070 bool doInitialization(Module &M);
71 bool doFinalization(Module &M);
Anton Korobeynikovf3693302008-10-10 10:15:03 +000072 bool PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
73 unsigned AsmVariant, const char *ExtraCode);
74 bool PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
75 unsigned AsmVariant, const char *ExtraCode);
Brian Gaeke4acfd032004-03-04 06:00:41 +000076 };
77} // end of anonymous namespace
78
Chris Lattner7c90f732006-02-05 05:50:24 +000079#include "SparcGenAsmWriter.inc"
Chris Lattner994b7352005-12-16 06:34:17 +000080
Chris Lattner7c90f732006-02-05 05:50:24 +000081/// createSparcCodePrinterPass - Returns a pass that prints the SPARC
Brian Gaeke4acfd032004-03-04 06:00:41 +000082/// assembly code for a MachineFunction to the given output stream,
83/// using the given target machine description. This should work
84/// regardless of whether the function is in SSA form.
85///
David Greene71847812009-07-14 20:18:05 +000086FunctionPass *llvm::createSparcCodePrinterPass(formatted_raw_ostream &o,
Bill Wendling57f0db82009-02-24 08:30:20 +000087 TargetMachine &tm,
Bill Wendlingbe8cc2a2009-04-29 00:15:41 +000088 bool verbose) {
Daniel Dunbar5bcc8bd2009-07-01 01:48:54 +000089 return new SparcAsmPrinter(o, tm, tm.getTargetAsmInfo(), verbose);
Brian Gaeke4acfd032004-03-04 06:00:41 +000090}
91
Chris Lattner225503a2009-06-19 15:48:10 +000092
Evan Cheng4eecdeb2008-02-02 08:39:46 +000093/// runOnMachineFunction - This uses the printInstruction()
Brian Gaeke4acfd032004-03-04 06:00:41 +000094/// method to print assembly for each instruction.
95///
Chris Lattner7c90f732006-02-05 05:50:24 +000096bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Bill Wendling57f0db82009-02-24 08:30:20 +000097 this->MF = &MF;
98
Chris Lattner1dbed162005-12-17 07:04:29 +000099 SetupMachineFunction(MF);
100
Chris Lattnerb5e9eb62005-12-17 07:11:43 +0000101 // Print out constants referenced by the function
102 EmitConstantPool(MF.getConstantPool());
103
Brian Gaeke4acfd032004-03-04 06:00:41 +0000104 // BBNumber is used here so that a given Printer will never give two
105 // BBs the same name. (If you have a better way, please let me know!)
Brian Gaeke4acfd032004-03-04 06:00:41 +0000106
107 O << "\n\n";
Brian Gaeke4acfd032004-03-04 06:00:41 +0000108
Chris Lattner29bd9e12006-10-05 02:48:40 +0000109 // Print out the label for the function.
110 const Function *F = MF.getFunction();
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000111 SwitchToSection(TAI->SectionForGlobal(F));
Bill Wendling20c568f2009-06-30 22:38:32 +0000112 EmitAlignment(MF.getAlignment(), F);
Anton Korobeynikov2a166e92008-08-07 09:53:13 +0000113 O << "\t.globl\t" << CurrentFnName << '\n';
Anton Korobeynikovf5b6a472008-08-08 18:25:07 +0000114
115 printVisibility(CurrentFnName, F->getVisibility());
116
Brian Gaeke54cc3c22004-03-16 22:52:04 +0000117 O << "\t.type\t" << CurrentFnName << ", #function\n";
Brian Gaeke4acfd032004-03-04 06:00:41 +0000118 O << CurrentFnName << ":\n";
119
120 // Number each basic block so that we can consistently refer to them
121 // in PC-relative references.
Chris Lattner29bd9e12006-10-05 02:48:40 +0000122 // FIXME: Why not use the MBB numbers?
Brian Gaeke4acfd032004-03-04 06:00:41 +0000123 NumberForBB.clear();
124 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
125 I != E; ++I) {
126 NumberForBB[I->getBasicBlock()] = BBNumber++;
127 }
128
129 // Print out code for the function.
130 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
131 I != E; ++I) {
132 // Print a label for the basic block.
Nate Begemancdf38c42006-05-02 05:37:32 +0000133 if (I != MF.begin()) {
Evan Chengfb8075d2008-02-28 00:43:03 +0000134 printBasicBlockLabel(I, true, true);
Nate Begemancdf38c42006-05-02 05:37:32 +0000135 O << '\n';
136 }
Brian Gaeke4acfd032004-03-04 06:00:41 +0000137 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
Misha Brukman27177f82005-04-22 18:06:01 +0000138 II != E; ++II) {
Brian Gaeke4acfd032004-03-04 06:00:41 +0000139 // Print the assembly for the instruction.
Chris Lattner0d8fcd32005-12-17 06:54:41 +0000140 printInstruction(II);
Chris Lattner1dbed162005-12-17 07:04:29 +0000141 ++EmittedInsts;
Brian Gaeke4acfd032004-03-04 06:00:41 +0000142 }
143 }
144
145 // We didn't modify anything.
146 return false;
147}
148
Chris Lattner7c90f732006-02-05 05:50:24 +0000149void SparcAsmPrinter::printOperand(const MachineInstr *MI, int opNum) {
Brian Gaeke446ae112004-06-15 19:52:59 +0000150 const MachineOperand &MO = MI->getOperand (opNum);
Dan Gohman6f0d0242008-02-10 18:45:23 +0000151 const TargetRegisterInfo &RI = *TM.getRegisterInfo();
Brian Gaeke446ae112004-06-15 19:52:59 +0000152 bool CloseParen = false;
Dan Gohmand735b802008-10-03 15:45:36 +0000153 if (MI->getOpcode() == SP::SETHIi && !MO.isReg() && !MO.isImm()) {
Brian Gaeke446ae112004-06-15 19:52:59 +0000154 O << "%hi(";
155 CloseParen = true;
Dan Gohmand735b802008-10-03 15:45:36 +0000156 } else if ((MI->getOpcode() == SP::ORri || MI->getOpcode() == SP::ADDri) &&
157 !MO.isReg() && !MO.isImm()) {
Brian Gaeke446ae112004-06-15 19:52:59 +0000158 O << "%lo(";
159 CloseParen = true;
160 }
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000161 switch (MO.getType()) {
Chris Lattner2d90ac72006-05-04 18:05:43 +0000162 case MachineOperand::MO_Register:
Dan Gohman6f0d0242008-02-10 18:45:23 +0000163 if (TargetRegisterInfo::isPhysicalRegister(MO.getReg()))
Bill Wendling74ab84c2008-02-26 21:11:01 +0000164 O << "%" << LowercaseString (RI.get(MO.getReg()).AsmName);
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000165 else
166 O << "%reg" << MO.getReg();
Brian Gaeke446ae112004-06-15 19:52:59 +0000167 break;
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000168
Chris Lattner63b3d712006-05-04 17:21:20 +0000169 case MachineOperand::MO_Immediate:
Chris Lattner9a1ceae2007-12-30 20:49:49 +0000170 O << (int)MO.getImm();
Brian Gaeke446ae112004-06-15 19:52:59 +0000171 break;
Nate Begeman37efe672006-04-22 18:53:45 +0000172 case MachineOperand::MO_MachineBasicBlock:
Chris Lattner8aa797a2007-12-30 23:10:15 +0000173 printBasicBlockLabel(MO.getMBB());
Brian Gaeke09c13092004-06-17 19:39:23 +0000174 return;
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000175 case MachineOperand::MO_GlobalAddress:
Chris Lattnerb8158ac2009-07-14 18:17:16 +0000176 O << Mang->getMangledName(MO.getGlobal());
Brian Gaeke446ae112004-06-15 19:52:59 +0000177 break;
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000178 case MachineOperand::MO_ExternalSymbol:
179 O << MO.getSymbolName();
Brian Gaeke446ae112004-06-15 19:52:59 +0000180 break;
Brian Gaeke8a0ae9e2004-06-27 22:50:44 +0000181 case MachineOperand::MO_ConstantPoolIndex:
Evan Cheng347d39f2007-10-14 05:57:21 +0000182 O << TAI->getPrivateGlobalPrefix() << "CPI" << getFunctionNumber() << "_"
Chris Lattner8aa797a2007-12-30 23:10:15 +0000183 << MO.getIndex();
Brian Gaeke8a0ae9e2004-06-27 22:50:44 +0000184 break;
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000185 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000186 llvm_unreachable("<unknown operand type>");
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000187 }
Brian Gaeke446ae112004-06-15 19:52:59 +0000188 if (CloseParen) O << ")";
Brian Gaeke62aa28a2004-03-05 08:39:09 +0000189}
190
Chris Lattnerad7a3e62006-02-10 07:35:42 +0000191void SparcAsmPrinter::printMemOperand(const MachineInstr *MI, int opNum,
192 const char *Modifier) {
Chris Lattnerbc83fd92005-12-17 20:04:49 +0000193 printOperand(MI, opNum);
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000194
Chris Lattnerad7a3e62006-02-10 07:35:42 +0000195 // If this is an ADD operand, emit it like normal operands.
196 if (Modifier && !strcmp(Modifier, "arith")) {
197 O << ", ";
198 printOperand(MI, opNum+1);
199 return;
200 }
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000201
Dan Gohmand735b802008-10-03 15:45:36 +0000202 if (MI->getOperand(opNum+1).isReg() &&
Chris Lattner7c90f732006-02-05 05:50:24 +0000203 MI->getOperand(opNum+1).getReg() == SP::G0)
Chris Lattner76acc872005-12-18 02:37:35 +0000204 return; // don't print "+%g0"
Dan Gohmand735b802008-10-03 15:45:36 +0000205 if (MI->getOperand(opNum+1).isImm() &&
Chris Lattner9a1ceae2007-12-30 20:49:49 +0000206 MI->getOperand(opNum+1).getImm() == 0)
Chris Lattner76acc872005-12-18 02:37:35 +0000207 return; // don't print "+0"
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000208
Chris Lattnerbc83fd92005-12-17 20:04:49 +0000209 O << "+";
Dan Gohmand735b802008-10-03 15:45:36 +0000210 if (MI->getOperand(opNum+1).isGlobal() ||
211 MI->getOperand(opNum+1).isCPI()) {
Chris Lattnere1389ad2005-12-18 02:27:00 +0000212 O << "%lo(";
213 printOperand(MI, opNum+1);
214 O << ")";
215 } else {
216 printOperand(MI, opNum+1);
217 }
Chris Lattnerbc83fd92005-12-17 20:04:49 +0000218}
219
Chris Lattner7c90f732006-02-05 05:50:24 +0000220void SparcAsmPrinter::printCCOperand(const MachineInstr *MI, int opNum) {
Chris Lattner9a1ceae2007-12-30 20:49:49 +0000221 int CC = (int)MI->getOperand(opNum).getImm();
Chris Lattner7c90f732006-02-05 05:50:24 +0000222 O << SPARCCondCodeToString((SPCC::CondCodes)CC);
Chris Lattner6788faa2006-01-31 06:49:09 +0000223}
224
Chris Lattner7c90f732006-02-05 05:50:24 +0000225bool SparcAsmPrinter::doInitialization(Module &M) {
Rafael Espindolabb46f522009-01-15 20:18:42 +0000226 Mang = new Mangler(M, "", TAI->getPrivateGlobalPrefix());
Brian Gaeke4acfd032004-03-04 06:00:41 +0000227 return false; // success
228}
229
Chris Lattner7c90f732006-02-05 05:50:24 +0000230bool SparcAsmPrinter::doFinalization(Module &M) {
Brian Gaeke4acfd032004-03-04 06:00:41 +0000231 // Print out module-level global variables here.
Chris Lattner04f96742006-03-09 06:14:35 +0000232 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
233 I != E; ++I)
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000234 printModuleLevelGV(I);
Brian Gaeke4acfd032004-03-04 06:00:41 +0000235
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000236 O << '\n';
Brian Gaeke4acfd032004-03-04 06:00:41 +0000237
Dan Gohmanb8275a32007-07-25 19:33:14 +0000238 return AsmPrinter::doFinalization(M);
Brian Gaeke4acfd032004-03-04 06:00:41 +0000239}
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000240
241void SparcAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
242 const TargetData *TD = TM.getTargetData();
243
244 if (!GVar->hasInitializer())
245 return; // External global require no code
246
247 // Check to see if this is a special global used by LLVM, if so, emit it.
248 if (EmitSpecialLLVMGlobal(GVar))
249 return;
250
251 O << "\n\n";
Chris Lattnerb8158ac2009-07-14 18:17:16 +0000252 std::string name = Mang->getMangledName(GVar);
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000253 Constant *C = GVar->getInitializer();
Devang Patel0f05d222009-06-26 02:26:12 +0000254 if (isa<MDNode>(C) || isa<MDString>(C))
Devang Patele4c0c0f2009-06-25 00:47:42 +0000255 return;
Duncan Sands777d2302009-05-09 07:06:46 +0000256 unsigned Size = TD->getTypeAllocSize(C->getType());
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000257 unsigned Align = TD->getPreferredAlignment(GVar);
258
Anton Korobeynikovf5b6a472008-08-08 18:25:07 +0000259 printVisibility(name, GVar->getVisibility());
260
Anton Korobeynikovc25e1ea2008-09-24 22:14:23 +0000261 SwitchToSection(TAI->SectionForGlobal(GVar));
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000262
263 if (C->isNullValue() && !GVar->hasSection()) {
264 if (!GVar->isThreadLocal() &&
Duncan Sands667d4b82009-03-07 15:45:40 +0000265 (GVar->hasLocalLinkage() || GVar->isWeakForLinker())) {
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000266 if (Size == 0) Size = 1; // .comm Foo, 0 is undefined, avoid it.
267
Rafael Espindolabb46f522009-01-15 20:18:42 +0000268 if (GVar->hasLocalLinkage())
Anton Korobeynikov2a166e92008-08-07 09:53:13 +0000269 O << "\t.local " << name << '\n';
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000270
271 O << TAI->getCOMMDirective() << name << ',' << Size;
272 if (TAI->getCOMMDirectiveTakesAlignment())
273 O << ',' << (1 << Align);
274
275 O << '\n';
276 return;
277 }
278 }
279
280 switch (GVar->getLinkage()) {
Duncan Sands4dc2b392009-03-11 20:14:15 +0000281 case GlobalValue::CommonLinkage:
Duncan Sands667d4b82009-03-07 15:45:40 +0000282 case GlobalValue::LinkOnceAnyLinkage:
283 case GlobalValue::LinkOnceODRLinkage:
284 case GlobalValue::WeakAnyLinkage: // FIXME: Verify correct for weak.
285 case GlobalValue::WeakODRLinkage: // FIXME: Verify correct for weak.
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000286 // Nonnull linkonce -> weak
Anton Korobeynikov2a166e92008-08-07 09:53:13 +0000287 O << "\t.weak " << name << '\n';
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000288 break;
289 case GlobalValue::AppendingLinkage:
290 // FIXME: appending linkage variables should go into a section of
291 // their name or something. For now, just emit them as external.
292 case GlobalValue::ExternalLinkage:
293 // If external or appending, declare as a global symbol
Anton Korobeynikov2a166e92008-08-07 09:53:13 +0000294 O << TAI->getGlobalDirective() << name << '\n';
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000295 // FALL THROUGH
Rafael Espindolabb46f522009-01-15 20:18:42 +0000296 case GlobalValue::PrivateLinkage:
Bill Wendling3d10a5a2009-07-20 01:03:30 +0000297 case GlobalValue::LinkerPrivateLinkage:
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000298 case GlobalValue::InternalLinkage:
299 break;
300 case GlobalValue::GhostLinkage:
Torok Edwinc23197a2009-07-14 16:55:14 +0000301 llvm_unreachable("Should not have any unmaterialized functions!");
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000302 case GlobalValue::DLLImportLinkage:
Torok Edwinc23197a2009-07-14 16:55:14 +0000303 llvm_unreachable("DLLImport linkage is not supported by this target!");
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000304 case GlobalValue::DLLExportLinkage:
Torok Edwinc23197a2009-07-14 16:55:14 +0000305 llvm_unreachable("DLLExport linkage is not supported by this target!");
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000306 default:
Torok Edwinc23197a2009-07-14 16:55:14 +0000307 llvm_unreachable("Unknown linkage type!");
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000308 }
309
Anton Korobeynikovfcd99bb2008-08-07 09:53:38 +0000310 EmitAlignment(Align, GVar);
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000311
312 if (TAI->hasDotTypeDotSizeDirective()) {
313 O << "\t.type " << name << ",#object\n";
Anton Korobeynikov2a166e92008-08-07 09:53:13 +0000314 O << "\t.size " << name << ',' << Size << '\n';
Anton Korobeynikov5b794b92008-08-07 09:51:25 +0000315 }
316
317 O << name << ":\n";
318 EmitGlobalConstant(C);
319}
Anton Korobeynikovf3693302008-10-10 10:15:03 +0000320
321/// PrintAsmOperand - Print out an operand for an inline asm expression.
322///
323bool SparcAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
324 unsigned AsmVariant,
325 const char *ExtraCode) {
Anton Korobeynikov4cf5e2e2008-10-10 20:29:50 +0000326 if (ExtraCode && ExtraCode[0]) {
327 if (ExtraCode[1] != 0) return true; // Unknown modifier.
328
329 switch (ExtraCode[0]) {
330 default: return true; // Unknown modifier.
331 case 'r':
332 break;
333 }
334 }
Anton Korobeynikovf3693302008-10-10 10:15:03 +0000335
336 printOperand(MI, OpNo);
337
338 return false;
339}
340
341bool SparcAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
342 unsigned OpNo,
343 unsigned AsmVariant,
344 const char *ExtraCode) {
345 if (ExtraCode && ExtraCode[0])
346 return true; // Unknown modifier
347
348 O << '[';
349 printMemOperand(MI, OpNo);
350 O << ']';
351
352 return false;
353}
Douglas Gregor1555a232009-06-16 20:12:29 +0000354
Bob Wilsona96751f2009-06-23 23:59:40 +0000355// Force static initialization.
Daniel Dunbar51b198a2009-07-15 20:24:03 +0000356extern "C" void LLVMInitializeSparcAsmPrinter() {
Daniel Dunbar51b198a2009-07-15 20:24:03 +0000357 TargetRegistry::RegisterAsmPrinter(TheSparcTarget,
358 createSparcCodePrinterPass);
359}