データ構造の名前を変更
[YACASL2.git] / include / assemble.h
1 #ifndef YACASL2_ASSEMBLE_INCLUDED
2 #define YACASL2_ASSEMBLE_INCLUDED
3
4 #include <stdbool.h>
5 #include "struct.h"
6 #include "word.h"
7
8 /**
9  * CASL IIの仕様
10  */
11 enum {
12     LABELSIZE = 8,         /**<ラベルの最大文字数 */
13     OPDSIZE = 40,          /**<オペラントの最大数。CASL IIシミュレータの制限 */
14 };
15
16 /**
17  * YACASL2の制限
18  */
19 enum {
20     LINESIZE = 1024,       /**<行の最大文字数 */
21     TOKENSIZE = 256,       /**<トークンの最大文字数 */
22 };
23
24 /**
25  * アセンブルモード
26  */
27 typedef struct {
28     bool src;             /**<ソースを表示する場合はtrue */
29     bool label;           /**<ラベル表を表示する場合はtrue */
30     bool onlylabel;       /**<ラベル表を表示して終了する場合はtrue */
31     bool asdetail;        /**<アセンブラ詳細結果を表示する場合はtrue */
32     bool onlyassemble;    /**<アセンブルだけを行う場合はtrue */
33 } ASMODE;
34
35 extern ASMODE asmode;
36
37 /**
38  * アセンブル時の、現在およびリテラルのアドレスと入口名
39  */
40 typedef struct {
41     WORD ptr;     /**<現在のアドレス */
42     WORD lptr;    /**<リテラル(=付きの値)のアドレス */
43     char *prog;   /**<他のプログラムで参照する入口名 */
44 } ASPTR;
45
46 extern ASPTR *asptr;
47
48 /**
49   * アセンブラ命令を表す番号
50   */
51 typedef enum {
52     START = 01,
53     END = 02,
54     DS = 03,
55     DC = 04,
56 } ASCMDID;
57
58 /**
59   * アセンブラ命令を表す配列
60   */
61 typedef struct {
62     ASCMDID cmdid;              /**<アセンブル命令のID */
63     int opdc_min;               /**<最小オペランド数 */
64     int opdc_max;               /**<最大オペランド数 */
65     char *cmd;                  /**<コマンド名 */
66 } ASCMD;
67
68 /**
69  * マクロ命令を表す番号
70  */
71 typedef enum {
72     IN = 011,
73     OUT = 012,
74     RPUSH = 013,
75     RPOP = 014,
76 } MACROCMDID;
77
78 /**
79  * マクロ命令を表す配列
80  */
81 typedef struct {
82     MACROCMDID cmdid;              /**<マクロ命令のID */
83     int opdc_min;                  /**<最小オペランド数 */
84     int opdc_max;                  /**<最大オペランド数 */
85     char *cmd;                     /**<コマンド名 */
86 } MACROCMD;
87
88 /**
89  * ラベル配列
90  */
91 typedef struct {
92     char *prog;                 /**<プログラム  */
93     char *label;                /**<ラベル */
94     WORD adr;                   /**<アドレス */
95 } LABELARRAY;
96
97 /**
98  * ラベル表
99  */
100 typedef struct _LABELTAB {
101     struct _LABELTAB *next;     /**<リスト次項目へのポインタ */
102     char *prog;                 /**<プログラム名  */
103     char *label;                /**<ラベル名 */
104     WORD adr;                   /**<アドレス */
105 } LABELTAB;
106
107 enum {
108     /**
109      * ラベル表のサイズ
110      */
111     LABELTABSIZE = 251,
112 };
113
114 /**
115  * アセンブラが、1回目か2回目か
116  */
117 typedef enum {
118     FIRST = 0,
119     SECOND = 1,
120 } PASS;
121
122 /**
123  * プログラム名とラベルに対応するアドレスをラベル表から検索する
124  */
125 WORD getlabel(const char *prog, const char *label);
126
127 /**
128  * プログラム名、ラベル、アドレスをラベル表に追加する
129  */
130 bool addlabel(const char *prog, const char *label, WORD word);
131
132 /**
133  * ラベル表を表示する
134  */
135 void printlabel();
136
137 /**
138  * ラベル表を解放する
139  */
140 void freelabel();
141
142 /**
143  * オペランド
144  */
145 typedef struct {
146     int opdc;                   /**<オペランド数 */
147     char *opdv[OPDSIZE];        /**<オペランド配列 */
148 } OPD;
149
150 /**
151  * 命令行
152  */
153 typedef struct {
154     char *label;                /**<ラベル */
155     char *cmd;                  /**<コマンド */
156     OPD *opd;                   /**<オペランド */
157 } CMDLINE;
158
159 /**
160  * トークン取得のエラーを追加
161  */
162 void addcerrlist_tok();
163
164 /**
165  * 空白またはタブで区切られた1行から、トークンを取得する
166  */
167 CMDLINE *linetok(const char *line);
168
169 /**
170  * アセンブルエラーをエラーリストに追加
171  */
172 void addcerrlist_assemble();
173
174 /**
175  * 指定された名前のファイルをアセンブル
176  * 2回実行される
177  */
178 bool assemble(const char *file, PASS pass);
179
180 /**
181  * 引数で指定したファイルにアセンブル結果を書込
182  */
183 void outassemble(const char *file);
184
185 #endif            /* YACASL2_ASSEMBLE_INCLUDEDの終端 */