thunk.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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 that use any type
  11. // except void, pointer types and signed 32-bit and 64-bit integers.
  12. auto IsCppThunkRequired(Context& context, const SemIR::Function& function)
  13. -> bool;
  14. // Given a function signature and a callee function, builds a C++ thunk with
  15. // simple ABI (pointers, i32 and i64 types) that calls the specified callee.
  16. // Assumes `IsCppThunkRequired()` return true for `callee_function`. Returns
  17. // `nullptr` on failure.
  18. auto BuildCppThunk(Context& context, const SemIR::Function& callee_function)
  19. -> clang::FunctionDecl*;
  20. // Builds a call to a thunk function that forwards a call argument list built
  21. // for `callee_function_id` to a call to `thunk_callee_id`, for use when
  22. // building a call from a C++ thunk to its target. This is like `PerformCall`,
  23. // except that it takes a list of call arguments for `callee_function_id`, not a
  24. // syntactic argument list.
  25. auto PerformCppThunkCall(Context& context, SemIR::LocId loc_id,
  26. SemIR::FunctionId callee_function_id,
  27. llvm::ArrayRef<SemIR::InstId> callee_arg_ids,
  28. SemIR::InstId thunk_callee_id) -> SemIR::InstId;
  29. } // namespace Carbon::Check
  30. #endif // CARBON_TOOLCHAIN_CHECK_CPP_THUNK_H_