blob: 1a8e8a211bf0f63d11c657eab29530c36f556e28 [file] [log] [blame]
Logan Chien7e6e33d2012-01-31 09:22:09 +08001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "utils_llvm.h"
18
19#include "class_loader.h"
20#include "object.h"
21#include "object_utils.h"
22
23namespace art {
24
25std::string MangleForLLVM(const std::string& s) {
26 std::string result;
27 size_t char_count = CountModifiedUtf8Chars(s.c_str());
28 const char* cp = &s[0];
29 for (size_t i = 0; i < char_count; ++i) {
30 uint16_t ch = GetUtf16FromUtf8(&cp);
31 if (ch == '$' || ch == '<' || ch == '>' || ch > 127) {
32 StringAppendF(&result, "_0%04x", ch);
33 } else {
34 switch (ch) {
35 case '_':
36 result += "_1";
37 break;
38 case ';':
39 result += "_2";
40 break;
41 case '[':
42 result += "_3";
43 break;
44 case '/':
45 result += "_";
46 break;
47 default:
48 result.push_back(ch);
49 break;
50 }
51 }
52 }
53 return result;
54}
55
56std::string LLVMShortName(const Method* m) {
57 MethodHelper mh(m);
58 std::string class_name(mh.GetDeclaringClassDescriptor());
59 // Remove the leading 'L' and trailing ';'...
60 CHECK_EQ(class_name[0], 'L') << class_name;
61 CHECK_EQ(class_name[class_name.size() - 1], ';') << class_name;
62 class_name.erase(0, 1);
63 class_name.erase(class_name.size() - 1, 1);
64
65 std::string method_name(mh.GetName());
66
67 std::string short_name;
68 short_name += "Art_";
69 short_name += MangleForLLVM(class_name);
70 short_name += "_";
71 short_name += MangleForLLVM(method_name);
72 return short_name;
73}
74
75std::string LLVMLongName(const Method* m) {
76 std::string long_name;
77 long_name += LLVMShortName(m);
78 long_name += "__";
79
80 std::string signature(MethodHelper(m).GetSignature());
81 signature.erase(0, 1);
82 signature.erase(signature.begin() + signature.find(')'), signature.end());
83
84 long_name += MangleForLLVM(signature);
85
86 return long_name;
87}
88
89} // namespace art