-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathputpcc.c
2169 lines (1921 loc) · 45 KB
/
putpcc.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
/****************************************************************
Copyright 1990-1996, 2000-2001 by AT&T, Lucent Technologies and Bellcore.
Permission to use, copy, modify, and distribute this software
and its documentation for any purpose and without fee is hereby
granted, provided that the above copyright notice appear in all
copies and that both that the copyright notice and this
permission notice and warranty disclaimer appear in supporting
documentation, and that the names of AT&T, Bell Laboratories,
Lucent or Bellcore or any of their entities not be used in
advertising or publicity pertaining to distribution of the
software without specific, written prior permission.
AT&T, Lucent and Bellcore disclaim all warranties with regard to
this software, including all implied warranties of
merchantability and fitness. In no event shall AT&T, Lucent or
Bellcore be liable for any special, indirect or consequential
damages or any damages whatsoever resulting from loss of use,
data or profits, whether in an action of contract, negligence or
other tortious action, arising out of or in connection with the
use or performance of this software.
****************************************************************/
/* INTERMEDIATE CODE GENERATION FOR S. C. JOHNSON C COMPILERS */
/* NEW VERSION USING BINARY POLISH POSTFIX INTERMEDIATE */
#include "defs.h"
#include "pccdefs.h"
#include "output.h" /* for nice_printf */
#include "names.h"
#include "p1defs.h"
static Addrp intdouble Argdcl((Addrp));
static Addrp putcx1 Argdcl((tagptr));
static tagptr putaddr Argdcl((tagptr));
static tagptr putcall Argdcl((tagptr, Addrp*));
static tagptr putcat Argdcl((tagptr, tagptr));
static Addrp putch1 Argdcl((tagptr));
static tagptr putchcmp Argdcl((tagptr));
static tagptr putcheq Argdcl((tagptr));
static void putct1 Argdcl((tagptr, Addrp, Addrp, ptr));
static tagptr putcxcmp Argdcl((tagptr));
static Addrp putcxeq Argdcl((tagptr));
static tagptr putmnmx Argdcl((tagptr));
static tagptr putop Argdcl((tagptr));
static tagptr putpower Argdcl((tagptr));
static long p1_where;
extern int init_ac[TYSUBR+1];
extern int ops2[];
extern int proc_argchanges, proc_protochanges;
extern int krparens;
#define P2BUFFMAX 128
/* Puthead -- output the header information about subroutines, functions
and entry points */
void
#ifdef KR_headers
puthead(s, Class)
char *s;
int Class;
#else
puthead(char *s, int Class)
#endif
{
if (headerdone == NO) {
if (Class == CLMAIN)
s = "MAIN__";
p1_head (Class, s);
headerdone = YES;
}
}
void
#ifdef KR_headers
putif(p, else_if_p)
register expptr p;
int else_if_p;
#else
putif(register expptr p, int else_if_p)
#endif
{
int k, n;
if( !ISLOGICAL((k = (p = fixtype(p))->headblock.vtype )) )
{
if(k != TYERROR)
err("non-logical expression in IF statement");
}
else {
if (else_if_p) {
if (ei_next >= ei_last)
{
k = ei_last - ei_first;
n = k + 100;
ei_next = mem(n,0);
ei_last = ei_first + n;
if (k)
memcpy(ei_next, ei_first, k);
ei_first = ei_next;
ei_next += k;
ei_last = ei_first + n;
}
p = putx(p);
if (*ei_next++ = ftell(pass1_file) > p1_where) {
p1_if(p);
new_endif();
}
else
p1_elif(p);
}
else {
p = putx(p);
p1_if(p);
}
}
}
void
#ifdef KR_headers
putout(p)
expptr p;
#else
putout(expptr p)
#endif
{
p1_expr (p);
/* Used to make temporaries in holdtemps available here, but they */
/* may be reused too soon (e.g. when multiple **'s are involved). */
}
void
#ifdef KR_headers
putcmgo(index, nlab, labs)
expptr index;
int nlab;
struct Labelblock **labs;
#else
putcmgo(expptr index, int nlab, struct Labelblock **labs)
#endif
{
if(! ISINT(index->headblock.vtype) )
{
execerr("computed goto index must be integer", CNULL);
return;
}
p1comp_goto (index, nlab, labs);
}
static expptr
#ifdef KR_headers
krput(p)
register expptr p;
#else
krput(register expptr p)
#endif
{
register expptr e, e1;
register unsigned op;
int t = krparens == 2 ? TYDREAL : p->exprblock.vtype;
op = p->exprblock.opcode;
e = p->exprblock.leftp;
if (e->tag == TEXPR && e->exprblock.opcode == op) {
e1 = (expptr)mktmp(t, ENULL);
putout(putassign(cpexpr(e1), e));
p->exprblock.leftp = e1;
}
else
p->exprblock.leftp = putx(e);
e = p->exprblock.rightp;
if (e->tag == TEXPR && e->exprblock.opcode == op) {
e1 = (expptr)mktmp(t, ENULL);
putout(putassign(cpexpr(e1), e));
p->exprblock.rightp = e1;
}
else
p->exprblock.rightp = putx(e);
return p;
}
expptr
#ifdef KR_headers
putx(p)
register expptr p;
#else
putx(register expptr p)
#endif
{
int opc;
int k;
if (p)
switch(p->tag)
{
case TERROR:
break;
case TCONST:
switch(p->constblock.vtype)
{
case TYLOGICAL1:
case TYLOGICAL2:
case TYLOGICAL:
#ifdef TYQUAD
case TYQUAD:
#endif
case TYLONG:
case TYSHORT:
case TYINT1:
break;
case TYADDR:
break;
case TYREAL:
case TYDREAL:
/* Don't write it out to the p2 file, since you'd need to call putconst,
which is just what we need to avoid in the translator */
break;
default:
p = putx( (expptr)putconst((Constp)p) );
break;
}
break;
case TEXPR:
switch(opc = p->exprblock.opcode)
{
case OPCALL:
case OPCCALL:
if( ISCOMPLEX(p->exprblock.vtype) )
p = putcxop(p);
else p = putcall(p, (Addrp *)NULL);
break;
case OPMIN:
case OPMAX:
p = putmnmx(p);
break;
case OPASSIGN:
if(ISCOMPLEX(p->exprblock.leftp->headblock.vtype)
|| ISCOMPLEX(p->exprblock.rightp->headblock.vtype)) {
(void) putcxeq(p);
p = ENULL;
} else if( ISCHAR(p) )
p = putcheq(p);
else
goto putopp;
break;
case OPEQ:
case OPNE:
if( ISCOMPLEX(p->exprblock.leftp->headblock.vtype) ||
ISCOMPLEX(p->exprblock.rightp->headblock.vtype) )
{
p = putcxcmp(p);
break;
}
case OPLT:
case OPLE:
case OPGT:
case OPGE:
if(ISCHAR(p->exprblock.leftp))
{
p = putchcmp(p);
break;
}
goto putopp;
case OPPOWER:
p = putpower(p);
break;
case OPSTAR:
/* m * (2**k) -> m<<k */
if(INT(p->exprblock.leftp->headblock.vtype) &&
ISICON(p->exprblock.rightp) &&
( (k = log_2(p->exprblock.rightp->constblock.Const.ci))>0) )
{
p->exprblock.opcode = OPLSHIFT;
frexpr(p->exprblock.rightp);
p->exprblock.rightp = ICON(k);
goto putopp;
}
if (krparens && ISREAL(p->exprblock.vtype))
return krput(p);
case OPMOD:
goto putopp;
case OPPLUS:
if (krparens && ISREAL(p->exprblock.vtype))
return krput(p);
case OPMINUS:
case OPSLASH:
case OPNEG:
case OPNEG1:
case OPABS:
case OPDABS:
if( ISCOMPLEX(p->exprblock.vtype) )
p = putcxop(p);
else goto putopp;
break;
case OPCONV:
if( ISCOMPLEX(p->exprblock.vtype) )
p = putcxop(p);
else if( ISCOMPLEX(p->exprblock.leftp->headblock.vtype) )
{
p = putx( mkconv(p->exprblock.vtype,
(expptr)realpart(putcx1(p->exprblock.leftp))));
}
else goto putopp;
break;
case OPNOT:
case OPOR:
case OPAND:
case OPEQV:
case OPNEQV:
case OPADDR:
case OPPLUSEQ:
case OPSTAREQ:
case OPCOMMA:
case OPQUEST:
case OPCOLON:
case OPBITOR:
case OPBITAND:
case OPBITXOR:
case OPBITNOT:
case OPLSHIFT:
case OPRSHIFT:
case OPASSIGNI:
case OPIDENTITY:
case OPCHARCAST:
case OPMIN2:
case OPMAX2:
case OPDMIN:
case OPDMAX:
case OPBITTEST:
case OPBITCLR:
case OPBITSET:
#ifdef TYQUAD
case OPQBITSET:
case OPQBITCLR:
#endif
putopp:
p = putop(p);
break;
case OPCONCAT:
/* weird things like ichar(a//a) */
p = (expptr)putch1(p);
break;
default:
badop("putx", opc);
p = errnode ();
}
break;
case TADDR:
p = putaddr(p);
break;
default:
badtag("putx", p->tag);
p = errnode ();
}
return p;
}
LOCAL expptr
#ifdef KR_headers
putop(p)
expptr p;
#else
putop(expptr p)
#endif
{
expptr lp, tp;
int pt, lt, lt1;
int comma;
char *hsave;
switch(p->exprblock.opcode) /* check for special cases and rewrite */
{
case OPCONV:
pt = p->exprblock.vtype;
lp = p->exprblock.leftp;
lt = lp->headblock.vtype;
/* Simplify nested type casts */
while(p->tag==TEXPR && p->exprblock.opcode==OPCONV &&
( (ISREAL(pt)&&ONEOF(lt,MSKREAL|MSKCOMPLEX)) ||
(INT(pt)&&(ONEOF(lt,MSKINT|MSKADDR|MSKCHAR|M(TYSUBR)))) ))
{
if(pt==TYDREAL && lt==TYREAL)
{
if(lp->tag==TEXPR
&& lp->exprblock.opcode == OPCONV) {
lt1 = lp->exprblock.leftp->headblock.vtype;
if (lt1 == TYDREAL) {
lp->exprblock.leftp =
putx(lp->exprblock.leftp);
return p;
}
if (lt1 == TYDCOMPLEX) {
lp->exprblock.leftp = putx(
(expptr)realpart(
putcx1(lp->exprblock.leftp)));
return p;
}
}
break;
}
else if (ISREAL(pt) && ISCOMPLEX(lt)) {
p->exprblock.leftp = putx(mkconv(pt,
(expptr)realpart(
putcx1(p->exprblock.leftp))));
break;
}
if(lt==TYCHAR && lp->tag==TEXPR &&
lp->exprblock.opcode==OPCALL)
{
/* May want to make a comma expression here instead. I had one, but took
it out for my convenience, not for the convenience of the end user */
putout (putcall (lp, (Addrp *) &(p ->
exprblock.leftp)));
return putop (p);
}
if (lt == TYCHAR) {
if (ISCONST(p->exprblock.leftp)
&& ISNUMERIC(p->exprblock.vtype)) {
hsave = halign;
halign = 0;
p->exprblock.leftp = putx((expptr)
putconst((Constp)
p->exprblock.leftp));
halign = hsave;
}
else
p->exprblock.leftp =
putx(p->exprblock.leftp);
return p;
}
if (pt < lt && ONEOF(lt,MSKINT|MSKREAL))
break;
frexpr(p->exprblock.vleng);
free( (charptr) p );
p = lp;
if (p->tag != TEXPR)
goto retputx;
pt = lt;
lp = p->exprblock.leftp;
lt = lp->headblock.vtype;
} /* while */
if(p->tag==TEXPR && p->exprblock.opcode==OPCONV)
break;
retputx:
return putx(p);
case OPADDR:
comma = NO;
lp = p->exprblock.leftp;
free( (charptr) p );
if(lp->tag != TADDR)
{
tp = (expptr)
mktmp(lp->headblock.vtype,lp->headblock.vleng);
p = putx( mkexpr(OPASSIGN, cpexpr(tp), lp) );
lp = tp;
comma = YES;
}
if(comma)
p = mkexpr(OPCOMMA, p, putaddr(lp));
else
p = (expptr)putaddr(lp);
return p;
case OPASSIGN:
case OPASSIGNI:
case OPLT:
case OPLE:
case OPGT:
case OPGE:
case OPEQ:
case OPNE:
;
}
if( ops2[p->exprblock.opcode] <= 0)
badop("putop", p->exprblock.opcode);
lp = p->exprblock.leftp = putx(p->exprblock.leftp);
if (p -> exprblock.rightp) {
tp = p->exprblock.rightp = putx(p->exprblock.rightp);
if (tp && ISCONST(tp) && ISCONST(lp))
p = fold(p);
}
return p;
}
LOCAL expptr
#ifdef KR_headers
putpower(p)
expptr p;
#else
putpower(expptr p)
#endif
{
expptr base;
Addrp t1, t2;
ftnint k;
int type;
char buf[80]; /* buffer for text of comment */
if(!ISICON(p->exprblock.rightp) ||
(k = p->exprblock.rightp->constblock.Const.ci)<2)
Fatal("putpower: bad call");
base = p->exprblock.leftp;
type = base->headblock.vtype;
t1 = mktmp(type, ENULL);
t2 = NULL;
free ((charptr) p);
p = putassign (cpexpr((expptr) t1), base);
sprintf (buf, "Computing %ld%s power", k,
k == 2 ? "nd" : k == 3 ? "rd" : "th");
p1_comment (buf);
for( ; (k&1)==0 && k>2 ; k>>=1 )
{
p = mkexpr (OPCOMMA, p, putsteq(t1, t1));
}
if(k == 2) {
/* Write the power computation out immediately */
putout (p);
p = putx( mkexpr(OPSTAR, cpexpr((expptr)t1), cpexpr((expptr)t1)));
} else if (k == 3) {
putout(p);
p = putx( mkexpr(OPSTAR, cpexpr((expptr)t1),
mkexpr(OPSTAR, cpexpr((expptr)t1), cpexpr((expptr)t1))));
} else {
t2 = mktmp(type, ENULL);
p = mkexpr (OPCOMMA, p, putassign(cpexpr((expptr)t2),
cpexpr((expptr)t1)));
for(k>>=1 ; k>1 ; k>>=1)
{
p = mkexpr (OPCOMMA, p, putsteq(t1, t1));
if(k & 1)
{
p = mkexpr (OPCOMMA, p, putsteq(t2, t1));
}
}
/* Write the power computation out immediately */
putout (p);
p = putx( mkexpr(OPSTAR, cpexpr((expptr)t2),
mkexpr(OPSTAR, cpexpr((expptr)t1), cpexpr((expptr)t1))));
}
frexpr((expptr)t1);
if(t2)
frexpr((expptr)t2);
return p;
}
LOCAL Addrp
#ifdef KR_headers
intdouble(p)
Addrp p;
#else
intdouble(Addrp p)
#endif
{
register Addrp t;
t = mktmp(TYDREAL, ENULL);
putout (putassign(cpexpr((expptr)t), (expptr)p));
return(t);
}
/* Complex-type variable assignment */
LOCAL Addrp
#ifdef KR_headers
putcxeq(p)
register expptr p;
#else
putcxeq(register expptr p)
#endif
{
register Addrp lp, rp;
expptr code;
if(p->tag != TEXPR)
badtag("putcxeq", p->tag);
lp = putcx1(p->exprblock.leftp);
rp = putcx1(p->exprblock.rightp);
code = putassign ( (expptr)realpart(lp), (expptr)realpart(rp));
if( ISCOMPLEX(p->exprblock.vtype) )
{
code = mkexpr (OPCOMMA, code, putassign
(imagpart(lp), imagpart(rp)));
}
putout (code);
frexpr((expptr)rp);
free ((charptr) p);
return lp;
}
/* putcxop -- used to write out embedded calls to complex functions, and
complex arguments to procedures */
expptr
#ifdef KR_headers
putcxop(p)
expptr p;
#else
putcxop(expptr p)
#endif
{
return (expptr)putaddr((expptr)putcx1(p));
}
#define PAIR(x,y) mkexpr (OPCOMMA, (x), (y))
LOCAL Addrp
#ifdef KR_headers
putcx1(p)
register expptr p;
#else
putcx1(register expptr p)
#endif
{
expptr q;
Addrp lp, rp;
register Addrp resp;
int opcode;
int ltype, rtype;
long ts, tskludge;
if(p == NULL)
return(NULL);
switch(p->tag)
{
case TCONST:
if( ISCOMPLEX(p->constblock.vtype) )
p = (expptr) putconst((Constp)p);
return( (Addrp) p );
case TADDR:
resp = &p->addrblock;
if (addressable(p))
return (Addrp) p;
ts = tskludge = 0;
if (q = resp->memoffset) {
if (resp->uname_tag == UNAM_REF) {
q = cpexpr((tagptr)resp);
q->addrblock.vtype = tyint;
q->addrblock.cmplx_sub = 1;
p->addrblock.skip_offset = 1;
resp->user.name->vsubscrused = 1;
resp->uname_tag = UNAM_NAME;
tskludge = typesize[resp->vtype]
* (resp->Field ? 2 : 1);
}
else if (resp->isarray
&& resp->vtype != TYCHAR) {
if (ONEOF(resp->vstg, M(STGCOMMON)|M(STGEQUIV))
&& resp->uname_tag == UNAM_NAME)
q = mkexpr(OPMINUS, q,
mkintcon(resp->user.name->voffset));
ts = typesize[resp->vtype]
* (resp->Field ? 2 : 1);
q = resp->memoffset = mkexpr(OPSLASH, q,
ICON(ts));
}
}
#ifdef TYQUAD
resp = mktmp(q->headblock.vtype == TYQUAD ? TYQUAD : tyint, ENULL);
#else
resp = mktmp(tyint, ENULL);
#endif
putout(putassign(cpexpr((expptr)resp), q));
p->addrblock.memoffset = tskludge
? mkexpr(OPSTAR, (expptr)resp, ICON(tskludge))
: (expptr)resp;
if (ts) {
resp = &p->addrblock;
q = mkexpr(OPSTAR, resp->memoffset, ICON(ts));
if (ONEOF(resp->vstg, M(STGCOMMON)|M(STGEQUIV))
&& resp->uname_tag == UNAM_NAME)
q = mkexpr(OPPLUS, q,
mkintcon(resp->user.name->voffset));
resp->memoffset = q;
}
return (Addrp) p;
case TEXPR:
if( ISCOMPLEX(p->exprblock.vtype) )
break;
resp = mktmp(p->exprblock.vtype, ENULL);
/*first arg of above mktmp call was TYDREAL before 19950102 */
putout (putassign( cpexpr((expptr)resp), p));
return(resp);
case TERROR:
return NULL;
default:
badtag("putcx1", p->tag);
}
opcode = p->exprblock.opcode;
if(opcode==OPCALL || opcode==OPCCALL)
{
Addrp t;
p = putcall(p, &t);
putout(p);
return t;
}
else if(opcode == OPASSIGN)
{
return putcxeq (p);
}
/* BUG (inefficient) Generates too many temporary variables */
resp = mktmp(p->exprblock.vtype, ENULL);
if(lp = putcx1(p->exprblock.leftp) )
ltype = lp->vtype;
if(rp = putcx1(p->exprblock.rightp) )
rtype = rp->vtype;
switch(opcode)
{
case OPCOMMA:
frexpr((expptr)resp);
resp = rp;
rp = NULL;
break;
case OPNEG:
case OPNEG1:
putout (PAIR (
putassign( (expptr)realpart(resp),
mkexpr(OPNEG, (expptr)realpart(lp), ENULL)),
putassign( imagpart(resp),
mkexpr(OPNEG, imagpart(lp), ENULL))));
break;
case OPPLUS:
case OPMINUS: { expptr r;
r = putassign( (expptr)realpart(resp),
mkexpr(opcode, (expptr)realpart(lp), (expptr)realpart(rp) ));
if(rtype < TYCOMPLEX)
q = putassign( imagpart(resp), imagpart(lp) );
else if(ltype < TYCOMPLEX)
{
if(opcode == OPPLUS)
q = putassign( imagpart(resp), imagpart(rp) );
else
q = putassign( imagpart(resp),
mkexpr(OPNEG, imagpart(rp), ENULL) );
}
else
q = putassign( imagpart(resp),
mkexpr(opcode, imagpart(lp), imagpart(rp) ));
r = PAIR (r, q);
putout (r);
break;
} /* case OPPLUS, OPMINUS: */
case OPSTAR:
if(ltype < TYCOMPLEX)
{
if( ISINT(ltype) )
lp = intdouble(lp);
putout (PAIR (
putassign( (expptr)realpart(resp),
mkexpr(OPSTAR, cpexpr((expptr)lp),
(expptr)realpart(rp))),
putassign( imagpart(resp),
mkexpr(OPSTAR, cpexpr((expptr)lp), imagpart(rp)))));
}
else if(rtype < TYCOMPLEX)
{
if( ISINT(rtype) )
rp = intdouble(rp);
putout (PAIR (
putassign( (expptr)realpart(resp),
mkexpr(OPSTAR, cpexpr((expptr)rp),
(expptr)realpart(lp))),
putassign( imagpart(resp),
mkexpr(OPSTAR, cpexpr((expptr)rp), imagpart(lp)))));
}
else {
putout (PAIR (
putassign( (expptr)realpart(resp), mkexpr(OPMINUS,
mkexpr(OPSTAR, (expptr)realpart(lp),
(expptr)realpart(rp)),
mkexpr(OPSTAR, imagpart(lp), imagpart(rp)))),
putassign( imagpart(resp), mkexpr(OPPLUS,
mkexpr(OPSTAR, (expptr)realpart(lp), imagpart(rp)),
mkexpr(OPSTAR, imagpart(lp),
(expptr)realpart(rp))))));
}
break;
case OPSLASH:
/* fixexpr has already replaced all divisions
* by a complex by a function call
*/
if( ISINT(rtype) )
rp = intdouble(rp);
putout (PAIR (
putassign( (expptr)realpart(resp),
mkexpr(OPSLASH, (expptr)realpart(lp), cpexpr((expptr)rp))),
putassign( imagpart(resp),
mkexpr(OPSLASH, imagpart(lp), cpexpr((expptr)rp)))));
break;
case OPCONV:
if (!lp)
break;
if(ISCOMPLEX(lp->vtype) )
q = imagpart(lp);
else if(rp != NULL)
q = (expptr) realpart(rp);
else
q = mkrealcon(TYDREAL, "0");
putout (PAIR (
putassign( (expptr)realpart(resp), (expptr)realpart(lp)),
putassign( imagpart(resp), q)));
break;
default:
badop("putcx1", opcode);
}
frexpr((expptr)lp);
frexpr((expptr)rp);
free( (charptr) p );
return(resp);
}
/* Only .EQ. and .NE. may be performed on COMPLEX data, other relations
are not defined */
LOCAL expptr
#ifdef KR_headers
putcxcmp(p)
register expptr p;
#else
putcxcmp(register expptr p)
#endif
{
int opcode;
register Addrp lp, rp;
expptr q;
if(p->tag != TEXPR)
badtag("putcxcmp", p->tag);
opcode = p->exprblock.opcode;
lp = putcx1(p->exprblock.leftp);
rp = putcx1(p->exprblock.rightp);
q = mkexpr( opcode==OPEQ ? OPAND : OPOR ,
mkexpr(opcode, (expptr)realpart(lp), (expptr)realpart(rp)),
mkexpr(opcode, imagpart(lp), imagpart(rp)) );
free( (charptr) lp);
free( (charptr) rp);
free( (charptr) p );
if (ISCONST(q))
return q;
return putx( fixexpr((Exprp)q) );
}
/* putch1 -- Forces constants into the literal pool, among other things */
LOCAL Addrp
#ifdef KR_headers
putch1(p)
register expptr p;
#else
putch1(register expptr p)
#endif
{
Addrp t;
expptr e;
switch(p->tag)
{
case TCONST:
return( putconst((Constp)p) );
case TADDR:
return( (Addrp) p );
case TEXPR:
switch(p->exprblock.opcode)
{
expptr q;
case OPCALL:
case OPCCALL:
p = putcall(p, &t);
putout (p);
break;
case OPCONCAT:
t = mktmp(TYCHAR, ICON(lencat(p)));
q = (expptr) cpexpr(p->headblock.vleng);
p = putcat( cpexpr((expptr)t), p );
/* put the correct length on the block */
frexpr(t->vleng);
t->vleng = q;
putout (p);
break;
case OPCONV:
if(!ISICON(p->exprblock.vleng)
|| p->exprblock.vleng->constblock.Const.ci!=1
|| ! INT(p->exprblock.leftp->headblock.vtype) )
Fatal("putch1: bad character conversion");
t = mktmp(TYCHAR, ICON(1));
e = mkexpr(OPCONV, (expptr)t, ENULL);
e->headblock.vtype = TYCHAR;
p = putop( mkexpr(OPASSIGN, cpexpr(e), p));
putout (p);
break;
default:
badop("putch1", p->exprblock.opcode);
}
return(t);
default:
badtag("putch1", p->tag);
}
/* NOT REACHED */ return 0;
}
/* putchop -- Write out a character actual parameter; that is, this is
part of a procedure invocation */
Addrp
#ifdef KR_headers
putchop(p)
expptr p;
#else
putchop(expptr p)
#endif
{
p = putaddr((expptr)putch1(p));
return (Addrp)p;
}
LOCAL expptr
#ifdef KR_headers
putcheq(p)
register expptr p;