diff --git a/.gitignore b/.gitignore index 7afafe0..887e11b 100644 --- a/.gitignore +++ b/.gitignore @@ -51,4 +51,6 @@ __init__.py *.pyc -.DS_* \ No newline at end of file +.DS_* + +antlr/ \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5d71f7f..c89b3b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,4 @@ -# Generate lexer and parser with ANTLR +# 移除 ANTLR 代码生成相关配置 # list(APPEND CMAKE_MODULE_PATH "${ANTLR_RUNTIME}/cmake") # include(FindANTLR) # antlr_target(SysYGen SysY.g4 @@ -7,15 +7,17 @@ # VISITOR # ) -add_library(SysYParser SHARED ${ANTLR_SysYGen_CXX_OUTPUTS}) -target_include_directories(SysYParser PUBLIC ${ANTLR_RUNTIME}/runtime/src) -target_link_libraries(SysYParser PUBLIC antlr4_shared) +# 移除 SysYParser 库的构建(如果不需要独立库) +# add_library(SysYParser SHARED ${ANTLR_SysYGen_CXX_OUTPUTS}) +# target_include_directories(SysYParser PUBLIC ${ANTLR_RUNTIME}/runtime/src) +# target_link_libraries(SysYParser PUBLIC antlr4_shared) +# 构建 sysyc 可执行文件,使用手动提供的 SysYLexer.cpp、SysYParser.cpp 等文件 add_executable(sysyc sysyc.cpp - SysYLexer.cpp - SysYParser.cpp - SysYVisitor.cpp + SysYLexer.cpp # 手动提供的文件 + SysYParser.cpp # 手动提供的文件 + SysYVisitor.cpp # 手动提供的文件 IR.cpp SysYIRGenerator.cpp SysYIRPrinter.cpp @@ -27,10 +29,19 @@ add_executable(sysyc RISCv64Backend.cpp ) -target_include_directories(sysyc PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include) -target_compile_options(sysyc PRIVATE -frtti) -target_link_libraries(sysyc PRIVATE SysYParser) +# 设置 include 路径,包含 ANTLR 运行时库和项目头文件 +target_include_directories(sysyc PRIVATE + ${CMAKE_CURRENT_SOURCE_DIR}/include # 项目头文件目录 + ${ANTLR_RUNTIME}/runtime/src # ANTLR 运行时库头文件 +) +# 保留 ANTLR 运行时库的链接 +target_link_libraries(sysyc PRIVATE antlr4_shared) + +# 保留其他编译选项 +target_compile_options(sysyc PRIVATE -frtti) + +# 可选:线程支持(如果需要,取消注释) # set(THREADS_PREFER_PTHREAD_FLAG ON) # find_package(Threads REQUIRED) # target_link_libraries(sysyc PRIVATE Threads::Threads) \ No newline at end of file diff --git a/src/SysY.interp b/src/SysY.interp deleted file mode 100644 index 1d73cfd..0000000 --- a/src/SysY.interp +++ /dev/null @@ -1,125 +0,0 @@ -token literal names: -null -'const' -'int' -'float' -'void' -'if' -'else' -'while' -'break' -'continue' -'return' -'+' -'-' -'*' -'/' -'%' -'==' -'!=' -'<' -'<=' -'>' -'>=' -'&&' -'||' -'!' -'=' -',' -';' -'(' -')' -'{' -'}' -'[' -']' -null -null -null -null -null -null -null - -token symbolic names: -null -CONST -INT -FLOAT -VOID -IF -ELSE -WHILE -BREAK -CONTINUE -RETURN -ADD -SUB -MUL -DIV -MOD -EQ -NE -LT -LE -GT -GE -AND -OR -NOT -ASSIGN -COMMA -SEMICOLON -LPAREN -RPAREN -LBRACE -RBRACE -LBRACK -RBRACK -Ident -ILITERAL -FLITERAL -STRING -WS -LINECOMMENT -BLOCKCOMMENT - -rule names: -compUnit -globalDecl -decl -constDecl -bType -constDef -constInitVal -varDecl -varDef -initVal -funcType -funcDef -funcFParams -funcFParam -blockStmt -blockItem -stmt -exp -cond -lValue -primaryExp -number -call -unaryExp -unaryOp -funcRParams -string -mulExp -addExp -relExp -eqExp -lAndExp -lOrExp -constExp - - -atn: -[4, 1, 40, 359, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 1, 0, 1, 0, 4, 0, 71, 8, 0, 11, 0, 12, 0, 72, 1, 1, 1, 1, 3, 1, 77, 8, 1, 1, 2, 1, 2, 3, 2, 81, 8, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 5, 3, 88, 8, 3, 10, 3, 12, 3, 91, 9, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 5, 5, 102, 8, 5, 10, 5, 12, 5, 105, 9, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 5, 6, 115, 8, 6, 10, 6, 12, 6, 118, 9, 6, 3, 6, 120, 8, 6, 1, 6, 3, 6, 123, 8, 6, 1, 7, 1, 7, 1, 7, 1, 7, 5, 7, 129, 8, 7, 10, 7, 12, 7, 132, 9, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 5, 8, 141, 8, 8, 10, 8, 12, 8, 144, 9, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 5, 8, 151, 8, 8, 10, 8, 12, 8, 154, 9, 8, 1, 8, 1, 8, 3, 8, 158, 8, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 5, 9, 165, 8, 9, 10, 9, 12, 9, 168, 9, 9, 3, 9, 170, 8, 9, 1, 9, 3, 9, 173, 8, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 11, 1, 11, 3, 11, 181, 8, 11, 1, 11, 1, 11, 1, 11, 1, 12, 1, 12, 1, 12, 5, 12, 189, 8, 12, 10, 12, 12, 12, 192, 9, 12, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 1, 13, 5, 13, 202, 8, 13, 10, 13, 12, 13, 205, 9, 13, 3, 13, 207, 8, 13, 1, 14, 1, 14, 5, 14, 211, 8, 14, 10, 14, 12, 14, 214, 9, 14, 1, 14, 1, 14, 1, 15, 1, 15, 3, 15, 220, 8, 15, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 3, 16, 228, 8, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 3, 16, 239, 8, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 1, 16, 3, 16, 253, 8, 16, 1, 16, 3, 16, 256, 8, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 19, 1, 19, 1, 19, 1, 19, 1, 19, 5, 19, 267, 8, 19, 10, 19, 12, 19, 270, 9, 19, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 1, 20, 3, 20, 279, 8, 20, 1, 21, 1, 21, 1, 22, 1, 22, 1, 22, 3, 22, 286, 8, 22, 1, 22, 1, 22, 1, 23, 1, 23, 1, 23, 1, 23, 1, 23, 3, 23, 295, 8, 23, 1, 24, 1, 24, 1, 25, 1, 25, 1, 25, 5, 25, 302, 8, 25, 10, 25, 12, 25, 305, 9, 25, 1, 26, 1, 26, 1, 27, 1, 27, 1, 27, 5, 27, 312, 8, 27, 10, 27, 12, 27, 315, 9, 27, 1, 28, 1, 28, 1, 28, 5, 28, 320, 8, 28, 10, 28, 12, 28, 323, 9, 28, 1, 29, 1, 29, 1, 29, 5, 29, 328, 8, 29, 10, 29, 12, 29, 331, 9, 29, 1, 30, 1, 30, 1, 30, 5, 30, 336, 8, 30, 10, 30, 12, 30, 339, 9, 30, 1, 31, 1, 31, 1, 31, 5, 31, 344, 8, 31, 10, 31, 12, 31, 347, 9, 31, 1, 32, 1, 32, 1, 32, 5, 32, 352, 8, 32, 10, 32, 12, 32, 355, 9, 32, 1, 33, 1, 33, 1, 33, 0, 0, 34, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 0, 8, 1, 0, 2, 3, 1, 0, 2, 4, 1, 0, 35, 36, 2, 0, 11, 12, 24, 24, 1, 0, 13, 15, 1, 0, 11, 12, 1, 0, 18, 21, 1, 0, 16, 17, 370, 0, 70, 1, 0, 0, 0, 2, 76, 1, 0, 0, 0, 4, 80, 1, 0, 0, 0, 6, 82, 1, 0, 0, 0, 8, 94, 1, 0, 0, 0, 10, 96, 1, 0, 0, 0, 12, 122, 1, 0, 0, 0, 14, 124, 1, 0, 0, 0, 16, 157, 1, 0, 0, 0, 18, 172, 1, 0, 0, 0, 20, 174, 1, 0, 0, 0, 22, 176, 1, 0, 0, 0, 24, 185, 1, 0, 0, 0, 26, 193, 1, 0, 0, 0, 28, 208, 1, 0, 0, 0, 30, 219, 1, 0, 0, 0, 32, 255, 1, 0, 0, 0, 34, 257, 1, 0, 0, 0, 36, 259, 1, 0, 0, 0, 38, 261, 1, 0, 0, 0, 40, 278, 1, 0, 0, 0, 42, 280, 1, 0, 0, 0, 44, 282, 1, 0, 0, 0, 46, 294, 1, 0, 0, 0, 48, 296, 1, 0, 0, 0, 50, 298, 1, 0, 0, 0, 52, 306, 1, 0, 0, 0, 54, 308, 1, 0, 0, 0, 56, 316, 1, 0, 0, 0, 58, 324, 1, 0, 0, 0, 60, 332, 1, 0, 0, 0, 62, 340, 1, 0, 0, 0, 64, 348, 1, 0, 0, 0, 66, 356, 1, 0, 0, 0, 68, 71, 3, 2, 1, 0, 69, 71, 3, 22, 11, 0, 70, 68, 1, 0, 0, 0, 70, 69, 1, 0, 0, 0, 71, 72, 1, 0, 0, 0, 72, 70, 1, 0, 0, 0, 72, 73, 1, 0, 0, 0, 73, 1, 1, 0, 0, 0, 74, 77, 3, 6, 3, 0, 75, 77, 3, 14, 7, 0, 76, 74, 1, 0, 0, 0, 76, 75, 1, 0, 0, 0, 77, 3, 1, 0, 0, 0, 78, 81, 3, 6, 3, 0, 79, 81, 3, 14, 7, 0, 80, 78, 1, 0, 0, 0, 80, 79, 1, 0, 0, 0, 81, 5, 1, 0, 0, 0, 82, 83, 5, 1, 0, 0, 83, 84, 3, 8, 4, 0, 84, 89, 3, 10, 5, 0, 85, 86, 5, 26, 0, 0, 86, 88, 3, 10, 5, 0, 87, 85, 1, 0, 0, 0, 88, 91, 1, 0, 0, 0, 89, 87, 1, 0, 0, 0, 89, 90, 1, 0, 0, 0, 90, 92, 1, 0, 0, 0, 91, 89, 1, 0, 0, 0, 92, 93, 5, 27, 0, 0, 93, 7, 1, 0, 0, 0, 94, 95, 7, 0, 0, 0, 95, 9, 1, 0, 0, 0, 96, 103, 5, 34, 0, 0, 97, 98, 5, 32, 0, 0, 98, 99, 3, 66, 33, 0, 99, 100, 5, 33, 0, 0, 100, 102, 1, 0, 0, 0, 101, 97, 1, 0, 0, 0, 102, 105, 1, 0, 0, 0, 103, 101, 1, 0, 0, 0, 103, 104, 1, 0, 0, 0, 104, 106, 1, 0, 0, 0, 105, 103, 1, 0, 0, 0, 106, 107, 5, 25, 0, 0, 107, 108, 3, 12, 6, 0, 108, 11, 1, 0, 0, 0, 109, 123, 3, 66, 33, 0, 110, 119, 5, 30, 0, 0, 111, 116, 3, 12, 6, 0, 112, 113, 5, 26, 0, 0, 113, 115, 3, 12, 6, 0, 114, 112, 1, 0, 0, 0, 115, 118, 1, 0, 0, 0, 116, 114, 1, 0, 0, 0, 116, 117, 1, 0, 0, 0, 117, 120, 1, 0, 0, 0, 118, 116, 1, 0, 0, 0, 119, 111, 1, 0, 0, 0, 119, 120, 1, 0, 0, 0, 120, 121, 1, 0, 0, 0, 121, 123, 5, 31, 0, 0, 122, 109, 1, 0, 0, 0, 122, 110, 1, 0, 0, 0, 123, 13, 1, 0, 0, 0, 124, 125, 3, 8, 4, 0, 125, 130, 3, 16, 8, 0, 126, 127, 5, 26, 0, 0, 127, 129, 3, 16, 8, 0, 128, 126, 1, 0, 0, 0, 129, 132, 1, 0, 0, 0, 130, 128, 1, 0, 0, 0, 130, 131, 1, 0, 0, 0, 131, 133, 1, 0, 0, 0, 132, 130, 1, 0, 0, 0, 133, 134, 5, 27, 0, 0, 134, 15, 1, 0, 0, 0, 135, 142, 5, 34, 0, 0, 136, 137, 5, 32, 0, 0, 137, 138, 3, 66, 33, 0, 138, 139, 5, 33, 0, 0, 139, 141, 1, 0, 0, 0, 140, 136, 1, 0, 0, 0, 141, 144, 1, 0, 0, 0, 142, 140, 1, 0, 0, 0, 142, 143, 1, 0, 0, 0, 143, 158, 1, 0, 0, 0, 144, 142, 1, 0, 0, 0, 145, 152, 5, 34, 0, 0, 146, 147, 5, 32, 0, 0, 147, 148, 3, 66, 33, 0, 148, 149, 5, 33, 0, 0, 149, 151, 1, 0, 0, 0, 150, 146, 1, 0, 0, 0, 151, 154, 1, 0, 0, 0, 152, 150, 1, 0, 0, 0, 152, 153, 1, 0, 0, 0, 153, 155, 1, 0, 0, 0, 154, 152, 1, 0, 0, 0, 155, 156, 5, 25, 0, 0, 156, 158, 3, 18, 9, 0, 157, 135, 1, 0, 0, 0, 157, 145, 1, 0, 0, 0, 158, 17, 1, 0, 0, 0, 159, 173, 3, 34, 17, 0, 160, 169, 5, 30, 0, 0, 161, 166, 3, 18, 9, 0, 162, 163, 5, 26, 0, 0, 163, 165, 3, 18, 9, 0, 164, 162, 1, 0, 0, 0, 165, 168, 1, 0, 0, 0, 166, 164, 1, 0, 0, 0, 166, 167, 1, 0, 0, 0, 167, 170, 1, 0, 0, 0, 168, 166, 1, 0, 0, 0, 169, 161, 1, 0, 0, 0, 169, 170, 1, 0, 0, 0, 170, 171, 1, 0, 0, 0, 171, 173, 5, 31, 0, 0, 172, 159, 1, 0, 0, 0, 172, 160, 1, 0, 0, 0, 173, 19, 1, 0, 0, 0, 174, 175, 7, 1, 0, 0, 175, 21, 1, 0, 0, 0, 176, 177, 3, 20, 10, 0, 177, 178, 5, 34, 0, 0, 178, 180, 5, 28, 0, 0, 179, 181, 3, 24, 12, 0, 180, 179, 1, 0, 0, 0, 180, 181, 1, 0, 0, 0, 181, 182, 1, 0, 0, 0, 182, 183, 5, 29, 0, 0, 183, 184, 3, 28, 14, 0, 184, 23, 1, 0, 0, 0, 185, 190, 3, 26, 13, 0, 186, 187, 5, 26, 0, 0, 187, 189, 3, 26, 13, 0, 188, 186, 1, 0, 0, 0, 189, 192, 1, 0, 0, 0, 190, 188, 1, 0, 0, 0, 190, 191, 1, 0, 0, 0, 191, 25, 1, 0, 0, 0, 192, 190, 1, 0, 0, 0, 193, 194, 3, 8, 4, 0, 194, 206, 5, 34, 0, 0, 195, 196, 5, 32, 0, 0, 196, 203, 5, 33, 0, 0, 197, 198, 5, 32, 0, 0, 198, 199, 3, 34, 17, 0, 199, 200, 5, 33, 0, 0, 200, 202, 1, 0, 0, 0, 201, 197, 1, 0, 0, 0, 202, 205, 1, 0, 0, 0, 203, 201, 1, 0, 0, 0, 203, 204, 1, 0, 0, 0, 204, 207, 1, 0, 0, 0, 205, 203, 1, 0, 0, 0, 206, 195, 1, 0, 0, 0, 206, 207, 1, 0, 0, 0, 207, 27, 1, 0, 0, 0, 208, 212, 5, 30, 0, 0, 209, 211, 3, 30, 15, 0, 210, 209, 1, 0, 0, 0, 211, 214, 1, 0, 0, 0, 212, 210, 1, 0, 0, 0, 212, 213, 1, 0, 0, 0, 213, 215, 1, 0, 0, 0, 214, 212, 1, 0, 0, 0, 215, 216, 5, 31, 0, 0, 216, 29, 1, 0, 0, 0, 217, 220, 3, 4, 2, 0, 218, 220, 3, 32, 16, 0, 219, 217, 1, 0, 0, 0, 219, 218, 1, 0, 0, 0, 220, 31, 1, 0, 0, 0, 221, 222, 3, 38, 19, 0, 222, 223, 5, 25, 0, 0, 223, 224, 3, 34, 17, 0, 224, 225, 5, 27, 0, 0, 225, 256, 1, 0, 0, 0, 226, 228, 3, 34, 17, 0, 227, 226, 1, 0, 0, 0, 227, 228, 1, 0, 0, 0, 228, 229, 1, 0, 0, 0, 229, 256, 5, 27, 0, 0, 230, 256, 3, 28, 14, 0, 231, 232, 5, 5, 0, 0, 232, 233, 5, 28, 0, 0, 233, 234, 3, 36, 18, 0, 234, 235, 5, 29, 0, 0, 235, 238, 3, 32, 16, 0, 236, 237, 5, 6, 0, 0, 237, 239, 3, 32, 16, 0, 238, 236, 1, 0, 0, 0, 238, 239, 1, 0, 0, 0, 239, 256, 1, 0, 0, 0, 240, 241, 5, 7, 0, 0, 241, 242, 5, 28, 0, 0, 242, 243, 3, 36, 18, 0, 243, 244, 5, 29, 0, 0, 244, 245, 3, 32, 16, 0, 245, 256, 1, 0, 0, 0, 246, 247, 5, 8, 0, 0, 247, 256, 5, 27, 0, 0, 248, 249, 5, 9, 0, 0, 249, 256, 5, 27, 0, 0, 250, 252, 5, 10, 0, 0, 251, 253, 3, 34, 17, 0, 252, 251, 1, 0, 0, 0, 252, 253, 1, 0, 0, 0, 253, 254, 1, 0, 0, 0, 254, 256, 5, 27, 0, 0, 255, 221, 1, 0, 0, 0, 255, 227, 1, 0, 0, 0, 255, 230, 1, 0, 0, 0, 255, 231, 1, 0, 0, 0, 255, 240, 1, 0, 0, 0, 255, 246, 1, 0, 0, 0, 255, 248, 1, 0, 0, 0, 255, 250, 1, 0, 0, 0, 256, 33, 1, 0, 0, 0, 257, 258, 3, 56, 28, 0, 258, 35, 1, 0, 0, 0, 259, 260, 3, 64, 32, 0, 260, 37, 1, 0, 0, 0, 261, 268, 5, 34, 0, 0, 262, 263, 5, 32, 0, 0, 263, 264, 3, 34, 17, 0, 264, 265, 5, 33, 0, 0, 265, 267, 1, 0, 0, 0, 266, 262, 1, 0, 0, 0, 267, 270, 1, 0, 0, 0, 268, 266, 1, 0, 0, 0, 268, 269, 1, 0, 0, 0, 269, 39, 1, 0, 0, 0, 270, 268, 1, 0, 0, 0, 271, 272, 5, 28, 0, 0, 272, 273, 3, 34, 17, 0, 273, 274, 5, 29, 0, 0, 274, 279, 1, 0, 0, 0, 275, 279, 3, 38, 19, 0, 276, 279, 3, 42, 21, 0, 277, 279, 3, 52, 26, 0, 278, 271, 1, 0, 0, 0, 278, 275, 1, 0, 0, 0, 278, 276, 1, 0, 0, 0, 278, 277, 1, 0, 0, 0, 279, 41, 1, 0, 0, 0, 280, 281, 7, 2, 0, 0, 281, 43, 1, 0, 0, 0, 282, 283, 5, 34, 0, 0, 283, 285, 5, 28, 0, 0, 284, 286, 3, 50, 25, 0, 285, 284, 1, 0, 0, 0, 285, 286, 1, 0, 0, 0, 286, 287, 1, 0, 0, 0, 287, 288, 5, 29, 0, 0, 288, 45, 1, 0, 0, 0, 289, 295, 3, 40, 20, 0, 290, 295, 3, 44, 22, 0, 291, 292, 3, 48, 24, 0, 292, 293, 3, 46, 23, 0, 293, 295, 1, 0, 0, 0, 294, 289, 1, 0, 0, 0, 294, 290, 1, 0, 0, 0, 294, 291, 1, 0, 0, 0, 295, 47, 1, 0, 0, 0, 296, 297, 7, 3, 0, 0, 297, 49, 1, 0, 0, 0, 298, 303, 3, 34, 17, 0, 299, 300, 5, 26, 0, 0, 300, 302, 3, 34, 17, 0, 301, 299, 1, 0, 0, 0, 302, 305, 1, 0, 0, 0, 303, 301, 1, 0, 0, 0, 303, 304, 1, 0, 0, 0, 304, 51, 1, 0, 0, 0, 305, 303, 1, 0, 0, 0, 306, 307, 5, 37, 0, 0, 307, 53, 1, 0, 0, 0, 308, 313, 3, 46, 23, 0, 309, 310, 7, 4, 0, 0, 310, 312, 3, 46, 23, 0, 311, 309, 1, 0, 0, 0, 312, 315, 1, 0, 0, 0, 313, 311, 1, 0, 0, 0, 313, 314, 1, 0, 0, 0, 314, 55, 1, 0, 0, 0, 315, 313, 1, 0, 0, 0, 316, 321, 3, 54, 27, 0, 317, 318, 7, 5, 0, 0, 318, 320, 3, 54, 27, 0, 319, 317, 1, 0, 0, 0, 320, 323, 1, 0, 0, 0, 321, 319, 1, 0, 0, 0, 321, 322, 1, 0, 0, 0, 322, 57, 1, 0, 0, 0, 323, 321, 1, 0, 0, 0, 324, 329, 3, 56, 28, 0, 325, 326, 7, 6, 0, 0, 326, 328, 3, 56, 28, 0, 327, 325, 1, 0, 0, 0, 328, 331, 1, 0, 0, 0, 329, 327, 1, 0, 0, 0, 329, 330, 1, 0, 0, 0, 330, 59, 1, 0, 0, 0, 331, 329, 1, 0, 0, 0, 332, 337, 3, 58, 29, 0, 333, 334, 7, 7, 0, 0, 334, 336, 3, 58, 29, 0, 335, 333, 1, 0, 0, 0, 336, 339, 1, 0, 0, 0, 337, 335, 1, 0, 0, 0, 337, 338, 1, 0, 0, 0, 338, 61, 1, 0, 0, 0, 339, 337, 1, 0, 0, 0, 340, 345, 3, 60, 30, 0, 341, 342, 5, 22, 0, 0, 342, 344, 3, 60, 30, 0, 343, 341, 1, 0, 0, 0, 344, 347, 1, 0, 0, 0, 345, 343, 1, 0, 0, 0, 345, 346, 1, 0, 0, 0, 346, 63, 1, 0, 0, 0, 347, 345, 1, 0, 0, 0, 348, 353, 3, 62, 31, 0, 349, 350, 5, 23, 0, 0, 350, 352, 3, 62, 31, 0, 351, 349, 1, 0, 0, 0, 352, 355, 1, 0, 0, 0, 353, 351, 1, 0, 0, 0, 353, 354, 1, 0, 0, 0, 354, 65, 1, 0, 0, 0, 355, 353, 1, 0, 0, 0, 356, 357, 3, 56, 28, 0, 357, 67, 1, 0, 0, 0, 37, 70, 72, 76, 80, 89, 103, 116, 119, 122, 130, 142, 152, 157, 166, 169, 172, 180, 190, 203, 206, 212, 219, 227, 238, 252, 255, 268, 278, 285, 294, 303, 313, 321, 329, 337, 345, 353] \ No newline at end of file diff --git a/src/SysY.tokens b/src/SysY.tokens deleted file mode 100644 index 4345538..0000000 --- a/src/SysY.tokens +++ /dev/null @@ -1,73 +0,0 @@ -CONST=1 -INT=2 -FLOAT=3 -VOID=4 -IF=5 -ELSE=6 -WHILE=7 -BREAK=8 -CONTINUE=9 -RETURN=10 -ADD=11 -SUB=12 -MUL=13 -DIV=14 -MOD=15 -EQ=16 -NE=17 -LT=18 -LE=19 -GT=20 -GE=21 -AND=22 -OR=23 -NOT=24 -ASSIGN=25 -COMMA=26 -SEMICOLON=27 -LPAREN=28 -RPAREN=29 -LBRACE=30 -RBRACE=31 -LBRACK=32 -RBRACK=33 -Ident=34 -ILITERAL=35 -FLITERAL=36 -STRING=37 -WS=38 -LINECOMMENT=39 -BLOCKCOMMENT=40 -'const'=1 -'int'=2 -'float'=3 -'void'=4 -'if'=5 -'else'=6 -'while'=7 -'break'=8 -'continue'=9 -'return'=10 -'+'=11 -'-'=12 -'*'=13 -'/'=14 -'%'=15 -'=='=16 -'!='=17 -'<'=18 -'<='=19 -'>'=20 -'>='=21 -'&&'=22 -'||'=23 -'!'=24 -'='=25 -','=26 -';'=27 -'('=28 -')'=29 -'{'=30 -'}'=31 -'['=32 -']'=33 diff --git a/src/SysYLexer.interp b/src/SysYLexer.interp deleted file mode 100644 index 3b3b457..0000000 --- a/src/SysYLexer.interp +++ /dev/null @@ -1,154 +0,0 @@ -token literal names: -null -'const' -'int' -'float' -'void' -'if' -'else' -'while' -'break' -'continue' -'return' -'+' -'-' -'*' -'/' -'%' -'==' -'!=' -'<' -'<=' -'>' -'>=' -'&&' -'||' -'!' -'=' -',' -';' -'(' -')' -'{' -'}' -'[' -']' -null -null -null -null -null -null -null - -token symbolic names: -null -CONST -INT -FLOAT -VOID -IF -ELSE -WHILE -BREAK -CONTINUE -RETURN -ADD -SUB -MUL -DIV -MOD -EQ -NE -LT -LE -GT -GE -AND -OR -NOT -ASSIGN -COMMA -SEMICOLON -LPAREN -RPAREN -LBRACE -RBRACE -LBRACK -RBRACK -Ident -ILITERAL -FLITERAL -STRING -WS -LINECOMMENT -BLOCKCOMMENT - -rule names: -CONST -INT -FLOAT -VOID -IF -ELSE -WHILE -BREAK -CONTINUE -RETURN -ADD -SUB -MUL -DIV -MOD -EQ -NE -LT -LE -GT -GE -AND -OR -NOT -ASSIGN -COMMA -SEMICOLON -LPAREN -RPAREN -LBRACE -RBRACE -LBRACK -RBRACK -DecDigit -OctDigit -HexDigit -OctPrefix -HexPrefix -NonZeroDecDigit -Sign -DecFractional -Exponent -DecFloat -HexFractional -BinExponent -HexFloat -ESC -ALPHA -ALPHANUM -NONDIGIT -Ident -ILITERAL -FLITERAL -STRING -WS -LINECOMMENT -BLOCKCOMMENT - -channel names: -DEFAULT_TOKEN_CHANNEL -HIDDEN - -mode names: -DEFAULT_MODE - -atn: -[4, 0, 40, 416, 6, -1, 2, 0, 7, 0, 2, 1, 7, 1, 2, 2, 7, 2, 2, 3, 7, 3, 2, 4, 7, 4, 2, 5, 7, 5, 2, 6, 7, 6, 2, 7, 7, 7, 2, 8, 7, 8, 2, 9, 7, 9, 2, 10, 7, 10, 2, 11, 7, 11, 2, 12, 7, 12, 2, 13, 7, 13, 2, 14, 7, 14, 2, 15, 7, 15, 2, 16, 7, 16, 2, 17, 7, 17, 2, 18, 7, 18, 2, 19, 7, 19, 2, 20, 7, 20, 2, 21, 7, 21, 2, 22, 7, 22, 2, 23, 7, 23, 2, 24, 7, 24, 2, 25, 7, 25, 2, 26, 7, 26, 2, 27, 7, 27, 2, 28, 7, 28, 2, 29, 7, 29, 2, 30, 7, 30, 2, 31, 7, 31, 2, 32, 7, 32, 2, 33, 7, 33, 2, 34, 7, 34, 2, 35, 7, 35, 2, 36, 7, 36, 2, 37, 7, 37, 2, 38, 7, 38, 2, 39, 7, 39, 2, 40, 7, 40, 2, 41, 7, 41, 2, 42, 7, 42, 2, 43, 7, 43, 2, 44, 7, 44, 2, 45, 7, 45, 2, 46, 7, 46, 2, 47, 7, 47, 2, 48, 7, 48, 2, 49, 7, 49, 2, 50, 7, 50, 2, 51, 7, 51, 2, 52, 7, 52, 2, 53, 7, 53, 2, 54, 7, 54, 2, 55, 7, 55, 2, 56, 7, 56, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 4, 1, 4, 1, 4, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 6, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 7, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 8, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 10, 1, 10, 1, 11, 1, 11, 1, 12, 1, 12, 1, 13, 1, 13, 1, 14, 1, 14, 1, 15, 1, 15, 1, 15, 1, 16, 1, 16, 1, 16, 1, 17, 1, 17, 1, 18, 1, 18, 1, 18, 1, 19, 1, 19, 1, 20, 1, 20, 1, 20, 1, 21, 1, 21, 1, 21, 1, 22, 1, 22, 1, 22, 1, 23, 1, 23, 1, 24, 1, 24, 1, 25, 1, 25, 1, 26, 1, 26, 1, 27, 1, 27, 1, 28, 1, 28, 1, 29, 1, 29, 1, 30, 1, 30, 1, 31, 1, 31, 1, 32, 1, 32, 1, 33, 1, 33, 1, 34, 1, 34, 1, 35, 1, 35, 1, 36, 1, 36, 1, 37, 1, 37, 1, 37, 1, 38, 1, 38, 1, 39, 1, 39, 1, 40, 5, 40, 241, 8, 40, 10, 40, 12, 40, 244, 9, 40, 1, 40, 1, 40, 4, 40, 248, 8, 40, 11, 40, 12, 40, 249, 1, 40, 4, 40, 253, 8, 40, 11, 40, 12, 40, 254, 1, 40, 1, 40, 3, 40, 259, 8, 40, 1, 41, 1, 41, 3, 41, 263, 8, 41, 1, 41, 4, 41, 266, 8, 41, 11, 41, 12, 41, 267, 1, 42, 1, 42, 3, 42, 272, 8, 42, 1, 42, 4, 42, 275, 8, 42, 11, 42, 12, 42, 276, 1, 42, 1, 42, 3, 42, 281, 8, 42, 1, 43, 5, 43, 284, 8, 43, 10, 43, 12, 43, 287, 9, 43, 1, 43, 1, 43, 4, 43, 291, 8, 43, 11, 43, 12, 43, 292, 1, 43, 4, 43, 296, 8, 43, 11, 43, 12, 43, 297, 1, 43, 1, 43, 3, 43, 302, 8, 43, 1, 44, 1, 44, 3, 44, 306, 8, 44, 1, 44, 4, 44, 309, 8, 44, 11, 44, 12, 44, 310, 1, 45, 1, 45, 1, 45, 1, 45, 1, 45, 1, 45, 4, 45, 319, 8, 45, 11, 45, 12, 45, 320, 1, 45, 1, 45, 3, 45, 325, 8, 45, 1, 46, 1, 46, 1, 46, 1, 46, 3, 46, 331, 8, 46, 1, 47, 1, 47, 1, 48, 1, 48, 1, 49, 1, 49, 1, 50, 1, 50, 1, 50, 5, 50, 342, 8, 50, 10, 50, 12, 50, 345, 9, 50, 1, 51, 1, 51, 5, 51, 349, 8, 51, 10, 51, 12, 51, 352, 9, 51, 1, 51, 1, 51, 5, 51, 356, 8, 51, 10, 51, 12, 51, 359, 9, 51, 1, 51, 1, 51, 4, 51, 363, 8, 51, 11, 51, 12, 51, 364, 3, 51, 367, 8, 51, 1, 52, 1, 52, 3, 52, 371, 8, 52, 1, 53, 1, 53, 1, 53, 5, 53, 376, 8, 53, 10, 53, 12, 53, 379, 9, 53, 1, 53, 1, 53, 1, 54, 1, 54, 1, 54, 1, 54, 1, 55, 1, 55, 1, 55, 1, 55, 5, 55, 391, 8, 55, 10, 55, 12, 55, 394, 9, 55, 1, 55, 3, 55, 397, 8, 55, 1, 55, 1, 55, 1, 55, 1, 55, 1, 56, 1, 56, 1, 56, 1, 56, 5, 56, 407, 8, 56, 10, 56, 12, 56, 410, 9, 56, 1, 56, 1, 56, 1, 56, 1, 56, 1, 56, 3, 377, 392, 408, 0, 57, 1, 1, 3, 2, 5, 3, 7, 4, 9, 5, 11, 6, 13, 7, 15, 8, 17, 9, 19, 10, 21, 11, 23, 12, 25, 13, 27, 14, 29, 15, 31, 16, 33, 17, 35, 18, 37, 19, 39, 20, 41, 21, 43, 22, 45, 23, 47, 24, 49, 25, 51, 26, 53, 27, 55, 28, 57, 29, 59, 30, 61, 31, 63, 32, 65, 33, 67, 0, 69, 0, 71, 0, 73, 0, 75, 0, 77, 0, 79, 0, 81, 0, 83, 0, 85, 0, 87, 0, 89, 0, 91, 0, 93, 0, 95, 0, 97, 0, 99, 0, 101, 34, 103, 35, 105, 36, 107, 37, 109, 38, 111, 39, 113, 40, 1, 0, 12, 1, 0, 48, 57, 1, 0, 48, 55, 3, 0, 48, 57, 65, 70, 97, 102, 2, 0, 88, 88, 120, 120, 1, 0, 49, 57, 2, 0, 43, 43, 45, 45, 2, 0, 69, 69, 101, 101, 2, 0, 80, 80, 112, 112, 2, 0, 65, 90, 97, 122, 3, 0, 48, 57, 65, 90, 97, 122, 3, 0, 65, 90, 95, 95, 97, 122, 3, 0, 9, 10, 13, 13, 32, 32, 429, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 0, 5, 1, 0, 0, 0, 0, 7, 1, 0, 0, 0, 0, 9, 1, 0, 0, 0, 0, 11, 1, 0, 0, 0, 0, 13, 1, 0, 0, 0, 0, 15, 1, 0, 0, 0, 0, 17, 1, 0, 0, 0, 0, 19, 1, 0, 0, 0, 0, 21, 1, 0, 0, 0, 0, 23, 1, 0, 0, 0, 0, 25, 1, 0, 0, 0, 0, 27, 1, 0, 0, 0, 0, 29, 1, 0, 0, 0, 0, 31, 1, 0, 0, 0, 0, 33, 1, 0, 0, 0, 0, 35, 1, 0, 0, 0, 0, 37, 1, 0, 0, 0, 0, 39, 1, 0, 0, 0, 0, 41, 1, 0, 0, 0, 0, 43, 1, 0, 0, 0, 0, 45, 1, 0, 0, 0, 0, 47, 1, 0, 0, 0, 0, 49, 1, 0, 0, 0, 0, 51, 1, 0, 0, 0, 0, 53, 1, 0, 0, 0, 0, 55, 1, 0, 0, 0, 0, 57, 1, 0, 0, 0, 0, 59, 1, 0, 0, 0, 0, 61, 1, 0, 0, 0, 0, 63, 1, 0, 0, 0, 0, 65, 1, 0, 0, 0, 0, 101, 1, 0, 0, 0, 0, 103, 1, 0, 0, 0, 0, 105, 1, 0, 0, 0, 0, 107, 1, 0, 0, 0, 0, 109, 1, 0, 0, 0, 0, 111, 1, 0, 0, 0, 0, 113, 1, 0, 0, 0, 1, 115, 1, 0, 0, 0, 3, 121, 1, 0, 0, 0, 5, 125, 1, 0, 0, 0, 7, 131, 1, 0, 0, 0, 9, 136, 1, 0, 0, 0, 11, 139, 1, 0, 0, 0, 13, 144, 1, 0, 0, 0, 15, 150, 1, 0, 0, 0, 17, 156, 1, 0, 0, 0, 19, 165, 1, 0, 0, 0, 21, 172, 1, 0, 0, 0, 23, 174, 1, 0, 0, 0, 25, 176, 1, 0, 0, 0, 27, 178, 1, 0, 0, 0, 29, 180, 1, 0, 0, 0, 31, 182, 1, 0, 0, 0, 33, 185, 1, 0, 0, 0, 35, 188, 1, 0, 0, 0, 37, 190, 1, 0, 0, 0, 39, 193, 1, 0, 0, 0, 41, 195, 1, 0, 0, 0, 43, 198, 1, 0, 0, 0, 45, 201, 1, 0, 0, 0, 47, 204, 1, 0, 0, 0, 49, 206, 1, 0, 0, 0, 51, 208, 1, 0, 0, 0, 53, 210, 1, 0, 0, 0, 55, 212, 1, 0, 0, 0, 57, 214, 1, 0, 0, 0, 59, 216, 1, 0, 0, 0, 61, 218, 1, 0, 0, 0, 63, 220, 1, 0, 0, 0, 65, 222, 1, 0, 0, 0, 67, 224, 1, 0, 0, 0, 69, 226, 1, 0, 0, 0, 71, 228, 1, 0, 0, 0, 73, 230, 1, 0, 0, 0, 75, 232, 1, 0, 0, 0, 77, 235, 1, 0, 0, 0, 79, 237, 1, 0, 0, 0, 81, 258, 1, 0, 0, 0, 83, 260, 1, 0, 0, 0, 85, 280, 1, 0, 0, 0, 87, 301, 1, 0, 0, 0, 89, 303, 1, 0, 0, 0, 91, 324, 1, 0, 0, 0, 93, 330, 1, 0, 0, 0, 95, 332, 1, 0, 0, 0, 97, 334, 1, 0, 0, 0, 99, 336, 1, 0, 0, 0, 101, 338, 1, 0, 0, 0, 103, 366, 1, 0, 0, 0, 105, 370, 1, 0, 0, 0, 107, 372, 1, 0, 0, 0, 109, 382, 1, 0, 0, 0, 111, 386, 1, 0, 0, 0, 113, 402, 1, 0, 0, 0, 115, 116, 5, 99, 0, 0, 116, 117, 5, 111, 0, 0, 117, 118, 5, 110, 0, 0, 118, 119, 5, 115, 0, 0, 119, 120, 5, 116, 0, 0, 120, 2, 1, 0, 0, 0, 121, 122, 5, 105, 0, 0, 122, 123, 5, 110, 0, 0, 123, 124, 5, 116, 0, 0, 124, 4, 1, 0, 0, 0, 125, 126, 5, 102, 0, 0, 126, 127, 5, 108, 0, 0, 127, 128, 5, 111, 0, 0, 128, 129, 5, 97, 0, 0, 129, 130, 5, 116, 0, 0, 130, 6, 1, 0, 0, 0, 131, 132, 5, 118, 0, 0, 132, 133, 5, 111, 0, 0, 133, 134, 5, 105, 0, 0, 134, 135, 5, 100, 0, 0, 135, 8, 1, 0, 0, 0, 136, 137, 5, 105, 0, 0, 137, 138, 5, 102, 0, 0, 138, 10, 1, 0, 0, 0, 139, 140, 5, 101, 0, 0, 140, 141, 5, 108, 0, 0, 141, 142, 5, 115, 0, 0, 142, 143, 5, 101, 0, 0, 143, 12, 1, 0, 0, 0, 144, 145, 5, 119, 0, 0, 145, 146, 5, 104, 0, 0, 146, 147, 5, 105, 0, 0, 147, 148, 5, 108, 0, 0, 148, 149, 5, 101, 0, 0, 149, 14, 1, 0, 0, 0, 150, 151, 5, 98, 0, 0, 151, 152, 5, 114, 0, 0, 152, 153, 5, 101, 0, 0, 153, 154, 5, 97, 0, 0, 154, 155, 5, 107, 0, 0, 155, 16, 1, 0, 0, 0, 156, 157, 5, 99, 0, 0, 157, 158, 5, 111, 0, 0, 158, 159, 5, 110, 0, 0, 159, 160, 5, 116, 0, 0, 160, 161, 5, 105, 0, 0, 161, 162, 5, 110, 0, 0, 162, 163, 5, 117, 0, 0, 163, 164, 5, 101, 0, 0, 164, 18, 1, 0, 0, 0, 165, 166, 5, 114, 0, 0, 166, 167, 5, 101, 0, 0, 167, 168, 5, 116, 0, 0, 168, 169, 5, 117, 0, 0, 169, 170, 5, 114, 0, 0, 170, 171, 5, 110, 0, 0, 171, 20, 1, 0, 0, 0, 172, 173, 5, 43, 0, 0, 173, 22, 1, 0, 0, 0, 174, 175, 5, 45, 0, 0, 175, 24, 1, 0, 0, 0, 176, 177, 5, 42, 0, 0, 177, 26, 1, 0, 0, 0, 178, 179, 5, 47, 0, 0, 179, 28, 1, 0, 0, 0, 180, 181, 5, 37, 0, 0, 181, 30, 1, 0, 0, 0, 182, 183, 5, 61, 0, 0, 183, 184, 5, 61, 0, 0, 184, 32, 1, 0, 0, 0, 185, 186, 5, 33, 0, 0, 186, 187, 5, 61, 0, 0, 187, 34, 1, 0, 0, 0, 188, 189, 5, 60, 0, 0, 189, 36, 1, 0, 0, 0, 190, 191, 5, 60, 0, 0, 191, 192, 5, 61, 0, 0, 192, 38, 1, 0, 0, 0, 193, 194, 5, 62, 0, 0, 194, 40, 1, 0, 0, 0, 195, 196, 5, 62, 0, 0, 196, 197, 5, 61, 0, 0, 197, 42, 1, 0, 0, 0, 198, 199, 5, 38, 0, 0, 199, 200, 5, 38, 0, 0, 200, 44, 1, 0, 0, 0, 201, 202, 5, 124, 0, 0, 202, 203, 5, 124, 0, 0, 203, 46, 1, 0, 0, 0, 204, 205, 5, 33, 0, 0, 205, 48, 1, 0, 0, 0, 206, 207, 5, 61, 0, 0, 207, 50, 1, 0, 0, 0, 208, 209, 5, 44, 0, 0, 209, 52, 1, 0, 0, 0, 210, 211, 5, 59, 0, 0, 211, 54, 1, 0, 0, 0, 212, 213, 5, 40, 0, 0, 213, 56, 1, 0, 0, 0, 214, 215, 5, 41, 0, 0, 215, 58, 1, 0, 0, 0, 216, 217, 5, 123, 0, 0, 217, 60, 1, 0, 0, 0, 218, 219, 5, 125, 0, 0, 219, 62, 1, 0, 0, 0, 220, 221, 5, 91, 0, 0, 221, 64, 1, 0, 0, 0, 222, 223, 5, 93, 0, 0, 223, 66, 1, 0, 0, 0, 224, 225, 7, 0, 0, 0, 225, 68, 1, 0, 0, 0, 226, 227, 7, 1, 0, 0, 227, 70, 1, 0, 0, 0, 228, 229, 7, 2, 0, 0, 229, 72, 1, 0, 0, 0, 230, 231, 5, 48, 0, 0, 231, 74, 1, 0, 0, 0, 232, 233, 5, 48, 0, 0, 233, 234, 7, 3, 0, 0, 234, 76, 1, 0, 0, 0, 235, 236, 7, 4, 0, 0, 236, 78, 1, 0, 0, 0, 237, 238, 7, 5, 0, 0, 238, 80, 1, 0, 0, 0, 239, 241, 3, 67, 33, 0, 240, 239, 1, 0, 0, 0, 241, 244, 1, 0, 0, 0, 242, 240, 1, 0, 0, 0, 242, 243, 1, 0, 0, 0, 243, 245, 1, 0, 0, 0, 244, 242, 1, 0, 0, 0, 245, 247, 5, 46, 0, 0, 246, 248, 3, 67, 33, 0, 247, 246, 1, 0, 0, 0, 248, 249, 1, 0, 0, 0, 249, 247, 1, 0, 0, 0, 249, 250, 1, 0, 0, 0, 250, 259, 1, 0, 0, 0, 251, 253, 3, 67, 33, 0, 252, 251, 1, 0, 0, 0, 253, 254, 1, 0, 0, 0, 254, 252, 1, 0, 0, 0, 254, 255, 1, 0, 0, 0, 255, 256, 1, 0, 0, 0, 256, 257, 5, 46, 0, 0, 257, 259, 1, 0, 0, 0, 258, 242, 1, 0, 0, 0, 258, 252, 1, 0, 0, 0, 259, 82, 1, 0, 0, 0, 260, 262, 7, 6, 0, 0, 261, 263, 3, 79, 39, 0, 262, 261, 1, 0, 0, 0, 262, 263, 1, 0, 0, 0, 263, 265, 1, 0, 0, 0, 264, 266, 3, 67, 33, 0, 265, 264, 1, 0, 0, 0, 266, 267, 1, 0, 0, 0, 267, 265, 1, 0, 0, 0, 267, 268, 1, 0, 0, 0, 268, 84, 1, 0, 0, 0, 269, 271, 3, 81, 40, 0, 270, 272, 3, 83, 41, 0, 271, 270, 1, 0, 0, 0, 271, 272, 1, 0, 0, 0, 272, 281, 1, 0, 0, 0, 273, 275, 3, 67, 33, 0, 274, 273, 1, 0, 0, 0, 275, 276, 1, 0, 0, 0, 276, 274, 1, 0, 0, 0, 276, 277, 1, 0, 0, 0, 277, 278, 1, 0, 0, 0, 278, 279, 3, 83, 41, 0, 279, 281, 1, 0, 0, 0, 280, 269, 1, 0, 0, 0, 280, 274, 1, 0, 0, 0, 281, 86, 1, 0, 0, 0, 282, 284, 3, 71, 35, 0, 283, 282, 1, 0, 0, 0, 284, 287, 1, 0, 0, 0, 285, 283, 1, 0, 0, 0, 285, 286, 1, 0, 0, 0, 286, 288, 1, 0, 0, 0, 287, 285, 1, 0, 0, 0, 288, 290, 5, 46, 0, 0, 289, 291, 3, 71, 35, 0, 290, 289, 1, 0, 0, 0, 291, 292, 1, 0, 0, 0, 292, 290, 1, 0, 0, 0, 292, 293, 1, 0, 0, 0, 293, 302, 1, 0, 0, 0, 294, 296, 3, 71, 35, 0, 295, 294, 1, 0, 0, 0, 296, 297, 1, 0, 0, 0, 297, 295, 1, 0, 0, 0, 297, 298, 1, 0, 0, 0, 298, 299, 1, 0, 0, 0, 299, 300, 5, 46, 0, 0, 300, 302, 1, 0, 0, 0, 301, 285, 1, 0, 0, 0, 301, 295, 1, 0, 0, 0, 302, 88, 1, 0, 0, 0, 303, 305, 7, 7, 0, 0, 304, 306, 3, 79, 39, 0, 305, 304, 1, 0, 0, 0, 305, 306, 1, 0, 0, 0, 306, 308, 1, 0, 0, 0, 307, 309, 3, 67, 33, 0, 308, 307, 1, 0, 0, 0, 309, 310, 1, 0, 0, 0, 310, 308, 1, 0, 0, 0, 310, 311, 1, 0, 0, 0, 311, 90, 1, 0, 0, 0, 312, 313, 3, 75, 37, 0, 313, 314, 3, 87, 43, 0, 314, 315, 3, 89, 44, 0, 315, 325, 1, 0, 0, 0, 316, 318, 3, 75, 37, 0, 317, 319, 3, 71, 35, 0, 318, 317, 1, 0, 0, 0, 319, 320, 1, 0, 0, 0, 320, 318, 1, 0, 0, 0, 320, 321, 1, 0, 0, 0, 321, 322, 1, 0, 0, 0, 322, 323, 3, 89, 44, 0, 323, 325, 1, 0, 0, 0, 324, 312, 1, 0, 0, 0, 324, 316, 1, 0, 0, 0, 325, 92, 1, 0, 0, 0, 326, 327, 5, 92, 0, 0, 327, 331, 5, 34, 0, 0, 328, 329, 5, 92, 0, 0, 329, 331, 5, 92, 0, 0, 330, 326, 1, 0, 0, 0, 330, 328, 1, 0, 0, 0, 331, 94, 1, 0, 0, 0, 332, 333, 7, 8, 0, 0, 333, 96, 1, 0, 0, 0, 334, 335, 7, 9, 0, 0, 335, 98, 1, 0, 0, 0, 336, 337, 7, 10, 0, 0, 337, 100, 1, 0, 0, 0, 338, 343, 3, 99, 49, 0, 339, 342, 3, 97, 48, 0, 340, 342, 5, 95, 0, 0, 341, 339, 1, 0, 0, 0, 341, 340, 1, 0, 0, 0, 342, 345, 1, 0, 0, 0, 343, 341, 1, 0, 0, 0, 343, 344, 1, 0, 0, 0, 344, 102, 1, 0, 0, 0, 345, 343, 1, 0, 0, 0, 346, 350, 3, 77, 38, 0, 347, 349, 3, 67, 33, 0, 348, 347, 1, 0, 0, 0, 349, 352, 1, 0, 0, 0, 350, 348, 1, 0, 0, 0, 350, 351, 1, 0, 0, 0, 351, 367, 1, 0, 0, 0, 352, 350, 1, 0, 0, 0, 353, 357, 3, 73, 36, 0, 354, 356, 3, 69, 34, 0, 355, 354, 1, 0, 0, 0, 356, 359, 1, 0, 0, 0, 357, 355, 1, 0, 0, 0, 357, 358, 1, 0, 0, 0, 358, 367, 1, 0, 0, 0, 359, 357, 1, 0, 0, 0, 360, 362, 3, 75, 37, 0, 361, 363, 3, 71, 35, 0, 362, 361, 1, 0, 0, 0, 363, 364, 1, 0, 0, 0, 364, 362, 1, 0, 0, 0, 364, 365, 1, 0, 0, 0, 365, 367, 1, 0, 0, 0, 366, 346, 1, 0, 0, 0, 366, 353, 1, 0, 0, 0, 366, 360, 1, 0, 0, 0, 367, 104, 1, 0, 0, 0, 368, 371, 3, 85, 42, 0, 369, 371, 3, 91, 45, 0, 370, 368, 1, 0, 0, 0, 370, 369, 1, 0, 0, 0, 371, 106, 1, 0, 0, 0, 372, 377, 5, 34, 0, 0, 373, 376, 3, 93, 46, 0, 374, 376, 9, 0, 0, 0, 375, 373, 1, 0, 0, 0, 375, 374, 1, 0, 0, 0, 376, 379, 1, 0, 0, 0, 377, 378, 1, 0, 0, 0, 377, 375, 1, 0, 0, 0, 378, 380, 1, 0, 0, 0, 379, 377, 1, 0, 0, 0, 380, 381, 5, 34, 0, 0, 381, 108, 1, 0, 0, 0, 382, 383, 7, 11, 0, 0, 383, 384, 1, 0, 0, 0, 384, 385, 6, 54, 0, 0, 385, 110, 1, 0, 0, 0, 386, 387, 5, 47, 0, 0, 387, 388, 5, 47, 0, 0, 388, 392, 1, 0, 0, 0, 389, 391, 9, 0, 0, 0, 390, 389, 1, 0, 0, 0, 391, 394, 1, 0, 0, 0, 392, 393, 1, 0, 0, 0, 392, 390, 1, 0, 0, 0, 393, 396, 1, 0, 0, 0, 394, 392, 1, 0, 0, 0, 395, 397, 5, 13, 0, 0, 396, 395, 1, 0, 0, 0, 396, 397, 1, 0, 0, 0, 397, 398, 1, 0, 0, 0, 398, 399, 5, 10, 0, 0, 399, 400, 1, 0, 0, 0, 400, 401, 6, 55, 0, 0, 401, 112, 1, 0, 0, 0, 402, 403, 5, 47, 0, 0, 403, 404, 5, 42, 0, 0, 404, 408, 1, 0, 0, 0, 405, 407, 9, 0, 0, 0, 406, 405, 1, 0, 0, 0, 407, 410, 1, 0, 0, 0, 408, 409, 1, 0, 0, 0, 408, 406, 1, 0, 0, 0, 409, 411, 1, 0, 0, 0, 410, 408, 1, 0, 0, 0, 411, 412, 5, 42, 0, 0, 412, 413, 5, 47, 0, 0, 413, 414, 1, 0, 0, 0, 414, 415, 6, 56, 0, 0, 415, 114, 1, 0, 0, 0, 31, 0, 242, 249, 254, 258, 262, 267, 271, 276, 280, 285, 292, 297, 301, 305, 310, 320, 324, 330, 341, 343, 350, 357, 364, 366, 370, 375, 377, 392, 396, 408, 1, 6, 0, 0] \ No newline at end of file diff --git a/src/SysYLexer.tokens b/src/SysYLexer.tokens deleted file mode 100644 index 4345538..0000000 --- a/src/SysYLexer.tokens +++ /dev/null @@ -1,73 +0,0 @@ -CONST=1 -INT=2 -FLOAT=3 -VOID=4 -IF=5 -ELSE=6 -WHILE=7 -BREAK=8 -CONTINUE=9 -RETURN=10 -ADD=11 -SUB=12 -MUL=13 -DIV=14 -MOD=15 -EQ=16 -NE=17 -LT=18 -LE=19 -GT=20 -GE=21 -AND=22 -OR=23 -NOT=24 -ASSIGN=25 -COMMA=26 -SEMICOLON=27 -LPAREN=28 -RPAREN=29 -LBRACE=30 -RBRACE=31 -LBRACK=32 -RBRACK=33 -Ident=34 -ILITERAL=35 -FLITERAL=36 -STRING=37 -WS=38 -LINECOMMENT=39 -BLOCKCOMMENT=40 -'const'=1 -'int'=2 -'float'=3 -'void'=4 -'if'=5 -'else'=6 -'while'=7 -'break'=8 -'continue'=9 -'return'=10 -'+'=11 -'-'=12 -'*'=13 -'/'=14 -'%'=15 -'=='=16 -'!='=17 -'<'=18 -'<='=19 -'>'=20 -'>='=21 -'&&'=22 -'||'=23 -'!'=24 -'='=25 -','=26 -';'=27 -'('=28 -')'=29 -'{'=30 -'}'=31 -'['=32 -']'=33 diff --git a/src/sysyc.cpp b/src/sysyc.cpp index 85ee1ec..edd9318 100644 --- a/src/sysyc.cpp +++ b/src/sysyc.cpp @@ -1,12 +1,16 @@ #include #include #include -#include +#include +#include // for getopt +#include // for std::stoi and exceptions + using namespace std; + #include "SysYLexer.h" #include "SysYParser.h" using namespace antlr4; -// #include "Backend.h" + #include "SysYIRGenerator.h" #include "SysYIRPrinter.h" #include "SysYIROptPre.h" @@ -15,7 +19,7 @@ using namespace antlr4; #include "DeadCodeElimination.h" #include "Mem2Reg.h" #include "Reg2Mem.h" -// #include "LLVMIRGenerator.h" + using namespace sysy; int DEBUG = 0; @@ -23,21 +27,27 @@ int DEEPDEBUG = 0; static string argStopAfter; static string argInputFile; -static bool argFormat = false; +static bool argFormat = false; // 目前未使用,但保留 +static string argOutputFilename; +static int optLevel = 0; // 优化级别,默认为0 (不加-O参数时) -void usage(int code = EXIT_FAILURE) { +void usage(int code) { const char *msg = "Usage: sysyc [options] inputfile\n\n" "Supported options:\n" - " -h \tprint help message and exit\n"; - " -f \tpretty-format the input file\n"; - " -s {ast,ir,asm,llvmir,asmd,ird}\tstop after generating AST/IR/Assembly\n"; + " -h \tprint help message and exit\n" + " -f \tpretty-format the input file\n" + " -s {ast,ir,asm,llvmir,asmd,ird}\tstop after generating AST/IR/Assembly\n" + " -S \tcompile to assembly (.s file)\n" + " -o \tplace the output into \n" + " -O\tenable optimization at (e.g., -O0, -O1)\n"; cerr << msg; exit(code); } void parseArgs(int argc, char **argv) { - const char *optstr = "hfs:"; + const char *optstr = "hfs:So:O:"; int opt = 0; + while ((opt = getopt(argc, argv, optstr)) != -1) { switch (opt) { case 'h': @@ -49,101 +59,179 @@ void parseArgs(int argc, char **argv) { case 's': argStopAfter = optarg; break; + case 'S': + argStopAfter = "asm"; + break; + case 'o': + argOutputFilename = optarg; + break; + case 'O': + try { + optLevel = std::stoi(optarg); + if (optLevel < 0) { + cerr << "Error: Optimization level must be non-negative." << endl; + usage(EXIT_FAILURE); + } + } catch (const std::invalid_argument& ia) { + cerr << "Error: Invalid argument for -O: " << optarg << endl; + usage(EXIT_FAILURE); + } catch (const std::out_of_range& oor) { + cerr << "Error: Optimization level out of range: " << optarg << endl; + usage(EXIT_FAILURE); + } + break; default: /* '?' */ - usage(); + usage(EXIT_FAILURE); } } - if (optind >= argc) - usage(); + + if (optind >= argc) { + usage(EXIT_FAILURE); + } argInputFile = argv[optind]; } int main(int argc, char **argv) { parseArgs(argc, argv); - // open the input file + // 1. 打开输入文件 ifstream fin(argInputFile); - if (not fin) { - cerr << "Failed to open file " << argv[1]; + if (not fin.is_open()) { + cerr << "Failed to open input file: " << argInputFile << endl; return EXIT_FAILURE; } - // parse sysy source to AST + // 2. 解析 SysY 源代码到 AST (前端) ANTLRInputStream input(fin); SysYLexer lexer(&input); CommonTokenStream tokens(&lexer); SysYParser parser(&tokens); auto moduleAST = parser.compUnit(); + + // 如果指定停止在 AST 阶段,则打印并退出 if (argStopAfter == "ast") { cout << moduleAST->toStringTree(true) << '\n'; return EXIT_SUCCESS; } - - // visit AST to generate IR + // 3. 遍历 AST 生成 IR (中端开始) SysYIRGenerator generator; generator.visitCompUnit(moduleAST); + auto moduleIR = generator.get(); + auto builder = generator.getBuilder(); // 获取 IRBuilder 实例 + + // 4. 执行 IR 优化 pass + // 无论最终输出是 IR 还是 ASM,只要不是停止在 AST 阶段,都会进入此优化流程。 + // optLevel = 0 时,执行默认优化。 + // optLevel >= 1 时,执行默认优化 + 额外的 -O1 优化。 + cout << "Applying middle-end optimizations (level -O" << optLevel << ")...\n"; + + // 默认优化 pass (在所有优化级别都会执行) + SysYOptPre optPre(moduleIR, builder); + optPre.SysYOptimizateAfterIR(); + + ControlFlowAnalysis cfa(moduleIR); + cfa.init(); + ActiveVarAnalysis ava; + ava.init(moduleIR); + + if (DEBUG) { + cout << "=== After CFA & AVA (Default) ===\n"; + SysYPrinter(moduleIR).printIR(); // 临时打印器用于调试 + } + + DeadCodeElimination dce(moduleIR, &cfa, &ava); + dce.runDCEPipeline(); + if (DEBUG) { + cout << "=== After 1st DCE (Default) ===\n"; + SysYPrinter(moduleIR).printIR(); + } + + Mem2Reg mem2reg(moduleIR, builder, &cfa, &ava); + mem2reg.mem2regPipeline(); + if (DEBUG) { + cout << "=== After Mem2Reg (Default) ===\n"; + SysYPrinter(moduleIR).printIR(); + } + + Reg2Mem reg2mem(moduleIR, builder); + reg2mem.DeletePhiInst(); + if (DEBUG) { + cout << "=== After Reg2Mem (Default) ===\n"; + SysYPrinter(moduleIR).printIR(); + } + + dce.runDCEPipeline(); // 第二次 DCE (默认) + if (DEBUG) { + cout << "=== After 2nd DCE (Default) ===\n"; + SysYPrinter(moduleIR).printIR(); + } + + // 根据优化级别,执行额外的优化 pass + if (optLevel >= 1) { + cout << "Applying additional -O" << optLevel << " optimizations...\n"; + // 放置 -O1 及其以上级别要启用的额外优化 pass + // 例如: + // MyNewOptimizationPass newOpt(moduleIR, builder); + // newOpt.run(); + + // 占位符注释,替换为你的具体优化 pass + // cout << "--- Additional Pass: MyCustomOpt1 ---" << endl; + // MyCustomOpt1 opt1_pass(moduleIR, builder); + // opt1_pass.run(); + + // cout << "--- Additional Pass: MyCustomOpt2 ---" << endl; + // MyCustomOpt2 opt2_pass(moduleIR, builder, &cfa); // 假设需要CFA + // opt2_pass.run(); + // ... 更多 -O1 特有的优化 + } else { + cout << "No additional middle-end optimizations applied for -O" << optLevel << ".\n"; + } + + // 5. 根据 argStopAfter 决定后续操作 + // a) 如果指定停止在 IR 阶段,则打印最终 IR 并退出 if (argStopAfter == "ir" || argStopAfter == "ird") { + // 设置 DEBUG 模式(如果指定了 'ird') if (argStopAfter == "ird") { - DEBUG = 1; - } - auto moduleIR = generator.get(); - SysYPrinter printer(moduleIR); - if (DEBUG) { - cout << "=== Original IR ===\n"; - printer.printIR(); - } - auto builder = generator.getBuilder(); - SysYOptPre optPre(moduleIR, builder); - optPre.SysYOptimizateAfterIR(); - ControlFlowAnalysis cfa(moduleIR); - cfa.init(); - ActiveVarAnalysis ava; - ava.init(moduleIR); - if (DEBUG) { - cout << "=== After CFA & AVA ===\n"; - printer.printIR(); - } - DeadCodeElimination dce(moduleIR, &cfa, &ava); - dce.runDCEPipeline(); - if (DEBUG) { - cout << "=== After 1st DCE ===\n"; - printer.printIR(); - } - Mem2Reg mem2reg(moduleIR, builder, &cfa, &ava); - mem2reg.mem2regPipeline(); - if (DEBUG) { - cout << "=== After Mem2Reg ===\n"; - printer.printIR(); - } - Reg2Mem reg2mem(moduleIR, builder); - reg2mem.DeletePhiInst(); - if (DEBUG) { - cout << "=== After Reg2Mem ===\n"; - printer.printIR(); - } - dce.runDCEPipeline(); - if (DEBUG) { - cout << "=== After 2nd DCE ===\n"; - printer.printIR(); + DEBUG = 1; // 这里可能需要更精细地控制 DEBUG 的开启时机和范围 } + // 打印最终 IR cout << "=== Final IR ===\n"; + SysYPrinter printer(moduleIR); // 在这里创建打印器,因为可能之前调试时用过临时打印器 printer.printIR(); return EXIT_SUCCESS; } - // generate assembly - auto module = generator.get(); - sysy::RISCv64CodeGen codegen(module); + // b) 如果未停止在 IR 阶段,则继续生成汇编 (后端) + sysy::RISCv64CodeGen codegen(moduleIR); // 传入优化后的 moduleIR string asmCode = codegen.code_gen(); + + // 如果指定停止在 ASM 阶段,则打印/保存汇编并退出 if (argStopAfter == "asm" || argStopAfter == "asmd") { + // 设置 DEBUG 模式(如果指定了 'asmd') if (argStopAfter == "asmd") { DEBUG = 1; DEEPDEBUG = 1; } - cout << asmCode << endl; + + if (!argOutputFilename.empty()) { + ofstream fout(argOutputFilename); + if (not fout.is_open()) { + cerr << "Failed to open output file: " << argOutputFilename << endl; + return EXIT_FAILURE; + } + fout << asmCode << endl; + fout.close(); + } else { + cout << asmCode << endl; + } return EXIT_SUCCESS; } - return EXIT_SUCCESS; + // 如果没有匹配到任何 -s 或 -S 选项,即意味着需要生成完整可执行文件(未来的功能) + // 目前,可以简单退出,或者打印一条提示 + cout << "Compilation completed. No output specified (neither -s nor -S). Exiting.\n"; + // return EXIT_SUCCESS; // 或者这里调用一个链接器生成可执行文件 + + return EXIT_SUCCESS; } \ No newline at end of file