blob: a202ffab06b0edc6a2776c9310a984253af26295 [file] [log] [blame]
Chris Lattnere88f78c2001-09-19 13:47:27 +00001//===-- EmitAssembly.cpp - Emit Sparc Specific .s File ---------------------==//
John Criswellb576c942003-10-20 19:43:21 +00002//
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//===----------------------------------------------------------------------===//
Chris Lattnere88f78c2001-09-19 13:47:27 +00009//
Misha Brukman5560c9d2003-08-18 14:43:39 +000010// This file implements all of the stuff necessary to output a .s file from
Chris Lattnere88f78c2001-09-19 13:47:27 +000011// LLVM. The code in this file assumes that the specified module has already
12// been compiled into the internal data structures of the Module.
13//
Chris Lattnerf57b8452002-04-27 06:56:12 +000014// This code largely consists of two LLVM Pass's: a FunctionPass and a Pass.
15// The FunctionPass is pipelined together with all of the rest of the code
16// generation stages, and the Pass runs at the end to emit code for global
17// variables and such.
Chris Lattnere88f78c2001-09-19 13:47:27 +000018//
19//===----------------------------------------------------------------------===//
20
Chris Lattner31bcdb82002-04-28 19:55:58 +000021#include "llvm/Constants.h"
Vikram S. Adve953c83e2001-10-28 21:38:52 +000022#include "llvm/DerivedTypes.h"
Chris Lattnere88f78c2001-09-19 13:47:27 +000023#include "llvm/Module.h"
Chris Lattnerd50b6712002-04-28 20:40:59 +000024#include "llvm/Pass.h"
Chris Lattner4b1de8e2002-04-18 18:15:38 +000025#include "llvm/Assembly/Writer.h"
Misha Brukman3d0ad412003-12-17 22:06:28 +000026#include "llvm/CodeGen/MachineConstantPool.h"
27#include "llvm/CodeGen/MachineFunction.h"
28#include "llvm/CodeGen/MachineFunctionInfo.h"
29#include "llvm/CodeGen/MachineInstr.h"
Chris Lattnercee8f9a2001-11-27 00:03:19 +000030#include "Support/StringExtras.h"
Brian Gaeke2c9b9132003-10-06 15:41:21 +000031#include "Support/Statistic.h"
Misha Brukmanf4de7832003-08-05 16:01:50 +000032#include "SparcInternals.h"
33#include <string>
Misha Brukman6275a042003-11-13 00:22:19 +000034using namespace llvm;
35
Chris Lattnere88f78c2001-09-19 13:47:27 +000036namespace {
Misha Brukman6275a042003-11-13 00:22:19 +000037 Statistic<> EmittedInsts("asm-printer", "Number of machine instrs printed");
Brian Gaeke2c9b9132003-10-06 15:41:21 +000038
Misha Brukman6275a042003-11-13 00:22:19 +000039 class GlobalIdTable: public Annotation {
40 static AnnotationID AnnotId;
41 friend class AsmPrinter; // give access to AnnotId
Misha Brukman6275a042003-11-13 00:22:19 +000042 public:
Chris Lattner7446dc02004-01-13 21:27:59 +000043 // AnonymousObjectMap - map anonymous values to unique integer IDs
44 std::map<const Value*, unsigned> AnonymousObjectMap;
45 unsigned LastAnonIDUsed;
Misha Brukman6275a042003-11-13 00:22:19 +000046
Chris Lattner7446dc02004-01-13 21:27:59 +000047 GlobalIdTable() : Annotation(AnnotId), LastAnonIDUsed(0) {}
Misha Brukman6275a042003-11-13 00:22:19 +000048 };
Vikram S. Adved198c472002-03-18 03:07:26 +000049
Misha Brukman6275a042003-11-13 00:22:19 +000050 AnnotationID GlobalIdTable::AnnotId =
Vikram S. Adved198c472002-03-18 03:07:26 +000051 AnnotationManager::getID("ASM PRINTER GLOBAL TABLE ANNOT");
Misha Brukman6275a042003-11-13 00:22:19 +000052
53 //===--------------------------------------------------------------------===//
54 // Utility functions
Misha Brukmanf905ed52003-11-07 17:45:28 +000055
Misha Brukman6275a042003-11-13 00:22:19 +000056 /// getAsCString - Return the specified array as a C compatible string, only
Chris Lattner07ad6422004-01-14 17:15:17 +000057 /// if the predicate isString() is true.
Misha Brukman6275a042003-11-13 00:22:19 +000058 ///
59 std::string getAsCString(const ConstantArray *CVA) {
Chris Lattner07ad6422004-01-14 17:15:17 +000060 assert(CVA->isString() && "Array is not string compatible!");
Misha Brukmanf905ed52003-11-07 17:45:28 +000061
Chris Lattner07ad6422004-01-14 17:15:17 +000062 std::string Result = "\"";
63 for (unsigned i = 0; i != CVA->getNumOperands(); ++i) {
Misha Brukman6275a042003-11-13 00:22:19 +000064 unsigned char C = cast<ConstantInt>(CVA->getOperand(i))->getRawValue();
Misha Brukmanf905ed52003-11-07 17:45:28 +000065
Misha Brukman6275a042003-11-13 00:22:19 +000066 if (C == '"') {
67 Result += "\\\"";
68 } else if (C == '\\') {
69 Result += "\\\\";
70 } else if (isprint(C)) {
71 Result += C;
72 } else {
73 Result += '\\'; // print all other chars as octal value
74 // Convert C to octal representation
75 Result += ((C >> 6) & 7) + '0';
76 Result += ((C >> 3) & 7) + '0';
77 Result += ((C >> 0) & 7) + '0';
78 }
79 }
80 Result += "\"";
Misha Brukmanf905ed52003-11-07 17:45:28 +000081
Misha Brukman6275a042003-11-13 00:22:19 +000082 return Result;
83 }
84
85 inline bool ArrayTypeIsString(const ArrayType* arrayType) {
86 return (arrayType->getElementType() == Type::UByteTy ||
87 arrayType->getElementType() == Type::SByteTy);
88 }
89
90 inline const std::string
91 TypeToDataDirective(const Type* type) {
92 switch(type->getPrimitiveID())
Misha Brukmanf905ed52003-11-07 17:45:28 +000093 {
94 case Type::BoolTyID: case Type::UByteTyID: case Type::SByteTyID:
95 return ".byte";
96 case Type::UShortTyID: case Type::ShortTyID:
97 return ".half";
98 case Type::UIntTyID: case Type::IntTyID:
99 return ".word";
100 case Type::ULongTyID: case Type::LongTyID: case Type::PointerTyID:
101 return ".xword";
102 case Type::FloatTyID:
103 return ".word";
104 case Type::DoubleTyID:
105 return ".xword";
106 case Type::ArrayTyID:
107 if (ArrayTypeIsString((ArrayType*) type))
108 return ".ascii";
109 else
110 return "<InvaliDataTypeForPrinting>";
111 default:
112 return "<InvaliDataTypeForPrinting>";
113 }
Misha Brukman6275a042003-11-13 00:22:19 +0000114 }
Misha Brukmanf905ed52003-11-07 17:45:28 +0000115
Misha Brukman6275a042003-11-13 00:22:19 +0000116 /// Get the size of the constant for the given target.
117 /// If this is an unsized array, return 0.
118 ///
119 inline unsigned int
120 ConstantToSize(const Constant* CV, const TargetMachine& target) {
121 if (const ConstantArray* CVA = dyn_cast<ConstantArray>(CV)) {
Misha Brukmanf905ed52003-11-07 17:45:28 +0000122 const ArrayType *aty = cast<ArrayType>(CVA->getType());
123 if (ArrayTypeIsString(aty))
124 return 1 + CVA->getNumOperands();
125 }
126
Misha Brukman6275a042003-11-13 00:22:19 +0000127 return target.findOptimalStorageSize(CV->getType());
128 }
Misha Brukmanf905ed52003-11-07 17:45:28 +0000129
Misha Brukman6275a042003-11-13 00:22:19 +0000130 /// Align data larger than one L1 cache line on L1 cache line boundaries.
131 /// Align all smaller data on the next higher 2^x boundary (4, 8, ...).
132 ///
133 inline unsigned int
134 SizeToAlignment(unsigned int size, const TargetMachine& target) {
135 unsigned short cacheLineSize = target.getCacheInfo().getCacheLineSize(1);
136 if (size > (unsigned) cacheLineSize / 2)
137 return cacheLineSize;
138 else
139 for (unsigned sz=1; /*no condition*/; sz *= 2)
140 if (sz >= size)
141 return sz;
142 }
Misha Brukmanf905ed52003-11-07 17:45:28 +0000143
Misha Brukman6275a042003-11-13 00:22:19 +0000144 /// Get the size of the type and then use SizeToAlignment.
145 ///
146 inline unsigned int
147 TypeToAlignment(const Type* type, const TargetMachine& target) {
148 return SizeToAlignment(target.findOptimalStorageSize(type), target);
149 }
Misha Brukmanf905ed52003-11-07 17:45:28 +0000150
Misha Brukman6275a042003-11-13 00:22:19 +0000151 /// Get the size of the constant and then use SizeToAlignment.
152 /// Handles strings as a special case;
153 inline unsigned int
154 ConstantToAlignment(const Constant* CV, const TargetMachine& target) {
155 if (const ConstantArray* CVA = dyn_cast<ConstantArray>(CV))
156 if (ArrayTypeIsString(cast<ArrayType>(CVA->getType())))
157 return SizeToAlignment(1 + CVA->getNumOperands(), target);
Misha Brukmanf905ed52003-11-07 17:45:28 +0000158
Misha Brukman6275a042003-11-13 00:22:19 +0000159 return TypeToAlignment(CV->getType(), target);
160 }
161
162} // End anonymous namespace
163
Misha Brukman6275a042003-11-13 00:22:19 +0000164
165
Vikram S. Adved198c472002-03-18 03:07:26 +0000166//===---------------------------------------------------------------------===//
Misha Brukman6275a042003-11-13 00:22:19 +0000167// Code abstracted away from the AsmPrinter
Vikram S. Adved198c472002-03-18 03:07:26 +0000168//===---------------------------------------------------------------------===//
169
Misha Brukman6275a042003-11-13 00:22:19 +0000170namespace {
Misha Brukman6275a042003-11-13 00:22:19 +0000171 class AsmPrinter {
172 GlobalIdTable* idTable;
173 public:
174 std::ostream &toAsm;
175 const TargetMachine &Target;
Misha Brukmanf905ed52003-11-07 17:45:28 +0000176
Misha Brukman6275a042003-11-13 00:22:19 +0000177 enum Sections {
178 Unknown,
179 Text,
180 ReadOnlyData,
181 InitRWData,
182 ZeroInitRWData,
183 } CurSection;
184
185 AsmPrinter(std::ostream &os, const TargetMachine &T)
186 : idTable(0), toAsm(os), Target(T), CurSection(Unknown) {}
Misha Brukmanf905ed52003-11-07 17:45:28 +0000187
Misha Brukman6275a042003-11-13 00:22:19 +0000188 // (start|end)(Module|Function) - Callback methods invoked by subclasses
189 void startModule(Module &M) {
190 // Create the global id table if it does not already exist
191 idTable = (GlobalIdTable*)M.getAnnotation(GlobalIdTable::AnnotId);
192 if (idTable == NULL) {
Chris Lattner7446dc02004-01-13 21:27:59 +0000193 idTable = new GlobalIdTable();
Misha Brukman6275a042003-11-13 00:22:19 +0000194 M.addAnnotation(idTable);
Misha Brukmanf905ed52003-11-07 17:45:28 +0000195 }
196 }
Misha Brukmanf905ed52003-11-07 17:45:28 +0000197
Misha Brukman6275a042003-11-13 00:22:19 +0000198 void PrintZeroBytesToPad(int numBytes) {
199 for (/* no init */; numBytes >= 8; numBytes -= 8)
200 printSingleConstantValue(Constant::getNullValue(Type::ULongTy));
Misha Brukmanf905ed52003-11-07 17:45:28 +0000201
Misha Brukman6275a042003-11-13 00:22:19 +0000202 if (numBytes >= 4) {
203 printSingleConstantValue(Constant::getNullValue(Type::UIntTy));
204 numBytes -= 4;
Misha Brukmanf905ed52003-11-07 17:45:28 +0000205 }
Misha Brukman6275a042003-11-13 00:22:19 +0000206
207 while (numBytes--)
208 printSingleConstantValue(Constant::getNullValue(Type::UByteTy));
Misha Brukmanf905ed52003-11-07 17:45:28 +0000209 }
Misha Brukmanf905ed52003-11-07 17:45:28 +0000210
Misha Brukman6275a042003-11-13 00:22:19 +0000211 /// Print a single constant value.
212 ///
213 void printSingleConstantValue(const Constant* CV);
Misha Brukmanf905ed52003-11-07 17:45:28 +0000214
Misha Brukman6275a042003-11-13 00:22:19 +0000215 /// Print a constant value or values (it may be an aggregate).
216 /// Uses printSingleConstantValue() to print each individual value.
217 ///
218 void printConstantValueOnly(const Constant* CV, int numPadBytesAfter = 0);
219
220 // Print a constant (which may be an aggregate) prefixed by all the
221 // appropriate directives. Uses printConstantValueOnly() to print the
222 // value or values.
223 void printConstant(const Constant* CV, std::string valID = "") {
224 if (valID.length() == 0)
225 valID = getID(CV);
Misha Brukmanf905ed52003-11-07 17:45:28 +0000226
Misha Brukman6275a042003-11-13 00:22:19 +0000227 toAsm << "\t.align\t" << ConstantToAlignment(CV, Target) << "\n";
Misha Brukmanf905ed52003-11-07 17:45:28 +0000228
Misha Brukman6275a042003-11-13 00:22:19 +0000229 // Print .size and .type only if it is not a string.
Chris Lattner07ad6422004-01-14 17:15:17 +0000230 if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV))
231 if (CVA->isString()) {
232 // print it as a string and return
233 toAsm << valID << ":\n";
234 toAsm << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n";
235 return;
236 }
Misha Brukman6275a042003-11-13 00:22:19 +0000237
238 toAsm << "\t.type" << "\t" << valID << ",#object\n";
239
240 unsigned int constSize = ConstantToSize(CV, Target);
241 if (constSize)
242 toAsm << "\t.size" << "\t" << valID << "," << constSize << "\n";
243
Misha Brukmanf905ed52003-11-07 17:45:28 +0000244 toAsm << valID << ":\n";
Misha Brukman6275a042003-11-13 00:22:19 +0000245
246 printConstantValueOnly(CV);
247 }
248
Misha Brukman6275a042003-11-13 00:22:19 +0000249 // enterSection - Use this method to enter a different section of the output
250 // executable. This is used to only output necessary section transitions.
251 //
252 void enterSection(enum Sections S) {
253 if (S == CurSection) return; // Only switch section if necessary
254 CurSection = S;
Misha Brukmanf905ed52003-11-07 17:45:28 +0000255
Misha Brukman6275a042003-11-13 00:22:19 +0000256 toAsm << "\n\t.section ";
257 switch (S)
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000258 {
259 default: assert(0 && "Bad section name!");
260 case Text: toAsm << "\".text\""; break;
261 case ReadOnlyData: toAsm << "\".rodata\",#alloc"; break;
262 case InitRWData: toAsm << "\".data\",#alloc,#write"; break;
263 case ZeroInitRWData: toAsm << "\".bss\",#alloc,#write"; break;
264 }
Misha Brukman6275a042003-11-13 00:22:19 +0000265 toAsm << "\n";
266 }
Chris Lattnere88f78c2001-09-19 13:47:27 +0000267
Misha Brukman6275a042003-11-13 00:22:19 +0000268 static std::string getValidSymbolName(const std::string &S) {
269 std::string Result;
Vikram S. Adve29ff8732001-11-08 05:12:37 +0000270
Misha Brukman6275a042003-11-13 00:22:19 +0000271 // Symbol names in Sparc assembly language have these rules:
272 // (a) Must match { letter | _ | . | $ } { letter | _ | . | $ | digit }*
273 // (b) A name beginning in "." is treated as a local name.
274 //
275 if (isdigit(S[0]))
276 Result = "ll";
Vikram S. Adve29ff8732001-11-08 05:12:37 +0000277
Misha Brukman6275a042003-11-13 00:22:19 +0000278 for (unsigned i = 0; i < S.size(); ++i) {
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000279 char C = S[i];
280 if (C == '_' || C == '.' || C == '$' || isalpha(C) || isdigit(C))
281 Result += C;
Misha Brukman6275a042003-11-13 00:22:19 +0000282 else {
283 Result += '_';
284 Result += char('0' + ((unsigned char)C >> 4));
285 Result += char('0' + (C & 0xF));
286 }
Chris Lattnerc56d7792001-09-28 15:07:24 +0000287 }
Misha Brukman6275a042003-11-13 00:22:19 +0000288 return Result;
Chris Lattnere88f78c2001-09-19 13:47:27 +0000289 }
Vikram S. Adve96918072002-10-30 20:16:38 +0000290
Misha Brukman6275a042003-11-13 00:22:19 +0000291 // getID - Return a valid identifier for the specified value. Base it on
292 // the name of the identifier if possible (qualified by the type), and
293 // use a numbered value based on prefix otherwise.
294 // FPrefix is always prepended to the output identifier.
295 //
296 std::string getID(const Value *V, const char *Prefix,
Chris Lattner7446dc02004-01-13 21:27:59 +0000297 const char *FPrefix = "")
Misha Brukman6275a042003-11-13 00:22:19 +0000298 {
Chris Lattner7446dc02004-01-13 21:27:59 +0000299 std::string Result = FPrefix; // "Forced prefix"
Misha Brukman6275a042003-11-13 00:22:19 +0000300
301 Result += V->hasName() ? V->getName() : std::string(Prefix);
302
303 // Qualify all internal names with a unique id.
Chris Lattner7446dc02004-01-13 21:27:59 +0000304 if (!isa<GlobalValue>(V) || !cast<GlobalValue>(V)->hasExternalLinkage()) {
305 unsigned &ValID = idTable->AnonymousObjectMap[V];
306 if (ValID == 0)
307 ValID = ++idTable->LastAnonIDUsed;
308
309 Result += "_" + utostr(ValID);
Misha Brukman6275a042003-11-13 00:22:19 +0000310
311 // Replace or prefix problem characters in the name
312 Result = getValidSymbolName(Result);
313 }
314
315 return Result;
316 }
Vikram S. Adve953c83e2001-10-28 21:38:52 +0000317
Misha Brukman6275a042003-11-13 00:22:19 +0000318 // getID Wrappers - Ensure consistent usage...
319 std::string getID(const Function *F) {
320 return getID(F, "LLVMFunction_");
321 }
322 std::string getID(const BasicBlock *BB) {
323 return getID(BB, "LL", (".L_"+getID(BB->getParent())+"_").c_str());
324 }
325 std::string getID(const GlobalVariable *GV) {
326 return getID(GV, "LLVMGlobal_");
327 }
328 std::string getID(const Constant *CV) {
329 return getID(CV, "LLVMConst_", ".C_");
330 }
331 std::string getID(const GlobalValue *GV) {
332 if (const GlobalVariable *V = dyn_cast<GlobalVariable>(GV))
333 return getID(V);
334 else if (const Function *F = dyn_cast<Function>(GV))
335 return getID(F);
336 assert(0 && "Unexpected type of GlobalValue!");
337 return "";
338 }
Vikram S. Advee99941a2002-08-22 02:58:36 +0000339
Misha Brukman6275a042003-11-13 00:22:19 +0000340 // Combines expressions
341 inline std::string ConstantArithExprToString(const ConstantExpr* CE,
342 const TargetMachine &TM,
343 const std::string &op) {
344 return "(" + valToExprString(CE->getOperand(0), TM) + op
345 + valToExprString(CE->getOperand(1), TM) + ")";
346 }
Misha Brukmanf4de7832003-08-05 16:01:50 +0000347
Misha Brukman6275a042003-11-13 00:22:19 +0000348 /// ConstantExprToString() - Convert a ConstantExpr to an asm expression
349 /// and return this as a string.
350 ///
351 std::string ConstantExprToString(const ConstantExpr* CE,
352 const TargetMachine& target);
353
354 /// valToExprString - Helper function for ConstantExprToString().
355 /// Appends result to argument string S.
356 ///
357 std::string valToExprString(const Value* V, const TargetMachine& target);
358 };
Misha Brukman6275a042003-11-13 00:22:19 +0000359} // End anonymous namespace
360
Misha Brukman6275a042003-11-13 00:22:19 +0000361
362/// Print a single constant value.
363///
364void AsmPrinter::printSingleConstantValue(const Constant* CV) {
365 assert(CV->getType() != Type::VoidTy &&
366 CV->getType() != Type::TypeTy &&
367 CV->getType() != Type::LabelTy &&
368 "Unexpected type for Constant");
369
370 assert((!isa<ConstantArray>(CV) && ! isa<ConstantStruct>(CV))
371 && "Aggregate types should be handled outside this function");
372
373 toAsm << "\t" << TypeToDataDirective(CV->getType()) << "\t";
374
375 if (const ConstantPointerRef* CPR = dyn_cast<ConstantPointerRef>(CV)) {
376 // This is a constant address for a global variable or method.
377 // Use the name of the variable or method as the address value.
378 assert(isa<GlobalValue>(CPR->getValue()) && "Unexpected non-global");
379 toAsm << getID(CPR->getValue()) << "\n";
380 } else if (isa<ConstantPointerNull>(CV)) {
381 // Null pointer value
382 toAsm << "0\n";
383 } else if (const ConstantExpr* CE = dyn_cast<ConstantExpr>(CV)) {
384 // Constant expression built from operators, constants, and symbolic addrs
385 toAsm << ConstantExprToString(CE, Target) << "\n";
386 } else if (CV->getType()->isPrimitiveType()) {
387 // Check primitive types last
388 if (CV->getType()->isFloatingPoint()) {
389 // FP Constants are printed as integer constants to avoid losing
390 // precision...
391 double Val = cast<ConstantFP>(CV)->getValue();
392 if (CV->getType() == Type::FloatTy) {
393 float FVal = (float)Val;
394 char *ProxyPtr = (char*)&FVal; // Abide by C TBAA rules
395 toAsm << *(unsigned int*)ProxyPtr;
396 } else if (CV->getType() == Type::DoubleTy) {
397 char *ProxyPtr = (char*)&Val; // Abide by C TBAA rules
398 toAsm << *(uint64_t*)ProxyPtr;
399 } else {
400 assert(0 && "Unknown floating point type!");
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000401 }
Misha Brukman6275a042003-11-13 00:22:19 +0000402
403 toAsm << "\t! " << CV->getType()->getDescription()
404 << " value: " << Val << "\n";
405 } else {
406 WriteAsOperand(toAsm, CV, false, false) << "\n";
407 }
408 } else {
409 assert(0 && "Unknown elementary type for constant");
410 }
411}
Vikram S. Advee99941a2002-08-22 02:58:36 +0000412
Misha Brukman6275a042003-11-13 00:22:19 +0000413/// Print a constant value or values (it may be an aggregate).
414/// Uses printSingleConstantValue() to print each individual value.
415///
416void AsmPrinter::printConstantValueOnly(const Constant* CV,
Chris Lattner07ad6422004-01-14 17:15:17 +0000417 int numPadBytesAfter) {
418 if (const ConstantArray *CVA = dyn_cast<ConstantArray>(CV)) {
419 if (CVA->isString()) {
420 // print the string alone and return
421 toAsm << "\t" << ".ascii" << "\t" << getAsCString(CVA) << "\n";
422 } else {
423 // Not a string. Print the values in successive locations
424 const std::vector<Use> &constValues = CVA->getValues();
425 for (unsigned i=0; i < constValues.size(); i++)
426 printConstantValueOnly(cast<Constant>(constValues[i].get()));
427 }
Misha Brukman6275a042003-11-13 00:22:19 +0000428 } else if (const ConstantStruct *CVS = dyn_cast<ConstantStruct>(CV)) {
429 // Print the fields in successive locations. Pad to align if needed!
430 const StructLayout *cvsLayout =
431 Target.getTargetData().getStructLayout(CVS->getType());
432 const std::vector<Use>& constValues = CVS->getValues();
433 unsigned sizeSoFar = 0;
434 for (unsigned i=0, N = constValues.size(); i < N; i++) {
435 const Constant* field = cast<Constant>(constValues[i].get());
Vikram S. Adve537a8772002-09-05 18:28:10 +0000436
Misha Brukman6275a042003-11-13 00:22:19 +0000437 // Check if padding is needed and insert one or more 0s.
438 unsigned fieldSize =
439 Target.getTargetData().getTypeSize(field->getType());
440 int padSize = ((i == N-1? cvsLayout->StructSize
441 : cvsLayout->MemberOffsets[i+1])
442 - cvsLayout->MemberOffsets[i]) - fieldSize;
443 sizeSoFar += (fieldSize + padSize);
Vikram S. Adve72666e62003-08-01 15:55:53 +0000444
Misha Brukman6275a042003-11-13 00:22:19 +0000445 // Now print the actual field value
446 printConstantValueOnly(field, padSize);
447 }
448 assert(sizeSoFar == cvsLayout->StructSize &&
449 "Layout of constant struct may be incorrect!");
450 }
451 else
452 printSingleConstantValue(CV);
Vikram S. Adve72666e62003-08-01 15:55:53 +0000453
Misha Brukman6275a042003-11-13 00:22:19 +0000454 if (numPadBytesAfter)
455 PrintZeroBytesToPad(numPadBytesAfter);
456}
Vikram S. Adve72666e62003-08-01 15:55:53 +0000457
Misha Brukman6275a042003-11-13 00:22:19 +0000458/// ConstantExprToString() - Convert a ConstantExpr to an asm expression
459/// and return this as a string.
460///
461std::string AsmPrinter::ConstantExprToString(const ConstantExpr* CE,
462 const TargetMachine& target) {
463 std::string S;
464 switch(CE->getOpcode()) {
465 case Instruction::GetElementPtr:
466 { // generate a symbolic expression for the byte address
467 const Value* ptrVal = CE->getOperand(0);
468 std::vector<Value*> idxVec(CE->op_begin()+1, CE->op_end());
469 const TargetData &TD = target.getTargetData();
470 S += "(" + valToExprString(ptrVal, target) + ") + ("
471 + utostr(TD.getIndexedOffset(ptrVal->getType(),idxVec)) + ")";
Vikram S. Advee99941a2002-08-22 02:58:36 +0000472 break;
473 }
474
Misha Brukman6275a042003-11-13 00:22:19 +0000475 case Instruction::Cast:
476 // Support only non-converting casts for now, i.e., a no-op.
477 // This assertion is not a complete check.
478 assert(target.getTargetData().getTypeSize(CE->getType()) ==
479 target.getTargetData().getTypeSize(CE->getOperand(0)->getType()));
480 S += "(" + valToExprString(CE->getOperand(0), target) + ")";
481 break;
482
483 case Instruction::Add:
484 S += ConstantArithExprToString(CE, target, ") + (");
485 break;
486
487 case Instruction::Sub:
488 S += ConstantArithExprToString(CE, target, ") - (");
489 break;
490
491 case Instruction::Mul:
492 S += ConstantArithExprToString(CE, target, ") * (");
493 break;
494
495 case Instruction::Div:
496 S += ConstantArithExprToString(CE, target, ") / (");
497 break;
498
499 case Instruction::Rem:
500 S += ConstantArithExprToString(CE, target, ") % (");
501 break;
502
503 case Instruction::And:
504 // Logical && for booleans; bitwise & otherwise
505 S += ConstantArithExprToString(CE, target,
506 ((CE->getType() == Type::BoolTy)? ") && (" : ") & ("));
507 break;
508
509 case Instruction::Or:
510 // Logical || for booleans; bitwise | otherwise
511 S += ConstantArithExprToString(CE, target,
512 ((CE->getType() == Type::BoolTy)? ") || (" : ") | ("));
513 break;
514
515 case Instruction::Xor:
516 // Bitwise ^ for all types
517 S += ConstantArithExprToString(CE, target, ") ^ (");
518 break;
519
520 default:
521 assert(0 && "Unsupported operator in ConstantExprToString()");
522 break;
Vikram S. Advee99941a2002-08-22 02:58:36 +0000523 }
524
Misha Brukman6275a042003-11-13 00:22:19 +0000525 return S;
526}
Vikram S. Advee99941a2002-08-22 02:58:36 +0000527
Misha Brukman6275a042003-11-13 00:22:19 +0000528/// valToExprString - Helper function for ConstantExprToString().
529/// Appends result to argument string S.
530///
531std::string AsmPrinter::valToExprString(const Value* V,
532 const TargetMachine& target) {
533 std::string S;
534 bool failed = false;
535 if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known
536 if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV))
537 S += std::string(CB == ConstantBool::True ? "1" : "0");
538 else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
539 S += itostr(CI->getValue());
540 else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV))
541 S += utostr(CI->getValue());
542 else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV))
543 S += ftostr(CFP->getValue());
544 else if (isa<ConstantPointerNull>(CV))
545 S += "0";
546 else if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CV))
547 S += valToExprString(CPR->getValue(), target);
548 else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV))
549 S += ConstantExprToString(CE, target);
Vikram S. Advee99941a2002-08-22 02:58:36 +0000550 else
551 failed = true;
Misha Brukman6275a042003-11-13 00:22:19 +0000552 } else if (const GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
553 S += getID(GV);
554 } else
555 failed = true;
Vikram S. Advee99941a2002-08-22 02:58:36 +0000556
Misha Brukman6275a042003-11-13 00:22:19 +0000557 if (failed) {
558 assert(0 && "Cannot convert value to string");
559 S += "<illegal-value>";
Vikram S. Advee99941a2002-08-22 02:58:36 +0000560 }
Misha Brukman6275a042003-11-13 00:22:19 +0000561 return S;
562}
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000563
564
565//===----------------------------------------------------------------------===//
Misha Brukman6275a042003-11-13 00:22:19 +0000566// SparcAsmPrinter Code
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000567//===----------------------------------------------------------------------===//
568
Misha Brukman6275a042003-11-13 00:22:19 +0000569namespace {
Misha Brukmanf905ed52003-11-07 17:45:28 +0000570
Misha Brukman6275a042003-11-13 00:22:19 +0000571 struct SparcAsmPrinter : public FunctionPass, public AsmPrinter {
572 inline SparcAsmPrinter(std::ostream &os, const TargetMachine &t)
573 : AsmPrinter(os, t) {}
Chris Lattner96c466b2002-04-29 14:57:45 +0000574
Misha Brukman6275a042003-11-13 00:22:19 +0000575 const Function *currFunction;
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000576
Misha Brukman6275a042003-11-13 00:22:19 +0000577 const char *getPassName() const {
578 return "Output Sparc Assembly for Functions";
Chris Lattnere88f78c2001-09-19 13:47:27 +0000579 }
Misha Brukman6275a042003-11-13 00:22:19 +0000580
581 virtual bool doInitialization(Module &M) {
582 startModule(M);
583 return false;
584 }
585
586 virtual bool runOnFunction(Function &F) {
587 currFunction = &F;
Misha Brukman6275a042003-11-13 00:22:19 +0000588 emitFunction(F);
Misha Brukman6275a042003-11-13 00:22:19 +0000589 return false;
590 }
591
592 virtual bool doFinalization(Module &M) {
593 emitGlobals(M);
594 return false;
595 }
596
597 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
598 AU.setPreservesAll();
599 }
600
601 void emitFunction(const Function &F);
602 private :
603 void emitBasicBlock(const MachineBasicBlock &MBB);
604 void emitMachineInst(const MachineInstr *MI);
605
606 unsigned int printOperands(const MachineInstr *MI, unsigned int opNum);
607 void printOneOperand(const MachineOperand &Op, MachineOpCode opCode);
608
609 bool OpIsBranchTargetLabel(const MachineInstr *MI, unsigned int opNum);
610 bool OpIsMemoryAddressBase(const MachineInstr *MI, unsigned int opNum);
611
612 unsigned getOperandMask(unsigned Opcode) {
613 switch (Opcode) {
614 case V9::SUBccr:
615 case V9::SUBcci: return 1 << 3; // Remove CC argument
616 default: return 0; // By default, don't hack operands...
617 }
618 }
619
620 void emitGlobals(const Module &M);
621 void printGlobalVariable(const GlobalVariable *GV);
622 };
623
624} // End anonymous namespace
Chris Lattnere88f78c2001-09-19 13:47:27 +0000625
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000626inline bool
Misha Brukman6275a042003-11-13 00:22:19 +0000627SparcAsmPrinter::OpIsBranchTargetLabel(const MachineInstr *MI,
628 unsigned int opNum) {
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000629 switch (MI->getOpCode()) {
Misha Brukman71ed1c92003-05-27 22:35:43 +0000630 case V9::JMPLCALLr:
631 case V9::JMPLCALLi:
632 case V9::JMPLRETr:
633 case V9::JMPLRETi:
Misha Brukmana98cd452003-05-20 20:32:24 +0000634 return (opNum == 0);
635 default:
636 return false;
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000637 }
638}
639
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000640inline bool
Misha Brukman6275a042003-11-13 00:22:19 +0000641SparcAsmPrinter::OpIsMemoryAddressBase(const MachineInstr *MI,
642 unsigned int opNum) {
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000643 if (Target.getInstrInfo().isLoad(MI->getOpCode()))
644 return (opNum == 0);
645 else if (Target.getInstrInfo().isStore(MI->getOpCode()))
646 return (opNum == 1);
647 else
648 return false;
649}
650
651
Vikram S. Adve78a4f232003-05-27 00:02:22 +0000652#define PrintOp1PlusOp2(mop1, mop2, opCode) \
653 printOneOperand(mop1, opCode); \
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000654 toAsm << "+"; \
Vikram S. Adve78a4f232003-05-27 00:02:22 +0000655 printOneOperand(mop2, opCode);
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000656
657unsigned int
Misha Brukman6275a042003-11-13 00:22:19 +0000658SparcAsmPrinter::printOperands(const MachineInstr *MI,
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000659 unsigned int opNum)
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000660{
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000661 const MachineOperand& mop = MI->getOperand(opNum);
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000662
Misha Brukman6275a042003-11-13 00:22:19 +0000663 if (OpIsBranchTargetLabel(MI, opNum)) {
664 PrintOp1PlusOp2(mop, MI->getOperand(opNum+1), MI->getOpCode());
665 return 2;
666 } else if (OpIsMemoryAddressBase(MI, opNum)) {
667 toAsm << "[";
668 PrintOp1PlusOp2(mop, MI->getOperand(opNum+1), MI->getOpCode());
669 toAsm << "]";
670 return 2;
671 } else {
672 printOneOperand(mop, MI->getOpCode());
673 return 1;
674 }
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000675}
676
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000677void
Misha Brukman6275a042003-11-13 00:22:19 +0000678SparcAsmPrinter::printOneOperand(const MachineOperand &mop,
679 MachineOpCode opCode)
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000680{
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000681 bool needBitsFlag = true;
682
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000683 if (mop.isHiBits32())
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000684 toAsm << "%lm(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000685 else if (mop.isLoBits32())
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000686 toAsm << "%lo(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000687 else if (mop.isHiBits64())
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000688 toAsm << "%hh(";
Alkis Evlogimenos4d7af652003-12-14 13:24:17 +0000689 else if (mop.isLoBits64())
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000690 toAsm << "%hm(";
691 else
692 needBitsFlag = false;
693
Chris Lattner133f0792002-10-28 04:45:29 +0000694 switch (mop.getType())
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000695 {
Vikram S. Adve786833a2003-07-06 20:13:59 +0000696 case MachineOperand::MO_VirtualRegister:
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000697 case MachineOperand::MO_CCRegister:
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000698 case MachineOperand::MO_MachineRegister:
699 {
700 int regNum = (int)mop.getAllocatedRegNum();
Vikram S. Adveb15f8d42003-07-10 19:42:11 +0000701
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000702 if (regNum == Target.getRegInfo().getInvalidRegNum()) {
703 // better to print code with NULL registers than to die
704 toAsm << "<NULL VALUE>";
705 } else {
706 toAsm << "%" << Target.getRegInfo().getUnifiedRegName(regNum);
707 }
708 break;
709 }
Misha Brukmanb3fabe02003-05-31 06:22:37 +0000710
Misha Brukmanf905ed52003-11-07 17:45:28 +0000711 case MachineOperand::MO_ConstantPoolIndex:
712 {
713 toAsm << ".CPI_" << currFunction->getName()
714 << "_" << mop.getConstantPoolIndex();
715 break;
716 }
717
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000718 case MachineOperand::MO_PCRelativeDisp:
719 {
720 const Value *Val = mop.getVRegValue();
Misha Brukman6275a042003-11-13 00:22:19 +0000721 assert(Val && "\tNULL Value in SparcAsmPrinter");
Misha Brukmanb3fabe02003-05-31 06:22:37 +0000722
Chris Lattner949a3622003-07-23 15:30:06 +0000723 if (const BasicBlock *BB = dyn_cast<BasicBlock>(Val))
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000724 toAsm << getID(BB);
725 else if (const Function *M = dyn_cast<Function>(Val))
726 toAsm << getID(M);
727 else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Val))
728 toAsm << getID(GV);
729 else if (const Constant *CV = dyn_cast<Constant>(Val))
730 toAsm << getID(CV);
731 else
Misha Brukman6275a042003-11-13 00:22:19 +0000732 assert(0 && "Unrecognized value in SparcAsmPrinter");
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000733 break;
734 }
Misha Brukmanb3fabe02003-05-31 06:22:37 +0000735
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000736 case MachineOperand::MO_SignExtendedImmed:
737 toAsm << mop.getImmedValue();
738 break;
Misha Brukmanb3fabe02003-05-31 06:22:37 +0000739
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000740 case MachineOperand::MO_UnextendedImmed:
741 toAsm << (uint64_t) mop.getImmedValue();
742 break;
Misha Brukmanb3fabe02003-05-31 06:22:37 +0000743
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000744 default:
745 toAsm << mop; // use dump field
746 break;
747 }
Vikram S. Adve195a5d52002-07-10 21:41:21 +0000748
749 if (needBitsFlag)
750 toAsm << ")";
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000751}
752
Misha Brukman6275a042003-11-13 00:22:19 +0000753void SparcAsmPrinter::emitMachineInst(const MachineInstr *MI) {
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000754 unsigned Opcode = MI->getOpCode();
755
Vikram S. Advec227a9a2002-11-06 00:34:26 +0000756 if (Target.getInstrInfo().isDummyPhiInstr(Opcode))
Vikram S. Adveaf9fd512003-05-31 07:27:17 +0000757 return; // IGNORE PHI NODES
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000758
Chris Lattnerf44f9052002-10-29 17:35:41 +0000759 toAsm << "\t" << Target.getInstrInfo().getName(Opcode) << "\t";
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000760
761 unsigned Mask = getOperandMask(Opcode);
762
763 bool NeedComma = false;
764 unsigned N = 1;
765 for (unsigned OpNum = 0; OpNum < MI->getNumOperands(); OpNum += N)
766 if (! ((1 << OpNum) & Mask)) { // Ignore this operand?
Misha Brukman8b2fe192003-09-23 17:27:28 +0000767 if (NeedComma) toAsm << ", "; // Handle comma outputting
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000768 NeedComma = true;
769 N = printOperands(MI, OpNum);
Chris Lattnerebdc7f32002-11-17 22:57:23 +0000770 } else
771 N = 1;
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000772
773 toAsm << "\n";
Brian Gaeke2c9b9132003-10-06 15:41:21 +0000774 ++EmittedInsts;
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000775}
776
Misha Brukman6275a042003-11-13 00:22:19 +0000777void SparcAsmPrinter::emitBasicBlock(const MachineBasicBlock &MBB) {
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000778 // Emit a label for the basic block
Misha Brukmane585a7d2002-10-28 20:01:13 +0000779 toAsm << getID(MBB.getBasicBlock()) << ":\n";
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000780
781 // Loop over all of the instructions in the basic block...
Misha Brukmane585a7d2002-10-28 20:01:13 +0000782 for (MachineBasicBlock::const_iterator MII = MBB.begin(), MIE = MBB.end();
Chris Lattner55291ea2002-10-28 01:41:47 +0000783 MII != MIE; ++MII)
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000784 emitMachineInst(*MII);
Misha Brukmanbc0e9982003-07-14 17:20:40 +0000785 toAsm << "\n"; // Separate BB's with newlines
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000786}
787
Misha Brukman6275a042003-11-13 00:22:19 +0000788void SparcAsmPrinter::emitFunction(const Function &F) {
Misha Brukmanf4de7832003-08-05 16:01:50 +0000789 std::string methName = getID(&F);
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000790 toAsm << "!****** Outputing Function: " << methName << " ******\n";
Misha Brukmanf905ed52003-11-07 17:45:28 +0000791
792 // Emit constant pool for this function
793 const MachineConstantPool *MCP = MachineFunction::get(&F).getConstantPool();
794 const std::vector<Constant*> &CP = MCP->getConstants();
795
796 enterSection(AsmPrinter::ReadOnlyData);
797 for (unsigned i = 0, e = CP.size(); i != e; ++i) {
798 std::string cpiName = ".CPI_" + F.getName() + "_" + utostr(i);
799 printConstant(CP[i], cpiName);
800 }
801
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000802 enterSection(AsmPrinter::Text);
803 toAsm << "\t.align\t4\n\t.global\t" << methName << "\n";
804 //toAsm << "\t.type\t" << methName << ",#function\n";
805 toAsm << "\t.type\t" << methName << ", 2\n";
806 toAsm << methName << ":\n";
807
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000808 // Output code for all of the basic blocks in the function...
Misha Brukmane585a7d2002-10-28 20:01:13 +0000809 MachineFunction &MF = MachineFunction::get(&F);
Chris Lattnerd0fe5f52002-12-28 20:15:01 +0000810 for (MachineFunction::const_iterator I = MF.begin(), E = MF.end(); I != E;++I)
Misha Brukmane585a7d2002-10-28 20:01:13 +0000811 emitBasicBlock(*I);
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000812
813 // Output a .size directive so the debugger knows the extents of the function
814 toAsm << ".EndOf_" << methName << ":\n\t.size "
815 << methName << ", .EndOf_"
816 << methName << "-" << methName << "\n";
817
Chris Lattner2fbfdcf2002-04-07 20:49:59 +0000818 // Put some spaces between the functions
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000819 toAsm << "\n\n";
820}
821
Misha Brukman6275a042003-11-13 00:22:19 +0000822void SparcAsmPrinter::printGlobalVariable(const GlobalVariable* GV) {
Vikram S. Adve13f1d712002-09-16 15:54:02 +0000823 if (GV->hasExternalLinkage())
824 toAsm << "\t.global\t" << getID(GV) << "\n";
Vikram S. Adve953c83e2001-10-28 21:38:52 +0000825
Misha Brukman6275a042003-11-13 00:22:19 +0000826 if (GV->hasInitializer() && ! GV->getInitializer()->isNullValue()) {
Vikram S. Adve953c83e2001-10-28 21:38:52 +0000827 printConstant(GV->getInitializer(), getID(GV));
Misha Brukman6275a042003-11-13 00:22:19 +0000828 } else {
Chris Lattnerc19b8b12002-02-03 23:41:08 +0000829 toAsm << "\t.align\t" << TypeToAlignment(GV->getType()->getElementType(),
830 Target) << "\n";
Chris Lattner697954c2002-01-20 22:54:45 +0000831 toAsm << "\t.type\t" << getID(GV) << ",#object\n";
Vikram S. Adveffbba0f2001-11-08 14:29:57 +0000832 toAsm << "\t.reserve\t" << getID(GV) << ","
Misha Brukman6275a042003-11-13 00:22:19 +0000833 << Target.findOptimalStorageSize(GV->getType()->getElementType())
Chris Lattner697954c2002-01-20 22:54:45 +0000834 << "\n";
Vikram S. Adve953c83e2001-10-28 21:38:52 +0000835 }
836}
837
Misha Brukman6275a042003-11-13 00:22:19 +0000838void SparcAsmPrinter::emitGlobals(const Module &M) {
Chris Lattner637ed862002-08-07 21:39:48 +0000839 // Output global variables...
Vikram S. Advefee76262002-10-13 00:32:18 +0000840 for (Module::const_giterator GI = M.gbegin(), GE = M.gend(); GI != GE; ++GI)
841 if (! GI->isExternal()) {
842 assert(GI->hasInitializer());
843 if (GI->isConstant())
844 enterSection(AsmPrinter::ReadOnlyData); // read-only, initialized data
845 else if (GI->getInitializer()->isNullValue())
846 enterSection(AsmPrinter::ZeroInitRWData); // read-write zero data
847 else
848 enterSection(AsmPrinter::InitRWData); // read-write non-zero data
849
850 printGlobalVariable(GI);
Chris Lattner637ed862002-08-07 21:39:48 +0000851 }
Chris Lattner637ed862002-08-07 21:39:48 +0000852
Chris Lattner697954c2002-01-20 22:54:45 +0000853 toAsm << "\n";
Vikram S. Adve953c83e2001-10-28 21:38:52 +0000854}
855
Chris Lattner7446dc02004-01-13 21:27:59 +0000856FunctionPass *llvm::createAsmPrinterPass(std::ostream &Out,
857 const TargetMachine &TM) {
Misha Brukman6275a042003-11-13 00:22:19 +0000858 return new SparcAsmPrinter(Out, TM);
Chris Lattnerc019a172002-02-03 07:48:06 +0000859}