diff options
author | jjasmine <tanghocle456@gmail.com> | 2024-05-22 01:18:48 -0700 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-17 16:35:39 +0100 |
commit | c02891fd841b6d1f17b806d3c5b0368c3dc159de (patch) | |
tree | 10f8b947f0aa94381ffe1b144142c4186166e8d8 /gcc | |
parent | 26c50996efd2d79f6f86e8decc7006f1384075ca (diff) | |
download | gcc-c02891fd841b6d1f17b806d3c5b0368c3dc159de.zip gcc-c02891fd841b6d1f17b806d3c5b0368c3dc159de.tar.gz gcc-c02891fd841b6d1f17b806d3c5b0368c3dc159de.tar.bz2 |
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 2 | ||||
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins-asm.cc | 30 | ||||
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins-asm.h | 2 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/inline_asm_legal_options.rs | 12 |
4 files changed, 28 insertions, 18 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 03336cd..719a76c 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -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; diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc index bcf8b6f..443c8a3 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<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; diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h b/gcc/rust/expand/rust-macro-builtins-asm.h index 1d7889f..163ad16 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<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 index 0000000..a41dbd9 --- /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 |