Skip to content

Commit ed0dbe1

Browse files
committed
add libc++ and libc++abi sources
upstream: LLVM 10
1 parent 463b90b commit ed0dbe1

File tree

99 files changed

+30450
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+30450
-0
lines changed

lib/libcxx/src/algorithm.cpp

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
//===----------------------- algorithm.cpp --------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "algorithm"
10+
#include "random"
11+
#ifndef _LIBCPP_HAS_NO_THREADS
12+
#include "mutex"
13+
#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
14+
#pragma comment(lib, "pthread")
15+
#endif
16+
#endif
17+
18+
_LIBCPP_BEGIN_NAMESPACE_STD
19+
20+
template void __sort<__less<char>&, char*>(char*, char*, __less<char>&);
21+
template void __sort<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
22+
template void __sort<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
23+
template void __sort<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
24+
template void __sort<__less<short>&, short*>(short*, short*, __less<short>&);
25+
template void __sort<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
26+
template void __sort<__less<int>&, int*>(int*, int*, __less<int>&);
27+
template void __sort<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
28+
template void __sort<__less<long>&, long*>(long*, long*, __less<long>&);
29+
template void __sort<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
30+
template void __sort<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
31+
template void __sort<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
32+
template void __sort<__less<float>&, float*>(float*, float*, __less<float>&);
33+
template void __sort<__less<double>&, double*>(double*, double*, __less<double>&);
34+
template void __sort<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
35+
36+
template bool __insertion_sort_incomplete<__less<char>&, char*>(char*, char*, __less<char>&);
37+
template bool __insertion_sort_incomplete<__less<wchar_t>&, wchar_t*>(wchar_t*, wchar_t*, __less<wchar_t>&);
38+
template bool __insertion_sort_incomplete<__less<signed char>&, signed char*>(signed char*, signed char*, __less<signed char>&);
39+
template bool __insertion_sort_incomplete<__less<unsigned char>&, unsigned char*>(unsigned char*, unsigned char*, __less<unsigned char>&);
40+
template bool __insertion_sort_incomplete<__less<short>&, short*>(short*, short*, __less<short>&);
41+
template bool __insertion_sort_incomplete<__less<unsigned short>&, unsigned short*>(unsigned short*, unsigned short*, __less<unsigned short>&);
42+
template bool __insertion_sort_incomplete<__less<int>&, int*>(int*, int*, __less<int>&);
43+
template bool __insertion_sort_incomplete<__less<unsigned>&, unsigned*>(unsigned*, unsigned*, __less<unsigned>&);
44+
template bool __insertion_sort_incomplete<__less<long>&, long*>(long*, long*, __less<long>&);
45+
template bool __insertion_sort_incomplete<__less<unsigned long>&, unsigned long*>(unsigned long*, unsigned long*, __less<unsigned long>&);
46+
template bool __insertion_sort_incomplete<__less<long long>&, long long*>(long long*, long long*, __less<long long>&);
47+
template bool __insertion_sort_incomplete<__less<unsigned long long>&, unsigned long long*>(unsigned long long*, unsigned long long*, __less<unsigned long long>&);
48+
template bool __insertion_sort_incomplete<__less<float>&, float*>(float*, float*, __less<float>&);
49+
template bool __insertion_sort_incomplete<__less<double>&, double*>(double*, double*, __less<double>&);
50+
template bool __insertion_sort_incomplete<__less<long double>&, long double*>(long double*, long double*, __less<long double>&);
51+
52+
template unsigned __sort5<__less<long double>&, long double*>(long double*, long double*, long double*, long double*, long double*, __less<long double>&);
53+
54+
#ifndef _LIBCPP_HAS_NO_THREADS
55+
_LIBCPP_SAFE_STATIC static __libcpp_mutex_t __rs_mut = _LIBCPP_MUTEX_INITIALIZER;
56+
#endif
57+
unsigned __rs_default::__c_ = 0;
58+
59+
__rs_default::__rs_default()
60+
{
61+
#ifndef _LIBCPP_HAS_NO_THREADS
62+
__libcpp_mutex_lock(&__rs_mut);
63+
#endif
64+
__c_ = 1;
65+
}
66+
67+
__rs_default::__rs_default(const __rs_default&)
68+
{
69+
++__c_;
70+
}
71+
72+
__rs_default::~__rs_default()
73+
{
74+
#ifndef _LIBCPP_HAS_NO_THREADS
75+
if (--__c_ == 0)
76+
__libcpp_mutex_unlock(&__rs_mut);
77+
#else
78+
--__c_;
79+
#endif
80+
}
81+
82+
__rs_default::result_type
83+
__rs_default::operator()()
84+
{
85+
static mt19937 __rs_g;
86+
return __rs_g();
87+
}
88+
89+
__rs_default
90+
__rs_get()
91+
{
92+
return __rs_default();
93+
}
94+
95+
_LIBCPP_END_NAMESPACE_STD

