mirror of https://github.com/exaloop/codon.git
Add type alloc function
parent
d9ca0c2cbf
commit
634878e6f1
|
@ -875,23 +875,6 @@ void LLVMVisitor::writeToPythonExtension(const PyModule &pymod,
|
||||||
? llvm::ConstantStruct::get(pySequenceMethodsType, sequenceSlots)
|
? llvm::ConstantStruct::get(pySequenceMethodsType, sequenceSlots)
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
auto *nameVar = new llvm::GlobalVariable(
|
|
||||||
*M, llvm::ArrayType::get(B->getInt8Ty(), pytype.name.length() + 1),
|
|
||||||
/*isConstant=*/true, llvm::GlobalValue::PrivateLinkage,
|
|
||||||
llvm::ConstantDataArray::getString(*context, pytype.name), ".pyext_type_name");
|
|
||||||
nameVar->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
|
|
||||||
|
|
||||||
auto *docsConst = null;
|
|
||||||
if (pytype.doc.empty()) {
|
|
||||||
auto *docsVar = new llvm::GlobalVariable(
|
|
||||||
*M, llvm::ArrayType::get(B->getInt8Ty(), pytype.doc.length() + 1),
|
|
||||||
/*isConstant=*/true, llvm::GlobalValue::PrivateLinkage,
|
|
||||||
llvm::ConstantDataArray::getString(*context, pytype.doc),
|
|
||||||
".pyext_type_docstring");
|
|
||||||
docsVar->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
|
|
||||||
docsConst = llvm::ConstantExpr::getBitCast(docsVar, ptr);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto *refType = cast<types::RefType>(pytype.type);
|
auto *refType = cast<types::RefType>(pytype.type);
|
||||||
auto *llvmType = getLLVMType(pytype.type);
|
auto *llvmType = getLLVMType(pytype.type);
|
||||||
auto *objectType = llvm::StructType::get(pyObjectType, llvmType);
|
auto *objectType = llvm::StructType::get(pyObjectType, llvmType);
|
||||||
|
@ -900,17 +883,23 @@ void LLVMVisitor::writeToPythonExtension(const PyModule &pymod,
|
||||||
? M->getDataLayout().getTypeAllocSize(getLLVMType(refType->getContents()))
|
? M->getDataLayout().getTypeAllocSize(getLLVMType(refType->getContents()))
|
||||||
: 0;
|
: 0;
|
||||||
auto pySize = M->getDataLayout().getTypeAllocSize(objectType);
|
auto pySize = M->getDataLayout().getTypeAllocSize(objectType);
|
||||||
|
|
||||||
auto *alloc = llvm::cast<llvm::Function>(
|
auto *alloc = llvm::cast<llvm::Function>(
|
||||||
M->getOrInsertFunction(pytype.name + ".py_alloc", ptr, ptr, i64).getCallee());
|
M->getOrInsertFunction(pytype.name + ".py_alloc", ptr, ptr, i64).getCallee());
|
||||||
/*
|
auto *entry = llvm::BasicBlock::Create(*context, "entry", alloc);
|
||||||
{
|
B->SetInsertPoint(entry);
|
||||||
auto *entry = llvm::BasicBlock::Create(*context, "entry", alloc);
|
auto *pythonObject = B->CreateCall(allocUncollectable, B->getInt64(pySize));
|
||||||
B->SetInsertPoint(entry);
|
auto *header = B->CreateInsertValue(
|
||||||
|
llvm::ConstantStruct::get(pyObjectType, B->getInt64(1), null),
|
||||||
auto *memory = B->CreateCall(allocUncollectable, pySize);
|
alloc->arg_begin(), 1);
|
||||||
// TODO
|
B->CreateStore(header, pythonObject);
|
||||||
|
if (refType) {
|
||||||
|
auto *codonObject = B->CreateCall(
|
||||||
|
makeAllocFunc(refType->getContents()->isAtomic()), B->getInt64(codonSize));
|
||||||
|
B->CreateStore(codonObject,
|
||||||
|
B->CreateConstInBoundsGEP2_32(objectType, pythonObject, 0, 1));
|
||||||
}
|
}
|
||||||
*/
|
B->CreateRet(pythonObject);
|
||||||
|
|
||||||
std::vector<llvm::Constant *> typeSlots = {
|
std::vector<llvm::Constant *> typeSlots = {
|
||||||
llvm::ConstantStruct::get(
|
llvm::ConstantStruct::get(
|
||||||
|
@ -920,7 +909,7 @@ void LLVMVisitor::writeToPythonExtension(const PyModule &pymod,
|
||||||
pyString(pytype.name), // const char *tp_name;
|
pyString(pytype.name), // const char *tp_name;
|
||||||
B->getInt64(pySize), // Py_ssize_t tp_basicsize;
|
B->getInt64(pySize), // Py_ssize_t tp_basicsize;
|
||||||
zero64, // Py_ssize_t tp_itemsize;
|
zero64, // Py_ssize_t tp_itemsize;
|
||||||
// destructor tp_dealloc;
|
free,
|
||||||
zero64, // Py_ssize_t tp_vectorcall_offset;
|
zero64, // Py_ssize_t tp_vectorcall_offset;
|
||||||
null, // getattrfunc tp_getattr;
|
null, // getattrfunc tp_getattr;
|
||||||
null, // setattrfunc tp_setattr;
|
null, // setattrfunc tp_setattr;
|
||||||
|
@ -936,7 +925,7 @@ void LLVMVisitor::writeToPythonExtension(const PyModule &pymod,
|
||||||
null, // setattrofunc tp_setattro;
|
null, // setattrofunc tp_setattro;
|
||||||
null, // PyBufferProcs *tp_as_buffer;
|
null, // PyBufferProcs *tp_as_buffer;
|
||||||
zero64, // unsigned long tp_flags;
|
zero64, // unsigned long tp_flags;
|
||||||
docsConst, // const char *tp_doc;
|
pyString(pytype.doc), // const char *tp_doc;
|
||||||
null, // traverseproc tp_traverse;
|
null, // traverseproc tp_traverse;
|
||||||
null, // inquiry tp_clear;
|
null, // inquiry tp_clear;
|
||||||
pyFunc(pytype.cmp), // richcmpfunc tp_richcompare;
|
pyFunc(pytype.cmp), // richcmpfunc tp_richcompare;
|
||||||
|
@ -968,7 +957,11 @@ void LLVMVisitor::writeToPythonExtension(const PyModule &pymod,
|
||||||
B->getInt8(0), // char tp_watched;
|
B->getInt8(0), // char tp_watched;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO
|
auto *pyTypeObjectVar = new llvm::GlobalVariable(
|
||||||
|
*M, pyTypeObjectType,
|
||||||
|
/*isConstant=*/false, llvm::GlobalValue::PrivateLinkage,
|
||||||
|
llvm::ConstantStruct::get(pyTypeObjectType, typeSlots),
|
||||||
|
".pyext_type." + pytype.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set tp_base in module init func
|
// set tp_base in module init func
|
||||||
|
|
Loading…
Reference in New Issue