Inspecting GCC’s command-line options

GCC’s command-line options are visible from Python scripts as instances of gcc.Option.

class gcc.Option

Wrapper around one of GCC’s command-line options.

You can locate a specific option using its text attribute:

option = gcc.Option('-Wdiv-by-zero')

The plugin will raise a ValueError if the option is not recognized.

It does not appear to be possible to create new options from the plugin.

text

(string) The text used at the command-line to affect this option e.g. -Werror.

help

(string) The help text for this option (e.g. “Warn about uninitialized automatic variables”)

is_enabled

(bool) Is this option enabled?

Note

Unfortunately, for many options, the internal implementation makes it difficult to extract this. The plugin will raise a NotImplementedError exception when querying this attribute for such an option.

Calling gcc.warning() with such an option will lead to GCC’s warning machinery treating the option as enabled and emitting a warning, regardless of whether or not the option was actually enabled.

It appears that this must be fixed on an option-by-option basis within the plugin.

is_driver

(bool) Is this a driver option?

is_optimization

(bool) Does this option control an optimization?

is_target

(bool) Is this a target-specific option?

is_warning

(bool) Does this option control a warning message?

Internally, the class wraps GCC’s enum opt_code (and thus a struct cl_option)

gcc.get_option_list()

Returns a list of all gcc.Option instances.

gcc.get_option_dict()

Returns a dictionary, mapping from the option names to gcc.Option instances