diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-03-12 07:40:41 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-03-12 07:40:41 +0000 |
commit | e9fba573bd9433b89a12f747f2c4ccfa490a79cb (patch) | |
tree | c590019021699ccd00bf99512932e0f8212efc75 | |
parent | 644eade617a4e2e665455accf18c455e8d025699 (diff) |
Driver: Add information on Driver input/temporary types.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66781 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/Driver/Options.def | 4 | ||||
-rw-r--r-- | include/clang/Driver/Types.def | 77 | ||||
-rw-r--r-- | include/clang/Driver/Types.h | 64 | ||||
-rw-r--r-- | lib/Driver/Types.cpp | 125 |
4 files changed, 268 insertions, 2 deletions
diff --git a/include/clang/Driver/Options.def b/include/clang/Driver/Options.def index 335fdc18b1..b35f56fecf 100644 --- a/include/clang/Driver/Options.def +++ b/include/clang/Driver/Options.def @@ -21,8 +21,8 @@ // The first value is the option name as a string. // The second value is the internal option id, which must be a valid -// C++ identifier, and results in a clang::driver::options::XX enum -// value for XX. +// C++ identifier, and results in a clang::driver::options::OPT_XX +// enum constant for XX. // // We want to unamiguously be able to refer to options from the driver // source code, for this reason the option name is mangled into an diff --git a/include/clang/Driver/Types.def b/include/clang/Driver/Types.def new file mode 100644 index 0000000000..27b5526261 --- /dev/null +++ b/include/clang/Driver/Types.def @@ -0,0 +1,77 @@ +//===--- Types.def - Driver Type info ---------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file defines the driver type information. Users of this file +// must define the TYPE macro to make use of this information. +// +//===----------------------------------------------------------------------===// + +#ifndef TYPE +#error "Define TYPE prior to including this file!" +#endif + +// TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) + +// The first value is the type name as a string; for types which can +// be user specified this should be the equivalent -x option. + +// The second value is the type id, which will result in a +// clang::driver::types::TY_XX enum constant. + +// The third value is that id of the type for preprocessed inputs of +// this type, or INVALID if this type is not preprocessed. + +// The fourth value is the suffix to use when creating temporary files +// of this type, or null if unspecified. + +// The fifth value is a string containt option flags. Valid values: +// a - The type should only be assembled. +// p - The type should only be precompiled. +// u - The type can be user specified (with -x). +// A - The type's temporary suffix should be appended when generating +// outputs of this type. + + +// C family source language (with and without preprocessing). +TYPE("cpp-output", PP_C, INVALID, "i", "u") +TYPE("c", C, PP_C, 0, "u") +TYPE("objective-c-cpp-output", PP_ObjC, INVALID, "mi", "u") +TYPE("objective-c", ObjC, PP_ObjC, 0, "u") +TYPE("c++-cpp-output", PP_CXX, INVALID, "ii", "u") +TYPE("c++", CXX, PP_CXX, 0, "u") +TYPE("objective-c++-cpp-output", PP_ObjCXX, INVALID, "mii", "u") +TYPE("objective-c++", ObjCXX, PP_ObjCXX, 0, "u") + +// C family input files to precompile. +TYPE("c-header-cpp-output", PP_CHeader, INVALID, "i", "p") +TYPE("c-header", CHeader, PP_CHeader, 0, "pu") +TYPE("objective-c-header-cpp-output", PP_ObjCHeader, INVALID, "mi", "p") +TYPE("objective-c-header", ObjCHeader, PP_ObjCHeader, 0, "pu") +TYPE("c++-header-cpp-output", PP_CXXHeader, INVALID, "ii", "p") +TYPE("c++-header", CXXHeader, PP_CXXHeader, 0, "pu") +TYPE("objective-c++-header-cpp-output", PP_ObjCXXHeader, INVALID, "mii", "p") +TYPE("objective-c++-header", ObjCXXHeader, PP_ObjCXXHeader, 0, "pu") + +// Other languages. +TYPE("ada", Ada, INVALID, 0, "u") +TYPE("assembler", PP_Asm, INVALID, "s", "au") +TYPE("assembler-with-cpp", Asm, PP_Asm, 0, "au") +TYPE("f95", PP_Fortran, INVALID, 0, "u") +TYPE("f95-cpp-input", Fortran, PP_Fortran, 0, "u") +TYPE("java", Java, INVALID, 0, "u") + +// Misc. +TYPE("llvm-asm", LLVMAsm, INVALID, "ll", "") +TYPE("llvm-bc", LLVMBC, INVALID, "bc", "") +TYPE("plist", Plist, INVALID, "plist", "") +TYPE("precompiled-header", PCH, INVALID, "gch", "A") +TYPE("object", Object, INVALID, "o", "") +TYPE("treelang", Treelang, INVALID, 0, "u") +TYPE("image", Image, INVALID, "out", "") +TYPE("nothing", Nothing, INVALID, 0, "") diff --git a/include/clang/Driver/Types.h b/include/clang/Driver/Types.h new file mode 100644 index 0000000000..d5c7986434 --- /dev/null +++ b/include/clang/Driver/Types.h @@ -0,0 +1,64 @@ +//===--- Types.h - Input & Temporary Driver Types ---------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef CLANG_DRIVER_TYPES_H_ +#define CLANG_DRIVER_TYPES_H_ + +namespace clang { +namespace driver { +namespace types { + enum ID { + TY_INVALID, +#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) TY_##ID, +#include "clang/Driver/Types.def" +#undef TYPE + TY_LAST + }; + + /// getTypeName - Return the name of the type for \arg Id. + const char *getTypeName(ID Id); + + /// getPreprocessedType - Get the ID of the type for this input when + /// it has been preprocessed, or INVALID if this input is not + /// preprocessed. + ID getPreprocessedType(ID Id); + + /// getTypeTempSuffix - Return the suffix to use when creating a + /// temp file of this type, or null if unspecified. + const char *getTypeTempSuffix(ID Id); + + /// onlyAssembleType - Should this type only be assembled. + bool onlyAssembleType(ID Id); + + /// onlyPrecompileType - Should this type only be precompiled. + bool onlyPrecompileType(ID Id); + + /// canTypeBeUserSpecified - Can this type be specified on the + /// command line (by the type name); this is used when forwarding + /// commands to gcc. + bool canTypeBeUserSpecified(ID Id); + + /// appendSuffixForType - When generating outputs of this type, + /// should the suffix be appended (instead of replacing the existing + /// suffix). + bool appendSuffixForType(ID Id); + + /// lookupTypeForExtension - Lookup the type to use for the file + /// extension \arg Ext. + ID lookupTypeForExtension(const char *Ext); + + /// lookupTypeForTypSpecifier - Lookup the type to use for a user + /// specified type name. + ID lookupTypeForTypeSpecifier(const char *Name); + +} // end namespace types +} // end namespace driver +} // end namespace clang + +#endif diff --git a/lib/Driver/Types.cpp b/lib/Driver/Types.cpp new file mode 100644 index 0000000000..a8eabeaaca --- /dev/null +++ b/lib/Driver/Types.cpp @@ -0,0 +1,125 @@ +//===--- Types.cpp - Driver input & temporary type information ----------*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "clang/Driver/Types.h" + +#include <string.h> +#include <cassert> + +using namespace clang; +using namespace clang::driver; +using namespace clang::driver::types; + +struct Info { + const char *Name; + const char *Flags; + const char *TempSuffix; + ID PreprocessedType; +}; + +static Info TypeInfos[] = { +#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) \ + { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, }, +#include "clang/Driver/Types.def" +#undef TYPE +}; +static const unsigned numTypes = sizeof(TypeInfos) / sizeof(TypeInfos[0]); + +static Info &getInfo(unsigned id) { + assert(id > 0 && id - 1 < numTypes && "Invalid Type ID."); + return TypeInfos[id - 1]; +} + +const char *types::getTypeName(ID Id) { + return getInfo(Id).Name; +} + +types::ID types::getPreprocessedType(ID Id) { + return getInfo(Id).PreprocessedType; +} + +const char *types::getTypeTempSuffix(ID Id) { + return getInfo(Id).TempSuffix; +} + +bool types::onlyAssembleType(ID Id) { + return strchr(getInfo(Id).Flags, 'a'); +} + +bool types::onlyPrecompileType(ID Id) { + return strchr(getInfo(Id).Flags, 'p'); +} + +bool types::canTypeBeUserSpecified(ID Id) { + return strchr(getInfo(Id).Flags, 'u'); +} + +bool types::appendSuffixForType(ID Id) { + return strchr(getInfo(Id).Flags, 'A'); +} + +types::ID types::lookupTypeForExtension(const char *Ext) { + unsigned N = strlen(Ext); + + switch (N) { + case 1: + if (memcmp(Ext, "c", 1) == 0) return TY_C; + if (memcmp(Ext, "i", 1) == 0) return TY_PP_C; + if (memcmp(Ext, "m", 1) == 0) return TY_ObjC; + if (memcmp(Ext, "M", 1) == 0) return TY_ObjCXX; + if (memcmp(Ext, "h", 1) == 0) return TY_CHeader; + if (memcmp(Ext, "C", 1) == 0) return TY_CXX; + if (memcmp(Ext, "H", 1) == 0) return TY_CXXHeader; + if (memcmp(Ext, "f", 1) == 0) return TY_PP_Fortran; + if (memcmp(Ext, "F", 1) == 0) return TY_Fortran; + if (memcmp(Ext, "s", 1) == 0) return TY_PP_Asm; + if (memcmp(Ext, "S", 1) == 0) return TY_Asm; + case 2: + if (memcmp(Ext, "ii", 2) == 0) return TY_PP_CXX; + if (memcmp(Ext, "mi", 2) == 0) return TY_PP_ObjC; + if (memcmp(Ext, "mm", 2) == 0) return TY_ObjCXX; + if (memcmp(Ext, "cc", 2) == 0) return TY_CXX; + if (memcmp(Ext, "cc", 2) == 0) return TY_CXX; + if (memcmp(Ext, "cp", 2) == 0) return TY_CXX; + if (memcmp(Ext, "hh", 2) == 0) return TY_CXXHeader; + break; + case 3: + if (memcmp(Ext, "ads", 3) == 0) return TY_Ada; + if (memcmp(Ext, "adb", 3) == 0) return TY_Ada; + if (memcmp(Ext, "cxx", 3) == 0) return TY_CXX; + if (memcmp(Ext, "cpp", 3) == 0) return TY_CXX; + if (memcmp(Ext, "CPP", 3) == 0) return TY_CXX; + if (memcmp(Ext, "cXX", 3) == 0) return TY_CXX; + if (memcmp(Ext, "for", 3) == 0) return TY_PP_Fortran; + if (memcmp(Ext, "FOR", 3) == 0) return TY_PP_Fortran; + if (memcmp(Ext, "fpp", 3) == 0) return TY_Fortran; + if (memcmp(Ext, "FPP", 3) == 0) return TY_Fortran; + if (memcmp(Ext, "f90", 3) == 0) return TY_PP_Fortran; + if (memcmp(Ext, "f95", 3) == 0) return TY_PP_Fortran; + if (memcmp(Ext, "F90", 3) == 0) return TY_Fortran; + if (memcmp(Ext, "F95", 3) == 0) return TY_Fortran; + if (memcmp(Ext, "mii", 3) == 0) return TY_PP_ObjCXX; + break; + } + + return TY_INVALID; +} + +types::ID types::lookupTypeForTypeSpecifier(const char *Name) { + unsigned N = strlen(Name); + + for (unsigned i=0; i<numTypes; ++i) { + types::ID Id = (types::ID) (i + 1); + if (canTypeBeUserSpecified(Id) && + memcmp(Name, getInfo(Id).Name, N) == 0) + return Id; + } + + return TY_INVALID; +} |