@@ -420,7 +420,7 @@ RefPtr<Expr> CompileRequest::parseTypeString(TranslationUnitRequest * translatio
420
420
SourceManager localSourceManager;
421
421
localSourceManager.initialize (sourceManager);
422
422
423
- Slang::RefPtr<Slang:: SourceFile> srcFile ( localSourceManager.createSourceFileWithString (PathInfo::makeTypeParse (), typeStr) );
423
+ Slang::SourceFile* srcFile = localSourceManager.createSourceFileWithString (PathInfo::makeTypeParse (), typeStr);
424
424
425
425
// We'll use a temporary diagnostic sink
426
426
DiagnosticSink sink;
@@ -561,17 +561,15 @@ void CompileRequest::generateIR()
561
561
// in isolation.
562
562
for ( auto & translationUnit : translationUnits )
563
563
{
564
- // TODO JS:
565
- // This is a bit of HACK. Apparently if we call generateIRForTranslationUnit(translationUnit) twice
566
- // we get a different result (!).
567
- // So here, we only create once even if we run verification.
568
- RefPtr<IRModule> irModule;
564
+ // We want to only run generateIRForTranslationUnit once here. This is for two side effects:
565
+ // * it can dump ir
566
+ // * it can generate diagnostics
567
+
568
+ // / Generate IR for translation unit
569
+ RefPtr<IRModule> irModule (generateIRForTranslationUnit (translationUnit));
569
570
570
571
if (verifyDebugSerialization)
571
572
{
572
- // / Generate IR for translation unit
573
- irModule = generateIRForTranslationUnit (translationUnit);
574
-
575
573
// Verify debug information
576
574
if (SLANG_FAILED (IRSerialUtil::verifySerialize (irModule, mSession , sourceManager, IRSerialBinary::CompressionType::None, IRSerialWriter::OptionFlag::DebugInfo)))
577
575
{
@@ -583,16 +581,11 @@ void CompileRequest::generateIR()
583
581
{
584
582
IRSerialData serialData;
585
583
{
586
- // / Generate IR for translation unit
587
- if (!irModule)
588
- {
589
- irModule = generateIRForTranslationUnit (translationUnit);
590
- }
591
-
592
584
// Write IR out to serialData - copying over SourceLoc information directly
593
585
IRSerialWriter writer;
594
586
writer.write (irModule, sourceManager, IRSerialWriter::OptionFlag::RawSourceLocation, &serialData);
595
587
588
+ // Destroy irModule such that memory can be used for newly constructed read irReadModule
596
589
irModule = nullptr ;
597
590
}
598
591
RefPtr<IRModule> irReadModule;
@@ -602,18 +595,12 @@ void CompileRequest::generateIR()
602
595
reader.read (serialData, mSession , nullptr , irReadModule);
603
596
}
604
597
605
- // Use the serialized irModule
606
- translationUnit-> irModule = irReadModule;
598
+ // Set irModule to the read module
599
+ irModule = irReadModule;
607
600
}
608
- else
609
- {
610
- if (!irModule)
611
- {
612
- irModule = generateIRForTranslationUnit (translationUnit);
613
- }
614
601
615
- translationUnit-> irModule = irModule;
616
- }
602
+ // Set the module on the translation unit
603
+ translationUnit-> irModule = irModule;
617
604
}
618
605
}
619
606
@@ -779,7 +766,7 @@ void CompileRequest::addTranslationUnitSourceBlob(
779
766
ISlangBlob* sourceBlob)
780
767
{
781
768
PathInfo pathInfo = PathInfo::makePath (path);
782
- RefPtr< SourceFile> sourceFile = getSourceManager ()->createSourceFileWithBlob (pathInfo, sourceBlob);
769
+ SourceFile* sourceFile = getSourceManager ()->createSourceFileWithBlob (pathInfo, sourceBlob);
783
770
784
771
addTranslationUnitSourceFile (translationUnitIndex, sourceFile);
785
772
}
@@ -790,7 +777,7 @@ void CompileRequest::addTranslationUnitSourceString(
790
777
String const & source)
791
778
{
792
779
PathInfo pathInfo = PathInfo::makePath (path);
793
- RefPtr< SourceFile> sourceFile = getSourceManager ()->createSourceFileWithString (pathInfo, source);
780
+ SourceFile* sourceFile = getSourceManager ()->createSourceFileWithString (pathInfo, source);
794
781
795
782
addTranslationUnitSourceFile (translationUnitIndex, sourceFile);
796
783
}
@@ -915,7 +902,7 @@ RefPtr<ModuleDecl> CompileRequest::loadModule(
915
902
translationUnit->compileFlags = 0 ;
916
903
917
904
// Create with the 'friendly' name
918
- RefPtr< SourceFile> sourceFile = getSourceManager ()->createSourceFileWithBlob (filePathInfo, sourceBlob);
905
+ SourceFile* sourceFile = getSourceManager ()->createSourceFileWithBlob (filePathInfo, sourceBlob);
919
906
920
907
translationUnit->sourceFiles .Add (sourceFile);
921
908
0 commit comments