diff options
Diffstat (limited to 'libacc/tests/data')
-rw-r--r-- | libacc/tests/data/constants.c | 30 | ||||
-rw-r--r-- | libacc/tests/data/expr-ansi.c | 60 | ||||
-rw-r--r-- | libacc/tests/data/expr2.c | 6 | ||||
-rw-r--r-- | libacc/tests/data/locals.c | 71 | ||||
-rw-r--r-- | libacc/tests/data/otcc-ansi.c | 25 | ||||
-rw-r--r-- | libacc/tests/data/otcc.c | 2 | ||||
-rw-r--r-- | libacc/tests/data/returnval-ansi.c | 3 | ||||
-rw-r--r-- | libacc/tests/data/returnval.c | 3 |
8 files changed, 192 insertions, 8 deletions
diff --git a/libacc/tests/data/constants.c b/libacc/tests/data/constants.c new file mode 100644 index 0000000..230109a --- /dev/null +++ b/libacc/tests/data/constants.c @@ -0,0 +1,30 @@ +#define FOO 0x10 + +int main() { + printf("0 = %d\n", 0); + printf("010 = %d\n", 010); + printf("0x10 = %d\n", FOO); + printf("'\\a' = %d\n", '\a'); + printf("'\\b' = %d\n", '\b'); + printf("'\\f' = %d\n", '\f'); + printf("'\\n' = %d\n", '\n'); + printf("'\\r' = %d\n", '\r'); + printf("'\\t' = %d\n", '\t'); + printf("'\\v' = %d\n", '\v'); + // Undefined + // printf("'\\z' = %d\n", '\z'); + printf("'\\\\' = %d\n", '\\'); + printf("'\\'' = %d\n", '\''); + printf("'\\\"' = %d\n", '\"'); + printf("'\\?' = %d\n", '\?'); + printf("'\\0' = %d\n", '\0'); + printf("'\\1' = %d\n", '\1'); + printf("'\\12' = %d\n", '\12'); + printf("'\\123' = %d\n", '\123'); + printf("'\\x0' = %d\n", '\x0'); + printf("'\\x1' = %d\n", '\x1'); + printf("'\\x12' = %d\n", '\x12'); + printf("'\\x123' = %d\n", '\x123'); + printf("'\\x1f' = %d\n", '\x1f'); + printf("'\\x1F' = %d\n", '\x1F'); +} diff --git a/libacc/tests/data/expr-ansi.c b/libacc/tests/data/expr-ansi.c new file mode 100644 index 0000000..d463659 --- /dev/null +++ b/libacc/tests/data/expr-ansi.c @@ -0,0 +1,60 @@ +/* Test operators */ + +void testInc() { int a, b; a = 3; b = a++; printf("3++ = %d %d\n", b, a); } +void testDec() { int a, b; a = 3; b = a--; printf("3-- = %d %d\n", b, a); } +void testTimes(){ printf("%d * %d = %d\n", 10, 4, 10 * 4); } +void testDiv(){ printf("%d / %d = %d\n", 11, 4, 11 / 4); } +void testMod(){ printf("%d %% %d = %d\n", 11, 4, 11 % 4); } +void testPlus(){ printf("%d + %d = %d\n", 10, 4, 10 + 4); } +void testMinus(){ printf("%d - %d = %d\n", 10, 4, 10 - 4); } +void testShiftLeft(){ printf("%d << %d = %d\n", 10, 4, 10 << 4); } +void testShiftRight(){ printf("%d >> %d = %d\n", 100, 4, 100 >> 4); } +void testLess(){ printf("%d < %d = %d\n", 10, 4, 10 < 4); } +void testLesEqual(){ printf("%d <= %d = %d\n", 10, 4, 10 <= 4); } +void testGreater(){ printf("%d > %d = %d\n", 10, 4, 10 > 4); } +void testGreaterEqual(){ printf("%d >= %d = %d\n", 10, 4, 10 >= 4); } +void testEqualTo(){ printf("%d == %d = %d\n", 10, 4, 10 == 4); } +void testNotEqualTo(){ printf("%d != %d = %d\n", 10, 4, 10 != 4); } +void testBitAnd(){ printf("%d & %d = %d\n", 10, 7, 10 & 7); } +void testBitXor(){ printf("%d ^ %d = %d\n", 10, 7, 10 ^ 7); } +void testBitOr(){ printf("%d | %d = %d\n", 10, 4, 10 | 4); } +void testAssignment(){ int a, b; a = 3; b = a; printf("b == %d\n", b); } +void testLogicalAnd(){ printf("%d && %d = %d\n", 10, 4, 10 && 4); } +void testLogicalOr(){ printf("%d || %d = %d\n", 10, 4, 10 || 4); } +void testAddressOf(){ int a; printf("&a is %d\n", &a); } +void testPointerIndirection(){ int a, b; a = &b; b = 17; printf("*%d = %d =?= %d\n", a, * (int*) a, b); } +void testNegation(){ printf("-%d = %d\n", 10, -10); } +void testUnaryPlus(){ printf("+%d = %d\n", 10, +10); } +void testUnaryNot(){ printf("!%d = %d\n", 10, !10); } +void testBitNot(){ printf("~%d = %d\n", 10, ~10); } + +int main(int a, char** b) { + testInc(); + testDec(); + testTimes(); + testDiv(); + testMod(); + testPlus(); + testMinus(); + testShiftLeft(); + testShiftRight(); + testLess(); + testLesEqual(); + testGreater(); + testGreaterEqual(); + testEqualTo(); + testNotEqualTo(); + testBitAnd(); + testBinXor(); + testBitOr(); + testAssignment(); + testLogicalAnd(); + testLogicalOr(); + testAddressOf(); + testPointerIndirection(); + testNegation(); + testUnaryPlus(); + testUnaryNot(); + testBitNot(); + return 0; +} diff --git a/libacc/tests/data/expr2.c b/libacc/tests/data/expr2.c new file mode 100644 index 0000000..04b6a38 --- /dev/null +++ b/libacc/tests/data/expr2.c @@ -0,0 +1,6 @@ +/* Test operators */ + +main() { + int a; + a = a++; +} diff --git a/libacc/tests/data/locals.c b/libacc/tests/data/locals.c new file mode 100644 index 0000000..f1ef363 --- /dev/null +++ b/libacc/tests/data/locals.c @@ -0,0 +1,71 @@ +int a; + +int f() { + int a; + // Undefined variable b + // printf("f 0: a = %d b = %d\n", a, b); + printf("f 0: a = %d\n", a); + a = 2; + printf("f 1: a = %d\n", a); +} + +int g(int a) { + printf("g 0: a = %d\n", a); + a = 3; + printf("g 1: a = %d\n", a); +} + +int h(int a) { + // int a; // gcc 4.3 says error: 'a' redeclared as different kind of symbol + + printf("h 0: a = %d\n", a); + a = 4; + printf("h 1: a = %d\n", a); +} + +// Already defined global +// int h() {} +int globCheck() { + fprintf(stdout, "globCheck()\n"); +} + +int fwdCheck() { + b(); + // Undefined forward reference + // c(); +} + +int b() { + printf("b()\n"); +} + +int nested() { + int a; + printf("nested 0: a = %d\n", a); + a = 50; + printf("nested 1: a = %d\n", a); + { + int a; + printf("nested 2: a = %d\n", a); + a = 51; + printf("nested 3: a = %d\n", a); + } + printf("nested 4: a = %d\n", a); +} + +int main() { + globCheck(); + fwdCheck(); + printf("main 0: a = %d\n", a); + a = 5; + printf("main 1: a = %d\n", a); + f(); + printf("main 2: a = %d\n", a); + g(77); + printf("main 3: a = %d\n", a); + h(30); + printf("main 4: a = %d\n", a); + nested(); + printf("main 5: a = %d\n", a); + return 0; +} diff --git a/libacc/tests/data/otcc-ansi.c b/libacc/tests/data/otcc-ansi.c index 069514b..72580e9 100644 --- a/libacc/tests/data/otcc-ansi.c +++ b/libacc/tests/data/otcc-ansi.c @@ -50,7 +50,7 @@ void ad() { o(); } C = 0; - d = h; + d = h; if (X()) { E(32); M = D; @@ -162,7 +162,7 @@ void Z(int e) { void N(int j, int e) { ae(j + 131); - s((e < 512) << 7 | 5, e); + s((e > -512 && e < 512) << 7 | 5, e); } void T (int j) { @@ -404,7 +404,7 @@ void ab (int j) { v=v +4; } ad(); - if( d == 44)ad(); + if( d == 44)ad() ; } ad(); } @@ -432,11 +432,20 @@ void ab (int j) { } } +int run(int g, int e) { + return (*(int(*)()) *(int*) (P + 592))(g, e); +} + int main(int g, int e) { + int result; Q = stdin; if (g-- > 1) { e = e + 4; Q = fopen(*(int*) e, "r"); + if (!Q) { + fprintf(stderr, "otcc-ansi.c: could not open file %s\n", *(int*) e); + return -2; + } } D = strcpy(R = calloc(1, 99999), " int if else while break return for define main ") + 48; v = calloc(1, 99999); @@ -445,5 +454,13 @@ int main(int g, int e) { o(); ad(); ab(0); - return (*(int(*)()) *(int*) (P + 592))(g, e); + if (mprotect(ac & (~ 4095), (99999 + 4095) & (~ 4095), 7)) { + printf("Mprotect failed. %d\n", errno); + return -1; + } + fprintf(stderr, "otcc-ansi.c: About to execute compiled code:\n"); + result = run(g, e); + fprintf(stderr, "atcc-ansi.c: result: %d\n", result); + return result; } + diff --git a/libacc/tests/data/otcc.c b/libacc/tests/data/otcc.c index 577fcf3..433ae2e 100644 --- a/libacc/tests/data/otcc.c +++ b/libacc/tests/data/otcc.c @@ -441,6 +441,8 @@ P V; o f; c; ab(0); +mprotect(ac & (~ 4095), (99999 + 4095) & (~ 4095), 7); +fprintf(stderr, "otcc.c: about to execute compiled code.\n"); J(*(int(*)f)k(P+592))(g,n; } diff --git a/libacc/tests/data/returnval-ansi.c b/libacc/tests/data/returnval-ansi.c index 42802c5..6b53fd5 100644 --- a/libacc/tests/data/returnval-ansi.c +++ b/libacc/tests/data/returnval-ansi.c @@ -1,7 +1,8 @@ + int main(int argc, char** argv) { return f(); } int f() { - return 10; + return 42; } diff --git a/libacc/tests/data/returnval.c b/libacc/tests/data/returnval.c index 1b9dd81..1cf5bae 100644 --- a/libacc/tests/data/returnval.c +++ b/libacc/tests/data/returnval.c @@ -1,6 +1,3 @@ -#pragma foo3(bar) //sdfsfd -#pragma a(b) - main() { return 42; } |