Split a function for readability.

llvm-svn: 226292
This commit is contained in:
Rui Ueyama 2015-01-16 17:53:55 +00:00
parent 2f5bb31302
commit 949dc41502
1 changed files with 30 additions and 26 deletions

View File

@ -232,6 +232,32 @@ static bool isPathUnderSysroot(StringRef sysroot, StringRef path) {
return !path.empty(); return !path.empty();
} }
static std::error_code
evaluateLinkerScriptGroup(ELFLinkingContext &ctx, StringRef path,
const script::Group *group, raw_ostream &diag) {
bool sysroot = (!ctx.getSysroot().empty()
&& isPathUnderSysroot(ctx.getSysroot(), path));
int numfiles = 0;
for (const script::Path &path : group->getPaths()) {
ErrorOr<StringRef> pathOrErr = path._isDashlPrefix
? ctx.searchLibrary(path._path) : ctx.searchFile(path._path, sysroot);
if (std::error_code ec = pathOrErr.getError())
return make_dynamic_error_code(
Twine("Unable to find file ") + path._path + ": " + ec.message());
std::vector<std::unique_ptr<File>> files
= loadFile(ctx, pathOrErr.get(), false);
for (std::unique_ptr<File> &file : files) {
if (ctx.logInputFiles())
diag << file->path() << "\n";
ctx.getNodes().push_back(llvm::make_unique<FileNode>(std::move(file)));
++numfiles;
}
}
ctx.getNodes().push_back(llvm::make_unique<GroupEnd>(numfiles));
return std::error_code();
}
static std::error_code static std::error_code
evaluateLinkerScript(ELFLinkingContext &ctx, StringRef path, evaluateLinkerScript(ELFLinkingContext &ctx, StringRef path,
raw_ostream &diag) { raw_ostream &diag) {
@ -248,32 +274,10 @@ evaluateLinkerScript(ELFLinkingContext &ctx, StringRef path,
// Evaluate script commands. // Evaluate script commands.
// Currently we only recognize GROUP() command. // Currently we only recognize GROUP() command.
bool sysroot = (!ctx.getSysroot().empty() for (const script::Command *c : script->_commands)
&& isPathUnderSysroot(ctx.getSysroot(), path)); if (auto *group = dyn_cast<script::Group>(c))
for (const script::Command *c : script->_commands) { if (std::error_code ec = evaluateLinkerScriptGroup(ctx, path, group, diag))
auto *group = dyn_cast<script::Group>(c); return ec;
if (!group)
continue;
int numfiles = 0;
for (const script::Path &path : group->getPaths()) {
// TODO : Propagate Set WholeArchive/dashlPrefix
ErrorOr<StringRef> pathOrErr = path._isDashlPrefix
? ctx.searchLibrary(path._path) : ctx.searchFile(path._path, sysroot);
if (std::error_code ec = pathOrErr.getError())
return make_dynamic_error_code(
Twine("Unable to find file ") + path._path + ": " + ec.message());
std::vector<std::unique_ptr<File>> files
= loadFile(ctx, pathOrErr.get(), false);
for (std::unique_ptr<File> &file : files) {
if (ctx.logInputFiles())
diag << file->path() << "\n";
ctx.getNodes().push_back(llvm::make_unique<FileNode>(std::move(file)));
++numfiles;
}
}
ctx.getNodes().push_back(llvm::make_unique<GroupEnd>(numfiles));
}
return std::error_code(); return std::error_code();
} }