122190Sdist /* 222190Sdist * Copyright (c) 1980 Regents of the University of California. 322190Sdist * All rights reserved. The Berkeley software License Agreement 422190Sdist * specifies the terms and conditions for redistribution. 522190Sdist */ 610358Smckusick 714742Sthien #ifndef lint 8*30034Smckusick static char sccsid[] = "@(#)sconv.c 5.2 (Berkeley) 11/12/86"; 922190Sdist #endif not lint 1010358Smckusick 1110358Smckusick /* 1210358Smckusick * functions to help pi put out 1310358Smckusick * polish postfix binary portable c compiler intermediate code 1410358Smckusick * thereby becoming the portable pascal compiler 1510358Smckusick */ 1610358Smckusick 1710358Smckusick #include "whoami.h" 1810358Smckusick #ifdef PC 1910358Smckusick #include "0.h" 2018469Sralph #include <pcc.h> 2110358Smckusick 2210358Smckusick /* 2310358Smckusick * this routine enforces ``the usual arithmetic conversions'' 2410358Smckusick * all integral operands are converted to ints. 2510358Smckusick * if either operand is a double, both are made to be double. 2610358Smckusick * this routine takes struct nl *'s for the types, 2710358Smckusick * and returns both the struct nl * and the p2type for the result. 2810358Smckusick */ 2910358Smckusick tuac(thistype, thattype, resulttypep, resultp2typep) 3010358Smckusick struct nl *thistype; 3110358Smckusick struct nl *thattype; 3210358Smckusick struct nl **resulttypep; 3310358Smckusick int *resultp2typep; 3410358Smckusick { 3510358Smckusick int thisp2type = p2type(thistype); 3610358Smckusick int thatp2type = p2type(thattype); 3710358Smckusick 3810358Smckusick *resulttypep = thistype; 3910358Smckusick *resultp2typep = thisp2type; 4010358Smckusick /* 4110358Smckusick * should only be passed scalars 4210358Smckusick */ 4310358Smckusick if (isnta(thistype,"sbcid") || isnta(thattype,"sbcid")) { 4410358Smckusick return; 4510358Smckusick } 4618469Sralph if (thisp2type == PCCT_CHAR || thisp2type == PCCT_SHORT) { 4718469Sralph *resultp2typep = PCCT_INT; 4810358Smckusick *resulttypep = nl + T4INT; 4910358Smckusick } 5018469Sralph if (*resultp2typep == PCCT_INT && thatp2type == PCCT_DOUBLE) { 5118469Sralph *resultp2typep = PCCT_DOUBLE; 5210358Smckusick *resulttypep = nl + TDOUBLE; 5310358Smckusick } 5410358Smckusick sconv(thisp2type, *resultp2typep); 5510358Smckusick } 5610358Smckusick 5710358Smckusick /* 5810358Smckusick * this routine will emit sconv operators when it thinks they are needed. 5910358Smckusick * this is code generator specific, rather than machine-specific. 6010358Smckusick * this routine takes p2types for arguments, not struct nl *'s. 6110358Smckusick */ 62*30034Smckusick #if defined(vax) || defined(tahoe) 6310358Smckusick /* 6410358Smckusick * the vax code genrator is very good, this routine is extremely boring. 6510358Smckusick */ 6610358Smckusick sconv(fromp2type, top2type) 6710358Smckusick int fromp2type; 6810358Smckusick int top2type; 6910358Smckusick { 7010358Smckusick 7110358Smckusick switch (top2type) { 7218469Sralph case PCCT_CHAR: 7318469Sralph case PCCT_SHORT: 7418469Sralph case PCCT_INT: 7510358Smckusick switch (fromp2type) { 7618469Sralph case PCCT_CHAR: 7718469Sralph case PCCT_SHORT: 7818469Sralph case PCCT_INT: 7918469Sralph case PCCT_DOUBLE: 8010358Smckusick return; /* pass1 knows how to do these */ 8110358Smckusick default: 8210358Smckusick return; 8310358Smckusick } 8418469Sralph case PCCT_DOUBLE: 8510358Smckusick switch (fromp2type) { 8618469Sralph case PCCT_CHAR: 8718469Sralph case PCCT_SHORT: 8818469Sralph case PCCT_INT: 8918469Sralph putop(PCC_SCONV, PCCT_DOUBLE); 9010358Smckusick return; 9118469Sralph case PCCT_DOUBLE: 9210358Smckusick return; 9310358Smckusick default: 9410358Smckusick return; 9510358Smckusick } 9610358Smckusick default: 9710358Smckusick return; 9810358Smckusick } 9910358Smckusick } 100*30034Smckusick #endif vax || tahoe 10110358Smckusick #ifdef mc68000 10210358Smckusick /* 10310358Smckusick * i don't know how much to trust the mc68000 compiler, 10410358Smckusick * so this routine is full. 10510358Smckusick */ 10610358Smckusick sconv(fromp2type, top2type) 10710358Smckusick int fromp2type; 10810358Smckusick int top2type; 10910358Smckusick { 11010358Smckusick 11110358Smckusick switch (top2type) { 11218469Sralph case PCCT_CHAR: 11310358Smckusick switch (fromp2type) { 11418469Sralph case PCCT_CHAR: 11510358Smckusick return; 11618469Sralph case PCCT_SHORT: 11718469Sralph case PCCT_INT: 11818469Sralph case PCCT_DOUBLE: 11918469Sralph putop(PCC_SCONV, PCCT_CHAR); 12010358Smckusick return; 12110358Smckusick default: 12210358Smckusick return; 12310358Smckusick } 12418469Sralph case PCCT_SHORT: 12510358Smckusick switch (fromp2type) { 12618469Sralph case PCCT_SHORT: 12710358Smckusick return; 12818469Sralph case PCCT_CHAR: 12918469Sralph case PCCT_INT: 13018469Sralph case PCCT_DOUBLE: 13118469Sralph putop(PCC_SCONV, PCCT_SHORT); 13210358Smckusick return; 13310358Smckusick default: 13410358Smckusick return; 13510358Smckusick } 13618469Sralph case PCCT_INT: 13710358Smckusick switch (fromp2type) { 13818469Sralph case PCCT_INT: 13910358Smckusick return; 14018469Sralph case PCCT_CHAR: 14118469Sralph case PCCT_SHORT: 14218469Sralph case PCCT_DOUBLE: 14318469Sralph putop(PCC_SCONV, PCCT_INT); 14410358Smckusick return; 14510358Smckusick default: 14610358Smckusick return; 14710358Smckusick } 14818469Sralph case PCCT_DOUBLE: 14910358Smckusick switch (fromp2type) { 15018469Sralph case PCCT_DOUBLE: 15110358Smckusick return; 15218469Sralph case PCCT_CHAR: 15318469Sralph case PCCT_SHORT: 15418469Sralph case PCCT_INT: 15518469Sralph putop(PCC_SCONV, PCCT_DOUBLE); 15610358Smckusick return; 15710358Smckusick default: 15810358Smckusick return; 15910358Smckusick } 16010358Smckusick default: 16110358Smckusick return; 16210358Smckusick } 16310358Smckusick } 16410358Smckusick #endif mc68000 16510358Smckusick #endif PC 166