[lld] r182912 - [WinLink][Driver] Handle file extensions and defualt output file name.
Reid Kleckner
rnk at google.com
Thu May 30 09:16:35 PDT 2013
On Thu, May 30, 2013 at 2:00 AM, Rui Ueyama <ruiu at google.com> wrote:
> Author: ruiu
> Date: Thu May 30 01:00:10 2013
> New Revision: 182912
>
> URL: http://llvm.org/viewvc/llvm-project?rev=182912&view=rev
> Log:
> [WinLink][Driver] Handle file extensions and defualt output file name.
>
> Modified:
> lld/trunk/lib/Driver/WinLinkDriver.cpp
>
> Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=182912&r1=182911&r2=182912&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
> +++ lld/trunk/lib/Driver/WinLinkDriver.cpp Thu May 30 01:00:10 2013
> @@ -16,6 +16,7 @@
> #include "llvm/ADT/StringSwitch.h"
> #include "llvm/Option/Arg.h"
> #include "llvm/Option/Option.h"
> +#include "llvm/Support/PathV2.h"
>
> #include "lld/Driver/Driver.h"
> #include "lld/ReaderWriter/PECOFFTargetInfo.h"
> @@ -72,6 +73,21 @@ llvm::COFF::WindowsSubsystem strToWinSub
> .Default(llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN);
> }
>
> +// Add ".obj" extension if the given path name has no file extension.
> +StringRef canonicalizeInputFileName(StringRef path) {
> + if (llvm::sys::path::extension(path).empty())
> + return path.str() + ".obj";
>
Isn't this a use-after-return? path.str() makes a temp std::string, which
is concatenated. Then we construct the StringRef from the string.
Probably the right thing is to take a std::string& and modify it in place.
> + return path;
> +}
> +
> +// Replace a file extension with ".exe". If the given file has no
> +// extension, just add ".exe".
> +StringRef getDefaultOutputFileName(StringRef path) {
> + StringRef ext = llvm::sys::path::extension(path);
> + StringRef filename = ext.empty() ? path : path.drop_back(ext.size());
> + return filename.str() + ".exe";
>
ditto?
> +}
> +
> } // namespace
>
>
> @@ -141,16 +157,26 @@ bool WinLinkDriver::parse(int argc, cons
> info.setOutputPath(outpath->getValue());
>
> // Add input files
> + std::vector<StringRef> inputPaths;
> for (llvm::opt::arg_iterator it = parsedArgs->filtered_begin(OPT_INPUT),
> ie = parsedArgs->filtered_end();
> it != ie; ++it) {
> - info.appendInputFile((*it)->getValue());
> + inputPaths.push_back((*it)->getValue());
> }
>
> // Arguments after "--" are also input files
> if (doubleDashPosition > 0)
> for (int i = doubleDashPosition + 1; i < argc; ++i)
> - info.appendInputFile(argv[i]);
> + inputPaths.push_back(argv[i]);
> +
> + // Add ".obj" extension for those who have no file extension.
> + for (const StringRef &path : inputPaths)
> + info.appendInputFile(canonicalizeInputFileName(path));
> +
> + // If -out option was not specified, the default output file name is
> + // constructed by replacing an extension with ".exe".
> + if (info.outputPath().empty() && !inputPaths.empty())
> + info.setOutputPath(getDefaultOutputFileName(inputPaths[0]));
>
> // Validate the combination of options used.
> return info.validate(diagnostics);
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130530/a52837c7/attachment.html>
More information about the llvm-commits
mailing list