[lld] r182912 - [WinLink][Driver] Handle file extensions and defualt output file name.

Shankar Easwaran shankare at codeaurora.org
Thu May 30 08:12:45 PDT 2013


Hi Ruiu,

Can you add a testcase ?

Also why do you want to add .obj extension if the input doesnot have an 
extension. How is the linker going to find the file ?

Thanks

Shankar Easwaran

On 5/30/2013 1:00 AM, Rui Ueyama 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";
> +  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";
> +}
> +
>   } // 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
>
>


-- 
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by the Linux Foundation




More information about the llvm-commits mailing list