CodeGenABITypes.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //==--- CodeGenABITypes.cpp - Convert Clang types to LLVM types for ABI ----==//
  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. // CodeGenABITypes is a simple interface for getting LLVM types for
  10. // the parameters and the return value of a function given the Clang
  11. // types.
  12. //
  13. // The class is implemented as a public wrapper around the private
  14. // CodeGenTypes class in lib/CodeGen.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #include "clang/CodeGen/CodeGenABITypes.h"
  18. #include "CGRecordLayout.h"
  19. #include "CodeGenModule.h"
  20. #include "clang/CodeGen/CGFunctionInfo.h"
  21. #include "clang/Lex/HeaderSearchOptions.h"
  22. #include "clang/Lex/PreprocessorOptions.h"
  23. using namespace clang;
  24. using namespace CodeGen;
  25. const CGFunctionInfo &
  26. CodeGen::arrangeObjCMessageSendSignature(CodeGenModule &CGM,
  27. const ObjCMethodDecl *MD,
  28. QualType receiverType) {
  29. return CGM.getTypes().arrangeObjCMessageSendSignature(MD, receiverType);
  30. }
  31. const CGFunctionInfo &
  32. CodeGen::arrangeFreeFunctionType(CodeGenModule &CGM,
  33. CanQual<FunctionProtoType> Ty) {
  34. return CGM.getTypes().arrangeFreeFunctionType(Ty);
  35. }
  36. const CGFunctionInfo &
  37. CodeGen::arrangeFreeFunctionType(CodeGenModule &CGM,
  38. CanQual<FunctionNoProtoType> Ty) {
  39. return CGM.getTypes().arrangeFreeFunctionType(Ty);
  40. }
  41. const CGFunctionInfo &
  42. CodeGen::arrangeCXXMethodType(CodeGenModule &CGM,
  43. const CXXRecordDecl *RD,
  44. const FunctionProtoType *FTP,
  45. const CXXMethodDecl *MD) {
  46. return CGM.getTypes().arrangeCXXMethodType(RD, FTP, MD);
  47. }
  48. const CGFunctionInfo &
  49. CodeGen::arrangeFreeFunctionCall(CodeGenModule &CGM,
  50. CanQualType returnType,
  51. ArrayRef<CanQualType> argTypes,
  52. FunctionType::ExtInfo info,
  53. RequiredArgs args) {
  54. return CGM.getTypes().arrangeLLVMFunctionInfo(
  55. returnType, /*instanceMethod=*/false, /*chainCall=*/false, argTypes,
  56. info, {}, args);
  57. }
  58. llvm::FunctionType *
  59. CodeGen::convertFreeFunctionType(CodeGenModule &CGM, const FunctionDecl *FD) {
  60. assert(FD != nullptr && "Expected a non-null function declaration!");
  61. llvm::Type *T = CGM.getTypes().ConvertType(FD->getType());
  62. if (auto FT = dyn_cast<llvm::FunctionType>(T))
  63. return FT;
  64. return nullptr;
  65. }
  66. llvm::Type *
  67. CodeGen::convertTypeForMemory(CodeGenModule &CGM, QualType T) {
  68. return CGM.getTypes().ConvertTypeForMem(T);
  69. }
  70. unsigned CodeGen::getLLVMFieldNumber(CodeGenModule &CGM,
  71. const RecordDecl *RD,
  72. const FieldDecl *FD) {
  73. return CGM.getTypes().getCGRecordLayout(RD).getLLVMFieldNo(FD);
  74. }