X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=ghc%2Finterpreter%2Fcodegen.c;h=ef123983909bb5b2b1344456f04d7b4eaae13982;hb=066dbe7804d1e0ca710d996f43628e88e0321be6;hp=9bc719e72e7b570014d4c93173d6bb5d9513b0a3;hpb=438596897ebbe25a07e1c82085cfbc5bdb00f09e;p=ghc-hetmet.git diff --git a/ghc/interpreter/codegen.c b/ghc/interpreter/codegen.c index 9bc719e..ef12398 100644 --- a/ghc/interpreter/codegen.c +++ b/ghc/interpreter/codegen.c @@ -1,26 +1,28 @@ -/* -*- mode: hugs-c; -*- */ + /* -------------------------------------------------------------------------- * Code generator * - * Copyright (c) The University of Nottingham and Yale University, 1994-1997. - * All rights reserved. See NOTICE for details and conditions of use etc... - * Hugs version 1.4, December 1997 + * The Hugs 98 system is Copyright (c) Mark P Jones, Alastair Reid, the + * Yale Haskell Group, and the Oregon Graduate Institute of Science and + * Technology, 1994-1999, All rights reserved. It is distributed as + * free software under the license in the file "License", which is + * included in the distribution. * * $RCSfile: codegen.c,v $ - * $Revision: 1.2 $ - * $Date: 1998/12/02 13:21:59 $ + * $Revision: 1.22 $ + * $Date: 2000/04/12 09:37:19 $ * ------------------------------------------------------------------------*/ -#include "prelude.h" +#include "hugsbasictypes.h" #include "storage.h" #include "connect.h" #include "errors.h" -#include "stg.h" + #include "Assembler.h" -#include "lift.h" -#include "link.h" -#include "pp.h" -#include "codegen.h" +#include "Rts.h" /* IF_DEBUG */ +#include "RtsFlags.h" + +/*#define DEBUG_CODEGEN*/ /* -------------------------------------------------------------------------- * Local function prototypes: @@ -42,16 +44,35 @@ static Void cgExpr ( AsmBCO bco, AsmSp root, StgExpr e ); static AsmBCO cgAlts ( AsmSp root, AsmSp sp, List alts ); static void testPrimPats ( AsmBCO bco, AsmSp root, List pats, StgExpr e ); -static void cgPrimAlt ( AsmBCO bco, AsmSp root, List vs, StgExpr e ); static AsmBCO cgLambda ( StgExpr e ); static AsmBCO cgRhs ( StgRhs rhs ); static void beginTop ( StgVar v ); static void endTop ( StgVar v ); +static StgVar currentTop; + /* -------------------------------------------------------------------------- * * ------------------------------------------------------------------------*/ +static Cell cptrFromName ( Name n ) +{ + char buf[1000]; + void* p; + Module m = name(n).mod; + Text mt = module(m).text; + sprintf(buf, MAYBE_LEADING_UNDERSCORE_STR("%s_%s_closure"), + textToStr(mt), + textToStr( enZcodeThenFindText ( + textToStr (name(n).text) ) ) ); + p = lookupOTabName ( m, buf ); + if (!p) { + ERRMSG(0) "Can't find object symbol %s", buf + EEND; + } + return mkCPtr(p); +} + static Bool varHasClosure( StgVar v ) { return asmObjectHasClosure((AsmClosure*)ptrOf(stgVarInfo(v))); @@ -67,31 +88,20 @@ char* lookupHugsName( void* closure ) { extern Name nameHw; Name nm; - for( nm=NAMEMIN; nm length(args); +# if DEBUG_CODEGEN + fprintf ( stderr, "nativeCall: name %s, arity %d, args %d\n", + nameFromOPtr(cptrOf(fun)), name(fun0).arity, + length(args) ); +# endif + } else { + itsaPAP = FALSE; + if (nonNull(stgVarBody(fun)) + && whatIs(stgVarBody(fun)) == LAMBDA + && length(stgLambdaArgs(stgVarBody(fun))) > length(args) + ) + itsaPAP = TRUE; } - if (nonNull(stgVarBody(fun)) - && whatIs(stgVarBody(fun)) == LAMBDA - && length(stgLambdaArgs(stgVarBody(fun))) > length(args)) { + + if (itsaPAP) { AsmSp start = asmBeginMkPAP(bco); map1Proc(pushAtom,bco,reverse(args)); pushAtom(bco,fun); @@ -475,7 +561,10 @@ static Void build( AsmBCO bco, StgVar v ) * of this except "let x = x in ..." */ case NAME: - rhs = name(rhs).stgVar; + if (nonNull(name(rhs).stgVar)) + rhs = name(rhs).stgVar; else + rhs = cptrFromName(rhs); + /* fall thru */ case STGVAR: { AsmSp start = asmBeginMkAP(bco); @@ -500,6 +589,7 @@ static Void build( AsmBCO bco, StgVar v ) * for each top level variable - this should be simpler! * ------------------------------------------------------------------------*/ +#if 0 /* appears to be unused */ static void cgAddVar( AsmObject obj, StgAtom v ) { if (isName(v)) { @@ -508,6 +598,8 @@ static void cgAddVar( AsmObject obj, StgAtom v ) assert(isStgVar(v)); asmAddPtr(obj,getObj(v)); } +#endif + /* allocate AsmObject for top level variables * any change requires a corresponding change in endTop @@ -516,16 +608,21 @@ static void beginTop( StgVar v ) { StgRhs rhs; assert(isStgVar(v)); + currentTop = v; rhs = stgVarBody(v); switch (whatIs(rhs)) { case STGCON: { - List as = stgConArgs(rhs); + //List as = stgConArgs(rhs); setObj(v,asmBeginCon(stgConInfo(stgConCon(rhs)))); break; } case LAMBDA: - setObj(v,asmBeginBCO()); +#ifdef CRUDE_PROFILING + setObj(v,asmBeginBCO(currentTop)); +#else + setObj(v,asmBeginBCO(rhs)); +#endif break; default: setObj(v,asmBeginCAF()); @@ -536,7 +633,7 @@ static void beginTop( StgVar v ) static void endTop( StgVar v ) { StgRhs rhs = stgVarBody(v); - ppStgRhs(rhs); + currentTop = v; switch (whatIs(rhs)) { case STGCON: { @@ -594,16 +691,64 @@ static void endTop( StgVar v ) static void zap( StgVar v ) { - stgVarBody(v) = NIL; + // ToDo: reinstate + // stgVarBody(v) = NIL; } /* external entry point */ Void cgBinds( List binds ) { + List b; + int i; + +#if 0 + if (lastModule() != modulePrelude) { + printf("\n\ncgBinds: before ll\n\n" ); + for (b=binds; nonNull(b); b=tl(b)) { + printStg ( stdout, hd(b) ); printf("\n\n"); + } + } +#endif + binds = liftBinds(binds); - mapProc(beginTop,binds); - mapProc(endTop,binds); - mapProc(zap,binds); + +#if 0 + if (lastModule() != modulePrelude) { + printf("\n\ncgBinds: after ll\n\n" ); + for (b=binds; nonNull(b); b=tl(b)) { + printStg ( stdout, hd(b) ); printf("\n\n"); + } + } +#endif + + for (b=binds,i=0; nonNull(b); b=tl(b),i++) { + /* printStg( stdout, hd(b) ); printf( "\n\n"); */ + beginTop(hd(b)); + } + + for (b=binds,i=0; nonNull(b); b=tl(b),i++) { + /* printStg( stdout, hd(b) ); printf( "\n\n"); */ + endTop(hd(b)); + } + + /* mapProc(zap,binds); */ +} + +/* Called by the evaluator's GC to tell Hugs to mark stuff in the + run-time heap. +*/ +void markHugsObjects( void ) +{ + extern Name nameHw; + Name nm; + for ( nm = NAME_BASE_ADDR; + nm < NAME_BASE_ADDR+tabNameSz; ++nm ) + if (tabName[nm-NAME_BASE_ADDR].inUse) { + StgVar v = name(nm).stgVar; + if (isStgVar(v) && isPtr(stgVarInfo(v))) { + asmMarkObject(ptrOf(stgVarInfo(v))); + } + } } /* -------------------------------------------------------------------------- @@ -613,12 +758,11 @@ Void cgBinds( List binds ) Void codegen(what) Int what; { switch (what) { - case INSTALL: - /* deliberate fall though */ - case RESET: - break; - case MARK: - break; + case PREPREL: + case RESET: + case MARK: + case POSTPREL: + break; } liftControl(what); }