projects
/
YACASL2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Ubuntu 10.04 PPC版で判明した問題を修正
[YACASL2.git]
/
src
/
comet2.c
diff --git
a/src/comet2.c
b/src/comet2.c
index
c6cf486
..
2f7696a
100644
(file)
--- a/
src/comet2.c
+++ b/
src/comet2.c
@@
-1,21
+1,15
@@
-#include
"casl2.h"
-#include
"exec.h"
+#include
<stdio.h>
+#include
<stdlib.h>
#define _GNU_SOURCE
#include <getopt.h>
#define _GNU_SOURCE
#include <getopt.h>
-/* 指定されたファイルからCOMET II仮想メモリ(アセンブル結果)を読込 */
-bool inassemble(char *file) {
- FILE *fp;
- reset();
- if((fp = fopen(file, "r")) == NULL) {
- perror(file);
- return false;
- }
- fread(memory, sizeof(WORD), memsize, fp);
- fclose(fp);
- return true;
-}
+#include "exec.h"
+#include "cmem.h"
+#include "cerr.h"
+/**
+ * comet2コマンドのオプション
+ */
static struct option longopts[] = {
{"trace", no_argument, NULL, 't'},
{"tracearithmetic", no_argument, NULL, 't'},
static struct option longopts[] = {
{"trace", no_argument, NULL, 't'},
{"tracearithmetic", no_argument, NULL, 't'},
@@
-27,22
+21,38
@@
static struct option longopts[] = {
{0, 0, 0, 0}
};
{0, 0, 0, 0}
};
+/**
+ * comet2コマンドのエラー
+ */
+static CERR cerr_comet2[] = {
+ { 208, "object file is not specified" },
+};
+
+/**
+ * comet2コマンドのメイン
+ */
int main(int argc, char *argv[])
{
int main(int argc, char *argv[])
{
- int opt;
- const char *usage = "Usage: %s [-tTdh] [-M <memorysize>] [-C <clocks>] FILE\n";
+ int memsize = DEFAULT_MEMSIZE, clocks = DEFAULT_CLOCKS;
+ int opt, status = 0;
+ const char *usage = "Usage: %s [-tTdh] [-M <MEMORYSIZE>] [-C <CLOCKS>] FILE\n";
+
+ cerr_init();
+ addcerrlist(ARRAYSIZE(cerr_comet2), cerr_comet2);
+ addcerrlist_exec();
+ /* オプションの処理 */
while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) {
switch(opt) {
case 't':
while((opt = getopt_long(argc, argv, "tTdM:C:h", longopts, NULL)) != -1) {
switch(opt) {
case 't':
-
tracemod
e = true;
+
execmode.trac
e = true;
break;
case 'T':
break;
case 'T':
-
tracemod
e = true;
-
logicalmode
= true;
+
execmode.trac
e = true;
+
execmode.logical
= true;
break;
case 'd':
break;
case 'd':
-
dumpmode
= true;
+
execmode.dump
= true;
break;
case 'M':
memsize = atoi(optarg);
break;
case 'M':
memsize = atoi(optarg);
@@
-58,12
+68,25
@@
int main(int argc, char *argv[])
exit(-1);
}
}
exit(-1);
}
}
- if(inassemble(argv[optind]) == true) {
- exec(); /* プログラム実行 */
- }
- if(cerrno > 0) {
- freecerr();
+ if(argv[optind] == NULL) {
+ setcerr(208, NULL); /* object file is not specified */
+ fprintf(stderr, "comet2 error - %d: %s\n", cerr->num, cerr->msg);
exit(-1);
}
exit(-1);
}
- return 0;
+ /* COMET II仮想マシンのリセット */
+ reset(memsize, clocks);
+ prog->start = 0;
+ if(loadassemble(argv[optind]) == true) {
+ create_code_type(); /* タイプがキーの命令ハッシュ表を作成 */
+ exec(); /* プログラム実行 */
+ free_code_type(); /* タイプがキーの命令ハッシュ表を解放 */
+ }
+ /* COMET II仮想マシンのシャットダウン */
+ shutdown();
+ if(cerr->num > 0) {
+ status = -1;
+ }
+ /* エラーの解放 */
+ freecerr();
+ return status;
}
}