projects
/
YACASL2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
DoxygenとGNU GLOBALが連携するよう設定を変更
[YACASL2.git]
/
src
/
assemble.c
diff --git
a/src/assemble.c
b/src/assemble.c
index
d6cb4f2
..
35c3e9f
100644
(file)
--- a/
src/assemble.c
+++ b/
src/assemble.c
@@
-148,7
+148,7
@@
bool assemblecmd(const CMDLINE *cmdl, PASS pass)
}
/* プログラム名の設定 */
asptr->prog = strdup_chk(cmdl->label, "asptr.prog");
}
/* プログラム名の設定 */
asptr->prog = strdup_chk(cmdl->label, "asptr.prog");
- /* オペランドがある場合、実行開始
番地
を設定 */
+ /* オペランドがある場合、実行開始
アドレス
を設定 */
if(pass == SECOND && cmdl->opd->opdc == 1) {
if((execptr->start = getlabel(asptr->prog, cmdl->opd->opdv[0])) == 0xFFFF) {
setcerr(103, cmdl->opd->opdv[0]); /* label not found */
if(pass == SECOND && cmdl->opd->opdc == 1) {
if((execptr->start = getlabel(asptr->prog, cmdl->opd->opdv[0])) == 0xFFFF) {
setcerr(103, cmdl->opd->opdv[0]); /* label not found */
@@
-157,16
+157,15
@@
bool assemblecmd(const CMDLINE *cmdl, PASS pass)
status = true;
break;
case END:
status = true;
break;
case END:
- /* 1回目のアセンブルの場合は、リテラル領域開始
番地
を設定 */
+ /* 1回目のアセンブルの場合は、リテラル領域開始
アドレス
を設定 */
if(pass == FIRST) {
asptr->lptr = asptr->ptr;
}
if(pass == FIRST) {
asptr->lptr = asptr->ptr;
}
- /* 2回目のアセンブルの場合は、リテラル領域終了
番地を実行終了番地
として設定 */
+ /* 2回目のアセンブルの場合は、リテラル領域終了
アドレスを実行終了アドレス
として設定 */
else if(pass == SECOND) {
execptr->end = asptr->lptr;
}
else if(pass == SECOND) {
execptr->end = asptr->lptr;
}
- /* プログラム名のクリア */
- asptr->prog = NULL;
+ FREE(asptr->prog);
status = true;
break;
case DS:
status = true;
break;
case DS:
@@
-204,7
+203,7
@@
bool assemblecmd(const CMDLINE *cmdl, PASS pass)
bool macrocmd(const CMDLINE *cmdl, PASS pass)
{
int i = 0;
bool macrocmd(const CMDLINE *cmdl, PASS pass)
{
int i = 0;
- MACROCMDID cmdid;
+ MACROCMDID cmdid
= 0
;
MACROCMD macrocmd[] = {
{ IN, 2, 2, "IN" },
{ OUT, 2, 2, "OUT" },
MACROCMD macrocmd[] = {
{ IN, 2, 2, "IN" },
{ OUT, 2, 2, "OUT" },
@@
-268,7
+267,7
@@
void writeIN(const char *ibuf, const char *len, PASS pass)
assembleline(" POP GR2", pass);
assembleline(" POP GR1", pass);
assembleline(" POP GR2", pass);
assembleline(" POP GR1", pass);
-
free_chk(line, "writeIN.line"
);
+
FREE(line
);
}
/**
}
/**
@@
-300,7
+299,7
@@
void writeOUT(const char *obuf, const char *len, PASS pass)
assembleline(" SVC 2", pass);
assembleline(" POP GR2", pass);
assembleline(" POP GR1", pass);
assembleline(" SVC 2", pass);
assembleline(" POP GR2", pass);
assembleline(" POP GR1", pass);
-
free_chk(line, "writeOUT.line"
);
+
FREE(line
);
}
/** マクロ命令「RPUSH」をメモリに書き込む
}
/** マクロ命令「RPUSH」をメモリに書き込む
@@
-321,7
+320,7
@@
void writeRPUSH(PASS pass)
sprintf(line, " PUSH 0,GR%d", i);
assembleline(line, pass);
}
sprintf(line, " PUSH 0,GR%d", i);
assembleline(line, pass);
}
-
free_chk(line, "writeRPUSH.line"
);
+
FREE(line
);
}
/**
}
/**
@@
-344,7
+343,7
@@
void writeRPOP(PASS pass)
sprintf(line, " POP GR%d", i);
assembleline(line, pass);
}
sprintf(line, " POP GR%d", i);
assembleline(line, pass);
}
-
free_chk(line, "writeRPOP.line"
);
+
FREE(line
);
}
/**
}
/**
@@
-525,17
+524,15
@@
void writeDC(const char *str, PASS pass)
}
/**
}
/**
- *
1行
をアセンブル
+ *
トークン
をアセンブル
*/
bool assembletok(const CMDLINE *cmdl, PASS pass)
{
bool status = false;
*/
bool assembletok(const CMDLINE *cmdl, PASS pass)
{
bool status = false;
+
/* 命令がない場合 */
if(cmdl->cmd == NULL){
/* 命令がない場合 */
if(cmdl->cmd == NULL){
- /* ラベルが定義されていて命令がない場合はエラー */
- if(cmdl->label != NULL) {
- setcerr(105, NULL); /* no command in the line */
- }
+ ;
}
/* アセンブラ命令の処理 */
else if(cerr->num == 0 && assemblecmd(cmdl, pass) == true) {
}
/* アセンブラ命令の処理 */
else if(cerr->num == 0 && assemblecmd(cmdl, pass) == true) {
@@
-595,18
+592,31
@@
WORD getadr(const char *prog, const char *str, PASS pass)
bool assembleline(const char *line, PASS pass)
{
CMDLINE *cmdl;
bool assembleline(const char *line, PASS pass)
{
CMDLINE *cmdl;
+ bool status = true;
+ int i;
- if((cmdl = linetok(line)) != NULL) {
- if(pass == FIRST && cmdl->label != NULL) {
- if(addlabel(asptr->prog, cmdl->label, asptr->ptr) == false) {
- return false;
+ cmdl = linetok(line);
+ status = (cerr->num == 0) ? true : false;
+ if(cmdl != NULL) {
+ if(status == true) {
+ if(pass == FIRST && cmdl->label != NULL) {
+ status = addlabel(asptr->prog, cmdl->label, asptr->ptr);
}
}
+ if(status == true) {
+ status = assembletok(cmdl, pass);
+ }
+ FREE(cmdl->label);
}
}
- if(assembletok(cmdl, pass) == false) {
- return false;
+ if(cmdl->opd != NULL) {
+ for(i = 0; i < cmdl->opd->opdc; i++) {
+ FREE(cmdl->opd->opdv[i]);
+ }
}
}
+ FREE(cmdl->opd);
+ FREE(cmdl->cmd);
}
}
- return true;
+ FREE(cmdl);
+ return status;
}
/**
}
/**
@@
-616,6
+626,7
@@
void addcerrlist_assemble()
{
addcerrlist_tok();
addcerrlist_word();
{
addcerrlist_tok();
addcerrlist_word();
+ addcerrlist_label();
addcerrlist(ARRAYSIZE(cerr_assemble), cerr_assemble);
}
addcerrlist(ARRAYSIZE(cerr_assemble), cerr_assemble);
}
@@
-627,20
+638,14
@@
bool assemble(const char *file, PASS pass)
{
int lineno = 0;
bool status = true;
{
int lineno = 0;
bool status = true;
- CMDLINE *cmdl;
- char *line;
+ char *line = malloc_chk(LINESIZE + 1, "line");
FILE *fp;
if((fp = fopen(file, "r")) == NULL) {
perror(file);
return false;
}
FILE *fp;
if((fp = fopen(file, "r")) == NULL) {
perror(file);
return false;
}
- for(; ;) {
- cmdl = malloc_chk(sizeof(CMDLINE), "cmdl");
- line = malloc_chk(LINESIZE + 1, "line");
- if((line = fgets(line, LINESIZE, fp)) == NULL) {
- break;
- }
+ while(fgets(line, LINESIZE, fp)) {
lineno++;
if((pass == FIRST && asmode.src == true) ||
(pass == SECOND && asmode.asdetail == true))
lineno++;
if((pass == FIRST && asmode.src == true) ||
(pass == SECOND && asmode.asdetail == true))
@@
-650,17
+655,13
@@
bool assemble(const char *file, PASS pass)
if(assembleline(line, pass) == false) {
break;
}
if(assembleline(line, pass) == false) {
break;
}
- if(cerr->num > 0) {
- break;
- }
- free_chk(line, "line");
- free_chk(cmdl, "cmdl");
}
if(cerr->num > 0) {
fprintf(stderr, "Assemble error - %d: %s\n", cerr->num, cerr->msg);
printline(stderr, file, lineno, line);
status = false;
}
}
if(cerr->num > 0) {
fprintf(stderr, "Assemble error - %d: %s\n", cerr->num, cerr->msg);
printline(stderr, file, lineno, line);
status = false;
}
+ FREE(line);
fclose(fp);
return status;
}
fclose(fp);
return status;
}