struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / sdas / xa51 / xa_rasm.l
blobb72b9e0d0b6038285b98eb77d824a403abaa5c64
1 %{
2 /* xa_rasm.l - This file is part of Paul's XA51 Assembler
4    Copyright 1997,2002 Paul Stoffregen (paul at pjrc dot com)
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 3, or (at your option) any
9 later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
19 /* Author contact: paul@pjrc.com */
21 #include <stdio.h>
22 #include <string.h>
23 #include "xa_main.h"
24 #include "xa_rasm.tab.h"
26 extern int inst_size, yylval;
27 char line_text[MAX_LINE]={'\0'}, last_line_text[MAX_LINE];
28 char lex_sym_name[MAX_SYMBOL];
29 extern char base_symbol_name[];
30 #define LIST if (p3) strcat(line_text, yytext)
35 add\.w          {LIST; inst_size=SIZE16; return ADD;}
36 add\.b          {LIST; inst_size=SIZE8; return ADD;}
37 add             {LIST; inst_size=UNKNOWN; return ADD;}
38 addc\.w         {LIST; inst_size=SIZE16; return ADDC;}
39 addc\.b         {LIST; inst_size=SIZE8; return ADDC;}
40 addc            {LIST; inst_size=UNKNOWN; return ADDC;}
41 adds\.w         {LIST; inst_size=SIZE16; return ADDS;}
42 adds\.b         {LIST; inst_size=SIZE8; return ADDS;}
43 adds            {LIST; inst_size=UNKNOWN; return ADDS;}
44 and\.w          {LIST; inst_size=SIZE16; return AND;}
45 and\.b          {LIST; inst_size=SIZE8; return AND;}
46 and             {LIST; inst_size=UNKNOWN; return AND;}
47 anl             {LIST; inst_size=UNKNOWN; return ANL;}
48 asl\.d          {LIST; inst_size=SIZE32; return ASL;}
49 asl\.w          {LIST; inst_size=SIZE16; return ASL;}
50 asl\.b          {LIST; inst_size=SIZE8; return ASL;}
51 asl             {LIST; inst_size=UNKNOWN; return ASL;}
52 asr\.d          {LIST; inst_size=SIZE32; return ASR;}
53 asr\.w          {LIST; inst_size=SIZE16; return ASR;}
54 asr\.b          {LIST; inst_size=SIZE8; return ASR;}
55 asr             {LIST; inst_size=UNKNOWN; return ASR;}
56 bcc             {LIST; inst_size=UNKNOWN; return BCC;}
57 bcs             {LIST; inst_size=UNKNOWN; return BCS;}
58 beq             {LIST; inst_size=UNKNOWN; return BEQ;}
59 bg              {LIST; inst_size=UNKNOWN; return BG;}
60 bge             {LIST; inst_size=UNKNOWN; return BGE;}
61 bgt             {LIST; inst_size=UNKNOWN; return BGT;}
62 bkpt            {LIST; inst_size=UNKNOWN; return BKPT;}
63 bl              {LIST; inst_size=UNKNOWN; return BL;}
64 ble             {LIST; inst_size=UNKNOWN; return BLE;}
65 blt             {LIST; inst_size=UNKNOWN; return BLT;}
66 bmi             {LIST; inst_size=UNKNOWN; return BMI;}
67 bne             {LIST; inst_size=UNKNOWN; return BNE;}
68 bnv             {LIST; inst_size=UNKNOWN; return BNV;}
69 bov             {LIST; inst_size=UNKNOWN; return BOV;}
70 bpl             {LIST; inst_size=UNKNOWN; return BPL;}
71 br              {LIST; inst_size=UNKNOWN; return BR;}
72 call            {LIST; inst_size=UNKNOWN; return CALL;}
73 cjne\.w         {LIST; inst_size=SIZE16; return CJNE;}
74 cjne\.b         {LIST; inst_size=SIZE8; return CJNE;}
75 cjne            {LIST; inst_size=UNKNOWN; return CJNE;}
76 clr             {LIST; inst_size=UNKNOWN; return CLR;}
77 cmp\.w          {LIST; inst_size=SIZE16; return CMP;}
78 cmp\.b          {LIST; inst_size=SIZE8; return CMP;}
79 cmp             {LIST; inst_size=UNKNOWN; return CMP;}
80 cpl\.w          {LIST; inst_size=SIZE16; return CPL;}
81 cpl\.b          {LIST; inst_size=SIZE8; return CPL;}
82 cpl             {LIST; inst_size=UNKNOWN; return CPL;}
83 da\.b           {LIST; inst_size=SIZE8; return DA;}
84 da              {LIST; inst_size=UNKNOWN; return DA;}
85 div\.d          {LIST; inst_size=SIZE32; return DIV;}
86 div\.w          {LIST; inst_size=SIZE16; return DIV;}
87 div\.b          {LIST; inst_size=SIZE8; return DIV;}
88 div             {LIST; inst_size=UNKNOWN; return DIV;}
89 divu\.d         {LIST; inst_size=SIZE32; return DIVU;}
90 divu\.w         {LIST; inst_size=SIZE16; return DIVU;}
91 divu\.b         {LIST; inst_size=SIZE8; return DIVU;}
92 divu            {LIST; inst_size=UNKNOWN; return DIVU;}
93 djnz\.w         {LIST; inst_size=SIZE16; return DJNZ;}
94 djnz\.b         {LIST; inst_size=SIZE8; return DJNZ;}
95 djnz            {LIST; inst_size=UNKNOWN; return DJNZ;}
96 fcall           {LIST; inst_size=UNKNOWN; return FCALL;}
97 fjmp            {LIST; inst_size=UNKNOWN; return FJMP;}
98 jb              {LIST; inst_size=UNKNOWN; return JB;}
99 jbc             {LIST; inst_size=UNKNOWN; return JBC;}
100 jmp             {LIST; inst_size=UNKNOWN; return JMP;}
101 jnb             {LIST; inst_size=UNKNOWN; return JNB;}
102 jnz             {LIST; inst_size=UNKNOWN; return JNZ;}
103 jz              {LIST; inst_size=UNKNOWN; return JZ;}
104 lea\.w          {LIST; inst_size=SIZE16; return LEA;}
105 lea             {LIST; inst_size=UNKNOWN; return LEA;}
106 lsr\.d          {LIST; inst_size=SIZE32; return LSR;}
107 lsr\.w          {LIST; inst_size=SIZE16; return LSR;}
108 lsr\.b          {LIST; inst_size=SIZE8; return LSR;}
109 lsr             {LIST; inst_size=UNKNOWN; return LSR;}
110 mov\.w          {LIST; inst_size=SIZE16; return MOV;}
111 mov\.b          {LIST; inst_size=SIZE8; return MOV;}
112 mov             {LIST; inst_size=UNKNOWN; return MOV;}
113 movc\.w         {LIST; inst_size=SIZE16; return MOVC;}
114 movc\.b         {LIST; inst_size=SIZE8; return MOVC;}
115 movc            {LIST; inst_size=UNKNOWN; return MOVC;}
116 movs\.w         {LIST; inst_size=SIZE16; return MOVS;}
117 movs\.b         {LIST; inst_size=SIZE8; return MOVS;}
118 movs            {LIST; inst_size=UNKNOWN; return MOVS;}
119 movx\.w         {LIST; inst_size=SIZE16; return MOVX;}
120 movx\.b         {LIST; inst_size=SIZE8; return MOVX;}
121 movx            {LIST; inst_size=UNKNOWN; return MOVX;}
122 mul\.d          {LIST; inst_size=SIZE32; return MUL;}
123 mul\.w          {LIST; inst_size=SIZE16; return MUL;}
124 mul\.b          {LIST; inst_size=SIZE8; return MUL;}
125 mul             {LIST; inst_size=UNKNOWN; return MUL;}
126 mulu\.d         {LIST; inst_size=SIZE32; return MULU;}
127 mulu\.w         {LIST; inst_size=SIZE16; return MULU;}
128 mulu\.b         {LIST; inst_size=SIZE8; return MULU;}
129 mulu            {LIST; inst_size=UNKNOWN; return MULU;}
130 neg\.w          {LIST; inst_size=SIZE16; return NEG;}
131 neg\.b          {LIST; inst_size=SIZE8; return NEG;}
132 neg             {LIST; inst_size=UNKNOWN; return NEG;}
133 nop             {LIST; inst_size=UNKNOWN; return NOP;}
134 norm\.d         {LIST; inst_size=SIZE32; return NORM;}
135 norm\.w         {LIST; inst_size=SIZE16; return NORM;}
136 norm\.b         {LIST; inst_size=SIZE8; return NORM;}
137 norm            {LIST; inst_size=UNKNOWN; return NORM;}
138 or\.w           {LIST; inst_size=SIZE16; return OR;}
139 or\.b           {LIST; inst_size=SIZE8; return OR;}
140 or              {LIST; inst_size=UNKNOWN; return OR;}
141 orl             {LIST; inst_size=UNKNOWN; return ORL;}
142 pop\.w          {LIST; inst_size=SIZE16; return POP;}
143 pop\.b          {LIST; inst_size=SIZE8; return POP;}
144 pop             {LIST; inst_size=UNKNOWN; return POP;}
145 popu\.w         {LIST; inst_size=SIZE16; return POPU;}
146 popu\.b         {LIST; inst_size=SIZE8; return POPU;}
147 popu            {LIST; inst_size=UNKNOWN; return POPU;}
148 push\.w         {LIST; inst_size=SIZE16; return PUSH;}
149 push\.b         {LIST; inst_size=SIZE8; return PUSH;}
150 push            {LIST; inst_size=UNKNOWN; return PUSH;}
151 pushu\.w        {LIST; inst_size=SIZE16; return PUSHU;}
152 pushu\.b        {LIST; inst_size=SIZE8; return PUSHU;}
153 pushu           {LIST; inst_size=UNKNOWN; return PUSHU;}
154 reset           {LIST; inst_size=UNKNOWN; return RESET;}
155 ret             {LIST; inst_size=UNKNOWN; return RET;}
156 reti            {LIST; inst_size=UNKNOWN; return RETI;}
157 rl\.w           {LIST; inst_size=SIZE16; return RL;}
158 rl\.b           {LIST; inst_size=SIZE8; return RL;}
159 rl              {LIST; inst_size=UNKNOWN; return RL;}
160 rlc\.w          {LIST; inst_size=SIZE16; return RLC;}
161 rlc\.b          {LIST; inst_size=SIZE8; return RLC;}
162 rlc             {LIST; inst_size=UNKNOWN; return RLC;}
163 rr\.w           {LIST; inst_size=SIZE16; return RR;}
164 rr\.b           {LIST; inst_size=SIZE8; return RR;}
165 rr              {LIST; inst_size=UNKNOWN; return RR;}
166 rrc\.w          {LIST; inst_size=SIZE16; return RRC;}
167 rrc\.b          {LIST; inst_size=SIZE8; return RRC;}
168 rrc             {LIST; inst_size=UNKNOWN; return RRC;}
169 setb            {LIST; inst_size=UNKNOWN; return SETB;}
170 sext\.w         {LIST; inst_size=SIZE16; return SEXT;}
171 sext\.b         {LIST; inst_size=SIZE8; return SEXT;}
172 sext            {LIST; inst_size=UNKNOWN; return SEXT;}
173 sub\.w          {LIST; inst_size=SIZE16; return SUB;}
174 sub\.b          {LIST; inst_size=SIZE8; return SUB;}
175 sub             {LIST; inst_size=UNKNOWN; return SUB;}
176 subb\.w         {LIST; inst_size=SIZE16; return SUBB;}
177 subb\.b         {LIST; inst_size=SIZE8; return SUBB;}
178 subb            {LIST; inst_size=UNKNOWN; return SUBB;}
179 trap            {LIST; inst_size=UNKNOWN; return TRAP;}
180 xch\.w          {LIST; inst_size=SIZE16; return XCH;}
181 xch\.b          {LIST; inst_size=SIZE8; return XCH;}
182 xch             {LIST; inst_size=UNKNOWN; return XCH;}
183 xor\.w          {LIST; inst_size=SIZE16; return XOR;}
184 xor\.b          {LIST; inst_size=SIZE8; return XOR;}
185 xor             {LIST; inst_size=UNKNOWN; return XOR;}
188 dptr            {LIST; return DPTR;}
189 pc              {LIST; return PC;}
190 a               {LIST; return A;}
191 c               {LIST; return C;}
192 usp             {LIST; return USP;}
194 org             {LIST; return ORG;}
195 equ             {LIST; return EQU;}
196 sfr             {LIST; return SFR;}
197 db              {LIST; return DB;}
198 dw              {LIST; return DW;}
199 byte            {LIST; return DB;}
200 bit             {LIST; return BITDEF;}
201 reg             {LIST; return REGDEF;}
202 area            {LIST; return AREA;}
203 ds              {LIST; return DS;}
204 DSEG            {LIST; yylval = AREA_DSEG; return AREA_NAME;}
205 BSEG            {LIST; yylval = AREA_BSEG; return AREA_NAME;}
206 XSEG            {LIST; yylval = AREA_XSEG; return AREA_NAME;}
207 XISEG           {LIST; yylval = AREA_XISEG; return AREA_NAME;}
208 XINIT           {LIST; yylval = AREA_XINIT; return AREA_NAME;}
209 GSINIT          {LIST; yylval = AREA_GSINIT; return AREA_NAME;}
210 GSFINAL         {LIST; yylval = AREA_GSFINAL; return AREA_NAME;}
211 HOME            {LIST; yylval = AREA_HOME; return AREA_NAME;}
212 SSEG            {LIST; yylval = AREA_SSEG; return AREA_NAME;}
213 CSEG            {LIST; yylval = AREA_CSEG; return AREA_NAME;}
214 module          {LIST; return MODULE;}
215 globl           {LIST; return GLOBL;}
216 \(DATA\)        {LIST; return AREA_DESC;}
217 \(OVR,XDATA\)   {LIST; return AREA_DESC;}
218 \(BIT\)         {LIST; return AREA_DESC;}
219 \(XDATA\)       {LIST; return AREA_DESC;}
220 \(CODE\)        {LIST; return AREA_DESC;}
221 low             {LIST; return LOW;}
222 high            {LIST; return HIGH;}
223 >>              {LIST; return RSHIFT;}
224 \<\<            {LIST; return LSHIFT;}
226 R[0-9]          {LIST; yylval = yytext[1] - '0' + WORD_REG; return REG;}
227 R1[0-5]         {LIST; yylval = yytext[2] - '0' + 10 + WORD_REG; return REG;}
228 R[0-7]L         {LIST; yylval = (yytext[1] - '0') * 2 + BYTE_REG; return REG;}
229 R[0-7]H         {LIST; yylval = (yytext[1] - '0') * 2 + 1 + BYTE_REG; return REG;}
232 [a-z_][a-z0-9_]*        {
233                                 LIST;
234                                 if (is_def(yytext)) {
235                                         yylval = get_value(yytext);
236                                 } else {
237                                         if (p1) build_sym_list(yytext);
238                                         yylval = 0;
239                                         //if (p3) error("Symbol undefined");
240                                 }
241                                 /* keep name in lex_sym_name since yytext */
242                                 /* could be overwritten if the parser does */
243                                 /* a lookahead operation */
244                                 strcpy(lex_sym_name, yytext);
245                                 if (is_def(lex_sym_name)) {
246                                         yylval = get_value(lex_sym_name);
247                                         /* return correct type if special */
248                                         if (is_bit(lex_sym_name)) return BIT;
249                                         if (is_reg(lex_sym_name)) return REG;
250                                 }
251                                 if (p3) {
252                                  if (*operand[0]) {
253                                    // first one in use
254                                    strcpy (operand[1], yytext);
255                                  } else {
256                                    strcpy (operand[0], yytext);
257                                  }
258                                 }
259                                 return WORD;
260                         }
261 [0-9]+\$                {
262                                 LIST;
263                                 /* should print error if base_symbol_name */
264                                 /* is not defined */
265                                 sprintf(lex_sym_name, "%s:%s",
266                                         base_symbol_name, yytext);
267                                 if (is_def(lex_sym_name)) {
268                                         yylval = get_value(lex_sym_name);
269                                 } else {
270                                         yylval = 0;
271                                         if (p3) error("Symbol undefined");
272                                 }
273                                 return WORD;
274                         }
275 [01]+[bq]               {
276                                 LIST;
277                                 yylval = binary2int(yytext);
278                                 return NUMBER;
279                         }
280 0x[0-9a-f]+             {
281                                 LIST;
282                                 sscanf(yytext, "%*c%*c%x", &yylval);
283                                 return NUMBER;
284                         }
285 [0-9a-f]+[h]            {
286                                 LIST;
287                                 sscanf(yytext, "%x%*[hH]", &yylval);
288                                 return NUMBER;
289                         }
290 \$[0-9a-f]+             {
291                                 LIST;
292                                 sscanf(yytext, "$%x", &yylval);
293                                 return NUMBER;
294                         }
295 -?[0-9]+                {
296                                 LIST;
297                                 sscanf(yytext, "%d", &yylval);
298                                 return NUMBER;
299                         }
300 \'.\'                   {
301                                 LIST;
302                                 yylval = (int)yytext[1];
303                                 return CHAR;
304                         }
305 \'\\.\'                 {
306                                 LIST;
307                                 switch (yytext[1]) {
308                                         case 'n':
309                                         case 'N': yylval = 10; break;
310                                         case 'r':
311                                         case 'R': yylval = 13; break;
312                                         case '0': yylval = 0; break;
313                                         default:  yylval = (int)yytext[1];
314                                         /* print a warning here */
315                                 }
316                                 return CHAR;
317                         }
318 \"[^"\n]*["\n]          {
319                                 LIST;
320                                 return STRING;
321                         }
323 ;[^\n]*         {LIST; /* comments */}
324 [ \t\r]         {LIST; /* whitespace */}
326 \n              {
327                         strcpy(last_line_text, line_text);
328                         line_text[0] = '\0';
329                         ++lineno;
330                         return EOL;
331                 }
333 .               {LIST; return yytext[0];}