-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path020gen.e
4255 lines (3768 loc) · 118 KB
/
020gen.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
-> EEC/020gen.e
/* formerly ECX/m68gen.e */
/* EEC by Samuel D. Crow [samuraileumas yahoo com] is Copyright (c) 2019 */
/* ECX by Leif Salomonsson [ecx tele2 se] is Copyright (c) 2002-2008 */
/* Released under the ECX COMPILER LICENSE, See ECXCOMPILERLICENSE.TXT */
-> File created May 2008, extracted from codegen.e.
OPT MODULE
OPT PREPROCESS
OPT LARGE
->#define DBG_M68GEN
MODULE '*codegen'
MODULE '*compiler'
MODULE '*assembler'
MODULE '*opcodes68'
MODULE '*opcodesppc'
MODULE '*common'
MODULE '*inline68'
MODULE '*support'
MODULE '*runtime'
MODULE '*binary'
MODULE 'exec/lists'
#define DOSICBICOPTI
EXPORT OBJECT m68amiga OF codegen
lasttempDREG
lasttempAREG
lasttempFREG
ENDOBJECT
EXPORT DEF g_codeptr:PTR TO LONG,
g_codebuf,
g_currentproc:PTR TO proc,
g_rwreflist:PTR TO rwref,
g_globalsize,
g_databufsize,
g_databuf:PTR TO LONG,
g_numregalloc,
g_numfregalloc,
g_gvarlist:PTR TO gvar,
g_regusetab:PTR TO oreg
EXPORT DEF g_od:PTR TO LONG -> shared with inline.e
EXPORT DEF g_lastx:PTR TO lastx
DEF g_exceptlab:PTR TO codelab
DEF g_endexceptlab:PTR TO codelab
DEF g_procendlab:PTR TO codelab
DEF g_d64bottom -> offset of bottom of d64 stack
DEF g_lastd64 -> actuall frameoffset and always negative
EXPORT DEF g_librarymode, g_optmodule, g_optroundnear
EXPORT DEF
g_dreg, -> RX/DRX
g_areg, -> RX/ARX
g_freg, -> FPX
g_vreg, -> VX
g_d64reg, -> D64 v55
g_ireg0, -> R3/D0 (non obtainable)
g_ireg1, -> R4/D1
g_freg0, -> FP1, F1
g_stackreg, -> R1/A7 (non obtainable, dedicated)
g_selfreg, -> R12/A0
g_globreg, -> R13/A4 (non obtainable, dedicated)
g_framereg, -> R1/A5 (non obtainable, dedicated)
g_atemp, -> R11/A6 (non obtainable)
g_dtemp, -> R12/D3 (non obtain)
g_ftemp, -> FP0/F0 (non obtain)
g_d64temp -> v55
EXPORT DEF g_multireturn:PTR TO multireturn
EXPORT DEF g_modulelist:PTR TO mlh, link_globaldatasize -> for .putInit()
PROC init() OF m68amiga
#ifdef DBG_M68GEN
DEBUGF('m8amiga.init()\n')
#endif
DREG := DRX
AREG := ARX
FREG := FPX
D64REG := D64 -> 2.3
IREG0 := 0 -> D0
IREG1 := 1 -> D1
FREG0 := 1
STACKREG := 7 -> A7
SELFREG := 0 -> A0 self arg
GLOBREG := 4 -> A4
FRAMEREG := 5 -> A5
ATEMP := 6 -> A6. non obtainable ptr scratch
DTEMP := 3 -> d3 v50
FTEMP := 0 -> f0 v50
D64TEMP := 0 -> is set by self.doprochead()
self.lasttempDREG := 1
self.lasttempAREG := 1
self.lasttempFREG := 1
ENDPROC
PROC putInit(globalsize, ivarsize) OF m68amiga
#ifdef DBG_M68GEN
DEBUGF('put68KInit()\n')
#endif
moveaxpofsax(SIZE_L,7,4,0) -> move.l 4(a7), a0 -> rwmemory
putRWInit()
leaaxpofsax(0,ivarsize,0) -> lea IVARSSIZE(a0), a0
moveaxax(SIZE_L,0,GLOBREG) -> a4 is set up !
-> set up a0 to globaldata
addlimmax(globalsize, 0) -> add.l #g_globalsize, a0
self.putGlobInit()
putModulesInit()
moveaxdx(SIZE_L,0,0) -> 1.10.0, return end of globdata so we may place stak after also in libmode
rts_() -> returns endofglobdata in d0
ENDPROC
PROC putRWInit()
DEF mod:PTR TO moduleheader
DEF info:PTR TO modinfo
DEF t
DEF lptr:PTR TO LONG
DEF a
mod := g_modulelist.head
WHILE mod.succ
info := mod.datainfo
IF info
info := info + mod
lptr := info + SIZEOF modinfo
a := info.count+1
WHILE a--
t := lptr[]++
IF t THEN movelimmaxpi(t, 0) ELSE addqax(SIZE_L,4,0)
ENDWHILE
ENDIF
mod := mod.succ
ENDWHILE
lptr := g_databuf
a := Shr(g_databufsize, 2) + 1
WHILE a--
t := lptr[]++
IF t THEN movelimmaxpi(t, 0) ELSE addqax(SIZE_L,4,0)
ENDWHILE
ENDPROC
-> 2.2 now called directly from main in module mode
PROC putGlobInit() OF m68amiga
DEF gvar:PTR TO gvar
-> initialise globals (v44)
gvar := g_gvarlist
WHILE gvar
link_globaldatasize := link_globaldatasize + initGvar(gvar)
gvar := gvar.next
ENDWHILE
IF g_optmodule THEN rts_() -> 2.2
ENDPROC
PROC putModulesInit()
DEF mod:PTR TO moduleheader, info:PTR TO modinfo, t
mod := g_modulelist.head
WHILE mod.succ
info := IF mod.headsize < 160 THEN NIL ELSE mod.globinitinfo
IF info
IF mod.cpu <> CPU_M68 THEN reportErr('init code cpu mismatch for module', mod.mname)
info := info + mod
t := info.misc - (currentOffset() + 2)
bsrofs32(t)
ENDIF
mod := mod.succ
ENDWHILE
ENDPROC
#define AxToGlobal(x) IF gvar.link THEN movelaxaxplab(x, GLOBREG, gvar) ELSE \
moveaxaxpofs(SIZE_L,x,GLOBREG,gvar.offset)
#define FpxToGlobal(x) IF gvar.link THEN fmovefpxaxplab(FD,x,GLOBREG,gvar.offset) ELSE \
fmovefpxaxpofs(FD,x,GLOBREG,gvar.offset)
PROC initGvar(gvar:PTR TO gvar)
DEF t, globaldatasize=0
IF gvar.type.numes
SELECT 256 OF gvar.type.esize
CASE 1
IF gvar.cmplx -> STRING
globaldatasize := 8 + (t := gvar.type.numes + 1 + 3 AND $FFFC)
addqax(SIZE_L,4,0) -> next=NIL
movelimmaxpi(Shl(gvar.type.numes,16),0) -> max,curr
clraxp(SIZE_L,0)
AxToGlobal(0)
addlimmax(t,0)
ELSE -> ARRAY OF CHAR
globaldatasize := (t := gvar.type.numes + 3 AND $FFFC)
AxToGlobal(0)
addlimmax(t,0)
ENDIF
CASE 2 -> ARRAY OF INT
globaldatasize := (t := gvar.type.numes * 2 + 3 AND $FFFFFC)
AxToGlobal(0)
addlimmax(t,0)
CASE 4
IF gvar.cmplx -> LIST
globaldatasize := 8 + (t := gvar.type.numes * 4)
addqax(SIZE_L,4,0) -> next=NIL
movelimmaxpi(Shl(gvar.type.numes,16),0) -> max,curr
AxToGlobal(0)
addlimmax(t,0)
ELSE -> ARRAY OF LONG
globaldatasize := (t := gvar.type.numes * 4)
AxToGlobal(0)
addlimmax(t,0)
ENDIF
CASE 8
globaldatasize := (t := gvar.type.numes * 8)
AxToGlobal(0)
addlimmax(t,0)
CASE 255 -> (ARRAY OF) OBJECT
IF gvar.type.object.nrofmethods
addWarning('methods will not be installed for global')
ENDIF
globaldatasize := (t := gvar.type.numes *
gvar.type.object.sizeof + 3 AND $FFFFFC)
AxToGlobal(0)
addlimmax(t,0)
ENDSELECT
ELSEIF gvar.defo
IF gvar.type.size = 4
movelimmax(gvar.defd, 1)
AxToGlobal(1)
ELSE
IF gvar.type.flags AND MEMBF_FLOAT
fmovesimmfpx(gvar.defd, 0)
FpxToGlobal(0)
ELSE -> 2.2
movelimmaxpd(gvar.defd, 7)
movelimmaxpd(Shr(gvar.defd,31), 7)
fmoveaxpifpx(FD, 7, 0)
FpxToGlobal(0)
ENDIF
ENDIF
ENDIF
ENDPROC globaldatasize
PROC abiArgs(array:PTR TO LONG, numargs, flags) OF m68amiga
DEF va:PTR TO arg, a, fnum=1
-> 1.8.0 flags does nada in 68k mode for now
FOR a := 0 TO numargs-1
va := array[a]
IF va.type.size = 4
va.rtype := M68ARGTYPE_STACK -> stack
va.rnum := NIL -> not used
ELSEIF va.type.size = 8
IF va.type.flags AND MEMBF_FLOAT
IF fnum < 8
va.rtype := M68ARGTYPE_FREG -> float reg
va.rnum := fnum++
ELSE
reportErr('too many REAL arguments for procedure (bug author)')
ENDIF
ELSE
-> 2.2.4, wide!
va.rtype := M68ARGTYPE_STACK_WIDE
va.rnum := NIL
ENDIF
ENDIF
ENDFOR
ENDPROC
PROC abiReturns(mret:PTR TO multireturn) OF m68amiga
DEF reg=0, freg=1, t
t := mret.ros[0]
SELECT t
CASE DREG ; mret.rds[0] := reg++
CASE FREG ; mret.rds[0] := freg++
CASE X2R ; mret.rds[0] := freg++
DEFAULT ; reportIErr('m68amiga.abiReturns 0 t=?')
ENDSELECT
t := mret.ros[1]
SELECT t
CASE DREG ; mret.rds[1] := reg++
CASE FREG ; mret.rds[1] := freg++
CASE X2R ; mret.rds[1] := freg++
DEFAULT ; reportIErr('m68amiga.abiReturns 1 t=?')
ENDSELECT
t := mret.ros[2]
SELECT t
CASE DREG ; mret.rds[2] := reg++
CASE FREG ; mret.rds[2] := freg++
CASE X2R ; mret.rds[2] := freg++
DEFAULT ; reportIErr('m68amiga.abiReturns 2 t=?')
ENDSELECT
t := mret.ros[3]
SELECT t
CASE DREG ; mret.rds[3] := reg++
CASE FREG ; mret.rds[3] := freg++
CASE X2R ; mret.rds[3] := freg++
DEFAULT ; reportIErr('m68amiga.abiReturns 3 t=?')
ENDSELECT
ENDPROC
-> v50: support for doubleargs
-> 2.3 added wide support
PROC doProcfunc(buf:PTR TO item, meth=NIL:PTR TO proc) OF m68amiga
DEF n:PTR TO item, hln:PTR TO hln, proc:PTR TO proc
DEF regusecopy[REGUSETABSIZE]:ARRAY OF oreg -> v44, 49
DEF a, as, as2, param:PTR TO var
DEF stub:PTR TO codelab, endstub:PTR TO codelab, trap:PTR TO codelab
DEF nrofparams, t:PTR TO LONG
DEF o,d, var:PTR TO var, float
DEF argtype
DEF it_funccall:PTR TO it_funccall
DEF ro, rd
DEF rems=0:PTR TO LONG, noraise
it_funccall := buf.info
hln := it_funccall.data ->n.info
nrofparams := it_funccall.numpars ->buf.num
n := it_funccall + SIZEOF it_funccall ->n++ -> skip label
#ifdef DBG_M68GEN
DEBUGF('.doProcfunc() \s numargs=\d\n', hln.name, nrofparams)
#endif
IF meth = NIL
self.saveObtained(regusecopy)
proc := hln.ident
IF proc = NIL THEN reportErr('unknown function', hln.name)
proc.referenced := 1
ELSE
proc := meth
ENDIF
ro := proc.mret.ros[0]
rd := proc.mret.rds[0]
IF nrofparams > proc.nrofargs THEN reportErr('too many parameters for procedure', proc.name)
IF (nrofparams+proc.nrofdefaults) < proc.nrofargs THEN reportErr('too few parameters for procedure', proc.name)
FOR a := 0 TO proc.nrofargs-1
param := proc.argarray[a]
IF n.data
n, as, as2 := self.doExpression(n)
IF param.rtype = M68ARGTYPE_FREG -> doublearg ? v50
inst_copy(as,as2, FPX,param.rnum)
self.copyObtainToFREG(FPX,param.rnum) -> put an obtain on register
ELSEIF param.rtype = M68ARGTYPE_STACK_WIDE -> 2.3
self.tox2r(as, as2, FTEMP)
inst_push(8, FREG, FTEMP)
rems++ ; rems++
ELSE
inst_push(4, as,as2)
rems++
ENDIF
ELSE
IF param.rtype = M68ARGTYPE_FREG -> doublearg ? v50
inst_copy(DV, param.defd, FPX, param.rnum)
self.copyObtainToFREG(FPX,param.rnum) -> put an obtain on register
ELSEIF param.rtype = M68ARGTYPE_STACK_WIDE -> 2.3
self.tox2r(DV, param.defd, FTEMP)
inst_push(8, FREG, FTEMP)
rems++ ; rems++
ELSE
inst_push(4, DV, param.defd)
rems++
ENDIF
ENDIF
ENDFOR
IF meth = NIL
IF proc.cpu = 1 -> 68k calling ppc
t := [DRX,0,0,DRX,1,4,DRX,2,8,DRX,3,12,ARX,0,32,ARX,1,36,ARX,2,40,ARX,3,44]
FOR a := (proc.nrofargs-1) TO 0 STEP -1 -> into 68k trash regs
IF t[a*3] = DRX THEN moveaxpidx(SIZE_L,7, t[a*3+1]) ELSE moveaxpiax(SIZE_L,7, t[a*3+1])
ENDFOR
trap := newLabel()
stub := newLabel()
endstub := newLabel()
bsrlab(trap)
bcclab(T,endstub) -> v49
putLabel(trap)
Put32($FF000000)
putReloc(stub)
putAlign(4) -> v49
putLabel(stub)
ppcstwu(1,1,-16) -> v49
ppcmfspr(0,8) -> v49
ppcstw(0,1,16+FRAMEPPC_LINKREG) -> v49
ppcstw(13,1,8) -> v49
ppclwz(13,2,48) -> v49
FOR a := 0 TO proc.nrofargs-1 -> from emulhand into ppcregs
ppclwz(a+3,2,t[a*3+2]) -> v49 fix
ENDFOR
ppcblab(proc,0,1) -> call ppc proc
ppclwz(13,1,8) -> v49
ppclwz(0,1,16+FRAMEPPC_LINKREG) -> v49
ppcmtspr(0,8) -> v49
ppcaddi(1,1,16) -> v49
ppcbclr(20,0,0) -> v49
putLabel(endstub) -> v49
ELSE
-> v50, release any doubleargregisters
FOR a := 0 TO nrofparams-1
param := proc.argarray[a]
IF param.rtype = 1 THEN self.releaseFREG(param.rnum,0)
ENDFOR
-> call function
inst_goslab(proc)
inst_incarx(STACKREG, rems)
ENDIF
ro, rd := self.secureReturn(ro, rd, regusecopy) -> v50
self.loadObtained(regusecopy)
clearRegs()
ENDIF
#ifdef DBG_M68GEN
DEBUGF('dofunction() \s DONE\n', hln.name)
#endif
IF proc.raise -> 2.2
noraise := newLabel()
inst_bic(DV,proc.raise.trigval,proc.raise.condition, ro,rd,noraise)
inst_push(4,DV,proc.raise.excval)
bsrlab(self.raise_lif)
def_label(noraise)
ENDIF
n := buf[1]
g_multireturn := proc.mret -> v49
ENDPROC n, ro, rd
-> 1.10.0 added support for new style varfunc
-> 2.3 added wide support
PROC doVarfunc(n:PTR TO item) OF m68amiga
DEF v:PTR TO var, r, count=0
DEF regusecopy[REGUSETABSIZE]:ARRAY OF oreg
DEF var:PTR TO var, o, d, arx
DEF it_funccall:PTR TO it_funccall
DEF ro, rd, a, param:PTR TO arg
r := n[1]
it_funccall := n.info
v := it_funccall.data
n := it_funccall + SIZEOF it_funccall
#ifdef DBG_M68GEN
DEBUGF('dovfunction() \s \n', v.hln.name)
#endif
self.saveObtained(regusecopy)
IF v.argsarray = FALSE
ro := DREG
rd := IREG0
WHILE n.data
count++
n, o, d := self.doExpression(n)
inst_push(4,o,d)
ENDWHILE
ELSE -> 1.10.0
FOR a := 0 TO ListLen(v.argsarray)-1
param := v.argsarray[a]
n, o, d := self.doExpression(n)
IF param.rtype = M68ARGTYPE_FREG -> doublearg ?
inst_copy(o,d, FPX,param.rnum)
self.copyObtainToFREG(FPX,param.rnum) -> put an obtain on register
ELSEIF param.rtype = M68ARGTYPE_STACK_WIDE -> 2.3
inst_push(8, o,d)
count++ ; count++
ELSE
inst_push(4, o,d)
count++
ENDIF
ENDFOR
ro := IF v.multiret THEN v.multiret.ros[0] ELSE DREG
rd := IF v.multiret THEN v.multiret.rds[0] ELSE IREG0
ENDIF
arx := self.copyObtainToAREG(v.o,v.d) -> v49
jsraxp(arx)
self.releaseAREG(arx,0) -> v49
inst_incarx(STACKREG, count*4)
ro, rd := self.secureReturn(ro, rd, regusecopy)
self.loadObtained(regusecopy)
clearRegs()
g_multireturn := IF v.multiret THEN v.multiret ELSE [ro,DREG,DREG,DREG,rd,1,2,3]:LONG
#ifdef DBG_M68GEN
DEBUGF('dovfunction() \s DONE\n', v.hln.name)
#endif
ENDPROC r, ro, rd
-> v50: added support for doubleargs
PROC doIntfunc(n:PTR TO item) OF m68amiga
DEF buf:PTR TO item, r:PTR TO raise, o, d, a, t
DEF numparams, defs:PTR TO LONG
DEF ifunc:PTR TO lif, regusecopy[REGUSETABSIZE]:ARRAY OF oreg
DEF hln:PTR TO hln, varargsofs:PTR TO LONG, var:PTR TO var
DEF noraise:PTR TO genlab, numvarargs
DEF o2,d2
DEF ifNumArgs
DEF it_funccall:PTR TO it_funccall
DEF ro, rd , fpx=1
DEF ha:hintargs
ha.hregisvar := FALSE
buf := n
it_funccall := n.info
numparams := it_funccall.numpars
ifunc := it_funccall.data
n := it_funccall + SIZEOF it_funccall
ifNumArgs := ListLen(ifunc.params)
#ifdef DBG_M68GEN
DEBUGF('doifunction() \s \n', ifunc.name)
#endif
self.saveObtained(regusecopy)
defs := ifunc.defaults
SELECT 5 OF ifunc.returns
CASE 0
ro := DRX
rd := IREG0
CASE 1
ro := FPX
rd := FREG0
CASE 2
ro := X2R
rd := 1
DEFAULT
reportIErr('m68.doIntFunc ifunc.returns ?')
ENDSELECT
FOR a := 0 TO ifNumArgs-1
IF n.data
t := ListItem(ifunc.params,a)
IF t = 1 -> doublearg ?
ha.hregop := FREG
ha.hregnum := fpx
n, o, d := self.doExpression(n, ha)
inst_copy(o,d, FPX,fpx)
self.copyObtainToFREG(FPX,fpx)
fpx++
ELSEIF t = 2 -> wide
n, o, d := self.doExpression(n)
self.tox2r(o, d, FTEMP)
inst_push(8, FREG, FTEMP)
ELSE
n, o, d := self.doExpression(n)
inst_push(4,o,d)
ENDIF
ELSE /* default value used */
t := ListItem(ifunc.params,a)
IF t = 1 -> doublearg ?
inst_copy(DV,defs[]++, FPX,fpx)
self.copyObtainToFREG(FPX,fpx)
fpx++
ELSEIF t = 2 -> wide
self.tox2r(DV, defs[]++, FTEMP)
inst_push(8, FREG, FTEMP)
ELSE
inst_push(4,DV,defs[]++)
ENDIF
ENDIF
ENDFOR
-> fixing to support 64bit varargs
IF ifunc.flags = 2 -> varargs ?
numvarargs := numparams - ifNumArgs
inst_decarx(7, numvarargs * 8) -> alloc enough for wide arguments!
-> push varargs
varargsofs := 0
WHILE n.data
n, o, d := self.doExpression(n)
SELECT 20 OF o
CASE VAR64, X2R, FPX, D64
inst_copy(o,d, ARXPO,AxSizeOfs(7,8,varargsofs++))
varargsofs++
DEFAULT
inst_copy(o,d, ARXPO,AxSizeOfs(7,4,varargsofs++))
ENDSELECT
ENDWHILE
inst_push(4, DV,numvarargs*8)
inst_goslab(ifunc)
inst_incarx(7, ifNumArgs+1*4+(numvarargs*8))
ELSE
WHILE fpx > 1
fpx--
self.releaseFREG(fpx,0)
ENDWHILE
inst_goslab(ifunc)
inst_incarx(7, ifNumArgs*4)
ENDIF
ro, rd := self.secureReturn(ro, rd, regusecopy) -> v50
self.loadObtained(regusecopy)
clearRegs()
IF ifunc.raise
noraise := newLabel()
inst_bic(DV,ifunc.raise.trigval,ifunc.raise.condition, ro,rd,noraise)
inst_push(4,DV,ifunc.raise.excval)
bsrlab(self.raise_lif)->g_internalfuncs[IF68K_RAISE]) -> Raise
def_label(noraise)
ENDIF
g_multireturn := [ro,DREG,DREG,DREG,rd,1,2,3]:LONG
#ifdef DBG_M68GEN
DEBUGF('doiunction() \s DONE\n', ifunc.name)
#endif
ENDPROC buf[1], ro, rd
PROC doLibfunc(n:PTR TO item) OF m68amiga
DEF buf:PTR TO item, a, o, d, libbase:PTR TO var, r:PTR TO raise
DEF regusecopy[REGUSETABSIZE]:ARRAY OF oreg, lfunc:PTR TO lfunc, hln:PTR TO hln
DEF numparams, t, var:PTR TO var
DEF o2, d2, t2, noraise:PTR TO genlab
DEF it_funccall:PTR TO it_funccall
DEF ro, rd
buf := n
it_funccall := n.info
numparams := it_funccall.numpars
lfunc := it_funccall.data
libbase := it_funccall.info
n := it_funccall + SIZEOF it_funccall
IF numparams <> lfunc.nrofargs THEN reportErr('wrong nr of parameters for function', lfunc.name)
#ifdef DBG_M68GEN
DEBUGF('dolfunction() \s \n', lfunc.name)
#endif
IF lfunc.type = 1 THEN reportErr('cannot call sysv from 68k (duh)')
ro := DREG
rd := IREG0
self.saveObtained(regusecopy)
/* save regs ? */
FOR a := numparams-1 TO 0 STEP -1 -> reverse order !
t := lfunc.regs[a].rnum
IF lfunc.regs[a].rtype
SELECT 8 OF t
CASE 4, 5 ; moveaxaxpd(SIZE_L,t,7) -> a4,a5
ENDSELECT
ELSE
SELECT 16 OF t
CASE 4,5,6,7 ; movedxaxpd(SIZE_L,t,7) -> d4-d7
ENDSELECT
ENDIF
ENDFOR
/* put on stack */
FOR a := 0 TO numparams-1
n, o, d := self.doExpression(n)
inst_push(4,o,d)
ENDFOR
/* set librarybase */
inst_copy(libbase.o,libbase.d, ARX,6)
/* set up parameters (by copying to regs) */
FOR a := numparams-1 TO 0 STEP -1
t2 := lfunc.regs[a]
o2 := IF lfunc.regs[a].rtype THEN ARX ELSE DRX
d2 := lfunc.regs[a].rnum
inst_pop(4,o2,d2)
ENDFOR
jsraxpofs(6,lfunc.baseofs)
/* restore regs ? */
FOR a := 0 TO numparams-1 -> non-reversed..
t := lfunc.regs[a].rnum
IF lfunc.regs[a].rtype
SELECT 16 OF t
CASE 4,5 ; moveaxpiax(SIZE_L,7,t) -> a4,a5
ENDSELECT
ELSE
SELECT 16 OF t
CASE 4,5,6,7 ; moveaxpidx(SIZE_L,7,t) -> d4-d7
ENDSELECT
ENDIF
ENDFOR
ro, rd := self.secureReturn(ro, rd, regusecopy)
self.loadObtained(regusecopy)
clearRegs()
IF lfunc.raise
noraise := newLabel()
inst_bic(DV,lfunc.raise.trigval,lfunc.raise.condition, ro,rd,noraise)
inst_push(4,DV,lfunc.raise.excval)
bsrlab(self.raise_lif)->g_internalfuncs[IF68K_RAISE]) -> Raise
def_label(noraise)
ENDIF
g_multireturn := [DREG,DREG,NIL,NIL,0,1,0,0]:LONG
#ifdef DBG_M68GEN
DEBUGF('dolfunction() \s DONE\n', lfunc.name)
#endif
ENDPROC buf[1], ro, rd
-> 2.3 added wide support
PROC doReturn(buf, ret) OF m68amiga
DEF n:PTR TO item
DEF o,d, x, t
DEF a=0, t1:PTR TO CHAR, t2:PTR TO CHAR
DEF m:PTR TO multireturn
DEF numrets
DEF ha:hintargs
ha.hregisvar := FALSE
m := g_currentproc.mret
#ifdef DBG_M68GEN
DEBUGF('doreturn($\h,\d)\n', buf, ret)
#endif
n := buf
numrets := n.num
IF numrets > 3 THEN reportErr('too many returnvalues')
n++
self.endLocalClasses(g_currentproc)
FOR a := 0 TO numrets-1
ha.hregop := m.ros[a]
ha.hregnum := m.rds[a]
n, o, d := self.doExpression(n, ha)
IF m.ros[a] = X2R
self.tox2r(o,d,m.rds[a])
ELSE
inst_copy(o,d, m.ros[a],m.rds[a])
ENDIF
IF m.ros[a] = DREG
self.copyObtainToDREG(DREG,m.rds[a]) -> obtain register
ELSEIF (m.ros[a] = FREG) OR (m.ros[a] = X2R)
self.copyObtainToFREG(FREG,m.rds[a]) -> obtain register
ENDIF
ENDFOR
FOR a := 0 TO numrets-1
IF m.ros[a] = DREG
self.releaseDREG(m.rds[a],0)
ELSEIF (m.ros[a] = FREG) OR (m.ros[a] = X2R)
self.releaseFREG(m.rds[a],0)
ENDIF
ENDFOR
IF numrets = 0 THEN inst_copy(DV,NIL, DREG,IREG0)
IF ret THEN inst_ret(0)
#ifdef DBG_M68GEN
DEBUGF('doreturn DONE()\n')
#endif
ENDPROC n, NIL, NIL
-> v50 (1.5.1)
-> v55: arg: neg=>unary
-> v58, changes
PROC mathlogichead(n:PTR TO item, mode, unary, ha_:PTR TO hintargs) OF m68amiga
DEF yreg, regusecopy[REGUSETABSIZE]:ARRAY OF oreg, ro, rd
DEF o,d, ha:hintargs
-> 2.3
SELECT mode
CASE MODE_DEFAULT
self.saveObtained(regusecopy) -> 1.8.0
yreg := self.obtainDREG()
ha.hregop := DREG
ha.hregnum := yreg
ha.hregisvar := FALSE
CASE MODE_FLOAT
yreg := self.obtainFREG()
ha.hregop := FREG
ha.hregnum := yreg
ha.hregisvar := FALSE
CASE MODE_D64
yreg := self.obtainD64()
ha.hregop := D64REG
ha.hregnum := yreg
ha.hregisvar := FALSE
DEFAULT
reportIErr('mathlogichead mode')
ENDSELECT
n, o, d := self.doSingleExp(n, ha)
IF mode = MODE_FLOAT
->yreg := self.obtainFREG() -> we need a write mode obtain
inst_copy(o,d, FREG,yreg)
IF unary = "_"
inst_fnegreg(yreg)
ELSEIF unary = KW_ABS -> 2.2
inst_fabsreg(yreg)
ENDIF
n, ro, rd := self.domathlogictail(n, MODE_FLOAT, yreg)
ELSEIF mode = MODE_DEFAULT
->yreg := self.obtainDREG() -> we need a write mode obtain
inst_copy(o,d, DREG,yreg)
IF unary = "-"
inst_negreg(yreg)
ELSEIF unary = "~"
inst_notreg(yreg)
ELSEIF unary = KW_ABS -> 2.2
inst_absreg(yreg)
ENDIF
n, ro, rd := self.domathlogictail(n, MODE_DEFAULT, yreg)
ELSEIF mode = MODE_D64 -> 1.10.0
->yreg := self.obtainD64() -> we need a write mode obtain
inst_copy(o,d, D64REG,yreg)
IF unary = "-"
inst_negd64(yreg)
ELSEIF unary = "~"
inst_notd64(yreg)
ELSEIF unary = KW_ABS -> 2.2
inst_absd64(yreg)
ENDIF
n, ro, rd := self.domathlogictail(n, MODE_D64, yreg)
ENDIF
IF mode = MODE_DEFAULT
-> 1.8.0
ro, rd := self.secureReturn(ro, rd, regusecopy)
self.loadObtained(regusecopy)
clearRegs()
ENDIF
ENDPROC n, ro, rd
-> 1.8.1
PROC m68RegisterizeD(o,d:PTR TO var) OF m68amiga
IF o = DREG
RETURN d
ELSEIF o = VAR
IF d.intreg AND d.trok AND (d.treg<8) THEN RETURN d.treg
ENDIF
inst_copy(o,d, DREG,DTEMP)
ENDPROC DTEMP
-> 1.8.1
PROC m68RegisterizeA(o,d:PTR TO var) OF m68amiga
IF o = AREG
RETURN d
ELSEIF o = VAR
IF d.intreg AND d.trok AND (d.treg>7) THEN RETURN d.treg-8
ENDIF
inst_copy(o,d, AREG,ATEMP)
ENDPROC ATEMP
-> 1.8.1
PROC m68RegisterizeF(o,d:PTR TO var) OF m68amiga
IF o = FREG
RETURN d
ELSEIF o = VAR64
IF d.intreg AND d.trok THEN RETURN d.treg
ENDIF
inst_copy(o,d, FREG,FTEMP)
ENDPROC FTEMP
/*
0 Dx
1 Ax
2 (Ax)
3 (Ax)+
4 -(Ax)
5 ofs(Ax) arg local .memb(Ax:obj) LibFunc(Ax)
6 lab(Ax) global
7 (Ax,Dx.L*Scale) (Ax,Dx.L) (Ax,Dx)
8 #imm #constexp
9 lab(PC) lab proc
*/
->-- 68k single operand parser ---
PROC getop68(n:PTR TO item, values:PTR TO LONG)
DEF t, ax, dx, scale=1, ri, as,as2, ofs, node:PTR TO var
DEF id, memb:PTR TO member, hln:PTR TO hln, proc:PTR TO proc
DEF var:PTR TO var, reg:PTR TO reg, lab:PTR TO codelab
t := n.data
SELECT 256 OF t
CASE "-" -> -(Ax)
n++
n++
reg := n.info
RETURN n[2], 4, ListAdd(values, [reg.num])
CASE IT_VALUE -> ofs(Ax), ofs(Ax,Dx), ofs(Ax,Dx*scale)
ofs := n.info
n++
n++ -> skip "("
reg := n.info
ax := reg.num
n++
IF n.data <> IT_REG
RETURN n[1], 5, ListAdd(values, [ax, ofs])
ELSE
-> indexed
reg := n.info
dx := reg.num
IF n.num
IF n.num <> "L" THEN reportErr('wrong size of value')
ENDIF
n++
IF n.data = IT_VALUE
scale := n.info
n++
ELSE
scale := 1
ENDIF
n++ -> skip ")"
RETURN n, 7, ListAdd(values, [ax, dx, scale, ofs])
ENDIF
CASE "("