feat: add compiler installation step
- Ref: add `-debug` suffix to debug targets - Ref: remove `-release` suffix from release targets - Feat: add `make install` command - Feat: add cmake variables: - `FZL_TESTS` for enable testing - `FZL_SKIP_C` to not build the compiler - `FZL_SKIP_VM` to not build the vm
This commit is contained in:
+123
-104
@@ -8,6 +8,7 @@ add_compile_options(-Wall -Wextra -Werror=implicit-function-declaration)
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
add_compile_options(-fsanitize=address,undefined -g)
|
||||
add_link_options(-fsanitize=address,undefined)
|
||||
set(FZL_TESTS TRUE)
|
||||
endif()
|
||||
|
||||
include_directories(include)
|
||||
@@ -29,119 +30,137 @@ set(CMAKE_SUPPRESS_DEVELOPER_WARNINGS ${PREV_SUPPRESS_DEV} CACHE INTERNAL "")
|
||||
# --------------
|
||||
|
||||
# Compiler
|
||||
add_executable(fzc
|
||||
src/compiler/utils/fzl_const_pool.c
|
||||
src/compiler/utils/fzl_symtable.c
|
||||
src/compiler/utils/fzl_linked.c
|
||||
src/compiler/utils/fzl_options.c
|
||||
src/compiler/utils/fzl_ctable.c
|
||||
src/compiler/analyzer/utility.c
|
||||
src/compiler/analyzer/context.c
|
||||
src/compiler/analyzer/an_assign.c
|
||||
src/compiler/analyzer/an_binmath.c
|
||||
src/compiler/analyzer/an_block.c
|
||||
src/compiler/analyzer/an_break.c
|
||||
src/compiler/analyzer/an_call.c
|
||||
src/compiler/analyzer/an_class.c
|
||||
src/compiler/analyzer/an_common.c
|
||||
src/compiler/analyzer/an_condition.c
|
||||
src/compiler/analyzer/an_conditional.c
|
||||
src/compiler/analyzer/an_construct.c
|
||||
src/compiler/analyzer/an_declaration.c
|
||||
src/compiler/analyzer/an_field.c
|
||||
src/compiler/analyzer/an_function.c
|
||||
src/compiler/analyzer/an_identifier.c
|
||||
src/compiler/analyzer/an_loop.c
|
||||
src/compiler/analyzer/an_return.c
|
||||
src/compiler/analyzer/an_strfmt.c
|
||||
src/compiler/analyzer/an_unarycond.c
|
||||
src/compiler/analyzer/an_unarymath.c
|
||||
src/compiler/parser/pa_and.c
|
||||
src/compiler/parser/pa_assignment.c
|
||||
src/compiler/parser/pa_block.c
|
||||
src/compiler/parser/pa_break.c
|
||||
src/compiler/parser/pa_class.c
|
||||
src/compiler/parser/pa_cond.c
|
||||
src/compiler/parser/pa_expression.c
|
||||
src/compiler/parser/pa_factor.c
|
||||
src/compiler/parser/pa_for.c
|
||||
src/compiler/parser/pa_function.c
|
||||
src/compiler/parser/pa_if.c
|
||||
src/compiler/parser/pa_loop.c
|
||||
src/compiler/parser/pa_new.c
|
||||
src/compiler/parser/pa_or.c
|
||||
src/compiler/parser/pa_postfix.c
|
||||
src/compiler/parser/pa_power.c
|
||||
src/compiler/parser/pa_primary.c
|
||||
src/compiler/parser/pa_program.c
|
||||
src/compiler/parser/pa_return.c
|
||||
src/compiler/parser/pa_statement.c
|
||||
src/compiler/parser/pa_term.c
|
||||
src/compiler/parser/pa_unary.c
|
||||
src/compiler/parser/pa_while.c
|
||||
src/compiler/parser/utility.c
|
||||
src/compiler/reader/rd_fmtstr.c
|
||||
src/compiler/reader/rd_name.c
|
||||
src/compiler/reader/rd_number.c
|
||||
src/compiler/reader/rd_string_literal.c
|
||||
src/compiler/reader/utility.c
|
||||
src/compiler/fzl_analyzer.c
|
||||
src/compiler/fzl_debug.c
|
||||
src/compiler/fzl_parser.c
|
||||
src/compiler/fzl_reader.c
|
||||
src/compiler/fzl_token.c
|
||||
src/compiler/fzl_walker.c
|
||||
src/compiler/fzl_writer.c
|
||||
src/compiler/main.c)
|
||||
if (NOT FZL_SKIP_C)
|
||||
add_executable(fzc
|
||||
src/compiler/utils/fzl_const_pool.c
|
||||
src/compiler/utils/fzl_symtable.c
|
||||
src/compiler/utils/fzl_linked.c
|
||||
src/compiler/utils/fzl_options.c
|
||||
src/compiler/utils/fzl_ctable.c
|
||||
src/compiler/analyzer/utility.c
|
||||
src/compiler/analyzer/context.c
|
||||
src/compiler/analyzer/an_assign.c
|
||||
src/compiler/analyzer/an_binmath.c
|
||||
src/compiler/analyzer/an_block.c
|
||||
src/compiler/analyzer/an_break.c
|
||||
src/compiler/analyzer/an_call.c
|
||||
src/compiler/analyzer/an_class.c
|
||||
src/compiler/analyzer/an_common.c
|
||||
src/compiler/analyzer/an_condition.c
|
||||
src/compiler/analyzer/an_conditional.c
|
||||
src/compiler/analyzer/an_construct.c
|
||||
src/compiler/analyzer/an_declaration.c
|
||||
src/compiler/analyzer/an_field.c
|
||||
src/compiler/analyzer/an_function.c
|
||||
src/compiler/analyzer/an_identifier.c
|
||||
src/compiler/analyzer/an_loop.c
|
||||
src/compiler/analyzer/an_return.c
|
||||
src/compiler/analyzer/an_strfmt.c
|
||||
src/compiler/analyzer/an_unarycond.c
|
||||
src/compiler/analyzer/an_unarymath.c
|
||||
src/compiler/parser/pa_and.c
|
||||
src/compiler/parser/pa_assignment.c
|
||||
src/compiler/parser/pa_block.c
|
||||
src/compiler/parser/pa_break.c
|
||||
src/compiler/parser/pa_class.c
|
||||
src/compiler/parser/pa_cond.c
|
||||
src/compiler/parser/pa_expression.c
|
||||
src/compiler/parser/pa_factor.c
|
||||
src/compiler/parser/pa_for.c
|
||||
src/compiler/parser/pa_function.c
|
||||
src/compiler/parser/pa_if.c
|
||||
src/compiler/parser/pa_loop.c
|
||||
src/compiler/parser/pa_new.c
|
||||
src/compiler/parser/pa_or.c
|
||||
src/compiler/parser/pa_postfix.c
|
||||
src/compiler/parser/pa_power.c
|
||||
src/compiler/parser/pa_primary.c
|
||||
src/compiler/parser/pa_program.c
|
||||
src/compiler/parser/pa_return.c
|
||||
src/compiler/parser/pa_statement.c
|
||||
src/compiler/parser/pa_term.c
|
||||
src/compiler/parser/pa_unary.c
|
||||
src/compiler/parser/pa_while.c
|
||||
src/compiler/parser/utility.c
|
||||
src/compiler/reader/rd_fmtstr.c
|
||||
src/compiler/reader/rd_name.c
|
||||
src/compiler/reader/rd_number.c
|
||||
src/compiler/reader/rd_string_literal.c
|
||||
src/compiler/reader/utility.c
|
||||
src/compiler/fzl_analyzer.c
|
||||
src/compiler/fzl_debug.c
|
||||
src/compiler/fzl_parser.c
|
||||
src/compiler/fzl_reader.c
|
||||
src/compiler/fzl_token.c
|
||||
src/compiler/fzl_walker.c
|
||||
src/compiler/fzl_writer.c
|
||||
src/compiler/main.c)
|
||||
endif ()
|
||||
|
||||
# Virtual machine
|
||||
add_executable(fz
|
||||
src/vm/handlers/group_and_or.c
|
||||
src/vm/handlers/group_cmp.c
|
||||
src/vm/handlers/group_ctx.c
|
||||
src/vm/handlers/group_flow.c
|
||||
src/vm/handlers/group_fn.c
|
||||
src/vm/handlers/group_math.c
|
||||
src/vm/handlers/group_not.c
|
||||
src/vm/handlers/group_obj.c
|
||||
src/vm/handlers/group_objcmp.c
|
||||
src/vm/handlers/group_stack.c
|
||||
src/vm/handlers/group_str.c
|
||||
src/vm/handlers/group_strcmp.c
|
||||
src/vm/handlers/master.c
|
||||
src/vm/fzl_vm.c
|
||||
src/vm/fzl_vm_env.c
|
||||
src/vm/fzl_vm_debug.c
|
||||
src/vm/main.c)
|
||||
if (NOT FZL_SKIP_VM)
|
||||
add_executable(fz
|
||||
src/vm/handlers/group_and_or.c
|
||||
src/vm/handlers/group_cmp.c
|
||||
src/vm/handlers/group_ctx.c
|
||||
src/vm/handlers/group_flow.c
|
||||
src/vm/handlers/group_fn.c
|
||||
src/vm/handlers/group_math.c
|
||||
src/vm/handlers/group_not.c
|
||||
src/vm/handlers/group_obj.c
|
||||
src/vm/handlers/group_objcmp.c
|
||||
src/vm/handlers/group_stack.c
|
||||
src/vm/handlers/group_str.c
|
||||
src/vm/handlers/group_strcmp.c
|
||||
src/vm/handlers/master.c
|
||||
src/vm/fzl_vm.c
|
||||
src/vm/fzl_vm_env.c
|
||||
src/vm/fzl_vm_debug.c
|
||||
src/vm/main.c)
|
||||
|
||||
target_link_libraries(fz PRIVATE ffi_static dl)
|
||||
target_link_libraries(fz PRIVATE ffi_static dl)
|
||||
endif ()
|
||||
|
||||
#
|
||||
# ========== Installtion ===========
|
||||
#
|
||||
|
||||
if (NOT FZL_SKIP_C)
|
||||
install (TARGETS fzc RUNTIME DESTINATION bin)
|
||||
endif ()
|
||||
|
||||
if (NOT FZL_SKIP_VM)
|
||||
install (TARGETS fz RUNTIME DESTINATION bin)
|
||||
endif ()
|
||||
|
||||
#
|
||||
# ========== Tests ==========
|
||||
#
|
||||
|
||||
enable_testing()
|
||||
if (FZL_TESTS)
|
||||
enable_testing()
|
||||
|
||||
file(GLOB TEST_PROGS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "tests/programs/*.fzs")
|
||||
foreach (TEST_FILE IN LISTS TEST_PROGS)
|
||||
get_filename_component(TEST_NAME "${TEST_FILE}" NAME_WE)
|
||||
|
||||
add_test(
|
||||
NAME "progs_compile_${TEST_NAME}"
|
||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/p_${TEST_NAME}.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FILE}"
|
||||
)
|
||||
add_test(
|
||||
NAME "progs_runtime_${TEST_NAME}"
|
||||
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/p_${TEST_NAME}.fzb"
|
||||
)
|
||||
file(GLOB TEST_PROGS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "tests/programs/*.fzs")
|
||||
foreach (TEST_FILE IN LISTS TEST_PROGS)
|
||||
get_filename_component(TEST_NAME "${TEST_FILE}" NAME_WE)
|
||||
|
||||
add_test(
|
||||
NAME "progs_compile_${TEST_NAME}"
|
||||
COMMAND fzc -o "${CMAKE_CURRENT_BINARY_DIR}/p_${TEST_NAME}.fzb" "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_FILE}"
|
||||
)
|
||||
add_test(
|
||||
NAME "progs_runtime_${TEST_NAME}"
|
||||
COMMAND fz "${CMAKE_CURRENT_BINARY_DIR}/p_${TEST_NAME}.fzb"
|
||||
)
|
||||
|
||||
if (TEST_NAME MATCHES "neg_")
|
||||
set_tests_properties("progs_compile_${TEST_NAME}" PROPERTIES WILL_FAIL TRUE)
|
||||
set_tests_properties("progs_runtime_${TEST_NAME}" PROPERTIES WILL_FAIL TRUE)
|
||||
endif()
|
||||
if (TEST_NAME MATCHES "neg_")
|
||||
set_tests_properties("progs_compile_${TEST_NAME}" PROPERTIES WILL_FAIL TRUE)
|
||||
set_tests_properties("progs_runtime_${TEST_NAME}" PROPERTIES WILL_FAIL TRUE)
|
||||
endif()
|
||||
|
||||
if (TEST_NAME MATCHES "negr_")
|
||||
set_tests_properties("progs_runtime_${TEST_NAME}" PROPERTIES WILL_FAIL TRUE)
|
||||
endif()
|
||||
endforeach()
|
||||
if (TEST_NAME MATCHES "negr_")
|
||||
set_tests_properties("progs_runtime_${TEST_NAME}" PROPERTIES WILL_FAIL TRUE)
|
||||
endif ()
|
||||
endforeach ()
|
||||
endif ()
|
||||
|
||||
|
||||
@@ -7,34 +7,37 @@ MAX_ITER ?= 2000000
|
||||
|
||||
current_time = python3 -c "import time; print(time.time())"
|
||||
|
||||
build:
|
||||
build-debug:
|
||||
cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug
|
||||
cmake --build build
|
||||
|
||||
build-release:
|
||||
build:
|
||||
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release $(COMPARING)
|
||||
cmake --build build $(COMPARING)
|
||||
|
||||
debug-c: build
|
||||
install: build-release
|
||||
cmake --install build
|
||||
|
||||
debug-c: build-debug
|
||||
gdb --args ./build/fzc -v ${FILE}
|
||||
|
||||
debug-vm: build
|
||||
debug-vm: build-debug
|
||||
gdb --args ./build/fz ${FILE}
|
||||
|
||||
test-debug: build-debug
|
||||
ctest --output-on-failure --test-dir build
|
||||
|
||||
test: build
|
||||
ctest --output-on-failure --test-dir build
|
||||
|
||||
test-release: build-release
|
||||
ctest --output-on-failure --test-dir build
|
||||
|
||||
bench: COMPARING=&>/dev/null
|
||||
bench: build-release
|
||||
bench: build
|
||||
@./build/fzc -o build/benchmark.fzb $(BENCH_FILE)
|
||||
@python3 scripts/benchmark.py --runs $(RUNS) --warmup $(WARMUP) \
|
||||
--max-iter $(MAX_ITER) --vm ./build/fz --program build/benchmark.fzb
|
||||
|
||||
compare: COMPARING=&>/dev/null
|
||||
compare: build-release
|
||||
compare: build
|
||||
@echo "=== Million sums benchmark ==="
|
||||
|
||||
@./build/fzc -o build/bench.fzb $(BENCH_FILE) 1>/dev/null 2>/dev/null
|
||||
|
||||
Reference in New Issue
Block a user