diff options
author | Adrian Thurston <thurston@complang.org> | 2008-11-05 23:39:27 +0000 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2008-11-05 23:39:27 +0000 |
commit | ac5de86f48a71ae57fcab8c66942f40e886b9d34 (patch) | |
tree | 4d95e83be0a76daa8fd3e568959b8ee6a277d478 | |
parent | e88b5fa8de227c1c9d95fcc1d9e60f4f91390fb3 (diff) | |
download | colm-ac5de86f48a71ae57fcab8c66942f40e886b9d34.tar.gz |
more work on the specialization of frame code into codeWV and codeWC
-rw-r--r-- | colm/bytecode.cpp | 4 | ||||
-rw-r--r-- | colm/compile.cpp | 93 | ||||
-rw-r--r-- | colm/fsmrun.cpp | 4 | ||||
-rw-r--r-- | colm/parsetree.h | 2 | ||||
-rw-r--r-- | colm/pdabuild.cpp | 27 | ||||
-rw-r--r-- | colm/pdacodegen.cpp | 21 | ||||
-rw-r--r-- | colm/pdarun.cpp | 2 | ||||
-rw-r--r-- | colm/pdarun.h | 4 |
8 files changed, 84 insertions, 73 deletions
diff --git a/colm/bytecode.cpp b/colm/bytecode.cpp index 17c9390e..b5582b67 100644 --- a/colm/bytecode.cpp +++ b/colm/bytecode.cpp @@ -2593,7 +2593,7 @@ again: push( (SW)instr ); push( (SW)frame ); - instr = prg->rtd->frameInfo[fi->frameId].code; + instr = prg->rtd->frameInfo[fi->frameId].codeWV; frame = ptop(); break; } @@ -2675,7 +2675,7 @@ again: /* Now set up the first yeild. */ uiter->ref.kid = 0; uiter->stackSize = uiter->stackRoot - ptop(); - uiter->resume = prg->rtd->frameInfo[fi->frameId].code; + uiter->resume = prg->rtd->frameInfo[fi->frameId].codeWV; uiter->frame = &uiter->stackRoot[-IFR_AA]; upref_uiter_args( frame, fi->argSize ); diff --git a/colm/compile.cpp b/colm/compile.cpp index ed2c6803..beab23ac 100644 --- a/colm/compile.cpp +++ b/colm/compile.cpp @@ -1942,26 +1942,28 @@ void ParseData::compileReductionCode( Definition *prod ) revertOn = true; block->frameId = nextFrameId++; + CodeVect &code = block->codeWV; + /* Add the alloc frame opcode. We don't have the right * frame size yet. We will fill it in later. */ - block->code.append( IN_INIT_LOCALS ); - block->code.appendHalf( 0 ); - long afterAllocFrame = block->code.length(); + code.append( IN_INIT_LOCALS ); + code.appendHalf( 0 ); + long afterAllocFrame = code.length(); /* Compile the reduce block. */ - block->compile( this, block->code ); + block->compile( this, code ); /* We have the frame size now. Set in the alloc frame instruction. */ long frameSize = curLocalFrame->size(); - block->code.setHalf( 1, frameSize ); + code.setHalf( 1, frameSize ); - addProdRHSLoads( prod, afterAllocFrame, block->code ); + addProdRHSLoads( prod, afterAllocFrame, code ); - block->code.append( IN_POP_LOCALS ); - block->code.appendHalf( block->frameId ); - block->code.appendHalf( frameSize ); + code.append( IN_POP_LOCALS ); + code.appendHalf( block->frameId ); + code.appendHalf( frameSize ); - block->code.append( IN_STOP ); + code.append( IN_STOP ); /* Now that compilation is done variables are referenced. Make the local * trees descriptor. */ @@ -1991,23 +1993,25 @@ void ParseData::compileTranslateBlock( KlangEl *langEl ) initFunction( uniqueTypeInt, curLocalFrame, "send_ignore", IN_IGNORE, IN_IGNORE, uniqueTypeAny, true ); + CodeVect &code = block->codeWV; + /* Add the alloc frame opcode. We don't have the right * frame size yet. We will fill it in later. */ - block->code.append( IN_INIT_LOCALS ); - block->code.appendHalf( 0 ); + code.append( IN_INIT_LOCALS ); + code.appendHalf( 0 ); /* Set the local frame and compile the reduce block. */ - block->compile( this, block->code ); + block->compile( this, code ); /* We have the frame size now. Set in the alloc frame instruction. */ long frameSize = curLocalFrame->size(); - block->code.setHalf( 1, frameSize ); + code.setHalf( 1, frameSize ); - block->code.append( IN_POP_LOCALS ); - block->code.appendHalf( block->frameId ); - block->code.appendHalf( frameSize ); + code.append( IN_POP_LOCALS ); + code.appendHalf( block->frameId ); + code.appendHalf( frameSize ); - block->code.append( IN_STOP ); + code.append( IN_STOP ); /* Now that compilation is done variables are referenced. Make the local * trees descriptor. */ @@ -2035,23 +2039,25 @@ void ParseData::compilePreEof( TokenRegion *region ) initFunction( uniqueTypeInt, curLocalFrame, "send_ignore", IN_IGNORE, IN_IGNORE, uniqueTypeAny, true ); + CodeVect &code = block->codeWV; + /* Add the alloc frame opcode. We don't have the right * frame size yet. We will fill it in later. */ - block->code.append( IN_INIT_LOCALS ); - block->code.appendHalf( 0 ); + code.append( IN_INIT_LOCALS ); + code.appendHalf( 0 ); /* Set the local frame and compile the reduce block. */ - block->compile( this, block->code ); + block->compile( this, code ); /* We have the frame size now. Set in the alloc frame instruction. */ long frameSize = curLocalFrame->size(); - block->code.setHalf( 1, frameSize ); + code.setHalf( 1, frameSize ); - block->code.append( IN_POP_LOCALS ); - block->code.appendHalf( block->frameId ); - block->code.appendHalf( frameSize ); + code.append( IN_POP_LOCALS ); + code.appendHalf( block->frameId ); + code.appendHalf( frameSize ); - block->code.append( IN_STOP ); + code.append( IN_STOP ); /* Now that compilation is done variables are referenced. Make the local * trees descriptor. */ @@ -2073,22 +2079,25 @@ void ParseData::compileRootBlock( ) /* The block needs a frame id. */ block->frameId = nextFrameId++; + /* The root block is not reverted. */ + CodeVect &code = block->codeWC; + /* Add the alloc frame opcode. We don't have the right * frame size yet. We will fill it in later. */ - block->code.append( IN_INIT_LOCALS ); - block->code.appendHalf( 0 ); + code.append( IN_INIT_LOCALS ); + code.appendHalf( 0 ); - block->compile( this, block->code ); + block->compile( this, code ); /* We have the frame size now. Store it in frame init. */ long frameSize = curLocalFrame->size(); - block->code.setHalf( 1, frameSize ); + code.setHalf( 1, frameSize ); - block->code.append( IN_POP_LOCALS ); - block->code.appendHalf( block->frameId ); - block->code.appendHalf( frameSize ); + code.append( IN_POP_LOCALS ); + code.appendHalf( block->frameId ); + code.appendHalf( frameSize ); - block->code.append( IN_STOP ); + code.append( IN_STOP ); /* Make the local trees descriptor. */ findLocalTrees( block->trees ); @@ -2291,25 +2300,27 @@ void ParseData::compileUserIter( Function *func ) makeFuncVisible( func, true ); + CodeVect &code = block->codeWV; + /* Add the alloc frame opcode. We don't have the right * frame size yet. We will fill it in later. */ - block->code.append( IN_INIT_LOCALS ); - block->code.appendHalf( 0 ); + code.append( IN_INIT_LOCALS ); + code.appendHalf( 0 ); /* Compile the block. */ - block->compile( this, block->code ); + block->compile( this, code ); /* We have the frame size now. Set in the alloc frame instruction. */ int frameSize = func->localFrame->size(); - block->code.setHalf( 1, frameSize ); + code.setHalf( 1, frameSize ); /* Check for a return statement. */ if ( block->stmtList->length() == 0 || block->stmtList->tail->type != LangStmt::YieldType ) { /* Push the return value. */ - block->code.append( IN_LOAD_NIL ); - block->code.append( IN_YIELD ); + code.append( IN_LOAD_NIL ); + code.append( IN_YIELD ); } /* Now that compilation is done variables are referenced. Make the local @@ -2375,7 +2386,7 @@ void ParseData::compileFunction( Function *func ) /* Compile once for revert. */ revertOn = true; - compileFunction( func, block->code ); + compileFunction( func, block->codeWV ); /* Compile once for commit. */ revertOn = false; diff --git a/colm/fsmrun.cpp b/colm/fsmrun.cpp index 6e89e888..993936f6 100644 --- a/colm/fsmrun.cpp +++ b/colm/fsmrun.cpp @@ -359,7 +359,7 @@ void FsmRun::sendEOF( ) cerr << "HAVE PRE_EOF BLOCK" << endl; #endif - Code *code = parser->tables->gbl->frameInfo[frameId].code; + Code *code = parser->tables->gbl->frameInfo[frameId].codeWV; /* Execute the translation. */ Execution execution( prg, parser->reverseCode, @@ -486,7 +486,7 @@ void FsmRun::generationAction( int id, Head *tokdata, bool namedLangEl, int bind /* Find the code. */ Code *code = parser->tables->gbl->frameInfo[ - parser->tables->gbl->lelInfo[id].frameId].code; + parser->tables->gbl->lelInfo[id].frameId].codeWV; /* Execute the translation. */ Execution execution( prg, parser->reverseCode, diff --git a/colm/parsetree.h b/colm/parsetree.h index 9d49d314..72beac98 100644 --- a/colm/parsetree.h +++ b/colm/parsetree.h @@ -1570,7 +1570,7 @@ struct CodeBlock /* Each frame has two versions of * the code: revert and commit. */ - CodeVect code, codeWC; + CodeVect codeWV, codeWC; }; struct Function diff --git a/colm/pdabuild.cpp b/colm/pdabuild.cpp index 538ed313..c81fb8e4 100644 --- a/colm/pdabuild.cpp +++ b/colm/pdabuild.cpp @@ -1167,12 +1167,12 @@ void ParseData::makeRuntimeData() runtimeData->rootCodeLen = 0; } else { - runtimeData->rootCode = rootCodeBlock->code.data; - runtimeData->rootCodeLen = rootCodeBlock->code.length(); + runtimeData->rootCode = rootCodeBlock->codeWC.data; + runtimeData->rootCodeLen = rootCodeBlock->codeWC.length(); } - runtimeData->frameInfo[rootCodeBlock->frameId].code = 0; - runtimeData->frameInfo[rootCodeBlock->frameId].codeLen = 0; + runtimeData->frameInfo[rootCodeBlock->frameId].codeWV = 0; + runtimeData->frameInfo[rootCodeBlock->frameId].codeLenWV = 0; runtimeData->frameInfo[rootCodeBlock->frameId].trees = rootCodeBlock->trees.data; runtimeData->frameInfo[rootCodeBlock->frameId].treesLen = rootCodeBlock->trees.length(); @@ -1193,8 +1193,9 @@ void ParseData::makeRuntimeData() CodeBlock *block = prod->redBlock; if ( block != 0 ) { runtimeData->prodInfo[count].frameId = block->frameId; - runtimeData->frameInfo[block->frameId].code = block->code.data; - runtimeData->frameInfo[block->frameId].codeLen = block->code.length(); + runtimeData->frameInfo[block->frameId].codeWV = block->codeWV.data; + runtimeData->frameInfo[block->frameId].codeLenWV = block->codeWV.length(); + runtimeData->frameInfo[block->frameId].trees = block->trees.data; runtimeData->frameInfo[block->frameId].treesLen = block->trees.length(); } @@ -1220,8 +1221,9 @@ void ParseData::makeRuntimeData() CodeBlock *block = reg->preEofBlock; if ( block != 0 ) { runtimeData->regionInfo[regId].eofFrameId = block->frameId; - runtimeData->frameInfo[block->frameId].code = block->code.data; - runtimeData->frameInfo[block->frameId].codeLen = block->code.length(); + runtimeData->frameInfo[block->frameId].codeWV = block->codeWV.data; + runtimeData->frameInfo[block->frameId].codeLenWV = block->codeWV.length(); + runtimeData->frameInfo[block->frameId].trees = block->trees.data; runtimeData->frameInfo[block->frameId].treesLen = block->trees.length(); } @@ -1247,8 +1249,9 @@ void ParseData::makeRuntimeData() CodeBlock *block = lel->transBlock; if ( block != 0 ) { runtimeData->lelInfo[i].frameId = block->frameId; - runtimeData->frameInfo[block->frameId].code = block->code.data; - runtimeData->frameInfo[block->frameId].codeLen = block->code.length(); + runtimeData->frameInfo[block->frameId].codeWV = block->codeWV.data; + runtimeData->frameInfo[block->frameId].codeLenWV = block->codeWV.length(); + runtimeData->frameInfo[block->frameId].trees = block->trees.data; runtimeData->frameInfo[block->frameId].treesLen = block->trees.length(); } @@ -1284,8 +1287,8 @@ void ParseData::makeRuntimeData() if ( block != 0 ) { runtimeData->functionInfo[func->funcId].frameId = block->frameId; - runtimeData->frameInfo[block->frameId].code = block->code.data; - runtimeData->frameInfo[block->frameId].codeLen = block->code.length(); + runtimeData->frameInfo[block->frameId].codeWV = block->codeWV.data; + runtimeData->frameInfo[block->frameId].codeLenWV = block->codeWV.length(); runtimeData->frameInfo[block->frameId].codeWC = block->codeWC.data; runtimeData->frameInfo[block->frameId].codeLenWC = block->codeWC.length(); diff --git a/colm/pdacodegen.cpp b/colm/pdacodegen.cpp index 3344a0f6..399209a8 100644 --- a/colm/pdacodegen.cpp +++ b/colm/pdacodegen.cpp @@ -99,14 +99,14 @@ void PdaCodeGen::writeRuntimeData( RuntimeData *runtimeData ) */ for ( int i = 0; i < runtimeData->numFrames; i++ ) { /* FIXME: horrible code cloning going on here. */ - if ( runtimeData->frameInfo[i].codeLen > 0 ) { - out << "Code code_" << i << "[] = {\n\t"; + if ( runtimeData->frameInfo[i].codeLenWV > 0 ) { + out << "Code code_" << i << "_wv[] = {\n\t"; - Code *block = runtimeData->frameInfo[i].code; - for ( int j = 0; j < runtimeData->frameInfo[i].codeLen; j++ ) { + Code *block = runtimeData->frameInfo[i].codeWV; + for ( int j = 0; j < runtimeData->frameInfo[i].codeLenWV; j++ ) { out << (unsigned long) block[j]; - if ( j < runtimeData->frameInfo[i].codeLen-1 ) { + if ( j < runtimeData->frameInfo[i].codeLenWV-1 ) { out << ", "; if ( (j+1) % 8 == 0 ) out << "\n\t"; @@ -206,25 +206,22 @@ void PdaCodeGen::writeRuntimeData( RuntimeData *runtimeData ) for ( int i = 0; i < runtimeData->numFrames; i++ ) { out << "\t{ "; - if ( runtimeData->frameInfo[i].codeLen > 0 ) - out << "code_" << i << ", "; + if ( runtimeData->frameInfo[i].codeLenWV > 0 ) + out << "code_" << i << "_wv, "; else out << "0, "; - - out << runtimeData->frameInfo[i].codeLenWC << ", "; + out << runtimeData->frameInfo[i].codeLenWV << ", "; if ( runtimeData->frameInfo[i].codeLenWC > 0 ) out << "code_" << i << "_wc, "; else out << "0, "; - - out << runtimeData->frameInfo[i].codeLen << ", "; + out << runtimeData->frameInfo[i].codeLenWC << ", "; if ( runtimeData->frameInfo[i].treesLen > 0 ) out << "trees_" << i << ", "; else out << "0, "; - out << runtimeData->frameInfo[i].treesLen << ", "; out << " }"; diff --git a/colm/pdarun.cpp b/colm/pdarun.cpp index 828596a9..b7708c38 100644 --- a/colm/pdarun.cpp +++ b/colm/pdarun.cpp @@ -416,7 +416,7 @@ again: /* Execution environment for the reduction code. */ Execution execution( prg, reverseCode, - this, fi->code, redLel->tree, 0 ); + this, fi->codeWV, redLel->tree, 0 ); /* Take a copy of the lhs and store it in alg. May need it during * reverse parsing. */ diff --git a/colm/pdarun.h b/colm/pdarun.h index 5dfe230c..f32c178e 100644 --- a/colm/pdarun.h +++ b/colm/pdarun.h @@ -349,8 +349,8 @@ struct ProdInfo struct FrameInfo { - Code *code; - long codeLen; + Code *codeWV; + long codeLenWV; Code *codeWC; long codeLenWC; char *trees; |