@@ -425,14 +425,22 @@ abstract class SimCompare {
425425
426426 if (! dontDeleteTmpFiles) {
427427 try {
428- File (tmpOutput).deleteSync ();
429- File (tmpTestFile).deleteSync ();
428+ final outFile = File (tmpOutput);
429+ if (outFile.existsSync ()) {
430+ outFile.deleteSync ();
431+ }
432+ final testFile = File (tmpTestFile);
433+ if (testFile.existsSync ()) {
434+ testFile.deleteSync ();
435+ }
430436 if (dumpWaves) {
431- File (tmpVcdFile).deleteSync ();
437+ final vcdFile = File (tmpVcdFile);
438+ if (vcdFile.existsSync ()) {
439+ vcdFile.deleteSync ();
440+ }
432441 }
433442 } on Exception catch (e) {
434443 print ("Couldn't delete: $e " );
435- return false ;
436444 }
437445 }
438446 return true ;
@@ -496,54 +504,6 @@ abstract class SimCompare {
496504 return _pchPath = pchDir;
497505 }
498506
499- /// Cached path to the shared Makefile (one per compiler-flags combination).
500- static String ? _makefilePath;
501-
502- /// Creates a shared Makefile once, reused for all compilations.
503- /// TARGET and SRC are passed as make variables at invocation time.
504- /// Uses atomic write (write-to-temp + rename) to avoid races when
505- /// multiple test isolates create the file concurrently.
506- static String _ensureMakefile ({
507- required String dir,
508- required String cxxStd,
509- required String pchInclude,
510- required String scHome,
511- required String scLib,
512- }) {
513- final path = '$dir /Makefile_sc' ;
514-
515- if (_makefilePath != null && File (path).existsSync ()) {
516- return _makefilePath! ;
517- }
518-
519- // If already on disk from another isolate, just reuse it
520- if (File (path).existsSync ()) {
521- return _makefilePath = path;
522- }
523-
524- final contents = '''
525- CXX = g++
526- CXXFLAGS = -std=$cxxStd -pipe $pchInclude -I$scHome
527- LDFLAGS = -L$scLib -lsystemc
528-
529- all: \$ (TARGET)
530-
531- \$ (TARGET): \$ (SRC)
532- \t\$ (CXX) \$ (CXXFLAGS) -o \$ (TARGET) \$ (SRC) \$ (LDFLAGS)
533-
534- .PHONY: all
535- ''' ;
536- Directory (dir).createSync (recursive: true );
537-
538- // Atomic write: write to temp file, then rename so concurrent
539- // readers never see a truncated Makefile.
540- File ('$path .${pid .hashCode }' )
541- ..writeAsStringSync (contents)
542- ..renameSync (path);
543-
544- return _makefilePath = path;
545- }
546-
547507 /// Resolves SystemC home/lib paths. If explicit paths are given, uses them.
548508 /// Otherwise uses the default Accellera install paths.
549509 static (String ? , String ? ) _resolveSystemCPaths (String scHome, String scLib) {
@@ -587,7 +547,6 @@ all: \$(TARGET)
587547 static void cleanupSystemCCache ({bool keepPch = true }) {
588548 _compilationCache.clear ();
589549 _pchPath = null ;
590- _makefilePath = null ;
591550 if (kIsWeb) {
592551 return ;
593552 }
@@ -596,9 +555,14 @@ all: \$(TARGET)
596555 if (dir.existsSync ()) {
597556 if (keepPch) {
598557 for (final entity in dir.listSync ()) {
558+ final name = entity.uri.pathSegments.last;
559+ // Only remove SystemC artifacts (tmp_sc_*), preserve iverilog files
599560 if (entity is Directory && entity.path.endsWith ('/pch' )) {
600561 continue ;
601562 }
563+ if (! name.startsWith ('tmp_sc_' ) && name != 'Makefile_sc' ) {
564+ continue ;
565+ }
602566 entity.deleteSync (recursive: true );
603567 }
604568 } else {
@@ -844,19 +808,19 @@ all: \$(TARGET)
844808
845809 // Build precompiled header on first use
846810 final pchDir = _ensurePch (resolvedHome, cxxStd);
847- final pchInclude = pchDir != null ? '-I$pchDir ' : '' ;
848-
849- // Create shared Makefile once (keyed by compiler flags)
850- final makefile = _ensureMakefile (
851- dir: dir,
852- cxxStd: cxxStd,
853- pchInclude: pchInclude,
854- scHome: resolvedHome,
855- scLib: resolvedLib,
856- );
811+ final pchArgs = pchDir != null ? ['-I$pchDir ' ] : < String > [];
857812
858- final compileResult = Process .runSync (
859- 'make' , ['-f' , makefile, 'TARGET=$tmpOutput ' , 'SRC=$tmpCppFile ' ]);
813+ final compileResult = Process .runSync ('g++' , [
814+ '-std=$cxxStd ' ,
815+ '-pipe' ,
816+ ...pchArgs,
817+ '-I$resolvedHome ' ,
818+ '-o' ,
819+ tmpOutput,
820+ tmpCppFile,
821+ '-L$resolvedLib ' ,
822+ '-lsystemc' ,
823+ ]);
860824 if (compileResult.exitCode != 0 ) {
861825 print ('SystemC compilation failed:' );
862826 print (compileResult.stdout);
0 commit comments