File tree Expand file tree Collapse file tree 4 files changed +49
-0
lines changed Expand file tree Collapse file tree 4 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -112,6 +112,7 @@ pub mod middle {
112112 pub mod check_static_recursion;
113113 pub mod check_loop;
114114 pub mod check_match;
115+ pub mod check_no_asm;
115116 pub mod check_rvalues;
116117 pub mod const_eval;
117118 pub mod dataflow;
Original file line number Diff line number Diff line change 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 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 ( _) => self . sess . span_err ( e. span ,
36+ "asm! is unsupported on this target" ) ,
37+ _ => { } ,
38+ }
39+ visit:: walk_expr ( self , e)
40+ }
41+ }
Original file line number Diff line number Diff line change @@ -168,6 +168,8 @@ pub struct TargetOptions {
168168 /// currently only "gnu" is used to fall into LLVM. Unknown strings cause
169169 /// the system linker to be used.
170170 pub archive_format : String ,
171+ /// Is asm!() allowed? Defaults to true.
172+ pub allow_asm : bool ,
171173 /// Whether the target uses a custom unwind resumption routine.
172174 /// By default LLVM lowers `resume` instructions into calls to `_Unwind_Resume`
173175 /// defined in libgcc. If this option is enabled, the target must provide
@@ -217,6 +219,7 @@ impl Default for TargetOptions {
217219 custom_unwind_resume : false ,
218220 lib_allocation_crate : "alloc_system" . to_string ( ) ,
219221 exe_allocation_crate : "alloc_system" . to_string ( ) ,
222+ allow_asm : true ,
220223 }
221224 }
222225}
@@ -310,6 +313,7 @@ impl Target {
310313 key ! ( no_compiler_rt, bool ) ;
311314 key ! ( pre_link_args, list) ;
312315 key ! ( post_link_args, list) ;
316+ key ! ( allow_asm, bool ) ;
313317
314318 base
315319 }
Original file line number Diff line number Diff line change @@ -563,6 +563,9 @@ pub fn phase_2_configure_and_expand(sess: &Session,
563563 time ( time_passes, "checking that all macro invocations are gone" , ||
564564 syntax:: ext:: expand:: check_for_macros ( & sess. parse_sess , & krate) ) ;
565565
566+ time ( time_passes, "checking for inline asm in case the target doesn't support it" , ||
567+ middle:: check_no_asm:: check_crate ( sess, & krate) ) ;
568+
566569 // One final feature gating of the true AST that gets compiled
567570 // later, to make sure we've got everything (e.g. configuration
568571 // can insert new attributes via `cfg_attr`)
You can’t perform that action at this time.
0 commit comments