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_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> call_arg_ids,
  24. SemIR::InstId callee_id) -> SemIR::InstId;
  25. // Builds the definition for a thunk whose definition was deferred until the end
  26. // of the enclosing scope.
  27. auto BuildThunkDefinition(Context& context,
  28. DeferredDefinitionWorklist::DefineThunk&& task)
  29. -> void;
  30. } // namespace Carbon::Check
  31. #endif // CARBON_TOOLCHAIN_CHECK_THUNK_H_