/src/spirv-tools/source/spirv_validator_options.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2017 Google Inc. |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | #include "source/spirv_validator_options.h" |
16 | | |
17 | | #include <cassert> |
18 | | #include <cstring> |
19 | | |
20 | 0 | bool spvParseUniversalLimitsOptions(const char* s, spv_validator_limit* type) { |
21 | 0 | auto match = [s](const char* b) { |
22 | 0 | return s && (0 == strncmp(s, b, strlen(b))); |
23 | 0 | }; |
24 | 0 | if (match("--max-struct-members")) { |
25 | 0 | *type = spv_validator_limit_max_struct_members; |
26 | 0 | } else if (match("--max-struct_depth")) { |
27 | 0 | *type = spv_validator_limit_max_struct_depth; |
28 | 0 | } else if (match("--max-local-variables")) { |
29 | 0 | *type = spv_validator_limit_max_local_variables; |
30 | 0 | } else if (match("--max-global-variables")) { |
31 | 0 | *type = spv_validator_limit_max_global_variables; |
32 | 0 | } else if (match("--max-switch-branches")) { |
33 | 0 | *type = spv_validator_limit_max_global_variables; |
34 | 0 | } else if (match("--max-function-args")) { |
35 | 0 | *type = spv_validator_limit_max_function_args; |
36 | 0 | } else if (match("--max-control-flow-nesting-depth")) { |
37 | 0 | *type = spv_validator_limit_max_control_flow_nesting_depth; |
38 | 0 | } else if (match("--max-access-chain-indexes")) { |
39 | 0 | *type = spv_validator_limit_max_access_chain_indexes; |
40 | 0 | } else if (match("--max-id-bound")) { |
41 | 0 | *type = spv_validator_limit_max_id_bound; |
42 | 0 | } else { |
43 | | // The command line option for this validator limit has not been added. |
44 | | // Therefore we return false. |
45 | 0 | return false; |
46 | 0 | } |
47 | | |
48 | 0 | return true; |
49 | 0 | } |
50 | | |
51 | 45.7k | spv_validator_options spvValidatorOptionsCreate(void) { |
52 | 45.7k | return new spv_validator_options_t; |
53 | 45.7k | } |
54 | | |
55 | 45.7k | void spvValidatorOptionsDestroy(spv_validator_options options) { |
56 | 45.7k | delete options; |
57 | 45.7k | } |
58 | | |
59 | | void spvValidatorOptionsSetUniversalLimit(spv_validator_options options, |
60 | | spv_validator_limit limit_type, |
61 | 26.8k | uint32_t limit) { |
62 | 26.8k | assert(options && "Validator options object may not be Null"); |
63 | 26.8k | switch (limit_type) { |
64 | 0 | #define LIMIT(TYPE, FIELD) \ |
65 | 26.8k | case TYPE: \ |
66 | 26.8k | options->universal_limits_.FIELD = limit; \ |
67 | 26.8k | break; |
68 | 0 | LIMIT(spv_validator_limit_max_struct_members, max_struct_members) |
69 | 0 | LIMIT(spv_validator_limit_max_struct_depth, max_struct_depth) |
70 | 0 | LIMIT(spv_validator_limit_max_local_variables, max_local_variables) |
71 | 0 | LIMIT(spv_validator_limit_max_global_variables, max_global_variables) |
72 | 0 | LIMIT(spv_validator_limit_max_switch_branches, max_switch_branches) |
73 | 0 | LIMIT(spv_validator_limit_max_function_args, max_function_args) |
74 | 0 | LIMIT(spv_validator_limit_max_control_flow_nesting_depth, |
75 | 0 | max_control_flow_nesting_depth) |
76 | 0 | LIMIT(spv_validator_limit_max_access_chain_indexes, |
77 | 0 | max_access_chain_indexes) |
78 | 26.8k | LIMIT(spv_validator_limit_max_id_bound, max_id_bound) |
79 | 26.8k | #undef LIMIT |
80 | 26.8k | } |
81 | 26.8k | } |
82 | | |
83 | | void spvValidatorOptionsSetRelaxStoreStruct(spv_validator_options options, |
84 | 0 | bool val) { |
85 | 0 | options->relax_struct_store = val; |
86 | 0 | } |
87 | | |
88 | | void spvValidatorOptionsSetRelaxLogicalPointer(spv_validator_options options, |
89 | 0 | bool val) { |
90 | 0 | options->relax_logical_pointer = val; |
91 | 0 | } |
92 | | |
93 | | void spvValidatorOptionsSetBeforeHlslLegalization(spv_validator_options options, |
94 | 0 | bool val) { |
95 | 0 | options->before_hlsl_legalization = val; |
96 | 0 | options->relax_logical_pointer = val; |
97 | 0 | } |
98 | | |
99 | | void spvValidatorOptionsSetRelaxBlockLayout(spv_validator_options options, |
100 | 0 | bool val) { |
101 | 0 | options->relax_block_layout = val; |
102 | 0 | } |
103 | | |
104 | | void spvValidatorOptionsSetUniformBufferStandardLayout( |
105 | 0 | spv_validator_options options, bool val) { |
106 | 0 | options->uniform_buffer_standard_layout = val; |
107 | 0 | } |
108 | | |
109 | | void spvValidatorOptionsSetScalarBlockLayout(spv_validator_options options, |
110 | 0 | bool val) { |
111 | 0 | options->scalar_block_layout = val; |
112 | 0 | } |
113 | | |
114 | | void spvValidatorOptionsSetWorkgroupScalarBlockLayout(spv_validator_options options, |
115 | 0 | bool val) { |
116 | 0 | options->workgroup_scalar_block_layout = val; |
117 | 0 | } |
118 | | |
119 | | void spvValidatorOptionsSetSkipBlockLayout(spv_validator_options options, |
120 | 0 | bool val) { |
121 | 0 | options->skip_block_layout = val; |
122 | 0 | } |
123 | | |
124 | | void spvValidatorOptionsSetAllowLocalSizeId(spv_validator_options options, |
125 | 0 | bool val) { |
126 | 0 | options->allow_localsizeid = val; |
127 | 0 | } |
128 | | |
129 | | void spvValidatorOptionsSetAllowOffsetTextureOperand( |
130 | 0 | spv_validator_options options, bool val) { |
131 | 0 | options->allow_offset_texture_operand = val; |
132 | 0 | } |
133 | | |
134 | | void spvValidatorOptionsSetAllowVulkan32BitBitwise( |
135 | 0 | spv_validator_options options, bool val) { |
136 | 0 | options->allow_vulkan_32_bit_bitwise = val; |
137 | 0 | } |
138 | | |
139 | | void spvValidatorOptionsSetFriendlyNames(spv_validator_options options, |
140 | 0 | bool val) { |
141 | 0 | options->use_friendly_names = val; |
142 | 0 | } |