Skip to content

Commit a7a01d8

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 e510daa commit a7a01d8

File tree

7 files changed

+783
-25
lines changed

7 files changed

+783
-25
lines changed

Utilities/import-llvm

Lines changed: 115 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,55 @@ import sys
1515
import subprocess
1616

1717
# ADT types.
18-
ADT_imports = ['EpochTracker', 'iterator', 'iterator_range', 'Hashing', 'None', 'Optional',
19-
'Statistic', 'StringExtras', 'STLExtras', 'AllocatorList', 'Triple']
18+
ADT_imports = ['iterator', 'iterator_range', 'APFloat', 'APInt', 'APSInt',
19+
'AllocatorList', 'EpochTracker', 'Hashing', 'None', 'Optional',
20+
'Statistic', 'StringExtras', 'STLExtras']
2021

2122
# 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']
23+
ADT_imports += ['ArrayRef', 'Bit', 'PointerIntPair', 'PointerUnion', 'StringRef',
24+
'StringSwitch', 'Triple', 'Twine', 'IntrusiveRefCntPtr',
25+
'ilist', 'ilist_base', 'ilist_node', 'ilist_node_base',
26+
'ilist_node_options', 'simple_ilist', 'ilist_iterator']
2527

2628
# ADT Mapping structures.
27-
ADT_imports += ['DenseMap', 'DenseMapInfo', 'DenseSet', 'FoldingSet', 'StringMap', 'StringSet']
29+
ADT_imports += ['DenseSet', 'DenseMap', 'DenseMapInfo', 'FoldingSet', 'StringMap', 'StringSet']
2830

2931
# ADT "Small" structures.
3032
ADT_imports += ['SmallPtrSet', 'SmallSet', 'SmallString', 'SmallVector']
3133

3234
# ADT Algorithms.
3335
ADT_imports += ['edit_distance']
3436

37+
Demangle_imports = ['Demangle', 'ItaniumDemangle', 'MicrosoftDemangle',
38+
'Compiler', 'MicrosoftDemangleNodes', 'StringView',
39+
'Utility']
40+
3541
# Support types and infrastructure.
36-
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']
42+
Support_imports = [ 'AlignOf', 'Allocator', 'Atomic', 'CBindingWrapping',
43+
'Casting', 'Compiler', 'CommandLine', 'ConvertUTF',
44+
'ConvertUTFWrapper', 'DJB', 'Endian', 'Errno', 'Error',
45+
'ErrorHandling', 'Errc', 'ErrorOr', 'Format',
46+
'ManagedStatic', 'MathExtras', 'MD5', 'Mutex',
47+
'MutexGuard', 'Memory', 'MemoryBuffer',
48+
'PointerLikeTypeTraits', 'Regex', 'Recycler',
49+
'ReverseIteration', 'SmallVectorMemoryBuffer',
50+
'StringSaver', 'SwapByteOrder', 'Timer',
51+
'Threading', 'Unicode', 'UniqueLock', 'Unix',
52+
'WindowsError', 'WindowsSupport', 'Valgrind',
53+
'circular_raw_ostream', 'raw_ostream', 'type_traits']
4354

4455
# 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']
56+
Support_imports += [ 'APFloat', 'ARMTargetParser', 'AArch64TargetParser',
57+
'ARMBuildAttributes', 'Chrono', 'DataTypes', 'Debug',
58+
'FileSystem', 'FileUtilities', 'FormatAdapters',
59+
'FormatCommon', 'FormatProviders',
60+
'FormatVariadic','FormatVariadicDetails', 'Host',
61+
'LineIterator', 'Locale', 'MemAlloc', 'NativeFormatting',
62+
'Options', 'Path', 'Process', 'Program', 'SMLoc',
63+
'SourceMgr', 'Signals', 'Support', 'TargetParser',
64+
'Types', 'Unicode', 'UnicodeCaseFold',
65+
'UnicodeCharRanges', 'VersionTuple', 'WithColor', 'X86TargetParser',
66+
'regex_impl', 'regcomp', 'regutils', 'regex2', 'regerror', 'regexec', 'regfree', 'regstrlcpy', 'regengine']
5367

