================ @@ -0,0 +1,626 @@ +#!/usr/bin/env python3 + +""" generate_unsupported_in_drivermode.py + +usage: python generate_unsupported_in_drivermode.py <path>/Options.td [<path>/llvm-tblgen] + +This script generates a Lit regression test file that validates that options +are only exposed to intended driver modes. + +The options and driver modes are parsed from Options.td, whose path should be +provided on the command line. See clang/include/clang/Driver/Options.td + +The path to the TableGen executable can optionally be provided. Otherwise, the +script will search for it. + +The primary maintenance task for this script would be updating the expected return message for a driver mode if +there are changes over time. See the instantiations of DriverController, specifically the check_string. + +Logic: +1) For each option, (records of class "Option"), and for each driver, (records of class "OptionVisibility") + a. if the option's "Visibility" field includes the driver flavour, skip processing this option for this driver + b. if the option is part of an option group, (the record has the "Group" property), + and the group's "Visibility" field includes the driver flavour, skip processing this option for this driver + c. otherwise this option is not supported by this driver flavour, and this pairing is saved for testing +2) For each unsupported pairing, generate a Lit RUN line, and a CHECK line to parse for expected output. Ex: "error: unknown argument" +""" + +import sys +import shutil +import os +import json +import subprocess +import math +from pathlib import Path + +LLVM_TABLEGEN = "llvm-tblgen" +LIT_TEST_PATH = "../test/Driver/unsupported_in_drivermode.c" +LIT_TEST_PATH_FLANG = "../test/Driver/flang/unsupported_in_flang.f90" +INCLUDE_PATH = "../../llvm/include" + +# Strings defined in Options.td for the various driver flavours. See "OptionVisibility" +VISIBILITY_CC1AS = "CC1AsOption" +VISIBILITY_CC1 = "CC1Option" +VISIBILITY_CL = "CLOption" +VISIBILITY_DXC = "DXCOption" +VISIBILITY_DEFAULT = "DefaultVis" +VISIBILITY_FC1 = "FC1Option" +VISIBILITY_FLANG = "FlangOption" + +# Strings used in the commands to be tested +CLANG = "clang" +CLANG_CL = f"{CLANG} --driver-mode=cl" +CLANG_DXC = f"{CLANG} --driver-mode=dxc" +FLANG = f"{CLANG} --driver-mode=flang" +CLANG_LIT = "%clang" +CLANG_CL_LIT = "%clang_cl" +CLANG_DXC_LIT = "%clang_dxc" +FLANG_LIT = f"%{FLANG}" +OPTION_HASH = "-###" +OPTION_X = "-x" +OPTION_WX = "/WX" +OPTION_CPP = "c++" +OPTION_C = "-c" +OPTION_CC1 = "-cc1" +OPTION_CC1AS = "-cc1as" +OPTION_FC1 = "-fc1" +OPTION_SLASH_C = "/c" +OPTION_T = "/T lib_6_7" +SLASH_SLASH = "// " +EXCLAMATION = "! " ---------------- Maetveis wrote:
I don't think giving these names like this is particularly helpful, it just requires me to jump back and forth when reading the strings below to see what the variables will resolve to. https://github.com/llvm/llvm-project/pull/120900 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits