xref: /csrg-svn/usr.bin/pascal/src/sconv.c (revision 18469)
110358Smckusick /* Copyright (c) 1983 Regents of the University of California */
210358Smckusick 
314742Sthien #ifndef lint
4*18469Sralph static	char sccsid[] = "@(#)sconv.c 2.2 03/20/85";
514742Sthien #endif
610358Smckusick 
710358Smckusick     /*
810358Smckusick      *	functions to help pi put out
910358Smckusick      *	polish postfix binary portable c compiler intermediate code
1010358Smckusick      *	thereby becoming the portable pascal compiler
1110358Smckusick      */
1210358Smckusick 
1310358Smckusick #include	"whoami.h"
1410358Smckusick #ifdef PC
1510358Smckusick #include	"0.h"
16*18469Sralph #include	<pcc.h>
1710358Smckusick 
1810358Smckusick     /*
1910358Smckusick      *	this routine enforces ``the usual arithmetic conversions''
2010358Smckusick      *	all integral operands are converted to ints.
2110358Smckusick      *	if either operand is a double, both are made to be double.
2210358Smckusick      *	this routine takes struct nl *'s for the types,
2310358Smckusick      *	and returns both the struct nl * and the p2type for the result.
2410358Smckusick      */
2510358Smckusick tuac(thistype, thattype, resulttypep, resultp2typep)
2610358Smckusick     struct nl	*thistype;
2710358Smckusick     struct nl	*thattype;
2810358Smckusick     struct nl	**resulttypep;
2910358Smckusick     int		*resultp2typep;
3010358Smckusick {
3110358Smckusick     int		thisp2type = p2type(thistype);
3210358Smckusick     int		thatp2type = p2type(thattype);
3310358Smckusick 
3410358Smckusick     *resulttypep = thistype;
3510358Smckusick     *resultp2typep = thisp2type;
3610358Smckusick 	/*
3710358Smckusick 	 *	should only be passed scalars
3810358Smckusick 	 */
3910358Smckusick     if (isnta(thistype,"sbcid") || isnta(thattype,"sbcid")) {
4010358Smckusick 	return;
4110358Smckusick     }
42*18469Sralph     if (thisp2type == PCCT_CHAR || thisp2type == PCCT_SHORT) {
43*18469Sralph 	*resultp2typep = PCCT_INT;
4410358Smckusick 	*resulttypep = nl + T4INT;
4510358Smckusick     }
46*18469Sralph     if (*resultp2typep == PCCT_INT && thatp2type == PCCT_DOUBLE) {
47*18469Sralph 	*resultp2typep = PCCT_DOUBLE;
4810358Smckusick 	*resulttypep = nl + TDOUBLE;
4910358Smckusick     }
5010358Smckusick     sconv(thisp2type, *resultp2typep);
5110358Smckusick }
5210358Smckusick 
5310358Smckusick     /*
5410358Smckusick      *	this routine will emit sconv operators when it thinks they are needed.
5510358Smckusick      *	this is code generator specific, rather than machine-specific.
5610358Smckusick      *	this routine takes p2types for arguments, not struct nl *'s.
5710358Smckusick      */
5810358Smckusick #ifdef vax
5910358Smckusick     /*
6010358Smckusick      *	the vax code genrator is very good, this routine is extremely boring.
6110358Smckusick      */
6210358Smckusick sconv(fromp2type, top2type)
6310358Smckusick     int	fromp2type;
6410358Smckusick     int	top2type;
6510358Smckusick {
6610358Smckusick 
6710358Smckusick     switch (top2type) {
68*18469Sralph 	case PCCT_CHAR:
69*18469Sralph 	case PCCT_SHORT:
70*18469Sralph 	case PCCT_INT:
7110358Smckusick 	    switch (fromp2type) {
72*18469Sralph 		case PCCT_CHAR:
73*18469Sralph 		case PCCT_SHORT:
74*18469Sralph 		case PCCT_INT:
75*18469Sralph 		case PCCT_DOUBLE:
7610358Smckusick 			return;	/* pass1 knows how to do these */
7710358Smckusick 		default:
7810358Smckusick 			return;
7910358Smckusick 	    }
80*18469Sralph 	case PCCT_DOUBLE:
8110358Smckusick 	    switch (fromp2type) {
82*18469Sralph 		case PCCT_CHAR:
83*18469Sralph 		case PCCT_SHORT:
84*18469Sralph 		case PCCT_INT:
85*18469Sralph 			putop(PCC_SCONV, PCCT_DOUBLE);
8610358Smckusick 			return;
87*18469Sralph 		case PCCT_DOUBLE:
8810358Smckusick 			return;
8910358Smckusick 		default:
9010358Smckusick 			return;
9110358Smckusick 	    }
9210358Smckusick 	default:
9310358Smckusick 		return;
9410358Smckusick     }
9510358Smckusick }
9610358Smckusick #endif vax
9710358Smckusick #ifdef mc68000
9810358Smckusick     /*
9910358Smckusick      *	i don't know how much to trust the mc68000 compiler,
10010358Smckusick      *	so this routine is full.
10110358Smckusick      */
10210358Smckusick sconv(fromp2type, top2type)
10310358Smckusick     int	fromp2type;
10410358Smckusick     int	top2type;
10510358Smckusick {
10610358Smckusick 
10710358Smckusick     switch (top2type) {
108*18469Sralph 	case PCCT_CHAR:
10910358Smckusick 	    switch (fromp2type) {
110*18469Sralph 		case PCCT_CHAR:
11110358Smckusick 			return;
112*18469Sralph 		case PCCT_SHORT:
113*18469Sralph 		case PCCT_INT:
114*18469Sralph 		case PCCT_DOUBLE:
115*18469Sralph 			putop(PCC_SCONV, PCCT_CHAR);
11610358Smckusick 			return;
11710358Smckusick 		default:
11810358Smckusick 			return;
11910358Smckusick 	    }
120*18469Sralph 	case PCCT_SHORT:
12110358Smckusick 	    switch (fromp2type) {
122*18469Sralph 		case PCCT_SHORT:
12310358Smckusick 			return;
124*18469Sralph 		case PCCT_CHAR:
125*18469Sralph 		case PCCT_INT:
126*18469Sralph 		case PCCT_DOUBLE:
127*18469Sralph 			putop(PCC_SCONV, PCCT_SHORT);
12810358Smckusick 			return;
12910358Smckusick 		default:
13010358Smckusick 			return;
13110358Smckusick 	    }
132*18469Sralph 	case PCCT_INT:
13310358Smckusick 	    switch (fromp2type) {
134*18469Sralph 		case PCCT_INT:
13510358Smckusick 			return;
136*18469Sralph 		case PCCT_CHAR:
137*18469Sralph 		case PCCT_SHORT:
138*18469Sralph 		case PCCT_DOUBLE:
139*18469Sralph 			putop(PCC_SCONV, PCCT_INT);
14010358Smckusick 			return;
14110358Smckusick 		default:
14210358Smckusick 			return;
14310358Smckusick 	    }
144*18469Sralph 	case PCCT_DOUBLE:
14510358Smckusick 	    switch (fromp2type) {
146*18469Sralph 		case PCCT_DOUBLE:
14710358Smckusick 			return;
148*18469Sralph 		case PCCT_CHAR:
149*18469Sralph 		case PCCT_SHORT:
150*18469Sralph 		case PCCT_INT:
151*18469Sralph 			putop(PCC_SCONV, PCCT_DOUBLE);
15210358Smckusick 			return;
15310358Smckusick 		default:
15410358Smckusick 			return;
15510358Smckusick 	    }
15610358Smckusick 	default:
15710358Smckusick 		return;
15810358Smckusick     }
15910358Smckusick }
16010358Smckusick #endif mc68000
16110358Smckusick #endif PC
162