]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add support for AST to HIR inline asm translation
authorjjasmine <tanghocle456@gmail.com>
Fri, 31 May 2024 21:55:45 +0000 (14:55 -0700)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:44 +0000 (16:35 +0100)
gcc/rust/ChangeLog:

* ast/rust-expr.h:
Add support for AST to HIR inline asm translation
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* hir/rust-ast-lower-expr.h: Likewise.
* hir/tree/rust-hir-expr.h (class InlineAsm): Likewise.

gcc/rust/ast/rust-expr.h
gcc/rust/hir/rust-ast-lower-base.cc
gcc/rust/hir/rust-ast-lower-base.h
gcc/rust/hir/rust-ast-lower-expr.cc
gcc/rust/hir/rust-ast-lower-expr.h
gcc/rust/hir/tree/rust-hir-expr.h

index ad742bfe85d6ba9a514b3d8ab5f16f8283bb9df9..cc8c6ea03500d0192c5f92a16d283eb749ccd195 100644 (file)
@@ -4994,6 +4994,16 @@ public:
 
   void set_outer_attrs (std::vector<Attribute> v) override { outer_attrs = v; }
 
+  std::vector<InlineAsmTemplatePiece> get_template_ () { return template_; }
+
+  std::vector<TupleTemplateStr> get_template_strs () { return template_strs; }
+
+  std::vector<InlineAsmOperand> get_operands () { return operands; }
+
+  std::vector<TupleClobber> get_clobber_abi () { return clobber_abi; }
+
+  std::set<InlineAsmOption> get_options () { return options; }
+
   InlineAsm *clone_expr_without_block_impl () const override
   {
     return new InlineAsm (*this);
index 96969782c98f07ae0f194374b47cb7c65899dd82..0f928a4f46209cfd61a5ddb50ddfc1712262f166 100644 (file)
@@ -248,6 +248,11 @@ ASTLoweringBase::visit (AST::IfLetExpr &)
 void
 ASTLoweringBase::visit (AST::IfLetExprConseqElse &)
 {}
+
+void
+ASTLoweringBase::visit (AST::InlineAsm &)
+{}
+
 //  void ASTLoweringBase::visit(MatchCasematch_case) {}
 // void ASTLoweringBase:: (AST::MatchCaseBlockExpr &) {}
 // void ASTLoweringBase:: (AST::MatchCaseExpr &) {}
index 94e0e48968ca4c1f65285a0ae009aac96ad759ca..1bd1343bd166d48e08109ca75a41a2ea1e287a68 100644 (file)
@@ -148,6 +148,7 @@ public:
   virtual void visit (AST::IfExprConseqElse &expr);
   virtual void visit (AST::IfLetExpr &expr);
   virtual void visit (AST::IfLetExprConseqElse &expr);
+  virtual void visit (AST::InlineAsm &expr);
   //  virtual void visit(MatchCase& match_case);
   // virtual void visit (AST::MatchCaseBlockExpr &match_case);
   // virtual void visit (AST::MatchCaseExpr &match_case);
index a0eb5e32f25b7ff36c4068a12a8010d9234ad102..be7ff413c93f4d9f9800cc6a9056a2d921515620 100644 (file)
@@ -829,6 +829,20 @@ ASTLoweringExpr::visit (AST::ClosureExprInnerTyped &expr)
                            expr.get_locus ());
 }
 
+void
+ASTLoweringExpr::visit (AST::InlineAsm &expr)
+{
+  auto crate_num = mappings.get_current_crate ();
+  Analysis::NodeMapping mapping (crate_num, expr.get_node_id (),
+                                mappings.get_next_hir_id (crate_num),
+                                mappings.get_next_localdef_id (crate_num));
+
+  translated
+    = new HIR::InlineAsm (expr.get_locus (), expr.is_global_asm,
+                         expr.get_template_ (), expr.get_template_strs (),
+                         expr.get_operands (), expr.get_clobber_abi (),
+                         expr.get_options (), mapping);
+}
 void
 ASTLoweringExpr::visit (AST::FormatArgs &fmt)
 {
index cd7b74aa7f2b1a0ae267308b235c103895eee6a4..fc53786613b3b4768c7e59ea8e4d33c6fba12ca2 100644 (file)
@@ -122,6 +122,7 @@ public:
   void visit (AST::RangeFromToInclExpr &expr) override;
   void visit (AST::ClosureExprInner &expr) override;
   void visit (AST::ClosureExprInnerTyped &expr) override;
+  void visit (AST::InlineAsm &expr) override;
 
   // Extra visitor for FormatArgs nodes
   void visit (AST::FormatArgs &fmt) override;
index 686c7311a4b3c8dbeefd99d9485ad6ccee0eae76..a0858a36f04c0426e600b8df9e49723bae685e58 100644 (file)
@@ -24,7 +24,7 @@
 #include "rust-hir.h"
 #include "rust-hir-path.h"
 #include "rust-operators.h"
-
+#include "rust-expr.h"
 namespace Rust {
 namespace HIR {
 
@@ -3865,13 +3865,69 @@ struct InlineAsmRegOrRegClass
 class InlineAsm : public ExprWithoutBlock
 {
   NodeId id;
+  location_t locus;
 
 public:
+  bool is_global_asm;
+
   std::vector<AST::InlineAsmTemplatePiece> template_;
   std::vector<AST::TupleTemplateStr> template_strs;
   std::vector<AST::InlineAsmOperand> operands;
-  AST::InlineAsmOption options;
+  std::vector<AST::TupleClobber> clobber_abi;
+  std::set<AST::InlineAsmOption> options;
+
   std::vector<location_t> line_spans;
+
+  void accept_vis (HIRExpressionVisitor &vis) override{};
+
+  void accept_vis (HIRFullVisitor &vis) override{};
+
+  std::string as_string () const override { return "InlineAsm HIR Node"; }
+
+  location_t get_locus () const override { return locus; }
+
+  InlineAsm *clone_expr_without_block_impl () const override
+  {
+    return new InlineAsm (*this);
+  }
+
+  ExprType get_expression_type () const final override
+  {
+    // TODO: Not sure if this expression type is UnsafeBlock or not.
+    return ExprType::UnsafeBlock;
+  }
+  std::vector<AST::InlineAsmTemplatePiece> get_template_ ()
+  {
+    return template_;
+  }
+
+  std::vector<AST::TupleTemplateStr> get_template_strs ()
+  {
+    return template_strs;
+  }
+
+  std::vector<AST::InlineAsmOperand> get_operands () { return operands; }
+
+  std::vector<AST::TupleClobber> get_clobber_abi () { return clobber_abi; }
+
+  std::set<AST::InlineAsmOption> get_options () { return options; }
+
+  InlineAsm (location_t locus, bool is_global_asm,
+            std::vector<AST::InlineAsmTemplatePiece> template_,
+            std::vector<AST::TupleTemplateStr> template_strs,
+            std::vector<AST::InlineAsmOperand> operands,
+            std::vector<AST::TupleClobber> clobber_abi,
+            std::set<AST::InlineAsmOption> options,
+            Analysis::NodeMapping mappings,
+            AST::AttrVec outer_attribs = AST::AttrVec ())
+    : ExprWithoutBlock (std::move (mappings), std::move (outer_attribs)),
+      locus (locus), is_global_asm (is_global_asm),
+      template_ (std::move (template_)),
+      template_strs (std::move (template_strs)),
+      operands (std::move (operands)), clobber_abi (std::move (clobber_abi)),
+      options (std::move (options))
+
+  {}
 };
 } // namespace HIR
 } // namespace Rust