# HG changeset patch # User Shinji KONO # Date 1382079095 -32400 # Node ID e5c8532ab38d34c5ee1803dcbd466a5681f555ac # Parent 5b631c16f89bc54a918d4f7d5e229fdc046130fa fix for Mountain lion diff -r 5b631c16f89b -r e5c8532ab38d Makefile --- a/Makefile Fri Nov 02 14:04:35 2012 +0900 +++ b/Makefile Fri Oct 18 15:51:35 2013 +0900 @@ -1,14 +1,15 @@ -TEST = s-intel +TEST = s-imac64 -CC = gcc -CFLAGS = -g -O -Wall +CC = clang +# CFLAGS = -g -O -Wall +CFLAGS = -g -O0 -Wall YYFLAGS = -v -COMPILER = s-compile.o s-token.o -# COMPILER = s-tree-compile.o s-token.o +# COMPILER = s-compile.o s-token.o +COMPILER = s-tree-compile.o s-token.o # COMPILER = s-yacc.o s-token.o # TARGET = token calc s-calc s-prefix s-rpn s-09 s-intel s-intel-r s-sparc s-rs6k s-m68k s-ppc s-imac -TARGET = token calc s-calc s-prefix s-rpn s-intel s-intel-r s-sparc s-ppc s-imac s-imac64 +TARGET = token calc s-calc s-calc-left s-prefix s-rpn s-intel s-intel-r s-sparc s-ppc s-imac s-imac64 # s-imac64-r s-llvm all: $(TARGET) token: token.o s-token.o @@ -17,7 +18,10 @@ calc: calc.c $(CC) $(CFLAGS) -o $@ $^ -s-calc: s-calc.c s-token.o +s-calc: s-calc-r.c s-token.o + $(CC) $(CFLAGS) -o $@ $^ + +s-calc-left: s-calc.c s-token.o $(CC) $(CFLAGS) -o $@ $^ s-tree: s-tree.c s-token.o @@ -39,6 +43,10 @@ $(CC) $(CFLAGS) -o $@ $^ s-imac64: $(COMPILER) s-code-intel64-mac.o $(CC) $(CFLAGS) -o $@ $^ +s-imac64-r: $(COMPILER) s-code-intel64-mac-r.o + $(CC) $(CFLAGS) -o $@ $^ +s-llvm: $(COMPILER) s-code-llvm.o + $(CC) $(CFLAGS) -o $@ $^ s-sparc: $(COMPILER) s-code-sparc.o $(CC) $(CFLAGS) -o $@ $^ s-rs6k: $(COMPILER) s-code-rs6k.o diff -r 5b631c16f89b -r e5c8532ab38d calc.c --- a/calc.c Fri Nov 02 14:04:35 2012 +0900 +++ b/calc.c Fri Oct 18 15:51:35 2013 +0900 @@ -58,7 +58,7 @@ } if('1'<=c && c<='9') { /* Decimal */ d = c-'0'; - while(c= *ptr++) { + while((c= *ptr++)) { if('0'<=c && c<='9') { d = d*10 + (c - '0'); } else { @@ -72,7 +72,7 @@ } else if ('0'==c && 'x'== *ptr) { /* Hex */ ptr++; d = 0; - while(c= *ptr++) { + while((c= *ptr++)) { if('0'<=c && c<='9') { d = d*16 + (c - '0'); } else if('a'<=c && c<='f') { @@ -89,7 +89,7 @@ return last_token; } else if ('0'==c) { /* Octal */ d = c-'0'; - while(c= *ptr++) { + while((c= *ptr++)) { if('0'<=c && c<='7') { d = d*8 + (c - '0'); } else { @@ -102,7 +102,7 @@ return last_token; } else if ('\''==c) { /* Ascii */ d = 0; - while(c= *ptr++) { + while((c= *ptr++)) { if('\''!=c && c<=0x7f) { d = d*256 + c; } else if(c>=0x80 && *ptr) { @@ -127,6 +127,7 @@ } else if ('!'==c && '='== *ptr) { /* equal */ ptr++; last_token = T_NEQUAL; + return last_token; } else if ('<'==c && '<'== *ptr) { /* shift */ ptr++; last_token = T_LSHIFT; @@ -138,7 +139,6 @@ } else { last_token = c; return last_token; - return c; } } diff -r 5b631c16f89b -r e5c8532ab38d s-code-intel-mac.c --- a/s-code-intel-mac.c Fri Nov 02 14:04:35 2012 +0900 +++ b/s-code-intel-mac.c Fri Oct 18 15:51:35 2013 +0900 @@ -111,7 +111,7 @@ printf("\tmovl %%eax,%%ebx\n"); printf("\tpopl %%eax\n"); printf("\tcltd\n"); - printf("\tidiv %%ebx\n",op); + printf("\tidiv %%ebx\n"); } else if(op==O_SUB) { printf("\tpopl %%ebx\n"); printf("\t%s %%ebx,%%eax\n",opcode[op]); diff -r 5b631c16f89b -r e5c8532ab38d s-code-intel-r.c --- a/s-code-intel-r.c Fri Nov 02 14:04:35 2012 +0900 +++ b/s-code-intel-r.c Fri Oct 18 15:51:35 2013 +0900 @@ -92,14 +92,14 @@ static char *reg_name[] = {"%eax","%ebx","%ecx","%edx","%esi", "%edi","%ebp","%esp"}; -static char *reg_name_l[] = {"%al","%bl","%cl","%dl"}; +// static char *reg_name_l[] = {"%al","%bl","%cl","%dl"}; -static char * -regster(i) -int i; -{ - return reg_name[i]; -} +//static char * +//regster(i) +//int i; +//{ +// return reg_name[i]; +//} static int get_register() @@ -119,6 +119,7 @@ regs[i]=0; } +/* static int register_full() { @@ -130,6 +131,7 @@ } return 1; } + */ void emit_init() @@ -157,7 +159,7 @@ } else { lreg = i; lrn = reg_name[lreg]; - regs[i]=0; + free_register(i); return lreg; } } diff -r 5b631c16f89b -r e5c8532ab38d s-code-intel.c --- a/s-code-intel.c Fri Nov 02 14:04:35 2012 +0900 +++ b/s-code-intel.c Fri Oct 18 15:51:35 2013 +0900 @@ -90,7 +90,7 @@ printf("\tmovl %%eax,%%ebx\n"); printf("\tpopl %%eax\n"); printf("\tcltd\n"); - printf("\tidiv %%ebx\n",op); + printf("\tidiv %%ebx\n"); } else if(op==O_SUB) { printf("\tpopl %%ebx\n"); printf("\t%s %%ebx,%%eax\n",opcode[op]); diff -r 5b631c16f89b -r e5c8532ab38d s-code-intel64-mac.c --- a/s-code-intel64-mac.c Fri Nov 02 14:04:35 2012 +0900 +++ b/s-code-intel64-mac.c Fri Oct 18 15:51:35 2013 +0900 @@ -174,9 +174,10 @@ void emit_calc(enum opcode op) { - if(op==O_DIV) { + if(op==O_DIV || op==O_DIV_R ) { printf("\tmovq %%rax,%%rbx\n"); printf("\tpopq %%rax\n"); + // printf("\tmovq $0,%%rdx\n"); printf("\tcltd\n"); printf("\tidivq %%rbx\n"); } else if(op==O_SUB) { diff -r 5b631c16f89b -r e5c8532ab38d s-code-sparc.c --- a/s-code-sparc.c Fri Nov 02 14:04:35 2012 +0900 +++ b/s-code-sparc.c Fri Oct 18 15:51:35 2013 +0900 @@ -63,7 +63,7 @@ i = reg_stack[--reg_sp]; lrn = reg_name[i]; - regs[j]=0; + free_register(j); current_register = i; crn = reg_name[i]; diff -r 5b631c16f89b -r e5c8532ab38d s-prefix.c --- a/s-prefix.c Fri Nov 02 14:04:35 2012 +0900 +++ b/s-prefix.c Fri Oct 18 15:51:35 2013 +0900 @@ -71,8 +71,6 @@ static void mexpr() { - int d; - emit_comment(); term(); while(last_token!=EOF) { @@ -132,7 +130,6 @@ int main() { - int d; char buf[BUFSIZ]; emit_intro(); diff -r 5b631c16f89b -r e5c8532ab38d s-tree-compile.c --- a/s-tree-compile.c Fri Nov 02 14:04:35 2012 +0900 +++ b/s-tree-compile.c Fri Oct 18 15:51:35 2013 +0900 @@ -7,7 +7,7 @@ #include // for malloc -static int variable[48]; +static int optimize = 0; #define NEW(type) ((type *)malloc(sizeof(type))) @@ -23,13 +23,12 @@ static node *mexpr(); static node *term(); static node *new_node(); -static void print_node(); static node_ptr new_node(int type,int value,node_ptr left,node_ptr right) { node *d; - if ((left && left->type =='0') && + if (optimize && (left && left->type =='0') && (right && right->type =='0')) { switch(type) { case '>': @@ -126,7 +125,6 @@ static node_ptr expr() { - int assign; node *d; d = aexpr(); diff -r 5b631c16f89b -r e5c8532ab38d token.c --- a/token.c Fri Nov 02 14:04:35 2012 +0900 +++ b/token.c Fri Oct 18 15:51:35 2013 +0900 @@ -9,7 +9,6 @@ int main() { - int d; char buf[BUFSIZ]; while (fgets(buf,BUFSIZ,stdin)) {