]> git.lizzy.rs Git - rust.git/blob - src/librustc_passes/no_asm.rs
Rollup merge of #31031 - brson:issue-30123, r=nikomatsakis
[rust.git] / src / librustc_passes / no_asm.rs
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 /// Run over the whole crate and check for ExprInlineAsm.
12 /// Inline asm isn't allowed on virtual ISA based targets, so we reject it
13 /// here.
14
15 use rustc::session::Session;
16
17 use syntax::ast;
18 use syntax::visit::Visitor;
19 use syntax::visit;
20
21 pub fn check_crate(sess: &Session, krate: &ast::Crate) {
22     if sess.target.target.options.allow_asm { return; }
23
24     visit::walk_crate(&mut CheckNoAsm { sess: sess, }, krate);
25 }
26
27 #[derive(Copy, Clone)]
28 struct CheckNoAsm<'a> {
29     sess: &'a Session,
30 }
31
32 impl<'a, 'v> Visitor<'v> for CheckNoAsm<'a> {
33     fn visit_expr(&mut self, e: &ast::Expr) {
34         match e.node {
35             ast::ExprInlineAsm(_) => span_err!(self.sess, e.span, E0472,
36                                                "asm! is unsupported on this target"),
37             _ => {},
38         }
39         visit::walk_expr(self, e)
40     }
41 }