-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
118 lines (92 loc) · 5.67 KB
/
CMakeLists.txt
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
cmake_minimum_required (VERSION 3.5)
project (compiler)
set (CMAKE_CXX_STANDARD 11)
# ------------------------------------------------------------------------------
# Compiler flags
# ------------------------------------------------------------------------------
# set (CMAKE_CXX_COMPILER g++-7)
#set (GCC_COMPILE_FLAGS "-Wall -Wextra -g")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COMPILE_FLAGS}")
option (BUILD_REG_TEST "Determines whether to build regression tests or not" OFF)
# ------------------------------------------------------------------------------
# Build
# ------------------------------------------------------------------------------
add_subdirectory (lexical_analyzer)
add_subdirectory (syntax_analyzer)
add_subdirectory (semantic_analyzer)
add_executable (compiler main.cpp)
target_link_libraries (compiler liblex libsyntax)
# ------------------------------------------------------------------------------
# Valgrind
# ------------------------------------------------------------------------------
set (MEMORYCHECK_COMMAND_OPTIONS "${MEMORYCHECK_COMMAND_OPTIONS} --leak-check=full")
set (MEMORYCHECK_COMMAND_OPTIONS "${MEMORYCHECK_COMMAND_OPTIONS} --trace-children=yes")
set (MEMORYCHECK_COMMAND_OPTIONS "${MEMORYCHECK_COMMAND_OPTIONS} --error-exitcode=1")
# ------------------------------------------------------------------------------
# Code Coverage (not used yet)
# ------------------------------------------------------------------------------
# set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMakeModules)
# include(CodeCoverage)
# setup_target_for_coverage(cov ${TEST_RUNNER} coverage)
# ------------------------------------------------------------------------------
# Tests
# ------------------------------------------------------------------------------
# Regression Tests
if (BUILD_REG_TEST)
enable_testing ()
# LEXICAL ANALYZER REGRESION TEST
add_test (reg_test_0_lexical_analyzer_run compiler --lex -g
${PROJECT_SOURCE_DIR}/tests/lexical_analyzer/regression/test_0/rules.txt
${PROJECT_SOURCE_DIR}/tests/lexical_analyzer/regression/test_0/test_0.txt)
add_test (reg_test_0_lexical_analyzer_compare_token_file ${CMAKE_COMMAND} -E compare_files
${PROJECT_SOURCE_DIR}/build/token-file.txt
${PROJECT_SOURCE_DIR}/tests/lexical_analyzer/regression/test_0/token-file.txt)
add_test (reg_test_0_lexical_analyzer_compare_symbol_table ${CMAKE_COMMAND} -E compare_files
${PROJECT_SOURCE_DIR}/build/symbol-table.txt
${PROJECT_SOURCE_DIR}/tests/lexical_analyzer/regression/test_0/symbol-table.txt)
add_test (reg_test_0_lexical_analyzer_compare_log ${CMAKE_COMMAND} -E compare_files
${PROJECT_SOURCE_DIR}/build/compiler.log
${PROJECT_SOURCE_DIR}/tests/lexical_analyzer/regression/test_0/compiler.log)
macro (do_test test_num)
add_test (reg_test_${test_num}_lexical_analyzer_run compiler --lex
${PROJECT_SOURCE_DIR}/build/transition_table.txt
${PROJECT_SOURCE_DIR}/tests/lexical_analyzer/regression/test_${test_num}/test_${test_num}.txt)
add_test (reg_test_${test_num}_lexical_analyzer_compare_token_file ${CMAKE_COMMAND}
-E compare_files ${PROJECT_SOURCE_DIR}/build/token-file.txt
${PROJECT_SOURCE_DIR}/tests/lexical_analyzer/regression/test_${test_num}/token-file.txt)
add_test (reg_test_${test_num}_lexical_analyzer_compare_symbol_table ${CMAKE_COMMAND}
-E compare_files ${PROJECT_SOURCE_DIR}/build/symbol-table.txt
${PROJECT_SOURCE_DIR}/tests/lexical_analyzer/regression/test_${test_num}/symbol-table.txt)
add_test (reg_test_${test_num}_lexical_analyzer_compare_log ${CMAKE_COMMAND}
-E compare_files ${PROJECT_SOURCE_DIR}/build/compiler.log
${PROJECT_SOURCE_DIR}/tests/lexical_analyzer/regression/test_${test_num}/compiler.log)
endmacro (do_test)
do_test (1)
do_test (2)
do_test (3)
do_test (4)
do_test (5)
do_test (6)
# SYNTAX ANALYZER REGRESION TEST (not ll1 grammar)
add_test (reg_test_0_syntax_analyzer_run compiler --parse
${PROJECT_SOURCE_DIR}/tests/syntax_analyzer/regression/test_0/transition_table.txt
${PROJECT_SOURCE_DIR}/tests/syntax_analyzer/regression/test_0/code.txt
${PROJECT_SOURCE_DIR}/tests/syntax_analyzer/regression/test_0/cfg.bnf)
# add_test (reg_test_0_syntax_analyzer_compare_debug_stack ${CMAKE_COMMAND} -E compare_files
# ${PROJECT_SOURCE_DIR}/build/debug_stack.log
# ${PROJECT_SOURCE_DIR}/tests/syntax_analyzer/regression/test_0/debug_stack.log)
# add_test (reg_test_0_syntax_analyzer_compare_actions_output ${CMAKE_COMMAND} -E compare_files
# ${PROJECT_SOURCE_DIR}/build/actions_output.log
# ${PROJECT_SOURCE_DIR}/tests/syntax_analyzer/regression/test_0/actions_output.log)
# SYNTAX ANALYZER REGRESION TEST (ll1 grammar)
add_test (reg_test_1_syntax_analyzer_run compiler --parse
${PROJECT_SOURCE_DIR}/tests/syntax_analyzer/regression/test_1/transition_table.txt
${PROJECT_SOURCE_DIR}/tests/syntax_analyzer/regression/test_1/code.txt
${PROJECT_SOURCE_DIR}/tests/syntax_analyzer/regression/test_1/ll1_cfg.bnf)
add_test (reg_test_1_syntax_analyzer_compare_debug_stack ${CMAKE_COMMAND} -E compare_files
${PROJECT_SOURCE_DIR}/build/debug_stack.log
${PROJECT_SOURCE_DIR}/tests/syntax_analyzer/regression/test_1/debug_stack.log)
add_test (reg_test_1_syntax_analyzer_compare_actions_output ${CMAKE_COMMAND} -E compare_files
${PROJECT_SOURCE_DIR}/build/actions_output.log
${PROJECT_SOURCE_DIR}/tests/syntax_analyzer/regression/test_1/actions_output.log)
endif (BUILD_REG_TEST)