You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now the functions createNewCall, createFreeCall in src\codegen\llvm\LLVMIRBuilder.cpp has hard coded references to malloc, free, abort and exit. This can be made more flexible by utilizing the linker support for weak symbols.
I replaced malloc with OberonRuntime_Allocate:
Value *
LLVMIRBuilder::createNewCall(TypeNode *type, llvm::Value *param) {
auto fun = module_->getFunction("OberonRuntime_Allocate");
if (!fun) {
auto funTy = FunctionType::get(builder_.getPtrTy(), { builder_.getInt64Ty() }, false);
fun = Function::Create(funTy, GlobalValue::ExternalLinkage, "OberonRuntime_Allocate", module_);
fun->addFnAttr(Attribute::getWithAllocSizeArgs(builder_.getContext(), 0, {}));
fun->addParamAttr(0, Attribute::NoUndef);
}
...
and free with OberonRuntime_Deallocate:
Value *
LLVMIRBuilder::createFreeCall([[maybe_unused]] TypeNode *type, Value *param) {
auto fun = module_->getFunction("OberonRuntime_Deallocate");
#ifdef _LLVM_LEGACY
auto voidTy = PointerType::get(builder_.getVoidTy(), 0);
#elseauto voidTy = builder_.getPtrTy();
#endifif (!fun) {
auto funTy = FunctionType::get(builder_.getVoidTy(), {voidTy}, false);
fun = Function::Create(funTy, GlobalValue::ExternalLinkage, "OberonRuntime_Deallocate", module_);
fun->addParamAttr(0, Attribute::NoUndef);
}
...
Then creates a default implementation OberonRuntimeDefault.c:
By linking this as a static library, these definitions take precedence over the weak version.
(This could also be done with an Oberon module.)
In order for this to work as expected with the JIT implementation, default functions need to be injected.
Perhaps default functions can just be defined in the main module.
Also this can be expanded to cover putchar etc., so that the Out module can be redirected.
This discussion was converted from issue #46 on May 02, 2024 05:11.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Right now the functions
createNewCall,createFreeCallinsrc\codegen\llvm\LLVMIRBuilder.cpphas hard coded references tomalloc,free,abortandexit. This can be made more flexible by utilizing the linker support for weak symbols.I replaced
mallocwithOberonRuntime_Allocate:and
freewithOberonRuntime_Deallocate:Then creates a default implementation OberonRuntimeDefault.c:
Functions here are decorated with the weak attribute.
This is then just compiled to a static library and works as expected when linked.
This can then exploited to replace the functionality with for example a Garbage Collector (Boehm):
By linking this as a static library, these definitions take precedence over the weak version.
(This could also be done with an Oberon module.)
In order for this to work as expected with the JIT implementation, default functions need to be injected.
Perhaps default functions can just be defined in the
mainmodule.Also this can be expanded to cover
putcharetc., so that theOutmodule can be redirected.Beta Was this translation helpful? Give feedback.
All reactions