<ulclass="crumbs"><li><ahref="../index.html">Home</a></li><li><ahref="../intern.html">Inter Modules</a></li><li><ahref="index.html">final</a></li><li><ahref="index.html#P">Preliminaries</a></li><li><b>What This Module Does</b></li></ul></div>
<pclass="commentary firstcommentary"><aid="SP1"class="paragraph-anchor"></a><b>§1. Prerequisites. </b>The final module is a part of the Inform compiler toolset. It is
presented as a literate program or "web". Before diving in:
full details, but essentially: it's C without predeclarations or header files,
and where functions have names like <spanclass="extract"><spanclass="extract-syntax">Tags::add_by_name</span></span> rather than just <spanclass="extract"><spanclass="extract-syntax">add_by_name</span></span>.
<pclass="commentary firstcommentary"><aid="SP2"class="paragraph-anchor"></a><b>§2. Finally final. </b>The final module is aptly named, in that it is the very last stage in compiling
an Inform project. Everything up to this module has been generating a tree of
Inter code, which is (to a large extent) an abstract, general-purpose description
of a program. We finally turn that into an Inform 6 program, or a C program,
or some other concrete expression of that program.
</p>
<pclass="commentary">This module has a very simple interface to the rest of the tool chain: it
simply provides a single Inter pipeline stage called <spanclass="extract"><spanclass="extract-syntax">generate</span></span>. See
<ahref="2-cg.html#SP1"class="internal">CodeGen::create_pipeline_stage</a>. When this stage is reached, the function
<ahref="2-cg.html#SP1"class="internal">CodeGen::run_pipeline_stage</a> is run. This then creates a <ahref="2-cg.html#SP2"class="internal">code_generation</a>
object, which holds all the temporary storage and configuration details for a
single act of code-generation. The most important of those details is the
choice of which <ahref="2-cg2.html#SP1"class="internal">code_generator</a> to use — see below.
</p>
<pclass="commentary firstcommentary"><aid="SP3"class="paragraph-anchor"></a><b>§3. </b>The module creates a small number of //code_generator//s, one for each
possible output format. For example, <ahref="4-fi6.html#SP1"class="internal">I6Target::create_generator</a> creates
one which represents "output Inform 6 code, please"; <ahref="5-fnc.html#SP1"class="internal">CTarget::create_generator</a>
creates one for "output ANSI C-99 code, please".
</p>
<pclass="commentary">If you are considering adding a new output format, say for JavaScript or Python,
that should be done by adding a new <ahref="2-cg2.html#SP1"class="internal">code_generator</a>. Although the default
generator is the Inform 6 one, that is in some ways misleadingly simple in
design because Inter, our intermediate format, was originally designed as a
sort of abstract paraphrase of Inform 6 — which means that it's quite easy
to turn Inter to I6. The C code generator is a much better example of the real
issues likely to present themselves. So reading through the chapter on C is
probably the best way to get an idea of the task.
</p>
<pclass="commentary firstcommentary"><aid="SP4"class="paragraph-anchor"></a><b>§4. </b>It seems likely that many if not most of the formats we will ever need to
generate will be procedural programming languages of the sort usually called
C-like, and we want to avoid duplicated effort. A generic algorithm called
<ahref="2-vnl.html"class="internal">Vanilla</a> is therefore provided: a generator can, if it wishes, make use of
this to simplify its work, and both our C and Inform 6 generators do so.