Skip to content

Commit c1adf5b

Browse files
committed
Update the LLVM Import Script to include Windows Support
Additionally, update it so that it's compatibile with the current stable branch (ab94816b593daf1c623322b0fb981abb0b156833)
1 parent 31ff487 commit c1adf5b

File tree

8 files changed

+930
-56
lines changed

8 files changed

+930
-56
lines changed

Utilities/import-llvm

Lines changed: 193 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#!/usr/bin/env python
22

33
# This is a helper script for importing the things we use from LLVM.
4-
#
5-
# NOTE: We have slightly modified copies of some of the files, to reduce the
6-
# dependency surface area, so if you run this to update the sources, please
7-
# examine the diffs to remove things that don't make sense.
84

95
import errno
106
import optparse
@@ -13,52 +9,139 @@ import re
139
import shutil
1410
import sys
1511
import subprocess
12+
import platform
1613

1714
# ADT types.
18-
ADT_imports = ['EpochTracker', 'iterator', 'iterator_range', 'Hashing', 'None', 'Optional',
19-
'Statistic', 'StringExtras', 'STLExtras', 'AllocatorList', 'Triple']
20-
21-
# ADT basic data structures.
22-
ADT_imports += ['APFloat', 'APInt', 'APSInt', 'ArrayRef', 'PointerIntPair', 'SetVector', 'StringRef', 'StringSwitch',
23-
'Twine', 'IntrusiveRefCntPtr', 'ilist', 'ilist_base', 'ilist_node', 'ilist_node_base',
24-
'ilist_node_options', 'ilist_iterator', 'simple_ilist', 'OptionSet', 'PointerUnion']
25-
26-
# ADT Mapping structures.
27-
ADT_imports += ['DenseMap', 'DenseMapInfo', 'DenseSet', 'FoldingSet', 'StringMap', 'StringSet']
28-
29-
# ADT "Small" structures.
30-
ADT_imports += ['SmallPtrSet', 'SmallSet', 'SmallString', 'SmallVector']
31-
32-
# ADT Algorithms.
33-
ADT_imports += ['edit_distance']
15+
ADT_imports = [
16+
'APFloat',
17+
'APInt',
18+
'APSInt',
19+
'AllocatorList',
20+
'ArrayRef',
21+
'Bit',
22+
'DenseMap',
23+
'DenseMapInfo',
24+
'DenseSet',
25+
'EpochTracker',
26+
'FoldingSet',
27+
'Hashing',
28+
'IntrusiveRefCntPtr',
29+
'None',
30+
'Optional',
31+
'PointerIntPair',
32+
'PointerUnion',
33+
'STLExtras',
34+
'SmallPtrSet',
35+
'SmallSet',
36+
'SmallString',
37+
'SmallVector',
38+
'Statistic',
39+
'StringExtras',
40+
'StringMap',
41+
'StringRef',
42+
'StringSet',
43+
'StringSwitch',
44+
'Triple',
45+
'Twine',
46+
'edit_distance',
47+
'ilist',
48+
'ilist_base',
49+
'ilist_iterator',
50+
'ilist_node',
51+
'ilist_node_base',
52+
'ilist_node_options',
53+
'iterator',
54+
'iterator_range',
55+
'simple_ilist'
56+
]
3457

