@@ -21,52 +21,51 @@ struct RustArchiveMember {
21
21
const char *name;
22
22
Archive::Child child;
23
23
24
- RustArchiveMember (): filename(NULL ), name(NULL ),
24
+ RustArchiveMember ()
25
+ : filename(nullptr ), name(nullptr ),
25
26
#if LLVM_VERSION_GE(3, 8)
26
- child (NULL , NULL , NULL )
27
+ child (nullptr , nullptr , nullptr )
27
28
#else
28
- child (NULL , NULL )
29
+ child (nullptr , nullptr )
29
30
#endif
30
- {}
31
+ {
32
+ }
31
33
~RustArchiveMember () {}
32
34
};
33
35
34
-
35
36
struct RustArchiveIterator {
36
- bool first;
37
- Archive::child_iterator cur;
38
- Archive::child_iterator end;
37
+ bool first;
38
+ Archive::child_iterator cur;
39
+ Archive::child_iterator end;
39
40
#if LLVM_VERSION_GE(3, 9)
40
- Error err;
41
+ Error err;
41
42
42
- RustArchiveIterator () : first(true ), err(Error::success()) { }
43
+ RustArchiveIterator () : first(true ), err(Error::success()) {}
43
44
#else
44
- RustArchiveIterator () : first(true ) { }
45
+ RustArchiveIterator () : first(true ) {}
45
46
#endif
46
47
};
47
48
48
49
enum class LLVMRustArchiveKind {
49
- Other,
50
- GNU,
51
- MIPS64,
52
- BSD,
53
- COFF,
50
+ Other,
51
+ GNU,
52
+ MIPS64,
53
+ BSD,
54
+ COFF,
54
55
};
55
56
56
- static Archive::Kind
57
- from_rust (LLVMRustArchiveKind kind)
58
- {
59
- switch (kind) {
60
- case LLVMRustArchiveKind::GNU:
61
- return Archive::K_GNU;
62
- case LLVMRustArchiveKind::MIPS64:
63
- return Archive::K_MIPS64;
64
- case LLVMRustArchiveKind::BSD:
65
- return Archive::K_BSD;
66
- case LLVMRustArchiveKind::COFF:
67
- return Archive::K_COFF;
68
- default :
69
- llvm_unreachable (" Bad ArchiveKind." );
57
+ static Archive::Kind from_rust (LLVMRustArchiveKind kind) {
58
+ switch (kind) {
59
+ case LLVMRustArchiveKind::GNU:
60
+ return Archive::K_GNU;
61
+ case LLVMRustArchiveKind::MIPS64:
62
+ return Archive::K_MIPS64;
63
+ case LLVMRustArchiveKind::BSD:
64
+ return Archive::K_BSD;
65
+ case LLVMRustArchiveKind::COFF:
66
+ return Archive::K_COFF;
67
+ default :
68
+ llvm_unreachable (" Bad ArchiveKind." );
70
69
}
71
70
}
72
71
@@ -76,174 +75,166 @@ typedef Archive::Child *LLVMRustArchiveChildRef;
76
75
typedef Archive::Child const *LLVMRustArchiveChildConstRef;
77
76
typedef RustArchiveIterator *LLVMRustArchiveIteratorRef;
78
77
79
- extern " C" LLVMRustArchiveRef
80
- LLVMRustOpenArchive (char *path) {
81
- ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or = MemoryBuffer::getFile (path,
82
- -1 ,
83
- false );
84
- if (!buf_or) {
85
- LLVMRustSetLastError (buf_or.getError ().message ().c_str ());
86
- return nullptr ;
87
- }
78
+ extern " C" LLVMRustArchiveRef LLVMRustOpenArchive (char *path) {
79
+ ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or =
80
+ MemoryBuffer::getFile (path, -1 , false );
81
+ if (!buf_or) {
82
+ LLVMRustSetLastError (buf_or.getError ().message ().c_str ());
83
+ return nullptr ;
84
+ }
88
85
89
86
#if LLVM_VERSION_LE(3, 8)
90
- ErrorOr<std::unique_ptr<Archive>> archive_or =
87
+ ErrorOr<std::unique_ptr<Archive>> archive_or =
91
88
#else
92
- Expected<std::unique_ptr<Archive>> archive_or =
89
+ Expected<std::unique_ptr<Archive>> archive_or =
93
90
#endif
94
- Archive::create (buf_or.get ()->getMemBufferRef ());
91
+ Archive::create (buf_or.get ()->getMemBufferRef ());
95
92
96
- if (!archive_or) {
93
+ if (!archive_or) {
97
94
#if LLVM_VERSION_LE(3, 8)
98
- LLVMRustSetLastError (archive_or.getError ().message ().c_str ());
95
+ LLVMRustSetLastError (archive_or.getError ().message ().c_str ());
99
96
#else
100
- LLVMRustSetLastError (toString (archive_or.takeError ()).c_str ());
97
+ LLVMRustSetLastError (toString (archive_or.takeError ()).c_str ());
101
98
#endif
102
- return nullptr ;
103
- }
99
+ return nullptr ;
100
+ }
104
101
105
- OwningBinary<Archive> *ret = new OwningBinary<Archive>(
106
- std::move (archive_or.get ()), std::move (buf_or.get ()));
102
+ OwningBinary<Archive> *ret = new OwningBinary<Archive>(
103
+ std::move (archive_or.get ()), std::move (buf_or.get ()));
107
104
108
- return ret;
105
+ return ret;
109
106
}
110
107
111
- extern " C" void
112
- LLVMRustDestroyArchive (LLVMRustArchiveRef ar) {
113
- delete ar;
114
- }
108
+ extern " C" void LLVMRustDestroyArchive (LLVMRustArchiveRef ar) { delete ar; }
115
109
116
110
extern " C" LLVMRustArchiveIteratorRef
117
111
LLVMRustArchiveIteratorNew (LLVMRustArchiveRef ra) {
118
- Archive *ar = ra->getBinary ();
119
- RustArchiveIterator *rai = new RustArchiveIterator ();
112
+ Archive *ar = ra->getBinary ();
113
+ RustArchiveIterator *rai = new RustArchiveIterator ();
120
114
#if LLVM_VERSION_LE(3, 8)
121
- rai->cur = ar->child_begin ();
115
+ rai->cur = ar->child_begin ();
122
116
#else
123
- rai->cur = ar->child_begin (rai->err );
124
- if (rai->err ) {
125
- LLVMRustSetLastError (toString (std::move (rai->err )).c_str ());
126
- delete rai;
127
- return NULL ;
128
- }
117
+ rai->cur = ar->child_begin (rai->err );
118
+ if (rai->err ) {
119
+ LLVMRustSetLastError (toString (std::move (rai->err )).c_str ());
120
+ delete rai;
121
+ return nullptr ;
122
+ }
129
123
#endif
130
- rai->end = ar->child_end ();
131
- return rai;
124
+ rai->end = ar->child_end ();
125
+ return rai;
132
126
}
133
127
134
128
extern " C" LLVMRustArchiveChildConstRef
135
129
LLVMRustArchiveIteratorNext (LLVMRustArchiveIteratorRef rai) {
136
- if (rai->cur == rai->end ) return nullptr ;
137
-
138
- // Advancing the iterator validates the next child, and this can
139
- // uncover an error. LLVM requires that we check all Errors,
140
- // so we only advance the iterator if we actually need to fetch
141
- // the next child.
142
- // This means we must not advance the iterator in the *first* call,
143
- // but instead advance it *before* fetching the child in all later calls.
144
- if (!rai->first ) {
145
- ++rai->cur ;
130
+ if (rai->cur == rai->end )
131
+ return nullptr ;
132
+
133
+ // Advancing the iterator validates the next child, and this can
134
+ // uncover an error. LLVM requires that we check all Errors,
135
+ // so we only advance the iterator if we actually need to fetch
136
+ // the next child.
137
+ // This means we must not advance the iterator in the *first* call,
138
+ // but instead advance it *before* fetching the child in all later calls.
139
+ if (!rai->first ) {
140
+ ++rai->cur ;
146
141
#if LLVM_VERSION_GE(3, 9)
147
- if (rai->err ) {
148
- LLVMRustSetLastError (toString (std::move (rai->err )).c_str ());
149
- return nullptr ;
150
- }
151
- #endif
152
- } else {
153
- rai->first = false ;
142
+ if (rai->err ) {
143
+ LLVMRustSetLastError (toString (std::move (rai->err )).c_str ());
144
+ return nullptr ;
154
145
}
146
+ #endif
147
+ } else {
148
+ rai->first = false ;
149
+ }
155
150
156
- if (rai->cur == rai->end ) return nullptr ;
151
+ if (rai->cur == rai->end )
152
+ return nullptr ;
157
153
158
154
#if LLVM_VERSION_EQ(3, 8)
159
- const ErrorOr<Archive::Child>* cur = rai->cur .operator ->();
160
- if (!*cur) {
161
- LLVMRustSetLastError (cur->getError ().message ().c_str ());
162
- return nullptr ;
163
- }
164
- const Archive::Child &child = cur->get ();
155
+ const ErrorOr<Archive::Child> * cur = rai->cur .operator ->();
156
+ if (!*cur) {
157
+ LLVMRustSetLastError (cur->getError ().message ().c_str ());
158
+ return nullptr ;
159
+ }
160
+ const Archive::Child &child = cur->get ();
165
161
#else
166
- const Archive::Child &child = *rai->cur .operator ->();
162
+ const Archive::Child &child = *rai->cur .operator ->();
167
163
#endif
168
- Archive::Child *ret = new Archive::Child (child);
164
+ Archive::Child *ret = new Archive::Child (child);
169
165
170
- return ret;
166
+ return ret;
171
167
}
172
168
173
- extern " C" void
174
- LLVMRustArchiveChildFree (LLVMRustArchiveChildRef child) {
175
- delete child;
169
+ extern " C" void LLVMRustArchiveChildFree (LLVMRustArchiveChildRef child) {
170
+ delete child;
176
171
}
177
172
178
- extern " C" void
179
- LLVMRustArchiveIteratorFree (LLVMRustArchiveIteratorRef rai) {
180
- delete rai;
173
+ extern " C" void LLVMRustArchiveIteratorFree (LLVMRustArchiveIteratorRef rai) {
174
+ delete rai;
181
175
}
182
176
183
- extern " C" const char *
177
+ extern " C" const char *
184
178
LLVMRustArchiveChildName (LLVMRustArchiveChildConstRef child, size_t *size) {
185
179
#if LLVM_VERSION_GE(4, 0)
186
- Expected<StringRef> name_or_err = child->getName ();
187
- if (!name_or_err) {
188
- // rustc_llvm currently doesn't use this error string, but it might be useful
189
- // in the future, and in the mean time this tells LLVM that the error was
190
- // not ignored and that it shouldn't abort the process.
191
- LLVMRustSetLastError (toString (name_or_err.takeError ()).c_str ());
192
- return NULL ;
193
- }
180
+ Expected<StringRef> name_or_err = child->getName ();
181
+ if (!name_or_err) {
182
+ // rustc_llvm currently doesn't use this error string, but it might be useful
183
+ // in the future, and in the mean time this tells LLVM that the error was
184
+ // not ignored and that it shouldn't abort the process.
185
+ LLVMRustSetLastError (toString (name_or_err.takeError ()).c_str ());
186
+ return nullptr ;
187
+ }
194
188
#else
195
- ErrorOr<StringRef> name_or_err = child->getName ();
196
- if (name_or_err.getError ())
197
- return NULL ;
189
+ ErrorOr<StringRef> name_or_err = child->getName ();
190
+ if (name_or_err.getError ())
191
+ return nullptr ;
198
192
#endif
199
- StringRef name = name_or_err.get ();
200
- *size = name.size ();
201
- return name.data ();
193
+ StringRef name = name_or_err.get ();
194
+ *size = name.size ();
195
+ return name.data ();
202
196
}
203
197
204
- extern " C" const char *
205
- LLVMRustArchiveChildData (LLVMRustArchiveChildRef child, size_t *size) {
206
- StringRef buf;
198
+ extern " C" const char * LLVMRustArchiveChildData (LLVMRustArchiveChildRef child,
199
+ size_t *size) {
200
+ StringRef buf;
207
201
#if LLVM_VERSION_GE(4, 0)
208
- Expected<StringRef> buf_or_err = child->getBuffer ();
209
- if (!buf_or_err) {
210
- LLVMRustSetLastError (toString (buf_or_err.takeError ()).c_str ());
211
- return NULL ;
212
- }
202
+ Expected<StringRef> buf_or_err = child->getBuffer ();
203
+ if (!buf_or_err) {
204
+ LLVMRustSetLastError (toString (buf_or_err.takeError ()).c_str ());
205
+ return nullptr ;
206
+ }
213
207
#else
214
- ErrorOr<StringRef> buf_or_err = child->getBuffer ();
215
- if (buf_or_err.getError ()) {
216
- LLVMRustSetLastError (buf_or_err.getError ().message ().c_str ());
217
- return NULL ;
218
- }
208
+ ErrorOr<StringRef> buf_or_err = child->getBuffer ();
209
+ if (buf_or_err.getError ()) {
210
+ LLVMRustSetLastError (buf_or_err.getError ().message ().c_str ());
211
+ return nullptr ;
212
+ }
219
213
#endif
220
- buf = buf_or_err.get ();
221
- *size = buf.size ();
222
- return buf.data ();
214
+ buf = buf_or_err.get ();
215
+ *size = buf.size ();
216
+ return buf.data ();
223
217
}
224
218
225
219
extern " C" LLVMRustArchiveMemberRef
226
220
LLVMRustArchiveMemberNew (char *Filename, char *Name,
227
- LLVMRustArchiveChildRef child) {
228
- RustArchiveMember *Member = new RustArchiveMember;
229
- Member->filename = Filename;
230
- Member->name = Name;
231
- if (child)
232
- Member->child = *child;
233
- return Member;
221
+ LLVMRustArchiveChildRef child) {
222
+ RustArchiveMember *Member = new RustArchiveMember;
223
+ Member->filename = Filename;
224
+ Member->name = Name;
225
+ if (child)
226
+ Member->child = *child;
227
+ return Member;
234
228
}
235
229
236
- extern " C" void
237
- LLVMRustArchiveMemberFree (LLVMRustArchiveMemberRef Member) {
238
- delete Member;
230
+ extern " C" void LLVMRustArchiveMemberFree (LLVMRustArchiveMemberRef Member) {
231
+ delete Member;
239
232
}
240
233
241
234
extern " C" LLVMRustResult
242
- LLVMRustWriteArchive (char *Dst,
243
- size_t NumMembers,
235
+ LLVMRustWriteArchive (char *Dst, size_t NumMembers,
244
236
const LLVMRustArchiveMemberRef *NewMembers,
245
- bool WriteSymbtab,
246
- LLVMRustArchiveKind rust_kind) {
237
+ bool WriteSymbtab, LLVMRustArchiveKind rust_kind) {
247
238
248
239
#if LLVM_VERSION_LE(3, 8)
249
240
std::vector<NewArchiveIterator> Members;
@@ -257,7 +248,8 @@ LLVMRustWriteArchive(char *Dst,
257
248
assert (Member->name );
258
249
if (Member->filename ) {
259
250
#if LLVM_VERSION_GE(3, 9)
260
- Expected<NewArchiveMember> MOrErr = NewArchiveMember::getFile (Member->filename , true );
251
+ Expected<NewArchiveMember> MOrErr =
252
+ NewArchiveMember::getFile (Member->filename , true );
261
253
if (!MOrErr) {
262
254
LLVMRustSetLastError (toString (MOrErr.takeError ()).c_str ());
263
255
return LLVMRustResult::Failure;
@@ -272,7 +264,8 @@ LLVMRustWriteArchive(char *Dst,
272
264
#if LLVM_VERSION_LE(3, 8)
273
265
Members.push_back (NewArchiveIterator (Member->child , Member->name ));
274
266
#else
275
- Expected<NewArchiveMember> MOrErr = NewArchiveMember::getOldMember (Member->child , true );
267
+ Expected<NewArchiveMember> MOrErr =
268
+ NewArchiveMember::getOldMember (Member->child , true );
276
269
if (!MOrErr) {
277
270
LLVMRustSetLastError (toString (MOrErr.takeError ()).c_str ());
278
271
return LLVMRustResult::Failure;
0 commit comments