Skip to content

Commit 812c534

Browse files
badumbatishCohenArthur
authored andcommitted
Implement resolve expr for inline asm ast
gcc/rust/ChangeLog: * resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Implement resolve expr for inline asm ast (translate_operand): Likewise. * resolve/rust-ast-resolve-expr.h: Likewise.
1 parent bcd860f commit 812c534

File tree

2 files changed

+63
-6
lines changed

2 files changed

+63
-6
lines changed

gcc/rust/resolve/rust-ast-resolve-expr.cc

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,60 @@ ResolveExpr::visit (AST::BlockExpr &expr)
346346
resolver->get_label_scope ().pop ();
347347
}
348348

349+
void
350+
translate_operand (AST::InlineAsm &expr, const CanonicalPath &prefix,
351+
const CanonicalPath &canonical_prefix)
352+
{
353+
const auto &operands = expr.get_operands ();
354+
using RegisterType = AST::InlineAsmOperand::RegisterType;
355+
for (auto &operand : operands)
356+
{
357+
switch (operand.get_register_type ())
358+
{
359+
case RegisterType::In: {
360+
auto in = operand.get_in ();
361+
ResolveExpr::go (*in.expr, prefix, canonical_prefix);
362+
break;
363+
}
364+
case RegisterType::Out: {
365+
auto out = operand.get_out ();
366+
ResolveExpr::go (*out.expr, prefix, canonical_prefix);
367+
break;
368+
}
369+
case RegisterType::InOut: {
370+
auto in_out = operand.get_in_out ();
371+
ResolveExpr::go (*in_out.expr, prefix, canonical_prefix);
372+
break;
373+
}
374+
case RegisterType::SplitInOut: {
375+
auto split_in_out = operand.get_split_in_out ();
376+
ResolveExpr::go (*split_in_out.in_expr, prefix, canonical_prefix);
377+
ResolveExpr::go (*split_in_out.out_expr, prefix, canonical_prefix);
378+
break;
379+
}
380+
case RegisterType::Const: {
381+
auto anon_const = operand.get_const ().anon_const;
382+
ResolveExpr::go (*anon_const.expr, prefix, canonical_prefix);
383+
break;
384+
}
385+
case RegisterType::Sym: {
386+
auto sym = operand.get_sym ();
387+
ResolveExpr::go (*sym.expr, prefix, canonical_prefix);
388+
break;
389+
}
390+
case RegisterType::Label: {
391+
auto label = operand.get_label ();
392+
ResolveExpr::go (*label.expr, prefix, canonical_prefix);
393+
break;
394+
}
395+
}
396+
}
397+
}
398+
void
399+
ResolveExpr::visit (AST::InlineAsm &expr)
400+
{
401+
translate_operand (expr, prefix, canonical_prefix);
402+
}
349403
void
350404
ResolveExpr::visit (AST::UnsafeBlockExpr &expr)
351405
{
@@ -477,12 +531,13 @@ ResolveExpr::visit (AST::BreakExpr &expr)
477531
auto &break_expr = expr.get_break_expr ();
478532
if (break_expr.get_ast_kind () == AST::Kind::IDENTIFIER)
479533
{
480-
/* This is a break with an expression, and the expression is just a
481-
single identifier. See if the identifier is either "rust" or
482-
"gcc", in which case we have "break rust" or "break gcc", and so
483-
may need to emit our funny error. We cannot yet emit the error
484-
here though, because the identifier may still be in scope, and
485-
ICE'ing on valid programs would not be very funny. */
534+
/* This is a break with an expression, and the expression is
535+
just a single identifier. See if the identifier is either
536+
"rust" or "gcc", in which case we have "break rust" or "break
537+
gcc", and so may need to emit our funny error. We cannot yet
538+
emit the error here though, because the identifier may still
539+
be in scope, and ICE'ing on valid programs would not be very
540+
funny. */
486541
std::string ident
487542
= static_cast<AST::IdentifierExpr &> (break_expr).as_string ();
488543
if (ident == "rust" || ident == "gcc")

gcc/rust/resolve/rust-ast-resolve-expr.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define RUST_AST_RESOLVE_EXPR_H
2121

2222
#include "rust-ast-resolve-base.h"
23+
#include "rust-ast.h"
2324
#include "rust-ast-resolve-pattern.h"
2425

2526
namespace Rust {
@@ -54,6 +55,7 @@ class ResolveExpr : public ResolverBase
5455
void visit (AST::IfLetExpr &expr) override;
5556
void visit (AST::IfLetExprConseqElse &expr) override;
5657
void visit (AST::BlockExpr &expr) override;
58+
void visit (AST::InlineAsm &expr) override;
5759
void visit (AST::UnsafeBlockExpr &expr) override;
5860
void visit (AST::ArrayElemsValues &elems) override;
5961
void visit (AST::ArrayExpr &expr) override;

0 commit comments

Comments
 (0)