-
Notifications
You must be signed in to change notification settings - Fork 3
/
eecmain.e
14209 lines (12604 loc) · 378 KB
/
eecmain.e
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
OPT PREPROCESS
#ifndef STACKSIZE
#define STACKSIZE 262144
#endif
OPT STACK=STACKSIZE
OPT LARGE
/* EEC by Samuel D. Crow [samuraileumas yahoo com] is Copyright (c) 2019 */
/* Derived from the work listed below */
/* ECX by Leif Salomonsson [ecx tele2 se] is Copyright (c) 2002-2008 */
/* Released under the ECX COMPILER LICENSE, See ECXCOMPILERLICENSE.TXT */
/*
ECX homepage: "http://blubbedev.net/ecx"
*/
-> Apr 15 2004: v45
-> June 2004: v46
-> Aug 2004: v47
-> Nov 2004: v48
-> Feb 2005: v49pre (aug 2005, released as 1.4.5)
-> Aug 2005: v49pre (sept 2005, 1.4.6)
-> Sep 2005: v49pre (1.4.7)
-> Apr 2006: v50 (1.5)
-> Mar 2007: v51 (1.6)
-> Jun 2007: v52 (1.7)
-> Aug 2007: v52 (1.7.1)
-> sept 2007: v52 (1.7.2)
-> Sept 2007: v53 (1.8.0) ecxmain.e
-> Feb 2008: v53 (1.8.1)
-> Apr 2008: v54 (1.9.0)
-> May 2008: v55 (1.10.0) => 2.0.0 !
-> something v56 (2.1)
-> July 2009: v57 (2.2)
-> Something: 2.2.1
-> June 2010: v57 (2.2.2)
-> June 2013: v58 (2.3.0)
-> Sept 2013: keyfile stuff removed. (2.3.1)
#define COMPILEDWITH 'Compiled with'
#define ECX_WIP ' WIP'
->#define ECX_WIP ''
#define ECX_BRANCH_VERSION_STR '58'
#define ECX_BRANCH_VERSION_NUM 58
#define ECX_COPYRIGHT_STR 'by Leif Salomonsson (c) 2002-2013'
#define ECX_VERSTR 'ECX 2.3.1' + ECX_WIP
#ifndef ECX_VERSION
#define ECX_PLATFORM_STR 'AmigaOS,68K'
#endif
#ifdef ECX_VERSION
#define ECX_PLATFORM_STR __TARGET__
#endif
#define ECX_VERSION_STRING '$VER: ' + \
ECX_VERSTR + \
' (xx.08.2013) ' + \
'[v' + \
ECX_BRANCH_VERSION_STR + \
'] (' + \
ECX_PLATFORM_STR + \
') ' + \
ECX_COPYRIGHT_STR
CONST VERSIONLONG = $FF020301 -> REPLACE FF with 00 for release version
-> #define DEBUG
#ifdef DEBUG
->#define DBG_MAIN
->#define DBG_PP
->#define DBG_EXE
->#define DBG_PASS1
->#define DBG_TRANS
->#define DBG_BMOD
->#define DBG_OOP
#endif
CONST REUSEREGS = TRUE
MODULE 'dos/dos'
MODULE 'exec/lists'
MODULE 'exec/nodes'
MODULE 'dos/dosextens'
MODULE 'dos/var' -> 1.10.0
MODULE '*binary'
MODULE '*compiler'
MODULE '*eecelf'
MODULE '*runtime' -> 1.5.6
MODULE '*support' -> 1.6.1
MODULE '*codegen' -> 1.8.0 (v53)
MODULE '*common' -> 1.8.0 (v53)
MODULE '*assembler' -> 1.10.0 (v55)
->MODULE '*initcode' -> 1.10.0 (v55)
MODULE '*inline68' -> 1.10.0 (v55)
MODULE '*inlineppc' -> 1.10.0 (v55)
MODULE '*ppcgen' -> 1.10.0 (v55)
MODULE '*020gen' -> 1.10.0 (v55)
MODULE '*ecmodtrans' -> 1.10.0 (v55)
MODULE '*libstubs' -> 2.2 v57
DEF g_globcheckhead="HEAD"
DEF g_modulecache:PTR TO modulecache
DEF g_optmodule=FALSE -> OPT MODULE
DEF g_optpreprocess=FALSE
DEF g_optexport=FALSE -> OPT EXPORT
DEF g_optstack=FALSE -> OPT STACK
DEF g_optosversion=FALSE -> OPT OSVERSION
DEF g_optpowerpc=CPU_NONE -> OPT POWERPC
DEF g_moduledir=NIL -> 1.10.0 now linked estrings
DEF g_nilcheck=FALSE -> NILCHECK/S
DEF g_optimize=FALSE -> OPTI/S
DEF g_nowarn=FALSE -> OPT NOWARN, NOWARN/S
DEF g_vardebug=FALSE -> VARDEBUG/S
DEF g_linedebug=FALSE -> LINEDEBUG/S
DEF g_stepdebug=FALSE -> STEPDEBUG/S
DEF g_stepdebug50=FALSE -> STEPDEBUG50/S
DEF g_symbolhunk=FALSE -> SYMBOLHUNK/S
DEF g_quiet=FALSE -> v49
DEF g_showbuf=FALSE
DEF g_numregalloc=0
DEF g_numfregalloc=0 -> v48
DEF g_optnostartup=FALSE
DEF g_nodefmods=FALSE
DEF g_linkobjmode=FALSE -> 1.7.1
DEF g_optroundnear=FALSE -> 1.7.1
DEF g_sourcename[512]:STRING -> was pointer
DEF g_linenum=0
DEF g_stacksize=0
DEF g_modulelist:mlh -> shared between various
DEF g_warnlist -> v45
DEF g_emacrolist=NIL
DEF g_librarymode=FALSE, g_libraryname, g_libraryversion
DEF g_libraryrevision, g_libraryidstr
DEF g_entrytable[1024]:ARRAY OF LONG, g_nrofentries=0
DEF g_econstlist=NIL:PTR TO const
DEF g_gvarlist=NIL:PTR TO gvar
DEF g_objectlist=NIL:PTR TO object
DEF ident_STRLEN:PTR TO const -> v46
DEF g_currentproc:PTR TO proc
DEF g_unrefs=NIL
DEF g_internalfuncs=NIL:PTR TO LONG, g_internalfuncsppc=NIL:PTR TO LONG
DEF link_datasize=0
DEF g_globalsize=0:PTR TO LONG -> first global starts at 0(A4).
DEF link_globaldatasize=0
DEF link_codesize=0
DEF link_reloc32list=NIL, link_nrofreloc32s=0
DEF g_codebuf, g_codeptr:PTR TO LONG
DEF g_databuf, g_databufsize=0
DEF g_linelist:PTR TO linedef
DEF g_extracodesize=0 -> set by various in pass1
DEF g_incbinsize=0 -> v45: sum of all incbins
DEF g_codelablist:PTR TO codelab -> user labels, procedures, generated labels. .codelink
DEF g_rwreflist:PTR TO rwref -> immedlists
DEF g_proclist:PTR TO proc -> user labels and procedures .next
DEF g_currentobject=NIL:PTR TO object
DEF g_temparray[TEMPARRAYLEN]:ARRAY OF LONG -> for members, params
DEF g_tempstr[TEMPSTRLEN]:STRING -> for immedstrings
DEF g_ppstring=NIL:PTR TO CHAR -> for macro definition and macro expansion
DEF g_argbodystr=NIL:PTR TO CHAR -> for expanding body with arguments
DEF g_argprocstr=NIL:PTR TO CHAR -> 1.10.0, for processing arguments
DEF itmz_linestart=NIL:PTR TO item
DEF itmz_buffer=NIL:PTR TO item, itmz_bufend -> realloc-able
DEF itmz_stringssize=0
DEF itmz_labelhashtable:PTR TO LONG
DEF g_secondariesloaded=FALSE -> V47
DEF c_functiondepth=0 -> to keep track of depth in pass1
DEF itmz_openbrackdepth=0 -> to keep track in itemizer
DEF g_startupcodelab:PTR TO codelab -> v48
DEF g_currentloopdepth=0 -> FOR/WHILE/LOOP/REPEAT. used by autoregalloc
-> v49
DEF g_currentselectdepth=0, g_currentifdepth=0
DEF g_privatekey=FALSE -> v45
DEF g_codegen=NIL:PTR TO codegen -> v46
-> v49
DEF g_multireturn:PTR TO multireturn -> set this when calling function/method
-> v50 (1.5.1)
DEF g_ivarsadded=FALSE -> 1.7.1
DEF g_methodlist:PTR TO proc -> all defned methods in this source here. meth.next lkinks them
DEF g_optminstartup=FALSE -> 1.5.4
DEF g_optosid=OSID_NONE -> 2.0
DEF g_maxmodosvers=NIL -> gets set to maximum osversion from modules 1.6.0
DEF g_sizeofptr=4 -> v52
DEF g_xcodelist=NIL -> 1.7.1, for external code referenced from LINKOBJECT
-> v53
DEF g_forcemodsyms=FALSE ->TRUE if user set SYMBOLHUNK/S for module explicetly
DEF g_libraryrtagsname=NIL
DEF itmz_export=FALSE -> 1.8.0
DEF g_modname[128]:STRING -> only filename !
DEF g_exename[128]:STRING -> only filename !
DEF g_destdir[256]:STRING
DEF g_naturalalign=FALSE -> 1.8.12 .. OBJECTs
-> 1.10.0
DEF ident_LINENUM:PTR TO const
DEF g_elfsym_target[100]:STRING -> __abox__ etc
DEF g_elf_usephdr=FALSE -> true for os4
DEF g_opt_moduledir[1024]:STRING -> OPT DIR
DEF g_arg_moduledir[1024]:STRING -> comandline dir
DEF g_defmodnames=NIL -> linked list of estrings set by scantargetmodule()
DEF g_privoptnotargetmod=FALSE -> special opt to not load target module (from self)
DEF
g_compiledwithstr,
g_verstr,
g_platformstr
DEF g_outformatstr[50]:STRING -> 2.0
DEF g_dblablist:PTR TO codelab -> 2.1, link all debugsymbols
-> 2.2
DEF g_showcondsyms=FALSE, g_condsymnames=NIL
DEF g_modglobinitlab:PTR TO genlab -> used in module mode with code
DEF g_safeimmlists=FALSE
-> 2.2.3
DEF itmz_lastbrackline -> improving error report
-> 2.3
DEF g_varfill=FALSE:PTR TO LONG
DEF g_globchecktail="TAIL"
CONST TICKS_PER_MINUTE=TICKS_PER_SECOND*60
ENUM ARG_SOURCE,
ARG_NILCHECK,
ARG_HOLD,
ARG_WBTOFRONT,
ARG_OPTIMIZE,
ARG_LARGE,
ARG_SHOWFNAME,
ARG_NOWARN,
ARG_VARDEBUG,
ARG_LINEDEBUG,
ARG_SYMBOLHUNK,
ARG_IGNORECACHE,
ARG_NODEFMODS,
ARG_SHOWBUF,
ARG_NUMREGALLOC,
ARG_NUMFREGALLOC, -> v48
ARG_TOADDR, -> v48
ARG_ABSOLUTE, -> v48
ARG_MODULEDIR, -> v48
ARG_DEFINE, -> v49p
ARG_DESTDIR, -> v49p
ARG_QUIET, -> v49p
ARG_EXENAME, -> v49
ARG_MODNAME, -> 1.5.6
ARG_STEPDEBUG, -> 1.6.0
ARG_STEPDEBUG50, -> 2.3.1
ARG_POWERPC, -> v52
ARG_MORPHOS, -> v52
ARG_AMIGAOS, -> 1.10.0
ARG_SHOWARGS, -> 1.10.0
ARG_AMIGAOS4, -> 2.0.0
ARG_OUTFORMAT, -> 2.0
ARG_SHOWCONDSYMS, -> 2.2
ARG_ERRLINE, -> 2.2
ARG_VARFILL, -> 2.3
NROFARGS -> keep last !
PROC main() HANDLE
DEF fbuf, flen, fib:fileinfoblock
DEF fh=NIL, rdargs=NIL, args:PTR TO LONG
DEF t:PTR TO item
DEF err
DEF mh:PTR TO moduleheader, a
DEF tempstr[2000]:STRING
DEF hold=FALSE, wbtofront=FALSE
DEF codebufsize, hln:PTR TO hln
DEF size
DEF ds1:datestamp, ds2:datestamp -> v49
DEF process:PTR TO process -> v49
DEF argstemplate, targetmacro:PTR TO macro
DEF errline=FALSE
DateStamp(ds1)
NEW args[NROFARGS]
argstemplate := 'SOURCE/A,'+
'NIL=NILCHECK/S,'+
'HOLD/S,'+
'WBTOFRONT/S,'+
'OPTI/S,'+
'LARGE/S,'+
'SHOWFNAME/S,'+
'NOWARN/S,'+
'VAR=VARDEBUG/S,'+
'LINE=LINEDEBUG/S,'+
'SYM=SYMBOLHUNK/S,'+
'ICA=IGNORECACHE/S,'+
'NODEFMODS/S,'+
'SHOWBUF/S,'+
'REG=NUMREGALLOC/N,'+
'FREG=NUMFREGALLOC/N,'+
'TOADDR/N,'+
'ABSOLUTE/N,'+
'MDIR=MODULEDIR/K,'+
'DEFINE/K,'+
'DDIR=DESTDIR/K,'+
'QUIET/S,'+
'EXENAME/K,'+
'MODNAME/K,'+
'STEP=STEPDEBUG/S,'+
'STEP50=STEPDEBUG50/S,'+
'POWERPC/S,'+
'MORPHOS/S,'+
'AMIGAOS/S,'+
'SHOWARGS/S,'+
'AMIGAOS4/S,'+
'OUTFORMAT/K,'+
'SHOWCONDSYMS/S,'+
'ERRLINE/S,'+
'VARFILL/N'
/* read agrs */
rdargs := ReadArgs(argstemplate, args, NIL)
IF rdargs = NIL THEN Raise("ARGS")
initSupport() -> 1.6.1
IF args[ARG_IGNORECACHE] = NIL
Forbid()
g_modulecache := FindSemaphore('EcxCache')
Permit()
IF g_modulecache = NIL
g_modulecache := ALLOCMEM(SIZEOF modulecache, MEMF_PUBLIC OR MEMF_CLEAR)
IF g_modulecache = NIL THEN Raise("MEM")
g_modulecache.modlist.head := g_modulecache.modlist + 4
g_modulecache.modlist.tail := NIL
g_modulecache.modlist.tailpred := g_modulecache.modlist
g_modulecache.ln.name := ALLOCMEM(9,MEMF_CLEAR OR MEMF_PUBLIC)
AstrCopy(g_modulecache.ln.name, 'EcxCache')
AddSemaphore(g_modulecache)
g_modulecache.ident := "MC" -> 1.8.0
ENDIF
ENDIF
IF g_modulecache
IF g_modulecache.ident <> "MC" THEN Raise("MCC") -> 1.8.0
IF AttemptSemaphore(g_modulecache) = NIL THEN g_modulecache := NIL
ENDIF
g_compiledwithstr := COMPILEDWITH
g_verstr := ECX_VERSTR
g_platformstr := ECX_PLATFORM_STR
NEW itmz_labelhashtable[LHASHSIZE+1] -> hln hash
IF args[ARG_NILCHECK] THEN g_nilcheck := TRUE
IF args[ARG_NOWARN] THEN g_nowarn := TRUE
IF args[ARG_SYMBOLHUNK]
g_symbolhunk := TRUE
ENDIF
IF args[ARG_LINEDEBUG] THEN g_linedebug := TRUE
IF args[ARG_STEPDEBUG]
g_stepdebug := TRUE
g_symbolhunk := TRUE
g_linedebug := TRUE
g_vardebug := TRUE
ENDIF
IF args[ARG_STEPDEBUG50]
g_stepdebug50 := TRUE
g_symbolhunk := TRUE
g_linedebug := TRUE
g_vardebug := TRUE
ENDIF
IF args[ARG_VARDEBUG] THEN g_vardebug := TRUE
IF args[ARG_SHOWBUF] THEN g_showbuf := TRUE
IF args[ARG_WBTOFRONT] THEN wbtofront := TRUE
IF args[ARG_HOLD] THEN hold := TRUE
IF args[ARG_NODEFMODS] THEN g_nodefmods := TRUE
IF args[ARG_NUMREGALLOC] THEN g_numregalloc := Long(args[ARG_NUMREGALLOC])
IF args[ARG_NUMFREGALLOC] THEN g_numfregalloc := Long(args[ARG_NUMFREGALLOC])
IF args[ARG_OPTIMIZE]
g_optimize := TRUE -> not used yet
g_numregalloc := -1
g_numfregalloc := -1
ENDIF
-> 2.3
IF args[ARG_VARFILL] THEN g_varfill := args[ARG_VARFILL]
IF g_vardebug THEN g_linedebug := TRUE -> 1.6.0
IF g_linedebug THEN g_symbolhunk := TRUE -> 1.6.0
-> 1.10.0
IF args[ARG_MODULEDIR]
StrCopy(g_arg_moduledir, args[ARG_MODULEDIR])
ENDIF
-> 2.2
IF args[ARG_ERRLINE] THEN errline := TRUE
IF args[ARG_QUIET] THEN g_quiet := TRUE
g_sizeofptr := 4 ->IF args[ARG_E64] THEN 8 ELSE 4 -> v52
g_modulelist.head := g_modulelist + 4
g_modulelist.tail := NIL
g_modulelist.tailpred := g_modulelist
StrCopy(g_sourcename, args[ARG_SOURCE])
IF StrCmp(g_sourcename+EstrLen(g_sourcename)-2, '.e') = FALSE THEN StrAdd(g_sourcename, '.e')
LowerStr(g_sourcename)
-> we need these this early in case error occurs, so we delete old file
IF args[ARG_DESTDIR]
StrCopy(g_destdir, args[ARG_DESTDIR])
ELSE
StrCopy(g_destdir, g_sourcename, FilePart(g_sourcename) - g_sourcename)
ENDIF
IF args[ARG_EXENAME]
StrCopy(g_exename, args[ARG_EXENAME])
ENDIF
IF args[ARG_MODNAME]
StrCopy(g_modname, args[ARG_MODNAME])
StrAdd(g_modname, '.m')
ENDIF
IF g_quiet = FALSE
WriteF('\s (\s) \s.\n',
ECX_VERSTR, ECX_PLATFORM_STR, ECX_COPYRIGHT_STR)
WriteF('\s \s.\n')
ENDIF
IF args[ARG_SHOWARGS] THEN WriteF('Arguments: "\s"\n', arg)
IF args[ARG_SHOWFNAME] THEN WriteF('-> \s\n', g_sourcename)
IF g_showbuf
WriteF('Stack: \d bytes FIXED.\n', FreeStack())
ENDIF
-> 1.10.0
->IF readConfig() = FALSE
-> addModuledirs('ecxmodules:')
->ENDIF
fh := Open(g_sourcename, OLDFILE)
IF fh = NIL THEN Throw("OPEN", g_sourcename)
IF ExamineFH(fh, fib) = NIL THEN Throw("EXAM", g_sourcename)
flen := fib.size
fbuf := NEWMEMR(flen+4)
fbuf[0] := 10 -> must start with newline
IF Read(fh, fbuf+1, flen) <> flen THEN Throw("READ", g_sourcename)
fbuf[flen+1] := 10 -> must end with newline
IF NameFromFH(fh, g_sourcename, StrMax(g_sourcename)) = NIL THEN Throw("NFFH", g_sourcename)
SetStr(g_sourcename, StrLen(g_sourcename))
LowerStr(g_sourcename) -> 1.8.2 fix
Close(fh) ; fh := NIL
addKeywords()
add_iconsts()
-> v52, deprecated,obsolete v55
->IF args[ARG_POWERPC]
-> g_optosid := OSID_MORPHOS
-> g_optpowerpc := CPU_PPC
->ENDIF
IF args[ARG_MORPHOS] OR args[ARG_POWERPC]
g_optosid := OSID_MORPHOS
g_optpowerpc := CPU_PPC
StrCopy(g_outformatstr, 'ELF')
ELSEIF args[ARG_AMIGAOS]
g_optosid := OSID_AMIGAOS
g_optpowerpc := CPU_M68
StrCopy(g_outformatstr, 'ADOS')
ELSEIF args[ARG_AMIGAOS4]
g_optosid := OSID_AMIGAOS4
g_optpowerpc := CPU_PPC
StrCopy(g_outformatstr, 'ELF')
ENDIF
-> 2.0
IF args[ARG_OUTFORMAT]
StrCopy(g_outformatstr, args[ARG_OUTFORMAT])
UpperStr(g_outformatstr)
ENDIF
IF g_optosid <> OSID_NONE THEN loadTargetModule() -> 2.0
-> v49, add commandline define ?
IF args[ARG_DEFINE] THEN addCLDefine(args[ARG_DEFINE])
-> 2.2
IF args[ARG_SHOWCONDSYMS] THEN g_showcondsyms := TRUE
/* internalfuncs may be un-inited ! */
g_internalfuncs := [NIL]
g_internalfuncsppc := [NIL]
-> 1.5.4
t := uncommentSource(fbuf) - fbuf
IF t > (fbuf+flen+4) THEN Raise("UNCO")
->WriteF(fbuf)
t := Mul(Div(t,10), SIZEOF item) + (4000*SIZEOF item)
itmz_buffer := NEWMEMR(t)
itmz_linestart := itmz_buffer
itmz_bufend := itmz_buffer + t
IF g_quiet = FALSE THEN WriteF('Lexical and syntax analysis..\n')
setLinenum(0)
itmz_linestart.data := 10
itmz_linestart.info := 0
t := itemize(fbuf, itmz_linestart+SIZEOF item)
t.data := 10 ; t++
t.data := NIL ; t++
IF t > itmz_bufend THEN Raise("IBUF")
-> 1.8.2
g_databufsize := g_databufsize + 15 AND (-16)
initTarget() -> in case it has not beendone in itemize() pass ! 1.8.0
initIvars() -> we need this too
-> 1.8.0
IF EstrLen(g_exename) = 0
StrCopy(g_exename, FilePart(g_sourcename), StrLen(FilePart(g_sourcename))-2)
ENDIF
IF EstrLen(g_modname) = 0
StrCopy(g_modname, FilePart(g_sourcename), StrLen(FilePart(g_sourcename))-2)
StrAdd(g_modname, '.m')
ENDIF
IF (g_globcheckhead <> "HEAD") OR (g_globchecktail <> "TAIL") THEN Raise("HTC1") -> 1.8.0
IF g_showbuf
WriteF('Item buffer: \d of \d bytes used.\n', t-itmz_buffer, itmz_bufend-itmz_buffer)
ENDIF
IF g_optosversion = 0 THEN g_optosversion := g_maxmodosvers -> 1.6.0
IF g_quiet = FALSE
WriteF('Targeting ')
IF g_proclist -> 1.8.0
hln := getLabelHLN('__TARGET__') -> 2.0
targetmacro := hln.ident
IF targetmacro THEN WriteF('\s ', targetmacro.ascii)
ENDIF
IF g_optmodule
WriteF(IF g_linkobjmode THEN 'linkobject' ELSE 'module')
ELSEIF g_librarymode
WriteF('library (\d.\d)', g_libraryversion, g_libraryrevision)
ELSE
WriteF('executable')
ENDIF
-> 1.6.0
WriteF(IF g_optosversion THEN ', osversion \d.\n' ELSE '.\n', g_optosversion)
ENDIF
DISPOSE(fbuf)
IF g_optmodule = FALSE THEN loadSecondaryModules() -> v49, do it here
codebufsize := (t - itmz_buffer / 2) + g_extracodesize -> functions/expressions extra code
codebufsize := Div(codebufsize,4)
codebufsize := Mul(codebufsize, IF g_optpowerpc THEN 3 ELSE 2)
codebufsize := codebufsize +
g_incbinsize +
itmz_stringssize +
32000 + -> startup,ifuncs,glob-initcode, misc
g_databufsize + -> datainit
link_datasize -> rw-initcode
g_codebuf := NEWMEMR(codebufsize)
g_codeptr := g_codebuf
g_databuf := NEWMEMR(g_databufsize) -> size computed in syntax/immedlist()
#ifdef DBG_PASS1
DEBUGF('finnishObjects()\n')
#endif
finnishObjects()
allocateGlobals() -> allocates all globals for exe, private globals for module
IF g_optmodule = FALSE
linkModules()
putAlign(4)
fixExtMethsOffsets()
patchMethods()
putStartup()
IF g_librarymode THEN putLibTable()
ENDIF
IF g_quiet = FALSE THEN WriteF('Parsing and generating..\n')
-> v57
hln := getLabelHLN('___SAFELISTS___')
IF hln.ident THEN g_safeimmlists := TRUE
t := g_codegen.compileCode(itmz_buffer)
putAlign(4)
#ifdef DBG_MAIN
DEBUGF('freeing items buffer $\h\n', itmz_buffer)
#endif
DISPOSE(itmz_buffer)
itmz_buffer := NIL
#ifdef DBG_MAIN
DEBUGF('freed items buffer OK\n')
#endif
IF g_codeptr > (g_codebuf + codebufsize) THEN Raise("CBUF")
putClassinfos()
putRelocStrings()
putAlign(4)
IF g_codeptr > (g_codebuf + codebufsize) THEN Raise("CBUF")
IF g_showbuf THEN WriteF('Code buffer: \d of \d bytes used.\n', g_codeptr - g_codebuf, codebufsize)
IF g_optmodule
StrCopy(tempstr, g_destdir)
StrAdd(tempstr, g_modname)
IF g_codeptr > g_codebuf -> 2.2
g_modglobinitlab := newLabel()
putLabel(g_modglobinitlab)
g_codegen.putGlobInit()
putAlign(4)
g_codeptr[]++ := VERSIONLONG -> 1.6.0
ENDIF
patchReferences()
IF g_linkobjmode -> 1.7.1
fbuf, size := makeLINKOBJ()
IF writeNewFile(fbuf, size, tempstr) = NIL THEN Throw("WRIT", tempstr)
ELSE
mh, size := makeModule()
setsum(mh)
IF writeNewFile(mh, size, tempstr) = NIL THEN Throw("WRIT", tempstr)
ENDIF
ELSE
IF g_optosid = OSID_MORPHOS
StrCopy(g_elfsym_target, '__abox__')
ELSEIF g_optosid = OSID_AMIGAOS4
StrCopy(g_elfsym_target, '__amigaos4__')
ELSE
StrCopy(g_elfsym_target, '__amigaos__')
ENDIF
/* v48 */
IF g_librarymode
putAlign(4)
IF g_optpowerpc THEN putEntriesPPC() ELSE putEntries68K()
putAlign(4)
ENDIF
linkMainIfuncs()
putAlign(4)
finnishExe()
g_codeptr[]++ := VERSIONLONG -> 1.6.0
patchReferences()
IF StrCmp(g_outformatstr, 'RAW')
fbuf, size := makeRAW(
IF args[ARG_ABSOLUTE] THEN Long(args[ARG_ABSOLUTE]) ELSE -1,
IF args[ARG_TOADDR] THEN Long(args[ARG_TOADDR]) ELSE NIL) -> v48
ELSEIF StrCmp(g_outformatstr, 'ELF')
fbuf, size := makeELF()
ELSEIF StrCmp(g_outformatstr, 'ADOS')
fbuf, size := makeADOS()
ELSE
reportIErr('unknown out format')
ENDIF
IF g_librarymode
StrCopy(tempstr, g_destdir)
StrAdd(tempstr, g_modname)
mh, a := makeLibMod()
setsum(mh)
IF writeNewFile(mh, a, tempstr) = NIL THEN Throw("WRIT", tempstr)
ENDIF
StrCopy(tempstr, g_destdir)
StrAdd(tempstr, g_exename)
IF args[ARG_TOADDR] = FALSE -> v48
IF writeNewExeFile(fbuf, size, tempstr) = NIL THEN Throw("WRIT", tempstr)
ENDIF
#ifdef DBG_EXE
DEBUGF('exe: \d bytes written\n', size)
#endif
ENDIF
checkUnrefs()
printUnrefs()
showCondSyms()
->printUndefglobs() -> v50 removed v55
IF (g_globcheckhead <> "HEAD") OR (g_globchecktail <> "TAIL") THEN Raise("HTC2")
->checkHashTable() -> debug
EXCEPT DO
-> debug
->IF g_modulecache
-> hln := getLabelHLN('createZonegroupClass')
-> g_modulecache.rsrvd := hln.ident
->ENDIF
-> moved here from above again 1.8.0
IF g_modulecache
IF EstrLen(g_modname)
mh := findModuleFile(g_modulecache.modlist, g_modname)
IF mh
IF mh.identification = "ECXM" -> 1.8.0
Remove(mh)
freeModule(mh)
ENDIF
ENDIF
ENDIF
ENDIF
-> 1.8.0
IF exception
IF EstrLen(g_exename) = 0
StrCopy(g_exename, FilePart(g_sourcename), StrLen(FilePart(g_sourcename))-2)
ENDIF
IF EstrLen(g_modname) = 0
StrCopy(g_modname, FilePart(g_sourcename), StrLen(FilePart(g_sourcename))-2)
StrAdd(g_modname, '.m')
ENDIF
StrCopy(tempstr, g_destdir)
StrAdd(tempstr, g_exename)
DeleteFile(tempstr)
StrCopy(tempstr, g_destdir)
StrAdd(tempstr, g_modname)
DeleteFile(tempstr)
IF g_codebuf
IF g_codeptr > (g_codebuf + codebufsize) THEN WriteF('INTERNAL ERROR: CBUF OVERFLOW\n')
ENDIF
ENDIF
IF exception = NIL THEN printWarnings()
IF g_modulecache THEN ReleaseSemaphore(g_modulecache)
endSupport() -> 1.6.1
IF rdargs THEN FreeArgs(rdargs)
->IF g_quiet = FALSE -> v49 removed 1.7.2
SELECT exception
CASE "ARGS" ; WriteF('ERROR: Invalid arguments.\n')
CASE "OPEN" ; WriteF('ERROR: Unable to open file "\s".\n', IF exceptioninfo THEN exceptioninfo ELSE '???')
CASE "WRIT" ; WriteF('ERROR: Unable to write to file "\s".\n', IF exceptioninfo THEN exceptioninfo ELSE '???')
CASE "MEM" ; WriteF('ERROR: Out of memory.\n')
CASE "NIL" ; WriteF('INTERNAL ERROR: NIL at \d\n', exceptioninfo)
CASE "STCK" ; WriteF('INTERNAL ERROR: Ran out of stack! Please notify author.\n')
CASE "68K" ; WriteF('INTERNAL ERROR: 68K, \s, Line: \d\n', exceptioninfo, g_linenum)
CASE "PPC" ; WriteF('INTERNAL ERROR: PPC, \s, Line: \d\n', exceptioninfo, g_linenum)
CASE "IDNT" ; WriteF('ERROR: Module failed identification "\s".\n', IF exceptioninfo THEN exceptioninfo ELSE '???')
CASE "SUM" ; WriteF('ERROR: Checksum failed for module "\s".\n', IF exceptioninfo THEN exceptioninfo ELSE '???')
CASE "ERR" -> error has already been printed out..
CASE "IBUF" ; WriteF('INTERNAL ERROR: IBUF OVERFLOW\n')
CASE "MODS" ; WriteF('ERROR: Corrupt module (wrong modsize) "\s"\n', exceptioninfo)
CASE "CBUF" ; WriteF('INTERNAL ERROR: CBUF OVERFLOW buffer=\d, actual=\d\n', codebufsize, g_codeptr - g_codebuf)
->CASE "DBUF" ; WriteF('INTERNAL ERROR: DBUF OVERFLOW\n')
CASE "TRNS" ; WriteF('INTERNAL ERROR: Module translation failed for module "\s"\n', exceptioninfo)
CASE "ABUF" ; WriteF('INTERNAL ERROR: ABUF OVERFLOW\n') -> argbody
CASE "MBUF" ; WriteF('INTERNAL ERROR: MBUF OVERFLOW\n') -> macrobody
CASE "OBUF" ; WriteF('INTERNAL ERROR: OBUF OVERFLOW\n')
CASE "LIB" ; WriteF('INTERNAL ERROR: Could not open library "\s"!\n', exceptioninfo)
CASE "HTC1" ; WriteF('INTERNAL ERROR: HTC1\n')
CASE "HTC2" ; WriteF('INTERNAL ERROR: HTC2\n')
CASE "MCC" ; WriteF('ERROR: Modulecache is corrupt! (reboot or use IGNORECACHE)\n')
CASE "READ" ; WriteF('ERROR: Unable to read file "\s".\n', exceptioninfo)
CASE "EXAM" ; WriteF('ERROR: Unable to examine file "\s".\n', exceptioninfo)
CASE "NFFH" ; WriteF('ERROR: Unable to get name from fh "\s".\n', exceptioninfo)
CASE "FORM" ; WriteF('ERROR: Bad module format for module "\s".\n', exceptioninfo)
CASE "UNCO" ; WriteF('INTERNAL ERROR: UNCO.\n')
DEFAULT
IF exception > 0 THEN WriteF('INTERNAL ERROR: UNKNOWN, \s\n', [exception,0])
ENDSELECT
IF (exception = NIL)
DateStamp(ds2)
IF g_quiet = FALSE THEN WriteF(':-) \d bytes written in \s seconds.\n', size,
RealF(tempstr, Mul(ds2.minute-ds1.minute,TICKS_PER_MINUTE) +
(ds2.tick-ds1.tick) ! / (TICKS_PER_SECOND!), 2))
ENDIF
->ENDIF
IF wbtofront THEN WbenchToFront()
IF hold THEN ReadStr(stdin, tempstr)
process := FindTask(NIL)
process.result2 := g_linenum
IF errline
IF exception
IF g_linenum = 0 THEN RETURN -1
RETURN g_linenum
ELSE
RETURN NIL
ENDIF
ENDIF
ENDPROC IF exception THEN 10 ELSE NIL
-> 2.0, used by initTarget()
PROC getEnvVar(estr, name)
DEF l
l := GetVar(name, estr, StrMax(estr), NIL)
IF l > -1
SetStr(estr, l)
ELSE
reportErr('could not read environment variable', name)
ENDIF
ENDPROC
/*
-> 1.10.0
PROC readConfig()
DEF l, buf[4096]:ARRAY, temp[100]:STRING
l := GetVar('ecx.config', buf, 4096, GVF_BINARY_VAR)
IF l > -1
IF getConfigItem(buf, '\ncache-max-size-module', temp)
ENDIF
IF getConfigItem(buf, '\ncache-max-num-modules', temp)
ENDIF
IF getConfigItem(buf, '\ncache-max-size-total', temp)
ENDIF
RETURN TRUE
ELSE
RETURN FALSE
ENDIF
ENDPROC
PROC getConfigItem(buf, item, data)
DEF p, e
p := InStr(buf, item)
IF p > -1
buf := buf + p + StrLen(item)
WHILE (buf[] = " ") OR (buf[] = "\t") DO buf++
e := InStr(buf, '\n')
IF e = -1 THEN e := StrLen(buf)
StrCopy(data, buf, e)
RETURN TRUE
ENDIF
ENDPROC FALSE
*/
-> 1.10.0
PROC addModuledirs(dirs)
DEF p, s
WHILE dirs[] > 32
p := dirs + 1
REPEAT
WHILE p[] > 32 DO p++
IF (p[-1] = ":") OR (p[-1] = "/")
s := String(p-dirs)
IF s = NIL THEN Raise("MEM")
StrCopy(s, dirs,p-dirs)
Link(s, g_moduledir)
g_moduledir := s
ELSEIF p[] = NIL
RETURN
ELSE
p++
ENDIF
UNTIL p[] < 33
dirs := p
WHILE dirs[] < 33
EXIT dirs[] = NIL
dirs++
ENDWHILE
ENDWHILE
ENDPROC
-> 1.8.0
PROC addVersiondateDefine()
DEF hln:PTR TO hln
DEF str[100]:STRING, m:PTR TO macro
-> deprecated
hln := getLabelHLN('_DATE_')
NEW m
m.name := hln.name
m.identID := IDENT_MACRO
m.type := 0
m.nrofargs := 0
hln.ident := m
makeVersiondateStr(str)
m.ascii := String(EstrLen(str))
IF m.ascii = NIL THEN Raise("MEM")
StrCopy(m.ascii, str)