GCStrategy.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. //===- GCStrategy.cpp - Garbage Collector Description ---------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file implements the policy object GCStrategy which describes the
  10. // behavior of a given garbage collector.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/IR/GCStrategy.h"
  14. using namespace llvm;
  15. LLVM_INSTANTIATE_REGISTRY(GCRegistry)
  16. GCStrategy::GCStrategy() = default;
  17. std::unique_ptr<GCStrategy> llvm::getGCStrategy(const StringRef Name) {
  18. for (auto &S : GCRegistry::entries())
  19. if (S.getName() == Name)
  20. return S.instantiate();
  21. if (GCRegistry::begin() == GCRegistry::end()) {
  22. // In normal operation, the registry should not be empty. There should
  23. // be the builtin GCs if nothing else. The most likely scenario here is
  24. // that we got here without running the initializers used by the Registry
  25. // itself and it's registration mechanism.
  26. const std::string error =
  27. std::string("unsupported GC: ") + Name.str() +
  28. " (did you remember to link and initialize the library?)";
  29. report_fatal_error(error);
  30. } else
  31. report_fatal_error(std::string("unsupported GC: ") + Name.str());
  32. }