SECOND = 1,
} PASS;
+/* アセンブルのエラー定義 */
+bool addcerrlist_assemble();
+
/* プログラム名とラベルに対応するハッシュ値を返す */
unsigned labelhash(const char *prog, const char *label);
NONE = 0,
} CMDTYPE;
-extern int cmdcodesize;
-
-/* 命令コードの配列 */
+/* 命令コード配列 */
typedef struct {
char *cmd;
CMDTYPE type;
WORD code;
} CMDCODEARRAY;
+/* 命令コード配列のサイズ */
+extern int cmdcodesize;
+
/* 命令コードのハッシュ表 */
typedef struct _CMDCODETAB {
struct _CMDCODETAB *next;
#include <stdlib.h>
#include <string.h>
#include <assert.h>
+#include <stdbool.h>
#ifndef ARRAYSIZE
#define ARRAYSIZE(array) (sizeof(array)/sizeof(array[0]))
};
/* エラーを追加する */
-void addcerrlist(int cerrc, CERRARRAY cerrv[]);
+bool addcerrlist(int cerrc, CERRARRAY cerrv[]);
/* エラー番号とエラーメッセージを設定 */
void setcerr(int num, const char *str);
} EXECMODE;
extern EXECMODE execmode;
+/* 実行のエラー定義 */
+bool addcerrlist_exec();
+
/* 仮想マシンのリセット */
void reset();
#include "cerr.h"
+/* wordのエラー定義 */
+bool addcerrlist_word();
+
/* WORD - 16ビットデータ型 */
typedef unsigned short WORD;
/* 他のプログラムで参照する入口名 */
char *prog;
+
+/* アセンブルのエラー定義 */
+CERRARRAY cerr_assemble[] = {
+ { 101, "label already defined" },
+ { 102, "label table is full" },
+ { 103, "label not found" },
+ { 104, "label length is too long" },
+ { 105, "no command in the line" },
+ { 106, "operand mismatch in assemble command" },
+ { 107, "no label in START" },
+ { 108, "not command of operand \"r\"" },
+ { 109, "not command of operand \"r1,r2\"" },
+ { 110, "not command of operand \"r,adr[,x]\"" },
+ { 111, "not command of operand \"adr[,x]\"" },
+ { 112, "not command of no operand" },
+ { 113, "operand too many in COMET II command" },
+ { 117, "operand too many in DC" },
+ { 118, "operand length too long" },
+ { 119, "out of COMET II memory" },
+ { 120, "GR0 in operand x" },
+ { 121, "cannot get operand token" },
+ { 122, "cannot create hash table" },
+ { 123, "unclosed quote" },
+ { 124, "more than one character in literal" },
+ { 125, "not GR in operand x" },
+};
+
+bool addcerrlist_assemble()
+{
+ return addcerrlist(ARRAYSIZE(cerr_assemble), cerr_assemble);
+}
+
/* 汎用レジスタを表す文字列「GR[0-7]」から、レジスタ番号[0-7]をWORD値で返す */
/* 文字列が汎用レジスタを表さない場合は、0xFFFFを返す */
/* is_xがtrueの場合は指標レジスタ。GR0は、COMET IIの仕様により、エラー発生 */
bool writememory(WORD word, WORD adr, PASS pass)
{
bool status = false;
+
/* COMET IIメモリオーバーの場合 */
if(adr >= memsize) {
setcerr(119, word2n(adr)); /* out of COMET II memory */
status = true;
}
} else {
- setcerr(113, cmdl->cmd); /* command not defined */
+ setcerr(113, cmdl->cmd); /* operand too many in COMET II command */
return false;
}
}
;
}
else if(cerrno == 0) {
- setcerr(113, cmdl->cmd); /* command not defined */
+ setcerr(113, cmdl->cmd); /* operand too many in COMET II command */
}
/* エラーが発生していないか確認 */
if(cerrno == 0) {
char *line;
FILE *fp;
+ addcerrlist_assemble();
if((fp = fopen(file, "r")) == NULL) {
perror(file);
return false;
{0, 0, 0, 0},
};
-/* エラー番号とエラーメッセージ */
+/* casl2のエラー定義 */
CERRARRAY cerr_casl2[] = {
- { 101, "label already defined" },
- { 102, "label table is full" },
- { 103, "label not found" },
- { 104, "label length is too long" },
- { 105, "no command in the line" },
- { 106, "operand mismatch in assemble command" },
- { 107, "no label in START" },
- { 108, "not command of operand \"r\"" },
- { 109, "not command of operand \"r1,r2\"" },
- { 110, "not command of operand \"r,adr[,x]\"" },
- { 111, "not command of operand \"adr[,x]\"" },
- { 112, "not command of no operand" },
- { 113, "operand too many in machine command" },
- { 114, "not integer" },
- { 115, "not hex" },
- { 116, "out of hex range" },
- { 117, "operand too many in DC" },
- { 118, "operand length too long" },
- { 119, "out of COMET II memory" },
- { 120, "GR0 in operand x" },
- { 121, "cannot get operand token" },
- { 122, "cannot create hash table" },
- { 123, "unclosed quote" },
- { 124, "more than one character in literal" },
- { 125, "not GR in operand x" },
{ 126, "source file is not specified" },
- { 201, "execute - out of COMET II memory" },
- { 202, "SVC input - out of Input memory" },
- { 203, "SVC output - out of COMET II memory" },
- { 204, "Program Register (PR) - out of COMET II memory" },
- { 205, "Stack Pointer (SP) - cannot allocate stack buffer" },
- { 206, "Address - out of COMET II memory" },
- { 207, "Stack Pointer (SP) - out of COMET II memory" },
};
+bool addcerrlist_casl2()
+{
+ return addcerrlist_casl2(ARRAYSIZE(cerr_casl2), cerr_casl2);
+}
/* 指定されたファイルにアセンブル結果を書込 */
void outassemble(const char *file) {
exit(-1);
}
}
- /* エラーリストにerr_casl2を追加 */
- addcerrlist(ARRAYSIZE(cerr_casl2), cerr_casl2);
+
+ #if 0
+ addcerrlist_casl2();
+ #endif
/* ソースファイルが指定されていない場合は終了 */
if(argv[optind] == NULL) {
setcerr(126, NULL); /* source file is not specified */
}
}
}
- freelabel(); /* ラベル表の解放 */
+ free_cmdtype_code(); /* 命令表の解放 */
+ freelabel(); /* ラベル表の解放 */
if(status == true) {
if(objfile != NULL) {
outassemble(objfile);
CERRLIST *cerr;
/* エラーリストを作成する */
-void addcerrlist(int newerrc, CERRARRAY newerrv[])
+bool addcerrlist(int newerrc, CERRARRAY newerrv[])
{
int i;
- CERRLIST *p = cerr, *q;
+ CERRLIST *p, *q;
+ assert(newerrc > 0 && newerrv != NULL);
if(cerr != NULL) {
- for(p = cerr; p != NULL; p = p->next) {
- ;
+ p = cerr;
+ while (p != NULL) {
+ q = p;
+ p = p->next;
}
- if((p = malloc(sizeof(CERRLIST *))) == NULL) {
- fprintf(stderr, "addcerrlist: cannot allocate memory\n");
- exit(-1);
+ if((p = q->next = malloc(sizeof(CERRLIST *))) == NULL) {
+ goto addcerrlisterr;
}
} else if((p = cerr = malloc(sizeof(CERRLIST *))) == NULL) {
- fprintf(stderr, "addcerrlist: cannot allocate memory\n");
- exit(-1);
+ goto addcerrlisterr;
}
for(i = 0; i < newerrc; i++) {
p->err = &(newerrv[i]);
if((p->next = malloc(sizeof(CERRLIST *))) == NULL) {
- fprintf(stderr, "addcerrlist: cannot allocate memory\n");
- exit(-1);
+ goto addcerrlisterr;
}
q = p;
p = p->next;
}
q->next = NULL;
+ return true;
+addcerrlisterr:
+ fprintf(stderr, "addcerrlist: cannot allocate memory\n");
+ exit(-1);
}
/* エラー番号とエラーメッセージを設定する */
{0, 0, 0, 0}
};
-/* エラー番号とエラーメッセージ */
+/* comet2のエラー定義 */
CERRARRAY cerr_comet2[] = {
{ 201, "Load object file - full of COMET II memory" },
- { 202, "SVC input - out of Input memory" },
- { 203, "SVC output - out of COMET II memory" },
- { 204, "Program Register (PR) - out of COMET II memory" },
- { 205, "Stack Pointer (SP) - cannot allocate stack buffer" },
- { 206, "Address - out of COMET II memory" },
- { 207, "Stack Pointer (SP) - out of COMET II memory" },
};
+bool addcerrlist_comet2()
+{
+ return addcerrlist(ARRAYSIZE(cerr_comet2), cerr_comet2);
+}
/* 指定されたファイルからアセンブル結果を読込 */
bool loadassemble(char *file) {
FILE *fp;
+
if((fp = fopen(file, "r")) == NULL) {
perror(file);
return false;
int opt;
const char *usage = "Usage: %s [-tTdh] [-M <memorysize>] [-C <clocks>] FILE\n";
+ addcerrlist_comet2();
while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) {
switch(opt) {
case 't':
exit(-1);
}
}
- /* エラーリストにerr_comet2を追加 */
- addcerrlist(ARRAYSIZE(cerr_comet2), cerr_comet2);
reset();
startptr = 0;
if(loadassemble(argv[optind]) == true) {
{0, 0, 0, 0},
};
-CERRARRAY cerr_dumpword[] = {
- { 114, "not integer" },
- { 115, "not hex" },
- { 116, "out of hex range" },
-};
-
int main(int argc, char *argv[])
{
bool logicalmode = false; /* レジストリの内容を論理値(0〜65535)で表示する場合はtrue */
fprintf(stderr, usage, argv[0]);
exit(-1);
}
- /* エラーリストにerr_casl2を追加 */
- addcerrlist(ARRAYSIZE(cerr_dumpword), cerr_dumpword);
/* WORD値に変換 */
word = nh2word(argv[optind]);
if(cerrno > 0) {
#include "casl2.h"
#include "exec.h"
+/* 実行のエラー定義 */
+CERRARRAY cerr_exec[] = {
+ { 202, "SVC input - out of Input memory" },
+ { 203, "SVC output - out of COMET II memory" },
+ { 204, "Program Register (PR) - out of COMET II memory" },
+ { 205, "Stack Pointer (SP) - cannot allocate stack buffer" },
+ { 206, "Address - out of COMET II memory" },
+ { 207, "Stack Pointer (SP) - out of COMET II memory" },
+};
+
+bool addcerrlist_exec()
+{
+ return addcerrlist(ARRAYSIZE(cerr_exec), cerr_exec);
+}
+
/* 実行モード: trace, logical, dump */
EXECMODE execmode = {false, false, false};
char *errpr = malloc(CERRSTRSIZE + 1);
clock_t clock_begin, clock_end;
+ addcerrlist_exec();
if(execmode.trace) {
fprintf(stdout, "\nExecuting machine codes\n");
}
#include "word.h"
+/* wordのエラー定義 */
+CERRARRAY cerr_word[] = {
+ { 114, "not integer" },
+ { 115, "not hex" },
+ { 116, "out of hex range" },
+};
+bool addcerrlist_word()
+{
+ return addcerrlist(ARRAYSIZE(cerr_word), cerr_word);
+}
+
/* 10進数の文字列をWORD値に変換 */
WORD n2word(const char *str)
{
assert(isdigit(*str) || *str == '-');
+
char *check;
int n;
/* WORD値に変換 */
WORD h2word(const char *str)
{
assert(*str == '#');
+
WORD word = 0x0;
char *check;
str++;
/* 10進数または16進数の文字列をWORD値に変換 */
WORD nh2word(const char *str)
{
+ addcerrlist_word();
WORD word;
if(!isdigit(*str) && *str != '-' && *str != '#') {
setcerr(114, str); /* not integer */
../../../../casl2 ../../../../as/err/err_113.casl
-Assemble error - 113: LD: operand too many in machine command
+Assemble error - 113: LD: operand too many in COMET II command
../../../../as/err/err_113.casl: 2: LD GR1,A,1,2
--- /dev/null
+UCLASS = COMMON
+TESTSRCFILE = addcerrlist.c
+include ../TEST.mk
--- /dev/null
+#include <stdio.h>
+#include "casl2.h"
+
+CERRARRAY cerr_0[] = {
+ { 126, "source file is not specified" },
+};
+
+CERRARRAY cerr_1[] = {
+ { 101, "label already defined" },
+ { 102, "label table is full" },
+ { 103, "label not found" },
+ { 104, "label length is too long" },
+ { 105, "no command in the line" },
+ { 106, "operand mismatch in assemble command" },
+ { 107, "no label in START" },
+ { 108, "not command of operand \"r\"" },
+ { 109, "not command of operand \"r1,r2\"" },
+ { 110, "not command of operand \"r,adr[,x]\"" },
+ { 111, "not command of operand \"adr[,x]\"" },
+ { 112, "not command of no operand" },
+ { 113, "operand too many in COMET II command" },
+ { 117, "operand too many in DC" },
+ { 118, "operand length too long" },
+ { 119, "out of COMET II memory" },
+ { 120, "GR0 in operand x" },
+ { 121, "cannot get operand token" },
+ { 122, "cannot create hash table" },
+ { 123, "unclosed quote" },
+ { 124, "more than one character in literal" },
+ { 125, "not GR in operand x" },
+};
+
+CERRARRAY cerr_2[] = {
+ { 114, "not integer" },
+ { 115, "not hex" },
+ { 116, "out of hex range" },
+};
+
+CERRARRAY cerr_3[] = {
+ { 114, "not integer" },
+ { 115, "not hex" },
+ { 116, "out of hex range" },
+};
+
+CERRARRAY cerr_4[] = {
+ { 201, "Load object file - full of COMET II memory" },
+};
+
+CERRARRAY cerr_5[] = {
+ { 202, "SVC input - out of Input memory" },
+ { 203, "SVC output - out of COMET II memory" },
+ { 204, "Program Register (PR) - out of COMET II memory" },
+ { 205, "Stack Pointer (SP) - cannot allocate stack buffer" },
+ { 206, "Address - out of COMET II memory" },
+ { 207, "Stack Pointer (SP) - out of COMET II memory" },
+};
+
+int main(){
+ CERRLIST *p;
+ addcerrlist(ARRAYSIZE(cerr_0), cerr_0);
+ addcerrlist(ARRAYSIZE(cerr_1), cerr_1);
+ addcerrlist(ARRAYSIZE(cerr_2), cerr_2);
+ addcerrlist(ARRAYSIZE(cerr_3), cerr_3);
+ addcerrlist(ARRAYSIZE(cerr_4), cerr_4);
+ addcerrlist(ARRAYSIZE(cerr_5), cerr_5);
+ for(p = cerr; p != NULL; p = p->next) {
+ printf("%d: %s\n", p->err->num, p->err->msg);
+ }
+ return 0;
+}
#include <stdio.h>
#include "casl2.h"
-/* エラー番号とエラーメッセージ */
static CERRARRAY cerr_utest[] = {
{ 101, "label already defined" },
{ 102, "label table is full" },
UCLASS = COMMON
-TESTSRCFILE = ../CERRARRAY.c getcmdcode.c
+TESTSRCFILE = getcmdcode.c
include ../TEST.mk
UCLASS = COMMON
-TESTSRCFILE = ../CERRARRAY.c getcmdtype.c
+TESTSRCFILE = getcmdtype.c
include ../TEST.mk
UCLASS = AS
-TESTSRCFILE = ../CERRARRAY.c getgr.c
+TESTSRCFILE = getgr.c
include ../TEST.mk
UCLASS = AS
-TESTSRCFILE = ../CERRARRAY.c h2word.c
+TESTSRCFILE = h2word.c
include ../TEST.mk