X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fincludes%2FAssembler.h;h=22244f6257b4a7880136eabc77b00fd98c5d9f56;hb=ec459c238894ee4e2f7d1a30875a4d5446131c5d;hp=d0c19980241a0f1fb07aff755dc4f56f7c017671;hpb=dfb12323d9fd0c8fb717b8e548592f20163b4ed0;p=ghc-hetmet.git diff --git a/ghc/includes/Assembler.h b/ghc/includes/Assembler.h index d0c1998..22244f6 100644 --- a/ghc/includes/Assembler.h +++ b/ghc/includes/Assembler.h @@ -1,6 +1,6 @@ /* ----------------------------------------------------------------------------- - * $Id: Assembler.h,v 1.8 1999/10/15 11:02:06 sewardj Exp $ + * $Id: Assembler.h,v 1.16 2000/06/27 09:18:04 sewardj Exp $ * * (c) The GHC Team 1994-1998. * @@ -29,7 +29,7 @@ extern void DEBUG_LoadSymbols( char *name ); 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; @@ -37,33 +37,81 @@ typedef float AsmFloat; /* ToDo: not on Alphas! */ 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 @@ -104,6 +152,7 @@ typedef enum { 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 */ @@ -111,16 +160,25 @@ typedef enum { 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 * ------------------------------------------------------------------------*/ @@ -130,10 +188,8 @@ extern void asmEndBCO ( AsmBCO bco ); 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 ); @@ -144,11 +200,6 @@ extern void asmEndCon ( AsmCon con ); * 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 ); /* -------------------------------------------------------------------------- @@ -204,29 +255,38 @@ typedef struct { 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 ); @@ -239,25 +299,50 @@ extern AsmVar asmAllocPAP ( AsmBCO bco, AsmNat size ); 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 ); /*-------------------------------------------------------------------------*/