Refactor ABCCompilerDriver to allow target-dependent settings.

Change-Id: Ie46a8838c0b911d5dedf82bc09616dcd728c663d
diff --git a/lib/AndroidBitcode/ABCCompilerDriver.cpp b/lib/AndroidBitcode/ABCCompilerDriver.cpp
index 84b6583..59d6dda 100644
--- a/lib/AndroidBitcode/ABCCompilerDriver.cpp
+++ b/lib/AndroidBitcode/ABCCompilerDriver.cpp
@@ -20,6 +20,10 @@
 #include <llvm/Support/MemoryBuffer.h>
 #include <llvm/Support/raw_ostream.h>
 
+#include "ARMABCCompilerDriver.h"
+#include "MipsABCCompilerDriver.h"
+#include "X86ABCCompilerDriver.h"
+
 #include "bcc/Config/Config.h"
 #include "bcc/Script.h"
 #include "bcc/Source.h"
@@ -34,11 +38,10 @@
 
 namespace bcc {
 
-ABCCompilerDriver::ABCCompilerDriver(const std::string &pTriple,
-                                     const std::string &pAndroidSysroot)
+ABCCompilerDriver::ABCCompilerDriver(const std::string &pTriple)
   : mContext(), mCompiler(), mLinker(),
     mCompilerConfig(NULL), mLinkerConfig(NULL),
-    mTriple(pTriple), mAndroidSysroot(pAndroidSysroot) {
+    mTriple(pTriple), mAndroidSysroot("/") {
 }
 
 ABCCompilerDriver::~ABCCompilerDriver() {
@@ -211,6 +214,38 @@
 
 //------------------------------------------------------------------------------
 
+ABCCompilerDriver *ABCCompilerDriver::Create(const std::string &pTriple) {
+  std::string error;
+  const llvm::Target *target =
+      llvm::TargetRegistry::lookupTarget(pTriple, error);
+
+  if (target == NULL) {
+    ALOGE("Unsupported target '%s' (detail: %s)!", pTriple.c_str(),
+          error.c_str());
+    return NULL;
+  }
+
+  switch (llvm::Triple::getArchTypeForLLVMName(target->getName())) {
+    case llvm::Triple::arm:
+    case llvm::Triple::thumb: {
+      return new ARMABCCompilerDriver(pTriple);
+    }
+    case llvm::Triple::mipsel: {
+      return new MipsABCCompilerDriver(pTriple);
+    }
+    case llvm::Triple::x86: {
+      return new X86ABCCompilerDriver(pTriple);
+    }
+    default: {
+      ALOGE("Unknown architecture '%s' supplied in %s!", target->getName(),
+            pTriple.c_str());
+      break;
+    }
+  }
+
+  return NULL;
+}
+
 bool ABCCompilerDriver::build(int pInputFd, int pOutputFd) {
   //===--------------------------------------------------------------------===//
   // Prepare the input.
diff --git a/lib/AndroidBitcode/ARMABCCompilerDriver.h b/lib/AndroidBitcode/ARMABCCompilerDriver.h
new file mode 100644
index 0000000..ff1c91e
--- /dev/null
+++ b/lib/AndroidBitcode/ARMABCCompilerDriver.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_ARM_ABC_COMPILER_DRIVER_H
+#define BCC_ARM_ABC_COMPILER_DRIVER_H
+
+#include "bcc/AndroidBitcode/ABCCompilerDriver.h"
+
+namespace bcc {
+
+class ARMABCCompilerDriver : public ABCCompilerDriver {
+public:
+  ARMABCCompilerDriver(const std::string &pTriple)
+      : ABCCompilerDriver(pTriple) { }
+
+  virtual ~ARMABCCompilerDriver() { }
+};
+
+} // end namespace bcc
+
+#endif // BCC_ARM_ABC_COMPILER_DRIVER_H
diff --git a/lib/AndroidBitcode/MipsABCCompilerDriver.h b/lib/AndroidBitcode/MipsABCCompilerDriver.h
new file mode 100644
index 0000000..dea58ea
--- /dev/null
+++ b/lib/AndroidBitcode/MipsABCCompilerDriver.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_MIPS_ABC_COMPILER_DRIVER_H
+#define BCC_MIPS_ABC_COMPILER_DRIVER_H
+
+#include "bcc/AndroidBitcode/ABCCompilerDriver.h"
+
+namespace bcc {
+
+class MipsABCCompilerDriver : public ABCCompilerDriver {
+public:
+  MipsABCCompilerDriver(const std::string &pTriple)
+      : ABCCompilerDriver(pTriple) { }
+
+  virtual ~MipsABCCompilerDriver() { }
+};
+
+} // end namespace bcc
+
+#endif // BCC_MIPS_ABC_COMPILER_DRIVER_H
diff --git a/lib/AndroidBitcode/X86ABCCompilerDriver.h b/lib/AndroidBitcode/X86ABCCompilerDriver.h
new file mode 100644
index 0000000..4d76b5f
--- /dev/null
+++ b/lib/AndroidBitcode/X86ABCCompilerDriver.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_X86_ABC_COMPILER_DRIVER_H
+#define BCC_X86_ABC_COMPILER_DRIVER_H
+
+#include "bcc/AndroidBitcode/ABCCompilerDriver.h"
+
+namespace bcc {
+
+class X86ABCCompilerDriver : public ABCCompilerDriver {
+public:
+  X86ABCCompilerDriver(const std::string &pTriple)
+      : ABCCompilerDriver(pTriple) { }
+
+  virtual ~X86ABCCompilerDriver() { }
+};
+
+} // end namespace bcc
+
+#endif // BCC_X86_ABC_COMPILER_DRIVER_H