diff options
| author | Yong He <yonghe@outlook.com> | 2024-02-08 18:29:32 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-08 18:29:32 -0800 |
| commit | f44da6cc5c0f211c13bd1eb0743d79c7861ea64e (patch) | |
| tree | 3ad4edb5e7806c41003280ebf60fd6419a742105 /source/slang/slang-ir.cpp | |
| parent | a16f712bb99e426519c9a556b17b54bcc4d1d22d (diff) | |
Support pointers in SPIRV. (#3561)
* Support pointers in SPIRV.
* Fix test.
* Enhance test.
* Fix test.
* Cleanup.
Diffstat (limited to 'source/slang/slang-ir.cpp')
| -rw-r--r-- | source/slang/slang-ir.cpp | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 94de28089..035b2aade 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -17,7 +17,14 @@ namespace Slang SourceLoc const& getDiagnosticPos(IRInst* inst) { - return inst->sourceLoc; + while (inst) + { + if (inst->sourceLoc.isValid()) + return inst->sourceLoc; + inst = inst->parent; + } + static SourceLoc invalid = SourceLoc(); + return invalid; } void printDiagnosticArg(StringBuilder& sb, IRInst* irObject) @@ -4900,7 +4907,7 @@ namespace Slang IRType* type = nullptr; auto basePtrType = as<IRPtrTypeBase>(basePtr->getDataType()); auto valueType = unwrapAttributedType(basePtrType->getValueType()); - if (auto arrayType = as<IRArrayType>(valueType)) + if (auto arrayType = as<IRArrayTypeBase>(valueType)) { type = arrayType->getElementType(); } @@ -5507,6 +5514,28 @@ namespace Slang return inst; } + IRInst* IRBuilder::emitCastPtrToInt(IRInst* val) + { + auto inst = createInst<IRInst>( + this, + kIROp_CastPtrToInt, + getUInt64Type(), + val); + addInst(inst); + return inst; + } + + IRInst* IRBuilder::emitCastIntToPtr(IRType* ptrType, IRInst* val) + { + auto inst = createInst<IRInst>( + this, + kIROp_CastIntToPtr, + ptrType, + val); + addInst(inst); + return inst; + } + IRGlobalConstant* IRBuilder::emitGlobalConstant( IRType* type) { @@ -7873,6 +7902,7 @@ namespace Slang case kIROp_FieldAddress: case kIROp_GetElement: case kIROp_GetElementPtr: + case kIROp_GetOffsetPtr: case kIROp_UpdateElement: case kIROp_MeshOutputRef: case kIROp_MakeVectorFromScalar: @@ -7910,6 +7940,7 @@ namespace Slang case kIROp_FloatCast: case kIROp_CastPtrToInt: case kIROp_CastIntToPtr: + case kIROp_PtrCast: case kIROp_AllocObj: case kIROp_PackAnyValue: case kIROp_UnpackAnyValue: @@ -8319,6 +8350,7 @@ namespace Slang case kIROp_FieldAddress: case kIROp_GetElement: case kIROp_GetElementPtr: + case kIROp_GetOffsetPtr: case kIROp_UpdateElement: case kIROp_Specialize: case kIROp_LookupWitness: @@ -8347,6 +8379,7 @@ namespace Slang case kIROp_CastIntToPtr: case kIROp_CastPtrToBool: case kIROp_CastPtrToInt: + case kIROp_PtrCast: case kIROp_BitAnd: case kIROp_BitNot: case kIROp_BitOr: |
