CodeGenCWrappers.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/Target/CodeGenCWrappers.h - CodeGen C Wrappers ------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines C bindings wrappers for enums in llvm/Support/CodeGen.h
  15. // that need them. The wrappers are separated to avoid adding an indirect
  16. // dependency on llvm/Config/Targets.def to CodeGen.h.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_TARGET_CODEGENCWRAPPERS_H
  20. #define LLVM_TARGET_CODEGENCWRAPPERS_H
  21. #include "llvm-c/TargetMachine.h"
  22. #include "llvm/Support/CodeGen.h"
  23. #include "llvm/Support/ErrorHandling.h"
  24. #include <optional>
  25. namespace llvm {
  26. inline std::optional<CodeModel::Model> unwrap(LLVMCodeModel Model, bool &JIT) {
  27. JIT = false;
  28. switch (Model) {
  29. case LLVMCodeModelJITDefault:
  30. JIT = true;
  31. [[fallthrough]];
  32. case LLVMCodeModelDefault:
  33. return std::nullopt;
  34. case LLVMCodeModelTiny:
  35. return CodeModel::Tiny;
  36. case LLVMCodeModelSmall:
  37. return CodeModel::Small;
  38. case LLVMCodeModelKernel:
  39. return CodeModel::Kernel;
  40. case LLVMCodeModelMedium:
  41. return CodeModel::Medium;
  42. case LLVMCodeModelLarge:
  43. return CodeModel::Large;
  44. }
  45. return CodeModel::Small;
  46. }
  47. inline LLVMCodeModel wrap(CodeModel::Model Model) {
  48. switch (Model) {
  49. case CodeModel::Tiny:
  50. return LLVMCodeModelTiny;
  51. case CodeModel::Small:
  52. return LLVMCodeModelSmall;
  53. case CodeModel::Kernel:
  54. return LLVMCodeModelKernel;
  55. case CodeModel::Medium:
  56. return LLVMCodeModelMedium;
  57. case CodeModel::Large:
  58. return LLVMCodeModelLarge;
  59. }
  60. llvm_unreachable("Bad CodeModel!");
  61. }
  62. } // namespace llvm
  63. #endif
  64. #ifdef __GNUC__
  65. #pragma GCC diagnostic pop
  66. #endif