|
|
/*./SysYFCompiler ../Student/task3/test_stu/test.sy -emit-ir -o ../Student/task3/test_stu/mytest.ll*/
|
|
|
/*输出99表示测试通过,否则输出的int对应出错的测试点*/
|
|
|
//float
|
|
|
float global_fbb2[5] = {1.0,2.0,3.0};
|
|
|
const float global_fca = 3.01;
|
|
|
const float global_fcaa[5]={1.0,2.0,3.0,4.0};
|
|
|
|
|
|
//int
|
|
|
const int global_ica = 3;
|
|
|
const int global_icaa[10] = {1,2,3,4,5,6,7,8,9,10};
|
|
|
|
|
|
int global_ia;
|
|
|
float global_fb;
|
|
|
int global_iaa[10];
|
|
|
float global_fbb[5];
|
|
|
|
|
|
int global_ia2 = 1;
|
|
|
int global_ia3 = 2+3;
|
|
|
float global_fb2 = 1.0;
|
|
|
int global_fb3 = 2*3+1;
|
|
|
|
|
|
int global_iaa2[10] = {1,2,3,4,5,6,7,8,9,10};
|
|
|
|
|
|
int global_iaa3[10] = {1,2,3,4,5,6,8,9};
|
|
|
|
|
|
//测试全局作用域和局部作用域
|
|
|
int scope_test = 1;
|
|
|
|
|
|
//函数定义
|
|
|
int func1(int a, int b){
|
|
|
int scope_test = a + b;
|
|
|
return scope_test;
|
|
|
}
|
|
|
int func2(float a, float b){
|
|
|
//给全局变量赋值
|
|
|
global_fb2 = a + b;
|
|
|
//return缺省
|
|
|
}
|
|
|
//测试返回值是表达式
|
|
|
int func3(int a, int b){
|
|
|
return a + b;
|
|
|
}
|
|
|
//测试返回类型转换
|
|
|
int func4(float a, float b){
|
|
|
float c = a + b;
|
|
|
return c;
|
|
|
}
|
|
|
|
|
|
int func_5(){
|
|
|
int a=1;
|
|
|
int c;
|
|
|
{
|
|
|
int a=2;
|
|
|
c=a;
|
|
|
}
|
|
|
int b=a;
|
|
|
return b+c;
|
|
|
}
|
|
|
|
|
|
|
|
|
//测试while循环
|
|
|
int func_while()
|
|
|
{
|
|
|
int a = 0;
|
|
|
int re;
|
|
|
while(a < 10)
|
|
|
{
|
|
|
a = a + 1;
|
|
|
if(a == 7)
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
else if(a==6)
|
|
|
{
|
|
|
re=a;
|
|
|
}
|
|
|
else
|
|
|
{//empty
|
|
|
}
|
|
|
}
|
|
|
return re+a;
|
|
|
}
|
|
|
//while+if
|
|
|
int func_while_if()
|
|
|
{
|
|
|
int b = 0;
|
|
|
int a = 0;
|
|
|
while(a < 20)
|
|
|
{
|
|
|
a = a + 1;
|
|
|
if(a < 5)
|
|
|
{
|
|
|
a = a + 1;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if(a>10)
|
|
|
{
|
|
|
a = a + 2;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
}
|
|
|
b = b + 1;//6
|
|
|
}
|
|
|
return b;
|
|
|
}
|
|
|
|
|
|
//febonacci数列
|
|
|
void func_febonacci(int febonacci[])
|
|
|
{
|
|
|
int i=2;
|
|
|
febonacci[0] = 0;
|
|
|
febonacci[1] = 1;//1 1 2 3 5 8 13 21 34
|
|
|
while(i < 10)
|
|
|
{
|
|
|
febonacci[i] = febonacci[i-1] + febonacci[i-2];
|
|
|
i = i + 1;
|
|
|
}
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//冒泡排序 while循环
|
|
|
int sort(int arr[],int n)
|
|
|
{
|
|
|
int i,j;
|
|
|
int temp;
|
|
|
i = 0;
|
|
|
while(i < n)
|
|
|
{
|
|
|
j = 0;
|
|
|
while(j < n - i - 1)
|
|
|
{
|
|
|
if(arr[j] > arr[j+1])
|
|
|
{
|
|
|
temp = arr[j+1];
|
|
|
arr[j+1] = arr[j];
|
|
|
arr[j] = temp;
|
|
|
}
|
|
|
j = j + 1;
|
|
|
}
|
|
|
i = i + 1;
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
//测试短路计算
|
|
|
int short_cut_flag=0;
|
|
|
int short_cut()
|
|
|
{
|
|
|
short_cut_flag=1;
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
|
int check=99;
|
|
|
int main()
|
|
|
{
|
|
|
if(global_ia3!=5)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 1;
|
|
|
}
|
|
|
if(global_fb3!=7)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 2;
|
|
|
}
|
|
|
int i=0;
|
|
|
while(i<10)
|
|
|
{
|
|
|
if(global_iaa2[i]!=i+1)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 3;
|
|
|
}
|
|
|
i=i+1;
|
|
|
}
|
|
|
if(global_fbb2[4]!=0)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 4;
|
|
|
}
|
|
|
if(func1(1,2)!=3)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 5;
|
|
|
}
|
|
|
if(scope_test!=1)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 6;
|
|
|
}
|
|
|
{//测试局部作用域
|
|
|
int scope_test=2;
|
|
|
if(scope_test!=2)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 7;
|
|
|
}
|
|
|
}
|
|
|
if(scope_test!=1)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 8;
|
|
|
}
|
|
|
//return缺省
|
|
|
if(func2(2.15,3.01)!=0)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 9;
|
|
|
}
|
|
|
if(global_fb2!=5.16)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 10;
|
|
|
}
|
|
|
if(func3(1,2)!=3)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 11;
|
|
|
}
|
|
|
if(func4(1.1,2.01)!=3)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 12;
|
|
|
}
|
|
|
if(func_5()!=3)//
|
|
|
{
|
|
|
check=-1;
|
|
|
return 13;
|
|
|
}
|
|
|
if(func_while()!=13)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 14;
|
|
|
}
|
|
|
int febonacci[10];
|
|
|
func_febonacci(febonacci);
|
|
|
if(febonacci[9]!=34)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 15;
|
|
|
}
|
|
|
int arr_2[10]={1,33,-5,7,-1,-2,4,6,28,10};
|
|
|
sort(arr_2,10);
|
|
|
if(arr_2[0]!=-5||arr_2[1]!=-2||arr_2[2]!=-1||arr_2[3]!=1||arr_2[4]!=4)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 16;
|
|
|
}
|
|
|
if(arr_2[5]!=6||arr_2[6]!=7||arr_2[7]!=10||arr_2[8]!=28||arr_2[9]!=33)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 17;
|
|
|
}
|
|
|
|
|
|
int arr_3[3]={global_iaa2[0]-global_iaa2[1],global_iaa2[2]*global_iaa2[3],global_iaa2[4]+global_iaa2[5]};
|
|
|
if(arr_3[0]!=-1||arr_3[1]!=12||arr_3[2]!=11)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 18;
|
|
|
}
|
|
|
//16进制和8进制赋值
|
|
|
const int h1=0x10+0x1;
|
|
|
if(h1!=17)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 19;
|
|
|
}
|
|
|
const int o1=017+011;
|
|
|
if(o1!=24)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 20;
|
|
|
}
|
|
|
short_cut_flag=0;
|
|
|
if(short_cut_flag<7||short_cut())
|
|
|
{
|
|
|
if(short_cut_flag!=0)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 21;
|
|
|
}
|
|
|
}
|
|
|
short_cut_flag=0;
|
|
|
if(5==5&&short_cut())
|
|
|
{
|
|
|
if(short_cut_flag!=1)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 22;
|
|
|
}
|
|
|
}
|
|
|
short_cut_flag=0;
|
|
|
if(5==6&&short_cut())
|
|
|
{
|
|
|
if(short_cut_flag!=0)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 23;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//单目运算符
|
|
|
int unary=12;
|
|
|
if((-+unary)!=-12)
|
|
|
{
|
|
|
//printf("unary=%d\n",unary);
|
|
|
check=-1;
|
|
|
return 24;
|
|
|
}
|
|
|
if(!unary)
|
|
|
{
|
|
|
check=-1;
|
|
|
return 25;
|
|
|
}
|
|
|
//printf("check=%d\n",check);
|
|
|
//printf("HHHHHHHHHHHHH");
|
|
|
return check;
|
|
|
|
|
|
} |