Files
R8Forge/CMakeLists.txt
T
dsh a56a12f132 r8forge --opt: the peephole pass is part of the assembler now
The pass moved out of tests/tape_opt.cc into src/tape_opt.cc with a header
(rot8_optimize(tape, cell_size)), so both entry points share one implementation:

  r8forge --opt file.r8asm > t.rot8     assemble, then optimise in memory
  r8forge_tape_opt t.rot8 t2.rot8       optimise a tape assembled earlier

--opt is peeled off argv before the rest of the parsing, so it can appear
anywhere and the existing flags are untouched; without it the output is byte for
byte what it was (flagship 64513).

Measured: flagship 64513 -> 58060 (-10.0%), calculator 62585 -> 54863 (-12.3%),
and "12 34 + ." still prints the same out stream from the optimised calculator.
ctest 8/8 still green.
2026-11-18 10:34:30 +08:00

87 lines
4.0 KiB
CMake

cmake_minimum_required(VERSION 3.10)
project(R8Forge)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
include_directories(include)
# The width of a cell. 11 is the project default; the tests and the VMs follow
# it, so `-DR8FORGE_CELL_SIZE=16` builds an entirely 16 bit toolchain.
set(R8FORGE_CELL_SIZE 11 CACHE STRING "bits per cell (1..32)")
add_compile_definitions(R8FORGE_CELL_SIZE=${R8FORGE_CELL_SIZE})
find_package(Threads REQUIRED)
add_library(r8forge_core src/r8asm.cc src/synth.cc src/tape_opt.cc)
target_link_libraries(r8forge_core PUBLIC Threads::Threads)
# 别再 set(CMAKE_CXX_FLAGS ...) 了:那会把默认 flag 整个换掉,MSVC 下丢 /EHsc、
# 还会把 -O3 塞进 Debug 和 /RTC1 打架。Release 配置本来就带 -O3 / /O2 和 NDEBUG。
if(NOT MSVC)
add_compile_options($<$<CONFIG:Release>:-march=native>)
endif()
add_executable(r8forge tests/asm_test.cc)
target_link_libraries(r8forge r8forge_core)
add_executable(r8forge_synth_test tests/synth_test.cc)
target_link_libraries(r8forge_synth_test r8forge_core)
add_executable(r8forge_derive src/derive.cc)
target_link_libraries(r8forge_derive r8forge_core)
# A second, independent ROT-8 interpreter: runs a .rot8 file with no assembler
# and no macros involved, so its verdict can be checked against r8forge_derive.
add_executable(r8forge_tape_run tests/tape_run.cc)
# Runs the byte level library macros (raw_add / raw_and / raw_or / raw_xor /
# raw_inc) over every input combination.
add_executable(r8forge_byte_op_test tests/byte_op_test.cc)
target_link_libraries(r8forge_byte_op_test r8forge_core)
# Checks that every %macro in asm/ carries a doc comment in the house format.
add_executable(r8forge_macro_docs_test tests/macro_docs_test.cc)
# Runs every examples/*.r8asm as a stand alone program and compares its OUT
# stream with the `; out ...` line in the file header.
add_executable(r8forge_examples_test tests/examples_test.cc)
target_link_libraries(r8forge_examples_test r8forge_core)
# The tape level peephole pass: three run-local rules, no bracket bookkeeping.
add_executable(r8forge_tape_opt tests/tape_opt.cc)
target_link_libraries(r8forge_tape_opt r8forge_core)
add_executable(r8forge_cost_par tests/cost_par.cc)
target_link_libraries(r8forge_cost_par r8forge_core)
add_executable(r8forge_cost_search tests/cost_search.cc)
target_link_libraries(r8forge_cost_search r8forge_core)
# ---- tests ------------------------------------------------------------------
# `ctest --test-dir build -j` runs the whole baseline. Every entry is a program
# under tests/ that exits non zero on failure; the working directory is the repo
# root because the drivers use relative paths.
#
# Labels: `widthfree` means "true at any cell width" (bit level slices, the
# synthesizer, the looping demo, the macro comment format). Everything else
# assumes the default 11 bit geometry -- examples/ fixes 2047 style values and
# byte_op_test drives the 8/11 bit word macros -- so a CI matrix over
# -DR8FORGE_CELL_SIZE runs only the widthfree set.
enable_testing()
set(R8FORGE_TEST_DIR ${CMAKE_CURRENT_SOURCE_DIR})
add_test(NAME flagship COMMAND r8forge asm/test.r8asm)
add_test(NAME byte_ops COMMAND r8forge_byte_op_test)
add_test(NAME examples COMMAND r8forge_examples_test examples)
add_test(NAME synth_full_add COMMAND r8forge_synth_test examples/full_add.r8asm)
add_test(NAME bit_add_slice COMMAND r8forge verify_clb_bit_add_nc.r8asm)
add_test(NAME bit_inc_slice COMMAND r8forge verify_clb_bit_inc_nc.r8asm)
add_test(NAME loop_derive COMMAND r8forge_derive verify_loop.r8asm -1 0=5)
add_test(NAME macro_docs COMMAND r8forge_macro_docs_test)
set_tests_properties(flagship byte_ops examples PROPERTIES LABELS "default-width")
set_tests_properties(synth_full_add bit_add_slice bit_inc_slice loop_derive
macro_docs PROPERTIES LABELS "widthfree")
set_tests_properties(flagship byte_ops examples synth_full_add bit_add_slice
bit_inc_slice loop_derive macro_docs
PROPERTIES WORKING_DIRECTORY ${R8FORGE_TEST_DIR})