]>
Commit | Line | Data |
---|---|---|
e9174d1e 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 | /// 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 | ||
9cc50fc6 | 15 | use rustc::session::Session; |
e9174d1e SL |
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) { | |
5bcae85e SL |
22 | if sess.target.target.options.allow_asm { |
23 | return; | |
24 | } | |
e9174d1e | 25 | |
5bcae85e | 26 | visit::walk_crate(&mut CheckNoAsm { sess: sess }, krate); |
e9174d1e SL |
27 | } |
28 | ||
29 | #[derive(Copy, Clone)] | |
30 | struct CheckNoAsm<'a> { | |
31 | sess: &'a Session, | |
32 | } | |
33 | ||
476ff2be SL |
34 | impl<'a> Visitor<'a> for CheckNoAsm<'a> { |
35 | fn visit_expr(&mut self, e: &'a ast::Expr) { | |
e9174d1e | 36 | match e.node { |
5bcae85e SL |
37 | ast::ExprKind::InlineAsm(_) => { |
38 | span_err!(self.sess, | |
39 | e.span, | |
40 | E0472, | |
41 | "asm! is unsupported on this target") | |
42 | } | |
43 | _ => {} | |
e9174d1e SL |
44 | } |
45 | visit::walk_expr(self, e) | |
46 | } | |
47 | } |