thunk.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_CHECK_CPP_THUNK_H_
  5. #define CARBON_TOOLCHAIN_CHECK_CPP_THUNK_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/sem_ir/ids.h"
  8. namespace Carbon::Check {
  9. // Returns whether the given C++ imported function requires a C++ thunk to be
  10. // used to call it. A C++ thunk is required for functions whose ABI uses any
  11. // type except void, pointer and reference types, and signed 32-bit and 64-bit
  12. // integers.
  13. auto IsCppThunkRequired(Context& context, const SemIR::Function& function)
  14. -> bool;
  15. // Given a function signature and a callee function, builds a C++ thunk with
  16. // simple ABI (pointers, i32 and i64 types) that calls the specified callee.
  17. // Assumes `IsCppThunkRequired()` return true for `callee_function`. Returns
  18. // `nullptr` on failure.
  19. auto BuildCppThunk(Context& context, const SemIR::Function& callee_function)
  20. -> clang::FunctionDecl*;
  21. // Builds a call to a thunk function that forwards a call argument list built
  22. // for `callee_function_id` to a call to `thunk_callee_id`, for use when
  23. // building a call from a C++ thunk to its target. This is like `PerformCall`,
  24. // except that it takes a list of call arguments for `callee_function_id`, not a
  25. // syntactic argument list.
  26. auto PerformCppThunkCall(Context& context, SemIR::LocId loc_id,
  27. SemIR::FunctionId callee_function_id,
  28. llvm::ArrayRef<SemIR::InstId> callee_arg_ids,
  29. SemIR::InstId thunk_callee_id) -> SemIR::InstId;
  30. } // namespace Carbon::Check
  31. #endif // CARBON_TOOLCHAIN_CHECK_CPP_THUNK_H_