[nhc-users] Target Code Generation
Malcolm Wallace
Malcolm.Wallace@cs.york.ac.uk
Mon Sep 1 10:11:43 EDT 2003
Arun Kumar S Jadhav <arunk@it.iitb.ac.in> writes:
> I'm looking at the implementation of Haskell done by
> nhc. The precise G-code semantics are still unclear to me.
> I wanted help in two matters
> 1) It would be great if someone explained the symbol table
> structure. Because many G-code seemed to refer to
> symbol table.
Internal to the compiler, G-code instructions refer to functions and
constructors by their index value in the symbol table, a simple Int.
For example,
HEAP_CON 32
means to write a constructor into a heap cell, where 32 is its index
in the global symbol table. Use the compiler option +CTS -abound -CTS
to see the symbol table immediately before G-code-generation.
The symbol entries are like this:
(48,
InfoConstr 48 Prelude.Right IEsel (infixl{-def-} ,9) \/ b c . c -> (5 b c) [Nothing] 5)
The number 48 is the entry number (duplicated inside the "Info"
structure). The Info structure is defined in src/compiler98/Info.hs.
* This particular value is a constructor (InfoConstr).
* Its name is "Prelude.Right".
* The value "IEsel" refers to whether it is imported/re-exported from this module.
* It has default fixity and precedence (infixl 9).
* Its type is "\/ b c . c -> (5 b c)", written in big-lambda
notation where a number refers to another entry in the symbol
table. Thus, in the context of two types, b and c, Prelude.Right
takes an argument of type c and returns a value of type (Either b c)
(where entry 5 in the symbol table is an InfoData for "Either").
* [Nothing] is a list of fieldnames for this constructor (there are none).
* The final number 5 is the type to which this constructor belongs (Either).
However, when the G-code is stored as bytecode in the target .hc
file, there is no longer a global symbol table available. Instead,
each function symbol (FN_) is associated with a local constant table
(CT_) which stores references to all and only those functions and
constructors used by this function. So for instance, the G-code
instruction
HEAP_CVAL_I3
now means to take the 3rd value from the local constant table and
write it to a heap cell.
More details of the bytecode representation are in the documentation at
http://haskell.org/nhc98/implementation-notes/bytecode
> 2) The file which generates target code from G-code and the
> related files.
Generation of a .hc file containing the G-code bytecode is performed by
src/compiler98/GcodeLowC.hs
using the mechanisms defined in
src/compiler98/EmitState.hs
to resolve local and global labels.
Regards,
Malcolm
More information about the Nhc-users
mailing list