Skip to content

Commit

Permalink
Dump includetree together with passes dump
Browse files Browse the repository at this point in the history
This should help us debug issues related to includes.

Signed-off-by: Giuliano Belinassi <[email protected]>
  • Loading branch information
giulianobelinassi committed Aug 21, 2024
1 parent 88556a5 commit 733a1a2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
32 changes: 22 additions & 10 deletions libcextract/IncludeTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,14 @@ IncludeNode *IncludeTree::Get(const SourceLocation &loc)
return nullptr;
}

void IncludeTree::Dump(llvm::raw_ostream &out)
{
Root->Dump(out);
}

void IncludeTree::Dump(void)
{
Root->Dump();

llvm::outs() << "Tree map:\n";
for (auto &p: Map)
llvm::outs() << " " << p.first << " => " << p.second << '\n';
}

/* ----- IncludeNode ------ */
Expand Down Expand Up @@ -565,18 +566,29 @@ void IncludeNode::Set_HeaderGuard(MacroDefinitionRecord *guard)
}
}

void IncludeTree::IncludeNode::Dump_Single_Node(llvm::raw_ostream &out)
{
out << File->getName() << " Expand: " << ShouldBeExpanded <<
" Output: " << ShouldBeOutput << " -include: " <<
IsFromMinusInclude << '\n';
}

void IncludeTree::IncludeNode::Dump_Single_Node(void)
{
llvm::outs() << File->getName() << " Expand: " << ShouldBeExpanded <<
" Output: " << ShouldBeOutput << '\n';
Dump_Single_Node(llvm::outs());
}

void IncludeTree::IncludeNode::Dump(unsigned ident)
void IncludeTree::IncludeNode::Dump(llvm::raw_ostream &out, unsigned ident)
{
llvm::outs() << std::string(ident*2, ' ');
Dump_Single_Node();
out << std::string(ident*2, ' ');
Dump_Single_Node(out);

for (IncludeNode *child : Childs) {
child->Dump(ident + 1);
child->Dump(out, ident + 1);
}
}

void IncludeTree::IncludeNode::Dump(void)
{
Dump(llvm::outs());
}
6 changes: 5 additions & 1 deletion libcextract/IncludeTree.hh
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,11 @@ class IncludeTree
}

/** Dump, for debugging reasons. */
void Dump_Single_Node(llvm::raw_ostream &out);
void Dump(llvm::raw_ostream &out, unsigned ident = 0);

void Dump_Single_Node(void);
void Dump(unsigned ident = 0);
void Dump(void);

private:

Expand Down Expand Up @@ -209,6 +212,7 @@ class IncludeTree
IncludeNode *Get(const InclusionDirective *);

/** Dump for debugging purposes. */
void Dump(llvm::raw_ostream &out);
void Dump(void);

private:
Expand Down
13 changes: 13 additions & 0 deletions libcextract/Passes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ class ClosurePass : public Pass
{
std::error_code ec;
llvm::raw_fd_ostream out(Get_Dump_Name_From_Input(ctx), ec);

/* Dump the IncludeTree. */
IncludeTree IT(ctx->AST.get(), ctx->IncExpansionPolicy, ctx->HeadersToExpand);
out << "/** IncludeTree: \n\n";
IT.Dump(out);
out << "\n */\n";

out << ctx->CodeOutput;
out.close();
}
Expand Down Expand Up @@ -487,6 +494,12 @@ class FunctionExternalizerPass : public Pass
}
out << "*/\n";

/* Dump the IncludeTree. */
IncludeTree IT(ctx->AST.get(), ctx->IncExpansionPolicy, ctx->HeadersToExpand);
out << "/** IncludeTree: \n\n";
IT.Dump(out);
out << "\n */\n";

/* Then the code. */
out << ctx->CodeOutput;
}
Expand Down

0 comments on commit 733a1a2

Please sign in to comment.