]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add pretty hir dump for inline assembly
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Tue, 29 Jul 2025 11:42:14 +0000 (13:42 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:58 +0000 (16:36 +0200)
gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): Dump inline assembly fields
* hir/tree/rust-hir-expr.h: Add non const getter and avoid operand copy
from getters.
* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Use non const
reference.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/hir/rust-hir-dump.cc
gcc/rust/hir/tree/rust-hir-expr.h
gcc/rust/hir/tree/rust-hir-visitor.cc

index 18589316e9f77ee3a9ee2f174550140968ce88bf..3d61de9e8bd582ce30d23df4af747dee260a743e 100644 (file)
@@ -1529,7 +1529,74 @@ Dump::visit (AsyncBlockExpr &e)
 
 void
 Dump::visit (InlineAsm &e)
-{}
+{
+  begin ("InlineAsm");
+  do_expr (e);
+  for (auto &temp : e.get_template_ ())
+    {
+      put_field ("template", temp.string);
+    }
+
+  for (auto &temp_str : e.get_template_strs ())
+    {
+      put_field ("template_str", temp_str.symbol);
+    }
+
+  for (auto &operand : e.get_operands ())
+    {
+      switch (operand.get_register_type ())
+       {
+       case HIR::InlineAsmOperand::RegisterType::In:
+         {
+           const auto &in = operand.get_in ();
+           visit_field ("in expr", *in.expr);
+           break;
+         }
+       case HIR::InlineAsmOperand::RegisterType::Out:
+         {
+           const auto &out = operand.get_out ();
+           visit_field ("out expr", *out.expr);
+           break;
+         }
+       case HIR::InlineAsmOperand::RegisterType::InOut:
+         {
+           const auto &inout = operand.get_in_out ();
+           visit_field ("inout expr", *inout.expr);
+           break;
+         }
+       case HIR::InlineAsmOperand::RegisterType::SplitInOut:
+         {
+           const auto &inout = operand.get_split_in_out ();
+           begin ("Split in out");
+           visit_field ("in expr", *inout.in_expr);
+           visit_field ("out expr", *inout.out_expr);
+           end ("Split in out");
+
+           break;
+         }
+       case HIR::InlineAsmOperand::RegisterType::Const:
+         {
+           auto &cnst = operand.get_const ();
+           visit_field ("const expr", cnst.anon_const.get_inner_expr ());
+           break;
+         }
+       case HIR::InlineAsmOperand::RegisterType::Sym:
+         {
+           auto &sym = operand.get_sym ();
+           visit_field ("sym expr", *sym.expr);
+           break;
+         }
+       case HIR::InlineAsmOperand::RegisterType::Label:
+         {
+           auto &label = operand.get_label ();
+           put_field ("label name", label.label_name);
+           do_expr (*label.expr);
+           break;
+         }
+       }
+    }
+  end ("InlineAsm");
+}
 
 void
 Dump::visit (LlvmInlineAsm &e)
index 8e14a7b2912595f76c7c4078413a890e2db16be7..64d01ee6f00fe7d4524d99840605dbacca25e825 100644 (file)
@@ -3098,8 +3098,9 @@ public:
     Label operator= (const struct Label &other);
   };
 
-private:
   using RegisterType = AST::InlineAsmOperand::RegisterType;
+
+private:
   AST::InlineAsmOperand::RegisterType register_type;
 
   tl::optional<struct In> in;
@@ -3143,13 +3144,24 @@ public:
   RegisterType get_register_type () const { return register_type; }
 
   // Potentially unsafe without get_register_type() check
-  struct In get_in () const { return in.value (); }
-  struct Out get_out () const { return out.value (); }
-  struct InOut get_in_out () const { return in_out.value (); }
-  struct SplitInOut get_split_in_out () const { return split_in_out.value (); }
-  struct Const get_const () const { return cnst.value (); }
-  struct Sym get_sym () const { return sym.value (); }
-  struct Label get_label () const { return label.value (); }
+  const struct In &get_in () const { return in.value (); }
+  const struct Out &get_out () const { return out.value (); }
+  const struct InOut &get_in_out () const { return in_out.value (); }
+  const struct SplitInOut &get_split_in_out () const
+  {
+    return split_in_out.value ();
+  }
+  const struct Const &get_const () const { return cnst.value (); }
+  const struct Sym &get_sym () const { return sym.value (); }
+  const struct Label &get_label () const { return label.value (); }
+
+  struct In &get_in () { return in.value (); }
+  struct Out &get_out () { return out.value (); }
+  struct InOut &get_in_out () { return in_out.value (); }
+  struct SplitInOut &get_split_in_out () { return split_in_out.value (); }
+  struct Const &get_const () { return cnst.value (); }
+  struct Sym &get_sym () { return sym.value (); }
+  struct Label &get_label () { return label.value (); }
 };
 
 // Inline Assembly Node
@@ -3196,7 +3208,7 @@ public:
     return template_strs;
   }
 
-  std::vector<HIR::InlineAsmOperand> get_operands () { return operands; }
+  std::vector<HIR::InlineAsmOperand> &get_operands () { return operands; }
 
   std::vector<AST::TupleClobber> get_clobber_abi () { return clobber_abi; }
 
index ece47eba8519a93c35cb000142c26c323fd143af..77b96e547af9d5e9e9782430ab641c24c6e42819 100644 (file)
@@ -547,7 +547,7 @@ void
 DefaultHIRVisitor::walk (InlineAsm &expr)
 {
   visit_outer_attrs (expr);
-  const auto &operands = expr.get_operands ();
+  auto &operands = expr.get_operands ();
   using RegisterType = AST::InlineAsmOperand::RegisterType;
   for (auto &operand : operands)
     {