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();
}
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
evaluateLinkerScript(ELFLinkingContext &ctx, StringRef path,
raw_ostream &diag) {
@ -248,32 +274,10 @@ evaluateLinkerScript(ELFLinkingContext &ctx, StringRef path,
// Evaluate script commands.
// Currently we only recognize GROUP() command.
bool sysroot = (!ctx.getSysroot().empty()
&& isPathUnderSysroot(ctx.getSysroot(), path));
for (const script::Command *c : script->_commands) {
auto *group = dyn_cast<script::Group>(c);
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));
}
for (const script::Command *c : script->_commands)
if (auto *group = dyn_cast<script::Group>(c))
if (std::error_code ec = evaluateLinkerScriptGroup(ctx, path, group, diag))
return ec;
return std::error_code();
}