Portability through backend abstraction
Context
Compilers from two different languages to the same
language, e.g. processor instruction set. It becomes desirable to support a
new hardware platform, and it is anticipated that new targets will continue
to emerge. Frequent minor modifications to the existing compilers are
required.
Problem
If a new system is developed ``from scratch'' for each new
target, the developers will be expected to meet demands from a rapidly
evolving set of target projects: it is important to minimise the work
needed to support a new platform and the maintenance work required. We
could consider ``wrapping'' the old compilers and translating from the old
target to the new, but such translations are not easily defined and appear
to be very error prone. At the same time, it is impossible to cease to
enhance the old compilers whilst developing the new ones.
Solution
Define an abstract intermediate target,
suitable for both easy translation from the front ends and easy translation
to the targets. Develop new versions of the two current systems, in which
their frontends are preserved intact but they compile to the new abstract
target. Produce translators from this abstract intermediate code to the
currently urgent targets. Do not modify the current working system for the
old target at this stage, but begin work, in parallel and at lower
priority, on a backend translator for this also.
Consequences
At worst the reengineering of the existing systems
is no worse than writing new systems from scratch for one new target. In
practice it is likely to be less costly, since the abstract target is
chosen in part to be easy to translate to. Work on the backend translators
will involve some extra overhead in the case of a single new target, but
will represent a significant gain for the second target. Future
retargetting will be quicker, easier and more flexible. The quality of the
backends will be higher since more resources will be freed to devote to
this stage.
Contributors
Rob Pooley, Perdita Stevens