From 61a6d18c4870eb55b804d36a30608a34c55e801d Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 20 Feb 2018 16:34:59 -0500 Subject: make CompileRequest retain specailized IR module. This is to workaround with the issue that the Types returned in ProgramLayout may reference to IRWitnessTables via GlobalGenericParamSubstitution. --- source/slang/compiler.h | 2 ++ source/slang/emit.cpp | 6 ++++-- source/slang/slang.cpp | 8 +++++++- 3 files changed, 13 insertions(+), 3 deletions(-) (limited to 'source') diff --git a/source/slang/compiler.h b/source/slang/compiler.h index b1cebc2a1..845de5c81 100644 --- a/source/slang/compiler.h +++ b/source/slang/compiler.h @@ -313,6 +313,8 @@ namespace Slang // Map from the logical name of a module to its definition Dictionary> mapNameToLoadedModules; + // The resulting specialized IR module for each entry point request + List> compiledModules; CompileRequest(Session* session); diff --git a/source/slang/emit.cpp b/source/slang/emit.cpp index 46c0b20a9..d2ed1c7c3 100644 --- a/source/slang/emit.cpp +++ b/source/slang/emit.cpp @@ -8158,6 +8158,10 @@ String emitEntryPoint( // TODO: do we want to emit directly from IR, or translate the // IR back into AST for emission? visitor.emitIRModule(&context, irModule); + + // retain the specialized ir module, because the current + // GlobalGenericParamSubstitution implementation may reference ir objects + targetRequest->compileRequest->compiledModules.Add(irModule); } destroyIRSpecializationState(irSpecializationState); @@ -8167,8 +8171,6 @@ String emitEntryPoint( // Now that we've emitted the code for all the declaratiosn in the file, // it is time to stich together the final output. - - // There may be global-scope modifiers that we should emit now visitor.emitGLSLPreprocessorDirectives(translationUnitSyntax); String prefix = sharedContext.sb.ProduceString(); diff --git a/source/slang/slang.cpp b/source/slang/slang.cpp index b65ec5615..42e412438 100644 --- a/source/slang/slang.cpp +++ b/source/slang/slang.cpp @@ -123,7 +123,13 @@ CompileRequest::CompileRequest(Session* session) } CompileRequest::~CompileRequest() -{} +{ + // delete things that may reference IR objects first + targets = decltype(targets)(); + translationUnits = decltype(translationUnits)(); + entryPoints = decltype(entryPoints)(); + types = decltype(types)(); +} RefPtr CompileRequest::parseTypeString(TranslationUnitRequest * translationUnit, String typeStr, RefPtr scope) -- cgit v1.2.3