blob: e04db880a58b2e48adbd98ecc7fda41af3289608 [file] [log] [blame]
Stephen Hines0164f462011-11-22 19:43:31 -08001/*
Stephen Hines7cd4c492012-03-13 19:57:37 -07002 * Copyright 2011-2012, The Android Open Source Project
Stephen Hines0164f462011-11-22 19:43:31 -08003 *
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 "bcinfo/BitcodeWrapper.h"
Stephen Hines7cd4c492012-03-13 19:57:37 -070018#include "bcinfo/Wrap/bitcode_wrapperer.h"
19#include "bcinfo/Wrap/in_memory_wrapper_input.h"
Stephen Hines0164f462011-11-22 19:43:31 -080020
21#define LOG_TAG "bcinfo"
22#include <cutils/log.h>
23
24#include "llvm/Bitcode/ReaderWriter.h"
25
26#include <cstdlib>
27#include <cstring>
28
29namespace bcinfo {
30
31BitcodeWrapper::BitcodeWrapper(const char *bitcode, size_t bitcodeSize)
32 : mFileType(BC_NOT_BC), mBitcode(bitcode),
Stephen Hines7cd4c492012-03-13 19:57:37 -070033 mBitcodeEnd(bitcode + bitcodeSize - 1), mBitcodeSize(bitcodeSize),
Stephen Hinesb67c9e72012-03-22 11:02:48 -070034 mHeaderVersion(0), mTargetAPI(0), mCompilerVersion(0),
35 mOptimizationLevel(3) {
Stephen Hines7cd4c492012-03-13 19:57:37 -070036 InMemoryWrapperInput inMem(mBitcode, mBitcodeSize);
37 BitcodeWrapperer wrapperer(&inMem, NULL);
38 if (wrapperer.IsInputBitcodeWrapper()) {
39 mFileType = BC_WRAPPER;
40 mHeaderVersion = wrapperer.getAndroidHeaderVersion();
41 mTargetAPI = wrapperer.getAndroidTargetAPI();
42 mCompilerVersion = wrapperer.getAndroidCompilerVersion();
43 mOptimizationLevel = wrapperer.getAndroidOptimizationLevel();
44 } else if (wrapperer.IsInputBitcodeFile()) {
45 mFileType = BC_RAW;
46 }
Stephen Hines0164f462011-11-22 19:43:31 -080047}
48
49
50BitcodeWrapper::~BitcodeWrapper() {
51 return;
52}
53
54
55bool BitcodeWrapper::unwrap() {
Stephen Hines7cd4c492012-03-13 19:57:37 -070056 return mFileType != BC_NOT_BC;
Stephen Hines0164f462011-11-22 19:43:31 -080057}
58
59} // namespace bcinfo
60