aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-12-14 12:16:45 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-12-14 12:16:45 -0800
commit02ab691e5965b6500886edea8289f3fac792ef75 (patch)
treee0c83fe6927cc5a28032769934872e962e1bccac
parenta3388042b3cf9be51a9c5b54d0d36bfde97e640b (diff)
export used redirects
-rw-r--r--lib/Target/CppBackend/CPPBackend.cpp22
-rw-r--r--lib/Target/CppBackend/CallHandlers.h2
2 files changed, 24 insertions, 0 deletions
diff --git a/lib/Target/CppBackend/CPPBackend.cpp b/lib/Target/CppBackend/CPPBackend.cpp
index 4d711827a5..57427c05bd 100644
--- a/lib/Target/CppBackend/CPPBackend.cpp
+++ b/lib/Target/CppBackend/CPPBackend.cpp
@@ -113,6 +113,7 @@ namespace {
typedef std::map<std::string, Address> GlobalAddressMap;
typedef std::vector<std::string> FunctionTable;
typedef std::map<std::string, FunctionTable> FunctionTableMap;
+ typedef std::map<std::string, std::string> StringMap;
/// CppWriter - This class is the main chunk of code that converts an LLVM
/// module to a C++ translation unit.
@@ -135,6 +136,7 @@ namespace {
GlobalAddressMap GlobalAddresses;
NameSet Externals; // vars
NameSet Declares; // funcs
+ StringMap Redirects; // library function redirects actually used, needed for wrapper funcs in tables
std::string PostSets;
std::map<std::string, unsigned> IndexedFunctions; // name -> index
FunctionTableMap FunctionTables; // sig => list of functions
@@ -250,6 +252,13 @@ namespace {
unsigned Index = Table.size();
Table.push_back(Name);
IndexedFunctions[Name] = Index;
+
+ // invoke the callHandler for this, if there is one. the function may only be indexed but never called directly, we need to catch it in the handler
+ CallHandlerMap::iterator CH = CallHandlers->find(Name);
+ if (CH != CallHandlers->end()) {
+ (this->*(CH->second))(NULL, Name, -1);
+ }
+
return Index;
}
void ensureFunctionTable(const FunctionType *F) {
@@ -2404,6 +2413,19 @@ void CppWriter::printModuleBody() {
}
Out << "],";
+ Out << "\"redirects\": {";
+ first = true;
+ for (StringMap::iterator I = Redirects.begin(), E = Redirects.end();
+ I != E; ++I) {
+ if (first) {
+ first = false;
+ } else {
+ Out << ", ";
+ }
+ Out << "\"_" << I->first << "\": \"" + I->second + "\"";
+ }
+ Out << "},";
+
Out << "\"externs\": [";
first = true;
for (NameSet::iterator I = Externals.begin(), E = Externals.end();
diff --git a/lib/Target/CppBackend/CallHandlers.h b/lib/Target/CppBackend/CallHandlers.h
index eb4a5bd5ad..d68237466a 100644
--- a/lib/Target/CppBackend/CallHandlers.h
+++ b/lib/Target/CppBackend/CallHandlers.h
@@ -86,6 +86,8 @@ DEF_CALL_HANDLER(bitshift64Shl, {
DEF_CALL_HANDLER(name, { \
/* FIXME: do not redirect if this is implemented and not just a declare! */ \
Declares.insert(#to); \
+ Redirects[#name] = #to; \
+ if (!CI) return ""; \
return CH___default__(CI, "_" #to); \
})