3558
# Support types and infrastructure.
3659
Support_imports = [
37-
'AlignOf', 'Allocator', 'Atomic', 'CBindingWrapping', 'Casting', 'Capacity', 'CommandLine', 'Compiler',
38-
'Endian', 'Errno', 'ErrorHandling', 'Errc', 'ErrorOr', 'Error', 'Format',
39-
'ManagedStatic', 'MathExtras', 'Mutex', 'MutexGuard', 'Memory',
40-
'MemoryBuffer', 'PointerLikeTypeTraits', 'Recycler', 'SwapByteOrder',
41-
'Timer', 'TimeValue', 'Threading', 'Unicode', 'UniqueLock', 'Unix', 'WindowsError',
42-
'Valgrind', 'circular_raw_ostream', 'raw_ostream', 'type_traits', 'JSON']
43-
44-
# Stuff we don't want, but have to pull in.
45-
Support_imports += [
46-
'COFF', 'ConvertUTF', 'ConvertUTFWrapper', 'Debug', 'FileSystem',
47-
'FileUtilities', 'Host', 'Locale', 'MachO', 'Path', 'Process', 'Program', 'SMLoc',
48-
'SourceMgr', 'Signals', 'StringSaver', 'ToolOutputFile', 'TrailingObjects', 'Unicode', 'UnicodeCharRanges',
49-
'MemAlloc', 'Chrono', 'FormatProviders', 'FormatVariadic', 'FormatCommon',
50-
'FormatVariadicDetails', 'NativeFormatting', 'DJB', 'ReverseIteration', 'MD5',
51-
'SmallVectorMemoryBuffer', 'WithColor', 'Options', 'PrettyStackTrace', 'Watchdog',
52-
'TargetParser', 'ARMBuildAttributes', 'ARMTargetParser.def', 'AArch64TargetParser.def', 'X86TargetParser.def', 'LineIterator']
60+
'AArch64TargetParser',
61+
'APFloat',
62+
'ARMBuildAttributes',
63+
'ARMTargetParser',
64+
'AlignOf',
65+
'Allocator',
66+
'Atomic',
67+
'CBindingWrapping',
68+
'Casting',
69+
'Chrono',
70+
'CommandLine',
71+
'Compiler',
72+
'ConvertUTF',
73+
'ConvertUTFWrapper',
74+
'DJB',
75+
'DataTypes',
76+
'Debug',
77+
'Endian',
78+
'Errc',
79+
'Errno',
80+
'Error',
81+
'ErrorHandling',
82+
'ErrorOr',
83+
'FileSystem',
84+
'FileUtilities',
85+
'Format',
86+
'FormatAdapters',
87+
'FormatCommon',
88+
'FormatProviders',
89+
'FormatVariadic',
90+
'FormatVariadicDetails',
91+
'Host',
92+
'LineIterator',
93+
'Locale',
94+
'MD5',
95+
'ManagedStatic',
96+
'MathExtras',
97+
'MemAlloc',
98+
'Memory',
99+
'MemoryBuffer',
100+
'Mutex',
101+
'MutexGuard',
102+
'NativeFormatting',
103+
'Options',
104+
'Path',
105+
'PointerLikeTypeTraits',
106+
'Process',
107+
'Program',
108+
'Recycler',
109+
'ReverseIteration',
110+
'SMLoc',
111+
'Signals',
112+
'SmallVectorMemoryBuffer',
113+
'SourceMgr',
114+
'StringSaver',
115+
'Support',
116+
'SwapByteOrder',
117+
'TargetParser',
118+
'Threading',
119+
'Timer',
120+
'Types',
121+
'Unicode',
122+
'Unicode',
123+
'UnicodeCaseFold',
124+
'UnicodeCharRanges',
125+
'UniqueLock',
126+
'Unix',
127+
'Valgrind',
128+
'VersionTuple',
129+
'WindowsError',
130+
'WindowsSupport',
131+
'WithColor',
132+
'X86TargetParser',
133+
'circular_raw_ostream',
134+
'raw_ostream',
135+
'type_traits'
136+
]
53137

54138
# Dependencies from llvm-c needed by Support.
55-
C_imports = ['Types', 'DataTypes', 'Support', 'ErrorHandling']
56-
57-
# Support data structures.
58-
Support_imports += ['YAMLParser', 'YAMLTraits']
59-
60-
# Source files to exclude.
61-
Support_source_excludes = set(['Host'])
139+
C_imports = [
140+
'DataTypes',
141+
'ErrorHandling',
142+
'Support',
143+
'Types'
144+
]
62145

63146
llvm_srcroot = None
64147
sourcekit_srcroot = None
@@ -80,6 +163,10 @@ def copyfile(src, dst):
80163
note("cp %r %r" % (src, dst))
81164
shutil.copyfile(src, dst)
82165

