blob: 44a218ca1ebbb76fa36b0b2cbd60dead8005e057 [file] [log] [blame]
Chris Lattnerb9740462005-07-01 22:44:09 +00001//===-- X86IntelAsmPrinter.cpp - Convert X86 LLVM code to Intel assembly --===//
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 contains a printer that converts from our internal representation
11// of machine-dependent LLVM code to Intel format assembly language.
12// This printer is the output mechanism used by `llc'.
13//
14//===----------------------------------------------------------------------===//
15
16#include "X86IntelAsmPrinter.h"
Jim Laskey261779b2006-09-07 22:06:40 +000017#include "X86TargetAsmInfo.h"
Chris Lattnerb9740462005-07-01 22:44:09 +000018#include "X86.h"
Jeff Cohen24a62a92006-05-02 01:16:28 +000019#include "llvm/Constants.h"
Chris Lattnerb9740462005-07-01 22:44:09 +000020#include "llvm/Module.h"
21#include "llvm/Assembly/Writer.h"
22#include "llvm/Support/Mangler.h"
Jim Laskey261779b2006-09-07 22:06:40 +000023#include "llvm/Target/TargetAsmInfo.h"
Evan Cheng5588de92006-02-18 00:15:05 +000024#include "llvm/Target/TargetOptions.h"
Chris Lattnerb9740462005-07-01 22:44:09 +000025using namespace llvm;
Chris Lattnerb9740462005-07-01 22:44:09 +000026
27/// runOnMachineFunction - This uses the printMachineInstruction()
28/// method to print assembly for each instruction.
29///
30bool X86IntelAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
Chris Lattner99946fb2005-11-21 07:51:23 +000031 SetupMachineFunction(MF);
Chris Lattnerb9740462005-07-01 22:44:09 +000032 O << "\n\n";
33
34 // Print out constants referenced by the function
Chris Lattner8a5f3c12005-11-21 08:32:23 +000035 EmitConstantPool(MF.getConstantPool());
Chris Lattnerb9740462005-07-01 22:44:09 +000036
37 // Print out labels for the function.
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +000038 const Function* F = MF.getFunction();
39 switch (F->getLinkage()) {
40 default: assert(0 && "Unsupported linkage type!");
41 case Function::InternalLinkage:
42 SwitchToTextSection("_text", F);
43 EmitAlignment(4);
44 break;
45 case Function::DLLExportLinkage:
46 DLLExportedFns.insert(CurrentFnName);
47 //FALLS THROUGH
48 case Function::ExternalLinkage:
Jeff Cohen24a62a92006-05-02 01:16:28 +000049 O << "\tpublic " << CurrentFnName << "\n";
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +000050 SwitchToTextSection("_text", F);
51 EmitAlignment(4);
52 break;
53 }
54
Jeff Cohen24a62a92006-05-02 01:16:28 +000055 O << CurrentFnName << "\tproc near\n";
Jim Laskeyc0d65182006-04-07 20:44:42 +000056
Chris Lattnerb9740462005-07-01 22:44:09 +000057 // Print out code for the function.
58 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end();
59 I != E; ++I) {
60 // Print a label for the basic block if there are any predecessors.
Nate Begemanb9d4f832006-05-02 05:37:32 +000061 if (I->pred_begin() != I->pred_end()) {
62 printBasicBlockLabel(I, true);
63 O << '\n';
64 }
Chris Lattnerb9740462005-07-01 22:44:09 +000065 for (MachineBasicBlock::const_iterator II = I->begin(), E = I->end();
66 II != E; ++II) {
67 // Print the assembly for the instruction.
68 O << "\t";
69 printMachineInstruction(II);
70 }
71 }
72
Jeff Cohen24a62a92006-05-02 01:16:28 +000073 O << CurrentFnName << "\tendp\n";
74
Chris Lattnerb9740462005-07-01 22:44:09 +000075 // We didn't modify anything.
76 return false;
77}
78
Nate Begeman6f8c1ac2005-11-30 18:54:35 +000079void X86IntelAsmPrinter::printSSECC(const MachineInstr *MI, unsigned Op) {
Nate Begeman0f38dc42005-07-14 22:52:25 +000080 unsigned char value = MI->getOperand(Op).getImmedValue();
81 assert(value <= 7 && "Invalid ssecc argument!");
82 switch (value) {
83 case 0: O << "eq"; break;
84 case 1: O << "lt"; break;
85 case 2: O << "le"; break;
86 case 3: O << "unord"; break;
87 case 4: O << "neq"; break;
88 case 5: O << "nlt"; break;
89 case 6: O << "nle"; break;
90 case 7: O << "ord"; break;
91 }
92}
93
Chris Lattnerd62a3bf2006-02-06 23:41:19 +000094void X86IntelAsmPrinter::printOp(const MachineOperand &MO,
95 const char *Modifier) {
Chris Lattnerb9740462005-07-01 22:44:09 +000096 const MRegisterInfo &RI = *TM.getRegisterInfo();
97 switch (MO.getType()) {
Chris Lattner10b71c02006-05-04 18:05:43 +000098 case MachineOperand::MO_Register:
Evan Chengddb6cc12006-05-05 05:40:20 +000099 if (MRegisterInfo::isPhysicalRegister(MO.getReg())) {
100 unsigned Reg = MO.getReg();
Evan Chengcfaffdd2006-05-31 22:34:26 +0000101 if (Modifier && strncmp(Modifier, "subreg", strlen("subreg")) == 0) {
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000102 MVT::ValueType VT = (strcmp(Modifier,"subreg64") == 0) ?
103 MVT::i64 : ((strcmp(Modifier, "subreg32") == 0) ? MVT::i32 :
104 ((strcmp(Modifier,"subreg16") == 0) ? MVT::i16 :MVT::i8));
Evan Chengddb6cc12006-05-05 05:40:20 +0000105 Reg = getX86SubSuperRegister(Reg, VT);
106 }
107 O << RI.get(Reg).Name;
108 } else
Chris Lattner563f0412006-05-01 05:53:50 +0000109 O << "reg" << MO.getReg();
Chris Lattnerb9740462005-07-01 22:44:09 +0000110 return;
111
Chris Lattnerfef7a2d2006-05-04 17:21:20 +0000112 case MachineOperand::MO_Immediate:
Evan Cheng70145f22006-05-26 08:04:31 +0000113 O << MO.getImmedValue();
Chris Lattnerb9740462005-07-01 22:44:09 +0000114 return;
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000115 case MachineOperand::MO_MachineBasicBlock:
116 printBasicBlockLabel(MO.getMachineBasicBlock());
Chris Lattnerb9740462005-07-01 22:44:09 +0000117 return;
Evan Cheng75b87832006-02-26 08:28:12 +0000118 case MachineOperand::MO_ConstantPoolIndex: {
119 bool isMemOp = Modifier && !strcmp(Modifier, "mem");
120 if (!isMemOp) O << "OFFSET ";
Jim Laskeya6211dc2006-09-06 18:34:40 +0000121 O << "[" << TAI->getPrivateGlobalPrefix() << "CPI"
122 << getFunctionNumber() << "_" << MO.getConstantPoolIndex();
Evan Cheng75b87832006-02-26 08:28:12 +0000123 int Offset = MO.getOffset();
124 if (Offset > 0)
125 O << " + " << Offset;
126 else if (Offset < 0)
127 O << Offset;
128 O << "]";
129 return;
130 }
Chris Lattnerb9740462005-07-01 22:44:09 +0000131 case MachineOperand::MO_GlobalAddress: {
Evan Cheng5588de92006-02-18 00:15:05 +0000132 bool isCallOp = Modifier && !strcmp(Modifier, "call");
133 bool isMemOp = Modifier && !strcmp(Modifier, "mem");
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000134 GlobalValue *GV = MO.getGlobal();
135
Evan Cheng5588de92006-02-18 00:15:05 +0000136 if (!isMemOp && !isCallOp) O << "OFFSET ";
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000137 if (GV->hasDLLImportLinkage()) {
138 // FIXME: This should be fixed with full support of stdcall & fastcall
139 // CC's
140 O << "__imp_";
141 }
142 O << Mang->getValueName(GV);
Chris Lattnerb9740462005-07-01 22:44:09 +0000143 int Offset = MO.getOffset();
144 if (Offset > 0)
145 O << " + " << Offset;
146 else if (Offset < 0)
Evan Chengd2cb7052005-11-30 01:59:00 +0000147 O << Offset;
Chris Lattnerb9740462005-07-01 22:44:09 +0000148 return;
149 }
Evan Cheng5588de92006-02-18 00:15:05 +0000150 case MachineOperand::MO_ExternalSymbol: {
151 bool isCallOp = Modifier && !strcmp(Modifier, "call");
Evan Cheng73136df2006-02-22 20:19:42 +0000152 if (!isCallOp) O << "OFFSET ";
Jim Laskeya6211dc2006-09-06 18:34:40 +0000153 O << TAI->getGlobalPrefix() << MO.getSymbolName();
Chris Lattnerb9740462005-07-01 22:44:09 +0000154 return;
Evan Cheng5588de92006-02-18 00:15:05 +0000155 }
Chris Lattnerb9740462005-07-01 22:44:09 +0000156 default:
157 O << "<unknown operand type>"; return;
158 }
159}
160
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000161void X86IntelAsmPrinter::printMemReference(const MachineInstr *MI, unsigned Op,
162 const char *Modifier) {
Chris Lattnerb9740462005-07-01 22:44:09 +0000163 assert(isMem(MI, Op) && "Invalid memory reference!");
164
165 const MachineOperand &BaseReg = MI->getOperand(Op);
166 int ScaleVal = MI->getOperand(Op+1).getImmedValue();
167 const MachineOperand &IndexReg = MI->getOperand(Op+2);
168 const MachineOperand &DispSpec = MI->getOperand(Op+3);
169
170 if (BaseReg.isFrameIndex()) {
171 O << "[frame slot #" << BaseReg.getFrameIndex();
172 if (DispSpec.getImmedValue())
173 O << " + " << DispSpec.getImmedValue();
174 O << "]";
175 return;
Chris Lattnerb9740462005-07-01 22:44:09 +0000176 }
177
178 O << "[";
179 bool NeedPlus = false;
180 if (BaseReg.getReg()) {
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000181 printOp(BaseReg, Modifier);
Chris Lattnerb9740462005-07-01 22:44:09 +0000182 NeedPlus = true;
183 }
184
185 if (IndexReg.getReg()) {
186 if (NeedPlus) O << " + ";
187 if (ScaleVal != 1)
188 O << ScaleVal << "*";
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000189 printOp(IndexReg, Modifier);
Chris Lattnerb9740462005-07-01 22:44:09 +0000190 NeedPlus = true;
191 }
192
Evan Cheng75b87832006-02-26 08:28:12 +0000193 if (DispSpec.isGlobalAddress() || DispSpec.isConstantPoolIndex()) {
Chris Lattnerb9740462005-07-01 22:44:09 +0000194 if (NeedPlus)
195 O << " + ";
Evan Cheng5a766802006-02-07 08:38:37 +0000196 printOp(DispSpec, "mem");
Chris Lattnerb9740462005-07-01 22:44:09 +0000197 } else {
198 int DispVal = DispSpec.getImmedValue();
199 if (DispVal || (!BaseReg.getReg() && !IndexReg.getReg())) {
200 if (NeedPlus)
201 if (DispVal > 0)
202 O << " + ";
203 else {
204 O << " - ";
205 DispVal = -DispVal;
206 }
207 O << DispVal;
208 }
209 }
210 O << "]";
211}
212
Evan Cheng5588de92006-02-18 00:15:05 +0000213void X86IntelAsmPrinter::printPICLabel(const MachineInstr *MI, unsigned Op) {
214 O << "\"L" << getFunctionNumber() << "$pb\"\n";
215 O << "\"L" << getFunctionNumber() << "$pb\":";
216}
Chris Lattnerb9740462005-07-01 22:44:09 +0000217
Evan Chengd3696032006-04-28 23:19:39 +0000218bool X86IntelAsmPrinter::printAsmMRegister(const MachineOperand &MO,
Evan Chengb244b802006-04-28 23:11:40 +0000219 const char Mode) {
220 const MRegisterInfo &RI = *TM.getRegisterInfo();
221 unsigned Reg = MO.getReg();
Evan Chengb244b802006-04-28 23:11:40 +0000222 switch (Mode) {
223 default: return true; // Unknown mode.
224 case 'b': // Print QImode register
Evan Chengddb6cc12006-05-05 05:40:20 +0000225 Reg = getX86SubSuperRegister(Reg, MVT::i8);
Evan Chengb244b802006-04-28 23:11:40 +0000226 break;
227 case 'h': // Print QImode high register
Evan Chengddb6cc12006-05-05 05:40:20 +0000228 Reg = getX86SubSuperRegister(Reg, MVT::i8, true);
Evan Chengb244b802006-04-28 23:11:40 +0000229 break;
230 case 'w': // Print HImode register
Evan Chengddb6cc12006-05-05 05:40:20 +0000231 Reg = getX86SubSuperRegister(Reg, MVT::i16);
Evan Chengb244b802006-04-28 23:11:40 +0000232 break;
233 case 'k': // Print SImode register
Evan Chengddb6cc12006-05-05 05:40:20 +0000234 Reg = getX86SubSuperRegister(Reg, MVT::i32);
Evan Chengb244b802006-04-28 23:11:40 +0000235 break;
236 }
237
Evan Chengddb6cc12006-05-05 05:40:20 +0000238 O << '%' << RI.get(Reg).Name;
Evan Chengb244b802006-04-28 23:11:40 +0000239 return false;
240}
241
Evan Cheng68a44dc2006-04-28 21:19:05 +0000242/// PrintAsmOperand - Print out an operand for an inline asm expression.
243///
244bool X86IntelAsmPrinter::PrintAsmOperand(const MachineInstr *MI, unsigned OpNo,
245 unsigned AsmVariant,
246 const char *ExtraCode) {
247 // Does this asm operand have a single letter operand modifier?
248 if (ExtraCode && ExtraCode[0]) {
249 if (ExtraCode[1] != 0) return true; // Unknown modifier.
250
251 switch (ExtraCode[0]) {
252 default: return true; // Unknown modifier.
Evan Chengb244b802006-04-28 23:11:40 +0000253 case 'b': // Print QImode register
254 case 'h': // Print QImode high register
255 case 'w': // Print HImode register
256 case 'k': // Print SImode register
Evan Chengd3696032006-04-28 23:19:39 +0000257 return printAsmMRegister(MI->getOperand(OpNo), ExtraCode[0]);
Evan Cheng68a44dc2006-04-28 21:19:05 +0000258 }
259 }
260
261 printOperand(MI, OpNo);
262 return false;
263}
264
265bool X86IntelAsmPrinter::PrintAsmMemoryOperand(const MachineInstr *MI,
266 unsigned OpNo,
267 unsigned AsmVariant,
268 const char *ExtraCode) {
269 if (ExtraCode && ExtraCode[0])
270 return true; // Unknown modifier.
271 printMemReference(MI, OpNo);
272 return false;
273}
274
Chris Lattnerb9740462005-07-01 22:44:09 +0000275/// printMachineInstruction -- Print out a single X86 LLVM instruction
276/// MI in Intel syntax to the current output stream.
277///
278void X86IntelAsmPrinter::printMachineInstruction(const MachineInstr *MI) {
279 ++EmittedInsts;
280
Evan Chengddb6cc12006-05-05 05:40:20 +0000281 // See if a truncate instruction can be turned into a nop.
282 switch (MI->getOpcode()) {
283 default: break;
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000284 case X86::TRUNC_64to32:
285 case X86::TRUNC_64to16:
286 case X86::TRUNC_32to16:
287 case X86::TRUNC_32to8:
288 case X86::TRUNC_16to8:
289 case X86::TRUNC_32_to8:
290 case X86::TRUNC_16_to8: {
Evan Chengddb6cc12006-05-05 05:40:20 +0000291 const MachineOperand &MO0 = MI->getOperand(0);
292 const MachineOperand &MO1 = MI->getOperand(1);
293 unsigned Reg0 = MO0.getReg();
294 unsigned Reg1 = MO1.getReg();
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000295 unsigned Opc = MI->getOpcode();
296 if (Opc == X86::TRUNC_64to32)
297 Reg1 = getX86SubSuperRegister(Reg1, MVT::i32);
298 else if (Opc == X86::TRUNC_32to16 || Opc == X86::TRUNC_64to16)
Evan Cheng9733bde2006-05-08 08:01:26 +0000299 Reg1 = getX86SubSuperRegister(Reg1, MVT::i16);
Evan Chengddb6cc12006-05-05 05:40:20 +0000300 else
Evan Cheng9733bde2006-05-08 08:01:26 +0000301 Reg1 = getX86SubSuperRegister(Reg1, MVT::i8);
Jim Laskeya6211dc2006-09-06 18:34:40 +0000302 O << TAI->getCommentString() << " TRUNCATE ";
Evan Cheng9733bde2006-05-08 08:01:26 +0000303 if (Reg0 != Reg1)
304 O << "\n\t";
Evan Chengddb6cc12006-05-05 05:40:20 +0000305 break;
306 }
Evan Cheng11b0a5d2006-09-08 06:48:29 +0000307 case X86::PsMOVZX64rr32:
308 O << TAI->getCommentString() << " ZERO-EXTEND " << "\n\t";
309 break;
Evan Chengddb6cc12006-05-05 05:40:20 +0000310 }
311
Chris Lattnerb9740462005-07-01 22:44:09 +0000312 // Call the autogenerated instruction printer routines.
313 printInstruction(MI);
314}
315
316bool X86IntelAsmPrinter::doInitialization(Module &M) {
Jeff Cohence9b9fe2006-05-06 21:27:14 +0000317 X86SharedAsmPrinter::doInitialization(M);
Chris Lattnerd0201942006-05-09 05:12:53 +0000318
Jim Laskeya6211dc2006-09-06 18:34:40 +0000319 Mang->markCharUnacceptable('.');
Jeff Cohen06041ab2006-05-04 16:20:22 +0000320
Jeff Cohenbfe9ffb2006-05-02 03:11:50 +0000321 O << "\t.686\n\t.model flat\n\n";
322
323 // Emit declarations for external functions.
324 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
325 if (I->isExternal())
326 O << "\textern " << Mang->getValueName(I) << ":near\n";
327
Jeff Cohence9b9fe2006-05-06 21:27:14 +0000328 // Emit declarations for external globals. Note that VC++ always declares
329 // external globals to have type byte, and if that's good enough for VC++...
Jeff Cohenbfe9ffb2006-05-02 03:11:50 +0000330 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
331 I != E; ++I) {
332 if (I->isExternal())
333 O << "\textern " << Mang->getValueName(I) << ":byte\n";
334 }
335
Chris Lattnerb9740462005-07-01 22:44:09 +0000336 return false;
337}
338
Jeff Cohenbfe9ffb2006-05-02 03:11:50 +0000339bool X86IntelAsmPrinter::doFinalization(Module &M) {
Jeff Cohence9b9fe2006-05-06 21:27:14 +0000340 const TargetData *TD = TM.getTargetData();
341
342 // Print out module-level global variables here.
343 for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
344 I != E; ++I) {
345 if (I->isExternal()) continue; // External global require no code
346
347 // Check to see if this is a special global used by LLVM, if so, emit it.
348 if (EmitSpecialLLVMGlobal(I))
349 continue;
350
351 std::string name = Mang->getValueName(I);
352 Constant *C = I->getInitializer();
353 unsigned Size = TD->getTypeSize(C->getType());
354 unsigned Align = getPreferredAlignmentLog(I);
355 bool bCustomSegment = false;
356
357 switch (I->getLinkage()) {
358 case GlobalValue::LinkOnceLinkage:
359 case GlobalValue::WeakLinkage:
Chris Lattner8488ba22006-05-09 04:59:56 +0000360 SwitchToDataSection("", 0);
Jeff Cohence9b9fe2006-05-06 21:27:14 +0000361 O << name << "?\tsegment common 'COMMON'\n";
362 bCustomSegment = true;
363 // FIXME: the default alignment is 16 bytes, but 1, 2, 4, and 256
364 // are also available.
365 break;
366 case GlobalValue::AppendingLinkage:
Chris Lattner8488ba22006-05-09 04:59:56 +0000367 SwitchToDataSection("", 0);
Jeff Cohence9b9fe2006-05-06 21:27:14 +0000368 O << name << "?\tsegment public 'DATA'\n";
369 bCustomSegment = true;
370 // FIXME: the default alignment is 16 bytes, but 1, 2, 4, and 256
371 // are also available.
372 break;
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000373 case GlobalValue::DLLExportLinkage:
374 DLLExportedGVs.insert(name);
375 // FALL THROUGH
Jeff Cohence9b9fe2006-05-06 21:27:14 +0000376 case GlobalValue::ExternalLinkage:
377 O << "\tpublic " << name << "\n";
378 // FALL THROUGH
379 case GlobalValue::InternalLinkage:
Jim Laskeya6211dc2006-09-06 18:34:40 +0000380 SwitchToDataSection(TAI->getDataSection(), I);
Jeff Cohence9b9fe2006-05-06 21:27:14 +0000381 break;
382 default:
383 assert(0 && "Unknown linkage type!");
384 }
385
386 if (!bCustomSegment)
387 EmitAlignment(Align, I);
388
Jim Laskeya6211dc2006-09-06 18:34:40 +0000389 O << name << ":\t\t\t\t" << TAI->getCommentString()
390 << " " << I->getName() << '\n';
Jeff Cohence9b9fe2006-05-06 21:27:14 +0000391
392 EmitGlobalConstant(C);
393
394 if (bCustomSegment)
395 O << name << "?\tends\n";
396 }
Anton Korobeynikovd61d39e2006-09-14 18:23:27 +0000397
398 // Output linker support code for dllexported globals
399 if ((DLLExportedGVs.begin() != DLLExportedGVs.end()) ||
400 (DLLExportedFns.begin() != DLLExportedFns.end())) {
401 SwitchToDataSection("", 0);
402 O << "; WARNING: The following code is valid only with MASM v8.x and (possible) higher\n"
403 << "; This version of MASM is usually shipped with Microsoft Visual Studio 2005\n"
404 << "; or (possible) further versions. Unfortunately, there is no way to support\n"
405 << "; dllexported symbols in the earlier versions of MASM in fully automatic way\n\n";
406 O << "_drectve\t segment info alias('.drectve')\n";
407 }
408
409 for (std::set<std::string>::iterator i = DLLExportedGVs.begin(),
410 e = DLLExportedGVs.end();
411 i != e; ++i) {
412 O << "\t db ' /EXPORT:" << *i << ",data'\n";
413 }
414
415 for (std::set<std::string>::iterator i = DLLExportedFns.begin(),
416 e = DLLExportedFns.end();
417 i != e; ++i) {
418 O << "\t db ' /EXPORT:" << *i << "'\n";
419 }
420
421 if ((DLLExportedGVs.begin() != DLLExportedGVs.end()) ||
422 (DLLExportedFns.begin() != DLLExportedFns.end())) {
423 O << "_drectve\t ends\n";
424 }
Jeff Cohence9b9fe2006-05-06 21:27:14 +0000425
426 // Bypass X86SharedAsmPrinter::doFinalization().
427 AsmPrinter::doFinalization(M);
Chris Lattnere0006c62006-05-09 05:15:24 +0000428 SwitchToDataSection("", 0);
Jeff Cohenbfe9ffb2006-05-02 03:11:50 +0000429 O << "\tend\n";
Jeff Cohence9b9fe2006-05-06 21:27:14 +0000430 return false; // success
Jeff Cohenbfe9ffb2006-05-02 03:11:50 +0000431}
432
Jeff Cohen24a62a92006-05-02 01:16:28 +0000433void X86IntelAsmPrinter::EmitString(const ConstantArray *CVA) const {
434 unsigned NumElts = CVA->getNumOperands();
435 if (NumElts) {
436 // ML does not have escape sequences except '' for '. It also has a maximum
437 // string length of 255.
438 unsigned len = 0;
439 bool inString = false;
440 for (unsigned i = 0; i < NumElts; i++) {
441 int n = cast<ConstantInt>(CVA->getOperand(i))->getRawValue() & 255;
442 if (len == 0)
443 O << "\tdb ";
444
445 if (n >= 32 && n <= 127) {
446 if (!inString) {
447 if (len > 0) {
448 O << ",'";
449 len += 2;
450 } else {
451 O << "'";
452 len++;
453 }
454 inString = true;
455 }
456 if (n == '\'') {
457 O << "'";
458 len++;
459 }
460 O << char(n);
461 } else {
462 if (inString) {
463 O << "'";
464 len++;
465 inString = false;
466 }
467 if (len > 0) {
468 O << ",";
469 len++;
470 }
471 O << n;
472 len += 1 + (n > 9) + (n > 99);
473 }
474
475 if (len > 60) {
476 if (inString) {
477 O << "'";
478 inString = false;
479 }
480 O << "\n";
481 len = 0;
482 }
483 }
484
485 if (len > 0) {
486 if (inString)
487 O << "'";
488 O << "\n";
489 }
490 }
491}
492
Chris Lattnerb9740462005-07-01 22:44:09 +0000493// Include the auto-generated portion of the assembly writer.
494#include "X86GenAsmWriter1.inc"