Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inline asm #2982

Merged
merged 43 commits into from
Jun 13, 2024
Merged

Inline asm #2982

merged 43 commits into from
Jun 13, 2024

Conversation

badumbatish
Copy link
Contributor

Draft PR for my mentors

@badumbatish badumbatish force-pushed the inline_asm branch 6 times, most recently from 5a0f0a9 to 69a06ce Compare May 22, 2024 04:28
gcc/rust/ast/rust-expr.h Outdated Show resolved Hide resolved
gcc/rust/ast/rust-expr.h Outdated Show resolved Hide resolved
gcc/rust/expand/rust-macro-builtins.cc Outdated Show resolved Hide resolved
@badumbatish badumbatish force-pushed the inline_asm branch 5 times, most recently from ec44fbd to fedb5ed Compare May 30, 2024 01:35
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is great progress :DD well done! a couple nitpicks and things to fix but we can merge this soon

gcc/rust/ast/rust-expr.h Show resolved Hide resolved
gcc/rust/ast/rust-expr.h Outdated Show resolved Hide resolved
gcc/rust/ast/rust-expr.h Outdated Show resolved Hide resolved
gcc/rust/ast/rust-expr.h Outdated Show resolved Hide resolved
gcc/rust/ast/rust-expr.h Outdated Show resolved Hide resolved
gcc/rust/expand/rust-macro-builtins-asm.cc Outdated Show resolved Hide resolved
gcc/rust/expand/rust-macro-builtins-asm.cc Outdated Show resolved Hide resolved
gcc/rust/expand/rust-macro-builtins-asm.cc Outdated Show resolved Hide resolved
gcc/rust/expand/rust-macro-builtins-asm.cc Outdated Show resolved Hide resolved
gcc/rust/expand/rust-macro-builtins.cc Outdated Show resolved Hide resolved
@badumbatish
Copy link
Contributor Author

Pr's looking good, i let some quoted strings warnings slipped through but it should get fixed soon. I'll look into tl::expected soon

gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (struct AsmParseError): title.
	(enum InlineAsmDirSpec): title.
	(enum InlineAsmOptions): title.
	(struct AsmArg): title.
	(parseAsmArg): title.
	(parse_global_asm): title.
	(parse_nonglobal_asm): title.
	(parse_asm): title.
	(parseDirSpec): title.
	(parse_format_string): title.
	(MacroBuiltin::global_asm_handler): title.
	(MacroBuiltin::nonglobal_asm_handler): title.
	* expand/rust-macro-builtins.cc: title.
	* expand/rust-macro-builtins.h: title.
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (enum InlineAsmRegOrRegClass): title.
	(parseAsmArg): title.
	(check_identifier): title.
	(parse_operand): title.
	(parse_options): title.
	(parse_reg): title.
	(parseDirSpec): title.
	(parse_asm): title.
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_clobber_abi): title.
	(parseAsmArg): title.
	* expand/rust-macro-builtins-asm.h (parse_clobber_abi): title.
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_options): title.
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_clobber_abi): title.
Finish up on parse_option, formatted parse_clobber_abi
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_clobber_abi): format
	(check_and_set): helper function, is try_set_option equivalent
	(parse_options): new function
	* expand/rust-macro-builtins-asm.h (enum InlineAsmOptions):
	removed
	(check_and_set): decl of helper function
gcc/rust/ChangeLog:

	* ast/rust-expr.h: Introduced is_global_asm to InlineAsm AST
gcc/rust/ChangeLog:

	* ast/rust-expr.h: Make InlineAsm non-abstract for usage in parsing.
Replace scaffolded InlineAsm with real InlineAsm node in rust-expr.h

gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parseDirSpec): replace
	scaffolded InlineAsm with real InlineAsm.
	(parse_clobber_abi): likewise.
	(check_and_set): likewise.
	(parse_options): likewise.
	(parseAsmArg): likewise.
	(parse_asm): likewise.
	* expand/rust-macro-builtins-asm.h (struct AsmParseError): likewise.
	(enum InlineAsmDirSpec): likewise.
	(enum InlineAsmRegOrRegClass): likewise.
	(struct AsmArg): likewise.
	(parseAsmArg): likewise.
	(check_and_set): likewise.
	(parse_operand): likewise.
	(parse_options): likewise.
	(parse_reg): likewise.
	(parse_clobber_abi): likewise.
gcc/testsuite/ChangeLog:

	* rust/compile/inline_asm_nop.rs: Simple test for asm!
gcc/testsuite/ChangeLog:

	* rust/compile/inline_asm_ident_first.rs: New test.
gcc/testsuite/ChangeLog:

	* rust/compile/inline_asm_nop_2.rs: New test.
gcc/testsuite/ChangeLog:

	* rust/compile/inline_asm_faulty_clobber.rs: New test.
	* rust/compile/inline_asm_faulty_clobber_1.rs: New test.
	* rust/compile/inline_asm_faulty_clobber_2.rs: New test.
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_clobber_abi):
	implemented parse_clobber_abi
	(parse_format_string): likewise.
	(parseAsmArg): likewise.
	(parse_asm): likewise.
	* expand/rust-macro-builtins-asm.h (parseAsmArg): likewise.
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.
gcc/rust/ChangeLog:

	* ast/rust-expr.h:
	Add support for AST to HIR inline asm translation
	* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
	* hir/rust-ast-lower-base.h: Likewise.
	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
	* hir/rust-ast-lower-expr.h: Likewise.
	* hir/tree/rust-hir-expr.h (class InlineAsm): Likewise.
gcc/rust/ChangeLog:

	* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
	Partial unsafe support for inline asm
	* checks/errors/rust-unsafe-checker.h: Likewise.
	* hir/tree/rust-hir-expr.h: Likewise.
	* hir/tree/rust-hir.cc (InlineAsm::accept_vis): Likewise.
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
	Fix compile warnings.
	(parse_options): Likewise.
	(parse_asm): Likewise.

gcc/testsuite/ChangeLog:

	* rust/compile/inline_asm_illegal_options.rs:
gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.h:
	Scaffolding ast visitor for InlineAsm
	* ast/rust-ast.cc (InlineAsm::accept_vis): Likewise.
	* ast/rust-expr.h: Likewise.
gcc/rust/ChangeLog:

	* ast/rust-ast-visitor.h:
	Scaffolding HIRFullVisitor for inline asm
	* ast/rust-ast.cc (InlineAsm::accept_vis): Likewise.
	* hir/tree/rust-hir-visitor.h (RUST_HIR_VISITOR_H): Likewise.
	* hir/tree/rust-hir.cc (InlineAsm::accept_vis): Likewise.
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
	Successful parse of in and inout, albeit with str
	(check_identifier): Likewise.
	(parse_asm_arg): Likewise.
	* expand/rust-macro-builtins-asm.h (parse_format_string): Likewise.

gcc/testsuite/ChangeLog:

	* rust/compile/inline_asm_parse_operand.rs: New test.
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
	Add potentially_nonpromoted_keywords set str
	(check_identifier): likewise
	* expand/rust-macro-builtins-asm.h (parse_format_string):
	likewise

gcc/testsuite/ChangeLog:

	* rust/compile/inline_asm_parse_operand.rs: fix warnings
gcc/rust/ChangeLog:

	* ast/rust-ast-collector.cc (TokenCollector::visit):
	Fix visitor-related warnings
	* ast/rust-ast-collector.h: Likewise.
	* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
	* ast/rust-ast-visitor.h: Likewise.
	* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
	* checks/errors/borrowck/rust-function-collector.h: Likewise.
	* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
	* checks/errors/rust-const-checker.h: Likewise.
	* expand/rust-derive.h: Likewise.
	* expand/rust-macro-builtins-asm.cc (parse_reg_operand): Likewise.
	* hir/rust-hir-dump.cc (Dump::visit): Likewise.
	* hir/rust-hir-dump.h: Likewise.
	* hir/tree/rust-hir-visitor.h: Likewise.
	* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
	* resolve/rust-ast-resolve-base.h: Likewise.
gcc/rust/ChangeLog:

	* ast/rust-expr.h (struct InlineAsmOperand):
	Refactoring and supporting more parse_reg_operand
	* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
	Likewise.
	(rust_debug): Likewise.
gcc/rust/ChangeLog:

	* ast/rust-expr.h (struct InlineAsmOperand):
	Partial support for operand
	* expand/rust-macro-builtins-asm.cc (parse_reg_operand): Likewise.
	(parse_label): Likewise.
	* expand/rust-macro-builtins-asm.h (parse_label): Likewise.
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/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
	Update parser to parse strings in the first stage
	(parse_label): not needed right now
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_clobber_abi):
	Move parser and last_token_id to InlineAsmCtx to prepapre
	for tl::expected.
	(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 (class InlineAsmParseError): Likewise.
	(parse_asm_arg): Likewise.
	(check_and_set): Likewise.
	(parse_operand): Likewise.
	(parse_reg_operand): Likewise.
	(parse_options): Likewise.
	(parse_reg): Likewise.
	(parse_clobber_abi): Likewise.
	(parse_format_string): Likewise.
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_reg):
	Expected first layer done
	(parse_reg_operand): Likewise.
	(parse_asm_arg): Likewise.
	(parse_format_strings): Likewise.
	(parse_asm): Likewise.
	(validate): Likewise.
	* expand/rust-macro-builtins-asm.h (parse_asm_arg): Likewise.
	(validate): Likewise.
	(parse_format_strings): Likewise.
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parseDirSpec):
	Partial second layer of expected in parsing asm
	(parse_clobber_abi): Likewise
	(parse_operand): Likewise
	(parse_reg_operand): Likewise
	(parse_asm_arg): Likewise
	* expand/rust-macro-builtins-asm.h (parse_clobber_abi): Likewise
	(parse_reg_operand): Likewise
	(parse_operand): Likewise
@badumbatish badumbatish marked this pull request as ready for review June 12, 2024 15:29
Comment on lines +34 to +35
tl::expected<InlineAsmContext, std::string>
parse_clobber_abi (InlineAsmContext inline_asm_ctx)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is good! in another PR, I'd like you to start working on a "proper" error type instead of strings, something like

enum class AsmParseError {
    Reason1,
    Reason2,
    MissingAbiArgument,
    ...
}

it'll clean up the code a little bit and we can then see how we'll transform these into proper Errors to emit for the user

@@ -6,6 +6,8 @@
#include "rust-path.h"
#include "rust-macro.h"
#include "rust-operators.h"
#include "rust-system.h"
#include <memory>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, the system include is still here. you should be able to remove it entirely

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gotcha

gcc/rust/ast/rust-expr.h Show resolved Hide resolved
Comment on lines +4868 to +5072
// TODO: Not sure how outer_attrs plays with InlineAsm, I put it here in order
// to override, very hacky.
std::vector<Attribute> outer_attrs;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, alright. can you open an issue for this please? titled something like Handle outer attributes properly for inline assembly and we'll have a look later during the project :)

@CohenArthur CohenArthur added this pull request to the merge queue Jun 12, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jun 12, 2024
@CohenArthur CohenArthur added this pull request to the merge queue Jun 13, 2024
Merged via the queue into Rust-GCC:master with commit 7fa14d4 Jun 13, 2024
9 checks passed
@badumbatish badumbatish deleted the inline_asm branch June 13, 2024 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants