• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

修订版aad2046b4d80e22ce1d1952cf700a4fe5379441f (tree)
时间2009-05-12 02:01:13
作者Android (Google) Code Review <android-gerrit@goog...>
CommiterAndroid (Google) Code Review

Log Message

Merge change 1366

* changes:

converted to C++

更改概述

差异

--- a/libacc/acc.c
+++ b/libacc/acc.cpp
@@ -20,11 +20,14 @@
2020 3. This notice may not be removed or altered from any source distribution.
2121 */
2222
23+#include <ctype.h>
24+#include <dlfcn.h>
2325 #include <stdarg.h>
2426 #include <stdio.h>
2527 #include <stdlib.h>
2628 #include <string.h>
2729
30+class compiler {
2831 /* vars: value of variables
2932 loc : local variable index
3033 glo : global variable index
@@ -64,12 +67,12 @@ FILE* file;
6467 #define TAG_TOK ' '
6568 #define TAG_MACRO 2
6669
67-pdef(t)
70+void pdef(int t)
6871 {
6972 *(char *)dstk++ = t;
7073 }
7174
72-inp()
75+void inp()
7376 {
7477 if (dptr) {
7578 ch = *(char *)dptr++;
@@ -82,13 +85,13 @@ inp()
8285 /* printf("ch=%c 0x%x\n", ch, ch); */
8386 }
8487
85-isid()
88+int isid()
8689 {
8790 return isalnum(ch) | ch == '_';
8891 }
8992
9093 /* read a character constant */
91-getq()
94+void getq()
9295 {
9396 if (ch == '\\') {
9497 inp();
@@ -97,7 +100,7 @@ getq()
97100 }
98101 }
99102
100-next()
103+void next()
101104 {
102105 int l, a;
103106
@@ -224,11 +227,11 @@ void error(char *fmt,...)
224227 fprintf(stderr, "%d: ", ftell((FILE *)file));
225228 vfprintf(stderr, fmt, ap);
226229 fprintf(stderr, "\n");
227- exit(1);
228230 va_end(ap);
231+ exit(1);
229232 }
230233
231-void skip(c)
234+void skip(int c)
232235 {
233236 if (tok != c) {
234237 error("'%c' expected", c);
@@ -236,7 +239,7 @@ void skip(c)
236239 next();
237240 }
238241
239-o(n)
242+void o(int n)
240243 {
241244 /* cannot use unsigned, so we must do a hack */
242245 while (n && n != -1) {
@@ -246,7 +249,7 @@ o(n)
246249 }
247250
248251 /* output a symbol and patch all calls to it */
249-gsym(t)
252+void gsym(int t)
250253 {
251254 int n;
252255 while (t) {
@@ -261,7 +264,7 @@ gsym(t)
261264 #define psym oad
262265
263266 /* instruction + address */
264-oad(n, t)
267+int oad(int n, int t)
265268 {
266269 o(n);
267270 *(int *)ind = t;
@@ -271,24 +274,24 @@ oad(n, t)
271274 }
272275
273276 /* load immediate value */
274-li(t)
277+int li(int t)
275278 {
276279 oad(0xb8, t); /* mov $xx, %eax */
277280 }
278281
279-gjmp(t)
282+int gjmp(int t)
280283 {
281284 return psym(0xe9, t);
282285 }
283286
284287 /* l = 0: je, l == 1: jne */
285-gtst(l, t)
288+int gtst(int l, int t)
286289 {
287290 o(0x0fc085); /* test %eax, %eax, je/jne xxx */
288291 return psym(0x84 + l, t);
289292 }
290293
291-gcmp(t)
294+int gcmp(int t)
292295 {
293296 o(0xc139); /* cmp %eax,%ecx */
294297 li(0);
@@ -297,14 +300,14 @@ gcmp(t)
297300 o(0xc0);
298301 }
299302
300-gmov(l, t)
303+int gmov(int l, int t)
301304 {
302305 o(l + 0x83);
303306 oad((t < LOCAL) << 7 | 5, t);
304307 }
305308
306309 /* l is one if '=' parsing wanted (quick hack) */
307-unary(l)
310+void unary(int l)
308311 {
309312 int n, t, a, c;
310313
@@ -375,7 +378,7 @@ unary(l)
375378 n = *(int *)t;
376379 /* forward reference: try dlsym */
377380 if (!n)
378- n = dlsym(0, last_id);
381+ n = (int) dlsym(0, (char*) last_id);
379382 if (tok == '=' & l) {
380383 /* assignment */
381384 next();
@@ -426,7 +429,7 @@ unary(l)
426429 }
427430 }
428431
429-sum(l)
432+void sum(int l)
430433 {
431434 int t, n, a;
432435
@@ -468,19 +471,20 @@ sum(l)
468471 }
469472 }
470473
471-expr()
474+void expr()
472475 {
473476 sum(11);
474477 }
475478
476479
477-test_expr()
480+int test_expr()
478481 {
479482 expr();
480483 return gtst(0, 0);
481484 }
482485
483-block(l)
486+
487+void block(int l)
484488 {
485489 int a, n, t;
486490
@@ -524,7 +528,7 @@ block(l)
524528 }
525529 }
526530 skip(')');
527- block(&a);
531+ block((int) &a);
528532 gjmp(n - ind - 5); /* jmp */
529533 gsym(a);
530534 } else if (tok == '{') {
@@ -550,7 +554,7 @@ block(l)
550554 }
551555
552556 /* 'l' is true if local declarations */
553-decl(l)
557+void decl(int l)
554558 {
555559 int a;
556560
@@ -599,7 +603,10 @@ decl(l)
599603 }
600604 }
601605
602-main(int n, char** t)
606+public:
607+compiler(){}
608+
609+int compile(int n, char** t)
603610 {
604611 file = stdin;
605612 if (n-- > 1) {
@@ -627,3 +634,10 @@ main(int n, char** t)
627634 return (*(int (*)())*(int *)(vars + TOK_MAIN)) (n, t);
628635 #endif
629636 }
637+
638+};
639+
640+int main(int argc, char** argv) {
641+ compiler c;
642+ return c.compile(argc, argv);
643+}
\ No newline at end of file
--- a/libacc/test
+++ b/libacc/test
@@ -1,2 +1,2 @@
11 #!/bin/sh
2-gcc acc.c -DTEST -ldl -o tests/acc && tests/acc tests/otcc.c tests/otcc.out && diff tests/otcc.out tests/otcc.out-orig
2+g++ acc.cpp -DTEST -ldl -o tests/acc && tests/acc tests/otcc.c tests/otcc.out && diff tests/otcc.out tests/otcc.out-orig
Binary files a/libacc/tests/hello.out-orig and b/libacc/tests/hello.out-orig differ
Binary files a/libacc/tests/otcc.out-orig and b/libacc/tests/otcc.out-orig differ