]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Added HIR::InlineAsm node
authorM V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
Thu, 16 Mar 2023 05:33:57 +0000 (11:03 +0530)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 17:37:16 +0000 (18:37 +0100)
Fixes Issue #1568
Added HIR node HIR::InlineAsm similar to the one found in rustc. In this
I also changed the defination of the AST::InlineAsm node, so that we can
reuse many of it's data members in the HIR::InlineAsm node.

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h (enum class): Added declaration.
(struct AnonConst): Added declaration.
(struct InlineAsmRegOrRegClass): Added declaration.
(struct InlineAsmOperand): Added declaration.
(struct InlineAsmPlaceHolder): Added declaration.
(struct InlineAsmTemplatePiece): Added declaration.
(struct TupleClobber): Added declaration.
(struct TupleTemplateStr): Added declaration.
* ast/rust-expr.h (class InlineAsm): Defined all it's data members outside.
(enum class InlineAsmOptions): Converted this to a enum class so we could use it in the HIR.
(struct AnonConst): Defined it independent of the AST::InlineAsm node.
(struct InlineAsmRegOrRegClass): Defined it independent of the AST::InlineAsm node.
(struct InlineAsmOperand): Defined it independent of the AST::InlineAsm node.
(struct InlineAsmPlaceHolder): Defined it independent of the AST::InlineAsm node.
(struct InlineAsmTemplatePiece): Defined it independent of the AST::InlineAsm node.
(struct TupleClobber): Defined it independent of the AST::InlineAsm node.
(struct TupleTemplateStr): Defined it independent of the AST::InlineAsm node.
* hir/tree/rust-hir-expr.h (class InlineAsmReg): Added defination.
(class InlineAsmRegClass): Added defination.
(struct InlineAsmRegOrRegClass): Added defination.
(class InlineAsm): Added defination.
* hir/tree/rust-hir-full-decls.h (class InlineAsmReg): Added declaration.
(class InlineAsmRegClass): Added declaration.
(struct InlineAsmRegOrRegClass): Added declaration.
(class InlineAsm): Added declaration.

Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
gcc/rust/ast/rust-ast-full-decls.h
gcc/rust/ast/rust-expr.h
gcc/rust/hir/tree/rust-hir-expr.h
gcc/rust/hir/tree/rust-hir-full-decls.h

index bd59c526ddc3786c7ec4e6227d26f0b23c07053e..de0f12b04bc571bbc868439180ce40ae911d36a6 100644 (file)
@@ -145,6 +145,14 @@ struct MatchCase;
 class MatchExpr;
 class AwaitExpr;
 class AsyncBlockExpr;
+enum class InlineAsmOptions;
+struct AnonConst;
+struct InlineAsmRegOrRegClass;
+struct InlineAsmOperand;
+struct InlineAsmPlaceHolder;
+struct InlineAsmTemplatePiece;
+struct TupleClobber;
+struct TupleTemplateStr;
 class InlineAsm;
 
 // rust-stmt.h
index c43baf3cadec3f749b5c71becbf9328b31a94b94..8f30965b9f7f64e60aa7f38a8f7ebd8e5d09eab8 100644 (file)
@@ -4413,135 +4413,135 @@ protected:
   }
 };
 
