public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Introduce the extended attribute for asm declarations
@ 2023-11-17  4:58 Julian Waters
  0 siblings, 0 replies; 2+ messages in thread
From: Julian Waters @ 2023-11-17  4:58 UTC (permalink / raw)
  To: gcc-patches

Resent as plain text to appear on the patch tracker

Hi all,

This is the beginning of a patch to introduce the extended attribute
for asm declarations proposed in
https://gcc.gnu.org/pipermail/gcc-patches/2023-November/636563.html. I
will need some reviewer help in implementing this patch, as I am not
very familiar with gcc's internals.

The attribute in question looks as such (Example):

[[gnu::extended([output] "=r" (output) [otheroutput] "=r" (otheroutput),
                          [input] "r" (input) [otherinput] "r" (otherinput),
                          "%rcx" "%rdx", label, volatile stack)]]
asm ("");

I would really appreciate any reviews, as well as help in implementing
this patch

best regards,
Julian

From a189f2820025315b5574d0e9384b96301c6ba7e8 Mon Sep 17 00:00:00 2001
From: TheShermanTanker <tanksherman27@gmail.com>
Date: Fri, 17 Nov 2023 11:09:50 +0800
Subject: [PATCH] Introduce the extended attribute for asm declarations

---
 gcc/cp/parser.cc | 25 +++++++++++++++++++++++++
 gcc/cp/tree.cc   | 11 +++++++++++
 2 files changed, 36 insertions(+)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 5116bcb78f6..ecc5f2fabc1 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -15407,6 +15407,13 @@ cp_parser_block_declaration (cp_parser *parser,
  cp_parser_commit_to_tentative_parse (parser);
       cp_parser_asm_definition (parser);
     }
+  else if ((attr_idx = cp_parser_skip_std_attribute_spec_seq (parser, 1)) != 1
+       && cp_lexer_nth_token_is_keyword (parser->lexer, attr_idx, RID_ASM))
+    {
+      if (statement_p)
+    cp_parser_commit_to_tentative_parse (parser);
+      cp_parser_asm_definition (parser);
+    }
   /* If the next keyword is `namespace', we have a
      namespace-alias-definition.  */
   else if (token1->keyword == RID_NAMESPACE)
@@ -22397,6 +22404,23 @@ cp_parser_asm_definition (cp_parser* parser)
   bool invalid_inputs_p = false;
   bool invalid_outputs_p = false;
   required_token missing = RT_NONE;
+
+  tree attrs = cp_parser_std_attribute_spec_seq (parser);
+  tree extended = error_mark_node;
+
+  if (cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
+    {
+      /* Error during attribute parsing that resulted in skipping
+         to next semicolon.  */
+      cp_parser_require (parser, CPP_SEMICOLON, RT_SEMICOLON);
+      return;
+    }
+
+  if (attrs != error_mark_node)
+    {
+      extended = lookup_attribute ("gnu", "extended", attrs);
+    }
+
   location_t asm_loc = cp_lexer_peek_token (parser->lexer)->location;

   /* Look for the `asm' keyword.  */
@@ -22511,6 +22535,7 @@ cp_parser_asm_definition (cp_parser* parser)
      two `:' tokens.  */
   if (cp_parser_allow_gnu_extensions_p (parser)
       && parser->in_function_body
+      && extended == error_mark_node
       && (cp_lexer_next_token_is (parser->lexer, CPP_COLON)
    || cp_lexer_next_token_is (parser->lexer, CPP_SCOPE)))
     {
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc
index 417c92ba76f..1f081b3dfd8 100644
--- a/gcc/cp/tree.cc
+++ b/gcc/cp/tree.cc
@@ -46,6 +46,7 @@ static tree verify_stmt_tree_r (tree *, int *, void *);

 static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *);
 static tree handle_abi_tag_attribute (tree *, tree, tree, int, bool *);
+static tree handle_extended_attribute (tree *, tree, tree, int, bool *);
 static tree handle_contract_attribute (tree *, tree, tree, int, bool *);

 /* If REF is an lvalue, returns the kind of lvalue that REF is.
@@ -5080,6 +5081,8 @@ const struct attribute_spec cxx_attribute_table[] =
     handle_init_priority_attribute, NULL },
   { "abi_tag", 1, -1, false, false, false, true,
     handle_abi_tag_attribute, NULL },
+  { "extended", 0, 5, true, false, false, false,
+    handle_extended_attribute, NULL },
   { NULL, 0, 0, false, false, false, false, NULL, NULL }
 };

@@ -5350,6 +5353,14 @@ handle_abi_tag_attribute (tree* node, tree
name, tree args,
   return NULL_TREE;
 }

+static tree
+handle_extended_attribute (tree *node, tree name, tree args, int
flags, bool *no_add_attrs)
+{
+  /* TODO What could be done here? */
+  *no_add_attrs = true;
+  return NULL_TREE;
+}
+
 /* Perform checking for contract attributes.  */

 tree
-- 
2.41.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH] C++: Introduce the extended attribute for asm declarations
@ 2023-11-17  3:23 Julian Waters
  0 siblings, 0 replies; 2+ messages in thread
From: Julian Waters @ 2023-11-17  3:23 UTC (permalink / raw)
  To: gcc-patches; +Cc: gcc

[-- Attachment #1: Type: text/plain, Size: 671 bytes --]

Hi all,

This is the beginning of a patch to introduce the extended attribute
for asm declarations proposed in
https://gcc.gnu.org/pipermail/gcc-patches/2023-November/636563.html. I
will need some reviewer help in implementing this patch, as I am not
very familiar with gcc's internals.

The attribute in question looks as such (Example):

[[gnu::extended([output] "=r" (output) [otheroutput] "=r" (otheroutput),
                          [input] "r" (input) [otherinput] "r" (otherinput),
                          "%rcx" "%rdx", label, volatile stack)]]
asm ("");

I would really appreciate any reviews, as well as help in implementing
this patch

best regards,
Julian

[-- Attachment #2: 0001-Introduce-the-extended-attribute-for-asm-declaration.patch --]
[-- Type: application/x-patch, Size: 3488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-17  4:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-17  4:58 [PATCH] c++: Introduce the extended attribute for asm declarations Julian Waters
  -- strict thread matches above, loose matches on Subject: below --
2023-11-17  3:23 [PATCH] C++: " Julian Waters

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).