命令表の作成
エラーリストの開放については要再検討
{ 126, "no source file" },
};
{ 126, "no source file" },
};
+/**
+ * CASL IIのエラーをエラーリストに追加
+ */
+void addcerrlist_casl2()
+{
+ addcerrlist(ARRAYSIZE(cerr_casl2), cerr_casl2);
+}
+
/**
* アセンブル結果を書き込むファイルの名前
*/
/**
* アセンブル結果を書き込むファイルの名前
*/
"Usage: %s [-slLaAtTdh] [-oO[<OBJECTFILE>]] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE1[ FILE2 ...]\n";
cerr_init();
"Usage: %s [-slLaAtTdh] [-oO[<OBJECTFILE>]] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE1[ FILE2 ...]\n";
cerr_init();
- addcerrlist(ARRAYSIZE(cerr_casl2), cerr_casl2);
addcerrlist_assemble();
addcerrlist_exec();
/* オプションの処理 */
addcerrlist_assemble();
addcerrlist_exec();
/* オプションの処理 */
for(pass = FIRST; pass <= SECOND; pass++) {
if(pass == FIRST) {
create_cmdtype_code(); /* 命令の名前とタイプがキーのハッシュ表を作成 */
for(pass = FIRST; pass <= SECOND; pass++) {
if(pass == FIRST) {
create_cmdtype_code(); /* 命令の名前とタイプがキーのハッシュ表を作成 */
- asptr = malloc_chk(sizeof(asptr), "asptr"); /* アセンブル時のプロパティ用の領域確保 */
+ asptr = malloc_chk(sizeof(ASPTR), "asptr"); /* アセンブル時のプロパティ用の領域確保 */
}
for(i = optind; i < argc; i++) {
/* データの格納開始位置 */
}
for(i = optind; i < argc; i++) {
/* データの格納開始位置 */
{
CERRLIST *p = cerrlist, *q;
{
CERRLIST *p = cerrlist, *q;
- /* エラーリストを解放 */
- while(p != NULL) {
- q = p->next;
- free_chk(p, "freecerr.p");
- p = q;
- }
/* 現在のエラーメッセージを解放 */
free_chk(cerr->msg, "cerr.msg");
/* 現在のエラーを解放 */
free_chk(cerr, "cerr");
/* 現在のエラーメッセージを解放 */
free_chk(cerr->msg, "cerr.msg");
/* 現在のエラーを解放 */
free_chk(cerr, "cerr");
+ /* エラーリストを解放 */
+ for(p = cerrlist; p != NULL; p = q) {
+ q = p->next;
+ /* free_chk(p->cerr->msg, "freecerr.p.cerr.msg"); */
+ /* free_chk(p->cerr, "freecerr.p.cerr"); */
+ free_chk(p, "freecerr.p");
+ }
*/
bool create_cmdtype_code()
{
*/
bool create_cmdtype_code()
{
unsigned hashval;
int i;
cmdtabsize = comet2cmdsize;
cmdtype_code = calloc_chk(cmdtabsize, sizeof(CMDTAB *), "cmdtype_code");
unsigned hashval;
int i;
cmdtabsize = comet2cmdsize;
cmdtype_code = calloc_chk(cmdtabsize, sizeof(CMDTAB *), "cmdtype_code");
- for(i = 0; i < cmdtabsize; i++) {
- *(cmdtype_code + i) = NULL;
- }
for(i = 0; i < comet2cmdsize; i++) {
for(i = 0; i < comet2cmdsize; i++) {
- np = malloc_chk(sizeof(CMDTAB), "cmdtype_code.np");
- np->cmd = NULL;
- np->next = NULL;
- /* ハッシュ値の生成 */
- hashval = hash_cmdtype(comet2cmd[i].name, comet2cmd[i].type);
- /* ハッシュ表に値を追加 */
- np->next = cmdtype_code[hashval];
- cmdtype_code[hashval] = np;
- np->cmd = &(comet2cmd[i]);
+ p = malloc_chk(sizeof(CMDTAB), "cmdtype_code.p");
+ hashval = hash_cmdtype(comet2cmd[i].name, comet2cmd[i].type); /* ハッシュ値の生成 */
+ p->next = cmdtype_code[hashval]; /* ハッシュ表に値を追加 */
+ p->cmd = &comet2cmd[i];
+ cmdtype_code[hashval] = p;
*/
WORD getcmdcode(const char *cmd, CMDTYPE type)
{
*/
WORD getcmdcode(const char *cmd, CMDTYPE type)
{
- for(np = cmdtype_code[hash_cmdtype(cmd, type)]; np != NULL; np = np->next){
- if(strcmp(cmd, np->cmd->name) == 0 && type == np->cmd->type) {
- return np->cmd->code;
+ for(p = cmdtype_code[hash_cmdtype(cmd, type)]; p != NULL; p = p->next){
+ if(strcmp(cmd, p->cmd->name) == 0 && type == p->cmd->type) {
+ return p->cmd->code;
void free_cmdtype_code()
{
int i;
void free_cmdtype_code()
{
int i;
for(i = 0; i < cmdtabsize; i++) {
for(i = 0; i < cmdtabsize; i++) {
- np = cmdtype_code[i];
- while(np != NULL) {
- nq = np->next;
- free_chk(np, "free_cmdtype_code.np");
- np = nq;
+ for(p = cmdtype_code[i]; p != NULL; p = q) {
+ q = p->next;
+ free_chk(p, "free_cmdtype_code.p");
}
}
free_chk(cmdtype_code, "cmdtype_code");
}
}
free_chk(cmdtype_code, "cmdtype_code");
*/
bool create_code_type()
{
*/
bool create_code_type()
{
unsigned hashval;
int i;
cmdtabsize = comet2cmdsize;
code_type = calloc_chk(cmdtabsize, sizeof(CMDTAB *), "code_type");
unsigned hashval;
int i;
cmdtabsize = comet2cmdsize;
code_type = calloc_chk(cmdtabsize, sizeof(CMDTAB *), "code_type");
- for(i = 0; i < cmdtabsize; i++) {
- *(code_type + i) = NULL;
- }
for(i = 0; i < comet2cmdsize; i++) {
for(i = 0; i < comet2cmdsize; i++) {
- np = malloc_chk(sizeof(CMDTAB), "code_type.np");
- np->cmd = NULL;
- np->next = NULL;
- /* ハッシュ値の生成 */
- hashval = hash_code((&comet2cmd[i])->code);
- /* ハッシュ表に値を追加 */
- np->next = code_type[hashval];
- code_type[hashval] = np;
- np->cmd = &comet2cmd[i];
+ p = malloc_chk(sizeof(CMDTAB), "code_type.p");
+ hashval = hash_code((&comet2cmd[i])->code); /* ハッシュ値の生成 */
+ p->next = code_type[hashval]; /* ハッシュ表に値を追加 */
+ p->cmd = &comet2cmd[i];
+ code_type[hashval] = p;
}
return true;
}
/**
* 命令コードから命令タイプを返す
}
return true;
}
/**
* 命令コードから命令タイプを返す
*/
CMDTYPE getcmdtype(WORD code)
{
*/
CMDTYPE getcmdtype(WORD code)
{
- CMDTAB *np;
- for(np = code_type[hash_code(code)]; np != NULL; np = np->next) {
- if(code == np->cmd->code) {
- return np->cmd->type;
+ CMDTAB *p;
+ for(p = code_type[hash_code(code)]; p != NULL; p = p->next) {
+ if(code == p->cmd->code) {
+ return p->cmd->type;
void free_code_type()
{
int i;
void free_code_type()
{
int i;
for(i = 0; i < cmdtabsize; i++) {
for(i = 0; i < cmdtabsize; i++) {
- np = code_type[i];
- while(np != NULL) {
- nq = np->next;
- free_chk(np, "code_type.np");
- np = nq;
+ p = code_type[i];
+ while(p != NULL) {
+ q = p->next;
+ free_chk(p, "code_type.p");
+ p = q;
}
}
free_chk(code_type, "code_type");
}
}
free_chk(code_type, "code_type");
void freelabel()
{
int i;
void freelabel()
{
int i;
for(i = 0; i < LABELTABSIZE; i++) {
for(i = 0; i < LABELTABSIZE; i++) {
- for(np = labels[i]; np != NULL; np = nq) {
- nq = np->next;
- if(np->prog != NULL) {
- free_chk(np->prog, "np.prog");
- }
- free_chk(np->label, "np.label");
- free_chk(np, "np");
+ for(p = labels[i]; p != NULL; p = q) {
+ q = p->next;
+ free_chk(p->prog, "freelabel.p.prog");
+ free_chk(p->label, "freelabel.p.label");
+ free_chk(p, "freelabel.p");