-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmacrossTypes.h
1098 lines (901 loc) · 32 KB
/
macrossTypes.h
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) 1987 Fujitsu
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/*
macrossTypes.h -- Data type definitions for the Macross assembler.
Chip Morningstar -- Lucasfilm Ltd.
1-November-1984
*/
#ifndef MACROSS_TYPES_H_
#define MACROSS_TYPES_H_
#include <stdlib.h>
#include <stdio.h>
/*
Stuff for sorting out which target processor we are going to be an
assembler for, this time around.
*/
/* TARGET_CPU gets defined as one of these on the 'cc' commmand line using
the "-D" option */
#define CPU_6502 1
#define CPU_68000 2
#if TARGET_CPU == CPU_6502
#define OPERAND_DEFS "operandDefs_6502.h"
#define OPERAND_BODY "operandBody_6502.h"
#define CONDITION_DEFS "conditionDefs_6502.h"
#define TARGET_CPU_STRING "6502"
#elif TARGET_CPU == CPU_68000
#define OPERAND_DEFS "operandDefs_68000.h"
#define OPERAND_BODY "operandBody_68000.h"
#define CONDITION_DEFS "conditionDefs_68000.h"
#define TARGET_CPU_STRING "MC68000"
#endif
/*
General types -- These data types are just useful for dealing with the
world at large.
*/
typedef int nullType; /* for nothingness */
typedef char anyOldThing; /* for storage allocators */
typedef int bool; /* for logical operations */
#define FALSE 0
#define TRUE 1
typedef unsigned char byte;
typedef unsigned short wordType;
typedef unsigned long longType;
typedef unsigned long bigWord;
typedef union { /* lets us build or take */
wordType wordPart; /* apart a word while */
byte bytePart[2]; /* keeping control over */
} byteToWordType;/* byte order. */
/* which element of bytePart is the low order byte and which is the high
order byte is host-system dependent! */
typedef union { /* lets us build or take */
longType longPart; /* apart a long while */
byte bytePart[4]; /* keeping control over */
} byteToLongType;/* byte order. */
/* which element of bytePart is the low order byte and which is the high
order byte is host-system dependent! */
typedef char stringType; /* sometimes...because
although a char is not a
string, a pointer to a char *is* a pointer to a string and pointers are what
we care about. We never declare anything to be 'stringType' but we'll declare
lots of things 'stringType *' */
typedef long addressType; /* address on the target
processor, not the host
processor */
/*
Values: the values of Macross expressions, instruction operands, and so on
are kept track of internally using objects of 'valueType'. This is a
struct consisting of the value itself together with something telling what
kind of value it is (string, relocatable address, etc.) and what address
mode is associated with it (direct, indirect, etc.).
*/
typedef enum {
ABSOLUTE_VALUE, DATA_VALUE, RELOCATABLE_VALUE, BSS_VALUE,
STRUCT_VALUE, FIELD_VALUE, MACRO_VALUE, OPERAND_VALUE, STRING_VALUE,
CONDITION_VALUE, UNDEFINED_VALUE, FUNCTION_VALUE, BLOCK_VALUE,
BUILT_IN_FUNCTION_VALUE, ARRAY_VALUE, FAIL
} valueKindType;
#define NUM_OF_VALUE_KINDS 16 /* C really could benefit from a
'cardinality-of-enumerated-type' operator */
#define ABSOLUTE_VALUE_BIT 0x0001
#define DATA_VALUE_BIT 0x0002
#define RELOCATABLE_VALUE_BIT 0x0004
#define BSS_VALUE_BIT 0x0008
#define STRUCT_VALUE_BIT 0x0010
#define FIELD_VALUE_BIT 0x0020
#define MACRO_VALUE_BIT 0x0040
#define OPERAND_VALUE_BIT 0x0080
#define STRING_VALUE_BIT 0x0100
#define CONDITION_VALUE_BIT 0x0200
#define UNDEFINED_VALUE_BIT 0x0400
#define FUNCTION_VALUE_BIT 0x0800
#define BLOCK_VALUE_BIT 0x1000
#define BUILT_IN_FUNCTION_VALUE_BIT 0x2000
#define ARRAY_VALUE_BIT 0x4000
#define FAIL_BIT 0x8000
#include OPERAND_DEFS
typedef struct {
valueKindType kindOfValue;
int value;
operandKindType addressMode;
} valueType;
typedef struct {
int arraySize;
valueType **arrayContents;
} arrayType;
/*
Input files are kept track of using 'fileNameListType'. A linked list of
these structs is built with one entry for each input file given on the
command line. Include files are pushed onto the head of this list. Thus,
the standard action upon reading an EOF is to pop the list. When the list
is empty, we're done!
*/
typedef struct fileNameListStruct {
char *name;
FILE *fildes;
bool openFlag;
int lineNumber;
struct fileNameListStruct *nextFileName;
} fileNameListType;
typedef struct commandLineDefineStruct {
char *name;
int value;
struct commandLineDefineStruct *nextDefine;
} commandLineDefineType;
/*
Internal tables
*/
/* Symbol table: all user-defined symbols are kept in the symbol table. Each
symbol has but one entry. Associated with each such entry is a list of
'symbolInContextType's that contain information pertaining to particular
uses of individual symbols. This is how we handle scoping in function and
macro calls. */
typedef int symbolAttributesType; /* Symbol attributes */
#define GLOBAL_ATT 0x01 /* are orthogonal to symbol */
#define ZERO_PAGE_ATT 0x02 /* type */
#define DEFINED_VARIABLE_ATT 0x04
#define SYMBOL_USED_ATT 0x08
#define SPECIAL_FUNCTION_ATT 0x10
#define TENTATIVE_GLOBAL_ATT 0x20
typedef enum {
STRUCT_NAME_SYMBOL, STRUCT_FIELD_SYMBOL, MACRO_SYMBOL,
ARGUMENT_SYMBOL, LABEL_SYMBOL, EXTERNAL_SYMBOL,
VARIABLE_SYMBOL, MVARIABLE_SYMBOL, UNKNOWN_SYMBOL,
DEAD_SYMBOL, FUNCTION_SYMBOL, BUILT_IN_FUNCTION_SYMBOL,
NESTED_UNKNOWN_SYMBOL, DEFINE_SYMBOL, MDEFINE_SYMBOL,
UNKNOWN_FUNCTION_SYMBOL, UNKNOWN_MACRO_SYMBOL,
} symbolUsageKindType;
#define NUM_OF_SYM_USAGES 17
typedef struct symbolInContextStruct {
valueType *value;
symbolUsageKindType usage;
symbolAttributesType attributes;
int referenceCount;
struct symbolInContextStruct *pushedContexts;
int environmentNumber;
int definingLineNumber;
char *definingFileName;
} symbolInContextType;
#define GLOBAL_ENVIRONMENT_NUMBER 0
typedef struct environmentStruct {
int environmentNumber;
struct environmentStruct *previousEnvironment;
} environmentType;
#define pushEnvironment(newEnv) {\
newEnv.environmentNumber = nextEnvironmentNumber++;\
newEnv.previousEnvironment = currentEnvironment;\
currentEnvironment = &newEnv;\
}
#define popEnvironment() currentEnvironment = currentEnvironment->\
previousEnvironment;
typedef struct symbolTableEntryStruct {
stringType *symbolName;
struct symbolTableEntryStruct *nextSymbol;
symbolInContextType *context;
int ordinal;
int referenceCount;
} symbolTableEntryType;
#define symbName(sptr) ((sptr)->symbolName)
/* symbolClass bits */
#define SYMBOL_UNDEFINED 0x00
#define SYMBOL_ABSOLUTE 0x02
#define SYMBOL_RELOCATABLE 0x04
#define SYMBOL_EXTERNAL 0x01
typedef struct {
byte symbolClass; /* see above */
int symbolValue;
} objectSymbolType;
/* These structs are used to allow us to put symbols in the object file */
#define MODE_ABSOLUTE 0
#define MODE_RELOCATABLE 1
#define REF_BYTE 0
#define REF_WORD 1
#define REF_DBYTE 2
#define REF_LONG 3
typedef struct {
bigWord referenceAddress : 24, /* target machine address */
referenceMode : 1, /* see above MODE_xx defines*/
referenceRelative : 1, /* TRUE==is relative */
referenceKind : 3, /* see above REF_xx defines */
referenceExternal : 1, /* TRUE==is ref to external */
: 2; /* unused bits */
int referenceExpression; /* local expression ordinal */
} expressionReferenceType;
#define ExpressionType struct expressionTermStruct
typedef struct expressionReferenceListStruct {
expressionReferenceType relocation;
struct expressionReferenceListStruct *nextReference;
ExpressionType *expressionReferenced;
} expressionReferenceListType;
/* These are sort of 'forward references' to types used in the construction of
parse trees, but they are refered to by various internal tables and so have
to go here, rather than with the other parse-tree types. */
#define BlockType struct statementStruct
#define IdentifierListType struct identifierListStruct
#define IdentifierListHeadType struct identifierListHeadStruct
typedef symbolTableEntryType argumentType;
typedef struct argumentDefinitionListStruct {
argumentType *theArgument;
struct argumentDefinitionListStruct *nextArgument;
} argumentDefinitionListType;
typedef struct {
argumentType *theArgument;
argumentDefinitionListType *nextArgument;
argumentDefinitionListType *tail;
bool arrayTag;
} argumentListHeadType;
/* Macros: */
typedef struct macroTableEntryStruct {
stringType *macroName;
struct macroTableEntryStruct *nextMacro;
argumentDefinitionListType *arguments;
BlockType *body;
} macroTableEntryType;
/* Functions: */
typedef struct functionDefinitionStruct {
symbolTableEntryType *functionName;
argumentDefinitionListType *arguments;
BlockType *body;
int ordinal;
struct functionDefinitionStruct *nextExternalFunction;
} functionDefinitionType;
typedef struct opcodeTableEntryStruct {
stringType *mnemonic;
struct opcodeTableEntryStruct *nextOpcode;
unsigned int opcode;
addressClassType addressClass;
int permissibleOperandModes;
int minNumberOfOperands;
int maxNumberOfOperands;
int subClass;
} opcodeTableEntryType;
/* Macross keywords: */
typedef struct keywordTableEntryStruct {
stringType *string;
struct keywordTableEntryStruct *nextKeyword;
int token;
} keywordTableEntryType;
/* All the various things that are stored in tables, like keywords, symbols
and macro names, are stored with a common format to the head of the struct
that defines them, so that a set of generic table handling routines may be
written. These routines look at the following type: */
typedef struct genericTableEntryStruct {
stringType *string;
struct genericTableEntryStruct *next;
} genericTableEntryType;
/*
Parser types -- These data types define the parse-tree data structure
which is constructed during the parse phase of assembly. This is the form
in which statements are stored internally prior to being turned into
object code, as well as the form in which macros and functions are
remembered.
The exposition of the types is by necessity bottom-up. That's C.
*/
typedef int postOpKindType;
typedef struct {
postOpKindType postOp;
ExpressionType *postOpArgument;
} postOpTermType;
typedef int preOpKindType;
typedef struct {
preOpKindType preOp;
ExpressionType *preOpArgument;
} preOpTermType;
typedef int unopKindType;
typedef int binopKindType;
typedef enum {
ASSIGN_ASSIGN, ADD_ASSIGN, SUB_ASSIGN, MUL_ASSIGN, DIV_ASSIGN,
MOD_ASSIGN, AND_ASSIGN, OR_ASSIGN, XOR_ASSIGN,
LEFT_SHIFT_ASSIGN, RIGHT_SHIFT_ASSIGN, NO_ASSIGN
} assignmentKindType;
typedef struct {
unopKindType unop;
ExpressionType *unopArgument;
} unopTermType;
typedef struct {
binopKindType binop;
ExpressionType *leftArgument;
ExpressionType *rightArgument;
} binopTermType;
#define ExpressionListType struct expressionListStruct
typedef struct {
ExpressionType *arrayName;
ExpressionType *arrayIndex;
} arrayTermType;
typedef ExpressionType subexpressionTermType;
typedef int numberTermType;
#define OperandListType struct operandStruct
typedef struct {
symbolTableEntryType *functionName;
OperandListType *parameters;
} functionCallTermType;
typedef symbolTableEntryType identifierTermType;
typedef nullType hereTermType;
#include CONDITION_DEFS
typedef struct conditionTableEntryStruct {
stringType *string;
struct conditionTableEntryStruct *nextCondition;
conditionType code;
} conditionTableEntryType;
typedef conditionType conditionCodeTermType;
typedef stringType stringTermType;
typedef enum {
IDENTIFIER_EXPR, FUNCTION_CALL_EXPR, NUMBER_EXPR,
SUBEXPRESSION_EXPR, UNOP_EXPR, BINOP_EXPR, PREOP_EXPR,
POSTOP_EXPR, HERE_EXPR, ASSIGN_EXPR, CONDITION_CODE_EXPR,
STRING_EXPR, VALUE_EXPR, ARRAY_EXPR,
} expressionTermKindType;
typedef union expressionTermBodyUnion {
identifierTermType *identifierUnion;
functionCallTermType *functionCallUnion;
numberTermType numberUnion;
conditionCodeTermType conditionCodeUnion;
subexpressionTermType *subexpressionUnion;
unopTermType *unopUnion;
binopTermType *binopUnion;
preOpTermType *preOpUnion;
postOpTermType *postOpUnion;
hereTermType *hereUnion;
stringTermType *stringUnion;
arrayTermType *arrayUnion;
valueType *valueUnion;
symbolTableEntryType *symbolTableUnion;
conditionType conditionTypeUnion;
void *expressionUnion; /* this should be expressionTermType, but there's a cycle */
} expressionTermBodyType;
typedef struct expressionTermStruct {
expressionTermKindType kindOfTerm;
expressionTermBodyType expressionTerm;
} expressionTermType;
typedef expressionTermType expressionType;
typedef enum {
BYTE_FIXUP, WORD_FIXUP, NO_FIXUP, OPERAND_FIXUP,
BYTE_RELATIVE_FIXUP, DBYTE_FIXUP, NO_FIXUP_OK, LONG_FIXUP,
WORD_RELATIVE_FIXUP,
} fixupKindType;
typedef enum {
ABSOLUTE_BUFFER, RELOCATABLE_BUFFER,
} codeBufferKindType;
#define LAST_BUFFER_KIND ((int)RELOCATABLE_BUFFER)
#define STRUCT_BUFFER (LAST_BUFFER_KIND + 1)
typedef struct fixupListStruct {
addressType locationToFixup;
codeBufferKindType codeMode;
fixupKindType kindOfFixup;
expressionType *theFixupExpression;
int targetOffset;
stringType *fileName;
int lineNumber;
struct fixupListStruct *nextFixup;
} fixupListType;
typedef struct simpleFixupListStruct {
valueType locationToFixup;
struct simpleFixupListStruct *nextFixup;
} simpleFixupListType;
typedef expressionType performStatementBodyType;
typedef expressionType orgStatementBodyType;
typedef expressionType targetStatementBodyType;
typedef expressionType startStatementBodyType;
typedef struct identifierListStruct {
symbolTableEntryType *theSymbol;
struct identifierListStruct *nextIdentifier;
} identifierListType;
typedef struct identifierListHeadStruct {
symbolTableEntryType *theSymbol;
struct identifierListStruct *nextIdentifier;
identifierListType *tail;
} identifierListHeadType;
typedef identifierListType externStatementBodyType;
#define StatementListType struct statementStruct
typedef BlockType structBodyType;
typedef struct {
structBodyType *structBody;
symbolTableEntryType *structName;
} structStatementBodyType;
typedef enum {
UNTIL_END, WHILE_END
} doEndKindType;
typedef struct {
doEndKindType mdoEndKind;
expressionType *mdoEndCondition;
} mdoEndType;
typedef struct {
expressionType *mdoUntilCondition;
BlockType *mdoUntilLoop;
} mdoUntilStatementBodyType;
typedef struct {
expressionType *mdoWhileCondition;
BlockType *mdoWhileLoop;
} mdoWhileStatementBodyType;
typedef struct {
expressionType *mwhileCondition;
BlockType *mwhileLoop;
} mwhileStatementBodyType;
typedef struct {
expressionType *initExpression;
expressionType *testExpression;
expressionType *incrExpression;
} forExpressionsType;
typedef struct {
expressionType *initExpression;
expressionType *testExpression;
expressionType *incrExpression;
BlockType *forLoop;
} mforStatementBodyType;
#define MifStatementBodyType struct mifStatementBodyStruct
typedef MifStatementBodyType mifContinuationBodyType;
typedef union {
mifContinuationBodyType *mifContinuationBodyUnion;
BlockType *mifBlockUnion;
} mifContinuationType;
typedef struct {
expressionType *headCondition;
BlockType *headBody;
} mifHeadType;
typedef struct mifStatementBodyStruct {
expressionType *mifCondition;
BlockType *mifConsequence;
mifContinuationType mifContinuation;
} mifStatementBodyType;
typedef identifierListType undefineStatementBodyType;
typedef struct {
macroTableEntryType *theMacro;
argumentDefinitionListType *theArguments;
BlockType *theBlock;
} macroStatementBodyType;
typedef struct {
stringType *functionName;
argumentDefinitionListType *theArguments;
BlockType *theBlock;
} functionStatementBodyType;
typedef struct {
symbolTableEntryType *theSymbol;
expressionType *theValue;
} defineStatementBodyType;
typedef struct {
symbolTableEntryType *theSymbol;
expressionType *theValue;
} mdefineStatementBodyType;
typedef struct {
symbolTableEntryType *theSymbol;
ExpressionListType *theValue;
expressionType *theDimension;
} variableStatementBodyType;
typedef struct {
symbolTableEntryType *theSymbol;
ExpressionListType *theValue;
expressionType *theDimension;
} mvariableStatementBodyType;
typedef identifierListType selectionListType;
typedef identifierListHeadType selectionListHeadType;
#include OPERAND_BODY
typedef struct operandStruct {
operandKindType kindOfOperand;
operandBodyType theOperand;
struct operandStruct *nextOperand;
} operandType;
typedef struct {
operandKindType kindOfOperand;
valueType *theOperand;
} operandValueType;
typedef expressionType freturnStatementBodyType;
typedef operandType operandListType;
typedef struct {
operandKindType kindOfOperand;
operandBodyType theOperand;
operandListType *nextOperand;
operandListType *tail;
} operandListHeadType;
typedef union {
opcodeTableEntryType *opcodeUnion;
macroTableEntryType *macroUnion;
} instructionType;
typedef enum {
OPCODE_INSTRUCTION, MACRO_INSTRUCTION
} instructionKindType;
typedef struct {
instructionKindType kindOfInstruction;
instructionType theInstruction;
operandListType *theOperands;
} instructionStatementBodyType;
typedef expressionType includeStatementBodyType;
typedef struct expressionListStruct {
expressionType *theExpression;
struct expressionListStruct *nextExpression;
} expressionListType;
typedef struct {
expressionType *theExpression;
expressionListType *nextExpression;
expressionListType *tail;
} expressionListHeadType;
typedef expressionListType stringStatementBodyType;
typedef expressionListType byteStatementBodyType;
typedef expressionListType dbyteStatementBodyType;
typedef expressionType alignStatementBodyType;
typedef expressionListType wordStatementBodyType;
typedef expressionListType longStatementBodyType;
typedef struct {
doEndKindType doEndKind;
conditionType doEndCondition;
} doEndType;
typedef struct {
conditionType doUntilCondition;
BlockType *doUntilLoop;
} doUntilStatementBodyType;
typedef struct {
conditionType doWhileCondition;
BlockType *doWhileLoop;
} doWhileStatementBodyType;
typedef struct {
conditionType whileCondition;
BlockType *whileLoop;
} whileStatementBodyType;
#define IfStatementBodyType struct ifStatementBodyStruct
typedef enum {
NO_CONTINUATION, ELSE_CONTINUATION, ELSEIF_CONTINUATION
} ifContinuationKindType;
typedef IfStatementBodyType ifContinuationBodyType;
typedef union {
ifContinuationBodyType *continuationBodyUnion;
BlockType *blockUnion;
} ifContinuationType;
typedef struct {
conditionType headCondition;
BlockType *headBody;
} ifHeadType;
typedef struct ifStatementBodyStruct {
conditionType ifCondition;
BlockType *consequence;
ifContinuationType continuation;
} ifStatementBodyType;
typedef struct {
expressionType *constraint;
BlockType *constrainedBlock;
} constrainStatementBodyType;
typedef struct {
expressionType *condition;
expressionType *message;
} assertStatementBodyType;
typedef struct {
expressionListType *caseTags;
BlockType *caseBody;
} caseType;
typedef struct caseListStruct {
caseType *theCase;
struct caseListStruct *nextCase;
} caseListType;
typedef struct {
caseType *theCase;
caseListType *nextCase;
caseListType *tail;
} caseListHeadType;
typedef struct {
expressionType *switchExpression;
caseListType *cases;
} mswitchStatementBodyType;
typedef nullType relStatementBodyType;
typedef expressionListType blockStatementBodyType;
typedef BlockType groupStatementBodyType;
typedef union {
ifStatementBodyType *ifUnion;
whileStatementBodyType *whileUnion;
doWhileStatementBodyType *doWhileUnion;
doUntilStatementBodyType *doUntilUnion;
wordStatementBodyType *wordUnion;
dbyteStatementBodyType *dbyteUnion;
byteStatementBodyType *byteUnion;
stringStatementBodyType *stringUnion;
blockStatementBodyType *blockUnion;
structStatementBodyType *structUnion;
instructionStatementBodyType *instructionUnion;
defineStatementBodyType *defineUnion;
mdefineStatementBodyType *mdefineUnion;
variableStatementBodyType *variableUnion;
mvariableStatementBodyType *mvariableUnion;
macroStatementBodyType *macroUnion;
functionStatementBodyType *functionUnion;
undefineStatementBodyType *undefineUnion;
mifStatementBodyType *mifUnion;
freturnStatementBodyType *freturnUnion;
mforStatementBodyType *mforUnion;
mwhileStatementBodyType *mwhileUnion;
mdoWhileStatementBodyType *mdoWhileUnion;
mdoUntilStatementBodyType *mdoUntilUnion;
includeStatementBodyType *includeUnion;
externStatementBodyType *externUnion;
startStatementBodyType *startUnion;
alignStatementBodyType *alignUnion;
orgStatementBodyType *orgUnion;
targetStatementBodyType *targetUnion;
relStatementBodyType *relUnion;
performStatementBodyType *performUnion;
groupStatementBodyType *groupUnion;
constrainStatementBodyType *constrainUnion;
assertStatementBodyType *assertUnion;
mswitchStatementBodyType *mswitchUnion;
longStatementBodyType *longUnion;
expressionType *expressionUnion;
} statementBodyType;
typedef enum {
IF_STATEMENT, WHILE_STATEMENT, DO_WHILE_STATEMENT,
DO_UNTIL_STATEMENT, WORD_STATEMENT, DBYTE_STATEMENT,
BYTE_STATEMENT, STRING_STATEMENT, STRUCT_STATEMENT,
INSTRUCTION_STATEMENT, DEFINE_STATEMENT,
UNDEFINE_STATEMENT, MIF_STATEMENT,
FRETURN_STATEMENT, MFOR_STATEMENT, MDO_WHILE_STATEMENT,
MDO_UNTIL_STATEMENT, INCLUDE_STATEMENT, EXTERN_STATEMENT,
START_STATEMENT, ALIGN_STATEMENT, ORG_STATEMENT,
REL_STATEMENT, PERFORM_STATEMENT, BLOCK_STATEMENT,
MWHILE_STATEMENT, MDEFINE_STATEMENT, NULL_STATEMENT,
GROUP_STATEMENT, MACRO_STATEMENT, FUNCTION_STATEMENT,
VARIABLE_STATEMENT, MVARIABLE_STATEMENT, CONSTRAIN_STATEMENT,
ASSERT_STATEMENT, MSWITCH_STATEMENT, LONG_STATEMENT,
TARGET_STATEMENT,
} statementKindType;
typedef struct labelStruct {
symbolTableEntryType *theLabel;
struct labelStruct *nextLabel;
} labelType;
typedef labelType labelListType;
typedef struct {
symbolTableEntryType *theLabel;
labelListType *nextLabel;
labelListType *tail;
} labelListHeadType;
typedef struct statementStruct {
statementKindType kindOfStatement;
labelListType *labels;
statementBodyType statementBody;
struct statementStruct *nextStatement;
stringType *fileName;
int lineNumber;
int cumulativeLineNumber;
} statementType;
typedef statementType statementListType;
typedef statementListType blockType;
typedef struct {
statementKindType kindOfStatement;
labelListType *labels;
statementBodyType statementBody;
statementListType *nextStatement;
stringType *fileName;
int lineNumber;
int cumulativeLineNumber;
statementListType *tail;
} statementListHeadType;
typedef statementListType programType;
/* End of parse-tree types */
#define UNASSIGNED NULL
#define MAX_NAME_SIZE 300
/* Struct instances */
#define MAXIMUM_ALLOWED_STRUCT_SIZE 255
typedef struct {
int structSize;
byte *structMap;
fixupListType *structFixups;
expressionReferenceListType *structReferences;
} structInstanceType;
/* Code output buffers */
#define CODE_BUFFER_SIZE 1024
#if TARGET_CPU == CPU_6502
#define CODE_BUFFERS_IN_ADDRESS_SPACE 64
#elif TARGET_CPU == CPU_68000
#define CODE_BUFFERS_IN_ADDRESS_SPACE 256
#endif
#define bufferNumber(addr) ((addr)/CODE_BUFFER_SIZE)
#define bufferPosition(addr) ((addr)%CODE_BUFFER_SIZE)
typedef byte codeBufferType[CODE_BUFFER_SIZE];
typedef enum {
BREAK_BREAK, ALIGN_BREAK, CONSTRAIN_BREAK,
END_CONSTRAIN_BREAK,
} codeBreakKindType;
typedef struct codeBreakStruct {
codeBreakKindType kindOfBreak;
addressType breakAddress;
int breakData;
struct codeBreakStruct *nextBreak;
} codeBreakType;
typedef struct {
addressType codeStartAddress;
addressType codeEndAddress;
codeBufferType *codeBuffer;
} codeSegmentType;
typedef struct {
addressType regionStartAddress;
addressType regionEndAddress;
codeSegmentType *codeSegments[
CODE_BUFFERS_IN_ADDRESS_SPACE];
} codeRegionType;
typedef struct reservationListStruct {
addressType startAddress;
int blockSize;
struct reservationListStruct *nextReservation;
} reservationListType;
#define LINE_BUFFER_SIZE 300
/* Error types */
typedef enum {
DEFINE_ASSIGNMENT_WRONG_ERROR,
DIGIT_OUT_OF_RADIX_ERROR,
UNCLOSED_CHARACTER_CONSTANT_ERROR,
UNCLOSED_STRING_CONSTANT_ERROR,
OCTAL_CHARACTER_TOO_BIG_ERROR,
UNRECOGNIZED_SOMETHING_OR_OTHER_ERROR,
UNCLOSED_COMMENT_ERROR,
UNCLOSED_LINE_COMMENT_ERROR,
UNABLE_TO_OPEN_PASS_2_FILE_ERROR,
BAD_ORG_ADDRESS_ERROR,
NEGATIVE_BLOCK_SIZE_ERROR,
UNASSIGNABLE_SYMBOL_TYPE_ERROR,
INCOMPATIBLE_ASSIGNMENT_OPERANDS_ERROR,
INCOMPATIBLE_BINOP_OPERANDS_ERROR,
UNPOSTINCREMENTABLE_OPERAND_ERROR,
UNPOSTDECREMENTABLE_OPERAND_ERROR,
UNPREINCREMENTABLE_OPERAND_ERROR,
UNPREDECREMENTABLE_OPERAND_ERROR,
INCOMPATIBLE_UNOP_OPERAND_ERROR,
VALUE_IS_NOT_AN_ADDRESS_ERROR,
VALUE_IS_NOT_AN_INT_ERROR,
IMPROPER_ALIGNMENT_VALUE_ERROR,
OPERATOR_ASSIGNMENT_ON_NULL_TARGET_ERROR,
TOO_MANY_INSTRUCTION_OPERANDS_ERROR,
ILLEGAL_OPERAND_TYPE_ERROR,
BYTE_VALUE_TOO_LARGE_ERROR,
WORD_VALUE_TOO_LARGE_ERROR,
BAD_INSTRUCTION_OPERAND_ERROR,
DIVIDE_BY_ZERO_ERROR,
UNDEFINED_SYMBOL_ERROR,
RELATIVE_OFFSET_TOO_LARGE_ERROR,
LABEL_ALREADY_DEFINED_ERROR,
CANT_OPEN_OBJECT_FILE_ERROR,
BAD_KIND_OF_SYMBOL_TO_MAKE_EXTERNAL_ERROR,
MORE_THAN_ONE_OUTPUT_FILE_ERROR,
BAD_COMMAND_LINE_FLAG_ERROR,
NO_DASH_O_FILE_NAME_ERROR,
UNABLE_TO_OPEN_INPUT_FILE_ERROR,
UNABLE_TO_OPEN_INCLUDE_FILE_ERROR,
INVALID_BOOLEAN_VALUE_ERROR,
SYMBOL_ALREADY_THERE_ERROR,
UNDECLARED_VARIABLE_ERROR,
REDEFINITION_OF_SYMBOL_ERROR,
NOT_A_STRUCT_NAME_ERROR,
STRUCT_TOO_BIG_ERROR,
FIELD_ALREADY_DEFINED_ERROR,
STRUCT_DEFINITION_INSIDE_STRUCT_DEFINITION_ERROR,
VALUE_IS_NOT_A_FIELD_ERROR,
MACRO_ALREADY_EXISTS_ERROR,
MACRO_DEFINITION_INSIDE_MACRO_ERROR,
TOO_MANY_ARGUMENTS_TO_MACRO_ERROR,
FUNCTION_DEFINITION_INSIDE_FUNCTION_ERROR,
FUNCTION_ALREADY_EXISTS_ERROR,
TOO_MANY_ARGUMENTS_TO_FUNCTION_ERROR,
NOT_A_FUNCTION_ERROR,
FUNCTION_DID_NOT_RETURN_A_VALUE_ERROR,
BAD_ADDRESS_MODE_ERROR,
MULTIPLE_ADDRESS_MODES_ERROR,
INCLUDE_FILE_NOT_A_STRING_VALUE_ERROR,
START_ADDRESS_ALREADY_GIVEN_ERROR,
FUNCTION_IS_NOT_A_VALUE_ERROR,
SIDE_EFFECT_ERROR,
CANT_FIND_SYMBOL_ERROR,
ERROR_INSIDE_MACRO_ERROR,
ERROR_INSIDE_FUNCTION_ERROR,
NO_LIST_FILE_NAME_ERROR,
NO_SYMBOL_DUMP_FILE_NAME_ERROR,
MORE_THAN_ONE_LIST_FILE_ERROR,
MORE_THAN_ONE_SYMBOL_DUMP_FILE_ERROR,
CANT_OPEN_LIST_FILE_ERROR,
CANT_OPEN_SYMBOL_DUMP_FILE_ERROR,
FILE_NAME_IS_NOT_MACROSS_SOURCE_ERROR,
OUTPUT_FILE_NAME_IS_MACROSS_SOURCE_ERROR,
LIST_FILE_NAME_IS_MACROSS_SOURCE_ERROR,
SYMBOL_DUMP_FILE_NAME_IS_MACROSS_SOURCE_ERROR,