110358Smckusick /* Copyright (c) 1983 Regents of the University of California */ 210358Smckusick 3*14742Sthien #ifndef lint 4*14742Sthien static char sccsid[] = "@(#)sconv.c 1.3 08/19/83"; 5*14742Sthien #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" 1610358Smckusick #include "pcops.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 } 4210650Speter if (thisp2type == P2CHAR || thisp2type == P2SHORT) { 4310358Smckusick *resultp2typep = P2INT; 4410358Smckusick *resulttypep = nl + T4INT; 4510358Smckusick } 4610358Smckusick if (*resultp2typep == P2INT && thatp2type == P2DOUBLE) { 4710358Smckusick *resultp2typep = P2DOUBLE; 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) { 6810358Smckusick case P2CHAR: 6910358Smckusick case P2SHORT: 7010358Smckusick case P2INT: 7110358Smckusick switch (fromp2type) { 7210358Smckusick case P2CHAR: 7310358Smckusick case P2SHORT: 7410358Smckusick case P2INT: 7510358Smckusick case P2DOUBLE: 7610358Smckusick return; /* pass1 knows how to do these */ 7710358Smckusick default: 7810358Smckusick return; 7910358Smckusick } 8010358Smckusick case P2DOUBLE: 8110358Smckusick switch (fromp2type) { 8210358Smckusick case P2CHAR: 8310358Smckusick case P2SHORT: 8410358Smckusick case P2INT: 8510358Smckusick putop(P2SCONV, P2DOUBLE); 8610358Smckusick return; 8710358Smckusick case P2DOUBLE: 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) { 10810358Smckusick case P2CHAR: 10910358Smckusick switch (fromp2type) { 11010358Smckusick case P2CHAR: 11110358Smckusick return; 11210358Smckusick case P2SHORT: 11310358Smckusick case P2INT: 11410358Smckusick case P2DOUBLE: 11510358Smckusick putop(P2SCONV, P2CHAR); 11610358Smckusick return; 11710358Smckusick default: 11810358Smckusick return; 11910358Smckusick } 12010358Smckusick case P2SHORT: 12110358Smckusick switch (fromp2type) { 12210358Smckusick case P2SHORT: 12310358Smckusick return; 12410358Smckusick case P2CHAR: 12510358Smckusick case P2INT: 12610358Smckusick case P2DOUBLE: 12710358Smckusick putop(P2SCONV, P2SHORT); 12810358Smckusick return; 12910358Smckusick default: 13010358Smckusick return; 13110358Smckusick } 13210358Smckusick case P2INT: 13310358Smckusick switch (fromp2type) { 13410358Smckusick case P2INT: 13510358Smckusick return; 13610358Smckusick case P2CHAR: 13710358Smckusick case P2SHORT: 13810358Smckusick case P2DOUBLE: 13910358Smckusick putop(P2SCONV, P2INT); 14010358Smckusick return; 14110358Smckusick default: 14210358Smckusick return; 14310358Smckusick } 14410358Smckusick case P2DOUBLE: 14510358Smckusick switch (fromp2type) { 14610358Smckusick case P2DOUBLE: 14710358Smckusick return; 14810358Smckusick case P2CHAR: 14910358Smckusick case P2SHORT: 15010358Smckusick case P2INT: 15110358Smckusick putop(P2SCONV, P2DOUBLE); 15210358Smckusick return; 15310358Smckusick default: 15410358Smckusick return; 15510358Smckusick } 15610358Smckusick default: 15710358Smckusick return; 15810358Smckusick } 15910358Smckusick } 16010358Smckusick #endif mc68000 16110358Smckusick #endif PC 162