Skip to content

Commit c16fed7

Browse files
committed
RemoteAST: Tweak swift-remoteast-test to reuse the context
I need this to reproduce a test failure.
1 parent c8effd2 commit c16fed7

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

tools/swift-remoteast-test/swift-remoteast-test.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,24 @@ using namespace swift::remoteAST;
4040
/// The context for the code we're running. Set by the observer.
4141
static ASTContext *Context = nullptr;
4242

43+
/// The RemoteAST for the code we're running.
44+
std::shared_ptr<MemoryReader> reader;
45+
std::unique_ptr<RemoteASTContext> remoteContext;
46+
47+
static RemoteASTContext &getRemoteASTContext() {
48+
if (remoteContext)
49+
return *remoteContext;
50+
51+
std::shared_ptr<MemoryReader> reader(new InProcessMemoryReader());
52+
remoteContext.reset(new RemoteASTContext(*Context, std::move(reader)));
53+
return *remoteContext;
54+
}
55+
4356
// FIXME: swiftcall
4457
/// func printType(forMetadata: Any.Type)
4558
LLVM_ATTRIBUTE_USED extern "C" void SWIFT_REMOTEAST_TEST_ABI
4659
printMetadataType(const Metadata *typeMetadata) {
47-
assert(Context && "context was not set");
48-
49-
std::shared_ptr<MemoryReader> reader(new InProcessMemoryReader());
50-
RemoteASTContext remoteAST(*Context, std::move(reader));
51-
60+
auto &remoteAST = getRemoteASTContext();
5261
auto &out = llvm::outs();
5362

5463
auto result =
@@ -66,11 +75,7 @@ printMetadataType(const Metadata *typeMetadata) {
6675
/// func printDynamicType(_: AnyObject)
6776
LLVM_ATTRIBUTE_USED extern "C" void SWIFT_REMOTEAST_TEST_ABI
6877
printHeapMetadataType(void *object) {
69-
assert(Context && "context was not set");
70-
71-
std::shared_ptr<MemoryReader> reader(new InProcessMemoryReader());
72-
RemoteASTContext remoteAST(*Context, std::move(reader));
73-
78+
auto &remoteAST = getRemoteASTContext();
7479
auto &out = llvm::outs();
7580

7681
auto metadataResult =
@@ -94,11 +99,7 @@ printHeapMetadataType(void *object) {
9499

95100
static void printMemberOffset(const Metadata *typeMetadata,
96101
StringRef memberName, bool passMetadata) {
97-
assert(Context && "context was not set");
98-
99-
std::shared_ptr<MemoryReader> reader(new InProcessMemoryReader());
100-
RemoteASTContext remoteAST(*Context, std::move(reader));
101-
102+
auto &remoteAST = getRemoteASTContext();
102103
auto &out = llvm::outs();
103104

104105
// The first thing we have to do is get the type.
@@ -147,10 +148,7 @@ printTypeMetadataMemberOffset(const Metadata *typeMetadata,
147148
LLVM_ATTRIBUTE_USED extern "C" void SWIFT_REMOTEAST_TEST_ABI
148149
printDynamicTypeAndAddressForExistential(void *object,
149150
const Metadata *typeMetadata) {
150-
assert(Context && "context was not set");
151-
std::shared_ptr<MemoryReader> reader(new InProcessMemoryReader());
152-
RemoteASTContext remoteAST(*Context, std::move(reader));
153-
151+
auto &remoteAST = getRemoteASTContext();
154152
auto &out = llvm::outs();
155153

156154
// First, retrieve the static type of the existential, so we can understand

0 commit comments

Comments
 (0)