Skip to content

Commit 51dae9d

Browse files
authored
Merge pull request swiftlang#14933 from compnerd/SwiftRemoteMirror
SwiftRemoteMirror: annotate public interfaces
2 parents 8e84201 + fbf646a commit 51dae9d

File tree

4 files changed

+103
-37
lines changed

4 files changed

+103
-37
lines changed
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
set(swift_remote_mirror_headers)
22
list(APPEND swift_remote_mirror_headers
3-
"MemoryReaderInterface.h"
4-
"SwiftRemoteMirror.h"
5-
"SwiftRemoteMirrorTypes.h")
3+
MemoryReaderInterface.h
4+
Platform.h
5+
SwiftRemoteMirror.h
6+
SwiftRemoteMirrorTypes.h)
67
swift_install_in_component("swift-remote-mirror-headers"
7-
FILES ${swift_remote_mirror_headers}
8-
DESTINATION "include/swift/SwiftRemoteMirror")
8+
FILES
9+
${swift_remote_mirror_headers}
10+
DESTINATION
11+
"include/swift/SwiftRemoteMirror")
912

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===-- SwiftRemoteMirror/Platform.h - Remote Mirror Platform --*-- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_REMOTE_MIRROR_PLATFORM_H
14+
#define SWIFT_REMOTE_MIRROR_PLATFORM_H
15+
16+
#if defined(__cplusplus)
17+
extern "C" {
18+
#endif
19+
20+
#if defined(swiftRemoteMirror_EXPORTS)
21+
# if defined(__ELF__)
22+
# define SWIFT_REMOTE_MIRROR_LINKAGE __attribute__((__visibility__("protected")))
23+
# elif defined(__MACH__)
24+
# define SWIFT_REMOTE_MIRROR_LINKAGE __attribute__((__visibility__("default")))
25+
# else
26+
# define SWIFT_REMOTE_MIRROR_LINKAGE __declspec(dllexport)
27+
# endif
28+
#else
29+
# if defined(__ELF__)
30+
# define SWIFT_REMOTE_MIRROR_LINKAGE __attribute__((__visibility__("default")))
31+
# elif defined(__MACH__)
32+
# define SWIFT_REMOTE_MIRROR_LINKAGE __attribute__((__visibility__("default")))
33+
# else
34+
# define SWIFT_REMOTE_MIRROR_LINKAGE __declspec(dllimport)
35+
# endif
36+
#endif
37+
38+
#if defined(__cplusplus)
39+
}
40+
#endif
41+
42+
#endif
43+
44+
45+

include/swift/SwiftRemoteMirror/SwiftRemoteMirror.h

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#ifndef SWIFT_REFLECTION_SWIFT_REFLECTION_H
2121
#define SWIFT_REFLECTION_SWIFT_REFLECTION_H
2222

23+
#include "Platform.h"
2324
#include "MemoryReaderInterface.h"
2425
#include "SwiftRemoteMirrorTypes.h"
2526

@@ -37,41 +38,42 @@ extern "C" {
3738
#endif
3839

3940
/// Get the metadata version supported by the Remote Mirror library.
40-
uint16_t
41-
swift_reflection_getSupportedMetadataVersion();
41+
SWIFT_REMOTE_MIRROR_LINKAGE
42+
uint16_t swift_reflection_getSupportedMetadataVersion();
4243

4344
/// \returns An opaque reflection context.
45+
SWIFT_REMOTE_MIRROR_LINKAGE
4446
SwiftReflectionContextRef
45-
swift_reflection_createReflectionContext(
46-
void *ReaderContext,
47-
PointerSizeFunction getPointerSize,
48-
SizeSizeFunction getSizeSize,
49-
ReadBytesFunction readBytes,
50-
GetStringLengthFunction getStringLength,
51-
GetSymbolAddressFunction getSymbolAddress);
47+
swift_reflection_createReflectionContext(void *ReaderContext,
48+
PointerSizeFunction getPointerSize,
49+
SizeSizeFunction getSizeSize,
50+
ReadBytesFunction readBytes,
51+
GetStringLengthFunction getStringLength,
52+
GetSymbolAddressFunction getSymbolAddress);
5253

5354
/// Destroys an opaque reflection context.
55+
SWIFT_REMOTE_MIRROR_LINKAGE
5456
void
5557
swift_reflection_destroyReflectionContext(SwiftReflectionContextRef Context);
5658

5759
/// Add reflection sections for a loaded Swift image.
58-
void
59-
swift_reflection_addReflectionInfo(SwiftReflectionContextRef ContextRef,
60-
swift_reflection_info_t Info);
61-
60+
SWIFT_REMOTE_MIRROR_LINKAGE
61+
void swift_reflection_addReflectionInfo(SwiftReflectionContextRef ContextRef,
62+
swift_reflection_info_t Info);
6263

6364
/// Returns a boolean indicating if the isa mask was successfully
6465
/// read, in which case it is stored in the isaMask out parameter.
65-
int
66-
swift_reflection_readIsaMask(SwiftReflectionContextRef ContextRef,
67-
uintptr_t *outIsaMask);
66+
SWIFT_REMOTE_MIRROR_LINKAGE
67+
int swift_reflection_readIsaMask(SwiftReflectionContextRef ContextRef,
68+
uintptr_t *outIsaMask);
6869

6970
/// Returns an opaque type reference for a metadata pointer, or
7071
/// NULL if one can't be constructed.
7172
///
7273
/// This function loses information; in particular, passing the
7374
/// result to swift_reflection_infoForTypeRef() will not give
7475
/// the same result as calling swift_reflection_infoForMetadata().
76+
SWIFT_REMOTE_MIRROR_LINKAGE
7577
swift_typeref_t
7678
swift_reflection_typeRefForMetadata(SwiftReflectionContextRef ContextRef,
7779
uintptr_t Metadata);
@@ -82,59 +84,66 @@ swift_reflection_typeRefForMetadata(SwiftReflectionContextRef ContextRef,
8284
/// This function loses information; in particular, passing the
8385
/// result to swift_reflection_infoForTypeRef() will not give
8486
/// the same result as calling swift_reflection_infoForInstance().
87+
SWIFT_REMOTE_MIRROR_LINKAGE
8588
swift_typeref_t
8689
swift_reflection_typeRefForInstance(SwiftReflectionContextRef ContextRef,
8790
uintptr_t Object);
8891

8992
/// Returns a typeref from a mangled type name string.
93+
SWIFT_REMOTE_MIRROR_LINKAGE
9094
swift_typeref_t
9195
swift_reflection_typeRefForMangledTypeName(SwiftReflectionContextRef ContextRef,
9296
const char *MangledName,
9397
uint64_t Length);
9498

9599
/// Returns a structure describing the layout of a value of a typeref.
96100
/// For classes, this returns the reference value itself.
101+
SWIFT_REMOTE_MIRROR_LINKAGE
97102
swift_typeinfo_t
98103
swift_reflection_infoForTypeRef(SwiftReflectionContextRef ContextRef,
99104
swift_typeref_t OpaqueTypeRef);
100105

101106
/// Returns the information about a child field of a value by index.
107+
SWIFT_REMOTE_MIRROR_LINKAGE
102108
swift_childinfo_t
103109
swift_reflection_childOfTypeRef(SwiftReflectionContextRef ContextRef,
104-
swift_typeref_t OpaqueTypeRef,
105-
unsigned Index);
110+
swift_typeref_t OpaqueTypeRef, unsigned Index);
106111

107112
/// Returns a structure describing the layout of a class instance
108113
/// from the isa pointer of a class.
114+
SWIFT_REMOTE_MIRROR_LINKAGE
109115
swift_typeinfo_t
110116
swift_reflection_infoForMetadata(SwiftReflectionContextRef ContextRef,
111117
uintptr_t Metadata);
112118

113119
/// Returns the information about a child field of a class instance
114120
/// by index.
121+
SWIFT_REMOTE_MIRROR_LINKAGE
115122
swift_childinfo_t
116123
swift_reflection_childOfMetadata(SwiftReflectionContextRef ContextRef,
117-
uintptr_t Metadata,
118-
unsigned Index);
124+
uintptr_t Metadata, unsigned Index);
119125

120126
/// Returns a structure describing the layout of a class or closure
121127
/// context instance, from a pointer to the object itself.
128+
SWIFT_REMOTE_MIRROR_LINKAGE
122129
swift_typeinfo_t
123130
swift_reflection_infoForInstance(SwiftReflectionContextRef ContextRef,
124131
uintptr_t Object);
125132

126133
/// Returns the information about a child field of a class or closure
127134
/// context instance.
135+
SWIFT_REMOTE_MIRROR_LINKAGE
128136
swift_childinfo_t
129137
swift_reflection_childOfInstance(SwiftReflectionContextRef ContextRef,
130-
uintptr_t Object,
131-
unsigned Index);
138+
uintptr_t Object, unsigned Index);
132139