-// Inline Assembly Node
-class InlineAsm : public ExprWithoutBlock
+// Inline-assembly specific options
+enum class InlineAsmOptions
+{
+  PURE = 1 << 0,
+  NOMEM = 1 << 1,
+  READONLY = 1 << 2,
+  PRESERVES_FLAGS = 1 << 3,
+  NORETURN = 1 << 4,
+  NOSTACK = 1 << 5,
+  ATT_SYNTAX = 1 << 6,
+  RAW = 1 << 7,
+  MAY_UNWIND = 1 << 8,
+};
+
+struct AnonConst
 {
-  // Inline-assembly specific options
-  enum InlineAsmOptions
-  {
-    PURE = 1 << 0,
-    NOMEM = 1 << 1,
-    READONLY = 1 << 2,
-    PRESERVES_FLAGS = 1 << 3,
-    NORETURN = 1 << 4,
-    NOSTACK = 1 << 5,
-    ATT_SYNTAX = 1 << 6,
-    RAW = 1 << 7,
-    MAY_UNWIND = 1 << 8,
+  NodeId id;
+  std::unique_ptr<Expr> value;
+};
+
+struct InlineAsmRegOrRegClass
+{
+  enum Type
+  {
+    Reg,
+    RegClass,
   };
 
-  struct AnonConst
+  struct Reg
   {
-    NodeId id;
-    std::unique_ptr<Expr> value;
+    std::string Symbol;
   };
 
-  struct InlineAsmRegOrRegClass
+  struct RegClass
   {
-    enum Type
-    {
-      Reg,
-      RegClass,
-    };
+    std::string Symbol;
+  };
 
-    struct Reg
-    {
-      std::string Symbol;
-    };
+  Identifier name;
+  Location locus;
+};
 
-    struct RegClass
-    {
-      std::string Symbol;
-    };
+struct InlineAsmOperand
+{
+  enum RegisterType
+  {
+    In,
+    Out,
+    InOut,
+    SplitInOut,
+    Const,
+    Sym,
+  };
 
-    Identifier name;
-    Location locus;
+  struct In
+  {
+    InlineAsmRegOrRegClass reg;
+    std::unique_ptr<Expr> expr;
+  };
+
+  struct Out
+  {
+    InlineAsmRegOrRegClass reg;
+    bool late;
+    std::unique_ptr<Expr> expr; // can be null
   };
 
-  struct InlineAsmOperand
-  {
-    enum RegisterType
-    {
-      In,
-      Out,
-      InOut,
-      SplitInOut,
-      Const,
-      Sym,
-    };
-
-    struct In
-    {
-      InlineAsmRegOrRegClass reg;
-      std::unique_ptr<Expr> expr;
-    };
-
-    struct Out
-    {
-      InlineAsmRegOrRegClass reg;
-      bool late;
-      std::unique_ptr<Expr> expr; // can be null
-    };
-
-    struct InOut
-    {
-      InlineAsmRegOrRegClass reg;
-      bool late;
-      std::unique_ptr<Expr> expr; // this can't be null
-    };
-
-    struct SplitInOut
-    {
-      InlineAsmRegOrRegClass reg;
-      bool late;
-      std::unique_ptr<Expr> in_expr;
-      std::unique_ptr<Expr> out_expr; // could be null
-    };
-
-    struct Const
-    {
-      AnonConst anon_const;
-    };
-
-    struct Sym
-    {
-      std::unique_ptr<Expr> sym;
-    };
-    Location locus;
+  struct InOut
+  {
+    InlineAsmRegOrRegClass reg;
+    bool late;
+    std::unique_ptr<Expr> expr; // this can't be null
   };
 
-  struct InlineAsmPlaceHolder
+  struct SplitInOut
   {
-    size_t operand_idx;
-    char modifier; // can be null
-    Location locus;
+    InlineAsmRegOrRegClass reg;
+    bool late;
+    std::unique_ptr<Expr> in_expr;
+    std::unique_ptr<Expr> out_expr; // could be null
   };
 
-  struct InlineAsmTemplatePiece
+  struct Const
   {
-    bool is_placeholder;
-    union
-    {
-      std::string string;
-      InlineAsmPlaceHolder placeholder;
-    };
+    AnonConst anon_const;
   };
 
-  struct TupleClobber
+  struct Sym
   {
-    // as gccrs still doesen't contain a symbol class I have put them as strings
-    std::string symbol;
-    Location loc;
+    std::unique_ptr<Expr> sym;
   };
+  Location locus;
+};
+
+struct InlineAsmPlaceHolder
+{
+  size_t operand_idx;
+  char modifier; // can be null
+  Location locus;
+};
 
-  struct TupleTemplateStr
+struct InlineAsmTemplatePiece
+{
+  bool is_placeholder;
+  union
   {
-    // as gccrs still doesen't contain a symbol class I have put them as strings
-    std::string symbol;
-    std::string optional_symbol;
-    Location loc;
+    std::string string;
+    InlineAsmPlaceHolder placeholder;
   };
+};
 
+struct TupleClobber
+{
+  // as gccrs still doesen't contain a symbol class I have put them as strings
+  std::string symbol;
+  Location loc;
+};
+
+struct TupleTemplateStr
+{
+  // as gccrs still doesen't contain a symbol class I have put them as strings
+  std::string symbol;
+  std::string optional_symbol;
+  Location loc;
+};
+
+// Inline Assembly Node
+class InlineAsm : public ExprWithoutBlock
+{
 public:
   std::vector<InlineAsmTemplatePiece> template_;
   std::vector<TupleTemplateStr> template_strs;
@@ -4550,6 +4550,7 @@ public:
   InlineAsmOptions options;
   std::vector<Location> line_spans;
 };
+
 } // namespace AST
 } // namespace Rust
 
