]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Provide input operand for gccrs
authorbadumbatish <tanghocle456@gmail.com>
Thu, 5 Sep 2024 06:59:36 +0000 (23:59 -0700)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 19 Mar 2025 14:32:17 +0000 (15:32 +0100)
gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_construct_inputs):
Provide input operand for gccrs
* expand/rust-macro-builtins-asm.cc (parse_reg_operand_in):
Move expr to In
(expand_inline_asm_strings):
Add comments to debug strings

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_parse_operand.rs:
Remove inout, functionality not supported. Remove redundant {}
* rust/execute/torture/inline_asm_mov_x_5_ARM.rs: Add operand in
* rust/execute/torture/inline_asm_mov_x_5_x86_64.rs: Likewise

gcc/rust/backend/rust-compile-asm.cc
gcc/rust/expand/rust-macro-builtins-asm.cc
gcc/testsuite/rust/compile/inline_asm_parse_operand.rs
gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5_ARM.rs
gcc/testsuite/rust/execute/torture/inline_asm_mov_x_5_x86_64.rs

index 8294feb219786991e2504bbc34717686570859f6..e85d08d05792a2e45e694b6e6180c39f7adb7ed0 100644 (file)
@@ -1,5 +1,4 @@
 #include "rust-compile-asm.h"
-#include "rust-system.h"
 #include "rust-compile-expr.h"
 namespace Rust {
 namespace Compile {
@@ -107,7 +106,26 @@ tree
 CompileAsm::asm_construct_inputs (HIR::InlineAsm &expr)
 {
   // TODO: Do i need to do this?
-  return NULL_TREE;
+  tree head = NULL_TREE;
+  for (auto &input : expr.get_operands ())
+    {
+      if (input.get_register_type () == AST::InlineAsmOperand::RegisterType::In)
+       {
+         auto in = input.get_in ();
+
+         tree in_tree = CompileExpr::Compile (in.expr.get (), this->ctx);
+         // expects a tree list
+         // TODO: This assumes that the input is a register
+         std::string expr_name = "r";
+         auto name = build_string (expr_name.size () + 1, expr_name.c_str ());
+         head
+           = chainon (head, build_tree_list (build_tree_list (NULL_TREE, name),
+                                             in_tree));
+
+         /*head = chainon (head, out_tree);*/
+       }
+    }
+  return head;
 }
 
 tree
index 1017d9fd6c4d1c088d7ecb5907fa1aaac581bc11..e970f285202e0b0f8ef6a1cf05495b586965e4a5 100644 (file)
@@ -330,8 +330,8 @@ parse_reg_operand_in (InlineAsmContext inline_asm_ctx)
 
       // TODO: When we've succesfully parse an expr, remember to clone_expr()
       // instead of nullptr
-      // struct AST::InlineAsmOperand::In in (reg, nullptr);
-      // inline_asm_ctx.inline_asm.operands.push_back (in);
+      struct AST::InlineAsmOperand::In in (reg, std::move (expr));
+      inline_asm_ctx.inline_asm.operands.push_back (in);
       return inline_asm_ctx;
     }
   return tl::unexpected<InlineAsmParseError> (NONCOMMITED);
@@ -792,8 +792,9 @@ expand_inline_asm_strings (InlineAsmContext inline_asm_ctx)
                     * trait});*/
 
                    transformed_template_str += "%" + std::to_string (idx);
-                   /*std::cout << "argument implicitly is: " << idx <<
-                    * std::endl;*/
+                   // std::cout << "argument implicitly is: " << idx <<
+                   // std::endl; std::cout << "transformed template str is:"
+                   // << transformed_template_str << std::endl;
                    /*std::cout << "trait: " << trait.to_string () <<
                     * std::endl;*/
                    /*std::cout << "arg: " << arg.to_string () << std::endl;*/
index e0efe1c420da63c77cc5c049e139ea0d954f46d5..c7bc152c7ced2b7aa10bec37fbd93644535533fc 100644 (file)
@@ -8,7 +8,7 @@ macro_rules! asm {
 fn main() -> i32 {
     unsafe {
         asm!(
-            "add {}, {}",
+            "add {}, 1",
             in(reg) 0
         );
     }
@@ -21,15 +21,15 @@ fn main() -> i32 {
     unsafe {
         asm!(
             "add {}, {}",
-            inout(reg) num1 =>_num1,
             in(reg) _num2,
+            out(reg) _num1,
         );
     }
 
     let mut _output_testing: u32 = 0;
     unsafe {
         asm!(
-            "add {}, {}",
+            "add {}, 1",
             in(reg) _num1,
             //out(reg) _,
         );
index 4e762608230f5ccc3c7e12875af7696ab9a921cb..0c867df657eb52dd7c981cf8416317829d6235e1 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do run { target arm*-*-* } } */
-/* { dg-output "5\r*\n" }*/
+/* { dg-output "5\r*\n9\r*\n" }*/
 
 #![feature(rustc_attrs)]
 #[rustc_builtin_macro]
@@ -13,12 +13,24 @@ extern "C" {
 
 fn main() -> i32 {
     let mut _x: i32 = 0;
+    let mut _y: i32 = 9;
+
     unsafe {
         asm!(
             "mov {}, 5",
             out(reg) _x
         );
         printf("%d\n\0" as *const str as *const i8, _x);
+    };
+
+    unsafe {
+        asm!(
+            "mov {}, {}",
+            in(reg) _y,
+            out(reg) _x
+        );
+        printf("%d\n\0" as *const str as *const i8, _x);
     }
+
     0
 }
index c6086e00d4606323dec7ccc8ee4ab9fdf8fcbc9f..5fbbb68d31cd130f006f33455b130d2576c058b7 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do run { target x86_64*-*-* } } */
-/* { dg-output "5\r*\n" }*/
+/* { dg-output "5\r*\n9\r*\n" }*/
 
 #![feature(rustc_attrs)]
 #[rustc_builtin_macro]
@@ -12,13 +12,24 @@ extern "C" {
 }
 
 fn main() -> i32 {
-    let mut _x: i32 = 0;
+    let mut x: i32 = 0;
+    let mut _y: i32 = 9; // Mark it as _y since it is only used as input operand, not printing
+
     unsafe {
         asm!(
             "mov $5, {}",
-            out(reg) _x
+            out(reg) x
+        );
+        printf("%d\n\0" as *const str as *const i8, x);
+    };
+
+    unsafe {
+        asm!(
+            "mov {}, {}",
+            in(reg) _y,
+            out(reg) x,
         );
-        printf("%d\n\0" as *const str as *const i8, _x);
+        printf("%d\n\0" as *const str as *const i8, x);
     }
     0
 }