mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #35429 from ahoppen/remove-bytetree
Remove ByteTree serialization format
This commit is contained in:
@@ -155,21 +155,6 @@ OmitNodeIds("omit-node-ids",
|
||||
llvm::cl::desc("If specified, the serialized syntax tree will not "
|
||||
"include the IDs of the serialized nodes."));
|
||||
|
||||
static llvm::cl::opt<bool>
|
||||
SerializeAsByteTree("serialize-byte-tree",
|
||||
llvm::cl::desc("If specified the syntax tree will be "
|
||||
"serialized in the ByteTree format instead "
|
||||
"of JSON."));
|
||||
|
||||
static llvm::cl::opt<bool>
|
||||
AddByteTreeFields("add-bytetree-fields",
|
||||
llvm::cl::desc("If specified, further fields will be added "
|
||||
"to the syntax tree if it is serialized as a "
|
||||
"ByteTree. This is to test forward "
|
||||
"compatibility with future versions of "
|
||||
"SwiftSyntax that might add more fields to "
|
||||
"syntax nodes."));
|
||||
|
||||
static llvm::cl::opt<bool>
|
||||
IncrementalSerialization("incremental-serialization",
|
||||
llvm::cl::desc("If specified, the serialized syntax "
|
||||
@@ -747,56 +732,28 @@ int doSerializeRawTree(const char *MainExecutablePath,
|
||||
ReusedNodeIds = SyntaxCache->getReusedNodeIds();
|
||||
}
|
||||
|
||||
if (options::SerializeAsByteTree) {
|
||||
if (options::OutputFilename.empty()) {
|
||||
llvm::errs() << "Cannot serialize syntax tree as ByteTree to stdout\n";
|
||||
return EXIT_FAILURE;
|
||||
auto SerializeTree = [&ReusedNodeIds](llvm::raw_ostream &os,
|
||||
RC<RawSyntax> Root,
|
||||
SyntaxParsingCache *SyntaxCache) {
|
||||
swift::json::Output::UserInfoMap JsonUserInfo;
|
||||
JsonUserInfo[swift::json::OmitNodesUserInfoKey] = &ReusedNodeIds;
|
||||
if (options::OmitNodeIds) {
|
||||
JsonUserInfo[swift::json::DontSerializeNodeIdsUserInfoKey] =
|
||||
(void *)true;
|
||||
}
|
||||
swift::json::Output out(os, JsonUserInfo);
|
||||
out << *Root;
|
||||
os << "\n";
|
||||
};
|
||||
|
||||
auto Stream = ExponentialGrowthAppendingBinaryByteStream();
|
||||
Stream.reserve(32 * 1024);
|
||||
std::map<void *, void *> UserInfo;
|
||||
UserInfo[swift::byteTree::UserInfoKeyReusedNodeIds] = &ReusedNodeIds;
|
||||
if (options::AddByteTreeFields) {
|
||||
UserInfo[swift::byteTree::UserInfoKeyAddInvalidFields] = (void *)true;
|
||||
}
|
||||
swift::byteTree::ByteTreeWriter::write(Stream,
|
||||
byteTree::SYNTAX_TREE_VERSION,
|
||||
*Root, UserInfo);
|
||||
auto OutputBufferOrError = llvm::FileOutputBuffer::create(
|
||||
options::OutputFilename, Stream.data().size());
|
||||
assert(OutputBufferOrError && "Couldn't open output file");
|
||||
auto &OutputBuffer = OutputBufferOrError.get();
|
||||
memcpy(OutputBuffer->getBufferStart(), Stream.data().data(),
|
||||
Stream.data().size());
|
||||
auto Error = OutputBuffer->commit();
|
||||
(void)Error;
|
||||
assert(!Error && "Unable to write output file");
|
||||
if (!options::OutputFilename.empty()) {
|
||||
std::error_code errorCode;
|
||||
llvm::raw_fd_ostream os(options::OutputFilename, errorCode,
|
||||
llvm::sys::fs::F_None);
|
||||
assert(!errorCode && "Couldn't open output file");
|
||||
SerializeTree(os, Root, SyntaxCache);
|
||||
} else {
|
||||
// Serialize as JSON
|
||||
auto SerializeTree = [&ReusedNodeIds](llvm::raw_ostream &os,
|
||||
RC<RawSyntax> Root,
|
||||
SyntaxParsingCache *SyntaxCache) {
|
||||
swift::json::Output::UserInfoMap JsonUserInfo;
|
||||
JsonUserInfo[swift::json::OmitNodesUserInfoKey] = &ReusedNodeIds;
|
||||
if (options::OmitNodeIds) {
|
||||
JsonUserInfo[swift::json::DontSerializeNodeIdsUserInfoKey] =
|
||||
(void *)true;
|
||||
}
|
||||
swift::json::Output out(os, JsonUserInfo);
|
||||
out << *Root;
|
||||
os << "\n";
|
||||
};
|
||||
|
||||
if (!options::OutputFilename.empty()) {
|
||||
std::error_code errorCode;
|
||||
llvm::raw_fd_ostream os(options::OutputFilename, errorCode,
|
||||
llvm::sys::fs::F_None);
|
||||
assert(!errorCode && "Couldn't open output file");
|
||||
SerializeTree(os, Root, SyntaxCache);
|
||||
} else {
|
||||
SerializeTree(llvm::outs(), Root, SyntaxCache);
|
||||
}
|
||||
SerializeTree(llvm::outs(), Root, SyntaxCache);
|
||||
}
|
||||
|
||||
if (!options::DiagsOutputFilename.empty()) {
|
||||
|
||||
Reference in New Issue
Block a user