blob: 98d1c7c72003c558be5bf53496281ceeb785e246 [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
Elliott Hughes13b835a2012-03-13 19:45:22 -070017#include "utils_llvm.h"
18
Shih-wei Liao5b8b1ed2012-02-23 23:48:21 -080019#include <fcntl.h>
20#include <string.h>
21#include <sys/mman.h>
Elliott Hughes13b835a2012-03-13 19:45:22 -070022#include <sys/stat.h>
23#include <sys/types.h>
24#include <unistd.h>
Shih-wei Liao5b8b1ed2012-02-23 23:48:21 -080025
Elliott Hughes13b835a2012-03-13 19:45:22 -070026#include "android/librsloader.h"
Logan Chien7e6e33d2012-01-31 09:22:09 +080027#include "class_loader.h"
28#include "object.h"
29#include "object_utils.h"
Shih-wei Liaoa8a9c342012-03-03 22:35:16 -080030#include "runtime_support_llvm.h"
31
Logan Chien7e6e33d2012-01-31 09:22:09 +080032namespace art {
33
34std::string MangleForLLVM(const std::string& s) {
35 std::string result;
36 size_t char_count = CountModifiedUtf8Chars(s.c_str());
37 const char* cp = &s[0];
38 for (size_t i = 0; i < char_count; ++i) {
39 uint16_t ch = GetUtf16FromUtf8(&cp);
40 if (ch == '$' || ch == '<' || ch == '>' || ch > 127) {
41 StringAppendF(&result, "_0%04x", ch);
42 } else {
43 switch (ch) {
44 case '_':
45 result += "_1";
46 break;
47 case ';':
48 result += "_2";
49 break;
50 case '[':
51 result += "_3";
52 break;
53 case '/':
54 result += "_";
55 break;
56 default:
57 result.push_back(ch);
58 break;
59 }
60 }
61 }
62 return result;
63}
64
65std::string LLVMShortName(const Method* m) {
66 MethodHelper mh(m);
67 std::string class_name(mh.GetDeclaringClassDescriptor());
68 // Remove the leading 'L' and trailing ';'...
69 CHECK_EQ(class_name[0], 'L') << class_name;
70 CHECK_EQ(class_name[class_name.size() - 1], ';') << class_name;
71 class_name.erase(0, 1);
72 class_name.erase(class_name.size() - 1, 1);
73
74 std::string method_name(mh.GetName());
75
76 std::string short_name;
77 short_name += "Art_";
78 short_name += MangleForLLVM(class_name);
79 short_name += "_";
80 short_name += MangleForLLVM(method_name);
81 return short_name;
82}
83
84std::string LLVMLongName(const Method* m) {
85 std::string long_name;
86 long_name += LLVMShortName(m);
87 long_name += "__";
88
89 std::string signature(MethodHelper(m).GetSignature());
90 signature.erase(0, 1);
91 signature.erase(signature.begin() + signature.find(')'), signature.end());
92
93 long_name += MangleForLLVM(signature);
94
95 return long_name;
96}
97
Shih-wei Liao5b8b1ed2012-02-23 23:48:21 -080098std::string LLVMStubName(const Method* m) {
99 MethodHelper mh(m);
100 std::string stub_name;
101 if (m->IsStatic()) {
102 stub_name += "ArtSUpcall_";
103 } else {
104 stub_name += "ArtUpcall_";
105 }
106 stub_name += mh.GetShorty();
107
108 return stub_name;
109}
110
Logan Chien7e6e33d2012-01-31 09:22:09 +0800111} // namespace art