| 51 | }; |
| 52 | |
| 53 | void PrintUsage(const char* program) { |
| 54 | // NOTE: Please maintain flags in lexicographical order. |
| 55 | printf( |
| 56 | R"(%s - Reduce a SPIR-V binary file with respect to a user-provided |
| 57 | interestingness test. |
| 58 | |
| 59 | USAGE: %s [options] <input.spv> -o <output.spv> -- <interestingness_test> [args...] |
| 60 | |
| 61 | The SPIR-V binary is read from <input.spv>. The reduced SPIR-V binary is |
| 62 | written to <output.spv>. |
| 63 | |
| 64 | Whether a binary is interesting is determined by <interestingness_test>, which |
| 65 | should be the path to a script. The "--" characters are optional but denote |
| 66 | that all arguments that follow are positional arguments and thus will be |
| 67 | forwarded to the interestingness test, and not parsed by %s. |
| 68 | |
| 69 | * The script must be executable. |
| 70 | |
| 71 | * The script should take the path to a SPIR-V binary file (.spv) as an |
| 72 | argument, and exit with code 0 if and only if the binary file is |
| 73 | interesting. The binary will be passed to the script as an argument after |
| 74 | any other provided arguments [args...]. |
| 75 | |
| 76 | * Example: an interestingness test for reducing a SPIR-V binary file that |
| 77 | causes tool "foo" to exit with error code 1 and print "Fatal error: bar" to |
| 78 | standard error should: |
| 79 | - invoke "foo" on the binary passed as the script argument; |
| 80 | - capture the return code and standard error from "bar"; |
| 81 | - exit with code 0 if and only if the return code of "foo" was 1 and the |
| 82 | standard error from "bar" contained "Fatal error: bar". |
| 83 | |
| 84 | * The reducer does not place a time limit on how long the interestingness test |
| 85 | takes to run, so it is advisable to use per-command timeouts inside the |
| 86 | script when invoking SPIR-V-processing tools (such as "foo" in the above |
| 87 | example). |
| 88 | |
| 89 | NOTE: The reducer is a work in progress. |
| 90 | |
| 91 | Options (in lexicographical order): |
| 92 | |
| 93 | --fail-on-validation-error |
| 94 | Stop reduction with an error if any reduction step produces a |
| 95 | SPIR-V module that fails to validate. |
| 96 | -h, --help |
| 97 | Print this help. |
| 98 | --step-limit= |
| 99 | 32-bit unsigned integer specifying maximum number of steps the |
| 100 | reducer will take before giving up. |
| 101 | --target-function= |
| 102 | 32-bit unsigned integer specifying the id of a function in the |
| 103 | input module. The reducer will restrict attention to this |
| 104 | function, and will not make changes to other functions or to |
| 105 | instructions outside of functions, except that some global |
| 106 | instructions may be added in support of reducing the target |
| 107 | function. If 0 is specified (the default) then all functions are |
| 108 | reduced. |
| 109 | --temp-file-prefix= |
| 110 | Specifies a temporary file prefix that will be used to output |