Rename some GC classes so that their roll will hopefully be clearer.
[oota-llvm.git] / lib / Target / CppBackend / CPPBackend.cpp
index a16b720c50b9d4870f8d0d9a498553d8b67cb774..b359659bcdf714092d263fe0942a1a37a30a2b73 100644 (file)
@@ -28,9 +28,9 @@
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/Streams.h"
 #include "llvm/Config/config.h"
 #include <algorithm>
-#include <iostream>
 #include <set>
 
 using namespace llvm;
@@ -209,7 +209,7 @@ namespace {
   }
 
   void CppWriter::error(const std::string& msg) {
-    std::cerr << progname << ": " << msg << "\n";
+    cerr << progname << ": " << msg << "\n";
     exit(2);
   }
 
@@ -221,10 +221,6 @@ namespace {
     if (CFP->getType() == Type::FloatTy)
       APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven);
     Out << "ConstantFP::get(";
-    if (CFP->getType() == Type::DoubleTy)
-      Out << "Type::DoubleTy, ";
-    else
-      Out << "Type::FloatTy, ";
     Out << "APFloat(";
 #if HAVE_PRINTF_A
     char Buffer[100];
@@ -737,8 +733,8 @@ namespace {
     }
     if (const ConstantInt *CI = dyn_cast<ConstantInt>(CV)) {
       Out << "ConstantInt* " << constName << " = ConstantInt::get(APInt("
-          << cast<IntegerType>(CI->getType())->getBitWidth() << ", "
-          << " \"" << CI->getValue().toStringSigned(10)  << "\", 10));";
+          << cast<IntegerType>(CI->getType())->getBitWidth() << ",  \""
+          << CI->getValue() << "\", 10));";
     } else if (isa<ConstantAggregateZero>(CV)) {
       Out << "ConstantAggregateZero* " << constName
           << " = ConstantAggregateZero::get(" << typeName << ");";
@@ -1069,6 +1065,10 @@ namespace {
     }
 
     switch (I->getOpcode()) {
+    default:
+      error("Invalid instruction");
+      break;
+
     case Instruction::Ret: {
       const ReturnInst* ret =  cast<ReturnInst>(I);
       Out << "ReturnInst::Create("
@@ -1442,6 +1442,40 @@ namespace {
       Out << "\", " << bbname << ");";
       break;
     }
+    case Instruction::ExtractValue: {
+      const ExtractValueInst *evi = cast<ExtractValueInst>(I);
+      Out << "std::vector<unsigned> " << iName << "_indices;";
+      nl(Out);
+      for (unsigned i = 0; i < evi->getNumIndices(); ++i) {
+        Out << iName << "_indices.push_back("
+            << evi->idx_begin()[i] << ");";
+        nl(Out);
+      }
+      Out << "ExtractValueInst* " << getCppName(evi)
+          << " = ExtractValueInst::Create(" << opNames[0]
+          << ", "
+          << iName << "_indices.begin(), " << iName << "_indices.end(), \"";
+      printEscapedString(evi->getName());
+      Out << "\", " << bbname << ");";
+      break;
+    }
+    case Instruction::InsertValue: {
+      const InsertValueInst *ivi = cast<InsertValueInst>(I);
+      Out << "std::vector<unsigned> " << iName << "_indices;";
+      nl(Out);
+      for (unsigned i = 0; i < ivi->getNumIndices(); ++i) {
+        Out << iName << "_indices.push_back("
+            << ivi->idx_begin()[i] << ");";
+        nl(Out);
+      }
+      Out << "InsertValueInst* " << getCppName(ivi)
+          << " = InsertValueInst::Create(" << opNames[0]
+          << ", " << opNames[1] << ", "
+          << iName << "_indices.begin(), " << iName << "_indices.end(), \"";
+      printEscapedString(ivi->getName());
+      Out << "\", " << bbname << ");";
+      break;
+    }
   }
   DefinedValues.insert(I);
   nl(Out);
@@ -1569,9 +1603,9 @@ namespace {
       Out << ");";
       nl(Out);
     }
-    if (F->hasCollector()) {
+    if (F->hasGC()) {
       printCppName(F);
-      Out << "->setCollector(\"" << F->getCollector() << "\");";
+      Out << "->setGC(\"" << F->getGC() << "\");";
       nl(Out);
     }
     if (is_inline) {