@@ -31,10 +31,44 @@ montgomery_factor = pow(2, 16, modulus)
31
31
# - header guards
32
32
# - #undef's for CU-local macros
33
33
34
+ # Standard color definitions
35
+ GREEN = "\033 [32m"
36
+ RED = "\033 [31m"
37
+ BLUE = "\033 [94m"
38
+ BOLD = "\033 [1m"
39
+ NORMAL = "\033 [0m"
40
+
41
+
42
+ def clear_status_line ():
43
+ """Clear any existing status line by overwriting with spaces and returning to start of line"""
44
+ print (f"\r { ' ' * 160 } " , end = "" , flush = True )
45
+
34
46
35
47
def status_update (task , msg ):
36
- print (f"\r { '' :<160} " , end = "" , flush = True )
37
- print (f"\r [{ task } ]: { msg } ..." , end = "" , flush = True )
48
+ clear_status_line ()
49
+ print (f"\r { BLUE } [{ task } ]{ NORMAL } : { msg } ..." , end = "" , flush = True )
50
+
51
+
52
+ def high_level_status (msg ):
53
+ clear_status_line ()
54
+ print (
55
+ f"\r { GREEN } ✓{ NORMAL } { msg } "
56
+ ) # This will end with a newline, clearing the status line
57
+
58
+
59
+ def info (msg ):
60
+ clear_status_line ()
61
+ print (f"\r { GREEN } info{ NORMAL } { msg } " )
62
+
63
+
64
+ def error (msg ):
65
+ clear_status_line ()
66
+ print (f"\r { RED } error{ NORMAL } { msg } " )
67
+
68
+
69
+ def file_updated (filename ):
70
+ clear_status_line ()
71
+ print (f"\r { BOLD } updated { filename } { NORMAL } " )
38
72
39
73
40
74
def gen_header ():
@@ -240,7 +274,7 @@ class CondParser:
240
274
return CondParser .print_exp (self .parse_condition (exp ))
241
275
242
276
243
- def adjust_preprocessor_comments_for_filename (content , source_file ):
277
+ def adjust_preprocessor_comments_for_filename (content , source_file , show_status = False ):
244
278
"""Automatically add comments to large `#if ... #else ... #endif`
245
279
blocks indicating the guarding conditions.
246
280
@@ -270,7 +304,8 @@ def adjust_preprocessor_comments_for_filename(content, source_file):
270
304
271
305
```
272
306
"""
273
- status_update ("if-else" , source_file )
307
+ if show_status :
308
+ status_update ("if-else" , source_file )
274
309
275
310
content = content .split ("\n " )
276
311
new_content = []
@@ -390,7 +425,9 @@ def adjust_preprocessor_comments_for_filename(content, source_file):
390
425
def gen_preprocessor_comments_for (source_file , dry_run = False ):
391
426
with open (source_file , "r" ) as f :
392
427
content = f .read ()
393
- new_content = adjust_preprocessor_comments_for_filename (content , source_file )
428
+ new_content = adjust_preprocessor_comments_for_filename (
429
+ content , source_file , show_status = True
430
+ )
394
431
update_file (source_file , new_content , dry_run = dry_run )
395
432
396
433
@@ -402,10 +439,17 @@ def gen_preprocessor_comments(dry_run=False):
402
439
)
403
440
404
441
405
- def update_file (filename , content , dry_run = False , force_format = False ):
442
+ def update_file (
443
+ filename ,
444
+ content ,
445
+ dry_run = False ,
446
+ force_format = False ,
447
+ skip_preprocessor_comments = False ,
448
+ ):
406
449
407
450
if force_format is True or filename .endswith ((".c" , ".h" , ".i" )):
408
- content = adjust_preprocessor_comments_for_filename (content , filename )
451
+ if skip_preprocessor_comments is False :
452
+ content = adjust_preprocessor_comments_for_filename (content , filename )
409
453
content = format_content (content )
410
454
411
455
if os .path .exists (filename ) is True :
@@ -418,15 +462,15 @@ def update_file(filename, content, dry_run=False, force_format=False):
418
462
return
419
463
420
464
if dry_run is False :
465
+ file_updated (filename )
421
466
with open (filename , "w+" ) as f :
422
467
f .write (content )
423
468
else :
424
469
filename_new = f"{ filename } .new"
425
- print (
426
- f"Autogenerated file { filename } needs updating. Have you called scripts/autogen?" ,
427
- file = sys .stderr ,
470
+ error (
471
+ f"Autogenerated file { filename } needs updating. Have you called scripts/autogen?"
428
472
)
429
- print (f"Writing new version to { filename_new } " , file = sys . stderr )
473
+ info (f"Writing new version to { filename_new } " )
430
474
with open (filename_new , "w" ) as f :
431
475
f .write (content )
432
476
# If the file exists, print diff between old and new version for debugging
@@ -2000,6 +2044,7 @@ def synchronize_backends(
2000
2044
update_via_copy (
2001
2045
f"dev/aarch64_{ ty } /meta.h" ,
2002
2046
"mlkem/src/native/aarch64/meta.h" ,
2047
+ dry_run = dry_run ,
2003
2048
transform = lambda c : adjust_header_guard_for_filename (
2004
2049
c , "mlkem/src/native/aarch64/meta.h"
2005
2050
),
@@ -2439,10 +2484,13 @@ def gen_c_citations_for(filename, bibliography, dry_run=False):
2439
2484
# Remember this usage of the bibliography entry
2440
2485
entry .register_usages (uses )
2441
2486
2442
- update_file (filename , "\n " .join (content ), dry_run = dry_run )
2487
+ update_file (
2488
+ filename , "\n " .join (content ), dry_run = dry_run , skip_preprocessor_comments = True
2489
+ )
2443
2490
2444
2491
2445
2492
def gen_citations_for (filename , bibliography , dry_run = False ):
2493
+ status_update ("citations" , filename )
2446
2494
if filename .endswith (".md" ):
2447
2495
gen_markdown_citations_for (filename , bibliography , dry_run = dry_run )
2448
2496
elif filename .endswith ((".c" , ".h" , ".S" )):
@@ -2557,13 +2605,18 @@ def _main():
2557
2605
os .chdir (os .path .join (os .path .dirname (__file__ ), ".." ))
2558
2606
2559
2607
gen_citations (args .dry_run )
2608
+ high_level_status ("Generated citations" )
2560
2609
2561
2610
if args .slothy == []:
2562
2611
args .slothy = slothy_choices
2563
- gen_slothy (args .slothy , args .dry_run )
2612
+ if args .slothy is not None :
2613
+ gen_slothy (args .slothy , args .dry_run )
2614
+ high_level_status ("Generated SLOTHY optimized assembly" )
2564
2615
2565
2616
check_asm_register_aliases ()
2617
+ high_level_status ("Checked assembly register aliases" )
2566
2618
check_asm_loop_labels ()
2619
+ high_level_status ("Checked assembly loop labels" )
2567
2620
2568
2621
gen_c_zeta_file (args .dry_run )
2569
2622
gen_aarch64_hol_light_zeta_file (args .dry_run )
@@ -2573,21 +2626,29 @@ def _main():
2573
2626
gen_avx2_zeta_file (args .dry_run )
2574
2627
gen_avx2_rej_uniform_table (args .dry_run )
2575
2628
gen_avx2_mulcache_twiddles_file (args .dry_run )
2629
+ high_level_status ("Generated zeta and lookup tables" )
2576
2630
2577
2631
if platform .machine ().lower () in ["arm64" , "aarch64" ]:
2578
2632
gen_hol_light_asm (args .dry_run )
2633
+ high_level_status ("Generated HOL Light assembly" )
2579
2634
2580
2635
synchronize_backends (
2581
2636
dry_run = args .dry_run ,
2582
2637
clean = args .aarch64_clean ,
2583
2638
no_simplify = args .no_simplify ,
2584
2639
force_cross = args .force_cross ,
2585
2640
)
2641
+ high_level_status ("Synchronized backends" )
2642
+
2586
2643
gen_header_guards (args .dry_run )
2644
+ high_level_status ("Generated header guards" )
2587
2645
gen_preprocessor_comments (args .dry_run )
2646
+ high_level_status ("Generated preprocessor comments" )
2588
2647
gen_monolithic_source_file (args .dry_run )
2589
2648
gen_monolithic_asm_file (args .dry_run )
2649
+ high_level_status ("Generated monolithic source files" )
2590
2650
gen_undefs (args .dry_run )
2651
+ high_level_status ("Generated undefs" )
2591
2652
2592
2653
synchronize_backends (
2593
2654
dry_run = args .dry_run ,
@@ -2596,9 +2657,10 @@ def _main():
2596
2657
force_cross = args .force_cross ,
2597
2658
no_simplify = args .no_simplify ,
2598
2659
)
2660
+ high_level_status ("Completed final backend synchronization" )
2599
2661
2600
2662
check_macro_typos ()
2601
- print ( )
2663
+ high_level_status ( "Checked macro typos" )
2602
2664
2603
2665
2604
2666
if __name__ == "__main__" :
0 commit comments