-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
syntactic.y
2224 lines (2092 loc) · 46.1 KB
/
syntactic.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
/*
* Copyright (C) 2022 Clownacy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/*%define parse.trace*/
%define api.pure
%define api.prefix {m68kasm_}
%param {void *scanner}
%parse-param {Statement *statement}
%define parse.error verbose
%code requires {
#include "clowncommon/clowncommon.h"
/* A hack for older versions of Bison. */
/* Should probably be removed when they go out of circulation. */
#if defined(YYBISON) && YYBISON < 30802 && !defined(YYNOMEM)
#define YYNOMEM goto yyexhaustedlab;
#endif
#define YYSTYPE M68KASM_STYPE
#define CREATE_LIST_TYPE(TYPE)\
typedef struct TYPE\
{\
TYPE##Node *head;\
TYPE##Node *tail;\
} TYPE
typedef enum Size
{
SIZE_BYTE = 1 << 0,
SIZE_SHORT = 1 << 1,
SIZE_WORD = 1 << 2,
SIZE_LONGWORD = 1 << 3,
SIZE_UNDEFINED = 1 << 4
} Size;
typedef enum Condition
{
CONDITION_TRUE,
CONDITION_FALSE,
CONDITION_HIGHER,
CONDITION_LOWER_OR_SAME,
CONDITION_CARRY_CLEAR,
CONDITION_CARRY_SET,
CONDITION_NOT_EQUAL,
CONDITION_EQUAL,
CONDITION_OVERFLOW_CLEAR,
CONDITION_OVERFLOW_SET,
CONDITION_PLUS,
CONDITION_MINUS,
CONDITION_GREATER_OR_EQUAL,
CONDITION_LESS_THAN,
CONDITION_GREATER_THAN,
CONDITION_LESS_OR_EQUAL
} Condition;
typedef enum OpCodeType
{
OPCODE_ORI_TO_CCR,
OPCODE_ORI_TO_SR,
OPCODE_ORI,
OPCODE_ANDI_TO_CCR,
OPCODE_ANDI_TO_SR,
OPCODE_ANDI,
OPCODE_SUBI,
OPCODE_ADDI,
OPCODE_EORI_TO_CCR,
OPCODE_EORI_TO_SR,
OPCODE_EORI,
OPCODE_CMPI,
OPCODE_BTST_STATIC,
OPCODE_BCHG_STATIC,
OPCODE_BCLR_STATIC,
OPCODE_BSET_STATIC,
OPCODE_BTST_DYNAMIC,
OPCODE_BCHG_DYNAMIC,
OPCODE_BCLR_DYNAMIC,
OPCODE_BSET_DYNAMIC,
OPCODE_MOVEP_TO_REG,
OPCODE_MOVEP_FROM_REG,
OPCODE_MOVEA,
OPCODE_MOVE,
OPCODE_MOVE_FROM_SR,
OPCODE_MOVE_TO_CCR,
OPCODE_MOVE_TO_SR,
OPCODE_NEGX,
OPCODE_CLR,
OPCODE_NEG,
OPCODE_NOT,
OPCODE_EXT,
OPCODE_NBCD,
OPCODE_SWAP,
OPCODE_PEA,
OPCODE_ILLEGAL,
OPCODE_TAS,
OPCODE_TST,
OPCODE_TRAP,
OPCODE_LINK,
OPCODE_UNLK,
OPCODE_MOVE_TO_USP,
OPCODE_MOVE_FROM_USP,
OPCODE_RESET,
OPCODE_NOP,
OPCODE_STOP,
OPCODE_RTE,
OPCODE_RTS,
OPCODE_TRAPV,
OPCODE_RTR,
OPCODE_JSR,
OPCODE_JMP,
OPCODE_MOVEM_TO_REGS,
OPCODE_MOVEM_FROM_REGS,
OPCODE_LEA,
OPCODE_CHK,
OPCODE_ADDQ,
OPCODE_SUBQ,
OPCODE_Scc,
OPCODE_DBcc,
OPCODE_BRA,
OPCODE_BSR,
OPCODE_Bcc,
OPCODE_MOVEQ,
OPCODE_DIVU,
OPCODE_DIVS,
OPCODE_SBCD_DATA_REGS,
OPCODE_SBCD_ADDRESS_REGS,
OPCODE_OR_TO_REG,
OPCODE_OR_FROM_REG,
OPCODE_SUB_TO_REG,
OPCODE_SUB_FROM_REG,
OPCODE_SUBX_DATA_REGS,
OPCODE_SUBX_ADDRESS_REGS,
OPCODE_SUBA,
OPCODE_EOR,
OPCODE_CMPM,
OPCODE_CMP,
OPCODE_CMPA,
OPCODE_MULU,
OPCODE_MULS,
OPCODE_ABCD_DATA_REGS,
OPCODE_ABCD_ADDRESS_REGS,
OPCODE_EXG,
OPCODE_AND_TO_REG,
OPCODE_AND_FROM_REG,
OPCODE_ADD_TO_REG,
OPCODE_ADD_FROM_REG,
OPCODE_ADDX_DATA_REGS,
OPCODE_ADDX_ADDRESS_REGS,
OPCODE_ADDA,
OPCODE_ASL_STATIC,
OPCODE_ASR_STATIC,
OPCODE_LSL_STATIC,
OPCODE_LSR_STATIC,
OPCODE_ROXL_STATIC,
OPCODE_ROXR_STATIC,
OPCODE_ROL_STATIC,
OPCODE_ROR_STATIC,
OPCODE_ASL_DYNAMIC,
OPCODE_ASR_DYNAMIC,
OPCODE_LSL_DYNAMIC,
OPCODE_LSR_DYNAMIC,
OPCODE_ROXL_DYNAMIC,
OPCODE_ROXR_DYNAMIC,
OPCODE_ROL_DYNAMIC,
OPCODE_ROR_DYNAMIC,
OPCODE_ASL_SINGLE,
OPCODE_ASR_SINGLE,
OPCODE_LSL_SINGLE,
OPCODE_LSR_SINGLE,
OPCODE_ROXL_SINGLE,
OPCODE_ROXR_SINGLE,
OPCODE_ROL_SINGLE,
OPCODE_ROR_SINGLE
} OpcodeType;
typedef enum ExpressionType
{
EXPRESSION_SUBTRACT,
EXPRESSION_ADD,
EXPRESSION_MULTIPLY,
EXPRESSION_DIVIDE,
EXPRESSION_MODULO,
EXPRESSION_NEGATE,
EXPRESSION_LOGICAL_NOT,
EXPRESSION_LOGICAL_OR,
EXPRESSION_LOGICAL_AND,
EXPRESSION_BITWISE_NOT,
EXPRESSION_BITWISE_OR,
EXPRESSION_BITWISE_XOR,
EXPRESSION_BITWISE_AND,
EXPRESSION_EQUALITY,
EXPRESSION_INEQUALITY,
EXPRESSION_LESS_THAN,
EXPRESSION_LESS_OR_EQUAL,
EXPRESSION_MORE_THAN,
EXPRESSION_MORE_OR_EQUAL,
EXPRESSION_LEFT_SHIFT,
EXPRESSION_RIGHT_SHIFT,
EXPRESSION_NUMBER,
EXPRESSION_IDENTIFIER,
EXPRESSION_STRING,
EXPRESSION_PROGRAM_COUNTER_OF_STATEMENT,
EXPRESSION_PROGRAM_COUNTER_OF_EXPRESSION,
EXPRESSION_STRLEN,
EXPRESSION_DEF
} ExpressionType;
typedef struct Expression
{
ExpressionType type;
union
{
unsigned long unsigned_long;
char *string;
struct Expression *subexpressions;
} shared;
} Expression;
typedef struct ExpressionListNode
{
struct ExpressionListNode *next;
Expression expression;
} ExpressionListNode;
CREATE_LIST_TYPE(ExpressionList);
typedef struct IdentifierListNode
{
struct IdentifierListNode *next;
char *identifier;
} IdentifierListNode;
CREATE_LIST_TYPE(IdentifierList);
typedef struct Opcode
{
OpcodeType type;
Condition condition;
Size size;
} Opcode;
typedef enum OperandType
{
OPERAND_NONE = 0,
OPERAND_DATA_REGISTER = 1 << 0,
OPERAND_ADDRESS_REGISTER = 1 << 1,
OPERAND_ADDRESS_REGISTER_INDIRECT = 1 << 2,
OPERAND_ADDRESS_REGISTER_INDIRECT_POSTINCREMENT = 1 << 3,
OPERAND_ADDRESS_REGISTER_INDIRECT_PREDECREMENT = 1 << 4,
OPERAND_ADDRESS_REGISTER_INDIRECT_WITH_DISPLACEMENT = 1 << 5,
OPERAND_ADDRESS_REGISTER_INDIRECT_WITH_DISPLACEMENT_AND_INDEX_REGISTER = 1 << 6,
OPERAND_ADDRESS = 1 << 7,
OPERAND_ADDRESS_ABSOLUTE = 1 << 8,
OPERAND_LITERAL = 1 << 9,
OPERAND_PROGRAM_COUNTER_WITH_DISPLACEMENT = 1 << 10,
OPERAND_PROGRAM_COUNTER_WITH_DISPLACEMENT_AND_INDEX_REGISTER = 1 << 11,
OPERAND_STATUS_REGISTER = 1 << 12,
OPERAND_CONDITION_CODE_REGISTER = 1 << 13,
OPERAND_USER_STACK_POINTER_REGISTER = 1 << 14,
OPERAND_REGISTER_LIST = 1 << 15
} OperandType;
typedef struct Operand
{
OperandType type;
unsigned int main_register;
unsigned int index_register;
Size size;
Expression literal;
cc_bool index_register_is_address_register;
} Operand;
typedef struct StatementInstruction
{
Opcode opcode;
Operand operands[2];
} StatementInstruction;
typedef struct StatementDc
{
Size size;
ExpressionList values;
} StatementDc;
typedef struct StatementDcb
{
Size size;
Expression repetitions;
Expression value;
} StatementDcb;
typedef struct StatementInclude
{
char *path;
} StatementInclude;
typedef struct StatementIncbin
{
char *path;
Expression start;
cc_bool has_length;
Expression length;
} StatementIncbin;
typedef struct StatementRept
{
Expression repetitions;
} StatementRept;
typedef struct StatementMacro
{
cc_bool uses_label;
IdentifierList parameter_names;
} StatementMacro;
typedef struct StatementInform
{
Expression severity;
char *message;
} StatementInform;
typedef enum StatementType
{
STATEMENT_TYPE_EMPTY,
STATEMENT_TYPE_INSTRUCTION,
STATEMENT_TYPE_DC,
STATEMENT_TYPE_DCB,
STATEMENT_TYPE_INCLUDE,
STATEMENT_TYPE_INCBIN,
STATEMENT_TYPE_REPT,
STATEMENT_TYPE_ENDR,
STATEMENT_TYPE_MACRO,
STATEMENT_TYPE_MACROS,
STATEMENT_TYPE_ENDM,
STATEMENT_TYPE_EQU,
STATEMENT_TYPE_SET,
STATEMENT_TYPE_IF,
STATEMENT_TYPE_ELSEIF,
STATEMENT_TYPE_ELSE,
STATEMENT_TYPE_ENDC,
STATEMENT_TYPE_WHILE,
STATEMENT_TYPE_ENDW,
STATEMENT_TYPE_EVEN,
STATEMENT_TYPE_CNOP,
STATEMENT_TYPE_INFORM,
STATEMENT_TYPE_END,
STATEMENT_TYPE_RS,
STATEMENT_TYPE_RSSET,
STATEMENT_TYPE_RSRESET,
STATEMENT_TYPE_OBJ,
STATEMENT_TYPE_OBJEND,
STATEMENT_TYPE_ORG
} StatementType;
typedef struct Statement
{
StatementType type;
union
{
StatementInstruction instruction;
StatementDc dc;
StatementDcb dcb;
StatementInclude include;
StatementIncbin incbin;
StatementRept rept;
StatementMacro macro;
struct
{
Expression offset;
Expression size_boundary;
} cnop;
StatementInform inform;
struct
{
Size size;
Expression length;
} rs;
Expression expression;
} shared;
} Statement;
}
%code provides {
void DestroyExpression(Expression *expression);
void DestroyStatement(Statement *statement);
}
%code {
#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
int m68kasm_lex(M68KASM_STYPE *yylval_param, void *yyscanner);
void m68kasm_warning(void *scanner, Statement *statement, const char *message);
void m68kasm_error(void *scanner, Statement *statement, const char *message);
static cc_bool DoExpression(Expression *expression, ExpressionType type, Expression *left_expression, Expression *right_expression);
static void DestroyIdentifierList(IdentifierList *list);
static void DestroyExpressionList(ExpressionList *list);
static void DestroyOperand(Operand *operand);
static void DestroyStatementInstruction(StatementInstruction *instruction);
}
%union {
unsigned long unsigned_long;
char *string;
Opcode opcode;
Size size;
Operand operand;
StatementInstruction instruction;
Statement statement;
ExpressionList expression_list;
IdentifierList identifier_list;
Expression expression;
}
%token TOKEN_DIRECTIVE_ORI
%token TOKEN_DIRECTIVE_ANDI
%token TOKEN_DIRECTIVE_SUBI
%token TOKEN_DIRECTIVE_ADDI
%token TOKEN_DIRECTIVE_EORI
%token TOKEN_DIRECTIVE_CMPI
%token TOKEN_DIRECTIVE_BTST
%token TOKEN_DIRECTIVE_BCHG
%token TOKEN_DIRECTIVE_BCLR
%token TOKEN_DIRECTIVE_BSET
%token TOKEN_DIRECTIVE_MOVEP
%token TOKEN_DIRECTIVE_MOVEA
%token TOKEN_DIRECTIVE_MOVE
%token TOKEN_DIRECTIVE_NEGX
%token TOKEN_DIRECTIVE_CLR
%token TOKEN_DIRECTIVE_NEG
%token TOKEN_DIRECTIVE_NOT
%token TOKEN_DIRECTIVE_EXT
%token TOKEN_DIRECTIVE_NBCD
%token TOKEN_DIRECTIVE_SWAP
%token TOKEN_DIRECTIVE_PEA
%token TOKEN_DIRECTIVE_ILLEGAL
%token TOKEN_DIRECTIVE_TAS
%token TOKEN_DIRECTIVE_TST
%token TOKEN_DIRECTIVE_TRAP
%token TOKEN_DIRECTIVE_LINK
%token TOKEN_DIRECTIVE_UNLK
%token TOKEN_DIRECTIVE_RESET
%token TOKEN_DIRECTIVE_NOP
%token TOKEN_DIRECTIVE_STOP
%token TOKEN_DIRECTIVE_RTE
%token TOKEN_DIRECTIVE_RTS
%token TOKEN_DIRECTIVE_TRAPV
%token TOKEN_DIRECTIVE_RTR
%token TOKEN_DIRECTIVE_JSR
%token TOKEN_DIRECTIVE_JMP
%token TOKEN_DIRECTIVE_MOVEM
%token TOKEN_DIRECTIVE_LEA
%token TOKEN_DIRECTIVE_CHK
%token TOKEN_DIRECTIVE_ADDQ
%token TOKEN_DIRECTIVE_SUBQ
%token TOKEN_DIRECTIVE_ST
%token TOKEN_DIRECTIVE_SF
%token TOKEN_DIRECTIVE_SHI
%token TOKEN_DIRECTIVE_SLS
%token TOKEN_DIRECTIVE_SCC
%token TOKEN_DIRECTIVE_SCS
%token TOKEN_DIRECTIVE_SNE
%token TOKEN_DIRECTIVE_SEQ
%token TOKEN_DIRECTIVE_SVC
%token TOKEN_DIRECTIVE_SVS
%token TOKEN_DIRECTIVE_SPL
%token TOKEN_DIRECTIVE_SMI
%token TOKEN_DIRECTIVE_SGE
%token TOKEN_DIRECTIVE_SLT
%token TOKEN_DIRECTIVE_SGT
%token TOKEN_DIRECTIVE_SLE
%token TOKEN_DIRECTIVE_DBT
%token TOKEN_DIRECTIVE_DBF
%token TOKEN_DIRECTIVE_DBHI
%token TOKEN_DIRECTIVE_DBLS
%token TOKEN_DIRECTIVE_DBCC
%token TOKEN_DIRECTIVE_DBCS
%token TOKEN_DIRECTIVE_DBNE
%token TOKEN_DIRECTIVE_DBEQ
%token TOKEN_DIRECTIVE_DBVC
%token TOKEN_DIRECTIVE_DBVS
%token TOKEN_DIRECTIVE_DBPL
%token TOKEN_DIRECTIVE_DBMI
%token TOKEN_DIRECTIVE_DBGE
%token TOKEN_DIRECTIVE_DBLT
%token TOKEN_DIRECTIVE_DBGT
%token TOKEN_DIRECTIVE_DBLE
%token TOKEN_DIRECTIVE_BRA
%token TOKEN_DIRECTIVE_BSR
%token TOKEN_DIRECTIVE_BHI
%token TOKEN_DIRECTIVE_BLS
%token TOKEN_DIRECTIVE_BCC
%token TOKEN_DIRECTIVE_BCS
%token TOKEN_DIRECTIVE_BNE
%token TOKEN_DIRECTIVE_BEQ
%token TOKEN_DIRECTIVE_BVC
%token TOKEN_DIRECTIVE_BVS
%token TOKEN_DIRECTIVE_BPL
%token TOKEN_DIRECTIVE_BMI
%token TOKEN_DIRECTIVE_BGE
%token TOKEN_DIRECTIVE_BLT
%token TOKEN_DIRECTIVE_BGT
%token TOKEN_DIRECTIVE_BLE
%token TOKEN_DIRECTIVE_MOVEQ
%token TOKEN_DIRECTIVE_DIVU
%token TOKEN_DIRECTIVE_DIVS
%token TOKEN_DIRECTIVE_SBCD
%token TOKEN_DIRECTIVE_OR
%token TOKEN_DIRECTIVE_SUB
%token TOKEN_DIRECTIVE_SUBX
%token TOKEN_DIRECTIVE_SUBA
%token TOKEN_DIRECTIVE_EOR
%token TOKEN_DIRECTIVE_CMPM
%token TOKEN_DIRECTIVE_CMP
%token TOKEN_DIRECTIVE_CMPA
%token TOKEN_DIRECTIVE_MULU
%token TOKEN_DIRECTIVE_MULS
%token TOKEN_DIRECTIVE_ABCD
%token TOKEN_DIRECTIVE_EXG
%token TOKEN_DIRECTIVE_AND
%token TOKEN_DIRECTIVE_ADD
%token TOKEN_DIRECTIVE_ADDX
%token TOKEN_DIRECTIVE_ADDA
%token TOKEN_DIRECTIVE_ASL
%token TOKEN_DIRECTIVE_ASR
%token TOKEN_DIRECTIVE_LSL
%token TOKEN_DIRECTIVE_LSR
%token TOKEN_DIRECTIVE_ROXL
%token TOKEN_DIRECTIVE_ROXR
%token TOKEN_DIRECTIVE_ROL
%token TOKEN_DIRECTIVE_ROR
%token TOKEN_DIRECTIVE_DC
%token TOKEN_DIRECTIVE_DCB
%token TOKEN_DIRECTIVE_REPT
%token TOKEN_DIRECTIVE_ENDR
%token TOKEN_DIRECTIVE_MACRO
%token TOKEN_DIRECTIVE_MACROS
%token TOKEN_DIRECTIVE_ENDM
%token TOKEN_DIRECTIVE_INCLUDE
%token TOKEN_DIRECTIVE_INCBIN
%token TOKEN_DIRECTIVE_EQU
%token TOKEN_DIRECTIVE_SET
%token TOKEN_DIRECTIVE_IF
%token TOKEN_DIRECTIVE_ELSEIF
%token TOKEN_DIRECTIVE_ELSE
%token TOKEN_DIRECTIVE_ENDC
%token TOKEN_DIRECTIVE_WHILE
%token TOKEN_DIRECTIVE_ENDW
%token TOKEN_DIRECTIVE_EVEN
%token TOKEN_DIRECTIVE_CNOP
%token TOKEN_DIRECTIVE_INFORM
%token TOKEN_DIRECTIVE_FAIL
%token TOKEN_DIRECTIVE_END
%token TOKEN_DIRECTIVE_RS
%token TOKEN_DIRECTIVE_RSSET
%token TOKEN_DIRECTIVE_RSRESET
%token TOKEN_DIRECTIVE_OBJ
%token TOKEN_DIRECTIVE_OBJEND
%token TOKEN_DIRECTIVE_ORG
%token TOKEN_SIZE_BYTE
%token TOKEN_SIZE_SHORT
%token TOKEN_SIZE_WORD
%token TOKEN_SIZE_LONGWORD
%token<unsigned_long> TOKEN_DATA_REGISTER
%token<unsigned_long> TOKEN_ADDRESS_REGISTER
%token<unsigned_long> TOKEN_NUMBER
%token<string> TOKEN_IDENTIFIER
%token<string> TOKEN_LOCAL_IDENTIFIER
%token<string> TOKEN_STRING
%token TOKEN_STATUS_REGISTER
%token TOKEN_CONDITION_CODE_REGISTER
%token TOKEN_USER_STACK_POINTER_REGISTER
%token TOKEN_PROGRAM_COUNTER
%token TOKEN_LOGICAL_AND
%token TOKEN_LOGICAL_OR
%token TOKEN_EQUALITY
%token TOKEN_INEQUALITY
%token TOKEN_LESS_OR_EQUAL
%token TOKEN_MORE_OR_EQUAL
%token TOKEN_LEFT_SHIFT
%token TOKEN_RIGHT_SHIFT
%token TOKEN_STRLEN
%token TOKEN_DEF
%type<instruction> instruction
%type<opcode> opcode
%type<size> size
%type<opcode> full_opcode
%type<operand> operand
%type<unsigned_long> register_list
%type<unsigned_long> register_span
%type<unsigned_long> data_or_address_register
%type<expression_list> expression_list
%type<identifier_list> identifier_list
%type<expression> expression expression1 expression2 expression3 expression4 expression5 expression6 expression7 expression8
%destructor { free($$); } TOKEN_IDENTIFIER TOKEN_LOCAL_IDENTIFIER TOKEN_STRING
%destructor { DestroyOperand(&$$); } operand
%destructor { DestroyExpressionList(&$$); } expression_list
%destructor { DestroyIdentifierList(&$$); } identifier_list
%destructor { DestroyExpression(&$$); } expression expression1 expression2 expression3 expression4 expression5 expression6 expression7 expression8
%start statement
%%
statement
:
{
statement->type = STATEMENT_TYPE_EMPTY;
}
| instruction
{
statement->type = STATEMENT_TYPE_INSTRUCTION;
statement->shared.instruction = $1;
}
| TOKEN_DIRECTIVE_DC size expression_list
{
statement->type = STATEMENT_TYPE_DC;
statement->shared.dc.size = $2;
statement->shared.dc.values = $3;
}
| TOKEN_DIRECTIVE_DCB size expression ',' expression
{
statement->type = STATEMENT_TYPE_DCB;
statement->shared.dcb.size = $2;
statement->shared.dcb.repetitions = $3;
statement->shared.dcb.value = $5;
}
| TOKEN_DIRECTIVE_INCLUDE TOKEN_STRING
{
statement->type = STATEMENT_TYPE_INCLUDE;
statement->shared.include.path = $2;
}
| TOKEN_DIRECTIVE_INCBIN TOKEN_STRING
{
statement->type = STATEMENT_TYPE_INCBIN;
statement->shared.incbin.path = $2;
statement->shared.incbin.start.type = EXPRESSION_NUMBER;
statement->shared.incbin.start.shared.unsigned_long = 0;
statement->shared.incbin.has_length = cc_false;
}
| TOKEN_DIRECTIVE_INCBIN TOKEN_STRING ',' expression
{
statement->type = STATEMENT_TYPE_INCBIN;
statement->shared.incbin.path = $2;
statement->shared.incbin.start = $4;
statement->shared.incbin.has_length = cc_false;
}
| TOKEN_DIRECTIVE_INCBIN TOKEN_STRING ',' expression ',' expression
{
statement->type = STATEMENT_TYPE_INCBIN;
statement->shared.incbin.path = $2;
statement->shared.incbin.start = $4;
statement->shared.incbin.has_length = cc_true;
statement->shared.incbin.length = $6;
}
| TOKEN_DIRECTIVE_REPT expression
{
statement->type = STATEMENT_TYPE_REPT;
statement->shared.rept.repetitions = $2;
}
| TOKEN_DIRECTIVE_ENDR
{
statement->type = STATEMENT_TYPE_ENDR;
}
| TOKEN_DIRECTIVE_MACRO
{
statement->type = STATEMENT_TYPE_MACRO;
statement->shared.macro.uses_label = cc_false;
statement->shared.macro.parameter_names.head = NULL;
statement->shared.macro.parameter_names.tail = NULL;
}
| TOKEN_DIRECTIVE_MACRO '*'
{
statement->type = STATEMENT_TYPE_MACRO;
statement->shared.macro.uses_label = cc_true;
statement->shared.macro.parameter_names.head = NULL;
statement->shared.macro.parameter_names.tail = NULL;
}
| TOKEN_DIRECTIVE_MACRO identifier_list
{
statement->type = STATEMENT_TYPE_MACRO;
statement->shared.macro.uses_label = cc_false;
statement->shared.macro.parameter_names = $2;
}
| TOKEN_DIRECTIVE_MACRO '*' ',' identifier_list
{
statement->type = STATEMENT_TYPE_MACRO;
statement->shared.macro.uses_label = cc_true;
statement->shared.macro.parameter_names = $4;
}
| TOKEN_DIRECTIVE_MACROS
{
statement->type = STATEMENT_TYPE_MACROS;
statement->shared.macro.parameter_names.head = NULL;
statement->shared.macro.parameter_names.tail = NULL;
}
| TOKEN_DIRECTIVE_MACROS identifier_list
{
statement->type = STATEMENT_TYPE_MACROS;
statement->shared.macro.parameter_names = $2;
}
| TOKEN_DIRECTIVE_ENDM
{
statement->type = STATEMENT_TYPE_ENDM;
}
| TOKEN_DIRECTIVE_EQU expression
{
statement->type = STATEMENT_TYPE_EQU;
statement->shared.expression = $2;
}
| TOKEN_DIRECTIVE_SET expression
{
statement->type = STATEMENT_TYPE_SET;
statement->shared.expression = $2;
}
| '=' expression
{
statement->type = STATEMENT_TYPE_SET;
statement->shared.expression = $2;
}
| TOKEN_DIRECTIVE_IF expression
{
statement->type = STATEMENT_TYPE_IF;
statement->shared.expression = $2;
}
| TOKEN_DIRECTIVE_ELSEIF expression
{
statement->type = STATEMENT_TYPE_ELSEIF;
statement->shared.expression = $2;
}
| TOKEN_DIRECTIVE_ELSEIF
{
statement->type = STATEMENT_TYPE_ELSE;
}
| TOKEN_DIRECTIVE_ELSE
{
statement->type = STATEMENT_TYPE_ELSE;
}
| TOKEN_DIRECTIVE_ENDC
{
statement->type = STATEMENT_TYPE_ENDC;
}
| TOKEN_DIRECTIVE_WHILE expression
{
statement->type = STATEMENT_TYPE_WHILE;
statement->shared.expression = $2;
}
| TOKEN_DIRECTIVE_ENDW
{
statement->type = STATEMENT_TYPE_ENDW;
}
| TOKEN_DIRECTIVE_EVEN
{
statement->type = STATEMENT_TYPE_EVEN;
}
| TOKEN_DIRECTIVE_CNOP expression ',' expression
{
statement->type = STATEMENT_TYPE_CNOP;
statement->shared.cnop.offset = $2;
statement->shared.cnop.size_boundary = $4;
}
| TOKEN_DIRECTIVE_INFORM expression ',' TOKEN_STRING
{
statement->type = STATEMENT_TYPE_INFORM;
statement->shared.inform.severity = $2;
statement->shared.inform.message = $4;
}
| TOKEN_DIRECTIVE_INFORM expression ',' TOKEN_STRING ',' expression_list
{
(void)$6;
/* TODO - parameters */
statement->type = STATEMENT_TYPE_INFORM;
statement->shared.inform.severity = $2;
statement->shared.inform.message = $4;
}
| TOKEN_DIRECTIVE_FAIL
{
statement->type = STATEMENT_TYPE_INFORM;
statement->shared.inform.message = NULL;
}
| TOKEN_DIRECTIVE_END
{
statement->type = STATEMENT_TYPE_END;
}
| TOKEN_DIRECTIVE_RS size expression
{
statement->type = STATEMENT_TYPE_RS;
statement->shared.rs.size = $2;
statement->shared.rs.length = $3;
}
| TOKEN_DIRECTIVE_RSSET expression
{
statement->type = STATEMENT_TYPE_RSSET;
statement->shared.expression = $2;
}
| TOKEN_DIRECTIVE_RSRESET expression
{
/* As mentioned in S.N. 68k's manual, this odd hack
is necessary for compatibility with other assemblers. */
statement->type = STATEMENT_TYPE_RSSET;
statement->shared.expression = $2;
}
| TOKEN_DIRECTIVE_RSRESET
{
statement->type = STATEMENT_TYPE_RSRESET;
}
| TOKEN_DIRECTIVE_OBJ expression
{
statement->type = STATEMENT_TYPE_OBJ;
statement->shared.expression = $2;
}
| TOKEN_DIRECTIVE_OBJEND
{
statement->type = STATEMENT_TYPE_OBJEND;
}
| TOKEN_DIRECTIVE_ORG expression
{
statement->type = STATEMENT_TYPE_ORG;
statement->shared.expression = $2;
}
;
expression_list
: expression
{
ExpressionListNode *node = (ExpressionListNode*)malloc(sizeof(ExpressionListNode));
if (node == NULL)
{
DestroyExpression(&$1);
YYNOMEM;
}
else
{
node->expression = $1;
node->next = NULL;
}
$$.head = $$.tail = node;
}
| expression_list ',' expression
{
ExpressionListNode *node = (ExpressionListNode*)malloc(sizeof(ExpressionListNode));
$$ = $1;
if (node == NULL)
{
DestroyExpressionList(&$1);
DestroyExpression(&$3);
YYNOMEM;
}
else
{
node->expression = $3;
node->next = NULL;
if ($$.head == NULL)
$$.head = node;
else
((ExpressionListNode*)$$.tail)->next = node;
$$.tail = node;
}
}
;
identifier_list
: TOKEN_IDENTIFIER
{
IdentifierListNode *node = (IdentifierListNode*)malloc(sizeof(IdentifierListNode));
if (node == NULL)
{
free($1);
YYNOMEM;
}
else
{
node->identifier = $1;
node->next = NULL;
}
$$.head = $$.tail = node;
}
| identifier_list ',' TOKEN_IDENTIFIER
{
IdentifierListNode *node = (IdentifierListNode*)malloc(sizeof(IdentifierListNode));
$$ = $1;
if (node == NULL)
{
DestroyIdentifierList(&$1);
free(&$3);
YYNOMEM;
}
else
{
node->identifier = $3;
node->next = NULL;
if ($$.head == NULL)
$$.head = node;
else
((IdentifierListNode*)$$.tail)->next = node;
$$.tail = node;
}
}
;
instruction
: full_opcode
{
$$.opcode = $1;
$$.operands[0].type = OPERAND_NONE;
$$.operands[1].type = OPERAND_NONE;
}
| full_opcode operand
{
$$.opcode = $1;
$$.operands[0] = $2;
$$.operands[1].type = OPERAND_NONE;
}
| full_opcode operand ',' operand
{
$$.opcode = $1;
$$.operands[0] = $2;
$$.operands[1] = $4;
}
;
full_opcode
: opcode
{
$$ = $1;
$$.size = SIZE_UNDEFINED;
}
| opcode '.'
{
$$ = $1;
$$.size = SIZE_UNDEFINED;
m68kasm_warning(scanner, statement, "Opcode has a dot but no size; either remove the dot or add an explicit size.");
}
| opcode size
{
$$ = $1;
$$.size = $2;
}
;
opcode
: TOKEN_DIRECTIVE_ORI
{
$$.type = OPCODE_ORI;
}
| TOKEN_DIRECTIVE_ANDI
{
$$.type = OPCODE_ANDI;
}
| TOKEN_DIRECTIVE_SUBI
{
$$.type = OPCODE_SUBI;
}