Fix init codegen; add "tp_new" slot

pull/335/head
A. R. Shajii 2023-02-12 18:05:50 -05:00
parent 727f251837
commit c8a24e0838
1 changed files with 9 additions and 6 deletions

View File

@ -925,6 +925,9 @@ void LLVMVisitor::writeToPythonExtension(const PyModule &pymod,
}
B->CreateRet(pythonObject);
auto *pyNew = llvm::cast<llvm::Function>(
M->getOrInsertFunction("PyType_GenericNew", ptr, ptr, ptr, ptr).getCallee());
std::vector<llvm::Constant *> typeSlots = {
llvm::ConstantStruct::get(
pyVarObjectType,
@ -966,7 +969,7 @@ void LLVMVisitor::writeToPythonExtension(const PyModule &pymod,
zero64, // tp_dictoffset
pyFunc(pytype.init), // tp_init
alloc, // tp_alloc
null, // tp_new
pyNew, // tp_new
free, // tp_free
null, // tp_is_gc
null, // tp_bases
@ -1017,6 +1020,11 @@ void LLVMVisitor::writeToPythonExtension(const PyModule &pymod,
auto *block = llvm::BasicBlock::Create(*context, "entry", pyModuleInit);
B->SetInsertPoint(block);
if (auto *main = M->getFunction("main")) {
main->setName(".main");
B->CreateCall({main->getFunctionType(), main}, {zero32, null});
}
auto *refModFuncType = llvm::FunctionType::get(B->getVoidTy(), {ptr},
/*isVarArg=*/false);
@ -1038,11 +1046,6 @@ void LLVMVisitor::writeToPythonExtension(const PyModule &pymod,
pyDecRef = B->CreateLoad(B->getInt8PtrTy(), pyDecRef);
}
if (auto *main = M->getFunction("main")) {
main->setName(".main");
B->CreateCall({main->getFunctionType(), main}, {zero32, null});
}
// Set base types
for (auto &pytype : pymod.types) {
if (pytype.base) {