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

Method allocateStack

src/ast/ast_allocate_stack.cpp:929–1010  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

927 // program
928
929 void Program::allocateStack(TextWriter & logs, bool permanent, bool everything) {
930 // string heap
931 AllocateConstString vstr;
932 for (auto & pm : library.modules) {
933 for ( auto & var : pm->globals.each() ) {
934 if (var->used && var->init) {
935 var->init->visit(vstr);
936 }
937 }
938 for ( auto & func : pm->functions.each() ) {
939 if (func->used) {
940 func->visit(vstr);
941 }
942 }
943 }
944 globalStringHeapSize = vstr.bytesTotal;
945 // move some variables to CMRES
946 VarCMRes vcm(this, everything);
947 visit(vcm);
948 // allocate stack for the rest of them
949 AllocateStack context(this, permanent, everything, logs);
950 visit(context);
951 // adjust stack size for all the used variables
952 for (auto & pm : library.modules) {
953 for ( auto & var : pm->globals.each() ) {
954 if ( var->used ) {
955 globalInitStackSize = das::max(globalInitStackSize, var->initStackSize);
956 }
957 }
958 }
959 // allocate used variables and functions indices
960 totalVariables = 0;
961 totalFunctions = 0;
962 auto log = options.getBoolOption("log_stack");
963 if ( log ) {
964 logs << "INIT STACK SIZE:\t" << globalInitStackSize << "\n";
965 logs << "FUNCTION TABLE:\n";
966 }
967 for (auto & pm : library.modules) {
968 for ( auto & func : pm->functions.each() ) {
969 if ( func->used && !func->builtIn && !func->isTemplate ) {
970 func->index = totalFunctions++;
971 if ( log ) {
972 logs << "\t" << func->index << "\t" << func->totalStackSize << "\t" << func->getMangledName();
973 if ( func->init ) {
974 logs << " [init";
975 if (func->lateInit ) logs << "(late)";
976 logs << "]";
977 }
978 if ( func->shutdown ) {
979 logs << " [finalize";
980 if (func->lateShutdown ) logs << "(late)";
981 logs << "]";
982 }
983 logs << " // " << HEX << func->getMangledNameHash() << DEC;
984 logs << "\n";
985 }
986 }

Callers 4

visitMethod · 0.45
parseDaScriptFunction · 0.45
compileDaScriptFunction · 0.45

Calls 8

getBoolOptionMethod · 0.80
foreach_in_orderMethod · 0.80
visitFunction · 0.50
visitMethod · 0.45
getMangledNameMethod · 0.45
getMangledNameHashMethod · 0.45
getSizeOfMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected