blob: 2a9ccba87532c5736f1aa9a88e82ef717e11721c [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;
TDYa127f058c0f2012-04-01 07:43:08 -070053 case ')':
54 result += "_4";
55 break;
Logan Chien7e6e33d2012-01-31 09:22:09 +080056 case '/':
57 result += "_";
58 break;
59 default:
60 result.push_back(ch);
61 break;
62 }
63 }
64 }
65 return result;
66}
67
68std::string LLVMShortName(const Method* m) {
69 MethodHelper mh(m);
70 std::string class_name(mh.GetDeclaringClassDescriptor());
71 // Remove the leading 'L' and trailing ';'...
72 CHECK_EQ(class_name[0], 'L') << class_name;
73 CHECK_EQ(class_name[class_name.size() - 1], ';') << class_name;
74 class_name.erase(0, 1);
75 class_name.erase(class_name.size() - 1, 1);
76
77 std::string method_name(mh.GetName());
78
79 std::string short_name;
80 short_name += "Art_";
81 short_name += MangleForLLVM(class_name);
82 short_name += "_";
83 short_name += MangleForLLVM(method_name);
84 return short_name;
85}
86
87std::string LLVMLongName(const Method* m) {
88 std::string long_name;
89 long_name += LLVMShortName(m);
90 long_name += "__";
91
92 std::string signature(MethodHelper(m).GetSignature());
93 signature.erase(0, 1);
Logan Chien7e6e33d2012-01-31 09:22:09 +080094
95 long_name += MangleForLLVM(signature);
96
97 return long_name;
98}
99
Shih-wei Liao5b8b1ed2012-02-23 23:48:21 -0800100std::string LLVMStubName(const Method* m) {
101 MethodHelper mh(m);
102 std::string stub_name;
103 if (m->IsStatic()) {
104 stub_name += "ArtSUpcall_";
105 } else {
106 stub_name += "ArtUpcall_";
107 }
108 stub_name += mh.GetShorty();
109
110 return stub_name;
111}
112
Logan Chien7e6e33d2012-01-31 09:22:09 +0800113} // namespace art