static void BasicBlock_WriteByteCode(KonohaContext *kctx, bblock_t blockId, ByteCodeWriter *writer) { BasicBlock *bb = BasicBlock_FindById(kctx, blockId); while(bb != NULL && bb->codeoffset == -1) { intptr_t len = bb->size - sizeof(BasicBlock); bb->codeoffset = CodeOffset(writer); bb->lastoffset = -1; // reset lastoffset if(len > 0) { bblock_t id = BasicBlock_id(kctx, bb); WriteByteCode(writer, ((char *)bb) + sizeof(BasicBlock), len); bb = BasicBlock_FindById(kctx, id); // recheck bb->lastoffset = CodeOffset(writer) - sizeof(KVirtualCode); DBG_ASSERT(bb->codeoffset + ((len / sizeof(KVirtualCode)) - 1) * sizeof(KVirtualCode) == (size_t) bb->lastoffset); } else { DBG_ASSERT(bb->branchid == -1); } bb = BasicBlock_FindById(kctx, bb->nextid); } bb = BasicBlock_FindById(kctx, blockId); while(bb != NULL) { if(bb->branchid != -1) { BasicBlock *bbJ = BasicBlock_FindById(kctx, bb->branchid); if(bbJ->codeoffset == -1) { BasicBlock_WriteByteCode(kctx, bb->branchid, writer); } } bb = BasicBlock_FindById(kctx, bb->nextid); } }
void asCRestore::WriteFunction(asCScriptFunction* func) { char c; // If there is no function, then store a null char if( func == 0 ) { c = '\0'; WRITE_NUM(c); return; } // First check if the function has been saved already for( asUINT f = 0; f < savedFunctions.GetLength(); f++ ) { if( savedFunctions[f] == func ) { c = 'r'; WRITE_NUM(c); WRITE_NUM(f); return; } } // Keep a reference to the function in the list savedFunctions.PushLast(func); c = 'f'; WRITE_NUM(c); asUINT i, count; WriteFunctionSignature(func); count = (asUINT)func->byteCode.GetLength(); WRITE_NUM(count); WriteByteCode(func->byteCode.AddressOf(), count); count = (asUINT)func->objVariablePos.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) { WriteObjectType(func->objVariableTypes[i]); WRITE_NUM(func->objVariablePos[i]); } WRITE_NUM(func->stackNeeded); asUINT length = (asUINT)func->lineNumbers.GetLength(); WRITE_NUM(length); for( i = 0; i < length; ++i ) WRITE_NUM(func->lineNumbers[i]); WRITE_NUM(func->vfTableIdx); // TODO: Write variables // TODO: Store script section index }
void asCRestore::WriteFunction(asCScriptFunction* func) { int i, count; WriteString(&func->name); WriteDataType(&func->returnType); count = func->parameterTypes.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) WriteDataType(&func->parameterTypes[i]); WRITE_NUM(func->id); count = func->byteCode.GetLength(); WRITE_NUM(count); WriteByteCode(func->byteCode.AddressOf(), count); count = func->objVariablePos.GetLength(); WRITE_NUM(count); for( i = 0; i < count; ++i ) { WriteObjectType(func->objVariableTypes[i]); WRITE_NUM(func->objVariablePos[i]); } WRITE_NUM(func->stackNeeded); WriteObjectType(func->objectType); int length = func->lineNumbers.GetLength(); WRITE_NUM(length); for( i = 0; i < length; ++i ) WRITE_NUM(func->lineNumbers[i]); }