Skip to content

Commit

Permalink
test: wip tree repr for demangled func names
Browse files Browse the repository at this point in the history
  • Loading branch information
haxscramper committed Apr 17, 2024
1 parent b00f14f commit 9560c41
Showing 1 changed file with 52 additions and 4 deletions.
56 changes: 52 additions & 4 deletions scripts/cxx_codegen/profdata_merger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,62 @@
namespace fs = std::filesystem;
using namespace llvm;
using namespace llvm::coverage;
using itanium_demangle::Node;
using namespace itanium_demangle;

BOOST_DESCRIBE_ENUM_BEGIN(itanium_demangle::Node::Kind)
#define NODE(NodeKind) \
BOOST_DESCRIBE_ENUM_ENTRY(itanium_demangle::Node::Kind, K##NodeKind)
enum class KindProxy
{
#define NODE(NodeKind) NodeKind,
#include <llvm/Demangle/ItaniumNodes.def>
};

BOOST_DESCRIBE_ENUM_BEGIN(KindProxy)
#define NODE(NodeKind) BOOST_DESCRIBE_ENUM_ENTRY(KindProxy, NodeKind)
#include <llvm/Demangle/ItaniumNodes.def>
BOOST_DESCRIBE_ENUM_END()


std::string treeRepr(Node const* node, int indent) {
std::string result = "";
if (node == nullptr) {
result += "<nil>";
return result;
}
result += std::string(indent * 2, ' ');
result += std::string{boost::describe::enum_to_string(
static_cast<KindProxy>(node->getKind()), "<none>")};


auto sub = [indent, &result](Node const* sub) {
result += "\n" + treeRepr(sub, indent + 1);
};

using K = itanium_demangle::Node::Kind;
switch (node->getKind()) {
case K::KFunctionEncoding: {
auto cast = static_cast<FunctionEncoding const*>(node);
sub(cast->getName());
break;
}
case K::KNestedName: {
auto cast = static_cast<NestedName const*>(node);
sub(cast->Qual);
sub(cast->Name);
break;
}
case K::KNameType: {
auto cast = static_cast<NameType const*>(node);
result += std::format(
" base:{} name:{}", cast->getBaseName(), cast->getName());
break;
}
default: {
result += " <unhandled>";
}
}

return result;
}

namespace {
class BumpPointerAllocator {
struct BlockMeta {
Expand Down Expand Up @@ -263,6 +310,7 @@ int main(int argc, char** argv) {
f.Name.data(), f.Name.data() + f.Name.length());

Node* AST = Parser.parse();
LOG(std::format("{}", treeRepr(AST, 0)));
}
}
}

0 comments on commit 9560c41

Please sign in to comment.