Related articles |
---|
Who should convert literals to integers? ubc-cs!calgary!radford@uunet.com (1988-08-12) |
Who should convert literals to integers? think!compass!worley@eddie.mit.edu.uucp (Dale Worley) (1988-08-17) |
Re: Who should convert literals to integers? haddock!ico!rcd (1988-08-17) |
Re: Who should convert literals to integers? Tom.Lane@ZOG.CS.CMU.EDU (1988-08-21) |
Re: Who should convert literals to integers? markhall@pyramid.pyramid.com (1988-08-29) |
Re: Who should convert literals to integers? tgl@zog.cs.cmu.edu (1988-09-04) |
Re: Who should convert literals to integers? wendyt@pyrps5.pyramid.com (1988-09-09) |
From: | markhall@pyramid.pyramid.com (Mark Hall) |
Newsgroups: | comp.compilers |
Date: | 29 Aug 88 23:36:58 GMT |
References: | <2299@ima.ima.isc.com> |
Organization: | Pyramid Technology Corp., Mountain View, CA |
In article <2299@ima.ima.isc.com> Tom.Lane@ZOG.CS.CMU.EDU writes:
>
>The main reason for converting constants to binary is so the compiler
>can do arithmetic on them. Somebody already mentioned constant folding,
>but nobody has yet pointed out the most crucial case where the compiler
>must do this: where the constants in question are array subscript
>bounds. You *must* do arithmetic at compile time to do storage
>allocation! (Unless you want to use a dope vector and run-time
>storage allocation for every array, which is mighty expensive.)
>
>[stuff deleted] Users weren't allowed to declare
>arrays of more than 32k elements... [stuff deleted]
>
If anyone out there is writing a compiler from scratch, please
don't do what is described above. Whenever compile-time
arithmetic is required, calls should be made to a retargetable
module which can carry out the computation in the same precision
and semantics of the target machine. If the host has more
precision than the target, then the representation possibly
`must' be strings, but it's far from impossible to do arithmetic
on strings! Other possibilities exist. One might be able to
successfully represent target `int's using host double-precision
floating point (this worked for one host-target pair that I
wrote a compiler for). On pg. 97 of:
%A William Waite
%A Gerhard Goos
%T Compiler Construction
%I Springer-Verlag
%C New York, NY
%D 1984
there is a more elaborate description of how (and why) this can be done.
You might not think your compiler will get targeted to another product
line, but just when you least suspect it, the CEO will drop in and insist
that it be done in 1 month!
[From markhall@pyramid.pyramid.com (Mark Hall)]
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.