1 /* -*- mode: hugs-c; -*- */
2 /* -----------------------------------------------------------------------------
5 * Copyright (c) 1994-1998.
7 * $RCSfile: Assembler.h,v $
9 * $Date: 1999/01/18 15:23:30 $
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 GAMMA_REP = 'c', /* c */
122 BOOL_REP = 'B', /* Bool */
123 IO_REP = 'i', /* IO a */
124 HANDLER_REP = 'H', /* Exception -> IO a */
125 ERROR_REP = 'E', /* Exception */
127 ARR_REP = 'X', /* PrimArray a */
128 REF_REP = 'R', /* Ref s a */
129 MUTARR_REP = 'M', /* PrimMutableArray s a */
131 #ifdef PROVIDE_CONCURRENT
132 THREADID_REP = 'T', /* ThreadId */
133 MVAR_REP = 'r', /* MVar a */
136 /* Allegedly used in the IO monad */
140 /* --------------------------------------------------------------------------
141 * Allocating (top level) heap objects
142 * ------------------------------------------------------------------------*/
144 extern AsmBCO asmBeginBCO ( void );
145 extern void asmEndBCO ( AsmBCO bco );
147 extern AsmBCO asmBeginContinuation ( AsmSp sp );
148 extern void asmEndContinuation ( AsmBCO bco );
150 extern AsmObject asmMkObject ( AsmClosure c );
152 extern AsmCAF asmBeginCAF ( void );
153 extern void asmEndCAF ( AsmCAF caf, AsmBCO body );
155 extern AsmInfo asmMkInfo ( AsmNat tag, AsmNat ptrs );
156 extern AsmCon asmBeginCon ( AsmInfo info );
157 extern void asmEndCon ( AsmCon con );
159 /* NB: we add ptrs to other objects in left-to-right order.
160 * This is different from pushing arguments on the stack which is done
161 * in right to left order.
163 extern void asmAddPtr ( AsmObject obj, AsmObject arg );
165 extern int asmObjectHasClosure( AsmObject obj );
166 extern AsmClosure asmClosureOfObject ( AsmObject obj );
167 extern void asmMarkObject ( AsmObject obj );
169 /* --------------------------------------------------------------------------
170 * Generating instruction streams
171 * ------------------------------------------------------------------------*/
173 extern AsmSp asmBeginArgCheck ( AsmBCO bco );
174 extern void asmEndArgCheck ( AsmBCO bco, AsmSp last_arg );
176 extern AsmSp asmBeginEnter ( AsmBCO bco );
177 extern void asmEndEnter ( AsmBCO bco, AsmSp sp1, AsmSp sp2 );
179 extern AsmVar asmBind ( AsmBCO bco, AsmRep rep );
180 extern void asmVar ( AsmBCO bco, AsmVar v, AsmRep rep );
182 extern AsmSp asmBeginCase ( AsmBCO bco );
183 extern void asmEndCase ( AsmBCO bco );
184 extern AsmSp asmContinuation ( AsmBCO bco, AsmBCO ret_addr );
186 extern AsmSp asmBeginAlt ( AsmBCO bco );
187 extern void asmEndAlt ( AsmBCO bco, AsmSp sp );
188 extern AsmPc asmTest ( AsmBCO bco, AsmWord tag );
189 extern AsmPc asmTestInt ( AsmBCO bco, AsmVar v, AsmInt x );
190 extern void asmFixBranch ( AsmBCO bco, AsmPc pc );
191 extern void asmPanic ( AsmBCO bco );
193 extern AsmVar asmBox ( AsmBCO bco, AsmRep rep );
194 extern AsmVar asmUnbox ( AsmBCO bco, AsmRep rep );
195 extern void asmReturnUnboxed ( AsmBCO bco, AsmRep rep );
197 /* push unboxed Ints, Floats, etc */
198 extern void asmConstInt ( AsmBCO bco, AsmInt x );
200 extern void asmConstAddr ( AsmBCO bco, AsmAddr x );
203 extern void asmConstWord ( AsmBCO bco, AsmWord x );
205 extern void asmConstChar ( AsmBCO bco, AsmChar x );
206 extern void asmConstFloat ( AsmBCO bco, AsmFloat x );
207 extern void asmConstDouble ( AsmBCO bco, AsmDouble x );
209 extern void asmConstInt64 ( AsmBCO bco, AsmInt64 x );
211 #ifdef PROVIDE_INTEGER
212 extern void asmConstInteger ( AsmBCO bco, AsmString x );
215 /* Which monad (if any) does the primop live in? */
217 MONAD_Id, /* no monad (aka the identity monad) */
227 AsmNat8 prefix; /* should be StgInstr */
228 AsmNat8 opcode; /* should be Primop1 or Primop2 */
231 extern const AsmPrim asmPrimOps[]; /* null terminated list */
233 extern const AsmPrim* asmFindPrim ( char* s );
234 extern const AsmPrim* asmFindPrimop ( AsmInstr prefix, AsmInstr op );
235 extern AsmSp asmBeginPrim ( AsmBCO bco );
236 extern void asmEndPrim ( AsmBCO bco, const AsmPrim* prim, AsmSp base );
238 /* --------------------------------------------------------------------------
240 * ------------------------------------------------------------------------*/
242 extern AsmVar asmClosure ( AsmBCO bco, AsmObject p );
244 extern AsmVar asmAllocCONSTR ( AsmBCO bco, AsmInfo info );
246 extern AsmSp asmBeginPack ( AsmBCO bco );
247 extern void asmEndPack ( AsmBCO bco, AsmVar v, AsmSp start, AsmInfo info );
249 extern void asmBeginUnpack ( AsmBCO bco );
250 extern void asmEndUnpack ( AsmBCO bco );
252 extern AsmVar asmAllocAP ( AsmBCO bco, AsmNat size );
253 extern AsmSp asmBeginMkAP ( AsmBCO bco );
254 extern void asmEndMkAP ( AsmBCO bco, AsmVar v, AsmSp start );
256 extern AsmVar asmAllocPAP ( AsmBCO bco, AsmNat size );
257 extern AsmSp asmBeginMkPAP ( AsmBCO bco );
258 extern void asmEndMkPAP ( AsmBCO bco, AsmVar v, AsmSp start );
260 /* --------------------------------------------------------------------------
262 * ------------------------------------------------------------------------*/
264 extern const AsmPrim ccall_Id;
265 extern const AsmPrim ccall_IO;
279 CFunDescriptor* mkDescriptor( char* as, char* rs );
281 /*-------------------------------------------------------------------------*/