summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-c-like.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-05-10 19:42:48 -0700
committerGitHub <noreply@github.com>2022-05-10 19:42:48 -0700
commit765061a77bcf4fe6300721263cc9e0f25595488d (patch)
tree5fe52269a46d8db85a869784f8637022f154c20f /source/slang/slang-emit-c-like.cpp
parentdc541cc10783de541d8341b5fccee4c6019b5c6e (diff)
Initial support for COM interface in host code. (#2230)
Co-authored-by: Yong He <yhe@nvidia.com> Co-authored-by: Theresa Foley <10618364+tangent-vector@users.noreply.github.com>
Diffstat (limited to 'source/slang/slang-emit-c-like.cpp')
-rw-r--r--source/slang/slang-emit-c-like.cpp28
1 files changed, 26 insertions, 2 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp
index 6b8939d85..a6edc0a1f 100644
--- a/source/slang/slang-emit-c-like.cpp
+++ b/source/slang/slang-emit-c-like.cpp
@@ -1506,12 +1506,12 @@ void CLikeSourceEmitter::emitIntrinsicCallExprImpl(
}
}
-void CLikeSourceEmitter::_emitCallArgList(IRCall* inst)
+void CLikeSourceEmitter::_emitCallArgList(IRCall* inst, int startingOperandIndex)
{
bool isFirstArg = true;
m_writer->emit("(");
UInt argCount = inst->getOperandCount();
- for (UInt aa = 1; aa < argCount; ++aa)
+ for (UInt aa = startingOperandIndex; aa < argCount; ++aa)
{
auto operand = inst->getOperand(aa);
if (as<IRVoidType>(operand->getDataType()))
@@ -1531,6 +1531,22 @@ void CLikeSourceEmitter::_emitCallArgList(IRCall* inst)
m_writer->emit(")");
}
+void CLikeSourceEmitter::emitComInterfaceCallExpr(IRCall* inst, EmitOpInfo const& inOuterPrec)
+{
+ auto funcValue = inst->getOperand(0);
+ auto object = funcValue->getOperand(0);
+ auto methodKey = funcValue->getOperand(1);
+ auto prec = getInfo(EmitOp::Postfix);
+
+ auto outerPrec = inOuterPrec;
+ bool needClose = maybeEmitParens(outerPrec, prec);
+ emitOperand(object, leftSide(outerPrec, prec));
+ m_writer->emit("->");
+ m_writer->emit(getName(methodKey));
+ _emitCallArgList(inst, 2);
+ maybeCloseParens(needClose);
+}
+
void CLikeSourceEmitter::emitCallExpr(IRCall* inst, EmitOpInfo outerPrec)
{
auto funcValue = inst->getOperand(0);
@@ -1538,6 +1554,14 @@ void CLikeSourceEmitter::emitCallExpr(IRCall* inst, EmitOpInfo outerPrec)
// Does this function declare any requirements.
handleRequiredCapabilities(funcValue);
+ // Detect if this is a call into a COM interface method.
+ if (funcValue->getOp() == kIROp_lookup_interface_method &&
+ funcValue->getOperand(0)->getDataType()->getOp() == kIROp_ComPtrType)
+ {
+ emitComInterfaceCallExpr(inst, outerPrec);
+ return;
+ }
+
// We want to detect any call to an intrinsic operation,
// that we can emit it directly without mangling, etc.
if(auto targetIntrinsic = findBestTargetIntrinsicDecoration(funcValue))