Skip to content

Commit 0ea6f1e

Browse files
committed
remove netlist leakage into this branch
1 parent e4d931d commit 0ea6f1e

5 files changed

Lines changed: 34 additions & 98 deletions

File tree

lib/src/diagnostics/module_services.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ class ModuleServices {
6060
SvService? svService;
6161

6262
/// Returns SV synthesis metadata as JSON, or an unavailable status.
63-
String get svJSON => svService != null
64-
? jsonEncode(svService!.toJson())
65-
: _unavailable('sv');
63+
String get svJSON =>
64+
svService != null ? jsonEncode(svService!.toJson()) : _unavailable('sv');
6665

6766
// ─── Helpers ──────────────────────────────────────────────────
6867

lib/src/synthesizers/systemverilog/sv_service.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ class SvService {
4747
/// DevTools access.
4848
SvService(this.module, {bool register = true}) {
4949
if (!module.hasBuilt) {
50-
throw Exception(
51-
'Module must be built before creating SvService. '
50+
throw Exception('Module must be built before creating SvService. '
5251
'Call build() first.');
5352
}
5453

@@ -65,8 +64,7 @@ class SvService {
6564

6665
/// Returns the concatenated SystemVerilog output as a single string,
6766
/// matching the format of [Module.generateSynth].
68-
String get allContents =>
69-
fileContents.map((fc) => fc.contents).join('\n\n');
67+
String get allContents => fileContents.map((fc) => fc.contents).join('\n\n');
7068

7169
/// Returns a map from module definition name to its SV file contents.
7270
///

lib/src/utilities/simcompare.dart

Lines changed: 29 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

test/module_services_test.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ class SimpleModule extends Module {
2121
}
2222

2323
void main() {
24-
tearDown(() {
25-
ModuleServices.instance.reset();
26-
});
24+
tearDown(ModuleServices.instance.reset);
2725

2826
group('ModuleServices', () {
2927
test('rootModule is set after build', () async {

tool/gh_actions/setup_systemc_pch.sh

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,3 @@ g++ -std="$CXX_STD" -I"$SC_HOME" -x c++-header \
4040
-o "$PCH_DIR/systemc.h.gch" "$SC_HOME/systemc.h"
4141

4242
echo "PCH built: $PCH_DIR/systemc.h.gch"
43-
44-
# Pre-create the shared Makefile
45-
MAKEFILE="tmp_test/Makefile_sc"
46-
cat > "$MAKEFILE" <<'EOF'
47-
CXX = g++
48-
CXXFLAGS = -std=__CXX_STD__ -pipe -I__PCH_DIR__ -I__SC_HOME__
49-
LDFLAGS = -L__SC_LIB__ -lsystemc
50-
51-
all: $(TARGET)
52-
53-
$(TARGET): $(SRC)
54-
$(CXX) $(CXXFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS)
55-
56-
.PHONY: all
57-
EOF
58-
59-
# Substitute paths into the Makefile
60-
sed -i "s|__CXX_STD__|$CXX_STD|g" "$MAKEFILE"
61-
sed -i "s|__PCH_DIR__|$PCH_DIR|g" "$MAKEFILE"
62-
sed -i "s|__SC_HOME__|$SC_HOME|g" "$MAKEFILE"
63-
sed -i "s|__SC_LIB__|$SC_LIB|g" "$MAKEFILE"
64-
65-
echo "Makefile created: $MAKEFILE"

0 commit comments

Comments
 (0)