-
Notifications
You must be signed in to change notification settings - Fork 13.4k
asm!: options
should work multiple times, to simplify macros
#73193
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
That seems like an extremely niche use case that would only really enable an |
A large codebase that uses primarily AT&T syntax will want to spell it as briefly as possible; I expect to see such a macro in common use. If you believe this would complicate the parser unnecessarily, then I would be open to a crate-based solution that shows how to implement the macro taking existing |
I think a simpler semantic would be "multiple This would be good not only for macros, but also for readability (some people might prefer multiple |
@cesarb That sounds reasonable to me. |
This is actually a very trivial change to the parsers, so it should be easy to add. |
@rustbot claim |
No no, go ahead, you can have it. |
Thanks! I’ll give it a try :) @rustbot claim |
How should I handle diagnostics? There are multiple errors that show where the error in the options occurred, e.g.: ecx.struct_span_err(span, "the `nomem` and `readonly` options are mutually exclusive")
.emit(); The way I'm doing the multiple options is to just let it bitwise-OR the different flags into the Advice? |
Also, perhaps there should be a simple diagnostic for checking for duplicate options? |
Alternatively, the errors could just be reported on all the options spans. |
Error reporting can take a |
You can add a diagnostic for setting the same option multiple times by just checking if it has already been ORed in. |
Yeah, that's what I was thinking |
Is it okay to |
Sure. |
Last option overrides is a better design if the goal is to enable macros. That way invocations of the same (EDIT: OTOH I think nomem vs readonly strongly informs the design towards no conflicting options) |
Uh oh!
There was an error while loading. Please reload this page.
To simplify the implementation of macros wrapping
asm!
, I thinkoptions
should work if specified multiple times, with the semantic that no conflicting options may be provided. (We could also do "last option wins", but I think I'd slightly prefer "don't specify conflicting options" instead.)This would, for instance, make it much easier to implement an
asm_att!
macro that passes all its arguments toasm!
and addsoptions(att_syntax)
, without having to scan all the tokens it receives, look for an existingoptions
, and append to it if found.Sample code that I think should work (printing
9
):The text was updated successfully, but these errors were encountered: