-
-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathasmy.y
2195 lines (1921 loc) · 42.4 KB
/
asmy.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of RGBDS.
*
* Copyright (c) 1997-2018, Carsten Sorensen and RGBDS contributors.
*
* SPDX-License-Identifier: MIT
*/
%{
#include <ctype.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include "asm/asm.h"
#include "asm/charmap.h"
#include "asm/constexpr.h"
#include "asm/fstack.h"
#include "asm/lexer.h"
#include "asm/main.h"
#include "asm/mymath.h"
#include "asm/output.h"
#include "asm/rpn.h"
#include "asm/symbol.h"
#include "extern/utf8decoder.h"
#include "common.h"
#include "linkdefs.h"
uint32_t nListCountEmpty;
char *tzNewMacro;
uint32_t ulNewMacroSize;
int32_t nPCOffset;
static void bankrangecheck(char *name, uint32_t secttype, int32_t org,
int32_t bank)
{
int32_t minbank = 0, maxbank = 0;
char *stype = NULL;
switch (secttype) {
case SECT_ROMX:
stype = "ROMX";
minbank = BANK_MIN_ROMX;
maxbank = BANK_MAX_ROMX;
break;
case SECT_SRAM:
stype = "SRAM";
minbank = BANK_MIN_SRAM;
maxbank = BANK_MAX_SRAM;
break;
case SECT_WRAMX:
stype = "WRAMX";
minbank = BANK_MIN_WRAMX;
maxbank = BANK_MAX_WRAMX;
break;
case SECT_VRAM:
stype = "VRAM";
minbank = BANK_MIN_VRAM;
maxbank = BANK_MAX_VRAM;
break;
default:
yyerror("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections");
}
if (stype && (bank < minbank || bank > maxbank)) {
yyerror("%s bank value $%x out of range ($%x to $%x)",
stype, bank, minbank, maxbank);
}
out_NewAbsSection(name, secttype, org, bank);
}
size_t symvaluetostring(char *dest, size_t maxLength, char *sym)
{
size_t length;
if (sym_isString(sym)) {
char *src = sym_GetStringValue(sym);
size_t i;
for (i = 0; src[i] != 0; i++) {
if (i >= maxLength)
fatalerror("Symbol value too long to fit buffer");
dest[i] = src[i];
}
length = i;
} else {
uint32_t value = sym_GetConstantValue(sym);
int32_t fullLength = snprintf(dest, maxLength + 1, "$%X",
value);
if (fullLength < 0) {
fatalerror("snprintf encoding error");
} else {
length = (size_t)fullLength;
if (length > maxLength)
fatalerror("Symbol value too long to fit buffer");
}
}
return length;
}
static uint32_t str2int2(char *s, int32_t length)
{
int32_t i;
uint32_t r = 0;
i = ((length - 4) < 0) ? 0 : length - 4;
while (i < length) {
r <<= 8;
r |= (uint8_t)s[i];
i++;
}
return r;
}
static uint32_t isWhiteSpace(char s)
{
return (s == ' ') || (s == '\t') || (s == '\0') || (s == '\n');
}
static uint32_t isRept(char *s)
{
return (strncasecmp(s, "REPT", 4) == 0)
&& isWhiteSpace(*(s - 1)) && isWhiteSpace(s[4]);
}
static uint32_t isEndr(char *s)
{
return (strncasecmp(s, "ENDR", 4) == 0)
&& isWhiteSpace(*(s - 1)) && isWhiteSpace(s[4]);
}
static void copyrept(void)
{
int32_t level = 1, len, instring = 0;
char *src = pCurrentBuffer->pBuffer;
char *bufferEnd = pCurrentBuffer->pBufferStart
+ pCurrentBuffer->nBufferSize;
while (src < bufferEnd && level) {
if (instring == 0) {
if (isRept(src)) {
level += 1;
src += 4;
} else if (isEndr(src)) {
level -= 1;
src += 4;
} else {
if (*src == '\"')
instring = 1;
src += 1;
}
} else {
if (*src == '\\') {
src += 2;
} else if (*src == '\"') {
src += 1;
instring = 0;
} else {
src += 1;
}
}
}
if (level != 0)
fatalerror("Unterminated REPT block");
len = src - pCurrentBuffer->pBuffer - 4;
src = pCurrentBuffer->pBuffer;
ulNewMacroSize = len;
tzNewMacro = malloc(ulNewMacroSize + 1);
if (tzNewMacro == NULL)
fatalerror("Not enough memory for REPT block.");
uint32_t i;
tzNewMacro[ulNewMacroSize] = 0;
for (i = 0; i < ulNewMacroSize; i += 1) {
tzNewMacro[i] = src[i];
if (src[i] == '\n')
nLineNo+=1;
}
yyskipbytes(ulNewMacroSize + 4);
}
static uint32_t isMacro(char *s)
{
return (strncasecmp(s, "MACRO", 4) == 0)
&& isWhiteSpace(*(s - 1)) && isWhiteSpace(s[5]);
}
static uint32_t isEndm(char *s)
{
return (strncasecmp(s, "ENDM", 4) == 0)
&& isWhiteSpace(*(s - 1)) && isWhiteSpace(s[4]);
}
static void copymacro(void)
{
int32_t level = 1, len, instring = 0;
char *src = pCurrentBuffer->pBuffer;
char *bufferEnd = pCurrentBuffer->pBufferStart
+ pCurrentBuffer->nBufferSize;
while (src < bufferEnd && level) {
if (instring == 0) {
if (isMacro(src)) {
level += 1;
src += 4;
} else if (isEndm(src)) {
level -= 1;
src += 4;
} else {
if(*src == '\"')
instring = 1;
src += 1;
}
} else {
if (*src == '\\') {
src += 2;
} else if (*src == '\"') {
src += 1;
instring = 0;
} else {
src += 1;
}
}
}
if (level != 0)
fatalerror("Unterminated MACRO definition.");
len = src - pCurrentBuffer->pBuffer - 4;
src = pCurrentBuffer->pBuffer;
ulNewMacroSize = len;
tzNewMacro = (char *)malloc(ulNewMacroSize+2);
if (tzNewMacro == NULL)
fatalerror("Not enough memory for MACRO definition.");
uint32_t i;
tzNewMacro[ulNewMacroSize] = '\n';
tzNewMacro[ulNewMacroSize+1] = 0;
for (i = 0; i < ulNewMacroSize; i += 1) {
tzNewMacro[i] = src[i];
if (src[i] == '\n')
nLineNo += 1;
}
yyskipbytes(ulNewMacroSize + 4);
}
static uint32_t isIf(char *s)
{
return (strncasecmp(s, "IF", 2) == 0)
&& isWhiteSpace(s[-1]) && isWhiteSpace(s[2]);
}
static uint32_t isElif(char *s)
{
return (strncasecmp(s, "ELIF", 4) == 0)
&& isWhiteSpace(s[-1]) && isWhiteSpace(s[4]);
}
static uint32_t isElse(char *s)
{
return (strncasecmp(s, "ELSE", 4) == 0)
&& isWhiteSpace(s[-1]) && isWhiteSpace(s[4]);
}
static uint32_t isEndc(char *s)
{
return (strncasecmp(s, "ENDC", 4) == 0)
&& isWhiteSpace(s[-1]) && isWhiteSpace(s[4]);
}
static void if_skip_to_else(void)
{
int32_t level = 1;
bool inString = false;
char *src = pCurrentBuffer->pBuffer;
while (*src && level) {
if (*src == '\n')
nLineNo++;
if (!inString) {
if (isIf(src)) {
level++;
src += 2;
} else if (level == 1 && isElif(src)) {
level--;
skipElif = false;
} else if (level == 1 && isElse(src)) {
level--;
src += 4;
} else if (isEndc(src)) {
level--;
if (level != 0)
src += 4;
} else {
if (*src == '\"')
inString = true;
src++;
}
} else {
switch (*src) {
case '\\':
src += 2;
break;
case '\"':
src += 2;
inString = false;
break;
default:
src++;
break;
}
}
}
if (level != 0)
fatalerror("Unterminated IF construct");
int32_t len = src - pCurrentBuffer->pBuffer;
yyskipbytes(len);
yyunput('\n');
nLineNo--;
}
static void if_skip_to_endc(void)
{
int32_t level = 1;
bool inString = false;
char *src = pCurrentBuffer->pBuffer;
while (*src && level) {
if (*src == '\n')
nLineNo++;
if (!inString) {
if (isIf(src)) {
level++;
src += 2;
} else if (isEndc(src)) {
level--;
if (level != 0)
src += 4;
} else {
if (*src == '\"')
inString = true;
src++;
}
} else {
switch (*src) {
case '\\':
src += 2;
break;
case '\"':
src++;
inString = false;
break;
default:
src++;
break;
}
}
}
if (level != 0)
fatalerror("Unterminated IF construct");
int32_t len = src - pCurrentBuffer->pBuffer;
yyskipbytes(len);
yyunput('\n');
nLineNo--;
}
static void startUnion(void)
{
if (!pCurrentSection)
fatalerror("UNIONs must be inside a SECTION");
uint32_t unionIndex = nUnionDepth;
nUnionDepth++;
if (nUnionDepth > MAXUNIONS)
fatalerror("Too many nested UNIONs");
unionStart[unionIndex] = nPC;
unionSize[unionIndex] = 0;
}
static void updateUnion(void)
{
uint32_t unionIndex = nUnionDepth - 1;
uint32_t size = nPC - unionStart[unionIndex];
if (size > unionSize[unionIndex])
unionSize[unionIndex] = size;
nPC = unionStart[unionIndex];
pCurrentSection->nPC = unionStart[unionIndex];
pPCSymbol->nValue = unionStart[unionIndex];
}
static size_t strlenUTF8(const char *s)
{
size_t len = 0;
uint32_t state = 0;
uint32_t codep = 0;
while (*s) {
switch (decode(&state, &codep, (uint8_t)*s)) {
case 1:
fatalerror("STRLEN: Invalid UTF-8 character");
break;
case 0:
len++;
break;
}
s++;
}
/* Check for partial code point. */
if (state != 0)
fatalerror("STRLEN: Invalid UTF-8 character");
return len;
}
static void strsubUTF8(char *dest, const char *src, uint32_t pos, uint32_t len)
{
size_t srcIndex = 0;
size_t destIndex = 0;
uint32_t state = 0;
uint32_t codep = 0;
uint32_t curPos = 1;
uint32_t curLen = 0;
if (pos < 1) {
warning("STRSUB: Position starts at 1");
pos = 1;
}
/* Advance to starting position in source string. */
while (src[srcIndex] && curPos < pos) {
switch (decode(&state, &codep, (uint8_t)src[srcIndex])) {
case 1:
fatalerror("STRSUB: Invalid UTF-8 character");
break;
case 0:
curPos++;
break;
}
srcIndex++;
}
if (!src[srcIndex])
warning("STRSUB: Position %lu is past the end of the string",
(unsigned long)pos);
/* Copy from source to destination. */
while (src[srcIndex] && destIndex < MAXSTRLEN && curLen < len) {
switch (decode(&state, &codep, (uint8_t)src[srcIndex])) {
case 1:
fatalerror("STRSUB: Invalid UTF-8 character");
break;
case 0:
curLen++;
break;
}
dest[destIndex++] = src[srcIndex++];
}
if (curLen < len)
warning("STRSUB: Length too big: %lu", (unsigned long)len);
/* Check for partial code point. */
if (state != 0)
fatalerror("STRSUB: Invalid UTF-8 character");
dest[destIndex] = 0;
}
%}
%union
{
char tzSym[MAXSYMLEN + 1];
char tzString[MAXSTRLEN + 1];
struct Expression sVal;
int32_t nConstValue;
struct ConstExpression sConstExpr;
}
%type <sVal> relocconst
%type <sConstExpr> const
%type <nConstValue> uconst
%type <nConstValue> const_3bit
%type <sVal> const_8bit
%type <sVal> const_16bit
%type <nConstValue> sectiontype
%type <tzString> string
%token <nConstValue> T_NUMBER
%token <tzString> T_STRING
%left <nConstValue> T_OP_LOGICNOT
%left <nConstValue> T_OP_LOGICOR T_OP_LOGICAND T_OP_LOGICEQU
%left <nConstValue> T_OP_LOGICGT T_OP_LOGICLT T_OP_LOGICGE T_OP_LOGICLE T_OP_LOGICNE
%left <nConstValue> T_OP_ADD T_OP_SUB
%left <nConstValue> T_OP_OR T_OP_XOR T_OP_AND
%left <nConstValue> T_OP_SHL T_OP_SHR
%left <nConstValue> T_OP_MUL T_OP_DIV T_OP_MOD
%left <nConstValue> T_OP_NOT
%left <nConstValue> T_OP_DEF
%left <nConstValue> T_OP_BANK T_OP_ALIGN
%left <nConstValue> T_OP_SIN
%left <nConstValue> T_OP_COS
%left <nConstValue> T_OP_TAN
%left <nConstValue> T_OP_ASIN
%left <nConstValue> T_OP_ACOS
%left <nConstValue> T_OP_ATAN
%left <nConstValue> T_OP_ATAN2
%left <nConstValue> T_OP_FDIV
%left <nConstValue> T_OP_FMUL
%left <nConstValue> T_OP_ROUND
%left <nConstValue> T_OP_CEIL
%left <nConstValue> T_OP_FLOOR
%token <nConstValue> T_OP_HIGH T_OP_LOW
%left <nConstValue> T_OP_STRCMP
%left <nConstValue> T_OP_STRIN
%left <nConstValue> T_OP_STRSUB
%left <nConstValue> T_OP_STRLEN
%left <nConstValue> T_OP_STRCAT
%left <nConstValue> T_OP_STRUPR
%left <nConstValue> T_OP_STRLWR
%left NEG /* negation -- unary minus */
%token <tzSym> T_LABEL
%token <tzSym> T_ID
%token <tzSym> T_POP_EQU
%token <tzSym> T_POP_SET
%token <tzSym> T_POP_EQUS
%token T_POP_INCLUDE T_POP_PRINTF T_POP_PRINTT T_POP_PRINTV T_POP_PRINTI
%token T_POP_IF T_POP_ELIF T_POP_ELSE T_POP_ENDC
%token T_POP_IMPORT T_POP_EXPORT T_POP_GLOBAL
%token T_POP_DB T_POP_DS T_POP_DW T_POP_DL
%token T_POP_SECTION
%token T_POP_RB
%token T_POP_RW
%token T_POP_RL
%token T_POP_MACRO
%token T_POP_ENDM
%token T_POP_RSRESET T_POP_RSSET
%token T_POP_UNION T_POP_NEXTU T_POP_ENDU
%token T_POP_INCBIN T_POP_REPT
%token T_POP_CHARMAP
%token T_POP_SHIFT
%token T_POP_ENDR
%token T_POP_FAIL
%token T_POP_WARN
%token T_POP_PURGE
%token T_POP_POPS
%token T_POP_PUSHS
%token T_POP_POPO
%token T_POP_PUSHO
%token T_POP_OPT
%token T_SECT_WRAM0 T_SECT_VRAM T_SECT_ROMX T_SECT_ROM0 T_SECT_HRAM
%token T_SECT_WRAMX T_SECT_SRAM T_SECT_OAM
%token T_SECT_HOME T_SECT_DATA T_SECT_CODE T_SECT_BSS
%token T_Z80_ADC T_Z80_ADD T_Z80_AND
%token T_Z80_BIT
%token T_Z80_CALL T_Z80_CCF T_Z80_CP T_Z80_CPL
%token T_Z80_DAA T_Z80_DEC T_Z80_DI
%token T_Z80_EI
%token T_Z80_HALT
%token T_Z80_INC
%token T_Z80_JP T_Z80_JR
%token T_Z80_LD
%token T_Z80_LDI
%token T_Z80_LDD
%token T_Z80_LDIO
%token T_Z80_NOP
%token T_Z80_OR
%token T_Z80_POP T_Z80_PUSH
%token T_Z80_RES T_Z80_RET T_Z80_RETI T_Z80_RST
%token T_Z80_RL T_Z80_RLA T_Z80_RLC T_Z80_RLCA
%token T_Z80_RR T_Z80_RRA T_Z80_RRC T_Z80_RRCA
%token T_Z80_SBC T_Z80_SCF T_Z80_STOP
%token T_Z80_SLA T_Z80_SRA T_Z80_SRL T_Z80_SUB T_Z80_SWAP
%token T_Z80_XOR
%token T_TOKEN_A T_TOKEN_B T_TOKEN_C T_TOKEN_D T_TOKEN_E T_TOKEN_H T_TOKEN_L
%token T_MODE_AF
%token T_MODE_BC T_MODE_BC_IND
%token T_MODE_DE T_MODE_DE_IND
%token T_MODE_SP T_MODE_SP_IND
%token T_MODE_C_IND
%token T_MODE_HL T_MODE_HL_IND T_MODE_HL_INDDEC T_MODE_HL_INDINC
%token T_CC_NZ T_CC_Z T_CC_NC
%type <nConstValue> reg_r
%type <nConstValue> reg_ss
%type <nConstValue> reg_rr
%type <nConstValue> reg_tt
%type <nConstValue> ccode
%type <sVal> op_a_n
%type <nConstValue> op_a_r
%type <nConstValue> op_hl_ss
%type <sVal> op_mem_ind
%start asmfile
%%
asmfile : lines;
/* Note: The lexer adds '\n' at the end of the input */
lines : /* empty */
| lines {
nListCountEmpty = 0;
nPCOffset = 1;
} line '\n' {
nLineNo += 1;
nTotalLines += 1;
}
;
line : label
| label cpu_command
| label macro
| label simple_pseudoop
| pseudoop
;
label : /* empty */
| T_LABEL
{
if ($1[0] == '.')
sym_AddLocalReloc($1);
else
sym_AddReloc($1);
}
| T_LABEL ':'
{
if ($1[0] == '.')
sym_AddLocalReloc($1);
else
sym_AddReloc($1);
}
| T_LABEL ':' ':'
{
if ($1[0] == '.')
sym_AddLocalReloc($1);
else
sym_AddReloc($1);
sym_Export($1);
}
;
macro : T_ID {
yy_set_state(LEX_STATE_MACROARGS);
} macroargs {
yy_set_state(LEX_STATE_NORMAL);
if (!fstk_RunMacro($1))
fatalerror("Macro '%s' not defined", $1);
}
;
macroargs : /* empty */
| macroarg
| macroarg comma macroargs
;
macroarg : T_STRING { sym_AddNewMacroArg($1); }
;
pseudoop : equ
| set
| rb
| rw
| rl
| equs
| macrodef
;
simple_pseudoop : include
| printf
| printt
| printv
| printi
| if
| elif
| else
| endc
| import
| export
| global
| { nPCOffset = 0; } db
| { nPCOffset = 0; } dw
| { nPCOffset = 0; } dl
| ds
| section
| rsreset
| rsset
| union
| nextu
| endu
| incbin
| charmap
| rept
| shift
| fail
| warn
| purge
| pops
| pushs
| popo
| pusho
| opt
;
opt : T_POP_OPT {
yy_set_state(LEX_STATE_MACROARGS);
} opt_list {
yy_set_state(LEX_STATE_NORMAL);
}
;
opt_list : opt_list_entry
| opt_list_entry comma opt_list
;
opt_list_entry : T_STRING { opt_Parse($1); }
;
popo : T_POP_POPO { opt_Pop(); }
;
pusho : T_POP_PUSHO { opt_Push(); }
;
pops : T_POP_POPS { out_PopSection(); }
;
pushs : T_POP_PUSHS { out_PushSection(); }
;
fail : T_POP_FAIL string { fatalerror("%s", $2); }
;
warn : T_POP_WARN string { warning("%s", $2); }
;
shift : T_POP_SHIFT { sym_ShiftCurrentMacroArgs(); }
;
rept : T_POP_REPT uconst
{
copyrept();
fstk_RunRept($2);
}
;
macrodef : T_LABEL ':' T_POP_MACRO
{
copymacro();
sym_AddMacro($1);
}
;
equs : T_LABEL T_POP_EQUS string
{
sym_AddString($1, $3);
}
;
rsset : T_POP_RSSET uconst
{
sym_AddSet("_RS", $2);
}
;
rsreset : T_POP_RSRESET
{
sym_AddSet("_RS", 0);
}
;
rl : T_LABEL T_POP_RL uconst
{
sym_AddEqu($1, sym_GetConstantValue("_RS"));
sym_AddSet("_RS", sym_GetConstantValue("_RS") + 4 * $3);
}
;
rw : T_LABEL T_POP_RW uconst
{
sym_AddEqu($1, sym_GetConstantValue("_RS"));
sym_AddSet("_RS", sym_GetConstantValue("_RS") + 2 * $3);
}
;
rb : T_LABEL T_POP_RB uconst
{
sym_AddEqu($1, sym_GetConstantValue("_RS"));
sym_AddSet("_RS", sym_GetConstantValue("_RS") + $3);
}
;
union : T_POP_UNION
{
startUnion();
}
;
nextu : T_POP_NEXTU
{
if (nUnionDepth <= 0)
fatalerror("Found NEXTU outside of a UNION construct");
updateUnion();
}
;
endu : T_POP_ENDU
{
if (nUnionDepth <= 0)
fatalerror("Found ENDU outside of a UNION construct");
updateUnion();
nUnionDepth--;
nPC = unionStart[nUnionDepth] + unionSize[nUnionDepth];
pCurrentSection->nPC = nPC;
pPCSymbol->nValue = nPC;
}
;
ds : T_POP_DS uconst
{
out_Skip($2);
}
;
db : T_POP_DB constlist_8bit_entry comma constlist_8bit {
if (nListCountEmpty > 0) {
warning("Empty entry in list of 8-bit elements (treated as 0).");
}
}
| T_POP_DB constlist_8bit_entry
;
dw : T_POP_DW constlist_16bit_entry comma constlist_16bit {
if (nListCountEmpty > 0) {
warning("Empty entry in list of 16-bit elements (treated as 0).");
}
}
| T_POP_DW constlist_16bit_entry
;
dl : T_POP_DL constlist_32bit_entry comma constlist_32bit {
if (nListCountEmpty > 0) {
warning("Empty entry in list of 32-bit elements (treated as 0).");
}
}
| T_POP_DL constlist_32bit_entry
;
purge : T_POP_PURGE {
oDontExpandStrings = true;
} purge_list {
oDontExpandStrings = false;
}
;
purge_list : purge_list_entry
| purge_list_entry comma purge_list
;
purge_list_entry : T_ID
{
sym_Purge($1);
}
;
import : T_POP_IMPORT import_list
;
import_list : import_list_entry
| import_list_entry comma import_list
;
import_list_entry : T_ID
{
/*
* This is done automatically if the label isn't found
* in the list of defined symbols.
*/
warning("IMPORT is a deprecated keyword with no effect: %s", $1);
}
;
export : T_POP_EXPORT export_list
;
export_list : export_list_entry
| export_list_entry comma export_list
;
export_list_entry : T_ID
{
sym_Export($1);
}
;
global : T_POP_GLOBAL global_list
;
global_list : global_list_entry
| global_list_entry comma global_list
;
global_list_entry : T_ID
{
sym_Export($1);
}
;
equ : T_LABEL T_POP_EQU const
{
sym_AddEqu($1, constexpr_GetConstantValue(&$3));
}
;
set : T_LABEL T_POP_SET const
{
sym_AddSet($1, constexpr_GetConstantValue(&$3));
}
;
include : T_POP_INCLUDE string
{
fstk_RunInclude($2);
}
;
incbin : T_POP_INCBIN string
{
out_BinaryFile($2);
}
| T_POP_INCBIN string comma uconst comma uconst
{
out_BinaryFileSlice($2, $4, $6);
}
;
charmap : T_POP_CHARMAP string comma string
{
if (charmap_Add($2, $4[0] & 0xFF) == -1) {
fprintf(stderr, "Error parsing charmap. Either you've added too many (%i), or the input character length is too long (%i)' : %s\n", MAXCHARMAPS, CHARMAPLENGTH, strerror(errno));
yyerror("Error parsing charmap.");
}
}