lib/libcxx/src/any.cpp

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//===---------------------------- any.cpp ---------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "any"
10+
11+
namespace std {
12+
const char* bad_any_cast::what() const _NOEXCEPT {
13+
return "bad any cast";
14+
}
15+
}
16+
17+
18+
#include <experimental/__config>
19+
20+
// Preserve std::experimental::any_bad_cast for ABI compatibility
21+
// Even though it no longer exists in a header file
22+
_LIBCPP_BEGIN_NAMESPACE_LFTS
23+
24+
class _LIBCPP_EXCEPTION_ABI _LIBCPP_AVAILABILITY_BAD_ANY_CAST bad_any_cast : public bad_cast
25+
{
26+
public:
27+
virtual const char* what() const _NOEXCEPT;
28+
};
29+
30+
const char* bad_any_cast::what() const _NOEXCEPT {
31+
return "bad any cast";
32+
}
33+
34+
_LIBCPP_END_NAMESPACE_LFTS

lib/libcxx/src/bind.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//===-------------------------- bind.cpp ----------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "functional"
10+
11+
_LIBCPP_BEGIN_NAMESPACE_STD
12+
13+
namespace placeholders
14+
{
15+
16+
const __ph<1> _1{};
17+
const __ph<2> _2{};
18+
const __ph<3> _3{};
19+
const __ph<4> _4{};
20+
const __ph<5> _5{};
21+
const __ph<6> _6{};
22+
const __ph<7> _7{};
23+
const __ph<8> _8{};
24+
const __ph<9> _9{};
25+
const __ph<10> _10{};
26+
27+
} // placeholders
28+
29+
_LIBCPP_END_NAMESPACE_STD

lib/libcxx/src/charconv.cpp

