Initial commit from sysy-main

This commit is contained in:
Lixuanwang
2025-02-27 23:14:53 +08:00
commit cc523fd30b
1125 changed files with 257793 additions and 0 deletions

2
testdata/functional/21_if_test2.out vendored Executable file
View File

@@ -0,0 +1,2 @@
-5
0

25
testdata/functional/21_if_test2.sy vendored Executable file
View File

@@ -0,0 +1,25 @@
// test if-else-if
int ifElseIf() {
int a;
a = 5;
int b;
b = 10;
if(a == 6 || b == 0xb) {
return a;
}
else {
if (b == 10 && a == 1)
a = 25;
else if (b == 10 && a == -5)
a = a + 15;
else
a = -+a;
}
return a;
}
int main(){
putint(ifElseIf());
return 0;
}

1
testdata/functional/26_while_test1.out vendored Executable file
View File

@@ -0,0 +1 @@
3

18
testdata/functional/26_while_test1.sy vendored Executable file
View File

@@ -0,0 +1,18 @@
int doubleWhile() {
int i;
i = 5;
int j;
j = 7;
while (i < 100) {
i = i + 30;
while(j < 100){
j = j + 6;
}
j = j - 100;
}
return (j);
}
int main() {
return doubleWhile();
}

1
testdata/functional/35_op_priority1.out vendored Executable file
View File

@@ -0,0 +1 @@
40

9
testdata/functional/35_op_priority1.sy vendored Executable file
View File

@@ -0,0 +1,9 @@
//test the priority of add and mul
int main(){
int a, b, c, d;
a = 10;
b = 4;
c = 2;
d = 2;
return c + a * b - d;
}

1
testdata/functional/40_unary_op.out vendored Executable file
View File

@@ -0,0 +1 @@
0

11
testdata/functional/40_unary_op.sy vendored Executable file
View File

@@ -0,0 +1,11 @@
int main() {
int a;
a = 10;
if (+-!!!a) {
a = - - -1;
}
else {
a = 0;
}
return a;
}

2
testdata/functional/44_stmt_expr.out vendored Executable file
View File

@@ -0,0 +1,2 @@
1024
0

13
testdata/functional/44_stmt_expr.sy vendored Executable file
View File

@@ -0,0 +1,13 @@
int k;
const int n = 10;
int main () {
int i = 0;
k = 1;
while (i <= n - 1) {
i = i + 1;
k + 1;
k = k + k;
}
putint(k);
return k;
}

4
testdata/functional/50_short_circuit.in vendored Executable file
View File

@@ -0,0 +1,4 @@
11
10
100
99

2
testdata/functional/50_short_circuit.out vendored Executable file
View File

@@ -0,0 +1,2 @@
11111210
0

21
testdata/functional/50_short_circuit.sy vendored Executable file
View File

@@ -0,0 +1,21 @@
int g = 0;
int func(int n) {
g = g + n;
putint(g);
return g;
}
int main() {
int i;
i = getint();
if (i > 10 && func(i)) i = 1; else i = 0;
i = getint();
if (i > 11 && func(i)) i = 1; else i = 0;
i = getint();
if (i <= 99 || func(i)) i = 1; else i = 0;
i = getint();
if (i <= 100 || func(i)) i = 1; else i = 0;
if (!func(99) && func(100)) i = 1; else i = 0;
return 0;
}

2
testdata/functional/52_scope.out vendored Executable file
View File

@@ -0,0 +1,2 @@
1
0

27
testdata/functional/52_scope.sy vendored Executable file
View File

@@ -0,0 +1,27 @@
int a = 7;
int func() {
int b = a;
int a = 1;
if (a == b) {
a = a + 1;
return 1;
}
else
return 0;
}
int main() {
int result = 0;
int i = 0;
while (i < 100) {
if (func() == 1)
result = result + 1;
i = i + 1;
}
if (result < 100)
putint(1);
else
putint(0);
return 0;
}

14
testdata/functional/73_int_io.in vendored Executable file
View File

@@ -0,0 +1,14 @@
5
4006571
9900
1504379
758219
99336677

6
testdata/functional/73_int_io.out vendored Executable file
View File

@@ -0,0 +1,6 @@
4006571
9900
1504379
758219
99336677
0

52
testdata/functional/73_int_io.sy vendored Executable file
View File

@@ -0,0 +1,52 @@
const int ascii_0 = 48;
int my_getint()
{
int sum = 0, c;
while (1) {
c = getch() - ascii_0;
if (c < 0 || c > 9) {
continue;
} else {
break;
}
}
sum = c;
while (1) {
c = getch() - ascii_0;
if (c >= 0 && c <= 9) {
sum = sum * 10 + c;
} else {
break;
}
}
return sum;
}
void my_putint(int a)
{
int b[16], i = 0;
while (a > 0) {
b[i] = a % 10 + ascii_0;
a = a / 10;
i = i + 1;
}
while (i > 0) {
i = i - 1;
putch(b[i]);
}
}
int main()
{
int n = my_getint();
while (n > 0) {
int m = my_getint();
my_putint(m); putch(10);
n = n - 1;
}
return 0;
}

2006
testdata/performance/2024-2D0-22.in vendored Executable file

File diff suppressed because one or more lines are too long

2
testdata/performance/2024-2D0-22.out vendored Executable file

File diff suppressed because one or more lines are too long

50
testdata/performance/2024-2D0-22.sy vendored Executable file
View File

@@ -0,0 +1,50 @@
void spmv(int n,int xptr[], int yidx[], int vals[], int b[], int x[]){
int i, j, k;
i = 0;
while (i < n){
x[i] = 0;
i = i + 1;
}
i = 0;
while (i < n){
j = xptr[i];
while (j < xptr[i + 1]){
x[yidx[j]] = x[yidx[j]] + vals[j];
j = j + 1;
}
j = xptr[i];
while (j < xptr[i + 1]){
x[yidx[j]] = x[yidx[j]] + vals[j] * (b[i] - 1);
j = j + 1;
}
i = i + 1;
}
}
const int N = 100010;
const int M = 3000000;
int x[N], y[M], v[M];
int a[N], b[N], c[N];
int main(){
int n = getarray(x) - 1;
int m = getarray(y);
getarray(v);
getarray(a);
starttime();
int i = 0;
while (i < 100){
spmv(n, x, y, v, a, b);
spmv(n, x, y, v, b, a);
i=i+1;
}
stoptime();
putarray(n, b);
return 0;
}

2
testdata/performance/2024-C64-14.out vendored Executable file
View File

@@ -0,0 +1,2 @@
10
0

50
testdata/performance/2024-C64-14.sy vendored Executable file
View File

@@ -0,0 +1,50 @@
//large loop and large array caculate
int COUNT = 500000;
float loop(float x[], float y[], int length) {
int i = 0;
float accum = 0.0;
while (i < length) {
accum = accum + x[i] * y[i];
i = i + 1;
}
return accum;
}
int main() {
int i = 0, j = 0;
float x[6000];
float y[6000];
int len=6000;
float total = 0.0;
float a = 0.0;
float b = 1.0;
starttime();
while ( i < COUNT) {
if (i % 10) {
a = 0.0;
b = 1.0;
} else {
a = a + 0.1;
b = b + 0.2;
}
while ( j < len) {
x[j] = a + j;
y[j] = b + j;
j = j + 1;
}
total = total + loop(x, y, len);
i = i + 1;
}
stoptime();
int final=total - 36239413625225216.0000001;
if (final <=0.000001 && final>= -0.000001) {
putint(10);
return 0;
}
else {
putint(1);
return 1;
}
}