forked from Macroassembler-AS/asl-releases
-
Notifications
You must be signed in to change notification settings - Fork 0
/
as.c
4835 lines (4129 loc) · 111 KB
/
as.c
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
/* as.c */
/*****************************************************************************/
/* AS-Portierung */
/* */
/* Hauptmodul */
/* */
/* Historie: 4. 5.1996 Grundsteinlegung */
/* 24. 6.1998 Zeichenuebersetzungstabellen */
/* 30. 6.1998 Ausgabe in MacPro-File auch wenn Zeile nur aus */
/* Kommentar oder Label besteht */
/* 18. 7.1998 IRPC-Statement */
/* 24. 7.1998 Debug-Modus NoICE */
/* 25. 7.1998 Formate glattgezogen */
/* 16. 8.1998 Datei-Adressbereiche zuruecksetzen */
/* 17. 8.1998 InMacroFlag nach asmdef verschoben */
/* 19. 8.1998 BranchExt-Initialisierung */
/* 25. 8.1998 i960-Initialisierung */
/* 28. 8.1998 32-Bit-Listen gehen auch korrekt mit */
/* Codelaengen != 4*n um */
/* 30. 8.1998 uPD7720-Initialisierung */
/* Einrueckung fuer 'R' in Retracted-Zeilen im Listing */
/* war nicht korrekt */
/* 13. 9.1998 uPD77230-Initialisierung */
/* 30. 9.1998 SYM53C8xx-Initialisierung */
/* 3.12.1998 8008-Initialisierung */
/* 9. 1.1999 PCs erst nach Schreiben des Codes hochzaehlen */
/* ChkPC mit Adresse als Parameter */
/* 30. 1.1999 Formate maschinenunabhaengig gemacht */
/* 12. 2.1999 Compilerwarnungen beseitigt */
/* 25. 3.1999 SC14xxx-Initialisierung */
/* 17. 4.1999 CPU per Kommandozeile setzen */
/* 18. 4.1999 Ausgabeliste Sharefiles */
/* 4. 7.1999 F2MC8-Initialisierung */
/* 8. 8.1999 Externliste immer am Ende einer Zeile loeschen */
/* 14. 8.1999 Initialisierung ACE */
/* 5.11.1999 ExtendErrors, 2. Stufe */
/* 19.11.1999 F2MC16-Initialisierung */
/* 4.12.1999 IRP/REPT-Zeilenangabe in Klammern */
/* 9. 1.2000 Zeilenzaehler mit plattformabhaengigem Formatstring */
/* 13. 2.2000 Ausgabename fuer Listing setzen */
/* 8. 3.2000 'ambigious else'-Warnungen beseitigt */
/* 20. 5.2000 added ArgCName, expansion of macro argument count */
/* 21. 5.2000 added TmpSymCounter initialization */
/* 1. 6.2000 REPT/WHILE/IRP(C) not expanded without IfAsm */
/* added maximum nesting level for macros */
/* 24.12.2000 added -noicemask option */
/* 14. 1.2001 silenced warnings about unused parameters */
/* set 'segment used' flag once code is generated */
/* 27. 1.2001 added 1802 initialization */
/* 24. 3.2001 correctly handle predefined symbols when operating */
/* in case-sensitive mode */
/* 9. 6.2001 moved initialization of DoPadding before CPU-specific*/
/* initialization, to allow CPU-specific override */
/* 2001-07-07 added intiialization of C54x generator */
/* 2001-10-20 GNU error style possible */
/* 2001-12-31 added IntLabel directive */
/* 2002-01-26 changed end behaviour of while statement */
/* 2002-03-03 use FromFile, LineRun fields in input tag */
/* */
/*****************************************************************************/
/* $Id: as.c,v 1.72 2017/06/16 19:06:08 alfred Exp $ */
/*****************************************************************************
* $Log: as.c,v $
* Revision 1.72 2017/06/16 19:06:08 alfred
* - correct some overlapping strcpy() uses
*
* Revision 1.71 2017/04/02 11:10:36 alfred
* - allow more fine-grained macro expansion in listing
*
* Revision 1.70 2017/02/26 16:20:46 alfred
* - silence compiler warnings about unused function results
*
* Revision 1.69 2016/11/25 18:12:12 alfred
* - first version to support OLMS-50
*
* Revision 1.68 2016/11/01 11:48:04 alfred
* - add support for OKI OLMS-40
*
* Revision 1.67 2016/10/09 19:55:52 alfred
* - first version of MIL STD 1750 support
*
* Revision 1.66 2016/09/30 19:37:17 alfred
* - renamed HMCS40x to HMCS400
*
* Revision 1.65 2016/09/25 20:31:20 alfred
* - add HMCS4x target
*
* Revision 1.64 2016/08/30 13:48:22 alfred
* - yet another TC9331 speciality in the parser...
*
* Revision 1.63 2016/08/30 10:08:17 alfred
* - regard empty OpPart with arguments
*
* Revision 1.62 2016/08/29 21:10:43 alfred
* - begun with TC9331
*
* Revision 1.61 2016/08/29 17:07:04 alfred
* - if last argument was empty, trailing blanks on second-last argument were not removed
*
* Revision 1.60 2016/08/26 19:03:56 alfred
* - remove separate C4x decoder (was folded into C3x)
*
* Revision 1.59 2016/08/25 20:43:02 alfred
* - C4x will be realized as extension of C3x target
*
* Revision 1.58 2016/08/24 12:13:18 alfred
* - begun with 320C4x support
*
* Revision 1.57 2016/08/10 21:06:22 alfred
* - begun with 78K3 support
*
* Revision 1.56 2016/06/23 15:57:21 alfred
* - correct code output in respect to structure expansion
*
* Revision 1.55 2015/10/25 20:06:11 alfred
* - regard new END... struction/union instructions
*
* Revision 1.54 2015/10/23 08:43:33 alfred
* - beef up & fix structure handling
*
* Revision 1.53 2015/10/18 20:08:52 alfred
* - when expanding structure, also regard sub-structures
*
* Revision 1.52 2015/10/18 19:02:15 alfred
* - first reork/fix of nested structure handling
*
* Revision 1.51 2015/08/28 17:22:26 alfred
* - add special handling for labels following BSR
*
* Revision 1.50 2015/08/05 18:28:05 alfred
* - correct initial construction of ALLARGS, compute ALLARGS/NUMARGS only if needed
*
* Revision 1.49 2015/08/03 18:25:37 alfred
* - add excess macro arguments to argument list for usage with SHIFT
*
* Revision 1.48 2015/04/20 18:40:29 alfred
* - add TMS1000 support (no docs yet)
*
* Revision 1.47 2015/01/04 20:33:42 alfred
* - avoid double build in parallel make
* - begun with disassembler
*
* Revision 1.46 2014/12/14 17:58:46 alfred
* - remove static variables in strutil.c
*
* Revision 1.45 2014/12/02 13:33:19 alfred
* - do not use strncpy()
*
* Revision 1.44 2014/11/23 18:52:36 alfred
* - use common allocator for OUTProcessor
*
* Revision 1.43 2014/11/23 18:27:09 alfred
* - remove trailing blanks
*
* Revision 1.42 2014/11/17 23:51:31 alfred
* - begun with TLCS-870/C
*
* Revision 1.41 2014/11/17 21:20:24 alfred
* - rework to current style
*
* Revision 1.40 2014/11/16 18:52:07 alfred
* - first step of rework
*
* Revision 1.39 2014/11/06 11:22:01 alfred
* - replace hook chain for ClearUp, document new mechanism
*
* Revision 1.38 2014/11/05 15:47:13 alfred
* - replace InitPass callchain with registry
*
* Revision 1.37 2014/11/05 09:19:39 alfred
* - remove static string
*
* Revision 1.36 2014/10/26 20:52:32 alfred
* - cleanup tag only right before destruction because contents may be needed for GetPos()
*
* Revision 1.35 2014/10/26 20:43:11 alfred
* - correct usage of parameter counter in IRP get position function
*
* Revision 1.34 2014/10/06 17:54:56 alfred
* - display filename if include failed
* - some valgrind workaraounds
*
* Revision 1.33 2014/09/21 13:15:16 alfred
* - assure structure is initialized
*
* Revision 1.32 2014/09/14 13:22:32 alfred
* - ass keyword arguments
*
* Revision 1.31 2014/06/15 09:17:08 alfred
* - optional Memo profiling
*
* Revision 1.30 2014/05/29 10:59:05 alfred
* - some const cleanups
*
* Revision 1.29 2013/12/21 19:46:50 alfred
* - dynamically resize code buffer
*
* Revision 1.28 2013/12/17 18:54:17 alfred
* - correct local symbol handle processing in IRPC
*
* Revision 1.27 2013-03-09 16:15:07 alfred
* - add NEC 75xx
*
* Revision 1.26 2013-03-09 07:54:38 alfred
* - add GLOBALSYMBOLS option
*
* Revision 1.25 2012-07-22 11:51:45 alfred
* - begun with XCore target
*
* Revision 1.24 2012-05-26 13:49:19 alfred
* - MSP additions, make implicit macro parameters always case-insensitive
*
* Revision 1.23 2012-01-14 14:34:58 alfred
* - add some platforms
*
* Revision 1.22 2010/04/17 13:14:18 alfred
* - address overlapping strcpy()
*
* Revision 1.21 2010/02/27 14:17:26 alfred
* - correct increment/decrement of macro nesting level
*
* Revision 1.20 2009/06/07 09:32:25 alfred
* - add named temporary symbols
*
* Revision 1.19 2009/05/10 10:48:45 alfred
* - display macro nesting in listing
*
* Revision 1.18 2008/04/13 20:23:46 alfred
* - add Atari Vecor Processor target
*
* Revision 1.17 2007/11/24 22:48:02 alfred
* - some NetBSD changes
*
* Revision 1.16 2007/04/30 10:19:19 alfred
* - make default nesting level consistent
*
* Revision 1.15 2006/12/19 17:26:00 alfred
* - allow full list mask range
*
* Revision 1.14 2006/10/10 10:41:12 alfred
* - allocate FileMask dynamically
*
* Revision 1.13 2006/07/08 10:32:55 alfred
* - added RS08
*
* Revision 1.12 2006/06/15 21:15:24 alfred
* - cleanups in listing output
*
* Revision 1.11 2006/04/06 20:26:53 alfred
* - add COP4
*
* Revision 1.10 2005/12/09 14:48:06 alfred
* - added 2650
*
* Revision 1.9 2005/10/02 10:00:43 alfred
* - ConstLongInt gets default base, correct length check on KCPSM3 registers
*
* Revision 1.8 2005/09/11 18:10:50 alfred
* - added XGATE
*
* Revision 1.7 2005/07/30 13:57:02 alfred
* - add LatticeMico8
*
* Revision 1.6 2005/03/21 19:48:16 alfred
* - shortened name to 8+3 (again...)
*
* Revision 1.5 2005/02/19 18:05:59 alfred
* - use shorter name for 8+3 filesystems, correct bugs
*
* Revision 1.4 2005/02/19 14:10:14 alfred
* - added KCPSM3
*
* Revision 1.3 2004/10/03 12:52:31 alfred
* - MinGW adaptions
*
* Revision 1.2 2004/05/29 12:28:13 alfred
* - remove unneccessary dummy fcn
*
* Revision 1.1 2003/11/06 02:49:18 alfred
* - recreated
*
* Revision 1.24 2003/10/12 19:28:52 alfred
* - created 78K/2
*
* Revision 1.23 2003/10/04 15:38:46 alfred
* - differentiate constant/variable messages
*
* Revision 1.22 2003/05/02 21:23:08 alfred
* - strlen() updates
*
* Revision 1.21 2003/03/29 18:45:50 alfred
* - allow source file spec in key files
*
* Revision 1.20 2003/03/26 20:31:51 alfred
* - some Win32 path fixes
*
* Revision 1.19 2003/03/16 18:53:42 alfred
* - created 807x
*
* Revision 1.18 2003/03/09 10:28:27 alfred
* - added KCPSM
*
* Revision 1.17 2003/02/02 13:00:05 alfred
* - use ReadLnCont()
*
* Revision 1.16 2003/01/29 21:25:41 alfred
* - do not convert IRP args when in case-sensitive mode
*
* Revision 1.15 2002/11/20 20:25:04 alfred
* - added unions
*
* Revision 1.14 2002/11/16 20:53:11 alfred
* - additions for structures
*
* Revision 1.13 2002/11/15 23:30:53 alfred
* - relocated EnterLebel
*
* Revision 1.12 2002/11/11 21:56:57 alfred
* - store/display struct elements
*
* Revision 1.11 2002/11/11 21:13:54 alfred
* - basic structure handling
*
* Revision 1.10 2002/11/11 19:24:57 alfred
* - new module for structs
*
* Revision 1.9 2002/11/10 16:27:32 alfred
* - use free fcns for macros
*
* Revision 1.8 2002/11/04 19:19:37 alfred
* - use struct separation character
*
* Revision 1.7 2002/10/07 20:25:01 alfred
* - added '/' nameless temporary symbols
*
* Revision 1.6 2002/09/30 17:12:20 alfred
* - added nameless symbol counter intialization
*
* Revision 1.5 2002/05/19 13:45:32 alfred
* - clear section usage before starting new pass
*
* Revision 1.4 2002/05/01 15:35:46 alfred
* - removed umlaut
*
* Revision 1.3 2002/03/10 10:47:20 alfred
* - add CVS log
*
*****************************************************************************/
#include "stdinc.h"
#include <string.h>
#include <ctype.h>
#include <setjmp.h>
#include <assert.h>
#include "version.h"
#include "endian.h"
#include "bpemu.h"
#include "stdhandl.h"
#include "nls.h"
#include "nlmessages.h"
#include "as.rsc"
#include "ioerrs.h"
#include "strutil.h"
#include "stringlists.h"
#include "cmdarg.h"
#include "asmitree.h"
#include "trees.h"
#include "chunks.h"
#include "asminclist.h"
#include "asmfnums.h"
#include "asmdef.h"
#include "cpulist.h"
#include "errmsg.h"
#include "asmsub.h"
#include "asmpars.h"
#include "asmmac.h"
#include "asmstructs.h"
#include "asmif.h"
#include "asmcode.h"
#include "asmdebug.h"
#include "asmrelocs.h"
#include "asmallg.h"
#include "codepseudo.h"
#include "as.h"
#include "code68k.h"
#include "code56k.h"
#include "code601.h"
#include "codemcore.h"
#include "codexgate.h"
#include "code68.h"
#include "code6805.h"
#include "code6809.h"
#include "code6812.h"
#include "codes12z.h"
#include "code6816.h"
#include "code68rs08.h"
#include "codeh8_3.h"
#include "codeh8_5.h"
#include "code7000.h"
#include "code65.h"
#include "code7700.h"
#include "codehmcs400.h"
#include "code4500.h"
#include "codem16.h"
#include "codem16c.h"
#include "code4004.h"
#include "code8008.h"
#include "code48.h"
#include "code51.h"
#include "code96.h"
#include "code85.h"
#include "code86.h"
#include "code960.h"
#include "code8x30x.h"
#include "code2650.h"
#include "codexa.h"
#include "codeavr.h"
#include "code29k.h"
#include "code166.h"
#include "codez80.h"
#include "codez8.h"
#include "codekcpsm.h"
#include "codekcp3.h"
#include "codemic8.h"
#include "code96c141.h"
#include "code90c141.h"
#include "code87c800.h"
#include "code870c.h"
#include "code47c00.h"
#include "code97c241.h"
#include "code9331.h"
#include "code16c5x.h"
#include "code16c8x.h"
#include "code17c4x.h"
#include "codesx20.h"
#include "codest6.h"
#include "codest7.h"
#include "codest9.h"
#include "code6804.h"
#include "code3201x.h"
#include "code3202x.h"
#include "code3203x.h"
#include "code3205x.h"
#include "code3254x.h"
#include "code3206x.h"
#include "code9900.h"
#include "codetms7.h"
#include "code370.h"
#include "codemsp.h"
#include "codetms1.h"
#include "codescmp.h"
#include "code807x.h"
#include "codecop4.h"
#include "codecop8.h"
#include "codesc14xxx.h"
#include "codeace.h"
#include "codef8.h"
#include "code78c10.h"
#include "code75xx.h"
#include "code75k0.h"
#include "code78k0.h"
#include "code78k2.h"
#include "code78k3.h"
#include "code78k4.h"
#include "code7720.h"
#include "code77230.h"
#include "code53c8xx.h"
#include "codefmc8.h"
#include "codefmc16.h"
#include "codeol40.h"
#include "codeol50.h"
#include "code1802.h"
#include "codevector.h"
#include "codexcore.h"
#include "code1750.h"
/** Code21xx};**/
static char *FileMask;
static long StartTime, StopTime;
static Boolean GlobErrFlag;
static Boolean MasterFile;
static Boolean WasIF, WasMACRO;
static unsigned MacroNestLevel = 0;
/*=== Zeilen einlesen ======================================================*/
#if 0
# define dbgentry(str) printf("***enter %s\n", str);
# define dbgexit(str) printf("***exit %s\n", str);
#else
# define dbgentry(str) {}
# define dbgexit(str) {}
#endif
static void NULL_Restorer(PInputTag PInp)
{
UNUSED(PInp);
}
static Boolean NULL_GetPos(PInputTag PInp, char *dest)
{
UNUSED(PInp);
*dest = '\0';
return False;
}
static Boolean INCLUDE_Processor(PInputTag PInp, char *Erg);
static PInputTag GenerateProcessor(void)
{
PInputTag PInp = malloc(sizeof(TInputTag));
PInp->IsMacro = False;
PInp->Next = NULL;
PInp->First = True;
PInp->OrigDoLst = DoLst;
PInp->StartLine = CurrLine;
PInp->ParCnt = 0; PInp->ParZ = 0;
InitStringList(&(PInp->Params));
PInp->LineCnt = 0; PInp->LineZ = 1;
PInp->Lines = PInp->LineRun = NULL;
StrCompMkTemp(&PInp->SpecName, PInp->SpecNameStr);
StrCompReset(&PInp->SpecName);
PInp->AllArgs[0] = '\0';
PInp->NumArgs[0] = '\0';
PInp->IsEmpty = False;
PInp->Buffer = NULL;
PInp->Datei = NULL;
PInp->IfLevel = SaveIFs();
PInp->Restorer = NULL_Restorer;
PInp->GetPos = NULL_GetPos;
PInp->Macro = NULL;
PInp->SaveAttr[0] = '\0';
PInp->SaveLabel[0] = '\0';
PInp->GlobalSymbols = False;
PInp->UsesNumArgs =
PInp->UsesAllArgs = False;
/* in case the input tag chain is empty, this must be the master file */
PInp->FromFile = (!FirstInputTag) || (FirstInputTag->Processor == INCLUDE_Processor);
return PInp;
}
static POutputTag GenerateOUTProcessor(SimpProc Processor, tErrorNum OpenErrMsg)
{
POutputTag POut;
POut = (POutputTag) malloc(sizeof(TOutputTag));
POut->Processor = Processor;
POut->NestLevel = 0;
POut->Tag = NULL;
POut->Mac = NULL;
POut->ParamNames = NULL;
POut->ParamDefVals = NULL;
POut->PubSect = 0;
POut->GlobSect = 0;
POut->DoExport = False;
POut->DoGlobCopy= False;
POut->UsesNumArgs =
POut->UsesAllArgs = False;
*POut->GName = '\0';
POut->OpenErrMsg = OpenErrMsg;
return POut;
}
/*=========================================================================*/
/* Listing erzeugen */
static void MakeList_Gen2Line(char *h, Word EffLen, Word *n)
{
int z, Rest;
char Str[20];
Rest = EffLen - (*n);
if (Rest > 8)
Rest = 8;
if (DontPrint)
Rest = 0;
for (z = 0; z < (Rest >> 1); z++)
{
HexString(Str, sizeof(Str), WAsmCode[(*n) >> 1], 4);
strmaxcat(h, Str, 255);
strmaxcat(h, " ", 255);
(*n) += 2;
}
if (Rest & 1)
{
HexString(Str, sizeof(Str), BAsmCode[*n], 2);
strmaxcat(h, Str, 255);
strmaxcat(h, " ", 255);
(*n)++;
}
for (z = 1; z <= (8 - Rest) >> 1; z++)
strmaxcat(h, " ", 255);
}
static void MakeList_Gen4Line(char *h, Word EffLen, Word *n)
{
int z, Rest, wr = 0;
char Str[20];
Rest = EffLen - (*n);
if (Rest > 8)
Rest = 8;
if (DontPrint)
Rest = 0;
for (z = 0; z < (Rest >> 2); z++)
{
HexString(Str, sizeof(Str), DAsmCode[(*n) >> 2], 8);
strmaxcat(h, Str, 255);
strmaxcat(h, " ", 255);
*n += 4;
wr += 9;
}
for (z = 0; z < (Rest&3); z++)
{
HexString(Str, sizeof(Str), BAsmCode[(*n)++], 2);
strmaxcat(h, Str, 255);
strmaxcat(h, " ", 255);
wr += 3;
}
strmaxcat(h, Blanks(20 - wr), 255);
}
static void MakeList(void)
{
String h, h2, h3, Tmp;
Word i, k;
Word n, EffLen;
Boolean ThisDoLst;
EffLen = CodeLen * Granularity();
#if 0
fprintf(stderr, "[%s] WasIF %u WasMACRO %u DoLst %u\n", OpPart.Str, WasIF, WasMACRO, DoLst);
#endif
if (WasIF)
ThisDoLst = !!(DoLst & eLstMacroExpIf);
else if (WasMACRO)
ThisDoLst = !!(DoLst & eLstMacroExpMacro);
else
{
if (!IfAsm && (!(DoLst & eLstMacroExpIf)))
ThisDoLst = False;
else
ThisDoLst = !!(DoLst & eLstMacroExpRest);
}
if ((!ListToNull) && (ThisDoLst) && ((ListMask & 1) != 0) && (!IFListMask()))
{
/* Zeilennummer / Programmzaehleradresse: */
if (IncDepth == 0)
strmaxcpy(h2, " ", 255);
else
{
sprintf(Tmp, IntegerFormat, IncDepth);
sprintf(h2, "(%s)", Tmp);
}
if (ListMask & ListMask_LineNums)
{
sprintf(h3, Integ32Format, CurrLine);
sprintf(h, "%5s/", h3);
strmaxcat(h2, h, 255);
}
strmaxcpy(h, h2, 255);
HexBlankString(h2, sizeof(h2), EProgCounter() - CodeLen, 8);
strmaxcat(h, h2, 255);
strmaxcat(h, Retracted?" R ":" : ", 255);
/* Extrawurst in Listing ? */
if (*ListLine != '\0')
{
strmaxcat(h, ListLine, 255);
strmaxcat(h, Blanks(20 - strlen(ListLine)), 255);
strmaxcat(h, OneLine, 255);
WrLstLine(h);
*ListLine = '\0';
}
/* Code ausgeben */
else
{
switch (ActListGran)
{
case 4:
n = 0;
MakeList_Gen4Line(h, EffLen, &n);
strmaxcat(h, OneLine, 255); WrLstLine(h);
if (!DontPrint)
{
while (n < EffLen)
{
strmaxcpy(h, " ", 255);
MakeList_Gen4Line(h, EffLen, &n);
WrLstLine(h);
}
}
break;
case 2:
n = 0;
MakeList_Gen2Line(h, EffLen, &n);
strmaxcat(h, OneLine, 255); WrLstLine(h);
if (!DontPrint)
{
while (n < EffLen)
{
strmaxcpy(h, " ", 255);
MakeList_Gen2Line(h, EffLen, &n);
WrLstLine(h);
}
}
break;
default:
{
char Str[20];
if ((TurnWords) && (Granularity() != ActListGran))
DreheCodes();
for (i = 0; i < 6; i++)
if ((!DontPrint) && (EffLen > i))
{
HexString(Str, sizeof(Str), BAsmCode[i], 2);
strmaxcat(h, Str, 255);
strmaxcat(h, " ", 255);
}
else
strmaxcat(h, " ", 255);
strmaxcat(h, " ", 255);
strmaxcat(h, OneLine, 255);
WrLstLine(h);
if ((EffLen > 6) && (!DontPrint))
{
EffLen -= 6;
n = EffLen / 6;
if ((EffLen % 6) == 0)
n--;
for (i = 0; i <= n; i++)
{
strmaxcpy(h, " ", 255);
if (ListMask & ListMask_LineNums)
strmaxcat(h, " ", 255);
for (k = 0; k < 6; k++)
if (EffLen > i * 6 + k)
{
HexString(Str, sizeof(Str), BAsmCode[i * 6 + k + 6], 2);
strmaxcat(h, Str, 255);
strmaxcat(h, " ", 255);
}
WrLstLine(h);
}
}
if ((TurnWords) && (Granularity() != ActListGran))
DreheCodes();
}
}
}
}
}
/*=========================================================================*/
/* Makroprozessor */
/*-------------------------------------------------------------------------*/
/* allgemein gebrauchte Subfunktionen */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* werden gebraucht, um festzustellen, ob innerhalb eines Makrorumpfes weitere
Makroschachtelungen auftreten */
static Boolean MacroStart(void)
{
return ((Memo("MACRO")) || (Memo("IRP")) || (Memo("IRPC")) || (Memo("REPT")) || (Memo("WHILE")));
}
static Boolean MacroEnd(void)
{
if (Memo("ENDM"))
{
WasMACRO = True;
return True;
}
else
return False;
}
typedef void (*tMacroArgCallback)(Boolean CtrlArg, const tStrComp *pArg, void *pUser);
static void ProcessMacroArgs(tMacroArgCallback Callback, void *pUser)
{
tStrComp *pArg;
int l;
for (pArg = ArgStr + 1; pArg <= ArgStr + ArgCnt; pArg++)
{
l = strlen(pArg->Str);
if ((l >= 2) && (pArg->Str[0] == '{') && (pArg->Str[l - 1] == '}'))
{
tStrComp Arg;
StrCompRefRight(&Arg, pArg, 1);
StrCompShorten(&Arg, 1);
Callback(TRUE, &Arg, pUser);
}
else
{
Callback(FALSE, pArg, pUser);
}
}
}
/*-------------------------------------------------------------------------*/
/* Dieser Einleseprozessor dient nur dazu, eine fehlerhafte Makrodefinition
bis zum Ende zu ueberlesen */
static void WaitENDM_Processor(void)
{
POutputTag Tmp;
if (MacroStart())
FirstOutputTag->NestLevel++;
else if (MacroEnd())
FirstOutputTag->NestLevel--;
if (FirstOutputTag->NestLevel <= -1)
{
Tmp = FirstOutputTag;
FirstOutputTag = Tmp->Next;
free(Tmp);
}
}
static void AddWaitENDM_Processor(void)
{
POutputTag Neu;
Neu = GenerateOUTProcessor(WaitENDM_Processor, ErrNum_OpenMacro);
Neu->Next = FirstOutputTag;
FirstOutputTag = Neu;
}
/*-------------------------------------------------------------------------*/
/* normale Makros */
static void ComputeMacroStrings(PInputTag Tag)
{
StringRecPtr Lauf;
/* recompute # of params */
if (Tag->UsesNumArgs)
sprintf(Tag->NumArgs, "%d", Tag->ParCnt);
/* recompute 'all string' parameter */
if (Tag->UsesAllArgs)
{
Tag->AllArgs[0] = '\0';
Lauf = Tag->Params;
while (Lauf)
{
if (Tag->AllArgs[0] != '\0')
strmaxcat(Tag->AllArgs, ",", 255);
strmaxcat(Tag->AllArgs, Lauf->Content, 255);
Lauf = Lauf->Next;
}
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Diese Routine leitet die Quellcodezeilen bei der Makrodefinition in den
Makro-Record um */
static void MACRO_OutProcessor(void)
{
POutputTag Tmp;
int z;
StringRecPtr l;
PMacroRec GMacro;
String s;
WasMACRO = True;
/* write preprocessed output to file ? */
if ((MacroOutput) && (FirstOutputTag->DoExport))
{
errno = 0;
fprintf(MacroFile, "%s\n", OneLine);
ChkIO(10004);
}
/* check for additional nested macros resp. end of definition */
if (MacroStart())
FirstOutputTag->NestLevel++;
else if (MacroEnd())
FirstOutputTag->NestLevel--;
/* still lines to put into the macro body ? */
if (FirstOutputTag->NestLevel != -1)
{
strmaxcpy(s, OneLine, 255);
KillCtrl(s);
/* compress into tokens */
l = FirstOutputTag->ParamNames;
for (z = 1; z <= FirstOutputTag->Mac->ParamCount; z++)
CompressLine(GetStringListNext(&l), z, s, sizeof(s), CaseSensitive);
/* reserved argument names are never case-sensitive */
if (HasAttrs)
CompressLine(AttrName, ArgCntMax + 1, s, sizeof(s), FALSE);
if (CompressLine(ArgCName, ArgCntMax + 2, s, sizeof(s), FALSE) > 0)
FirstOutputTag->UsesNumArgs = TRUE;
if (CompressLine(AllArgName, ArgCntMax + 3, s, sizeof(s), FALSE) > 0)
FirstOutputTag->UsesAllArgs = TRUE;
if (FirstOutputTag->Mac->LocIntLabel)
CompressLine(LabelName, ArgCntMax + 4, s, sizeof(s), FALSE);
AddStringListLast(&(FirstOutputTag->Mac->FirstLine), s);
}
/* otherwise, finish definition */
if (FirstOutputTag->NestLevel == -1)
{
if (IfAsm)
{
FirstOutputTag->Mac->UsesNumArgs = FirstOutputTag->UsesNumArgs;
FirstOutputTag->Mac->UsesAllArgs = FirstOutputTag->UsesAllArgs;
FirstOutputTag->Mac->ParamNames = FirstOutputTag->ParamNames;
FirstOutputTag->ParamNames = NULL;
FirstOutputTag->Mac->ParamDefVals = FirstOutputTag->ParamDefVals;
FirstOutputTag->ParamDefVals = NULL;
AddMacro(FirstOutputTag->Mac, FirstOutputTag->PubSect, True);
if ((FirstOutputTag->DoGlobCopy) && (SectionStack))
{
GMacro = (PMacroRec) malloc(sizeof(MacroRec));
GMacro->Name = as_strdup(FirstOutputTag->GName);
GMacro->ParamCount = FirstOutputTag->Mac->ParamCount;
GMacro->FirstLine = DuplicateStringList(FirstOutputTag->Mac->FirstLine);
GMacro->ParamNames = DuplicateStringList(FirstOutputTag->Mac->ParamNames);
GMacro->ParamDefVals = DuplicateStringList(FirstOutputTag->Mac->ParamDefVals);
GMacro->UsesNumArgs = FirstOutputTag->Mac->UsesNumArgs;
GMacro->UsesAllArgs = FirstOutputTag->Mac->UsesAllArgs;
AddMacro(GMacro, FirstOutputTag->GlobSect, False);
}
}
else
{
ClearMacroRec(&(FirstOutputTag->Mac), TRUE);
}
Tmp = FirstOutputTag;
FirstOutputTag = Tmp->Next;
ClearStringList(&(Tmp->ParamNames));
ClearStringList(&(Tmp->ParamDefVals));
free(Tmp);
}
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Hierher kommen bei einem Makroaufruf die expandierten Zeilen */
Boolean MACRO_Processor(PInputTag PInp, char *erg)
{
StringRecPtr Lauf;
int z;
Boolean Result;
Result = True;
/* run to current line */
Lauf = PInp->Lines;
for (z = 1; z <= PInp->LineZ - 1; z++)
Lauf = Lauf->Next;
strcpy(erg, Lauf->Content);
/* process parameters */
Lauf = PInp->Params;
for (z = 1; z <= PInp->ParCnt; z++)
{
ExpandLine(Lauf->Content, z, erg, STRINGSIZE);
Lauf = Lauf->Next;
}