]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // Copyright 2012-2014 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 | ||
c34b1796 | 11 | |
1a4d82fc JJ |
12 | #![feature(asm)] |
13 | ||
14 | type History = Vec<&'static str>; | |
15 | ||
16 | fn wrap<A>(x:A, which: &'static str, history: &mut History) -> A { | |
17 | history.push(which); | |
18 | x | |
19 | } | |
20 | ||
21 | macro_rules! demo { | |
22 | ( $output_constraint:tt ) => { | |
23 | { | |
c34b1796 AL |
24 | let mut x: isize = 0; |
25 | let y: isize = 1; | |
1a4d82fc JJ |
26 | |
27 | let mut history: History = vec!(); | |
28 | unsafe { | |
29 | asm!("mov ($1), $0" | |
30 | : $output_constraint (*wrap(&mut x, "out", &mut history)) | |
5bcae85e SL |
31 | : "r"(&wrap(y, "in", &mut history)) |
32 | :: "volatile"); | |
1a4d82fc JJ |
33 | } |
34 | assert_eq!((x,y), (1,1)); | |
35 | let b: &[_] = &["out", "in"]; | |
85aaf69f | 36 | assert_eq!(history, b); |
1a4d82fc JJ |
37 | } |
38 | } | |
39 | } | |
40 | ||
41 | #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] | |
42 | fn main() { | |
43 | fn out_write_only_expr_then_in_expr() { | |
44 | demo!("=r") | |
45 | } | |
46 | ||
47 | fn out_read_write_expr_then_in_expr() { | |
48 | demo!("+r") | |
49 | } | |
50 | ||
51 | out_write_only_expr_then_in_expr(); | |
52 | out_read_write_expr_then_in_expr(); | |
53 | } | |
54 | ||
55 | #[cfg(all(not(target_arch = "x86"), not(target_arch = "x86_64")))] | |
56 | pub fn main() {} |