1*48116Sbostic /*- 2*48116Sbostic * Copyright (c) 1980 The Regents of the University of California. 3*48116Sbostic * All rights reserved. 4*48116Sbostic * 5*48116Sbostic * %sccs.include.redist.c% 622190Sdist */ 710358Smckusick 814742Sthien #ifndef lint 9*48116Sbostic static char sccsid[] = "@(#)sconv.c 5.3 (Berkeley) 04/16/91"; 10*48116Sbostic #endif /* not lint */ 1110358Smckusick 1210358Smckusick /* 1310358Smckusick * functions to help pi put out 1410358Smckusick * polish postfix binary portable c compiler intermediate code 1510358Smckusick * thereby becoming the portable pascal compiler 1610358Smckusick */ 1710358Smckusick 1810358Smckusick #include "whoami.h" 1910358Smckusick #ifdef PC 2010358Smckusick #include "0.h" 2118469Sralph #include <pcc.h> 2210358Smckusick 2310358Smckusick /* 2410358Smckusick * this routine enforces ``the usual arithmetic conversions'' 2510358Smckusick * all integral operands are converted to ints. 2610358Smckusick * if either operand is a double, both are made to be double. 2710358Smckusick * this routine takes struct nl *'s for the types, 2810358Smckusick * and returns both the struct nl * and the p2type for the result. 2910358Smckusick */ 3010358Smckusick tuac(thistype, thattype, resulttypep, resultp2typep) 3110358Smckusick struct nl *thistype; 3210358Smckusick struct nl *thattype; 3310358Smckusick struct nl **resulttypep; 3410358Smckusick int *resultp2typep; 3510358Smckusick { 3610358Smckusick int thisp2type = p2type(thistype); 3710358Smckusick int thatp2type = p2type(thattype); 3810358Smckusick 3910358Smckusick *resulttypep = thistype; 4010358Smckusick *resultp2typep = thisp2type; 4110358Smckusick /* 4210358Smckusick * should only be passed scalars 4310358Smckusick */ 4410358Smckusick if (isnta(thistype,"sbcid") || isnta(thattype,"sbcid")) { 4510358Smckusick return; 4610358Smckusick } 4718469Sralph if (thisp2type == PCCT_CHAR || thisp2type == PCCT_SHORT) { 4818469Sralph *resultp2typep = PCCT_INT; 4910358Smckusick *resulttypep = nl + T4INT; 5010358Smckusick } 5118469Sralph if (*resultp2typep == PCCT_INT && thatp2type == PCCT_DOUBLE) { 5218469Sralph *resultp2typep = PCCT_DOUBLE; 5310358Smckusick *resulttypep = nl + TDOUBLE; 5410358Smckusick } 5510358Smckusick sconv(thisp2type, *resultp2typep); 5610358Smckusick } 5710358Smckusick 5810358Smckusick /* 5910358Smckusick * this routine will emit sconv operators when it thinks they are needed. 6010358Smckusick * this is code generator specific, rather than machine-specific. 6110358Smckusick * this routine takes p2types for arguments, not struct nl *'s. 6210358Smckusick */ 6330034Smckusick #if defined(vax) || defined(tahoe) 6410358Smckusick /* 6510358Smckusick * the vax code genrator is very good, this routine is extremely boring. 6610358Smckusick */ 6710358Smckusick sconv(fromp2type, top2type) 6810358Smckusick int fromp2type; 6910358Smckusick int top2type; 7010358Smckusick { 7110358Smckusick 7210358Smckusick switch (top2type) { 7318469Sralph case PCCT_CHAR: 7418469Sralph case PCCT_SHORT: 7518469Sralph case PCCT_INT: 7610358Smckusick switch (fromp2type) { 7718469Sralph case PCCT_CHAR: 7818469Sralph case PCCT_SHORT: 7918469Sralph case PCCT_INT: 8018469Sralph case PCCT_DOUBLE: 8110358Smckusick return; /* pass1 knows how to do these */ 8210358Smckusick default: 8310358Smckusick return; 8410358Smckusick } 8518469Sralph case PCCT_DOUBLE: 8610358Smckusick switch (fromp2type) { 8718469Sralph case PCCT_CHAR: 8818469Sralph case PCCT_SHORT: 8918469Sralph case PCCT_INT: 9018469Sralph putop(PCC_SCONV, PCCT_DOUBLE); 9110358Smckusick return; 9218469Sralph case PCCT_DOUBLE: 9310358Smckusick return; 9410358Smckusick default: 9510358Smckusick return; 9610358Smckusick } 9710358Smckusick default: 9810358Smckusick return; 9910358Smckusick } 10010358Smckusick } 10130034Smckusick #endif vax || tahoe 10210358Smckusick #ifdef mc68000 10310358Smckusick /* 10410358Smckusick * i don't know how much to trust the mc68000 compiler, 10510358Smckusick * so this routine is full. 10610358Smckusick */ 10710358Smckusick sconv(fromp2type, top2type) 10810358Smckusick int fromp2type; 10910358Smckusick int top2type; 11010358Smckusick { 11110358Smckusick 11210358Smckusick switch (top2type) { 11318469Sralph case PCCT_CHAR: 11410358Smckusick switch (fromp2type) { 11518469Sralph case PCCT_CHAR: 11610358Smckusick return; 11718469Sralph case PCCT_SHORT: 11818469Sralph case PCCT_INT: 11918469Sralph case PCCT_DOUBLE: 12018469Sralph putop(PCC_SCONV, PCCT_CHAR); 12110358Smckusick return; 12210358Smckusick default: 12310358Smckusick return; 12410358Smckusick } 12518469Sralph case PCCT_SHORT: 12610358Smckusick switch (fromp2type) { 12718469Sralph case PCCT_SHORT: 12810358Smckusick return; 12918469Sralph case PCCT_CHAR: 13018469Sralph case PCCT_INT: 13118469Sralph case PCCT_DOUBLE: 13218469Sralph putop(PCC_SCONV, PCCT_SHORT); 13310358Smckusick return; 13410358Smckusick default: 13510358Smckusick return; 13610358Smckusick } 13718469Sralph case PCCT_INT: 13810358Smckusick switch (fromp2type) { 13918469Sralph case PCCT_INT: 14010358Smckusick return; 14118469Sralph case PCCT_CHAR: 14218469Sralph case PCCT_SHORT: 14318469Sralph case PCCT_DOUBLE: 14418469Sralph putop(PCC_SCONV, PCCT_INT); 14510358Smckusick return; 14610358Smckusick default: 14710358Smckusick return; 14810358Smckusick } 14918469Sralph case PCCT_DOUBLE: 15010358Smckusick switch (fromp2type) { 15118469Sralph case PCCT_DOUBLE: 15210358Smckusick return; 15318469Sralph case PCCT_CHAR: 15418469Sralph case PCCT_SHORT: 15518469Sralph case PCCT_INT: 15618469Sralph putop(PCC_SCONV, PCCT_DOUBLE); 15710358Smckusick return; 15810358Smckusick default: 15910358Smckusick return; 16010358Smckusick } 16110358Smckusick default: 16210358Smckusick return; 16310358Smckusick } 16410358Smckusick } 16510358Smckusick #endif mc68000 16610358Smckusick #endif PC 167