From cd7f01b63a52eaaad00088524801e502bcb0f168 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 17 Jun 2020 13:08:27 -0700 Subject: Generate dynamic C++ code for the minimal test case. (#1391) * Add IR pass to lower generics into ordinary functions. * Fix project files * Emit dynamic C++ code for simple generics and witness tables. Fixes #1386. * Remove -dump-ir flag. * Fixups. --- source/slang/slang-emit.cpp | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'source/slang/slang-emit.cpp') diff --git a/source/slang/slang-emit.cpp b/source/slang/slang-emit.cpp index 2212d5d5a..260a862ae 100644 --- a/source/slang/slang-emit.cpp +++ b/source/slang/slang-emit.cpp @@ -11,6 +11,7 @@ #include "slang-ir-glsl-legalize.h" #include "slang-ir-insts.h" #include "slang-ir-link.h" +#include "slang-ir-lower-generics.h" #include "slang-ir-restructure.h" #include "slang-ir-restructure-scoping.h" #include "slang-ir-specialize.h" @@ -273,6 +274,18 @@ Result linkAndOptimizeIR( if (!compileRequest->allowDynamicCode) specializeModule(irModule); + switch (target) + { + case CodeGenTarget::CPPSource: + // For targets that supports dynamic dispatch, we need to lower the + // generics / interface types to ordinary functions and types using + // function pointers. + lowerGenerics(irModule); + break; + default: + break; + } + // Debugging code for IR transformations... #if 0 dumpIRIfEnabled(compileRequest, irModule, "SPECIALIZED"); @@ -389,6 +402,7 @@ Result linkAndOptimizeIR( #if 0 dumpIRIfEnabled(compileRequest, irModule, "AFTER RESOURCE SPECIALIZATION"); #endif + validateIRModuleIfEnabled(compileRequest, irModule); // For HLSL (and fxc/dxc) only, we need to "wrap" any @@ -558,11 +572,14 @@ Result linkAndOptimizeIR( break; } - // For all targets that don't support true dynamic dispatch through - // witness tables (that is all targets at present), we need - // to eliminate witness tables from the IR so that they - // don't keep symbols live that we don't actually need. - stripWitnessTables(irModule); + if (!compileRequest->allowDynamicCode) + { + // For all targets that don't support true dynamic dispatch through + // witness tables, we need to eliminate witness tables from the IR so + // that they don't keep symbols live that we don't actually need. + stripWitnessTables(irModule); + } + #if 0 dumpIRIfEnabled(compileRequest, irModule, "AFTER STRIP WITNESS TABLES"); #endif -- cgit v1.2.3