Make the release build work
[oota-llvm.git] / lib / VMCore / AsmWriter.cpp
index dcf8cf3f35c1e969d675797203a205ee96d8ddf4..f92fac512add6add91757b7041bce2ff85d6a5b4 100644 (file)
@@ -13,7 +13,7 @@
 #include "llvm/Assembly/CachedWriter.h"
 #include "llvm/Analysis/SlotCalculator.h"
 #include "llvm/Module.h"
-#include "llvm/Method.h"
+#include "llvm/Function.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/ConstantVals.h"
 #include "Support/STLExtras.h"
 #include <algorithm>
 #include <map>
+using std::string;
+using std::map;
+using std::vector;
+using std::ostream;
 
 static const Module *getModuleFromVal(const Value *V) {
-  if (const MethodArgument *MA =dyn_cast<const MethodArgument>(V))
+  if (const FunctionArgument *MA = dyn_cast<const FunctionArgument>(V))
     return MA->getParent() ? MA->getParent()->getParent() : 0;
   else if (const BasicBlock *BB = dyn_cast<const BasicBlock>(V))
     return BB->getParent() ? BB->getParent()->getParent() : 0;
   else if (const Instruction *I = dyn_cast<const Instruction>(V)) {
-    const Method *M = I->getParent() ? I->getParent()->getParent() : 0;
+    const Function *M = I->getParent() ? I->getParent()->getParent() : 0;
     return M ? M->getParent() : 0;
-  } else if (const GlobalValue *GV =dyn_cast<const GlobalValue>(V))
+  } else if (const GlobalValue *GV = dyn_cast<const GlobalValue>(V))
     return GV->getParent();
   else if (const Module *Mod  = dyn_cast<const Module>(V))
     return Mod;
@@ -44,16 +48,16 @@ static const Module *getModuleFromVal(const Value *V) {
 
 static SlotCalculator *createSlotCalculator(const Value *V) {
   assert(!isa<Type>(V) && "Can't create an SC for a type!");
-  if (const MethodArgument *MA =dyn_cast<const MethodArgument>(V)){
-    return new SlotCalculator(MA->getParent(), true);
+  if (const FunctionArgument *FA = dyn_cast<const FunctionArgument>(V)) {
+    return new SlotCalculator(FA->getParent(), true);
   } else if (const Instruction *I = dyn_cast<const Instruction>(V)) {
     return new SlotCalculator(I->getParent()->getParent(), true);
   } else if (const BasicBlock *BB = dyn_cast<const BasicBlock>(V)) {
     return new SlotCalculator(BB->getParent(), true);
-  } else if (const GlobalVariable *GV =dyn_cast<const GlobalVariable>(V)){
+  } else if (const GlobalVariable *GV = dyn_cast<const GlobalVariable>(V)){
     return new SlotCalculator(GV->getParent(), true);
-  } else if (const Method *Meth = dyn_cast<const Method>(V)) {
-    return new SlotCalculator(Meth, true);
+  } else if (const Function *Func = dyn_cast<const Function>(V)) {
+    return new SlotCalculator(Func, true);
   } else if (const Module *Mod  = dyn_cast<const Module>(V)) {
     return new SlotCalculator(Mod, true);
   }
@@ -111,8 +115,8 @@ static void fillTypeNameTable(const Module *M,
         //
         const Type *Ty = cast<const Type>(I->second);
         if (!isa<PointerType>(Ty) ||
-            !cast<PointerType>(Ty)->getValueType()->isPrimitiveType())
-          TypeNames.insert(make_pair(Ty, "%"+I->first));
+            !cast<PointerType>(Ty)->getElementType()->isPrimitiveType())
+          TypeNames.insert(std::make_pair(Ty, "%"+I->first));
       }
     }
   }
