mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 21:40:12 +01:00
This helps us move away from the clone-with-modifications approach to thunking, which gets unwieldy as signatures get more complex. --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
60 lines
2.8 KiB
C++
60 lines
2.8 KiB
C++
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
#ifndef CARBON_TOOLCHAIN_CHECK_THUNK_H_
|
|
#define CARBON_TOOLCHAIN_CHECK_THUNK_H_
|
|
|
|
#include "toolchain/check/context.h"
|
|
#include "toolchain/check/deferred_definition_worklist.h"
|
|
#include "toolchain/sem_ir/ids.h"
|
|
|
|
namespace Carbon::Check {
|
|
|
|
// Given a function signature and a callee function, build a thunk that matches
|
|
// the given signature and calls the specified callee. If
|
|
// `override_self_type_id` is not `None`, this thunk wraps a virtual function
|
|
// override declared in the given type. Returns the callee unchanged if it can
|
|
// be used directly.
|
|
auto BuildThunk(Context& context, SemIR::FunctionId signature_id,
|
|
SemIR::SpecificId signature_specific_id,
|
|
SemIR::TypeId override_self_type_id, SemIR::InstId callee_id,
|
|
bool defer_definition) -> SemIR::InstId;
|
|
|
|
// Builds a call to a function that forwards a call argument list `call_arg_ids`
|
|
// built for `function_id` to a call to `callee_id`, for use when building a
|
|
// call from a thunk to its target. `param_pattern_ids` contains the parameter
|
|
// patterns of `function_id`. If `override_self_type_id` is not `None`,
|
|
// `callee_id` refers to a virtual function override declared in the given type.
|
|
auto PerformThunkCall(Context& context, SemIR::LocId loc_id,
|
|
SemIR::FunctionId function_id,
|
|
llvm::ArrayRef<SemIR::InstId> param_pattern_ids,
|
|
llvm::ArrayRef<SemIR::InstId> call_arg_ids,
|
|
SemIR::InstId callee_id,
|
|
SemIR::TypeId override_self_type_id) -> SemIR::InstId;
|
|
|
|
// Builds the definition for a thunk whose definition was deferred until the end
|
|
// of the enclosing scope.
|
|
auto BuildThunkDefinition(Context& context,
|
|
DeferredDefinitionWorklist::DefineThunk&& task)
|
|
-> void;
|
|
|
|
// Given a declaration of a thunk and the function that it should call,
|
|
// build a thunk body for calling a Carbon function from a C++
|
|
// function. If the callee has a return value, the thunk returns it
|
|
// through an explicit output parameter at the end of the parameter
|
|
// list.
|
|
auto BuildThunkDefinitionForExport(Context& context,
|
|
SemIR::FunctionId thunk_function_id,
|
|
SemIR::FunctionId callee_function_id,
|
|
SemIR::InstId thunk_id,
|
|
SemIR::InstId callee_id) -> void;
|
|
|
|
// Build a function that destroys an object of the given class.
|
|
auto BuildDestroyThunk(Context& context, SemIR::LocId loc_id,
|
|
const SemIR::Class& class_info) -> SemIR::FunctionId;
|
|
|
|
} // namespace Carbon::Check
|
|
|
|
#endif // CARBON_TOOLCHAIN_CHECK_THUNK_H_
|