From 48f26ef082fa3b0c2a02dc57585f7e43210bbb63 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 13 Jul 2020 15:16:09 -0700 Subject: Dynamic code gen for functions returning generic types. (#1439) * Dynamic code gen for functions returning generic types. * Add expected test result. --- source/slang/slang-ir.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index b2ddc8ed3..efb8b3b27 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -343,6 +343,25 @@ namespace Slang } } + // Similar to addParam, but instead of appending `param` to the end + // of the parameter list, this function inserts `param` before the + // head of the list. + void IRBlock::insertParamAtHead(IRParam* param) + { + if (auto firstParam = getFirstParam()) + { + param->insertBefore(firstParam); + } + else if (auto firstOrdinary = getFirstOrdinaryInst()) + { + param->insertBefore(firstOrdinary); + } + else + { + param->insertAtEnd(this); + } + } + IRInst* IRBlock::getFirstOrdinaryInst() { // Find the last parameter (if any) of the block @@ -3030,6 +3049,17 @@ namespace Slang return param; } + IRParam* IRBuilder::emitParamAtHead( + IRType* type) + { + auto param = createParam(type); + if (auto bb = getBlock()) + { + bb->insertParamAtHead(param); + } + return param; + } + IRVar* IRBuilder::emitVar( IRType* type) { -- cgit v1.2.3