From: jjasmine Date: Wed, 22 May 2024 08:18:48 +0000 (-0700) Subject: gccrs: Parsing of options(...) done. X-Git-Tag: basepoints/gcc-16~1376 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c02891fd841b6d1f17b806d3c5b0368c3dc159de;p=thirdparty%2Fgcc.git gccrs: Parsing of options(...) done. 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. --- diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 03336cdcc59..719a76cdbb3 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -4843,7 +4843,7 @@ public: std::vector operands; std::vector clobber_abi; // std::set options; - std::set options; + std::set options; std::vector line_spans; diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc index bcf8b6fb3f2..443c8a3bce3 100644 --- a/gcc/rust/expand/rust-macro-builtins-asm.cc +++ b/gcc/rust/expand/rust-macro-builtins-asm.cc @@ -116,7 +116,7 @@ parse_clobber_abi (Parser &parser, TokenId last_token_id, void check_and_set (Parser &p, AST::InlineAsm &inlineAsm, - std::string option) + AST::InlineAsmOptions option) { if (inlineAsm.options.count (option) == 1) { @@ -148,43 +148,40 @@ parse_options (Parser &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 &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 &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; diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h b/gcc/rust/expand/rust-macro-builtins-asm.h index 1d7889f2698..163ad161b5a 100644 --- a/gcc/rust/expand/rust-macro-builtins-asm.h +++ b/gcc/rust/expand/rust-macro-builtins-asm.h @@ -24,7 +24,7 @@ check_identifier (Parser &p, std::string ident); void check_and_set (Parser &p, AST::InlineAsm &inlineAsm, - std::string option); + AST::InlineAsmOptions option); // From rustc int parse_operand (Parser &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 index 00000000000..a41dbd9f07a --- /dev/null +++ b/gcc/testsuite/rust/compile/inline_asm_legal_options.rs @@ -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