]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Parsing of options(...) done.
authorjjasmine <tanghocle456@gmail.com>
Wed, 22 May 2024 08:18:48 +0000 (01:18 -0700)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:39 +0000 (16:35 +0100)
This is without any mutually exclusive options checked, or
any relationship with reg_operands. Very primitive.

gcc/rust/ChangeLog:

* ast/rust-expr.h: parsing of options(...)
* expand/rust-macro-builtins-asm.cc (check_and_set):
likewise.
(parse_options): likewise.
(parseAsmArg): likewise.
* expand/rust-macro-builtins-asm.h (check_and_set):
likewise.

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_legal_options.rs: New test.

gcc/rust/ast/rust-expr.h
gcc/rust/expand/rust-macro-builtins-asm.cc
gcc/rust/expand/rust-macro-builtins-asm.h
gcc/testsuite/rust/compile/inline_asm_legal_options.rs [new file with mode: 0644]

index 03336cdcc5944df7393ebc2d3dd699bf760cd0dd..719a76cdbb3d6ce88b0582df6281dc50022f936d 100644 (file)
@@ -4843,7 +4843,7 @@ public:
   std::vector<InlineAsmOperand> operands;
   std::vector<TupleClobber> clobber_abi;
   // std::set<InlineAsmOptions> options;
-  std::set<std::string> options;
+  std::set<InlineAsmOptions> options;
 
   std::vector<location_t> line_spans;
 
index bcf8b6fb3f251f8b62e77760c6c89272cd026c19..443c8a3bce31ea6c558f25fc84197bb50c186866 100644 (file)
@@ -116,7 +116,7 @@ parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
 
 void
 check_and_set (Parser<MacroInvocLexer> &p, AST::InlineAsm &inlineAsm,
-              std::string option)
+              AST::InlineAsmOptions option)
 {
   if (inlineAsm.options.count (option) == 1)
     {
@@ -148,43 +148,40 @@ parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
     {
       if (!is_global_asm && check_identifier (parser, "pure"))
        {
-         check_and_set (parser, inlineAsm, "pure");
+         check_and_set (parser, inlineAsm, AST::InlineAsmOptions::PURE);
        }
       else if (!is_global_asm && check_identifier (parser, "nomem"))
        {
-         check_and_set (parser, inlineAsm, "nomem");
+         check_and_set (parser, inlineAsm, AST::InlineAsmOptions::NOMEM);
        }
       else if (!is_global_asm && check_identifier (parser, "readonly"))
        {
-         check_and_set (parser, inlineAsm, "readonly");
+         check_and_set (parser, inlineAsm, AST::InlineAsmOptions::READONLY);
        }
       else if (!is_global_asm && check_identifier (parser, "preserves_flags"))
        {
-         check_and_set (parser, inlineAsm, "preserves_flags");
+         check_and_set (parser, inlineAsm,
+                        AST::InlineAsmOptions::PRESERVES_FLAGS);
        }
       else if (!is_global_asm && check_identifier (parser, "noreturn"))
        {
-         check_and_set (parser, inlineAsm, "noreturn");
-       }
-      else if (!is_global_asm && check_identifier (parser, "noreturn"))
-       {
-         check_and_set (parser, inlineAsm, "noreturn");
+         check_and_set (parser, inlineAsm, AST::InlineAsmOptions::NORETURN);
        }
       else if (!is_global_asm && check_identifier (parser, "nostack"))
        {
-         check_and_set (parser, inlineAsm, "nostack");
+         check_and_set (parser, inlineAsm, AST::InlineAsmOptions::NOSTACK);
        }
       else if (!is_global_asm && check_identifier (parser, "may_unwind"))
        {
-         check_and_set (parser, inlineAsm, "may_unwind");
+         check_and_set (parser, inlineAsm, AST::InlineAsmOptions::MAY_UNWIND);
        }
       else if (check_identifier (parser, "att_syntax"))
        {
-         check_and_set (parser, inlineAsm, "att_syntax");
+         check_and_set (parser, inlineAsm, AST::InlineAsmOptions::ATT_SYNTAX);
        }
       else if (check_identifier (parser, "raw"))
        {
-         check_and_set (parser, inlineAsm, "raw");
+         check_and_set (parser, inlineAsm, AST::InlineAsmOptions::RAW);
        }
       else
        {
@@ -201,6 +198,7 @@ parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
        {
          // TODO: If the skip of comma is unsuccessful, which should be
          // illegal, pleaes emit the correct error.
+         std::cout << "Illegal comma" << std::endl;
          return -1;
        }
 
@@ -315,13 +313,13 @@ parseAsmArg (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
       // TODO: Parse options
       if (check_identifier (parser, "options"))
        {
-         std::cout << "Parse optoins" << std::endl;
+         parse_options (parser, last_token_id, inlineAsm);
          continue;
        }
 
       // Ok after we have check that neither clobber_abi nor options works, the
       // only other logical choice is reg_operand
-      std::cout << "reg_operand" << std::endl;
+      // std::cout << "reg_operand" << std::endl;
       fm_string = parse_format_string (parser, last_token_id);
     }
   return 0;
index 1d7889f2698d99d384786453c94eff561c126de8..163ad161b5a45a73db870f2c1e2f20e1b2695766 100644 (file)
@@ -24,7 +24,7 @@ check_identifier (Parser<MacroInvocLexer> &p, std::string ident);
 
 void
 check_and_set (Parser<MacroInvocLexer> &p, AST::InlineAsm &inlineAsm,
-              std::string option);
+              AST::InlineAsmOptions option);
 // From rustc
 int
 parse_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
diff --git a/gcc/testsuite/rust/compile/inline_asm_legal_options.rs b/gcc/testsuite/rust/compile/inline_asm_legal_options.rs
new file mode 100644 (file)
index 0000000..a41dbd9
--- /dev/null
@@ -0,0 +1,12 @@
+#![feature(rustc_attrs)]
+
+#[rustc_builtin_macro]
+macro_rules! asm {
+    () => {}
+}
+
+fn main() {
+    unsafe {
+        asm!("nop", options(nomem, nostack, att_syntax, raw));
+    }
+}
\ No newline at end of file