Mercurial > hg > Members > shinya > pyrect
changeset 3:a193b4ff3909
prepare graph outputs (but not implement)
author | ryoma <e075725@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 29 Jun 2010 11:44:40 +0900 |
parents | 9816b755ac91 |
children | 7e47839a54ad |
files | code/as/reg.s code/c/reg.c code/c/regcbc.c code/graph/makepng.sh code/graph/sample.dot code/graph/sample.pdf code/graph/texput.log src/dfareg.py |
diffstat | 8 files changed, 382 insertions(+), 94 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/code/as/reg.s Tue Jun 29 11:44:40 2010 +0900 @@ -0,0 +1,275 @@ + .const +LC0: + .ascii "regexp: (A|B)*C\0" +LC1: + .ascii "number of state: 4\0" +LC2: + .ascii "string: %s\12\0" + .text +.globl _main +_main: + pushl %ebp + movl %esp, %ebp + pushl %ebx + subl $36, %esp + call ___i686.get_pc_thunk.bx +"L00000000001$pb": + leal LC0-"L00000000001$pb"(%ebx), %eax + movl %eax, (%esp) + call L_puts$stub + leal LC1-"L00000000001$pb"(%ebx), %eax + movl %eax, (%esp) + call L_puts$stub + movl 12(%ebp), %eax + addl $4, %eax + movl (%eax), %eax + movl %eax, 4(%esp) + leal LC2-"L00000000001$pb"(%ebx), %eax + movl %eax, (%esp) + call L_printf$stub + movl 12(%ebp), %edx + addl $4, %edx + movl (%edx), %edx + movl %edx, -12(%ebp) + movl -12(%ebp), %edx + movl %edx, %ecx + addl $36, %esp + popl %ebx + popl %ebp + jmp _state_1_3_5_6_7 +.globl _state_8 +_state_8: + pushl %ebp + movl %esp, %ebp + subl $40, %esp + movl %ecx, -28(%ebp) + movl -28(%ebp), %eax + movzbl (%eax), %eax + movsbl %al, %eax + addl $1, -28(%ebp) + testl %eax, %eax + jne L5 +L4: + movl -28(%ebp), %eax + movl %eax, -12(%ebp) + movl -12(%ebp), %eax + movl %eax, %ecx + leave + jmp _accept +L5: + movl -28(%ebp), %eax + movl %eax, -16(%ebp) + movl -16(%ebp), %eax + movl %eax, %ecx + leave + jmp _reject +.globl _state_1_3_5_6_7 +_state_1_3_5_6_7: + pushl %ebp + movl %esp, %ebp + subl $40, %esp + movl %ecx, -28(%ebp) + movl -28(%ebp), %eax + movzbl (%eax), %eax + movsbl %al, %eax + addl $1, -28(%ebp) + cmpl $66, %eax + je L9 + cmpl $67, %eax + je L10 + cmpl $65, %eax + jne L11 +L8: + movl -28(%ebp), %eax + movl %eax, -12(%ebp) + movl -12(%ebp), %eax + movl %eax, %ecx + leave + jmp _state_1_2_3_5_7 +L10: + movl -28(%ebp), %eax + movl %eax, -16(%ebp) + movl -16(%ebp), %eax + movl %eax, %ecx + leave + jmp _state_8 +L9: + movl -28(%ebp), %eax + movl %eax, -20(%ebp) + movl -20(%ebp), %eax + movl %eax, %ecx + leave + jmp _state_1_3_4_5_7 +L11: + movl -28(%ebp), %eax + movl %eax, -24(%ebp) + movl -24(%ebp), %eax + movl %eax, %ecx + leave + jmp _reject +.globl _state_1_3_4_5_7 +_state_1_3_4_5_7: + pushl %ebp + movl %esp, %ebp + subl $40, %esp + movl %ecx, -28(%ebp) + movl -28(%ebp), %eax + movzbl (%eax), %eax + movsbl %al, %eax + addl $1, -28(%ebp) + cmpl $66, %eax + je L15 + cmpl $67, %eax + je L16 + cmpl $65, %eax + jne L17 +L14: + movl -28(%ebp), %eax + movl %eax, -12(%ebp) + movl -12(%ebp), %eax + movl %eax, %ecx + leave + jmp _state_1_2_3_5_7 +L16: + movl -28(%ebp), %eax + movl %eax, -16(%ebp) + movl -16(%ebp), %eax + movl %eax, %ecx + leave + jmp _state_8 +L15: + movl -28(%ebp), %eax + movl %eax, -20(%ebp) + movl -20(%ebp), %eax + movl %eax, %ecx + leave + jmp _state_1_3_4_5_7 +L17: + movl -28(%ebp), %eax + movl %eax, -24(%ebp) + movl -24(%ebp), %eax + movl %eax, %ecx + leave + jmp _reject +.globl _state_1_2_3_5_7 +_state_1_2_3_5_7: + pushl %ebp + movl %esp, %ebp + subl $40, %esp + movl %ecx, -28(%ebp) + movl -28(%ebp), %eax + movzbl (%eax), %eax + movsbl %al, %eax + addl $1, -28(%ebp) + cmpl $66, %eax + je L21 + cmpl $67, %eax + je L22 + cmpl $65, %eax + jne L23 +L20: + movl -28(%ebp), %eax + movl %eax, -12(%ebp) + movl -12(%ebp), %eax + movl %eax, %ecx + leave + jmp _state_1_2_3_5_7 +L22: + movl -28(%ebp), %eax + movl %eax, -16(%ebp) + movl -16(%ebp), %eax + movl %eax, %ecx + leave + jmp _state_8 +L21: + movl -28(%ebp), %eax + movl %eax, -20(%ebp) + movl -20(%ebp), %eax + movl %eax, %ecx + leave + jmp _state_1_3_4_5_7 +L23: + movl -28(%ebp), %eax + movl %eax, -24(%ebp) + movl -24(%ebp), %eax + movl %eax, %ecx + leave + jmp _reject + .const +LC3: + .ascii "\12string matches regexp. \12\0" + .text +.globl _accept +_accept: + pushl %ebp + movl %esp, %ebp + pushl %ebx + subl $36, %esp + call ___i686.get_pc_thunk.bx +"L00000000002$pb": + movl %ecx, -12(%ebp) + leal LC3-"L00000000002$pb"(%ebx), %eax + movl %eax, (%esp) + call L_puts$stub + addl $36, %esp + popl %ebx + popl %ebp + ret + .const + .align 2 +LC4: + .ascii "\12string does not match regexp. \12\0" + .text +.globl _reject +_reject: + pushl %ebp + movl %esp, %ebp + pushl %ebx + subl $36, %esp + call ___i686.get_pc_thunk.bx +"L00000000003$pb": + movl %ecx, -12(%ebp) + leal LC4-"L00000000003$pb"(%ebx), %eax + movl %eax, (%esp) + call L_puts$stub + addl $36, %esp + popl %ebx + popl %ebp + ret + .picsymbol_stub +L_printf$stub: + .indirect_symbol _printf + call LPC$1 +LPC$1: popl %eax + movl L1$lz-LPC$1(%eax),%edx + jmp *%edx +L_printf$stub_binder: + lea L1$lz-LPC$1(%eax),%eax + pushl %eax + jmp dyld_stub_binding_helper + .lazy_symbol_pointer +L1$lz: + .indirect_symbol _printf + .long L_printf$stub_binder + .picsymbol_stub +L_puts$stub: + .indirect_symbol _puts + call LPC$2 +LPC$2: popl %eax + movl L2$lz-LPC$2(%eax),%edx + jmp *%edx +L_puts$stub_binder: + lea L2$lz-LPC$2(%eax),%eax + pushl %eax + jmp dyld_stub_binding_helper + .lazy_symbol_pointer +L2$lz: + .indirect_symbol _puts + .long L_puts$stub_binder + .subsections_via_symbols + .section __TEXT,__textcoal_nt,coalesced,pure_instructions + .weak_definition ___i686.get_pc_thunk.bx + .private_extern ___i686.get_pc_thunk.bx +___i686.get_pc_thunk.bx: + movl (%esp), %ebx + ret
--- a/code/c/reg.c Thu Jun 17 15:53:50 2010 +0900 +++ b/code/c/reg.c Tue Jun 29 11:44:40 2010 +0900 @@ -1,81 +1,81 @@ #include <stdio.h> -__code state_8(char* s); -__code state_1_3_5_6_7(char* s); -__code state_1_3_4_5_7(char* s); -__code state_1_2_3_5_7(char* s); -__code accept(char* s); -__code reject(char* s); +void state_8(char* s); +void state_1_3_5_6_7(char* s); +void state_1_3_4_5_7(char* s); +void state_1_2_3_5_7(char* s); +void accept(char* s); +void reject(char* s); int main(int argc, char* argv[]) { puts("regexp: (A|B)*C"); puts("number of state: 4"); printf("string: %s\n", argv[1]); - goto state_1_3_5_6_7(argv[1]); + state_1_3_5_6_7(argv[1]); return 0; } -__code state_8(char* s) { +void state_8(char* s) { switch(*s++) { case '\0': - goto accept(s); + accept(s); break; - default: goto reject(s); + default: reject(s); } } -__code state_1_3_5_6_7(char* s) { +void state_1_3_5_6_7(char* s) { switch(*s++) { case 'A': - goto state_1_2_3_5_7(s); + state_1_2_3_5_7(s); break; case 'C': - goto state_8(s); + state_8(s); break; case 'B': - goto state_1_3_4_5_7(s); + state_1_3_4_5_7(s); break; - default: goto reject(s); + default: reject(s); } } -__code state_1_3_4_5_7(char* s) { +void state_1_3_4_5_7(char* s) { switch(*s++) { case 'A': - goto state_1_2_3_5_7(s); + state_1_2_3_5_7(s); break; case 'C': - goto state_8(s); + state_8(s); break; case 'B': - goto state_1_3_4_5_7(s); + state_1_3_4_5_7(s); break; - default: goto reject(s); + default: reject(s); } } -__code state_1_2_3_5_7(char* s) { +void state_1_2_3_5_7(char* s) { switch(*s++) { case 'A': - goto state_1_2_3_5_7(s); + state_1_2_3_5_7(s); break; case 'C': - goto state_8(s); + state_8(s); break; case 'B': - goto state_1_3_4_5_7(s); + state_1_3_4_5_7(s); break; - default: goto reject(s); + default: reject(s); } } -__code accept(char* s) { +void accept(char* s) { printf("\nstring matches regexp. \n\n"); } -__code reject(char* s) { +void reject(char* s) { printf("\nstring does not match regexp. \n\n"); }
--- a/code/c/regcbc.c Thu Jun 17 15:53:50 2010 +0900 +++ b/code/c/regcbc.c Tue Jun 29 11:44:40 2010 +0900 @@ -1,97 +1,60 @@ #include <stdio.h> -__code state_14(char* s); -__code state_12(char* s); -__code state_9_11_13_15(char* s); -__code state_7_11_13_15(char* s); -__code state_2_6_8_10(char* s); -__code state_4_6_8_10(char* s); -__code state_1_3_5(char* s); +__code state_8(char* s); +__code state_1_3_5_6_7(char* s); +__code state_1_3_4_5_7(char* s); +__code state_1_2_3_5_7(char* s); __code accept(char* s); __code reject(char* s); int main(int argc, char* argv[]) { - puts("regexp: (f|F)(o|O)(o|O)"); - puts("number of state: 7"); + puts("regexp: (A|B)*C"); + puts("number of state: 4"); printf("string: %s\n", argv[1]); - goto state_1_3_5(argv[1]); + goto state_1_3_5_6_7(argv[1]); return 0; } -__code state_14(char* s) { +__code state_8(char* s) { switch(*s++) { case '\0': goto accept(s); - break; - default: goto reject(s); - } -} - -__code state_12(char* s) { - switch(*s++) { - case '\0': - goto accept(s); - break; default: goto reject(s); } } -__code state_9_11_13_15(char* s) { +__code state_1_3_5_6_7(char* s) { switch(*s++) { - case 'o': - goto state_12(s); - break; - case 'O': - goto state_14(s); - break; - default: goto reject(s); - } -} - -__code state_7_11_13_15(char* s) { - switch(*s++) { - case 'o': - goto state_12(s); - break; - case 'O': - goto state_14(s); - break; + case 'A': + goto state_1_2_3_5_7(s); + case 'C': + goto state_8(s); + case 'B': + goto state_1_3_4_5_7(s); default: goto reject(s); } } -__code state_2_6_8_10(char* s) { +__code state_1_3_4_5_7(char* s) { switch(*s++) { - case 'o': - goto state_7_11_13_15(s); - break; - case 'O': - goto state_9_11_13_15(s); - break; + case 'A': + goto state_1_2_3_5_7(s); + case 'C': + goto state_8(s); + case 'B': + goto state_1_3_4_5_7(s); default: goto reject(s); } } -__code state_4_6_8_10(char* s) { +__code state_1_2_3_5_7(char* s) { switch(*s++) { - case 'O': - goto state_9_11_13_15(s); - break; - case 'o': - goto state_7_11_13_15(s); - break; - default: goto reject(s); - } -} - -__code state_1_3_5(char* s) { - switch(*s++) { - case 'F': - goto state_4_6_8_10(s); - break; - case 'f': - goto state_2_6_8_10(s); - break; + case 'A': + goto state_1_2_3_5_7(s); + case 'C': + goto state_8(s); + case 'B': + goto state_1_3_4_5_7(s); default: goto reject(s); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/code/graph/makepng.sh Tue Jun 29 11:44:40 2010 +0900 @@ -0,0 +1,7 @@ +#!/bin/sh +neato -Txdot $1.dot | dot2tex -ftikz --tikzedgelabels -tmath --styleonly > $1.tex +platex $1.tex +platex $1.tex +dvips $1.dvi +dvipdf $1.dvi +rm -f $1.dvi $1.tex $1.dvi $1.aux $1.ps $1.log
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/code/graph/sample.dot Tue Jun 29 11:44:40 2010 +0900 @@ -0,0 +1,23 @@ +digraph G { + d2ttikzedgelabels = true; + d2tstyleonly = true; + d2tdocpreamble = "\usetikzlibrary{automata}"; + d2tfigpreamble = "\tikzstyle{every state}=\ + [draw=blue!50,shape=circle, very thick,fill=blue!20]"; + edge [lblstyle="fill=blue!20", style="arrows=->", topath="bend left"]; + node [style="state"]; + + a_1 [style="state, initial"] + a_1 -> a_2 [texlbl="1"] + a_1 -> a_3 [texlbl="2"]; + a_1 -> a_4 [texlbl="3"]; + + a_2 -> a_1 [texlbl="4"]; + a_2 -> a_3 [texlbl="5"]; + + a_3 -> a_1 [texlbl="7"]; + a_3 -> a_2 [texlbl="8"]; + + a_4 -> a_1 [texlbl="10",shape="circle"]; + a_4 [style="state, accepting"]; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/code/graph/texput.log Tue Jun 29 11:44:40 2010 +0900 @@ -0,0 +1,18 @@ +This is pTeX, Version 3.141592-p3.1.10 (utf8.euc) (Web2C 7.5.4) (format=platex 2008.4.16) 29 JUN 2010 10:35 +**sample.tsx + +! Emergency stop. +<*> sample.tsx + +End of file on the terminal! + + +Here is how much of TeX's memory you used: + 3 strings out of 95542 + 20 string characters out of 1190872 + 47119 words of memory out of 1500000 + 3250 multiletter control sequences out of 10000+50000 + 7511 words of font info for 31 fonts, out of 1200000 for 2000 + 14 hyphenation exceptions out of 8191 + 0i,0n,0p,1b,6s stack positions out of 5000i,500n,6000p,300000b,5000s +No pages of output.
--- a/src/dfareg.py Thu Jun 17 15:53:50 2010 +0900 +++ b/src/dfareg.py Tue Jun 29 11:44:40 2010 +0900 @@ -380,9 +380,11 @@ if emitCFlag: fun_type = 'void ' call_t = '' + break_s = '\n\t\t\tbreak;' else: fun_type = '__code ' call_t = 'goto ' + break_s = '' # emit cbc(or c) code print "#include <stdio.h>\n" @@ -404,7 +406,7 @@ print "\tswitch(*s++) {" for case, next_state in v.iteritems(): print "\t\tcase '%s': " % (case) - print "\t\t\t%s%s(s);\n\t\t\tbreak;" % (call_t, next_state) + print "\t\t\t%s%s(s);%s" % (call_t, next_state, break_s) print "\t\tdefault: %sreject(s);\n\t}" % call_t print "}\n"