https://gcc.gnu.org/g:37ecb97134bc8b0ce28ef2caa946587f0c4bcd05
commit r16-2962-g37ecb97134bc8b0ce28ef2caa946587f0c4bcd05 Author: Pierre-Emmanuel Patry <pierre-emmanuel.pa...@embecosm.com> Date: Tue Jul 29 13:42:14 2025 +0200 gccrs: Add pretty hir dump for inline assembly 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.pa...@embecosm.com> Diff: --- gcc/rust/hir/rust-hir-dump.cc | 69 ++++++++++++++++++++++++++++++++++- gcc/rust/hir/tree/rust-hir-expr.h | 30 ++++++++++----- gcc/rust/hir/tree/rust-hir-visitor.cc | 2 +- 3 files changed, 90 insertions(+), 11 deletions(-) diff --git a/gcc/rust/hir/rust-hir-dump.cc b/gcc/rust/hir/rust-hir-dump.cc index 18589316e9f7..3d61de9e8bd5 100644 --- a/gcc/rust/hir/rust-hir-dump.cc +++ b/gcc/rust/hir/rust-hir-dump.cc @@ -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) diff --git a/gcc/rust/hir/tree/rust-hir-expr.h b/gcc/rust/hir/tree/rust-hir-expr.h index 8e14a7b29125..64d01ee6f00f 100644 --- a/gcc/rust/hir/tree/rust-hir-expr.h +++ b/gcc/rust/hir/tree/rust-hir-expr.h @@ -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; } diff --git a/gcc/rust/hir/tree/rust-hir-visitor.cc b/gcc/rust/hir/tree/rust-hir-visitor.cc index ece47eba8519..77b96e547af9 100644 --- a/gcc/rust/hir/tree/rust-hir-visitor.cc +++ b/gcc/rust/hir/tree/rust-hir-visitor.cc @@ -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) {