--- /dev/null
+#include <stdio.h>
+#include "casl2.h"
+#include "assemble.h"
+#include "exec.h"
+
+int main(){
+ int i;
+ WORD r;
+ char *str[] = {
+ "str0", "str1", "str2", "str3", "str4", "str5", "str6", ...
+ };
+ for(i = 0; i < sizeof(str)/sizeof(str[0]); i++) {
+ r = ##testfunc##(str[i]);
+ printf("%s\t0x%04x", str[i], r);
+ if(cerrno > 0) {
+ printf("\tError - %d\t%s", cerrno, cerrmsg);
+ freecerr();
+ }
+ printf("\n");
+ }
+ return 0;
+}
--- /dev/null
+# テストのテンプレート
+# make : CMDで設定されたコマンドを実行した出力結果を1.txtに出力し、0.txtと比較し、レポート
+# make check : ↓
+# make prepare : CMDで設定されたコマンドを実行した出力結果を0.txt(テストの想定結果)に出力
+# make clean : 「make」で生成されたファイルをクリア
+# make cleanall: 「make」と「make clean」で生成されたファイルをクリア
+LOGFILE = ../TEST.log
+ERRFILE = err.txt
+UNITNAME = `pwd | xargs basename`
+
+INCLUDE = ../../../include
+CC = gcc
+CFLAGS = -g -Wall -I $(INCLUDE)
+SRCDIR = ../../../src
+COMMONSRC = $(SRCDIR)/struct.o $(SRCDIR)/hash.o $(SRCDIR)/cmd.o $(SRCDIR)/cerr.o $(SRCDIR)/dump.o
+ASSRC = $(SRCDIR)/assemble.o $(SRCDIR)/token.o $(SRCDIR)/label.o $(SRCDIR)/macro.o
+EXECSRC = $(SRCDIR)/exec.o
+
+ifeq "$(UCLASS)" "AS"
+ SRC = $(COMMONSRC) $(ASSRC)
+endif
+ifeq "$(UCLASS)" "EXEC"
+ SRC = $(COMMONSRC) $(EXECSRC)
+endif
+ifeq "$(UCLASS)" "COMMON"
+ SRC = $(COMMONSRC)
+endif
+
+.PHPNY: check prepare clean cleanall
+check: clean report.txt
+prepare: cleanall 0.txt
+clean:
+ @rm -f a.out 1.txt diff.txt report.txt
+cleanall: clean
+ @rm -f 0.txt
+a.out: $(SRC) $(TESTSRCFILE)
+ @gcc $(CFLAGS) $(SRC) $(TESTSRCFILE)
+$(SRCDIR)/%.o: $(SRCDIR)/%.c
+ @$(CC) -c $(CFLAGS) $<
+0.txt 1.txt: a.out
+ @./a.out >$@ 2>&1
+diff.txt: 1.txt
+ @-diff 0.txt 1.txt >$@ 2>&1
+report.txt: diff.txt
+ @echo -n "$(UNITNAME): Test " >$@; \
+ if test ! -s $^; then echo -n "Success " >>$@; rm -f $^; else echo -n "Failure " >>$@; fi; \
+ echo `date +"%F %T"` >>$@
--- /dev/null
+LD:000 ---> #FFFF
+LD:066 ---> #FFFF
+NOEX:020 ---> #FFFF
+NOP:000 ---> #0000
+LD:011 ---> #1000
+ST:010 ---> #1100
+LAD:010 ---> #1200
+LD:020 ---> #1400
+ADDA:011 ---> #2000
+SUBA:011 ---> #2100
+ADDL:011 ---> #2200
+SUBL:011 ---> #2300
+ADDA:020 ---> #2400
+SUBA:020 ---> #2500
+ADDL:020 ---> #2600
+SUBL:020 ---> #2700
+AND:011 ---> #3000
+OR:011 ---> #3100
+XOR:011 ---> #3200
+AND:020 ---> #3400
+OR:020 ---> #3500
+XOR:020 ---> #3600
+CPA:011 ---> #4000
+CPL:011 ---> #4100
+CPA:020 ---> #4400
+CPL:020 ---> #4500
+SLA:010 ---> #5000
+SRA:010 ---> #5100
+SLL:010 ---> #5200
+SRL:010 ---> #5300
+JMI:030 ---> #6100
+JNZ:030 ---> #6200
+JZE:030 ---> #6300
+JUMP:030 ---> #6400
+JPL:030 ---> #6500
+JOV:030 ---> #6600
+PUSH:030 ---> #7000
+POP:040 ---> #7100
+CALL:030 ---> #8000
+SVC:030 ---> #F000
+RET:000 ---> #8100
UCLASS = COMMON
+TESTSRCFILE = getcmdcode.c
include ../TEST.mk
create_cmdtype_code();
for(i = 0; i < sizeof(cmdcodelist)/sizeof(cmdcodelist[0]); i++) {
code = getcmdcode(cmdcodelist[i].cmd, cmdcodelist[i].type);
- printf("%s:0%02o ---> 0x%04x\n", cmdcodelist[i].cmd, cmdcodelist[i].type, code);
+ printf("%s:0%02o ---> #%04X\n", cmdcodelist[i].cmd, cmdcodelist[i].type, code);
if(cerrno != 0) {
printf("\terror - %d: %s", cerrno, cerrmsg);
freecerr();
--- /dev/null
+#FFFF ---> 000
+#0001 ---> 000
+#0000 ---> 000
+#1000 ---> 011
+#1100 ---> 010
+#1200 ---> 010
+#1400 ---> 020
+#2000 ---> 011
+#2100 ---> 011
+#2200 ---> 011
+#2300 ---> 011
+#2400 ---> 020
+#2500 ---> 020
+#2600 ---> 020
+#2700 ---> 020
+#3000 ---> 011
+#3100 ---> 011
+#3200 ---> 011
+#3400 ---> 020
+#3500 ---> 020
+#3600 ---> 020
+#4000 ---> 011
+#4100 ---> 011
+#4400 ---> 020
+#4500 ---> 020
+#5000 ---> 010
+#5100 ---> 010
+#5200 ---> 010
+#5300 ---> 010
+#6100 ---> 030
+#6200 ---> 030
+#6300 ---> 030
+#6400 ---> 030
+#6500 ---> 030
+#6600 ---> 030
+#7000 ---> 030
+#7100 ---> 040
+#8000 ---> 030
+#F000 ---> 030
+#8100 ---> 000
UCLASS = COMMON
+TESTSRCFILE = getcmdtype.c
include ../TEST.mk
-#include <stdio.h>
#include "casl2.h"
int main(){
0x8000, 0xF000, 0x8100
};
create_code_type();
- for(i = 0; i < sizeof(codelist)/sizeof(codelist[0]); i++) {
+ for(i = 0; i < ARRAYSIZE(codelist); i++) {
type = getcmdtype(codelist[i]);
- printf("0x%04x ---> 0%02o\n", codelist[i], type);
+ printf("#%04X ---> 0%02o\n", codelist[i], type);
if(cerrno != 0) {
printf("\t%s", cerrmsg);
freecerr();
--- /dev/null
+== Generel Register ==
+ #FFFF
+0 #FFFF
+aaa #FFFF
+GR #FFFF
+GR8 #FFFF
+GR20 #FFFF
+GR0 #0000
+GR1 #0001
+GR2 #0002
+GR3 #0003
+GR4 #0004
+GR5 #0005
+GR6 #0006
+GR7 #0007
+== Index Register ==
+ #FFFF
+0 #FFFF
+aaa #FFFF
+GR #FFFF
+GR8 #FFFF
+GR20 #FFFF
+GR0 #0000 Error - 120 GR0 in operand x
+GR1 #0001
+GR2 #0002
+GR3 #0003
+GR4 #0004
+GR5 #0005
+GR6 #0006
+GR7 #0007
UCLASS = AS
+TESTSRCFILE = getgr.c
include ../TEST.mk
--- /dev/null
+#32768 #0000 Error - 116 #32768: out of hex range
+#-1 #0000 Error - 116 #-1: out of hex range
+#G #0000 Error - 115 #G: not hex
+#FFFF #FFFF
+#0 #0000
+#1 #0001
+#ab #00AB
+#AB #00AB
+#20 #0020
UCLASS = AS
+TESTSRCFILE = gethex.c
include ../TEST.mk
--- /dev/null
+0 0x0000
+01 0x0001
+1a 0x0000 Error - 114 1a: not integer
+-5G 0x0000 Error - 114 -5G: not integer
+123 0x007b
+32767 0x7fff
+32768 0x0000
+32769 0x0001
+-1 0xffff
+-2345 0xf6d7
+-32768 0x8000
+-32769 0xffff
+-32770 0xfffe
UCLASS = AS
+TESTSRCFILE = getint.c
include ../TEST.mk
--- /dev/null
+HASH VALUE: 20
+HASH VALUE: 11
+HASH VALUE: 23
--- /dev/null
+UCLASS = COMMON
+TESTSRCFILE = hash.c
+include ../TEST.mk
--- /dev/null
+#include <stdio.h>
+#include "hash.h"
+#include <string.h>
+#include <stdlib.h>
+
+unsigned hash_char2(int tsize)
+{
+ char *str[2] = {"abc", "123"};
+ int i;
+ HKEY *keys[2];
+
+ /* ハッシュ共用体の設定 */
+ for(i = 0; i < 2; i++) {
+ keys[i] = malloc(sizeof(HKEY));
+ keys[i]->type = CHARS;
+ keys[i]->val.s = strdup(str[i]);
+ }
+ /* ハッシュ値を取得する */
+ return hash(2, keys, tsize);
+}
+
+unsigned hash_int2(int tsize)
+{
+ int num[2] = {19, 11}, i;
+ HKEY *keys[2];
+
+ /* ハッシュ共用体の設定 */
+ for(i = 0; i < 2; i++) {
+ keys[i] = malloc(sizeof(HKEY));
+ keys[i]->type = INT;
+ keys[i]->val.i = num[i];
+ }
+ /* ハッシュ値を取得する */
+ return hash(2, keys, tsize);
+}
+
+unsigned hash_char2_int2(int tsize)
+{
+ char *str[2] = {"abc", "123"};
+ int num[2] = {19, 11}, i;
+ HKEY *keys[4];
+
+ /* ハッシュ共用体の設定 */
+ for(i = 0; i < 2; i++) {
+ keys[i] = malloc(sizeof(HKEY));
+ keys[i]->type = CHARS;
+ keys[i]->val.s = strdup(str[i]);
+ }
+ for(i = 2; i < 4; i++) {
+ keys[i] = malloc(sizeof(HKEY));
+ keys[i]->type = INT;
+ keys[i]->val.i = num[i];
+ }
+ /* ハッシュ値を取得する */
+ return hash(4, keys, tsize);
+}
+
+int main()
+{
+ int tsize = 31;
+
+ printf("HASH VALUE: %d\n", hash_char2(tsize));
+ printf("HASH VALUE: %d\n", hash_int2(tsize));
+ printf("HASH VALUE: %d\n", hash_char2_int2(tsize));
+ return 0;
+}
--- /dev/null
+0: IOTEST START
+cl->label: IOTEST
+cl->cmd: START
+cl->opdc: 0
+
+1: OUT OBUF1,OLEN1
+cl->cmd: OUT
+cl->opdc: 2
+cl->opdv[0]: OBUF1
+cl->opdv[1]: OLEN1
+
+2: OUT OBUF2,OLEN2 ;comment
+cl->cmd: OUT
+cl->opdc: 2
+cl->opdv[0]: OBUF2
+cl->opdv[1]: OLEN2
+
+3: OUT OBUF1,OLEN1
+cl->cmd: OUT
+cl->opdc: 2
+cl->opdv[0]: OBUF1
+cl->opdv[1]: OLEN1
+
+4: OUT OBUF1,OLEN1
+cl->cmd: OUT
+cl->opdc: 2
+cl->opdv[0]: OBUF1
+cl->opdv[1]: OLEN1
+
+5: OUT OBUF2,OLEN2
+cl->cmd: OUT
+cl->opdc: 2
+cl->opdv[0]: OBUF2
+cl->opdv[1]: OLEN2
+
+6: OUT OBUF1, OLEN1
+cl->cmd: OUT
+cl->opdc: 1
+cl->opdv[0]: OBUF1
+ error - 121: cannot get operand token
+
+7: BEGIN LD GR1, A
+cl->label: BEGIN
+cl->cmd: LD
+cl->opdc: 1
+cl->opdv[0]: GR1
+ error - 121: cannot get operand token
+
+8:
+cl is NULL
+
+9: ;comment
+cl is NULL
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[1]:2
+OPDC[2]:3
+OPDC[3]:4
+OPDC[4]:5
+OPDC[5]:6
+OPDC[6]:7
+OPDC[7]:8
+OPDC[8]:9
+OPDC[9]:0
+OPDC[10]:1
+OPDC[11]:2
+OPDC[12]:3
+OPDC[13]:4
+OPDC[14]:5
+OPDC[15]:6
+OPDC[16]:7
+OPDC[17]:8
+OPDC[18]:9
+OPDC[19]:0
+OPDC[20]:1
+OPDC[21]:2
+OPDC[22]:3
+OPDC[23]:4
+OPDC[24]:5
+OPDC[25]:6
+OPDC[26]:7
+OPDC[27]:8
+OPDC[28]:9
+OPDC[29]:0
+OPDC[30]:1
+OPDC[31]:2
+OPDC[32]:3
+OPDC[33]:4
+OPDC[34]:5
+OPDC[35]:6
+OPDC[36]:7
+OPDC[37]:8
+OPDC[38]:9
+OPDC[39]:0
+Error - 117: operand is too many
+
+'1234567890123456789012345678901234567890'
+OPDC:1
+OPDC[0]:'1234567890123456789012345678901234567890'
+
+'12345678901234567890123456789012345678901'
+OPDC:0
+Error - 118: '12345678901234567890123456789012345678901': operand length is too long
+
--- /dev/null
+== CMDTYPE_CODE TABLE ==
+( 0) - SVC 030 #F000
+( 1) - JZE 030 #6300
+( 1) - SLL 010 #5200
+( 2) - SLA 010 #5000
+( 3) - ADDL 011 #2200
+( 3) - NOP 000 #0000
+( 4) - ADDA 011 #2000
+( 7) - OR 020 #3500
+(10) - CALL 030 #8000
+(11) - ADDL 020 #2600
+(12) - ADDA 020 #2400
+(13) - RET 000 #8100
+(14) - SUBL 011 #2300
+(15) - SUBA 011 #2100
+(19) - LAD 010 #1200
+(20) - JMI 030 #6100
+(21) - AND 011 #3000
+(22) - JUMP 030 #6400
+(22) - SUBL 020 #2700
+(23) - CPL 011 #4100
+(23) - SUBA 020 #2500
+(24) - CPA 011 #4000
+(25) - XOR 011 #3200
+(26) - JNZ 030 #6200
+(26) - LD 011 #1000
+(27) - JOV 030 #6600
+(29) - SRL 010 #5300
+(29) - AND 020 #3400
+(29) - ST 010 #1100
+(30) - SRA 010 #5100
+(31) - CPL 020 #4500
+(32) - JPL 030 #6500
+(32) - CPA 020 #4400
+(33) - POP 040 #7100
+(33) - XOR 020 #3600
+(34) - PUSH 030 #7000
+(34) - LD 020 #1400
+(37) - OR 011 #3100
--- /dev/null
+== CODE_TYPE TABLE ==
+( 0) - #2600 020 ADDL
+( 0) - #0000 000 NOP
+( 1) - #2700 020 SUBL
+( 4) - #5000 010 SLA
+( 5) - #5100 010 SRA
+( 6) - #5200 010 SLL
+( 7) - #5300 010 SRL
+(10) - #3000 011 AND
+(11) - #3100 011 OR
+(12) - #F000 030 SVC
+(12) - #3200 011 XOR
+(14) - #8000 030 CALL
+(14) - #3400 020 AND
+(15) - #8100 000 RET
+(15) - #3500 020 OR
+(16) - #3600 020 XOR
+(16) - #1000 011 LD
+(17) - #1100 010 ST
+(18) - #1200 010 LAD
+(20) - #1400 020 LD
+(21) - #6100 030 JMI
+(22) - #6200 030 JNZ
+(23) - #6300 030 JZE
+(24) - #6400 030 JUMP
+(25) - #6500 030 JPL
+(26) - #6600 030 JOV
+(26) - #4000 011 CPA
+(27) - #4100 011 CPL
+(30) - #4400 020 CPA
+(31) - #4500 020 CPL
+(32) - #2000 011 ADDA
+(33) - #2100 011 SUBA
+(34) - #2200 011 ADDL
+(35) - #2300 011 SUBL
+(36) - #7000 030 PUSH
+(36) - #2400 020 ADDA
+(37) - #7100 040 POP
+(37) - #2500 020 SUBA