diff options
| author | Yong He <yonghe@outlook.com> | 2020-06-25 16:29:07 -0700 |
|---|---|---|
| committer | Yong He <yonghe@outlook.com> | 2020-06-25 16:29:07 -0700 |
| commit | 218a39b65c86654772c3d6adf2479e7cadc85d24 (patch) | |
| tree | c636a65ff1ed8c347f10f4e9c2c6a703fd9ad8ad /source/slang/slang-emit-cpp.cpp | |
| parent | 509e36b62de7578843abc2547921beadff7a3ce0 (diff) | |
remove ThisPointerDecoration, generate IRInterfaceType in one pass
Diffstat (limited to 'source/slang/slang-emit-cpp.cpp')
| -rw-r--r-- | source/slang/slang-emit-cpp.cpp | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/source/slang/slang-emit-cpp.cpp b/source/slang/slang-emit-cpp.cpp index f895b1119..7f743d9e0 100644 --- a/source/slang/slang-emit-cpp.cpp +++ b/source/slang/slang-emit-cpp.cpp @@ -1617,12 +1617,27 @@ void CPPSourceEmitter::_emitWitnessTableWrappers() { for (auto witnessTable : pendingWitnessTableDefinitions) { + auto interfaceType = cast<IRInterfaceType>(witnessTable->getOperand(0)); for (auto child : witnessTable->getChildren()) { if (auto entry = as<IRWitnessTableEntry>(child)) { if (auto funcVal = as<IRFunc>(entry->getSatisfyingVal())) { + IRInst* requirementVal = nullptr; + for (UInt i = 0; i < interfaceType->getOperandCount(); i++) + { + if (auto reqEntry = as<IRInterfaceRequirementEntry>(interfaceType->getOperand(i))) + { + if (reqEntry->getRequirementKey() == entry->getRequirementKey()) + { + requirementVal = reqEntry->getRequirementVal(); + break; + } + } + } + SLANG_ASSERT(requirementVal != nullptr); + IRFuncType* requirementFuncType = cast<IRFuncType>(requirementVal); emitType(funcVal->getResultType()); m_writer->emit(" "); m_writer->emit(_getWitnessTableWrapperFuncName(funcVal)); @@ -1630,23 +1645,20 @@ void CPPSourceEmitter::_emitWitnessTableWrappers() // Emit parameter list. { bool isFirst = true; - for (auto param : funcVal->getParams()) + SLANG_ASSERT(funcVal->getParamCount() == requirementFuncType->getParamCount()); + auto pp = funcVal->getParams().begin(); + for (UInt i = 0; i < requirementFuncType->getParamCount(); ++i, ++pp) { - if (as<IRTypeType>(param->getFullType())) + auto paramType = requirementFuncType->getParamType(i); + + if (as<IRTypeType>(paramType)) continue; if (isFirst) isFirst = false; else m_writer->emit(","); - - if (param->findDecoration<IRThisPointerDecoration>()) - { - m_writer->emit("void* "); - m_writer->emit(getName(param)); - continue; - } - emitSimpleFuncParamImpl(param); + emitParamType(paramType, getName(*pp)); } } m_writer->emit(")\n{\n"); @@ -1657,8 +1669,13 @@ void CPPSourceEmitter::_emitWitnessTableWrappers() // Emit argument list. { bool isFirst = true; - for (auto param : funcVal->getParams()) + UInt paramIndex = 0; + for (auto defParamIter = funcVal->getParams().begin(); + defParamIter!=funcVal->getParams().end(); + ++defParamIter, ++paramIndex) { + auto param = *defParamIter; + auto reqParamType = requirementFuncType->getParamType(paramIndex); if (as<IRTypeType>(param->getFullType())) continue; @@ -1667,7 +1684,8 @@ void CPPSourceEmitter::_emitWitnessTableWrappers() else m_writer->emit(", "); - if (param->findDecoration<IRThisPointerDecoration>()) + if (reqParamType->op == kIROp_RawPointerType && + param->getFullType()->op != kIROp_RawPointerType) { m_writer->emit("*static_cast<"); emitType(param->getFullType()); @@ -1779,13 +1797,7 @@ void CPPSourceEmitter::_maybeEmitWitnessTableTypeDefinition( m_writer->emit(", "); else isFirstParam = false; - auto thisDecor = funcVal->findDecoration<IRThisPointerDecoration>(); - if (thisDecor && cast<IRIntLit>(thisDecor->getOperand(0))->value.intVal == (IRIntegerValue)p) - { - m_writer->emit("void* param"); - m_writer->emit(p); - continue; - } + emitParamType(paramType, String("param") + String(p)); } m_writer->emit(");\n"); |
