From 318cf22bd1955ba870a0a3189cb5dfdbce31b53e Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 13 Jan 2018 23:13:49 +0300 Subject: [PATCH] Move "no asm" check into AST validation --- src/librustc_driver/driver.rs | 6 +--- src/librustc_passes/ast_validation.rs | 3 ++ src/librustc_passes/lib.rs | 1 - src/librustc_passes/no_asm.rs | 47 --------------------------- 4 files changed, 4 insertions(+), 53 deletions(-) delete mode 100644 src/librustc_passes/no_asm.rs diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index b7265762208..75a7f990841 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -37,7 +37,7 @@ use rustc_typeck as typeck; use rustc_privacy; use rustc_plugin::registry::Registry; use rustc_plugin as plugin; -use rustc_passes::{self, ast_validation, no_asm, loops, consts, static_recursion, hir_stats}; +use rustc_passes::{self, ast_validation, loops, consts, static_recursion, hir_stats}; use rustc_const_eval::{self, check_match}; use super::Compilation; use ::DefaultTransCrate; @@ -856,10 +856,6 @@ pub fn phase_2_configure_and_expand(sess: &Session, println!("{}", json::as_json(&krate)); } - time(time_passes, - "checking for inline asm in case the target doesn't support it", - || no_asm::check_crate(sess, &krate)); - time(time_passes, "AST validation", || ast_validation::check_crate(sess, &krate)); diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs index 61f54774163..dbad82ed977 100644 --- a/src/librustc_passes/ast_validation.rs +++ b/src/librustc_passes/ast_validation.rs @@ -149,6 +149,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> { ExprKind::Continue(Some(ident)) => { self.check_label(ident.node, ident.span); } + ExprKind::InlineAsm(..) if !self.session.target.target.options.allow_asm => { + span_err!(self.session, expr.span, E0472, "asm! is unsupported on this target"); + } _ => {} } diff --git a/src/librustc_passes/lib.rs b/src/librustc_passes/lib.rs index 754c3bbd074..73c71ec0b2f 100644 --- a/src/librustc_passes/lib.rs +++ b/src/librustc_passes/lib.rs @@ -42,7 +42,6 @@ pub mod consts; pub mod hir_stats; pub mod loops; mod mir_stats; -pub mod no_asm; pub mod static_recursion; #[cfg(not(stage0))] // remove after the next snapshot diff --git a/src/librustc_passes/no_asm.rs b/src/librustc_passes/no_asm.rs deleted file mode 100644 index 4dbf57a99bc..00000000000 --- a/src/librustc_passes/no_asm.rs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -/// Run over the whole crate and check for ExprInlineAsm. -/// Inline asm isn't allowed on virtual ISA based targets, so we reject it -/// here. - -use rustc::session::Session; - -use syntax::ast; -use syntax::visit::Visitor; -use syntax::visit; - -pub fn check_crate(sess: &Session, krate: &ast::Crate) { - if sess.target.target.options.allow_asm { - return; - } - - visit::walk_crate(&mut CheckNoAsm { sess: sess }, krate); -} - -#[derive(Copy, Clone)] -struct CheckNoAsm<'a> { - sess: &'a Session, -} - -impl<'a> Visitor<'a> for CheckNoAsm<'a> { - fn visit_expr(&mut self, e: &'a ast::Expr) { - match e.node { - ast::ExprKind::InlineAsm(_) => { - span_err!(self.sess, - e.span, - E0472, - "asm! is unsupported on this target") - } - _ => {} - } - visit::walk_expr(self, e) - } -}