アセンブルのソースを整理
[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 struct {
52     char *prog;                 /**<プログラム  */
53     char *label;                /**<ラベル */
54     WORD adr;                   /**<アドレス */
55 } LABELARRAY;
56
57 /**
58  * ラベル表
59  */
60 typedef struct _LABELTAB {
61     struct _LABELTAB *next;     /**<リスト次項目へのポインタ */
62     char *prog;                 /**<プログラム名  */
63     char *label;                /**<ラベル名 */
64     WORD adr;                   /**<アドレス */
65 } LABELTAB;
66
67 enum {
68     /**
69      * ラベル表のサイズ
70      */
71     LABELTABSIZE = 251,
72 };
73
74 /**
75  * アセンブラが、1回目か2回目か
76  */
77 typedef enum {
78     FIRST = 0,
79     SECOND = 1,
80 } PASS;
81
82 /**
83  * ラベルのエラーをエラーリストに追加
84  */
85 void addcerrlist_label();
86
87 /**
88  * プログラム名とラベルに対応するアドレスをラベル表から検索する
89  */
90 WORD getlabel(const char *prog, const char *label);
91
92 /**
93  * プログラム名、ラベル、アドレスをラベル表に追加する
94  */
95 bool addlabel(const char *prog, const char *label, WORD word);
96
97 /**
98  * ラベル表を表示する
99  */
100 void printlabel();
101
102 /**
103  * ラベル表を解放する
104  */
105 void freelabel();
106
107 /**
108  * オペランド
109  */
110 typedef struct {
111     int opdc;                   /**<オペランド数 */
112     char *opdv[OPDSIZE];        /**<オペランド配列 */
113 } OPD;
114
115 /**
116  * 命令行
117  */
118 typedef struct {
119     char *label;                /**<ラベル */
120     char *cmd;                  /**<コマンド */
121     OPD *opd;                   /**<オペランド */
122 } CMDLINE;
123
124 /**
125  * トークン取得のエラーを追加
126  */
127 void addcerrlist_tok();
128
129 /**
130  * 空白またはタブで区切られた1行から、トークンを取得する
131  */
132 CMDLINE *linetok(const char *line);
133
134 /**
135  * アセンブルエラーをエラーリストに追加
136  */
137 void addcerrlist_assemble();
138
139 /**
140  * 指定された名前のファイルをアセンブル
141  * 1回目ではラベルを登録し、2回目ではラベルからアドレスを読み込む
142  * アセンブル完了時はtrue、エラー発生時はfalseを返す
143  */
144 bool assemblefile(const char *file, PASS pass);
145
146 /**
147  * 引数で指定したファイルにアセンブル結果を書込
148  */
149 void outassemble(const char *file);
150
151 #endif            /* YACASL2_ASSEMBLE_INCLUDEDの終端 */