2019-11-02 16:38:11 -07:00
|
|
|
cmake_minimum_required(VERSION 3.1)
|
|
|
|
project(compiler)
|
|
|
|
|
2019-11-02 17:53:15 -07:00
|
|
|
# Find all the required packages
|
2019-11-02 16:38:11 -07:00
|
|
|
find_package(BISON)
|
|
|
|
find_package(FLEX)
|
2019-11-02 17:53:15 -07:00
|
|
|
find_package(LLVM REQUIRED CONFIG)
|
|
|
|
|
|
|
|
# Set up the flex and bison targets
|
2019-11-02 16:38:11 -07:00
|
|
|
bison_target(parser
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/parser.y
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/parser.cpp
|
|
|
|
COMPILE_FLAGS "-d")
|
|
|
|
flex_target(scanner
|
|
|
|
${CMAKE_CURRENT_SOURCE_DIR}/scanner.l
|
|
|
|
${CMAKE_CURRENT_BINARY_DIR}/scanner.cpp)
|
|
|
|
add_flex_bison_dependency(scanner parser)
|
|
|
|
|
2019-11-02 17:53:15 -07:00
|
|
|
# Find all the relevant LLVM components
|
|
|
|
llvm_map_components_to_libnames(LLVM_LIBS core x86asmparser x86codegen)
|
|
|
|
|
|
|
|
# Create compiler executable
|
2019-11-02 16:38:11 -07:00
|
|
|
add_executable(compiler
|
|
|
|
ast.cpp ast.hpp definition.cpp
|
2019-11-04 18:25:54 -08:00
|
|
|
llvm_context.cpp llvm_context.hpp
|
2019-11-02 16:38:11 -07:00
|
|
|
type_env.cpp type_env.hpp
|
|
|
|
env.cpp env.hpp
|
|
|
|
type.cpp type.hpp
|
|
|
|
error.cpp error.hpp
|
|
|
|
binop.cpp binop.hpp
|
|
|
|
instruction.cpp instruction.hpp
|
|
|
|
${BISON_parser_OUTPUTS}
|
|
|
|
${FLEX_scanner_OUTPUTS}
|
|
|
|
main.cpp
|
|
|
|
)
|
2019-11-02 17:53:15 -07:00
|
|
|
|
|
|
|
# Configure compiler executable
|
2019-11-02 16:38:11 -07:00
|
|
|
target_include_directories(compiler PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
|
|
|
target_include_directories(compiler PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
|
2019-11-02 17:53:15 -07:00
|
|
|
target_include_directories(compiler PUBLIC ${LLVM_DEFINITIONS})
|
|
|
|
target_compile_definitions(compiler PUBLIC ${LLVM_DEFINITIONS})
|
|
|
|
target_link_libraries(compiler ${LLVM_LIBS})
|