thunk.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_THUNK_H_
  5. #define CARBON_TOOLCHAIN_CHECK_THUNK_H_
  6. #include "toolchain/check/context.h"
  7. #include "toolchain/check/deferred_definition_worklist.h"
  8. #include "toolchain/sem_ir/ids.h"
  9. namespace Carbon::Check {
  10. // Given a function signature and a callee function, build a thunk that matches
  11. // the given signature and calls the specified callee. Returns the callee
  12. // unchanged if it can be used directly.
  13. auto BuildThunk(Context& context, SemIR::FunctionId signature_id,
  14. SemIR::SpecificId signature_specific_id,
  15. SemIR::InstId callee_id, bool defer_definition)
  16. -> SemIR::InstId;
  17. // Builds a call to a function that forwards a call argument list built for
  18. // `function_id` to a call to `callee_id`, for use when building a call from a
  19. // thunk to its target. This is like `PerformCall`, except that it takes a list
  20. // of call arguments for `function_id`, not a syntactic argument list.
  21. auto PerformThunkCall(Context& context, SemIR::LocId loc_id,
  22. SemIR::FunctionId function_id,
  23. llvm::ArrayRef<SemIR::InstId> param_pattern_ids,
  24. llvm::ArrayRef<SemIR::InstId> call_arg_ids,
  25. SemIR::InstId callee_id) -> SemIR::InstId;
  26. // Builds the definition for a thunk whose definition was deferred until the end
  27. // of the enclosing scope.
  28. auto BuildThunkDefinition(Context& context,
  29. DeferredDefinitionWorklist::DefineThunk&& task)
  30. -> void;
  31. // Given a declaration of a thunk and the function that it should call,
  32. // build a thunk body for calling a Carbon function from a C++
  33. // function. If the callee has a return value, the thunk returns it
  34. // through an explicit output parameter at the end of the parameter
  35. // list.
  36. auto BuildThunkDefinitionForExport(Context& context,
  37. SemIR::FunctionId thunk_function_id,
  38. SemIR::FunctionId callee_function_id,
  39. SemIR::InstId thunk_id,
  40. SemIR::InstId callee_id) -> void;
  41. } // namespace Carbon::Check
  42. #endif // CARBON_TOOLCHAIN_CHECK_THUNK_H_