]>
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; |
7453a54e SL |
15 | use rustc::mir::repr::*; |
16 | use rustc::mir::visit::MutVisitor; | |
54a0048b SL |
17 | use rustc::mir::transform::{Pass, MirPass}; |
18 | use syntax::ast::NodeId; | |
7453a54e SL |
19 | |
20 | pub struct NoLandingPads; | |
21 | ||
22 | impl<'tcx> MutVisitor<'tcx> for NoLandingPads { | |
23 | fn visit_terminator(&mut self, bb: BasicBlock, terminator: &mut Terminator<'tcx>) { | |
54a0048b SL |
24 | match terminator.kind { |
25 | TerminatorKind::Goto { .. } | | |
26 | TerminatorKind::Resume | | |
27 | TerminatorKind::Return | | |
28 | TerminatorKind::If { .. } | | |
29 | TerminatorKind::Switch { .. } | | |
30 | TerminatorKind::SwitchInt { .. } => { | |
7453a54e SL |
31 | /* nothing to do */ |
32 | }, | |
54a0048b | 33 | TerminatorKind::Drop { ref mut unwind, .. } => { |
7453a54e SL |
34 | unwind.take(); |
35 | }, | |
54a0048b | 36 | TerminatorKind::Call { ref mut cleanup, .. } => { |
7453a54e SL |
37 | cleanup.take(); |
38 | }, | |
39 | } | |
40 | self.super_terminator(bb, terminator); | |
41 | } | |
42 | } | |
43 | ||
54a0048b SL |
44 | impl<'tcx> MirPass<'tcx> for NoLandingPads { |
45 | fn run_pass(&mut self, tcx: &TyCtxt<'tcx>, _: NodeId, mir: &mut Mir<'tcx>) { | |
46 | if tcx.sess.no_landing_pads() { | |
7453a54e SL |
47 | self.visit_mir(mir); |
48 | } | |
49 | } | |
50 | } | |
54a0048b SL |
51 | |
52 | impl Pass for NoLandingPads {} |