Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

a solution tool to the "anvill-specify-bitcode(Currently unsupported)" #360

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
11 changes: 11 additions & 0 deletions tools/ExternalFunctionAuto-Completion/DemanglingTools/in.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

{
"Function" : [
{ "name":"_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_" },
{ "name":"_ZNSolsEPFRSoS_E" },
{ "name":"_ZNSt8ios_base4InitC1Ev" },
{ "name":"_ZNSolsEd" },
{ "name":"_ZNSt8ios_base4InitD1Ev" }

]
}
Submodule jsoncpp added at 8190e0
74 changes: 74 additions & 0 deletions tools/ExternalFunctionAuto-Completion/DemanglingTools/out.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
"Function" : [
{
"BaseName" : "endl",
"DeclContextName" : "std",
"EntireName" : "std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)",
"FunctionName" : "std::endl<char, std::char_traits<char> >",
"MangledName" : "_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_",
"Parameters" : "(std::basic_ostream<char, std::char_traits<char> >&)",
"ReturnType" : "std::basic_ostream<char, std::char_traits<char> >&",
"hasFunctionQualifiers" : false,
"isCtorOrDtor" : false,
"isData" : false,
"isFunction" : true,
"isSpecialName" : false
},
{
"BaseName" : "operator<<",
"DeclContextName" : "std::ostream",
"EntireName" : "std::ostream::operator<<(std::ostream& (*)(std::ostream&))",
"FunctionName" : "std::ostream::operator<<",
"MangledName" : "_ZNSolsEPFRSoS_E",
"Parameters" : "(std::ostream& (*)(std::ostream&))",
"ReturnType" : "",
"hasFunctionQualifiers" : false,
"isCtorOrDtor" : false,
"isData" : false,
"isFunction" : true,
"isSpecialName" : false
},
{
"BaseName" : "Init",
"DeclContextName" : "std::ios_base::Init",
"EntireName" : "std::ios_base::Init::Init()",
"FunctionName" : "std::ios_base::Init::Init",
"MangledName" : "_ZNSt8ios_base4InitC1Ev",
"Parameters" : "()",
"ReturnType" : "",
"hasFunctionQualifiers" : false,
"isCtorOrDtor" : true,
"isData" : false,
"isFunction" : true,
"isSpecialName" : false
},
{
"BaseName" : "operator<<",
"DeclContextName" : "std::ostream",
"EntireName" : "std::ostream::operator<<(double)",
"FunctionName" : "std::ostream::operator<<",
"MangledName" : "_ZNSolsEd",
"Parameters" : "(double)",
"ReturnType" : "",
"hasFunctionQualifiers" : false,
"isCtorOrDtor" : false,
"isData" : false,
"isFunction" : true,
"isSpecialName" : false
},
{
"BaseName" : "~Init",
"DeclContextName" : "std::ios_base::Init",
"EntireName" : "std::ios_base::Init::~Init()",
"FunctionName" : "std::ios_base::Init::~Init",
"MangledName" : "_ZNSt8ios_base4InitD1Ev",
"Parameters" : "()",
"ReturnType" : "",
"hasFunctionQualifiers" : false,
"isCtorOrDtor" : true,
"isData" : false,
"isFunction" : true,
"isSpecialName" : false
}
]
}
164 changes: 164 additions & 0 deletions tools/ExternalFunctionAuto-Completion/DemanglingTools/test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
//this file is a simple tools to use the llvm/Demangle.h to demangle extern_funcs
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <list>
#include <iostream>
#include <fstream>
#include "llvm/Demangle/Demangle.h"
#include "jsoncpp/include/json/json.h"


typedef struct
{
std::string MangledName;
std::string BaseName;
std::string DeclContextName;
std::string Parameters;
std::string FunctionName;
std::string EntireName;
std::string ReturnType;
bool hasFunctionQualifiers =false;
bool isCtorOrDtor =false;
bool isFunction =false;
bool isData =false;
bool isSpecialName =false;
}MangleNode;

void readFileJson(std::list<std::string>* funclist)
{
Json::Reader reader;
Json::Value root;

std::ifstream in("in.json", std::ios::binary);
if (!in.is_open())
{
std::cout << "Error opening file\n";
return ;
}
if (reader.parse(in, root))
{
if (root["Function"].isArray())
{
int nArraySize = root["Function"].size();
for (int i=0; i<nArraySize; i++)
{
std::string funcName = root["Function"][i]["name"].asString();
funclist->push_back(funcName);
}
}

}
else
{
std::cout << "parse error\n" << std::endl;
}
in.close();

}

MangleNode DemangleFunction(std::string funcName)
{
MangleNode MNode;
const char* pcmangledname = funcName.data();
int size = 0;
int status = 0;
char * demangled = NULL;
char * FunctionReturnType = NULL;
char * FunctionBaseName = NULL;
char * demangled4 = NULL;
char * demangled5 = NULL;
char * demangled6 = NULL;
llvm::ItaniumPartialDemangler IPD;

IPD.partialDemangle(funcName.data());
MNode.MangledName=funcName;
MNode.ReturnType= IPD.getFunctionReturnType(NULL, NULL);
MNode.BaseName= IPD.getFunctionBaseName(NULL, NULL);
MNode.DeclContextName= IPD.getFunctionDeclContextName(NULL, NULL);
MNode.FunctionName= IPD.getFunctionName(NULL,NULL);
MNode.Parameters= IPD.getFunctionParameters(NULL,NULL);
MNode.EntireName = llvm::itaniumDemangle(funcName.data(), NULL, NULL, &status);
if(IPD.isCtorOrDtor())
{
MNode.isCtorOrDtor=true;
}
if(IPD.hasFunctionQualifiers())
{
MNode.hasFunctionQualifiers=true;
}
if(IPD.isData())
{
MNode.isData=true;
}
if(IPD.isFunction())
{
MNode.isFunction=true;
}
if(IPD.isSpecialName())
{
MNode.isSpecialName=true;
}

return MNode;




}





int main ()
{

std::list<std::string> func_list;
readFileJson(&func_list);
std::list<std::string>::iterator iter;
Json::Value root;
for(iter=func_list.begin(); iter != func_list.end(); iter++)
{
Json::Value bro;
MangleNode MNode=DemangleFunction(*iter);
bro["MangledName"]=Json::Value(MNode.MangledName);
bro["BaseName"]=Json::Value(MNode.BaseName);
bro["DeclContextName"]=Json::Value(MNode.DeclContextName);
bro["Parameters"]=Json::Value(MNode.Parameters);
bro["ReturnType"]=Json::Value(MNode.ReturnType);
bro["FunctionName"]=Json::Value(MNode.FunctionName);
bro["EntireName"]=Json::Value(MNode.EntireName);
bro["hasFunctionQualifiers"]=Json::Value(MNode.hasFunctionQualifiers);
bro["isCtorOrDtor"]=Json::Value(MNode.isCtorOrDtor);
bro["isFunction"]=Json::Value(MNode.isFunction);
bro["isData"]=Json::Value(MNode.isData);
bro["isSpecialName"]=Json::Value(MNode.isSpecialName);

root["Function"].append(Json::Value(bro));
}
std::ofstream os;
os.open("out.json", std::ios::out);
Json::StyledWriter sw;
if (!os.is_open())
{
std::cout << "error:can't find the file" << std::endl;
}
os << sw.write(root);
os.close();












//free(demangled);

return 0;
}
Loading