blob: e6c9085b6d0b48a1b950c8c7699d0cae0278f380 [file] [log] [blame]
Chris Lattnerf7e79482002-04-07 22:31:46 +00001//===-- AsmWriter.cpp - Printing LLVM as an assembly file -----------------===//
John Criswell482202a2003-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 Lattner2f7c9632001-06-06 20:29:01 +00009//
10// This library implements the functionality defined in llvm/Assembly/Writer.h
11//
Chris Lattner189088e2002-04-12 18:21:53 +000012// Note that these routines must be extremely tolerant of various errors in the
Chris Lattnerf70da102003-05-08 02:44:12 +000013// LLVM code, because it can be used for debugging transformations.
Chris Lattner189088e2002-04-12 18:21:53 +000014//
Chris Lattner2f7c9632001-06-06 20:29:01 +000015//===----------------------------------------------------------------------===//
16
Chris Lattner7db79582001-11-07 04:21:57 +000017#include "llvm/Assembly/CachedWriter.h"
Chris Lattnerc0b4c7b2002-04-08 22:03:40 +000018#include "llvm/Assembly/Writer.h"
Chris Lattner7f8845a2002-07-23 18:07:49 +000019#include "llvm/Assembly/PrintModulePass.h"
Chris Lattner8339f7d2003-10-30 23:41:03 +000020#include "llvm/Assembly/AsmAnnotationWriter.h"
Chris Lattnerc70b3f62004-01-20 19:50:34 +000021#include "llvm/Constants.h"
Chris Lattner913d18f2002-04-29 18:46:50 +000022#include "llvm/DerivedTypes.h"
Vikram S. Adveb952b542002-07-14 23:14:45 +000023#include "llvm/Instruction.h"
Chris Lattner2f7c9632001-06-06 20:29:01 +000024#include "llvm/iMemory.h"
Chris Lattner862e3382001-10-13 06:42:36 +000025#include "llvm/iTerminators.h"
Chris Lattnerfb5ae022001-12-03 18:02:31 +000026#include "llvm/iPHINode.h"
27#include "llvm/iOther.h"
Chris Lattnerc70b3f62004-01-20 19:50:34 +000028#include "llvm/Module.h"
Chris Lattnerfee714f2001-09-07 16:36:04 +000029#include "llvm/SymbolTable.h"
Misha Brukman4685e262004-04-28 15:31:21 +000030#include "llvm/Assembly/Writer.h"
Chris Lattner58185f22002-10-02 19:38:55 +000031#include "llvm/Support/CFG.h"
Chris Lattner5de22042001-11-27 00:03:19 +000032#include "Support/StringExtras.h"
33#include "Support/STLExtras.h"
Chris Lattnerfee714f2001-09-07 16:36:04 +000034#include <algorithm>
Chris Lattner189d19f2003-11-21 20:23:48 +000035using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000036
Reid Spencer16f2f7f2004-05-26 07:18:52 +000037namespace {
38
39/// This class provides computation of slot numbers for LLVM Assembly writing.
40/// @brief LLVM Assembly Writing Slot Computation.
41class SlotMachine {
42
43/// @name Types
44/// @{
45public:
46
47 /// @brief A mapping of Values to slot numbers
48 typedef std::map<const Value*, unsigned> ValueMap;
49
50 /// @brief A plane with next slot number and ValueMap
51 struct Plane {
52 unsigned next_slot; ///< The next slot number to use
53 ValueMap map; ///< The map of Value* -> unsigned
54 Plane() { next_slot = 0; } ///< Make sure we start at 0
55 };
56
57 /// @brief The map of planes by Type
58 typedef std::map<const Type*, Plane> TypedPlanes;
59
60/// @}
61/// @name Constructors
62/// @{
63public:
64 /// @brief Construct from a module
65 SlotMachine(const Module *M );
66
67 /// @brief Construct from a function, starting out in incorp state.
68 SlotMachine(const Function *F );
69
70/// @}
71/// @name Accessors
72/// @{
73public:
74 /// Return the slot number of the specified value in it's type
75 /// plane. Its an error to ask for something not in the SlotMachine.
76 /// Its an error to ask for a Type*
Reid Spencer56010e42004-05-26 21:56:09 +000077 unsigned getSlot(const Value *V) ;
Reid Spencer16f2f7f2004-05-26 07:18:52 +000078
79/// @}
80/// @name Mutators
81/// @{
82public:
83 /// If you'd like to deal with a function instead of just a module, use
84 /// this method to get its data into the SlotMachine.
Reid Spencer56010e42004-05-26 21:56:09 +000085 void incorporateFunction(const Function *F) { TheFunction = F; }
Reid Spencer16f2f7f2004-05-26 07:18:52 +000086
87 /// After calling incorporateFunction, use this method to remove the
88 /// most recently incorporated function from the SlotMachine. This
89 /// will reset the state of the machine back to just the module contents.
90 void purgeFunction();
91
92/// @}
93/// @name Implementation Details
94/// @{
95private:
Reid Spencer56010e42004-05-26 21:56:09 +000096 /// This function does the actual initialization.
97 inline void initialize();
98
Reid Spencer16f2f7f2004-05-26 07:18:52 +000099 /// Values can be crammed into here at will. If they haven't
100 /// been inserted already, they get inserted, otherwise they are ignored.
101 /// Either way, the slot number for the Value* is returned.
102 unsigned createSlot(const Value *V);
103
104 /// Insert a value into the value table. Return the slot number
105 /// that it now occupies. BadThings(TM) will happen if you insert a
106 /// Value that's already been inserted.
107 unsigned insertValue( const Value *V );
108
109 /// Add all of the module level global variables (and their initializers)
110 /// and function declarations, but not the contents of those functions.
111 void processModule();
112
Reid Spencer56010e42004-05-26 21:56:09 +0000113 /// Add all of the functions arguments, basic blocks, and instructions
114 void processFunction();
115
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000116 SlotMachine(const SlotMachine &); // DO NOT IMPLEMENT
117 void operator=(const SlotMachine &); // DO NOT IMPLEMENT
118
119/// @}
120/// @name Data
121/// @{
122public:
123
124 /// @brief The module for which we are holding slot numbers
Reid Spencer56010e42004-05-26 21:56:09 +0000125 const Module* TheModule;
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000126
Reid Spencer56010e42004-05-26 21:56:09 +0000127 /// @brief The function for which we are holding slot numbers
128 const Function* TheFunction;
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000129
130 /// @brief The TypePlanes map for the module level data
131 TypedPlanes mMap;
132
133 /// @brief The TypePlanes map for the function level data
134 TypedPlanes fMap;
135
136/// @}
137
138};
139
140}
141
Chris Lattnerc8b70922002-07-26 21:12:46 +0000142static RegisterPass<PrintModulePass>
143X("printm", "Print module to stderr",PassInfo::Analysis|PassInfo::Optimization);
144static RegisterPass<PrintFunctionPass>
145Y("print","Print function to stderr",PassInfo::Analysis|PassInfo::Optimization);
Chris Lattner7f8845a2002-07-23 18:07:49 +0000146
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000147static void WriteAsOperandInternal(std::ostream &Out, const Value *V,
148 bool PrintName,
149 std::map<const Type *, std::string> &TypeTable,
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000150 SlotMachine *Machine);
Chris Lattnerd84bb632002-04-16 21:36:08 +0000151
Chris Lattnerb86620e2001-10-29 16:37:48 +0000152static const Module *getModuleFromVal(const Value *V) {
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000153 if (const Argument *MA = dyn_cast<Argument>(V))
Chris Lattnerb86620e2001-10-29 16:37:48 +0000154 return MA->getParent() ? MA->getParent()->getParent() : 0;
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000155 else if (const BasicBlock *BB = dyn_cast<BasicBlock>(V))
Chris Lattnerb86620e2001-10-29 16:37:48 +0000156 return BB->getParent() ? BB->getParent()->getParent() : 0;
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000157 else if (const Instruction *I = dyn_cast<Instruction>(V)) {
Chris Lattner57698e22002-03-26 18:01:55 +0000158 const Function *M = I->getParent() ? I->getParent()->getParent() : 0;
Chris Lattnerb86620e2001-10-29 16:37:48 +0000159 return M ? M->getParent() : 0;
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000160 } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
Chris Lattnerb86620e2001-10-29 16:37:48 +0000161 return GV->getParent();
Chris Lattnerb86620e2001-10-29 16:37:48 +0000162 return 0;
163}
164
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000165static SlotMachine *createSlotMachine(const Value *V) {
Chris Lattner7bfee412001-10-29 16:05:51 +0000166 assert(!isa<Type>(V) && "Can't create an SC for a type!");
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000167 if (const Argument *FA = dyn_cast<Argument>(V)) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000168 return new SlotMachine(FA->getParent());
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000169 } else if (const Instruction *I = dyn_cast<Instruction>(V)) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000170 return new SlotMachine(I->getParent()->getParent());
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000171 } else if (const BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000172 return new SlotMachine(BB->getParent());
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000173 } else if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(V)){
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000174 return new SlotMachine(GV->getParent());
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000175 } else if (const Function *Func = dyn_cast<Function>(V)) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000176 return new SlotMachine(Func);
Chris Lattner7bfee412001-10-29 16:05:51 +0000177 }
178 return 0;
179}
Chris Lattner2f7c9632001-06-06 20:29:01 +0000180
Chris Lattner1c343042003-08-22 05:40:38 +0000181// getLLVMName - Turn the specified string into an 'LLVM name', which is either
182// prefixed with % (if the string only contains simple characters) or is
183// surrounded with ""'s (if it has special chars in it).
184static std::string getLLVMName(const std::string &Name) {
185 assert(!Name.empty() && "Cannot get empty name!");
186
187 // First character cannot start with a number...
188 if (Name[0] >= '0' && Name[0] <= '9')
189 return "\"" + Name + "\"";
190
191 // Scan to see if we have any characters that are not on the "white list"
192 for (unsigned i = 0, e = Name.size(); i != e; ++i) {
193 char C = Name[i];
194 assert(C != '"' && "Illegal character in LLVM value name!");
195 if ((C < 'a' || C > 'z') && (C < 'A' || C > 'Z') && (C < '0' || C > '9') &&
196 C != '-' && C != '.' && C != '_')
197 return "\"" + Name + "\"";
198 }
199
200 // If we get here, then the identifier is legal to use as a "VarID".
201 return "%"+Name;
202}
203
Chris Lattnerb86620e2001-10-29 16:37:48 +0000204
Misha Brukmanc566ca362004-03-02 00:22:19 +0000205/// fillTypeNameTable - If the module has a symbol table, take all global types
206/// and stuff their names into the TypeNames map.
207///
Chris Lattnerb86620e2001-10-29 16:37:48 +0000208static void fillTypeNameTable(const Module *M,
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000209 std::map<const Type *, std::string> &TypeNames) {
Chris Lattner98cf1f52002-11-20 18:36:02 +0000210 if (!M) return;
211 const SymbolTable &ST = M->getSymbolTable();
Reid Spencere7e96712004-05-25 08:53:40 +0000212 SymbolTable::type_const_iterator TI = ST.type_begin();
213 for (; TI != ST.type_end(); ++TI ) {
214 // As a heuristic, don't insert pointer to primitive types, because
215 // they are used too often to have a single useful name.
216 //
217 const Type *Ty = cast<Type>(TI->second);
218 if (!isa<PointerType>(Ty) ||
Reid Spencer56010e42004-05-26 21:56:09 +0000219 !cast<PointerType>(Ty)->getElementType()->isPrimitiveType() ||
220 isa<OpaqueType>(cast<PointerType>(Ty)->getElementType()))
Reid Spencere7e96712004-05-25 08:53:40 +0000221 TypeNames.insert(std::make_pair(Ty, getLLVMName(TI->first)));
Chris Lattnerb86620e2001-10-29 16:37:48 +0000222 }
223}
224
225
226
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000227static std::string calcTypeName(const Type *Ty,
228 std::vector<const Type *> &TypeStack,
229 std::map<const Type *, std::string> &TypeNames){
Chris Lattnerf14ead92003-10-30 00:22:33 +0000230 if (Ty->isPrimitiveType() && !isa<OpaqueType>(Ty))
231 return Ty->getDescription(); // Base case
Chris Lattnerb86620e2001-10-29 16:37:48 +0000232
233 // Check to see if the type is named.
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000234 std::map<const Type *, std::string>::iterator I = TypeNames.find(Ty);
Chris Lattnerb86620e2001-10-29 16:37:48 +0000235 if (I != TypeNames.end()) return I->second;
236
Chris Lattnerf14ead92003-10-30 00:22:33 +0000237 if (isa<OpaqueType>(Ty))
238 return "opaque";
239
Chris Lattnerb86620e2001-10-29 16:37:48 +0000240 // Check to see if the Type is already on the stack...
241 unsigned Slot = 0, CurSize = TypeStack.size();
242 while (Slot < CurSize && TypeStack[Slot] != Ty) ++Slot; // Scan for type
243
244 // This is another base case for the recursion. In this case, we know
245 // that we have looped back to a type that we have previously visited.
246 // Generate the appropriate upreference to handle this.
Chris Lattnerb86620e2001-10-29 16:37:48 +0000247 if (Slot < CurSize)
248 return "\\" + utostr(CurSize-Slot); // Here's the upreference
249
250 TypeStack.push_back(Ty); // Recursive case: Add us to the stack..
251
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000252 std::string Result;
Chris Lattnerb86620e2001-10-29 16:37:48 +0000253 switch (Ty->getPrimitiveID()) {
Chris Lattner91db5822002-03-29 03:44:36 +0000254 case Type::FunctionTyID: {
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000255 const FunctionType *FTy = cast<FunctionType>(Ty);
Chris Lattnerd816b532002-04-13 20:53:41 +0000256 Result = calcTypeName(FTy->getReturnType(), TypeStack, TypeNames) + " (";
Chris Lattnerfa829be2004-02-09 04:14:01 +0000257 for (FunctionType::param_iterator I = FTy->param_begin(),
258 E = FTy->param_end(); I != E; ++I) {
259 if (I != FTy->param_begin())
Chris Lattnerb86620e2001-10-29 16:37:48 +0000260 Result += ", ";
261 Result += calcTypeName(*I, TypeStack, TypeNames);
262 }
Chris Lattnerd816b532002-04-13 20:53:41 +0000263 if (FTy->isVarArg()) {
Chris Lattnerfa829be2004-02-09 04:14:01 +0000264 if (FTy->getNumParams()) Result += ", ";
Chris Lattnerb86620e2001-10-29 16:37:48 +0000265 Result += "...";
266 }
267 Result += ")";
268 break;
269 }
270 case Type::StructTyID: {
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000271 const StructType *STy = cast<StructType>(Ty);
Chris Lattnerb86620e2001-10-29 16:37:48 +0000272 Result = "{ ";
Chris Lattnerac6db752004-02-09 04:37:31 +0000273 for (StructType::element_iterator I = STy->element_begin(),
274 E = STy->element_end(); I != E; ++I) {
275 if (I != STy->element_begin())
Chris Lattnerb86620e2001-10-29 16:37:48 +0000276 Result += ", ";
277 Result += calcTypeName(*I, TypeStack, TypeNames);
278 }
279 Result += " }";
280 break;
281 }
282 case Type::PointerTyID:
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000283 Result = calcTypeName(cast<PointerType>(Ty)->getElementType(),
Chris Lattner189088e2002-04-12 18:21:53 +0000284 TypeStack, TypeNames) + "*";
Chris Lattnerb86620e2001-10-29 16:37:48 +0000285 break;
286 case Type::ArrayTyID: {
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000287 const ArrayType *ATy = cast<ArrayType>(Ty);
Chris Lattner8a939c92002-04-13 21:11:04 +0000288 Result = "[" + utostr(ATy->getNumElements()) + " x ";
Chris Lattnerb86620e2001-10-29 16:37:48 +0000289 Result += calcTypeName(ATy->getElementType(), TypeStack, TypeNames) + "]";
290 break;
291 }
Chris Lattner15285ab2003-05-14 17:50:47 +0000292 case Type::OpaqueTyID:
293 Result = "opaque";
294 break;
Chris Lattnerb86620e2001-10-29 16:37:48 +0000295 default:
Vikram S. Adveb952b542002-07-14 23:14:45 +0000296 Result = "<unrecognized-type>";
Chris Lattnerb86620e2001-10-29 16:37:48 +0000297 }
298
299 TypeStack.pop_back(); // Remove self from stack...
300 return Result;
301}
302
303
Misha Brukmanb22d09c2004-03-01 19:48:13 +0000304/// printTypeInt - The internal guts of printing out a type that has a
305/// potentially named portion.
306///
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000307static std::ostream &printTypeInt(std::ostream &Out, const Type *Ty,
308 std::map<const Type *, std::string> &TypeNames) {
Chris Lattnerb86620e2001-10-29 16:37:48 +0000309 // Primitive types always print out their description, regardless of whether
310 // they have been named or not.
311 //
Chris Lattner92d60532003-10-30 00:12:51 +0000312 if (Ty->isPrimitiveType() && !isa<OpaqueType>(Ty))
313 return Out << Ty->getDescription();
Chris Lattnerb86620e2001-10-29 16:37:48 +0000314
315 // Check to see if the type is named.
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000316 std::map<const Type *, std::string>::iterator I = TypeNames.find(Ty);
Chris Lattnerb86620e2001-10-29 16:37:48 +0000317 if (I != TypeNames.end()) return Out << I->second;
318
319 // Otherwise we have a type that has not been named but is a derived type.
320 // Carefully recurse the type hierarchy to print out any contained symbolic
321 // names.
322 //
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000323 std::vector<const Type *> TypeStack;
324 std::string TypeName = calcTypeName(Ty, TypeStack, TypeNames);
Chris Lattner7f74a562002-01-20 22:54:45 +0000325 TypeNames.insert(std::make_pair(Ty, TypeName));//Cache type name for later use
Chris Lattnerb86620e2001-10-29 16:37:48 +0000326 return Out << TypeName;
327}
328
Chris Lattner34b95182001-10-31 04:33:19 +0000329
Misha Brukmanb22d09c2004-03-01 19:48:13 +0000330/// WriteTypeSymbolic - This attempts to write the specified type as a symbolic
331/// type, iff there is an entry in the modules symbol table for the specified
332/// type or one of it's component types. This is slower than a simple x << Type
333///
Chris Lattner189d19f2003-11-21 20:23:48 +0000334std::ostream &llvm::WriteTypeSymbolic(std::ostream &Out, const Type *Ty,
335 const Module *M) {
Chris Lattnerb86620e2001-10-29 16:37:48 +0000336 Out << " ";
337
338 // If they want us to print out a type, attempt to make it symbolic if there
339 // is a symbol table in the module...
Chris Lattner98cf1f52002-11-20 18:36:02 +0000340 if (M) {
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000341 std::map<const Type *, std::string> TypeNames;
Chris Lattnerb86620e2001-10-29 16:37:48 +0000342 fillTypeNameTable(M, TypeNames);
343
Chris Lattner72f866e2001-10-29 16:40:32 +0000344 return printTypeInt(Out, Ty, TypeNames);
Chris Lattnerb86620e2001-10-29 16:37:48 +0000345 } else {
Chris Lattner72f866e2001-10-29 16:40:32 +0000346 return Out << Ty->getDescription();
Chris Lattnerb86620e2001-10-29 16:37:48 +0000347 }
348}
349
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000350static void WriteConstantInt(std::ostream &Out, const Constant *CV,
351 bool PrintName,
352 std::map<const Type *, std::string> &TypeTable,
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000353 SlotMachine *Machine) {
Chris Lattner1e194682002-04-18 18:53:13 +0000354 if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV)) {
355 Out << (CB == ConstantBool::True ? "true" : "false");
356 } else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV)) {
357 Out << CI->getValue();
358 } else if (const ConstantUInt *CI = dyn_cast<ConstantUInt>(CV)) {
359 Out << CI->getValue();
360 } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(CV)) {
361 // We would like to output the FP constant value in exponential notation,
362 // but we cannot do this if doing so will lose precision. Check here to
363 // make sure that we only output it in exponential format if we can parse
364 // the value back and get the same value.
365 //
366 std::string StrVal = ftostr(CFP->getValue());
367
368 // Check to make sure that the stringized number is not some string like
369 // "Inf" or NaN, that atof will accept, but the lexer will not. Check that
370 // the string matches the "[-+]?[0-9]" regex.
371 //
372 if ((StrVal[0] >= '0' && StrVal[0] <= '9') ||
373 ((StrVal[0] == '-' || StrVal[0] == '+') &&
Brian Gaeke87b4f072003-06-17 23:55:35 +0000374 (StrVal[1] >= '0' && StrVal[1] <= '9')))
Chris Lattner1e194682002-04-18 18:53:13 +0000375 // Reparse stringized version!
376 if (atof(StrVal.c_str()) == CFP->getValue()) {
377 Out << StrVal; return;
378 }
379
380 // Otherwise we could not reparse it to exactly the same value, so we must
381 // output the string in hexadecimal format!
382 //
383 // Behave nicely in the face of C TBAA rules... see:
384 // http://www.nullstone.com/htmls/category/aliastyp.htm
385 //
386 double Val = CFP->getValue();
387 char *Ptr = (char*)&Val;
388 assert(sizeof(double) == sizeof(uint64_t) && sizeof(double) == 8 &&
389 "assuming that double is 64 bits!");
390 Out << "0x" << utohexstr(*(uint64_t*)Ptr);
391
Chris Lattner76b2ff42004-02-15 05:55:15 +0000392 } else if (isa<ConstantAggregateZero>(CV)) {
393 Out << "zeroinitializer";
Chris Lattner1e194682002-04-18 18:53:13 +0000394 } else if (const ConstantArray *CA = dyn_cast<ConstantArray>(CV)) {
395 // As a special case, print the array as a string if it is an array of
396 // ubytes or an array of sbytes with positive values.
397 //
398 const Type *ETy = CA->getType()->getElementType();
399 bool isString = (ETy == Type::SByteTy || ETy == Type::UByteTy);
400
401 if (ETy == Type::SByteTy)
402 for (unsigned i = 0; i < CA->getNumOperands(); ++i)
403 if (cast<ConstantSInt>(CA->getOperand(i))->getValue() < 0) {
404 isString = false;
405 break;
406 }
407
408 if (isString) {
409 Out << "c\"";
410 for (unsigned i = 0; i < CA->getNumOperands(); ++i) {
Chris Lattner6077c312003-07-23 15:22:26 +0000411 unsigned char C = cast<ConstantInt>(CA->getOperand(i))->getRawValue();
Chris Lattner1e194682002-04-18 18:53:13 +0000412
Chris Lattnere5fd3862002-07-31 23:56:44 +0000413 if (isprint(C) && C != '"' && C != '\\') {
Chris Lattner1e194682002-04-18 18:53:13 +0000414 Out << C;
415 } else {
416 Out << '\\'
417 << (char) ((C/16 < 10) ? ( C/16 +'0') : ( C/16 -10+'A'))
418 << (char)(((C&15) < 10) ? ((C&15)+'0') : ((C&15)-10+'A'));
419 }
420 }
421 Out << "\"";
422
423 } else { // Cannot output in string format...
Chris Lattnerd84bb632002-04-16 21:36:08 +0000424 Out << "[";
425 if (CA->getNumOperands()) {
426 Out << " ";
Chris Lattner1e194682002-04-18 18:53:13 +0000427 printTypeInt(Out, ETy, TypeTable);
Chris Lattnerd84bb632002-04-16 21:36:08 +0000428 WriteAsOperandInternal(Out, CA->getOperand(0),
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000429 PrintName, TypeTable, Machine);
Chris Lattnerd84bb632002-04-16 21:36:08 +0000430 for (unsigned i = 1, e = CA->getNumOperands(); i != e; ++i) {
431 Out << ", ";
Chris Lattner1e194682002-04-18 18:53:13 +0000432 printTypeInt(Out, ETy, TypeTable);
Chris Lattnerd84bb632002-04-16 21:36:08 +0000433 WriteAsOperandInternal(Out, CA->getOperand(i), PrintName,
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000434 TypeTable, Machine);
Chris Lattnerd84bb632002-04-16 21:36:08 +0000435 }
436 }
437 Out << " ]";
438 }
439 } else if (const ConstantStruct *CS = dyn_cast<ConstantStruct>(CV)) {
440 Out << "{";
441 if (CS->getNumOperands()) {
442 Out << " ";
443 printTypeInt(Out, CS->getOperand(0)->getType(), TypeTable);
444
445 WriteAsOperandInternal(Out, CS->getOperand(0),
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000446 PrintName, TypeTable, Machine);
Chris Lattnerd84bb632002-04-16 21:36:08 +0000447
448 for (unsigned i = 1; i < CS->getNumOperands(); i++) {
449 Out << ", ";
450 printTypeInt(Out, CS->getOperand(i)->getType(), TypeTable);
451
452 WriteAsOperandInternal(Out, CS->getOperand(i),
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000453 PrintName, TypeTable, Machine);
Chris Lattnerd84bb632002-04-16 21:36:08 +0000454 }
455 }
456
457 Out << " }";
458 } else if (isa<ConstantPointerNull>(CV)) {
459 Out << "null";
460
Chris Lattner113f4f42002-06-25 16:13:24 +0000461 } else if (const ConstantPointerRef *PR = dyn_cast<ConstantPointerRef>(CV)) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000462 WriteAsOperandInternal(Out, PR->getValue(), true, TypeTable, Machine);
Vikram S. Adveb952b542002-07-14 23:14:45 +0000463
Chris Lattner3cd8c562002-07-30 18:54:25 +0000464 } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
Chris Lattnerb8257222003-03-06 23:23:32 +0000465 Out << CE->getOpcodeName() << " (";
Vikram S. Adveb952b542002-07-14 23:14:45 +0000466
467 for (User::const_op_iterator OI=CE->op_begin(); OI != CE->op_end(); ++OI) {
468 printTypeInt(Out, (*OI)->getType(), TypeTable);
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000469 WriteAsOperandInternal(Out, *OI, PrintName, TypeTable, Machine);
Vikram S. Adveb952b542002-07-14 23:14:45 +0000470 if (OI+1 != CE->op_end())
Chris Lattner3cd8c562002-07-30 18:54:25 +0000471 Out << ", ";
Vikram S. Adveb952b542002-07-14 23:14:45 +0000472 }
473
Chris Lattnercfe8f532002-08-16 21:17:11 +0000474 if (CE->getOpcode() == Instruction::Cast) {
Chris Lattner83b396b2002-08-15 19:37:43 +0000475 Out << " to ";
476 printTypeInt(Out, CE->getType(), TypeTable);
477 }
Chris Lattnercfe8f532002-08-16 21:17:11 +0000478 Out << ")";
Chris Lattner83b396b2002-08-15 19:37:43 +0000479
Chris Lattnerd84bb632002-04-16 21:36:08 +0000480 } else {
Vikram S. Adveb952b542002-07-14 23:14:45 +0000481 Out << "<placeholder or erroneous Constant>";
Chris Lattnerd84bb632002-04-16 21:36:08 +0000482 }
483}
484
485
Misha Brukmanc566ca362004-03-02 00:22:19 +0000486/// WriteAsOperand - Write the name of the specified value out to the specified
487/// ostream. This can be useful when you just want to print int %reg126, not
488/// the whole instruction that generated it.
489///
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000490static void WriteAsOperandInternal(std::ostream &Out, const Value *V,
491 bool PrintName,
492 std::map<const Type*, std::string> &TypeTable,
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000493 SlotMachine *Machine) {
Chris Lattnerd84bb632002-04-16 21:36:08 +0000494 Out << " ";
495 if (PrintName && V->hasName()) {
Chris Lattner1c343042003-08-22 05:40:38 +0000496 Out << getLLVMName(V->getName());
Chris Lattnerd84bb632002-04-16 21:36:08 +0000497 } else {
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000498 if (const Constant *CV = dyn_cast<Constant>(V)) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000499 WriteConstantInt(Out, CV, PrintName, TypeTable, Machine);
Chris Lattnerd84bb632002-04-16 21:36:08 +0000500 } else {
501 int Slot;
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000502 if (Machine) {
Reid Spencer56010e42004-05-26 21:56:09 +0000503 Slot = Machine->getSlot(V);
Chris Lattnerd84bb632002-04-16 21:36:08 +0000504 } else {
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000505 if (const Type *Ty = dyn_cast<Type>(V)) {
Chris Lattnerd84bb632002-04-16 21:36:08 +0000506 Out << Ty->getDescription();
507 return;
508 }
509
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000510 Machine = createSlotMachine(V);
511 if (Machine == 0) { Out << "BAD VALUE TYPE!"; return; }
Chris Lattnerd84bb632002-04-16 21:36:08 +0000512
Reid Spencer56010e42004-05-26 21:56:09 +0000513 Slot = Machine->getSlot(V);
514 delete Machine;
Chris Lattnerd84bb632002-04-16 21:36:08 +0000515 }
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000516 Out << "%" << Slot;
Chris Lattnerd84bb632002-04-16 21:36:08 +0000517 }
518 }
519}
520
521
Misha Brukmanb22d09c2004-03-01 19:48:13 +0000522/// WriteAsOperand - Write the name of the specified value out to the specified
523/// ostream. This can be useful when you just want to print int %reg126, not
524/// the whole instruction that generated it.
525///
Chris Lattner189d19f2003-11-21 20:23:48 +0000526std::ostream &llvm::WriteAsOperand(std::ostream &Out, const Value *V,
Misha Brukmanb22d09c2004-03-01 19:48:13 +0000527 bool PrintType, bool PrintName,
528 const Module *Context) {
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000529 std::map<const Type *, std::string> TypeNames;
Chris Lattner5a9f63e2002-07-10 16:48:17 +0000530 if (Context == 0) Context = getModuleFromVal(V);
Chris Lattnerb86620e2001-10-29 16:37:48 +0000531
Chris Lattner98cf1f52002-11-20 18:36:02 +0000532 if (Context)
Chris Lattner5a9f63e2002-07-10 16:48:17 +0000533 fillTypeNameTable(Context, TypeNames);
Chris Lattnerd84bb632002-04-16 21:36:08 +0000534
535 if (PrintType)
536 printTypeInt(Out, V->getType(), TypeNames);
537
Brian Gaekefda1f182003-11-16 23:08:27 +0000538 if (const Type *Ty = dyn_cast<Type> (V))
539 printTypeInt(Out, Ty, TypeNames);
540
Chris Lattner5a9f63e2002-07-10 16:48:17 +0000541 WriteAsOperandInternal(Out, V, PrintName, TypeNames, 0);
Chris Lattner5e5abe32001-07-20 19:15:21 +0000542 return Out;
543}
544
Chris Lattner189d19f2003-11-21 20:23:48 +0000545namespace llvm {
Chris Lattner2e9fee42001-07-12 23:35:26 +0000546
Chris Lattnerfee714f2001-09-07 16:36:04 +0000547class AssemblyWriter {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000548 std::ostream *Out;
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000549 SlotMachine &Machine;
Chris Lattner7bfee412001-10-29 16:05:51 +0000550 const Module *TheModule;
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000551 std::map<const Type *, std::string> TypeNames;
Chris Lattner8339f7d2003-10-30 23:41:03 +0000552 AssemblyAnnotationWriter *AnnotationWriter;
Chris Lattner2f7c9632001-06-06 20:29:01 +0000553public:
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000554 inline AssemblyWriter(std::ostream &o, SlotMachine &Mac, const Module *M,
Chris Lattner8339f7d2003-10-30 23:41:03 +0000555 AssemblyAnnotationWriter *AAW)
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000556 : Out(&o), Machine(Mac), TheModule(M), AnnotationWriter(AAW) {
Chris Lattner7bfee412001-10-29 16:05:51 +0000557
558 // If the module has a symbol table, take all global types and stuff their
559 // names into the TypeNames map.
560 //
Chris Lattnerb86620e2001-10-29 16:37:48 +0000561 fillTypeNameTable(M, TypeNames);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000562 }
563
Chris Lattner7bfee412001-10-29 16:05:51 +0000564 inline void write(const Module *M) { printModule(M); }
565 inline void write(const GlobalVariable *G) { printGlobal(G); }
Chris Lattner57698e22002-03-26 18:01:55 +0000566 inline void write(const Function *F) { printFunction(F); }
Chris Lattner7bfee412001-10-29 16:05:51 +0000567 inline void write(const BasicBlock *BB) { printBasicBlock(BB); }
Chris Lattner113f4f42002-06-25 16:13:24 +0000568 inline void write(const Instruction *I) { printInstruction(*I); }
Chris Lattner3462ae32001-12-03 22:26:30 +0000569 inline void write(const Constant *CPV) { printConstant(CPV); }
Chris Lattner7db79582001-11-07 04:21:57 +0000570 inline void write(const Type *Ty) { printType(Ty); }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000571
Chris Lattner1e194682002-04-18 18:53:13 +0000572 void writeOperand(const Value *Op, bool PrintType, bool PrintName = true);
573
Misha Brukman4685e262004-04-28 15:31:21 +0000574 const Module* getModule() { return TheModule; }
Misha Brukmanda546ea2004-04-28 19:24:28 +0000575 void setStream(std::ostream &os) { Out = &os; }
Misha Brukman4685e262004-04-28 15:31:21 +0000576
Chris Lattner2f7c9632001-06-06 20:29:01 +0000577private :
Chris Lattner7bfee412001-10-29 16:05:51 +0000578 void printModule(const Module *M);
579 void printSymbolTable(const SymbolTable &ST);
Chris Lattner3462ae32001-12-03 22:26:30 +0000580 void printConstant(const Constant *CPV);
Chris Lattner7bfee412001-10-29 16:05:51 +0000581 void printGlobal(const GlobalVariable *GV);
Chris Lattner57698e22002-03-26 18:01:55 +0000582 void printFunction(const Function *F);
Chris Lattner2e9fa6d2002-04-09 19:48:49 +0000583 void printArgument(const Argument *FA);
Chris Lattner7bfee412001-10-29 16:05:51 +0000584 void printBasicBlock(const BasicBlock *BB);
Chris Lattner113f4f42002-06-25 16:13:24 +0000585 void printInstruction(const Instruction &I);
Chris Lattnerd816b532002-04-13 20:53:41 +0000586
587 // printType - Go to extreme measures to attempt to print out a short,
588 // symbolic version of a type name.
589 //
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000590 std::ostream &printType(const Type *Ty) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000591 return printTypeInt(*Out, Ty, TypeNames);
Chris Lattnerd816b532002-04-13 20:53:41 +0000592 }
593
594 // printTypeAtLeastOneLevel - Print out one level of the possibly complex type
595 // without considering any symbolic types that we may have equal to it.
596 //
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000597 std::ostream &printTypeAtLeastOneLevel(const Type *Ty);
Chris Lattner7bfee412001-10-29 16:05:51 +0000598
Chris Lattner862e3382001-10-13 06:42:36 +0000599 // printInfoComment - Print a little comment after the instruction indicating
600 // which slot it occupies.
Chris Lattner113f4f42002-06-25 16:13:24 +0000601 void printInfoComment(const Value &V);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000602};
Chris Lattner189d19f2003-11-21 20:23:48 +0000603} // end of anonymous namespace
Chris Lattner2f7c9632001-06-06 20:29:01 +0000604
Misha Brukmanc566ca362004-03-02 00:22:19 +0000605/// printTypeAtLeastOneLevel - Print out one level of the possibly complex type
606/// without considering any symbolic types that we may have equal to it.
607///
Chris Lattnerab7d1ab2003-05-08 02:08:14 +0000608std::ostream &AssemblyWriter::printTypeAtLeastOneLevel(const Type *Ty) {
Chris Lattner113f4f42002-06-25 16:13:24 +0000609 if (const FunctionType *FTy = dyn_cast<FunctionType>(Ty)) {
Chris Lattnerd816b532002-04-13 20:53:41 +0000610 printType(FTy->getReturnType()) << " (";
Chris Lattnerfa829be2004-02-09 04:14:01 +0000611 for (FunctionType::param_iterator I = FTy->param_begin(),
612 E = FTy->param_end(); I != E; ++I) {
613 if (I != FTy->param_begin())
Misha Brukmanda546ea2004-04-28 19:24:28 +0000614 *Out << ", ";
Chris Lattnerd84bb632002-04-16 21:36:08 +0000615 printType(*I);
Chris Lattnerd816b532002-04-13 20:53:41 +0000616 }
617 if (FTy->isVarArg()) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000618 if (FTy->getNumParams()) *Out << ", ";
619 *Out << "...";
Chris Lattnerd816b532002-04-13 20:53:41 +0000620 }
Misha Brukmanda546ea2004-04-28 19:24:28 +0000621 *Out << ")";
Chris Lattner113f4f42002-06-25 16:13:24 +0000622 } else if (const StructType *STy = dyn_cast<StructType>(Ty)) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000623 *Out << "{ ";
Chris Lattnerac6db752004-02-09 04:37:31 +0000624 for (StructType::element_iterator I = STy->element_begin(),
625 E = STy->element_end(); I != E; ++I) {
626 if (I != STy->element_begin())
Misha Brukmanda546ea2004-04-28 19:24:28 +0000627 *Out << ", ";
Chris Lattnerd816b532002-04-13 20:53:41 +0000628 printType(*I);
629 }
Misha Brukmanda546ea2004-04-28 19:24:28 +0000630 *Out << " }";
Chris Lattner113f4f42002-06-25 16:13:24 +0000631 } else if (const PointerType *PTy = dyn_cast<PointerType>(Ty)) {
Chris Lattnerd816b532002-04-13 20:53:41 +0000632 printType(PTy->getElementType()) << "*";
Chris Lattner113f4f42002-06-25 16:13:24 +0000633 } else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000634 *Out << "[" << ATy->getNumElements() << " x ";
Chris Lattnerd816b532002-04-13 20:53:41 +0000635 printType(ATy->getElementType()) << "]";
Chris Lattner113f4f42002-06-25 16:13:24 +0000636 } else if (const OpaqueType *OTy = dyn_cast<OpaqueType>(Ty)) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000637 *Out << "opaque";
Chris Lattnerd816b532002-04-13 20:53:41 +0000638 } else {
Vikram S. Adveb952b542002-07-14 23:14:45 +0000639 if (!Ty->isPrimitiveType())
Misha Brukmanda546ea2004-04-28 19:24:28 +0000640 *Out << "<unknown derived type>";
Chris Lattnerd816b532002-04-13 20:53:41 +0000641 printType(Ty);
642 }
Misha Brukmanda546ea2004-04-28 19:24:28 +0000643 return *Out;
Chris Lattnerd816b532002-04-13 20:53:41 +0000644}
645
646
Chris Lattnerfee714f2001-09-07 16:36:04 +0000647void AssemblyWriter::writeOperand(const Value *Operand, bool PrintType,
Reid Spencer56010e42004-05-26 21:56:09 +0000648 bool PrintName) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000649 if (PrintType) { *Out << " "; printType(Operand->getType()); }
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000650 WriteAsOperandInternal(*Out, Operand, PrintName, TypeNames, &Machine);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000651}
652
Chris Lattner2f7c9632001-06-06 20:29:01 +0000653
Chris Lattner7bfee412001-10-29 16:05:51 +0000654void AssemblyWriter::printModule(const Module *M) {
Chris Lattner8068e0c2003-08-24 13:48:48 +0000655 switch (M->getEndianness()) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000656 case Module::LittleEndian: *Out << "target endian = little\n"; break;
657 case Module::BigEndian: *Out << "target endian = big\n"; break;
Chris Lattner8068e0c2003-08-24 13:48:48 +0000658 case Module::AnyEndianness: break;
659 }
660 switch (M->getPointerSize()) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000661 case Module::Pointer32: *Out << "target pointersize = 32\n"; break;
662 case Module::Pointer64: *Out << "target pointersize = 64\n"; break;
Chris Lattner8068e0c2003-08-24 13:48:48 +0000663 case Module::AnyPointerSize: break;
664 }
665
Chris Lattnerfee714f2001-09-07 16:36:04 +0000666 // Loop over the symbol table, emitting all named constants...
Chris Lattner98cf1f52002-11-20 18:36:02 +0000667 printSymbolTable(M->getSymbolTable());
Chris Lattnerda975502001-09-10 07:58:01 +0000668
Chris Lattner113f4f42002-06-25 16:13:24 +0000669 for (Module::const_giterator I = M->gbegin(), E = M->gend(); I != E; ++I)
670 printGlobal(I);
Chris Lattnerfee714f2001-09-07 16:36:04 +0000671
Misha Brukmanda546ea2004-04-28 19:24:28 +0000672 *Out << "\nimplementation ; Functions:\n";
Vikram S. Adve13ba19a2001-09-18 12:48:16 +0000673
Chris Lattner6915f8f2002-04-07 22:49:37 +0000674 // Output all of the functions...
Chris Lattner113f4f42002-06-25 16:13:24 +0000675 for (Module::const_iterator I = M->begin(), E = M->end(); I != E; ++I)
676 printFunction(I);
Chris Lattnerfee714f2001-09-07 16:36:04 +0000677}
678
Chris Lattner7bfee412001-10-29 16:05:51 +0000679void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000680 if (GV->hasName()) *Out << getLLVMName(GV->getName()) << " = ";
Chris Lattner37798642001-09-18 04:01:05 +0000681
Chris Lattner379a8d22003-04-16 20:28:45 +0000682 if (!GV->hasInitializer())
Misha Brukmanda546ea2004-04-28 19:24:28 +0000683 *Out << "external ";
Chris Lattner379a8d22003-04-16 20:28:45 +0000684 else
685 switch (GV->getLinkage()) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000686 case GlobalValue::InternalLinkage: *Out << "internal "; break;
687 case GlobalValue::LinkOnceLinkage: *Out << "linkonce "; break;
688 case GlobalValue::WeakLinkage: *Out << "weak "; break;
689 case GlobalValue::AppendingLinkage: *Out << "appending "; break;
Chris Lattner379a8d22003-04-16 20:28:45 +0000690 case GlobalValue::ExternalLinkage: break;
691 }
Chris Lattner37798642001-09-18 04:01:05 +0000692
Misha Brukmanda546ea2004-04-28 19:24:28 +0000693 *Out << (GV->isConstant() ? "constant " : "global ");
Chris Lattner2413b162001-12-04 00:03:30 +0000694 printType(GV->getType()->getElementType());
Chris Lattner37798642001-09-18 04:01:05 +0000695
696 if (GV->hasInitializer())
697 writeOperand(GV->getInitializer(), false, false);
698
Chris Lattner113f4f42002-06-25 16:13:24 +0000699 printInfoComment(*GV);
Misha Brukmanda546ea2004-04-28 19:24:28 +0000700 *Out << "\n";
Chris Lattnerda975502001-09-10 07:58:01 +0000701}
702
Chris Lattnerfee714f2001-09-07 16:36:04 +0000703
Reid Spencere7e96712004-05-25 08:53:40 +0000704// printSymbolTable - Run through symbol table looking for constants
705// and types. Emit their declarations.
Chris Lattner7bfee412001-10-29 16:05:51 +0000706void AssemblyWriter::printSymbolTable(const SymbolTable &ST) {
Reid Spencere7e96712004-05-25 08:53:40 +0000707
708 // Print the types.
709 for (SymbolTable::type_const_iterator TI = ST.type_begin();
710 TI != ST.type_end(); ++TI ) {
711 *Out << "\t" << getLLVMName(TI->first) << " = type ";
712
713 // Make sure we print out at least one level of the type structure, so
714 // that we do not get %FILE = type %FILE
715 //
716 printTypeAtLeastOneLevel(TI->second) << "\n";
717 }
Chris Lattnerfee714f2001-09-07 16:36:04 +0000718
Reid Spencere7e96712004-05-25 08:53:40 +0000719 // Print the constants, in type plane order.
720 for (SymbolTable::plane_const_iterator PI = ST.plane_begin();
721 PI != ST.plane_end(); ++PI ) {
722 SymbolTable::value_const_iterator VI = ST.value_begin(PI->first);
723 SymbolTable::value_const_iterator VE = ST.value_end(PI->first);
724
725 for (; VI != VE; ++VI) {
726 const Value *V = VI->second;
Chris Lattnerf26a8ee2003-07-23 15:30:06 +0000727 if (const Constant *CPV = dyn_cast<Constant>(V)) {
Reid Spencer56010e42004-05-26 21:56:09 +0000728 printConstant(CPV);
Chris Lattnerfee714f2001-09-07 16:36:04 +0000729 }
730 }
Chris Lattnera7620d92001-07-15 06:35:59 +0000731 }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000732}
733
734
Misha Brukmanc566ca362004-03-02 00:22:19 +0000735/// printConstant - Print out a constant pool entry...
736///
Chris Lattner3462ae32001-12-03 22:26:30 +0000737void AssemblyWriter::printConstant(const Constant *CPV) {
Chris Lattnerfee714f2001-09-07 16:36:04 +0000738 // Don't print out unnamed constants, they will be inlined
739 if (!CPV->hasName()) return;
Chris Lattner2f7c9632001-06-06 20:29:01 +0000740
Chris Lattneree998be2001-07-26 16:29:38 +0000741 // Print out name...
Misha Brukmanda546ea2004-04-28 19:24:28 +0000742 *Out << "\t" << getLLVMName(CPV->getName()) << " =";
Chris Lattner2f7c9632001-06-06 20:29:01 +0000743
744 // Write the value out now...
Chris Lattnerd84bb632002-04-16 21:36:08 +0000745 writeOperand(CPV, true, false);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000746
Chris Lattner113f4f42002-06-25 16:13:24 +0000747 printInfoComment(*CPV);
Misha Brukmanda546ea2004-04-28 19:24:28 +0000748 *Out << "\n";
Chris Lattner2f7c9632001-06-06 20:29:01 +0000749}
750
Misha Brukmanc566ca362004-03-02 00:22:19 +0000751/// printFunction - Print all aspects of a function.
752///
Chris Lattner113f4f42002-06-25 16:13:24 +0000753void AssemblyWriter::printFunction(const Function *F) {
Chris Lattner2f7c9632001-06-06 20:29:01 +0000754 // Print out the return type and name...
Misha Brukmanda546ea2004-04-28 19:24:28 +0000755 *Out << "\n";
Chris Lattner379a8d22003-04-16 20:28:45 +0000756
Misha Brukmanda546ea2004-04-28 19:24:28 +0000757 if (AnnotationWriter) AnnotationWriter->emitFunctionAnnot(F, *Out);
Chris Lattner8339f7d2003-10-30 23:41:03 +0000758
Chris Lattner379a8d22003-04-16 20:28:45 +0000759 if (F->isExternal())
Misha Brukmanda546ea2004-04-28 19:24:28 +0000760 *Out << "declare ";
Chris Lattner379a8d22003-04-16 20:28:45 +0000761 else
762 switch (F->getLinkage()) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000763 case GlobalValue::InternalLinkage: *Out << "internal "; break;
764 case GlobalValue::LinkOnceLinkage: *Out << "linkonce "; break;
765 case GlobalValue::WeakLinkage: *Out << "weak "; break;
766 case GlobalValue::AppendingLinkage: *Out << "appending "; break;
Chris Lattner379a8d22003-04-16 20:28:45 +0000767 case GlobalValue::ExternalLinkage: break;
768 }
769
Chris Lattner13651f02003-09-03 17:56:43 +0000770 printType(F->getReturnType()) << " ";
Chris Lattner5b337482003-10-18 05:57:43 +0000771 if (!F->getName().empty())
Misha Brukmanda546ea2004-04-28 19:24:28 +0000772 *Out << getLLVMName(F->getName());
Chris Lattner5b337482003-10-18 05:57:43 +0000773 else
Misha Brukmanda546ea2004-04-28 19:24:28 +0000774 *Out << "\"\"";
775 *Out << "(";
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000776 Machine.incorporateFunction(F);
Chris Lattnerfee714f2001-09-07 16:36:04 +0000777
Chris Lattner7bfee412001-10-29 16:05:51 +0000778 // Loop over the arguments, printing them...
Chris Lattner113f4f42002-06-25 16:13:24 +0000779 const FunctionType *FT = F->getFunctionType();
Chris Lattnerfee714f2001-09-07 16:36:04 +0000780
Chris Lattner149376d2002-10-13 20:57:00 +0000781 for(Function::const_aiterator I = F->abegin(), E = F->aend(); I != E; ++I)
782 printArgument(I);
Chris Lattnerfee714f2001-09-07 16:36:04 +0000783
784 // Finish printing arguments...
Chris Lattner113f4f42002-06-25 16:13:24 +0000785 if (FT->isVarArg()) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000786 if (FT->getNumParams()) *Out << ", ";
787 *Out << "..."; // Output varargs portion of signature!
Chris Lattnerfee714f2001-09-07 16:36:04 +0000788 }
Misha Brukmanda546ea2004-04-28 19:24:28 +0000789 *Out << ")";
Chris Lattnerfee714f2001-09-07 16:36:04 +0000790
Chris Lattner113f4f42002-06-25 16:13:24 +0000791 if (F->isExternal()) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000792 *Out << "\n";
Chris Lattnerb2f02e52002-05-06 03:00:40 +0000793 } else {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000794 *Out << " {";
Chris Lattnerfee714f2001-09-07 16:36:04 +0000795
Chris Lattner6915f8f2002-04-07 22:49:37 +0000796 // Output all of its basic blocks... for the function
Chris Lattner113f4f42002-06-25 16:13:24 +0000797 for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I)
798 printBasicBlock(I);
Chris Lattnerfee714f2001-09-07 16:36:04 +0000799
Misha Brukmanda546ea2004-04-28 19:24:28 +0000800 *Out << "}\n";
Chris Lattnerfee714f2001-09-07 16:36:04 +0000801 }
802
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000803 Machine.purgeFunction();
Chris Lattner2f7c9632001-06-06 20:29:01 +0000804}
805
Misha Brukmanc566ca362004-03-02 00:22:19 +0000806/// printArgument - This member is called for every argument that is passed into
807/// the function. Simply print it out
808///
Chris Lattner2e9fa6d2002-04-09 19:48:49 +0000809void AssemblyWriter::printArgument(const Argument *Arg) {
Chris Lattner2f7c9632001-06-06 20:29:01 +0000810 // Insert commas as we go... the first arg doesn't get a comma
Misha Brukmanda546ea2004-04-28 19:24:28 +0000811 if (Arg != &Arg->getParent()->afront()) *Out << ", ";
Chris Lattner2f7c9632001-06-06 20:29:01 +0000812
813 // Output type...
Chris Lattner7bfee412001-10-29 16:05:51 +0000814 printType(Arg->getType());
Chris Lattner2f7c9632001-06-06 20:29:01 +0000815
816 // Output name, if available...
817 if (Arg->hasName())
Misha Brukmanda546ea2004-04-28 19:24:28 +0000818 *Out << " " << getLLVMName(Arg->getName());
Chris Lattner2f7c9632001-06-06 20:29:01 +0000819}
820
Misha Brukmanc566ca362004-03-02 00:22:19 +0000821/// printBasicBlock - This member is called for each basic block in a method.
822///
Chris Lattner7bfee412001-10-29 16:05:51 +0000823void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
Chris Lattner2f7c9632001-06-06 20:29:01 +0000824 if (BB->hasName()) { // Print out the label if it exists...
Misha Brukmanda546ea2004-04-28 19:24:28 +0000825 *Out << "\n" << BB->getName() << ":";
Chris Lattner408dbdb2002-05-14 16:02:05 +0000826 } else if (!BB->use_empty()) { // Don't print block # of no uses...
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000827 *Out << "\n; <label>:" << Machine.getSlot(BB);
Chris Lattner58185f22002-10-02 19:38:55 +0000828 }
Chris Lattner2447ef52003-11-20 00:09:43 +0000829
830 if (BB->getParent() == 0)
Misha Brukmanda546ea2004-04-28 19:24:28 +0000831 *Out << "\t\t; Error: Block without parent!";
Chris Lattner2447ef52003-11-20 00:09:43 +0000832 else {
833 if (BB != &BB->getParent()->front()) { // Not the entry block?
834 // Output predecessors for the block...
Misha Brukmanda546ea2004-04-28 19:24:28 +0000835 *Out << "\t\t;";
Chris Lattner2447ef52003-11-20 00:09:43 +0000836 pred_const_iterator PI = pred_begin(BB), PE = pred_end(BB);
837
838 if (PI == PE) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000839 *Out << " No predecessors!";
Chris Lattner2447ef52003-11-20 00:09:43 +0000840 } else {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000841 *Out << " preds =";
Chris Lattner00211f12003-11-16 22:59:57 +0000842 writeOperand(*PI, false, true);
Chris Lattner2447ef52003-11-20 00:09:43 +0000843 for (++PI; PI != PE; ++PI) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000844 *Out << ",";
Chris Lattner2447ef52003-11-20 00:09:43 +0000845 writeOperand(*PI, false, true);
846 }
Chris Lattner00211f12003-11-16 22:59:57 +0000847 }
Chris Lattner58185f22002-10-02 19:38:55 +0000848 }
Chris Lattner2f7c9632001-06-06 20:29:01 +0000849 }
Chris Lattner408dbdb2002-05-14 16:02:05 +0000850
Misha Brukmanda546ea2004-04-28 19:24:28 +0000851 *Out << "\n";
Chris Lattner2f7c9632001-06-06 20:29:01 +0000852
Misha Brukmanda546ea2004-04-28 19:24:28 +0000853 if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, *Out);
Chris Lattner8339f7d2003-10-30 23:41:03 +0000854
Chris Lattnerfee714f2001-09-07 16:36:04 +0000855 // Output all of the instructions in the basic block...
Chris Lattner113f4f42002-06-25 16:13:24 +0000856 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I)
857 printInstruction(*I);
Chris Lattner96cdd272004-03-08 18:51:45 +0000858
Misha Brukmanda546ea2004-04-28 19:24:28 +0000859 if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, *Out);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000860}
861
Chris Lattner862e3382001-10-13 06:42:36 +0000862
Misha Brukmanc566ca362004-03-02 00:22:19 +0000863/// printInfoComment - Print a little comment after the instruction indicating
864/// which slot it occupies.
865///
Chris Lattner113f4f42002-06-25 16:13:24 +0000866void AssemblyWriter::printInfoComment(const Value &V) {
867 if (V.getType() != Type::VoidTy) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000868 *Out << "\t\t; <";
Chris Lattner113f4f42002-06-25 16:13:24 +0000869 printType(V.getType()) << ">";
Chris Lattner862e3382001-10-13 06:42:36 +0000870
Chris Lattner113f4f42002-06-25 16:13:24 +0000871 if (!V.hasName()) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +0000872 *Out << ":" << Machine.getSlot(&V); // Print out the def slot taken.
Chris Lattner862e3382001-10-13 06:42:36 +0000873 }
Misha Brukmanda546ea2004-04-28 19:24:28 +0000874 *Out << " [#uses=" << V.use_size() << "]"; // Output # uses
Chris Lattner862e3382001-10-13 06:42:36 +0000875 }
876}
877
Misha Brukmanc566ca362004-03-02 00:22:19 +0000878/// printInstruction - This member is called for each Instruction in a method.
879///
Chris Lattner113f4f42002-06-25 16:13:24 +0000880void AssemblyWriter::printInstruction(const Instruction &I) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000881 if (AnnotationWriter) AnnotationWriter->emitInstructionAnnot(&I, *Out);
Chris Lattner8339f7d2003-10-30 23:41:03 +0000882
Misha Brukmanda546ea2004-04-28 19:24:28 +0000883 *Out << "\t";
Chris Lattner2f7c9632001-06-06 20:29:01 +0000884
885 // Print out name if it exists...
Chris Lattner113f4f42002-06-25 16:13:24 +0000886 if (I.hasName())
Misha Brukmanda546ea2004-04-28 19:24:28 +0000887 *Out << getLLVMName(I.getName()) << " = ";
Chris Lattner2f7c9632001-06-06 20:29:01 +0000888
Chris Lattner504f9242003-09-08 17:45:59 +0000889 // If this is a volatile load or store, print out the volatile marker
890 if ((isa<LoadInst>(I) && cast<LoadInst>(I).isVolatile()) ||
891 (isa<StoreInst>(I) && cast<StoreInst>(I).isVolatile()))
Misha Brukmanda546ea2004-04-28 19:24:28 +0000892 *Out << "volatile ";
Chris Lattner504f9242003-09-08 17:45:59 +0000893
Chris Lattner2f7c9632001-06-06 20:29:01 +0000894 // Print out the opcode...
Misha Brukmanda546ea2004-04-28 19:24:28 +0000895 *Out << I.getOpcodeName();
Chris Lattner2f7c9632001-06-06 20:29:01 +0000896
897 // Print out the type of the operands...
Chris Lattner113f4f42002-06-25 16:13:24 +0000898 const Value *Operand = I.getNumOperands() ? I.getOperand(0) : 0;
Chris Lattner2f7c9632001-06-06 20:29:01 +0000899
900 // Special case conditional branches to swizzle the condition out to the front
Chris Lattner113f4f42002-06-25 16:13:24 +0000901 if (isa<BranchInst>(I) && I.getNumOperands() > 1) {
902 writeOperand(I.getOperand(2), true);
Misha Brukmanda546ea2004-04-28 19:24:28 +0000903 *Out << ",";
Chris Lattner2f7c9632001-06-06 20:29:01 +0000904 writeOperand(Operand, true);
Misha Brukmanda546ea2004-04-28 19:24:28 +0000905 *Out << ",";
Chris Lattner113f4f42002-06-25 16:13:24 +0000906 writeOperand(I.getOperand(1), true);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000907
Chris Lattner8d48df22002-04-13 18:34:38 +0000908 } else if (isa<SwitchInst>(I)) {
Chris Lattner2f7c9632001-06-06 20:29:01 +0000909 // Special case switch statement to get formatting nice and correct...
Misha Brukmanda546ea2004-04-28 19:24:28 +0000910 writeOperand(Operand , true); *Out << ",";
911 writeOperand(I.getOperand(1), true); *Out << " [";
Chris Lattner2f7c9632001-06-06 20:29:01 +0000912
Chris Lattner113f4f42002-06-25 16:13:24 +0000913 for (unsigned op = 2, Eop = I.getNumOperands(); op < Eop; op += 2) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000914 *Out << "\n\t\t";
915 writeOperand(I.getOperand(op ), true); *Out << ",";
Chris Lattner113f4f42002-06-25 16:13:24 +0000916 writeOperand(I.getOperand(op+1), true);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000917 }
Misha Brukmanda546ea2004-04-28 19:24:28 +0000918 *Out << "\n\t]";
Chris Lattnerda558102001-10-02 03:41:24 +0000919 } else if (isa<PHINode>(I)) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000920 *Out << " ";
Chris Lattner113f4f42002-06-25 16:13:24 +0000921 printType(I.getType());
Misha Brukmanda546ea2004-04-28 19:24:28 +0000922 *Out << " ";
Chris Lattner2f7c9632001-06-06 20:29:01 +0000923
Chris Lattner113f4f42002-06-25 16:13:24 +0000924 for (unsigned op = 0, Eop = I.getNumOperands(); op < Eop; op += 2) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000925 if (op) *Out << ", ";
926 *Out << "[";
927 writeOperand(I.getOperand(op ), false); *Out << ",";
928 writeOperand(I.getOperand(op+1), false); *Out << " ]";
Chris Lattner931ef3b2001-06-11 15:04:20 +0000929 }
Chris Lattner862e3382001-10-13 06:42:36 +0000930 } else if (isa<ReturnInst>(I) && !Operand) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000931 *Out << " void";
Chris Lattner862e3382001-10-13 06:42:36 +0000932 } else if (isa<CallInst>(I)) {
Chris Lattner463d6a52003-08-05 15:34:45 +0000933 const PointerType *PTy = cast<PointerType>(Operand->getType());
934 const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
935 const Type *RetTy = FTy->getReturnType();
Chris Lattner2f2d9472001-11-06 21:28:12 +0000936
Chris Lattner463d6a52003-08-05 15:34:45 +0000937 // If possible, print out the short form of the call instruction. We can
Chris Lattner6915f8f2002-04-07 22:49:37 +0000938 // only do this if the first argument is a pointer to a nonvararg function,
Chris Lattner463d6a52003-08-05 15:34:45 +0000939 // and if the return type is not a pointer to a function.
Chris Lattner2f2d9472001-11-06 21:28:12 +0000940 //
Chris Lattner463d6a52003-08-05 15:34:45 +0000941 if (!FTy->isVarArg() &&
Chris Lattner8d48df22002-04-13 18:34:38 +0000942 (!isa<PointerType>(RetTy) ||
Chris Lattnerd9a36a62002-07-25 20:58:51 +0000943 !isa<FunctionType>(cast<PointerType>(RetTy)->getElementType()))) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000944 *Out << " "; printType(RetTy);
Chris Lattner2f2d9472001-11-06 21:28:12 +0000945 writeOperand(Operand, false);
946 } else {
947 writeOperand(Operand, true);
948 }
Misha Brukmanda546ea2004-04-28 19:24:28 +0000949 *Out << "(";
Chris Lattner113f4f42002-06-25 16:13:24 +0000950 if (I.getNumOperands() > 1) writeOperand(I.getOperand(1), true);
951 for (unsigned op = 2, Eop = I.getNumOperands(); op < Eop; ++op) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000952 *Out << ",";
Chris Lattner113f4f42002-06-25 16:13:24 +0000953 writeOperand(I.getOperand(op), true);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000954 }
955
Misha Brukmanda546ea2004-04-28 19:24:28 +0000956 *Out << " )";
Chris Lattner113f4f42002-06-25 16:13:24 +0000957 } else if (const InvokeInst *II = dyn_cast<InvokeInst>(&I)) {
Chris Lattner463d6a52003-08-05 15:34:45 +0000958 const PointerType *PTy = cast<PointerType>(Operand->getType());
959 const FunctionType *FTy = cast<FunctionType>(PTy->getElementType());
960 const Type *RetTy = FTy->getReturnType();
961
962 // If possible, print out the short form of the invoke instruction. We can
963 // only do this if the first argument is a pointer to a nonvararg function,
964 // and if the return type is not a pointer to a function.
965 //
966 if (!FTy->isVarArg() &&
967 (!isa<PointerType>(RetTy) ||
968 !isa<FunctionType>(cast<PointerType>(RetTy)->getElementType()))) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000969 *Out << " "; printType(RetTy);
Chris Lattner463d6a52003-08-05 15:34:45 +0000970 writeOperand(Operand, false);
971 } else {
972 writeOperand(Operand, true);
973 }
974
Misha Brukmanda546ea2004-04-28 19:24:28 +0000975 *Out << "(";
Chris Lattner113f4f42002-06-25 16:13:24 +0000976 if (I.getNumOperands() > 3) writeOperand(I.getOperand(3), true);
977 for (unsigned op = 4, Eop = I.getNumOperands(); op < Eop; ++op) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000978 *Out << ",";
Chris Lattner113f4f42002-06-25 16:13:24 +0000979 writeOperand(I.getOperand(op), true);
Chris Lattner862e3382001-10-13 06:42:36 +0000980 }
981
Misha Brukmanda546ea2004-04-28 19:24:28 +0000982 *Out << " )\n\t\t\tto";
Chris Lattner862e3382001-10-13 06:42:36 +0000983 writeOperand(II->getNormalDest(), true);
Misha Brukmanda546ea2004-04-28 19:24:28 +0000984 *Out << " unwind";
Chris Lattnerfae8ab32004-02-08 21:44:31 +0000985 writeOperand(II->getUnwindDest(), true);
Chris Lattner862e3382001-10-13 06:42:36 +0000986
Chris Lattner113f4f42002-06-25 16:13:24 +0000987 } else if (const AllocationInst *AI = dyn_cast<AllocationInst>(&I)) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000988 *Out << " ";
Chris Lattner8d48df22002-04-13 18:34:38 +0000989 printType(AI->getType()->getElementType());
990 if (AI->isArrayAllocation()) {
Misha Brukmanda546ea2004-04-28 19:24:28 +0000991 *Out << ",";
Chris Lattner8d48df22002-04-13 18:34:38 +0000992 writeOperand(AI->getArraySize(), true);
Chris Lattner2f7c9632001-06-06 20:29:01 +0000993 }
Chris Lattner862e3382001-10-13 06:42:36 +0000994 } else if (isa<CastInst>(I)) {
Chris Lattnerc96e96b2003-11-17 01:17:04 +0000995 if (Operand) writeOperand(Operand, true); // Work with broken code
Misha Brukmanda546ea2004-04-28 19:24:28 +0000996 *Out << " to ";
Chris Lattner113f4f42002-06-25 16:13:24 +0000997 printType(I.getType());
Chris Lattner5b337482003-10-18 05:57:43 +0000998 } else if (isa<VAArgInst>(I)) {
Chris Lattnerc96e96b2003-11-17 01:17:04 +0000999 if (Operand) writeOperand(Operand, true); // Work with broken code
Misha Brukmanda546ea2004-04-28 19:24:28 +00001000 *Out << ", ";
Chris Lattnerf70da102003-05-08 02:44:12 +00001001 printType(I.getType());
Chris Lattner5b337482003-10-18 05:57:43 +00001002 } else if (const VANextInst *VAN = dyn_cast<VANextInst>(&I)) {
Chris Lattnerc96e96b2003-11-17 01:17:04 +00001003 if (Operand) writeOperand(Operand, true); // Work with broken code
Misha Brukmanda546ea2004-04-28 19:24:28 +00001004 *Out << ", ";
Chris Lattner5b337482003-10-18 05:57:43 +00001005 printType(VAN->getArgType());
Chris Lattner2f7c9632001-06-06 20:29:01 +00001006 } else if (Operand) { // Print the normal way...
1007
1008 // PrintAllTypes - Instructions who have operands of all the same type
1009 // omit the type from all but the first operand. If the instruction has
1010 // different type operands (for example br), then they are all printed.
1011 bool PrintAllTypes = false;
1012 const Type *TheType = Operand->getType();
Chris Lattner2f7c9632001-06-06 20:29:01 +00001013
Chris Lattner52bd5cb92004-03-12 05:53:14 +00001014 // Shift Left & Right print both types even for Ubyte LHS, and select prints
1015 // types even if all operands are bools.
1016 if (isa<ShiftInst>(I) || isa<SelectInst>(I)) {
Chris Lattnerdeccfaf2003-04-16 20:20:02 +00001017 PrintAllTypes = true;
1018 } else {
1019 for (unsigned i = 1, E = I.getNumOperands(); i != E; ++i) {
1020 Operand = I.getOperand(i);
1021 if (Operand->getType() != TheType) {
1022 PrintAllTypes = true; // We have differing types! Print them all!
1023 break;
1024 }
Chris Lattner2f7c9632001-06-06 20:29:01 +00001025 }
1026 }
Chris Lattnerdeccfaf2003-04-16 20:20:02 +00001027
Chris Lattner7bfee412001-10-29 16:05:51 +00001028 if (!PrintAllTypes) {
Misha Brukmanda546ea2004-04-28 19:24:28 +00001029 *Out << " ";
Chris Lattnerdeccfaf2003-04-16 20:20:02 +00001030 printType(TheType);
Chris Lattner7bfee412001-10-29 16:05:51 +00001031 }
Chris Lattner2f7c9632001-06-06 20:29:01 +00001032
Chris Lattner113f4f42002-06-25 16:13:24 +00001033 for (unsigned i = 0, E = I.getNumOperands(); i != E; ++i) {
Misha Brukmanda546ea2004-04-28 19:24:28 +00001034 if (i) *Out << ",";
Chris Lattner113f4f42002-06-25 16:13:24 +00001035 writeOperand(I.getOperand(i), PrintAllTypes);
Chris Lattner2f7c9632001-06-06 20:29:01 +00001036 }
1037 }
1038
Chris Lattner862e3382001-10-13 06:42:36 +00001039 printInfoComment(I);
Misha Brukmanda546ea2004-04-28 19:24:28 +00001040 *Out << "\n";
Chris Lattner2f7c9632001-06-06 20:29:01 +00001041}
1042
1043
1044//===----------------------------------------------------------------------===//
1045// External Interface declarations
1046//===----------------------------------------------------------------------===//
1047
Chris Lattner8339f7d2003-10-30 23:41:03 +00001048void Module::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001049 SlotMachine SlotTable(this);
Chris Lattner8339f7d2003-10-30 23:41:03 +00001050 AssemblyWriter W(o, SlotTable, this, AAW);
Chris Lattnerc0b4c7b2002-04-08 22:03:40 +00001051 W.write(this);
Chris Lattner2f7c9632001-06-06 20:29:01 +00001052}
1053
Chris Lattnerc0b4c7b2002-04-08 22:03:40 +00001054void GlobalVariable::print(std::ostream &o) const {
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001055 SlotMachine SlotTable(getParent());
Chris Lattner8339f7d2003-10-30 23:41:03 +00001056 AssemblyWriter W(o, SlotTable, getParent(), 0);
Chris Lattnerc0b4c7b2002-04-08 22:03:40 +00001057 W.write(this);
Chris Lattneradfe0d12001-09-10 20:08:19 +00001058}
1059
Chris Lattner8339f7d2003-10-30 23:41:03 +00001060void Function::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001061 SlotMachine SlotTable(getParent());
Chris Lattner8339f7d2003-10-30 23:41:03 +00001062 AssemblyWriter W(o, SlotTable, getParent(), AAW);
Chris Lattner2f7c9632001-06-06 20:29:01 +00001063
Chris Lattnerc0b4c7b2002-04-08 22:03:40 +00001064 W.write(this);
Chris Lattner2f7c9632001-06-06 20:29:01 +00001065}
1066
Chris Lattner8339f7d2003-10-30 23:41:03 +00001067void BasicBlock::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001068 SlotMachine SlotTable(getParent());
Chris Lattner7bfee412001-10-29 16:05:51 +00001069 AssemblyWriter W(o, SlotTable,
Chris Lattner8339f7d2003-10-30 23:41:03 +00001070 getParent() ? getParent()->getParent() : 0, AAW);
Chris Lattnerc0b4c7b2002-04-08 22:03:40 +00001071 W.write(this);
Chris Lattner2f7c9632001-06-06 20:29:01 +00001072}
1073
Chris Lattner8339f7d2003-10-30 23:41:03 +00001074void Instruction::print(std::ostream &o, AssemblyAnnotationWriter *AAW) const {
Chris Lattnerc0b4c7b2002-04-08 22:03:40 +00001075 const Function *F = getParent() ? getParent()->getParent() : 0;
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001076 SlotMachine SlotTable(F);
Chris Lattner8339f7d2003-10-30 23:41:03 +00001077 AssemblyWriter W(o, SlotTable, F ? F->getParent() : 0, AAW);
Chris Lattner2f7c9632001-06-06 20:29:01 +00001078
Chris Lattnerc0b4c7b2002-04-08 22:03:40 +00001079 W.write(this);
Chris Lattner2f7c9632001-06-06 20:29:01 +00001080}
Chris Lattner7db79582001-11-07 04:21:57 +00001081
Chris Lattnerc0b4c7b2002-04-08 22:03:40 +00001082void Constant::print(std::ostream &o) const {
1083 if (this == 0) { o << "<null> constant value\n"; return; }
Chris Lattner7d734802002-09-10 15:53:49 +00001084
1085 // Handle CPR's special, because they have context information...
1086 if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(this)) {
1087 CPR->getValue()->print(o); // Print as a global value, with context info.
1088 return;
1089 }
1090
Chris Lattner1e194682002-04-18 18:53:13 +00001091 o << " " << getType()->getDescription() << " ";
1092
Chris Lattnerab7d1ab2003-05-08 02:08:14 +00001093 std::map<const Type *, std::string> TypeTable;
Chris Lattner1e194682002-04-18 18:53:13 +00001094 WriteConstantInt(o, this, false, TypeTable, 0);
Chris Lattnerc0b4c7b2002-04-08 22:03:40 +00001095}
1096
1097void Type::print(std::ostream &o) const {
1098 if (this == 0)
1099 o << "<null Type>";
1100 else
1101 o << getDescription();
1102}
1103
Chris Lattner2e9fa6d2002-04-09 19:48:49 +00001104void Argument::print(std::ostream &o) const {
Chris Lattnerc0b4c7b2002-04-08 22:03:40 +00001105 o << getType() << " " << getName();
1106}
1107
Reid Spencer52641832004-05-25 18:14:38 +00001108// Value::dump - allow easy printing of Values from the debugger.
1109// Located here because so much of the needed functionality is here.
Chris Lattnerc0b4c7b2002-04-08 22:03:40 +00001110void Value::dump() const { print(std::cerr); }
Reid Spencer52641832004-05-25 18:14:38 +00001111
1112// Type::dump - allow easy printing of Values from the debugger.
1113// Located here because so much of the needed functionality is here.
Reid Spencere7e96712004-05-25 08:53:40 +00001114void Type::dump() const { print(std::cerr); }
Chris Lattnerc0b4c7b2002-04-08 22:03:40 +00001115
1116//===----------------------------------------------------------------------===//
1117// CachedWriter Class Implementation
1118//===----------------------------------------------------------------------===//
1119
Chris Lattner7db79582001-11-07 04:21:57 +00001120void CachedWriter::setModule(const Module *M) {
1121 delete SC; delete AW;
1122 if (M) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001123 SC = new SlotMachine(M );
Misha Brukman4685e262004-04-28 15:31:21 +00001124 AW = new AssemblyWriter(*Out, *SC, M, 0);
Chris Lattner7db79582001-11-07 04:21:57 +00001125 } else {
1126 SC = 0; AW = 0;
1127 }
1128}
1129
1130CachedWriter::~CachedWriter() {
1131 delete AW;
1132 delete SC;
1133}
1134
1135CachedWriter &CachedWriter::operator<<(const Value *V) {
1136 assert(AW && SC && "CachedWriter does not have a current module!");
1137 switch (V->getValueType()) {
1138 case Value::ConstantVal:
Chris Lattner1e194682002-04-18 18:53:13 +00001139 case Value::ArgumentVal: AW->writeOperand(V, true, true); break;
Chris Lattnerf26a8ee2003-07-23 15:30:06 +00001140 case Value::TypeVal: AW->write(cast<Type>(V)); break;
Chris Lattner7db79582001-11-07 04:21:57 +00001141 case Value::InstructionVal: AW->write(cast<Instruction>(V)); break;
1142 case Value::BasicBlockVal: AW->write(cast<BasicBlock>(V)); break;
Chris Lattner57698e22002-03-26 18:01:55 +00001143 case Value::FunctionVal: AW->write(cast<Function>(V)); break;
Chris Lattner7db79582001-11-07 04:21:57 +00001144 case Value::GlobalVariableVal: AW->write(cast<GlobalVariable>(V)); break;
Misha Brukman4685e262004-04-28 15:31:21 +00001145 default: *Out << "<unknown value type: " << V->getValueType() << ">"; break;
Chris Lattner7db79582001-11-07 04:21:57 +00001146 }
1147 return *this;
1148}
Misha Brukman4685e262004-04-28 15:31:21 +00001149
1150CachedWriter& CachedWriter::operator<<(const Type *X) {
1151 if (SymbolicTypes) {
1152 const Module *M = AW->getModule();
1153 if (M) WriteTypeSymbolic(*Out, X, M);
1154 return *this;
1155 } else
1156 return *this << (const Value*)X;
1157}
Misha Brukmanda546ea2004-04-28 19:24:28 +00001158
1159void CachedWriter::setStream(std::ostream &os) {
1160 Out = &os;
1161 if (AW) AW->setStream(os);
1162}
Reid Spencere7e96712004-05-25 08:53:40 +00001163
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001164//===----------------------------------------------------------------------===//
1165//===-- SlotMachine Implementation
1166//===----------------------------------------------------------------------===//
1167
1168#if 0
1169#define SC_DEBUG(X) std::cerr << X
1170#else
1171#define SC_DEBUG(X)
1172#endif
1173
1174// Module level constructor. Causes the contents of the Module (sans functions)
1175// to be added to the slot table.
1176SlotMachine::SlotMachine(const Module *M)
Reid Spencer56010e42004-05-26 21:56:09 +00001177 : TheModule(M) ///< Saved for lazy initialization.
1178 , TheFunction(0)
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001179 , mMap()
1180 , fMap()
1181{
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001182}
1183
1184// Function level constructor. Causes the contents of the Module and the one
1185// function provided to be added to the slot table.
1186SlotMachine::SlotMachine(const Function *F )
Reid Spencer56010e42004-05-26 21:56:09 +00001187 : TheModule( F ? F->getParent() : 0 ) ///< Saved for lazy initialization
1188 , TheFunction(F) ///< Saved for lazy initialization
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001189 , mMap()
1190 , fMap()
1191{
Reid Spencer56010e42004-05-26 21:56:09 +00001192}
1193
1194inline void SlotMachine::initialize(void) {
1195 if ( TheModule) {
1196 processModule();
1197 TheModule = 0; ///< Prevent re-processing next time we're called.
1198 }
1199 if ( TheFunction ) {
1200 processFunction();
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001201 }
1202}
1203
1204// Iterate through all the global variables, functions, and global
1205// variable initializers and create slots for them.
1206void SlotMachine::processModule() {
1207 SC_DEBUG("begin processModule!\n");
1208
1209 // Add all of the global variables to the value table...
1210 for (Module::const_giterator I = TheModule->gbegin(), E = TheModule->gend();
1211 I != E; ++I)
1212 createSlot(I);
1213
1214 // Add all the functions to the table
1215 for (Module::const_iterator I = TheModule->begin(), E = TheModule->end();
1216 I != E; ++I)
1217 createSlot(I);
1218
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001219 SC_DEBUG("end processModule!\n");
1220}
1221
1222
Reid Spencer56010e42004-05-26 21:56:09 +00001223// Process the arguments, basic blocks, and instructions of a function.
1224void SlotMachine::processFunction() {
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001225 SC_DEBUG("begin processFunction!\n");
1226
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001227 // Add all the function arguments
Reid Spencer56010e42004-05-26 21:56:09 +00001228 for(Function::const_aiterator AI = TheFunction->abegin(),
1229 AE = TheFunction->aend(); AI != AE; ++AI)
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001230 createSlot(AI);
1231
1232 SC_DEBUG("Inserting Instructions:\n");
1233
1234 // Add all of the basic blocks and instructions
Reid Spencer56010e42004-05-26 21:56:09 +00001235 for (Function::const_iterator BB = TheFunction->begin(),
1236 E = TheFunction->end(); BB != E; ++BB) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001237 createSlot(BB);
1238 for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I!=E; ++I) {
1239 createSlot(I);
1240 }
1241 }
1242
1243 SC_DEBUG("end processFunction!\n");
1244}
1245
1246// Clean up after incorporating a function. This is the only way
Reid Spencer56010e42004-05-26 21:56:09 +00001247// to get out of the function incorporation state that affects the
1248// getSlot/createSlot lock. Function incorporation state is indicated
1249// by TheFunction != 0.
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001250void SlotMachine::purgeFunction() {
1251 SC_DEBUG("begin purgeFunction!\n");
1252 fMap.clear(); // Simply discard the function level map
Reid Spencer56010e42004-05-26 21:56:09 +00001253 TheFunction = 0;
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001254 SC_DEBUG("end purgeFunction!\n");
1255}
1256
1257/// Get the slot number for a value. This function will assert if you
1258/// ask for a Value that hasn't previously been inserted with createSlot.
1259/// Types are forbidden because Type does not inherit from Value (any more).
Reid Spencer56010e42004-05-26 21:56:09 +00001260unsigned SlotMachine::getSlot(const Value *V) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001261 assert( V && "Can't get slot for null Value" );
1262 assert( !isa<Type>(V) && "Can't get slot for a type" );
Reid Spencer56010e42004-05-26 21:56:09 +00001263 assert(!isa<Constant>(V) || isa<GlobalValue>(V) &&
1264 "Can't insert a non-GlobalValue Constant into SlotMachine");
1265
1266 // Check for uninitialized state and do lazy initialization
1267 this->initialize();
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001268
1269 // Do not number CPR's at all. They are an abomination
1270 if ( const ConstantPointerRef* CPR = dyn_cast<ConstantPointerRef>(V) )
1271 V = CPR->getValue() ;
1272
1273 // Get the type of the value
1274 const Type* VTy = V->getType();
1275
1276 // Find the type plane in the module map
1277 TypedPlanes::const_iterator MI = mMap.find(VTy);
1278
Reid Spencer56010e42004-05-26 21:56:09 +00001279 if ( TheFunction ) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001280 // Lookup the type in the function map too
1281 TypedPlanes::const_iterator FI = fMap.find(VTy);
1282 // If there is a corresponding type plane in the function map
1283 if ( FI != fMap.end() ) {
1284 // Lookup the Value in the function map
1285 ValueMap::const_iterator FVI = FI->second.map.find(V);
1286 // If the value doesn't exist in the function map
1287 if ( FVI == FI->second.map.end() ) {
Reid Spencer56010e42004-05-26 21:56:09 +00001288 // Look up the value in the module map
1289 ValueMap::const_iterator MVI = MI->second.map.find(V);
1290 // If we didn't find it, it wasn't inserted
1291 assert( MVI != MI->second.map.end() && "Value not found");
1292 // We found it only at the module level
1293 return MVI->second;
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001294
1295 // else the value exists in the function map
1296 } else {
Reid Spencer56010e42004-05-26 21:56:09 +00001297 // Return the slot number as the module's contribution to
1298 // the type plane plus the index in the function's contribution
1299 // to the type plane.
1300 return MI->second.next_slot + FVI->second;
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001301 }
1302
1303 // else there is not a corresponding type plane in the function map
1304 } else {
1305 assert( MI != mMap.end() && "No such type plane!" );
1306 // Look up the value in the module's map
1307 ValueMap::const_iterator MVI = MI->second.map.find(V);
1308 // If we didn't find it, it wasn't inserted.
1309 assert( MVI != MI->second.map.end() && "Value not found");
1310 // We found it only in the module level and function level
1311 // didn't even have a type plane.
1312 return MVI->second;
1313 }
1314 }
1315
Reid Spencer56010e42004-05-26 21:56:09 +00001316 // N.B. Can only get here if !TheFunction
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001317
1318 // Make sure the type plane exists
1319 assert( MI != mMap.end() && "No such type plane!" );
1320 // Lookup the value in the module's map
1321 ValueMap::const_iterator MVI = MI->second.map.find(V);
1322 // Make sure we found it.
1323 assert( MVI != MI->second.map.end() && "Value not found" );
1324 // Return it.
1325 return MVI->second;
1326}
1327
1328
1329// Create a new slot, or return the existing slot if it is already
1330// inserted. Note that the logic here parallels getSlot but instead
1331// of asserting when the Value* isn't found, it inserts the value.
1332unsigned SlotMachine::createSlot(const Value *V) {
1333 assert( V && "Can't insert a null Value to SlotMachine");
1334 assert( !isa<Type>(V) && "Can't insert a Type into SlotMachine");
Reid Spencer56010e42004-05-26 21:56:09 +00001335 assert(!isa<Constant>(V) || isa<GlobalValue>(V) &&
1336 "Can't insert a non-GlobalValue Constant into SlotMachine");
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001337
1338 const Type* VTy = V->getType();
1339
1340 // Just ignore void typed things
1341 if (VTy == Type::VoidTy) return 0; // FIXME: Wrong return value!
1342
1343 // Look up the type plane for the Value's type from the module map
1344 TypedPlanes::const_iterator MI = mMap.find(VTy);
1345
Reid Spencer56010e42004-05-26 21:56:09 +00001346 if ( TheFunction ) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001347 // Get the type plane for the Value's type from the function map
1348 TypedPlanes::const_iterator FI = fMap.find(VTy);
1349 // If there is a corresponding type plane in the function map
1350 if ( FI != fMap.end() ) {
1351 // Lookup the Value in the function map
1352 ValueMap::const_iterator FVI = FI->second.map.find(V);
1353 // If the value doesn't exist in the function map
1354 if ( FVI == FI->second.map.end() ) {
Reid Spencer56010e42004-05-26 21:56:09 +00001355 // If there is no corresponding type plane in the module map
1356 if ( MI == mMap.end() )
1357 return insertValue(V);
1358 // Look up the value in the module map
1359 ValueMap::const_iterator MVI = MI->second.map.find(V);
1360 // If we didn't find it, it wasn't inserted
1361 if ( MVI == MI->second.map.end() )
1362 return insertValue(V);
1363 else
1364 // We found it only at the module level
1365 return MVI->second;
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001366
1367 // else the value exists in the function map
1368 } else {
Reid Spencer56010e42004-05-26 21:56:09 +00001369 if ( MI == mMap.end() )
1370 return FVI->second;
1371 else
1372 // Return the slot number as the module's contribution to
1373 // the type plane plus the index in the function's contribution
1374 // to the type plane.
1375 return MI->second.next_slot + FVI->second;
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001376 }
1377
1378 // else there is not a corresponding type plane in the function map
1379 } else {
1380 // If the type plane doesn't exists at the module level
1381 if ( MI == mMap.end() ) {
Reid Spencer56010e42004-05-26 21:56:09 +00001382 return insertValue(V);
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001383 // else type plane exists at the module level, examine it
1384 } else {
Reid Spencer56010e42004-05-26 21:56:09 +00001385 // Look up the value in the module's map
1386 ValueMap::const_iterator MVI = MI->second.map.find(V);
1387 // If we didn't find it there either
1388 if ( MVI == MI->second.map.end() )
1389 // Return the slot number as the module's contribution to
1390 // the type plane plus the index of the function map insertion.
1391 return MI->second.next_slot + insertValue(V);
1392 else
1393 return MVI->second;
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001394 }
1395 }
1396 }
1397
Reid Spencer56010e42004-05-26 21:56:09 +00001398 // N.B. Can only get here if !TheFunction
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001399
1400 // If the module map's type plane is not for the Value's type
1401 if ( MI != mMap.end() ) {
1402 // Lookup the value in the module's map
1403 ValueMap::const_iterator MVI = MI->second.map.find(V);
1404 if ( MVI != MI->second.map.end() )
1405 return MVI->second;
1406 }
1407
1408 return insertValue(V);
1409}
1410
1411
1412// Low level insert function. Minimal checking is done. This
1413// function is just for the convenience of createSlot (above).
1414unsigned SlotMachine::insertValue(const Value *V ) {
1415 assert(V && "Can't insert a null Value into SlotMachine!");
1416 assert(!isa<Type>(V) && "Can't insert a Type into SlotMachine!");
Reid Spencer56010e42004-05-26 21:56:09 +00001417 assert(!isa<Constant>(V) || isa<GlobalValue>(V) &&
1418 "Can't insert a non-GlobalValue Constant into SlotMachine");
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001419
Reid Spencer56010e42004-05-26 21:56:09 +00001420 // If this value does not contribute to a plane (is void)
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001421 // or if the value already has a name then ignore it.
Reid Spencer56010e42004-05-26 21:56:09 +00001422 if (V->getType() == Type::VoidTy || V->hasName() ) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001423 SC_DEBUG("ignored value " << *V << "\n");
1424 return 0; // FIXME: Wrong return value
1425 }
1426
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001427 const Type *VTy = V->getType();
1428 unsigned DestSlot = 0;
1429
Reid Spencer56010e42004-05-26 21:56:09 +00001430 if ( TheFunction ) {
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001431 TypedPlanes::iterator I = fMap.find( VTy );
1432 if ( I == fMap.end() )
1433 I = fMap.insert(std::make_pair(VTy,Plane())).first;
1434 DestSlot = I->second.map[V] = I->second.next_slot++;
1435 } else {
1436 TypedPlanes::iterator I = mMap.find( VTy );
1437 if ( I == mMap.end() )
1438 I = mMap.insert(std::make_pair(VTy,Plane())).first;
1439 DestSlot = I->second.map[V] = I->second.next_slot++;
1440 }
1441
1442 SC_DEBUG(" Inserting value [" << VTy << "] = " << V << " slot=" <<
Reid Spencer56010e42004-05-26 21:56:09 +00001443 DestSlot << " [");
Reid Spencer16f2f7f2004-05-26 07:18:52 +00001444 // G = Global, C = Constant, T = Type, F = Function, o = other
1445 SC_DEBUG((isa<GlobalVariable>(V) ? "G" : (isa<Constant>(V) ? "C" :
1446 (isa<Function>(V) ? "F" : "o"))));
1447 SC_DEBUG("]\n");
1448 return DestSlot;
1449}
1450
Reid Spencere7e96712004-05-25 08:53:40 +00001451// vim: sw=2