[project @ 1996-01-08 20:28:12 by partain]
[ghc-hetmet.git] / ghc / docs / users_guide / tutorial.lit
1 %
2 % $Header: /srv/cvs/cvs.haskell.org/fptools/ghc/docs/users_guide/Attic/tutorial.lit,v 1.1 1996/01/08 20:25:11 partain Exp $
3 %
4 \section[compiler-tutorial]{Tutorial material about this compilation system}
5
6 This guide assumes quite a bit of knowledge about UNIX compilers and
7 their conventional use.  This section has a little extra information
8 for those who are new at this racket.
9
10 %************************************************************************
11 %*                                                                      *
12 \subsection[batch-system-parts]{The (batch) compilation system components}
13 %*                                                                      *
14 %************************************************************************
15
16 The Glorious Haskell Compilation System, as with most UNIX (batch)
17 compilation systems, has several interacting parts:
18 \begin{enumerate}
19 \item
20 A {\em driver}\index{driver program} \tr{ghc}\index{ghc}---which you
21 usually think of as ``the compiler''---is a program that merely
22 invokes/glues-together the other pieces of the system (listed below),
23 passing the right options to each, slurping in the right libraries,
24 etc.
25
26 \item
27 A {\em literate pre-processor}
28 \index{literate pre-processor}
29 \index{pre-processor, literate}
30 \tr{unlit}\index{unlit} that extracts Haskell
31 code from a literate script; used if you believe in that sort of
32 thing.
33
34 \item
35 The {\em Haskellised C pre-processor}
36 \index{Haskellised C pre-processor}
37 \index{C pre-processor, Haskellised}
38 \index{pre-processor, Haskellised C}
39 \tr{hscpp},\index{hscpp} only needed by people requiring conditional
40 compilation, probably for large systems.  The ``Haskellised'' part
41 just means that \tr{#line} directives in the output have been
42 converted into proper Haskell \tr{{-# LINE ... -}} pragmas.
43
44 You must give an explicit \tr{-cpp} option 
45 \index{-cpp option} for the C pre-processor to be invoked.
46
47 \item
48 The {\em Haskell compiler}
49 \index{Haskell compiler}
50 \index{compiler, Haskell}
51 \tr{hsc},\index{hsc}
52 which---in normal use---takes its input from the C pre-processor
53 and produces assembly-language output (sometimes: ANSI C output).
54
55 \item
56 The {\em ANSI~C Haskell high-level assembler :-)}
57 \index{ANSI C compiler}
58 \index{high-level assembler}
59 \index{assembler, high-level}
60 compiles \tr{hsc}'s C output into assembly language for a particular
61 target architecture.  (It doesn't have to be an ANSI C compiler, but
62 that's preferred; to go fastest, you need GNU C, version 2.x.)
63
64 \item
65 The {\em assembler}\index{assembler}---a standard UNIX one, probably
66 \tr{as}\index{as}.
67
68 \item
69 The {\em linker}\index{linker}---a standard UNIX one, probably
70 \tr{ld}.\index{ld}
71
72 \item
73 A {\em runtime system},\index{runtime system} including (most notably)
74 a storage manager; the linker links in the code for this.
75
76 \item
77 The {\em Haskell standard prelude}\index{standard prelude}, a
78 large library of standard functions, is linked in as well.
79
80 \item
81 Parts of other {\em installed libraries} that you have at your site
82 may be linked in also.
83 \end{enumerate}
84
85 %************************************************************************
86 %*                                                                      *
87 \subsection[compile-what-really-happens]{What really happens when I ``compile'' a Haskell program?}
88 %*                                                                      *
89 %************************************************************************
90
91 You invoke the Glasgow Haskell compilation system through the
92 driver program \tr{ghc}.\index{ghc} For example, if you had typed a
93 literate ``Hello, world!'' program into \tr{hello.lhs}, and you then
94 invoked:
95 \begin{verbatim}
96 ghc hello.lhs
97 \end{verbatim}
98
99 the following would happen:
100 \begin{enumerate}
101 \item
102 The file \tr{hello.lhs} is run through the literate-program
103 code extractor \tr{unlit}\index{unlit}, feeding its output to
104
105 \item
106 The Haskell compiler proper \tr{hsc}\index{hsc}, which produces
107 input for
108
109 \item
110 The assembler (or that ubiquitous ``high-level assembler,'' a C
111 compiler), which produces an object file and passes it to
112
113 \item
114 The linker, which links your code with the appropriate libraries
115 (including the standard prelude), producing an executable program in
116 the default output file named \tr{a.out}.
117 \end{enumerate}
118
119 You have considerable control over the compilation process.  You feed
120 command-line arguments (call them ``options,'' for short) to the
121 driver, \tr{ghc}; the ``types'' of the input files (as encoded in
122 their names' suffixes) also matter.
123
124 Here's hoping this is enough background so that you can read the rest
125 of this guide!
126
127 % The ``style'' of the driver program \tr{ghc} follows that of the GNU C
128 % compiler driver \tr{gcc}.  The use of environment variables to provide
129 % defaults is more extensive in this compilation system.