public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Added AST Node AST::InlineAsm
@ 2023-02-20 10:30 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2023-02-20 10:30 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1774ff486a3352c52e4faa9a9096bac43d675a4e

commit 1774ff486a3352c52e4faa9a9096bac43d675a4e
Author: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
Date:   Fri Feb 17 23:39:56 2023 +0530

    Added AST Node AST::InlineAsm
    
    Addresses #1567
    Created a AST node InlineAsm similar to the one found in rustc.
    As there is no Symbol struct/class in gccrs I have made every instance
    of Symbol a string.
    
    Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
    
    gcc/rust/ChangeLog:
    
            * ast/rust-ast-full-decls.h (class InlineAsm):Added class declaration.
            * ast/rust-expr.h (class InlineAsm):Added class definition.

Diff:
---
 gcc/rust/ast/rust-ast-full-decls.h |   1 +
 gcc/rust/ast/rust-expr.h           | 138 +++++++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+)

diff --git a/gcc/rust/ast/rust-ast-full-decls.h b/gcc/rust/ast/rust-ast-full-decls.h
index 9d7b00ac5a2..64341d32641 100644
--- a/gcc/rust/ast/rust-ast-full-decls.h
+++ b/gcc/rust/ast/rust-ast-full-decls.h
@@ -149,6 +149,7 @@ struct MatchCase;
 class MatchExpr;
 class AwaitExpr;
 class AsyncBlockExpr;
+class InlineAsm;
 
 // rust-stmt.h
 class EmptyStmt;
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h
index 3ed1885d5af..f5461848009 100644
--- a/gcc/rust/ast/rust-expr.h
+++ b/gcc/rust/ast/rust-expr.h
@@ -4634,6 +4634,144 @@ protected:
     return new AsyncBlockExpr (*this);
   }
 };
+
+// Inline Assembly Node
+class InlineAsm : public ExprWithoutBlock
+{
+  // 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,
+  };
+
+  struct AnonConst
+  {
+    NodeId id;
+    std::unique_ptr<Expr> value;
+  };
+
+  struct InlineAsmRegOrRegClass
+  {
+    enum Type
+    {
+      Reg,
+      RegClass,
+    };
+
+    struct Reg
+    {
+      std::string Symbol;
+    };
+
+    struct RegClass
+    {
+      std::string Symbol;
+    };
+
+    Identifier name;
+    Location locus;
+  };
+
+  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 InlineAsmPlaceHolder
+  {
+    size_t operand_idx;
+    char modifier; // can be null
+    Location locus;
+  };
+
+  struct InlineAsmTemplatePiece
+  {
+    bool is_placeholder;
+    union
+    {
+      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;
+  };
+
+public:
+  std::vector<InlineAsmTemplatePiece> template_;
+  std::vector<TupleTemplateStr> template_strs;
+  std::vector<InlineAsmOperand> operands;
+  TupleClobber clobber_abi;
+  InlineAsmOptions options;
+  std::vector<Location> line_spans;
+};
 } // namespace AST
 } // namespace Rust

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-20 10:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-20 10:30 [gcc/devel/rust/master] Added AST Node AST::InlineAsm Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).