166+
def movefile(src, dst):
167+
note("mv %r %r" % (src, dst))
168+
shutil.movefile(src, dst)
169+
83170
def includes_prefix(source, include_dir):
84171
defs = subprocess.check_output([
85172
'clang', '-std=c++14', '-dM', '-E',
@@ -137,12 +224,32 @@ def main():
137224
llvm_srcroot, = args
138225
sourcekit_srcroot = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
139226

227+
# Remove the old llvm import
228+
sourcekit_llvm_include = os.path.join(sourcekit_srcroot, 'include', 'llvm')
229+
sourcekit_llvm_lib = os.path.join(sourcekit_srcroot, 'lib', 'LLVMSupport')
230+
if os.path.exists(sourcekit_llvm_include):
231+
shutil.rmtree(sourcekit_llvm_include)
232+
if os.path.exists(sourcekit_llvm_lib):
233+
shutil.rmtree(sourcekit_llvm_lib)
234+
235+
# Add the platform specific config files
236+
#
237+
# NOTE: If you're updating to a newer llvm, you may have to manually merge
238+
# these with the newer version produced by the llvm build
239+
sourcekit_llvm_config = os.path.join(sourcekit_srcroot, 'Utilities', 'import-llvm.d', 'include', 'llvm', 'Config')
240+
shutil.copytree(sourcekit_llvm_config, os.path.join(sourcekit_llvm_include, 'Config'))
241+
140242
def import_header(dir, name):
141243
src = os.path.join(llvm_srcroot, 'include', 'llvm', dir, name)
244+
c_src = os.path.join(llvm_srcroot, 'include', 'llvm-c', name)
142245
if os.path.exists(src):
143246
dst = os.path.join(sourcekit_srcroot, 'include', 'llvm', dir, name)
144247
mkdir_p(os.path.dirname(dst))
145248
copyfile(src, dst)
249+
if os.path.exists(c_src):
250+
dst = os.path.join(sourcekit_srcroot, 'include', 'llvm-c', name)
251+
mkdir_p(os.path.dirname(dst))
252+
copyfile(c_src, dst)
146253

147254
def import_c_header(name):
148255
src = os.path.join(llvm_srcroot, 'include', 'llvm-c', name)
@@ -162,23 +269,32 @@ def main():
162269

163270
for name in ADT_imports:
164271
import_header('ADT', name+'.h')
165-
if name not in Support_source_excludes:
166-
import_source('Support', name+'.c')
167-
import_source('Support', name+'.cpp')
272+
import_source('Support', name+'.c')
273+
import_source('Support', name+'.cpp')
168274
for name in Support_imports:
169-
if name.endswith('.def'):
170-
import_header('Support', name)
171-
continue
172275
import_header('Support', name+'.h')
173-
if name not in Support_source_excludes:
174-
import_source('Support', name+'.c')
175-
import_source('Support', name+'.cpp')
176-
import_source('Support', os.path.join('Unix', name+'.h'))
177-
import_source('Support', os.path.join('Unix', name+'.inc'))
178-
276+
import_header('Support', name+'.def')
277+
import_source('Support', name+'.c')
278+
import_source('Support', name+'.cpp')
279+
import_source('Support', name+'.inc')
280+
import_source('Support', name+'.h')
281+
import_source('Support', os.path.join('Unix', name+'.h'))
282+
import_source('Support', os.path.join('Unix', name+'.inc'))
283+
import_source('Support', os.path.join('Windows', name+'.h'))
284+
import_source('Support', os.path.join('Windows', name+'.inc'))
179285
for name in C_imports:
180286
import_c_header(name + '.h')
181287

288+
# Create symlinks so SwiftPM can find headers
289+
os.makedirs(os.path.join(sourcekit_llvm_lib, 'include'))
290+
os.symlink(os.path.join('..', '..', '..', 'include', 'llvm'),
291+
os.path.join(sourcekit_llvm_lib, 'include', 'llvm'))
292+
os.symlink(os.path.join('..', '..', '..', 'include', 'llvm-c'),
293+
os.path.join(sourcekit_llvm_lib, 'include', 'llvm-c'))
294+
295+
copyfile(os.path.join(sourcekit_srcroot, 'Utilities', 'import-llvm.d', 'lib', 'LLVMSupport', 'include', 'module.modulemap'),
296+
os.path.join(sourcekit_srcroot, 'lib', 'LLVMSupport', 'include', 'module.modulemap'))
297+
182298
print ""
183299
print "Adding prefix header includes"
184300

@@ -189,11 +305,32 @@ def main():
189305
]
190306

191307
include_dir = os.path.join(sourcekit_srcroot, 'include')
192-
193308
for base in base_dirs:
194309
for root, dirs, files in os.walk(base):
195310
for file in files:
196311
maybe_add_prefix(os.path.join(root, file), include_dir)
197312

313+
# Finish off with a bunch of really gross hacks. These all offend my better
314+
# sensibilities and what have you.
315+
316+
# TODO: Indexstoredb uses an out of tree/non merged OptionSet.h We should
317+
# remove uses of this or get it merged upstream.
318+
copyfile(os.path.join(sourcekit_srcroot, 'Utilities', 'import-llvm.d', 'include', 'llvm', 'ADT', 'OptionSet.h'),
319+
os.path.join(sourcekit_srcroot, 'include', 'llvm', 'ADT', 'OptionSet.h'))
320+
321+
# AArch64TargetParser uses a relative path to find the .def file, so we
322+
# copy this one to the expected location :(
323+
def_location = os.path.join(sourcekit_srcroot, 'lib', 'include', 'llvm', 'Support')
324+
if os.path.exists(def_location):
325+
shutil.rmtree(def_location)
326+
os.makedirs(def_location)
327+
copyfile(os.path.join(sourcekit_srcroot, 'include', 'llvm', 'Support', 'AArch64TargetParser.def'),
328+
os.path.join(def_location, 'AArch64TargetParser.def'))
329+
330+
# Patch out requirements for Demangle and YAML/Regex from the LLVM support we imported
331+
patch_file = os.path.join(sourcekit_srcroot, 'Utilities', 'import-llvm.d', 'RemoveLLVMImports.patch')
332+
with open(patch_file, 'r') as f:
333+
subprocess.Popen(['patch', '-p1'], stdin=f, cwd=sourcekit_srcroot)
334+
198335
if __name__ == '__main__':
199336
main()
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
diff --git a/lib/LLVMSupport/Support/Statistic.cpp b/lib/LLVMSupport/Support/Statistic.cpp
2+
index d57300a..86e6dc1 100644
3+
--- a/lib/LLVMSupport/Support/Statistic.cpp
4+
+++ b/lib/LLVMSupport/Support/Statistic.cpp
5+
@@ -30,7 +30,6 @@
6+
#include "llvm/Support/ManagedStatic.h"
7+
#include "llvm/Support/Mutex.h"
8+
#include "llvm/Support/Timer.h"
9+
-#include "llvm/Support/YAMLTraits.h"
10+
#include "llvm/Support/raw_ostream.h"
11+
#include <algorithm>
12+
#include <cstring>
13+
@@ -211,10 +210,6 @@ void llvm::PrintStatisticsJSON(raw_ostream &OS) {
14+
const char *delim = "";
15+
for (const Statistic *Stat : Stats.Stats) {
16+
OS << delim;
17+
- assert(yaml::needsQuotes(Stat->getDebugType()) == yaml::QuotingType::None &&
18+
- "Statistic group/type name is simple.");
19+
- assert(yaml::needsQuotes(Stat->getName()) == yaml::QuotingType::None &&
20+
- "Statistic name is simple");
21+
OS << "\t\"" << Stat->getDebugType() << '.' << Stat->getName() << "\": "
22+
<< Stat->getValue();
23+
delim = ",\n";
24+
diff --git a/lib/LLVMSupport/Support/Timer.cpp b/lib/LLVMSupport/Support/Timer.cpp
25+
index 82f5810..3ec1801 100644
26+
--- a/lib/LLVMSupport/Support/Timer.cpp
27+
+++ b/lib/LLVMSupport/Support/Timer.cpp
28+
@@ -20,7 +20,6 @@
29+
#include "llvm/Support/ManagedStatic.h"
30+
#include "llvm/Support/Mutex.h"
31+
#include "llvm/Support/Process.h"
32+
-#include "llvm/Support/YAMLTraits.h"
33+
#include "llvm/Support/raw_ostream.h"
34+
#include <limits>
35+
36+
@@ -388,10 +387,6 @@ void TimerGroup::clearAll() {
37+
38+
void TimerGroup::printJSONValue(raw_ostream &OS, const PrintRecord &R,
39+
const char *suffix, double Value) {
40+
- assert(yaml::needsQuotes(Name) == yaml::QuotingType::None &&
41+
- "TimerGroup name should not need quotes");
42+
- assert(yaml::needsQuotes(R.Name) == yaml::QuotingType::None &&
43+
- "Timer name should not need quotes");
44+
constexpr auto max_digits10 = std::numeric_limits<double>::max_digits10;
45+
OS << "\t\"time." << Name << '.' << R.Name << suffix
46+
<< "\": " << format("%.*e", max_digits10 - 1, Value);
47+
diff --git a/lib/LLVMSupport/Support/Unix/Signals.inc b/lib/LLVMSupport/Support/Unix/Signals.inc
48+
index ad88d5e..7ed843d 100644
49+
--- a/lib/LLVMSupport/Support/Unix/Signals.inc
50+
+++ b/lib/LLVMSupport/Support/Unix/Signals.inc
51+
@@ -36,7 +36,6 @@
52+
#include "Unix.h"
53+
#include "llvm/ADT/STLExtras.h"
54+
#include "llvm/Config/config.h"
55+
-#include "llvm/Demangle/Demangle.h"
56+
#include "llvm/Support/FileSystem.h"
57+
#include "llvm/Support/FileUtilities.h"
58+
#include "llvm/Support/Format.h"
59+
@@ -535,7 +534,7 @@ void llvm::sys::PrintStackTrace(raw_ostream &OS) {
60+
if (dlinfo.dli_sname != nullptr) {
61+
OS << ' ';
62+
int res;
63+
- char* d = itaniumDemangle(dlinfo.dli_sname, nullptr, nullptr, &res);
64+
+ char* d = NULL;
65+
if (!d) OS << dlinfo.dli_sname;
66+
else OS << d;
67+
free(d);

0 commit comments

Comments
 (0)