Deleted test/func/sy/00_main.sy, test/func/sy/01_var_defn2.sy,...
嘉然今天偷着乐 authored
Deleted test/func/sy/00_main.sy, test/func/sy/01_var_defn2.sy, test/func/sy/02_var_defn3.sy, test/func/sy/03_arr_defn2.sy, test/func/sy/04_arr_defn3.sy, test/func/sy/05_arr_defn4.sy, test/func/sy/06_const_var_defn2.sy, test/func/sy/07_const_var_defn3.sy, test/func/sy/08_const_array_defn.sy, test/func/sy/09_func_defn.sy, test/func/sy/100_comment2.sy, test/func/sy/101_multiple_returns.sy, test/func/sy/102_ret_in_block.sy, test/func/sy/103_branch.sy, test/func/sy/104_break_continue.sy, test/func/sy/105_param_name.sy, test/func/sy/106_func_name.sy, test/func/sy/107_arr_init_nd.sy, test/func/sy/108_global_arr_init.sy, test/func/sy/109_BFS.sy, test/func/sy/10_var_defn_func.sy, test/func/sy/110_DFS.sy, test/func/sy/111_BST.sy, test/func/sy/112_DSU.sy, test/func/sy/113_LCA.sy, test/func/sy/114_dp.sy, test/func/sy/115_graph_coloring.sy, test/func/sy/116_k_smallest.sy, test/func/sy/117_maximal_clique.sy, test/func/sy/118_prim.sy, test/func/sy/119_search.sy, test/func/sy/11_add2.sy, test/func/sy/120_sort.sy, test/func/sy/121_union_find.sy, test/func/sy/122_matrix_multiply.sy, test/func/sy/123_json.sy, test/func/sy/124_array_only.sy, test/func/sy/125_scope3.sy, test/func/sy/126_scope4.sy, test/func/sy/127_scope5.sy, test/func/sy/128_side_effect2.sy, test/func/sy/129_long_line.sy, test/func/sy/12_addc.sy, test/func/sy/130_many_dimensions.sy, test/func/sy/131_many_indirections.sy, test/func/sy/132_many_params3.sy, test/func/sy/133_multi_branch.sy, test/func/sy/134_multi_loop.sy, test/func/sy/135_math.sy, test/func/sy/136_rotate.sy, test/func/sy/137_dct.sy, test/func/sy/138_light2d.sy, test/func/sy/139_fp_params.sy, test/func/sy/13_sub2.sy, test/func/sy/14_subc.sy, test/func/sy/15_mul.sy, test/func/sy/16_mulc.sy, test/func/sy/17_div.sy, test/func/sy/18_divc.sy, test/func/sy/19_mod.sy, test/func/sy/20_rem.sy, test/func/sy/21_if_test2.sy, test/func/sy/22_if_test3.sy, test/func/sy/23_if_test4.sy, test/func/sy/24_if_test5.sy, test/func/sy/25_while_if.sy, test/func/sy/26_while_test1.sy, test/func/sy/27_while_test2.sy, test/func/sy/28_while_test3.sy, test/func/sy/29_break.sy, test/func/sy/30_continue.sy, test/func/sy/31_while_if_test1.sy, test/func/sy/32_while_if_test2.sy, test/func/sy/33_while_if_test3.sy, test/func/sy/34_arr_expr_len.sy, test/func/sy/35_op_priority1.sy, test/func/sy/36_op_priority2.sy, test/func/sy/37_op_priority3.sy, test/func/sy/38_op_priority4.sy, test/func/sy/39_op_priority5.sy, test/func/sy/40_unary_op.sy, test/func/sy/41_unary_op2.sy, test/func/sy/42_empty_stmt.sy, test/func/sy/43_logi_assign.sy, test/func/sy/44_stmt_expr.sy, test/func/sy/45_comment1.sy, test/func/sy/46_hex_defn.sy, test/func/sy/47_hex_oct_add.sy, test/func/sy/48_assign_complex_expr.sy, test/func/sy/49_if_complex_expr.sy, test/func/sy/50_short_circuit.sy, test/func/sy/51_short_circuit3.sy, test/func/sy/52_scope.sy, test/func/sy/53_scope2.sy, test/func/sy/54_hidden_var.sy, test/func/sy/55_sort_test1.sy, test/func/sy/56_sort_test2.sy, test/func/sy/57_sort_test3.sy, test/func/sy/58_sort_test4.sy, test/func/sy/59_sort_test5.sy, test/func/sy/60_sort_test6.sy, test/func/sy/61_sort_test7.sy, test/func/sy/62_percolation.sy, test/func/sy/63_big_int_mul.sy, test/func/sy/64_calculator.sy, test/func/sy/65_color.sy, test/func/sy/66_exgcd.sy, test/func/sy/67_reverse_output.sy, test/func/sy/68_brainfk.sy, test/func/sy/69_expr_eval.sy, test/func/sy/70_dijkstra.sy, test/func/sy/71_full_conn.sy, test/func/sy/72_hanoi.sy, test/func/sy/73_int_io.sy, test/func/sy/74_kmp.sy, test/func/sy/75_max_flow.sy, test/func/sy/76_n_queens.sy, test/func/sy/77_substr.sy, test/func/sy/78_side_effect.sy, test/func/sy/79_var_name.sy, test/func/sy/80_chaos_token.sy, test/func/sy/81_skip_spaces.sy, test/func/sy/82_long_func.sy, test/func/sy/83_long_array.sy, test/func/sy/84_long_array2.sy, test/func/sy/85_long_code.sy, test/func/sy/86_long_code2.sy, test/func/sy/87_many_params.sy, test/func/sy/88_many_params2.sy, test/func/sy/89_many_globals.sy, test/func/sy/90_many_locals.sy, test/func/sy/91_many_locals2.sy, test/func/sy/92_register_alloc.sy, test/func/sy/93_nested_calls.sy, test/func/sy/94_nested_loops.sy, test/func/sy/95_float.sy, test/func/sy/96_matrix_add.sy, test/func/sy/97_matrix_sub.sy, test/func/sy/98_matrix_mul.sy, test/func/sy/99_matrix_tran.sy, test/test.sy files
d6df9210

