Files
swift-mirror/lib/ASTSectionImporter/ASTSectionImporter.cpp
Jordan Rose 2c13b2e6fe Remove SwiftASTStreamerPass and the LegacyDebugInfo option.
Finishes the removal of the old "wrapped" module section that was made
unnecessary in r12922/3. Now that we no longer use the old compiler, we
don't need this at all. That also removes the need for SwiftTargetMachine.

No functionality change; this was all dead code.

Swift SVN r14758
2014-03-06 22:05:03 +00:00

69 lines
2.2 KiB
C++

//===--- ASTSectionImporter.cpp - Import AST Section Modules --------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file implements support for loading modules serialized into a
// Mach-O AST section into Swift.
//
//===----------------------------------------------------------------------===//
#include "swift/ASTSectionImporter/ASTSectionImporter.h"
#include "swift/Basic/Dwarf.h"
#include "swift/Serialization/SerializedModuleLoader.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
using namespace swift;
bool swift::parseASTSection(SerializedModuleLoader *SML, StringRef buf,
SmallVectorImpl<std::string> &foundModules) {
if (!SerializedModuleLoader::isSerializedAST(buf))
return false;
// An AST section consists of one or more AST modules, optionally with
// headers. Iterate over all AST modules.
while (!buf.empty()) {
auto info = SerializedModuleLoader::validateSerializedAST(buf);
assert(info.name.size() < (2 << 10) && "name failed sanity check");
if (info.status == ModuleStatus::Valid) {
assert(info.bytes != 0);
if (!info.name.empty()) {
StringRef moduleData = buf.substr(0, info.bytes);
std::unique_ptr<llvm::MemoryBuffer> bitstream(
llvm::MemoryBuffer::getMemBuffer(moduleData, info.name, false));
// Register the memory buffer.
SML->registerMemoryBuffer(info.name, std::move(bitstream));
foundModules.push_back(info.name);
}
} else {
llvm::dbgs() << "Unable to load module";
if (!info.name.empty())
llvm::dbgs() << '\'' << info.name << '\'';
llvm::dbgs() << ".\n";
}
if (info.bytes == 0)
return false;
if (info.bytes > buf.size()) {
llvm::dbgs() << "AST section too small.\n";
return false;
}
buf = buf.substr(info.bytes);
}
return true;
}