]> git.proxmox.com Git - rustc.git/blame - src/test/auxiliary/dummy_mir_pass.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / auxiliary / dummy_mir_pass.rs
CommitLineData
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// force-host
12
13#![feature(plugin_registrar, rustc_private)]
14#![feature(box_syntax)]
15
16#[macro_use] extern crate rustc;
7453a54e 17extern crate rustc_plugin;
54a0048b 18extern crate rustc_const_math;
7453a54e
SL
19extern crate syntax;
20
54a0048b 21use rustc::mir::transform::{self, MirPass};
7453a54e
SL
22use rustc::mir::repr::{Mir, Literal};
23use rustc::mir::visit::MutVisitor;
54a0048b
SL
24use rustc::ty;
25use rustc::middle::const_val::ConstVal;
26use rustc_const_math::ConstInt;
7453a54e
SL
27use rustc_plugin::Registry;
28
54a0048b
SL
29use syntax::ast::NodeId;
30
7453a54e
SL
31struct Pass;
32
54a0048b
SL
33impl transform::Pass for Pass {}
34impl<'tcx> MirPass<'tcx> for Pass {
35 fn run_pass(&mut self, _: &ty::TyCtxt<'tcx>, _: NodeId, mir: &mut Mir<'tcx>) {
7453a54e
SL
36 Visitor.visit_mir(mir)
37 }
38}
39
40struct Visitor;
41
42impl<'tcx> MutVisitor<'tcx> for Visitor {
43 fn visit_literal(&mut self, literal: &mut Literal<'tcx>) {
54a0048b
SL
44 if let Literal::Value { ref mut value } = *literal {
45 if let ConstVal::Integral(ConstInt::I32(ref mut i @ 11)) = *value {
46 *i = 42;
47 }
7453a54e
SL
48 }
49 }
50}
51
52#[plugin_registrar]
53pub fn plugin_registrar(reg: &mut Registry) {
54 reg.register_mir_pass(box Pass);
55}