bool Item::serialize_object( Stream *file, CoreObject *obj, bool bLive ) const { byte type = FLC_ITEM_OBJECT; if ( bLive ) type |= 0x80; file->write( &type, 1 ); // write the class symbol so that it can be rebuilt back. serialize_symbol( file, obj->generator()->symbol() ); // then serialzie the object itself return obj->serialize( file, bLive ); }
bool Item::serialize_function( Stream *file, const CoreFunc *func, bool bLive ) const { byte type = FLC_ITEM_FUNC; if ( bLive ) type |= 0x80; file->write( &type, 1 ); // we don't serialize the module ID because it is better to rebuild it on deserialization serialize_symbol( file, func->symbol() ); if ( func->symbol()->isFunction() ) { // language function ? -- serialize the state. FuncDef *fdef = func->symbol()->getFuncDef(); // write the called status uint32 itemId = fdef->onceItemId(); if ( itemId != FuncDef::NO_STATE ) { byte called = func->liveModule()->globals()[ itemId ].isNil() ? 0 : 1; file->write( &called, 1 ); } // and we may need to serialize also it's closure. ItemArray* closed = func->closure(); if( closed != 0 ) { int32 len = endianInt32( closed->length() ); file->write( (byte *) &len, sizeof( len ) ); for( uint32 i = 0; i < closed->length(); i ++ ) { (*closed)[i].serialize( file, bLive ); if( ! file->good() ) return false; } } else { int32 len = 0; file->write( (byte *) &len, sizeof( len ) ); } } if ( ! file->good() ) return false; return true; }
void Trace::write_file(const char * filename) { xmlDocPtr doc = NULL; xmlNodePtr root_node = NULL, node = NULL, memories_n, instructions_n, symbols_n, xrefs_n; LIBXML_TEST_VERSION; doc = xmlNewDoc( BAD_CAST "1.0"); root_node = xmlNewNode(NULL, BAD_CAST "atdoc"); xmlDocSetRootElement(doc, root_node); memories_n = xmlNewChild(root_node, NULL, BAD_CAST "memblocks", NULL); instructions_n =xmlNewChild(root_node, NULL, BAD_CAST "instructions", NULL); symbols_n = xmlNewChild(root_node, NULL, BAD_CAST "symbols", NULL); xrefs_n = xmlNewChild(root_node, NULL, BAD_CAST "xrefs", NULL); for (memseglist_ci i = m_mem_segments.begin(); i != m_mem_segments.end(); i++) serialize_memsegment(*i, memories_n); for (memloclist_i i = m_memdata.begin(); i!=m_memdata.end(); i++) serialize_Instruction(dynamic_cast<Instruction *>((*i).second), instructions_n); for (SymbolList::symaddr_ci i = m_symlist.begin_addr(); i!=m_symlist.end_addr(); i++) serialize_symbol(*i, symbols_n); for (memloclist_i i = m_memdata.begin(); i!=m_memdata.end(); i++) { MemlocData * instr = (*i).second; if (!instr || !instr->has_xrefs_from()) continue; for (xref_map_ci j = instr->begin_xref_from(); j != instr->end_xref_from(); j++) serialize_xref((*j).second, xrefs_n); } XMLBZIP2_writer writer; if (!writer.xmlWriteDoc(doc, filename)) printf("Failed to save!\n"); xmlFreeDoc(doc); xmlCleanupParser(); }