Skip to content

Commit cdeec23

Browse files
P-E-PCohenArthur
authored andcommitted
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 <[email protected]>
1 parent 5df539d commit cdeec23

File tree

3 files changed

+90
-11
lines changed

3 files changed

+90
-11
lines changed

gcc/rust/hir/rust-hir-dump.cc

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,74 @@ Dump::visit (AsyncBlockExpr &e)
15291529

15301530
void
15311531
Dump::visit (InlineAsm &e)
1532-
{}
1532+
{
1533+
begin ("InlineAsm");
1534+
do_expr (e);
1535+
for (auto &temp : e.get_template_ ())
1536+
{
1537+
put_field ("template", temp.string);
1538+
}
1539+
1540+
for (auto &temp_str : e.get_template_strs ())
1541+
{
1542+
put_field ("template_str", temp_str.symbol);
1543+
}
1544+
1545+
for (auto &operand : e.get_operands ())
1546+
{
1547+
switch (operand.get_register_type ())
1548+
{
1549+
case HIR::InlineAsmOperand::RegisterType::In:
1550+
{
1551+
const auto &in = operand.get_in ();
1552+
visit_field ("in expr", *in.expr);
1553+
break;
1554+
}
1555+
case HIR::InlineAsmOperand::RegisterType::Out:
1556+
{
1557+
const auto &out = operand.get_out ();
1558+
visit_field ("out expr", *out.expr);
1559+
break;
1560+
}
1561+
case HIR::InlineAsmOperand::RegisterType::InOut:
1562+
{
1563+
const auto &inout = operand.get_in_out ();
1564+
visit_field ("inout expr", *inout.expr);
1565+
break;
1566+
}
1567+
case HIR::InlineAsmOperand::RegisterType::SplitInOut:
1568+
{
1569+
const auto &inout = operand.get_split_in_out ();
1570+
begin ("Split in out");
1571+
visit_field ("in expr", *inout.in_expr);
1572+
visit_field ("out expr", *inout.out_expr);
1573+
end ("Split in out");
1574+
1575+
break;
1576+
}
1577+
case HIR::InlineAsmOperand::RegisterType::Const:
1578+
{
1579+
auto &cnst = operand.get_const ();
1580+
visit_field ("const expr", cnst.anon_const.get_inner_expr ());
1581+
break;
1582+
}
1583+
case HIR::InlineAsmOperand::RegisterType::Sym:
1584+
{
1585+
auto &sym = operand.get_sym ();
1586+
visit_field ("sym expr", *sym.expr);
1587+
break;
1588+
}
1589+
case HIR::InlineAsmOperand::RegisterType::Label:
1590+
{
1591+
auto &label = operand.get_label ();
1592+
put_field ("label name", label.label_name);
1593+
do_expr (*label.expr);
1594+
break;
1595+
}
1596+
}
1597+
}
1598+
end ("InlineAsm");
1599+
}
15331600

15341601
void
15351602
Dump::visit (LlvmInlineAsm &e)

gcc/rust/hir/tree/rust-hir-expr.h

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,8 +3098,9 @@ class InlineAsmOperand
30983098
Label operator= (const struct Label &other);
30993099
};
31003100

3101-
private:
31023101
using RegisterType = AST::InlineAsmOperand::RegisterType;
3102+
3103+
private:
31033104
AST::InlineAsmOperand::RegisterType register_type;
31043105

31053106
tl::optional<struct In> in;
@@ -3143,13 +3144,24 @@ class InlineAsmOperand
31433144
RegisterType get_register_type () const { return register_type; }
31443145

31453146
// Potentially unsafe without get_register_type() check
3146-
struct In get_in () const { return in.value (); }
3147-
struct Out get_out () const { return out.value (); }
3148-
struct InOut get_in_out () const { return in_out.value (); }
3149-
struct SplitInOut get_split_in_out () const { return split_in_out.value (); }
3150-
struct Const get_const () const { return cnst.value (); }
3151-
struct Sym get_sym () const { return sym.value (); }
3152-
struct Label get_label () const { return label.value (); }
3147+
const struct In &get_in () const { return in.value (); }
3148+
const struct Out &get_out () const { return out.value (); }
3149+
const struct InOut &get_in_out () const { return in_out.value (); }
3150+
const struct SplitInOut &get_split_in_out () const
3151+
{
3152+
return split_in_out.value ();
3153+
}
3154+
const struct Const &get_const () const { return cnst.value (); }
3155+
const struct Sym &get_sym () const { return sym.value (); }
3156+
const struct Label &get_label () const { return label.value (); }
3157+
3158+
struct In &get_in () { return in.value (); }
3159+
struct Out &get_out () { return out.value (); }
3160+
struct InOut &get_in_out () { return in_out.value (); }
3161+
struct SplitInOut &get_split_in_out () { return split_in_out.value (); }
3162+
struct Const &get_const () { return cnst.value (); }
3163+
struct Sym &get_sym () { return sym.value (); }
3164+
struct Label &get_label () { return label.value (); }
31533165
};
31543166

31553167
// Inline Assembly Node
@@ -3196,7 +3208,7 @@ class InlineAsm : public ExprWithoutBlock
31963208
return template_strs;
31973209
}
31983210

3199-
std::vector<HIR::InlineAsmOperand> get_operands () { return operands; }
3211+
std::vector<HIR::InlineAsmOperand> &get_operands () { return operands; }
32003212

32013213
std::vector<AST::TupleClobber> get_clobber_abi () { return clobber_abi; }
32023214

gcc/rust/hir/tree/rust-hir-visitor.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ void
547547
DefaultHIRVisitor::walk (InlineAsm &expr)
548548
{
549549
visit_outer_attrs (expr);
550-
const auto &operands = expr.get_operands ();
550+
auto &operands = expr.get_operands ();
551551
using RegisterType = AST::InlineAsmOperand::RegisterType;
552552
for (auto &operand : operands)
553553
{

0 commit comments

Comments
 (0)