/src/test/assembly/asm/msp430-types.rs

https://gitlab.com/rust-lang/rust · Rust · 158 lines · 94 code · 20 blank · 44 comment · 5 complexity · e7b9c1a720eb5456ec1f79c49051b3ad MD5 · raw file

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