blob: 4cf847525ae1b4f534521cc88742ca4c34d31c14 [file] [log] [blame]
Zonr Chang19218c02012-04-05 10:44:53 +08001/*
2 * Copyright 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
Zonr Chang80232dd2012-04-12 15:38:53 +080017#include "bcc/RenderScript/RSScript.h"
Zonr Chang19218c02012-04-05 10:44:53 +080018
Zonr Chang19218c02012-04-05 10:44:53 +080019#include <cstring>
20
21#include <llvm/ADT/STLExtras.h>
22
Zonr Chang80232dd2012-04-12 15:38:53 +080023#include "bcc/Support/DebugHelper.h"
Zonr Chang19218c02012-04-05 10:44:53 +080024
Zonr Changfef9a1b2012-04-13 15:58:24 +080025using namespace bcc;
Zonr Chang19218c02012-04-05 10:44:53 +080026
Zonr Chang255cbc82012-04-12 13:29:43 +080027RSScript::SourceDependency::SourceDependency(const std::string &pSourceName,
Zonr Chang19218c02012-04-05 10:44:53 +080028 const uint8_t *pSHA1)
Zonr Chang255cbc82012-04-12 13:29:43 +080029 : mSourceName(pSourceName) {
Zonr Chang19218c02012-04-05 10:44:53 +080030 ::memcpy(mSHA1, pSHA1, sizeof(mSHA1));
31 return;
32}
33
34RSScript::RSScript(Source &pSource)
Zonr Changfef9a1b2012-04-13 15:58:24 +080035 : Script(pSource), mInfo(NULL), mCompilerVersion(0),
36 mOptimizationLevel(kOptLvl3) { }
Zonr Chang19218c02012-04-05 10:44:53 +080037
38RSScript::~RSScript() {
Zonr Chang19218c02012-04-05 10:44:53 +080039 llvm::DeleteContainerPointers(mSourceDependencies);
40}
41
Zonr Chang19218c02012-04-05 10:44:53 +080042bool RSScript::doReset() {
Zonr Changfef9a1b2012-04-13 15:58:24 +080043 mInfo = NULL;
44 mCompilerVersion = 0;
45 mOptimizationLevel = kOptLvl3;
46 llvm::DeleteContainerPointers(mSourceDependencies);
Zonr Chang19218c02012-04-05 10:44:53 +080047 return true;
48}
49
Zonr Chang255cbc82012-04-12 13:29:43 +080050bool RSScript::addSourceDependency(const std::string &pSourceName,
Zonr Chang19218c02012-04-05 10:44:53 +080051 const uint8_t *pSHA1) {
52 SourceDependency *source_dep =
Zonr Chang255cbc82012-04-12 13:29:43 +080053 new (std::nothrow) SourceDependency(pSourceName, pSHA1);
Zonr Chang19218c02012-04-05 10:44:53 +080054 if (source_dep == NULL) {
55 ALOGE("Out of memory when record dependency information of `%s'!",
56 pSourceName.c_str());
57 return false;
58 }
59
60 mSourceDependencies.push_back(source_dep);
61 return true;
62}