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 <cassert> 16 #include <cstring> 17 18 #include "source/spirv_validator_options.h" 19 20 bool spvParseUniversalLimitsOptions(const char* s, spv_validator_limit* type) { 21 auto match = [s](const char* b) { 22 return s && (0 == strncmp(s, b, strlen(b))); 23 }; 24 if (match("--max-struct-members")) { 25 *type = spv_validator_limit_max_struct_members; 26 } else if (match("--max-struct_depth")) { 27 *type = spv_validator_limit_max_struct_depth; 28 } else if (match("--max-local-variables")) { 29 *type = spv_validator_limit_max_local_variables; 30 } else if (match("--max-global-variables")) { 31 *type = spv_validator_limit_max_global_variables; 32 } else if (match("--max-switch-branches")) { 33 *type = spv_validator_limit_max_global_variables; 34 } else if (match("--max-function-args")) { 35 *type = spv_validator_limit_max_function_args; 36 } else if (match("--max-control-flow-nesting-depth")) { 37 *type = spv_validator_limit_max_control_flow_nesting_depth; 38 } else if (match("--max-access-chain-indexes")) { 39 *type = spv_validator_limit_max_access_chain_indexes; 40 } else if (match("--max-id-bound")) { 41 *type = spv_validator_limit_max_id_bound; 42 } else { 43 // The command line option for this validator limit has not been added. 44 // Therefore we return false. 45 return false; 46 } 47 48 return true; 49 } 50 51 spv_validator_options spvValidatorOptionsCreate(void) { 52 return new spv_validator_options_t; 53 } 54 55 void spvValidatorOptionsDestroy(spv_validator_options options) { 56 delete options; 57 } 58 59 void spvValidatorOptionsSetUniversalLimit(spv_validator_options options, 60 spv_validator_limit limit_type, 61 uint32_t limit) { 62 assert(options && "Validator options object may not be Null"); 63 switch (limit_type) { 64 #define LIMIT(TYPE, FIELD) \ 65 case TYPE: \ 66 options->universal_limits_.FIELD = limit; \ 67 break; 68 LIMIT(spv_validator_limit_max_struct_members, max_struct_members) 69 LIMIT(spv_validator_limit_max_struct_depth, max_struct_depth) 70 LIMIT(spv_validator_limit_max_local_variables, max_local_variables) 71 LIMIT(spv_validator_limit_max_global_variables, max_global_variables) 72 LIMIT(spv_validator_limit_max_switch_branches, max_switch_branches) 73 LIMIT(spv_validator_limit_max_function_args, max_function_args) 74 LIMIT(spv_validator_limit_max_control_flow_nesting_depth, 75 max_control_flow_nesting_depth) 76 LIMIT(spv_validator_limit_max_access_chain_indexes, 77 max_access_chain_indexes) 78 LIMIT(spv_validator_limit_max_id_bound, max_id_bound) 79 #undef LIMIT 80 } 81 } 82 83 void spvValidatorOptionsSetRelaxStoreStruct(spv_validator_options options, 84 bool val) { 85 options->relax_struct_store = val; 86 } 87 88 void spvValidatorOptionsSetRelaxLogicalPointer(spv_validator_options options, 89 bool val) { 90 options->relax_logical_pointer = val; 91 } 92 93 void spvValidatorOptionsSetRelaxBlockLayout(spv_validator_options options, 94 bool val) { 95 options->relax_block_layout = val; 96 } 97 98 void spvValidatorOptionsSetScalarBlockLayout(spv_validator_options options, 99 bool val) { 100 options->scalar_block_layout = val; 101 } 102 103 void spvValidatorOptionsSetSkipBlockLayout(spv_validator_options options, 104 bool val) { 105 options->skip_block_layout = val; 106 } 107