#ifndef CLANG_DRIVER_HOSTINFO_H_
#define CLANG_DRIVER_HOSTINFO_H_
+#include "clang/Driver/Types.h"
#include <string>
namespace clang {
/// driver for this host and support -arch, -Xarch, etc.
virtual bool useDriverDriver() const = 0;
+ /// lookupTypeForExtension - Return the default language type to use
+ /// for the given extension.
+ virtual types::ID lookupTypeForExtension(const char *Ext) const = 0;
+
/// getToolChain - Construct the toolchain to use for this host.
///
/// \param Args - The argument list, which may be used to alter the
Ty = types::TY_C;
} else {
// Otherwise lookup by extension, and fallback to ObjectType
- // if not found.
+ // if not found. We use a host hook here because Darwin at
+ // least has its own idea of what .s is.
if (const char *Ext = strrchr(Value, '.'))
- Ty = types::lookupTypeForExtension(Ext + 1);
+ Ty = Host->lookupTypeForExtension(Ext + 1);
+
if (Ty == types::TY_INVALID)
Ty = types::TY_Object;
}
virtual bool useDriverDriver() const;
+ virtual types::ID lookupTypeForExtension(const char *Ext) const {
+ types::ID Ty = types::lookupTypeForExtension(Ext);
+
+ // Darwin always preprocesses assembly files (unless -x is used
+ // explicitly).
+ if (Ty == types::TY_PP_Asm)
+ return types::TY_Asm;
+
+ return Ty;
+ }
+
virtual ToolChain *getToolChain(const ArgList &Args,
const char *ArchName) const;
};
virtual bool useDriverDriver() const;
+ virtual types::ID lookupTypeForExtension(const char *Ext) const {
+ return types::lookupTypeForExtension(Ext);
+ }
+
virtual ToolChain *getToolChain(const ArgList &Args,
const char *ArchName) const;
};
// RUN: grep -F '1: preprocessor, {0}, c-header-cpp-output' %t &&
// RUN: grep -F '2: precompiler, {1}, precompiled-header' %t &&
+// Darwin overrides the handling for .s
+// RUN: touch %t.s &&
+// RUN: clang-driver -ccc-host-triple i386-unknown-unknown -ccc-print-phases -c %t.s &> %t &&
+// RUN: grep '0: input, ".*\.s", assembler' %t &&
+// RUN: grep -F '1: assembler, {0}, object' %t &&
+// RUN: clang-driver -ccc-host-triple i386-apple-darwin9 -ccc-print-phases -c %t.s &> %t &&
+// RUN: grep '0: input, ".*\.s", assembler-with-cpp' %t &&
+// RUN: grep -F '1: preprocessor, {0}, assembler' %t &&
+// RUN: grep -F '2: assembler, {1}, object' %t &&
+
// RUN: true
else:
raise Arguments.InvalidArgumentsError("-E or -x required when input is from standard input")
elif ext and ext in Types.kTypeSuffixMap:
- klass = Types.kTypeSuffixMap[ext]
+ klass = self.hostInfo.lookupTypeForExtension(ext)
else:
# FIXME: Its not clear why we shouldn't just
# revert to unknown. I think this is more likely a
import ToolChain
+import Types
class HostInfo(object):
"""HostInfo - Config information about a particular host which may
def useDriverDriver(self):
abstract
+ def lookupTypeForExtension(self, ext):
+ abstract
+
def getToolChain(self):
abstract
def useDriverDriver(self):
return True
+ def lookupTypeForExtension(self, ext):
+ ty = Types.kTypeSuffixMap.get(ext)
+ if ty is Types.AsmTypeNoPP:
+ return Types.AsmType
+ return ty
+
def getToolChain(self):
return self.getToolChainForArch(self.getArchName(None))
def useDriverDriver(self):
return False
+ def lookupTypeForExtension(self, ext):
+ return Types.kTypeSuffixMap.get(ext)
+
def getToolChain(self):
return ToolChain.Generic_GCC_ToolChain(self.driver, '')