You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

397 lines
8.4 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/* this is a test file coded by gjm
anything to be polished can be added.
./SysYFCompiler ../Student/task3/test_stu/01_test.sy -emit-ir -o ../Student/task3/test_stu/test_stu.ll
*/
int check = -1;
int test_scope = 3;
const float arr1[10] = {1.0, 2.0, 3.0, 4.0}; // 测试数组常量定义
const int N = -1;
int arr_global[N + 2 * 4 - 8 / 8] = {1, 2, 3, 4, 5, 6};
const int year = 2023, month = 12; // 测试int常量定义
const float pi = 3.14159, e = 2.71415; // 测试float常量定义
int test_void = 0;
int test_short_cut = 0;
int func1(int p)
{
int test_scope = 5; // 测试全局与局部作用域覆盖
return (test_scope + p);
}
float func2() // 测试float返回值
{
float p = 0.8;
return (p - 1);
}
void func3()
{
test_void = 1;
;
return;
}
int func4()
{
int c = 70;
while (c <= 70)
{
int d;
d = 40;
if (c < 100)
{
c = c + d;
if (c > 100)
{
int e;
e = -50;
c = c + e;
}
}
}
return c;
}
int func5()
{
int i = 5, j = 7;
while (i < 100)
{
i = i + 30;
while (j < 100)
{
j = j + 6;
}
j = j - 100;
}
return j;
}
int func6()
{
test_short_cut = 1;
return 0;
}
int bubblesort(int arr[], int n)
{
int i, j;
i = 0;
while (i < n - 1)
{
// Last i elements are already in place
j = 0;
while (j < n - i - 1)
{
if (arr[j] > arr[j + 1])
{
int tmp;
tmp = arr[j + 1];
arr[j + 1] = arr[j];
arr[j] = tmp;
}
j = j + 1;
}
i = i + 1;
}
return 0;
}
int mul(int a0[],int a1[], int a2[],int b0[],int b1[],int b2[],int c0[],int c1[],int c2[])
{
int i;
i=0;
c0[0]=a0[0]*b0[0]+a0[1]*b1[0]+a0[2]*b2[0];
c0[1]=a0[0]*b0[1]+a0[1]*b1[1]+a0[2]*b2[1];
c0[2]=a0[0]*b0[2]+a0[1]*b1[2]+a0[2]*b2[2];
c1[0]=a1[0]*b0[0]+a1[1]*b1[0]+a1[2]*b2[0];
c1[1]=a1[0]*b0[1]+a1[1]*b1[1]+a1[2]*b2[1];
c1[2]=a1[0]*b0[2]+a1[1]*b1[2]+a1[2]*b2[2];
c2[0]=a2[0]*b0[0]+a2[1]*b1[0]+a2[2]*b2[0];
c2[1]=a2[0]*b0[1]+a2[1]*b1[1]+a2[2]*b2[1];
c2[2]=a2[0]*b0[2]+a2[1]*b1[2]+a2[2]*b2[2];
return 0;
}
int main()
{
int i = 0; // 通过修改i测试不同语句测试 若check正确都是返回正值错误返回负值-1
if (!i)
{
int a, b;
a = 2;
b = func1(a) * 8 / 14;
if (b == 4)
check = 0;
else
{
{
} // 测试空语句块
return -1;
}
}
i = i + 1;
if (i == 1)
{
int a = 1;
float b = a + func2(); // 测试类型转换
if (b == 0.8)
check = 1;
else
return -1;
}
i = i + 1;
if (i == 2)
{
float arr2[10] = {0.1, 0.2, 0.3};
float arr3[5] = {arr1[1], arr2[2], 0.4, 0.5};
if (arr3[0] == 2.0 && arr3[1] != 0.1) // 测试条件判断和数组初始化
check = 2;
else
return -1;
}
i = i + 1;
if (i == 3)
{
if (arr_global[2] == 3)
check = 3; // 测试全局数组的数组长度计算
else
return (arr_global[2] - arr_global[2] - 1);
}
i = i + 1;
if (i == 4)
{
int a[4] = {1, 2, 3, 4};
int b[3] = {a[0] + a[1], a[1] * a[2]}; // 测试数组用左值计算表达式赋值
if (b[1] == 6)
check = 4;
else
return -1;
}
i = i + 1;
if (i == 5)
{
const int mss = 0xffff;
const int MAX = 114514; // 测试十六进制和八进制
if (mss == 65535 && MAX == 0337522)
check = 5;
else
return -1;
}
i = i + 1;
if (i == 6)
{
int i = 10;
if (i < 20 || func6()) // 测试短路计算
{
if (test_short_cut == 0)
check = 6;
else
return -1;
}
else
{
return -1;
}
}
i = i + 1;
if (i == 7)
{
int a = 2023, b = 12; // 测试if嵌套
if (a == year)
if (b == month)
check = 7;
else
return -1;
else
return -1;
}
i = i + 1;
if (i == 8)
{
func3(); // 测试void函数
if (test_void == 1)
check = 8;
else
return -1;
}
i = i + 1;
if (i == 9)
{
int p;
p = func4(); // 测试while-if嵌套
if (p == 100)
check = 9;
else
return -1;
}
i = i + 1;
if (i == 10)
{
if (!(func5() - 3)) // 测试while嵌套
check = 10;
else
return -1;
}
i = i + 1;
if (i == 11)
{
int j = 0, sum = 0;
while (j < 100)
{
if (j == 50)
{
break; // 测试break语句
}
sum = sum + j;
j = j + 1;
}
if (sum != 1225)
return -1;
else
check = 11;
}
i = i + 1;
if (i == 12)
{
int j = 0, sum = 0;
while (j < 100)
{
if (j == 50)
{
j = j + 1;
continue; // 测试continue语句
}
sum = sum + j;
j = j + 1;
}
if (sum != 4900)
return -1;
else
check = 12;
}
i = i + 1;
if (i == 13)
{
int a = 10;
if (+-!!!a) // 测试单目运算符和非号条件判断
{
a = - - -1;
return a;
}
else // 测试else分支
{
check = 13;
}
}
i = i + 1;
if (i == 14)
{
const int a = 0xf;
const int b = 0xc;
if ((a + b + 075) == 88) // 测试非十进制数值计算
check = 14;
else
return -1;
}
i = i + 1;
if (i == 15)
{
int a = 5, b = 5, c = 1, d = -2;
int result;
result = ((d % 2 + 67) + -(a - b) - -((c + 2) % 2)); // 测试复杂表达式计算
result = result - 68;
if (!result)
check = 15;
else
return -1;
}
i = i + 1;
if (i == 16)
{
int a[10];
a[0] = 4;a[1] = 3;a[2] = 9;a[3] = 2;a[4] = 0;
a[5] = 1;a[6] = 6;a[7] = 5;a[8] = 7;a[9] = 8;
int i;
int n = 10;
i = bubblesort(a, n);
while (i < n)
{
int tmp;
tmp = a[i];
//putint(tmp);
tmp = 10;
//putch(tmp); //换行
i = i + 1;
}
}
i = i + 1;
// if( i == 17 )
// {
// int a0[3];int a1[3]; int a2[3];int b0[3];int b1[3];int b2[3];int c0[6];int c1[3];int c2[3];
// int i;
// i=0;
// while(i<3)
// {
// a0[i]=i;a1[i]=i;a2[i]=i;b0[i]=i;b1[i]=i;b2[i]=i;i=i+1;
// }
// i=mul( a0, a1, a2, b0, b1, b2, c0, c1, c2);
// int x;
// while(i<3)
// {
// x = c0[i];
// putint(x);
// i=i+1;
// }
// x = 10;i=0;
// putch(x);
// while(i<3)
// {
// x = c1[i];
// putint(x);
// i=i+1;
// }
// x = 10;i=0;
// putch(x);
// while(i<3)
// {
// x = c2[i];
// putint(x);
// i=i+1;
// }
// x = 10;putch(x);
// }
i = i + 1;
// if(i == 18)
// {
// int i, sum;
// int a[10];
// sum=0;i=0;
// while(i<10)
// {
// a[i]=i+1;
// i=i+1;
// }
// int x,high,low,mid;
// int n = 10;
// x=5; //待查找数1-10之间
// high=n-1;
// low=0;
// mid=(high+low)/2;
// while(a[mid]!=x && low < high)
// {
// mid=(high+low)/2;
// if(x<a[mid])
// high=mid-1;
// else
// {
// low = mid +1;
// }
// }
// if(x==a[mid])
// putint(x);
// else
// {
// x = -1;
// putint(x);
// }
// x = 10;
// putch(x);
// }
return check;
}