]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Scaffolding validation of asm!
authorjjasmine <tanghocle456@gmail.com>
Tue, 11 Jun 2024 01:08:42 +0000 (18:08 -0700)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:47 +0000 (16:35 +0100)
gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_asm):
Scaffolding validation of asm!
(validate): Likewise
* expand/rust-macro-builtins-asm.h (validate): Likewise

gcc/rust/expand/rust-macro-builtins-asm.cc
gcc/rust/expand/rust-macro-builtins-asm.h

index 47a47607cfe0a61611e58846993875095e2c9508..3073761d5d6140c1c55a2447ebdf8a855b6fd2c0 100644 (file)
@@ -703,13 +703,26 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
   // operands stream, also handles the optional ","
   parse_asm_arg (parser, last_token_id, inline_asm_ctx);
 
-  AST::SingleASTNode single = AST::SingleASTNode (
-    inline_asm_ctx.inline_asm.clone_expr_without_block ());
-  std::vector<AST::SingleASTNode> single_vec = {single};
+  // TODO: I'm putting the validation here because the rust reference put it
+  // here Per Arthur's advice we would actually do the validation in a different
+  // stage. and visit on the InlineAsm AST instead of it's context.
+  auto is_valid = validate (inline_asm_ctx);
 
-  AST::Fragment fragment_ast
-    = AST::Fragment (single_vec, std::vector<std::unique_ptr<AST::Token>> ());
-  return fragment_ast;
+  if (is_valid)
+    {
+      AST::SingleASTNode single = AST::SingleASTNode (
+       inline_asm_ctx.inline_asm.clone_expr_without_block ());
+      std::vector<AST::SingleASTNode> single_vec = {single};
+
+      AST::Fragment fragment_ast
+       = AST::Fragment (single_vec,
+                        std::vector<std::unique_ptr<AST::Token>> ());
+      return fragment_ast;
+    }
+  else
+    {
+      return tl::nullopt;
+    }
 }
 
 tl::optional<std::string>
@@ -749,4 +762,10 @@ parse_label (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
       return tl::nullopt;
     }
 }
+
+bool
+validate (InlineAsmContext &inline_asm_ctx)
+{
+  return true;
+}
 } // namespace Rust
index 267c1b609d91d394578dfce96e5194c4abba658f..293d790ca40ccf4ac6fb3f74c8d468977bb08b2d 100644 (file)
@@ -75,7 +75,8 @@ parse_format_string (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
 tl::optional<std::string>
 parse_label (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
             InlineAsmContext &inline_asm_ctx);
-
+bool
+validate (InlineAsmContext &inline_asm_ctx);
 std::set<std::string> potentially_nonpromoted_keywords
   = {"in", "out", "lateout", "inout", "inlateout", "const", "sym", "label"};