diff options
author | jjasmine <tanghocle456@gmail.com> | 2024-05-31 02:01:18 -0700 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-17 16:35:43 +0100 |
commit | f0c9a6e73d21eef5c5b3c6051f42e6e262eba1df (patch) | |
tree | 9b9408988c10232c6427b9c89f59bb5ffc44dbc1 /gcc | |
parent | 256bb62f995625ff32748e479b371c20082189ba (diff) | |
download | gcc-f0c9a6e73d21eef5c5b3c6051f42e6e262eba1df.zip gcc-f0c9a6e73d21eef5c5b3c6051f42e6e262eba1df.tar.gz gcc-f0c9a6e73d21eef5c5b3c6051f42e6e262eba1df.tar.bz2 |
gccrs: Refactoring for inline asm pr
gcc/rust/ChangeLog:
* ast/rust-expr.h (struct AnonConst):
major refactoring of inline asm, mostly concerns
naming convention, trinary conditionals, warnings,
adding rust_unreachables in not-yet supported errors.
(struct InlineAsmRegOrRegClass): Likewise.
(struct InlineAsmOperand): Likewise.
* expand/rust-macro-builtins-asm.cc (parse_clobber_abi): Likewise.
(parse_reg): Likewise.
(parse_operand): Likewise.
(parse_reg_operand): Likewise.
(check_and_set): Likewise.
(parse_options): Likewise.
(parse_format_string): Likewise.
(parse_asm_arg): Likewise.
(parse_asm): Likewise.
* expand/rust-macro-builtins-asm.h (parse_asm_arg): Likewise.
(check_identifier): Likewise.
(check_and_set): Likewise.
(parse_operand): Likewise.
(parse_reg_operand): Likewise.
(parse_options): Likewise.
(parse_reg): Likewise.
(parse_clobber_abi): Likewise.
* expand/rust-macro-builtins.cc (enum class): Likewise.
(inline_asm_maker): Likewise.
* checks/errors/borrowck/ffi-polonius/Cargo.lock: Removed. Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/inline_asm_faulty_clobber.rs: Likewise.
* rust/compile/inline_asm_faulty_clobber_1.rs: Likewise.
* rust/compile/inline_asm_faulty_clobber_2.rs: Likewise.
* rust/compile/inline_asm_illegal_options.rs: Likewise.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 88 | ||||
-rw-r--r-- | gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock | 39 | ||||
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins-asm.cc | 139 | ||||
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins-asm.h | 28 | ||||
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins.cc | 10 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs | 2 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs | 2 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs | 2 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/inline_asm_illegal_options.rs | 4 |
9 files changed, 142 insertions, 172 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index 1284c73..ad742bf 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -6,7 +6,7 @@ #include "rust-path.h" #include "rust-macro.h" #include "rust-operators.h" -#include <memory> +#include "rust-system.h" namespace Rust { namespace AST { @@ -4723,22 +4723,20 @@ enum class InlineAsmOption struct AnonConst { NodeId id; - std::unique_ptr<Expr> value; + std::unique_ptr<Expr> expr; AnonConst () {} AnonConst (const AnonConst &other) { id = other.id; - value = other.value == nullptr - ? nullptr - : std::unique_ptr<Expr> (other.value->clone_expr ()); + if (other.expr) + expr = other.expr->clone_expr (); } AnonConst operator= (const AnonConst &other) { id = other.id; - value = other.value == nullptr - ? nullptr - : std::unique_ptr<Expr> (other.value->clone_expr ()); + if (other.expr) + expr = other.expr->clone_expr (); return *this; } }; @@ -4763,7 +4761,7 @@ struct InlineAsmRegOrRegClass Type type; struct Reg reg; - struct RegClass regClass; + struct RegClass reg_class; Identifier name; location_t locus; @@ -4790,17 +4788,15 @@ struct InlineAsmOperand In (const struct In &other) { reg = other.reg; - expr = other.expr == nullptr - ? nullptr - : std::unique_ptr<Expr> (other.expr->clone_expr ()); + if (other.expr) + expr = other.expr->clone_expr (); } In operator= (const struct In &other) { reg = other.reg; - expr = other.expr == nullptr - ? nullptr - : std::unique_ptr<Expr> (other.expr->clone_expr ()); + if (other.expr) + expr = other.expr->clone_expr (); return *this; } @@ -4817,18 +4813,16 @@ struct InlineAsmOperand { reg = other.reg; late = other.late; - expr = other.expr == nullptr - ? nullptr - : std::unique_ptr<Expr> (other.expr->clone_expr ()); + if (other.expr) + expr = other.expr->clone_expr (); } Out operator= (const struct Out &other) { reg = other.reg; late = other.late; - expr = other.expr == nullptr - ? nullptr - : std::unique_ptr<Expr> (other.expr->clone_expr ()); + if (other.expr) + expr = other.expr->clone_expr (); return *this; } }; @@ -4844,18 +4838,17 @@ struct InlineAsmOperand { reg = other.reg; late = other.late; - expr = other.expr == nullptr - ? nullptr - : std::unique_ptr<Expr> (other.expr->clone_expr ()); + if (other.expr) + expr = other.expr->clone_expr (); } InOut operator= (const struct InOut &other) { reg = other.reg; late = other.late; - expr = other.expr == nullptr - ? nullptr - : std::unique_ptr<Expr> (other.expr->clone_expr ()); + if (other.expr) + expr = other.expr->clone_expr (); + return *this; } }; @@ -4872,24 +4865,23 @@ struct InlineAsmOperand { reg = other.reg; late = other.late; - in_expr = other.in_expr == nullptr - ? nullptr - : std::unique_ptr<Expr> (other.in_expr->clone_expr ()); - out_expr = other.out_expr == nullptr - ? nullptr - : std::unique_ptr<Expr> (other.out_expr->clone_expr ()); + if (other.in_expr) + in_expr = other.in_expr->clone_expr (); + + if (other.out_expr) + out_expr = other.out_expr->clone_expr (); } SplitInOut operator= (const struct SplitInOut &other) { reg = other.reg; late = other.late; - in_expr = other.in_expr == nullptr - ? nullptr - : std::unique_ptr<Expr> (other.in_expr->clone_expr ()); - out_expr = other.out_expr == nullptr - ? nullptr - : std::unique_ptr<Expr> (other.out_expr->clone_expr ()); + + if (other.in_expr) + in_expr = other.in_expr->clone_expr (); + + if (other.out_expr) + out_expr = other.out_expr->clone_expr (); return *this; } @@ -4902,33 +4894,35 @@ struct InlineAsmOperand struct Sym { - std::unique_ptr<Expr> sym; + std::unique_ptr<Expr> expr; Sym () {} Sym (const struct Sym &other) { - sym = std::unique_ptr<Expr> (other.sym->clone_expr ()); + if (other.expr) + expr = std::unique_ptr<Expr> (other.expr->clone_expr ()); } Sym operator= (const struct Sym &other) { - sym = std::unique_ptr<Expr> (other.sym->clone_expr ()); + if (other.expr) + expr = std::unique_ptr<Expr> (other.expr->clone_expr ()); return *this; } }; - RegisterType registerType; + RegisterType register_type; struct In in; struct Out out; - struct InOut inOut; - struct SplitInOut splitInOut; + struct InOut in_out; + struct SplitInOut split_in_out; struct Const cnst; struct Sym sym; InlineAsmOperand () {} InlineAsmOperand (const InlineAsmOperand &other) - : in (other.in), out (other.out), inOut (other.inOut), - splitInOut (other.splitInOut), cnst (other.cnst), sym (other.sym) + : in (other.in), out (other.out), in_out (other.in_out), + split_in_out (other.split_in_out), cnst (other.cnst), sym (other.sym) {} location_t locus; diff --git a/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock b/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock deleted file mode 100644 index 55cc711..0000000 --- a/gcc/rust/checks/errors/borrowck/ffi-polonius/Cargo.lock +++ /dev/null @@ -1,39 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "datafrog" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69" - -[[package]] -name = "ffi-polonius" -version = "0.1.0" -dependencies = [ - "polonius-engine", -] - -[[package]] -name = "log" -version = "0.4.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" - -[[package]] -name = "polonius-engine" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4e8e505342045d397d0b6674dcb82d6faf5cf40484d30eeb88fc82ef14e903f" -dependencies = [ - "datafrog", - "log", - "rustc-hash", -] - -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc index ee57f7f..dd053df 100644 --- a/gcc/rust/expand/rust-macro-builtins-asm.cc +++ b/gcc/rust/expand/rust-macro-builtins-asm.cc @@ -39,12 +39,12 @@ parseDirSpec (Parser<MacroInvocLexer> &parser, TokenId last_token_id) int parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id, - InlineAsmContext &inlineAsmCtx) + InlineAsmContext &inline_asm_ctx) { // clobber_abi := "clobber_abi(" <abi> *("," <abi>) [","] ")" // PARSE EVERYTHING COMMITTEDLY IN THIS FUNCTION, WE CONFIRMED VIA clobber_abi // identifier keyword - auto &inlineAsm = inlineAsmCtx.inlineAsm; + auto &inline_asm = inline_asm_ctx.inline_asm; auto token = parser.peek_current_token (); if (!parser.skip_token (LEFT_PAREN)) { @@ -56,16 +56,14 @@ parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id, // why. if (token->get_id () == last_token_id) { - rust_error_at (parser.peek_current_token ()->get_locus (), - "expected `(`, found end of macro arguments"); + rust_error_at (token->get_locus (), + "expected %<(%>, found end of macro arguments"); return -1; } else { - rust_error_at ( - parser.peek_current_token ()->get_locus (), - "expected `(`, found `%s`", - parser.peek_current_token ()->get_token_description ()); + rust_error_at (token->get_locus (), "expected %<(%>, found %qs", + token->get_token_description ()); } return -1; } @@ -76,7 +74,7 @@ parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id, // https://github.com/rust-lang/rust/blob/c00957a3e269219413041a4e3565f33b1f9d0779/compiler/rustc_builtin_macros/src/asm.rs#L381 rust_error_at ( parser.peek_current_token ()->get_locus (), - "at least one abi must be provided as an argument to `clobber_abi`"); + "at least one abi must be provided as an argument to %<clobber_abi%>"); return -1; } @@ -97,6 +95,7 @@ parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id, // TODO: We encountered something that is not string literal, which // should be illegal, please emit the correct error // https://github.com/rust-lang/rust/blob/b92758a9aef1cef7b79e2b72c3d8ba113e547f89/compiler/rustc_builtin_macros/src/asm.rs#L387 + rust_unreachable (); } if (parser.skip_token (RIGHT_PAREN)) @@ -108,6 +107,7 @@ parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id, { // TODO: If the skip of comma is unsuccessful, which should be // illegal, pleaes emit the correct error. + rust_unreachable (); return -1; } @@ -119,7 +119,7 @@ parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id, for (auto abi : new_abis) { - inlineAsm.clobber_abi.push_back (abi); + inline_asm.clobber_abi.push_back (abi); } return 0; @@ -127,13 +127,14 @@ parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id, tl::optional<AST::InlineAsmRegOrRegClass> parse_reg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, - InlineAsmContext &inlineAsmCtx) + InlineAsmContext &inline_asm_ctx) { using RegType = AST::InlineAsmRegOrRegClass::Type; if (!parser.skip_token (LEFT_PAREN)) { // TODO: we expect a left parenthesis here, please return the correct // error. + rust_unreachable (); return tl::nullopt; } @@ -141,12 +142,12 @@ parse_reg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, // InlineAsmRegOrRegClass of reg or reg class auto token = parser.peek_current_token (); auto tok_id = token->get_id (); - AST::InlineAsmRegOrRegClass regClass; + AST::InlineAsmRegOrRegClass reg_class; if (parser.skip_token (IDENTIFIER)) { // construct a InlineAsmRegOrRegClass - regClass.type = RegType::RegClass; - regClass.regClass.Symbol = token->as_string (); + reg_class.type = RegType::RegClass; + reg_class.reg_class.Symbol = token->as_string (); } else if (tok_id == STRING_LITERAL) { @@ -155,9 +156,9 @@ parse_reg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, // construct a InlineAsmRegOrRegClass // parse_format_string - regClass.type = RegType::Reg; - inlineAsmCtx.is_explicit = true; - regClass.regClass.Symbol = token->as_string (); + reg_class.type = RegType::Reg; + inline_asm_ctx.is_explicit = true; + reg_class.reg_class.Symbol = token->as_string (); } else { @@ -167,20 +168,22 @@ parse_reg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, // { // span: p.token.span, // })); + rust_unreachable (); } if (!parser.skip_token (RIGHT_PAREN)) { // TODO: we expect a left parenthesis here, please return the correct // error. + rust_unreachable (); return tl::nullopt; } - return regClass; + return reg_class; } int parse_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id, - InlineAsmContext &inlineAsmCtx) + InlineAsmContext &inline_asm_ctx) { return 0; } @@ -188,7 +191,7 @@ parse_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id, // From rustc tl::optional<AST::InlineAsmOperand> parse_reg_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id, - InlineAsmContext &inlineAsmCtx) + InlineAsmContext &inline_asm_ctx) { // let name = if p.token.is_ident() && p.look_ahead(1, |t| *t == token::Eq) { // let (ident, _) = p.token.ident().unwrap(); @@ -200,11 +203,10 @@ parse_reg_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id, // None // }; - using RegisterType = AST::InlineAsmOperand::RegisterType; AST::InlineAsmOperand reg_operand; auto token = parser.peek_current_token (); auto iden_token = parser.peek_current_token (); - auto &inlineAsm = inlineAsmCtx.inlineAsm; + auto &inline_asm = inline_asm_ctx.inline_asm; if (check_identifier (parser, "")) { auto equal_token = parser.peek_current_token (); @@ -218,72 +220,83 @@ parse_reg_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id, token = parser.peek_current_token (); bool is_explicit_reg = false; - bool is_global_asm = inlineAsm.is_global_asm; + bool is_global_asm = inline_asm.is_global_asm; if (!is_global_asm && check_identifier (parser, "in")) { + rust_unreachable (); return tl::nullopt; } else if (!is_global_asm && check_identifier (parser, "out")) { + rust_unreachable (); return tl::nullopt; } else if (!is_global_asm && check_identifier (parser, "lateout")) { + rust_unreachable (); return tl::nullopt; } else if (!is_global_asm && check_identifier (parser, "inout")) { + rust_unreachable (); return tl::nullopt; } else if (!is_global_asm && check_identifier (parser, "inlateout")) { + rust_unreachable (); return tl::nullopt; } else if (parser.peek_current_token ()->get_id () == CONST) { + // TODO: Please handle const rust_unreachable (); - // todo: Please handle const return tl::nullopt; } else if (false && check_identifier (parser, "sym")) { - // todo: Please handle sym + // TODO: Please handle sym + rust_unreachable (); return tl::nullopt; } else if (false && check_identifier (parser, "label")) { - // todo: Please handle label + // TODO: Please handle label + rust_unreachable (); return tl::nullopt; } else { + // 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 (); return tl::nullopt; } return reg_operand; } void -check_and_set (Parser<MacroInvocLexer> &parser, InlineAsmContext &inlineAsmCtx, - AST::InlineAsmOption option) +check_and_set (Parser<MacroInvocLexer> &parser, + InlineAsmContext &inline_asm_ctx, AST::InlineAsmOption option) { - auto &inlineAsm = inlineAsmCtx.inlineAsm; - if (inlineAsm.options.count (option) != 0) + auto &inline_asm = inline_asm_ctx.inline_asm; + if (inline_asm.options.count (option) != 0) { // TODO: report an error of duplication rust_error_at (parser.peek_current_token ()->get_locus (), - "the `%s` option was already provided", + "the %qs option was already provided", InlineAsmOptionMap[option].c_str ()); return; } else { - inlineAsm.options.insert (option); + inline_asm.options.insert (option); } } int parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id, - InlineAsmContext &inlineAsmCtx) + InlineAsmContext &inline_asm_ctx) { - bool is_global_asm = inlineAsmCtx.inlineAsm.is_global_asm; + bool is_global_asm = inline_asm_ctx.inline_asm.is_global_asm; // Parse everything commitedly if (!parser.skip_token (LEFT_PAREN)) { @@ -298,42 +311,44 @@ parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id, { if (!is_global_asm && check_identifier (parser, "pure")) { - check_and_set (parser, inlineAsmCtx, AST::InlineAsmOption::PURE); + check_and_set (parser, inline_asm_ctx, AST::InlineAsmOption::PURE); } else if (!is_global_asm && check_identifier (parser, "nomem")) { - check_and_set (parser, inlineAsmCtx, AST::InlineAsmOption::NOMEM); + check_and_set (parser, inline_asm_ctx, AST::InlineAsmOption::NOMEM); } else if (!is_global_asm && check_identifier (parser, "readonly")) { - check_and_set (parser, inlineAsmCtx, AST::InlineAsmOption::READONLY); + check_and_set (parser, inline_asm_ctx, + AST::InlineAsmOption::READONLY); } else if (!is_global_asm && check_identifier (parser, "preserves_flags")) { - check_and_set (parser, inlineAsmCtx, + check_and_set (parser, inline_asm_ctx, AST::InlineAsmOption::PRESERVES_FLAGS); } else if (!is_global_asm && check_identifier (parser, "noreturn")) { - check_and_set (parser, inlineAsmCtx, AST::InlineAsmOption::NORETURN); + check_and_set (parser, inline_asm_ctx, + AST::InlineAsmOption::NORETURN); } else if (!is_global_asm && check_identifier (parser, "nostack")) { - check_and_set (parser, inlineAsmCtx, AST::InlineAsmOption::NOSTACK); + check_and_set (parser, inline_asm_ctx, AST::InlineAsmOption::NOSTACK); } else if (!is_global_asm && check_identifier (parser, "may_unwind")) { - check_and_set (parser, inlineAsmCtx, + check_and_set (parser, inline_asm_ctx, AST::InlineAsmOption::MAY_UNWIND); } else if (check_identifier (parser, "att_syntax")) { - check_and_set (parser, inlineAsmCtx, + check_and_set (parser, inline_asm_ctx, AST::InlineAsmOption::ATT_SYNTAX); } else if (check_identifier (parser, "raw")) { - check_and_set (parser, inlineAsmCtx, AST::InlineAsmOption::RAW); + check_and_set (parser, inline_asm_ctx, AST::InlineAsmOption::RAW); } else { @@ -353,7 +368,7 @@ parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id, } else { - std::cout << "Sum wrong here, check it out" << std::endl; + rust_unreachable (); token = parser.peek_current_token (); return -1; } @@ -383,7 +398,7 @@ check_identifier (Parser<MacroInvocLexer> &p, std::string ident) } tl::optional<std::string> parse_format_string (Parser<MacroInvocLexer> &parser, TokenId last_token_id, - InlineAsmContext &inlineAsmCtx) + InlineAsmContext &inline_asm_ctx) { auto token = parser.peek_current_token (); @@ -408,7 +423,7 @@ MacroBuiltin::asm_handler (location_t invoc_locus, AST::MacroInvocData &invoc, int parse_asm_arg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, - InlineAsmContext &inlineAsmCtx) + InlineAsmContext &inline_asm_ctx) { auto token = parser.peek_current_token (); tl::optional<std::string> fm_string; @@ -418,16 +433,16 @@ parse_asm_arg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, // We accept a comma token here. if (token->get_id () != COMMA - && inlineAsmCtx.consumed_comma_without_formatted_string) + && inline_asm_ctx.consumed_comma_without_formatted_string) { // if it is not a comma, but we consumed it previously, this is fine // but we have to set it to false tho. - inlineAsmCtx.consumed_comma_without_formatted_string = false; + inline_asm_ctx.consumed_comma_without_formatted_string = false; } else if (token->get_id () == COMMA - && !inlineAsmCtx.consumed_comma_without_formatted_string) + && !inline_asm_ctx.consumed_comma_without_formatted_string) { - inlineAsmCtx.consumed_comma_without_formatted_string = false; + inline_asm_ctx.consumed_comma_without_formatted_string = false; parser.skip_token (); } else @@ -452,21 +467,21 @@ parse_asm_arg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, // TODO: Parse clobber abi, eat the identifier named "clobber_abi" if true if (check_identifier (parser, "clobber_abi")) { - parse_clobber_abi (parser, last_token_id, inlineAsmCtx); + parse_clobber_abi (parser, last_token_id, inline_asm_ctx); continue; } // TODO: Parse options if (check_identifier (parser, "options")) { - parse_options (parser, last_token_id, inlineAsmCtx); + parse_options (parser, last_token_id, inline_asm_ctx); 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; - fm_string = parse_format_string (parser, last_token_id, inlineAsmCtx); + fm_string = parse_format_string (parser, last_token_id, inline_asm_ctx); } return 0; } @@ -495,11 +510,11 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc, Parser<MacroInvocLexer> parser (lex); auto last_token_id = macro_end_token (invoc.get_delim_tok_tree (), parser); - AST::InlineAsm inlineAsm (invoc_locus, is_global_asm); - auto inlineAsmCtx = InlineAsmContext (inlineAsm); + AST::InlineAsm inline_asm (invoc_locus, is_global_asm); + auto inline_asm_ctx = InlineAsmContext (inline_asm); // Parse the first ever formatted string, success or not, will skip 1 token - auto fm_string = parse_format_string (parser, last_token_id, inlineAsmCtx); + auto fm_string = parse_format_string (parser, last_token_id, inline_asm_ctx); if (fm_string == tl::nullopt) { @@ -518,21 +533,21 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc, } // Ok after the comma is good, we better be parsing correctly everything // in here, which is formatted string in ABNF - inlineAsmCtx.consumed_comma_without_formatted_string = false; + inline_asm_ctx.consumed_comma_without_formatted_string = false; - fm_string = parse_format_string (parser, last_token_id, inlineAsmCtx); + fm_string = parse_format_string (parser, last_token_id, inline_asm_ctx); if (fm_string == tl::nullopt) { - inlineAsmCtx.consumed_comma_without_formatted_string = true; + inline_asm_ctx.consumed_comma_without_formatted_string = true; break; } } // operands stream, also handles the optional "," - parse_asm_arg (parser, last_token_id, inlineAsmCtx); + parse_asm_arg (parser, last_token_id, inline_asm_ctx); - AST::SingleASTNode single - = AST::SingleASTNode (inlineAsmCtx.inlineAsm.clone_expr_without_block ()); + 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 diff --git a/gcc/rust/expand/rust-macro-builtins-asm.h b/gcc/rust/expand/rust-macro-builtins-asm.h index c7fcf30..45f1fd2 100644 --- a/gcc/rust/expand/rust-macro-builtins-asm.h +++ b/gcc/rust/expand/rust-macro-builtins-asm.h @@ -14,13 +14,13 @@ public: bool allow_templates; bool is_explicit; bool consumed_comma_without_formatted_string; - AST::InlineAsm &inlineAsm; - InlineAsmContext (AST::InlineAsm &inlineAsm) + AST::InlineAsm &inline_asm; + InlineAsmContext (AST::InlineAsm &inline_asm) : allow_templates (true), is_explicit (false), - consumed_comma_without_formatted_string (false), inlineAsm (inlineAsm) + consumed_comma_without_formatted_string (false), inline_asm (inline_asm) {} - bool is_global_asm () { return inlineAsm.is_global_asm; } + bool is_global_asm () { return inline_asm.is_global_asm; } bool allows_templates () { return allow_templates; } @@ -31,41 +31,41 @@ public: }; int -parse_asm_arg (Parser<MacroInvocLexer> &p, TokenId last_token_id, - InlineAsmContext &inlineAsmCtx); +parse_asm_arg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, + InlineAsmContext &inline_asm_ctx); tl::optional<AST::Fragment> parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc, bool is_global_asm); bool -check_identifier (Parser<MacroInvocLexer> &p, std::string ident); +check_identifier (Parser<MacroInvocLexer> &parser, std::string ident); void -check_and_set (Parser<MacroInvocLexer> &p, InlineAsmContext &inlineAsmCtx, - AST::InlineAsmOption option); +check_and_set (Parser<MacroInvocLexer> &parser, + InlineAsmContext &inline_asm_ctx, AST::InlineAsmOption option); // From rustc int parse_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id, - InlineAsmContext &inlineAsmCtx); + InlineAsmContext &inline_asm_ctx); // From rustc tl::optional<AST::InlineAsmOperand> parse_reg_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id, - InlineAsmContext &inlineAsmCtx); + InlineAsmContext &inline_asm_ctx); // From rustc int parse_options (Parser<MacroInvocLexer> &parser, TokenId last_token_id, - InlineAsmContext &inlineAsmCtx); + InlineAsmContext &inline_asm_ctx); // From rustc tl::optional<AST::InlineAsmRegOrRegClass> parse_reg (Parser<MacroInvocLexer> &parser, TokenId last_token_id, - InlineAsmContext &inlineAsmCtx); + InlineAsmContext &inline_asm_ctx); int parse_clobber_abi (Parser<MacroInvocLexer> &parser, TokenId last_token_id, - InlineAsmContext &inlineAsmCtx); + InlineAsmContext &inline_asm_ctx); } // namespace Rust
\ No newline at end of file diff --git a/gcc/rust/expand/rust-macro-builtins.cc b/gcc/rust/expand/rust-macro-builtins.cc index 7940f33..cd709c3 100644 --- a/gcc/rust/expand/rust-macro-builtins.cc +++ b/gcc/rust/expand/rust-macro-builtins.cc @@ -94,14 +94,14 @@ format_args_maker (AST::FormatArgs::Newline nl) enum class isGlobalAsm { - Yes, - No, + Global, + Inline, }; AST::MacroTranscriberFunc inline_asm_maker (isGlobalAsm is_global_asm) { - bool global_asm = is_global_asm == isGlobalAsm::Yes ? true : false; + bool global_asm = is_global_asm == isGlobalAsm::Global ? true : false; return [global_asm] (location_t loc, AST::MacroInvocData &invoc) { return MacroBuiltin::asm_handler (loc, invoc, global_asm); @@ -124,8 +124,8 @@ std::unordered_map<std::string, AST::MacroTranscriberFunc> {"include", MacroBuiltin::include_handler}, {"format_args", format_args_maker (AST::FormatArgs::Newline::No)}, {"format_args_nl", format_args_maker (AST::FormatArgs::Newline::Yes)}, - {"asm", inline_asm_maker (isGlobalAsm::No)}, - {"global_asm", inline_asm_maker (isGlobalAsm::Yes)}, + {"asm", inline_asm_maker (isGlobalAsm::Inline)}, + {"global_asm", inline_asm_maker (isGlobalAsm::Global)}, /* Unimplemented macro builtins */ {"option_env", MacroBuiltin::sorry}, {"concat_idents", MacroBuiltin::sorry}, diff --git a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs index 67dc10b..1358b5e 100644 --- a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs +++ b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber.rs @@ -7,6 +7,6 @@ macro_rules! asm { fn main() { unsafe { - asm!("nop", clobber_abi()); // { dg-error "at least one abi must be provided as an argument to `clobber_abi`" } + asm!("nop", clobber_abi()); // { dg-error "at least one abi must be provided as an argument to 'clobber_abi'" } } }
\ No newline at end of file diff --git a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs index 2906ea4..5688992 100644 --- a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs +++ b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_1.rs @@ -7,6 +7,6 @@ macro_rules! asm { fn main() { unsafe { - asm!("nop", clobber_abi); // { dg-error "expected `\\(`, found end of macro arguments" } + asm!("nop", clobber_abi); // { dg-error "expected '\\(', found end of macro arguments" } } }
\ No newline at end of file diff --git a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs index e5bf1d1..98cd052 100644 --- a/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs +++ b/gcc/testsuite/rust/compile/inline_asm_faulty_clobber_2.rs @@ -7,6 +7,6 @@ macro_rules! asm { fn main() { unsafe { - asm!("nop", clobber_abi+); // { dg-error "expected `\\(`, found `\\+`" } + asm!("nop", clobber_abi+); // { dg-error "expected '\\(', found '\\+'" } } }
\ No newline at end of file diff --git a/gcc/testsuite/rust/compile/inline_asm_illegal_options.rs b/gcc/testsuite/rust/compile/inline_asm_illegal_options.rs index ee50194..bf34c44 100644 --- a/gcc/testsuite/rust/compile/inline_asm_illegal_options.rs +++ b/gcc/testsuite/rust/compile/inline_asm_illegal_options.rs @@ -7,7 +7,7 @@ macro_rules! asm { fn main() { unsafe { - asm!("nop", options(nomem, nomem)); // { dg-error "the `nomem` option was already provided" } - asm!("nop", options(noreturn, noreturn)); // { dg-error "the `noreturn` option was already provided" } + asm!("nop", options(nomem, nomem)); // { dg-error "the 'nomem' option was already provided" } + asm!("nop", options(noreturn, noreturn)); // { dg-error "the 'noreturn' option was already provided" } } }
\ No newline at end of file |