Skip to content

Commit

Permalink
much smaller size of SCC in memory and saved file due to removal of u…
Browse files Browse the repository at this point in the history
…nrelated Semicompiled Code nodes.
  • Loading branch information
GillesDuvert committed Dec 13, 2023
1 parent c7472b0 commit 5df8651
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/dcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void DCompiler::StartPro(const string& n, const int compileOpt, const string& o,
pro->SetCompileOpt(compileOpt);
//"restored" procedures have no file name associated. They will be marked as "CompileHidden", to avoid the message "Compiled module" issued when (re)compiling the Lexer code.
if (actualFile.length()==0) pro->AddHiddenToCompileOpt();
pro->SetAstTree(semiCompiledTree); //entry number
pro->SetSCC(semiCompiledTree); //entry number
}
else
{
Expand All @@ -177,7 +177,7 @@ void DCompiler::StartFun(const string& n, const int compileOpt = 0, const string
pro->SetCompileOpt(compileOpt);
//"restored" procedures have no file name associated. They will be marked as "CompileHidden", to avoid the message "Compiled module" issued when (re)compiling the Lexer code.
if (actualFile.length() == 0) pro->AddHiddenToCompileOpt();
pro->SetAstTree(semiCompiledTree); //entry number
pro->SetSCC(semiCompiledTree); //entry number
}

bool DCompiler::IsActivePro( DSub* p)
Expand Down
9 changes: 8 additions & 1 deletion src/dinterpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ bool GDLInterpreter::CompileFile(const string& f, const string& untilPro, bool s
#ifdef GDL_DEBUG
cout << "Parser output:" << endl;
antlr::print_tree pt;
pt.pr_tree(static_cast<antlr::RefAST>(theSemiCompiledAST));
pt.pr_tree(static_cast<antlr::RefAST>(theAST));
cout << "CompileFile: Parser end." << endl;
#endif

Expand Down Expand Up @@ -714,6 +714,13 @@ bool GDLInterpreter::CompileFile(const string& f, const string& untilPro, bool s

bool GDLInterpreter::CompileSaveFile(RefDNode theSemiCompiledAST)
{
#ifdef GDL_DEBUG
cout << "Parser output:" << endl;
antlr::print_tree pt;
pt.pr_tree(static_cast<antlr::RefAST>(theSemiCompiledAST));
cout << "CompileFile: Parser end." << endl;
#endif

#ifdef GDL_DEBUG
RefDNode trAST;
#endif
Expand Down
34 changes: 19 additions & 15 deletions src/dpro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "print_tree.hpp"
#endif

CodeListT codeList;
SCCodeListT sccList;

using namespace std;
Expand Down Expand Up @@ -70,9 +69,11 @@ using namespace std;
savenode.ligne = dNode->getLine();
savenode.flags=dNode->GetCompileOpt();
// trick to avoid saving a Text and a CData containing the same text, either as a string or a value converted to the good BaseGDL type.
// if dNode->CData() is non-nil, set savenode.Text to ""
savenode.var=dNode->CData();
if (savenode.var == NULL) savenode.Text = dNode->getText(); else savenode.Text = "";
// if dNode->CData() is non-nil, set savenode.Text to "" and save CData as copy.
if (dNode->CData() != NULL) {
savenode.var=dNode->CData()->Convert2(dNode->CData()->Type(),BaseGDL::COPY);
savenode.Text = "";
} else savenode.Text = dNode->getText();
nodes.push_back(savenode);
}

Expand Down Expand Up @@ -101,9 +102,11 @@ using namespace std;
process_leaves(top,nodes,addrList);
}
}

//same as index_tree: no not use
void process_tree(RefDNode top, SCCStructV &nodes, SCCodeAddresses &addrList) {

Check warning on line 106 in src/dpro.cpp

View check run for this annotation

Codecov / codecov/patch

src/dpro.cpp#L106

Added line #L106 was not covered by tests
RefDNode t;
std::cerr<<"use of process_tree, please report."<<std::endl;
assert(false);
RefDNode t;
for (t = top; t != NULL; t = t->getNextSibling()) {
process_top(t,nodes,addrList);

Check warning on line 111 in src/dpro.cpp

View check run for this annotation

Codecov / codecov/patch

src/dpro.cpp#L111

Added line #L111 was not covered by tests
}
Expand All @@ -115,7 +118,7 @@ void indexNodeAddress(RefDNode node, SCCodeAddresses &addrList, int &i) {
// associate node address to an increasing number starting at 1
DNode* ast = node.get();
addrList.insert(std::pair<DNode*,int>(ast, ++i)); //+1 as address 0 is special for all nodes
}
}

void index_leaves(RefDNode top, SCCodeAddresses &addrList, int &i) {
RefDNode t;
Expand All @@ -140,7 +143,10 @@ void index_top(RefDNode top, SCCodeAddresses &addrList, int &i) {
}
}

//this would be to index a full tree, but our use at the time is of index_top, that serialize only the current PRO or FUN .
void index_tree(RefDNode top, SCCodeAddresses &addrList, int &i) {

Check warning on line 147 in src/dpro.cpp

View check run for this annotation

Codecov / codecov/patch

src/dpro.cpp#L147

Added line #L147 was not covered by tests
std::cerr<<"use of index_tree, please report."<<std::endl;
assert(false);
RefDNode t;
for (t = top; t != NULL; t = t->getNextSibling()) {
index_top(t, addrList, i);

Check warning on line 152 in src/dpro.cpp

View check run for this annotation

Codecov / codecov/patch

src/dpro.cpp#L152

Added line #L152 was not covered by tests
Expand Down Expand Up @@ -369,7 +375,7 @@ DSubUD::~DSubUD()

labelList.Clear();
delete tree;
codeList.erase(this);
sccList.erase(this);
}

DSubUD::DSubUD(const string& n,const string& o,const string& f) :
Expand Down Expand Up @@ -525,20 +531,18 @@ void DSubUD::SetTree( RefDNode n)
}
//converts a SemiCompiledCode (chained list of DNodes) to a 'flat' vector of sccstruct and insert the vector in the map pointed by "sccList"

void DSubUD::SetAstTree(RefDNode n) {
//first, walk RefDnode tree to associate right,down, and self addresses with a number in the list:
void DSubUD::SetSCC(RefDNode n) {
//first, walk RefDnode tree to associate right,down, and self addresses with a number in the list.
SCCodeAddresses addrList;
int i=0;
index_tree(n, addrList, i);
//serialize only the current PRO or FUN by using index_top and *not* index_tree.
index_top(n, addrList, i);
SCCStructV sccv;
process_tree(n, sccv, addrList);
process_top(n, sccv, addrList);
//PRO or FUNCTION top node may contain a 'wrong' right pointer in the first node, due to the way the whole .pro file is compiled at once.
//Remove it:
sccv[0].right=0;
sccList.insert(std::pair<DSubUD*,SCCStructV >(this, sccv));

//to be removed
codeList.insert(std::pair<DSubUD*, RefDNode>(this, n));
}
bool DSubUD::GetCommonVarName(const BaseGDL* p, std::string& varName)
{
Expand Down
10 changes: 2 additions & 8 deletions src/dpro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ class DSubUD: public DSub
void SetTree( ProgNodeP t) { tree = t;}

//converts a SemiCompiledCode (chained list of DNodes) to a 'flat' vector of sccstruct and insert the vector in the map pointed by "sccList"
void SetAstTree( RefDNode n);
void SetSCC( RefDNode n);

void AddCommon(DCommonBase* c) { common.push_back(c);}
void DeleteLastAddedCommon(bool kill=true)
Expand Down Expand Up @@ -568,13 +568,7 @@ void ReName( SizeT ix, const std::string& s)
{
return tree;
}
RefDNode GetAstTree()
{
//find Semicompiled code saved in codeList
CodeListIterator i = codeList.find(this);
if (i!=codeList.end()) return (*i).second;
return NULL;
}

SCCStructV* GetSCC()
{
//find Semicompiled code saved in codeList
Expand Down
8 changes: 4 additions & 4 deletions src/gdlhelp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ static void help_object(std::ostream* ostrp, DStructDesc* objDesc, bool verbose
//if object is purely GDL internal , do not display it if not verbose:
if (!verbose) {
bool internal=true;
for (auto i=0; i< funlist.size(); ++i) if (funlist[i]->GetAstTree()!=NULL) {internal=false; break;}
if (internal) for (auto i=0; i< prolist.size(); ++i) if (prolist[i]->GetAstTree()!=NULL) {internal=false; break;}
for (auto i=0; i< funlist.size(); ++i) if (funlist[i]->GetSCC()!=NULL) {internal=false; break;}
if (internal) for (auto i=0; i< prolist.size(); ++i) if (prolist[i]->GetSCC()!=NULL) {internal=false; break;}
if (internal) return;
}
int num_methods = funlist.size() + prolist.size();
Expand Down Expand Up @@ -1030,7 +1030,7 @@ void help_help(EnvT* e)
DStructDesc* s = structList[i];
for (auto j = 0; j < s->FunList().size(); ++j) {
DFun* fun = (s->FunList())[j];
if (fun->GetAstTree() != NULL) { //compiled objects, not native ones
if (fun->GetSCC() != NULL) { //compiled objects, not native ones
if (fullKW or !fun->isHidden()) {
fList.push_back(fun->ObjectName());
++nfun;
Expand All @@ -1052,7 +1052,7 @@ void help_help(EnvT* e)
DStructDesc* s = structList[i];
for (auto j = 0; j < s->ProList().size(); ++j) {
DPro * pro = (s->ProList())[j];
if (pro->GetAstTree() != NULL) { //compiled objects, not native ones
if (pro->GetSCC() != NULL) { //compiled objects, not native ones
if (fullKW or !pro->isHidden()) {
pList.push_back(pro->ObjectName());
++npro;
Expand Down
50 changes: 26 additions & 24 deletions src/saverestore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,85 +121,87 @@ enum {

// write a copy of the SemiCompiledCode stored along with any new compiled routine.

void wr_writeNode(sccstruct node, XDR* xdrs) {
void wr_writeNode(sccstruct savenode, XDR* xdrs) {
//write node index:
xdr_u_int(xdrs, & node.node);
xdr_u_int(xdrs, & savenode.node);
//write right index:
xdr_u_int(xdrs, & node.right);
xdr_u_int(xdrs, & savenode.right);
//write down index:
xdr_u_int(xdrs, & node.down);
xdr_u_int(xdrs, & savenode.down);
//other infos
xdr_u_int(xdrs, &node.nodeType); //ttype
uint l = (node.Text).length();
xdr_u_int(xdrs, &savenode.nodeType); //ttype
uint l = (savenode.Text).length();
xdr_u_int(xdrs, &l);
char *t = (char*) (node.Text).c_str();
char *t = (char*) (savenode.Text).c_str();
xdr_string(xdrs, &t, l); //TEXT
xdr_u_int(xdrs, & node.ligne); //LineNUM
xdr_u_int(xdrs, & node.flags);
xdr_u_int(xdrs, & savenode.ligne); //LineNUM
xdr_u_int(xdrs, & savenode.flags);
int varType = 0;
if (node.var) varType = node.var->Type(); //will be 0 otherwise
if (savenode.var!=NULL) {
varType = savenode.var->Type(); //will be 0 otherwise
}
xdr_int32_t(xdrs, &varType);
if (varType > 0) {
switch (varType) {
case GDL_FLOAT:
{
DFloat f = (*static_cast<DFloatGDL*> (node.var))[0];
DFloat f = (*static_cast<DFloatGDL*> (savenode.var))[0];
xdr_float(xdrs, &f);
break;
}
case GDL_DOUBLE:

Check warning on line 152 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L152

Added line #L152 was not covered by tests
{
DDouble d = (*static_cast<DDoubleGDL*> (node.var))[0];
DDouble d = (*static_cast<DDoubleGDL*> (savenode.var))[0];
xdr_double(xdrs, & d);

Check warning on line 155 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L154-L155

Added lines #L154 - L155 were not covered by tests
break;
}
// case GDL_COMPLEX: //should not happen
// case GDL_COMPLEXDBL:
case GDL_ULONG64:

Check warning on line 160 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L160

Added line #L160 was not covered by tests
{
u_int64_t ul6 = (*static_cast<DULong64GDL*> (node.var))[0];
u_int64_t ul6 = (*static_cast<DULong64GDL*> (savenode.var))[0];
xdr_u_int64_t(xdrs, & ul6);

Check warning on line 163 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L162-L163

Added lines #L162 - L163 were not covered by tests
break;
}
case GDL_LONG64:

Check warning on line 166 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L166

Added line #L166 was not covered by tests
{
int64_t l6 = (*static_cast<DLong64GDL*> (node.var))[0];
int64_t l6 = (*static_cast<DLong64GDL*> (savenode.var))[0];
xdr_int64_t(xdrs, & l6);

Check warning on line 169 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L168-L169

Added lines #L168 - L169 were not covered by tests
break;
}
case GDL_BYTE:

Check warning on line 172 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L172

Added line #L172 was not covered by tests
{
DByte b = (*static_cast<DByteGDL*> (node.var))[0];
DByte b = (*static_cast<DByteGDL*> (savenode.var))[0];
xdr_u_char(xdrs, & b);

Check warning on line 175 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L174-L175

Added lines #L174 - L175 were not covered by tests
break;
}
case GDL_INT:
{
DInt i = (*static_cast<DIntGDL*> (node.var))[0];
DInt i = (*static_cast<DIntGDL*> (savenode.var))[0];
xdr_short(xdrs, & i);
break;
}
case GDL_UINT:

Check warning on line 184 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L184

Added line #L184 was not covered by tests
{
DUInt ui = (*static_cast<DUIntGDL*> (node.var))[0];
DUInt ui = (*static_cast<DUIntGDL*> (savenode.var))[0];
xdr_u_short(xdrs, & ui);

Check warning on line 187 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L186-L187

Added lines #L186 - L187 were not covered by tests
break;
}
case GDL_LONG:
{
int32_t l = (*static_cast<DLongGDL*> (node.var))[0];
int32_t l = (*static_cast<DLongGDL*> (savenode.var))[0];
xdr_int32_t(xdrs, & l);
break;
}
case GDL_ULONG:

Check warning on line 196 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L196

Added line #L196 was not covered by tests
{
u_int32_t ul = (*static_cast<DULongGDL*> (node.var))[0];
u_int32_t ul = (*static_cast<DULongGDL*> (savenode.var))[0];
xdr_u_int32_t(xdrs, & ul);

Check warning on line 199 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L198-L199

Added lines #L198 - L199 were not covered by tests
break;
}
case GDL_STRING:
{
DString s = (*static_cast<DStringGDL*> (node.var))[0];
DString s = (*static_cast<DStringGDL*> (savenode.var))[0];
u_int l = s.length();
char* c = (char*) s.c_str();
xdr_string(xdrs, &c, l);
Expand Down Expand Up @@ -2860,7 +2862,7 @@ if (!doRoutines){
for (ProListT::iterator i = proList.begin(); i != proList.end(); ++i) {
if ((*i)->ObjectName() == name) {
DPro * p = (*i);
if (p->GetAstTree() != NULL) {
if (p->GetSCC() != NULL) {

Check warning on line 2865 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L2865

Added line #L2865 was not covered by tests
nextptr = writeDSubUD(xdrs, p, true);
notFound = false;
}
Expand All @@ -2871,7 +2873,7 @@ if (!doRoutines){
for (FunListT::iterator i = funList.begin(); i != funList.end(); ++i) {
if ((*i)->ObjectName() == name) {
DFun * f = (*i);
if (f->GetAstTree() != NULL) {
if (f->GetSCC() != NULL) {

Check warning on line 2876 in src/saverestore.cpp

View check run for this annotation

Codecov / codecov/patch

src/saverestore.cpp#L2876

Added line #L2876 was not covered by tests
nextptr = writeDSubUD(xdrs, f, false);
notFound = false;
}
Expand All @@ -2895,11 +2897,11 @@ if (!doRoutines){
DStructDesc* s=structList[i];
for (auto j = 0; j < s->ProList().size(); ++j) {
DPro * p = (s->ProList())[j];
if (p->GetAstTree() != NULL) if (ignore_nosave || !(p->isNoSave())) nextptr = writeDSubUD(xdrs, p, true);
if (p->GetSCC() != NULL) if (ignore_nosave || !(p->isNoSave())) nextptr = writeDSubUD(xdrs, p, true);
}
for (auto j= 0 ; j < s->FunList().size(); ++j) {
DFun * f = (s->FunList())[j];
if (f->GetAstTree() != NULL) if (ignore_nosave || !(f->isNoSave())) nextptr = writeDSubUD(xdrs, f, false);
if (f->GetSCC() != NULL) if (ignore_nosave || !(f->isNoSave())) nextptr = writeDSubUD(xdrs, f, false);
}
}

Expand Down

0 comments on commit 5df8651

Please sign in to comment.