From 049aac1b80143753b4b3449e529024bafe2250be Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 12 Jul 2022 22:45:05 -0700 Subject: Support `class` types. (#2321) * Support `class` types. * Ignore class-keyword test * Fix codereview comments and warnings. Co-authored-by: Yong He --- source/slang/slang-ir.cpp | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 081b9103f..ca6435d8e 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -3560,6 +3560,16 @@ namespace Slang return structType; } + IRClassType* IRBuilder::createClassType() + { + IRClassType* classType = createInst( + this, + kIROp_ClassType, + getTypeKind()); + addGlobalValue(this, classType); + return classType; + } + IRInterfaceType* IRBuilder::createInterfaceType(UInt operandCount, IRInst* const* operands) { IRInterfaceType* interfaceType = createInst( @@ -3585,7 +3595,7 @@ namespace Slang // Create a field nested in a struct type, declaring that // the specified field key maps to a field with the specified type. IRStructField* IRBuilder::createStructField( - IRStructType* structType, + IRType* aggType, IRStructKey* fieldKey, IRType* fieldType) { @@ -3599,9 +3609,9 @@ namespace Slang 2, operands); - if (structType) + if (aggType) { - field->insertAtEnd(structType); + field->insertAtEnd(aggType); } return field; @@ -3696,6 +3706,11 @@ namespace Slang return param; } + IRInst* IRBuilder::emitAllocObj(IRType* type) + { + return emitIntrinsicInst(type, kIROp_AllocObj, 0, nullptr); + } + IRVar* IRBuilder::emitVar( IRType* type) { @@ -5527,6 +5542,7 @@ namespace Slang switch (op) { case kIROp_StructType: + case kIROp_ClassType: case kIROp_InterfaceType: case kIROp_Generic: case kIROp_Param: @@ -6081,6 +6097,7 @@ namespace Slang case kIROp_ExtractExistentialWitnessTable: case kIROp_WrapExistential: case kIROp_BitCast: + case kIROp_AllocObj: return false; } } @@ -6313,16 +6330,6 @@ namespace Slang irValue->getDataType())); } - bool isPointerOfType(IRInst* ptrType, IRInst* elementType) - { - return ptrType && ptrType->getOp() == kIROp_PtrType && ptrType->getOperand(0) == elementType; - } - - bool isPointerOfType(IRInst* ptrType, IROp opCode) - { - return ptrType && ptrType->getOp() == kIROp_PtrType && ptrType->getOperand(0) && - ptrType->getOperand(0)->getOp() == opCode; - } bool isBuiltin(IRInst* inst) { return inst->findDecoration() != nullptr; -- cgit v1.2.3