MCPcopy Create free account
hub / github.com/GaijinEntertainment/daScript / serializeProgram

Method serializeProgram

src/builtin/module_builtin_ast_serialize.cpp:2588–2698  ·  view source on GitHub ↗

Used in eden

Source from the content-addressed store, hash-verified

2586
2587 // Used in eden
2588 void AstSerializer::serializeProgram ( ProgramPtr program, ModuleGroup & libGroup ) noexcept {
2589 auto & ser = *this;
2590 // Bump epoch so reused pointer addresses across program boundaries
2591 // get distinct SerializeNodeIds on this persistent serializer.
2592 ser.epoch++;
2593
2594 ser << program->thisNamespace << program->thisModuleName;
2595
2596 ser << program->totalFunctions << program->totalVariables << program->newLambdaIndex;
2597 ser << program->globalInitStackSize << program->globalStringHeapSize;
2598 ser << program->flags;
2599
2600 ser << program->options << program->policies;
2601
2602 if ( writing ) {
2603 TopSort ts(program->library.getModules());
2604 auto modules = ts.getDependecyOrdered(program->thisModule.get());
2605
2606 uint64_t size = modules.size(); *this << size;
2607
2608 for ( auto & m : modules ) {
2609 bool builtin = m->builtIn, promoted = m->promoted;
2610 *this << builtin << promoted;
2611 *this << m->name;
2612
2613 if ( m->builtIn && !m->promoted ) {
2614 *this << m->cumulativeHash;
2615 continue;
2616 }
2617
2618 bool isNew = writingReadyModules.count(m) == 0;
2619 *this << isNew;
2620 if ( isNew ) {
2621 writingReadyModules.insert(m);
2622 *this << *m;
2623 }
2624 }
2625 } else {
2626 uint64_t size = 0; ser << size;
2627
2628 program->library.reset();
2629 program->thisModule.release();
2630 moduleLibrary = &program->library;
2631
2632 for ( uint64_t i = 0; i < size; i++ ) {
2633 bool builtin = false, promoted = false;
2634 ser << builtin << promoted;
2635 string name; ser << name;
2636
2637 if ( builtin && !promoted ) {
2638 auto m = Module::require(name);
2639 uint64_t savedHash = 0, moduleHash = m->cumulativeHash;
2640 *this << savedHash;
2641
2642 if ( moduleHash != savedHash ) {
2643 LOG(LogLevel::warning) << "das: serialize: cumulative hash for module '" << m->name
2644 << "' differs" << " (" << moduleHash << " vs " << savedHash << ") ";
2645 program->failToCompile = true;

Callers 2

writebackModulesFunction · 0.80

Calls 12

getDependecyOrderedMethod · 0.80
findModuleMethod · 0.80
setModuleNameMethod · 0.80
getMethod · 0.45
sizeMethod · 0.45
countMethod · 0.45
insertMethod · 0.45
resetMethod · 0.45
releaseMethod · 0.45
addModuleMethod · 0.45
whatMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected