summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-c-like.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2020-06-24 13:16:11 -0700
committerYong He <yonghe@outlook.com>2020-06-24 18:10:15 -0700
commit0ca75fe002f346f6ab9b77f40c0576d2905560f1 (patch)
treeed8a3af372900923e59f0d6da629c2d0969ee7fd /source/slang/slang-emit-c-like.cpp
parent3fe4f5398d524333e955ecb91be5646e86f3b2da (diff)
Dynamic dispatch for generic interface requirements.
-Lower interfaces into actual `IRInterfaceType` insts. -Lower `DeclRef<AssocTypeDecl>` into `IRAssociatedType` -Generate proper IRType for generic functions. -Add a test case exercising dynamic dispatching a generic static function through an associated type. -Bug fixes for the test case.
Diffstat (limited to 'source/slang/slang-emit-c-like.cpp')
-rw-r--r--source/slang/slang-emit-c-like.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp
index 3438fd3f4..2605723c7 100644
--- a/source/slang/slang-emit-c-like.cpp
+++ b/source/slang/slang-emit-c-like.cpp
@@ -236,9 +236,9 @@ List<IRWitnessTableEntry*> CLikeSourceEmitter::getSortedWitnessTableEntries(IRWi
// Get a sorted list of entries using RequirementKeys defined in `interfaceType`.
for (UInt i = 0; i < interfaceType->getOperandCount(); i++)
{
- auto reqKey = cast<IRStructKey>(interfaceType->getOperand(i));
+ auto reqEntry = cast<IRInterfaceRequirementEntry>(interfaceType->getOperand(i));
IRWitnessTableEntry* entry = nullptr;
- if (witnessTableEntryDictionary.TryGetValue(reqKey, entry))
+ if (witnessTableEntryDictionary.TryGetValue(reqEntry->getRequirementKey(), entry))
{
sortedWitnessTableEntries.add(entry);
}
@@ -1962,6 +1962,10 @@ void CLikeSourceEmitter::defaultEmitInstExpr(IRInst* inst, const EmitOpInfo& inO
are hashed with 'getStringHash' */
break;
+ case kIROp_undefined:
+ m_writer->emit(getName(inst));
+ break;
+
case kIROp_IntLit:
case kIROp_FloatLit:
case kIROp_BoolLit:
@@ -3554,6 +3558,11 @@ void CLikeSourceEmitter::emitGlobalInst(IRInst* inst)
are hashed with 'getStringHash' */
break;
+ case kIROp_InterfaceRequirementEntry:
+ // Don't emit anything for interface requirement at global level.
+ // They are handled in `emitInterface`.
+ break;
+
case kIROp_Func:
emitFunc((IRFunc*) inst);
break;
@@ -3610,6 +3619,10 @@ void CLikeSourceEmitter::ensureInstOperandsRec(ComputeEmitActionsContext* ctx, I
ensureInstOperand(ctx, inst->getFullType());
UInt operandCount = inst->operandCount;
+ auto requiredLevel = EmitAction::Definition;
+ if (inst->op == kIROp_InterfaceType)
+ requiredLevel = EmitAction::ForwardDeclaration;
+
for(UInt ii = 0; ii < operandCount; ++ii)
{
// TODO: there are some special cases we can add here,
@@ -3620,8 +3633,8 @@ void CLikeSourceEmitter::ensureInstOperandsRec(ComputeEmitActionsContext* ctx, I
// only need the type they point to to be forward-declared.
// Similarly, a `call` instruction only needs the callee
// to be forward-declared, etc.
-
- ensureInstOperand(ctx, inst->getOperand(ii));
+
+ ensureInstOperand(ctx, inst->getOperand(ii), requiredLevel);
}
for(auto child : inst->getDecorationsAndChildren())