diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-04-28 01:49:42 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-04-28 01:49:42 +0000 |
commit | f74d946624f30d60fd3f90a9545a455308931c32 (patch) | |
tree | 7b557e0dfc4727fa3d53543984bdcf0e1a1aeaca /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | 7fca8c0757a5ee5f290844376c7f8c5f3c1ffcfe (diff) | |
download | bcm5719-llvm-f74d946624f30d60fd3f90a9545a455308931c32.tar.gz bcm5719-llvm-f74d946624f30d60fd3f90a9545a455308931c32.zip |
Move functionality for handling module maps as inputs from the -emit-module
action to the general FrontendAction infrastructure.
This permits applying -E, -ast-dump, -fsyntax-only, and so on to a module map
compilation. (The -E form is not currently especially useful yet as there's no
good way to take the output and use it to actually build a module.)
In order to support this, -cc1 now accepts -x <lang>-module-map in all cases
where it accepts -x <lang> for a language we can parse (not ir/ast). And for
uniformity, we also accept -x <lang>-header for all such languages (we used
to reject for cuda and renderscript), and -x <lang>-cpp-output for all such
languages (we used to reject for c, cl, and renderscript).
(None of these new alternatives are accepted by the driver yet, so no
user-visible changes.)
llvm-svn: 301610
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 63 |
1 files changed, 45 insertions, 18 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 2cc48e1d1de..d3ebf48315e 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -1350,30 +1350,51 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, InputKind DashX(InputKind::Unknown); if (const Arg *A = Args.getLastArg(OPT_x)) { StringRef XValue = A->getValue(); + + // Parse suffixes: '<lang>(-header|[-module-map][-cpp-output])'. + // FIXME: Supporting '<lang>-header-cpp-output' would be useful. + bool Preprocessed = XValue.consume_back("-cpp-output"); + bool ModuleMap = XValue.consume_back("-module-map"); + IsHeaderFile = + !Preprocessed && !ModuleMap && XValue.consume_back("-header"); + + // Principal languages. DashX = llvm::StringSwitch<InputKind>(XValue) - .Cases("c", "c-header", "cpp-output", InputKind::C) - .Cases("cl", "cl-header", InputKind::OpenCL) - .Cases("cuda", "cuda-cpp-output", InputKind::CUDA) - .Cases("c++", "c++-header", "c++-cpp-output", InputKind::CXX) - .Cases("objective-c", "objective-c-header", - "objective-c-cpp-output", "objc-cpp-output", - InputKind::ObjC) - .Cases("objective-c++", "objective-c++-header", - "objective-c++-cpp-output", "objc++-cpp-output", - InputKind::ObjCXX) - .Case("renderscript", InputKind::RenderScript) - .Case("assembler-with-cpp", InputKind::Asm) - .Cases("ast", "pcm", - InputKind(InputKind::Unknown, InputKind::Precompiled)) - .Case("ir", InputKind::LLVM_IR) - .Default(InputKind::Unknown); + .Case("c", InputKind::C) + .Case("cl", InputKind::OpenCL) + .Case("cuda", InputKind::CUDA) + .Case("c++", InputKind::CXX) + .Case("objective-c", InputKind::ObjC) + .Case("objective-c++", InputKind::ObjCXX) + .Case("renderscript", InputKind::RenderScript) + .Default(InputKind::Unknown); + + // "objc[++]-cpp-output" is an acceptable synonym for + // "objective-c[++]-cpp-output". + if (DashX.isUnknown() && Preprocessed && !IsHeaderFile && !ModuleMap) + DashX = llvm::StringSwitch<InputKind>(XValue) + .Case("objc", InputKind::ObjC) + .Case("objc++", InputKind::ObjCXX) + .Default(InputKind::Unknown); + + // Some special cases cannot be combined with suffixes. + if (DashX.isUnknown() && !Preprocessed && !ModuleMap && !IsHeaderFile) + DashX = llvm::StringSwitch<InputKind>(XValue) + .Case("cpp-output", InputKind(InputKind::C).getPreprocessed()) + .Case("assembler-with-cpp", InputKind::Asm) + .Cases("ast", "pcm", + InputKind(InputKind::Unknown, InputKind::Precompiled)) + .Case("ir", InputKind::LLVM_IR) + .Default(InputKind::Unknown); + if (DashX.isUnknown()) Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << A->getValue(); - if (XValue.endswith("cpp-output")) + if (Preprocessed) DashX = DashX.getPreprocessed(); - IsHeaderFile = XValue.endswith("-header"); + if (ModuleMap) + DashX = DashX.withFormat(InputKind::ModuleMap); } // '-' is the default input if none is given. @@ -1393,6 +1414,12 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, if (i == 0) DashX = IK; } + + // The -emit-module action implicitly takes a module map. + if (Opts.ProgramAction == frontend::GenerateModule && + IK.getFormat() == InputKind::Source) + IK = IK.withFormat(InputKind::ModuleMap); + Opts.Inputs.emplace_back(std::move(Inputs[i]), IK); } |