]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Implement resolve expr for inline asm ast
authorbadumbatish <tanghocle456@gmail.com>
Wed, 31 Jul 2024 03:22:48 +0000 (20:22 -0700)
committerArthur Cohen <arthur.cohen@embecosm.com>
Wed, 19 Mar 2025 14:32:02 +0000 (15:32 +0100)
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.

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

index 44ba2a8dffc4f4be971972e617e518e443156db2..7c2ba9c9d2cfc823228ac5e234da34def79ce438 100644 (file)
@@ -347,6 +347,60 @@ ResolveExpr::visit (AST::BlockExpr &expr)
   resolver->get_label_scope ().pop ();
 }
 
+void
+translate_operand (AST::InlineAsm &expr, const CanonicalPath &prefix,
+                  const CanonicalPath &canonical_prefix)
+{
+  const auto &operands = expr.get_operands ();
+  using RegisterType = AST::InlineAsmOperand::RegisterType;
+  for (auto &operand : operands)
+    {
+      switch (operand.get_register_type ())
+       {
+         case RegisterType::In: {
+           auto in = operand.get_in ();
+           ResolveExpr::go (*in.expr, prefix, canonical_prefix);
+           break;
+         }
+         case RegisterType::Out: {
+           auto out = operand.get_out ();
+           ResolveExpr::go (*out.expr, prefix, canonical_prefix);
+           break;
+         }
+         case RegisterType::InOut: {
+           auto in_out = operand.get_in_out ();
+           ResolveExpr::go (*in_out.expr, prefix, canonical_prefix);
+           break;
+         }
+         case RegisterType::SplitInOut: {
+           auto split_in_out = operand.get_split_in_out ();
+           ResolveExpr::go (*split_in_out.in_expr, prefix, canonical_prefix);
+           ResolveExpr::go (*split_in_out.out_expr, prefix, canonical_prefix);
+           break;
+         }
+         case RegisterType::Const: {
+           auto anon_const = operand.get_const ().anon_const;
+           ResolveExpr::go (*anon_const.expr, prefix, canonical_prefix);
+           break;
+         }
+         case RegisterType::Sym: {
+           auto sym = operand.get_sym ();
+           ResolveExpr::go (*sym.expr, prefix, canonical_prefix);
+           break;
+         }
+         case RegisterType::Label: {
+           auto label = operand.get_label ();
+           ResolveExpr::go (*label.expr, prefix, canonical_prefix);
+           break;
+         }
+       }
+    }
+}
+void
+ResolveExpr::visit (AST::InlineAsm &expr)
+{
+  translate_operand (expr, prefix, canonical_prefix);
+}
 void
 ResolveExpr::visit (AST::UnsafeBlockExpr &expr)
 {
@@ -478,12 +532,13 @@ ResolveExpr::visit (AST::BreakExpr &expr)
       auto &break_expr = expr.get_break_expr ();
       if (break_expr.get_ast_kind () == AST::Kind::IDENTIFIER)
        {
-         /* This is a break with an expression, and the expression is just a
-            single identifier.  See if the identifier is either "rust" or
-            "gcc", in which case we have "break rust" or "break gcc", and so
-            may need to emit our funny error.  We cannot yet emit the error
-            here though, because the identifier may still be in scope, and
-            ICE'ing on valid programs would not be very funny.  */
+         /* This is a break with an expression, and the expression is
+            just a single identifier.  See if the identifier is either
+            "rust" or "gcc", in which case we have "break rust" or "break
+            gcc", and so may need to emit our funny error.  We cannot yet
+            emit the error here though, because the identifier may still
+            be in scope, and ICE'ing on valid programs would not be very
+            funny.  */
          std::string ident
            = static_cast<AST::IdentifierExpr &> (break_expr).as_string ();
          if (ident == "rust" || ident == "gcc")
index 75b07b81ec79628ab59476e5f57d975dd8080d79..51a69e9886cc6ec13bbca4db10f679dcb5e121cc 100644 (file)
@@ -20,6 +20,7 @@
 #define RUST_AST_RESOLVE_EXPR_H
 
 #include "rust-ast-resolve-base.h"
+#include "rust-ast.h"
 #include "rust-ast-resolve-pattern.h"
 
 namespace Rust {
@@ -54,6 +55,7 @@ public:
   void visit (AST::IfLetExpr &expr) override;
   void visit (AST::IfLetExprConseqElse &expr) override;
   void visit (AST::BlockExpr &expr) override;
+  void visit (AST::InlineAsm &expr) override;
   void visit (AST::UnsafeBlockExpr &expr) override;
   void visit (AST::ArrayElemsValues &elems) override;
   void visit (AST::ArrayExpr &expr) override;