SysY-Compiler

介绍

SysY语言编译器

软件架构

本编译器采用了前端ANTLR+后端MLIR的总体架构,当前完成了前端到AST的生成,具体文件结构如下。

sys-y-compiler
├── LICENSE
├── Makefile
├── README.en.md
├── README.md
├── build
├── doc
│   ├── SysY语言定义.pdf
│   └── SysY运行时库.pdf
├── include
│   └── sysy
│       ├── Frontend
│       │   ├── Ast.h
│       │   ├── AstTramsform.h
│       │   ├── AstType.h
│       │   ├── Frontend.h
│       │   ├── Location.h
│       │   ├── SysYLexer.h
│       │   ├── SysYOp.h
│       │   ├── SysYParser.h
│       │   ├── SysYParserBaseVisitor.h
│       │   ├── SysYParserVisitor.h
│       │   ├── SysYVisitor.h
│       │   └── SysyContext.h
│       └── Support
│           ├── CommandLine.h
│           ├── common.h
│           └── debug.h
├── lib
│   └── Frontend
│       ├── Ast.cpp
│       ├── AstTramsform.cpp
│       ├── Frontend.cpp
│       ├── Location.cpp
│       ├── SysYLexer.cpp
│       ├── SysYLexer.g4
│       ├── SysYParser.cpp
│       ├── SysYParser.g4
│       ├── SysYParserBaseVisitor.cpp
│       ├── SysYParserVisitor.cpp
│       ├── SysYVisitor.cpp
│       └── SysyContext.cpp
├── scripts
│   └── config.mk
├── sysyc
├── sysyc.cpp
└── test.sy

安装说明

编译依赖于LLVM和ANTLR

LLVM

我们需要修改scripts/config.mk 中的变量LLVM_CONFIG为您系统中正确的CONIG脚本名。

ANTLR4

我们需要安装ANTLR作为依赖文件。

cd <Where/you/want/to/install/Antlr4>
wget https://www.antlr.org/download/antlr-4.9.3-complete.jar
export CLASSPATH=".:<Where/you/want/to/install/Antlr4>/antlr-4.9.3-complete.jar:$CLASSPATH"
alias antlr4='java -jar <Where/you/want/to/install/Antlr4>/antlr-4.9.3-complete.jar'
alias grun='java org.antlr.v4.gui.TestRig'

我们还需要安装ANTLR的C++运行时环境

git clone https://github.com/antlr/antlr4.git
cd antlr4/runtime/Cpp
mkdir build && mkdir run && cd build
cmake .. -DANTLR_JAR_LOCATION=<Where/you/want/to/install/Antlr4>/antlr-4.9.3-complete.jar -DWITH_DEMO=True
make
sudo make install

后我们需要修改scripts/config.mk的ANTLR相关的变量

ANTLR4 = java -jar <Where/you/want/to/install/Antlr4>/antlr-4.9.2-complete.jar -Dlanguage=Cpp -no-listener -visitor

可以使用发行版

软件使用

$ sysyc <filename> [opt, ..]

$ sysyc <filename> -o outName

# 打印源代码
$ sysyc <filename> --gen=src

# 打印CST
$ sysyc <filename> --gen=cst

# 打印AST
$ sysyc <filename> --gen=ast

# 打印llvm-ir
$ sysyc <filename> --gen=llvm-ir