1 /*
2 * Copyright 2013, 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 <memory>
18 #include <jni.h>
19 #include "Abcc_device.h"
20 using namespace abcc;
21
22 #if VERBOSE
23 long long abcc::llc_usec;
24 #endif
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 JNIEXPORT jint JNICALL
Java_compiler_abcc_AbccService_genLibs(JNIEnv * env,jobject thiz,jstring j_lib_dir,jstring j_sysroot)31 Java_compiler_abcc_AbccService_genLibs(JNIEnv *env, jobject thiz,
32 jstring j_lib_dir, jstring j_sysroot) {
33 const char *lib_dir = env->GetStringUTFChars(j_lib_dir, 0);
34 LOGV("Working directory: %s", lib_dir);
35
36 const char *sysroot = env->GetStringUTFChars(j_sysroot, 0);
37 LOGV("Sysroot: %s", sysroot);
38
39
40 std::auto_ptr<BitcodeCompiler> compiler(new DeviceBitcodeCompiler(lib_dir, sysroot));
41 compiler->prepare();
42 if (compiler->returnCode() != RET_OK) {
43 LOGE("prepare failed");
44 return -1;
45 }
46
47 compiler->cleanupPre();
48 if (compiler->returnCode() != RET_OK) {
49 LOGE("cleanupPre failed");
50 return -1;
51 }
52
53 #if VERBOSE
54 Timer t;
55 t.start();
56 llc_usec = 0;
57 #endif
58
59 compiler->execute();
60
61 #if VERBOSE
62 long long elapsed_msec = (t.stop() + 500) / 1000;
63 long long llc_msec = (llc_usec + 500) / 1000;
64 LOGV("Elapsed time: %lld.%03ds (llc = %lld.%03ds)", elapsed_msec/1000, (int)elapsed_msec%1000,
65 llc_msec/1000, (int)llc_msec%1000);
66 #endif
67
68 compiler->cleanupPost();
69
70 if (compiler->returnCode() != RET_OK) {
71 LOGE("execution failed");
72 return -1;
73 }
74
75 return 0;
76 }
77
78
79 #ifdef __cplusplus
80 } // extern "C"
81 #endif
82