spirv_validator_options.cpp 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 {
  38. // The command line option for this validator limit has not been added.
  39. // Therefore we return false.
  40. return false;
  41. }
  42. return true;
  43. }
  44. spv_validator_options spvValidatorOptionsCreate(void) {
  45. return new spv_validator_options_t;
  46. }
  47. void spvValidatorOptionsDestroy(spv_validator_options options) {
  48. delete options;
  49. }
  50. void spvValidatorOptionsSetUniversalLimit(spv_validator_options options,
  51. spv_validator_limit limit_type,
  52. uint32_t limit) {
  53. assert(options && "Validator options object may not be Null");
  54. switch (limit_type) {
  55. #define LIMIT(TYPE, FIELD) \
  56. case TYPE: \
  57. options->universal_limits_.FIELD = limit; \
  58. break;
  59. LIMIT(spv_validator_limit_max_struct_members, max_struct_members)
  60. LIMIT(spv_validator_limit_max_struct_depth, max_struct_depth)
  61. LIMIT(spv_validator_limit_max_local_variables, max_local_variables)
  62. LIMIT(spv_validator_limit_max_global_variables, max_global_variables)
  63. LIMIT(spv_validator_limit_max_switch_branches, max_switch_branches)
  64. LIMIT(spv_validator_limit_max_function_args, max_function_args)
  65. LIMIT(spv_validator_limit_max_control_flow_nesting_depth,
  66. max_control_flow_nesting_depth)
  67. LIMIT(spv_validator_limit_max_access_chain_indexes,
  68. max_access_chain_indexes)
  69. #undef LIMIT
  70. }
  71. }
  72. void spvValidatorOptionsSetRelaxStoreStruct(spv_validator_options options,
  73. bool val) {
  74. options->relax_struct_store = val;
  75. }
  76. void spvValidatorOptionsSetRelaxLogicalPointer(spv_validator_options options,
  77. bool val) {
  78. options->relax_logical_pointer = val;
  79. }
  80. void spvValidatorOptionsSetRelaxBlockLayout(spv_validator_options options,
  81. bool val) {
  82. options->relax_block_layout = val;
  83. }
  84. void spvValidatorOptionsSetSkipBlockLayout(spv_validator_options options,
  85. bool val) {
  86. options->skip_block_layout = val;
  87. }