5468
# Dependencies from llvm-c needed by Support.
5569
C_imports = ['Types', 'DataTypes', 'Support', 'ErrorHandling']
@@ -58,7 +72,7 @@ C_imports = ['Types', 'DataTypes', 'Support', 'ErrorHandling']
5872
Support_imports += ['YAMLParser', 'YAMLTraits']
5973

6074
# Source files to exclude.
61-
Support_source_excludes = set(['Host'])
75+
Support_source_excludes = set([])
6276

6377
llvm_srcroot = None
6478
sourcekit_srcroot = None
@@ -137,12 +151,32 @@ def main():
137151
llvm_srcroot, = args
138152
sourcekit_srcroot = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
139153

154+
# Remove the old llvm import
155+
sourcekit_llvm_include = os.path.join(sourcekit_srcroot, 'include', 'llvm')
156+
sourcekit_llvm_lib = os.path.join(sourcekit_srcroot, 'lib', 'LLVMSupport')
157+
if os.path.exists(sourcekit_llvm_include):
158+
shutil.rmtree(sourcekit_llvm_include)
159+
if os.path.exists(sourcekit_llvm_lib):
160+
shutil.rmtree(sourcekit_llvm_lib)
161+
162+
# Add the platform specific config files
163+
#
164+
# NOTE: If you're updating to a newer llvm, you may have to manually merge
165+
# these with the newer version produced by the llvm build
166+
sourcekit_llvm_config = os.path.join(sourcekit_srcroot, 'Utilities', 'import-llvm.d', 'include', 'llvm', 'Config')
167+
shutil.copytree(sourcekit_llvm_config, os.path.join(sourcekit_llvm_include, 'Config'))
168+
140169
def import_header(dir, name):
141170
src = os.path.join(llvm_srcroot, 'include', 'llvm', dir, name)
171+
c_src = os.path.join(llvm_srcroot, 'include', 'llvm-c', name)
142172
if os.path.exists(src):
143173
dst = os.path.join(sourcekit_srcroot, 'include', 'llvm', dir, name)
144174
mkdir_p(os.path.dirname(dst))
145175
copyfile(src, dst)
176+
if os.path.exists(c_src):
177+
dst = os.path.join(sourcekit_srcroot, 'include', 'llvm-c', name)
178+
mkdir_p(os.path.dirname(dst))
179+
copyfile(c_src, dst)
146180

147181
def import_c_header(name):
148182
src = os.path.join(llvm_srcroot, 'include', 'llvm-c', name)
@@ -166,15 +200,26 @@ def main():
166200
import_source('Support', name+'.c')
167201
import_source('Support', name+'.cpp')
168202
for name in Support_imports:
169-
if name.endswith('.def'):
170-
import_header('Support', name)
171-
continue
172203
import_header('Support', name+'.h')
204+
import_header('Support', name+'.def')
173205
if name not in Support_source_excludes:
174206
import_source('Support', name+'.c')
207+
import_source('Support', name+'.h')
175208
import_source('Support', name+'.cpp')
209+
import_source('Support', name+'.def')
210+
import_source('Support', name+'.inc')
176211
import_source('Support', os.path.join('Unix', name+'.h'))
177212
import_source('Support', os.path.join('Unix', name+'.inc'))
213+
import_source('Support', os.path.join('Windows', name+'.h'))
214+
import_source('Support', os.path.join('Windows', name+'.inc'))
215+
for name in Demangle_imports:
216+
import_header('Demangle', name+'.h')
217+
import_source('Demangle', name+'.cpp')
218+
219+
# Copy over all of demangle
220+
demangle_src = os.path.join(llvm_srcroot, 'lib', 'Demangle')
221+
demangle_dest = os.path.join(sourcekit_srcroot, 'lib', 'LLVMSupport', 'Demangle')
222+
#shutil.copytree(demangle_src, demangle_dest)
178223

179224
for name in C_imports:
180225
import_c_header(name + '.h')
@@ -190,6 +235,51 @@ def main():
190235

