root/doc_inner/doxygen/latex/casl2_8c_source.tex

/* [<][>][^][v][top][bottom][index][help] */
\doxysection{casl2.\+c}
\label{casl2_8c_source}\index{src/casl2.c@{src/casl2.c}}
\textbf{ Go to the documentation of this file.}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#include\ "{}package.h"{}}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#include\ "{}assemble.h"{}}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include\ "{}exec.h"{}}}
\DoxyCodeLine{00004\ }
\DoxyCodeLine{00009\ \textcolor{keywordtype}{void}\ addcerrlist\_casl2();}
\DoxyCodeLine{00010\ }
\DoxyCodeLine{00018\ \textcolor{keywordtype}{char}\ *objfile\_name(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *str);}
\DoxyCodeLine{00019\ }
\DoxyCodeLine{00023\ \textcolor{keyword}{static}\ \textcolor{keyword}{struct\ }option\ longopts[]\ =\ \{}
\DoxyCodeLine{00024\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}source"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'s'}\ \},}
\DoxyCodeLine{00025\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}label"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'l'}\ \},}
\DoxyCodeLine{00026\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}labelonly"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'L'}\ \},}
\DoxyCodeLine{00027\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}assembledetail"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'a'}\ \},}
\DoxyCodeLine{00028\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}assembledetailonly"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'A'}\ \},}
\DoxyCodeLine{00029\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}assembleout"{}},\ optional\_argument,\ NULL,\ \textcolor{charliteral}{'o'}\ \},}
\DoxyCodeLine{00030\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}assembleoutonly"{}},\ optional\_argument,\ NULL,\ \textcolor{charliteral}{'O'}\ \},}
\DoxyCodeLine{00031\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}trace"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'t'}\ \},}
\DoxyCodeLine{00032\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}tracearithmetic"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'t'}\ \},}
\DoxyCodeLine{00033\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}tracelogical"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'T'}\ \},}
\DoxyCodeLine{00034\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}dump"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'d'}\ \},}
\DoxyCodeLine{00035\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}monitor"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'m'}\ \},}
\DoxyCodeLine{00036\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}memorysize"{}},\ required\_argument,\ NULL,\ \textcolor{charliteral}{'M'}\ \},}
\DoxyCodeLine{00037\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}clocks"{}},\ required\_argument,\ NULL,\ \textcolor{charliteral}{'C'}\ \},}
\DoxyCodeLine{00038\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}version"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'v'}\ \},}
\DoxyCodeLine{00039\ \ \ \ \ \{\ \textcolor{stringliteral}{"{}help"{}},\ no\_argument,\ NULL,\ \textcolor{charliteral}{'h'}\ \},}
\DoxyCodeLine{00040\ \ \ \ \ \{\ 0,\ 0,\ 0,\ 0\ \},}
\DoxyCodeLine{00041\ \};}
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00046\ CERR\ cerr\_casl2[]\ =\ \{}
\DoxyCodeLine{00047\ \ \ \ \ \{\ 126,\ \textcolor{stringliteral}{"{}no\ source\ file"{}}\ \},}
\DoxyCodeLine{00048\ \ \ \ \ \{\ 127,\ \textcolor{stringliteral}{"{}invalid\ option"{}}\ \},}
\DoxyCodeLine{00049\ \};}
\DoxyCodeLine{00050\ }
\DoxyCodeLine{00051\ \textcolor{keywordtype}{void}\ addcerrlist\_casl2()}
\DoxyCodeLine{00052\ \{}
\DoxyCodeLine{00053\ \ \ \ \ addcerrlist(ARRAYSIZE(cerr\_casl2),\ cerr\_casl2);}
\DoxyCodeLine{00054\ \}}
\DoxyCodeLine{00055\ }
\DoxyCodeLine{00056\ \textcolor{keywordtype}{char}\ *objfile\_name(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *name)}
\DoxyCodeLine{00057\ \{}
\DoxyCodeLine{00058\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *default\_name\ =\ \textcolor{stringliteral}{"{}a.o"{}};}
\DoxyCodeLine{00059\ \ \ \ \ \textcolor{keywordflow}{return}\ strdup\_chk(}
\DoxyCodeLine{00060\ \ \ \ \ \ \ \ \ (name\ ==\ NULL\ ||\ !name[0])\ ?\ default\_name\ :\ name,}
\DoxyCodeLine{00061\ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}objfile\_name"{}}}
\DoxyCodeLine{00062\ \ \ \ \ \ \ \ \ );}
\DoxyCodeLine{00063\ \}}
\DoxyCodeLine{00064\ }
\DoxyCodeLine{00073\ \textcolor{keywordtype}{int}\ main(\textcolor{keywordtype}{int}\ argc,\ \textcolor{keywordtype}{char}\ *argv[])}
\DoxyCodeLine{00074\ \{}
\DoxyCodeLine{00075\ \ \ \ \ \textcolor{keywordtype}{int}\ memsize\ =\ DEFAULT\_MEMSIZE;}
\DoxyCodeLine{00076\ \ \ \ \ \textcolor{keywordtype}{int}\ clocks\ =\ DEFAULT\_CLOCKS;}
\DoxyCodeLine{00077\ \ \ \ \ \textcolor{keywordtype}{int}\ opt\ =\ 0;}
\DoxyCodeLine{00078\ \ \ \ \ \textcolor{keywordtype}{int}\ stat\ =\ 0;}
\DoxyCodeLine{00079\ \ \ \ \ \textcolor{keywordtype}{int}\ asfilecnt\ =\ 0;}
\DoxyCodeLine{00080\ \ \ \ \ \textcolor{keywordtype}{char}\ **asfile\ =\ NULL;}
\DoxyCodeLine{00081\ \ \ \ \ \textcolor{keywordtype}{char}\ *objfile\ =\ NULL;}
\DoxyCodeLine{00082\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *version\ =\ PACKAGE\_VERSION;}
\DoxyCodeLine{00083\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *cmdversion\ =\ \textcolor{stringliteral}{"{}casl2\ of\ YACASL2\ version\ \%s\(\backslash\)n"{}};}
\DoxyCodeLine{00084\ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *usage\ =}
\DoxyCodeLine{00085\ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}Usage:\ \%s\ [-\/slLaAtTdmvh]\ [-\/oO[<OBJECTFILE>]]\ [-\/M\ <MEMORYSIZE>]\ [-\/C\ <CLOCKS>]\ FILE1[\ FILE2\ \ ...]\(\backslash\)n"{}};}
\DoxyCodeLine{00086\ }
\DoxyCodeLine{00087\ \ \ \ \ \textcolor{comment}{/*\ エラーの定義\ */}}
\DoxyCodeLine{00088\ \ \ \ \ cerr\_init();}
\DoxyCodeLine{00089\ \ \ \ \ addcerrlist\_casl2();}
\DoxyCodeLine{00090\ \ \ \ \ addcerrlist\_assemble();}
\DoxyCodeLine{00091\ \ \ \ \ addcerrlist\_exec();}
\DoxyCodeLine{00092\ }
\DoxyCodeLine{00093\ \ \ \ \ \textcolor{comment}{/*\ オプションの処理\ */}}
\DoxyCodeLine{00094\ \ \ \ \ \textcolor{keywordflow}{while}((opt\ =\ getopt\_long(argc,\ argv,\ \textcolor{stringliteral}{"{}tTdslLmao::O::AM:C:vh"{}},\ longopts,\ NULL))\ !=\ -\/1)\ \{}
\DoxyCodeLine{00095\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{switch}(opt)\ \{}
\DoxyCodeLine{00096\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'s'}:}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \ \ \ \ \ \ asmode.src\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00098\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00099\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'l'}:}
\DoxyCodeLine{00100\ \ \ \ \ \ \ \ \ \ \ \ \ asmode.label\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00101\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00102\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'L'}:}
\DoxyCodeLine{00103\ \ \ \ \ \ \ \ \ \ \ \ \ asmode.label\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00104\ \ \ \ \ \ \ \ \ \ \ \ \ asmode.onlylabel\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00105\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00106\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'a'}:}
\DoxyCodeLine{00107\ \ \ \ \ \ \ \ \ \ \ \ \ asmode.asdetail\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00108\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00109\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'A'}:}
\DoxyCodeLine{00110\ \ \ \ \ \ \ \ \ \ \ \ \ asmode.asdetail\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00111\ \ \ \ \ \ \ \ \ \ \ \ \ asmode.onlyassemble\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00112\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00113\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'o'}:}
\DoxyCodeLine{00114\ \ \ \ \ \ \ \ \ \ \ \ \ objfile\ =\ objfile\_name(optarg);}
\DoxyCodeLine{00115\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00116\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'O'}:}
\DoxyCodeLine{00117\ \ \ \ \ \ \ \ \ \ \ \ \ asmode.onlyassemble\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00118\ \ \ \ \ \ \ \ \ \ \ \ \ objfile\ =\ objfile\_name(optarg);}
\DoxyCodeLine{00119\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00120\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'t'}:}
\DoxyCodeLine{00121\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.trace\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00122\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00123\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'T'}:}
\DoxyCodeLine{00124\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.trace\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00125\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.logical\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00126\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00127\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'d'}:}
\DoxyCodeLine{00128\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.dump\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00129\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'m'}:}
\DoxyCodeLine{00131\ \ \ \ \ \ \ \ \ \ \ \ \ execmode.step\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00132\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00133\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'M'}:}
\DoxyCodeLine{00134\ \ \ \ \ \ \ \ \ \ \ \ \ memsize\ =\ atoi(optarg);}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00136\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'C'}:}
\DoxyCodeLine{00137\ \ \ \ \ \ \ \ \ \ \ \ \ clocks\ =\ atoi(optarg);}
\DoxyCodeLine{00138\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{break};}
\DoxyCodeLine{00139\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'v'}:}
\DoxyCodeLine{00140\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stdout,\ cmdversion,\ version);}
\DoxyCodeLine{00141\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ casl2fin;}
\DoxyCodeLine{00142\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'h'}:}
\DoxyCodeLine{00143\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stdout,\ usage,\ argv[0]);}
\DoxyCodeLine{00144\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ casl2fin;}
\DoxyCodeLine{00145\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{case}\ \textcolor{charliteral}{'?'}:}
\DoxyCodeLine{00146\ \ \ \ \ \ \ \ \ \ \ \ \ fprintf(stderr,\ usage,\ argv[0]);}
\DoxyCodeLine{00147\ \ \ \ \ \ \ \ \ \ \ \ \ setcerr(212,\ \textcolor{stringliteral}{"{}"{}});\ \ \ \ \textcolor{comment}{/*\ invalid\ option\ */}}
\DoxyCodeLine{00148\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ casl2fin;}
\DoxyCodeLine{00149\ \ \ \ \ \ \ \ \ \}}
\DoxyCodeLine{00150\ \ \ \ \ \}}
\DoxyCodeLine{00151\ }
\DoxyCodeLine{00152\ \ \ \ \ \textcolor{comment}{/*\ ソースファイルが指定されていない場合は終了\ */}}
\DoxyCodeLine{00153\ \ \ \ \ \textcolor{keywordflow}{if}(argv[optind]\ ==\ NULL)\ \{}
\DoxyCodeLine{00154\ \ \ \ \ \ \ \ \ setcerr(126,\ \textcolor{stringliteral}{"{}"{}});\ \ \ \ \textcolor{comment}{/*\ no\ source\ file\ */}}
\DoxyCodeLine{00155\ \ \ \ \ \ \ \ \ fprintf(stderr,\ \textcolor{stringliteral}{"{}casl2\ error\ -\/\ \%d:\ \%s\(\backslash\)n"{}},\ cerr-\/>num,\ cerr-\/>msg);}
\DoxyCodeLine{00156\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ casl2fin;}
\DoxyCodeLine{00157\ \ \ \ \ \}}
\DoxyCodeLine{00158\ \ \ \ \ create\_cmdtable(HASH\_CMDTYPE);\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ 命令の名前とタイプがキーのハッシュ表を作成\ */}}
\DoxyCodeLine{00159\ \ \ \ \ reset(memsize,\ clocks);\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ 仮想マシンCOMET\ IIのリセット\ */}}
\DoxyCodeLine{00160\ \ \ \ \ asfilecnt\ =\ argc\ -\/\ optind;}
\DoxyCodeLine{00161\ \ \ \ \ asfile\ =\ calloc\_chk(asfilecnt,\ \textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}\ *),\ \textcolor{stringliteral}{"{}asfile"{}});}
\DoxyCodeLine{00162\ \ \ \ \ \textcolor{keywordflow}{for}(\textcolor{keywordtype}{int}\ i\ =\ 0;\ i\ <\ asfilecnt;\ i++)\ \{\ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ 引数からファイル名配列を取得\ */}}
\DoxyCodeLine{00163\ \ \ \ \ \ \ \ \ asfile[i]\ =\ argv[optind\ +\ i];}
\DoxyCodeLine{00164\ \ \ \ \ \}}
\DoxyCodeLine{00165\ \ \ \ \ \textcolor{comment}{/*\ アセンブル\ */}}
\DoxyCodeLine{00166\ \ \ \ \ \textcolor{keywordflow}{if}(assemble(asfilecnt,\ asfile,\ 0)\ ==\ \textcolor{keyword}{false}\ ||\ asmode.onlylabel\ ==\ \textcolor{keyword}{true})\ \{}
\DoxyCodeLine{00167\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{goto}\ shutdown;}
\DoxyCodeLine{00168\ \ \ \ \ \}}
\DoxyCodeLine{00169\ \ \ \ \ \textcolor{comment}{/*\ オブジェクトファイル名が指定されている場合は、アセンブル結果をオブジェクトファイルに出力\ */}}
\DoxyCodeLine{00170\ \ \ \ \ \textcolor{keywordflow}{if}(objfile\ !=\ NULL)\ \{}
\DoxyCodeLine{00171\ \ \ \ \ \ \ \ \ outassemble(objfile);}
\DoxyCodeLine{00172\ \ \ \ \ \}}
\DoxyCodeLine{00173\ \ \ \ \ \textcolor{comment}{/*\ onlyassembleモード以外の場合、仮想マシンCOMET\ IIを実行\ */}}
\DoxyCodeLine{00174\ \ \ \ \ \textcolor{keywordflow}{if}(asmode.onlyassemble\ ==\ \textcolor{keyword}{false})\ \{}
\DoxyCodeLine{00175\ \ \ \ \ \ \ \ \ exec();\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ 仮想マシンCOMET\ IIの実行\ */}}
\DoxyCodeLine{00176\ \ \ \ \ \}}
\DoxyCodeLine{00177\ shutdown:}
\DoxyCodeLine{00178\ \ \ \ \ shutdown();\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ 仮想マシンCOMET\ IIのシャットダウン\ */}}
\DoxyCodeLine{00179\ casl2fin:}
\DoxyCodeLine{00180\ \ \ \ \ FREE(objfile);}
\DoxyCodeLine{00181\ \ \ \ \ FREE(asfile);}
\DoxyCodeLine{00182\ \ \ \ \ free\_cmdtable(HASH\_CMDTYPE);}
\DoxyCodeLine{00183\ \ \ \ \ \textcolor{keywordflow}{if}(cerr-\/>num\ >\ 0)\ \{}
\DoxyCodeLine{00184\ \ \ \ \ \ \ \ \ stat\ =\ 1;}
\DoxyCodeLine{00185\ \ \ \ \ \}}
\DoxyCodeLine{00186\ \ \ \ \ freecerr();\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{/*\ エラーの解放\ */}}
\DoxyCodeLine{00187\ \ \ \ \ \textcolor{keywordflow}{return}\ stat;}
\DoxyCodeLine{00188\ \}}

\end{DoxyCode}

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