Script.cpp revision fc9c55b0c248a04a325c3540b75ecd3ae64fd91f
1/*
2 * Copyright 2010-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 "bcc/Script.h"
18
19#include "Assert.h"
20#include "Log.h"
21
22#include "bcc/CompilerConfig.h"
23#include "bcc/Source.h"
24
25using namespace bcc;
26
27Script::Script(Source *pSource)
28    : mSource(pSource),
29      mCompilerVersion(0),
30      mOptimizationLevel(llvm::CodeGenOpt::Aggressive),
31      mLinkRuntimeCallback(nullptr), mEmbedInfo(false), mEmbedGlobalInfo(false),
32      mEmbedGlobalInfoSkipConstant(false) {}
33
34bool Script::LinkRuntime(const char *core_lib) {
35  bccAssert(core_lib != nullptr);
36
37  // Using the same context with the source.
38  BCCContext &context = mSource->getContext();
39
40  Source *libclcore_source = Source::CreateFromFile(context, core_lib);
41  if (libclcore_source == nullptr) {
42    ALOGE("Failed to load Renderscript library '%s' to link!", core_lib);
43    return false;
44  }
45
46  if (mLinkRuntimeCallback != nullptr) {
47    mLinkRuntimeCallback(this, &mSource->getModule(),
48                         &libclcore_source->getModule());
49  }
50
51  if (!mSource->merge(*libclcore_source)) {
52    ALOGE("Failed to link Renderscript library '%s'!", core_lib);
53    delete libclcore_source;
54    return false;
55  }
56
57  return true;
58}
59
60bool Script::mergeSource(Source &pSource) { return mSource->merge(pSource); }
61