-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Internal IR for compiler args #14748
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
base: master
Are you sure you want to change the base?
Internal IR for compiler args #14748
Conversation
The goal is to be able to convert arguments from raw arguments that are passed in via the `c_args` and friends methods, as well as from options and the environment, into an abstract IR. This IR is then passed around internally, and the backend is responsible for lowering it into the format that it wants. I'm hoping that this will simplify some amount of passing arguments between languages (like C arguments being passed to non-c compilers, and linker arguments between languages) as well as simplify the non-ninja backends which generally use a different mechanism than raw compiler arguments.
…arguments These will be used to convert the arguments in many cases.
FWIW, I like this! |
:param enable: If true then enable the warning, otherwise suppress it. | ||
""" | ||
|
||
target: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think an enable
member went missing here.
elif arg.startswith('-U'): | ||
ret.append(arguments.Undefine(arg.removeprefix('-U'))) | ||
elif arg.startswith('-Wno-'): | ||
ret.append(arguments.Warning(arg.removeprefix('-Wno-'), False)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handling of arguments starting with -Wno-
is duplicated below.
|
||
for arg in args: | ||
match arg: | ||
case arguments.Define(name, value): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be case arguments.Define(name, None)
?
This is set to draft because it's very much a Work in Progress.
The way we handle compiler arguments in Meson is to manipulate raw strings. This works fine when the majority of your compilers are the same, or at least attempt to be compatible. Unfortunately, Meson has to deal with many different toolchains, which often have incompatible argument syntax.
This manifests in a number of different ways:
-Wl,-rlink
or-rlink
inside ofbuild.py
, but that could miss-rlink
for many compilers.if
blocks converting string command line arguments to XML fieldsIn order to address this I propose moving to an abstract IR for these arguments. This abstract IR would simplify de-duplicating and cleaning arguments, as well as converting their forms. Each Compiler provides a mechanism to convert arguments from their format into the abstract IR, and a method to convert the abstract IR back into concrete arguments in their expected format. We then manipulate the abstract IR more easily. Consider something like this:
In this format it's pretty easy to look and see that we have two copies of
-DX
and two copies of-Wfoo
along with-Wno-foo
, cancelling both of those out.Below is a very trivial implementation of this idea, with just enough implemented for GCC or Clang to compile the
1 trivial
test (run directly). This also is making use of python features we currently cant rely on, I'll rewrite those later.