https://gcc.gnu.org/g:c37eb03de6b316cf5654b7d7ff86d38022aca2d8

commit c37eb03de6b316cf5654b7d7ff86d38022aca2d8
Author: jjasmine <tanghocle...@gmail.com>
Date:   Sat Jun 15 22:18:22 2024 -0700

    Finish expected parse_reg_operand
    
    gcc/rust/ChangeLog:
    
            * expand/rust-macro-builtins-asm.cc (parse_reg_operand_in):
            Finish expected parse_reg_operand
            (parse_reg_operand_unexpected): Likewise
            * expand/rust-macro-builtins-asm.h (parse_reg_operand_unexpected): 
Likewise
    
    Signed-off-by: badumbatish <tanghocle...@gmail.com>

Diff:
---
 gcc/rust/expand/rust-macro-builtins-asm.cc | 68 ++++++++++++++----------------
 gcc/rust/expand/rust-macro-builtins-asm.h  |  3 ++
 2 files changed, 35 insertions(+), 36 deletions(-)

diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc 
b/gcc/rust/expand/rust-macro-builtins-asm.cc
index 8dd7238f8b9c..2c59e8ee4ea1 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.cc
+++ b/gcc/rust/expand/rust-macro-builtins-asm.cc
@@ -208,52 +208,34 @@ parse_reg_operand (InlineAsmContext inline_asm_ctx)
        }
     }
 
-  // For the keyword IN, currently we count it as a seperate keyword called
-  // Rust::IN search for #define RS_TOKEN_LIST in code base.
   tl::expected<InlineAsmContext, InlineAsmParseError> parsing_operand
     = tl::expected<InlineAsmContext, InlineAsmParseError> (inline_asm_ctx);
 
-  // PARSING WITH IN
-  parsing_operand.map (parse_reg_operand_in);
-  if (parsing_operand || parsing_operand.error () == COMMITTED)
-    return parsing_operand;
-
-  // KEEP ON PARSING WITH OUT
-  parsing_operand.emplace (inline_asm_ctx);
-  parsing_operand.map (parse_reg_operand_out);
-  if (parsing_operand || parsing_operand.error () == COMMITTED)
-    return parsing_operand;
-
-  // KEEP ON PARSING WITH LATEOUT
-  parsing_operand.emplace (inline_asm_ctx);
-  parsing_operand.map (parse_reg_operand_lateout);
-  if (parsing_operand || parsing_operand.error () == COMMITTED)
-    return parsing_operand;
-
-  // KEEP ON PARSING WITH INOUT
-  parsing_operand.emplace (inline_asm_ctx);
-  parsing_operand.map (parse_reg_operand_inout);
-  if (parsing_operand || parsing_operand.error () == COMMITTED)
-    return parsing_operand;
-
-  // KEEP ON PARSING WITH INOUT
-  parsing_operand.emplace (inline_asm_ctx);
-  parsing_operand.map (parse_reg_operand_const);
-  if (parsing_operand || parsing_operand.error () == COMMITTED)
-    return parsing_operand;
+  // Here is all parse_reg_operand functions we're using in a for loop
+  auto parse_funcs = {parse_reg_operand_in,       parse_reg_operand_out,
+                     parse_reg_operand_lateout,   parse_reg_operand_inout,
+                     parse_reg_operand_const,     parse_reg_operand_sym,
+                     parse_reg_operand_unexpected};
 
-  // TODO: It is  weird that we can't seem to match any identifier,
-  // something must be wrong. consult compiler code in asm.rs or rust online
-  // compiler.
-  rust_unreachable ();
+  // Loop over and execute the parsing functions, if the parser successfullly
+  // parses or if the parser fails to parse while it has committed to a token,
+  // we propogate the result.
+  for (auto &parse_func : parse_funcs)
+    {
+      parsing_operand.emplace (inline_asm_ctx);
+      parsing_operand.map (parse_func);
+      if (parsing_operand || parsing_operand.error () == COMMITTED)
+       return parsing_operand;
+    }
 
-  rust_error_at (token->get_locus (), "ERROR RIGHT HERE");
-  return tl::unexpected<InlineAsmParseError> (COMMITTED);
+  return parsing_operand;
 }
 
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_reg_operand_in (InlineAsmContext inline_asm_ctx)
 {
+  // For the keyword IN, currently we count it as a seperate keyword called
+  // Rust::IN search for #define RS_TOKEN_LIST in code base.
   AST::InlineAsmOperand reg_operand;
   auto &parser = inline_asm_ctx.parser;
   if (!inline_asm_ctx.is_global_asm () && parser.skip_token (IN))
@@ -412,6 +394,20 @@ parse_reg_operand_sym (InlineAsmContext inline_asm_ctx)
     }
   return tl::unexpected<InlineAsmParseError> (NONCOMMITED);
 }
+
+tl::expected<InlineAsmContext, InlineAsmParseError>
+parse_reg_operand_unexpected (InlineAsmContext inline_asm_ctx)
+{
+  auto token = inline_asm_ctx.parser.peek_current_token ();
+  // TODO: It is  weird that we can't seem to match any identifier,
+  // something must be wrong. consult compiler code in asm.rs or rust online
+  // compiler.
+  rust_unreachable ();
+
+  rust_error_at (token->get_locus (), "ERROR RIGHT HERE");
+  return tl::unexpected<InlineAsmParseError> (COMMITTED);
+}
+
 void
 check_and_set (InlineAsmContext &inline_asm_ctx, AST::InlineAsmOption option)
 {
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h 
b/gcc/rust/expand/rust-macro-builtins-asm.h
index 9e7dae85ba78..d03adf004ca3 100644
--- a/gcc/rust/expand/rust-macro-builtins-asm.h
+++ b/gcc/rust/expand/rust-macro-builtins-asm.h
@@ -105,6 +105,9 @@ parse_reg_operand_const (InlineAsmContext inline_asm_ctx);
 tl::expected<InlineAsmContext, InlineAsmParseError>
 parse_reg_operand_sym (InlineAsmContext inline_asm_ctx);
 
+tl::expected<InlineAsmContext, InlineAsmParseError>
+parse_reg_operand_unexpected (InlineAsmContext inline_asm_ctx);
+
 tl::optional<AST::Fragment>
 parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
           AST::InvocKind semicolon, AST::AsmKind is_global_asm);

Reply via email to