mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
IRGen: Add implementation for dynamically replaceable functions
A dynamically replaceable function calls through a global variable that
holds the function pointer.
struct ChainEntry {
void *(funPtr)();
struct ChainEntry *next;
}
ChainEntry dynamicallyReplaceableVar;
void dynamicallyReplaceableFunction() {
dynamicallyReplaceableVar.funPtr()
}
dynamic replacements will be chainable so the global variable also
functions as the root entry in the chain of replacements.
A dynamic replacement functions can call the previous implementation by
going through its chain entry.
ChainEntry chainEntryOf_dynamic_replacement_for_foo;
void dynamic_replacement_for_foo() {
// call the previous (original) implementation.
chainEntryOf_dynamic_replacement_for_foo.funPtr();
}
This commit is contained in:
@@ -458,6 +458,16 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
|
||||
IsSwiftErrorInRegister =
|
||||
clang::CodeGen::swiftcall::isSwiftErrorLoweredInRegister(
|
||||
ClangCodeGen->CGM());
|
||||
|
||||
DynamicReplacementLinkEntryTy =
|
||||
llvm::StructType::create(getLLVMContext(), "swift.dyn_repl_link_entry");
|
||||
DynamicReplacementLinkEntryPtrTy =
|
||||
DynamicReplacementLinkEntryTy->getPointerTo(DefaultAS);
|
||||
llvm::Type *linkEntryFields[] = {
|
||||
Int8PtrTy, // function pointer.
|
||||
DynamicReplacementLinkEntryPtrTy // next.
|
||||
};
|
||||
DynamicReplacementLinkEntryTy->setBody(linkEntryFields);
|
||||
}
|
||||
|
||||
IRGenModule::~IRGenModule() {
|
||||
|
||||
Reference in New Issue
Block a user