mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-04-29 22:50:53 +03:00
Implement _d_arraycatnTX and remove _d_arraycatnT.
With this commit, the first simple applications can be linked and run!
This commit is contained in:
parent
51b9822916
commit
9ef4c8f421
3 changed files with 34 additions and 16 deletions
|
@ -757,23 +757,43 @@ DSliceValue* DtoCatArrays(Loc& loc, Type* arrayType, Expression* exp1, Expressio
|
||||||
|
|
||||||
if (exp1->op == TOKcat)
|
if (exp1->op == TOKcat)
|
||||||
{ // handle multiple concat
|
{ // handle multiple concat
|
||||||
fn = LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_arraycatnT");
|
fn = LLVM_D_GetRuntimeFunction(loc, gIR->module, "_d_arraycatnTX");
|
||||||
|
|
||||||
args.push_back(DtoSlicePtr(toElem(exp2)));
|
// Create array of slices
|
||||||
|
std::vector<LLValue*> arrs;
|
||||||
|
arrs.push_back(DtoSlicePtr(toElem(exp2)));
|
||||||
CatExp *ce = static_cast<CatExp*>(exp1);
|
CatExp *ce = static_cast<CatExp*>(exp1);
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
args.push_back(DtoSlicePtr(toElem(ce->e2)));
|
arrs.push_back(DtoSlicePtr(toElem(ce->e2)));
|
||||||
ce = static_cast<CatExp *>(ce->e1);
|
ce = static_cast<CatExp *>(ce->e1);
|
||||||
|
|
||||||
} while (ce->op == TOKcat);
|
} while (ce->op == TOKcat);
|
||||||
args.push_back(DtoSlicePtr(toElem(ce)));
|
arrs.push_back(DtoSlicePtr(toElem(ce)));
|
||||||
// uint n
|
|
||||||
args.push_back(DtoConstUint(args.size()));
|
// Create static array from slices
|
||||||
|
LLPointerType* ptrarraytype = isaPointer(arrs[0]->getType());
|
||||||
|
assert(ptrarraytype && "Expected pointer type");
|
||||||
|
LLStructType* arraytype = isaStruct(ptrarraytype->getElementType());
|
||||||
|
assert(arraytype && "Expected struct type");
|
||||||
|
LLArrayType* type = LLArrayType::get(arraytype, arrs.size());
|
||||||
|
LLValue* array = DtoRawAlloca(type, 0, ".slicearray");
|
||||||
|
unsigned int i = 0;
|
||||||
|
for (std::vector<LLValue*>::iterator I = arrs.begin(), E = arrs.end(); I != E; ++I)
|
||||||
|
{
|
||||||
|
DtoStore(DtoLoad(*I), DtoGEPi(array, 0, i++, ".slice"));
|
||||||
|
}
|
||||||
|
|
||||||
|
LLStructType* type2 = DtoArrayType(arraytype);
|
||||||
|
LLValue* array2 = DtoRawAlloca(type2, 0, ".array");
|
||||||
|
DtoStore(DtoConstSize_t(arrs.size()), DtoGEPi(array2, 0, 0, ".len"));
|
||||||
|
DtoStore(DtoBitCast(array, ptrarraytype), DtoGEPi(array2, 0, 1, ".ptr"));
|
||||||
|
//LLValue* val = DtoLoad(array2);
|
||||||
|
LLValue* val = DtoBitCast(DtoLoad(array2), DtoArrayType(DtoArrayType(LLType::getInt8Ty(gIR->context()))));
|
||||||
|
|
||||||
// TypeInfo ti
|
// TypeInfo ti
|
||||||
args.push_back(DtoTypeInfoOf(arrayType));
|
args.push_back(DtoTypeInfoOf(arrayType));
|
||||||
|
// byte[][] arrs
|
||||||
std::reverse(args.begin(), args.end());
|
args.push_back(val);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -136,9 +136,7 @@ void DtoDeleteArray(Loc& loc, DValue* arr)
|
||||||
llvm::AllocaInst* DtoAlloca(Type* type, const char* name)
|
llvm::AllocaInst* DtoAlloca(Type* type, const char* name)
|
||||||
{
|
{
|
||||||
LLType* lltype = i1ToI8(DtoType(type));
|
LLType* lltype = i1ToI8(DtoType(type));
|
||||||
llvm::AllocaInst* ai = new llvm::AllocaInst(lltype, name, gIR->topallocapoint());
|
return DtoRawAlloca(lltype, type->alignsize(), name);
|
||||||
ai->setAlignment(type->alignsize());
|
|
||||||
return ai;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::AllocaInst* DtoArrayAlloca(Type* type, unsigned arraysize, const char* name)
|
llvm::AllocaInst* DtoArrayAlloca(Type* type, unsigned arraysize, const char* name)
|
||||||
|
|
|
@ -75,7 +75,7 @@ static void checkForImplicitGCCall(const Loc &loc, const char *name)
|
||||||
"_d_arrayappendcd",
|
"_d_arrayappendcd",
|
||||||
"_d_arrayappendwd",
|
"_d_arrayappendwd",
|
||||||
"_d_arraycatT",
|
"_d_arraycatT",
|
||||||
"_d_arraycatnT",
|
"_d_arraycatnTX",
|
||||||
"_d_arraysetlengthT",
|
"_d_arraysetlengthT",
|
||||||
"_d_arraysetlengthiT",
|
"_d_arraysetlengthiT",
|
||||||
"_d_assocarrayliteralTX",
|
"_d_assocarrayliteralTX",
|
||||||
|
@ -483,10 +483,10 @@ static void LLVM_D_BuildRuntimeModule()
|
||||||
LLFunctionType* fty = llvm::FunctionType::get(voidArrayTy, types, false);
|
LLFunctionType* fty = llvm::FunctionType::get(voidArrayTy, types, false);
|
||||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||||
}
|
}
|
||||||
// byte[] _d_arraycatnT(TypeInfo ti, uint n, ...)
|
// void[] _d_arraycatnTX(const TypeInfo ti, byte[][] arrs)
|
||||||
{
|
{
|
||||||
llvm::StringRef fname("_d_arraycatnT");
|
llvm::StringRef fname("_d_arraycatnTX");
|
||||||
LLType *types[] = { typeInfoTy };
|
LLType *types[] = { typeInfoTy, rt_array(voidArrayTy) };
|
||||||
LLFunctionType* fty = llvm::FunctionType::get(voidArrayTy, types, true);
|
LLFunctionType* fty = llvm::FunctionType::get(voidArrayTy, types, true);
|
||||||
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue