Skip to content

Commit 21af90b

Browse files
authored
更新测试流水线 (#52)
* 增加测试样例 * 支持 macos * 不必要的输出 * 更新 readme * 暂时去除 mips 以验证流水线正确性 * install llvm 增加条件 * macos 下准备 llvm 环境 * 更新阶段名 * 集成测试增加 mips,目前会导致流水线失败
1 parent 2d233e1 commit 21af90b

14 files changed

+150
-7
lines changed

.github/workflows/pr-check.yml

+20-5
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ on:
88

99
env:
1010
BUILD_TYPE: Release
11+
LLVM_VERSION: 16.0
1112

1213
jobs:
1314
build:
1415
strategy:
1516
matrix:
17+
os: [ "ubuntu-22.04", "macos-14" ]
1618
backend: [ "llvm", "pcode" ]
1719

18-
runs-on: ubuntu-latest
20+
runs-on: ${{matrix.os}}
1921

2022
steps:
2123
- uses: actions/checkout@v4
@@ -34,20 +36,33 @@ jobs:
3436

3537
strategy:
3638
matrix:
39+
os: [ "ubuntu-22.04", "macos-14" ]
3740
stage: [ "llvm", "pcode", "mips" ]
3841

39-
runs-on: ubuntu-latest
42+
runs-on: ${{matrix.os}}
4043

4144
steps:
4245
- uses: actions/checkout@v4
4346

4447
- name: Install llvm
45-
if: matrix.stage == 'llvm'
48+
if: ${{ matrix.stage == 'llvm' }}
4649
uses: KyleMayes/install-llvm-action@v2
4750
with:
48-
version: "16.0"
51+
version: ${{env.LLVM_VERSION}}
52+
53+
- name: Setup llvm environment for macos
54+
if: ${{ matrix.stage == 'llvm' && contains(matrix.os, 'macos') }}
55+
run: |
56+
LLVM_PATH=${{ env.LLVM_PATH }}
57+
LLVM_VERSION=${{ env.LLVM_VERSION }}
58+
echo "SDKROOT=$(xcrun --sdk macosx --show-sdk-path)" >> $GITHUB_ENV
59+
echo "CPATH=$LLVM_PATH/lib/clang/$LLVM_VERSION/include/" >> $GITHUB_ENV
60+
echo "LDFLAGS=-L$LLVM_PATH/lib" >> $GITHUB_ENV
61+
echo "CPPFLAGS=-I$LLVM_PATH/include" >> $GITHUB_ENV
62+
echo "CC=$LLVM_PATH/bin/clang" >> $GITHUB_ENV
63+
echo "CXX=$LLVM_PATH/bin/clang++" >> $GITHUB_ENV
4964
50-
- name: Install MARS for mips
65+
- name: Install mars emulator for mips
5166
if: matrix.stage == 'mips'
5267
run: wget https://courses.missouristate.edu/KenVollmar/MARS/MARS_4_5_Aug2014/Mars4_5.jar -O ${{github.workspace}}/mars.jar
5368

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ Number: (0|[1-9][0-9]*)(\.[0-9]+)?
6767

6868
[CONTRIBUTING.md](CONTRIBUTING.md)
6969

70+
## 编译构建
71+
72+
- 经过测试的编译环境:ubuntu-22.04、macos-14。
73+
- 前置条件:已安装 cmake、make、clang。
74+
- 构建方式:运行 `./script/build.sh` 脚本,并指定对应后端,如 `bash ./script/build.sh llvm`
75+
7076
## Todo
7177
- [x] 编译器前端
7278
- [x] 词法分析

scripts/build.sh

-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ if [ ! -z "$BUILD_TYPE" ]; then
5151
opt="$opt -DCMAKE_BUILD_TYPE=$BUILD_TYPE"
5252
fi
5353

54-
echo $BUILD_DIR
55-
5654
cmake $opt -B$BUILD_DIR .
5755

5856
make -C $BUILD_DIR

testcases/fibo.input

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
5
2+
1
3+
3
4+
5
5+
7
6+
9

testcases/fibo.output

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
1
2+
3
3+
8
4+
21
5+
55

testcases/fibo.tol

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
var a;
2+
var b;
3+
var i;
4+
var n;
5+
var j;
6+
var m;
7+
var tmp;
8+
9+
let i = 0;
10+
get n;
11+
12+
tag loop;
13+
if i >= n to done;
14+
15+
get m;
16+
let j = 0;
17+
let a = 1;
18+
let b = 1;
19+
20+
tag loop2;
21+
if j >= m to done2;
22+
23+
let tmp = b;
24+
let b = b + a;
25+
let a = tmp;
26+
27+
let j = j + 1;
28+
to loop2;
29+
tag done2;
30+
31+
put a;
32+
33+
let i = i + 1;
34+
to loop;
35+
tag done;

testcases/func.output

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
64

testcases/func.tol

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn add5(a, b) => a + b;
2+
fn add4(a, b) => add5(a, b) + add5(a, b);
3+
fn add3(a, b) => add4(a, b) + add4(a, b);
4+
fn add2(a, b) => add3(a, b) + add3(a, b);
5+
fn add1(a, b) => add2(a, b) + add2(a, b);
6+
fn add(a, b) => add1(a, b) + add1(a, b);
7+
8+
put add(1, 1);

testcases/newton.input

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
5
2+
0.00001
3+
2 3 4 5 7

testcases/newton.output

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
1.414216
2+
1.732051
3+
2.000000
4+
2.236069
5+
2.645751

testcases/newton.tol

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
fn square(x) => x * x;
3+
4+
var eps;
5+
var n;
6+
var x;
7+
var absval;
8+
var N;
9+
var i;
10+
11+
get N;
12+
get eps;
13+
14+
let i = 0;
15+
tag outerloop;
16+
if i >= N to outerdone;
17+
18+
get n;
19+
20+
let x = n;
21+
22+
tag loop;
23+
let absval = square(x) - n;
24+
if absval > 0 to absfin;
25+
let absval = -absval;
26+
tag absfin;
27+
28+
if absval < eps to done;
29+
30+
let x = 0.5 * (x + (n / x));
31+
32+
to loop;
33+
tag done;
34+
35+
put x;
36+
37+
let i = i + 1;
38+
to outerloop;
39+
tag outerdone;

testcases/sum.input

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
10
2+
1 2 3 4 5 6 7 8 9 10

testcases/sum.output

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
55

testcases/sum.tol

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var sum;
2+
var n;
3+
var num;
4+
var i;
5+
6+
let i = 0;
7+
let sum = 0;
8+
9+
get n;
10+
11+
tag loop;
12+
if i >= n to done;
13+
get num;
14+
let sum = sum + num;
15+
let i = i + 1;
16+
to loop;
17+
tag done;
18+
19+
put sum;

0 commit comments

Comments
 (0)