]>
Commit | Line | Data |
---|---|---|
7453a54e SL |
1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
2 | // file at the top-level directory of this distribution and at | |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
11 | //! This pass removes the unwind branch of all the terminators when the no-landing-pads option is | |
12 | //! specified. | |
13 | ||
54a0048b | 14 | use rustc::ty::TyCtxt; |
c30ab7b3 | 15 | use rustc::mir::*; |
7453a54e | 16 | use rustc::mir::visit::MutVisitor; |
abe05a73 | 17 | use transform::{MirPass, MirSource}; |
7453a54e SL |
18 | |
19 | pub struct NoLandingPads; | |
20 | ||
7cac9316 XL |
21 | impl MirPass for NoLandingPads { |
22 | fn run_pass<'a, 'tcx>(&self, | |
23 | tcx: TyCtxt<'a, 'tcx, 'tcx>, | |
24 | _: MirSource, | |
25 | mir: &mut Mir<'tcx>) { | |
26 | no_landing_pads(tcx, mir) | |
27 | } | |
28 | } | |
29 | ||
30 | pub fn no_landing_pads<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &mut Mir<'tcx>) { | |
31 | if tcx.sess.no_landing_pads() { | |
32 | NoLandingPads.visit_mir(mir); | |
33 | } | |
34 | } | |
35 | ||
7453a54e | 36 | impl<'tcx> MutVisitor<'tcx> for NoLandingPads { |
9e0c209e SL |
37 | fn visit_terminator(&mut self, |
38 | bb: BasicBlock, | |
39 | terminator: &mut Terminator<'tcx>, | |
40 | location: Location) { | |
54a0048b SL |
41 | match terminator.kind { |
42 | TerminatorKind::Goto { .. } | | |
43 | TerminatorKind::Resume | | |
44 | TerminatorKind::Return | | |
3157f602 | 45 | TerminatorKind::Unreachable | |
ea8adc8c XL |
46 | TerminatorKind::GeneratorDrop | |
47 | TerminatorKind::Yield { .. } | | |
abe05a73 XL |
48 | TerminatorKind::SwitchInt { .. } | |
49 | TerminatorKind::FalseEdges { .. } => { | |
7453a54e SL |
50 | /* nothing to do */ |
51 | }, | |
3157f602 XL |
52 | TerminatorKind::Call { cleanup: ref mut unwind, .. } | |
53 | TerminatorKind::Assert { cleanup: ref mut unwind, .. } | | |
54 | TerminatorKind::DropAndReplace { ref mut unwind, .. } | | |
54a0048b | 55 | TerminatorKind::Drop { ref mut unwind, .. } => { |
7453a54e SL |
56 | unwind.take(); |
57 | }, | |
7453a54e | 58 | } |
9e0c209e | 59 | self.super_terminator(bb, terminator, location); |
7453a54e SL |
60 | } |
61 | } |