|
19 | 19 | using namespace swift;
|
20 | 20 | using namespace Lowering;
|
21 | 21 |
|
| 22 | +//===----------------------------------------------------------------------===// |
| 23 | +// CleanupState |
| 24 | +//===----------------------------------------------------------------------===// |
| 25 | + |
| 26 | +llvm::raw_ostream &Lowering::operator<<(llvm::raw_ostream &os, |
| 27 | + CleanupState state) { |
| 28 | + switch (state) { |
| 29 | + case CleanupState::Dormant: |
| 30 | + return os << "Dormant"; |
| 31 | + case CleanupState::Dead: |
| 32 | + return os << "Dead"; |
| 33 | + case CleanupState::Active: |
| 34 | + return os << "Active"; |
| 35 | + case CleanupState::PersistentlyActive: |
| 36 | + return os << "PersistentlyActive"; |
| 37 | + } |
| 38 | + |
| 39 | + llvm_unreachable("Unhandled CleanupState in switch."); |
| 40 | +} |
| 41 | + |
| 42 | +//===----------------------------------------------------------------------===// |
| 43 | +// CleanupManager |
| 44 | +//===----------------------------------------------------------------------===// |
| 45 | + |
22 | 46 | /// Are there any active cleanups in the given range?
|
23 | 47 | static bool hasAnyActiveCleanups(DiverseStackImpl<Cleanup>::iterator begin,
|
24 | 48 | DiverseStackImpl<Cleanup>::iterator end) {
|
@@ -218,6 +242,38 @@ void CleanupManager::setCleanupState(Cleanup &cleanup, CleanupState state) {
|
218 | 242 | // code to be emitted at transition points.
|
219 | 243 | }
|
220 | 244 |
|
| 245 | +void CleanupManager::dump() const { |
| 246 | +#ifndef NDEBUG |
| 247 | + auto begin = stack.stable_begin(); |
| 248 | + auto end = stack.stable_end(); |
| 249 | + while (begin != end) { |
| 250 | + auto iter = stack.find(begin); |
| 251 | + const Cleanup &stackCleanup = *iter; |
| 252 | + llvm::errs() << "CLEANUP DEPTH: " << begin.getDepth() << "\n"; |
| 253 | + stackCleanup.dump(SGF); |
| 254 | + begin = stack.stabilize(++iter); |
| 255 | + stack.checkIterator(begin); |
| 256 | + } |
| 257 | +#endif |
| 258 | +} |
| 259 | + |
| 260 | +void CleanupManager::dump(CleanupHandle handle) const { |
| 261 | + auto iter = stack.find(handle); |
| 262 | + const Cleanup &stackCleanup = *iter; |
| 263 | + llvm::errs() << "CLEANUP DEPTH: " << handle.getDepth() << "\n"; |
| 264 | + stackCleanup.dump(SGF); |
| 265 | +} |
| 266 | + |
| 267 | +void CleanupManager::checkIterator(CleanupHandle handle) const { |
| 268 | +#ifndef NDEBUG |
| 269 | + stack.checkIterator(handle); |
| 270 | +#endif |
| 271 | +} |
| 272 | + |
| 273 | +//===----------------------------------------------------------------------===// |
| 274 | +// CleanupStateRestorationScope |
| 275 | +//===----------------------------------------------------------------------===// |
| 276 | + |
221 | 277 | void CleanupStateRestorationScope::pushCleanupState(CleanupHandle handle,
|
222 | 278 | CleanupState newState) {
|
223 | 279 | // Don't put the cleanup in a state we can't restore it from.
|
@@ -267,50 +323,6 @@ void CleanupStateRestorationScope::popImpl() {
|
267 | 323 |
|
268 | 324 | void CleanupStateRestorationScope::pop() && { popImpl(); }
|
269 | 325 |
|
270 |
| -llvm::raw_ostream &Lowering::operator<<(llvm::raw_ostream &os, |
271 |
| - CleanupState state) { |
272 |
| - switch (state) { |
273 |
| - case CleanupState::Dormant: |
274 |
| - return os << "Dormant"; |
275 |
| - case CleanupState::Dead: |
276 |
| - return os << "Dead"; |
277 |
| - case CleanupState::Active: |
278 |
| - return os << "Active"; |
279 |
| - case CleanupState::PersistentlyActive: |
280 |
| - return os << "PersistentlyActive"; |
281 |
| - } |
282 |
| - |
283 |
| - llvm_unreachable("Unhandled CleanupState in switch."); |
284 |
| -} |
285 |
| - |
286 |
| -void CleanupManager::dump() const { |
287 |
| -#ifndef NDEBUG |
288 |
| - auto begin = stack.stable_begin(); |
289 |
| - auto end = stack.stable_end(); |
290 |
| - while (begin != end) { |
291 |
| - auto iter = stack.find(begin); |
292 |
| - const Cleanup &stackCleanup = *iter; |
293 |
| - llvm::errs() << "CLEANUP DEPTH: " << begin.getDepth() << "\n"; |
294 |
| - stackCleanup.dump(SGF); |
295 |
| - begin = stack.stabilize(++iter); |
296 |
| - stack.checkIterator(begin); |
297 |
| - } |
298 |
| -#endif |
299 |
| -} |
300 |
| - |
301 |
| -void CleanupManager::dump(CleanupHandle handle) const { |
302 |
| - auto iter = stack.find(handle); |
303 |
| - const Cleanup &stackCleanup = *iter; |
304 |
| - llvm::errs() << "CLEANUP DEPTH: " << handle.getDepth() << "\n"; |
305 |
| - stackCleanup.dump(SGF); |
306 |
| -} |
307 |
| - |
308 |
| -void CleanupManager::checkIterator(CleanupHandle handle) const { |
309 |
| -#ifndef NDEBUG |
310 |
| - stack.checkIterator(handle); |
311 |
| -#endif |
312 |
| -} |
313 |
| - |
314 | 326 | //===----------------------------------------------------------------------===//
|
315 | 327 | // Cleanup Cloner
|
316 | 328 | //===----------------------------------------------------------------------===//
|
|
0 commit comments