linker.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright (c) 2017 Pierre Moreau
  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. #ifndef INCLUDE_SPIRV_TOOLS_LINKER_HPP_
  15. #define INCLUDE_SPIRV_TOOLS_LINKER_HPP_
  16. #include <cstdint>
  17. #include <memory>
  18. #include <vector>
  19. #include "libspirv.hpp"
  20. namespace spvtools {
  21. class SPIRV_TOOLS_EXPORT LinkerOptions {
  22. public:
  23. // Returns whether a library or an executable should be produced by the
  24. // linking phase.
  25. //
  26. // All exported symbols are kept when creating a library, whereas they will
  27. // be removed when creating an executable.
  28. // The returned value will be true if creating a library, and false if
  29. // creating an executable.
  30. bool GetCreateLibrary() const { return create_library_; }
  31. // Sets whether a library or an executable should be produced.
  32. void SetCreateLibrary(bool create_library) {
  33. create_library_ = create_library;
  34. }
  35. // Returns whether to verify the uniqueness of the unique ids in the merged
  36. // context.
  37. bool GetVerifyIds() const { return verify_ids_; }
  38. // Sets whether to verify the uniqueness of the unique ids in the merged
  39. // context.
  40. void SetVerifyIds(bool verify_ids) { verify_ids_ = verify_ids; }
  41. // Returns whether to allow for imported symbols to have no corresponding
  42. // exported symbols
  43. bool GetAllowPartialLinkage() const { return allow_partial_linkage_; }
  44. // Sets whether to allow for imported symbols to have no corresponding
  45. // exported symbols
  46. void SetAllowPartialLinkage(bool allow_partial_linkage) {
  47. allow_partial_linkage_ = allow_partial_linkage;
  48. }
  49. bool GetUseHighestVersion() const { return use_highest_version_; }
  50. void SetUseHighestVersion(bool use_highest_vers) {
  51. use_highest_version_ = use_highest_vers;
  52. }
  53. bool GetAllowPtrTypeMismatch() const { return allow_ptr_type_mismatch_; }
  54. void SetAllowPtrTypeMismatch(bool allow_ptr_type_mismatch) {
  55. allow_ptr_type_mismatch_ = allow_ptr_type_mismatch;
  56. }
  57. private:
  58. bool create_library_{false};
  59. bool verify_ids_{false};
  60. bool allow_partial_linkage_{false};
  61. bool use_highest_version_{false};
  62. bool allow_ptr_type_mismatch_{false};
  63. };
  64. // Links one or more SPIR-V modules into a new SPIR-V module. That is, combine
  65. // several SPIR-V modules into one, resolving link dependencies between them.
  66. //
  67. // At least one binary has to be provided in |binaries|. Those binaries do not
  68. // have to be valid, but they should be at least parseable.
  69. // The functions can fail due to the following:
  70. // * The given context was not initialised using `spvContextCreate()`;
  71. // * No input modules were given;
  72. // * One or more of those modules were not parseable;
  73. // * The input modules used different addressing or memory models;
  74. // * The ID or global variable number limit were exceeded;
  75. // * Some entry points were defined multiple times;
  76. // * Some imported symbols did not have an exported counterpart;
  77. // * Possibly other reasons.
  78. SPIRV_TOOLS_EXPORT spv_result_t
  79. Link(const Context& context, const std::vector<std::vector<uint32_t>>& binaries,
  80. std::vector<uint32_t>* linked_binary,
  81. const LinkerOptions& options = LinkerOptions());
  82. SPIRV_TOOLS_EXPORT spv_result_t
  83. Link(const Context& context, const uint32_t* const* binaries,
  84. const size_t* binary_sizes, size_t num_binaries,
  85. std::vector<uint32_t>* linked_binary,
  86. const LinkerOptions& options = LinkerOptions());
  87. } // namespace spvtools
  88. #endif // INCLUDE_SPIRV_TOOLS_LINKER_HPP_