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 3.20 1994/06/24 12:02:47 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 */
24 /* conversion() generates the EM code for a conversion between
25 the types char, short, int, long, float, double and pointer.
26 There are three conversion types: signed, unsigned and floating.
27 The EM code to obtain this conversion looks like:
33 static int convtype();
35 conversion(from_type, to_type)
36 register struct type *from_type, *to_type;
38 register arith from_size = from_type->tp_size;
39 register arith to_size = to_type->tp_size;
40 int from_cnvtype = convtype(from_type);
41 int to_cnvtype = convtype(to_type);
43 if ((int)to_size < (int)word_size) to_size = word_size;
44 if ((int)from_size == (int)to_size && from_cnvtype == to_cnvtype)
46 switch (from_cnvtype) {
58 if ((int)from_size < (int)word_size) {
62 from_size = word_size;
66 if (to_cnvtype == T_UNSIGNED) C_ciu();
72 if ((int)from_size < (int)word_size) from_size = word_size;
107 crash("(conversion) illegal type conversion");
110 if ((int)(to_type->tp_size) < (int)word_size
112 && to_cnvtype != T_FLOATING
115 extern long full_mask[];
117 if (to_cnvtype == T_SIGNED) {
118 C_loc(to_type->tp_size);
123 C_loc((arith) full_mask[(int)(to_type->tp_size)]);
129 /* convtype() returns in which category a given type falls:
130 signed, unsigned or floating
134 register struct type *tp;
136 switch (tp->tp_fund) {
143 return tp->tp_unsigned ? T_UNSIGNED : T_SIGNED;