2016-01-04 15:26:31 +03:00
|
|
|
//===--- lldb-moduleimport-test.cpp - LLDB moduleimport tester ------------===//
|
2013-08-29 04:57:05 +04:00
|
|
|
//
|
|
|
|
// This source file is part of the Swift.org open source project
|
|
|
|
//
|
2017-01-06 18:41:22 +03:00
|
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
2013-08-29 04:57:05 +04:00
|
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
|
|
//
|
2016-11-20 11:19:12 +03:00
|
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
2013-08-29 04:57:05 +04:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This program simulates LLDB importing modules from the __apple_ast
|
|
|
|
// section in Mach-O files. We use it to test for regressions in the
|
|
|
|
// deserialization API.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2019-01-24 19:32:16 +03:00
|
|
|
#include "swift/AST/ASTDemangler.h"
|
2019-01-30 02:03:30 +03:00
|
|
|
#include "swift/AST/PrintOptions.h"
|
2013-09-04 01:56:53 +04:00
|
|
|
#include "swift/ASTSectionImporter/ASTSectionImporter.h"
|
2015-02-12 02:07:48 +03:00
|
|
|
#include "swift/Frontend/Frontend.h"
|
|
|
|
#include "swift/Serialization/SerializedModuleLoader.h"
|
2015-02-12 08:32:25 +03:00
|
|
|
#include "swift/Serialization/Validation.h"
|
2015-02-12 02:07:48 +03:00
|
|
|
#include "swift/Basic/Dwarf.h"
|
2015-09-03 00:56:25 +03:00
|
|
|
#include "llvm/Object/ELFObjectFile.h"
|
2015-09-09 07:37:38 +03:00
|
|
|
#include "swift/Basic/LLVMInitialize.h"
|
2019-03-22 22:47:39 +03:00
|
|
|
#include "llvm/Object/COFF.h"
|
2014-12-16 23:23:58 +03:00
|
|
|
#include "llvm/Object/MachO.h"
|
|
|
|
#include "llvm/Object/ObjectFile.h"
|
2013-08-29 04:57:05 +04:00
|
|
|
#include "llvm/Support/CommandLine.h"
|
2014-05-01 18:26:34 +04:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2014-12-16 23:23:58 +03:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
2013-08-29 04:57:05 +04:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
|
|
|
#include "llvm/Support/Signals.h"
|
|
|
|
#include "llvm/Support/TargetSelect.h"
|
2013-08-29 22:59:14 +04:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2015-09-09 07:37:38 +03:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2013-08-29 04:57:05 +04:00
|
|
|
#include <fstream>
|
2014-07-23 22:04:10 +04:00
|
|
|
#include <sstream>
|
2013-08-29 04:57:05 +04:00
|
|
|
|
|
|
|
void anchorForGetMainExecutable() {}
|
|
|
|
|
2013-09-04 00:14:43 +04:00
|
|
|
using namespace llvm::MachO;
|
2013-09-03 22:09:53 +04:00
|
|
|
|
2018-08-28 23:01:56 +03:00
|
|
|
static bool
|
|
|
|
validateModule(llvm::StringRef data, bool Verbose,
|
|
|
|
swift::serialization::ValidationInfo &info,
|
|
|
|
swift::serialization::ExtendedValidationInfo &extendedInfo) {
|
2018-04-02 23:05:34 +03:00
|
|
|
info = swift::serialization::validateSerializedAST(data, &extendedInfo);
|
2019-05-08 21:34:21 +03:00
|
|
|
if (info.status != swift::serialization::Status::Valid) {
|
|
|
|
llvm::outs() << "error: validateSerializedAST() failed\n";
|
2018-03-31 04:04:02 +03:00
|
|
|
return false;
|
2019-05-08 21:34:21 +03:00
|
|
|
}
|
2018-03-31 04:04:02 +03:00
|
|
|
|
2018-08-28 23:01:56 +03:00
|
|
|
swift::CompilerInvocation CI;
|
2019-05-08 21:34:21 +03:00
|
|
|
if (CI.loadFromSerializedAST(data) != swift::serialization::Status::Valid) {
|
|
|
|
llvm::outs() << "error: loadFromSerializedAST() failed\n";
|
2018-08-28 23:01:56 +03:00
|
|
|
return false;
|
2019-05-08 21:34:21 +03:00
|
|
|
}
|
2018-08-28 23:01:56 +03:00
|
|
|
|
2018-03-31 04:04:02 +03:00
|
|
|
if (Verbose) {
|
|
|
|
if (!info.shortVersion.empty())
|
|
|
|
llvm::outs() << "- Swift Version: " << info.shortVersion << "\n";
|
2018-08-28 23:01:56 +03:00
|
|
|
llvm::outs() << "- Compatibility Version: "
|
|
|
|
<< CI.getLangOptions()
|
|
|
|
.EffectiveLanguageVersion.asAPINotesVersionString()
|
|
|
|
<< "\n";
|
2018-03-31 04:04:02 +03:00
|
|
|
llvm::outs() << "- Target: " << info.targetTriple << "\n";
|
|
|
|
if (!extendedInfo.getSDKPath().empty())
|
|
|
|
llvm::outs() << "- SDK path: " << extendedInfo.getSDKPath() << "\n";
|
|
|
|
if (!extendedInfo.getExtraClangImporterOptions().empty()) {
|
|
|
|
llvm::outs() << "- -Xcc options:";
|
|
|
|
for (llvm::StringRef option : extendedInfo.getExtraClangImporterOptions())
|
|
|
|
llvm::outs() << " " << option;
|
|
|
|
llvm::outs() << "\n";
|
|
|
|
}
|
2015-02-12 02:07:48 +03:00
|
|
|
}
|
2018-03-31 04:04:02 +03:00
|
|
|
|
|
|
|
return true;
|
2015-02-12 02:07:48 +03:00
|
|
|
}
|
|
|
|
|
2018-03-22 20:47:24 +03:00
|
|
|
static void resolveDeclFromMangledNameList(
|
|
|
|
swift::ASTContext &Ctx, llvm::ArrayRef<std::string> MangledNames) {
|
|
|
|
for (auto &Mangled : MangledNames) {
|
2019-02-22 23:32:26 +03:00
|
|
|
swift::TypeDecl *ResolvedDecl =
|
|
|
|
swift::Demangle::getTypeDeclForMangling(Ctx, Mangled);
|
2018-03-22 20:47:24 +03:00
|
|
|
if (!ResolvedDecl) {
|
|
|
|
llvm::errs() << "Can't resolve decl of " << Mangled << "\n";
|
|
|
|
} else {
|
2019-02-22 23:32:26 +03:00
|
|
|
ResolvedDecl->dumpRef(llvm::outs());
|
|
|
|
llvm::outs() << "\n";
|
2018-03-22 20:47:24 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 19:03:08 +03:00
|
|
|
static void resolveTypeFromMangledNameList(
|
2018-03-22 20:07:10 +03:00
|
|
|
swift::ASTContext &Ctx, llvm::ArrayRef<std::string> MangledNames) {
|
2019-01-24 19:32:16 +03:00
|
|
|
for (auto &Mangled : MangledNames) {
|
|
|
|
swift::Type ResolvedType =
|
|
|
|
swift::Demangle::getTypeForMangling(Ctx, Mangled);
|
|
|
|
if (!ResolvedType) {
|
|
|
|
llvm::outs() << "Can't resolve type of " << Mangled << "\n";
|
|
|
|
} else {
|
2019-01-30 02:03:30 +03:00
|
|
|
swift::PrintOptions PO;
|
|
|
|
PO.PrintStorageRepresentationAttrs = true;
|
|
|
|
ResolvedType->print(llvm::outs(), PO);
|
2019-01-24 19:32:16 +03:00
|
|
|
llvm::outs() << "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 19:03:08 +03:00
|
|
|
static void
|
2018-03-22 20:07:10 +03:00
|
|
|
collectMangledNames(const std::string &FilePath,
|
|
|
|
llvm::SmallVectorImpl<std::string> &MangledNames) {
|
2018-03-22 19:03:08 +03:00
|
|
|
std::string Name;
|
|
|
|
std::ifstream InputStream(FilePath);
|
|
|
|
while (std::getline(InputStream, Name)) {
|
|
|
|
if (Name.empty())
|
|
|
|
continue;
|
|
|
|
MangledNames.push_back(Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-31 04:04:02 +03:00
|
|
|
llvm::BumpPtrAllocator Alloc;
|
|
|
|
|
|
|
|
static bool
|
|
|
|
collectASTModules(llvm::cl::list<std::string> &InputNames,
|
|
|
|
llvm::SmallVectorImpl<std::pair<char *, uint64_t>> &Modules) {
|
|
|
|
for (auto &name : InputNames) {
|
|
|
|
auto OF = llvm::object::ObjectFile::createObjectFile(name);
|
|
|
|
if (!OF) {
|
2018-05-14 22:16:12 +03:00
|
|
|
llvm::outs() << "error: " << name << " "
|
|
|
|
<< errorToErrorCode(OF.takeError()).message() << "\n";
|
2018-03-31 04:04:02 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
auto *Obj = OF->getBinary();
|
|
|
|
auto *MachO = llvm::dyn_cast<llvm::object::MachOObjectFile>(Obj);
|
|
|
|
auto *ELF = llvm::dyn_cast<llvm::object::ELFObjectFileBase>(Obj);
|
2019-03-22 22:47:39 +03:00
|
|
|
auto *COFF = llvm::dyn_cast<llvm::object::COFFObjectFile>(Obj);
|
2018-03-31 04:04:02 +03:00
|
|
|
|
|
|
|
if (MachO) {
|
|
|
|
for (auto &Symbol : Obj->symbols()) {
|
|
|
|
auto RawSym = Symbol.getRawDataRefImpl();
|
|
|
|
llvm::MachO::nlist nlist = MachO->getSymbolTableEntry(RawSym);
|
|
|
|
if (nlist.n_type != N_AST)
|
|
|
|
continue;
|
|
|
|
auto Path = MachO->getSymbolName(RawSym);
|
|
|
|
if (!Path) {
|
|
|
|
llvm::outs() << "Cannot get symbol name\n;";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto fileBuf = llvm::MemoryBuffer::getFile(*Path);
|
|
|
|
if (!fileBuf) {
|
|
|
|
llvm::outs() << "Cannot read from '" << *Path
|
|
|
|
<< "': " << fileBuf.getError().message();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t Size = fileBuf.get()->getBufferSize();
|
|
|
|
char *Module = Alloc.Allocate<char>(Size);
|
|
|
|
std::memcpy(Module, (void *)fileBuf.get()->getBufferStart(), Size);
|
|
|
|
Modules.push_back({Module, Size});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &Section : Obj->sections()) {
|
|
|
|
llvm::StringRef Name;
|
|
|
|
Section.getName(Name);
|
|
|
|
if ((MachO && Name == swift::MachOASTSectionName) ||
|
2019-03-22 22:47:39 +03:00
|
|
|
(ELF && Name == swift::ELFASTSectionName) ||
|
|
|
|
(COFF && Name == swift::COFFASTSectionName)) {
|
2018-03-31 04:04:02 +03:00
|
|
|
uint64_t Size = Section.getSize();
|
2019-05-18 03:56:17 +03:00
|
|
|
|
|
|
|
llvm::Expected<llvm::StringRef> ContentsReference = Section.getContents();
|
|
|
|
if (!ContentsReference) {
|
2019-05-22 17:56:12 +03:00
|
|
|
llvm::errs() << "error: " << name << " "
|
2019-05-18 03:56:17 +03:00
|
|
|
<< errorToErrorCode(OF.takeError()).message() << "\n";
|
|
|
|
return false;
|
|
|
|
}
|
2018-03-31 04:04:02 +03:00
|
|
|
char *Module = Alloc.Allocate<char>(Size);
|
2019-05-18 03:56:17 +03:00
|
|
|
std::memcpy(Module, (void *)ContentsReference->begin(), Size);
|
2018-03-31 04:04:02 +03:00
|
|
|
Modules.push_back({Module, Size});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-29 04:57:05 +04:00
|
|
|
int main(int argc, char **argv) {
|
2018-03-01 06:56:19 +03:00
|
|
|
PROGRAM_START(argc, argv);
|
|
|
|
INITIALIZE_LLVM();
|
2015-03-12 05:00:56 +03:00
|
|
|
|
|
|
|
// Command line handling.
|
2018-11-14 23:18:43 +03:00
|
|
|
using namespace llvm::cl;
|
|
|
|
static OptionCategory Visible("Specific Options");
|
|
|
|
HideUnrelatedOptions({&Visible});
|
2015-03-12 05:00:56 +03:00
|
|
|
|
2018-11-14 23:18:43 +03:00
|
|
|
list<std::string> InputNames(Positional, desc("compiled_swift_file1.o ..."),
|
|
|
|
OneOrMore, cat(Visible));
|
2015-03-12 05:00:56 +03:00
|
|
|
|
2018-11-14 23:18:43 +03:00
|
|
|
opt<bool> DumpModule(
|
|
|
|
"dump-module",
|
|
|
|
desc("Dump the imported module after checking it imports just fine"),
|
|
|
|
cat(Visible));
|
2018-03-16 00:49:48 +03:00
|
|
|
|
2018-11-14 23:18:43 +03:00
|
|
|
opt<bool> Verbose("verbose", desc("Dump informations on the loaded module"),
|
|
|
|
cat(Visible));
|
2015-03-12 05:00:56 +03:00
|
|
|
|
2018-11-14 23:18:43 +03:00
|
|
|
opt<std::string> ModuleCachePath(
|
|
|
|
"module-cache-path", desc("Clang module cache path"), cat(Visible));
|
2018-03-22 20:47:24 +03:00
|
|
|
|
2018-11-14 23:18:43 +03:00
|
|
|
opt<std::string> DumpDeclFromMangled(
|
|
|
|
"decl-from-mangled", desc("dump decl from mangled names list"),
|
|
|
|
cat(Visible));
|
2018-03-15 21:45:56 +03:00
|
|
|
|
2018-11-14 23:18:43 +03:00
|
|
|
opt<std::string> DumpTypeFromMangled(
|
|
|
|
"type-from-mangled", desc("dump type from mangled names list"),
|
|
|
|
cat(Visible));
|
2018-06-26 09:03:32 +03:00
|
|
|
|
2018-11-14 23:18:43 +03:00
|
|
|
opt<std::string> ResourceDir(
|
|
|
|
"resource-dir",
|
|
|
|
desc("The directory that holds the compiler resource files"),
|
|
|
|
cat(Visible));
|
|
|
|
|
2019-08-16 02:32:48 +03:00
|
|
|
opt<bool> DummyDWARFImporter(
|
|
|
|
"dummy-dwarfimporter",
|
|
|
|
desc("Install a dummy DWARFImporterDelegate"), cat(Visible));
|
|
|
|
|
2018-11-14 23:18:43 +03:00
|
|
|
ParseCommandLineOptions(argc, argv);
|
Experimental: Extend ClangImporter to import clang modules from DWARF
When debugging Objective-C or C++ code on Darwin, the debug info
collected by dsymutil in the .dSYM bundle is entirely
self-contained. It is possible to debug a program, set breakpoints and
print variables even without having the complete original source code
or a matching SDK available. With Swift, this is currently not the
case. Even though .dSYM bundles contain the binary .swiftmodule for
all Swift modules, any Clang modules that the Swift modules depend on,
still need to be imported from source to even get basic LLDB
functionality to work. If ClangImporter fails to import a Clang
module, effectively the entire Swift module depending on it gets
poisoned.
This patch is addressing this issue by introducing a ModuleLoader that
can ask queries about Clang Decls to LLDB, since LLDB knows how to
reconstruct Clang decls from DWARF and clang -gmodules producxes full
debug info for Clang modules that is embedded into the .dSYM budle.
This initial version does not contain any advanced functionality at
all, it merely produces an empty ModuleDecl. Intertestingly, even this
is a considerable improvement over the status quo. LLDB can now print
Swift-only variables in modules with failing Clang depenecies, and
becuase of fallback mechanisms that were implemented earlier, it can
even display the contents of pure Objective-C objects that are
imported into Swift. C structs obviously don't work yet.
rdar://problem/36032653
2018-11-15 00:56:06 +03:00
|
|
|
|
2015-03-12 05:00:56 +03:00
|
|
|
// Unregister our options so they don't interfere with the command line
|
|
|
|
// parsing in CodeGen/BackendUtil.cpp.
|
|
|
|
ModuleCachePath.removeArgument();
|
|
|
|
DumpModule.removeArgument();
|
2018-03-15 21:45:56 +03:00
|
|
|
DumpTypeFromMangled.removeArgument();
|
2015-03-12 05:00:56 +03:00
|
|
|
InputNames.removeArgument();
|
2013-08-29 04:57:05 +04:00
|
|
|
|
2018-04-17 21:22:15 +03:00
|
|
|
auto validateInputFile = [](std::string Filename) {
|
|
|
|
if (Filename.empty())
|
|
|
|
return true;
|
|
|
|
if (!llvm::sys::fs::exists(llvm::Twine(Filename))) {
|
2018-12-21 05:37:55 +03:00
|
|
|
llvm::errs() << Filename << " does not exist, exiting.\n";
|
2018-04-17 21:22:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!llvm::sys::fs::is_regular_file(llvm::Twine(Filename))) {
|
|
|
|
llvm::errs() << Filename << " is not a regular file, exiting.\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!validateInputFile(DumpTypeFromMangled))
|
|
|
|
return 1;
|
|
|
|
if (!validateInputFile(DumpDeclFromMangled))
|
|
|
|
return 1;
|
|
|
|
|
2018-03-31 04:04:02 +03:00
|
|
|
// Fetch the serialized module bitstreams from the Mach-O files and
|
|
|
|
// register them with the module loader.
|
|
|
|
llvm::SmallVector<std::pair<char *, uint64_t>, 8> Modules;
|
|
|
|
if (!collectASTModules(InputNames, Modules))
|
|
|
|
return 1;
|
|
|
|
|
2018-04-02 23:05:34 +03:00
|
|
|
if (Modules.empty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
swift::serialization::ValidationInfo info;
|
|
|
|
swift::serialization::ExtendedValidationInfo extendedInfo;
|
2018-03-31 04:04:02 +03:00
|
|
|
for (auto &Module : Modules) {
|
2019-05-08 21:34:21 +03:00
|
|
|
info = {};
|
|
|
|
extendedInfo = {};
|
2018-04-02 23:05:34 +03:00
|
|
|
if (!validateModule(StringRef(Module.first, Module.second), Verbose, info,
|
|
|
|
extendedInfo)) {
|
2018-03-31 04:04:02 +03:00
|
|
|
llvm::errs() << "Malformed module!\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-29 04:57:05 +04:00
|
|
|
// Create a Swift compiler.
|
2013-09-03 22:09:53 +04:00
|
|
|
llvm::SmallVector<std::string, 4> modules;
|
2013-08-29 04:57:05 +04:00
|
|
|
swift::CompilerInstance CI;
|
|
|
|
swift::CompilerInvocation Invocation;
|
|
|
|
|
|
|
|
Invocation.setMainExecutablePath(
|
|
|
|
llvm::sys::fs::getMainExecutable(argv[0],
|
|
|
|
reinterpret_cast<void *>(&anchorForGetMainExecutable)));
|
|
|
|
|
2018-04-02 23:05:34 +03:00
|
|
|
// Infer SDK and Target triple from the module.
|
2019-05-08 21:34:21 +03:00
|
|
|
if (!extendedInfo.getSDKPath().empty())
|
|
|
|
Invocation.setSDKPath(extendedInfo.getSDKPath());
|
2018-04-02 23:05:34 +03:00
|
|
|
Invocation.setTargetTriple(info.targetTriple);
|
2018-03-23 23:13:26 +03:00
|
|
|
|
2013-08-29 04:57:05 +04:00
|
|
|
Invocation.setModuleName("lldbtest");
|
2014-03-12 04:27:24 +04:00
|
|
|
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
|
2019-04-20 01:18:19 +03:00
|
|
|
Invocation.getLangOptions().EnableMemoryBufferImporter = true;
|
2013-08-29 04:57:05 +04:00
|
|
|
|
2018-06-26 09:03:32 +03:00
|
|
|
if (!ResourceDir.empty()) {
|
|
|
|
Invocation.setRuntimeResourcePath(ResourceDir);
|
|
|
|
}
|
|
|
|
|
2019-05-08 21:34:21 +03:00
|
|
|
if (CI.setup(Invocation)) {
|
|
|
|
llvm::errs() << "error: Failed setup invocation!\n";
|
2013-08-29 04:57:05 +04:00
|
|
|
return 1;
|
2019-05-08 21:34:21 +03:00
|
|
|
}
|
2013-08-29 04:57:05 +04:00
|
|
|
|
2019-08-16 02:32:48 +03:00
|
|
|
swift::DWARFImporterDelegate dummyDWARFImporter;
|
|
|
|
if (DummyDWARFImporter) {
|
|
|
|
auto *ClangImporter = static_cast<swift::ClangImporter *>(
|
|
|
|
CI.getASTContext().getClangModuleLoader());
|
|
|
|
ClangImporter->setDWARFImporterDelegate(dummyDWARFImporter);
|
|
|
|
}
|
|
|
|
|
2018-03-31 04:04:02 +03:00
|
|
|
for (auto &Module : Modules)
|
2019-04-20 01:18:19 +03:00
|
|
|
if (!parseASTSection(*CI.getMemoryBufferSerializedModuleLoader(),
|
2019-05-08 21:34:21 +03:00
|
|
|
StringRef(Module.first, Module.second), modules)) {
|
|
|
|
llvm::errs() << "error: Failed to parse AST section!\n";
|
2018-03-31 04:04:02 +03:00
|
|
|
return 1;
|
2019-05-08 21:34:21 +03:00
|
|
|
}
|
2013-08-29 04:57:05 +04:00
|
|
|
|
|
|
|
// Attempt to import all modules we found.
|
|
|
|
for (auto path : modules) {
|
2018-03-16 00:49:48 +03:00
|
|
|
if (Verbose)
|
|
|
|
llvm::outs() << "Importing " << path << "... ";
|
2013-08-29 04:57:05 +04:00
|
|
|
|
|
|
|
#ifdef SWIFT_SUPPORTS_SUBMODULES
|
|
|
|
std::vector<std::pair<swift::Identifier, swift::SourceLoc> > AccessPath;
|
|
|
|
for (auto i = llvm::sys::path::begin(path);
|
2013-08-29 22:46:56 +04:00
|
|
|
i != llvm::sys::path::end(path); ++i)
|
2013-08-29 04:57:05 +04:00
|
|
|
if (!llvm::sys::path::is_separator((*i)[0]))
|
|
|
|
AccessPath.push_back({ CI.getASTContext().getIdentifier(*i),
|
|
|
|
swift::SourceLoc() });
|
|
|
|
#else
|
|
|
|
std::vector<std::pair<swift::Identifier, swift::SourceLoc> > AccessPath;
|
|
|
|
AccessPath.push_back({ CI.getASTContext().getIdentifier(path),
|
|
|
|
swift::SourceLoc() });
|
|
|
|
#endif
|
|
|
|
|
2013-09-03 22:09:53 +04:00
|
|
|
auto Module = CI.getASTContext().getModule(AccessPath);
|
2013-08-29 04:57:05 +04:00
|
|
|
if (!Module) {
|
2018-03-16 00:49:48 +03:00
|
|
|
if (Verbose)
|
|
|
|
llvm::errs() << "FAIL!\n";
|
2013-08-29 04:57:05 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2018-03-16 00:49:48 +03:00
|
|
|
if (Verbose)
|
|
|
|
llvm::outs() << "ok!\n";
|
2014-02-01 05:22:04 +04:00
|
|
|
if (DumpModule) {
|
2014-02-01 05:24:05 +04:00
|
|
|
llvm::SmallVector<swift::Decl*, 10> Decls;
|
2014-02-01 05:22:04 +04:00
|
|
|
Module->getTopLevelDecls(Decls);
|
|
|
|
for (auto Decl : Decls) {
|
|
|
|
Decl->dump(llvm::outs());
|
|
|
|
}
|
|
|
|
}
|
2018-03-15 21:45:56 +03:00
|
|
|
if (!DumpTypeFromMangled.empty()) {
|
|
|
|
llvm::SmallVector<std::string, 8> MangledNames;
|
2018-03-22 19:03:08 +03:00
|
|
|
collectMangledNames(DumpTypeFromMangled, MangledNames);
|
|
|
|
resolveTypeFromMangledNameList(CI.getASTContext(), MangledNames);
|
2018-03-15 21:45:56 +03:00
|
|
|
}
|
2018-03-22 20:47:24 +03:00
|
|
|
if (!DumpDeclFromMangled.empty()) {
|
|
|
|
llvm::SmallVector<std::string, 8> MangledNames;
|
|
|
|
collectMangledNames(DumpDeclFromMangled, MangledNames);
|
|
|
|
resolveDeclFromMangledNameList(CI.getASTContext(), MangledNames);
|
|
|
|
}
|
2013-08-29 04:57:05 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|