]> git.lizzy.rs Git - rust.git/blob - tests/assembly/asm/msp430-types.rs
Rollup merge of #107048 - DebugSteven:newer-x-check-cargo, r=albertlarsan68
[rust.git] / tests / assembly / asm / msp430-types.rs
1 // assembly-output: emit-asm
2 // compile-flags: --target msp430-none-elf
3 // needs-llvm-components: msp430
4
5 #![feature(no_core, lang_items, rustc_attrs, asm_experimental_arch, asm_const)]
6 #![crate_type = "rlib"]
7 #![no_core]
8 #![allow(non_camel_case_types)]
9
10 #[rustc_builtin_macro]
11 macro_rules! asm {
12     () => {};
13 }
14 #[rustc_builtin_macro]
15 macro_rules! concat {
16     () => {};
17 }
18
19 #[lang = "sized"]
20 trait Sized {}
21 #[lang = "copy"]
22 trait Copy {}
23
24 type ptr = *const i16;
25
26 impl Copy for i8 {}
27 impl Copy for i16 {}
28 impl Copy for i32 {}
29 impl Copy for i64 {}
30 impl Copy for ptr {}
31
32 macro_rules! check {
33     ($func:ident $ty:ident $class:ident) => {
34         #[no_mangle]
35         pub unsafe fn $func(x: $ty) -> $ty {
36             let y;
37             asm!("mov {}, {}", lateout($class) y, in($class) x);
38             y
39         }
40     };
41 }
42
43 macro_rules! checkb {
44     ($func:ident $ty:ident $class:ident) => {
45         #[no_mangle]
46         pub unsafe fn $func(x: $ty) -> $ty {
47             let y;
48             asm!("mov.b {}, {}", lateout($class) y, in($class) x);
49             y
50         }
51     };
52 }
53
54 macro_rules! check_reg {
55     ($func:ident $ty:ident $reg:tt) => {
56         #[no_mangle]
57         pub unsafe fn $func(x: $ty) -> $ty {
58             let y;
59             asm!(concat!("mov ", $reg, ", ", $reg), lateout($reg) y, in($reg) x);
60             y
61         }
62     };
63 }
64
65 macro_rules! check_regb {
66     ($func:ident $ty:ident $reg:tt) => {
67         #[no_mangle]
68         pub unsafe fn $func(x: $ty) -> $ty {
69             let y;
70             asm!(concat!("mov.b ", $reg, ", ", $reg), lateout($reg) y, in($reg) x);
71             y
72         }
73     };
74 }
75
76 extern "C" {
77     fn extern_func();
78     static extern_static: i8;
79 }
80
81 // CHECK-LABEL: sym_fn
82 // CHECK: ;APP
83 // CHECK: call extern_func
84 // CHECK: ;NO_APP
85 #[no_mangle]
86 pub unsafe fn sym_fn() {
87     asm!("call {}", sym extern_func);
88 }
89
90 // CHECK-LABEL: sym_static
91 // CHECK: ;APP
92 // CHECK: mov.b extern_static, r{{[0-9]+}}
93 // CHECK: ;NO_APP
94 #[no_mangle]
95 pub unsafe fn sym_static() -> i8 {
96     let y;
97     asm!("mov.b {1}, {0}", lateout(reg) y, sym extern_static);
98     y
99 }
100
101 // CHECK-LABEL: add_const:
102 // CHECK: ;APP
103 // CHECK: add.b #5, r{{[0-9]+}}
104 // CHECK: ;NO_APP
105 #[no_mangle]
106 pub unsafe fn add_const() -> i8 {
107     let y;
108     asm!("add.b #{number}, {}", out(reg) y, number = const 5);
109     y
110 }
111
112 // CHECK-LABEL: mov_postincrement:
113 // CHECK: ;APP
114 // CHECK: mov @r5+, r{{[0-9]+}}
115 // CHECK: ;NO_APP
116 #[no_mangle]
117 pub unsafe fn mov_postincrement(mut x: *const i16) -> (i16, *const i16) {
118     let y;
119     asm!("mov @r5+, {0}", out(reg) y, inlateout("r5") x);
120     (y, x)
121 }
122
123 // CHECK-LABEL: reg_i8:
124 // CHECK: ;APP
125 // CHECK: mov r{{[0-9]+}}, r{{[0-9]+}}
126 // CHECK: ;NO_APP
127 check!(reg_i8 i8 reg);
128
129 // CHECK-LABEL: reg_i16:
130 // CHECK: ;APP
131 // CHECK: mov r{{[0-9]+}}, r{{[0-9]+}}
132 // CHECK: ;NO_APP
133 check!(reg_i16 i16 reg);
134
135 // CHECK-LABEL: reg_i8b:
136 // CHECK: ;APP
137 // CHECK: mov.b r{{[0-9]+}}, r{{[0-9]+}}
138 // CHECK: ;NO_APP
139 checkb!(reg_i8b i8 reg);
140
141 // CHECK-LABEL: r5_i8:
142 // CHECK: ;APP
143 // CHECK: mov r5, r5
144 // CHECK: ;NO_APP
145 check_reg!(r5_i8 i8 "r5");
146
147 // CHECK-LABEL: r5_i16:
148 // CHECK: ;APP
149 // CHECK: mov r5, r5
150 // CHECK: ;NO_APP
151 check_reg!(r5_i16 i16 "r5");
152
153 // CHECK-LABEL: r5_i8b:
154 // CHECK: ;APP
155 // CHECK: mov.b r5, r5
156 // CHECK: ;NO_APP
157 check_regb!(r5_i8b i8 "r5");