\doxysection{comet2.\+c}
\label{comet2_8c_source}\index{src/comet2.c@{src/comet2.c}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#include\ "{}package.h"{}}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#include\ "{}exec.h"{}}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include\ "{}load.h"{}}}
\DoxyCodeLine{00004\ }
\DoxyCodeLine{00008\ \textcolor{keyword}{static}\ \textcolor{keyword}{struct\ }option\ longopts[]\ =\ \{}
\DoxyCodeLine{00009\ \ \ \ \ \{\textcolor{stringliteral}{"{}trace"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'t'}\},}
\DoxyCodeLine{00010\ \ \ \ \ \{\textcolor{stringliteral}{"{}tracearithmetic"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'t'}\},}
\DoxyCodeLine{00011\ \ \ \ \ \{\textcolor{stringliteral}{"{}tracelogical"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'T'}\},}
\DoxyCodeLine{00012\ \ \ \ \ \{\textcolor{stringliteral}{"{}dump"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'d'}\},}
\DoxyCodeLine{00013\ \ \ \ \ \{\textcolor{stringliteral}{"{}monitor"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'m'}\},}
\DoxyCodeLine{00014\ \ \ \ \ \{\textcolor{stringliteral}{"{}memorysize"{}},\ required\_argument,\ NULL,\ \textcolor{charliteral}{'M'}\},}
\DoxyCodeLine{00015\ \ \ \ \ \{\textcolor{stringliteral}{"{}clocks"{}},\ required\_argument,\ NULL,\ \textcolor{charliteral}{'C'}\},}
\DoxyCodeLine{00016\ \ \ \ \ \{\textcolor{stringliteral}{"{}version"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'v'}\ \},}
\DoxyCodeLine{00017\ \ \ \ \ \{\textcolor{stringliteral}{"{}help"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'h'}\},}
\DoxyCodeLine{00018\ \ \ \ \ \{0,\ 0,\ 0,\ 0\},}
\DoxyCodeLine{00019\ \};}
\DoxyCodeLine{00020\ }
\DoxyCodeLine{00021\ }
\DoxyCodeLine{00030\ \textcolor{keywordtype}{int}\ main(\textcolor{keywordtype}{int}\ argc,\ \textcolor{keywordtype}{char}\ *argv[])}
\DoxyCodeLine{00031\ \{}
\DoxyCodeLine{00032\ \ \ \ \ \textcolor{keywordtype}{int}\ memsize\ =\ DEFAULT\_MEMSIZE;}
\DoxyCodeLine{00033\ \ \ \ \ \textcolor{keywordtype}{int}\ clocks\ =\ DEFAULT\_CLOCKS;}
\DoxyCodeLine{00034\ \ \ \ \ \textcolor{keywordtype}{int}\ opt\ =\ 0;}
\DoxyCodeLine{00035\ \ \ \ \ \textcolor{keywordtype}{int}\ stat\ =\ 0;}
\DoxyCodeLine{00036\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *version\ =\ PACKAGE\_VERSION;}
\DoxyCodeLine{00037\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *cmdversion\ =\ \textcolor{stringliteral}{"{}comet2\ of\ YACASL2\ version\ \%s\(\backslash\)n"{}};}
\DoxyCodeLine{00038\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *usage\ =\ \textcolor{stringliteral}{"{}Usage:\ \%s\ [-\/tTdmvh]\ [-\/M\ <MEMORYSIZE>]\ [-\/C\ <CLOCKS>]\ FILE\(\backslash\)n"{}};}
\DoxyCodeLine{00039\ }
\DoxyCodeLine{00040\ \ \ \ \ \textcolor{comment}{/*\ エラーの定義\ */}}
\DoxyCodeLine{00041\ \ \ \ \ cerr\_init();}
\DoxyCodeLine{00042\ \ \ \ \ addcerrlist\_load();}
\DoxyCodeLine{00043\ \ \ \ \ addcerrlist\_exec();}
\DoxyCodeLine{00044\ }
\DoxyCodeLine{00045\ \ \ \ \ \textcolor{comment}{/*\ オプションの処理\ */}}
\DoxyCodeLine{00046\ \ \ \ \ \textcolor{keywordflow}{while}((opt\ =\ getopt\_long(argc,\ argv,\ \textcolor{stringliteral}{"{}tTdmM:C:vh"{}},\ longopts,\ NULL))\ !=\ -\/1)\ \{}
\DoxyCodeLine{00047\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{switch}(opt)\ \{}
\DoxyCodeLine{00048\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'t'}:}
\DoxyCodeLine{00049\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.trace\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00050\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00051\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'T'}:}
\DoxyCodeLine{00052\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.trace\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00053\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.logical\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00054\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00055\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'d'}:}
\DoxyCodeLine{00056\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.dump\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00057\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00058\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'m'}:}
\DoxyCodeLine{00059\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.monitor\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00060\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00061\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'M'}:}
\DoxyCodeLine{00062\ \ \ \ \ \ \ \ \ \ \ \ \ memsize\ =\ atoi(optarg);}
\DoxyCodeLine{00063\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00064\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'C'}:}
\DoxyCodeLine{00065\ \ \ \ \ \ \ \ \ \ \ \ \ clocks\ =\ atoi(optarg);}
\DoxyCodeLine{00066\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00067\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'v'}:}
\DoxyCodeLine{00068\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stdout,\ cmdversion,\ version);}
\DoxyCodeLine{00069\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ comet2fin;}
\DoxyCodeLine{00070\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'h'}:}
\DoxyCodeLine{00071\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stdout,\ usage,\ argv[0]);}
\DoxyCodeLine{00072\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ comet2fin;}
\DoxyCodeLine{00073\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'?'}:}
\DoxyCodeLine{00074\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,\ usage,\ argv[0]);}
\DoxyCodeLine{00075\ \ \ \ \ \ \ \ \ \ \ \ \ setcerr(212,\ \textcolor{stringliteral}{"{}"{}});\ \ \ \ \textcolor{comment}{/*\ invalid\ option\ */}}
\DoxyCodeLine{00076\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ comet2fin;}
\DoxyCodeLine{00077\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00078\ \ \ \ \ \}}
\DoxyCodeLine{00079\ \ \ \ \ \textcolor{keywordflow}{if}(argv[optind]\ ==\ NULL)\ \{}
\DoxyCodeLine{00080\ \ \ \ \ \ \ \ \ setcerr(211,\ \textcolor{stringliteral}{"{}"{}});\ \ \ \ \textcolor{comment}{/*\ object\ file\ not\ specified\ */}}
\DoxyCodeLine{00081\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}comet2\ error\ -\/\ \%d:\ \%s\(\backslash\)n"{}},\ cerr-\/>num,\ cerr-\/>msg);}
\DoxyCodeLine{00082\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ comet2fin;}
\DoxyCodeLine{00083\ \ \ \ \ \}}
\DoxyCodeLine{00084\ \ \ \ \ reset(memsize,\ clocks);\ \ \ \ \ \textcolor{comment}{/*\ COMET\ II仮想マシンのリセット\ */}}
\DoxyCodeLine{00085\ \ \ \ \ execptr-\/>start\ =\ 0;}
\DoxyCodeLine{00086\ \ \ \ \ execptr-\/>end\ =\ loadassemble(argv[optind],\ execptr-\/>start);}
\DoxyCodeLine{00087\ \ \ \ \ \textcolor{keywordflow}{if}(execptr-\/>end\ >\ 0\ \&\&\ cerr-\/>num\ ==\ 0)\ \{}
\DoxyCodeLine{00088\ \ \ \ \ \ \ \ \ exec();\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ プログラム実行\ */}}
\DoxyCodeLine{00089\ \ \ \ \ \}}
\DoxyCodeLine{00090\ \ \ \ \ shutdown();\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ COMET\ II仮想マシンのシャットダウン\ */}}
\DoxyCodeLine{00091\ comet2fin:}
\DoxyCodeLine{00092\ \ \ \ \ \textcolor{keywordflow}{if}(cerr-\/>num\ >\ 0)\ \{}
\DoxyCodeLine{00093\ \ \ \ \ \ \ \ \ stat\ =\ 1;}
\DoxyCodeLine{00094\ \ \ \ \ \}}
\DoxyCodeLine{00095\ \ \ \ \ freecerr();\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ エラーの解放\ */}}
\DoxyCodeLine{00096\ \ \ \ \ \textcolor{keywordflow}{return}\ stat;}
\DoxyCodeLine{00097\ \}}
\end{DoxyCode}