Files
swift-mirror/lib/TBDGen/TBDGenRequests.cpp
Hamish Knight 586e586af2 Add top-level request for TBDGen
Introduce `GenerateTBDRequest` which outputs the
interface file along with a set of public symbols.
2020-02-13 21:52:45 -08:00

81 lines
2.7 KiB
C++

//===--- TBDGenRequests.cpp - Requests for TBD Generation ----------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2020 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
#include "swift/AST/TBDGenRequests.h"
#include "swift/AST/Evaluator.h"
#include "swift/AST/FileUnit.h"
#include "swift/AST/Module.h"
#include "swift/Subsystems.h"
#include "swift/TBDGen/TBDGen.h"
#include "llvm/TextAPI/MachO/InterfaceFile.h"
using namespace swift;
namespace swift {
// Implement the TBDGen type zone (zone 14).
#define SWIFT_TYPEID_ZONE TBDGen
#define SWIFT_TYPEID_HEADER "swift/AST/TBDGenTypeIDZone.def"
#include "swift/Basic/ImplementTypeIDZone.h"
#undef SWIFT_TYPEID_ZONE
#undef SWIFT_TYPEID_HEADER
} // end namespace swift
//----------------------------------------------------------------------------//
// GenerateTBDRequest computation.
//----------------------------------------------------------------------------//
FileUnit *TBDGenDescriptor::getSingleFile() const {
return Input.dyn_cast<FileUnit *>();
}
ModuleDecl *TBDGenDescriptor::getParentModule() const {
if (auto *module = Input.dyn_cast<ModuleDecl *>())
return module;
return Input.get<FileUnit *>()->getParentModule();
}
bool TBDGenDescriptor::operator==(const TBDGenDescriptor &other) const {
return Input == other.Input && Opts == other.Opts;
}
llvm::hash_code swift::hash_value(const TBDGenDescriptor &desc) {
return llvm::hash_combine(desc.getFileOrModule(), desc.getOptions());
}
void swift::simple_display(llvm::raw_ostream &out,
const TBDGenDescriptor &desc) {
out << "Generate TBD for ";
if (auto *module = desc.getFileOrModule().dyn_cast<ModuleDecl *>()) {
out << "module ";
simple_display(out, module);
} else {
out << "file ";
simple_display(out, desc.getFileOrModule().get<FileUnit *>());
}
}
SourceLoc swift::extractNearestSourceLoc(const TBDGenDescriptor &desc) {
return extractNearestSourceLoc(desc.getFileOrModule());
}
// Define request evaluation functions for each of the TBDGen requests.
static AbstractRequestFunction *tbdGenRequestFunctions[] = {
#define SWIFT_REQUEST(Zone, Name, Sig, Caching, LocOptions) \
reinterpret_cast<AbstractRequestFunction *>(&Name::evaluateRequest),
#include "swift/AST/TBDGenTypeIDZone.def"
#undef SWIFT_REQUEST
};
void swift::registerTBDGenRequestFunctions(Evaluator &evaluator) {
evaluator.registerRequestFunctions(Zone::TBDGen, tbdGenRequestFunctions);
}