Skip to content

Commit

Permalink
use ${PROJECT_NAME}; update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
WuK committed Feb 21, 2024
1 parent 11ae31c commit 2d14130
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"image": "wukan0621/sysu-lang",
"image": "wukan0621/sysu-lang:v2404.0.0.20240115"
}
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# syntax=docker/dockerfile:1.4
ARG BASE_IMAGE=ubuntu
ARG BASE_IMAGE=ubuntu:noble
FROM ${BASE_IMAGE}
WORKDIR /autograder
WORKDIR /opt/SYsU-lang
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ int main(){

### `grammar`

SYsU 的新文法分析器,产生类似于 `clang -cc1 -dump-tokens 2>&1``clang -cc1 -ast-dump=json` 的输出。作为文法分析实验模块,本仓库中的 `sysu-grammar` 并不能处理完整的 SYsU,但提供了一个模板,需要学生将其文法分析规则补充完整([详细实验要求](grammar/README.md))。
SYsU 的新基于 antlr4 的文法分析器,用于代替被诟病已久的 flex+bison 旧实验,产生类似于 `clang -cc1 -dump-tokens 2>&1``clang -cc1 -ast-dump=json` 的输出。作为文法分析实验模块,本仓库中的 `sysu-grammar` 并不能处理完整的 SYsU,但提供了一个模板,需要学生将其文法分析规则补充完整([详细实验要求](grammar/README.md))。

```bash
$ ( export PATH=$HOME/sysu/bin:$PATH \
Expand Down
9 changes: 5 additions & 4 deletions generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
project(sysu-generator)
find_package(LLVM REQUIRED)
add_executable(sysu-generator main.cc)
add_executable(${PROJECT_NAME} main.cc)
llvm_map_components_to_libnames(LLVM_LIBS core support)
target_link_libraries(sysu-generator ${LLVM_LIBS})
target_include_directories(sysu-generator PRIVATE ${LLVM_INCLUDE_DIRS})
install(TARGETS sysu-generator)
target_link_libraries(${PROJECT_NAME} ${LLVM_LIBS})
target_include_directories(${PROJECT_NAME} PRIVATE ${LLVM_INCLUDE_DIRS})
install(TARGETS ${PROJECT_NAME})
28 changes: 14 additions & 14 deletions grammar/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
project(sysu-grammar)

# Bring in the required packages
find_package(antlr4-runtime REQUIRED)

Expand All @@ -12,31 +14,29 @@ endif()
find_package(antlr4-generator REQUIRED)

# generate lexer
antlr4_generate(
sysu_grammar
${CMAKE_CURRENT_SOURCE_DIR}/C.g4 BOTH
TRUE TRUE "sysu_grammar")
antlr4_generate(sysu_grammar ${CMAKE_CURRENT_SOURCE_DIR}/C.g4 BOTH TRUE TRUE
"sysu_grammar")

# add generated source files
add_executable(sysu-grammar main.cc ${ANTLR4_SRC_FILES_sysu_grammar})
install(TARGETS sysu-grammar)
add_executable(${PROJECT_NAME} main.cc ${ANTLR4_SRC_FILES_sysu_grammar})
install(TARGETS ${PROJECT_NAME})

# add directories for generated include files
target_include_directories(
sysu-grammar
PRIVATE ${ANTLR4_INCLUDE_DIR} ${ANTLR4_INCLUDE_DIR_sysu_grammar})
${PROJECT_NAME} PRIVATE ${ANTLR4_INCLUDE_DIR}
${ANTLR4_INCLUDE_DIR_sysu_grammar})

target_link_directories(sysu-grammar PUBLIC ${ANTLR4_LIB_DIR})
target_link_libraries(sysu-grammar antlr4_shared)
target_link_directories(${PROJECT_NAME} PUBLIC ${ANTLR4_LIB_DIR})
target_link_libraries(${PROJECT_NAME} antlr4_shared)

if(${ANTLR_VERSION} VERSION_LESS_EQUAL 4.10.1)
find_package(PkgConfig REQUIRED)
pkg_check_modules(UUID REQUIRED uuid)
target_link_directories(sysu-grammar PUBLIC ${UUID_LIBRARY_DIRS})
target_link_libraries(sysu-grammar ${UUID_LIBRARIES})
target_link_directories(${PROJECT_NAME} PUBLIC ${UUID_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME} ${UUID_LIBRARIES})
endif()

find_package(LLVM REQUIRED)
llvm_map_components_to_libnames(LLVM_LIBS support)
target_link_libraries(sysu-grammar ${LLVM_LIBS})
target_include_directories(sysu-grammar PRIVATE ${LLVM_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${LLVM_LIBS})
target_include_directories(${PROJECT_NAME} PRIVATE ${LLVM_INCLUDE_DIRS})
2 changes: 1 addition & 1 deletion grammar/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ $ ( export PATH=$HOME/sysu/bin:$PATH \
可以发现,`clang -cc1 -ast-dump=json` 输出一个 json 格式的语法分析树。我们要求你的输出不包含图上忽略的内置类型,也不需要为每个节点生成单独的 `id`
本目录下提供了一个基于 antlr4 + `llvm::json` 实现的模板,接受词法分析器的输出,你可以基于此继续实现完整的逻辑,也可以使用其他的工具实现,如 bison,但不得使用任何封装好的库直接获得 ast,如 libclang。
本目录下提供了一个基于 antlr4 + `llvm::json` 实现的模板,接受词法分析器的输出,你可以基于此继续实现完整的逻辑,也可以使用其他的工具实现,如 bison,但不得使用任何封装好的库直接获得 ast,如 libclang。[`C.g4`](./C.g4) 语法文件来自于 [antlr/grammars-v4](https://github.com/antlr/grammars-v4/blob/753536777d827ccc0c9b108531ea67375c2039ac/c/C.g4) 社区(感谢!),如有需要可自行修改。
### Q & A:实验要求太抽象了,需要一个更直观的例子
Expand Down
5 changes: 3 additions & 2 deletions lexer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
project(sysu-lexer)
find_package(FLEX REQUIRED)
flex_target(lexer lexer.l ${CMAKE_CURRENT_BINARY_DIR}/main.cc
DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/lexer.hh)
add_executable(sysu-lexer ${FLEX_lexer_OUTPUTS})
install(TARGETS sysu-lexer)
add_executable(${PROJECT_NAME} ${FLEX_lexer_OUTPUTS})
install(TARGETS ${PROJECT_NAME})
9 changes: 5 additions & 4 deletions optimizer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
project(sysu-optimizer)
find_package(LLVM REQUIRED)

add_library(sysuOptimizer SHARED optimizer.cc)
target_include_directories(sysuOptimizer PRIVATE ${LLVM_INCLUDE_DIRS})
install(TARGETS sysuOptimizer)

add_executable(sysu-optimizer main.cc)
add_executable(${PROJECT_NAME} main.cc)
llvm_map_components_to_libnames(LLVM_LIBS passes irreader core support)
target_link_libraries(sysu-optimizer sysuOptimizer ${LLVM_LIBS})
target_include_directories(sysu-optimizer PRIVATE ${LLVM_INCLUDE_DIRS})
install(TARGETS sysu-optimizer)
target_link_libraries(${PROJECT_NAME} sysuOptimizer ${LLVM_LIBS})
target_include_directories(${PROJECT_NAME} PRIVATE ${LLVM_INCLUDE_DIRS})
install(TARGETS ${PROJECT_NAME})
install(FILES optimizer.hh DESTINATION include/sysu-compiler)
9 changes: 5 additions & 4 deletions parser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
project(sysu-parser)
find_package(LLVM REQUIRED)
find_package(BISON REQUIRED)
bison_target(parser parser.y ${CMAKE_CURRENT_BINARY_DIR}/main.cc
DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/parser.hh)
add_executable(sysu-parser ${BISON_parser_OUTPUT_SOURCE})
add_executable(${PROJECT_NAME} ${BISON_parser_OUTPUT_SOURCE})
llvm_map_components_to_libnames(LLVM_LIBS support)
target_link_libraries(sysu-parser ${LLVM_LIBS})
target_include_directories(sysu-parser PRIVATE ${LLVM_INCLUDE_DIRS})
install(TARGETS sysu-parser)
target_link_libraries(${PROJECT_NAME} ${LLVM_LIBS})
target_include_directories(${PROJECT_NAME} PRIVATE ${LLVM_INCLUDE_DIRS})
install(TARGETS ${PROJECT_NAME})
10 changes: 5 additions & 5 deletions tester/mizuno_ai/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
add_executable(sysu-tester-mizuno_ai mizuno_ai.sysu.c)
target_link_libraries(sysu-tester-mizuno_ai sysu)
project(sysu-tester-mizuno_ai)
add_executable(${PROJECT_NAME} mizuno_ai.sysu.c)
target_link_libraries(${PROJECT_NAME} sysu)
target_include_directories(
sysu-tester-mizuno_ai
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../librarian/include)
install(TARGETS sysu-tester-mizuno_ai)
${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../librarian/include)
install(TARGETS ${PROJECT_NAME})

0 comments on commit 2d14130

Please sign in to comment.