-/* -*- mode: hugs-c; -*- */
+
/* -----------------------------------------------------------------------------
- * Bytecode assembler
+ * $Id: Assembler.h,v 1.16 2000/06/27 09:18:04 sewardj Exp $
*
- * Copyright (c) 1994-1998.
+ * (c) The GHC Team 1994-1998.
*
- * $RCSfile: Assembler.h,v $
- * $Revision: 1.2 $
- * $Date: 1998/12/02 13:20:52 $
+ * Bytecode assembler
*
* NB This is one of the few files shared between Hugs and the runtime system,
* so it is very important that it not conflict with either and that it not
typedef unsigned char AsmNat8;
typedef unsigned int AsmNat;
typedef signed int AsmInt;
-typedef signed long long int AsmInt64; /* ToDo: not portable! */
+typedef int64 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
/* The following can be passed to C */
CHAR_REP = 'C',
INT_REP = 'I',
-#ifdef PROVIDE_INT64
- INT64_REP = 'z',
-#endif
-#ifdef PROVIDE_INTEGER
INTEGER_REP = 'Z',
-#endif
-#ifdef PROVIDE_WORD
WORD_REP = 'W',
-#endif
-#ifdef PROVIDE_ADDR
ADDR_REP = 'A',
-#endif
FLOAT_REP = 'F',
DOUBLE_REP = 'D',
-#ifdef PROVIDE_STABLE
STABLE_REP = 's', /* StablePtr a */
-#endif
#ifdef PROVIDE_FOREIGN
FOREIGN_REP = 'f', /* ForeignObj */
#endif
#ifdef PROVIDE_WEAK
WEAK_REP = 'w', /* Weak a */
#endif
-#ifdef PROVIDE_ARRAY
BARR_REP = 'x', /* PrimByteArray a */
MUTBARR_REP = 'm', /* PrimMutableByteArray s a */
-#endif
/* The following can't be passed to C */
PTR_REP = 'P',
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 */
ERROR_REP = 'E', /* Exception */
-#ifdef PROVIDE_ARRAY
ARR_REP = 'X', /* PrimArray a */
REF_REP = 'R', /* Ref s a */
MUTARR_REP = 'M', /* PrimMutableArray s a */
-#endif
-#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 asmBeginBCO ( void );
+extern AsmBCO asmBeginBCO ( int /*StgExpr*/ e );
extern void asmEndBCO ( AsmBCO bco );
-extern AsmBCO asmBeginContinuation ( AsmSp sp );
+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 );
/* --------------------------------------------------------------------------
* Generating instruction streams
extern AsmSp asmBeginCase ( AsmBCO bco );
extern void asmEndCase ( AsmBCO bco );
extern AsmSp asmContinuation ( AsmBCO bco, AsmBCO ret_addr );
-
+
extern AsmSp asmBeginAlt ( AsmBCO bco );
extern void asmEndAlt ( AsmBCO bco, AsmSp sp );
extern AsmPc asmTest ( AsmBCO bco, AsmWord tag );
/* push unboxed Ints, Floats, etc */
extern void asmConstInt ( AsmBCO bco, AsmInt x );
-#ifdef PROVIDE_ADDR
extern void asmConstAddr ( AsmBCO bco, AsmAddr x );
-#endif
-#ifdef PROVIDE_WORD
extern void asmConstWord ( AsmBCO bco, AsmWord x );
-#endif
extern void asmConstChar ( AsmBCO bco, AsmChar x );
extern void asmConstFloat ( AsmBCO bco, AsmFloat x );
extern void asmConstDouble ( AsmBCO bco, AsmDouble x );
-#ifdef PROVIDE_INT64
-extern void asmConstInt64 ( AsmBCO bco, AsmInt64 x );
-#endif
-#ifdef PROVIDE_INTEGER
extern void asmConstInteger ( AsmBCO bco, AsmString x );
-#endif
/* Which monad (if any) does the primop live in? */
typedef enum {
AsmNat8 opcode; /* should be Primop1 or Primop2 */
} AsmPrim;
-extern const AsmPrim asmPrimOps[]; /* null terminated list */
+extern AsmPrim asmPrimOps[]; /* null terminated list */
+
+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 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 );
-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 );
/* --------------------------------------------------------------------------
* Heap manipulation
* ------------------------------------------------------------------------*/
-extern AsmVar asmClosure ( 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 AsmInt AsmIndex;
+
+/* Rows */
+extern AsmVar asmAllocRow ( AsmBCO bco, AsmNat /*number of fields*/ n );
+
+extern AsmSp asmBeginPackRow ( AsmBCO bco );
+extern void asmEndPackRow ( AsmBCO bco, AsmVar v, AsmSp start,
+ AsmNat /*number of fields*/ n );
+
+extern void asmBeginUnpackRow( AsmBCO bco );
+extern void asmEndUnpackRow ( AsmBCO bco );
+
+extern AsmPrim primRowRemoveAtN;
+extern AsmPrim primRowIndexAtN;
+
+/* Inj */
+extern AsmVar asmInj( AsmBCO bco, AsmVar var );
+extern AsmVar asmInjConst( AsmBCO bco, AsmIndex i );
+extern AsmVar asmUnInj( AsmBCO bco );
+extern AsmPc asmTestInj( AsmBCO bco, AsmVar var );
+extern AsmPc asmTestInjConst( AsmBCO, AsmIndex i );
+extern AsmVar asmConstIndex( AsmBCO bco, AsmIndex x );
+#endif
+
/* --------------------------------------------------------------------------
* C-call and H-call
* ------------------------------------------------------------------------*/
-extern const AsmPrim ccall_Id;
-extern const AsmPrim ccall_IO;
+extern AsmPrim ccall_ccall_Id;
+extern AsmPrim ccall_ccall_IO;
+extern AsmPrim ccall_stdcall_Id;
+extern AsmPrim ccall_stdcall_IO;
typedef struct {
- char * arg_tys;
- int arg_size;
- char * result_tys;
- int result_size;
+ unsigned int num_args;
+ char* arg_tys;
+ unsigned int num_results;
+ char* result_tys;
} CFunDescriptor;
-typedef struct {
- char * arg_tys;
- char * result_tys;
-} HFunDescriptor;
-
CFunDescriptor* mkDescriptor( char* as, char* rs );
/*-------------------------------------------------------------------------*/