[lld] r199021 - Make anonymous namespace as small as possible.
Rui Ueyama
ruiu at google.com
Sat Jan 11 14:15:54 PST 2014
Author: ruiu
Date: Sat Jan 11 16:15:54 2014
New Revision: 199021
URL: http://llvm.org/viewvc/llvm-project?rev=199021&view=rev
Log:
Make anonymous namespace as small as possible.
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=199021&r1=199020&r2=199021&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Sat Jan 11 16:15:54 2014
@@ -37,8 +37,6 @@
namespace lld {
-namespace {
-
//
// Option definitions
//
@@ -68,6 +66,8 @@ static const llvm::opt::OptTable::Info i
#undef OPTION
};
+namespace {
+
// Create OptTable class for parsing actual command line arguments
class WinLinkOptTable : public llvm::opt::OptTable {
public:
@@ -78,12 +78,14 @@ public:
/* ignoreCase */ true) {}
};
+} // anonymous namespace
+
//
// Functions to parse each command line option
//
// Split the given string with spaces.
-std::vector<std::string> splitArgList(const std::string &str) {
+static std::vector<std::string> splitArgList(const std::string &str) {
std::stringstream stream(str);
std::istream_iterator<std::string> begin(stream);
std::istream_iterator<std::string> end;
@@ -91,7 +93,7 @@ std::vector<std::string> splitArgList(co
}
// Split the given string with the path separator.
-std::vector<StringRef> splitPathList(StringRef str) {
+static std::vector<StringRef> splitPathList(StringRef str) {
std::vector<StringRef> ret;
while (!str.empty()) {
StringRef path;
@@ -103,8 +105,8 @@ std::vector<StringRef> splitPathList(Str
// Parse an argument for /alternatename. The expected string is
// "<string>=<string>".
-bool parseAlternateName(StringRef arg, StringRef &weak, StringRef &def,
- raw_ostream &diagnostics) {
+static bool parseAlternateName(StringRef arg, StringRef &weak, StringRef &def,
+ raw_ostream &diagnostics) {
llvm::tie(weak, def) = arg.split('=');
if (weak.empty() || def.empty()) {
diagnostics << "Error: malformed /alternatename option: " << arg << "\n";
@@ -115,7 +117,8 @@ bool parseAlternateName(StringRef arg, S
// Parse an argument for /base, /stack or /heap. The expected string
// is "<integer>[,<integer>]".
-bool parseMemoryOption(StringRef arg, uint64_t &reserve, uint64_t &commit) {
+static bool parseMemoryOption(StringRef arg, uint64_t &reserve,
+ uint64_t &commit) {
StringRef reserveStr, commitStr;
llvm::tie(reserveStr, commitStr) = arg.split(',');
if (reserveStr.getAsInteger(0, reserve))
@@ -127,7 +130,7 @@ bool parseMemoryOption(StringRef arg, ui
// Parse an argument for /version or /subsystem. The expected string is
// "<integer>[.<integer>]".
-bool parseVersion(StringRef arg, uint32_t &major, uint32_t &minor) {
+static bool parseVersion(StringRef arg, uint32_t &major, uint32_t &minor) {
StringRef majorVersion, minorVersion;
llvm::tie(majorVersion, minorVersion) = arg.split('.');
if (minorVersion.empty())
@@ -140,7 +143,7 @@ bool parseVersion(StringRef arg, uint32_
}
// Returns subsystem type for the given string.
-llvm::COFF::WindowsSubsystem stringToWinSubsystem(StringRef str) {
+static llvm::COFF::WindowsSubsystem stringToWinSubsystem(StringRef str) {
return llvm::StringSwitch<llvm::COFF::WindowsSubsystem>(str.lower())
.Case("windows", llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_GUI)
.Case("console", llvm::COFF::IMAGE_SUBSYSTEM_WINDOWS_CUI)
@@ -159,9 +162,11 @@ llvm::COFF::WindowsSubsystem stringToWin
// Parse /subsystem command line option. The form of /subsystem is
// "subsystem_name[,majorOSVersion[.minorOSVersion]]".
-bool parseSubsystem(StringRef arg, llvm::COFF::WindowsSubsystem &subsystem,
- llvm::Optional<uint32_t> &major,
- llvm::Optional<uint32_t> &minor, raw_ostream &diagnostics) {
+static bool parseSubsystem(StringRef arg,
+ llvm::COFF::WindowsSubsystem &subsystem,
+ llvm::Optional<uint32_t> &major,
+ llvm::Optional<uint32_t> &minor,
+ raw_ostream &diagnostics) {
StringRef subsystemStr, osVersion;
llvm::tie(subsystemStr, osVersion) = arg.split(',');
if (!osVersion.empty()) {
@@ -179,7 +184,7 @@ bool parseSubsystem(StringRef arg, llvm:
return true;
}
-llvm::COFF::MachineTypes stringToMachineType(StringRef str) {
+static llvm::COFF::MachineTypes stringToMachineType(StringRef str) {
return llvm::StringSwitch<llvm::COFF::MachineTypes>(str.lower())
.Case("arm", llvm::COFF::IMAGE_FILE_MACHINE_ARM)
.Case("ebc", llvm::COFF::IMAGE_FILE_MACHINE_EBC)
@@ -199,9 +204,9 @@ llvm::COFF::MachineTypes stringToMachine
// off regardless of the default value. You can even create a section which is
// not readable, writable nor executable with this -- although it's probably
// useless.
-bool parseSection(StringRef option, std::string §ion,
- llvm::Optional<uint32_t> &flags,
- llvm::Optional<uint32_t> &mask) {
+static bool parseSection(StringRef option, std::string §ion,
+ llvm::Optional<uint32_t> &flags,
+ llvm::Optional<uint32_t> &mask) {
StringRef flagString;
llvm::tie(section, flagString) = option.split(",");
@@ -241,8 +246,8 @@ bool parseSection(StringRef option, std:
return true;
}
-bool readFile(PECOFFLinkingContext &ctx, StringRef path,
- ArrayRef<uint8_t> &result) {
+static bool readFile(PECOFFLinkingContext &ctx, StringRef path,
+ ArrayRef<uint8_t> &result) {
OwningPtr<MemoryBuffer> buf;
if (MemoryBuffer::getFile(path, buf))
return false;
@@ -253,7 +258,8 @@ bool readFile(PECOFFLinkingContext &ctx,
}
// Parse /manifest:EMBED[,ID=#]|NO.
-bool parseManifest(StringRef option, bool &enable, bool &embed, int &id) {
+static bool parseManifest(StringRef option, bool &enable, bool &embed,
+ int &id) {
if (option.equals_lower("no")) {
enable = false;
return true;
@@ -278,8 +284,9 @@ bool parseManifest(StringRef option, boo
// The arguments will be embedded to the manifest XML file with no error check,
// so the values given via the command line must be valid as XML attributes.
// This may sound a bit odd, but that's how link.exe works, so we will follow.
-bool parseManifestUac(StringRef option, llvm::Optional<std::string> &level,
- llvm::Optional<std::string> &uiAccess) {
+static bool parseManifestUac(StringRef option,
+ llvm::Optional<std::string> &level,
+ llvm::Optional<std::string> &uiAccess) {
for (;;) {
option = option.ltrim();
if (option.empty())
@@ -303,7 +310,8 @@ bool parseManifestUac(StringRef option,
}
// Parse /export:name[, at ordinal[,NONAME]][,DATA].
-bool parseExport(StringRef option, PECOFFLinkingContext::ExportDesc &ret) {
+static bool parseExport(StringRef option,
+ PECOFFLinkingContext::ExportDesc &ret) {
StringRef name;
StringRef rest;
llvm::tie(name, rest) = option.split(",");
@@ -340,8 +348,8 @@ bool parseExport(StringRef option, PECOF
}
// Read module-definition file.
-llvm::Optional<moduledef::Directive *> parseDef(StringRef option,
- llvm::BumpPtrAllocator &alloc) {
+static llvm::Optional<moduledef::Directive *>
+parseDef(StringRef option, llvm::BumpPtrAllocator &alloc) {
OwningPtr<MemoryBuffer> buf;
if (MemoryBuffer::getFile(option, buf))
return llvm::None;
@@ -350,15 +358,15 @@ llvm::Optional<moduledef::Directive *> p
return parser.parse();
}
-StringRef replaceExtension(PECOFFLinkingContext &ctx, StringRef path,
- StringRef extension) {
+static StringRef replaceExtension(PECOFFLinkingContext &ctx, StringRef path,
+ StringRef extension) {
SmallString<128> val = path;
llvm::sys::path::replace_extension(val, extension);
return ctx.allocate(val.str());
}
// Create a manifest file contents.
-std::string createManifestXml(PECOFFLinkingContext &ctx) {
+static std::string createManifestXml(PECOFFLinkingContext &ctx) {
std::string ret;
llvm::raw_string_ostream out(ret);
// Emit the XML. Note that we do *not* verify that the XML attributes are
@@ -391,7 +399,7 @@ std::string createManifestXml(PECOFFLink
// Convert one doublequote to two doublequotes, so that we can embed the string
// into a resource script file.
-void quoteAndPrintXml(raw_ostream &out, StringRef str) {
+static void quoteAndPrintXml(raw_ostream &out, StringRef str) {
for (;;) {
if (str.empty())
return;
@@ -423,9 +431,9 @@ void quoteAndPrintXml(raw_ostream &out,
// The temporary file created in step 1 will be deleted on exit from this
// function. The file created in step 2 will have the same lifetime as the
// PECOFFLinkingContext.
-bool createManifestResourceFile(PECOFFLinkingContext &ctx,
- raw_ostream &diagnostics,
- std::string &resFile) {
+static bool createManifestResourceFile(PECOFFLinkingContext &ctx,
+ raw_ostream &diagnostics,
+ std::string &resFile) {
// Create a temporary file for the resource script file.
SmallString<128> rcFileSmallString;
if (llvm::sys::fs::createTemporaryFile("tmp", "rc", rcFileSmallString)) {
@@ -492,8 +500,8 @@ bool createManifestResourceFile(PECOFFLi
// Create a side-by-side manifest file. The side-by-side manifest file is a
// separate XML file having ".manifest" extension. It will be created in the
// same directory as the resulting executable.
-bool createSideBySideManifestFile(PECOFFLinkingContext &ctx,
- raw_ostream &diagnostics) {
+static bool createSideBySideManifestFile(PECOFFLinkingContext &ctx,
+ raw_ostream &diagnostics) {
std::string errorInfo;
llvm::raw_fd_ostream out(ctx.getManifestOutputPath().data(), errorInfo);
if (!errorInfo.empty()) {
@@ -512,7 +520,8 @@ bool createSideBySideManifestFile(PECOFF
// the binary needs to run as Administrator or not. Instead of being placed in
// the PE/COFF header, it's in XML format for some reason -- I guess it's
// probably because it's invented in the early dot-com era.
-bool createManifest(PECOFFLinkingContext &ctx, raw_ostream &diagnostics) {
+static bool createManifest(PECOFFLinkingContext &ctx,
+ raw_ostream &diagnostics) {
if (ctx.getEmbedManifest()) {
std::string resourceFilePath;
if (!createManifestResourceFile(ctx, diagnostics, resourceFilePath))
@@ -526,9 +535,10 @@ bool createManifest(PECOFFLinkingContext
}
// Handle /failifmismatch option.
-bool handleFailIfMismatchOption(StringRef option,
- std::map<StringRef, StringRef> &mustMatch,
- raw_ostream &diagnostics) {
+static bool
+handleFailIfMismatchOption(StringRef option,
+ std::map<StringRef, StringRef> &mustMatch,
+ raw_ostream &diagnostics) {
StringRef key, value;
llvm::tie(key, value) = option.split('=');
if (key.empty() || value.empty()) {
@@ -551,8 +561,8 @@ bool handleFailIfMismatchOption(StringRe
// Process "LINK" environment variable. If defined, the value of the variable
// should be processed as command line arguments.
-std::vector<const char *> processLinkEnv(PECOFFLinkingContext &context,
- int argc, const char **argv) {
+static std::vector<const char *> processLinkEnv(PECOFFLinkingContext &context,
+ int argc, const char **argv) {
std::vector<const char *> ret;
// The first argument is the name of the command. This should stay at the head
// of the argument list.
@@ -574,7 +584,7 @@ std::vector<const char *> processLinkEnv
// Process "LIB" environment variable. The variable contains a list of search
// paths separated by semicolons.
-void processLibEnv(PECOFFLinkingContext &context) {
+static void processLibEnv(PECOFFLinkingContext &context) {
llvm::Optional<std::string> env = llvm::sys::Process::GetEnv("LIB");
if (env.hasValue())
for (StringRef path : splitPathList(*env))
@@ -583,7 +593,7 @@ void processLibEnv(PECOFFLinkingContext
// Returns a default entry point symbol name depending on context image type and
// subsystem. These default names are MS CRT compliant.
-StringRef getDefaultEntrySymbolName(PECOFFLinkingContext &context) {
+static StringRef getDefaultEntrySymbolName(PECOFFLinkingContext &context) {
if (context.isDll())
return "_DllMainCRTStartup at 12";
llvm::COFF::WindowsSubsystem subsystem = context.getSubsystem();
@@ -596,7 +606,7 @@ StringRef getDefaultEntrySymbolName(PECO
// Parses the given command line options and returns the result. Returns NULL if
// there's an error in the options.
-std::unique_ptr<llvm::opt::InputArgList>
+static std::unique_ptr<llvm::opt::InputArgList>
parseArgs(int argc, const char *argv[], raw_ostream &diagnostics,
bool isReadingDirectiveSection) {
// Parse command line options using WinLinkOptions.td
@@ -628,7 +638,7 @@ parseArgs(int argc, const char *argv[],
// Returns true if the given file node has already been added to the input
// graph.
-bool hasLibrary(const PECOFFLinkingContext &ctx, FileNode *fileNode) {
+static bool hasLibrary(const PECOFFLinkingContext &ctx, FileNode *fileNode) {
ErrorOr<StringRef> path = fileNode->getPath(ctx);
if (!path)
return false;
@@ -639,8 +649,6 @@ bool hasLibrary(const PECOFFLinkingConte
return false;
}
-} // namespace
-
//
// Main driver
//
More information about the llvm-commits
mailing list