8000 Make useful driver arguments available on all targets by ChrisDodd · Pull Request #5328 · p4lang/p4c · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Make useful driver arguments available on all targets #5328

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

Merged
merged 1 commit into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 0 additions & 80 deletions 10000 backends/tofino/bf-p4c/driver/barefoot.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,26 +258,6 @@ def add_command_line_options(self):
choices=[0, 1, 2, 3],
help="Set compiler logging verbosity level: 0=OFF, 1=SUMMARY, 2=INFO, 3=DEBUG",
)
self._argGroup.add_argument(
"--Wdisable",
action="append",
nargs="?",
default=None,
const="",
type=str,
help="Disable a compiler diagnostic, or disable all warnings "
"if no diagnostic is specified.",
)
self._argGroup.add_argument(
"--Werror",
action="append",
nargs="?",
default=None,
const="",
type=str,
help="Report an error for a compiler diagnostic, or treat all "
"warnings as errors if no diagnostic is specified.",
)
self._argGroup.add_argument(
"--help-warnings",
help="Print warning types that can be used for --Werror and --Wdisable options.",
Expand Down Expand Up @@ -316,13 +296,6 @@ def add_command_line_options(self):
help="Reduce PHV allocation search space for faster compilation.",
)
if os.environ['P4C_BUILD_TYPE'] == "DEVELOPER":
for debugger in ["gdb", "cgdb", "lldb"]:
self._argGroup.add_argument(
"--" + debugger,
action="store_true",
default=False,
help="run the backend compiler under the %s debugger" % (debugger,),
)
self._argGroup.add_argument(
"--validate-output",
action="store_true",
Expand Down Expand Up @@ -442,35 +415,6 @@ def config_assembler(self, targetName):
def config_p4c_gen_conf(self, maxPipe):
self.add_command_option('p4c-gen-conf', "--max-pipe " + str(maxPipe))

def config_warning_modifiers(self, arguments, option):
"""! Behaviour of warnings emitted by p4c can be modified by two options:
--Werror which turns all/selected warnings into errors
--Wdisable which ignores all/selected warnings
Both accept either no further options or they accept comma separated list of strings
or they can occur multiple times with a different CSL each time. If argparser is properly configured
(action="append", nargs="?", default=None, const="", type=str) it will create a list of strings
(plain or CSLs) or empty string (if no further option was provided).
You can then pass parsed argument to this function to properly select between everything or something
and to properly parse CSLs.

@param arguments Warning arguments
@param option String value, either "disable" or "error"
"""
if option != "disable" and option != "error":
raise Exception(
"Programmer error - config_warning_modifiers does not support option " + option
)

all = len(arguments) == 1 and arguments[0] == ""

if all:
self.add_command_option('compiler', '--W{}'.format(option))
else:
for diag in arguments:
subdiags = diag.split(',')
for sd in subdiags:
self.add_command_option('compiler', '--W{}={}'.format(option, sd))

def should_not_check_input(self, opts):
"""!
@return True if input should not be checked, otherwise False
Expand Down Expand Up @@ -529,11 +473,6 @@ def process_command_line_options(self, opts):
self.checkVersionTargetArch(opts.target, opts.language, opts.arch)
self.language = opts.language

# Make sure we don't have conflicting debugger options.
if os.environ['P4C_BUILD_TYPE'] == "DEVELOPER":
if sum(int(x) for x in [opts.gdb, opts.cgdb, opts.lldb]) > 1:
self.exitWithError("Cannot use more than one debugger at a time.")

# process the options related to source file
if self._output_directory == '.':
# if no output directory set, set it to <program_name.target>
Expand Down Expand Up @@ -577,19 +516,6 @@ def process_command_line_options(self, opts):
if opts.skip_linker:
self._no_link = True

if os.environ['P4C_BUILD_TYPE'] == "DEVELOPER":
if opts.gdb or opts.cgdb or opts.lldb:
# XXX breaks abstraction
old_command = self._commands['compiler']
if opts.lldb:
self.add_command('compiler', 'lldb')
self.add_command_option('compiler', '--')
else:
self.add_command('compiler', 'gdb' if opts.gdb else 'cgdb')
self.add_command_option('compiler', '--args')
for arg in old_command:
self.add_command_option('compiler', arg)

if opts.create_graphs or opts.archive:
self.add_command_option('compiler', '--create-graphs')

Expand Down Expand Up @@ -650,12 +576,6 @@ def process_command_line_options(self, opts):
# no need for anything else, we printed the pragmas and we need to exit
sys.exit(0)

if opts.Wdisable is not None:
self.config_warning_modifiers(opts.Wdisable, "disable")

if opts.Werror is not None:
self.config_warning_modifiers(opts.Werror, "error")

self.pragmas_help = opts.help_pragmas
if opts.help_pragmas:
self.add_command_option('compiler', '--help-pragmas')
Expand Down
47 changes: 47 additions & 0 deletions tools/driver/p4c_src/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,35 @@ def add_command_line_options(self):
"""Method for derived classes to add options to the parser"""
self._argGroup = self._argParser.add_argument_group(title=self._backend)

def config_warning_modifiers(self, arguments, option):
"""! Behaviour of warnings emitted by p4c can be modified by two options:
--Werror which turns all/selected warnings into errors
--Wdisable which ignores all/selected warnings
Both accept either no further options or they accept comma separated list of strings
or they can occur multiple times with a different CSL each time. If argparser is properly configured
(action="append", nargs="?", default=None, const="", type=str) it will create a list of strings
(plain or CSLs) or empty string (if no further option was provided).
You can then pass parsed argument to this function to properly select between everything or something
and to properly parse CSLs.

@param arguments Warning arguments
@param option String value, either "disable" or "error"
"""
if option != "disable" and option != "error":
raise Exception(
"Programmer error - config_warning_modifiers does not support option " + option
)

all = len(arguments) == 1 and arguments[0] == ""

if all:
self.add_command_option('compiler', '--W{}'.format(option))
else:
for diag in arguments:
subdiags = diag.split(',')
for sd in subdiags:
self.add_command_option('compiler', '--W{}={}'.format(option, sd))

def process_command_line_options(self, opts):
"""Process all command line options"""
self._dry_run = opts.dry_run
Expand All @@ -100,6 +129,10 @@ def process_command_line_options(self, opts):
# set compiler options.
for option in opts.compiler_options:
self.add_command_option("compiler", option)
if opts.Wdisable is not None:
self.config_warning_modifiers(opts.Wdisable, "disable")
if opts.Werror is not None:
self.config_warning_modifiers(opts.Werror, "error")

# set debug info
if opts.debug_info:
Expand Down Expand Up @@ -195,6 +228,20 @@ def process_command_line_options(self, opts):
self.add_command_option("compiler", "--pp {}".format(opts.pretty_print))
if opts.ndebug_mode:
self.add_command_option("compiler", "--ndebug")
# Make sure we don't have conflicting debugger options.
if sum(int(x) for x in [opts.gdb, opts.cgdb, opts.lldb]) > 1:
self.exitWithError("Cannot use more than one debugger at a time.")
if opts.gdb or opts.cgdb or opts.lldb:
# XXX breaks abstraction
old_command = self._commands['compiler']
if opts.lldb:
self.add_command('compiler', 'lldb')
self.add_command_option('compiler', '--')
else:
self.add_command('compiler', 'gdb' if opts.gdb else 'cgdb')
self.add_command_option('compiler', '--args')
for arg in old_command:
self.add_command_option('compiler', arg)

if (
(os.environ["P4C_BUILD_TYPE"] == "DEVELOPER")
Expand Down
27 changes: 27 additions & 0 deletions tools/driver/p4c_src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ def add_developer_options(parser):
default=None,
help="Pretty-print the program in the specified file.",
)
for debugger in ["gdb", "cgdb", "lldb"]:
parser.add_argument(
"--" + debugger,
action="store_true",
default=False,
help="run the backend compiler under the %s debugger" % (debugger,),
)


def s_and_were_or_just_was(parameter):
Expand Down Expand Up @@ -426,6 +433,26 @@ def main():
action="store",
default=None,
)
parser.add_argument(
"--Wdisable",
action="append",
nargs="?",
default=None,
const="",
type=str,
help="Disable a compiler diagnostic, or disable all warnings "
"if no diagnostic is specified.",
)
parser.add_argument(
"--Werror",
action="append",
nargs="?",
default=None,
const="",
type=str,
help="Report an error for a compiler diagnostic, or treat all "
"warnings as errors if no diagnostic is specified.",
)

### DRYified “env_indicates_developer_build”
env_indicates_developer_build = os.environ["P4C_BUILD_TYPE"] == "DEVELOPER"
Expand Down
Loading
< 19 /div> 0