133140
/// Returns the number of generic arguments of a typeref.
141+
SWIFT_REMOTE_MIRROR_LINKAGE
134142
unsigned
135143
swift_reflection_genericArgumentCountOfTypeRef(swift_typeref_t OpaqueTypeRef);
136144

137145
/// Returns a fully instantiated typeref for a generic argument by index.
146+
SWIFT_REMOTE_MIRROR_LINKAGE
138147
swift_typeref_t
139148
swift_reflection_genericArgumentOfTypeRef(swift_typeref_t OpaqueTypeRef,
140149
unsigned Index);
@@ -158,24 +167,29 @@ swift_reflection_genericArgumentOfTypeRef(swift_typeref_t OpaqueTypeRef,
158167
///
159168
/// Returns true if InstanceTypeRef and StartOfInstanceData contain valid
160169
/// valid values.
170+
SWIFT_REMOTE_MIRROR_LINKAGE
161171
int swift_reflection_projectExistential(SwiftReflectionContextRef ContextRef,
162172
swift_addr_t ExistentialAddress,
163173
swift_typeref_t ExistentialTypeRef,
164174
swift_typeref_t *OutInstanceTypeRef,
165175
swift_addr_t *OutStartOfInstanceData);
166176

167177
/// Dump a brief description of the typeref as a tree to stderr.
178+
SWIFT_REMOTE_MIRROR_LINKAGE
168179
void swift_reflection_dumpTypeRef(swift_typeref_t OpaqueTypeRef);
169180

170181
/// Dump information about the layout for a typeref.
182+
SWIFT_REMOTE_MIRROR_LINKAGE
171183
void swift_reflection_dumpInfoForTypeRef(SwiftReflectionContextRef ContextRef,
172184
swift_typeref_t OpaqueTypeRef);
173185

174186
/// Dump information about the layout of a class instance from its isa pointer.
187+
SWIFT_REMOTE_MIRROR_LINKAGE
175188
void swift_reflection_dumpInfoForMetadata(SwiftReflectionContextRef ContextRef,
176189
uintptr_t Metadata);
177190

178191
/// Dump information about the layout of a class or closure context instance.
192+
SWIFT_REMOTE_MIRROR_LINKAGE
179193
void swift_reflection_dumpInfoForInstance(SwiftReflectionContextRef ContextRef,
180194
uintptr_t Object);
181195

@@ -186,10 +200,9 @@ void swift_reflection_dumpInfoForInstance(SwiftReflectionContextRef ContextRef,
186200
///
187201
/// Returns the length of the demangled string this function tried to copy
188202
/// into `OutDemangledName`.
189-
size_t swift_reflection_demangle(const char *MangledName,
190-
size_t Length,
191-
char *OutDemangledName,
192-
size_t MaxLength);
203+
SWIFT_REMOTE_MIRROR_LINKAGE
204+
size_t swift_reflection_demangle(const char *MangledName, size_t Length,
205+
char *OutDemangledName, size_t MaxLength);
193206

194207
#ifdef __cplusplus
195208
} // extern "C"

stdlib/public/SwiftRemoteMirror/CMakeLists.txt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@ string(REGEX REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_
44
# libswiftRemoteMirror.dylib should not have runtime dependencies; it's
55
# always built as a shared library.
66
if(SWIFT_BUILD_DYNAMIC_STDLIB OR SWIFT_BUILD_REMOTE_MIRROR)
7-
add_swift_library(swiftRemoteMirror SHARED TARGET_LIBRARY DONT_EMBED_BITCODE NOSWIFTRT
8-
SwiftRemoteMirror.cpp
9-
LINK_LIBRARIES swiftReflection
10-
C_COMPILE_FLAGS ${SWIFT_RUNTIME_CXX_FLAGS}
11-
LINK_FLAGS ${SWIFT_RUNTIME_LINK_FLAGS}
12-
INSTALL_IN_COMPONENT swift-remote-mirror)
7+
add_swift_library(swiftRemoteMirror
8+
SHARED TARGET_LIBRARY DONT_EMBED_BITCODE NOSWIFTRT
9+
SwiftRemoteMirror.cpp
10+
LINK_LIBRARIES
11+
swiftReflection
12+
C_COMPILE_FLAGS
13+
${SWIFT_RUNTIME_CXX_FLAGS} -DswiftRemoteMirror_EXPORTS
14+
LINK_FLAGS
15+
${SWIFT_RUNTIME_LINK_FLAGS}
16+
INSTALL_IN_COMPONENT
17+
swift-remote-mirror)
1318
endif()

0 commit comments

Comments
 (0)