annotate src/lwasm.h @ 57:035b95a3690f

Added conditional assembly and macros
author lost
date Mon, 05 Jan 2009 00:01:21 +0000
parents 8e32696380f3
children b1d81800bc91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
1 /*
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
2 lwasm.h
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
3 Copyright © 2008 William Astle
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
4
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
5 This file is part of LWASM.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
6
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
8 terms of the GNU General Public License as published by the Free Software
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
10 version.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
11
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
15 more details.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
16
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
17 You should have received a copy of the GNU General Public License along with
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
19
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
20 Contains the main defs used by the assembler
34568fab6058 Fixed package to include all required files; also added copyright preamble to all source files
lost
parents: 0
diff changeset
21 */
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
22
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
23
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
24 #ifndef __lwasm_h_seen__
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
25 #define __lwasm_h_seen__
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
26
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
27 #include "expr.h"
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
28
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
29 #define OUTPUT_DECB 0 // DECB multirecord format
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
30 #define OUTPUT_RAW 1 // raw sequence of bytes
21
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
31 #define OUTPUT_OBJ 2 // proprietary object file format
46
b962cee20bf4 Ported output modules forward from old version
lost
parents: 44
diff changeset
32 #define OUTPUT_RAWREL 3 // raw bytes where ORG causes a SEEK in the file
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
33
57
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
34 // structure for tracking macros
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
35 typedef struct macrotab_s macrotab_t;
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
36 struct macrotab_s
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
37 {
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
38 char *name;
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
39 char **lines;
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
40 int numlines;
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
41 macrotab_t *next;
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
42 };
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
43
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
44 // structure for tracking errors
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
45 typedef struct lwasm_error_s lwasm_error_t;
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
46 struct lwasm_error_s
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
47 {
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
48 char *mess; // the actual error message
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
49 lwasm_error_t *next; // ptr to next error
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
50 };
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
51
21
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
52 // structure for keeping track of lines
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
53 typedef struct lwasm_line_s lwasm_line_t;
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
54 struct lwasm_line_s {
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
55 char *text; // the actual text of the line
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
56 int lineno; // line number within the file
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
57 char *filename; // file name reference
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
58 lwasm_line_t *next; // next line
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
59 lwasm_line_t *prev; // previous line
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
60 lwasm_error_t *err; // error messages
28
c0ff62e5ad39 Added register list mode handler
lost
parents: 27
diff changeset
61 int fsize; // forced size (0 = no forced size)
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
62 char *sym; // scratch area to record the presence of a symbol
42
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 38
diff changeset
63 unsigned char *bytes; // actual bytes emitted
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 38
diff changeset
64 int codelen; // number of bytes emitted
4bb7b723e5b7 Added pass2 code generation to lwasm_emit()
lost
parents: 38
diff changeset
65 int codesize; // the size of the code buffer
44
2330b88f9600 Added simple output listing
lost
parents: 42
diff changeset
66 int codeaddr; // address the code goes at
46
b962cee20bf4 Ported output modules forward from old version
lost
parents: 44
diff changeset
67 int nocodelen; // for "RMB" type instructions
49
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 46
diff changeset
68 int addrset; // set if this instruction sets the assembly address
21ae0fab469b Added needed infra for useful listing of EQU and ORG type statements
lost
parents: 46
diff changeset
69 int symaddr; // set if this instruction sets a symbol addr with EQU or the like
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
70 };
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
71
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
72 // for keeping track of symbols
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
73 typedef struct lwasm_symbol_ent_s lwasm_symbol_ent_t;
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
74 struct lwasm_symbol_ent_s
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
75 {
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
76 char *sym; // the symbol
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
77 int context; // the context number of the symbol (-1 for global)
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
78 int value; // the value of the symbol
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
79 lwasm_symbol_ent_t *next; // next symbol in the table
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
80 lwasm_symbol_ent_t *prev; // previous symbol in the table
21
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
81 };
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
82
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
83 // keep track of current assembler state
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
84 typedef struct {
13
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
85 int dpval; // current dp value (setdp)
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
86 int addr; // current address
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
87 int context; // context counter (for local symbols)
13
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
88 int errorcount; // error count
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
89 int passnum; // which pass are we on?
21
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
90 int execaddr; // execution address for the program (END ....)
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
91 int pragmas; // what pragmas are in effect?
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
92
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
93 lwasm_line_t *lineshead; // first line of source code
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
94 lwasm_line_t *linestail; // last line of source code
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
95
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
96 lwasm_symbol_ent_t *symhead; // first entry in symbol table
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
97 lwasm_symbol_ent_t *symtail; // last entry in symbol table
57
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
98
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
99 macrotab_t *macros; // macro table
21
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
100
13
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
101 const char *infile; // input file
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
102 const char *outfile; // output file
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
103 const char *listfile; // output listing file
05d4115b4860 Started work on new expression evaluator system and major code re-work for next release
lost
parents: 4
diff changeset
104 int outformat; // output format type
21
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
105 char **filelist; // files that have been read
3c0e5f311c95 Added reading of input file for pass1
lost
parents: 13
diff changeset
106 int filelistlen; // number of files in the list
54
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 49
diff changeset
107
360d53062bb9 Fixed typo in instruction table and added END directive
lost
parents: 49
diff changeset
108 int endseen; // set to true if "end" has been seen
57
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
109 int skipcond; // skipping a condition?
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
110 int skipcount; // how many?
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
111 int skipmacro; // skipping a macro?
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
112 int inmacro; // are we currently in a macro?
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
113 int macroex; // current depth of macro expansion
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
114 int nextcontext; // next context number
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
115 int skiplines; // number of lines to skip
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
116 } asmstate_t;
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
117
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
118 #define PRAGMA_NOINDEX0TONONE 1
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
119
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
120 #ifndef __lwasm_c_seen__
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
121 #define __lwasm_E__ extern
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
122 #else
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
123 #define __lwasm_E__
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
124 #endif
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
125
38
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
126 __lwasm_E__ int debug_level;
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
127
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
128 __lwasm_E__ int register_error(asmstate_t *as, lwasm_line_t *l, int pass, const char *fmt, ...);
38
9bd584bb6296 Added debugging message infrastructure
lost
parents: 37
diff changeset
129 __lwasm_E__ void debug_message(int level, const char *fmt, ...);
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
130
27
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
131 __lwasm_E__ void lwasm_emit(asmstate_t *as, lwasm_line_t *l, int b);
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
132 __lwasm_E__ void lwasm_emitop(asmstate_t *as, lwasm_line_t *l, int o);
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
133 __lwasm_E__ int lwasm_lookupreg2(const char *reglist, char **str);
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents: 28
diff changeset
134 __lwasm_E__ int lwasm_lookupreg3(const char *rlist, const char **str);
27
f736579569b4 Added handlers for inherent and register to register instructions
lost
parents: 26
diff changeset
135
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
136 __lwasm_E__ lwasm_expr_stack_t *lwasm_evaluate_expr(asmstate_t *as, lwasm_line_t *l, const char *inp, const char **outp);
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
137
55
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
138
57
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
139 // return next context number and update it
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
140 __lwasm_E__ int lwasm_next_context(asmstate_t *as);
035b95a3690f Added conditional assembly and macros
lost
parents: 55
diff changeset
141
55
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
142 // also throw an error on expression eval failure
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
143 // return 0 on ok, -1 on error
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
144 #define EXPR_NOFLAG 0
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
145 #define EXPR_PASS1CONST 1
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
146 #define EXPR_PASS2CONST 2
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
147 #define EXPR_BYTE 4
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
148 __lwasm_E__ int lwasm_expr_result(asmstate_t *as, lwasm_line_t *l, char **inp, int flag, int *val);
8e32696380f3 added expression evaluation and checking function
lost
parents: 54
diff changeset
149
26
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
150 #undef __lwasm_E__
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
151
d2e86babd958 Added error tracking infrastructure
lost
parents: 21
diff changeset
152
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
153 #ifndef __symbol_c_seen__
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
154 #define __lwasm_E__ extern
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
155 #else
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
156 #define __lwasm_E__
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
157 #endif
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
158
37
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
159 __lwasm_E__ int lwasm_register_symbol(asmstate_t *as, lwasm_line_t *l, char *sym, int val);
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
160 __lwasm_E__ lwasm_symbol_ent_t *lwasm_find_symbol(asmstate_t *as, char *sym, int scontext);
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
161 __lwasm_E__ int lwasm_set_symbol(asmstate_t *as, char *sym, int scontext, int val);
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
162
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
163 #undef __lwasm_E__
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
164
538e15927776 Added symbol handling to expression subsystem; adpated instruction handlers to the new scheme; misc fixes
lost
parents: 32
diff changeset
165
0
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
166
57495da01900 Initial checking of LWASM
lost
parents:
diff changeset
167 #endif //__lwasm_h_seen__