Estimated hours taken: 16
Add an MLDS to MLDS transformation that converts MLDS switches
into computed gotos or if-then-else chains. (Eventually we
should make this code also handle binary searches.)
This transformation should allow tag switch optimization to work for
the IL back-end. It also replaces ml_dense_switch.m and lets us
simplify ml_string_switch.m.
compiler/mlds.m:
Add a new `switch_range' field to the `switch' stmt.
compiler/ml_simplify_switch.m:
The new transformation. This converts MLDS switches into
computed gotos or if-then-else chains.
It uses the new `switch_range' field to determine how big
it would need to make the jump table to cover all cases.
compiler/ml_switch_gen.m:
compiler/ml_string_switch.m:
compiler/ml_tag_switch.m:
compiler/ml_dense_switch.m:
Generate the new field.
Change the places that generate switches so that after
generating the switch they invoke the new transformation.
Delete ml_dense_switch.m, since it is now redundant,
and significantly simplify ml_string_switch.m.
compiler/ml_elim_nested.m:
compiler/ml_optimize.m:
compiler/ml_tailcall.m:
compiler/ml_util.m:
compiler/mlds_to_c.m:
compiler/mlds_to_il.m:
Trivial changes to handle the new field.
compiler/switch_util.m:
compiler/dense_switch.m:
Move most of the code from the `type_range' procedure from
dense_switch.m to switch_util.m, so we can use it in
ml_switch_gen.m for computing the switch range.
Estimated hours taken: 2
Reorganize the code for handling switches in the MLDS and
LLDS back-ends to reduce code duplication.
compiler/switch_util.m:
New file. Contains stuff for switches that is shared
between the MLDS and LLDS back-ends.
compiler/ml_switch_gen.m:
compiler/ml_string_switch.m:
compiler/ml_tag_switch.m:
compiler/switch_gen.m:
compiler/string_switch.m:
compiler/tag_switch.m:
Move code that was duplicated in the LLDS and MLDS back-ends
into string_util.m. Change some names and import_module
declarations to match the new organization.
compiler/notes/compiler_design.html:
Document the new module switch_util.m.
Also mention ml_tag_switch.m.