Skip to content

Commit bc7b632

Browse files
committed
Replace the sil-nm binary with a symlink to swift-frontend
rdar://76551283
1 parent b6132d1 commit bc7b632

File tree

9 files changed

+91
-92
lines changed

9 files changed

+91
-92
lines changed

include/swift/Driver/Driver.h

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ class Driver {
168168
Batch, // swiftc
169169
SILOpt, // sil-opt
170170
SILFuncExtractor,// sil-func-extractor
171+
SILNM, // sil-nm
171172
AutolinkExtract, // swift-autolink-extract
172173
SwiftIndent, // swift-indent
173174
SymbolGraph, // swift-symbolgraph

lib/Driver/Driver.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ void Driver::parseDriverKind(ArrayRef<const char *> Args) {
101101
.Case("swiftc", DriverKind::Batch)
102102
.Case("sil-opt", DriverKind::SILOpt)
103103
.Case("sil-func-extractor", DriverKind::SILFuncExtractor)
104+
.Case("sil-nm", DriverKind::SILNM)
104105
.Case("swift-autolink-extract", DriverKind::AutolinkExtract)
105106
.Case("swift-indent", DriverKind::SwiftIndent)
106107
.Case("swift-symbolgraph-extract", DriverKind::SymbolGraph)
@@ -3559,6 +3560,7 @@ void Driver::printHelp(bool ShowHidden) const {
35593560
case DriverKind::Batch:
35603561
case DriverKind::SILOpt:
35613562
case DriverKind::SILFuncExtractor:
3563+
case DriverKind::SILNM:
35623564
case DriverKind::AutolinkExtract:
35633565
case DriverKind::SwiftIndent:
35643566
case DriverKind::SymbolGraph:

lib/DriverTool/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(driver_sources_and_options
22
driver.cpp
33
sil_opt_main.cpp
44
sil_func_extractor_main.cpp
5+
sil_nm_main.cpp
56
autolink_extract_main.cpp
67
modulewrap_main.cpp
78
swift_api_digester_main.cpp

lib/DriverTool/driver.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ extern int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr);
6969
/// Run 'sil-func-extractor'
7070
extern int sil_func_extractor_main(ArrayRef<const char *> argv, void *MainAddr);
7171

72+
/// Run 'sil-nm'
73+
extern int sil_nm_main(ArrayRef<const char *> argv, void *MainAddr);
74+
7275
/// Run 'swift-autolink-extract'.
7376
extern int autolink_extract_main(ArrayRef<const char *> Args, const char *Argv0,
7477
void *MainAddr);
@@ -291,6 +294,8 @@ static int run_driver(StringRef ExecName,
291294
return sil_opt_main(argv, (void *)(intptr_t)getExecutablePath);
292295
case Driver::DriverKind::SILFuncExtractor:
293296
return sil_func_extractor_main(argv, (void *)(intptr_t)getExecutablePath);
297+
case Driver::DriverKind::SILNM:
298+
return sil_nm_main(argv, (void *)(intptr_t)getExecutablePath);
294299
case Driver::DriverKind::AutolinkExtract:
295300
return autolink_extract_main(
296301
TheDriver.getArgsWithoutProgramNameAndDriverMode(argv),
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- SILNM.cpp --------------------------------------------------------===//
1+
//===--- sil_nm_main.cpp --------------------------------------------------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -46,52 +46,50 @@
4646

4747
using namespace swift;
4848

49-
static llvm::cl::opt<std::string> InputFilename(llvm::cl::desc("input file"),
50-
llvm::cl::init("-"),
51-
llvm::cl::Positional);
52-
53-
static llvm::cl::list<std::string>
54-
ImportPaths("I",
55-
llvm::cl::desc("add a directory to the import search path"));
56-
57-
static llvm::cl::opt<std::string>
58-
ModuleName("module-name",
59-
llvm::cl::desc("The name of the module if processing"
60-
" a module. Necessary for processing "
61-
"stdin."));
62-
63-
static llvm::cl::opt<bool>
64-
DemangleNames("demangle",
65-
llvm::cl::desc("Demangle names of entities outputted"));
66-
67-
static llvm::cl::opt<std::string>
68-
ModuleCachePath("module-cache-path",
69-
llvm::cl::desc("Clang module cache path"));
70-
71-
static llvm::cl::opt<std::string> ResourceDir(
72-
"resource-dir",
73-
llvm::cl::desc("The directory that holds the compiler resource files"));
74-
75-
static llvm::cl::opt<std::string>
76-
SDKPath("sdk", llvm::cl::desc("The path to the SDK for use with the clang "
77-
"importer."),
78-
llvm::cl::init(""));
79-
80-
static llvm::cl::opt<std::string> Triple("target",
81-
llvm::cl::desc("target triple"));
82-
83-
// This function isn't referenced outside its translation unit, but it
84-
// can't use the "static" keyword because its address is used for
85-
// getMainExecutable (since some platforms don't support taking the
86-
// address of main, and some platforms can't implement getMainExecutable
87-
// without being given the address of a function in the main executable).
88-
void anchorForGetMainExecutable() {}
89-
90-
static void printAndSortNames(std::vector<StringRef> &Names, char Code) {
49+
struct SILNMOptions {
50+
llvm::cl::opt<std::string>
51+
InputFilename = llvm::cl::opt<std::string>(llvm::cl::desc("input file"),
52+
llvm::cl::init("-"),
53+
llvm::cl::Positional);
54+
55+
llvm::cl::list<std::string>
56+
ImportPaths = llvm::cl::list<std::string>("I",
57+
llvm::cl::desc("add a directory to the import search path"));
58+
59+
llvm::cl::opt<std::string>
60+
ModuleName = llvm::cl::opt<std::string>("module-name",
61+
llvm::cl::desc("The name of the module if processing"
62+
" a module. Necessary for processing "
63+
"stdin."));
64+
65+
llvm::cl::opt<bool>
66+
DemangleNames = llvm::cl::opt<bool>("demangle",
67+
llvm::cl::desc("Demangle names of entities outputted"));
68+
69+
llvm::cl::opt<std::string>
70+
ModuleCachePath = llvm::cl::opt<std::string>("module-cache-path",
71+
llvm::cl::desc("Clang module cache path"));
72+
73+
llvm::cl::opt<std::string>
74+
ResourceDir = llvm::cl::opt<std::string>(
75+
"resource-dir",
76+
llvm::cl::desc("The directory that holds the compiler resource files"));
77+
78+
llvm::cl::opt<std::string>
79+
SDKPath = llvm::cl::opt<std::string>("sdk", llvm::cl::desc("The path to the SDK for use with the clang "
80+
"importer."),
81+
llvm::cl::init(""));
82+
83+
llvm::cl::opt<std::string>
84+
Triple = llvm::cl::opt<std::string>("target", llvm::cl::desc("target triple"));
85+
};
86+
87+
static void printAndSortNames(std::vector<StringRef> &Names, char Code,
88+
const SILNMOptions &options) {
9189
std::sort(Names.begin(), Names.end());
9290
for (StringRef N : Names) {
9391
llvm::outs() << Code << " ";
94-
if (DemangleNames) {
92+
if (options.DemangleNames) {
9593
llvm::outs() << swift::Demangle::demangleSymbolAsString(N);
9694
} else {
9795
llvm::outs() << N;
@@ -100,77 +98,78 @@ static void printAndSortNames(std::vector<StringRef> &Names, char Code) {
10098
}
10199
}
102100

103-
static void nmModule(SILModule *M) {
101+
static void nmModule(SILModule *M, const SILNMOptions &options) {
104102
{
105103
std::vector<StringRef> FuncNames;
106-
llvm::transform(*M, std::back_inserter(FuncNames),
107-
std::mem_fn(&SILFunction::getName));
108-
printAndSortNames(FuncNames, 'F');
104+
for (SILFunction &f : *M) {
105+
FuncNames.push_back(f.getName());
106+
}
107+
printAndSortNames(FuncNames, 'F', options);
109108
}
110109

111110
{
112111
std::vector<StringRef> GlobalNames;
113-
llvm::transform(M->getSILGlobals(), std::back_inserter(GlobalNames),
114-
std::mem_fn(&SILGlobalVariable::getName));
115-
printAndSortNames(GlobalNames, 'G');
112+
for (SILGlobalVariable &g : M->getSILGlobals()) {
113+
GlobalNames.push_back(g.getName());
114+
}
115+
printAndSortNames(GlobalNames, 'G', options);
116116
}
117117

118118
{
119119
std::vector<StringRef> WitnessTableNames;
120-
llvm::transform(M->getWitnessTables(),
121-
std::back_inserter(WitnessTableNames),
122-
std::mem_fn(&SILWitnessTable::getName));
123-
printAndSortNames(WitnessTableNames, 'W');
120+
for (SILWitnessTable &wt : M->getWitnessTables()) {
121+
WitnessTableNames.push_back(wt.getName());
122+
}
123+
printAndSortNames(WitnessTableNames, 'W', options);
124124
}
125125

126126
{
127127
std::vector<StringRef> VTableNames;
128-
llvm::transform(M->getVTables(), std::back_inserter(VTableNames),
129-
[](const SILVTable *VT) -> StringRef {
130-
return VT->getClass()->getName().str();
131-
});
132-
printAndSortNames(VTableNames, 'V');
128+
for (SILVTable *vt : M->getVTables()) {
129+
VTableNames.push_back(vt->getClass()->getName().str());
130+
}
131+
printAndSortNames(VTableNames, 'V', options);
133132
}
134133
}
135134

136-
int main(int argc, char **argv) {
137-
PROGRAM_START(argc, argv);
135+
int sil_nm_main(ArrayRef<const char *> argv, void *MainAddr) {
138136
INITIALIZE_LLVM();
139137

140-
llvm::cl::ParseCommandLineOptions(argc, argv, "SIL NM\n");
138+
SILNMOptions options;
139+
140+
llvm::cl::ParseCommandLineOptions(argv.size(), argv.data(), "SIL NM\n");
141141

142142
CompilerInvocation Invocation;
143143

144-
Invocation.setMainExecutablePath(llvm::sys::fs::getMainExecutable(
145-
argv[0], reinterpret_cast<void *>(&anchorForGetMainExecutable)));
144+
Invocation.setMainExecutablePath(llvm::sys::fs::getMainExecutable(argv[0], MainAddr));
146145

147146
// Give the context the list of search paths to use for modules.
148-
Invocation.setImportSearchPaths(ImportPaths);
147+
Invocation.setImportSearchPaths(options.ImportPaths);
149148
// Set the SDK path and target if given.
150-
if (SDKPath.getNumOccurrences() == 0) {
149+
if (options.SDKPath.getNumOccurrences() == 0) {
151150
const char *SDKROOT = getenv("SDKROOT");
152151
if (SDKROOT)
153-
SDKPath = SDKROOT;
152+
options.SDKPath = SDKROOT;
154153
}
155-
if (!SDKPath.empty())
156-
Invocation.setSDKPath(SDKPath);
157-
if (!Triple.empty())
158-
Invocation.setTargetTriple(Triple);
159-
if (!ResourceDir.empty())
160-
Invocation.setRuntimeResourcePath(ResourceDir);
161-
Invocation.getClangImporterOptions().ModuleCachePath = ModuleCachePath;
154+
if (!options.SDKPath.empty())
155+
Invocation.setSDKPath(options.SDKPath);
156+
if (!options.Triple.empty())
157+
Invocation.setTargetTriple(options.Triple);
158+
if (!options.ResourceDir.empty())
159+
Invocation.setRuntimeResourcePath(options.ResourceDir);
160+
Invocation.getClangImporterOptions().ModuleCachePath = options.ModuleCachePath;
162161
Invocation.setParseStdlib();
163162
Invocation.getLangOptions().DisableAvailabilityChecking = true;
164163
Invocation.getLangOptions().EnableAccessControl = false;
165164
Invocation.getLangOptions().EnableObjCAttrRequiresFoundation = false;
166165

167166
serialization::ExtendedValidationInfo extendedInfo;
168167
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileBufOrErr =
169-
Invocation.setUpInputForSILTool(InputFilename, ModuleName,
168+
Invocation.setUpInputForSILTool(options.InputFilename, options.ModuleName,
170169
/*alwaysSetModuleToMain*/ true,
171170
/*bePrimary*/ false, extendedInfo);
172171
if (!FileBufOrErr) {
173-
fprintf(stderr, "Error! Failed to open file: %s\n", InputFilename.c_str());
172+
fprintf(stderr, "Error! Failed to open file: %s\n", options.InputFilename.c_str());
174173
exit(-1);
175174
}
176175

@@ -191,7 +190,7 @@ int main(int argc, char **argv) {
191190

192191
auto SILMod = performASTLowering(CI.getMainModule(), CI.getSILTypes(),
193192
CI.getSILOptions());
194-
nmModule(SILMod.get());
193+
nmModule(SILMod.get(), options);
195194

196195
return CI.getASTContext().hadError();
197196
}

test/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ function(get_test_dependencies SDK result_var_name)
5353
list(APPEND deps_binaries
5454
lldb-moduleimport-test
5555
sil-llvm-gen
56-
sil-nm
5756
sil-passpipeline-dumper
5857
swift-frontend
5958
swift-demangle

tools/CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ add_swift_tool_subdirectory(swift-demangle-yamldump)
2424
add_swift_tool_subdirectory(swift-def-to-strings-converter)
2525
add_swift_tool_subdirectory(swift-serialize-diagnostics)
2626
add_swift_tool_subdirectory(sil-llvm-gen)
27-
add_swift_tool_subdirectory(sil-nm)
2827
add_swift_tool_subdirectory(sil-passpipeline-dumper)
2928
add_swift_tool_subdirectory(swift-llvm-opt)
3029
add_swift_tool_subdirectory(swift-ast-script)

tools/driver/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ swift_create_post_build_symlink(swift-frontend
9999
DESTINATION "sil-func-extractor${CMAKE_EXECUTABLE_SUFFIX}"
100100
WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
101101

102+
swift_create_post_build_symlink(swift-frontend
103+
SOURCE "swift-frontend${CMAKE_EXECUTABLE_SUFFIX}"
104+
DESTINATION "sil-nm${CMAKE_EXECUTABLE_SUFFIX}"
105+
WORKING_DIRECTORY "${SWIFT_RUNTIME_OUTPUT_INTDIR}")
106+
102107
swift_create_post_build_symlink(swift-frontend
103108
SOURCE "swift-frontend${CMAKE_EXECUTABLE_SUFFIX}"
104109
DESTINATION "swift-indent${CMAKE_EXECUTABLE_SUFFIX}"

tools/sil-nm/CMakeLists.txt

-12
This file was deleted.

0 commit comments

Comments
 (0)