1 /* -*- mode: hugs-c; -*- */
2 /* -----------------------------------------------------------------------------
5 * Copyright (c) 1994-1998.
7 * $RCSfile: Assembler.h,v $
9 * $Date: 1998/12/02 13:20:52 $
11 * NB This is one of the few files shared between Hugs and the runtime system,
12 * so it is very important that it not conflict with either and that it not
14 * (In fact, it might be fun to create a GreenCard interface to this file too.)
15 * ---------------------------------------------------------------------------*/
17 /* ToDo: put this somewhere more sensible */
18 extern void DEBUG_LoadSymbols( char *name );
20 /* This file is supposed to be somewhat self-contained because it is one
21 * of the major external interfaces to the runtime system.
22 * Keeping it self-contained reduces the chance of conflict with Hugs
23 * (or anything else that includes it).
24 * The big disadvantage of being self-contained is that definitions
25 * like AsmNat8, etc duplicate definitions in StgTypes.h.
26 * I'm not sure what we can do about this but, if you try to fix it,
27 * please remember why it was done this way in the first place.
31 typedef unsigned char AsmNat8;
32 typedef unsigned int AsmNat;
33 typedef signed int AsmInt;
34 typedef signed long long int AsmInt64; /* ToDo: not portable! */
35 typedef unsigned int AsmWord;
36 typedef void* AsmAddr;
37 typedef unsigned char AsmChar;
38 typedef float AsmFloat; /* ToDo: not on Alphas! */
39 typedef double AsmDouble;
40 typedef char* AsmString;
42 /* I want to #include this file into the file that defines the
43 * functions but I don't want to expose the structures that
44 * these types point to.
45 * This hack is the best I could think of. Surely there's a better way?
47 #ifdef INSIDE_ASSEMBLER_C
48 typedef struct AsmObject_ *AsmObject;
49 typedef struct AsmBCO_ *AsmBCO;
50 typedef struct AsmCAF_ *AsmCAF;
51 typedef struct AsmCon_ *AsmCon;
52 typedef StgInfoTable *AsmInfo;
53 typedef StgClosure *AsmClosure;
54 typedef Instr AsmInstr;
56 /* the types we export are totally opaque */
57 typedef void *AsmObject;
61 typedef void *AsmInfo;
62 typedef void *AsmClosure;
63 typedef unsigned int AsmInstr;
66 typedef int AsmSp; /* stack offset */
67 typedef int AsmPc; /* program counter */
68 typedef AsmSp AsmVar; /* offset of a Var on the stack */
70 /* --------------------------------------------------------------------------
71 * "Types" used within the assembler
73 * Some of these types are synonyms for the same underlying representation
74 * to let Hugs (or whoever) generate useful Haskell types from the type
75 * of a primitive operation.
77 * Extreme care should be taken if you change any of these - the
78 * same constants are hardwired into Hugs (ILLEGAL_REP) and into
79 * pieces of assembly language used to implement foreign import/export.
80 * And, of course, you'll have to change the primop table in Assembler.c
81 * ------------------------------------------------------------------------*/
86 /* The following can be passed to C */
92 #ifdef PROVIDE_INTEGER
103 #ifdef PROVIDE_STABLE
104 STABLE_REP = 's', /* StablePtr a */
106 #ifdef PROVIDE_FOREIGN
107 FOREIGN_REP = 'f', /* ForeignObj */
110 WEAK_REP = 'w', /* Weak a */
113 BARR_REP = 'x', /* PrimByteArray a */
114 MUTBARR_REP = 'm', /* PrimMutableByteArray s a */
117 /* The following can't be passed to C */
119 ALPHA_REP = 'a', /* a */
120 BETA_REP = 'b', /* b */
121 BOOL_REP = 'B', /* Bool */
122 IO_REP = 'i', /* IO a */
123 HANDLER_REP = 'H', /* Exception -> IO a */
124 ERROR_REP = 'E', /* Exception */
126 ARR_REP = 'X', /* PrimArray a */
127 REF_REP = 'R', /* Ref s a */
128 MUTARR_REP = 'M', /* PrimMutableArray s a */
130 #ifdef PROVIDE_CONCURRENT
131 THREADID_REP = 'T', /* ThreadId */
132 MVAR_REP = 'r', /* MVar a */
135 /* Allegedly used in the IO monad */
139 /* --------------------------------------------------------------------------
140 * Allocating (top level) heap objects
141 * ------------------------------------------------------------------------*/
143 extern AsmBCO asmBeginBCO ( void );
144 extern void asmEndBCO ( AsmBCO bco );
146 extern AsmBCO asmBeginContinuation ( AsmSp sp );
147 extern void asmEndContinuation ( AsmBCO bco );
149 extern AsmObject asmMkObject ( AsmClosure c );
151 extern AsmCAF asmBeginCAF ( void );
152 extern void asmEndCAF ( AsmCAF caf, AsmBCO body );
154 extern AsmInfo asmMkInfo ( AsmNat tag, AsmNat ptrs );
155 extern AsmCon asmBeginCon ( AsmInfo info );
156 extern void asmEndCon ( AsmCon con );
158 /* NB: we add ptrs to other objects in left-to-right order.
159 * This is different from pushing arguments on the stack which is done
160 * in right to left order.
162 extern void asmAddPtr ( AsmObject obj, AsmObject arg );
164 extern int asmObjectHasClosure( AsmObject obj );
165 extern AsmClosure asmClosureOfObject ( AsmObject obj );
166 extern void asmMarkObject ( AsmObject obj );
168 /* --------------------------------------------------------------------------
169 * Generating instruction streams
170 * ------------------------------------------------------------------------*/
172 extern AsmSp asmBeginArgCheck ( AsmBCO bco );
173 extern void asmEndArgCheck ( AsmBCO bco, AsmSp last_arg );
175 extern AsmSp asmBeginEnter ( AsmBCO bco );
176 extern void asmEndEnter ( AsmBCO bco, AsmSp sp1, AsmSp sp2 );
178 extern AsmVar asmBind ( AsmBCO bco, AsmRep rep );
179 extern void asmVar ( AsmBCO bco, AsmVar v, AsmRep rep );
181 extern AsmSp asmBeginCase ( AsmBCO bco );
182 extern void asmEndCase ( AsmBCO bco );
183 extern AsmSp asmContinuation ( AsmBCO bco, AsmBCO ret_addr );
185 extern AsmSp asmBeginAlt ( AsmBCO bco );
186 extern void asmEndAlt ( AsmBCO bco, AsmSp sp );
187 extern AsmPc asmTest ( AsmBCO bco, AsmWord tag );
188 extern AsmPc asmTestInt ( AsmBCO bco, AsmVar v, AsmInt x );
189 extern void asmFixBranch ( AsmBCO bco, AsmPc pc );
190 extern void asmPanic ( AsmBCO bco );
192 extern AsmVar asmBox ( AsmBCO bco, AsmRep rep );
193 extern AsmVar asmUnbox ( AsmBCO bco, AsmRep rep );
194 extern void asmReturnUnboxed ( AsmBCO bco, AsmRep rep );
196 /* push unboxed Ints, Floats, etc */
197 extern void asmConstInt ( AsmBCO bco, AsmInt x );
199 extern void asmConstAddr ( AsmBCO bco, AsmAddr x );
202 extern void asmConstWord ( AsmBCO bco, AsmWord x );
204 extern void asmConstChar ( AsmBCO bco, AsmChar x );
205 extern void asmConstFloat ( AsmBCO bco, AsmFloat x );
206 extern void asmConstDouble ( AsmBCO bco, AsmDouble x );
208 extern void asmConstInt64 ( AsmBCO bco, AsmInt64 x );
210 #ifdef PROVIDE_INTEGER
211 extern void asmConstInteger ( AsmBCO bco, AsmString x );
214 /* Which monad (if any) does the primop live in? */
216 MONAD_Id, /* no monad (aka the identity monad) */
226 AsmNat8 prefix; /* should be StgInstr */
227 AsmNat8 opcode; /* should be Primop1 or Primop2 */
230 extern const AsmPrim asmPrimOps[]; /* null terminated list */
232 extern const AsmPrim* asmFindPrim ( char* s );
233 extern const AsmPrim* asmFindPrimop ( AsmInstr prefix, AsmInstr op );
234 extern AsmSp asmBeginPrim ( AsmBCO bco );
235 extern void asmEndPrim ( AsmBCO bco, const AsmPrim* prim, AsmSp base );
237 /* --------------------------------------------------------------------------
239 * ------------------------------------------------------------------------*/
241 extern AsmVar asmClosure ( AsmBCO bco, AsmObject p );
243 extern AsmVar asmAllocCONSTR ( AsmBCO bco, AsmInfo info );
245 extern AsmSp asmBeginPack ( AsmBCO bco );
246 extern void asmEndPack ( AsmBCO bco, AsmVar v, AsmSp start, AsmInfo info );
248 extern void asmBeginUnpack ( AsmBCO bco );
249 extern void asmEndUnpack ( AsmBCO bco );
251 extern AsmVar asmAllocAP ( AsmBCO bco, AsmNat size );
252 extern AsmSp asmBeginMkAP ( AsmBCO bco );
253 extern void asmEndMkAP ( AsmBCO bco, AsmVar v, AsmSp start );
255 extern AsmVar asmAllocPAP ( AsmBCO bco, AsmNat size );
256 extern AsmSp asmBeginMkPAP ( AsmBCO bco );
257 extern void asmEndMkPAP ( AsmBCO bco, AsmVar v, AsmSp start );
259 /* --------------------------------------------------------------------------
261 * ------------------------------------------------------------------------*/
263 extern const AsmPrim ccall_Id;
264 extern const AsmPrim ccall_IO;
278 CFunDescriptor* mkDescriptor( char* as, char* rs );
280 /*-------------------------------------------------------------------------*/