root/doc_inner/doxygen/latex/comet2monitor_8c_source.tex

/* [<][>][^][v][top][bottom][index][help] */
\doxysection{comet2monitor.\+c}
\label{comet2monitor_8c_source}\index{src/comet2monitor.c@{src/comet2monitor.c}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#define\ \_GNU\_SOURCE}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#include\ "{}package.h"{}}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include\ "{}exec.h"{}}}
\DoxyCodeLine{00004\ \textcolor{preprocessor}{\#include\ "{}load.h"{}}}
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include\ "{}monitor.h"{}}}
\DoxyCodeLine{00006\ }
\DoxyCodeLine{00010\ \textcolor{keyword}{static}\ \textcolor{keyword}{struct\ }option\ longopts[]\ =\ \{}
\DoxyCodeLine{00011\ \ \ \ \ \{\textcolor{stringliteral}{"{}trace"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'t'}\},}
\DoxyCodeLine{00012\ \ \ \ \ \{\textcolor{stringliteral}{"{}tracearithmetic"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'t'}\},}
\DoxyCodeLine{00013\ \ \ \ \ \{\textcolor{stringliteral}{"{}tracelogical"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'T'}\},}
\DoxyCodeLine{00014\ \ \ \ \ \{\textcolor{stringliteral}{"{}dump"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'d'}\},}
\DoxyCodeLine{00015\ \ \ \ \ \{\textcolor{stringliteral}{"{}memorysize"{}},\ required\_argument,\ NULL,\ \textcolor{charliteral}{'M'}\},}
\DoxyCodeLine{00016\ \ \ \ \ \{\textcolor{stringliteral}{"{}clocks"{}},\ required\_argument,\ NULL,\ \textcolor{charliteral}{'C'}\},}
\DoxyCodeLine{00017\ \ \ \ \ \{\textcolor{stringliteral}{"{}version"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'v'}\ \},}
\DoxyCodeLine{00018\ \ \ \ \ \{\textcolor{stringliteral}{"{}help"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'h'}\},}
\DoxyCodeLine{00019\ \ \ \ \ \{0,\ 0,\ 0,\ 0\},}
\DoxyCodeLine{00020\ \};}
\DoxyCodeLine{00021\ }
\DoxyCodeLine{00025\ CERR\ cerr\_comet2monitor[]\ =\ \{}
\DoxyCodeLine{00026\ \ \ \ \ \{\ 401,\ \textcolor{stringliteral}{"{}invalid\ option"{}}\ \},}
\DoxyCodeLine{00027\ \};}
\DoxyCodeLine{00028\ }
\DoxyCodeLine{00029\ \textcolor{keywordtype}{void}\ addcerrlist\_comet2monitor()}
\DoxyCodeLine{00030\ \{}
\DoxyCodeLine{00031\ \ \ \ \ addcerrlist(ARRAYSIZE(cerr\_comet2monitor),\ cerr\_comet2monitor);}
\DoxyCodeLine{00032\ \}}
\DoxyCodeLine{00033\ }
\DoxyCodeLine{00042\ \textcolor{keywordtype}{int}\ main(\textcolor{keywordtype}{int}\ argc,\ \textcolor{keywordtype}{char}\ *argv[])}
\DoxyCodeLine{00043\ \{}
\DoxyCodeLine{00044\ \ \ \ \ \textcolor{keywordtype}{int}\ memsize\ =\ DEFAULT\_MEMSIZE;}
\DoxyCodeLine{00045\ \ \ \ \ \textcolor{keywordtype}{int}\ clocks\ =\ DEFAULT\_CLOCKS;}
\DoxyCodeLine{00046\ \ \ \ \ \textcolor{keywordtype}{int}\ opt\ =\ 0;}
\DoxyCodeLine{00047\ \ \ \ \ \textcolor{keywordtype}{int}\ stat\ =\ 0;}
\DoxyCodeLine{00048\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *version\ =\ PACKAGE\_VERSION;}
\DoxyCodeLine{00049\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *cmdversion\ =\ \textcolor{stringliteral}{"{}comet2monitor:\ COMET\ II\ machine\ code\ monitor\ of\ YACASL2\ version\ \%s\(\backslash\)n"{}};}
\DoxyCodeLine{00050\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *usage\ =\ \textcolor{stringliteral}{"{}Usage:\ \%s\ [-\/tTdvh]\ [-\/M\ <MEMORYSIZE>]\ [-\/C\ <CLOCKS>]\ FILE\(\backslash\)n"{}};}
\DoxyCodeLine{00051\ }
\DoxyCodeLine{00052\ \ \ \ \ \textcolor{comment}{/*\ エラーの定義\ */}}
\DoxyCodeLine{00053\ \ \ \ \ cerr\_init();}
\DoxyCodeLine{00054\ \ \ \ \ addcerrlist\_load();}
\DoxyCodeLine{00055\ \ \ \ \ addcerrlist\_exec();}
\DoxyCodeLine{00056\ \ \ \ \ addcerrlist\_comet2monitor();}
\DoxyCodeLine{00057\ }
\DoxyCodeLine{00058\ \ \ \ \ \textcolor{comment}{/*\ オプションの処理\ */}}
\DoxyCodeLine{00059\ \ \ \ \ \textcolor{keywordflow}{while}((opt\ =\ getopt\_long(argc,\ argv,\ \textcolor{stringliteral}{"{}tTdM:C:vh"{}},\ longopts,\ NULL))\ !=\ -\/1)\ \{}
\DoxyCodeLine{00060\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{switch}(opt)\ \{}
\DoxyCodeLine{00061\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'t'}:}
\DoxyCodeLine{00062\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.trace\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00063\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00064\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'T'}:}
\DoxyCodeLine{00065\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.trace\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00066\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.logical\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00067\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00068\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'d'}:}
\DoxyCodeLine{00069\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.dump\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00070\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00071\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'M'}:}
\DoxyCodeLine{00072\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}((memsize\ =\ memsize\_str2word(optarg))\ ==\ 0)\ \{}
\DoxyCodeLine{00073\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ comet2monitorfin;}
\DoxyCodeLine{00074\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00075\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00076\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'C'}:}
\DoxyCodeLine{00077\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}((clocks\ =\ clock\_str2clock(optarg))\ ==\ 0)\ \{}
\DoxyCodeLine{00078\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ comet2monitorfin;}
\DoxyCodeLine{00079\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00080\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00081\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'v'}:}
\DoxyCodeLine{00082\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stdout,\ cmdversion,\ version);}
\DoxyCodeLine{00083\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00084\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'h'}:}
\DoxyCodeLine{00085\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stdout,\ usage,\ argv[0]);}
\DoxyCodeLine{00086\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ 0;}
\DoxyCodeLine{00087\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'?'}:}
\DoxyCodeLine{00088\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,\ usage,\ argv[0]);}
\DoxyCodeLine{00089\ \ \ \ \ \ \ \ \ \ \ \ \ setcerr(212,\ \textcolor{stringliteral}{"{}"{}});\ \ \ \ \textcolor{comment}{/*\ invalid\ option\ */}}
\DoxyCodeLine{00090\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ comet2monitorfin;}
\DoxyCodeLine{00091\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00092\ \ \ \ \ \}}
\DoxyCodeLine{00093\ \ \ \ \ create\_cmdtable(HASH\_CMDTYPE);}
\DoxyCodeLine{00094\ \ \ \ \ comet2\_init(memsize,\ clocks);\ \ \ \ \ \textcolor{comment}{/*\ COMET\ II仮想マシンの初期化\ */}}
\DoxyCodeLine{00095\ \ \ \ \ execptr-\/>start\ =\ 0;}
\DoxyCodeLine{00096\ \ \ \ \ \textcolor{keywordflow}{if}(argv[optind]\ !=\ NULL)\ \{}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \ \ execptr-\/>end\ =\ loadassemble(argv[optind++],\ execptr-\/>start);}
\DoxyCodeLine{00098\ \ \ \ \ \}}
\DoxyCodeLine{00099\ \ \ \ \ \textcolor{comment}{/*\ 残りの引数(オプション以外の引数)があるかチェック\ */}}
\DoxyCodeLine{00100\ \ \ \ \ \textcolor{keywordflow}{if}\ (optind\ <\ argc)\ \{}
\DoxyCodeLine{00101\ \ \ \ \ \ \ \ \ warn\_ignore\_arg(argc\ -\/\ optind,\ argv\ +\ optind);}
\DoxyCodeLine{00102\ \ \ \ \ \}}
\DoxyCodeLine{00103\ \ \ \ \ execmode.monitor\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00104\ \ \ \ \ exec();\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ プログラム実行\ */}}
\DoxyCodeLine{00105\ \ \ \ \ comet2\_shutdown();}
\DoxyCodeLine{00106\ comet2monitorfin:}
\DoxyCodeLine{00107\ \ \ \ \ free\_cmdtable(HASH\_CMDTYPE);}
\DoxyCodeLine{00108\ \ \ \ \ \textcolor{keywordflow}{if}(cerr-\/>num\ >\ 0)\ \{}
\DoxyCodeLine{00109\ \ \ \ \ \ \ \ \ stat\ =\ 1;}
\DoxyCodeLine{00110\ \ \ \ \ \}}
\DoxyCodeLine{00111\ \ \ \ \ freecerr();\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ エラーの解放\ */}}
\DoxyCodeLine{00112\ \ \ \ \ \textcolor{keywordflow}{return}\ stat;}
\DoxyCodeLine{00113\ \}}

\end{DoxyCode}

/* [<][>][^][v][top][bottom][index][help] */