Don't try to set an EFLAGS operand to dead if no instruction was created.
[oota-llvm.git] / lib / Target / CppBackend / CPPBackend.cpp
index 21e6735b3298032d35ad8b01f8b44bea7abd0f3d..dbe4f2d2d3010d946d08ba102ce5b2906328051a 100644 (file)
@@ -71,8 +71,16 @@ 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");
+static RegisterTarget<CPPTargetMachine> X("cpp", "C++ backend");
 
 namespace {
   typedef std::vector<const Type*> TypeList;
@@ -218,9 +226,10 @@ namespace {
   // This makes sure that conversion to/from floating yields the same binary
   // result so that we don't lose precision.
   void CppWriter::printCFP(const ConstantFP *CFP) {
+    bool ignored;
     APFloat APF = APFloat(CFP->getValueAPF());  // copy
     if (CFP->getType() == Type::FloatTy)
-      APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven);
+      APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &ignored);
     Out << "ConstantFP::get(";
     Out << "APFloat(";
 #if HAVE_PRINTF_A
@@ -283,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:
@@ -438,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);";
@@ -1268,7 +1276,7 @@ namespace {
     }
     case Instruction::Store: {
       const StoreInst* store = cast<StoreInst>(I);
-      Out << "StoreInst* " << iName << " = new StoreInst("
+      Out << " new StoreInst("
           << opNames[0] << ", "
           << opNames[1] << ", "
           << (store->isVolatile() ? "true" : "false")
@@ -1778,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";