Skip to content

Commit 0f60a8d

Browse files
committed
feat: add big array skip
1 parent 828a146 commit 0f60a8d

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,11 @@ diff-internal:
383383
$(MAKE) MODE=2 compile
384384
$(MAKE) MODE=2 difftest
385385

386-
run:
386+
run: clean
387387
mkdir -p $(dir $(LOG_FILE))
388-
set -o pipefail && $(TIME) $(MAKE) run-internal 2>&1 | tee $(LOG_FILE)
388+
set -o pipefail && stdbuf -oL -eL $(TIME) $(MAKE) run-internal 2>&1 | tee $(LOG_FILE)
389389

390-
run-waveform:
390+
run-waveform: clean
391391
$(MAKE) run WAVEFORM=1 LOG_FILE=$(WAVE_LOG_FILE) WAVE_LOG_FILE=$(WAVE_LOG_FILE) WAVEFORM_PATH=$(WAVEFORM_PATH)
392392

393393
diff:

emu/emu.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <iostream>
22
#include <time.h>
33
#include <cstring>
4+
#include <cstdio>
45
#include <cassert>
56
#include <vector>
67
#include <numeric>
@@ -270,6 +271,11 @@ bool checkSignals(bool display) {
270271
#endif
271272

272273
int main(int argc, char** argv) {
274+
// Force immediate flushing even when stdout/stderr are piped (e.g. via tee).
275+
std::cout.setf(std::ios::unitbuf);
276+
std::cerr.setf(std::ios::unitbuf);
277+
setvbuf(stdout, nullptr, _IOLBF, 0);
278+
setvbuf(stderr, nullptr, _IOLBF, 0);
273279
load_program(argv[1]);
274280
#ifdef GSIM
275281
dut = new DUT_NAME();

include/config.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
#ifndef CONFIG_H
22
#define CONFIG_H
33

4+
#include <cstddef>
5+
#include <set>
6+
#include <string>
7+
48
struct Config {
59
bool EnableDumpGraph;
610
bool DumpGraphDot;
711
bool DumpGraphJson;
812
bool DumpAssignTree;
913
bool DumpConstStatus;
1014
bool TraceFst;
15+
size_t FstMaxArrayElems;
16+
bool TraceFstNoNext;
1117
std::string OutputDir;
1218
int SuperNodeMaxSize;
1319
uint32_t cppMaxSizeKB;

src/cppEmitter.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
#define ENABLE_ACTIVATOR false
1818

19+
// Avoid emitting waveform handles for giant arrays (e.g., full RAM contents);
20+
// limit is controlled by globalConfig.FstMaxArrayElems (0 = unlimited).
21+
1922
#ifdef DIFFTEST_PER_SIG
2023
FILE* sigFile = nullptr;
2124
#endif
@@ -971,8 +974,31 @@ void graph::cppEmitter() {
971974

972975
fstWaveNodes.clear();
973976
fstWaveNodeSet.clear();
977+
const size_t fstWaveLimit = globalConfig.FstMaxArrayElems;
974978
auto collectWaveNode = [&](Node* n) {
975-
if (isTopField(n)) fstWaveNodeSet.insert(n);
979+
if (!isTopField(n)) return;
980+
if (globalConfig.TraceFstNoNext) {
981+
const std::string& nm = n->name;
982+
if (nm.size() >= 5 && nm.rfind("$NEXT") == nm.size() - 5) return;
983+
}
984+
auto dims = nodeArrayDims(n);
985+
if (!dims.empty() && fstWaveLimit != 0) {
986+
size_t total = 1;
987+
for (int dim : dims) {
988+
if (dim <= 0) continue;
989+
if (total > fstWaveLimit / static_cast<size_t>(dim)) {
990+
total = fstWaveLimit + 1;
991+
break;
992+
}
993+
total *= static_cast<size_t>(dim);
994+
}
995+
if (total > fstWaveLimit) {
996+
fprintf(stderr, "[gsim] skip waveform for %s: %zu elements exceed limit %zu\n",
997+
n->name.c_str(), total, fstWaveLimit);
998+
return;
999+
}
1000+
}
1001+
fstWaveNodeSet.insert(n);
9761002
};
9771003
for (SuperNode* super : sortedSuper) {
9781004
if (super->superType == SUPER_VALID || super->superType == SUPER_ASYNC_RESET) {

src/main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <sstream>
1212
#include <getopt.h>
13+
#include <cstdlib>
1314
#include <sys/mman.h>
1415
#include <sys/stat.h>
1516
#include <fcntl.h>
@@ -27,6 +28,8 @@ Config::Config() {
2728
DumpAssignTree = false;
2829
DumpConstStatus = false;
2930
TraceFst = false;
31+
FstMaxArrayElems = 1 << 20; // 1M elements cap for waveform handle emission
32+
TraceFstNoNext = true; // drop xxx$NEXT signals by default
3033
OutputDir = ".";
3134
SuperNodeMaxSize = 35;
3235
cppMaxSizeKB = -1;
@@ -93,6 +96,8 @@ static void printUsage(const char* ProgName) {
9396
<< " --dump-assign-tree Include assignTree structure in JSON dump (can be large).\n"
9497
<< " --dump-const-status Dump per-node constant-analysis status before removing constants.\n"
9598
<< " --trace-fst Enable FST waveform support in generated C++ (defines FST_WAVE).\n"
99+
<< " --trace-fst-max-elems=[num] Max array elements to emit FST handles (0 for unlimited, default: 1048576).\n"
100+
<< " --trace-fst-no-next=[0|1] Filter next-state signals (xxx$NEXT); default 1 = filter out.\n"
96101
;
97102
}
98103

@@ -121,6 +126,8 @@ static char* parseCommandLine(int argc, char** argv) {
121126
OPT_DUMP_ASSIGN_TREE,
122127
OPT_DUMP_CONST_STATUS,
123128
OPT_TRACE_FST,
129+
OPT_TRACE_FST_MAX_ELEMS,
130+
OPT_TRACE_FST_NO_NEXT,
124131
};
125132

126133
const struct option Table[] = {
@@ -140,6 +147,8 @@ static char* parseCommandLine(int argc, char** argv) {
140147
{"dump-assign-tree", no_argument, nullptr, 0},
141148
{"dump-const-status", no_argument, nullptr, 0},
142149
{"trace-fst", no_argument, nullptr, 0},
150+
{"trace-fst-max-elems", required_argument, nullptr, 0},
151+
{"trace-fst-no-next", required_argument, nullptr, 0},
143152
{nullptr, no_argument, nullptr, 0},
144153
};
145154

@@ -203,6 +212,16 @@ static char* parseCommandLine(int argc, char** argv) {
203212
case OPT_TRACE_FST:
204213
globalConfig.TraceFst = true;
205214
break;
215+
case OPT_TRACE_FST_MAX_ELEMS: {
216+
unsigned long long val = strtoull(optarg, nullptr, 0);
217+
globalConfig.FstMaxArrayElems = static_cast<size_t>(val);
218+
break;
219+
}
220+
case OPT_TRACE_FST_NO_NEXT: {
221+
int v = atoi(optarg);
222+
globalConfig.TraceFstNoNext = (v != 0);
223+
break;
224+
}
206225
case OPT_HELP:
207226
default: printUsage(argv[0]); std::cout.flush(); fflush(nullptr); _exit(EXIT_SUCCESS);
208227
}

0 commit comments

Comments
 (0)