-/* -*- mode: hugs-c; -*- */
+
/* --------------------------------------------------------------------------
* Code generator
*
* Hugs version 1.4, December 1997
*
* $RCSfile: codegen.c,v $
- * $Revision: 1.2 $
- * $Date: 1998/12/02 13:21:59 $
+ * $Revision: 1.4 $
+ * $Date: 1999/03/01 14:46:42 $
* ------------------------------------------------------------------------*/
#include "prelude.h"
#include "storage.h"
+#include "backend.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"
/* --------------------------------------------------------------------------
* Local function prototypes:
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 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 pushVar( AsmBCO bco, StgVar v )
{
Cell info = stgVarInfo(v);
- assert(isStgVar(v));
+ // if (!isStgVar(v)) {
+ //printf("\n\nprefail\n");
+ //print(v,1000);
+ assert(isStgVar(v));
+ //}
if (isPtr(info)) {
asmClosure(bco,ptrOf(info));
} else if (isInt(info)) {
static AsmBCO cgAlts( AsmSp root, AsmSp sp, List alts )
{
- AsmBCO bco = asmBeginContinuation(sp);
+ AsmBCO bco = asmBeginContinuation(sp,alts);
/* ppStgAlts(alts); */
for(; nonNull(alts); alts=tl(alts)) {
StgCaseAlt alt = hd(alts);
StgPat pat = stgCaseAltPat(alt);
StgExpr body = stgCaseAltBody(alt);
if (isDefaultPat(pat)) {
- AsmSp begin = asmBeginAlt(bco);
+ //AsmSp begin = asmBeginAlt(bco);
cgBind(bco,pat);
cgExpr(bco,root,body);
asmEndContinuation(bco);
}
}
+#if 0 /* appears to be unused */
static void cgPrimAlt( AsmBCO bco, AsmSp root, List vs, StgExpr e )
{
assert(0); /* ToDo: test for patterns */
map1Proc(cgBind,bco,vs); /* ToDo: are these in right order? */
cgExpr(bco,root,e);
}
+#endif
+
static AsmBCO cgLambda( StgExpr e )
{
- AsmBCO bco = asmBeginBCO();
+ AsmBCO bco = asmBeginBCO(e);
AsmSp root = asmBeginArgCheck(bco);
map1Proc(cgBind,bco,reverse(stgLambdaArgs(e)));
static AsmBCO cgRhs( StgRhs rhs )
{
- AsmBCO bco = asmBeginBCO( );
+ AsmBCO bco = asmBeginBCO(rhs );
AsmSp root = asmBeginArgCheck(bco);
asmEndArgCheck(bco,root);
return bco;
}
+
static Void cgExpr( AsmBCO bco, AsmSp root, StgExpr e )
{
+ //printf("cgExpr:");ppStgExpr(e);printf("\n");
switch (whatIs(e)) {
case LETREC:
{
}
}
+void* itblNames[1000];
+int nItblNames = 0;
+
/* allocate space for top level variable
* any change requires a corresponding change in 'build'.
*/
pushAtom(bco,hd(args));
setPos(v,asmBox(bco,boxingConRep(con)));
} else {
- setPos(v,asmAllocCONSTR(bco,stgConInfo(con)));
+
+ void* vv = stgConInfo(con);
+ assert (nItblNames < (1000-2));
+ if (isName(con)) {
+ itblNames[nItblNames++] = vv;
+ itblNames[nItblNames++] = textToStr(name(con).text);
+ } else
+ if (isTuple(con)) {
+ char* cc = malloc(10);
+ assert(cc);
+ sprintf(cc, "Tuple%d", tupleOf(con) );
+ itblNames[nItblNames++] = vv;
+ itblNames[nItblNames++] = cc;
+ } else
+ assert ( /* cant identify constructor name */ 0 );
+
+ setPos(v,asmAllocCONSTR(bco, vv));
}
break;
}
{
StgRhs rhs = stgVarBody(v);
assert(isStgVar(v));
+
switch (whatIs(rhs)) {
case STGCON:
{
* 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)) {
assert(isStgVar(v));
asmAddPtr(obj,getObj(v));
}
+#endif
+
/* allocate AsmObject for top level variables
* any change requires a corresponding change in endTop
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());
+ setObj(v,asmBeginBCO(rhs));
break;
default:
setObj(v,asmBeginCAF());
static void endTop( StgVar v )
{
StgRhs rhs = stgVarBody(v);
- ppStgRhs(rhs);
+ //ppStgRhs(rhs);
switch (whatIs(rhs)) {
case STGCON:
{
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 (lastModule() != modulePrelude) {
+ // printf("\n\ncgBinds: before ll\n\n" );
+ // for (b=binds; nonNull(b); b=tl(b)) {
+ // printStg ( stdout, hd(b) ); printf("\n\n");
+ // }
+ //}
+
binds = liftBinds(binds);
- mapProc(beginTop,binds);
- mapProc(endTop,binds);
- mapProc(zap,binds);
+
+ //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");
+ // }
+ //}
+
+
+ //mapProc(beginTop,binds);
+ for (b=binds,i=0; nonNull(b); b=tl(b),i++) {
+ //printf("beginTop %d\n", i);
+ beginTop(hd(b));
+ }
+
+ //mapProc(endTop,binds);
+ for (b=binds,i=0; nonNull(b); b=tl(b),i++) {
+ endTop(hd(b));
+ //if (lastModule() != modulePrelude) {
+ // printStg ( stdout, hd(b) ); printf("\n\n");
+ //}
+ }
+
+ //mapProc(zap,binds);
}
/* --------------------------------------------------------------------------