[project @ 2000-03-09 06:14:38 by andy]
[ghc-hetmet.git] / ghc / interpreter / object.h
1
2 /* --------------------------------------------------------------------------
3  * Machinery for dynamic loading and linking of object code.  Should be 
4  * completely independent from the rest of Hugs so we can use it in
5  * other applications if desired.
6  *
7  * The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the
8  * Yale Haskell Group, and the Oregon Graduate Institute of Science and
9  * Technology, 1994-1999, All rights reserved.  It is distributed as
10  * free software under the license in the file "License", which is
11  * included in the distribution.
12  *
13  * ------------------------------------------------------------------------*/
14
15 #ifndef __HUGS_OBJECT_H
16 #define __HUGS_OBJECT_H
17
18 /* An entry in a very crude object symbol table */
19 typedef struct { char* nm; void* ad; } 
20    OSym;
21
22
23 /* Indication of section kinds for loaded objects.  Needed by
24    the GC for deciding whether or not a pointer on the stack
25    is a code pointer.
26 */
27 typedef enum { HUGS_SECTIONKIND_CODE_OR_RODATA,
28                HUGS_SECTIONKIND_RWDATA,
29                HUGS_SECTIONKIND_OTHER,
30                HUGS_SECTIONKIND_NOINFOAVAIL } 
31    OSectionKind;
32
33 typedef struct { void* start; void* end; OSectionKind kind; } 
34    OSection;
35
36
37 /* Indication of the status of an ObjectCode structure.
38    NOTINUSE  -- currently unused.
39    OIMAGE    -- object image is in memory, but that's all.
40    VERIFIED  -- OIMAGE + the loaded image has been verified as 
41                 a valid object file.
42    HAVENAMES -- VERIFIED + names *defined* in this image have been 
43                 extracted from the image and placed in the oTab, 
44                 and also section info placed in sectionTab.
45    RESOLVED  -- HAVENAMES + all names *used* in this image have
46                 successfully been resolved.
47     
48 */
49 typedef enum { OBJECT_NOTINUSE,
50                OBJECT_OIMAGE,
51                OBJECT_VERIFIED,
52                OBJECT_HAVENAMES,
53                OBJECT_RESOLVED }
54    OStatus;
55
56
57 /* Top-level structure for an object module.  One of these is allocated
58    for each object file in use.  This should really be an abstract type
59    to clients.
60 */
61 typedef
62    struct __ObjectCode {
63       OStatus   status;
64       char*     objFileName;
65       int       objFileSize;
66       char*     formatName;            /* eg "ELF32", "DLL", "COFF", etc. */
67
68       /* proc to call to deliver an error message to the client. */
69       void      (*errMsg)(char*);
70
71       /* proc to call to resolve symbols not defined in this module, 
72          when asked to resolve symbols in this module */
73       void*     (*clientLookup)(char*);
74
75       /* ptr to malloc'd lump of memory holding the obj file */
76       void*     oImage;
77
78       /* ptr to object symbol table; lives in mallocville.  
79          Dynamically expands. */
80       OSym*     oTab;
81       int       sizeoTab;
82       int       usedoTab;
83
84       /* The section-kind entries for this object module.  
85          Dynamically expands. */    
86       OSection* sectionTab;
87       int       sizesectionTab;
88       int       usedsectionTab;        
89
90       /* Allow a chain of these things */
91       struct __ObjectCode * next;
92    }
93    ObjectCode;
94
95
96 /* The API */
97 extern ObjectCode*  ocNew ( void  (*errMsg)(char*),
98                             void* (*clientLookup)(char*),
99                             char*  objFileName,
100                             int    objFileSize );
101                             
102 extern int /*Bool*/ ocLoadImage     ( ObjectCode* oc, int verb );
103 extern int /*Bool*/ ocVerifyImage   ( ObjectCode* oc, int verb );
104 extern int /*Bool*/ ocGetNames      ( ObjectCode* oc, int verb );
105 extern int /*Bool*/ ocResolve       ( ObjectCode* oc, int verb );
106 extern void         ocFree          ( ObjectCode* oc );
107
108 extern void*        ocLookupSym     ( ObjectCode* oc, char* sym );
109 extern char*        ocLookupAddr    ( ObjectCode* oc, void* addr );
110 extern OSectionKind ocLookupSection ( ObjectCode* oc, void* addr );
111
112 #endif
113
114 /*-------------------------------------------------------------------------*/
115