diff options
| author | Yong He <yonghe@outlook.com> | 2022-08-20 01:03:06 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-20 01:03:06 -0700 |
| commit | af70651a4843b16dd24e14b5cedffe399ebeb862 (patch) | |
| tree | a6aefd5db94a048114b9a8d7ed3f826533105fab /source/slang/slang-emit-c-like.cpp | |
| parent | 6412c4913b6a063438bb11863f2c154d3ae42dfe (diff) | |
Call `gfx` in slang program. (#2370)
Diffstat (limited to 'source/slang/slang-emit-c-like.cpp')
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 44 |
1 files changed, 39 insertions, 5 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index 226e29764..e98c8c6f3 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -3378,16 +3378,25 @@ void CLikeSourceEmitter::ensureInstOperandsRec(ComputeEmitActionsContext* ctx, I auto requiredLevel = EmitAction::Definition; switch (inst->getOp()) { - case kIROp_InterfaceType: - requiredLevel = EmitAction::ForwardDeclaration; - break; - case kIROp_COMWitnessDecoration: + case kIROp_NativePtrType: requiredLevel = EmitAction::ForwardDeclaration; break; default: break; } + if (auto comWitnessDecoration = as<IRCOMWitnessDecoration>(inst)) + { + // A COMWitnessDecoration marks the interface inheritance of a class. + // We need to make sure the implemented interface is emited before the class. + // The witness table itself doesn't matter. + if (auto witnessTable = as<IRWitnessTable>(comWitnessDecoration->getWitnessTable())) + { + ensureInstOperand(ctx, witnessTable->getConformanceType(), requiredLevel); + } + requiredLevel = EmitAction::ForwardDeclaration; + } + for(UInt ii = 0; ii < operandCount; ++ii) { // TODO: there are some special cases we can add here, @@ -3415,13 +3424,26 @@ void CLikeSourceEmitter::ensureGlobalInst(ComputeEmitActionsContext* ctx, IRInst { case kIROp_Generic: return; - + case kIROp_ThisType: + return; default: break; } if (as<IRBasicType>(inst)) return; + // Certain inst ops will always emit as definition. + switch (inst->getOp()) + { + case kIROp_NativePtrType: + // Pointer type will have their value type emited as forward declaration, + // but the pointer type itself should be considered emitted as definition. + requiredLevel = EmitAction::Level::Definition; + break; + default: + break; + } + // Have we already processed this instruction? EmitAction::Level existingLevel; if(ctx->mapInstToLevel.TryGetValue(inst, existingLevel)) @@ -3457,7 +3479,9 @@ void CLikeSourceEmitter::ensureGlobalInst(ComputeEmitActionsContext* ctx, IRInst switch (inst->getOp()) { case kIROp_InterfaceRequirementEntry: + { return; + } default: break; @@ -3496,6 +3520,16 @@ void CLikeSourceEmitter::emitForwardDeclaration(IRInst* inst) m_writer->emit(getName(inst)); m_writer->emit(";\n"); break; + case kIROp_InterfaceType: + { + if (inst->findDecoration<IRComInterfaceDecoration>()) + { + m_writer->emit("struct "); + m_writer->emit(getName(inst)); + m_writer->emit(";\n"); + } + break; + } default: SLANG_UNREACHABLE("emit forward declaration"); } |