191236
include_dir = os.path.join(sourcekit_srcroot, 'include')
192237

238+
# Create Symlinks for SwiftPM include directory resolution
239+
os.makedirs(os.path.join(sourcekit_llvm_lib, 'Support', 'include', 'llvm'))
240+
os.makedirs(os.path.join(sourcekit_llvm_lib, 'Demangle', 'include'))
241+
os.makedirs(os.path.join(sourcekit_llvm_lib, 'include'))
242+
os.makedirs(os.path.join(sourcekit_llvm_include, 'Demangle', 'include'))
243+
os.symlink(os.path.join('..', '..', '..', '..', '..', 'include', 'llvm', 'ADT'),
244+
os.path.join(sourcekit_llvm_lib, 'Support', 'include', 'llvm', 'ADT'))
245+
os.symlink(os.path.join('..', '..', '..', '..', '..', 'include', 'llvm', 'Config'),
246+
os.path.join(sourcekit_llvm_lib, 'Support', 'include', 'llvm', 'Config'))
247+
os.symlink(os.path.join('..', '..', '..', '..', '..', 'include', 'llvm', 'Support'),
248+
os.path.join(sourcekit_llvm_lib, 'Support', 'include', 'llvm', 'Support'))
249+
os.symlink(os.path.join('..', '..', '..', '..', 'include', 'llvm-c'),
250+
os.path.join(sourcekit_llvm_lib, 'Support', 'include', 'llvm-c'))
251+
os.symlink(os.path.join('..', '..', '..', '..', 'include', 'llvm'),
252+
os.path.join(sourcekit_llvm_lib, 'Demangle', 'include', 'llvm'))
253+
os.symlink(os.path.join('..', '..', '..', 'llvm'),
254+
os.path.join(sourcekit_llvm_include, 'Demangle', 'include', 'llvm'))
255+
os.symlink(os.path.join('..', '..', '..', 'include', 'llvm'),
256+
os.path.join(sourcekit_llvm_lib, 'include', 'llvm'))
257+
os.symlink(os.path.join('..', '..', '..', 'include', 'llvm-c'),
258+
os.path.join(sourcekit_llvm_lib, 'include', 'llvm-c'))
259+
260+
copyfile(os.path.join(sourcekit_srcroot, 'Utilities', 'import-llvm.d', 'lib', 'LLVMSupport', 'include', 'module.modulemap'),
261+
os.path.join(sourcekit_srcroot, 'lib', 'LLVMSupport', 'include', 'module.modulemap'))
262+
263+
copyfile(os.path.join(sourcekit_srcroot, 'Utilities', 'import-llvm.d', 'include', 'llvm', 'ADT', 'OptionSet.h'),
264+
os.path.join(sourcekit_srcroot, 'include', 'llvm', 'ADT', 'OptionSet.h'))
265+
266+
# AArch64TargetParser uses a relative path to find the .def file, so we
267+
# copy this one to the expected location :(
268+
def_location = os.path.join(sourcekit_srcroot, 'lib', 'include', 'llvm', 'Support')
269+
if os.path.exists(def_location):
270+
shutil.rmtree(def_location)
271+
os.makedirs(def_location)
272+
copyfile(os.path.join(sourcekit_srcroot, 'include', 'llvm', 'Support', 'AArch64TargetParser.def'),
273+
os.path.join(def_location, 'AArch64TargetParser.def'))
274+
275+
# Process.cpp uses LLVM_ENABLE_CRASH_DUMPS which is usually set in CMake.
276+
# Since the Linux and Darwin builds use SwiftPM, this doesn't get set.
277+
# We'll modify the file to set it via proprocessor
278+
process_cpp = os.path.join(sourcekit_srcroot, 'lib', 'LLVMSupport', 'Support', 'Process.cpp')
279+
with open(process_cpp, 'r+') as f:
280+
content = f.read()
281+
f.seek(0, 0)
282+
f.write('#define LLVM_ENABLE_CRASH_DUMPS false\n' + content)
193283
for base in base_dirs:
194284
for root, dirs, files in os.walk(base):
195285
for file in files:
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
//===--- OptionSet.h - Sets of boolean options ------------------*- C++ -*-===//
2+
//
3+
// The LLVM Compiler Infrastructure
4+
//
5+
// This file is distributed under the University of Illinois Open Source
6+
// License. See LICENSE.TXT for details.
7+
//
8+
//===----------------------------------------------------------------------===//
9+
//
10+
// This file defines the OptionSet class template.
11+
//
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_ADT_OPTIONSET_H
15+
#define LLVM_ADT_OPTIONSET_H
16+
17+
#include "llvm/ADT/None.h"
18+
19+
#include <type_traits>
20+
#include <cstdint>
21+
22+
namespace llvm {
23+
24+
/// The class template \c OptionSet captures a set of options stored as the
25+
/// bits in an unsigned integral value.
26+
///
27+
/// Each option corresponds to a particular flag value in the provided
28+
/// enumeration type (\c Flags). The option set provides ways to add options,
29+
/// remove options, intersect sets, etc., providing a thin type-safe layer
30+
/// over the underlying unsigned value.
31+
///
32+
/// \tparam Flags An enumeration type that provides the individual flags
33+
/// for options. Each enumerator should have a power-of-two value, indicating
34+
/// which bit it is associated with.
35+
///
36+
/// \tparam StorageType The unsigned integral type to use to store the flags
37+
/// enabled within this option set. This defaults to the unsigned form of the
38+
/// underlying type of the enumeration.
39+
template<typename Flags,
40+
typename StorageType = typename std::make_unsigned<
41+
typename std::underlying_type<Flags>::type
42+
>::type>
43+
class OptionSet {
44+
StorageType Storage;
45+
46+
public:
47+
/// Create an empty option set.
48+
OptionSet() : Storage() { }
49+
50+
/// Create an empty option set.
51+
OptionSet(llvm::NoneType) : Storage() { }
52+
53+
/// Create an option set with only the given option set.
54+
OptionSet(Flags flag) : Storage(static_cast<StorageType>(flag)) { }
55+
56+
/// Create an option set from raw storage.
57+
explicit OptionSet(StorageType storage) : Storage(storage) { }
58+
59+
/// Check whether an option set is non-empty.
60+
explicit operator bool() const { return Storage != 0; }
61+
62+
/// Explicitly convert an option set to its underlying storage.
63+
explicit operator StorageType() const { return Storage; }
64+
65+
/// Explicitly convert an option set to intptr_t, for use in
66+
/// llvm::PointerIntPair.
67+
///
68+
/// This member is not present if the underlying type is bigger than
69+
/// a pointer.
70+
template <typename T = std::intptr_t>
71+
explicit operator typename std::enable_if<sizeof(StorageType) <= sizeof(T),
72+
std::intptr_t>::type () const {
73+
return static_cast<intptr_t>(Storage);
74+
}
75+
76+
/// Retrieve the "raw" representation of this option set.
77+
StorageType toRaw() const { return Storage; }
78+
79+
bool containsAny(OptionSet set) const {
80+
return static_cast<bool>(*this & set);
81+
}
82+
bool containsAll(OptionSet set) const {
83+
return (*this & set).toRaw() == set.toRaw();
84+
}
85+
86+
/// Determine whether this option set contains all of the options in the
87+
/// given set.
88+
bool contains(OptionSet set) const {
89+
return !static_cast<bool>(set - *this);
90+
}
91+
92+
/// Produce the union of two option sets.
93+
friend OptionSet operator|(OptionSet lhs, OptionSet rhs) {
94+
return OptionSet(lhs.Storage | rhs.Storage);
95+
}
96+
97+
/// Produce the union of two option sets.
98+
friend OptionSet &operator|=(OptionSet &lhs, OptionSet rhs) {
99+
lhs.Storage |= rhs.Storage;
100+
return lhs;
101+
}
102+
103+
/// Produce the intersection of two option sets.
104+
friend OptionSet operator&(OptionSet lhs, OptionSet rhs) {
105+
return OptionSet(lhs.Storage & rhs.Storage);
106+
}
107+
108+
/// Produce the intersection of two option sets.
109+
friend OptionSet &operator&=(OptionSet &lhs, OptionSet rhs) {
110+
lhs.Storage &= rhs.Storage;
111+
return lhs;
112+
}
113+
114+
/// Produce the difference of two option sets.
115+
friend OptionSet operator-(OptionSet lhs, OptionSet rhs) {
116+
return OptionSet(lhs.Storage & ~rhs.Storage);
117+
}
118+
119+
/// Produce the intersection of two option sets.
120+
friend OptionSet &operator-=(OptionSet &lhs, OptionSet rhs) {
121+
lhs.Storage &= ~rhs.Storage;
122+
return lhs;
123+
}
124+
125+
private:
126+
#ifndef _MSC_VER
127+
// This is crashing MSVC.
128+
template <typename T>
129+
static auto _checkResultTypeOperatorOr(T t) -> decltype(t | t) { return T(); }
130+
131+
static void _checkResultTypeOperatorOr(...) {}
132+
133+
static_assert(!std::is_same<decltype(_checkResultTypeOperatorOr(Flags())),
134+
Flags>::value,
135+
"operator| should produce an OptionSet");
136+
#endif
137+
};
138+
139+
}
140+
141+
#endif
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*===------- llvm/Config/abi-breaking.h - llvm configuration -------*- C -*-===*/
2+
/* */
3+
/* The LLVM Compiler Infrastructure */
4+
/* */
5+
/* This file is distributed under the University of Illinois Open Source */
6+
/* License. See LICENSE.TXT for details. */
7+
/* */
8+
/*===----------------------------------------------------------------------===*/
9+
10+
/* This file controls the C++ ABI break introduced in LLVM public header. */
11+
12+
#ifndef LLVM_ABI_BREAKING_CHECKS_H
13+
#define LLVM_ABI_BREAKING_CHECKS_H
14+
15+
#include "llvm/Config/indexstoredb-prefix.h"
16+
17+
/* Define to enable checks that alter the LLVM C++ ABI */
18+
#define LLVM_ENABLE_ABI_BREAKING_CHECKS 0
19+
20+
/* Define to enable reverse iteration of unordered llvm containers */
21+
#define LLVM_ENABLE_REVERSE_ITERATION 0
22+
23+
/* Allow selectively disabling link-time mismatch checking so that header-only
24+
ADT content from LLVM can be used without linking libSupport. */
25+
#if !LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING
26+
27+
// ABI_BREAKING_CHECKS protection: provides link-time failure when clients build
28+
// mismatch with LLVM
29+
#if defined(_MSC_VER)
30+
// Use pragma with MSVC
31+
#define LLVM_XSTR(s) LLVM_STR(s)
32+
#define LLVM_STR(s) #s
33+
#pragma detect_mismatch("LLVM_ENABLE_ABI_BREAKING_CHECKS", LLVM_XSTR(LLVM_ENABLE_ABI_BREAKING_CHECKS))
34+
#undef LLVM_XSTR
35+
#undef LLVM_STR
36+
#elif defined(_WIN32) || defined(__CYGWIN__) // Win32 w/o #pragma detect_mismatch
37+
// FIXME: Implement checks without weak.
38+
#elif defined(__cplusplus)
39+
namespace llvm {
40+
#if LLVM_ENABLE_ABI_BREAKING_CHECKS
41+
extern int EnableABIBreakingChecks;
42+
__attribute__((weak, visibility ("hidden"))) int *VerifyEnableABIBreakingChecks = &EnableABIBreakingChecks;
43+
#else
44+
extern int DisableABIBreakingChecks;
45+
__attribute__((weak, visibility ("hidden"))) int *VerifyDisableABIBreakingChecks = &DisableABIBreakingChecks;
46+
#endif
47+
}
48+
#endif // _MSC_VER
49+
50+
#endif // LLVM_DISABLE_ABI_BREAKING_CHECKS_ENFORCING
51+
52+
#endif

0 commit comments

Comments
 (0)