spirv_validator_options.cpp 4.0 KB

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