@@ -106,6 +106,7 @@ static void print_help(FILE *out) {
106106 " --rep-n N N-gram length (e.g. 8)\n" ,
107107 " --rep-mode MODE MODE: exact | shape\n" ,
108108 " --rep-out PATH Write repetition report JSONL to PATH (or '-' for stdout)\n" ,
109+ " --rep-max-report N Emit up to N zem_rep_ngram records (top repeated n-grams)\n" ,
109110 " --rep-coverage-jsonl PATH Optional coverage JSONL to enrich bloat score\n" ,
110111 " --rep-diag Print one-line bloat_diag summary to stdout\n" ,
111112 " -- Stop option parsing; remaining args become guest argv\n" ,
@@ -224,6 +225,7 @@ int main(int argc, char **argv) {
224225 const char * rep_mode = "shape" ;
225226 const char * rep_out = NULL ;
226227 const char * rep_cov = NULL ;
228+ int rep_max_report = 0 ;
227229
228230 zem_proc_t proc ;
229231 memset (& proc , 0 , sizeof (proc ));
@@ -321,6 +323,16 @@ int main(int argc, char **argv) {
321323 rep_out = argv [++ i ];
322324 continue ;
323325 }
326+ if (strcmp (argv [i ], "--rep-max-report" ) == 0 ) {
327+ if (i + 1 >= argc ) {
328+ return zem_failf ("--rep-max-report requires a number" );
329+ }
330+ char * end = NULL ;
331+ long v = strtol (argv [++ i ], & end , 10 );
332+ if (!end || end == argv [i ]) return zem_failf ("bad --rep-max-report value" );
333+ rep_max_report = (int )v ;
334+ continue ;
335+ }
324336 if (strcmp (argv [i ], "--rep-coverage-jsonl" ) == 0 ) {
325337 if (i + 1 >= argc ) {
326338 return zem_failf ("--rep-coverage-jsonl requires a path" );
@@ -621,7 +633,7 @@ int main(int argc, char **argv) {
621633 return zem_failf ("cannot read program IR from stdin while --debug-script - uses stdin" );
622634 }
623635 return zem_rep_scan_program (inputs , ninputs , rep_n , rep_mode , rep_cov , rep_out ,
624- rep_diag );
636+ rep_max_report , rep_diag );
625637 }
626638
627639 if (!dbg .debug_events_only ) {
0 commit comments