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