[llvm-commits] CVS: llvm-java/lib/Compiler/Compiler.cpp

Alkis Evlogimenos alkis at cs.uiuc.edu
Sat Dec 11 15:29:34 PST 2004



Changes in directory llvm-java/lib/Compiler:

Compiler.cpp updated: 1.177 -> 1.178
---
Log message:

Correctly mangle overloaded JNI calls.


---
Diffs of the changes:  (+29 -18)

Index: llvm-java/lib/Compiler/Compiler.cpp
diff -u llvm-java/lib/Compiler/Compiler.cpp:1.177 llvm-java/lib/Compiler/Compiler.cpp:1.178
--- llvm-java/lib/Compiler/Compiler.cpp:1.177	Fri Dec 10 04:20:56 2004
+++ llvm-java/lib/Compiler/Compiler.cpp	Sat Dec 11 17:29:23 2004
@@ -1192,6 +1192,24 @@
       return new GetElementPtrInst(ptr, indices, fieldName, currentBB_);
     }
 
+    std::string getMangledString(const std::string& str) {
+      std::string mangledStr;
+
+      for (unsigned i = 0, e = str.size(); i != e; ++i) {
+        if (str[i] == '/')
+          mangledStr += '_';
+        else if (str[i] == '_')
+          mangledStr += "_1";
+        else if (str[i] == ';')
+          mangledStr += "_2";
+        else if (str[i] == '[')
+          mangledStr += "_3";
+        else
+          mangledStr += str[i];
+      }
+      return mangledStr;
+    }
+
     /// Compiles the passed method only (it does not compile any
     /// callers or methods of objects it creates).
     Function* compileMethodOnly(const std::string& classMethodDesc) {
@@ -1210,24 +1228,17 @@
         FunctionType* funcTy = cast<FunctionType>(
             getJNIType(method->getDescriptor(), ClassInfo::ObjectBaseTy));
 
-        std::string funcName = "Java_";
-        const std::string& className = cf_->getThisClass()->getName()->str();
-        for (unsigned i = 0, e = className.size(); i != e; ++i) {
-          if (className[i] == '/')
-            funcName += '_';
-          else if (className[i] == '_')
-            funcName += "_1";
-          else
-            funcName += className[i];
-        }
-        funcName += '_';
-
-        const std::string& methodName = method->getName()->str();
-        for (unsigned i = 0, e = methodName.size(); i != e; ++i) {
-          if (methodName[i] == '_')
-            funcName += "_1";
-          else
-            funcName += methodName[i];
+        std::string funcName =
+          "Java_" +
+          getMangledString(cf_->getThisClass()->getName()->str()) + '_' +
+          getMangledString(method->getName()->str());
+        if (cf_->isNativeMethodOverloaded(*method)) {
+          // We need to add two underscores and a mangled argument signature
+          funcName += "__";
+          const std::string descr = method->getDescriptor()->str();
+          funcName += getMangledString(
+            std::string(descr.begin() + descr.find('(') + 1,
+                        descr.begin() + descr.find(')')));
         }
 
         Function* jniFunction = module_.getOrInsertFunction(funcName, funcTy);






More information about the llvm-commits mailing list