From: j8takagi Date: Fri, 22 Jan 2010 23:58:26 +0000 (+0900) Subject: hash.cの分離独立とソースコードの草取り X-Git-Tag: v0.1~84 X-Git-Url: https://j8takagi.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=faec695d5b7ecf7dd3e4a07ac926ea93ca89020b;p=YACASL2.git hash.cの分離独立とソースコードの草取り --- diff --git a/.gitignore b/.gitignore index 4ffad4b..28d892d 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,6 @@ diff.txt casl2 comet2 dumpword -test.log +TEST.log *~ TAGS diff --git a/include/casl2.h b/include/casl2.h index 65d2870..e68a24e 100644 --- a/include/casl2.h +++ b/include/casl2.h @@ -14,7 +14,7 @@ enum { CMDSIZE = 4, /* 命令の最大文字数 */ REGSIZE = 8, /* 汎用レジスタの数 */ DEFAULT_MEMSIZE = 512, /* デフォルトのメモリ容量。COMET II規格では、65536語 */ - DEFAULT_CLOCKS = 5000000 /* デフォルトのクロック周波数。COMET II規格では、未定義 */ + DEFAULT_CLOCKS = 5000000, /* デフォルトのクロック周波数。COMET II規格では、未定義 */ }; /* ハッシュ値を取得する */ @@ -33,7 +33,7 @@ extern WORD GR[REGSIZE], SP, PR, FR; enum { OF = 0x4, /* Overflow Flag */ SF = 0x2, /* Sign Flag */ - ZF = 0x1 /* Zero Flag */ + ZF = 0x1, /* Zero Flag */ }; /* エラー番号 */ @@ -94,7 +94,7 @@ typedef enum { R1_R2 = 020, ADR_X = 030, R_ = 040, - NONE = 0 + NONE = 0, } CMDTYPE; typedef struct { diff --git a/src/Makefile b/src/Makefile index 0ff70c2..af972cd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,7 +1,7 @@ INCLUDE = ../include CC = gcc CFLAGS = -Wall -I $(INCLUDE) -COMMONSRC = struct.o cmd.o cerr.o dump.o +COMMONSRC = struct.o hash.o cmd.o cerr.o dump.o ASSRC = assemble.o token.o label.o macro.o EXECSRC = exec.o .PHPNY: all clean diff --git a/src/cmd.c b/src/cmd.c index 7e2b7fa..1ba5152 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -50,7 +50,7 @@ bool create_cmdtype_code() CMDCODETAB *np; unsigned hashval; int i; - + for(i = 0; i < cmdcodesize; i++) { np = (CMDCODETAB *) malloc(sizeof(*np)); if(np == NULL) { @@ -128,10 +128,9 @@ bool create_code_type() CMDCODETAB *np; unsigned hashval; int i; - + for(i = 0; i < cmdcodesize; i++) { - np = (CMDCODETAB *) malloc(sizeof(*np)); - if(np == NULL) { + if((np = (CMDCODETAB *) malloc(sizeof(*np))) == NULL) { setcerr(122, NULL); /* cannot create hash table */ return false; } diff --git a/src/dump.c b/src/dump.c index d07c40f..5362de4 100644 --- a/src/dump.c +++ b/src/dump.c @@ -7,14 +7,9 @@ char *word2bit(const WORD word) char *bit, *p; bit = malloc(16 + 1); p = bit; - while(mask > 0){ - if((word & mask) == 0) { - *p++ = '0'; - } else { - *p++ = '1'; - } - mask = (mask >> 1); - } + do { + *p++ = (word & mask) ? '1' : '0'; + } while((mask >>= 1) > 0); *p = '\0'; return bit; } diff --git a/src/hash.c b/src/hash.c new file mode 100644 index 0000000..b673d53 --- /dev/null +++ b/src/hash.c @@ -0,0 +1,9 @@ +/* ハッシュ値を取得する */ +unsigned hash(const char *key, int size){ + unsigned hashval; + + for(hashval = 0; *key != '\0'; key++){ + hashval = *key + 31 * hashval; + } + return hashval % size; +} diff --git a/src/struct.c b/src/struct.c index 7f6fd41..31be1e6 100644 --- a/src/struct.c +++ b/src/struct.c @@ -45,13 +45,3 @@ WORD startptr = 0x0; /* 実行終了番地 */ WORD endptr = 0x0; - -/* ハッシュ値を取得する */ -unsigned hash(const char *key, int size){ - unsigned hashval; - - for(hashval = 0; *key != '\0'; key++){ - hashval = *key + 31 * hashval; - } - return hashval % size; -} diff --git a/test/integration/CASL2/TEST.log b/test/integration/CASL2/TEST.log deleted file mode 100644 index 20529d8..0000000 --- a/test/integration/CASL2/TEST.log +++ /dev/null @@ -1,76 +0,0 @@ -abs_call: Test Success 2010-01-21 02:33:30 -adda0: Test Success 2010-01-21 02:33:30 -adda1: Test Success 2010-01-21 02:33:30 -adda_overflow: Test Success 2010-01-21 02:33:30 -addl: Test Success 2010-01-21 02:33:30 -addl_overflow: Test Success 2010-01-21 02:33:30 -and0: Test Success 2010-01-21 02:33:30 -and1: Test Success 2010-01-21 02:33:30 -and2: Test Success 2010-01-21 02:33:30 -and3: Test Success 2010-01-21 02:33:30 -binout: Test Success 2010-01-21 02:33:30 -call0: Test Success 2010-01-21 02:33:30 -call1: Test Success 2010-01-21 02:33:30 -call2: Test Success 2010-01-21 02:33:30 -cmd_err0: Test Success 2010-01-21 02:33:31 -cmd_err1: Test Success 2010-01-21 02:33:31 -count_call: Test Success 2010-01-21 02:33:31 -cpa1: Test Success 2010-01-21 02:33:31 -dc_overflow: Test Success 2010-01-21 02:33:31 -dc_spc: Test Success 2010-01-21 02:33:31 -divl0_call: Test Success 2010-01-21 02:33:32 -divl1_call: Test Success 2010-01-21 02:33:34 -ds_0: Test Success 2010-01-21 02:33:34 -ds_err: Test Success 2010-01-21 02:33:34 -fib_outl: Test Success 2010-01-21 02:33:34 -floatedit: Test Success 2010-01-21 02:33:34 -hanoi: Test Success 2010-01-21 02:33:34 -hello: Test Success 2010-01-21 02:33:34 -iotest: Test Success 2010-01-21 02:33:34 -labeldup_err: Test Success 2010-01-21 02:33:34 -lad0: Test Success 2010-01-21 02:33:34 -lad1: Test Success 2010-01-21 02:33:34 -lad2: Test Success 2010-01-21 02:33:34 -lad3: Test Success 2010-01-21 02:33:34 -ld0: Test Success 2010-01-21 02:33:34 -ld1: Test Success 2010-01-21 02:33:34 -ld2: Test Success 2010-01-21 02:33:34 -ld3: Test Success 2010-01-21 02:33:35 -ld4: Test Success 2010-01-21 02:33:35 -ld5: Test Success 2010-01-21 02:33:35 -ld_loop: Test Success 2010-01-21 02:33:35 -literal_spc: Test Success 2010-01-21 02:33:35 -literalstr: Test Success 2010-01-21 02:33:35 -minim_call: Test Success 2010-01-21 02:33:35 -mula0_call: Test Success 2010-01-21 02:33:40 -mula1_call: Test Success 2010-01-21 02:33:41 -mull0_call: Test Success 2010-01-21 02:33:46 -mull1_call: Test Success 2010-01-21 02:33:46 -opdspc_err: Test Success 2010-01-21 02:33:46 -out0: Test Success 2010-01-21 02:33:46 -out1: Test Success 2010-01-21 02:33:46 -outa_call: Test Success 2010-01-21 02:33:46 -outb_call: Test Success 2010-01-21 02:33:47 -outd_q15_call: Test Success 2010-01-21 02:33:47 -outl_call: Test Success 2010-01-21 02:33:47 -ptn1: Test Success 2010-01-21 02:33:47 -ptn2: Test Success 2010-01-21 02:33:47 -ptn3: Test Success 2010-01-21 02:33:47 -ptn4: Test Success 2010-01-21 02:33:47 -pushpop: Test Success 2010-01-21 02:33:47 -rev_call: Test Success 2010-01-21 02:33:47 -sla2: Test Success 2010-01-21 02:33:47 -sra2: Test Success 2010-01-21 02:33:47 -sra3: Test Success 2010-01-21 02:33:48 -sra4: Test Success 2010-01-21 02:33:48 -st0: Test Success 2010-01-21 02:33:48 -st1: Test Success 2010-01-21 02:33:48 -sum_call: Test Success 2010-01-21 02:33:48 -summary: Test Success 2010-01-21 02:33:48 -svc2: Test Success 2010-01-21 02:33:48 -svc2_out: Test Success 2010-01-21 02:33:48 -xor0: Test Success 2010-01-21 02:33:48 -xor1: Test Success 2010-01-21 02:33:48 -xor3: Test Success 2010-01-21 02:33:48 -xor4: Test Success 2010-01-21 02:33:48 -xor5: Test Success 2010-01-21 02:33:48 diff --git a/test/integration/COMET2/TEST.log b/test/integration/COMET2/TEST.log deleted file mode 100644 index 94a1a9c..0000000 --- a/test/integration/COMET2/TEST.log +++ /dev/null @@ -1,71 +0,0 @@ -abs_call: Test Success 2010-01-21 02:33:49 -adda0: Test Success 2010-01-21 02:33:49 -adda1: Test Success 2010-01-21 02:33:49 -adda_overflow: Test Success 2010-01-21 02:33:49 -addl: Test Success 2010-01-21 02:33:50 -addl_overflow: Test Success 2010-01-21 02:33:50 -and0: Test Success 2010-01-21 02:33:50 -and1: Test Success 2010-01-21 02:33:50 -and2: Test Success 2010-01-21 02:33:50 -and3: Test Success 2010-01-21 02:33:50 -binout: Test Success 2010-01-21 02:33:50 -call0: Test Success 2010-01-21 02:33:50 -call1: Test Success 2010-01-21 02:33:51 -call2: Test Success 2010-01-21 02:33:51 -count_call: Test Success 2010-01-21 02:33:51 -cpa1: Test Success 2010-01-21 02:33:51 -dc_overflow: Test Success 2010-01-21 02:33:51 -dc_spc: Test Success 2010-01-21 02:33:51 -divl0_call: Test Success 2010-01-21 02:33:53 -divl1_call: Test Success 2010-01-21 02:33:54 -ds_0: Test Success 2010-01-21 02:33:54 -fib_outl: Test Success 2010-01-21 02:33:54 -floatedit: Test Success 2010-01-21 02:33:55 -hanoi: Test Success 2010-01-21 02:33:55 -hello: Test Success 2010-01-21 02:33:55 -iotest: Test Success 2010-01-21 02:33:55 -lad0: Test Success 2010-01-21 02:33:55 -lad1: Test Success 2010-01-21 02:33:55 -lad2: Test Success 2010-01-21 02:33:55 -lad3: Test Success 2010-01-21 02:33:56 -ld0: Test Success 2010-01-21 02:33:56 -ld1: Test Success 2010-01-21 02:33:56 -ld2: Test Success 2010-01-21 02:33:56 -ld3: Test Success 2010-01-21 02:33:56 -ld4: Test Success 2010-01-21 02:33:57 -ld5: Test Success 2010-01-21 02:33:57 -ld_loop: Test Success 2010-01-21 02:33:57 -literal_spc: Test Success 2010-01-21 02:33:57 -literalstr: Test Success 2010-01-21 02:33:57 -minim_call: Test Success 2010-01-21 02:33:57 -mula0_call: Test Success 2010-01-21 02:34:02 -mula1_call: Test Success 2010-01-21 02:34:03 -mull0_call: Test Success 2010-01-21 02:34:08 -mull1_call: Test Success 2010-01-21 02:34:09 -out0: Test Success 2010-01-21 02:34:09 -out1: Test Success 2010-01-21 02:34:09 -outa_call: Test Success 2010-01-21 02:34:09 -outb_call: Test Success 2010-01-21 02:34:09 -outd_q15_call: Test Success 2010-01-21 02:34:10 -outl_call: Test Success 2010-01-21 02:34:10 -ptn1: Test Success 2010-01-21 02:34:10 -ptn2: Test Success 2010-01-21 02:34:10 -ptn3: Test Success 2010-01-21 02:34:10 -ptn4: Test Success 2010-01-21 02:34:10 -pushpop: Test Success 2010-01-21 02:34:11 -rev_call: Test Success 2010-01-21 02:34:11 -sla2: Test Success 2010-01-21 02:34:11 -sra2: Test Success 2010-01-21 02:34:11 -sra3: Test Success 2010-01-21 02:34:11 -sra4: Test Success 2010-01-21 02:34:11 -st0: Test Success 2010-01-21 02:34:11 -st1: Test Success 2010-01-21 02:34:12 -sum_call: Test Success 2010-01-21 02:34:12 -summary: Test Success 2010-01-21 02:34:12 -svc2: Test Success 2010-01-21 02:34:12 -svc2_out: Test Success 2010-01-21 02:34:12 -xor0: Test Success 2010-01-21 02:34:12 -xor1: Test Success 2010-01-21 02:34:12 -xor3: Test Success 2010-01-21 02:34:13 -xor4: Test Success 2010-01-21 02:34:13 -xor5: Test Success 2010-01-21 02:34:13 diff --git a/test/integration/DUMPWORD/TEST.log b/test/integration/DUMPWORD/TEST.log deleted file mode 100644 index b2c5c0d..0000000 --- a/test/integration/DUMPWORD/TEST.log +++ /dev/null @@ -1,3 +0,0 @@ -a: Test Success 2010-01-21 02:34:13 -l: Test Success 2010-01-21 02:34:14 -noopt: Test Success 2010-01-21 02:34:14