-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfd2pragma.c
13746 lines (12388 loc) · 433 KB
/
fd2pragma.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
/* $Id$ */
static const char version[] =
"$VER: fd2pragma 2.197 (09.10.2016) by Dirk Stoecker <[email protected]>";
/* There are four defines, which alter the result which is produced after
compiling this piece of code. */
/* turns on usage of Amiga ReadArgs-system (requires <proto/dos.h> include) */
/* #define FD2PRAGMA_READARGS */
/* enables Amiga style file name (only relevant for fd2pragma.types file) */
/* #define FD2PRAGMA_AMIGA */
/* debugging output */
/* #define DEBUG */
/* more debugging output */
/* #define DEBUG_OLD */
/* Programmheader
Name: fd2pragma
Author: SDI
Distribution: PD
Description: creates pragmas files, lvo files, ...
Compileropts: -
Linkeropts: -
1.2 : added pragmas for the Dice compiler. Available via switch "Dice".
added switches "Aztec", "SAS" and "Maxon": Maxon and Aztec just
turn on the default (except that Maxon expects pragma files to be
called "xxx_pragmas.h" instead of "xxx_lib.h"), SAS is equal to
Dice, except that SAS supports the pragma tagcall.
2.0 : Added support for tag functions. See the docs for details.
Author until this version:
Jochen Wiedmann
Am Eisteich 9
72555 Metzingen (Germany)
Tel. 07123 / 14881
2.1 19.08.96 : now made by SDI, added correct __MAXON__ support and
support for StormC++, added auto recognition of tagcall functions
changed the CLI interface completely
2.2 21.08.96 : fixed a lot of errors, added debug code
2.3 22.08.96 : little changes
2.4 24.08.96 : added proto-file creation
2.5 25.08.96 : added syscall and fix for functions ending in ...DMA
2.6 26.08.96 : fixed some errors, added CLIB parameter (used later for
CSTUBS)
2.7 01.09.96 : added correct Storm definition, added CLIB scan
2.8 02.09.96 : added assembler stub functions, added first ASM-stub code
2.9 04.09.96 : added Comment-Support
2.10 05.09.96 : changed CSTUB creation a bit
2.11 07.09.96 : speeded up output, reduced number of strndup calls
2.12 26.09.96 : pressing CTRL-C in early startup brought a wrong error
message - fixed
2.13 30.09.96 : made RegNames field to RegNames string - shorter Exe-file
2.14 01.10.96 : made SPECIAL 6 default, COMMENT also in LVO files
2.15 13.10.96 : corrected an error text
2.16 14.10.96 : added correct comment support and PRIVATE option
2.17 19.10.96 : now Maxon-compiled in Small data mode
2.18 22.10.96 : removed EXTERNC in Storm, Maxon and all pragmas, corrected
the texts, again SAS compiled
2.19 26.10.96 : added option to create FD files out of pragma files,
reworked a lot in the source
2.20 27.10.96 : fixed errors of previous version
2.21 28.10.96 : fixed error in CLIB scan
2.22 27.11.96 : SPECIAL numbers for lib and ASM code were wrong, removed
bug in Tag function stubs
2.23 06.12.96 : lib and stub creation still was wrong
2.24 31.12.96 : formed stub libs matching C++ file names, corrected CLIB
scan errors
2.25 04.01.97 : added HEADER option (I was asked for)
2.26 05.01.97 : added HEADER scan (in old file) and auto inserting
2.27 10.01.97 : stub functions missed register saving, outfuncs skip now,
when error occured (makes lots of error checking obsolete)
2.28 11.01.97 : forgot to add offset made by register saving
2.29 18.01.97 : now libtags and amitags defines only, when at least 1
tagfunc
2.30 13.02.97 : added local library base functions, rearranged SPECIAL
options, fixed some bugs
2.31 15.02.97 : corrected bugs inserted in previous version
2.32 16.02.97 : and again bug fixes, still didn't work
2.33 18.02.97 : corrected texts, added SPECIAL 28
2.34 25.03.97 : corrected Pragma --> FD file conversion, added ##shadow
2.35 26.03.97 : added STORMFD option, COMMENT, PRIVATE work again
2.36 29.03.97 : corrected *tagcall scan a bit
2.37 20.06.97 : added PASCAL stub lib production (SPECIAL 14, 15)
2.38 01.07.97 : fixed ##end handling
2.39 20.07.97 : added better proto file (__GNUC__ inline and pragma call),
removed C++ comments
2.40 24.11.97 : added new basenames to the list (devices and resources),
added tag-exception name checking (dos, utility libraries)
2.41 27.11.97 : fixed little bug with private functions, CSTUBS now
special option and no longer commandline arg, SPECIAL 10-15 got
numbers 11-16 (Sorry)
2.42 28.11.97 : Added two new warnings for CLIB
2.43 12.12.97 : faster FD file scan, one new warning
2.44 19.12.97 : fixed MODE settings for SPECIAL 15,16
2.45 30.01.98 : added function recognition, included inline creation,
inline stuff is based on fd2inline 1.11 (incomplete)
2.46 31.01.98 : continued inline stuff, fixed clib functions
2.47 05.02.98 : completed inline stuff, added alias names for dos functions
2.48 06.02.98 : changed Func interface - flags instead of tagmode
2.49 10.02.98 : fixed inline generation a bit, added SORTED argument,
RegNames got strings again
2.50 11.02.98 : bug-fixes, still did not work completely, hopefully got
all now
2.51 12.02.98 : and bug-fixes again :-(
2.52 15.02.98 : changed sorting order of arguments
2.53 20.02.98 : some code style changes
2.54 25.02.98 : added SMALLDATA model, removed 5 global variables (better
style), stub libs use MOVEM when possible, own MemRemember function
2.55 26.02.98 : bug fixes
2.56 15.03.98 : added FPU support
2.57 17.03.98 : added NOFPU keyword
2.58 19.03.98 : little fixes
2.59 20.03.98 : added enum and external type definitions defines
2.60 22.03.98 : added external types file scan
2.61 23.03.98 : fixed SAS flibcall, added FPU stubs
2.62 28.03.98 : bug fix with NOFPU and new option FPUONLY, total new clib
handling
2.63 29.03.98 : really lots of bug fixes, There are so much problems.
A better definition format would have been wonderful.
2.64 05.04.98 : bug fixes
2.65 07.04.98 : fixed Enforcer hit
2.66 08.04.98 : bug fix with type detection
2.67 20.04.98 : added GNU-only stuff
2.68 28.04.98 : SPECIAL 8 defaults to SAS-C names now
2.69 25.05.98 : added PowerUP stuff support
2.70 28.05.98 : added SAS PowerUP stuff, fixed error with function
detection in CLIB scan
2.71 30.05.98 : added PowerUP Inlines
2.72 12.06.98 : sorting turns of COMMENT now
2.73 05.07.98 : added first FPC stuff, added HEADER to PowerUP stuff,
added PASCAL header scan
2.74 06.07.98 : finished FPC stuff
2.75 07.07.98 : bug fixes for FPC stuff
2.76 09.07.98 : style changes for FPC stuff, bug fixes
2.77 11.07.98 : hopefully last FPC bug removed
2.78 23.07.98 : style changes and bug fixes for FPC stuff, more comments
2.79 10.08.98 : bug fix, when TO was used with a directory, clib got
wrong path if it was a relative path description
2.80 16.08.98 : now prints better error when filopen failed
2.81 26.10.98 : added BMAP files for BASIC, CODE needs to use large mode
now :-(
2.82 28.10.98 : optimizations and bug fixes
2.83 31.12.98 : fixed powerup stuff a bit
2.84 05.01.99 : fixed bug in Lib creation, when Dx/Ax and FPx were mixed
2.85 06.01.99 : added recognition of names ending in MESA, added notagcall
comment support, void functions no longer can be tagcall
2.86 10.01.99 : added BGUI special funcs, fixed bug in SPECIAL 42 code
2.87 12.01.99 : added asm-text (SECTION), moved 12-17 to 13-18
2.88 17.01.99 : better type detection, added some more basenames, some
little bug fixes, new makefile reduces file size a lot
2.89 17.07.99 : added union support
2.90 12.11.99 : added new motorola syntax, opt040 and vbcc inlines
2.91 13.11.99 : Now supports changes in OS3.5 includes, why the hell must
such changes be? I thought new includes will bring cleanup and not
cleandown. And the reported bugs are still unfixed, but there are
new ones!, bug-fixes
2.92 14.11.99 : added PPC-WOS library text and code, FD-creation moved from
80 to 200 (now finally! - there should be enough free number space),
added VBCC-PUP text generation
2.93 15.11.99 : added CheckError function, moved DisplayInfoHandle to
types definition file
2.94 16.11.99 : added first VBCC-PowerUP-Lib production stuff, only ELF
tables missing
2.95 17.11.99 : finished PowerUP stub stuff, startet PPC-ABI stuff
2.96 18.11.99 : little bug fixes
2.97 19.11.99 : added SECTION keyword, moved 11-18 to 12-17, ahh 3 releases
more and we get an anniversary, my first program using third revision
digit :-)
2.98 20.11.99 : added VBCC-WOS-Code for PPC libs
2.99 25.11.99 : bug fixes
2.100 17.02.00 : fixed bug for VBCC inlines
2.101 29.02.00 : fixed name for VBCC inlines
2.102 13.03.00 : added new style GCC inlines
2.103 21.03.00 : bug fixed, SPECIAL 35 has VBCC stuff now.
2.104 25.03.00 : fixed path lock problem
2.105 11.04.00 : library HUNK_UNIT get functionname now
2.106 13.07.00 : added E-Modules
2.107 06.08.00 : removed VBCC inline support from 35 and moved it to 38, 35
does now skip pragma/inline files for VBCC
2.108 18.08.00 : added new ppc modification proto file 39, modified protos a
bit, support for register types and function pointer args, int got
internally type CPP_TYPE_INT
2.109 19.08.00 : bug fixes
2.110 24.08.00 : fixed SPECIAL 7,40-44, added SPECIAL 80-83
2.111 31.08.00 : bug fixes
2.112 03.09.00 : FD2Pragma.types scanner no longer accepts multi-word types.
2.113 29.12.00 : added extern keword support for return types.
2.114 07.01.01 : made FD2Pragma partly portable, removed 4 direct pragma
arguments
2.115 14.01.01 : lots of bug fixes, renamed from FD2Pragma to fd2pragma
2.116 28.01.01 : added internal types, SPECIAL 90, NOCPPNAMES and bug fixes,
VBCC inlines fix for data in A-regs
2.117 04.02.01 : changed NOCPPNAMES to ONLYCNAMES, added HUNKNAME, LocCode is
portable, added BASENAME, added VBCCWOSInlines
2.118 07.02.01 : added destination file printout, LIBTYPE, fixes VBCC-PUP-Code
2.119 11.02.01 : bug fixes
2.120 17.02.01 : added NOPPCREGNAME, bug fixes
2.121 04.03.01 : added MorphOS text
2.122 11.03.01 : little bug fixes
2.123 03.04.01 : now uses EXT_DEXT16 instead of EXT_REF16 also for 68k files
2.124 08.04.01 : bug fixes, added MorphOS binary mode, finally full portable
2.125 28.04.01 : added LVO's for PPC, started support for SFD format
2.126 29.05.01 : fixed PPC LVO's, removed STORMFD Option (auto detection),
now handles up to 5 alias names, finished SFD format read, added FD
creation, added keyword checks for argument names, lots of optimizations
and fixes, which came in hand with SFD inclusion.
Thanks Olaf Barthel for making the SFD stuff possible.
2.127 30.04.01 : private comments are skipped now, finished SFD production,
fixed bugs, removed SPECIAL 8 redirect (is replaced by 80-83)
2.128 01.05.01 : bug fixes
2.129 03.06.01 : included support for files previous made by vbcc genauto tool
2.130 04.06.01 : bug fixes in genauto stuff
2.131 11.06.01 : newer types handle cia now correct
2.132 27.06.01 : fixed crash caused by illegal interpretation of ANSI-C :-)
2.133 28.06.01 : added VOIDBASE argument
2.134 01.07.01 : added MorphOS types, fixed PowerUp stuff
2.135 28.07.01 : added VBCC inline varargs support
2.136 30.07.01 : fixed VBCC inline varargs
2.137 18.11.01 : little bug-fix
2.138 30.11.01 : fixed CLIB scanning (now a preparser cleans the file a lot)
2.139 13.12.01 : fixed ==libname scan and xvsBase
2.140 21.12.01 : fixed some uint32 in created files, which have been wrongly
introduced in 2.1xx versions when making tool portable
2.141 04.01.02 : fixed problem with multiple pointer function args like in
"void (**func)(void)"
2.142 07.01.02 : started new direct inline types 46 and 47.
2.143 08.01.02 : Fixed warnings, bugs, card.resouce entry and added
==copyright directive
2.144 09.01.02 : Fixed MUI varargs inlines
2.145 03.03.02 : Some bug fixes
2.146 20.05.02 : one little bug fix, added support for missing empty () in
defective FD files
2.147 01.05.02 : now continues when detecting no fd-arg name
2.148 09.06.02 : fixed problem with MorphOS stubs, added AUTOHEADER keyword,
added auto type defaults to int, fixed bug with STACK type
2.149 24.06.02 : fixed lots of problems found when converting amissl includes
2.150 08.08.02 : fixed inline files a bit
2.151 31.08.02 : fixed SPECIAL 46 files (error when no args, but return value)
2.152 01.09.02 : bug-fix with SPECIAL 47
2.153 11.09.02 : modified SPECIAL 46 varargs on request of Sebastian Bauer
and Olaf Barthel
2.154 03.10.02 : added VBCC MorphOS inlines (SPECIAL 122). Thanks Frank Wille
for design help.
2.155 04.10.02 : optimized VBCC MorphOS text (SPECIAL 93), fixed VBCC MorphOS
inlines
2.156 06.10.02 : added warning about obsolete types, fixed VBCC MorphOS Code
(SPECIAL 78)
2.157 12.10.02 : Fixed CLIB scan problem
2.158 19.10.02 : added CLIB define in SPECIAL 46
2.159 16.11.02 : bugfix with SPECIAL 46 varargs redefine
2.160 04.12.02 : fixed bug in MorphOS-vbcc code
2.161 15.12.02 : now no longer includes clib files for GCC, the GCC inlines
include the needed include lines directly
2.162 26.01.03 : bug fixes, added updated fpc code made by Nils Sjöholm (it
is not that complicated to do fixes yourself, fd2pragma's inner
structure is really easy)
2.163 28.01.03 : little fixes
2.164 15.02.03 : fixed DirectInline for GCC mode, changed FPC layout
2.165 04.01.04 : fixed VBCC TAG inlines (SPECIAL 70), added modified MorphOS
FD file types, fixed GCC direct inlines for GCC 3
2.166 06.01.04 : added first set of OS4 filetypes
2.167 09.01.04 : more OS4 stuff, added library name comment scanning for SFD
2.168 19.01.04 : some fixes (a lot of thanks to Frank Wille)
2.169 22.01.04 : completed OS4 stuff
2.170 28.01.04 : some more VBCC-MOS things
2.171 26.02.04 : finished VBCC-MOS text
2.172 09.05.04 : (phx) fixed clib-parsing problem with splitted function
name and arguments over two lines, more flexible "base,sysv"
recognition for MorphOS, never use "Device *" pointer in a proto file
- should be "Library *"
2.173 10.05.04 : fixed MOS-base,sysv to allow autodetected Tag-Functions
2.174 23.05.04 : some fixes for MorphOS and VBCC
2.175 11.07.04 : (phx) has to recognize and skip 'extern "C" {', as a
result of my modifications in 2.172.
2.176 21.09.04 : added new MorphOS VBCC inlines and some other OS4 fixes
2.177 23.09.04 : minor bugfix
2.178 09.10.04 : (phx) vbcc: use __linearvarargs instead of __aos4varargs
2.179 09.11.04 : (phx) make it compile natively under AmigaOS 4.x
2.180 07.12.04 : (phx) don't create vbcc inlines for MUI_NewObject &
PM_MakeItem - otherwise the preprocessor gets confused
2.181 20.12.04 : made test for MUI_NewObject and PM_MakeItem based on a field
containing the names - allows easier expansion
2.182 16.01.05 : (phx) experimental MorphOS "(sysv)" support, which doesn't
need a base-register passed as first argument
2.183 24.01.05 : added support for long long types, nevertheless files using
that will not produce correct results for now
2.184 07.02.05 : (phx) Fixed FuncVBCCWOSCode() (special 73) to read the
function ptr from (bias-2) instead from (bias) for PPC0/2-ABI.
Picasso96 support.
2.185 08.02.05 : (phx) Special 38 (proto with vbcc inline) always generates
an inline-include now, and is no longer restricted to MorphOS & 68k.
Special Warp3DPPC support.
Marked some powerpc.library functions, which were erroneously
detected as tag functions.
2.186 17.02.05 : fixed PPC0-mode VBCC WOS stubs
2.187 26.03.05 : (phx) "(sysv,r12base)" in MorphOS FD-files is supported.
I made it identical to (sysv), which both load the library base
to r12 (correct in (sysv,r12base) mode and can't hurt in (sysv) mode).
Allow "(void)" instead of "()" as parameter list.
Function-pointer types can extend over multiple lines now (does
this make sense for other types too?).
New SDL-types: FPSmanager, Mix_Chunk, Mix_Music, Mix_MusicType,
Mix_EffectFunc_t, Mix_EffectDone_t, Mix_Fading, IPaddress,
TCPsocket, UDPpacket, UDPsocket, SDLNet_SocketSet,
SDLNet_GenericSocket, TTF_Font.
Put some of SDL-gfx functions ("...RGBA()") in the exceptions list.
2.188 30.03.05 : (phx) Put NewObject() into the NoInline-list.
2.189 21.05.05 : (phx) Always include emul/emulregs.h in vbcc/MOS inlines.
2.190 23.08.05 : (phx) Use ".file <name>.o" in assembler sources, HUNK_NAME
and ELF ST_FILE symbols. It was "<name>.s" before, which is wrong.
2.191 01.11.05 : (phx) Rewrote FuncVBCCWOSInline() based on the MOSInline-
function, to be able to handle varargs functions correctly.
Also fixed WOS-text and -code generation for PPC0-ABI.
2.192 06.01.10 : (phx) Do vbcc MorphOS OS-calls with BCTRL instead of BLRL
to avoid messing up the LR-stack of more recent PowerPCs (G4+).
2.193 18.09.10 : (phx) GLContext type (tinygl).
2.194 03.01.11 : (mazze) Fix for building it on CYGWIN.
Added AROS support in the proto file.
2.195 24.05.15 : (phx) Merge data-register pairs from the FD file for
64-bit data types when generating vbcc 68k assembler inlines.
2.196 06.02.16 : (phx) Varargs function for rtEZRequestA() is
rtEZRequestTags(). rtEZRequest() has swapped arguments and needs
to be implemented in amiga.lib.
2.197 09.10.16 : (phx) ShortBaseName must not be enforced as lower case.
Some libraries, like Warp3D and Picasso96API, have upper case letters
in their FD, proto and clib file names.
2.198 27.10.18 : (sba) For special 42 format, don't put used registers in the
clobber list as newer GCC complain about this.
*/
/* A short note, how fd2pragma works.
Working mode for SPECIAL 200 is a bit different!
The main function parses arguments. Switches are converted into FLAG_XXX
values and stored in global "Flags" or "Flags2" variable. SPECIAL numbers
are parsed and are used to call a CreateXXX function, with its interface
depending on the need of arguments (Some have 2, some none, ...). Before
SPECIAL arguments are parsed, fd2pragma loads (S)FD file and scans it using
Scan(S)FDFile(). If SORTED is specified, the list gets sorted nearly directly
afterwards. IF CLIB argument is given, the clib file is scanned after FD file
and a clib list is created. Now SPECIAL is parsed and mode is set to any of
the MODUS_XXX values. Also the destination file name is created if not given.
The destination file is opened now.
The mode variable is used to determine the correct CreateXXX function,
which is called afterwards. This function produces file headers and stuff
like that and calls CallFunc to process each FD entry.
CallFunc gets 3 arguments. First the workmode (TAG, NORMAL, BOTH).
Second the comment method (for C it is "/%s *\x2F\n", for ASM it is "\n%s",
no comment is reached with 0 argument). The last is most important. It is the
function pointer to a function creating the entries. These functions have
always the same interface and are called through CallFunc only! They create
an entry for the specified function (e.g. FD entry). Parsing special
functions, adding comments, checking for tag-functions, ... is done by
CallFunc. It is no problem to call CallFunc multiple with different function
pointers (as is done for SPECIAL 6 pragmas).
This is also the method if information abount the type or number of functions
is needed somewhere in the begin of the output file. A special function to
collect this data needs to be started before doing real output. Althought I
do not like it much, global variables or flags can be used to store that
information.
The functions can use DoOutput to output texts in printf style or
DoOutputDirect to output all data in fwrite style. Buffering is done
automatically.
fd2pragma has its own memory managment. All memory must be allocated using
AllocListMem and is freed automatically. This is especially useful for
DupString function, which is used in FD, SFD and CLIB scanner.
Normally this source-file is to big and should be splitted into different
files compiled alone and linked together. :-) It takes about 20 minutes to
compile it on my Amiga system with optimizations turned on.
There are lots of different input and output types and some combinations
are really useless or wrong. fd2pragma has the mechanisms to catch these
cases properly, but not all cases are really checked, as there are too many
of them and each new input type increases the number of combinations.
Also not all useful combinations me be handled correctly. If you find a
case which really matters please inform me. All the others require the
users to use their brains :-)
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <time.h>
/* These are the only allowed variable types of all related programs! */
#ifdef __amigaos4__
#include <exec/types.h>
#else
#include <limits.h>
typedef signed char int8; /* signed 8 bit */
typedef unsigned char uint8; /* unsigned 8 bit */
typedef signed short int int16; /* signed 16 bit */
typedef unsigned short int uint16; /* unsigned 16 bit */
#if (LONG_MAX == 2147483647L)
typedef signed long int int32; /* signed 32 bit */
typedef unsigned long int uint32; /* unsigned 32 bit */
#elif (INT_MAX == 2147483647)
typedef signed int int32; /* signed 32 bit */
typedef unsigned int uint32; /* unsigned 32 bit */
#else
#error define a 32bit integral type
#endif /* int32_t */
#endif
typedef float fl32; /* 32 bit IEEE float value */
typedef double fl64; /* 64 bit IEEE double value */
typedef char string; /* the string datatype [e.g. one character of string!] */
typedef char * strptr; /* and an string pointer */
#define EndPutM32(a, b) {uint32 epu32 = (b); (a)[0] = (uint8) (epu32 >> 24); (a)[1] = (uint8) (epu32 >> 16); \
(a)[2] = (uint8) (epu32 >> 8); (a)[3] = (uint8) epu32;}
#define EndPutM16(a, b) {uint16 epu16 = (b); (a)[0] = (uint8) (epu16 >> 8); (a)[1] = (uint8) epu16;}
#define EndPutI32(a, b) {uint32 epu32 = (b); (a)[3] = (uint8) (epu32 >> 24); (a)[2] = (uint8) (epu32 >> 16); \
(a)[1] = (uint8) (epu32 >> 8); (a)[0] = (uint8) epu32;}
#define EndPutI16(a, b) {uint16 epu16 = (b); (a)[1] = (uint8) (epu16 >> 8); (a)[0] = (uint8) epu16;}
#define EndPutM32Inc(a, b) {EndPutM32(a,b); (a) += 4;}
#define EndPutM16Inc(a, b) {EndPutM16(a,b); (a) += 2;}
#define EndPutI32Inc(a, b) {EndPutI32(a,b); (a) += 4;}
#define EndPutI16Inc(a, b) {EndPutI16(a,b); (a) += 2;}
#define TEXT_SAS "__SASC" /* verified */
#define TEXT_SAS_60 "__SASC_60" /* verified */
#define TEXT_MAXON "__MAXON__" /* verified */
#define TEXT_STORM "__STORM__" /* verified */
#define TEXT_DICE "_DCC" /* in 2.0 code */
#define TEXT_AZTEC "AZTEC_C" /* verified */
#define TEXT_GNUC "__GNUC__" /* verified */
#define TEXT_VBCC "__VBCC__" /* verified */
#define TEMPSIZE 20480
#define FLAG_EXTERNC (1<< 0) /* add externc statements */
#define FLAG_SYSCALL (1<< 1) /* create SAS-C syscall pragmas */
#define FLAG_DOCOMMENT (1<< 2) /* do comment processing */
#define FLAG_PRIVATE (1<< 3) /* also use private functions */
#define FLAG_LOCALREG (1<< 4) /* local file uses register call */
#define FLAG_ISPRIVATE (1<< 5) /* for FD creation, currently working in private mode */
#define FLAG_PASCAL (1<< 6) /* library creation with PASCAL style */
#define FLAG_SMALLDATA (1<< 7) /* libraries use small data modell */
#define FLAG_DONE (1<< 8) /* destination file is not empty */
#define FLAG_INLINENEW (1<< 9) /* produce new style inlines */
#define FLAG_INLINESTUB (1<<10) /* produce stubs style inlines */
#define FLAG_NOFPU (1<<11) /* do not allow FPU registers */
#define FLAG_DIDERROR (1<<12) /* one error already printed, don't print 2nd */
#define FLAG_FPUONLY (1<<13) /* only use FPU registers */
#define FLAG_GNUPRAG (1<<14) /* insert inline call into pragma file */
#define FLAG_POWERUP (1<<15) /* create Phase5 PowerUP files */
#define FLAG_ASMSECTION (1<<16) /* create SECTIONS in Asm code */
#define FLAG_NEWSYNTAX (1<<17) /* new motorola syntax */
#define FLAG_NOMOVEM (1<<18) /* 68040 optimization, don't use MOVEM */
#define FLAG_WOSLIBBASE (1<<19) /* first arg is libbase for VBCC WOS */
#define FLAG_NOPPC (1<<20) /* do not allow PPC functions */
#define FLAG_PPCONLY (1<<21) /* only take PPC functions */
#define FLAG_STORMGCC (1<<22) /* special workaround for StormGCC */
#define FLAG_NOSYMBOL (1<<23) /* do not create symbol section for libs */
#define FLAG_MORPHOS (1<<24) /* create MorphOS files */
#define FLAG_SORTED (1<<25) /* sort the functions by name */
#define FLAG_DIDPPCWARN (1<<26) /* we already printed ppc warning */
#define FLAG_SINGLEFILE (1<<27) /* create single files */
#define FLAG_ONLYCNAMES (1<<28) /* do not create C++, ASM names */
#define FLAG_BASENAME (1<<29) /* Basename was command-line specified */
#define FLAG_DIDM68KWARN (1<<30) /* we already printed M68K warning */
#define FLAG_ABIV4 (1<<31) /* ABI V4 design for PPC-LVO */
#define FLAG2_SFDMODE (1<< 0) /* input file was SFD file */
#define FLAG2_LIBTYPE (1<< 1) /* libtype was specified on command line */
#define FLAG2_CLIBOUT (1<< 2) /* output type is CLIB */
#define FLAG2_SYSTEMRELEASE (1<< 3) /* systemrelease special comment handling */
#define FLAG2_SFDOUT (1<< 4) /* output type is SFD */
#define FLAG2_LIBNAME (1<< 5) /* libname was specified on command line */
#define FLAG2_SMALLCODE (1<< 6) /* libraries use small code modell */
#define FLAG2_VOIDBASE (1<< 7) /* library base should be of type "void *" */
#define FLAG2_INLINEMAC (1<< 8) /* use inline macro instead of function */
#define FLAG2_DIRECTVARARGS (1<< 9) /* direct varargs for MorphOS stub libs */
#define FLAG2_PRELIB (1<<10) /* MorphOS gate PRELIB flag */
#define FLAG2_POSTLIB (1<<11) /* MorphOS gate POSTLIB flag */
#define FLAG2_REGLIB (1<<12) /* MorphOS gate REGLIB flag */
#define FLAG2_OLDVBCC (1<<13) /* old VBCC style */
#define FLAG2_SMALLTYPES (1<<14) /* allow small data types */
#define FLAG2_AUTOHEADER (1<<15) /* creates auto generated header */
#define FLAG2_LIBNAMECOM (1<<16) /* libname was specified in SFD comment */
#define FLAG2_OS4M68KCSTUB (1<<17) /* OS4 M68K stub needs C */
#define FLAG2_SHORTPPCVBCCINLINE (1<<18) /* shorter PPC inline using argument */
#define FUNCFLAG_NORMAL (1<<0) /* normal function */
#define FUNCFLAG_TAG (1<<1) /* a tagcall function */
#define FUNCFLAG_ALIAS (1<<2) /* an alias name for previous function */
#define FUNCFLAG_EXTENDMODE (1<<3) /* name and args extension for CSTUBS */
/* Different modes the main program uses, one for each different file
type (except for those done with one function and flag settings). */
#define MODUS_STUBTEXT 1
#define MODUS_STUBCODE 2
#define MODUS_LOCALDATA 3
#define MODUS_PRAGMA 4
#define MODUS_CSTUB 5
#define MODUS_SASPOWER 6
#define MODUS_PROTOPOWER 7
#define MODUS_BMAP 8
#define MODUS_PASCAL 9
#define MODUS_VBCCINLINE 10
#define MODUS_VBCCPUPLIB 11
#define MODUS_LVOLIB 12
#define MODUS_EMODULE 13
#define MODUS_REDIRECT 14
#define MODUS_ASMTEXTSF 15
#define MODUS_VBCCPUPTEXTSF 16
#define MODUS_VBCCWOSTEXTSF 17
#define MODUS_VBCCWOSINLINE 18
#define MODUS_VBCCMORPHTEXTSF 19
#define MODUS_VBCCMORPHCODE 20
#define MODUS_LVOLIBPPC 21
#define MODUS_FD 22
#define MODUS_CLIB 23
#define MODUS_SFD 24
#define MODUS_GATESTUBS 25
#define MODUS_VBCCMORPHINLINE 26
#define MODUS_XML 27
#define MODUS_OS4_PPCSTUBS 28
#define MODUS_OS4_68KSTUBS 29
#define MODUS_LVO 50 /* and 51 and 52 and 53 */
#define MODUS_PROTO 60 /* and 61 to 69 */
/* new protos start with 90, but are added to MODUS_PROTO ! */
#define MODUS_INLINE 80 /* and 81 to 86 */
#define MODUS_VBCC 90 /* and 91 to 94 */
#define MODUS_LVOPPC 100 /* and 101 */
#define MODUS_GENAUTO 110 /* and 111 to 113 */
#define MODUS_ERROR 200
enum ABI {ABI_M68K, ABI_PPC, ABI_PPC2, ABI_PPC0};
/* call types for CallFunc */
#define TAGMODE_NORMAL 0 /* produce normal functions only */
#define TAGMODE_TAGS 1 /* produce only tag functions */
#define TAGMODE_BOTH 2 /* produce both types */
/* types specifying name method for pragma creation */
#define PRAGMODE_PRAGLIB 1
#define PRAGMODE_PRAGSLIB 2
#define PRAGMODE_PRAGSPRAGS 3
#define PRAGMODE_NONE 4
#define BIAS_START 30 /* the library start offset */
#define BIAS_OFFSET 6 /* value to switch from one to next function */
#ifndef FD2PRAGMA_AMIGA
#define EXTTYPESFILEHIDDEN ".fd2pragma.types"
#endif
#ifndef EXTTYPESFILE
#define EXTTYPESFILE "fd2pragma.types"
#endif
#ifndef EXTTYPESFILE2
#ifdef FD2PRAGMA_AMIGA
#define EXTTYPESFILE2 "PROGDIR:fd2pragma.types"
#else
#define EXTTYPESFILE2 "/usr/local/share/fd2pragma.types"
#endif
#endif
#define AUTOHEADERTEXT "Automatically generated header! Do not edit!"
#define FDFILEEXTENSION "_lib.fd"
#define SFDFILEEXTENSION "_lib.sfd"
static const strptr RegNames[] = {
"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
"a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
"fp0", "fp1", "fp2", "fp3", "fp4", "fp5", "fp6", "fp7",
"d0/d1", "d2/d3", "d4/d5", "d6/d7",
};
static const strptr RegNamesUpper[] = {
"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
"A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7",
"FP0", "FP1", "FP2", "FP3", "FP4", "FP5", "FP6", "FP7",
"D0/D1", "D2/D3", "D4/D5", "D6/D7",
};
enum Register_ID {
REG_D0, REG_D1, REG_D2, REG_D3, REG_D4, REG_D5, REG_D6, REG_D7,
REG_A0, REG_A1, REG_A2, REG_A3, REG_A4, REG_A5, REG_A6, REG_A7,
REG_FP0, REG_FP1, REG_FP2, REG_FP3, REG_FP4, REG_FP5, REG_FP6, REG_FP7,
REG_D0D1, REG_D2D3, REG_D4D5, REG_D6D7
};
static const char ClobberRegs [] = {
REG_D0, REG_D1, REG_A0, REG_A1, REG_FP0, REG_FP1
};
#define MAXREGPPC 26
#define MAXREG 24 /* maximum registers of 68K */
#define MAXREGNF 16 /* maximum register number without float regs */
#define UNDEFREGISTER 255 /* for type scanner */
struct Args {
strptr infile;
strptr to;
strptr clib;
strptr header;
int32 special;
int32 mode;
};
struct ShortList {
struct ShortList *Next;
};
struct ShortListRoot {
struct ShortList *First;
struct ShortList *Last;
size_t Size;
};
#define AMIPRAGFLAG_PUBLIC (1<< 0) /* is a public function */
#define AMIPRAGFLAG_A6USE (1<< 1) /* A6 is used for this function */
#define AMIPRAGFLAG_A5USE (1<< 2) /* A5 is used */
#define AMIPRAGFLAG_A4USE (1<< 3) /* A4 is used */
#define AMIPRAGFLAG_D7USE (1<< 4) /* D7 is used */
#define AMIPRAGFLAG_ARGCOUNT (1<< 5) /* when double args, ... */
#define AMIPRAGFLAG_DIDARGWARN (1<< 6) /* We printed a argcount warning */
#define AMIPRAGFLAG_FLOATARG (1<< 7) /* It has a float argument */
#define AMIPRAGFLAG_DIDFLOATWARN (1<< 8) /* We printed a float warning */
#define AMIPRAGFLAG_NOCLIB (1<< 9) /* No clib definition found */
#define AMIPRAGFLAG_CLIBARGCNT (1<<10) /* CLIB argument count error */
#define AMIPRAGFLAG_PPC (1<<11) /* This is an PPC function */
#define AMIPRAGFLAG_PPC0 (1<<12) /* type PPC0 */
#define AMIPRAGFLAG_PPC2 (1<<13) /* type PPC2 */
#define AMIPRAGFLAG_M68K (1<<14) /* This is an M68K function */
#define AMIPRAGFLAG_OWNTAGFUNC (1<<15) /* MakeTagFunction create tag */
#define AMIPRAGFLAG_MOSSYSV (1<<16) /* MorphOS(sysv) type */
#define AMIPRAGFLAG_MOSSYSVR12 (1<<17) /* MorphOS(sysv,r12base) type */
#define AMIPRAGFLAG_MOSBASESYSV (1<<18) /* MorphOS(base,sysv) type */
#define AMIPRAGFLAG_VARARGS (1<<19) /* last argument is ... */
#define AMIPRAGFLAG_MOS_ALL (AMIPRAGFLAG_MOSSYSV|AMIPRAGFLAG_MOSSYSVR12|AMIPRAGFLAG_MOSBASESYSV)
struct AmiArgs {
strptr ArgName;
uint16 ArgReg;
};
#define NUMALIASNAMES 5
struct AmiPragma {
struct ShortList List;
uint32 Line;
uint32 Flags;
strptr FuncName;
strptr TagName;
struct Pragma_AliasName * AliasName[NUMALIASNAMES]; /* alias names */
uint16 NumArgs; /* register numbers */
uint16 CallArgs; /* argument number in fd file */
int16 Bias;
int8 NumAlias;
enum ABI Abi;
struct AmiArgs Args[MAXREGPPC];
};
struct Comment {
struct ShortList List;
strptr Data;
int16 Bias;
uint16 ReservedNum;
uint16 Version;
uint8 Private; /* is a flag only */
};
struct Include {
struct ShortList List;
strptr Include;
};
struct PragList {
struct ShortList List;
struct ShortListRoot Data; /* contains list of PragData */
strptr Basename;
};
struct PragData {
struct ShortList List;
struct ShortListRoot Name;
uint32 NumNames;
uint32 Bias;
uint32 NumArgs;
uint8 ArgReg[MAXREG];
};
struct FDData {
strptr Name;
strptr Basename;
uint32 Bias;
uint32 Mode; /* 0 = Normal, != 0 is TagName */
uint32 NumArgs;
uint8 ArgReg[MAXREG];
};
/* NOTE: string creation for CPP-Functions probably does not work at all
at the moment, as every compiler uses different systems which seem to
change constantly. */
/* These CPP types match the strings used for CPP name creation. The
defines are used both for name creation and type specification. */
#define CPP_TYPE_VOID 'v' /* void, VOID */
#define CPP_TYPE_BYTE 'c' /* char, int8 */
#define CPP_TYPE_WORD 's' /* short, int16 */
#define CPP_TYPE_LONG 'j' /* long, int32 */
#define CPP_TYPE_FLOAT 'f' /* float, FLOAT */
#define CPP_TYPE_DOUBLE 'd' /* double, DOUBLE */
#define CPP_TYPE_INT 'i' /* int */
#define CPP_TYPE_STRUCTURE 0
#define CPP_TYPE_VARARGS 'e'
#define CPP_TYPE_LONGLONG 'l' /* long long, int64 */
/* These types are for string creation only. */
#define CPP_TYPE_ENUM 'E'
#define CPP_TYPE_CONST 'C'
#define CPP_TYPE_FUNCTION 'F'
#define CPP_TYPE_POINTER 'P'
#define CPP_TYPE_UNSIGNED 'U'
#define CPP_TYPE_FUNCEND 'p'
#define CPP_TYPE_REGISTER 'r'
/* Some flags to be used in CPP_NameType->Flags. */
#define CPP_FLAG_UNSIGNED (1<<0) /* is an unsigned variable */
#define CPP_FLAG_CONST (1<<1) /* type is const */
#define CPP_FLAG_STRPTR (1<<2) /* this variable contains a strptr */
#define CPP_FLAG_POINTER (1<<3) /* the variable is a pointer */
#define CPP_FLAG_ENUM (1<<4) /* it is a enumeration */
#define CPP_FLAG_STRUCT (1<<5) /* it is a structure */
#define CPP_FLAG_UNION (1<<6) /* it is a union */
#define CPP_FLAG_FUNCTION (1<<7) /* it is a function */
#define CPP_FLAG_BOOLEAN (1<<8) /* in truth this element is bool */
#define CPP_FLAG_REGISTER (1<<9) /* argument is register type */
#define CPP_FLAG_TYPEDEFNAME (1<<10) /* name is created from typedef */
#define CPP_FLAG_ARRAY (1<<11) /* this type is an array */
#define CPP_FLAG_LONG (1<<12) /* type is long */
/* STRPTR is defined different under C and CPP -> I have to create two
names, one time unsigned char *, one time signed char *, when somewhere
a STRPTR occurs */
#define COPYCPP_PASSES 4
struct CPP_NameType { /* structure to describe a argument type */
strptr StructureName; /* if a structure or enum only */
strptr FuncArgs; /* arguments of function - unterminated */
strptr TypeStart; /* start of this type */
strptr Replace; /* replacement of type for SFD files */
strptr Unknown; /* unknown type handled as int */
strptr FunctionName; /* Argument name of function argument */
struct ClibData *FuncPtr; /* if it is a function pointer */
uint16 StructureLength; /* length of the structure name */
uint16 ArgsLength; /* length of FuncArgs */
uint16 TypeLength; /* length of this type */
uint16 FullLength; /* length of complete type */
uint16 PointerDepth; /* number of * in type */
uint16 FuncPointerDepth; /* number of * in function pointer */
uint16 Flags; /* see above flags */
uint8 Type; /* see above defines */
uint8 Register; /* register number */
};
struct ClibData { /* structure to describe data in CLIB file */
struct ClibData * Next; /* The next entry in this list */
strptr FuncName; /* name of the function */
struct CPP_NameType ReturnType; /* data for return type */
struct CPP_NameType Args[MAXREGPPC+1]; /* data for argument types */
uint16 NumArgs; /* number of arguments */
};
struct CPP_ExternNames { /* structure for EXTTYPESFILE data */
struct CPP_ExternNames * Next; /* The next entry in this list */
strptr Type; /* The unknown type */
struct CPP_NameType NameType; /* The replacement */
};
struct CPP_TypeField { /* structure for internal defined types */
strptr Text; /* name of the type */
uint16 Length; /* length of the name string */
uint16 Flags; /* CPP_FLAG flags */
uint8 Type; /* CPP_TYPE value */
};
struct CPP_Unknown {
struct CPP_Unknown *Next;
strptr Unknown;
};
struct Proto_LibType { /* structure to define structure type of base vars */
strptr BaseName; /* name of the library base */
strptr StructureName; /* name of the structure to be used (0 for default) */
strptr LibraryName; /* name of the library (maybe 0 for default method) */
strptr ShortBaseName; /* short name of the library base */
};
struct Pragma_ExecpName { /* structure to specify special tagnames */
strptr FunctionName; /* function name */
strptr TagName; /* tag name to be used for this function */
}; /* TagName 0 is valid as well to disable tagfunctions */
struct Pragma_AliasName {
strptr FunctionName;
strptr AliasName;
uint32 Type;
};
#define NTP_NORMAL 0 /* no tags/args */
#define NTP_TAGS 1 /* TagFunction */
#define NTP_ARGS 2 /* ArgFunction */
#define NTP_UNKNOWN 3 /* CommentFunction */
struct NameList {
struct ShortList List;
uint32 Type; /* set by OptimizeFDData */
strptr NormName;
strptr PragName;
};
struct InFile {
strptr pos;
strptr buf;
size_t size;
};
/* EHF definitions! */
#define HUNK_PPC_CODE 0x4E9
#define HUNK_RELRELOC26 0x4EC
#define EXT_RELREF26 229
/* ------------------------------------------------------------------ */
/* A short set of ELF definitions, see pasm sources in vbcc release for an
more complete set of stuff or get elf documentation. These are needed for
VBCCPUPCode function. */
#define ELFCLASS32 1
#define ELFDATA2MSB 2
#define EV_CURRENT 1 /* version information */
#define ET_REL 1 /* type information */
#define EM_POWERPC 20
#define SHT_NULL 0 /* inactive */
#define SHT_PROGBITS 1 /* program information */
#define SHT_SYMTAB 2 /* symbol table */
#define SHT_STRTAB 3 /* string table */
#define SHT_RELA 4 /* relocation */
#define SHF_ALLOC 0x2 /* needs memory when started */
#define SHF_EXECINSTR 0x4 /* executable instructions */
#define SHN_ABS 0xFFF1
#define EI_NIDENT 16
#define EI_MAG0 0
#define EI_MAG1 1
#define EI_MAG2 2
#define EI_MAG3 3
#define EI_CLASS 4
#define EI_DATA 5
#define EI_VERSION 6
#define STB_LOCAL 0
#define STB_GLOBAL 1
#define STT_FUNC 2
#define STT_NOTYPE 0
#define STT_SECTION 3
#define STT_FILE 4
#define ELF32_ST_INFO(b,t) (((b)<<4)+((t)&0xf))
#define ELF32_R_INFO(s,t) (((s)<<8)+(uint8)(t))
#define R_PPC_ADDR16_LO 4
#define R_PPC_ADDR16_HA 6
#define R_PPC_REL24 10
#define R_PPC_SDAREL16 32
struct ArHeader {
string ar_name[16]; /* name */
string ar_time[12]; /* modification time */
string ar_uid[6]; /* user id */
string ar_gid[6]; /* group id */
string ar_mode[8]; /* octal file permissions */
string ar_size[10]; /* size in bytes */
string ar_fmag[2]; /* consistency check */
};
/* AmigaOS hunk structure definitions */
#ifdef __amigaos4__
#include <dos/doshunks.h>
#else
#define HUNK_UNIT 999
#define HUNK_NAME 1000
#define HUNK_CODE 1001
#define HUNK_BSS 1003
#define HUNK_ABSRELOC32 1004
#define HUNK_EXT 1007
#define HUNK_SYMBOL 1008
#define HUNK_END 1010
#define HUNK_DREL16 1016
#define EXT_DEF 1 /* normal definition */
#define EXT_ABS 2 /* Absolute definition */
#define EXT_REF32 129 /* 32 bit absolute reference to symbol */
#define EXT_DEXT16 134 /* 16 bit data relative reference */
#endif
/* ------------------------------------------------------------------ */
static struct Args args = {0,0,0,0,6,0};
static struct InFile in = {0,0,0};
static FILE * outfile;
static struct ClibData * clibdata = 0;
static struct ShortListRoot AmiPragma = {0,0,sizeof(struct AmiPragma)},
Comment = {0,0,sizeof(struct Comment)},
Includes = {0,0,sizeof(struct Include)};
static struct CPP_ExternNames *extnames = 0;
static struct CPP_Unknown *unknown = 0;
static strptr BaseName = 0; /* the correct basename */
/* the filename part of basename without Base */
static strptr ShortBaseName = 0;
/* like ShortBaseName, but upper case */
static strptr ShortBaseNameUpper = 0;
static strptr HEADER = 0;
static strptr Copyright = 0;
static strptr filenamefmt = 0;
static strptr libtype = 0;
static strptr libname = 0;
static strptr defabi = 0;
static strptr hunkname = ".text";
static strptr datahunkname = "__MERGED";
static strptr PPCRegPrefix = "r";
static strptr IDstring = 0;
static strptr prefix = "";
static strptr subprefix = "";
static strptr premacro = "";
static uint8 * tempbuf = 0;
static size_t headersize = 0;
static uint32 Flags = 0;
static uint32 Flags2 = 0;
/* Output error occured when 0 */
static uint32 Output_Error = 1;
/* are there some tagfuncs in FD */
static uint32 tagfuncs = 0;
/* priority for auto libopen */
static uint32 priority = 5;
/* needed for filename */
static string filename[255];
/* Only for E-Stuff, FD, SFD, XML creation */
static int32 LastBias = 0;
/* Only for PPC-LVO Lib's */
static uint8 * elfbufpos = 0;
/* Only for PPC-LVO Lib's */
static uint32 symoffset = 0;
/* Only for FD, SFD creation */
static enum ABI CurrentABI = ABI_M68K;
/* Prototypes for the functions */
static strptr DupString(strptr, size_t);
static strptr AllocListMem(size_t);
static strptr SkipBlanks(strptr);
static strptr SkipBlanksRet(strptr);
static strptr SkipName(strptr);
static uint32 GetTypes(void);
static strptr GetBaseType(void);
static strptr GetBaseTypeLib(void);
static strptr GetLibraryName(void);
static strptr GetIFXName(void);
static int32 MakeShortBaseName(void);
static uint32 OpenDest(strptr);
static uint32 CloseDest(strptr);
static uint32 MakeTagFunction(struct AmiPragma *);
static void MakeLines(strptr, uint32);
static uint32 SpecialFuncs(void);
static void SortFDList(void);
static void AddAliasName(struct AmiPragma *, struct Pragma_AliasName *,
uint32);
static uint32 CheckNames(struct AmiPragma *);
static uint32 ScanSFDFile(enum ABI);
static uint32 ScanFDFile(void);
static int32 ScanTypes(strptr, uint32);
static void FindHeader(void);
static uint32 GetRegisterData(struct AmiPragma *);
static uint16 GetFRegisterData(struct AmiPragma *);
static uint32 OutputXDEF(uint32, strptr, ...);
static uint32 OutputXREF(uint32, uint32, strptr, ...);
static uint32 OutputXREF2(uint32, uint32, uint32, strptr, ...);
static uint32 OutputSYMBOL(uint32, strptr, ...);
static uint8 * AsmStackCopy(uint8 *, struct AmiPragma *, uint32, uint32);
/* ------------------------------------------------------------------ */
static void DoError(uint32, uint32, ...);
static uint32 CheckError(struct AmiPragma *, uint32);
static uint32 DoOutputDirect(void *, size_t);
#if defined(__GNUC__)