index 47b989757faad925bcef2809ca00fdd7f44a95a3..ba9d0aae0df7572588885b5d9910c4f1249ac93c 100644 (file)
@@ -3889,6 +3889,94 @@ private:
   Location locus;
 };
 
+class InlineAsmReg
+{
+  enum Kind
+  {
+    X86,
+    Arm,
+    AArch64,
+    RiscV,
+    Nvptx,
+    PowerPC,
+    Hexagon,
+    Mips,
+    S390x,
+    SpirV,
+    Wasm,
+    Bpf,
+    Avr,
+    Msp430,
+    // Placeholder for invalid register constraints for the current target
+    Err,
+  };
+
+  // this placeholder is to be removed when the definations
+  // of the above enums are made in a later PR/patch.
+  std::string placeholder;
+};
+
+class InlineAsmRegClass
+{
+  enum Type
+  {
+    X86,
+    Arm,
+    AArch64,
+    RiscV,
+    Nvptx,
+    PowerPC,
+    Hexagon,
+    Mips,
+    S390x,
+    SpirV,
+    Wasm,
+    Bpf,
+    Avr,
+    Msp430,
+    // Placeholder for invalid register constraints for the current target
+    Err,
+  };
+
+  // this placeholder is to be removed when the definations
+  // of the above enums are made in a later PR/patch.
+  std::string placeholder;
+};
+
+struct InlineAsmRegOrRegClass
+{
+  enum Type
+  {
+    Reg,      // links to struct Register
+    RegClass, // links to struct RegisterClass
+  };
+
+  struct Register
+  {
+    InlineAsmReg Reg;
+  };
+
+  struct RegisterClass
+  {
+    InlineAsmRegClass RegClass;
+  };
+
+  Identifier name;
+  Location locus;
+};
+
+// Inline Assembly Node
+class InlineAsm : public ExprWithoutBlock
+{
+  NodeId id;
+
+public:
+  std::vector<AST::InlineAsmTemplatePiece> template_;
+  std::vector<AST::TupleTemplateStr> template_strs;
+  std::vector<AST::InlineAsmOperand> operands;
+  AST::InlineAsmOptions options;
+  std::vector<Location> line_spans;
+};
 } // namespace HIR
 } // namespace Rust
 
index d628c52bbc251b07df7a6cc44c6efc14724b6fca..3d3c29e7a7c91b8bca4dd00252dac7c05056a264 100644 (file)
@@ -124,6 +124,10 @@ struct MatchCase;
 class MatchExpr;
 class AwaitExpr;
 class AsyncBlockExpr;
+class InlineAsmReg;
+class InlineAsmRegClass;
+struct InlineAsmRegOrRegClass;
+class InlineAsm;
 
 // rust-stmt.h
 class EmptyStmt;