/* -----------------------------------------------------------------------------
- * $Id: Assembler.h,v 1.10 1999/10/26 17:27:35 sewardj Exp $
+ * $Id: Assembler.h,v 1.18 2000/10/09 11:21:41 daan Exp $
*
* (c) The GHC Team 1994-1998.
*
typedef unsigned char AsmNat8;
typedef unsigned int AsmNat;
typedef signed int AsmInt;
-typedef signed long long int AsmInt64; /* ToDo: not portable! */
+typedef HsInt64_ AsmInt64;
typedef unsigned int AsmWord;
typedef void* AsmAddr;
typedef unsigned char AsmChar;
typedef double AsmDouble;
typedef char* AsmString;
+typedef int AsmSp; /* stack offset */
+typedef int AsmPc; /* program counter */
+typedef AsmSp AsmVar; /* offset of a Var on the stack */
+
/* I want to #include this file into the file that defines the
* functions but I don't want to expose the structures that
* these types point to.
* This hack is the best I could think of. Surely there's a better way?
*/
#ifdef INSIDE_ASSEMBLER_C
-typedef struct AsmObject_ *AsmObject;
-typedef struct AsmBCO_ *AsmBCO;
-typedef struct AsmCAF_ *AsmCAF;
-typedef struct AsmCon_ *AsmCon;
-typedef StgInfoTable *AsmInfo;
-typedef StgClosure *AsmClosure;
-typedef Instr AsmInstr;
+/* these types are defined in Assembler.c */
+typedef
+ enum {
+ Asm_RefNoOp, /* Pointer which needs no further messing with */
+ Asm_RefObject, /* Reference to malloc'd AsmCAF/AsmBCO/AsmCon */
+ Asm_RefHugs, /* Reference to Hugs name or tycon table */
+
+ Asm_NonPtrWord, /* A non-pointer word */
+ Asm_Insn8, /* One BCO insn byte */
+ }
+ Asm_Kind;
+
+typedef
+ struct {
+ Asm_Kind kind;
+ StgWord val; /* StgWord is allegedly big enough to also hold
+ a pointer, on all platforms */
+ }
+ Asm_Entity;
+
+
+ struct AsmObject_ {
+ unsigned int magic;
+ struct AsmObject_* next;
+ enum { Asm_BCO, Asm_CAF, Asm_Con } kind;
+ int sizeEntities;
+ int usedEntities;
+ Asm_Entity* entities;
+ StgClosure* closure;
+
+ int n_refs; /* number of ptr words */
+ int n_words; /* number of words */
+ int n_insns; /* number of insn BYTES */
+
+ /* AsmCon specifics */
+ StgInfoTable* itbl;
+
+ /* AsmBCO specifics */
+ int /*StgExpr*/ stgexpr; /* stg tree for debugging */
+ AsmSp sp; /* simulated sp */
+ AsmSp max_sp; /* high-tide of sp */
+ Instr lastOpc; /* last opcode, for peephole opt */
+ };
+ /* AsmObject_ is only mentioned in Assembler.c; clients use
+ AsmObject/AsmBCO/AsmCAF/AsmCon.
+ */
+
+typedef StgInfoTable* AsmInfo;
+typedef struct AsmObject_* AsmBCO;
+typedef struct AsmObject_* AsmCAF;
+typedef struct AsmObject_* AsmCon;
+typedef struct AsmObject_* AsmObject;
+typedef Instr AsmInstr;
#else
/* the types we export are totally opaque */
-typedef void *AsmObject;
-typedef void *AsmBCO;
-typedef void *AsmCAF;
-typedef void *AsmCon;
-typedef void *AsmInfo;
-typedef void *AsmClosure;
-typedef unsigned int AsmInstr;
+typedef void* AsmObject;
+typedef void* AsmBCO;
+typedef void* AsmCAF;
+typedef void* AsmCon;
+typedef void* AsmInfo;
+typedef void* AsmClosure;
+typedef unsigned int AsmInstr;
#endif
-typedef int AsmSp; /* stack offset */
-typedef int AsmPc; /* program counter */
-typedef AsmSp AsmVar; /* offset of a Var on the stack */
+
/* --------------------------------------------------------------------------
* "Types" used within the assembler
ALPHA_REP = 'a', /* a */
BETA_REP = 'b', /* b */
GAMMA_REP = 'c', /* c */
+ DELTA_REP = 'd', /* d */
BOOL_REP = 'B', /* Bool */
IO_REP = 'i', /* IO a */
HANDLER_REP = 'H', /* Exception -> IO a */
ARR_REP = 'X', /* PrimArray a */
REF_REP = 'R', /* Ref s a */
MUTARR_REP = 'M', /* PrimMutableArray s a */
-#ifdef PROVIDE_CONCURRENT
THREADID_REP = 'T', /* ThreadId */
MVAR_REP = 'r', /* MVar a */
-#endif
/* Allegedly used in the IO monad */
VOID_REP = 'v'
} AsmRep;
/* --------------------------------------------------------------------------
+ * Top-level control of the BCO generation + linking mechanism
+ * ------------------------------------------------------------------------*/
+
+extern void asmInitialise ( void );
+extern void asmAllocateHeapSpace ( void );
+extern void asmCopyAndLink ( void );
+extern void asmShutdown ( void );
+
+extern void* /* StgClosure* */ asmGetClosureOfObject ( AsmObject );
+
+/* --------------------------------------------------------------------------
* Allocating (top level) heap objects
* ------------------------------------------------------------------------*/
extern AsmBCO asmBeginContinuation ( AsmSp sp, int /*List*/ alts );
extern void asmEndContinuation ( AsmBCO bco );
-extern AsmObject asmMkObject ( AsmClosure c );
-
extern AsmCAF asmBeginCAF ( void );
-extern void asmEndCAF ( AsmCAF caf, AsmBCO body );
+extern void asmEndCAF ( AsmCAF caf );
extern AsmInfo asmMkInfo ( AsmNat tag, AsmNat ptrs );
extern AsmCon asmBeginCon ( AsmInfo info );
* in right to left order.
*/
extern void asmAddPtr ( AsmObject obj, AsmObject arg );
-
-extern int asmObjectHasClosure( AsmObject obj );
-extern AsmClosure asmClosureOfObject ( AsmObject obj );
-extern void asmMarkObject ( AsmObject obj );
-
extern int asmRepSizeW ( AsmRep rep );
/* --------------------------------------------------------------------------
AsmNat8 opcode; /* should be Primop1 or Primop2 */
} AsmPrim;
-extern const AsmPrim asmPrimOps[]; /* null terminated list */
+extern AsmPrim asmPrimOps[]; /* null terminated list */
-extern const AsmPrim* asmFindPrim ( char* s );
-extern const AsmPrim* asmFindPrimop ( AsmInstr prefix, AsmInstr op );
-extern AsmSp asmBeginPrim ( AsmBCO bco );
-extern void asmEndPrim ( AsmBCO bco, const AsmPrim* prim, AsmSp base );
+extern AsmPrim* asmFindPrim ( char* s );
+extern AsmPrim* asmFindPrimop ( AsmInstr prefix, AsmInstr op );
+extern AsmSp asmBeginPrim ( AsmBCO bco );
+extern void asmEndPrim ( AsmBCO bco, const AsmPrim* prim,
+ AsmSp base );
+extern char* asmGetPrimopName ( AsmPrim* p );
-extern AsmBCO asm_BCO_catch ( void );
-extern AsmBCO asm_BCO_raise ( void );
-extern AsmBCO asm_BCO_seq ( void );
+extern void* /* StgBCO* */ asm_BCO_catch ( void );
+extern void* /* StgBCO* */ asm_BCO_raise ( void );
+extern void* /* StgBCO* */ asm_BCO_seq ( void );
+extern void* /* StgBCO* */ asm_BCO_takeMVar ( void );
/* --------------------------------------------------------------------------
* Heap manipulation
* ------------------------------------------------------------------------*/
-extern AsmVar asmClosure ( AsmBCO bco, AsmObject p );
-extern AsmVar asmGHCClosure ( AsmBCO bco, AsmObject p );
+extern AsmVar asmPushRefHugs ( AsmBCO bco, int /*Name*/ n );
+extern AsmVar asmPushRefObject ( AsmBCO bco, AsmObject p );
+extern AsmVar asmPushRefNoOp ( AsmBCO bco, StgPtr p );
+
+extern void asmAddRefObject ( AsmObject obj, AsmObject p );
+extern void asmAddRefNoOp ( AsmObject obj, StgPtr p );
+extern void asmAddRefHugs ( AsmObject obj,int /*Name*/ n );
extern AsmVar asmAllocCONSTR ( AsmBCO bco, AsmInfo info );
extern AsmSp asmBeginPack ( AsmBCO bco );
-extern void asmEndPack ( AsmBCO bco, AsmVar v, AsmSp start, AsmInfo info );
+extern void asmEndPack ( AsmBCO bco, AsmVar v, AsmSp start,
+ AsmInfo info );
extern void asmBeginUnpack ( AsmBCO bco );
extern void asmEndUnpack ( AsmBCO bco );
extern AsmSp asmBeginMkPAP ( AsmBCO bco );
extern void asmEndMkPAP ( AsmBCO bco, AsmVar v, AsmSp start );
+#ifdef XMLAMBDA
+/*------------------------------------------------------------------------
+ XMlambda primitives.
+------------------------------------------------------------------------*/
+typedef AsmWord AsmWitness;
+#define WITNESS_REP WORD_REP
+
+/* insert/remove primitives on rows */
+extern void asmEndPrimRowChainInsert( AsmBCO bco, AsmSp base, AsmWord n /* number of args */ );
+extern void asmEndPrimRowChainBuild ( AsmBCO bco, AsmSp base, AsmWord n /* number of args */ );
+extern void asmEndPrimRowChainRemove( AsmBCO bco, AsmSp base, AsmWord n /* number of args */ );
+extern void asmEndPrimRowChainSelect( AsmBCO bco, AsmSp base, AsmWord n /* number of args */ );
+
+/* pack/unpack instructions for rows */
+extern AsmVar asmAllocRow ( AsmBCO bco, AsmWord /*number of fields*/ n );
+extern AsmSp asmBeginPackRow ( AsmBCO bco );
+extern void asmEndPackRow ( AsmBCO bco, AsmVar v, AsmSp start,
+ AsmWord /*number of fields*/ n );
+
+extern void asmBeginUnpackRow( AsmBCO bco );
+extern void asmEndUnpackRow ( AsmBCO bco );
+
+extern void asmConstRowTriv ( AsmBCO bco );
+
+/* Inj primitives */
+extern AsmVar asmInjRel( AsmBCO bco, AsmVar var, AsmWitness w );
+extern AsmVar asmInjConst( AsmBCO bco, AsmWitness w );
+
+extern AsmPc asmTestInjRel( AsmBCO bco, AsmVar var, AsmWitness w );
+extern AsmPc asmTestInjConst( AsmBCO, AsmWitness w );
+
+extern void asmWitnessRel( AsmBCO bco, AsmVar var, AsmWitness w );
+extern void asmWitnessConst( AsmBCO bco, AsmWitness w );
+
+extern AsmVar asmUnInj( AsmBCO bco );
+
+#endif
+
/* --------------------------------------------------------------------------
* C-call and H-call
* ------------------------------------------------------------------------*/
-extern const AsmPrim ccall_ccall_Id;
-extern const AsmPrim ccall_ccall_IO;
-extern const AsmPrim ccall_stdcall_Id;
-extern const AsmPrim ccall_stdcall_IO;
+extern AsmPrim ccall_ccall_Id;
+extern AsmPrim ccall_ccall_IO;
+extern AsmPrim ccall_stdcall_Id;
+extern AsmPrim ccall_stdcall_IO;
typedef struct {
unsigned int num_args;
CFunDescriptor* mkDescriptor( char* as, char* rs );
+#ifdef XMLAMBDA
+
+typedef enum _CallType
+{ CCall = 'c' /* C calling convention */
+, StdCall = 's' /* Standard calling convention */
+} CallType;
+
+/* The asmEndPrimCall*** functions call external functions.
+ Just start with "asmBeginPrim", push the arguments
+ and end with one of these functions. The argument and
+ result types are given as an argument string containing
+ the character representation of AsmRep's. */
+
+/* asmEndPrimCallDynamic calls a function defined in a dynamic link library.
+ If decorate is true, the funName will be decorated according to its
+ calling convention, for example, with CCall an underscore is prefixed */
+extern void asmEndPrimCallDynamic( AsmBCO bco
+ , AsmSp base
+ , const char* libName
+ , const char* funName
+ , const char* argTypes
+ , const char* resultTypes
+ , CallType callType
+ , int /*bool*/ decorate);
+
+/* asmEndPrimCallIndirect calls the function given by its first
+ argument. (ie. push the address just before calling) */
+extern void asmEndPrimCallIndirect( AsmBCO bco
+ , AsmSp base
+ , const char* argTypes
+ , const char* resultTypes
+ , CallType callType );
+
+
+#endif
+
/*-------------------------------------------------------------------------*/