Related articles |
---|
switch statement generation dgaudet@undergrad.math.uwaterloo.ca (1994-04-06) |
Re: switch statement generation mps@dent.uchicago.edu (1994-04-07) |
switch statement generation dgaudet@undergrad.math.uwaterloo.ca (1994-04-07) |
Re: switch generation and exceptions nandu@cs.clemson.edu (1994-04-09) |
Re: switch statement generation henry@zoo.toronto.edu (1994-04-10) |
Re: switch statement generation ch+@cs.cmu.edu (1994-04-11) |
Re: switch statement generation ok@cs.rmit.oz.au (1994-04-13) |
Re: switch statement generation ltd@netcom.com (1994-04-14) |
[1 later articles] |
Newsgroups: | comp.compilers |
From: | mps@dent.uchicago.edu (Michael Spertus) |
Keywords: | code, optimize |
Organization: | Dept. of Mathematics |
References: | 94-04-031 |
Date: | Thu, 7 Apr 1994 13:35:27 GMT |
Switch statement suggestion.
I would like to see the keyword nodefault: added to switch statements.
nodefault: would have different meanings for optimized and unoptimized
code. For unoptimized code it means the case should be one of the above
cases, if not generate a run time error like an assert.
For optimized code nodefault would mean I promice the switch value is one
of the above cases and you may jump the rails if I'm wrong. Generally this
would mean picking up something not intended as an address and going there.
// A good example would be
switch((i & 3) << 2) {
case 0:
// some code
case 4:
// some code
case 8:
// some code
case 12:
// some code
nodefault:
}
In this case a very efficient switch could be built on a machine where the
addresses were 4 bytes long. I put the expression in the switch for
illustration, i could be a value taken out of a table.
This is part of a more general notion of assert() where assert means check
the expression at run time given one kind of compiler behavior e.g.
unoptimized code generaton. And promice the expression to the optimizer
given another kind of compiler behavior, e.g. optimized code generation.
In partial evaluation systems this could be very valuable.
--
Return to the
comp.compilers page.
Search the
comp.compilers archives again.