Script.cpp revision 0a2acce3493df1609be2730e3058fe27af01b88f
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      mOptimizationLevel(llvm::CodeGenOpt::Aggressive),
30      mLinkRuntimeCallback(nullptr), mEmbedInfo(false), mEmbedGlobalInfo(false),
31      mEmbedGlobalInfoSkipConstant(false) {}
32
33bool Script::LinkRuntime(const char *core_lib) {
34  bccAssert(core_lib != nullptr);
35
36  // Using the same context with the source.
37  BCCContext &context = mSource->getContext();
38
39  Source *libclcore_source = Source::CreateFromFile(context, core_lib);
40  if (libclcore_source == nullptr) {
41    ALOGE("Failed to load Renderscript library '%s' to link!", core_lib);
42    return false;
43  }
44
45  if (mLinkRuntimeCallback != nullptr) {
46    mLinkRuntimeCallback(this, &mSource->getModule(),
47                         &libclcore_source->getModule());
48  }
49
50  if (!mSource->merge(*libclcore_source)) {
51    ALOGE("Failed to link Renderscript library '%s'!", core_lib);
52    delete libclcore_source;
53    return false;
54  }
55
56  return true;
57}
58
59bool Script::mergeSource(Source &pSource) { return mSource->merge(pSource); }
60