+160
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
//===------------------------- charconv.cpp -------------------------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
#include "charconv"
10+
#include <string.h>
11+
12+
_LIBCPP_BEGIN_NAMESPACE_STD
13+
14+
namespace __itoa
15+
{
16+
17+
static constexpr char cDigitsLut[200] = {
18+
'0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0',
19+
'7', '0', '8', '0', '9', '1', '0', '1', '1', '1', '2', '1', '3', '1', '4',
20+
'1', '5', '1', '6', '1', '7', '1', '8', '1', '9', '2', '0', '2', '1', '2',
21+
'2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
22+
'3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3',
23+
'7', '3', '8', '3', '9', '4', '0', '4', '1', '4', '2', '4', '3', '4', '4',
24+
'4', '5', '4', '6', '4', '7', '4', '8', '4', '9', '5', '0', '5', '1', '5',
25+
'2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
26+
'6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6',
27+
'7', '6', '8', '6', '9', '7', '0', '7', '1', '7', '2', '7', '3', '7', '4',
28+
'7', '5', '7', '6', '7', '7', '7', '8', '7', '9', '8', '0', '8', '1', '8',
29+
'2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
30+
'9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9',
31+
'7', '9', '8', '9', '9'};
32+
33+
template <typename T>
34+
inline _LIBCPP_INLINE_VISIBILITY char*
35+
append1(char* buffer, T i)
36+
{
37+
*buffer = '0' + static_cast<char>(i);
38+
return buffer + 1;
39+
}
40+
41+
template <typename T>
42+
inline _LIBCPP_INLINE_VISIBILITY char*
43+
append2(char* buffer, T i)
44+
{
45+
memcpy(buffer, &cDigitsLut[(i)*2], 2);
46+
return buffer + 2;
47+
}
48+
49+
template <typename T>
50+
inline _LIBCPP_INLINE_VISIBILITY char*
51+
append3(char* buffer, T i)
52+
{
53+
return append2(append1(buffer, (i) / 100), (i) % 100);
54+
}
55+
56+
template <typename T>
57+
inline _LIBCPP_INLINE_VISIBILITY char*
58+
append4(char* buffer, T i)
59+
{
60+
return append2(append2(buffer, (i) / 100), (i) % 100);
61+
}
62+
63+
template <typename T>
64+
inline _LIBCPP_INLINE_VISIBILITY char*
65+
append2_no_zeros(char* buffer, T v)
66+
{
67+
if (v < 10)
68+
return append1(buffer, v);
69+
else
70+
return append2(buffer, v);
71+
}
72+
73+
template <typename T>
74+
inline _LIBCPP_INLINE_VISIBILITY char*
75+
append4_no_zeros(char* buffer, T v)
76+
{
77+
if (v < 100)
78+
return append2_no_zeros(buffer, v);
79+
else if (v < 1000)
80+
return append3(buffer, v);
81+
else
82+
return append4(buffer, v);
83+
}
84+
85+
template <typename T>
86+
inline _LIBCPP_INLINE_VISIBILITY char*
87+
append8_no_zeros(char* buffer, T v)
88+
{
89+
if (v < 10000)
90+
{
91+
buffer = append4_no_zeros(buffer, v);
92+
}
93+
else
94+
{
95+
buffer = append4_no_zeros(buffer, v / 10000);
96+
buffer = append4(buffer, v % 10000);
97+
}
98+
return buffer;
99+
}
100+
101+
char*
102+
__u32toa(uint32_t value, char* buffer)
103+
{
104+
if (value < 100000000)
105+
{
106+
buffer = append8_no_zeros(buffer, value);
107+
}
108+
else
109+
{
110+
// value = aabbbbcccc in decimal
111+
const uint32_t a = value / 100000000; // 1 to 42
112+
value %= 100000000;
113+
114+
buffer = append2_no_zeros(buffer, a);
115+
buffer = append4(buffer, value / 10000);
116+
buffer = append4(buffer, value % 10000);
117+
}
118+
119+
return buffer;
120+
}
121+
122+
char*
123+
__u64toa(uint64_t value, char* buffer)
124+
{
125+
if (value < 100000000)
126+
{
127+
uint32_t v = static_cast<uint32_t>(value);
128+
buffer = append8_no_zeros(buffer, v);
129+
}
130+
else if (value < 10000000000000000)
131+
{
132+
const uint32_t v0 = static_cast<uint32_t>(value / 100000000);
133+
const uint32_t v1 = static_cast<uint32_t>(value % 100000000);
134+
135+
buffer = append8_no_zeros(buffer, v0);
136+
buffer = append4(buffer, v1 / 10000);
137+
buffer = append4(buffer, v1 % 10000);
138+
}
139+
else
140+
{
141+
const uint32_t a =
142+
static_cast<uint32_t>(value / 10000000000000000); // 1 to 1844
143+
value %= 10000000000000000;
144+
145+
buffer = append4_no_zeros(buffer, a);
146+
147+
const uint32_t v0 = static_cast<uint32_t>(value / 100000000);
148+
const uint32_t v1 = static_cast<uint32_t>(value % 100000000);
149+
buffer = append4(buffer, v0 / 10000);
150+
buffer = append4(buffer, v0 % 10000);
151+
buffer = append4(buffer, v1 / 10000);
152+
buffer = append4(buffer, v1 % 10000);
153+
}
154+
155+
return buffer;
156+
}
157+
158+
} // namespace __itoa
159+
160+
_LIBCPP_END_NAMESPACE_STD

0 commit comments

Comments
 (0)