mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-14 22:38:46 +00:00
Update IR's helper functions
This commit is contained in:
10
examples/array4.c
Normal file
10
examples/array4.c
Normal file
@@ -0,0 +1,10 @@
|
||||
int main() {
|
||||
int a[10];
|
||||
int *p = a;
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
*(p++) = i;
|
||||
}
|
||||
|
||||
return a[5] == 5;
|
||||
}
|
||||
13
examples/bitwise.c
Normal file
13
examples/bitwise.c
Normal file
@@ -0,0 +1,13 @@
|
||||
int main() {
|
||||
unsigned char a = -1;
|
||||
unsigned char b = -128;
|
||||
unsigned char c = 127;
|
||||
unsigned char d = b | a; // -1 (255)
|
||||
unsigned char e = b & a; // -128 (128)
|
||||
unsigned char f = b & c; // 0 (0)
|
||||
unsigned char g = b | c; // -1 (255)
|
||||
unsigned char h = -1 ^ -1; // 0 (0)
|
||||
unsigned char i = -1 ^ 0; // -1 (255)
|
||||
|
||||
return d == 255 && e == 128 && f == 0 && g == 255 && h == 0 && i == 255;
|
||||
}
|
||||
5
examples/integer_literal.c
Normal file
5
examples/integer_literal.c
Normal file
@@ -0,0 +1,5 @@
|
||||
int main() {
|
||||
short temp = 0;
|
||||
unsigned int temp2 = 4294967163;
|
||||
return (char)(temp ^ temp2) == 123;
|
||||
}
|
||||
5
examples/integer_literal2.c
Normal file
5
examples/integer_literal2.c
Normal file
@@ -0,0 +1,5 @@
|
||||
int main() {
|
||||
int temp = 0;
|
||||
// `0xFFFFFFFF` is translated as `unsigned int` not `int`
|
||||
return temp < 0xFFFFFFFF;
|
||||
}
|
||||
16
examples/logical_op.c
Normal file
16
examples/logical_op.c
Normal file
@@ -0,0 +1,16 @@
|
||||
int main() {
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
int c = 0;
|
||||
int d = 0;
|
||||
|
||||
if ((a = 1) || (b = 1)) {
|
||||
b++;
|
||||
}
|
||||
|
||||
if ((c = 1) && (d = 1)) {
|
||||
d++;
|
||||
}
|
||||
|
||||
return b == 1 && d == 2;
|
||||
}
|
||||
8
examples/minus_constant.c
Normal file
8
examples/minus_constant.c
Normal file
@@ -0,0 +1,8 @@
|
||||
int a = -1;
|
||||
long b = -1l;
|
||||
float c = -1.5f;
|
||||
double d = -1.5;
|
||||
|
||||
int main() {
|
||||
return (a + b + (int)c + (long)d) == -4;
|
||||
}
|
||||
7
examples/shift.c
Normal file
7
examples/shift.c
Normal file
@@ -0,0 +1,7 @@
|
||||
int main() {
|
||||
char a = -1;
|
||||
char b = a << 1;
|
||||
unsigned char c = (unsigned char)b >> 1;
|
||||
|
||||
return b == -2 && c == 0x7F;
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
int main() {
|
||||
long int l = 1;
|
||||
long l2 = 2;
|
||||
short int s = 3;
|
||||
short s2 = 4;
|
||||
int i = 5;
|
||||
char c = 6;
|
||||
long long l3 = 3;
|
||||
short int s = 4;
|
||||
short s2 = 5;
|
||||
int i = 6;
|
||||
char c = 7;
|
||||
|
||||
return l + l2 + s + s2 + i + c;
|
||||
return (l + l2 + l3 + s + s2 + i + c) == 28;
|
||||
}
|
||||
|
||||
5
examples/typecast.c
Normal file
5
examples/typecast.c
Normal file
@@ -0,0 +1,5 @@
|
||||
char temp = 0x00L;
|
||||
|
||||
int main(){
|
||||
return (temp = 0xEF36L) >= (2L);
|
||||
}
|
||||
4
examples/unary.c
Normal file
4
examples/unary.c
Normal file
@@ -0,0 +1,4 @@
|
||||
int main() {
|
||||
unsigned char temp = 0x00L;
|
||||
return 1 > (--temp);
|
||||
}
|
||||
Reference in New Issue
Block a user