blob: 205c68751f6f0072f1920881dd139b0d505b5d1d [file] [log] [blame]
Chris Lattner6a8e0f52004-08-16 23:15:22 +00001//===-- AsmPrinter.cpp - Common AsmPrinter code ---------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the AsmPrinter class.
11//
12//===----------------------------------------------------------------------===//
13
Evan Cheng993e9cf2006-03-03 02:04:29 +000014#include "llvm/CodeGen/AsmPrinter.h"
Evan Cheng38d5e762006-03-01 22:18:09 +000015#include "llvm/Assembly/Writer.h"
Nate Begeman41b1cdc2005-12-06 06:18:55 +000016#include "llvm/DerivedTypes.h"
Chris Lattner6a8e0f52004-08-16 23:15:22 +000017#include "llvm/Constants.h"
Chris Lattnerc0a1eba2005-11-10 18:36:17 +000018#include "llvm/Module.h"
Chris Lattnerf2991ce2005-11-21 08:25:09 +000019#include "llvm/CodeGen/MachineConstantPool.h"
Nate Begeman4ca2ea52006-04-22 18:53:45 +000020#include "llvm/CodeGen/MachineJumpTableInfo.h"
Chris Lattner6a8e0f52004-08-16 23:15:22 +000021#include "llvm/Support/Mangler.h"
Jim Laskeyb74c6662005-08-17 19:34:49 +000022#include "llvm/Support/MathExtras.h"
Owen Anderson8c2c1e92006-05-12 06:33:49 +000023#include "llvm/Target/TargetData.h"
Chris Lattner6a8e0f52004-08-16 23:15:22 +000024#include "llvm/Target/TargetMachine.h"
Duraid Madina26b037e2005-12-28 06:29:02 +000025#include <iostream>
Chris Lattneraa23fa92006-02-01 22:41:11 +000026#include <cerrno>
Chris Lattner6a8e0f52004-08-16 23:15:22 +000027using namespace llvm;
28
Chris Lattnerf0e9aef2005-12-13 06:32:10 +000029AsmPrinter::AsmPrinter(std::ostream &o, TargetMachine &tm)
30: FunctionNumber(0), O(o), TM(tm),
31 CommentString("#"),
32 GlobalPrefix(""),
33 PrivateGlobalPrefix("."),
34 GlobalVarAddrPrefix(""),
35 GlobalVarAddrSuffix(""),
36 FunctionAddrPrefix(""),
37 FunctionAddrSuffix(""),
Chris Lattnera633c3132006-05-05 21:47:05 +000038 InlineAsmStart("#APP"),
39 InlineAsmEnd("#NO_APP"),
Chris Lattnerf0e9aef2005-12-13 06:32:10 +000040 ZeroDirective("\t.zero\t"),
Jeff Cohenf34ddb12006-05-02 03:46:13 +000041 ZeroDirectiveSuffix(0),
Chris Lattnerf0e9aef2005-12-13 06:32:10 +000042 AsciiDirective("\t.ascii\t"),
43 AscizDirective("\t.asciz\t"),
44 Data8bitsDirective("\t.byte\t"),
45 Data16bitsDirective("\t.short\t"),
46 Data32bitsDirective("\t.long\t"),
47 Data64bitsDirective("\t.quad\t"),
48 AlignDirective("\t.align\t"),
49 AlignmentIsInBytes(true),
50 SwitchToSectionDirective("\t.section\t"),
Chris Lattner4ebc6a22006-05-09 05:33:48 +000051 TextSectionStartSuffix(""),
52 DataSectionStartSuffix(""),
53 SectionEndDirectiveSuffix(0),
Chris Lattnerf0e9aef2005-12-13 06:32:10 +000054 ConstantPoolSection("\t.section .rodata\n"),
Nate Begeman78756502006-07-27 01:13:04 +000055 JumpTableDataSection("\t.section .rodata\n"),
56 JumpTableTextSection("\t.text\n"),
Chris Lattnerf0e9aef2005-12-13 06:32:10 +000057 StaticCtorsSection("\t.section .ctors,\"aw\",@progbits"),
58 StaticDtorsSection("\t.section .dtors,\"aw\",@progbits"),
Evan Chengec1d60b2006-06-29 00:26:09 +000059 FourByteConstantSection(0),
60 EightByteConstantSection(0),
61 SixteenByteConstantSection(0),
Chris Lattnerf0e9aef2005-12-13 06:32:10 +000062 LCOMMDirective(0),
63 COMMDirective("\t.comm\t"),
64 COMMDirectiveTakesAlignment(true),
65 HasDotTypeDotSizeDirective(true) {
66}
67
68
Chris Lattner8488ba22006-05-09 04:59:56 +000069/// SwitchToTextSection - Switch to the specified text section of the executable
70/// if we are not already in it!
Chris Lattner2ea5c992005-11-21 07:06:27 +000071///
Chris Lattner8488ba22006-05-09 04:59:56 +000072void AsmPrinter::SwitchToTextSection(const char *NewSection,
73 const GlobalValue *GV) {
Chris Lattner2ea5c992005-11-21 07:06:27 +000074 std::string NS;
Chris Lattner8c2bfc02006-05-09 05:24:50 +000075 if (GV && GV->hasSection())
Chris Lattnerf8017922006-05-09 16:41:59 +000076 NS = SwitchToSectionDirective + GV->getSection();
Chris Lattner8c2bfc02006-05-09 05:24:50 +000077 else
78 NS = NewSection;
79
80 // If we're already in this section, we're done.
81 if (CurrentSection == NS) return;
Jeff Cohen470f4312006-05-02 03:58:45 +000082
Chris Lattner4ebc6a22006-05-09 05:33:48 +000083 // Close the current section, if applicable.
84 if (SectionEndDirectiveSuffix && !CurrentSection.empty())
85 O << CurrentSection << SectionEndDirectiveSuffix << "\n";
Jeff Cohen470f4312006-05-02 03:58:45 +000086
Chris Lattner4ebc6a22006-05-09 05:33:48 +000087 CurrentSection = NS;
88
89 if (!CurrentSection.empty())
90 O << CurrentSection << TextSectionStartSuffix << '\n';
Chris Lattner2ea5c992005-11-21 07:06:27 +000091}
92
Nate Begeman78756502006-07-27 01:13:04 +000093/// SwitchToDataSection - Switch to the specified data section of the executable
Chris Lattner8488ba22006-05-09 04:59:56 +000094/// if we are not already in it!
95///
96void AsmPrinter::SwitchToDataSection(const char *NewSection,
97 const GlobalValue *GV) {
98 std::string NS;
Chris Lattner6341df82006-05-09 05:23:12 +000099 if (GV && GV->hasSection())
100 NS = SwitchToSectionDirective + GV->getSection();
101 else
102 NS = NewSection;
Chris Lattner8488ba22006-05-09 04:59:56 +0000103
Chris Lattner6341df82006-05-09 05:23:12 +0000104 // If we're already in this section, we're done.
105 if (CurrentSection == NS) return;
106
Chris Lattner4ebc6a22006-05-09 05:33:48 +0000107 // Close the current section, if applicable.
108 if (SectionEndDirectiveSuffix && !CurrentSection.empty())
109 O << CurrentSection << SectionEndDirectiveSuffix << "\n";
110
111 CurrentSection = NS;
Chris Lattner8488ba22006-05-09 04:59:56 +0000112
Chris Lattner4ebc6a22006-05-09 05:33:48 +0000113 if (!CurrentSection.empty())
114 O << CurrentSection << DataSectionStartSuffix << '\n';
Chris Lattner8488ba22006-05-09 04:59:56 +0000115}
116
117
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000118bool AsmPrinter::doInitialization(Module &M) {
Chris Lattner6d42cbd2004-08-17 06:06:19 +0000119 Mang = new Mangler(M, GlobalPrefix);
Chris Lattnere3a79262006-01-23 23:47:53 +0000120
Chris Lattner00fcdfe2006-01-24 04:16:34 +0000121 if (!M.getModuleInlineAsm().empty())
122 O << CommentString << " Start of file scope inline assembly\n"
123 << M.getModuleInlineAsm()
124 << "\n" << CommentString << " End of file scope inline assembly\n";
Chris Lattnere3a79262006-01-23 23:47:53 +0000125
Chris Lattner8488ba22006-05-09 04:59:56 +0000126 SwitchToDataSection("", 0); // Reset back to no section.
Jim Laskey0bbdc552006-01-26 20:21:46 +0000127
128 if (MachineDebugInfo *DebugInfo = getAnalysisToUpdate<MachineDebugInfo>()) {
129 DebugInfo->AnalyzeModule(M);
130 }
131
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000132 return false;
133}
134
135bool AsmPrinter::doFinalization(Module &M) {
136 delete Mang; Mang = 0;
137 return false;
138}
139
Chris Lattnerbb644e32005-11-21 07:51:36 +0000140void AsmPrinter::SetupMachineFunction(MachineFunction &MF) {
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000141 // What's my mangled name?
Chris Lattnerc0a1eba2005-11-10 18:36:17 +0000142 CurrentFnName = Mang->getValueName(MF.getFunction());
Chris Lattner08adbd132005-11-21 08:13:27 +0000143 IncrementFunctionNumber();
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000144}
145
Chris Lattnerf2991ce2005-11-21 08:25:09 +0000146/// EmitConstantPool - Print to the current output stream assembly
147/// representations of the constants in the constant pool MCP. This is
148/// used to print out constants which have been "spilled to memory" by
149/// the code generator.
150///
151void AsmPrinter::EmitConstantPool(MachineConstantPool *MCP) {
Chris Lattnerba972642006-02-09 04:22:52 +0000152 const std::vector<MachineConstantPoolEntry> &CP = MCP->getConstants();
Chris Lattnerf2991ce2005-11-21 08:25:09 +0000153 if (CP.empty()) return;
Evan Chengec1d60b2006-06-29 00:26:09 +0000154
155 // Some targets require 4-, 8-, and 16- byte constant literals to be placed
156 // in special sections.
157 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > FourByteCPs;
158 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > EightByteCPs;
159 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > SixteenByteCPs;
160 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > OtherCPs;
Chris Lattnerf2991ce2005-11-21 08:25:09 +0000161 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
Evan Chengec1d60b2006-06-29 00:26:09 +0000162 MachineConstantPoolEntry CPE = CP[i];
163 const Constant *CV = CPE.Val;
164 const Type *Ty = CV->getType();
165 if (FourByteConstantSection &&
166 TM.getTargetData()->getTypeSize(Ty) == 4)
167 FourByteCPs.push_back(std::make_pair(CPE, i));
168 else if (EightByteConstantSection &&
169 TM.getTargetData()->getTypeSize(Ty) == 8)
170 EightByteCPs.push_back(std::make_pair(CPE, i));
171 else if (SixteenByteConstantSection &&
172 TM.getTargetData()->getTypeSize(Ty) == 16)
173 SixteenByteCPs.push_back(std::make_pair(CPE, i));
174 else
175 OtherCPs.push_back(std::make_pair(CPE, i));
176 }
177
178 unsigned Alignment = MCP->getConstantPoolAlignment();
179 EmitConstantPool(Alignment, FourByteConstantSection, FourByteCPs);
180 EmitConstantPool(Alignment, EightByteConstantSection, EightByteCPs);
181 EmitConstantPool(Alignment, SixteenByteConstantSection, SixteenByteCPs);
182 EmitConstantPool(Alignment, ConstantPoolSection, OtherCPs);
183}
184
185void AsmPrinter::EmitConstantPool(unsigned Alignment, const char *Section,
186 std::vector<std::pair<MachineConstantPoolEntry,unsigned> > &CP) {
187 if (CP.empty()) return;
188
189 SwitchToDataSection(Section, 0);
190 EmitAlignment(Alignment);
191 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
192 O << PrivateGlobalPrefix << "CPI" << getFunctionNumber() << '_'
193 << CP[i].second << ":\t\t\t\t\t" << CommentString << " ";
194 WriteTypeSymbolic(O, CP[i].first.Val->getType(), 0) << '\n';
195 EmitGlobalConstant(CP[i].first.Val);
Chris Lattnerf6190822006-02-09 04:46:04 +0000196 if (i != e-1) {
Evan Chengec1d60b2006-06-29 00:26:09 +0000197 unsigned EntSize =
198 TM.getTargetData()->getTypeSize(CP[i].first.Val->getType());
199 unsigned ValEnd = CP[i].first.Offset + EntSize;
Chris Lattnerf6190822006-02-09 04:46:04 +0000200 // Emit inter-object padding for alignment.
Evan Chengec1d60b2006-06-29 00:26:09 +0000201 EmitZeros(CP[i+1].first.Offset-ValEnd);
Chris Lattnerf6190822006-02-09 04:46:04 +0000202 }
Chris Lattnerf2991ce2005-11-21 08:25:09 +0000203 }
204}
205
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000206/// EmitJumpTableInfo - Print assembly representations of the jump tables used
207/// by the current function to the current output stream.
208///
209void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI) {
210 const std::vector<MachineJumpTableEntry> &JT = MJTI->getJumpTables();
211 if (JT.empty()) return;
Owen Anderson20a631f2006-05-03 01:29:57 +0000212 const TargetData *TD = TM.getTargetData();
Nate Begemanefc312a2006-07-27 16:46:58 +0000213
214 // JTEntryDirective is a string to print sizeof(ptr) for non-PIC jump tables,
215 // and 32 bits for PIC since PIC jump table entries are differences, not
216 // pointers to blocks.
217 const char *JTEntryDirective = Data32bitsDirective;
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000218
Nate Begeman78756502006-07-27 01:13:04 +0000219 // Pick the directive to use to print the jump table entries, and switch to
220 // the appropriate section.
221 if (TM.getRelocationModel() == Reloc::PIC_) {
222 SwitchToTextSection(JumpTableTextSection, 0);
223 } else {
224 SwitchToDataSection(JumpTableDataSection, 0);
225 if (TD->getPointerSize() == 8)
Nate Begemanefc312a2006-07-27 16:46:58 +0000226 JTEntryDirective = Data64bitsDirective;
Nate Begeman78756502006-07-27 01:13:04 +0000227 }
Owen Anderson20a631f2006-05-03 01:29:57 +0000228 EmitAlignment(Log2_32(TD->getPointerAlignment()));
Chris Lattnerfd5a8eb2006-07-15 01:34:12 +0000229
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000230 for (unsigned i = 0, e = JT.size(); i != e; ++i) {
231 O << PrivateGlobalPrefix << "JTI" << getFunctionNumber() << '_' << i
232 << ":\n";
233 const std::vector<MachineBasicBlock*> &JTBBs = JT[i].MBBs;
234 for (unsigned ii = 0, ee = JTBBs.size(); ii != ee; ++ii) {
Nate Begemanefc312a2006-07-27 16:46:58 +0000235 O << JTEntryDirective << ' ';
Nate Begeman78756502006-07-27 01:13:04 +0000236 printBasicBlockLabel(JTBBs[ii], false, false);
237 if (TM.getRelocationModel() == Reloc::PIC_) {
238 O << '-' << PrivateGlobalPrefix << "JTI" << getFunctionNumber()
239 << '_' << i;
240 }
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000241 O << '\n';
242 }
243 }
244}
245
Chris Lattnerf0e9aef2005-12-13 06:32:10 +0000246/// EmitSpecialLLVMGlobal - Check to see if the specified global is a
247/// special global used by LLVM. If so, emit it and return true, otherwise
248/// do nothing and return false.
249bool AsmPrinter::EmitSpecialLLVMGlobal(const GlobalVariable *GV) {
Jim Laskey313570f2006-03-07 22:00:35 +0000250 // Ignore debug and non-emitted data.
251 if (GV->getSection() == "llvm.metadata") return true;
252
253 if (!GV->hasAppendingLinkage()) return false;
254
255 assert(GV->hasInitializer() && "Not a special LLVM global!");
Chris Lattnerf0e9aef2005-12-13 06:32:10 +0000256
257 if (GV->getName() == "llvm.used")
258 return true; // No need to emit this at all.
259
Chris Lattner3760e902006-01-12 19:17:23 +0000260 if (GV->getName() == "llvm.global_ctors" && GV->use_empty()) {
Chris Lattner8488ba22006-05-09 04:59:56 +0000261 SwitchToDataSection(StaticCtorsSection, 0);
Chris Lattnerf0e9aef2005-12-13 06:32:10 +0000262 EmitAlignment(2, 0);
263 EmitXXStructorList(GV->getInitializer());
264 return true;
265 }
266
Chris Lattner3760e902006-01-12 19:17:23 +0000267 if (GV->getName() == "llvm.global_dtors" && GV->use_empty()) {
Chris Lattner8488ba22006-05-09 04:59:56 +0000268 SwitchToDataSection(StaticDtorsSection, 0);
Chris Lattnerf0e9aef2005-12-13 06:32:10 +0000269 EmitAlignment(2, 0);
270 EmitXXStructorList(GV->getInitializer());
271 return true;
272 }
273
274 return false;
275}
276
277/// EmitXXStructorList - Emit the ctor or dtor list. This just prints out the
278/// function pointers, ignoring the init priority.
279void AsmPrinter::EmitXXStructorList(Constant *List) {
280 // Should be an array of '{ int, void ()* }' structs. The first value is the
281 // init priority, which we ignore.
282 if (!isa<ConstantArray>(List)) return;
283 ConstantArray *InitList = cast<ConstantArray>(List);
284 for (unsigned i = 0, e = InitList->getNumOperands(); i != e; ++i)
285 if (ConstantStruct *CS = dyn_cast<ConstantStruct>(InitList->getOperand(i))){
286 if (CS->getNumOperands() != 2) return; // Not array of 2-element structs.
Chris Lattner434ffe42005-12-21 01:17:37 +0000287
288 if (CS->getOperand(1)->isNullValue())
289 return; // Found a null terminator, exit printing.
290 // Emit the function pointer.
Chris Lattnerf0e9aef2005-12-13 06:32:10 +0000291 EmitGlobalConstant(CS->getOperand(1));
292 }
293}
Chris Lattnerf2991ce2005-11-21 08:25:09 +0000294
Chris Lattnera9b25252006-02-05 01:29:18 +0000295/// getPreferredAlignmentLog - Return the preferred alignment of the
296/// specified global, returned in log form. This includes an explicitly
297/// requested alignment (if the global has one).
298unsigned AsmPrinter::getPreferredAlignmentLog(const GlobalVariable *GV) const {
Jim Laskeydce07562006-06-15 13:10:58 +0000299 const Type *ElemType = GV->getType()->getElementType();
300 unsigned Alignment = TM.getTargetData()->getTypeAlignmentShift(ElemType);
Chris Lattnera9b25252006-02-05 01:29:18 +0000301 if (GV->getAlignment() > (1U << Alignment))
302 Alignment = Log2_32(GV->getAlignment());
303
Chris Lattnercbab2842006-02-05 01:46:49 +0000304 if (GV->hasInitializer()) {
Jim Laskey3519b872006-06-15 19:37:14 +0000305 // Always round up alignment of global doubles to 8 bytes.
306 if (GV->getType()->getElementType() == Type::DoubleTy && Alignment < 3)
307 Alignment = 3;
Chris Lattnercbab2842006-02-05 01:46:49 +0000308 if (Alignment < 4) {
309 // If the global is not external, see if it is large. If so, give it a
310 // larger alignment.
Jim Laskeydce07562006-06-15 13:10:58 +0000311 if (TM.getTargetData()->getTypeSize(ElemType) > 128)
Chris Lattnercbab2842006-02-05 01:46:49 +0000312 Alignment = 4; // 16-byte alignment.
313 }
Chris Lattnera9b25252006-02-05 01:29:18 +0000314 }
315 return Alignment;
316}
Chris Lattnerf2991ce2005-11-21 08:25:09 +0000317
Chris Lattnerbb644e32005-11-21 07:51:36 +0000318// EmitAlignment - Emit an alignment directive to the specified power of two.
319void AsmPrinter::EmitAlignment(unsigned NumBits, const GlobalValue *GV) const {
Chris Lattnerdd8eeed2005-11-14 19:00:06 +0000320 if (GV && GV->getAlignment())
321 NumBits = Log2_32(GV->getAlignment());
Chris Lattner747960d2005-11-10 18:09:27 +0000322 if (NumBits == 0) return; // No need to emit alignment.
Chris Lattner1d35c162004-08-17 19:14:29 +0000323 if (AlignmentIsInBytes) NumBits = 1 << NumBits;
324 O << AlignDirective << NumBits << "\n";
325}
326
Chris Lattnerbb644e32005-11-21 07:51:36 +0000327/// EmitZeros - Emit a block of zeros.
Chris Lattnerea751992004-08-17 21:38:40 +0000328///
Chris Lattnerbb644e32005-11-21 07:51:36 +0000329void AsmPrinter::EmitZeros(uint64_t NumZeros) const {
Chris Lattnerea751992004-08-17 21:38:40 +0000330 if (NumZeros) {
Jeff Cohenf34ddb12006-05-02 03:46:13 +0000331 if (ZeroDirective) {
332 O << ZeroDirective << NumZeros;
333 if (ZeroDirectiveSuffix)
334 O << ZeroDirectiveSuffix;
335 O << "\n";
336 } else {
Chris Lattnerea751992004-08-17 21:38:40 +0000337 for (; NumZeros; --NumZeros)
338 O << Data8bitsDirective << "0\n";
339 }
340 }
341}
342
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000343// Print out the specified constant, without a storage class. Only the
344// constants valid in constant expressions can occur here.
Chris Lattnerbb644e32005-11-21 07:51:36 +0000345void AsmPrinter::EmitConstantValueOnly(const Constant *CV) {
Chris Lattner61753bf2004-10-16 18:19:26 +0000346 if (CV->isNullValue() || isa<UndefValue>(CV))
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000347 O << "0";
348 else if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
349 assert(CB == ConstantBool::True);
350 O << "1";
351 } else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
352 if (((CI->getValue() << 32) >> 32) == CI->getValue())
353 O << CI->getValue();
354 else
Duraid Madina73c4dba2005-05-15 13:05:48 +0000355 O << (uint64_t)CI->getValue();
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000356 else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
357 O << CI->getValue();
Chris Lattnerc0a1eba2005-11-10 18:36:17 +0000358 else if (const GlobalValue *GV = dyn_cast<GlobalValue>(CV)) {
Duraid Madina73a316d2005-04-02 12:21:51 +0000359 // This is a constant address for a global variable or function. Use the
360 // name of the variable or function as the address value, possibly
361 // decorating it with GlobalVarAddrPrefix/Suffix or
362 // FunctionAddrPrefix/Suffix (these all default to "" )
Chris Lattnerc0a1eba2005-11-10 18:36:17 +0000363 if (isa<Function>(GV))
364 O << FunctionAddrPrefix << Mang->getValueName(GV) << FunctionAddrSuffix;
Duraid Madina73a316d2005-04-02 12:21:51 +0000365 else
Chris Lattnerc0a1eba2005-11-10 18:36:17 +0000366 O << GlobalVarAddrPrefix << Mang->getValueName(GV) << GlobalVarAddrSuffix;
Duraid Madina73a316d2005-04-02 12:21:51 +0000367 } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
Owen Anderson20a631f2006-05-03 01:29:57 +0000368 const TargetData *TD = TM.getTargetData();
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000369 switch(CE->getOpcode()) {
370 case Instruction::GetElementPtr: {
371 // generate a symbolic expression for the byte address
372 const Constant *ptrVal = CE->getOperand(0);
373 std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
Owen Anderson20a631f2006-05-03 01:29:57 +0000374 if (int64_t Offset = TD->getIndexedOffset(ptrVal->getType(), idxVec)) {
Chris Lattner145569b2005-02-14 21:40:26 +0000375 if (Offset)
376 O << "(";
Chris Lattnerbb644e32005-11-21 07:51:36 +0000377 EmitConstantValueOnly(ptrVal);
Chris Lattner145569b2005-02-14 21:40:26 +0000378 if (Offset > 0)
379 O << ") + " << Offset;
380 else if (Offset < 0)
381 O << ") - " << -Offset;
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000382 } else {
Chris Lattnerbb644e32005-11-21 07:51:36 +0000383 EmitConstantValueOnly(ptrVal);
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000384 }
385 break;
386 }
387 case Instruction::Cast: {
388 // Support only non-converting or widening casts for now, that is, ones
389 // that do not involve a change in value. This assertion is really gross,
390 // and may not even be a complete check.
391 Constant *Op = CE->getOperand(0);
392 const Type *OpTy = Op->getType(), *Ty = CE->getType();
393
394 // Remember, kids, pointers can be losslessly converted back and forth
395 // into 32-bit or wider integers, regardless of signedness. :-P
396 assert(((isa<PointerType>(OpTy)
397 && (Ty == Type::LongTy || Ty == Type::ULongTy
398 || Ty == Type::IntTy || Ty == Type::UIntTy))
399 || (isa<PointerType>(Ty)
400 && (OpTy == Type::LongTy || OpTy == Type::ULongTy
401 || OpTy == Type::IntTy || OpTy == Type::UIntTy))
Owen Anderson20a631f2006-05-03 01:29:57 +0000402 || (((TD->getTypeSize(Ty) >= TD->getTypeSize(OpTy))
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000403 && OpTy->isLosslesslyConvertibleTo(Ty))))
404 && "FIXME: Don't yet support this kind of constant cast expr");
Chris Lattnerbb644e32005-11-21 07:51:36 +0000405 EmitConstantValueOnly(Op);
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000406 break;
407 }
408 case Instruction::Add:
409 O << "(";
Chris Lattnerbb644e32005-11-21 07:51:36 +0000410 EmitConstantValueOnly(CE->getOperand(0));
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000411 O << ") + (";
Chris Lattnerbb644e32005-11-21 07:51:36 +0000412 EmitConstantValueOnly(CE->getOperand(1));
Chris Lattner6a8e0f52004-08-16 23:15:22 +0000413 O << ")";
414 break;
415 default:
416 assert(0 && "Unsupported operator!");
417 }
418 } else {
419 assert(0 && "Unknown constant value!");
420 }
421}
Chris Lattner8452a1f2004-08-17 06:36:49 +0000422
423/// toOctal - Convert the low order bits of X into an octal digit.
424///
425static inline char toOctal(int X) {
426 return (X&7)+'0';
427}
428
Chris Lattner55a6d902005-11-10 18:06:33 +0000429/// printAsCString - Print the specified array as a C compatible string, only if
Chris Lattner8452a1f2004-08-17 06:36:49 +0000430/// the predicate isString is true.
431///
Chris Lattner55a6d902005-11-10 18:06:33 +0000432static void printAsCString(std::ostream &O, const ConstantArray *CVA,
433 unsigned LastElt) {
Chris Lattner8452a1f2004-08-17 06:36:49 +0000434 assert(CVA->isString() && "Array is not string compatible!");
435
436 O << "\"";
Chris Lattner55a6d902005-11-10 18:06:33 +0000437 for (unsigned i = 0; i != LastElt; ++i) {
Misha Brukman835702a2005-04-21 22:36:52 +0000438 unsigned char C =
Chris Lattner0b955fd2005-01-08 19:59:10 +0000439 (unsigned char)cast<ConstantInt>(CVA->getOperand(i))->getRawValue();
Chris Lattner8452a1f2004-08-17 06:36:49 +0000440
441 if (C == '"') {
442 O << "\\\"";
443 } else if (C == '\\') {
444 O << "\\\\";
445 } else if (isprint(C)) {
446 O << C;
447 } else {
448 switch(C) {
449 case '\b': O << "\\b"; break;
450 case '\f': O << "\\f"; break;
451 case '\n': O << "\\n"; break;
452 case '\r': O << "\\r"; break;
453 case '\t': O << "\\t"; break;
454 default:
455 O << '\\';
456 O << toOctal(C >> 6);
457 O << toOctal(C >> 3);
458 O << toOctal(C >> 0);
459 break;
460 }
461 }
462 }
463 O << "\"";
464}
465
Jeff Cohen24a62a92006-05-02 01:16:28 +0000466/// EmitString - Emit a zero-byte-terminated string constant.
467///
468void AsmPrinter::EmitString(const ConstantArray *CVA) const {
469 unsigned NumElts = CVA->getNumOperands();
470 if (AscizDirective && NumElts &&
471 cast<ConstantInt>(CVA->getOperand(NumElts-1))->getRawValue() == 0) {
472 O << AscizDirective;
473 printAsCString(O, CVA, NumElts-1);
474 } else {
475 O << AsciiDirective;
476 printAsCString(O, CVA, NumElts);
477 }
478 O << "\n";
479}
480
Chris Lattnerbb644e32005-11-21 07:51:36 +0000481/// EmitGlobalConstant - Print a general LLVM constant to the .s file.
Chris Lattner8452a1f2004-08-17 06:36:49 +0000482///
Chris Lattnerbb644e32005-11-21 07:51:36 +0000483void AsmPrinter::EmitGlobalConstant(const Constant *CV) {
Owen Anderson20a631f2006-05-03 01:29:57 +0000484 const TargetData *TD = TM.getTargetData();
Chris Lattner8452a1f2004-08-17 06:36:49 +0000485
Chris Lattner61753bf2004-10-16 18:19:26 +0000486 if (CV->isNullValue() || isa<UndefValue>(CV)) {
Owen Anderson20a631f2006-05-03 01:29:57 +0000487 EmitZeros(TD->getTypeSize(CV->getType()));
Chris Lattner8452a1f2004-08-17 06:36:49 +0000488 return;
489 } else if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
490 if (CVA->isString()) {
Jeff Cohen24a62a92006-05-02 01:16:28 +0000491 EmitString(CVA);
Chris Lattner8452a1f2004-08-17 06:36:49 +0000492 } else { // Not a string. Print the values in successive locations
493 for (unsigned i = 0, e = CVA->getNumOperands(); i != e; ++i)
Chris Lattnerbb644e32005-11-21 07:51:36 +0000494 EmitGlobalConstant(CVA->getOperand(i));
Chris Lattner8452a1f2004-08-17 06:36:49 +0000495 }
496 return;
497 } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
498 // Print the fields in successive locations. Pad to align if needed!
Owen Anderson20a631f2006-05-03 01:29:57 +0000499 const StructLayout *cvsLayout = TD->getStructLayout(CVS->getType());
Chris Lattner0b955fd2005-01-08 19:59:10 +0000500 uint64_t sizeSoFar = 0;
Chris Lattner8452a1f2004-08-17 06:36:49 +0000501 for (unsigned i = 0, e = CVS->getNumOperands(); i != e; ++i) {
502 const Constant* field = CVS->getOperand(i);
503
504 // Check if padding is needed and insert one or more 0s.
Owen Anderson20a631f2006-05-03 01:29:57 +0000505 uint64_t fieldSize = TD->getTypeSize(field->getType());
Chris Lattner0b955fd2005-01-08 19:59:10 +0000506 uint64_t padSize = ((i == e-1? cvsLayout->StructSize
Chris Lattner8452a1f2004-08-17 06:36:49 +0000507 : cvsLayout->MemberOffsets[i+1])
508 - cvsLayout->MemberOffsets[i]) - fieldSize;
509 sizeSoFar += fieldSize + padSize;
510
511 // Now print the actual field value
Chris Lattnerbb644e32005-11-21 07:51:36 +0000512 EmitGlobalConstant(field);
Chris Lattner8452a1f2004-08-17 06:36:49 +0000513
514 // Insert the field padding unless it's zero bytes...
Chris Lattnerbb644e32005-11-21 07:51:36 +0000515 EmitZeros(padSize);
Chris Lattner8452a1f2004-08-17 06:36:49 +0000516 }
517 assert(sizeSoFar == cvsLayout->StructSize &&
518 "Layout of constant struct may be incorrect!");
519 return;
520 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
521 // FP Constants are printed as integer constants to avoid losing
522 // precision...
523 double Val = CFP->getValue();
524 if (CFP->getType() == Type::DoubleTy) {
Chris Lattner9fa0fc42004-08-17 06:48:16 +0000525 if (Data64bitsDirective)
Jim Laskeyb74c6662005-08-17 19:34:49 +0000526 O << Data64bitsDirective << DoubleToBits(Val) << "\t" << CommentString
Chris Lattnerea751992004-08-17 21:38:40 +0000527 << " double value: " << Val << "\n";
Owen Anderson20a631f2006-05-03 01:29:57 +0000528 else if (TD->isBigEndian()) {
Jim Laskeyb74c6662005-08-17 19:34:49 +0000529 O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32)
Chris Lattner10262ab2004-08-18 02:22:55 +0000530 << "\t" << CommentString << " double most significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000531 << Val << "\n";
Jim Laskeyb74c6662005-08-17 19:34:49 +0000532 O << Data32bitsDirective << unsigned(DoubleToBits(Val))
Chris Lattner10262ab2004-08-18 02:22:55 +0000533 << "\t" << CommentString << " double least significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000534 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000535 } else {
Jim Laskeyb74c6662005-08-17 19:34:49 +0000536 O << Data32bitsDirective << unsigned(DoubleToBits(Val))
Chris Lattner10262ab2004-08-18 02:22:55 +0000537 << "\t" << CommentString << " double least significant word " << Val
Chris Lattnerda6beac2004-08-17 16:27:05 +0000538 << "\n";
Jim Laskeyb74c6662005-08-17 19:34:49 +0000539 O << Data32bitsDirective << unsigned(DoubleToBits(Val) >> 32)
Chris Lattner10262ab2004-08-18 02:22:55 +0000540 << "\t" << CommentString << " double most significant word " << Val
Chris Lattnerda6beac2004-08-17 16:27:05 +0000541 << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000542 }
543 return;
544 } else {
Jim Laskeyb74c6662005-08-17 19:34:49 +0000545 O << Data32bitsDirective << FloatToBits(Val) << "\t" << CommentString
Chris Lattnerda6beac2004-08-17 16:27:05 +0000546 << " float " << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000547 return;
548 }
549 } else if (CV->getType() == Type::ULongTy || CV->getType() == Type::LongTy) {
550 if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
551 uint64_t Val = CI->getRawValue();
Misha Brukman835702a2005-04-21 22:36:52 +0000552
Chris Lattner9fa0fc42004-08-17 06:48:16 +0000553 if (Data64bitsDirective)
554 O << Data64bitsDirective << Val << "\n";
Owen Anderson20a631f2006-05-03 01:29:57 +0000555 else if (TD->isBigEndian()) {
Chris Lattner8452a1f2004-08-17 06:36:49 +0000556 O << Data32bitsDirective << unsigned(Val >> 32)
Chris Lattner10262ab2004-08-18 02:22:55 +0000557 << "\t" << CommentString << " Double-word most significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000558 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000559 O << Data32bitsDirective << unsigned(Val)
Chris Lattner10262ab2004-08-18 02:22:55 +0000560 << "\t" << CommentString << " Double-word least significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000561 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000562 } else {
563 O << Data32bitsDirective << unsigned(Val)
Chris Lattner10262ab2004-08-18 02:22:55 +0000564 << "\t" << CommentString << " Double-word least significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000565 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000566 O << Data32bitsDirective << unsigned(Val >> 32)
Chris Lattner10262ab2004-08-18 02:22:55 +0000567 << "\t" << CommentString << " Double-word most significant word "
Chris Lattnerda6beac2004-08-17 16:27:05 +0000568 << Val << "\n";
Chris Lattner8452a1f2004-08-17 06:36:49 +0000569 }
570 return;
571 }
Nate Begeman41b1cdc2005-12-06 06:18:55 +0000572 } else if (const ConstantPacked *CP = dyn_cast<ConstantPacked>(CV)) {
573 const PackedType *PTy = CP->getType();
574
575 for (unsigned I = 0, E = PTy->getNumElements(); I < E; ++I)
576 EmitGlobalConstant(CP->getOperand(I));
577
578 return;
Chris Lattner8452a1f2004-08-17 06:36:49 +0000579 }
580
581 const Type *type = CV->getType();
Chris Lattner8452a1f2004-08-17 06:36:49 +0000582 switch (type->getTypeID()) {
Misha Brukman835702a2005-04-21 22:36:52 +0000583 case Type::BoolTyID:
Chris Lattner8452a1f2004-08-17 06:36:49 +0000584 case Type::UByteTyID: case Type::SByteTyID:
585 O << Data8bitsDirective;
586 break;
587 case Type::UShortTyID: case Type::ShortTyID:
588 O << Data16bitsDirective;
589 break;
Chris Lattner8452a1f2004-08-17 06:36:49 +0000590 case Type::PointerTyID:
Owen Anderson20a631f2006-05-03 01:29:57 +0000591 if (TD->getPointerSize() == 8) {
Evan Chengdf631792006-06-15 08:10:56 +0000592 assert(Data64bitsDirective &&
593 "Target cannot handle 64-bit pointer exprs!");
Andrew Lenharthc8770aa2005-02-04 13:47:16 +0000594 O << Data64bitsDirective;
595 break;
596 }
597 //Fall through for pointer size == int size
Chris Lattner8452a1f2004-08-17 06:36:49 +0000598 case Type::UIntTyID: case Type::IntTyID:
599 O << Data32bitsDirective;
600 break;
Misha Brukman835702a2005-04-21 22:36:52 +0000601 case Type::ULongTyID: case Type::LongTyID:
Chris Lattner88e2d2e2005-08-08 04:26:32 +0000602 assert(Data64bitsDirective &&"Target cannot handle 64-bit constant exprs!");
603 O << Data64bitsDirective;
604 break;
Chris Lattner8452a1f2004-08-17 06:36:49 +0000605 case Type::FloatTyID: case Type::DoubleTyID:
606 assert (0 && "Should have already output floating point constant.");
607 default:
608 assert (0 && "Can't handle printing this type of thing");
609 break;
610 }
Chris Lattnerbb644e32005-11-21 07:51:36 +0000611 EmitConstantValueOnly(CV);
Chris Lattner8452a1f2004-08-17 06:36:49 +0000612 O << "\n";
613}
Chris Lattner061d9e22006-01-27 02:10:10 +0000614
615/// printInlineAsm - This method formats and prints the specified machine
616/// instruction that is an inline asm.
617void AsmPrinter::printInlineAsm(const MachineInstr *MI) const {
Chris Lattner57ecb562006-01-30 23:00:08 +0000618 unsigned NumOperands = MI->getNumOperands();
619
620 // Count the number of register definitions.
621 unsigned NumDefs = 0;
622 for (; MI->getOperand(NumDefs).isDef(); ++NumDefs)
623 assert(NumDefs != NumOperands-1 && "No asm string?");
624
625 assert(MI->getOperand(NumDefs).isExternalSymbol() && "No asm string?");
Chris Lattneraa23fa92006-02-01 22:41:11 +0000626
627 // Disassemble the AsmStr, printing out the literal pieces, the operands, etc.
Chris Lattner57ecb562006-01-30 23:00:08 +0000628 const char *AsmStr = MI->getOperand(NumDefs).getSymbolName();
Chris Lattneraa23fa92006-02-01 22:41:11 +0000629
Chris Lattner3390cbe2006-07-28 00:17:20 +0000630 // If this asmstr is empty, don't bother printing the #APP/#NOAPP markers.
631 if (AsmStr[0] == 0) {
632 O << "\n"; // Tab already printed, avoid double indenting next instr.
633 return;
634 }
635
636 O << InlineAsmStart << "\n\t";
637
Chris Lattneraa23fa92006-02-01 22:41:11 +0000638 // The variant of the current asmprinter: FIXME: change.
639 int AsmPrinterVariant = 0;
Chris Lattner57ecb562006-01-30 23:00:08 +0000640
Chris Lattneraa23fa92006-02-01 22:41:11 +0000641 int CurVariant = -1; // The number of the {.|.|.} region we are in.
642 const char *LastEmitted = AsmStr; // One past the last character emitted.
Chris Lattner3a5ed552006-02-01 01:28:23 +0000643
Chris Lattneraa23fa92006-02-01 22:41:11 +0000644 while (*LastEmitted) {
645 switch (*LastEmitted) {
646 default: {
647 // Not a special case, emit the string section literally.
648 const char *LiteralEnd = LastEmitted+1;
649 while (*LiteralEnd && *LiteralEnd != '{' && *LiteralEnd != '|' &&
Chris Lattnera633c3132006-05-05 21:47:05 +0000650 *LiteralEnd != '}' && *LiteralEnd != '$' && *LiteralEnd != '\n')
Chris Lattneraa23fa92006-02-01 22:41:11 +0000651 ++LiteralEnd;
652 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
653 O.write(LastEmitted, LiteralEnd-LastEmitted);
654 LastEmitted = LiteralEnd;
655 break;
656 }
Chris Lattnera633c3132006-05-05 21:47:05 +0000657 case '\n':
658 ++LastEmitted; // Consume newline character.
659 O << "\n\t"; // Indent code with newline.
660 break;
Chris Lattneraa23fa92006-02-01 22:41:11 +0000661 case '$': {
662 ++LastEmitted; // Consume '$' character.
663 if (*LastEmitted == '$') { // $$ -> $
664 if (CurVariant == -1 || CurVariant == AsmPrinterVariant)
665 O << '$';
666 ++LastEmitted; // Consume second '$' character.
667 break;
668 }
669
670 bool HasCurlyBraces = false;
671 if (*LastEmitted == '{') { // ${variable}
672 ++LastEmitted; // Consume '{' character.
673 HasCurlyBraces = true;
674 }
675
676 const char *IDStart = LastEmitted;
677 char *IDEnd;
678 long Val = strtol(IDStart, &IDEnd, 10); // We only accept numbers for IDs.
679 if (!isdigit(*IDStart) || (Val == 0 && errno == EINVAL)) {
680 std::cerr << "Bad $ operand number in inline asm string: '"
681 << AsmStr << "'\n";
682 exit(1);
683 }
684 LastEmitted = IDEnd;
685
Chris Lattner34f74c12006-02-06 22:17:23 +0000686 char Modifier[2] = { 0, 0 };
687
Chris Lattneraa23fa92006-02-01 22:41:11 +0000688 if (HasCurlyBraces) {
Chris Lattner34f74c12006-02-06 22:17:23 +0000689 // If we have curly braces, check for a modifier character. This
690 // supports syntax like ${0:u}, which correspond to "%u0" in GCC asm.
691 if (*LastEmitted == ':') {
692 ++LastEmitted; // Consume ':' character.
693 if (*LastEmitted == 0) {
694 std::cerr << "Bad ${:} expression in inline asm string: '"
695 << AsmStr << "'\n";
696 exit(1);
697 }
698
699 Modifier[0] = *LastEmitted;
700 ++LastEmitted; // Consume modifier character.
701 }
702
Chris Lattneraa23fa92006-02-01 22:41:11 +0000703 if (*LastEmitted != '}') {
704 std::cerr << "Bad ${} expression in inline asm string: '"
705 << AsmStr << "'\n";
706 exit(1);
707 }
708 ++LastEmitted; // Consume '}' character.
709 }
710
711 if ((unsigned)Val >= NumOperands-1) {
712 std::cerr << "Invalid $ operand number in inline asm string: '"
713 << AsmStr << "'\n";
714 exit(1);
715 }
716
Chris Lattner571d9642006-02-23 19:21:04 +0000717 // Okay, we finally have a value number. Ask the target to print this
Chris Lattneraa23fa92006-02-01 22:41:11 +0000718 // operand!
Chris Lattner571d9642006-02-23 19:21:04 +0000719 if (CurVariant == -1 || CurVariant == AsmPrinterVariant) {
720 unsigned OpNo = 1;
Chris Lattner8f8b5e42006-06-08 18:00:47 +0000721
722 bool Error = false;
723
Chris Lattner571d9642006-02-23 19:21:04 +0000724 // Scan to find the machine operand number for the operand.
Chris Lattner5af3fde2006-02-24 19:50:58 +0000725 for (; Val; --Val) {
Chris Lattner8f8b5e42006-06-08 18:00:47 +0000726 if (OpNo >= MI->getNumOperands()) break;
Chris Lattner5af3fde2006-02-24 19:50:58 +0000727 unsigned OpFlags = MI->getOperand(OpNo).getImmedValue();
728 OpNo += (OpFlags >> 3) + 1;
729 }
Chris Lattner1d08c652006-02-24 20:21:58 +0000730
Chris Lattner8f8b5e42006-06-08 18:00:47 +0000731 if (OpNo >= MI->getNumOperands()) {
732 Error = true;
Chris Lattner1d08c652006-02-24 20:21:58 +0000733 } else {
Chris Lattner8f8b5e42006-06-08 18:00:47 +0000734 unsigned OpFlags = MI->getOperand(OpNo).getImmedValue();
735 ++OpNo; // Skip over the ID number.
736
737 AsmPrinter *AP = const_cast<AsmPrinter*>(this);
738 if ((OpFlags & 7) == 4 /*ADDR MODE*/) {
739 Error = AP->PrintAsmMemoryOperand(MI, OpNo, AsmPrinterVariant,
740 Modifier[0] ? Modifier : 0);
741 } else {
742 Error = AP->PrintAsmOperand(MI, OpNo, AsmPrinterVariant,
743 Modifier[0] ? Modifier : 0);
744 }
Chris Lattner1d08c652006-02-24 20:21:58 +0000745 }
746 if (Error) {
Chris Lattneraa23fa92006-02-01 22:41:11 +0000747 std::cerr << "Invalid operand found in inline asm: '"
748 << AsmStr << "'\n";
749 MI->dump();
750 exit(1);
751 }
Chris Lattner571d9642006-02-23 19:21:04 +0000752 }
Chris Lattneraa23fa92006-02-01 22:41:11 +0000753 break;
754 }
755 case '{':
756 ++LastEmitted; // Consume '{' character.
757 if (CurVariant != -1) {
758 std::cerr << "Nested variants found in inline asm string: '"
759 << AsmStr << "'\n";
760 exit(1);
761 }
762 CurVariant = 0; // We're in the first variant now.
763 break;
764 case '|':
765 ++LastEmitted; // consume '|' character.
766 if (CurVariant == -1) {
767 std::cerr << "Found '|' character outside of variant in inline asm "
768 << "string: '" << AsmStr << "'\n";
769 exit(1);
770 }
771 ++CurVariant; // We're in the next variant.
772 break;
773 case '}':
774 ++LastEmitted; // consume '}' character.
775 if (CurVariant == -1) {
776 std::cerr << "Found '}' character outside of variant in inline asm "
777 << "string: '" << AsmStr << "'\n";
778 exit(1);
779 }
780 CurVariant = -1;
781 break;
782 }
783 }
Chris Lattnera633c3132006-05-05 21:47:05 +0000784 O << "\n\t" << InlineAsmEnd << "\n";
Chris Lattneraa23fa92006-02-01 22:41:11 +0000785}
786
787/// PrintAsmOperand - Print the specified operand of MI, an INLINEASM
788/// instruction, using the specified assembler variant. Targets should
789/// overried this to format as appropriate.
790bool AsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
Chris Lattner34f74c12006-02-06 22:17:23 +0000791 unsigned AsmVariant, const char *ExtraCode) {
Chris Lattneraa23fa92006-02-01 22:41:11 +0000792 // Target doesn't support this yet!
793 return true;
Chris Lattner061d9e22006-01-27 02:10:10 +0000794}
Chris Lattner1d08c652006-02-24 20:21:58 +0000795
796bool AsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI, unsigned OpNo,
797 unsigned AsmVariant,
798 const char *ExtraCode) {
799 // Target doesn't support this yet!
800 return true;
801}
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000802
803/// printBasicBlockLabel - This method prints the label for the specified
804/// MachineBasicBlock
Nate Begemanb9d4f832006-05-02 05:37:32 +0000805void AsmPrinter::printBasicBlockLabel(const MachineBasicBlock *MBB,
806 bool printColon,
807 bool printComment) const {
Nate Begeman4971ba52006-05-02 17:36:46 +0000808 O << PrivateGlobalPrefix << "BB" << FunctionNumber << "_"
809 << MBB->getNumber();
Nate Begemanb9d4f832006-05-02 05:37:32 +0000810 if (printColon)
811 O << ':';
812 if (printComment)
813 O << '\t' << CommentString << MBB->getBasicBlock()->getName();
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000814}