This repository was archived by the owner on Sep 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
917 lines (821 loc) · 34 KB
/
Copy pathCMakeLists.txt
File metadata and controls
917 lines (821 loc) · 34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
cmake_minimum_required(VERSION 3.20)
project(nitpick VERSION 0.61.105 LANGUAGES C CXX)
# C++17 standard required
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# ============================================================================
# ccache — Accelerate rebuilds (v0.8.2)
# ============================================================================
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
message(STATUS "ccache found: ${CCACHE_PROGRAM} — compiler caching enabled")
else()
message(STATUS "ccache not found — install with: sudo apt install ccache")
endif()
# liburing configuration
set(LIBURING_ROOT ${CMAKE_SOURCE_DIR}/third_party/liburing-master/install)
include_directories(${LIBURING_ROOT}/include)
link_directories(${LIBURING_ROOT}/lib)
# Compiler warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic")
# Debug build type flags
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
# Release build type flags
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
# Memory sanitizer for debug builds (optional, can enable with -DUSE_ASAN=ON)
option(USE_ASAN "Enable AddressSanitizer" OFF)
if(USE_ASAN)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address")
endif()
# Code coverage (optional, can enable with -DUSE_COVERAGE=ON)
option(USE_COVERAGE "Enable code coverage" OFF)
if(USE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
endif()
# ============================================================================
# Build Time Profiling (v0.8.2) — -DUSE_TIME_TRACE=ON
# ============================================================================
# Generates per-TU Chrome trace JSON files (-ftime-trace) for analysis.
# Open the .json files in chrome://tracing or https://ui.perfetto.dev
option(USE_TIME_TRACE "Enable -ftime-trace for build profiling" OFF)
if(USE_TIME_TRACE)
check_cxx_compiler_flag("-ftime-trace" HAS_FTIME_TRACE)
if(HAS_FTIME_TRACE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftime-trace")
message(STATUS "Build time profiling enabled (-ftime-trace)")
else()
message(STATUS "Build time profiling unavailable — compiler does not support -ftime-trace")
endif()
endif()
# ── Runtime-only build mode (ARM-001, v0.86.1) ─────────────────────────────
# When cross-compiling for AArch64, we only need the runtime library.
# LLVM and the compiler itself aren't needed on the target.
option(NITPICK_RUNTIME_ONLY "Build only the runtime library (skip LLVM, npkc)" OFF)
if(NITPICK_RUNTIME_ONLY)
message(STATUS "RUNTIME-ONLY mode: building libnitpick_runtime.a only (no LLVM, no npkc)")
endif()
# ── TUI support (ftxui) ─────────────────────────────────────────────────────
# NTU-002/003: FetchContent provides ftxui::screen, ftxui::dom, ftxui::component
option(NITPICK_HAS_TUI "Enable interactive terminal analysis dashboard (ftxui)" ON)
if(NITPICK_HAS_TUI)
include(FetchContent)
FetchContent_Declare(
ftxui
GIT_REPOSITORY https://github.com/ArthurSonzogni/FTXUI
GIT_TAG v6.1.9
GIT_SHALLOW TRUE # Only fetch the tagged commit — faster
)
set(FETCHCONTENT_QUIET OFF) # Show download progress
set(FTXUI_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(FTXUI_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(FTXUI_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(ftxui)
message(STATUS "ftxui: ENABLED — targets: ftxui::screen ftxui::dom ftxui::component")
else()
message(STATUS "ftxui: DISABLED (NITPICK_HAS_TUI=OFF)")
endif()
# ============================================================================
# LLVM Configuration (LLVM 20.1.2)
# ============================================================================
if(NOT NITPICK_RUNTIME_ONLY)
find_package(LLVM 20.1 REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
include_directories(${LLVM_INCLUDE_DIRS})
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})
# Find the LLVM libraries we need
llvm_map_components_to_libnames(llvm_libs
core
support
irreader
bitwriter
transformutils
analysis
target
mcjit
native
orcjit
passes
X86
AArch64
AMDGPU
ARM
AVR
BPF
Hexagon
Lanai
LoongArch
Mips
MSP430
NVPTX
PowerPC
RISCV
Sparc
SPIRV
SystemZ
VE
WebAssembly
XCore
M68k
Xtensa
nvptxdesc # NVPTX target description
nvptxinfo # NVPTX target info
webassemblycodegen # WebAssembly code generator for WASM target
webassemblydesc # WebAssembly target description
webassemblyinfo # WebAssembly target info
webassemblyasmparser # WebAssembly assembly parser
)
else()
# Runtime-only: no LLVM, set empty libs
set(llvm_libs "")
set(LLDB_FOUND FALSE)
endif() # NOT NITPICK_RUNTIME_ONLY (LLVM block)
if(NOT NITPICK_RUNTIME_ONLY)
# ============================================================================
# LLDB Configuration (for debugger formatters)
# ============================================================================
# Find LLDB library
find_library(LLDB_LIBRARY
NAMES lldb LLDB lldb-20
HINTS ${LLVM_LIBRARY_DIRS} /usr/lib/llvm-20/lib
PATHS /usr/lib/x86_64-linux-gnu
)
if(LLDB_LIBRARY)
message(STATUS "Found LLDB library: ${LLDB_LIBRARY}")
# LLDB headers are always in /usr/lib/llvm-*/include regardless of library location
# Try to find the version-specific directory
if(EXISTS "/usr/lib/llvm-20/include/lldb")
set(LLDB_INCLUDE_DIRS "/usr/lib/llvm-20/include")
elseif(EXISTS "/usr/lib/llvm-19/include/lldb")
set(LLDB_INCLUDE_DIRS "/usr/lib/llvm-19/include")
elseif(EXISTS "/usr/lib/llvm-18/include/lldb")
set(LLDB_INCLUDE_DIRS "/usr/lib/llvm-18/include")
else()
# Fallback: try to derive from LLVM_INCLUDE_DIRS
set(LLDB_INCLUDE_DIRS "${LLVM_INCLUDE_DIRS}")
endif()
message(STATUS "LLDB include directory: ${LLDB_INCLUDE_DIRS}")
set(LLDB_FOUND TRUE)
else()
message(STATUS "LLDB library not found - debugger formatters will not be built")
set(LLDB_FOUND FALSE)
endif()
endif() # NOT NITPICK_RUNTIME_ONLY (LLDB block)
# ============================================================================
# Third-party libraries
# ============================================================================
# toml11 for nitpick.toml parsing (header-only library)
add_subdirectory(vendor/toml11)
# nlohmann/json for LSP JSON-RPC (header-only library)
# No add_subdirectory needed - just include headers
# ============================================================================
# aglob - GlobEngine for file pattern matching (ARIA-010)
# ============================================================================
# Located in nitpick_utils repository, provides FFI-safe glob pattern matching
# for the std.fs.glob module and nitpick_make build system.
set(AGLOB_ROOT ${CMAKE_SOURCE_DIR}/../nitpick_utils/src/aglob)
if(EXISTS ${AGLOB_ROOT}/include)
message(STATUS "Found aglob at: ${AGLOB_ROOT}")
include_directories(${AGLOB_ROOT}/include)
# Add aglob as external project (build if not already built)
if(EXISTS ${AGLOB_ROOT}/build/libaglob.a)
# Use pre-built library
add_library(aglob STATIC IMPORTED)
set_target_properties(aglob PROPERTIES
IMPORTED_LOCATION ${AGLOB_ROOT}/build/libaglob.a
)
message(STATUS "Using pre-built aglob library")
else()
# Build aglob as part of nitpick build
add_subdirectory(${AGLOB_ROOT} ${CMAKE_BINARY_DIR}/aglob)
message(STATUS "Building aglob from source")
endif()
set(AGLOB_FOUND TRUE)
else()
message(WARNING "aglob not found at ${AGLOB_ROOT} - std.fs.glob will not be available")
set(AGLOB_FOUND FALSE)
endif()
if(NOT NITPICK_RUNTIME_ONLY)
# ============================================================================
# Z3 SMT Solver Configuration (v0.2.45 — Static Verification)
# ============================================================================
find_library(Z3_LIBRARY NAMES z3)
find_path(Z3_INCLUDE_DIR NAMES z3.h)
if(Z3_LIBRARY AND Z3_INCLUDE_DIR)
message(STATUS "Found Z3: ${Z3_LIBRARY}")
message(STATUS "Z3 include: ${Z3_INCLUDE_DIR}")
include_directories(${Z3_INCLUDE_DIR})
set(Z3_FOUND TRUE)
else()
message(STATUS "Z3 not found — --verify flag will not be available")
set(Z3_FOUND FALSE)
endif()
# ============================================================================
# NIKOS Abstract Interpretation Engine (v0.4.0 — IKOS LLVM 20 Fork)
# ============================================================================
# Links against pre-built IKOS static libraries for abstract interpretation
# analysis. Requires the nikos repo to be built as a sibling directory.
option(USE_NIKOS "Enable NIKOS abstract interpretation engine" ON)
set(NIKOS_ROOT "${CMAKE_SOURCE_DIR}/../nikos" CACHE PATH "Path to NIKOS source tree")
set(NIKOS_BUILD_DIR "${NIKOS_ROOT}/build" CACHE PATH "Path to NIKOS build directory")
if(USE_NIKOS AND EXISTS ${NIKOS_ROOT}/ar/include AND EXISTS ${NIKOS_BUILD_DIR}/ar/libikos-ar.a
AND EXISTS ${NIKOS_BUILD_DIR}/frontend/llvm/libikos-pp.a)
message(STATUS "Found NIKOS source tree: ${NIKOS_ROOT}")
message(STATUS "Found NIKOS build directory: ${NIKOS_BUILD_DIR}")
# Boost (required by IKOS — filesystem + system)
find_package(Boost 1.55.0 REQUIRED COMPONENTS filesystem system)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
# GMP + GMPXX (required by IKOS — arbitrary precision arithmetic)
find_library(GMP_LIB gmp)
find_library(GMPXX_LIB gmpxx)
find_path(GMP_INCLUDE_DIR gmp.h)
if(GMP_LIB AND GMPXX_LIB AND GMP_INCLUDE_DIR)
include_directories(SYSTEM ${GMP_INCLUDE_DIR})
message(STATUS "Found GMP: ${GMP_LIB}")
message(STATUS "Found GMPXX: ${GMPXX_LIB}")
else()
message(FATAL_ERROR "GMP/GMPXX not found — required by NIKOS. Install with: sudo apt install libgmp-dev")
endif()
# NIKOS include paths (core is header-only, ar and frontend have libs)
include_directories(${NIKOS_ROOT}/core/include)
include_directories(${NIKOS_ROOT}/ar/include)
include_directories(${NIKOS_ROOT}/frontend/llvm/include)
# Import pre-built NIKOS static libraries
add_library(ikos-ar STATIC IMPORTED)
set_target_properties(ikos-ar PROPERTIES
IMPORTED_LOCATION ${NIKOS_BUILD_DIR}/ar/libikos-ar.a)
add_library(ikos-llvm-to-ar STATIC IMPORTED)
set_target_properties(ikos-llvm-to-ar PROPERTIES
IMPORTED_LOCATION ${NIKOS_BUILD_DIR}/frontend/llvm/libikos-llvm-to-ar.a)
# IKOS preprocessing passes (LowerSelect, LowerCstExpr, etc.)
add_library(ikos-pp STATIC IMPORTED)
set_target_properties(ikos-pp PROPERTIES
IMPORTED_LOCATION ${NIKOS_BUILD_DIR}/frontend/llvm/libikos-pp.a)
# Full link set: order matters (ikos-pp and ikos-llvm-to-ar depend on ikos-ar)
set(NIKOS_LIBS ikos-pp ikos-llvm-to-ar ikos-ar ${Boost_LIBRARIES} ${GMP_LIB} ${GMPXX_LIB})
set(NIKOS_FOUND TRUE)
message(STATUS "NIKOS enabled — abstract interpretation analysis available")
else()
if(USE_NIKOS)
message(STATUS "NIKOS not found at ${NIKOS_ROOT} — abstract interpretation disabled")
if(NOT EXISTS ${NIKOS_BUILD_DIR}/ar/libikos-ar.a)
message(STATUS " (Build NIKOS first: cd ${NIKOS_ROOT}/build && cmake .. && make -j)")
endif()
else()
message(STATUS "NIKOS disabled by user (-DUSE_NIKOS=OFF)")
endif()
set(NIKOS_FOUND FALSE)
endif()
else()
# Runtime-only mode: skip Z3 and NIKOS
set(Z3_FOUND FALSE)
set(NIKOS_FOUND FALSE)
endif() # NOT NITPICK_RUNTIME_ONLY (Z3/NIKOS block)
# ============================================================================
# Include directories
# ============================================================================
include_directories(${CMAKE_SOURCE_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/vendor/toml11/include)
include_directories(${CMAKE_SOURCE_DIR}/vendor/json/include)
# ============================================================================
# Source files (will be populated as we implement each phase)
# ============================================================================
# Phase 0: Preprocessor (NASM-style macro system)
set(PREPROCESSOR_SOURCES
src/frontend/preprocessor/preprocessor.cpp
)
# Phase 1: Lexer
set(LEXER_SOURCES
src/frontend/lexer/token.cpp
src/frontend/lexer/lexer.cpp
)
# Phase 2: AST & Parser
set(AST_SOURCES
src/frontend/ast/ast_node.cpp
src/frontend/ast/expr.cpp
src/frontend/ast/stmt.cpp
src/frontend/ast/type.cpp
)
set(PARSER_SOURCES
src/frontend/parser/parser.cpp
# src/frontend/parser/parse_expr.cpp
# src/frontend/parser/parse_stmt.cpp
# src/frontend/parser/parse_type.cpp
# src/frontend/parser/parse_module.cpp
)
# Diagnostics (Phase 7.2)
set(DIAGNOSTICS_SOURCES
src/frontend/diagnostics.cpp
src/frontend/warnings.cpp
)
# Phase 3: Semantic Analysis
set(SEMA_SOURCES
src/frontend/sema/symbol_table.cpp
src/frontend/sema/type.cpp
src/frontend/sema/module_table.cpp
src/frontend/sema/module_loader.cpp
src/frontend/sema/type_checker.cpp
src/frontend/sema/type_checker_call.cpp
src/frontend/sema/type_checker_expr.cpp
src/frontend/sema/type_checker_stmts.cpp
src/frontend/sema/exhaustiveness.cpp
src/frontend/sema/definite_assignment.cpp
src/frontend/sema/borrow_checker.cpp
src/frontend/sema/liveness_analysis.cpp
src/frontend/sema/generic_resolver.cpp
src/frontend/sema/module_resolver.cpp
src/frontend/sema/closure_analyzer.cpp
src/frontend/sema/visibility_checker.cpp
src/frontend/sema/async_analyzer.cpp
src/frontend/sema/const_evaluator.cpp
src/frontend/sema/safety_checker.cpp
src/semantic/literal_converter.cpp
)
# Phase 3.5: Static Verification (Z3 SMT solver + NIKOS abstract interpretation)
set(VERIFY_SOURCES
src/analysis/range_analysis.cpp
)
if(Z3_FOUND)
list(APPEND VERIFY_SOURCES src/analysis/z3_verifier.cpp)
endif()
if(NIKOS_FOUND)
list(APPEND VERIFY_SOURCES src/analysis/nikos_bridge.cpp)
list(APPEND VERIFY_SOURCES src/analysis/nikos_analyzer.cpp)
list(APPEND VERIFY_SOURCES src/analysis/nikos_cross_validator.cpp)
list(APPEND VERIFY_SOURCES src/analysis/nikos_warning_promoter.cpp)
# NKS-022: SQLite DB reader (compiled even without SQLite3 guard,
# but only contains code under #ifdef NITPICK_HAS_SQLITE3)
list(APPEND VERIFY_SOURCES src/analysis/nikos_db_reader.cpp)
# NUI-012: HTML report generator
list(APPEND VERIFY_SOURCES src/analysis/nikos_html_report.cpp)
endif()
# NKS-022: SQLite3 optional dependency for NIKOS database reader
find_package(SQLite3)
if(SQLite3_FOUND)
message(STATUS "SQLite3 ${SQLite3_VERSION} found — NIKOS DB reader enabled")
else()
message(STATUS "SQLite3 not found — NIKOS DB reader disabled (text parsing fallback)")
endif()
# Phase 4: IR Generation
set(IR_SOURCES
src/backend/ir/ir_generator.cpp
src/backend/ir/tbb_codegen.cpp
src/backend/ir/ternary_codegen.cpp
src/backend/ir/codegen_expr.cpp
src/backend/ir/codegen_expr_binary.cpp
src/backend/ir/codegen_expr_call.cpp
src/backend/ir/codegen_expr_compound.cpp
# codegen_stmt.cpp removed in v0.26.3.1 (was dead code, never instantiated;
# variable lowering lives in ir_generator.cpp). Backup at
# META/NITPICK/ROADMAP/0.26/0.26.3.x/_dead_code_backup/.
# src/backend/ir/type_mapper.cpp
# src/backend/ir/memory_codegen.cpp
# SYS-038: Architecture abstraction layer (v0.56.10)
src/backend/arch/syscall_abi.cpp
)
# Phase 5: Runtime
set(RUNTIME_SOURCES
src/runtime/gc/allocator.cpp
src/runtime/gc/gc.cpp
src/runtime/allocators/wild_alloc.cpp
src/runtime/allocators/wildx_alloc.cpp
src/runtime/allocators/arena_alloc.cpp
src/runtime/allocators/pool_alloc.cpp
src/runtime/allocators/slab_alloc.cpp
src/runtime/allocators/arena_builtins.cpp
src/runtime/allocators/pool_builtins.cpp
src/runtime/allocators/slab_builtins.cpp
src/runtime/allocators/mem_primitives.c
src/runtime/allocators/handle_alloc.cpp # npk_handle_* generational arena ABI
# NitpickAlloc — Native memory allocator (v0.59.x)
src/runtime/mem/vm.cpp
src/runtime/mem/size_class.cpp
src/runtime/mem/slab.cpp
src/runtime/mem/allocator_core.cpp
src/runtime/mem/ebr.cpp
src/runtime/mem/calloc_ralloc.cpp
src/runtime/mem/mem_utils.cpp
src/runtime/mem/hardened.cpp
src/runtime/mem/tlc.cpp
src/runtime/mem/cpu_cache.cpp
src/runtime/mem/npk_mem_contracts.cpp
src/runtime/panic/panic_handler.cpp
src/runtime/format/locale_safe_format.cpp
src/runtime/assembler/assembler.cpp
src/runtime/assembler/llvm_jit.cpp
src/runtime/assembler/code_cache.cpp
src/runtime/assembler/jit_smoke.cpp
src/runtime/jit_gdb.cpp
src/runtime/assembler/aarch64_encoder.cpp
src/runtime/assembler/cpuid.cpp
src/runtime/io/io.cpp
src/runtime/io/zero_copy_bridge.cpp
src/runtime/streams/streams.cpp
src/runtime/process/process.cpp
src/runtime/thread/thread.cpp
src/runtime/thread/thread_shim.cpp
src/runtime/thread/thread_pool_shim.cpp
src/runtime/thread/lockfree_shim.c
src/backend/runtime/ternary_ops.cpp
src/backend/runtime/frac_ops.cpp
src/backend/runtime/tfp_ops.cpp
src/backend/runtime/vec9_ops.cpp
src/backend/runtime/tmatrix_ops.cpp
src/backend/runtime/matrix_ops.cpp
src/backend/runtime/tensor_ops.cpp
src/backend/runtime/ttensor_ops.cpp
src/runtime/atomic/atomic.cpp
src/runtime/atomic/atomic_shim.cpp
src/runtime/int_array.cpp
src/runtime/timer/timer.cpp
src/runtime/async/executor.cpp
src/runtime/async/coroutine.cpp
src/runtime/async/runtime_api.cpp
src/runtime/async/async_io.cpp
src/runtime/async/async_io_api.cpp
src/runtime/async/event_loop.cpp
src/runtime/async/async_net.cpp
src/runtime/async/io_uring.cpp
src/runtime/async/file_stream.cpp
src/runtime/async/work_stealing.cpp
src/runtime/async/net_shim.cpp
src/runtime/async/gc_integration.cpp
src/runtime/telemetry/telemetry.cpp
src/runtime/args/args.c
src/runtime/exotic_types.c
src/runtime/os/os_shim.c
src/runtime/os/aifs_shim.c
src/runtime/os/hexstream_shim.c
src/runtime/security/seccomp.c
)
# v0.86.1 (ARM-001): Exclude LLVM-dependent sources in runtime-only mode
if(NITPICK_RUNTIME_ONLY)
list(REMOVE_ITEM RUNTIME_SOURCES src/runtime/assembler/llvm_jit.cpp)
message(STATUS "Excluded llvm_jit.cpp from runtime (no LLVM in runtime-only mode)")
endif()
# Phase 6: Standard Library Runtime Support
set(STDLIB_SOURCES
src/runtime/stdlib/stdlib.cpp
src/runtime/result/result.cpp
src/runtime/collections/collections.cpp
src/runtime/collections/map.cpp
src/runtime/collections/collection_helpers.cpp
src/runtime/collections/ustack.cpp
src/runtime/collections/uhash.cpp
src/runtime/collections/alist.cpp
src/runtime/collections/astringlist.cpp
src/runtime/strings/strings.cpp
src/runtime/strings/string_helpers.cpp
src/runtime/json/json_helpers.cpp
src/runtime/toml/toml_helpers.cpp
src/runtime/binary/binary_helpers.cpp
src/runtime/lex/lex_helpers.cpp
src/runtime/ast/ast_helpers.cpp
src/runtime/sema/sema_helpers.cpp
src/runtime/sema/pass_helpers.cpp
src/runtime/sema/visibility_shim.cpp
src/runtime/sema/async_shim.cpp
src/runtime/sema/diagnostics_shim.cpp
src/runtime/sema/module_table_shim.cpp
src/runtime/sema/definite_assignment_shim.cpp
src/runtime/sema/closure_analyzer_shim.cpp
src/runtime/sema/warnings_shim.cpp
src/runtime/sema/module_resolver_shim.cpp
src/runtime/sema/usage_stats_shim.cpp
src/runtime/sema/doc_generator_shim.cpp
src/runtime/sema/pkg_manager_shim.cpp
src/runtime/sema/project_config_shim.cpp
src/runtime/net/net.cpp
src/runtime/math/math.cpp
src/runtime/math/lbim.cpp
src/runtime/math/lbim_extended.cpp
src/runtime/math/fix256.cpp
src/runtime/math/fix32.cpp
src/runtime/math/fix64.cpp
src/runtime/math/fix128.cpp
src/runtime/tbb/tbb.cpp
src/runtime/fmt/formatters.cpp
src/runtime/fmt/string_format.cpp
src/runtime/fmt/table.cpp
)
# ARIA-017: High-Precision Floating-Point (flt256, flt512)
set(HIGHPREC_SOURCES
src/runtime/highprec_float.cpp
src/runtime/highprec_simd.cpp
)
# Phase 5.4: Integration Pipeline — AST converter + validation
# These frontend sources are LLVM-free and needed by pipeline_helpers.cpp
# to convert self-hosted ASTNodeCompat trees to native C++ AST nodes.
# Added ONLY to nitpick_runtime (npkc already has them via NITPICK_SOURCES).
set(PIPELINE_SOURCES
src/frontend/ast/ast_node.cpp
src/frontend/ast/expr.cpp
src/frontend/ast/stmt.cpp
src/frontend/ast/type.cpp
src/frontend/lexer/token.cpp
src/frontend/lexer/lexer.cpp
src/frontend/parser/parser.cpp
src/runtime/pipeline/pipeline_helpers.cpp
)
# Phase 7: Tooling
set(TOOLS_SOURCES
src/tools/project_config.cpp
src/tools/lsp/transport.cpp
src/tools/lsp/server.cpp
src/tools/lsp/vfs.cpp
src/tools/lsp/work_queue.cpp
src/tools/lsp/thread_pool.cpp
src/tools/debugger/web_server.cpp
)
# Phase 7.4: Debugger (optional, requires LLDB)
if(LLDB_FOUND)
set(DEBUGGER_SOURCES
src/tools/debugger/npk_formatters.cpp
src/tools/debugger/dap_server.cpp
src/tools/debugger/async_debugger.cpp
src/tools/debugger/memory_visualizer.cpp
)
endif()
# Phase 7.5: Package Manager
# PKG_SOURCES removed
# Phase 7.6: Documentation Generator
set(DOC_SOURCES
src/tools/doc/parser.cpp
src/tools/doc/generator.cpp
)
# Combine all sources
set(NITPICK_SOURCES
${PREPROCESSOR_SOURCES}
${LEXER_SOURCES}
${AST_SOURCES}
${PARSER_SOURCES}
${DIAGNOSTICS_SOURCES}
${SEMA_SOURCES}
${VERIFY_SOURCES}
${IR_SOURCES}
${RUNTIME_SOURCES}
${STDLIB_SOURCES}
${TOOLS_SOURCES}
)
# ============================================================================
# Runtime library (for compiled Nitpick programs)
# ============================================================================
# Static runtime library that gets linked into all Nitpick executables
add_library(nitpick_runtime STATIC
${RUNTIME_SOURCES}
${STDLIB_SOURCES}
${HIGHPREC_SOURCES}
${PIPELINE_SOURCES}
)
# ARIA-017: Enable AVX-512 and ADX intrinsics for high-precision floating-point
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-mavx512f" COMPILER_SUPPORTS_AVX512F)
check_cxx_compiler_flag("-mavx2" COMPILER_SUPPORTS_AVX2)
check_cxx_compiler_flag("-madx" COMPILER_SUPPORTS_ADX)
check_cxx_compiler_flag("-mbmi2" COMPILER_SUPPORTS_BMI2)
if(COMPILER_SUPPORTS_AVX512F)
# Removing forced COMPILE_FLAGS as they cause SIGILL on non-AVX512 CPUs (e.g. CI runners)
# set_source_files_properties(src/runtime/highprec_simd.cpp PROPERTIES
# COMPILE_FLAGS "-mavx512f -mavx512vl -mavx512dq -mavx2 -madx -mbmi2"
# )
message(STATUS "ARIA-017: AVX-512 SIMD available in compiler, but disabled to prevent SIGILL. Use -march=native for local builds.")
elseif(COMPILER_SUPPORTS_AVX2)
# set_source_files_properties(src/runtime/highprec_simd.cpp PROPERTIES
# COMPILE_FLAGS "-mavx2 -madx -mbmi2"
# )
message(STATUS "ARIA-017: AVX2 available in compiler, but disabled to prevent SIGILL. Use -march=native for local builds.")
else()
message(STATUS "ARIA-017: Using portable implementation for high-precision arithmetic")
endif()
# ============================================================================
# v0.59.11: rseq (restartable sequences) detection for per-CPU cache
# ============================================================================
# rseq provides the fastest possible CPU ID on Linux 4.18+ / glibc 2.35+.
# If available, cpu_cache.cpp uses __rseq_current_cpu() (~1ns vs ~5ns RDTSCP).
include(CheckCSourceCompiles)
check_c_source_compiles("
#include <sys/rseq.h>
extern __thread ptrdiff_t __rseq_offset;
extern unsigned int __rseq_size;
int main(void) { return (int)__rseq_size; }
" HAS_RSEQ)
if(HAS_RSEQ)
message(STATUS "rseq support detected — per-CPU cache will use rseq fast path (~1ns)")
target_compile_definitions(nitpick_runtime PRIVATE HAS_RSEQ=1)
else()
message(STATUS "rseq not available — per-CPU cache will use RDTSCP/sched_getcpu fallback")
endif()
# Link aglob for std.fs.glob support (ARIA-010)
if(AGLOB_FOUND)
target_link_libraries(nitpick_runtime aglob atomic)
message(STATUS "nitpick_runtime linked with aglob and atomic for glob and atomics support")
endif()
# Install runtime library so the compiler can find it
install(TARGETS nitpick_runtime DESTINATION lib)
# ============================================================================
# WASM Runtime Library (for WebAssembly compilation target)
# ============================================================================
# Cross-compiled with clang --target=wasm32-wasi to produce libnitpick_runtime_wasm.a
# This is a stripped-down runtime: no threads, no io_uring, no fork/exec, no signals
set(WASM_RUNTIME_SOURCE ${CMAKE_SOURCE_DIR}/src/runtime/wasm/wasm_runtime.c)
set(WASM_RUNTIME_OUTPUT ${CMAKE_BINARY_DIR}/libnitpick_runtime_wasm.a)
set(WASM_SYSROOT_INCLUDE "/usr/include/wasm32-wasi")
set(WASM_SYSROOT_LIB "/usr/lib/wasm32-wasi")
# Only build WASM runtime if wasi-libc sysroot exists
if(EXISTS ${WASM_SYSROOT_INCLUDE} AND EXISTS ${WASM_RUNTIME_SOURCE})
find_program(CLANG_EXECUTABLE NAMES clang-20 clang)
find_program(WASM_AR_EXECUTABLE NAMES llvm-ar-20 llvm-ar)
if(CLANG_EXECUTABLE AND WASM_AR_EXECUTABLE)
add_custom_command(
OUTPUT ${WASM_RUNTIME_OUTPUT}
COMMAND ${CLANG_EXECUTABLE}
--target=wasm32-wasi
--sysroot=/usr
-I${WASM_SYSROOT_INCLUDE}
-O2
-c ${WASM_RUNTIME_SOURCE}
-o ${CMAKE_BINARY_DIR}/wasm_runtime.o
COMMAND ${WASM_AR_EXECUTABLE} rcs
${WASM_RUNTIME_OUTPUT}
${CMAKE_BINARY_DIR}/wasm_runtime.o
DEPENDS ${WASM_RUNTIME_SOURCE}
COMMENT "Building WASM runtime library (libnitpick_runtime_wasm.a)"
)
add_custom_target(nitpick_runtime_wasm ALL DEPENDS ${WASM_RUNTIME_OUTPUT})
message(STATUS "WASM runtime will be built: ${WASM_RUNTIME_OUTPUT}")
else()
message(STATUS "WASM runtime skipped: clang or llvm-ar not found")
endif()
else()
if(NOT EXISTS ${WASM_SYSROOT_INCLUDE})
message(STATUS "WASM runtime skipped: wasi-libc sysroot not found at ${WASM_SYSROOT_INCLUDE}")
endif()
if(NOT EXISTS ${WASM_RUNTIME_SOURCE})
message(STATUS "WASM runtime skipped: source not found at ${WASM_RUNTIME_SOURCE}")
endif()
endif()
# ============================================================================
# Compiler executable
# ============================================================================
if(NOT NITPICK_RUNTIME_ONLY)
# Main compiler executable
add_executable(npkc src/main.cpp ${NITPICK_SOURCES})
set(NPKC_LINK_LIBS ${llvm_libs} uring atomic)
if(Z3_FOUND)
list(APPEND NPKC_LINK_LIBS ${Z3_LIBRARY})
target_compile_definitions(npkc PRIVATE NITPICK_HAS_Z3=1)
endif()
if(NIKOS_FOUND)
list(APPEND NPKC_LINK_LIBS ${NIKOS_LIBS})
target_compile_definitions(npkc PRIVATE NITPICK_HAS_NIKOS=1)
endif()
if(SQLite3_FOUND)
list(APPEND NPKC_LINK_LIBS SQLite::SQLite3)
target_compile_definitions(npkc PRIVATE NITPICK_HAS_SQLITE3=1)
endif()
# NTU-004: Link ftxui and define NITPICK_HAS_TUI for npkc
if(NITPICK_HAS_TUI)
target_compile_definitions(npkc PRIVATE NITPICK_HAS_TUI=1)
target_link_libraries(npkc ftxui::screen ftxui::dom ftxui::component)
endif()
target_link_libraries(npkc ${NPKC_LINK_LIBS})
# NTU-005: TUI source files (only compiled when NITPICK_HAS_TUI is ON)
if(NITPICK_HAS_TUI)
target_sources(npkc PRIVATE
src/tui/nikos_tui.cpp
src/tui/summary_bar.cpp
src/tui/filter_bar.cpp
src/tui/check_table.cpp
src/tui/detail_panel.cpp
)
endif()
# Testing compiler executable (separate binary for testing without disrupting fuzzer)
# Build with: cmake --build build --target npkc_testing
add_executable(npkc_testing src/main.cpp ${NITPICK_SOURCES})
set(NPKC_TEST_LINK_LIBS ${llvm_libs} uring atomic)
if(Z3_FOUND)
list(APPEND NPKC_TEST_LINK_LIBS ${Z3_LIBRARY})
target_compile_definitions(npkc_testing PRIVATE NITPICK_HAS_Z3=1)
endif()
if(NIKOS_FOUND)
list(APPEND NPKC_TEST_LINK_LIBS ${NIKOS_LIBS})
target_compile_definitions(npkc_testing PRIVATE NITPICK_HAS_NIKOS=1)
endif()
if(SQLite3_FOUND)
list(APPEND NPKC_TEST_LINK_LIBS SQLite::SQLite3)
target_compile_definitions(npkc_testing PRIVATE NITPICK_HAS_SQLITE3=1)
endif()
target_link_libraries(npkc_testing ${NPKC_TEST_LINK_LIBS})
# ============================================================================
# Precompiled Headers (v0.8.2) — Cut build time by pre-parsing LLVM headers
# ============================================================================
# LLVM headers are large and included in many translation units. PCH avoids
# re-parsing them for each .cpp file, significantly reducing compile time.
set(NITPICK_PCH_HEADER ${CMAKE_SOURCE_DIR}/include/npk_pch.h)
# Separate C++ sources that benefit from PCH (exclude .c files)
# PCH with LLVM headers only makes sense for C++ translation units
set_source_files_properties(
${PREPROCESSOR_SOURCES} ${LEXER_SOURCES} ${AST_SOURCES} ${PARSER_SOURCES}
${DIAGNOSTICS_SOURCES} ${SEMA_SOURCES} ${VERIFY_SOURCES} ${IR_SOURCES}
${TOOLS_SOURCES} src/main.cpp
PROPERTIES SKIP_PRECOMPILE_HEADERS OFF
)
target_precompile_headers(npkc PRIVATE ${NITPICK_PCH_HEADER})
# v0.35.7: keep 'nitpickc' alias in the build dir so legacy build scripts continue
# to work without changes while the ecosystem migrates to npkc.
add_custom_command(TARGET npkc POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:npkc> ${CMAKE_BINARY_DIR}/nitpickc
COMMENT "Updating nitpickc alias → npkc (backward compat, POLISH-002)")
# C source files must not use the C++ PCH
set_source_files_properties(
src/runtime/allocators/mem_primitives.c
src/runtime/args/args.c
src/runtime/exotic_types.c
src/runtime/os/os_shim.c
src/runtime/os/aifs_shim.c
src/runtime/os/hexstream_shim.c
src/runtime/thread/lockfree_shim.c
src/runtime/security/seccomp.c
PROPERTIES SKIP_PRECOMPILE_HEADERS ON
)
target_precompile_headers(npkc_testing REUSE_FROM npkc)
message(STATUS "Precompiled headers enabled for npkc (LLVM + stdlib, CXX only)")
# LSP server executable
add_executable(npk-ls src/tools/lsp/npk-ls.cpp
${TOOLS_SOURCES}
${DIAGNOSTICS_SOURCES}
${LEXER_SOURCES}
${PARSER_SOURCES}
${AST_SOURCES}
${SEMA_SOURCES}
src/lsp/nikos_lsp_serializer.cpp # NLS-007: NIKOS LSP serializer
)
# LSP server needs lexer, parser, diagnostics, sema, and NIKOS (conditional)
if(NIKOS_FOUND)
target_compile_definitions(npk-ls PRIVATE NITPICK_HAS_NIKOS)
target_link_libraries(npk-ls ${llvm_libs} ${NIKOS_LIBS})
message(STATUS "npk-ls: NIKOS integration ENABLED (NLS-015)")
else()
target_link_libraries(npk-ls ${llvm_libs})
message(STATUS "npk-ls: NIKOS integration DISABLED (NIKOS not found)")
endif()
# DAP server executable
if(LLDB_FOUND)
add_executable(npk-dap
src/tools/debugger/npk_dap.cpp
${DEBUGGER_SOURCES}
)
target_include_directories(npk-dap PRIVATE ${LLDB_INCLUDE_DIRS})
target_link_libraries(npk-dap ${LLDB_LIBRARY})
message(STATUS "Building DAP server: npk-dap")
message(STATUS "LLDB include dirs for npk-dap: ${LLDB_INCLUDE_DIRS}")
else()
message(STATUS "LLDB not found - DAP server will not be built")
endif()
# npkpkg target removed
# Documentation generator executable
add_executable(npk-doc
src/tools/doc/main.cpp
${DOC_SOURCES}
)
target_link_libraries(npk-doc)
# ============================================================================
# Installation
# ============================================================================
install(TARGETS npkc DESTINATION bin)
install(TARGETS npk-doc DESTINATION bin)
install(PROGRAMS $<TARGET_FILE:npkc> DESTINATION bin RENAME nitpickc) # backward compat alias
install(DIRECTORY lib/std DESTINATION lib/nitpick)
install(FILES cmake/FindNitpick.cmake DESTINATION share/nitpick/cmake)
# ============================================================================
# Print configuration summary
# ============================================================================
message(STATUS "")
message(STATUS "============================================")
message(STATUS "Nitpick Compiler Configuration")
message(STATUS "============================================")
message(STATUS "Version: ${PROJECT_VERSION}")
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "C++ Standard: ${CMAKE_CXX_STANDARD}")
message(STATUS "LLVM Version: ${LLVM_PACKAGE_VERSION}")
message(STATUS "NIKOS (IKOS): ${NIKOS_FOUND}")
message(STATUS "Z3 Solver: ${Z3_FOUND}")
message(STATUS "AddressSanitizer: ${USE_ASAN}")
message(STATUS "Code Coverage: ${USE_COVERAGE}")
message(STATUS "============================================")
message(STATUS "")
endif() # NOT NITPICK_RUNTIME_ONLY (compiler/tools/install block)
# ============================================================================
# Testing
# ============================================================================
enable_testing()
# Test runner (Phase 0.2) — only if test_runner.cpp exists (gitignored in dev)
if(EXISTS "${CMAKE_SOURCE_DIR}/tests/test_runner.cpp")
add_subdirectory(tests)
endif()