1/*******************************************************************************
2 Copyright (c) The Taichi Authors (2016- ). All Rights Reserved.
3 The use of this software is governed by the LICENSE file.
4*******************************************************************************/
5
6#include "taichi/common/core.h"
7#include "taichi/common/task.h"
8#if !defined(_WIN64)
9#include <cxxabi.h>
10#endif
11
12namespace taichi {
13
14// From https://en.wikipedia.org/wiki/Name_mangling
15
16std::string cpp_demangle(const std::string &mangled_name) {
17#if defined(TI_PLATFORM_UNIX)
18 char *demangled_name;
19 int status = -1;
20 demangled_name =
21 abi::__cxa_demangle(mangled_name.c_str(), nullptr, nullptr, &status);
22 std::string ret(demangled_name);
23 free(demangled_name);
24 return ret;
25#else
26 TI_NOT_IMPLEMENTED
27#endif
28}
29
30class Demangling : public Task {
31 std::string run(const std::vector<std::string> &parameters) override {
32 if (parameters.size() == 0) {
33 printf("There should be at least one parameter for demangling.\n");
34 }
35 for (auto p : parameters) {
36#if !defined(_WIN64)
37 printf("Demangled C++ Identifier: %s\n", cpp_demangle(p).c_str());
38#else
39 TI_NOT_IMPLEMENTED
40#endif
41 }
42 return "";
43 }
44};
45
46TI_IMPLEMENTATION(Task, Demangling, "demangle")
47
48} // namespace taichi
49