Mercurial > hg > Members > kono > compiler-examples
changeset 7:fbb9cf5e483f
*** empty log message ***
author | kono |
---|---|
date | Fri, 17 Nov 2006 18:31:08 +0900 |
parents | 5350f1289f50 |
children | 2735d0b637b6 |
files | Makefile s-calc.s test0.c test0.s tmp.pl tmptmp |
diffstat | 6 files changed, 2 insertions(+), 504 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Fri Nov 17 18:26:08 2006 +0900 +++ b/Makefile Fri Nov 17 18:31:08 2006 +0900 @@ -2,9 +2,9 @@ CC = gcc CFLAGS = -g -COMPILER = s-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 +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 all: $(TARGET)
--- a/s-calc.s Fri Nov 17 18:26:08 2006 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,431 +0,0 @@ -gcc2_compiled.: -___gnu_compiled_c: -.text - .align 4 - .global _token - .proc 04 -_token: - !#PROLOGUE# 0 - !#PROLOGUE# 1 - sethi %hi(_last_ptr),%g2 - sethi %hi(_ptr),%g3 - ld [%g3+%lo(_ptr)],%g3 - st %g3,[%g2+%lo(_last_ptr)] - ldsb [%g3],%o0 - cmp %o0,0 - bne L2 - sethi %hi(_ptr),%o1 - sethi %hi(_last_token),%g3 - mov -1,%g2 - st %g2,[%g3+%lo(_last_token)] - b L19 - mov -1,%o0 -L2: - ld [%o1+%lo(_ptr)],%g3 - add %g3,1,%g2 - cmp %o0,32 - bg L3 - st %g2,[%o1+%lo(_ptr)] - add %g3,2,%g2 - st %g2,[%o1+%lo(_ptr)] - ldsb [%g3+1],%g2 - cmp %g2,0 - be L20 - sethi %hi(_ptr),%g2 - sethi %hi(_ptr),%o0 - ld [%o0+%lo(_ptr)],%g2 -L21: - add %g2,1,%g3 - st %g3,[%o0+%lo(_ptr)] - ldsb [%g2],%g2 - cmp %g2,0 - bne L21 - ld [%o0+%lo(_ptr)],%g2 - sethi %hi(_ptr),%g2 -L20: - ld [%g2+%lo(_ptr)],%g3 - add %g3,-1,%g3 - st %g3,[%g2+%lo(_ptr)] - sethi %hi(_last_token),%o0 - mov -1,%g2 - st %g2,[%o0+%lo(_last_token)] - sethi %hi(_last_ptr),%g2 - st %g3,[%g2+%lo(_last_ptr)] - b L19 - mov -1,%o0 -L3: - add %o0,-48,%g2 - cmp %g2,9 - bgu L8 - mov %g2,%o1 - sethi %hi(_ptr),%g2 - ld [%g2+%lo(_ptr)],%o0 - add %o0,1,%g3 - st %g3,[%g2+%lo(_ptr)] - ldsb [%o0],%o0 - cmp %o0,0 - be L23 - mov %g2,%o2 - add %o0,-48,%g2 -L22: - cmp %g2,9 - bgu L10 - sll %o1,2,%g2 - add %g2,%o1,%g2 - sll %g2,1,%g2 - add %g2,-48,%g2 - add %g2,%o0,%o1 - ld [%o2+%lo(_ptr)],%g3 - add %g3,1,%g2 - st %g2,[%o2+%lo(_ptr)] - ldsb [%g3],%o0 - cmp %o0,0 - bne L22 - add %o0,-48,%g2 -L10: - cmp %o0,0 -L23: - be L15 - sethi %hi(_ptr),%g3 - ld [%g3+%lo(_ptr)],%g2 - add %g2,-1,%g2 - st %g2,[%g3+%lo(_ptr)] -L15: - sethi %hi(_value),%g2 - st %o1,[%g2+%lo(_value)] - sethi %hi(_last_token),%g3 - mov 48,%g2 - st %g2,[%g3+%lo(_last_token)] - b L19 - mov 48,%o0 -L8: - add %o0,-97,%g2 - cmp %g2,25 - bleu L17 - sethi %hi(_last_token),%g2 - b L19 - st %o0,[%g2+%lo(_last_token)] -L17: - sethi %hi(_value),%g3 - add %o0,-97,%g2 - st %g2,[%g3+%lo(_value)] - sethi %hi(_last_token),%g3 - mov 118,%g2 - st %g2,[%g3+%lo(_last_token)] - mov 118,%o0 -L19: - retl - nop - .align 8 -LC0: - .ascii "Bad assignment\0" - .align 8 -LC1: - .ascii "Bad expression\0" - .align 4 - .global _expr - .proc 04 -_expr: - !#PROLOGUE# 0 - save %sp,-104,%sp - !#PROLOGUE# 1 - call _aexpr,0 - nop - mov %o0,%i0 - sethi %hi(_lvalue),%o0 - ld [%o0+%lo(_lvalue)],%l0 - sethi %hi(_last_token),%o0 - mov %o0,%o1 - ld [%o0+%lo(_last_token)],%o0 - cmp %o0,-1 - be L26 - sethi %hi(_variable),%o0 - or %o0,%lo(_variable),%l4 - sll %l0,2,%l1 - sethi %hi(LC0),%l3 - sethi %hi(LC1),%l2 - ld [%o1+%lo(_last_token)],%o0 - cmp %o0,61 -L40: - be,a L30 - cmp %l0,0 - bg L36 - cmp %o0,62 - cmp %o0,41 - be L38 - nop - b,a L34 -L36: - bne L34 - nop - call _aexpr,0 - nop - cmp %i0,%o0 - bg,a L41 - mov 1,%i0 - mov 0,%i0 -L41: - b L39 - sethi %hi(_last_token),%o1 -L30: - bl L31 - nop - call _expr,0 - nop - mov %o0,%i0 - b L38 - st %i0,[%l1+%l4] -L31: - call _error,0 - or %l3,%lo(LC0),%o0 - b L38 - mov 0,%i0 -L34: - call _error,0 - or %l2,%lo(LC1),%o0 - call _token,0 - nop - sethi %hi(_last_token),%o1 -L39: - ld [%o1+%lo(_last_token)],%o0 - cmp %o0,-1 - bne L40 - cmp %o0,61 -L26: - sethi %hi(_last_token),%o1 - mov -1,%o0 - st %o0,[%o1+%lo(_last_token)] -L38: - ret - restore - .align 4 - .global _aexpr - .proc 04 -_aexpr: - !#PROLOGUE# 0 - save %sp,-104,%sp - !#PROLOGUE# 1 - call _mexpr,0 - nop - mov %o0,%i0 - sethi %hi(_last_token),%o0 - mov %o0,%o1 - ld [%o0+%lo(_last_token)],%o0 - cmp %o0,-1 - be L52 - ld [%o1+%lo(_last_token)],%o0 - cmp %o0,43 -L53: - be L48 - cmp %o0,45 - bne L52 - nop - call _mexpr,0 - nop - b L43 - sub %i0,%o0,%i0 -L48: - call _mexpr,0 - nop - add %i0,%o0,%i0 -L43: - sethi %hi(_last_token),%o1 - ld [%o1+%lo(_last_token)],%o0 - cmp %o0,-1 - bne L53 - cmp %o0,43 -L52: - ret - restore - .align 4 - .global _mexpr - .proc 04 -_mexpr: - !#PROLOGUE# 0 - save %sp,-104,%sp - !#PROLOGUE# 1 - call _term,0 - nop - mov %o0,%i0 - sethi %hi(_last_token),%o0 - mov %o0,%o1 - ld [%o0+%lo(_last_token)],%o0 - cmp %o0,-1 - be L64 - ld [%o1+%lo(_last_token)],%o0 - cmp %o0,42 -L67: - be L59 - cmp %o0,47 - be L60 - nop - b,a L64 -L59: - call _mexpr,0 - nop - mov %o0,%o1 - call .umul,0 - mov %i0,%o0 - b L66 - mov %o0,%i0 -L60: - call _mexpr,0 - nop - mov %o0,%o1 - call .div,0 - mov %i0,%o0 - mov %o0,%i0 -L66: - sethi %hi(_last_token),%o1 - ld [%o1+%lo(_last_token)],%o0 - cmp %o0,-1 - bne L67 - cmp %o0,42 -L64: - ret - restore - .align 8 -LC2: - .ascii "Term expected\0" - .align 8 -LC3: - .ascii "Unbalanced parenthsis\0" - .align 8 -LC4: - .ascii "Unknown term\0" - .align 4 - .global _term - .proc 04 -_term: - !#PROLOGUE# 0 - save %sp,-104,%sp - !#PROLOGUE# 1 - sethi %hi(_lvalue),%o1 - mov -1,%o0 - call _token,0 - st %o0,[%o1+%lo(_lvalue)] - sethi %hi(_last_token),%o0 - ld [%o0+%lo(_last_token)],%o0 - cmp %o0,-1 - bne,a L80 - sethi %hi(_last_token),%o0 - sethi %hi(LC2),%o0 - call _error,0 - or %o0,%lo(LC2),%o0 - sethi %hi(_last_token),%o0 -L80: - ld [%o0+%lo(_last_token)],%o0 - cmp %o0,48 - be,a L71 - sethi %hi(_value),%o0 - bg L77 - cmp %o0,118 - cmp %o0,40 - be L73 - nop - b,a L75 -L77: - be L72 - sethi %hi(_lvalue),%o1 - b,a L75 -L71: - ld [%o0+%lo(_value)],%i0 -L79: - call _token,0 - add %o7,(L78-.-4),%o7 -L72: - sethi %hi(_value),%o0 - ld [%o0+%lo(_value)],%o0 - st %o0,[%o1+%lo(_lvalue)] - call _token,0 - mov %o0,%i0 - sethi %hi(_variable),%o0 - or %o0,%lo(_variable),%o0 - sll %i0,2,%o1 - b L78 - ld [%o1+%o0],%i0 -L73: - call _expr,0 - nop - mov %o0,%i0 - sethi %hi(_last_token),%o0 - ld [%o0+%lo(_last_token)],%o0 - cmp %o0,41 - be L79 - sethi %hi(LC3),%o0 - call _error,0 - or %o0,%lo(LC3),%o0 - b,a L79 -L75: - call _token,0 - mov 0,%i0 - sethi %hi(LC4),%o0 - call _error,0 - or %o0,%lo(LC4),%o0 -L78: - ret - restore - .align 8 -LC5: - .ascii "%s = 0x%08x = %d\12\0" - .align 4 - .global _main - .proc 04 -_main: - !#PROLOGUE# 0 - save %sp,-1128,%sp - !#PROLOGUE# 1 - call ___main,0 - sethi %hi(_ptr),%l2 - add %fp,-1032,%i0 - sethi %hi(__iob),%o0 - or %o0,%lo(__iob),%l0 - sethi %hi(LC5),%l1 - mov %i0,%o0 -L85: - mov 1024,%o1 - call _fgets,0 - mov %l0,%o2 - cmp %o0,0 - be L83 - nop - call _expr,0 - st %i0,[%l2+%lo(_ptr)] - mov %o0,%o3 - or %l1,%lo(LC5),%o0 - mov %i0,%o1 - call _printf,0 - mov %o3,%o2 - call _fflush,0 - add %l0,20,%o0 - b L85 - mov %i0,%o0 -L83: - ret - restore %g0,0,%o0 - .align 8 -LC6: - .ascii "%s on %s\12\0" - .align 4 - .global _error - .proc 020 -_error: - !#PROLOGUE# 0 - save %sp,-104,%sp - !#PROLOGUE# 1 - sethi %hi(_last_ptr),%o3 - sethi %hi(__iob+40),%o0 - or %o0,%lo(__iob+40),%o0 - sethi %hi(LC6),%o1 - or %o1,%lo(LC6),%o1 - mov %i0,%o2 - call _fprintf,0 - ld [%o3+%lo(_last_ptr)],%o3 - ret - restore - .common _ptr,4,"bss" - .common _last_ptr,4,"bss" - .common _value,4,"bss" - .common _lvalue,4,"bss" - .common _last_token,4,"bss" - .common _variable,192,"bss"
--- a/test0.c Fri Nov 17 18:26:08 2006 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -int variable[64]; - -main() { - print(variable[20]=0x80000001); - print(1+variable[20]); - return 0; -} - -print(i) -int i; -{ - printf("0x%08x = %d\n",i,i); -} -
--- a/test0.s Fri Nov 17 18:26:08 2006 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -.text - .align 2,0x90 -.globl _main -_main: - pushl %ebp - movl %esp,%ebp - movl $-2147483647,_variable+80 - pushl $-2147483647 - call _print - addl $4,%esp - movl _variable+80,%eax - incl %eax - pushl %eax - call _print - addl $4,%esp - xorl %eax,%eax - jmp L1 - .align 2,0x90 -L1: - movl %ebp,%esp - popl %ebp - ret -.cstring -LC0: - .ascii "0x%08x = %d\12\0" -.text - .align 2,0x90 -.globl _print -_print: - pushl %ebp - movl %esp,%ebp - movl 8(%ebp),%edx - pushl %edx - movl 8(%ebp),%edx - pushl %edx - pushl $LC0 - call _printf - addl $12,%esp -L2: - movl %ebp,%esp - popl %ebp - ret -.comm _variable,256
--- a/tmp.pl Fri Nov 17 18:26:08 2006 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ - -while(<>) { - s/([\200-\376])(.)/sprintf("\\%o\\%o",ord($1),ord($2))/ego; - s/\033\$.[^\033]*\033\(./&convert($&)/ego; - print; -} - -sub convert { - $tmp = $_[0]; - $tmp=~s/./sprintf("\\%o",ord($&))/ego; - return $tmp; -}