2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 /* $Id: conversion.c,v 1.7 1994/06/27 07:58:51 ceriel Exp $ */
6 /* C O N V E R S I O N - C O D E G E N E R A T O R */
21 /* conversion() generates the EM code for a conversion between
22 the types char, short, int, long, float, double and pointer.
23 There are three conversion types: signed, unsigned and floating.
24 The EM code to obtain this conversion looks like:
30 static int convtype();
32 conversion(from_type, to_type)
33 register struct type *from_type, *to_type;
35 register arith from_size = from_type->tp_size;
36 register arith to_size = to_type->tp_size;
37 int from_cnvtype = convtype(from_type);
38 int to_cnvtype = convtype(to_type);
40 if ((int)to_size < (int)word_size) to_size = word_size;
41 if ((int)from_size != (int)to_size || from_cnvtype != to_cnvtype) {
42 switch (from_cnvtype) {
52 if ((int)from_size < (int)word_size) {
56 from_size = word_size;
59 if (to_cnvtype == T_UNSIGNED
60 && (int)from_size < (int)to_size) {
68 if (to_cnvtype == T_UNSIGNED) C_ciu();
74 if ((int)from_size < (int)word_size) from_size = word_size;
105 crash("(conversion) illegal type conversion");
109 if ((int)(to_type->tp_size) < (int)word_size
110 && to_cnvtype != T_FLOATING
112 extern arith full_mask[];
114 if (to_cnvtype == T_SIGNED) {
115 C_loc(to_type->tp_size);
120 C_loc((arith) full_mask[(int)(to_type->tp_size)]);
126 /* convtype() returns in which category a given type falls:
127 signed, unsigned or floating
131 register struct type *tp;
133 switch (tp->tp_fund) {
140 return tp->tp_unsigned ? T_UNSIGNED : T_SIGNED;