@@ -143,10 +147,10 @@ static string calcTypeName(const Type *Ty, vector<const Type *> &TypeStack,
   
   string Result;
   switch (Ty->getPrimitiveID()) {
-  case Type::MethodTyID: {
-    const MethodType *MTy = cast<const MethodType>(Ty);
+  case Type::FunctionTyID: {
+    const FunctionType *MTy = cast<const FunctionType>(Ty);
     Result = calcTypeName(MTy->getReturnType(), TypeStack, TypeNames) + " (";
-    for (MethodType::ParamTypes::const_iterator
+    for (FunctionType::ParamTypes::const_iterator
            I = MTy->getParamTypes().begin(),
            E = MTy->getParamTypes().end(); I != E; ++I) {
       if (I != MTy->getParamTypes().begin())
@@ -174,7 +178,7 @@ static string calcTypeName(const Type *Ty, vector<const Type *> &TypeStack,
     break;
   }
   case Type::PointerTyID:
-    Result = calcTypeName(cast<const PointerType>(Ty)->getValueType(), 
+    Result = calcTypeName(cast<const PointerType>(Ty)->getElementType(), 
                           TypeStack, TypeNames) + " *";
     break;
   case Type::ArrayTyID: {
@@ -215,7 +219,7 @@ static ostream &printTypeInt(ostream &Out, const Type *Ty,
   //
   vector<const Type *> TypeStack;
   string TypeName = calcTypeName(Ty, TypeStack, TypeNames);
-  TypeNames.insert(make_pair(Ty, TypeName));   // Cache type name for later use
+  TypeNames.insert(std::make_pair(Ty, TypeName));//Cache type name for later use
   return Out << TypeName;
 }
 
@@ -272,7 +276,7 @@ public:
 
   inline void write(const Module *M)         { printModule(M);      }
   inline void write(const GlobalVariable *G) { printGlobal(G);      }
-  inline void write(const Method *M)         { printMethod(M);      }
+  inline void write(const Function *F)       { printFunction(F);    }
   inline void write(const BasicBlock *BB)    { printBasicBlock(BB); }
   inline void write(const Instruction *I)    { printInstruction(I); }
   inline void write(const Constant *CPV)     { printConstant(CPV);  }
@@ -283,8 +287,8 @@ private :
   void printSymbolTable(const SymbolTable &ST);
   void printConstant(const Constant *CPV);
   void printGlobal(const GlobalVariable *GV);
-  void printMethod(const Method *M);
-  void printMethodArgument(const MethodArgument *MA);
+  void printFunction(const Function *F);
+  void printFunctionArgument(const FunctionArgument *FA);
   void printBasicBlock(const BasicBlock *BB);
   void printInstruction(const Instruction *I);
   ostream &printType(const Type *Ty);
@@ -315,7 +319,7 @@ void AssemblyWriter::printModule(const Module *M) {
   Out << "implementation\n";
   
   // Output all of the methods...
-  for_each(M->begin(), M->end(), bind_obj(this,&AssemblyWriter::printMethod));
+  for_each(M->begin(), M->end(), bind_obj(this,&AssemblyWriter::printFunction));
 }
 
 void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
@@ -325,13 +329,13 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
   if (!GV->hasInitializer()) Out << "uninitialized ";
 
   Out << (GV->isConstant() ? "constant " : "global ");
-  printType(GV->getType()->getValueType());
+  printType(GV->getType()->getElementType());
 
   if (GV->hasInitializer())
     writeOperand(GV->getInitializer(), false, false);
 
   printInfoComment(GV);
-  Out << endl;
+  Out << "\n";
 }
 
 
@@ -348,7 +352,7 @@ void AssemblyWriter::printSymbolTable(const SymbolTable &ST) {
       if (const Constant *CPV = dyn_cast<const Constant>(V)) {
        printConstant(CPV);
       } else if (const Type *Ty = dyn_cast<const Type>(V)) {
-       Out << "\t%" << I->first << " = type " << Ty->getDescription() << endl;
+       Out << "\t%" << I->first << " = type " << Ty->getDescription() << "\n";
       }
     }
   }
@@ -378,12 +382,12 @@ void AssemblyWriter::printConstant(const Constant *CPV) {
     else Out << "<badref>";
   } 
 
-  Out << endl;
+  Out << "\n";
 }
 
-// printMethod - Print all aspects of a method.
+// printFunction - Print all aspects of a method.
 //
-void AssemblyWriter::printMethod(const Method *M) {
+void AssemblyWriter::printFunction(const Function *M) {
   // Print out the return type and name...
   Out << "\n" << (M->isExternal() ? "declare " : "")
       << (M->hasInternalLinkage() ? "internal " : "");
@@ -391,15 +395,15 @@ void AssemblyWriter::printMethod(const Method *M) {
   Table.incorporateMethod(M);
 
   // Loop over the arguments, printing them...
-  const MethodType *MT = cast<const MethodType>(M->getMethodType());
+  const FunctionType *MT = M->getFunctionType();
 
   if (!M->isExternal()) {
     for_each(M->getArgumentList().begin(), M->getArgumentList().end(),
-            bind_obj(this, &AssemblyWriter::printMethodArgument));
+            bind_obj(this, &AssemblyWriter::printFunctionArgument));
   } else {
     // Loop over the arguments, printing them...
-    const MethodType *MT = cast<const MethodType>(M->getMethodType());
-    for (MethodType::ParamTypes::const_iterator I = MT->getParamTypes().begin(),
+    const FunctionType *MT = M->getFunctionType();
+    for (FunctionType::ParamTypes::const_iterator I = MT->getParamTypes().begin(),
           E = MT->getParamTypes().end(); I != E; ++I) {
       if (I != MT->getParamTypes().begin()) Out << ", ";
       printType(*I);
@@ -430,10 +434,10 @@ void AssemblyWriter::printMethod(const Method *M) {
   Table.purgeMethod();
 }
 
-// printMethodArgument - This member is called for every argument that 
+// printFunctionArgument - This member is called for every argument that 
 // is passed into the method.  Simply print it out
 //
-void AssemblyWriter::printMethodArgument(const MethodArgument *Arg) {
+void AssemblyWriter::printFunctionArgument(const FunctionArgument *Arg) {
   // Insert commas as we go... the first arg doesn't get a comma
   if (Arg != Arg->getParent()->getArgumentList().front()) Out << ", ";
 
@@ -481,7 +485,7 @@ void AssemblyWriter::printInfoComment(const Value *V) {
       if (Slot >= 0) Out << ":" << Slot;
       else Out << ":<badref>";
     }
-    Out << "\t[#uses=" << V->use_size() << "]";  // Output # uses
+    Out << " [#uses=" << V->use_size() << "]";  // Output # uses
   }
 }
 
@@ -534,7 +538,7 @@ void AssemblyWriter::printInstruction(const Instruction *I) {
     Out << " void";
   } else if (isa<CallInst>(I)) {
     const PointerType *PTy = dyn_cast<PointerType>(Operand->getType());
-    const MethodType  *MTy = PTy ? dyn_cast<MethodType>(PTy->getValueType()) :0;
+    const FunctionType*MTy = PTy ? dyn_cast<FunctionType>(PTy->getElementType()):0;
     const Type      *RetTy = MTy ? MTy->getReturnType() : 0;
 
     // If possible, print out the short form of the call instruction, but we can
@@ -542,7 +546,7 @@ void AssemblyWriter::printInstruction(const Instruction *I) {
     // and if the value returned is not a pointer to a method.
     //
     if (RetTy && !MTy->isVarArg() &&
-        (!isa<PointerType>(RetTy)||!isa<MethodType>(cast<PointerType>(RetTy)))){
+        (!isa<PointerType>(RetTy)||!isa<FunctionType>(cast<PointerType>(RetTy)))){
       Out << " "; printType(RetTy);
       writeOperand(Operand, false);
     } else {
@@ -574,7 +578,7 @@ void AssemblyWriter::printInstruction(const Instruction *I) {
   } else if (I->getOpcode() == Instruction::Malloc || 
             I->getOpcode() == Instruction::Alloca) {
     Out << " ";
-    printType(cast<const PointerType>(I->getType())->getValueType());
+    printType(cast<const PointerType>(I->getType())->getElementType());
     if (I->getNumOperands()) {
       Out << ",";
       writeOperand(I->getOperand(0), true);
@@ -614,7 +618,7 @@ void AssemblyWriter::printInstruction(const Instruction *I) {
   }
 
   printInfoComment(I);
-  Out << endl;
+  Out << "\n";
 }
 
 
@@ -647,12 +651,12 @@ void WriteToAssembly(const GlobalVariable *G, ostream &o) {
   W.write(G);
 }
 
-void WriteToAssembly(const Method *M, ostream &o) {
-  if (M == 0) { o << "<null> method\n"; return; }
-  SlotCalculator SlotTable(M->getParent(), true);
-  AssemblyWriter W(o, SlotTable, M->getParent());
+void WriteToAssembly(const Function *F, ostream &o) {
+  if (F == 0) { o << "<null> function\n"; return; }
+  SlotCalculator SlotTable(F->getParent(), true);
+  AssemblyWriter W(o, SlotTable, F->getParent());
 
-  W.write(M);
+  W.write(F);
 }
 
 
@@ -674,9 +678,9 @@ void WriteToAssembly(const Constant *CPV, ostream &o) {
 void WriteToAssembly(const Instruction *I, ostream &o) {
   if (I == 0) { o << "<null> instruction\n"; return; }
 
-  const Method *M = I->getParent() ? I->getParent()->getParent() : 0;
-  SlotCalculator SlotTable(M, true);
-  AssemblyWriter W(o, SlotTable, M ? M->getParent() : 0);
+  const Function *F = I->getParent() ? I->getParent()->getParent() : 0;
+  SlotCalculator SlotTable(F, true);
+  AssemblyWriter W(o, SlotTable, F ? F->getParent() : 0);
 
   W.write(I);
 }
@@ -702,12 +706,12 @@ CachedWriter &CachedWriter::operator<<(const Value *V) {
   case Value::ConstantVal:
     Out << " "; AW->write(V->getType());
     Out << " " << cast<Constant>(V)->getStrValue(); break;
-  case Value::MethodArgumentVal: 
+  case Value::FunctionArgumentVal: 
     AW->write(V->getType()); Out << " " << V->getName(); break;
   case Value::TypeVal:           AW->write(cast<const Type>(V)); break;
   case Value::InstructionVal:    AW->write(cast<Instruction>(V)); break;
   case Value::BasicBlockVal:     AW->write(cast<BasicBlock>(V)); break;
-  case Value::MethodVal:         AW->write(cast<Method>(V)); break;
+  case Value::FunctionVal:       AW->write(cast<Function>(V)); break;
   case Value::GlobalVariableVal: AW->write(cast<GlobalVariable>(V)); break;
   case Value::ModuleVal:         AW->write(cast<Module>(V)); break;
   default: Out << "<unknown value type: " << V->getValueType() << ">"; break;