1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Added RefType, changed how CRepr types are represented

This commit is contained in:
Brian Fiete 2020-07-02 11:05:17 -07:00
parent 716f7b3638
commit 0c946de3ca
13 changed files with 311 additions and 40 deletions

View file

@ -377,6 +377,31 @@ void BfIRCodeGen::PrintFunction()
os.flush();
}
void BfIRCodeGen::FixValues(llvm::StructType* structType, llvm::SmallVector<llvm::Value*, 8>& values)
{
if (values.size() >= structType->getNumElements())
return;
int readIdx = (int)values.size() - 1;
values.resize(structType->getNumElements());
for (int i = (int)values.size() - 1; i >= 0; i--)
{
if (values[readIdx]->getType() == structType->getElementType(i))
{
values[i] = values[readIdx];
readIdx--;
}
else if (structType->getElementType(i)->isArrayTy())
{
values[i] = llvm::ConstantAggregateZero::get(structType->getElementType(i));
}
else
{
BF_FATAL("Malformed structure values");
}
}
}
BfTypeCode BfIRCodeGen::GetTypeCode(llvm::Type* type, bool isSigned)
{
if (type->isIntegerTy())
@ -1267,8 +1292,9 @@ void BfIRCodeGen::HandleNextCmd()
CMD_PARAM(llvm::Type*, type);
CMD_PARAM(CmdParamVec<llvm::Value*>, values)
llvm::SmallVector<llvm::Constant*, 8> copyValues;
FixValues((llvm::StructType*)type, values);
for (auto val : values)
copyValues.push_back(llvm::dyn_cast<llvm::Constant>(val));
copyValues.push_back(llvm::dyn_cast<llvm::Constant>(val));
SetResult(curId, llvm::ConstantStruct::get((llvm::StructType*)type, copyValues));
}
break;