1 /*- 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 */ 7 8 #ifndef lint 9 static char sccsid[] = "@(#)sconv.c 8.1 (Berkeley) 06/06/93"; 10 #endif /* not lint */ 11 12 /* 13 * functions to help pi put out 14 * polish postfix binary portable c compiler intermediate code 15 * thereby becoming the portable pascal compiler 16 */ 17 18 #include "whoami.h" 19 #ifdef PC 20 #include "0.h" 21 #include <pcc.h> 22 23 /* 24 * this routine enforces ``the usual arithmetic conversions'' 25 * all integral operands are converted to ints. 26 * if either operand is a double, both are made to be double. 27 * this routine takes struct nl *'s for the types, 28 * and returns both the struct nl * and the p2type for the result. 29 */ 30 tuac(thistype, thattype, resulttypep, resultp2typep) 31 struct nl *thistype; 32 struct nl *thattype; 33 struct nl **resulttypep; 34 int *resultp2typep; 35 { 36 int thisp2type = p2type(thistype); 37 int thatp2type = p2type(thattype); 38 39 *resulttypep = thistype; 40 *resultp2typep = thisp2type; 41 /* 42 * should only be passed scalars 43 */ 44 if (isnta(thistype,"sbcid") || isnta(thattype,"sbcid")) { 45 return; 46 } 47 if (thisp2type == PCCT_CHAR || thisp2type == PCCT_SHORT) { 48 *resultp2typep = PCCT_INT; 49 *resulttypep = nl + T4INT; 50 } 51 if (*resultp2typep == PCCT_INT && thatp2type == PCCT_DOUBLE) { 52 *resultp2typep = PCCT_DOUBLE; 53 *resulttypep = nl + TDOUBLE; 54 } 55 sconv(thisp2type, *resultp2typep); 56 } 57 58 /* 59 * this routine will emit sconv operators when it thinks they are needed. 60 * this is code generator specific, rather than machine-specific. 61 * this routine takes p2types for arguments, not struct nl *'s. 62 */ 63 #if defined(vax) || defined(tahoe) 64 /* 65 * the vax code genrator is very good, this routine is extremely boring. 66 */ 67 sconv(fromp2type, top2type) 68 int fromp2type; 69 int top2type; 70 { 71 72 switch (top2type) { 73 case PCCT_CHAR: 74 case PCCT_SHORT: 75 case PCCT_INT: 76 switch (fromp2type) { 77 case PCCT_CHAR: 78 case PCCT_SHORT: 79 case PCCT_INT: 80 case PCCT_DOUBLE: 81 return; /* pass1 knows how to do these */ 82 default: 83 return; 84 } 85 case PCCT_DOUBLE: 86 switch (fromp2type) { 87 case PCCT_CHAR: 88 case PCCT_SHORT: 89 case PCCT_INT: 90 putop(PCC_SCONV, PCCT_DOUBLE); 91 return; 92 case PCCT_DOUBLE: 93 return; 94 default: 95 return; 96 } 97 default: 98 return; 99 } 100 } 101 #endif vax || tahoe 102 #ifdef mc68000 103 /* 104 * i don't know how much to trust the mc68000 compiler, 105 * so this routine is full. 106 */ 107 sconv(fromp2type, top2type) 108 int fromp2type; 109 int top2type; 110 { 111 112 switch (top2type) { 113 case PCCT_CHAR: 114 switch (fromp2type) { 115 case PCCT_CHAR: 116 return; 117 case PCCT_SHORT: 118 case PCCT_INT: 119 case PCCT_DOUBLE: 120 putop(PCC_SCONV, PCCT_CHAR); 121 return; 122 default: 123 return; 124 } 125 case PCCT_SHORT: 126 switch (fromp2type) { 127 case PCCT_SHORT: 128 return; 129 case PCCT_CHAR: 130 case PCCT_INT: 131 case PCCT_DOUBLE: 132 putop(PCC_SCONV, PCCT_SHORT); 133 return; 134 default: 135 return; 136 } 137 case PCCT_INT: 138 switch (fromp2type) { 139 case PCCT_INT: 140 return; 141 case PCCT_CHAR: 142 case PCCT_SHORT: 143 case PCCT_DOUBLE: 144 putop(PCC_SCONV, PCCT_INT); 145 return; 146 default: 147 return; 148 } 149 case PCCT_DOUBLE: 150 switch (fromp2type) { 151 case PCCT_DOUBLE: 152 return; 153 case PCCT_CHAR: 154 case PCCT_SHORT: 155 case PCCT_INT: 156 putop(PCC_SCONV, PCCT_DOUBLE); 157 return; 158 default: 159 return; 160 } 161 default: 162 return; 163 } 164 } 165 #endif mc68000 166 #endif PC 167