If compile unit's language is not set then don't crash while dump'ing compile unit.
[oota-llvm.git] / lib / Target / CppBackend / CPPBackend.cpp
index 351c3394f4c8dc0f2e3cf8b86f7449142852fcff..dbe4f2d2d3010d946d08ba102ce5b2906328051a 100644 (file)
@@ -71,6 +71,14 @@ static cl::opt<std::string> NameToGenerate("cppfor", cl::Optional,
   cl::desc("Specify the name of the thing to generate"),
   cl::init("!bad!"));
 
+/// CppBackendTargetMachineModule - Note that this is used on hosts
+/// that cannot link in a library unless there are references into the
+/// library.  In particular, it seems that it is not possible to get
+/// things to work on Win32 without this.  Though it is unused, do not
+/// remove it.
+extern "C" int CppBackendTargetMachineModule;
+int CppBackendTargetMachineModule = 0;
+
 // Register the target.
 static RegisterTarget<CPPTargetMachine> X("cpp", "C++ backend");
 
@@ -284,6 +292,8 @@ namespace {
     switch (LT) {
     case GlobalValue::InternalLinkage:
       Out << "GlobalValue::InternalLinkage"; break;
+    case GlobalValue::PrivateLinkage:
+      Out << "GlobalValue::PrivateLinkage"; break;
     case GlobalValue::LinkOnceLinkage:
       Out << "GlobalValue::LinkOnceLinkage "; break;
     case GlobalValue::WeakLinkage:
@@ -439,31 +449,28 @@ namespace {
       Out << "SmallVector<AttributeWithIndex, 4> Attrs;"; nl(Out);
       Out << "AttributeWithIndex PAWI;"; nl(Out);
       for (unsigned i = 0; i < PAL.getNumSlots(); ++i) {
-        uint16_t index = PAL.getSlot(i).Index;
+        unsigned index = PAL.getSlot(i).Index;
         Attributes attrs = PAL.getSlot(i).Attrs;
-        Out << "PAWI.Index = " << index << "; PAWI.Attrs = 0 ";
-        if (attrs & Attribute::SExt)
-          Out << " | Attribute::SExt";
-        if (attrs & Attribute::ZExt)
-          Out << " | Attribute::ZExt";
-        if (attrs & Attribute::StructRet)
-          Out << " | Attribute::StructRet";
-        if (attrs & Attribute::InReg)
-          Out << " | Attribute::InReg";
-        if (attrs & Attribute::NoReturn)
-          Out << " | Attribute::NoReturn";
-        if (attrs & Attribute::NoUnwind)
-          Out << " | Attribute::NoUnwind";
-        if (attrs & Attribute::ByVal)
-          Out << " | Attribute::ByVal";
-        if (attrs & Attribute::NoAlias)
-          Out << " | Attribute::NoAlias";
-        if (attrs & Attribute::Nest)
-          Out << " | Attribute::Nest";
-        if (attrs & Attribute::ReadNone)
-          Out << " | Attribute::ReadNone";
-        if (attrs & Attribute::ReadOnly)
-          Out << " | Attribute::ReadOnly";
+        Out << "PAWI.Index = " << index << "U; PAWI.Attrs = 0 ";
+#define HANDLE_ATTR(X)                 \
+        if (attrs & Attribute::X)      \
+          Out << " | Attribute::" #X;  \
+        attrs &= ~Attribute::X;
+        
+        HANDLE_ATTR(SExt);
+        HANDLE_ATTR(ZExt);
+        HANDLE_ATTR(StructRet);
+        HANDLE_ATTR(InReg);
+        HANDLE_ATTR(NoReturn);
+        HANDLE_ATTR(NoUnwind);
+        HANDLE_ATTR(ByVal);
+        HANDLE_ATTR(NoAlias);
+        HANDLE_ATTR(Nest);
+        HANDLE_ATTR(ReadNone);
+        HANDLE_ATTR(ReadOnly);
+        HANDLE_ATTR(NoCapture);
+#undef HANDLE_ATTR
+        assert(attrs == 0 && "Unhandled attribute!");
         Out << ";";
         nl(Out);
         Out << "Attrs.push_back(PAWI);";
@@ -1269,7 +1276,7 @@ namespace {
     }
     case Instruction::Store: {
       const StoreInst* store = cast<StoreInst>(I);
-      Out << " new StoreInst("
+      Out << " new StoreInst("
           << opNames[0] << ", "
           << opNames[1] << ", "
           << (store->isVolatile() ? "true" : "false")
@@ -1779,22 +1786,22 @@ namespace {
     Out << "#include <llvm/Instructions.h>\n";
     Out << "#include <llvm/InlineAsm.h>\n";
     Out << "#include <llvm/Support/MathExtras.h>\n";
+    Out << "#include <llvm/Support/raw_ostream.h>\n";
     Out << "#include <llvm/Pass.h>\n";
     Out << "#include <llvm/PassManager.h>\n";
     Out << "#include <llvm/ADT/SmallVector.h>\n";
     Out << "#include <llvm/Analysis/Verifier.h>\n";
     Out << "#include <llvm/Assembly/PrintModulePass.h>\n";
     Out << "#include <algorithm>\n";
-    Out << "#include <iostream>\n\n";
     Out << "using namespace llvm;\n\n";
     Out << "Module* " << fname << "();\n\n";
     Out << "int main(int argc, char**argv) {\n";
     Out << "  Module* Mod = " << fname << "();\n";
     Out << "  verifyModule(*Mod, PrintMessageAction);\n";
-    Out << "  std::cerr.flush();\n";
-    Out << "  std::cout.flush();\n";
+    Out << "  errs().flush();\n";
+    Out << "  outs().flush();\n";
     Out << "  PassManager PM;\n";
-    Out << "  PM.add(new PrintModulePass(&llvm::cout));\n";
+    Out << "  PM.add(createPrintModulePass(&outs()));\n";
     Out << "  PM.run(*Mod);\n";
     Out << "  return 0;\n";
     Out << "}\n\n";