CodeGenCWrappers.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //===- llvm/Target/CodeGenCWrappers.h - CodeGen C Wrappers ------*- C++ -*-===//
  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 defines C bindings wrappers for enums in llvm/Support/CodeGen.h
  10. // that need them. The wrappers are separated to avoid adding an indirect
  11. // dependency on llvm/Config/Targets.def to CodeGen.h.
  12. //
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_TARGET_CODEGENCWRAPPERS_H
  15. #define LLVM_TARGET_CODEGENCWRAPPERS_H
  16. #include "llvm-c/TargetMachine.h"
  17. #include "llvm/ADT/Optional.h"
  18. #include "llvm/Support/CodeGen.h"
  19. #include "llvm/Support/ErrorHandling.h"
  20. namespace llvm {
  21. inline Optional<CodeModel::Model> unwrap(LLVMCodeModel Model, bool &JIT) {
  22. JIT = false;
  23. switch (Model) {
  24. case LLVMCodeModelJITDefault:
  25. JIT = true;
  26. LLVM_FALLTHROUGH;
  27. case LLVMCodeModelDefault:
  28. return None;
  29. case LLVMCodeModelTiny:
  30. return CodeModel::Tiny;
  31. case LLVMCodeModelSmall:
  32. return CodeModel::Small;
  33. case LLVMCodeModelKernel:
  34. return CodeModel::Kernel;
  35. case LLVMCodeModelMedium:
  36. return CodeModel::Medium;
  37. case LLVMCodeModelLarge:
  38. return CodeModel::Large;
  39. }
  40. return CodeModel::Small;
  41. }
  42. inline LLVMCodeModel wrap(CodeModel::Model Model) {
  43. switch (Model) {
  44. case CodeModel::Tiny:
  45. return LLVMCodeModelTiny;
  46. case CodeModel::Small:
  47. return LLVMCodeModelSmall;
  48. case CodeModel::Kernel:
  49. return LLVMCodeModelKernel;
  50. case CodeModel::Medium:
  51. return LLVMCodeModelMedium;
  52. case CodeModel::Large:
  53. return LLVMCodeModelLarge;
  54. }
  55. llvm_unreachable("Bad CodeModel!");
  56. }
  57. } // namespace llvm
  58. #endif