summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler.h1
-rw-r--r--src/pdabuild.cc29
-rw-r--r--src/pdacodegen.cc20
-rw-r--r--src/pdarun.h2
-rw-r--r--src/program.c4
5 files changed, 56 insertions, 0 deletions
diff --git a/src/compiler.h b/src/compiler.h
index 7123c3db..b9ab5bba 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -809,6 +809,7 @@ struct Compiler
void generateExportsImpl();
LocalInfo *makeLocalInfo( Locals &locals );
+ short *makeTrees( ObjectDef *objectDef, int &numTrees );
/*
* Graphviz Generation
diff --git a/src/pdabuild.cc b/src/pdabuild.cc
index 67bdd262..1b5f52c4 100644
--- a/src/pdabuild.cc
+++ b/src/pdabuild.cc
@@ -1278,6 +1278,32 @@ LocalInfo *Compiler::makeLocalInfo( Locals &locals )
return localInfo;
}
+short *Compiler::makeTrees( ObjectDef *objectDef, int &numTrees )
+{
+ numTrees = 0;
+ for ( FieldList::Iter of = *objectDef->fieldList; of.lte(); of++ ) {
+ UniqueType *ut = of->value->typeRef->resolveType( this );
+ if ( ut->typeId == TYPE_TREE || ut->typeId == TYPE_PTR )
+ numTrees += 1;
+ }
+
+ short *trees = new short[numTrees];
+ memset( trees, 0, sizeof(short) * numTrees );
+
+ short pos = 0, fieldPos = 0;;
+ for ( FieldList::Iter of = *objectDef->fieldList; of.lte(); of++ ) {
+ UniqueType *ut = of->value->typeRef->resolveType( this );
+ if ( ut->typeId == TYPE_TREE || ut->typeId == TYPE_PTR ) {
+ trees[pos] = fieldPos;
+ pos += 1;
+ }
+ fieldPos += 1;
+ }
+
+ return trees;
+}
+
+
void Compiler::makeRuntimeData()
{
long count = 0;
@@ -1462,7 +1488,10 @@ void Compiler::makeRuntimeData()
memset( runtimeData->selInfo, 0, sizeof(StructElInfo)*count );
StructElList::Iter sel = structEls;
for ( int i = 0; i < count; i++, sel++ ) {
+ int treesLen;
runtimeData->selInfo[i].size = sel->context->objectDef->size();
+ runtimeData->selInfo[i].trees = makeTrees( sel->context->objectDef, treesLen );
+ runtimeData->selInfo[i].treesLen = treesLen;
}
/*
diff --git a/src/pdacodegen.cc b/src/pdacodegen.cc
index 96b1df1a..21518079 100644
--- a/src/pdacodegen.cc
+++ b/src/pdacodegen.cc
@@ -197,6 +197,18 @@ void PdaCodeGen::writeRuntimeData( RuntimeData *runtimeData, PdaTables *pdaTable
}
out << "\n};\n\n";
+
+ for ( int i = 0; i < runtimeData->numStructEls; i++ ) {
+ if ( runtimeData->selInfo[i].treesLen > 0 ) {
+ out << "static short struct_trees_" << i << "[] = {\n\t";
+
+ short *ti = runtimeData->selInfo[i].trees;
+ for ( int j = 0; j < runtimeData->selInfo[i].treesLen; j++ )
+ out << ti[j] << ", ";
+ out << "\n};\n\n";
+ }
+ }
+
/*
* selInfo
*/
@@ -204,6 +216,14 @@ void PdaCodeGen::writeRuntimeData( RuntimeData *runtimeData, PdaTables *pdaTable
for ( int i = 0; i < runtimeData->numStructEls; i++ ) {
out << "\t{ ";
out << runtimeData->selInfo[i].size << ", ";
+
+ /* trees. */
+ if ( runtimeData->selInfo[i].treesLen > 0 )
+ out << "struct_trees_" << i << ", ";
+ else
+ out << "0, ";
+ out << runtimeData->selInfo[i].treesLen << ", ";
+
out << " }";
}
out << "\n};\n\n";
diff --git a/src/pdarun.h b/src/pdarun.h
index 7f7aa39b..9a517a4b 100644
--- a/src/pdarun.h
+++ b/src/pdarun.h
@@ -167,6 +167,8 @@ typedef struct _LangElInfo
typedef struct _StructElInfo
{
long size;
+ short *trees;
+ long treesLen;
} StructElInfo;
typedef struct _ObjFieldInfo
diff --git a/src/program.c b/src/program.c
index 7b8cbd72..b331c484 100644
--- a/src/program.c
+++ b/src/program.c
@@ -300,6 +300,10 @@ static void colm_clear_heap2( Program *prg, Tree **sp )
HeapItem *hi = prg->heapHead;
while ( hi != 0 ) {
HeapItem *next = hi->next;
+ short *t = prg->rtd->selInfo[hi->id].trees;
+ int i, len = prg->rtd->selInfo[hi->id].treesLen;
+ for ( i = 0; i < len; i++ )
+ treeDownref( prg, sp, ((Tree**)(hi+1))[t[i]] );
free( hi );
hi = next;
}